Current File : /home/k/a/r/karenpetzb/www/items/category/Zend.zip |
PK pG[�X�܄% �% Feed/Entry/Atom.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 10383 2008-07-24 19:46:15Z matthew $
*/
/**
* @see Zend_Feed_Entry_Abstract
*/
require_once 'Zend/Feed/Entry/Abstract.php';
/**
* Concrete class for working with Atom entries.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Root XML element for Atom entries.
*
* @var string
*/
protected $_rootElement = 'entry';
/**
* Root namespace for Atom entries.
*
* @var string
*/
protected $_rootNamespace = 'atom';
/**
* Delete an atom entry.
*
* Delete tries to delete this entry from its feed. If the entry
* does not contain a link rel="edit", we throw an error (either
* the entry does not yet exist or this is not an editable
* feed). If we have a link rel="edit", we do the empty-body
* HTTP DELETE to that URI and check for a response of 2xx.
* Usually the response would be 204 No Content, but the Atom
* Publishing Protocol permits it to be 200 OK.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function delete()
{
// Look for link rel="edit" in the entry object.
$deleteUri = $this->link('edit');
if (!$deleteUri) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot delete entry; no link rel="edit" is present.');
}
// DELETE
$client = Zend_Feed::getHttpClient();
do {
$client->setUri($deleteUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeader('X-HTTP-Method-Override', 'DELETE');
$response = $client->request('POST');
} else {
$response = $client->request('DELETE');
}
$httpStatus = $response->getStatus();
switch ((int) $httpStatus / 100) {
// Success
case 2:
return true;
// Redirect
case 3:
$deleteUri = $response->getHeader('Location');
continue;
// Error
default:
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("Expected response code 2xx, got $httpStatus");
}
} while (true);
}
/**
* Save a new or updated Atom entry.
*
* Save is used to either create new entries or to save changes to
* existing ones. If we have a link rel="edit", we are changing
* an existing entry. In this case we re-serialize the entry and
* PUT it to the edit URI, checking for a 200 OK result.
*
* For posting new entries, you must specify the $postUri
* parameter to save() to tell the object where to post itself.
* We use $postUri and POST the serialized entry there, checking
* for a 201 Created response. If the insert is successful, we
* then parse the response from the POST to get any values that
* the server has generated: an id, an updated time, and its new
* link rel="edit".
*
* @param string $postUri Location to POST for creating new entries.
* @return void
* @throws Zend_Feed_Exception
*/
public function save($postUri = null)
{
if ($this->id()) {
// If id is set, look for link rel="edit" in the
// entry object and PUT.
$editUri = $this->link('edit');
if (!$editUri) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($editUri);
if (Zend_Feed::getHttpMethodOverride()) {
$client->setHeaders(array('X-HTTP-Method-Override: PUT',
'Content-Type: application/atom+xml'));
$client->setRawData($this->saveXML());
$response = $client->request('POST');
} else {
$client->setHeaders('Content-Type', 'application/atom+xml');
$client->setRawData($this->saveXML());
$response = $client->request('PUT');
}
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
}
} else {
if ($postUri === null) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
}
$client = Zend_Feed::getHttpClient();
$client->setUri($postUri);
$client->setRawData($this->saveXML());
$response = $client->request('POST');
if ($response->getStatus() !== 201) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Expected response code 201, got '
. $response->getStatus());
}
}
// Update internal properties using $client->responseBody;
@ini_set('track_errors', 1);
$newEntry = new DOMDocument;
$status = @$newEntry->loadXML($response->getBody());
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
}
$newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
if (!$newEntry) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <feed> element found in server response:'
. "\n\n" . $client->responseBody);
}
if ($this->_element->parentNode) {
$oldElement = $this->_element;
$this->_element = $oldElement->ownerDocument->importNode($newEntry, true);
$oldElement->parentNode->replaceChild($this->_element, $oldElement);
} else {
$this->_element = $newEntry;
}
}
/**
* Easy access to <link> tags keyed by "rel" attributes.
*
* If $elt->link() is called with no arguments, we will attempt to
* return the value of the <link> tag(s) like all other
* method-syntax attribute access. If an argument is passed to
* link(), however, then we will return the "href" value of the
* first <link> tag that has a "rel" attribute matching $rel:
*
* $elt->link(): returns the value of the link tag.
* $elt->link('self'): returns the href from the first <link rel="self"> in the entry.
*
* @param string $rel The "rel" attribute to look for.
* @return mixed
*/
public function link($rel = null)
{
if ($rel === null) {
return parent::__call('link', null);
}
// index link tags by their "rel" attribute.
$links = parent::__get('link');
if (!is_array($links)) {
if ($links instanceof Zend_Feed_Element) {
$links = array($links);
} else {
return $links;
}
}
foreach ($links as $link) {
if (empty($link['rel'])) {
continue;
}
if ($rel == $link['rel']) {
return $link['href'];
}
}
return null;
}
}
PK pG[8_�2 Feed/Entry/Rss.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rss.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Feed_Entry_Abstract
*/
require_once 'Zend/Feed/Entry/Abstract.php';
/**
* Concrete class for working with RSS items.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Root XML element for RSS items.
*
* @var string
*/
protected $_rootElement = 'item';
/**
* Overwrites parent::_get method to enable read access
* to content:encoded element.
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'content':
$prefix = $this->_element->lookupPrefix('http://purl.org/rss/1.0/modules/content/');
return parent::__get("$prefix:encoded");
default:
return parent::__get($var);
}
}
/**
* Overwrites parent::_set method to enable write access
* to content:encoded element.
*
* @param string $var The property to change.
* @param string $val The property's new value.
* @return void
*/
public function __set($var, $value)
{
switch ($var) {
case 'content':
parent::__set('content:encoded', $value);
break;
default:
parent::__set($var, $value);
}
}
/**
* Overwrites parent::_isset method to enable access
* to content:encoded element.
*
* @param string $var
* @return boolean
*/
public function __isset($var)
{
switch ($var) {
case 'content':
// don't use other callback to prevent invalid returned value
return $this->content() !== null;
default:
return parent::__isset($var);
}
}
/**
* Overwrites parent::_call method to enable read access
* to content:encoded element.
* Please note that method-style write access is not currently supported
* by parent method, consequently this method doesn't as well.
*
* @param string $var The element to get the string value of.
* @param mixed $unused This parameter is not used.
* @return mixed The node's value, null, or an array of nodes.
*/
public function __call($var, $unused)
{
switch ($var) {
case 'content':
$prefix = $this->_element->lookupPrefix('http://purl.org/rss/1.0/modules/content/');
return parent::__call("$prefix:encoded", $unused);
default:
return parent::__call($var, $unused);
}
}
}
PK pG[�~Ν Feed/Entry/Abstract.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 10383 2008-07-24 19:46:15Z matthew $
*/
/**
* @see Zend_Feed
*/
require_once 'Zend/Feed.php';
/**
* @see Zend_Feed_Element
*/
require_once 'Zend/Feed/Element.php';
/**
* Zend_Feed_Entry_Abstract represents a single entry in an Atom or RSS
* feed.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Root XML element for entries. Subclasses must define this to a
* non-null value.
*
* @var string
*/
protected $_rootElement;
/**
* Root namespace for entries. Subclasses may define this to a
* non-null value.
*
* @var string
*/
protected $_rootNamespace = null;
/**
* Zend_Feed_Entry_Abstract constructor
*
* The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
* is part of, and optionally an XML construct (usually a
* SimpleXMLElement, but it can be an XML string or a DOMNode as
* well) that contains the contents of the entry.
*
* @param string $uri
* @param SimpleXMLElement|DOMNode|string $element
* @return void
* @throws Zend_Feed_Exception
*/
public function __construct($uri = null, $element = null)
{
if (!($element instanceof DOMElement)) {
if ($element) {
// Load the feed as an XML DOMDocument object
@ini_set('track_errors', 1);
$doc = new DOMDocument();
$status = @$doc->loadXML($element);
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
if (!$element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
}
} else {
$doc = new DOMDocument('1.0', 'utf-8');
if ($this->_rootNamespace !== null) {
$element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
} else {
$element = $doc->createElement($this->_rootElement);
}
}
}
parent::__construct($element);
}
}
PK pG[�f��F F Feed/Builder.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Builder.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Feed_Builder_Interface
*/
require_once 'Zend/Feed/Builder/Interface.php';
/**
* @see Zend_Feed_Builder_Header
*/
require_once 'Zend/Feed/Builder/Header.php';
/**
* @see Zend_Feed_Builder_Entry
*/
require_once 'Zend/Feed/Builder/Entry.php';
/**
* A simple implementation of Zend_Feed_Builder_Interface.
*
* Users are encouraged to make their own classes to implement Zend_Feed_Builder_Interface
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* The data of the feed
*
* @var $_data array
*/
private $_data;
/**
* Header of the feed
*
* @var $_header Zend_Feed_Builder_Header
*/
private $_header;
/**
* List of the entries of the feed
*
* @var $_entries array
*/
private $_entries = array();
/**
* Constructor. The $data array must conform to the following format:
* <code>
* array(
* 'title' => 'title of the feed', //required
* 'link' => 'canonical url to the feed', //required
* 'lastUpdate' => 'timestamp of the update date', // optional
* 'published' => 'timestamp of the publication date', //optional
* 'charset' => 'charset', // required
* 'description' => 'short description of the feed', //optional
* 'author' => 'author/publisher of the feed', //optional
* 'email' => 'email of the author', //optional
* 'webmaster' => 'email address for person responsible for technical issues' // optional, ignored if atom is used
* 'copyright' => 'copyright notice', //optional
* 'image' => 'url to image', //optional
* 'generator' => 'generator', // optional
* 'language' => 'language the feed is written in', // optional
* 'ttl' => 'how long in minutes a feed can be cached before refreshing', // optional, ignored if atom is used
* 'rating' => 'The PICS rating for the channel.', // optional, ignored if atom is used
* 'cloud' => array(
* 'domain' => 'domain of the cloud, e.g. rpc.sys.com' // required
* 'port' => 'port to connect to' // optional, default to 80
* 'path' => 'path of the cloud, e.g. /RPC2 //required
* 'registerProcedure' => 'procedure to call, e.g. myCloud.rssPleaseNotify' // required
* 'protocol' => 'protocol to use, e.g. soap or xml-rpc' // required
* ), a cloud to be notified of updates // optional, ignored if atom is used
* 'textInput' => array(
* 'title' => 'the label of the Submit button in the text input area' // required,
* 'description' => 'explains the text input area' // required
* 'name' => 'the name of the text object in the text input area' // required
* 'link' => 'the URL of the CGI script that processes text input requests' // required
* ) // a text input box that can be displayed with the feed // optional, ignored if atom is used
* 'skipHours' => array(
* 'hour in 24 format', // e.g 13 (1pm)
* // up to 24 rows whose value is a number between 0 and 23
* ) // Hint telling aggregators which hours they can skip // optional, ignored if atom is used
* 'skipDays ' => array(
* 'a day to skip', // e.g Monday
* // up to 7 rows whose value is a Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday
* ) // Hint telling aggregators which days they can skip // optional, ignored if atom is used
* 'itunes' => array(
* 'author' => 'Artist column' // optional, default to the main author value
* 'owner' => array(
* 'name' => 'name of the owner' // optional, default to main author value
* 'email' => 'email of the owner' // optional, default to main email value
* ) // Owner of the podcast // optional
* 'image' => 'album/podcast art' // optional, default to the main image value
* 'subtitle' => 'short description' // optional, default to the main description value
* 'summary' => 'longer description' // optional, default to the main description value
* 'block' => 'Prevent an episode from appearing (yes|no)' // optional
* 'category' => array(
* array('main' => 'main category', // required
* 'sub' => 'sub category' // optional
* ),
* // up to 3 rows
* ) // 'Category column and in iTunes Music Store Browse' // required
* 'explicit' => 'parental advisory graphic (yes|no|clean)' // optional
* 'keywords' => 'a comma separated list of 12 keywords maximum' // optional
* 'new-feed-url' => 'used to inform iTunes of new feed URL location' // optional
* ) // Itunes extension data // optional, ignored if atom is used
* 'entries' => array(
* array(
* 'title' => 'title of the feed entry', //required
* 'link' => 'url to a feed entry', //required
* 'description' => 'short version of a feed entry', // only text, no html, required
* 'guid' => 'id of the article, if not given link value will used', //optional
* 'content' => 'long version', // can contain html, optional
* 'lastUpdate' => 'timestamp of the publication date', // optional
* 'comments' => 'comments page of the feed entry', // optional
* 'commentRss' => 'the feed url of the associated comments', // optional
* 'source' => array(
* 'title' => 'title of the original source' // required,
* 'url' => 'url of the original source' // required
* ) // original source of the feed entry // optional
* 'category' => array(
* array(
* 'term' => 'first category label' // required,
* 'scheme' => 'url that identifies a categorization scheme' // optional
* ),
* array(
* //data for the second category and so on
* )
* ) // list of the attached categories // optional
* 'enclosure' => array(
* array(
* 'url' => 'url of the linked enclosure' // required
* 'type' => 'mime type of the enclosure' // optional
* 'length' => 'length of the linked content in octets' // optional
* ),
* array(
* //data for the second enclosure and so on
* )
* ) // list of the enclosures of the feed entry // optional
* ),
* array(
* //data for the second entry and so on
* )
* )
* );
* </code>
*
* @param array $data
* @return void
*/
public function __construct(array $data)
{
$this->_data = $data;
$this->_createHeader($data);
if (isset($data['entries'])) {
$this->_createEntries($data['entries']);
}
}
/**
* Returns an instance of Zend_Feed_Builder_Header
* describing the header of the feed
*
* @return Zend_Feed_Builder_Header
*/
public function getHeader()
{
return $this->_header;
}
/**
* Returns an array of Zend_Feed_Builder_Entry instances
* describing the entries of the feed
*
* @return array of Zend_Feed_Builder_Entry
*/
public function getEntries()
{
return $this->_entries;
}
/**
* Create the Zend_Feed_Builder_Header instance
*
* @param array $data
* @throws Zend_Feed_Builder_Exception
* @return void
*/
private function _createHeader(array $data)
{
$mandatories = array('title', 'link', 'charset');
foreach ($mandatories as $mandatory) {
if (!isset($data[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$this->_header = new Zend_Feed_Builder_Header($data['title'], $data['link'], $data['charset']);
if (isset($data['lastUpdate'])) {
$this->_header->setLastUpdate($data['lastUpdate']);
}
if (isset($data['published'])) {
$this->_header->setPublishedDate($data['published']);
}
if (isset($data['description'])) {
$this->_header->setDescription($data['description']);
}
if (isset($data['author'])) {
$this->_header->setAuthor($data['author']);
}
if (isset($data['email'])) {
$this->_header->setEmail($data['email']);
}
if (isset($data['webmaster'])) {
$this->_header->setWebmaster($data['webmaster']);
}
if (isset($data['copyright'])) {
$this->_header->setCopyright($data['copyright']);
}
if (isset($data['image'])) {
$this->_header->setImage($data['image']);
}
if (isset($data['generator'])) {
$this->_header->setGenerator($data['generator']);
}
if (isset($data['language'])) {
$this->_header->setLanguage($data['language']);
}
if (isset($data['ttl'])) {
$this->_header->setTtl($data['ttl']);
}
if (isset($data['rating'])) {
$this->_header->setRating($data['rating']);
}
if (isset($data['cloud'])) {
$mandatories = array('domain', 'path', 'registerProcedure', 'protocol');
foreach ($mandatories as $mandatory) {
if (!isset($data['cloud'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your cloud");
}
}
$uri_str = 'http://' . $data['cloud']['domain'] . $data['cloud']['path'];
$this->_header->setCloud($uri_str, $data['cloud']['registerProcedure'], $data['cloud']['protocol']);
}
if (isset($data['textInput'])) {
$mandatories = array('title', 'description', 'name', 'link');
foreach ($mandatories as $mandatory) {
if (!isset($data['textInput'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define $mandatory property of your textInput");
}
}
$this->_header->setTextInput($data['textInput']['title'],
$data['textInput']['description'],
$data['textInput']['name'],
$data['textInput']['link']);
}
if (isset($data['skipHours'])) {
$this->_header->setSkipHours($data['skipHours']);
}
if (isset($data['skipDays'])) {
$this->_header->setSkipDays($data['skipDays']);
}
if (isset($data['itunes'])) {
$itunes = new Zend_Feed_Builder_Header_Itunes($data['itunes']['category']);
if (isset($data['itunes']['author'])) {
$itunes->setAuthor($data['itunes']['author']);
}
if (isset($data['itunes']['owner'])) {
$name = isset($data['itunes']['owner']['name']) ? $data['itunes']['owner']['name'] : '';
$email = isset($data['itunes']['owner']['email']) ? $data['itunes']['owner']['email'] : '';
$itunes->setOwner($name, $email);
}
if (isset($data['itunes']['image'])) {
$itunes->setImage($data['itunes']['image']);
}
if (isset($data['itunes']['subtitle'])) {
$itunes->setSubtitle($data['itunes']['subtitle']);
}
if (isset($data['itunes']['summary'])) {
$itunes->setSummary($data['itunes']['summary']);
}
if (isset($data['itunes']['block'])) {
$itunes->setBlock($data['itunes']['block']);
}
if (isset($data['itunes']['explicit'])) {
$itunes->setExplicit($data['itunes']['explicit']);
}
if (isset($data['itunes']['keywords'])) {
$itunes->setKeywords($data['itunes']['keywords']);
}
if (isset($data['itunes']['new-feed-url'])) {
$itunes->setNewFeedUrl($data['itunes']['new-feed-url']);
}
$this->_header->setITunes($itunes);
}
}
/**
* Create the array of article entries
*
* @param array $data
* @throws Zend_Feed_Builder_Exception
* @return void
*/
private function _createEntries(array $data)
{
foreach ($data as $row) {
$mandatories = array('title', 'link', 'description');
foreach ($mandatories as $mandatory) {
if (!isset($row[$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key is missing");
}
}
$entry = new Zend_Feed_Builder_Entry($row['title'], $row['link'], $row['description']);
if (isset($row['guid'])) {
$entry->setId($row['guid']);
}
if (isset($row['content'])) {
$entry->setContent($row['content']);
}
if (isset($row['lastUpdate'])) {
$entry->setLastUpdate($row['lastUpdate']);
}
if (isset($row['comments'])) {
$entry->setCommentsUrl($row['comments']);
}
if (isset($row['commentRss'])) {
$entry->setCommentsRssUrl($row['commentRss']);
}
if (isset($row['source'])) {
$mandatories = array('title', 'url');
foreach ($mandatories as $mandatory) {
if (!isset($row['source'][$mandatory])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$mandatory key of source property is missing");
}
}
$entry->setSource($row['source']['title'], $row['source']['url']);
}
if (isset($row['category'])) {
$entry->setCategories($row['category']);
}
if (isset($row['enclosure'])) {
$entry->setEnclosures($row['enclosure']);
}
$this->_entries[] = $entry;
}
}
}PK pG[\�d�. �. Feed/Builder/Header.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Header.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Feed_Builder_Header_Itunes
*/
require_once 'Zend/Feed/Builder/Header/Itunes.php';
/**
* @see Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* Header of a custom build feed
*
* Classes implementing the Zend_Feed_Builder_Interface interface
* uses this class to describe the header of a feed
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Constructor
*
* @param string $title title of the feed
* @param string $link canonical url of the feed
* @param string $charset charset of the textual data
* @return void
*/
public function __construct($title, $link, $charset = 'utf-8')
{
$this->offsetSet('title', $title);
$this->offsetSet('link', $link);
$this->offsetSet('charset', $charset);
$this->setLastUpdate(time())
->setGenerator('Zend_Feed');
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
/**
* Timestamp of the update date
*
* @param int $lastUpdate
* @return Zend_Feed_Builder_Header
*/
public function setLastUpdate($lastUpdate)
{
$this->offsetSet('lastUpdate', $lastUpdate);
return $this;
}
/**
* Timestamp of the publication date
*
* @param int $published
* @return Zend_Feed_Builder_Header
*/
public function setPublishedDate($published)
{
$this->offsetSet('published', $published);
return $this;
}
/**
* Short description of the feed
*
* @param string $description
* @return Zend_Feed_Builder_Header
*/
public function setDescription($description)
{
$this->offsetSet('description', $description);
return $this;
}
/**
* Sets the author of the feed
*
* @param string $author
* @return Zend_Feed_Builder_Header
*/
public function setAuthor($author)
{
$this->offsetSet('author', $author);
return $this;
}
/**
* Sets the author's email
*
* @param string $email
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setEmail($email)
{
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($email)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property");
}
$this->offsetSet('email', $email);
return $this;
}
/**
* Sets the copyright notice
*
* @param string $copyright
* @return Zend_Feed_Builder_Header
*/
public function setCopyright($copyright)
{
$this->offsetSet('copyright', $copyright);
return $this;
}
/**
* Sets the image of the feed
*
* @param string $image
* @return Zend_Feed_Builder_Header
*/
public function setImage($image)
{
$this->offsetSet('image', $image);
return $this;
}
/**
* Sets the generator of the feed
*
* @param string $generator
* @return Zend_Feed_Builder_Header
*/
public function setGenerator($generator)
{
$this->offsetSet('generator', $generator);
return $this;
}
/**
* Sets the language of the feed
*
* @param string $language
* @return Zend_Feed_Builder_Header
*/
public function setLanguage($language)
{
$this->offsetSet('language', $language);
return $this;
}
/**
* Email address for person responsible for technical issues
* Ignored if atom is used
*
* @param string $webmaster
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setWebmaster($webmaster)
{
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($webmaster)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property");
}
$this->offsetSet('webmaster', $webmaster);
return $this;
}
/**
* How long in minutes a feed can be cached before refreshing
* Ignored if atom is used
*
* @param int $ttl
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setTtl($ttl)
{
Zend_Loader::loadClass('Zend_Validate_Int');
$validate = new Zend_Validate_Int();
if (!$validate->isValid($ttl)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property");
}
$this->offsetSet('ttl', $ttl);
return $this;
}
/**
* PICS rating for the feed
* Ignored if atom is used
*
* @param string $rating
* @return Zend_Feed_Builder_Header
*/
public function setRating($rating)
{
$this->offsetSet('rating', $rating);
return $this;
}
/**
* Cloud to be notified of updates of the feed
* Ignored if atom is used
*
* @param string|Zend_Uri_Http $uri
* @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify
* @param string $protocol protocol to use, e.g. soap or xml-rpc
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setCloud($uri, $procedure, $protocol)
{
if (is_string($uri) && Zend_Uri_Http::check($uri)) {
$uri = Zend_Uri::factory($uri);
}
if (!$uri instanceof Zend_Uri_Http) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
}
if (!$uri->getPort()) {
$uri->setPort(80);
}
$this->offsetSet('cloud', array('uri' => $uri,
'procedure' => $procedure,
'protocol' => $protocol));
return $this;
}
/**
* A text input box that can be displayed with the feed
* Ignored if atom is used
*
* @param string $title the label of the Submit button in the text input area
* @param string $description explains the text input area
* @param string $name the name of the text object in the text input area
* @param string $link the URL of the CGI script that processes text input requests
* @return Zend_Feed_Builder_Header
*/
public function setTextInput($title, $description, $name, $link)
{
$this->offsetSet('textInput', array('title' => $title,
'description' => $description,
'name' => $name,
'link' => $link));
return $this;
}
/**
* Hint telling aggregators which hours they can skip
* Ignored if atom is used
*
* @param array $hours list of hours in 24 format
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setSkipHours(array $hours)
{
if (count($hours) > 24) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property");
}
foreach ($hours as $hour) {
if ($hour < 0 || $hour > 23) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23");
}
}
$this->offsetSet('skipHours', $hours);
return $this;
}
/**
* Hint telling aggregators which days they can skip
* Ignored if atom is used
*
* @param array $days list of days to skip, e.g. Monday
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setSkipDays(array $days)
{
if (count($days) > 7) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property");
}
$valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
foreach ($days as $day) {
if (!in_array(strtolower($day), $valid)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("$day is not a valid day");
}
}
$this->offsetSet('skipDays', $days);
return $this;
}
/**
* Sets the iTunes rss extension
*
* @param Zend_Feed_Builder_Header_Itunes $itunes
* @return Zend_Feed_Builder_Header
*/
public function setITunes(Zend_Feed_Builder_Header_Itunes $itunes)
{
$this->offsetSet('itunes', $itunes);
return $this;
}
}
PK pG[1Dd Feed/Builder/Exception.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
/**
* Zend_Feed_Builder exception class
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
}
PK pG[�Y0m/ / Feed/Builder/Interface.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Input feed data interface
*
* Classes implementing this interface can be passe to Zend_Feed::importBuilder
* as an input data source for the Zend_Feed construction
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Feed_Builder_Interface
{
/**
* Returns an instance of Zend_Feed_Builder_Header
* describing the header of the feed
*
* @return Zend_Feed_Builder_Header
*/
public function getHeader();
/**
* Returns an array of Zend_Feed_Builder_Entry instances
* describing the entries of the feed
*
* @return array of Zend_Feed_Builder_Entry
*/
public function getEntries();
}
PK pG[��/�Z Z Feed/Builder/Header/Itunes.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Itunes.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* ITunes rss extension
*
* Classes used to describe the itunes channel extension
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Constructor
*
* @param array $categories Categories columns and in iTunes Music Store Browse
* @return void
*/
public function __construct(array $categories)
{
$this->setCategories($categories);
}
/**
* Sets the categories column and in iTunes Music Store Browse
* $categories must conform to the following format:
* <code>
* array(array('main' => 'main category',
* 'sub' => 'sub category' // optionnal
* ),
* // up to 3 rows
* )
* </code>
*
* @param array $categories
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setCategories(array $categories)
{
$nb = count($categories);
if (0 === $nb) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set at least one itunes category");
}
if ($nb > 3) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set at most three itunes categories");
}
foreach ($categories as $i => $category) {
if (empty($category['main'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set the main category (category #$i)");
}
}
$this->offsetSet('category', $categories);
return $this;
}
/**
* Sets the artist value, default to the feed's author value
*
* @param string $author
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setAuthor($author)
{
$this->offsetSet('author', $author);
return $this;
}
/**
* Sets the owner of the postcast
*
* @param string $name default to the feed's author value
* @param string $email default to the feed's email value
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setOwner($name = '', $email = '')
{
if (!empty($email)) {
Zend_Loader::loadClass('Zend_Validate_EmailAddress');
$validate = new Zend_Validate_EmailAddress();
if (!$validate->isValid($email)) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the itunes owner's email property");
}
}
$this->offsetSet('owner', array('name' => $name, 'email' => $email));
return $this;
}
/**
* Sets the album/podcast art picture
* Default to the feed's image value
*
* @param string $image
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setImage($image)
{
$this->offsetSet('image', $image);
return $this;
}
/**
* Sets the short description of the podcast
* Default to the feed's description
*
* @param string $subtitle
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setSubtitle($subtitle)
{
$this->offsetSet('subtitle', $subtitle);
return $this;
}
/**
* Sets the longer description of the podcast
* Default to the feed's description
*
* @param string $summary
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setSummary($summary)
{
$this->offsetSet('summary', $summary);
return $this;
}
/**
* Prevent a feed from appearing
*
* @param string $block can be 'yes' or 'no'
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setBlock($block)
{
$block = strtolower($block);
if (!in_array($block, array('yes', 'no'))) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
}
$this->offsetSet('block', $block);
return $this;
}
/**
* Configuration of the parental advisory graphic
*
* @param string $explicit can be 'yes', 'no' or 'clean'
* @return Zend_Feed_Builder_Header_Itunes
* @throws Zend_Feed_Builder_Exception
*/
public function setExplicit($explicit)
{
$explicit = strtolower($explicit);
if (!in_array($explicit, array('yes', 'no', 'clean'))) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to set yes, no or clean to the itunes explicit property");
}
$this->offsetSet('explicit', $explicit);
return $this;
}
/**
* Sets a comma separated list of 12 keywords maximum
*
* @param string $keywords
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setKeywords($keywords)
{
$this->offsetSet('keywords', $keywords);
return $this;
}
/**
* Sets the new feed URL location
*
* @param string $url
* @return Zend_Feed_Builder_Header_Itunes
*/
public function setNewFeedUrl($url)
{
$this->offsetSet('new_feed_url', $url);
return $this;
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
}PK pG[D_v(� � Feed/Builder/Entry.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Entry.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* An entry of a custom build feed
*
* Classes implementing the Zend_Feed_Builder_Interface interface
* uses this class to describe an entry of a feed
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Create a new builder entry
*
* @param string $title
* @param string $link
* @param string $description short version of the entry, no html
* @return void
*/
public function __construct($title, $link, $description)
{
$this->offsetSet('title', $title);
$this->offsetSet('link', $link);
$this->offsetSet('description', $description);
$this->setLastUpdate(time());
}
/**
* Read only properties accessor
*
* @param string $name property to read
* @return mixed
*/
public function __get($name)
{
if (!$this->offsetExists($name)) {
return NULL;
}
return $this->offsetGet($name);
}
/**
* Write properties accessor
*
* @param string $name name of the property to set
* @param mixed $value value to set
* @return void
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
/**
* Isset accessor
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* Unset accessor
*
* @param string $key
* @return void
*/
public function __unset($key)
{
if ($this->offsetExists($key)) {
$this->offsetUnset($key);
}
}
/**
* Sets the id/guid of the entry
*
* @param string $id
* @return Zend_Feed_Builder_Entry
*/
public function setId($id)
{
$this->offsetSet('guid', $id);
return $this;
}
/**
* Sets the full html content of the entry
*
* @param string $content
* @return Zend_Feed_Builder_Entry
*/
public function setContent($content)
{
$this->offsetSet('content', $content);
return $this;
}
/**
* Timestamp of the update date
*
* @param int $lastUpdate
* @return Zend_Feed_Builder_Entry
*/
public function setLastUpdate($lastUpdate)
{
$this->offsetSet('lastUpdate', $lastUpdate);
return $this;
}
/**
* Sets the url of the commented page associated to the entry
*
* @param string $comments
* @return Zend_Feed_Builder_Entry
*/
public function setCommentsUrl($comments)
{
$this->offsetSet('comments', $comments);
return $this;
}
/**
* Sets the url of the comments feed link
*
* @param string $commentRss
* @return Zend_Feed_Builder_Entry
*/
public function setCommentsRssUrl($commentRss)
{
$this->offsetSet('commentRss', $commentRss);
return $this;
}
/**
* Defines a reference to the original source
*
* @param string $title
* @param string $url
* @return Zend_Feed_Builder_Entry
*/
public function setSource($title, $url)
{
$this->offsetSet('source', array('title' => $title,
'url' => $url));
return $this;
}
/**
* Sets the categories of the entry
* Format of the array:
* <code>
* array(
* array(
* 'term' => 'first category label',
* 'scheme' => 'url that identifies a categorization scheme' // optional
* ),
* // second category and so one
* )
* </code>
*
* @param array $categories
* @return Zend_Feed_Builder_Entry
*/
public function setCategories(array $categories)
{
foreach ($categories as $category) {
$this->addCategory($category);
}
return $this;
}
/**
* Add a category to the entry
*
* @param array $category see Zend_Feed_Builder_Entry::setCategories() for format
* @return Zend_Feed_Builder_Entry
* @throws Zend_Feed_Builder_Exception
*/
public function addCategory(array $category)
{
if (empty($category['term'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to define the name of the category");
}
if (!$this->offsetExists('category')) {
$categories = array($category);
} else {
$categories = $this->offsetGet('category');
$categories[] = $category;
}
$this->offsetSet('category', $categories);
return $this;
}
/**
* Sets the enclosures of the entry
* Format of the array:
* <code>
* array(
* array(
* 'url' => 'url of the linked enclosure',
* 'type' => 'mime type of the enclosure' // optional
* 'length' => 'length of the linked content in octets' // optional
* ),
* // second enclosure and so one
* )
* </code>
*
* @param array $enclosures
* @return Zend_Feed_Builder_Entry
* @throws Zend_Feed_Builder_Exception
*/
public function setEnclosures(array $enclosures)
{
foreach ($enclosures as $enclosure) {
if (empty($enclosure['url'])) {
/**
* @see Zend_Feed_Builder_Exception
*/
require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception("you have to supply an url for your enclosure");
}
$type = isset($enclosure['type']) ? $enclosure['type'] : '';
$length = isset($enclosure['length']) ? $enclosure['length'] : '';
$this->addEnclosure($enclosure['url'], $type, $length);
}
return $this;
}
/**
* Add an enclosure to the entry
*
* @param string $url
* @param string $type
* @param string $length
* @return Zend_Feed_Builder_Entry
*/
public function addEnclosure($url, $type = '', $length = '')
{
if (!$this->offsetExists('enclosure')) {
$enclosure = array();
} else {
$enclosure = $this->offsetGet('enclosure');
}
$enclosure[] = array('url' => $url,
'type' => $type,
'length' => $length);
$this->offsetSet('enclosure', $enclosure);
return $this;
}
}
PK pG[��, �, Feed/Element.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Element.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Wraps a DOMElement allowing for SimpleXML-like access to attributes.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* @var DOMElement
*/
protected $_element;
/**
* @var Zend_Feed_Element
*/
protected $_parentElement;
/**
* @var boolean
*/
protected $_appended = true;
/**
* Zend_Feed_Element constructor.
*
* @param DOMElement $element The DOM element we're encapsulating.
* @return void
*/
public function __construct($element = null)
{
$this->_element = $element;
}
/**
* Get a DOM representation of the element
*
* Returns the underlying DOM object, which can then be
* manipulated with full DOM methods.
*
* @return DOMDocument
*/
public function getDOM()
{
return $this->_element;
}
/**
* Update the object from a DOM element
*
* Take a DOMElement object, which may be originally from a call
* to getDOM() or may be custom created, and use it as the
* DOM tree for this Zend_Feed_Element.
*
* @param DOMElement $element
* @return void
*/
public function setDOM(DOMElement $element)
{
$this->_element = $this->_element->ownerDocument->importNode($element, true);
}
/**
* Set the parent element of this object to another
* Zend_Feed_Element.
*
* @param Zend_Feed_Element $element
* @return void
*/
public function setParent(Zend_Feed_Element $element)
{
$this->_parentElement = $element;
$this->_appended = false;
}
/**
* Appends this element to its parent if necessary.
*
* @return void
*/
protected function ensureAppended()
{
if (!$this->_appended) {
$this->_parentElement->getDOM()->appendChild($this->_element);
$this->_appended = true;
$this->_parentElement->ensureAppended();
}
}
/**
* Get an XML string representation of this element
*
* Returns a string of this element's XML, including the XML
* prologue.
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$doc->appendChild($doc->importNode($this->_element, true));
return $doc->saveXML();
}
/**
* Get the XML for only this element
*
* Returns a string of this element's XML without prologue.
*
* @return string
*/
public function saveXmlFragment()
{
return $this->_element->ownerDocument->saveXML($this->_element);
}
/**
* Map variable access onto the underlying entry representation.
*
* Get-style access returns a Zend_Feed_Element representing the
* child element accessed. To get string values, use method syntax
* with the __call() overriding.
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
$nodes = $this->_children($var);
$length = count($nodes);
if ($length == 1) {
return new Zend_Feed_Element($nodes[0]);
} elseif ($length > 1) {
return array_map(create_function('$e', 'return new Zend_Feed_Element($e);'), $nodes);
} else {
// When creating anonymous nodes for __set chaining, don't
// call appendChild() on them. Instead we pass the current
// element to them as an extra reference; the child is
// then responsible for appending itself when it is
// actually set. This way "if ($foo->bar)" doesn't create
// a phantom "bar" element in our tree.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
$node = $this->_element->ownerDocument->createElementNS(Zend_Feed::lookupNamespace($ns), $elt);
} else {
$node = $this->_element->ownerDocument->createElement($var);
}
$node = new self($node);
$node->setParent($this);
return $node;
}
}
/**
* Map variable sets onto the underlying entry representation.
*
* @param string $var The property to change.
* @param string $val The property's new value.
* @return void
* @throws Zend_Feed_Exception
*/
public function __set($var, $val)
{
$this->ensureAppended();
$nodes = $this->_children($var);
if (!$nodes) {
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
$node = $this->_element->ownerDocument->createElementNS(Zend_Feed::lookupNamespace($ns), $var, $val);
$this->_element->appendChild($node);
} else {
$node = $this->_element->ownerDocument->createElement($var, $val);
$this->_element->appendChild($node);
}
} elseif (count($nodes) > 1) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot set the value of multiple tags simultaneously.');
} else {
$nodes[0]->nodeValue = $val;
}
}
/**
* Map isset calls onto the underlying entry representation.
*
* @param string $var
* @return boolean
*/
public function __isset($var)
{
// Look for access of the form {ns:var}. We don't use
// _children() here because we can break out of the loop
// immediately once we find something.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
return true;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
return true;
}
}
}
}
/**
* Get the value of an element with method syntax.
*
* Map method calls to get the string value of the requested
* element. If there are multiple elements that match, this will
* return an array of those objects.
*
* @param string $var The element to get the string value of.
* @param mixed $unused This parameter is not used.
* @return mixed The node's value, null, or an array of nodes.
*/
public function __call($var, $unused)
{
$nodes = $this->_children($var);
if (!$nodes) {
return null;
} elseif (count($nodes) > 1) {
return $nodes;
} else {
return $nodes[0]->nodeValue;
}
}
/**
* Remove all children matching $var.
*
* @param string $var
* @return void
*/
public function __unset($var)
{
$nodes = $this->_children($var);
foreach ($nodes as $node) {
$parent = $node->parentNode;
$parent->removeChild($node);
}
}
/**
* Returns the nodeValue of this element when this object is used
* in a string context.
*
* @return string
*/
public function __toString()
{
return $this->_element->nodeValue;
}
/**
* Finds children with tagnames matching $var
*
* Similar to SimpleXML's children() method.
*
* @param string $var Tagname to match, can be either namespace:tagName or just tagName.
* @return array
*/
protected function _children($var)
{
$found = array();
// Look for access of the form {ns:var}.
if (strpos($var, ':') !== false) {
list($ns, $elt) = explode(':', $var, 2);
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $elt && $child->prefix == $ns) {
$found[] = $child;
}
}
} else {
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $var) {
$found[] = $child;
}
}
}
return $found;
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return boolean
*/
public function offsetExists($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->hasAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->hasAttribute($offset);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return string
*/
public function offsetGet($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->getAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->getAttribute($offset);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @param string $value
* @return string
*/
public function offsetSet($offset, $value)
{
$this->ensureAppended();
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->setAttributeNS(Zend_Feed::lookupNamespace($ns), $attr, $value);
} else {
return $this->_element->setAttribute($offset, $value);
}
}
/**
* Required by the ArrayAccess interface.
*
* @param string $offset
* @return boolean
*/
public function offsetUnset($offset)
{
if (strpos($offset, ':') !== false) {
list($ns, $attr) = explode(':', $offset, 2);
return $this->_element->removeAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
} else {
return $this->_element->removeAttribute($offset);
}
}
}
PK pG[�N�t�5 �5
Feed/Atom.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Atom.php 11654 2008-10-03 16:03:35Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Feed_Abstract
*/
require_once 'Zend/Feed/Abstract.php';
/**
* @see Zend_Feed_Entry_Atom
*/
require_once 'Zend/Feed/Entry/Atom.php';
/**
* Atom feed class
*
* The Zend_Feed_Atom class is a concrete subclass of the general
* Zend_Feed_Abstract class, tailored for representing an Atom
* feed. It shares all of the same methods with its abstract
* parent. The distinction is made in the format of data that
* Zend_Feed_Atom expects, and as a further pointer for users as to
* what kind of feed object they have been passed.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Feed_Entry_Atom';
/**
* The element name for individual feed elements (Atom <entry>
* elements).
*
* @var string
*/
protected $_entryElementName = 'entry';
/**
* The default namespace for Atom feeds.
*
* @var string
*/
protected $_defaultNamespace = 'atom';
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base feed element and create an alias to it.
$element = $this->_element->getElementsByTagName('feed')->item(0);
if (!$element) {
// Try to find a single <entry> instead.
$element = $this->_element->getElementsByTagName($this->_entryElementName)->item(0);
if (!$element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <feed> or <' . $this->_entryElementName
. '> element found, cannot parse feed.');
}
$doc = new DOMDocument($this->_element->version,
$this->_element->actualEncoding);
$feed = $doc->appendChild($doc->createElement('feed'));
$feed->appendChild($doc->importNode($element, true));
$element = $feed;
}
$this->_element = $element;
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
/**
* Easy access to <link> tags keyed by "rel" attributes.
*
* If $elt->link() is called with no arguments, we will attempt to
* return the value of the <link> tag(s) like all other
* method-syntax attribute access. If an argument is passed to
* link(), however, then we will return the "href" value of the
* first <link> tag that has a "rel" attribute matching $rel:
*
* $elt->link(): returns the value of the link tag.
* $elt->link('self'): returns the href from the first <link rel="self"> in the entry.
*
* @param string $rel The "rel" attribute to look for.
* @return mixed
*/
public function link($rel = null)
{
if ($rel === null) {
return parent::__call('link', null);
}
// index link tags by their "rel" attribute.
$links = parent::__get('link');
if (!is_array($links)) {
if ($links instanceof Zend_Feed_Element) {
$links = array($links);
} else {
return $links;
}
}
foreach ($links as $link) {
if (empty($link['rel'])) {
continue;
}
if ($rel == $link['rel']) {
return $link['href'];
}
}
return null;
}
/**
* Make accessing some individual elements of the feed easier.
*
* Special accessors 'entry' and 'entries' are provided so that if
* you wish to iterate over an Atom feed's entries, you can do so
* using foreach ($feed->entries as $entry) or foreach
* ($feed->entry as $entry).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'entry':
// fall through to the next case
case 'entries':
return $this;
default:
return parent::__get($var);
}
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
protected function _mapFeedHeaders($array)
{
$feed = $this->_element->createElement('feed');
$feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$id = $this->_element->createElement('id', $array->link);
$feed->appendChild($id);
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($array->title));
$feed->appendChild($title);
if (isset($array->author)) {
$author = $this->_element->createElement('author');
$name = $this->_element->createElement('name', $array->author);
$author->appendChild($name);
if (isset($array->email)) {
$email = $this->_element->createElement('email', $array->email);
$author->appendChild($email);
}
$feed->appendChild($author);
}
$updated = isset($array->lastUpdate) ? $array->lastUpdate : time();
$updated = $this->_element->createElement('updated', date(DATE_ATOM, $updated));
$feed->appendChild($updated);
if (isset($array->published)) {
$published = $this->_element->createElement('published', date(DATE_ATOM, $array->published));
$feed->appendChild($published);
}
$link = $this->_element->createElement('link');
$link->setAttribute('rel', 'self');
$link->setAttribute('href', $array->link);
if (isset($array->language)) {
$link->setAttribute('hreflang', $array->language);
}
$feed->appendChild($link);
if (isset($array->description)) {
$subtitle = $this->_element->createElement('subtitle');
$subtitle->appendChild($this->_element->createCDATASection($array->description));
$feed->appendChild($subtitle);
}
if (isset($array->copyright)) {
$copyright = $this->_element->createElement('rights', $array->copyright);
$feed->appendChild($copyright);
}
if (isset($array->image)) {
$image = $this->_element->createElement('logo', $array->image);
$feed->appendChild($image);
}
$generator = !empty($array->generator) ? $array->generator : 'Zend_Feed';
$generator = $this->_element->createElement('generator', $generator);
$feed->appendChild($generator);
return $feed;
}
/**
* Generate the entries of the feed when working in write mode
*
* The following nodes are constructed for each feed entry
* <entry>
* <id>url to feed entry</id>
* <title>entry title</title>
* <updated>last update</updated>
* <link rel="alternate" href="url to feed entry" />
* <summary>short text</summary>
* <content>long version, can contain html</content>
* </entry>
*
* @param array $array the data to use
* @param DOMElement $root the root node to use
* @return void
*/
protected function _mapFeedEntries(DOMElement $root, $array)
{
foreach ($array as $dataentry) {
$entry = $this->_element->createElement('entry');
$id = $this->_element->createElement('id', isset($dataentry->guid) ? $dataentry->guid : $dataentry->link);
$entry->appendChild($id);
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($dataentry->title));
$entry->appendChild($title);
$updated = isset($dataentry->lastUpdate) ? $dataentry->lastUpdate : time();
$updated = $this->_element->createElement('updated', date(DATE_ATOM, $updated));
$entry->appendChild($updated);
$link = $this->_element->createElement('link');
$link->setAttribute('rel', 'alternate');
$link->setAttribute('href', $dataentry->link);
$entry->appendChild($link);
$summary = $this->_element->createElement('summary');
$summary->appendChild($this->_element->createCDATASection($dataentry->description));
$entry->appendChild($summary);
if (isset($dataentry->content)) {
$content = $this->_element->createElement('content');
$content->setAttribute('type', 'html');
$content->appendChild($this->_element->createCDATASection($dataentry->content));
$entry->appendChild($content);
}
if (isset($dataentry->category)) {
foreach ($dataentry->category as $category) {
$node = $this->_element->createElement('category');
$node->setAttribute('term', $category['term']);
if (isset($category['scheme'])) {
$node->setAttribute('scheme', $category['scheme']);
}
$entry->appendChild($node);
}
}
if (isset($dataentry->source)) {
$source = $this->_element->createElement('source');
$title = $this->_element->createElement('title', $dataentry->source['title']);
$source->appendChild($title);
$link = $this->_element->createElement('link', $dataentry->source['title']);
$link->setAttribute('rel', 'alternate');
$link->setAttribute('href', $dataentry->source['url']);
$source->appendChild($link);
}
if (isset($dataentry->enclosure)) {
foreach ($dataentry->enclosure as $enclosure) {
$node = $this->_element->createElement('link');
$node->setAttribute('rel', 'enclosure');
$node->setAttribute('href', $enclosure['url']);
if (isset($enclosure['type'])) {
$node->setAttribute('type', $enclosure['type']);
}
if (isset($enclosure['length'])) {
$node->setAttribute('length', $enclosure['length']);
}
$entry->appendChild($node);
}
}
if (isset($dataentry->comments)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:comment',
$dataentry->comments);
$entry->appendChild($comments);
}
if (isset($dataentry->commentRss)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:commentRss',
$dataentry->commentRss);
$entry->appendChild($comments);
}
$root->appendChild($entry);
}
}
/**
* Override Zend_Feed_Element to allow formated feeds
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$doc->appendChild($doc->importNode($this->_element, true));
$doc->formatOutput = true;
return $doc->saveXML();
}
/**
* Send feed to a http client with the correct header
*
* @return void
* @throws Zend_Feed_Exception if headers have already been sent
*/
public function send()
{
if (headers_sent()) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot send ATOM because headers have already been sent.');
}
header('Content-Type: application/atom+xml; charset=' . $this->_element->ownerDocument->actualEncoding);
echo $this->saveXML();
}
}
PK pG[�h�5� � Feed/Abstract.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 12507 2008-11-10 16:29:09Z matthew $
*/
/**
* @see Zend_Feed_Element
*/
require_once 'Zend/Feed/Element.php';
/**
* The Zend_Feed_Abstract class is an abstract class representing feeds.
*
* Zend_Feed_Abstract implements two core PHP 5 interfaces: ArrayAccess and
* Iterator. In both cases the collection being treated as an array is
* considered to be the entry collection, such that iterating over the
* feed takes you through each of the feed.s entries.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* Current index on the collection of feed entries for the
* Iterator implementation.
*
* @var integer
*/
protected $_entryIndex = 0;
/**
* Cache of feed entries.
*
* @var array
*/
protected $_entries;
/**
* Feed constructor
*
* The Zend_Feed_Abstract constructor takes the URI of a feed or a
* feed represented as a string and loads it as XML.
*
* @param string $uri The full URI of the feed to load, or NULL if not retrieved via HTTP or as an array.
* @param string $string The feed as a string, or NULL if retrieved via HTTP or as an array.
* @param Zend_Feed_Builder_Interface $builder The feed as a builder instance or NULL if retrieved as a string or via HTTP.
* @return void
* @throws Zend_Feed_Exception If loading the feed failed.
*/
public function __construct($uri = null, $string = null, Zend_Feed_Builder_Interface $builder = null)
{
if ($uri !== null) {
// Retrieve the feed via HTTP
$client = Zend_Feed::getHttpClient();
$client->setUri($uri);
$response = $client->request('GET');
if ($response->getStatus() !== 200) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
}
$this->_element = $response->getBody();
$this->__wakeup();
} elseif ($string !== null) {
// Retrieve the feed from $string
$this->_element = $string;
$this->__wakeup();
} else {
// Generate the feed from the array
$header = $builder->getHeader();
$this->_element = new DOMDocument('1.0', $header['charset']);
$root = $this->_mapFeedHeaders($header);
$this->_mapFeedEntries($root, $builder->getEntries());
$this->_element = $root;
$this->_buildEntryCache();
}
}
/**
* Load the feed as an XML DOMDocument object
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
@ini_set('track_errors', 1);
$doc = new DOMDocument;
$status = @$doc->loadXML($this->_element);
@ini_restore('track_errors');
if (!$status) {
// prevent the class to generate an undefined variable notice (ZF-2590)
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
}
$this->_element = $doc;
}
/**
* Prepare for serialiation
*
* @return array
*/
public function __sleep()
{
$this->_element = $this->saveXML();
return array('_element');
}
/**
* Cache the individual feed elements so they don't need to be
* searched for on every operation.
*
* @return void
*/
protected function _buildEntryCache()
{
$this->_entries = array();
foreach ($this->_element->childNodes as $child) {
if ($child->localName == $this->_entryElementName) {
$this->_entries[] = $child;
}
}
}
/**
* Get the number of entries in this feed object.
*
* @return integer Entry count.
*/
public function count()
{
return count($this->_entries);
}
/**
* Required by the Iterator interface.
*
* @return void
*/
public function rewind()
{
$this->_entryIndex = 0;
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row, or null if no rows.
*/
public function current()
{
return new $this->_entryClassName(
null,
$this->_entries[$this->_entryIndex]);
}
/**
* Required by the Iterator interface.
*
* @return mixed The current row number (starts at 0), or NULL if no rows
*/
public function key()
{
return $this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return mixed The next row, or null if no more rows.
*/
public function next()
{
++$this->_entryIndex;
}
/**
* Required by the Iterator interface.
*
* @return boolean Whether the iteration is valid
*/
public function valid()
{
return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count();
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
abstract protected function _mapFeedHeaders($array);
/**
* Generate the entries of the feed when working in write mode
*
* @param DOMElement $root the root node to use
* @param array $array the data to use
* @return DOMElement root node
*/
abstract protected function _mapFeedEntries(DOMElement $root, $array);
/**
* Send feed to a http client with the correct header
*
* @throws Zend_Feed_Exception if headers have already been sent
* @return void
*/
abstract public function send();
}
PK pG[��$�J �J Feed/Rss.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rss.php 11654 2008-10-03 16:03:35Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Feed_Abstract
*/
require_once 'Zend/Feed/Abstract.php';
/**
* @see Zend_Feed_Entry_Rss
*/
require_once 'Zend/Feed/Entry/Rss.php';
/**
* RSS channel class
*
* The Zend_Feed_Rss class is a concrete subclass of
* Zend_Feed_Abstract meant for representing RSS channels. It does not
* add any methods to its parent, just provides a classname to check
* against with the instanceof operator, and expects to be handling
* RSS-formatted data instead of Atom.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{
/**
* The classname for individual channel elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Feed_Entry_Rss';
/**
* The element name for individual channel elements (RSS <item>s).
*
* @var string
*/
protected $_entryElementName = 'item';
/**
* The default namespace for RSS channels.
*
* @var string
*/
protected $_defaultNamespace = 'rss';
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*
* @return void
* @throws Zend_Feed_Exception
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base channel element and create an alias to it.
$this->_element = $this->_element->getElementsByTagName('channel')->item(0);
if (!$this->_element) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <channel> element found, cannot parse channel.');
}
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
/**
* Make accessing some individual elements of the channel easier.
*
* Special accessors 'item' and 'items' are provided so that if
* you wish to iterate over an RSS channel's items, you can do so
* using foreach ($channel->items as $item) or foreach
* ($channel->item as $item).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'item':
// fall through to the next case
case 'items':
return $this;
default:
return parent::__get($var);
}
}
/**
* Generate the header of the feed when working in write mode
*
* @param array $array the data to use
* @return DOMElement root node
*/
protected function _mapFeedHeaders($array)
{
$channel = $this->_element->createElement('channel');
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($array->title));
$channel->appendChild($title);
$link = $this->_element->createElement('link', $array->link);
$channel->appendChild($link);
$desc = isset($array->description) ? $array->description : '';
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($desc));
$channel->appendChild($description);
$pubdate = isset($array->lastUpdate) ? $array->lastUpdate : time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r', $pubdate));
$channel->appendChild($pubdate);
if (isset($array->published)) {
$lastBuildDate = $this->_element->createElement('lastBuildDate', gmdate('r', $array->published));
}
$editor = '';
if (!empty($array->email)) {
$editor .= $array->email;
}
if (!empty($array->author)) {
$editor .= ' (' . $array->author . ')';
}
if (!empty($editor)) {
$author = $this->_element->createElement('managingEditor', ltrim($editor));
$channel->appendChild($author);
}
if (isset($array->webmaster)) {
$channel->appendChild($this->_element->createElement('webMaster', $array->webmaster));
}
if (!empty($array->copyright)) {
$copyright = $this->_element->createElement('copyright', $array->copyright);
$channel->appendChild($copyright);
}
if (!empty($array->image)) {
$image = $this->_element->createElement('image');
$url = $this->_element->createElement('url', $array->image);
$image->appendChild($url);
$imagetitle = $this->_element->createElement('title', $array->title);
$image->appendChild($imagetitle);
$imagelink = $this->_element->createElement('link', $array->link);
$image->appendChild($imagelink);
$channel->appendChild($image);
}
$generator = !empty($array->generator) ? $array->generator : 'Zend_Feed';
$generator = $this->_element->createElement('generator', $generator);
$channel->appendChild($generator);
if (!empty($array->language)) {
$language = $this->_element->createElement('language', $array->language);
$channel->appendChild($language);
}
$doc = $this->_element->createElement('docs', 'http://blogs.law.harvard.edu/tech/rss');
$channel->appendChild($doc);
if (isset($array->cloud)) {
$cloud = $this->_element->createElement('cloud');
$cloud->setAttribute('domain', $array->cloud['uri']->getHost());
$cloud->setAttribute('port', $array->cloud['uri']->getPort());
$cloud->setAttribute('path', $array->cloud['uri']->getPath());
$cloud->setAttribute('registerProcedure', $array->cloud['procedure']);
$cloud->setAttribute('protocol', $array->cloud['protocol']);
$channel->appendChild($cloud);
}
if (isset($array->rating)) {
$rating = $this->_element->createElement('rating', $array->rating);
$channel->appendChild($rating);
}
if (isset($array->textInput)) {
$textinput = $this->_element->createElement('textInput');
$textinput->appendChild($this->_element->createElement('title', $array->textInput['title']));
$textinput->appendChild($this->_element->createElement('description', $array->textInput['description']));
$textinput->appendChild($this->_element->createElement('name', $array->textInput['name']));
$textinput->appendChild($this->_element->createElement('link', $array->textInput['link']));
$channel->appendChild($textinput);
}
if (isset($array->skipHours)) {
$skipHours = $this->_element->createElement('skipHours');
foreach ($array->skipHours as $hour) {
$skipHours->appendChild($this->_element->createElement('hour', $hour));
}
$channel->appendChild($skipHours);
}
if (isset($array->skipDays)) {
$skipDays = $this->_element->createElement('skipDays');
foreach ($array->skipDays as $day) {
$skipDays->appendChild($this->_element->createElement('day', $day));
}
$channel->appendChild($skipDays);
}
if (isset($array->itunes)) {
$this->_buildiTunes($channel, $array);
}
return $channel;
}
/**
* Adds the iTunes extensions to a root node
*
* @param DOMElement $root
* @param array $array
* @return void
*/
private function _buildiTunes(DOMElement $root, $array)
{
/* author node */
$author = '';
if (isset($array->itunes->author)) {
$author = $array->itunes->author;
} elseif (isset($array->author)) {
$author = $array->author;
}
if (!empty($author)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:author', $author);
$root->appendChild($node);
}
/* owner node */
$author = '';
$email = '';
if (isset($array->itunes->owner)) {
if (isset($array->itunes->owner['name'])) {
$author = $array->itunes->owner['name'];
}
if (isset($array->itunes->owner['email'])) {
$email = $array->itunes->owner['email'];
}
}
if (empty($author) && isset($array->author)) {
$author = $array->author;
}
if (empty($email) && isset($array->email)) {
$email = $array->email;
}
if (!empty($author) || !empty($email)) {
$owner = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:owner');
if (!empty($author)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:name', $author);
$owner->appendChild($node);
}
if (!empty($email)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:email', $email);
$owner->appendChild($node);
}
$root->appendChild($owner);
}
$image = '';
if (isset($array->itunes->image)) {
$image = $array->itunes->image;
} elseif (isset($array->image)) {
$image = $array->image;
}
if (!empty($image)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:image');
$node->setAttribute('href', $image);
$root->appendChild($node);
}
$subtitle = '';
if (isset($array->itunes->subtitle)) {
$subtitle = $array->itunes->subtitle;
} elseif (isset($array->description)) {
$subtitle = $array->description;
}
if (!empty($subtitle)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:subtitle', $subtitle);
$root->appendChild($node);
}
$summary = '';
if (isset($array->itunes->summary)) {
$summary = $array->itunes->summary;
} elseif (isset($array->description)) {
$summary = $array->description;
}
if (!empty($summary)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:summary', $summary);
$root->appendChild($node);
}
if (isset($array->itunes->block)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:block', $array->itunes->block);
$root->appendChild($node);
}
if (isset($array->itunes->explicit)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:explicit', $array->itunes->explicit);
$root->appendChild($node);
}
if (isset($array->itunes->keywords)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:keywords', $array->itunes->keywords);
$root->appendChild($node);
}
if (isset($array->itunes->new_feed_url)) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:new-feed-url', $array->itunes->new_feed_url);
$root->appendChild($node);
}
if (isset($array->itunes->category)) {
foreach ($array->itunes->category as $i => $category) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$node->setAttribute('text', $category['main']);
$root->appendChild($node);
$add_end_category = false;
if (!empty($category['sub'])) {
$add_end_category = true;
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$node->setAttribute('text', $category['sub']);
$root->appendChild($node);
}
if ($i > 0 || $add_end_category) {
$node = $this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd', 'itunes:category');
$root->appendChild($node);
}
}
}
}
/**
* Generate the entries of the feed when working in write mode
*
* The following nodes are constructed for each feed entry
* <item>
* <title>entry title</title>
* <link>url to feed entry</link>
* <guid>url to feed entry</guid>
* <description>short text</description>
* <content:encoded>long version, can contain html</content:encoded>
* </item>
*
* @param DOMElement $root the root node to use
* @param array $array the data to use
* @return void
*/
protected function _mapFeedEntries(DOMElement $root, $array)
{
Zend_Feed::registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
foreach ($array as $dataentry) {
$item = $this->_element->createElement('item');
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($dataentry->title));
$item->appendChild($title);
$link = $this->_element->createElement('link', $dataentry->link);
$item->appendChild($link);
if (isset($dataentry->guid)) {
$guid = $this->_element->createElement('guid', $dataentry->guid);
$item->appendChild($guid);
}
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($dataentry->description));
$item->appendChild($description);
if (isset($dataentry->content)) {
$content = $this->_element->createElement('content:encoded');
$content->appendChild($this->_element->createCDATASection($dataentry->content));
$item->appendChild($content);
}
$pubdate = isset($dataentry->lastUpdate) ? $dataentry->lastUpdate : time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r', $pubdate));
$item->appendChild($pubdate);
if (isset($dataentry->category)) {
foreach ($dataentry->category as $category) {
$node = $this->_element->createElement('category', $category['term']);
if (isset($category['scheme'])) {
$node->setAttribute('domain', $category['scheme']);
}
$item->appendChild($node);
}
}
if (isset($dataentry->source)) {
$source = $this->_element->createElement('source', $dataentry->source['title']);
$source->setAttribute('url', $dataentry->source['url']);
$item->appendChild($source);
}
if (isset($dataentry->comments)) {
$comments = $this->_element->createElement('comments', $dataentry->comments);
$item->appendChild($comments);
}
if (isset($dataentry->commentRss)) {
$comments = $this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:commentRss',
$dataentry->commentRss);
$item->appendChild($comments);
}
if (isset($dataentry->enclosure)) {
foreach ($dataentry->enclosure as $enclosure) {
$node = $this->_element->createElement('enclosure');
$node->setAttribute('url', $enclosure['url']);
if (isset($enclosure['type'])) {
$node->setAttribute('type', $enclosure['type']);
}
if (isset($enclosure['length'])) {
$node->setAttribute('length', $enclosure['length']);
}
$item->appendChild($node);
}
}
$root->appendChild($item);
}
}
/**
* Override Zend_Feed_Element to include <rss> root node
*
* @return string
*/
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$root = $doc->createElement('rss');
// Use rss version 2.0
$root->setAttribute('version', '2.0');
// Content namespace
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:content', 'http://purl.org/rss/1.0/modules/content/');
$root->appendChild($doc->importNode($this->_element, true));
// Append root node
$doc->appendChild($root);
// Format output
$doc->formatOutput = true;
return $doc->saveXML();
}
/**
* Send feed to a http client with the correct header
*
* @return void
* @throws Zend_Feed_Exception if headers have already been sent
*/
public function send()
{
if (headers_sent()) {
/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot send RSS because headers have already been sent.');
}
header('Content-Type: application/rss+xml; charset=' . $this->_element->ownerDocument->actualEncoding);
echo $this->saveXml();
}
}
PK pG[nJ�� � Feed/Exception.phpnu &1i� <?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* Feed exceptions
*
* Class to represent exceptions that occur during Feed operations.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2008 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
{}
PK pG[F!�� � Date/DateObject.phpnu &1i� <?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_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: DateObject.php 13319 2008-12-16 09:27:04Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_DateObject
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Date_DateObject {
/**
* UNIX Timestamp
*/
private $_unixTimestamp;
protected static $_cache = null;
protected static $_defaultOffset = 0;
/**
* active timezone
*/
private $_timezone = 'UTC';
private $_offset = 0;
private $_syncronised = 0;
// turn off DST correction if UTC or GMT
protected $_dst = true;
/**
* Table of Monthdays
*/
private static $_monthTable = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
/**
* Table of Years
*/
private static $_yearTable = array(
1970 => 0, 1960 => -315619200, 1950 => -631152000,
1940 => -946771200, 1930 => -1262304000, 1920 => -1577923200,
1910 => -1893456000, 1900 => -2208988800, 1890 => -2524521600,
1880 => -2840140800, 1870 => -3155673600, 1860 => -3471292800,
1850 => -3786825600, 1840 => -4102444800, 1830 => -4417977600,
1820 => -4733596800, 1810 => -5049129600, 1800 => -5364662400,
1790 => -5680195200, 1780 => -5995814400, 1770 => -6311347200,
1760 => -6626966400, 1750 => -6942499200, 1740 => -7258118400,
1730 => -7573651200, 1720 => -7889270400, 1710 => -8204803200,
1700 => -8520336000, 1690 => -8835868800, 1680 => -9151488000,
1670 => -9467020800, 1660 => -9782640000, 1650 => -10098172800,
1640 => -10413792000, 1630 => -10729324800, 1620 => -11044944000,
1610 => -11360476800, 1600 => -11676096000);
/**
* Set this object to have a new UNIX timestamp.
*
* @param string|integer $timestamp OPTIONAL timestamp; defaults to local time using time()
* @return string|integer old timestamp
* @throws Zend_Date_Exception
*/
protected function setUnixTimestamp($timestamp = null)
{
$old = $this->_unixTimestamp;
if (is_numeric($timestamp)) {
$this->_unixTimestamp = $timestamp;
} else if ($timestamp === null) {
$this->_unixTimestamp = time();
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('\'' . $timestamp . '\' is not a valid UNIX timestamp', $timestamp);
}
return $old;
}
/**
* Returns this object's UNIX timestamp
* A timestamp greater then the integer range will be returned as string
* This function does not return the timestamp as object. Use copy() instead.
*
* @return integer|string timestamp
*/
protected function getUnixTimestamp()
{
if ($this->_unixTimestamp === intval($this->_unixTimestamp)) {
return (int) $this->_unixTimestamp;
} else {
return (string) $this->_unixTimestamp;
}
}
/**
* Internal function.
* Returns time(). This method exists to allow unit tests to work-around methods that might otherwise
* be hard-coded to use time(). For example, this makes it possible to test isYesterday() in Date.php.
*
* @param integer $sync OPTIONAL time syncronisation value
* @return integer timestamp
*/
protected function _getTime($sync = null)
{
if ($sync !== null) {
$this->_syncronised = round($sync);
}
return (time() + $this->_syncronised);
}
/**
* Internal mktime function used by Zend_Date.
* The timestamp returned by mktime() can exceed the precision of traditional UNIX timestamps,
* by allowing PHP to auto-convert to using a float value.
*
* Returns a timestamp relative to 1970/01/01 00:00:00 GMT/UTC.
* DST (Summer/Winter) is depriciated since php 5.1.0.
* Year has to be 4 digits otherwise it would be recognised as
* year 70 AD instead of 1970 AD as expected !!
*
* @param integer $hour
* @param integer $minute
* @param integer $second
* @param integer $month
* @param integer $day
* @param integer $year
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return integer|float timestamp (number of seconds elapsed relative to 1970/01/01 00:00:00 GMT/UTC)
*/
protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
{
// complete date but in 32bit timestamp - use PHP internal
if ((1901 < $year) and ($year < 2038)) {
$oldzone = @date_default_timezone_get();
// Timezone also includes DST settings, therefor substracting the GMT offset is not enough
// We have to set the correct timezone to get the right value
if (($this->_timezone != $oldzone) and ($gmt === false)) {
date_default_timezone_set($this->_timezone);
}
$result = ($gmt) ? @gmmktime($hour, $minute, $second, $month, $day, $year)
: @mktime($hour, $minute, $second, $month, $day, $year);
date_default_timezone_set($oldzone);
return $result;
}
if ($gmt !== true) {
$second += $this->_offset;
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_mkTime_' . $this->_offset . '_' . $year.$month.$day.'_'.$hour.$minute.$second . '_'.(int)$gmt, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
// date to integer
$day = intval($day);
$month = intval($month);
$year = intval($year);
// correct months > 12 and months < 1
if ($month > 12) {
$overlap = floor($month / 12);
$year += $overlap;
$month -= $overlap * 12;
} else {
$overlap = ceil((1 - $month) / 12);
$year -= $overlap;
$month += $overlap * 12;
}
$date = 0;
if ($year >= 1970) {
// Date is after UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1970; $count <= $year; $count++) {
$leapyear = self::isYearLeapYear($count);
if ($count < $year) {
$date += 365;
if ($leapyear === true) {
$date++;
}
} else {
for ($mcount = 0; $mcount < ($month - 1); $mcount++) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += $day - 1;
$date = (($date * 86400) + ($hour * 3600) + ($minute * 60) + $second);
} else {
// Date is before UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1969; $count >= $year; $count--) {
$leapyear = self::isYearLeapYear($count);
if ($count > $year)
{
$date += 365;
if ($leapyear === true)
$date++;
} else {
for ($mcount = 11; $mcount > ($month - 1); $mcount--) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += (self::$_monthTable[$month - 1] - $day);
$date = -(($date * 86400) + (86400 - (($hour * 3600) + ($minute * 60) + $second)));
// gregorian correction for 5.Oct.1582
if ($date < -12220185600) {
$date += 864000;
} else if ($date < -12219321600) {
$date = -12219321600;
}
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($date), $id);
}
return $date;
}
/**
* Returns true, if given $year is a leap year.
*
* @param integer $year
* @return boolean true, if year is leap year
*/
protected static function isYearLeapYear($year)
{
// all leapyears can be divided through 4
if (($year % 4) != 0) {
return false;
}
// all leapyears can be divided through 400
if ($year % 400 == 0) {
return true;
} else if (($year > 1582) and ($year % 100 == 0)) {
return false;
}
return true;
}
/**
* Internal mktime function used by Zend_Date for handling 64bit timestamps.
*
* Returns a formatted date for a given timestamp.
*
* @param string $format format for output
* @param mixed $timestamp
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return string
*/
protected function date($format, $timestamp = null, $gmt = false)
{
$oldzone = @date_default_timezone_get();
if ($this->_timezone != $oldzone) {
date_default_timezone_set($this->_timezone);
}
if ($timestamp === null) {
$result = ($gmt) ? @gmdate($format) : @date($format);
date_default_timezone_set($oldzone);
return $result;
}
if (abs($timestamp) <= 0x7FFFFFFF) {
$result = ($gmt) ? @gmdate($format, $timestamp) : @date($format, $timestamp);
date_default_timezone_set($oldzone);
return $result;
}
$jump = false;
if (isset(self::$_cache)) {
$idstamp = strtr('Zend_DateObject_date_' . $this->_offset . '_'. $timestamp . '_'.(int)$gmt, '-','_');
if ($result2 = self::$_cache->load($idstamp)) {
$timestamp = unserialize($result2);
$jump = true;
}
}
// check on false or null alone failes
if (empty($gmt) and empty($jump)) {
$tempstamp = $timestamp;
if ($tempstamp > 0) {
while (abs($tempstamp) > 0x7FFFFFFF) {
$tempstamp -= (86400 * 23376);
}
$dst = date("I", $tempstamp);
if ($dst === 1) {
$timestamp += 3600;
}
$temp = date('Z', $tempstamp);
$timestamp += $temp;
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($timestamp), $idstamp);
}
}
if (($timestamp < 0) and ($gmt !== true)) {
$timestamp -= $this->_offset;
}
date_default_timezone_set($oldzone);
$date = $this->getDateParts($timestamp, true);
$length = strlen($format);
$output = '';
for ($i = 0; $i < $length; $i++) {
switch($format[$i]) {
// day formats
case 'd': // day of month, 2 digits, with leading zero, 01 - 31
$output .= (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']);
break;
case 'D': // day of week, 3 letters, Mon - Sun
$output .= date('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'j': // day of month, without leading zero, 1 - 31
$output .= $date['mday'];
break;
case 'l': // day of week, full string name, Sunday - Saturday
$output .= date('l', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'N': // ISO 8601 numeric day of week, 1 - 7
$day = self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
if ($day == 0) {
$day = 7;
}
$output .= $day;
break;
case 'S': // english suffix for day of month, st nd rd th
if (($date['mday'] % 10) == 1) {
$output .= 'st';
} else if ((($date['mday'] % 10) == 2) and ($date['mday'] != 12)) {
$output .= 'nd';
} else if (($date['mday'] % 10) == 3) {
$output .= 'rd';
} else {
$output .= 'th';
}
break;
case 'w': // numeric day of week, 0 - 6
$output .= self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
break;
case 'z': // day of year, 0 - 365
$output .= $date['yday'];
break;
// week formats
case 'W': // ISO 8601, week number of year
$output .= $this->weekNumber($date['year'], $date['mon'], $date['mday']);
break;
// month formats
case 'F': // string month name, january - december
$output .= date('F', mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'm': // number of month, with leading zeros, 01 - 12
$output .= (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']);
break;
case 'M': // 3 letter month name, Jan - Dec
$output .= date('M',mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'n': // number of month, without leading zeros, 1 - 12
$output .= $date['mon'];
break;
case 't': // number of day in month
$output .= self::$_monthTable[$date['mon'] - 1];
break;
// year formats
case 'L': // is leap year ?
$output .= (self::isYearLeapYear($date['year'])) ? '1' : '0';
break;
case 'o': // ISO 8601 year number
$week = $this->weekNumber($date['year'], $date['mon'], $date['mday']);
if (($week > 50) and ($date['mon'] == 1)) {
$output .= ($date['year'] - 1);
} else {
$output .= $date['year'];
}
break;
case 'Y': // year number, 4 digits
$output .= $date['year'];
break;
case 'y': // year number, 2 digits
$output .= substr($date['year'], strlen($date['year']) - 2, 2);
break;
// time formats
case 'a': // lower case am/pm
$output .= (($date['hours'] >= 12) ? 'pm' : 'am');
break;
case 'A': // upper case am/pm
$output .= (($date['hours'] >= 12) ? 'PM' : 'AM');
break;
case 'B': // swatch internet time
$dayseconds = ($date['hours'] * 3600) + ($date['minutes'] * 60) + $date['seconds'];
if ($gmt === true) {
$dayseconds += 3600;
}
$output .= (int) (($dayseconds % 86400) / 86.4);
break;
case 'g': // hours without leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= $hour;
break;
case 'G': // hours without leading zeros, 24h format
$output .= $date['hours'];
break;
case 'h': // hours with leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= (($hour < 10) ? '0'.$hour : $hour);
break;
case 'H': // hours with leading zeros, 24h format
$output .= (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']);
break;
case 'i': // minutes with leading zeros
$output .= (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']);
break;
case 's': // seconds with leading zeros
$output .= (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);
break;
// timezone formats
case 'e': // timezone identifier
if ($gmt === true) {
$output .= gmdate('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'I': // daylight saving time or not
if ($gmt === true) {
$output .= gmdate('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'O': // difference to GMT in hours
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$output .= sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
break;
case 'P': // difference to GMT with colon
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$gmtstr = sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
$output = $output . substr($gmtstr, 0, 3) . ':' . substr($gmtstr, 3);
break;
case 'T': // timezone settings
if ($gmt === true) {
$output .= gmdate('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'Z': // timezone offset in seconds
$output .= ($gmt === true) ? 0 : -$this->_offset;
break;
// complete time formats
case 'c': // ISO 8601 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= $date['year'] . '-'
. (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']) . '-'
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . 'T'
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds'])
. $difference;
break;
case 'r': // RFC 2822 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= gmdate('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday']))) . ', '
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . ' '
. date('M', mktime(0, 0, 0, $date['mon'], 2, 1971)) . ' '
. $date['year'] . ' '
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']) . ' '
. $difference;
break;
case 'U': // Unix timestamp
$output .= $timestamp;
break;
// special formats
case "\\": // next letter to print with no format
$i++;
if ($i < $length) {
$output .= $format[$i];
}
break;
default: // letter is no format so add it direct
$output .= $format[$i];
break;
}
}
return (string) $output;
}
/**
* Returns the day of week for a Gregorian calendar date.
* 0 = sunday, 6 = saturday
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer dayOfWeek
*/
protected static function dayOfWeek($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('w', mktime(0, 0, 0, $month, $day, $year));
}
// gregorian correction
$correction = 0;
if (($year < 1582) or (($year == 1582) and (($month < 10) or (($month == 10) && ($day < 15))))) {
$correction = 3;
}
if ($month > 2) {
$month -= 2;
} else {
$month += 10;
$year--;
}
$day = floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4);
$day += floor(($year / 100) / 4) - 2 * floor($year / 100) + 77 + $correction;
return (int) ($day - 7 * floor($day / 7));
}
/**
* Internal getDateParts function for handling 64bit timestamps, similar to:
* http://www.php.net/getdate
*
* Returns an array of date parts for $timestamp, relative to 1970/01/01 00:00:00 GMT/UTC.
*
* $fast specifies ALL date parts should be returned (slower)
* Default is false, and excludes $dayofweek, weekday, month and timestamp from parts returned.
*
* @param mixed $timestamp
* @param boolean $fast OPTIONAL defaults to fast (false), resulting in fewer date parts
* @return array
*/
protected function getDateParts($timestamp = null, $fast = null)
{
// actual timestamp
if ($timestamp === null) {
return getdate();
}
// 32bit timestamp
if (abs($timestamp) <= 0x7FFFFFFF) {
return @getdate($timestamp);
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_getDateParts_' . $timestamp.'_'.(int)$fast, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
$otimestamp = $timestamp;
$numday = 0;
$month = 0;
// gregorian correction
if ($timestamp < -12219321600) {
$timestamp -= 864000;
}
// timestamp lower 0
if ($timestamp < 0) {
$sec = 0;
$act = 1970;
// iterate through 10 years table, increasing speed
foreach(self::$_yearTable as $year => $seconds) {
if ($timestamp >= $seconds) {
$i = $act;
break;
}
$sec = $seconds;
$act = $year;
}
$timestamp -= $sec;
if (!isset($i)) {
$i = $act;
}
// iterate the max last 10 years
do {
--$i;
$day = $timestamp;
$timestamp += 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$year = $i;
break;
}
} while ($timestamp < 0);
$secondsPerYear = 86400 * ($leapyear ? 366 : 365) + $day;
$timestamp = $day;
// iterate through months
for ($i = 12; --$i >= 0;) {
$day = $timestamp;
$timestamp += self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = $numday + ceil(($timestamp + 1) / 86400);
$timestamp += ($numday - $numberdays + 1) * 86400;
$hours = floor($timestamp / 3600);
} else {
// iterate through years
for ($i = 1970;;$i++) {
$day = $timestamp;
$timestamp -= 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$year = $i;
break;
}
}
$secondsPerYear = $day;
$timestamp = $day;
// iterate through months
for ($i = 0; $i <= 11; $i++) {
$day = $timestamp;
$timestamp -= self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = ceil(($timestamp + 1) / 86400);
$timestamp = $timestamp - ($numberdays - 1) * 86400;
$hours = floor($timestamp / 3600);
}
$timestamp -= $hours * 3600;
$month += 1;
$minutes = floor($timestamp / 60);
$seconds = $timestamp - $minutes * 60;
if ($fast === true) {
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
);
} else {
$dayofweek = self::dayOfWeek($year, $month, $numberdays);
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'wday' => $dayofweek,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
'weekday' => gmdate('l', 86400 * (3 + $dayofweek)),
'month' => gmdate('F', mktime(0, 0, 0, $month, 1, 1971)),
0 => $otimestamp
);
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($array), $id);
}
return $array;
}
/**
* Internal getWeekNumber function for handling 64bit timestamps
*
* Returns the ISO 8601 week number of a given date
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer
*/
protected function weekNumber($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('W', mktime(0, 0, 0, $month, $day, $year));
}
$dayofweek = self::dayOfWeek($year, $month, $day);
$firstday = self::dayOfWeek($year, 1, 1);
if (($month == 1) and (($firstday < 1) or ($firstday > 4)) and ($day < 4)) {
$firstday = self::dayOfWeek($year - 1, 1, 1);
$month = 12;
$day = 31;
} else if (($month == 12) and ((self::dayOfWeek($year + 1, 1, 1) < 5) and
(self::dayOfWeek($year + 1, 1, 1) > 0))) {
return 1;
}
return intval (((self::dayOfWeek($year, 1, 1) < 5) and (self::dayOfWeek($year, 1, 1) > 0)) +
4 * ($month - 1) + (2 * ($month - 1) + ($day - 1) + $firstday - $dayofweek + 6) * 36 / 256);
}
/**
* Internal _range function
* Sets the value $a to be in the range of [0, $b]
*
* @param float $a - value to correct
* @param float $b - maximum range to set
*/
private function _range($a, $b) {
while ($a < 0) {
$a += $b;
}
while ($a >= $b) {
$a -= $b;
}
return $a;
}
/**
* Calculates the sunrise or sunset based on a location
*
* @param array $location Location for calculation MUST include 'latitude', 'longitude', 'horizon'
* @param bool $horizon true: sunrise; false: sunset
* @return mixed - false: midnight sun, integer:
*/
protected function calcSun($location, $horizon, $rise = false)
{
// timestamp within 32bit
if (abs($this->_unixTimestamp) <= 0x7FFFFFFF) {
if ($rise === false) {
return date_sunset($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'],
$location['longitude'], 90 + $horizon, $this->_offset / 3600);
}
return date_sunrise($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'],
$location['longitude'], 90 + $horizon, $this->_offset / 3600);
}
// self calculation - timestamp bigger than 32bit
// fix circle values
$quarterCircle = 0.5 * M_PI;
$halfCircle = M_PI;
$threeQuarterCircle = 1.5 * M_PI;
$fullCircle = 2 * M_PI;
// radiant conversion for coordinates
$radLatitude = $location['latitude'] * $halfCircle / 180;
$radLongitude = $location['longitude'] * $halfCircle / 180;
// get solar coordinates
$tmpRise = $rise ? $quarterCircle : $threeQuarterCircle;
$radDay = $this->date('z',$this->_unixTimestamp) + ($tmpRise - $radLongitude) / $fullCircle;
// solar anomoly and longitude
$solAnomoly = $radDay * 0.017202 - 0.0574039;
$solLongitude = $solAnomoly + 0.0334405 * sin($solAnomoly);
$solLongitude += 4.93289 + 3.49066E-4 * sin(2 * $solAnomoly);
// get quadrant
$solLongitude = $this->_range($solLongitude, $fullCircle);
if (($solLongitude / $quarterCircle) - intval($solLongitude / $quarterCircle) == 0) {
$solLongitude += 4.84814E-6;
}
// solar ascension
$solAscension = sin($solLongitude) / cos($solLongitude);
$solAscension = atan2(0.91746 * $solAscension, 1);
// adjust quadrant
if ($solLongitude > $threeQuarterCircle) {
$solAscension += $fullCircle;
} else if ($solLongitude > $quarterCircle) {
$solAscension += $halfCircle;
}
// solar declination
$solDeclination = 0.39782 * sin($solLongitude);
$solDeclination /= sqrt(-$solDeclination * $solDeclination + 1);
$solDeclination = atan2($solDeclination, 1);
$solHorizon = $horizon - sin($solDeclination) * sin($radLatitude);
$solHorizon /= cos($solDeclination) * cos($radLatitude);
// midnight sun, always night
if (abs($solHorizon) > 1) {
return false;
}
$solHorizon /= sqrt(-$solHorizon * $solHorizon + 1);
$solHorizon = $quarterCircle - atan2($solHorizon, 1);
if ($rise) {
$solHorizon = $fullCircle - $solHorizon;
}
// time calculation
$localTime = $solHorizon + $solAscension - 0.0172028 * $radDay - 1.73364;
$universalTime = $localTime - $radLongitude;
// determinate quadrant
$universalTime = $this->_range($universalTime, $fullCircle);
// radiant to hours
$universalTime *= 24 / $fullCircle;
// convert to time
$hour = intval($universalTime);
$universalTime = ($universalTime - $hour) * 60;
$min = intval($universalTime);
$universalTime = ($universalTime - $min) * 60;
$sec = intval($universalTime);
return $this->mktime($hour, $min, $sec, $this->date('m', $this->_unixTimestamp),
$this->date('j', $this->_unixTimestamp), $this->date('Y', $this->_unixTimestamp),
-1, true);
}
/**
* Sets a new timezone for calculation of $this object's gmt offset.
* For a list of supported timezones look here: http://php.net/timezones
* If no timezone can be detected or the given timezone is wrong UTC will be set.
*
* @param string $zone OPTIONAL timezone for date calculation; defaults to date_default_timezone_get()
* @return Zend_Date_DateObject Provides fluent interface
* @throws Zend_Date_Exception
*/
public function setTimezone($zone = null)
{
$oldzone = @date_default_timezone_get();
if ($zone === null) {
$zone = $oldzone;
}
// throw an error on false input, but only if the new date extension is available
if (function_exists('timezone_open')) {
if (!@timezone_open($zone)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("timezone ($zone) is not a known timezone", $zone);
}
}
// this can generate an error if the date extension is not available and a false timezone is given
$result = @date_default_timezone_set($zone);
if ($result === true) {
$this->_offset = mktime(0, 0, 0, 1, 2, 1970) - gmmktime(0, 0, 0, 1, 2, 1970);
$this->_timezone = $zone;
}
date_default_timezone_set($oldzone);
if (($zone == 'UTC') or ($zone == 'GMT')) {
$this->_dst = false;
} else {
$this->_dst = true;
}
return $this;
}
/**
* Return the timezone of $this object.
* The timezone is initially set when the object is instantiated.
*
* @return string actual set timezone string
*/
public function getTimezone()
{
return $this->_timezone;
}
/**
* Return the offset to GMT of $this object's timezone.
* The offset to GMT is initially set when the object is instantiated using the currently,
* in effect, default timezone for PHP functions.
*
* @return integer seconds difference between GMT timezone and timezone when object was instantiated
*/
public function getGmtOffset()
{
return $this->_offset;
}
}
PK pG[q�*. . Date/Exception.phpnu &1i� <?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_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Date_Exception extends Zend_Exception
{
protected $operand = null;
public function __construct($message, $op = null)
{
$this->operand = $op;
parent::__construct($message);
}
public function getOperand()
{
return $this->operand;
}
}
PK pG[�'�4�\ �\ Date/Cities.phpnu &1i� <?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_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DateObject.php 2511 2006-12-26 22:54:37Z bkarwin $
*/
/**
* Additional data for sunset/sunrise calculations
*
* Holds the geographical data for all capital cities and many others worldwide
* Original data from http://www.fallingrain.com/world/
*
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_Cities
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Date_Cities
{
/**
* Array Collection of known cities
*
* The array contains 'latitude' and 'longitude' for every known city
*
* @var Array
*/
public static $cities = array(
'Abidjan' => array('latitude' => 5.3411111, 'longitude' => -4.0280556),
'Abu Dhabi' => array('latitude' => 24.4666667, 'longitude' => 54.3666667),
'Abuja' => array('latitude' => 9.1758333, 'longitude' => 7.1808333),
'Accra' => array('latitude' => 5.55, 'longitude' => -0.2166667),
'Adamstown' => array('latitude' => -25.0666667, 'longitude' => -130.0833333),
'Addis Ababa' => array('latitude' => 9.0333333, 'longitude' => 38.7),
'Adelaide' => array('latitude' => -34.9333333, 'longitude' => 138.6),
'Algiers' => array('latitude' => 36.7630556, 'longitude' => 3.0505556),
'Alofi' => array('latitude' => -19.0166667, 'longitude' => -169.9166667),
'Amman' => array('latitude' => 31.95, 'longitude' => 35.9333333),
'Amsterdam' => array('latitude' => 52.35, 'longitude' => 4.9166667),
'Andorra la Vella' => array('latitude' => 42.5, 'longitude' => 1.5166667),
'Ankara' => array('latitude' => 39.9272222, 'longitude' => 32.8644444),
'Antananarivo' => array('latitude' => -18.9166667, 'longitude' => 47.5166667),
'Apia' => array('latitude' => -13.8333333, 'longitude' => -171.7333333),
'Ashgabat' => array('latitude' => 37.95, 'longitude' => 58.3833333),
'Asmara' => array('latitude' => 15.3333333, 'longitude' => 38.9333333),
'Astana' => array('latitude' => 51.1811111, 'longitude' => 71.4277778),
'Asunción' => array('latitude' => -25.2666667, 'longitude' => -57.6666667),
'Athens' => array('latitude' => 37.9833333, 'longitude' => 23.7333333),
'Auckland' => array('latitude' => -36.8666667, 'longitude' => 174.7666667),
'Avarua' => array('latitude' => -21.2, 'longitude' => -159.7666667),
'Baghdad' => array('latitude' => 33.3386111, 'longitude' => 44.3938889),
'Baku' => array('latitude' => 40.3952778, 'longitude' => 49.8822222),
'Bamako' => array('latitude' => 12.65, 'longitude' => -8),
'Bandar Seri Begawan' => array('latitude' => 4.8833333, 'longitude' => 114.9333333),
'Bankok' => array('latitude' => 13.5833333, 'longitude' => 100.2166667),
'Bangui' => array('latitude' => 4.3666667, 'longitude' => 18.5833333),
'Banjul' => array('latitude' => 13.4530556, 'longitude' => -16.5775),
'Basel' => array('latitude' => 47.5666667, 'longitude' => 7.6),
'Basseterre' => array('latitude' => 17.3, 'longitude' => -62.7166667),
'Beijing' => array('latitude' => 39.9288889, 'longitude' => 116.3883333),
'Beirut' => array('latitude' => 33.8719444, 'longitude' => 35.5097222),
'Belgrade' => array('latitude' => 44.8186111, 'longitude' => 20.4680556),
'Belmopan' => array('latitude' => 17.25, 'longitude' => -88.7666667),
'Berlin' => array('latitude' => 52.5166667, 'longitude' => 13.4),
'Bern' => array('latitude' => 46.9166667, 'longitude' => 7.4666667),
'Bishkek' => array('latitude' => 42.8730556, 'longitude' => 74.6002778),
'Bissau' => array('latitude' => 11.85, 'longitude' => -15.5833333),
'Bloemfontein' => array('latitude' => -29.1333333, 'longitude' => 26.2),
'Bogotá' => array('latitude' => 4.6, 'longitude' => -74.0833333),
'Brasilia' => array('latitude' => -15.7833333, 'longitude' => -47.9166667),
'Bratislava' => array('latitude' => 48.15, 'longitude' => 17.1166667),
'Brazzaville' => array('latitude' => -4.2591667, 'longitude' => 15.2847222),
'Bridgetown' => array('latitude' => 13.1, 'longitude' => -59.6166667),
'Brisbane' => array('latitude' => -27.5, 'longitude' => 153.0166667),
'Brussels' => array('latitude' => 50.8333333, 'longitude' => 4.3333333),
'Bucharest' => array('latitude' => 44.4333333, 'longitude' => 26.1),
'Budapest' => array('latitude' => 47.5, 'longitude' => 19.0833333),
'Buenos Aires' => array('latitude' => -34.5875, 'longitude' => -58.6725),
'Bujumbura' => array('latitude' => -3.3761111, 'longitude' => 29.36),
'Cairo' => array('latitude' => 30.05, 'longitude' => 31.25),
'Calgary' => array('latitude' => 51.0833333, 'longitude' => -114.0833333),
'Canberra' => array('latitude' => -35.2833333, 'longitude' => 149.2166667),
'Cape Town' => array('latitude' => -33.9166667, 'longitude' => 18.4166667),
'Caracas' => array('latitude' => 10.5, 'longitude' => -66.9166667),
'Castries' => array('latitude' => 14, 'longitude' => -61),
'Charlotte Amalie' => array('latitude' => 18.34389, 'longitude' => -64.93111),
'Chicago' => array('latitude' => 41.85, 'longitude' => -87.65),
'Chisinau' => array('latitude' => 47.055556, 'longitude' => 28.8575),
'Cockburn Town' => array('latitude' => 21.4666667, 'longitude' => -71.1333333),
'Colombo' => array('latitude' => 6.9319444, 'longitude' => 79.8477778),
'Conakry' => array('latitude' => 9.5091667, 'longitude' => -13.7122222),
'Copenhagen' => array('latitude' => 55.6666667, 'longitude' => 12.5833333),
'Cotonou' => array('latitude' => 6.35, 'longitude' => 2.4333333),
'Dakar' => array('latitude' => 14.6708333, 'longitude' => -17.4380556),
'Damascus' => array('latitude' => 33.5, 'longitude' => 36.3),
'Dar es Salaam' => array('latitude' => -6.8, 'longitude' => 39.2833333),
'Dhaka' => array('latitude' => 23.7230556, 'longitude' => 90.4086111),
'Dili' => array('latitude' => -8.5586111, 'longitude' => 125.5736111),
'Djibouti' => array('latitude' => 11.595, 'longitude' => 43.1480556),
'Dodoma' => array('latitude' => -6.1833333, 'longitude' => 35.75),
'Doha' => array('latitude' => 25.2866667, 'longitude' => 51.5333333),
'Dubai' => array('latitude' => 25.2522222, 'longitude' => 55.28),
'Dublin' => array('latitude' => 53.3330556, 'longitude' => -6.2488889),
'Dushanbe' => array('latitude' => 38.56, 'longitude' => 68.7738889 ),
'Fagatogo' => array('latitude' => -14.2825, 'longitude' => -170.69),
'Fongafale' => array('latitude' => -8.5166667, 'longitude' => 179.2166667),
'Freetown' => array('latitude' => 8.49, 'longitude' => -13.2341667),
'Gaborone' => array('latitude' => -24.6463889, 'longitude' => 25.9119444),
'Geneva' => array('latitude' => 46.2, 'longitude' => 6.1666667),
'George Town' => array('latitude' => 19.3, 'longitude' => -81.3833333),
'Georgetown' => array('latitude' => 6.8, 'longitude' => -58.1666667),
'Gibraltar' => array('latitude' => 36.1333333, 'longitude' => -5.35),
'Glasgow' => array('latitude' => 55.8333333, 'longitude' => -4.25),
'Guatemala la Nueva' => array('latitude' => 14.6211111, 'longitude' => -90.5269444),
'Hagatna' => array('latitude' => 13.47417, 'longitude' => 144.74778),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Hamilton' => array('latitude' => 32.2941667, 'longitude' => -64.7838889),
'Hanoi' => array('latitude' => 21.0333333, 'longitude' => 105.85),
'Harare' => array('latitude' => -17.8177778, 'longitude' => 31.0447222),
'Havana' => array('latitude' => 23.1319444, 'longitude' => -82.3641667),
'Helsinki' => array('latitude' => 60.1755556, 'longitude' => 24.9341667),
'Honiara' => array('latitude' => -9.4333333, 'longitude' => 159.95),
'Islamabad' => array('latitude' => 30.8486111, 'longitude' => 72.4944444),
'Istanbul' => array('latitude' => 41.0186111, 'longitude' => 28.9647222),
'Jakarta' => array('latitude' => -6.1744444, 'longitude' => 106.8294444),
'Jamestown' => array('latitude' => -15.9333333, 'longitude' => -5.7166667),
'Jerusalem' => array('latitude' => 31.7666667, 'longitude' => 35.2333333),
'Johannesburg' => array('latitude' => -26.2, 'longitude' => 28.0833333),
'Kabul' => array('latitude' => 34.5166667, 'longitude' => 69.1833333),
'Kampala' => array('latitude' => 0.3155556, 'longitude' => 32.5655556),
'Kathmandu' => array('latitude' => 27.7166667, 'longitude' => 85.3166667),
'Khartoum' => array('latitude' => 15.5880556, 'longitude' => 32.5341667),
'Kigali' => array('latitude' => -1.9536111, 'longitude' => 30.0605556),
'Kingston' => array('latitude' => -29.05, 'longitude' => 167.95),
'Kingstown' => array('latitude' => 13.1333333, 'longitude' => -61.2166667),
'Kinshasa' => array('latitude' => -4.3, 'longitude' => 15.3),
'Kolkata' => array('latitude' => 22.5697222, 'longitude' => 88.3697222),
'Kuala Lumpur' => array('latitude' => 3.1666667, 'longitude' => 101.7),
'Kuwait City' => array('latitude' => 29.3697222, 'longitude' => 47.9783333),
'Kiev' => array('latitude' => 50.4333333, 'longitude' => 30.5166667),
'La Paz' => array('latitude' => -16.5, 'longitude' => -68.15),
'Libreville' => array('latitude' => 0.3833333, 'longitude' => 9.45),
'Lilongwe' => array('latitude' => -13.9833333, 'longitude' => 33.7833333),
'Lima' => array('latitude' => -12.05, 'longitude' => -77.05),
'Lisbon' => array('latitude' => 38.7166667, 'longitude' => -9.1333333),
'Ljubljana' => array('latitude' => 46.0552778, 'longitude' => 14.5144444),
'Lobamba' => array('latitude' => -26.4666667, 'longitude' => 31.2),
'Lomé' => array('latitude' => 9.7166667, 'longitude' => 38.3),
'London' => array('latitude' => 51.5, 'longitude' => -0.1166667),
'Los Angeles' => array('latitude' => 34.05222, 'longitude' => -118.24278),
'Luanda' => array('latitude' => -8.8383333, 'longitude' => 13.2344444),
'Lusaka' => array('latitude' => -15.4166667, 'longitude' => 28.2833333),
'Luxembourg' => array('latitude' => 49.6116667, 'longitude' => 6.13),
'Madrid' => array('latitude' => 40.4, 'longitude' => -3.6833333),
'Majuro' => array('latitude' => 7.1, 'longitude' => 171.3833333),
'Malabo' => array('latitude' => 3.75, 'longitude' => 8.7833333),
'Managua' => array('latitude' => 12.1508333, 'longitude' => -86.2683333),
'Manama' => array('latitude' => 26.2361111, 'longitude' => 50.5830556),
'Manila' => array('latitude' => 14.6041667, 'longitude' => 120.9822222),
'Maputo' => array('latitude' => -25.9652778, 'longitude' => 32.5891667),
'Maseru' => array('latitude' => -29.3166667, 'longitude' => 27.4833333),
'Mbabane' => array('latitude' => -26.3166667, 'longitude' => 31.1333333),
'Melbourne' => array('latitude' => -37.8166667, 'longitude' => 144.9666667),
'Melekeok' => array('latitude' => 7.4933333, 'longitude' => 134.6341667),
'Mexiko City' => array('latitude' => 19.4341667, 'longitude' => -99.1386111),
'Minsk' => array('latitude' => 53.9, 'longitude' => 27.5666667),
'Mogadishu' => array('latitude' => 2.0666667, 'longitude' => 45.3666667),
'Monaco' => array('latitude' => 43.7333333, 'longitude' => 7.4166667),
'Monrovia' => array('latitude' => 6.3105556, 'longitude' => -10.8047222),
'Montevideo' => array('latitude' => -34.8580556, 'longitude' => -56.1708333),
'Montreal' => array('latitude' => 45.5, 'longitude' => -73.5833333),
'Moroni' => array('latitude' => -11.7041667, 'longitude' => 43.2402778),
'Moscow' => array('latitude' => 55.7522222, 'longitude' => 37.6155556),
'Muscat' => array('latitude' => 23.6133333, 'longitude' => 58.5933333),
'Nairobi' => array('latitude' => -1.3166667, 'longitude' => 36.8333333),
'Nassau' => array('latitude' => 25.0833333, 'longitude' => -77.35),
'N´Djamena' => array('latitude' => 12.1130556, 'longitude' => 15.0491667),
'New Dehli' => array('latitude' => 28.6, 'longitude' => 77.2),
'New York' => array('latitude' => 40.71417, 'longitude' => -74.00639),
'Newcastle' => array('latitude' => -32.9166667, 'longitude' => 151.75),
'Niamey' => array('latitude' => 13.6666667, 'longitude' => 1.7833333),
'Nicosia' => array('latitude' => 35.1666667, 'longitude' => 33.3666667),
'Nouakchott' => array('latitude' => 18.0863889, 'longitude' => -15.9752778),
'Noumea' => array('latitude' => -22.2666667, 'longitude' => 166.45),
'Nuku´alofa' => array('latitude' => -21.1333333, 'longitude' => -175.2),
'Nuuk' => array('latitude' => 64.1833333, 'longitude' => -51.75),
'Oranjestad' => array('latitude' => 12.5166667, 'longitude' => -70.0333333),
'Oslo' => array('latitude' => 59.9166667, 'longitude' => 10.75),
'Ouagadougou' => array('latitude' => 12.3702778, 'longitude' => -1.5247222),
'Palikir' => array('latitude' => 6.9166667, 'longitude' => 158.15),
'Panama City' => array('latitude' => 8.9666667, 'longitude' => -79.5333333),
'Papeete' => array('latitude' => -17.5333333, 'longitude' => -149.5666667),
'Paramaribo' => array('latitude' => 5.8333333, 'longitude' => -55.1666667),
'Paris' => array('latitude' => 48.8666667, 'longitude' => 2.3333333),
'Perth' => array('latitude' => -31.9333333, 'longitude' => 115.8333333),
'Phnom Penh' => array('latitude' => 11.55, 'longitude' => 104.9166667),
'Podgorica' => array('latitude' => 43.7752778, 'longitude' => 19.6827778),
'Port Louis' => array('latitude' => -20.1666667, 'longitude' => 57.5),
'Port Moresby' => array('latitude' => -9.4647222, 'longitude' => 147.1925),
'Port-au-Prince' => array('latitude' => 18.5391667, 'longitude' => -72.335),
'Port of Spain' => array('latitude' => 10.6666667, 'longitude' => -61.5),
'Porto-Novo' => array('latitude' => 6.4833333, 'longitude' => 2.6166667),
'Prague' => array('latitude' => 50.0833333, 'longitude' => 14.4666667),
'Praia' => array('latitude' => 14.9166667, 'longitude' => -23.5166667),
'Pretoria' => array('latitude' => -25.7069444, 'longitude' => 28.2294444),
'Pyongyang' => array('latitude' => 39.0194444, 'longitude' => 125.7547222),
'Quito' => array('latitude' => -0.2166667, 'longitude' => -78.5),
'Rabat' => array('latitude' => 34.0252778, 'longitude' => -6.8361111),
'Reykjavik' => array('latitude' => 64.15, 'longitude' => -21.95),
'Riga' => array('latitude' => 56.95, 'longitude' => 24.1),
'Rio de Janero' => array('latitude' => -22.9, 'longitude' => -43.2333333),
'Road Town' => array('latitude' => 18.4166667, 'longitude' => -64.6166667),
'Rome' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Roseau' => array('latitude' => 15.3, 'longitude' => -61.4),
'Rotterdam' => array('latitude' => 51.9166667, 'longitude' => 4.5),
'Salvador' => array('latitude' => -12.9833333, 'longitude' => -38.5166667),
'San José' => array('latitude' => 9.9333333, 'longitude' => -84.0833333),
'San Juan' => array('latitude' => 18.46833, 'longitude' => -66.10611),
'San Marino' => array('latitude' => 43.5333333, 'longitude' => 12.9666667),
'San Salvador' => array('latitude' => 13.7086111, 'longitude' => -89.2030556),
'Sanaá' => array('latitude' => 15.3547222, 'longitude' => 44.2066667),
'Santa Cruz' => array('latitude' => -17.8, 'longitude' => -63.1666667),
'Santiago' => array('latitude' => -33.45, 'longitude' => -70.6666667),
'Santo Domingo' => array('latitude' => 18.4666667, 'longitude' => -69.9),
'Sao Paulo' => array('latitude' => -23.5333333, 'longitude' => -46.6166667),
'Sarajevo' => array('latitude' => 43.85, 'longitude' => 18.3833333),
'Seoul' => array('latitude' => 37.5663889, 'longitude' => 126.9997222),
'Shanghai' => array('latitude' => 31.2222222, 'longitude' => 121.4580556),
'Sydney' => array('latitude' => -33.8833333, 'longitude' => 151.2166667),
'Singapore' => array('latitude' => 1.2930556, 'longitude' => 103.8558333),
'Skopje' => array('latitude' => 42, 'longitude' => 21.4333333),
'Sofia' => array('latitude' => 42.6833333, 'longitude' => 23.3166667),
'St. George´s' => array('latitude' => 12.05, 'longitude' => -61.75),
'St. John´s' => array('latitude' => 17.1166667, 'longitude' => -61.85),
'Stanley' => array('latitude' => -51.7, 'longitude' => -57.85),
'Stockholm' => array('latitude' => 59.3333333, 'longitude' => 18.05),
'Suva' => array('latitude' => -18.1333333, 'longitude' => 178.4166667),
'Taipei' => array('latitude' => 25.0166667, 'longitude' => 121.45),
'Tallinn' => array('latitude' => 59.4338889, 'longitude' => 24.7280556),
'Tashkent' => array('latitude' => 41.3166667, 'longitude' => 69.25),
'Tbilisi' => array('latitude' => 41.725, 'longitude' => 44.7908333),
'Tegucigalpa' => array('latitude' => 14.1, 'longitude' => -87.2166667),
'Tehran' => array('latitude' => 35.6719444, 'longitude' => 51.4244444),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Thimphu' => array('latitude' => 27.4833333, 'longitude' => 89.6),
'Tirana' => array('latitude' => 41.3275, 'longitude' => 19.8188889),
'Tiraspol' => array('latitude' => 46.8402778, 'longitude' => 29.6433333),
'Tokyo' => array('latitude' => 35.685, 'longitude' => 139.7513889),
'Toronto' => array('latitude' => 43.6666667, 'longitude' => -79.4166667),
'Tórshavn' => array('latitude' => 62.0166667, 'longitude' => -6.7666667),
'Tripoli' => array('latitude' => 32.8925, 'longitude' => 13.18),
'Tunis' => array('latitude' => 36.8027778, 'longitude' => 10.1797222),
'Ulaanbaatar' => array('latitude' => 47.9166667, 'longitude' => 106.9166667),
'Vaduz' => array('latitude' => 47.1333333, 'longitude' => 9.5166667),
'Valletta' => array('latitude' => 35.8997222, 'longitude' => 14.5147222),
'Valparaiso' => array('latitude' => -33.0477778, 'longitude' => -71.6011111),
'Vancouver' => array('latitude' => 49.25, 'longitude' => -123.1333333),
'Vatican City' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Victoria' => array('latitude' => -4.6166667, 'longitude' => 55.45),
'Vienna' => array('latitude' => 48.2, 'longitude' => 16.3666667),
'Vientaine' => array('latitude' => 17.9666667, 'longitude' => 102.6),
'Vilnius' => array('latitude' => 54.6833333, 'longitude' => 25.3166667),
'Warsaw' => array('latitude' => 52.25, 'longitude' => 21),
'Washington dc' => array('latitude' => 38.895, 'longitude' => -77.03667),
'Wellington' => array('latitude' => -41.3, 'longitude' => 174.7833333),
'Willemstad' => array('latitude' => 12.1, 'longitude' => -68.9166667),
'Windhoek' => array('latitude' => -22.57, 'longitude' => 17.0836111),
'Yamoussoukro' => array('latitude' => 6.8166667, 'longitude' => -5.2833333),
'Yaoundé' => array('latitude' => 3.8666667, 'longitude' => 11.5166667),
'Yerevan' => array('latitude' => 40.1811111, 'longitude' => 44.5136111),
'Zürich' => array('latitude' => 47.3666667, 'longitude' => 8.55),
'Zagreb' => array('latitude' => 45.8, 'longitude' => 16)
);
/**
* Returns the location from the selected city
*
* @param string $city City to get location for
* @param string $horizon Horizon to use :
* default: effective
* others are civil, nautic, astronomic
* @return array
* @throws Zend_Date_Exception When city is unknown
*/
public static function City($city, $horizon = false)
{
foreach (self::$cities as $key => $value) {
if (strtolower($key) === strtolower($city)) {
$return = $value;
$return['horizon'] = $horizon;
return $return;
}
}
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('unknown city');
}
/**
* Return a list with all known cities
*
* @return array
*/
public static function getCityList()
{
return array_keys(self::$cities);
}
}
PK pG[�77 7 Loader/PluginLoader.phpnu &1i� <?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_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Loader_PluginLoader_Interface */
require_once 'Zend/Loader/PluginLoader/Interface.php';
/** Zend_Loader */
require_once 'Zend/Loader.php';
/**
* Generic plugin class loader
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 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
{
/**
* Class map cache file
* @var string
*/
protected static $_includeFileCache;
/**
* Instance loaded plugin paths
*
* @var array
*/
protected $_loadedPluginPaths = array();
/**
* Instance loaded plugins
*
* @var array
*/
protected $_loadedPlugins = array();
/**
* Instance registry property
*
* @var array
*/
protected $_prefixToPaths = array();
/**
* Statically loaded plugin path mappings
*
* @var array
*/
protected static $_staticLoadedPluginPaths = array();
/**
* Statically loaded plugins
*
* @var array
*/
protected static $_staticLoadedPlugins = array();
/**
* Static registry property
*
* @var array
*/
protected static $_staticPrefixToPaths = array();
/**
* Whether to use a statically named registry for loading plugins
*
* @var string|null
*/
protected $_useStaticRegistry = null;
/**
* Constructor
*
* @param array $prefixToPaths
* @param string $staticRegistryName OPTIONAL
*/
public function __construct(Array $prefixToPaths = array(), $staticRegistryName = null)
{
if (is_string($staticRegistryName) && !empty($staticRegistryName)) {
$this->_useStaticRegistry = $staticRegistryName;
if(!isset(self::$_staticPrefixToPaths[$staticRegistryName])) {
self::$_staticPrefixToPaths[$staticRegistryName] = array();
}
if(!isset(self::$_staticLoadedPlugins[$staticRegistryName])) {
self::$_staticLoadedPlugins[$staticRegistryName] = array();
}
}
foreach ($prefixToPaths as $prefix => $path) {
$this->addPrefixPath($prefix, $path);
}
}
/**
* Format prefix for internal use
*
* @param string $prefix
* @return string
*/
protected function _formatPrefix($prefix)
{
return rtrim($prefix, '_') . '_';
}
/**
* Add prefixed paths to the registry of paths
*
* @param string $prefix
* @param string $path
* @return Zend_Loader_PluginLoader
*/
public function addPrefixPath($prefix, $path)
{
if (!is_string($prefix) || !is_string($path)) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Zend_Loader_PluginLoader::addPrefixPath() method only takes strings for prefix and path.');
}
$prefix = $this->_formatPrefix($prefix);
$path = rtrim($path, '/\\') . '/';
if ($this->_useStaticRegistry) {
self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix][] = $path;
} else {
$this->_prefixToPaths[$prefix][] = $path;
}
return $this;
}
/**
* Get path stack
*
* @param string $prefix
* @return false|array False if prefix does not exist, array otherwise
*/
public function getPaths($prefix = null)
{
if ((null !== $prefix) && is_string($prefix)) {
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix])) {
return self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix];
}
return false;
}
if (isset($this->_prefixToPaths[$prefix])) {
return $this->_prefixToPaths[$prefix];
}
return false;
}
if ($this->_useStaticRegistry) {
return self::$_staticPrefixToPaths[$this->_useStaticRegistry];
}
return $this->_prefixToPaths;
}
/**
* Clear path stack
*
* @param string $prefix
* @return bool False only if $prefix does not exist
*/
public function clearPaths($prefix = null)
{
if ((null !== $prefix) && is_string($prefix)) {
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
if (isset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix])) {
unset(self::$_staticPrefixToPaths[$this->_useStaticRegistry][$prefix]);
return true;
}
return false;
}
if (isset($this->_prefixToPaths[$prefix])) {
unset($this->_prefixToPaths[$prefix]);
return true;
}
return false;
}
if ($this->_useStaticRegistry) {
self::$_staticPrefixToPaths[$this->_useStaticRegistry] = array();
} else {
$this->_prefixToPaths = array();
}
return true;
}
/**
* Remove a prefix (or prefixed-path) from the registry
*
* @param string $prefix
* @param string $path OPTIONAL
* @return Zend_Loader_PluginLoader
*/
public function removePrefixPath($prefix, $path = null)
{
$prefix = $this->_formatPrefix($prefix);
if ($this->_useStaticRegistry) {
$registry =& self::$_staticPrefixToPaths[$this->_useStaticRegistry];
} else {
$registry =& $this->_prefixToPaths;
}
if (!isset($registry[$prefix])) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' was not found in the PluginLoader.');
}
if ($path != null) {
$pos = array_search($path, $registry[$prefix]);
if ($pos === null) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' / Path ' . $path . ' was not found in the PluginLoader.');
}
unset($registry[$prefix][$pos]);
} else {
unset($registry[$prefix]);
}
return $this;
}
/**
* Normalize plugin name
*
* @param string $name
* @return string
*/
protected function _formatName($name)
{
return ucfirst((string) $name);
}
/**
* Whether or not a Plugin by a specific name is loaded
*
* @param string $name
* @return Zend_Loader_PluginLoader
*/
public function isLoaded($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry) {
return isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name]);
}
return isset($this->_loadedPlugins[$name]);
}
/**
* Return full class name for a named plugin
*
* @param string $name
* @return string|false False if class not found, class name otherwise
*/
public function getClassName($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry
&& isset(self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name])
) {
return self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name];
} elseif (isset($this->_loadedPlugins[$name])) {
return $this->_loadedPlugins[$name];
}
return false;
}
/**
* Get path to plugin class
*
* @param mixed $name
* @return string|false False if not found
*/
public function getClassPath($name)
{
$name = $this->_formatName($name);
if ($this->_useStaticRegistry
&& !empty(self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name])
) {
return self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name];
} elseif (!empty($this->_loadedPluginPaths[$name])) {
return $this->_loadedPluginPaths[$name];
}
if ($this->isLoaded($name)) {
$class = $this->getClassName($name);
$r = new ReflectionClass($class);
$path = $r->getFileName();
if ($this->_useStaticRegistry) {
self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = $path;
} else {
$this->_loadedPluginPaths[$name] = $path;
}
return $path;
}
return false;
}
/**
* Load a plugin via the name provided
*
* @param string $name
* @return string Class name of loaded class
* @throws Zend_Loader_Exception if class not found
*/
public function load($name)
{
$name = $this->_formatName($name);
if ($this->isLoaded($name)) {
return $this->getClassName($name);
}
if ($this->_useStaticRegistry) {
$registry = self::$_staticPrefixToPaths[$this->_useStaticRegistry];
} else {
$registry = $this->_prefixToPaths;
}
$registry = array_reverse($registry, true);
$found = false;
$classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
$incFile = self::getIncludeFileCache();
foreach ($registry as $prefix => $paths) {
$className = $prefix . $name;
if (class_exists($className, false)) {
$found = true;
break;
}
$paths = array_reverse($paths, true);
foreach ($paths as $path) {
$loadFile = $path . $classFile;
if (Zend_Loader::isReadable($loadFile)) {
include_once $loadFile;
if (class_exists($className, false)) {
if (null !== $incFile) {
self::_appendIncFile($loadFile);
}
$found = true;
break 2;
}
}
}
}
if (!$found) {
$message = "Plugin by name '$name' was not found in the registry; used paths:";
foreach ($registry as $prefix => $paths) {
$message .= "\n$prefix: " . implode(PATH_SEPARATOR, $paths);
}
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception($message);
}
if ($this->_useStaticRegistry) {
self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name] = $className;
self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = (isset($loadFile) ? $loadFile : '');
} else {
$this->_loadedPlugins[$name] = $className;
$this->_loadedPluginPaths[$name] = (isset($loadFile) ? $loadFile : '');
}
return $className;
}
/**
* Set path to class file cache
*
* Specify a path to a file that will add include_once statements for each
* plugin class loaded. This is an opt-in feature for performance purposes.
*
* @param string $file
* @return void
* @throws Zend_Loader_PluginLoader_Exception if file is not writeable or path does not exist
*/
public static function setIncludeFileCache($file)
{
if (null === $file) {
self::$_includeFileCache = null;
return;
}
if (!file_exists($file) && !file_exists(dirname($file))) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file does not exist and/or directory does not exist (' . $file . ')');
}
if (file_exists($file) && !is_writable($file)) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file is not writeable (' . $file . ')');
}
if (!file_exists($file) && file_exists(dirname($file)) && !is_writable(dirname($file))) {
require_once 'Zend/Loader/PluginLoader/Exception.php';
throw new Zend_Loader_PluginLoader_Exception('Specified file is not writeable (' . $file . ')');
}
self::$_includeFileCache = $file;
}
/**
* Retrieve class file cache path
*
* @return string|null
*/
public static function getIncludeFileCache()
{
return self::$_includeFileCache;
}
/**
* Append an include_once statement to the class file cache
*
* @param string $incFile
* @return void
*/
protected static function _appendIncFile($incFile)
{
if (!file_exists(self::$_includeFileCache)) {
$file = '<?php';
} else {
$file = file_get_contents(self::$_includeFileCache);
}
if (!strstr($file, $incFile)) {
$file .= "\ninclude_once '$incFile';";
file_put_contents(self::$_includeFileCache, $file);
}
}
}
PK pG[3��Cm m Loader/Exception.phpnu &1i� <?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_Loader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: CamelCaseToUnderscore.php 6779 2007-11-08 15:10:41Z matthew $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Loader
* @uses Zend_Exception
* @copyright Copyright (c) 2005-2008 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
{}PK pG[���h� � ! Loader/PluginLoader/Interface.phpnu &1i� <?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_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Plugin class loader interface
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Loader_PluginLoader_Interface
{
/**
* Add prefixed paths to the registry of paths
*
* @param string $prefix
* @param string $path
* @return Zend_Loader_PluginLoader
*/
public function addPrefixPath($prefix, $path);
/**
* Remove a prefix (or prefixed-path) from the registry
*
* @param string $prefix
* @param string $path OPTIONAL
* @return Zend_Loader_PluginLoader
*/
public function removePrefixPath($prefix, $path = null);
/**
* Whether or not a Helper by a specific name
*
* @param string $name
* @return Zend_Loader_PluginLoader
*/
public function isLoaded($name);
/**
* Return full class name for a named helper
*
* @param string $name
* @return string
*/
public function getClassName($name);
/**
* Load a helper via the name provided
*
* @param string $name
* @return string
*/
public function load($name);
}
PK pG[����} } ! Loader/PluginLoader/Exception.phpnu &1i� <?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_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Loader_Exception
*/
require_once 'Zend/Loader/Exception.php';
/**
* Plugin class loader exceptions
*
* @category Zend
* @package Zend_Loader
* @subpackage PluginLoader
* @copyright Copyright (c) 2005-2008 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
{
}
PK pG[g��-) )
Filter.phpnu &1i� <?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_Filter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Filter.php 8434 2008-02-27 19:15:13Z darby $
*/
/**
* @see Zend_Filter_Interface
*/
require_once 'Zend/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Filter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Filter implements Zend_Filter_Interface
{
/**
* Filter chain
*
* @var array
*/
protected $_filters = array();
/**
* Adds a filter to the end of the chain
*
* @param Zend_Filter_Interface $filter
* @return Zend_Filter Provides a fluent interface
*/
public function addFilter(Zend_Filter_Interface $filter)
{
$this->_filters[] = $filter;
return $this;
}
/**
* Returns $value filtered through each filter in the chain
*
* Filters are run in the order in which they were added to the chain (FIFO)
*
* @param mixed $value
* @return mixed
*/
public function filter($value)
{
$valueFiltered = $value;
foreach ($this->_filters as $filter) {
$valueFiltered = $filter->filter($valueFiltered);
}
return $valueFiltered;
}
/**
* Returns a value filtered through a specified filter class, without requiring separate
* instantiation of the filter object.
*
* The first argument of this method is a data input value, that you would have filtered.
* The second argument is a string, which corresponds to the basename of the filter class,
* relative to the Zend_Filter namespace. This method automatically loads the class,
* creates an instance, and applies the filter() method to the data input. You can also pass
* an array of constructor arguments, if they are needed for the filter class.
*
* @param mixed $value
* @param string $classBaseName
* @param array $args OPTIONAL
* @param array|string $namespaces OPTIONAL
* @return mixed
* @throws Zend_Filter_Exception
*/
public static function get($value, $classBaseName, array $args = array(), $namespaces = array())
{
require_once 'Zend/Loader.php';
$namespaces = array_merge(array('Zend_Filter'), (array) $namespaces);
foreach ($namespaces as $namespace) {
$className = $namespace . '_' . ucfirst($classBaseName);
try {
@Zend_Loader::loadClass($className);
} catch (Zend_Exception $ze) {
continue;
}
$class = new ReflectionClass($className);
if ($class->implementsInterface('Zend_Filter_Interface')) {
if ($class->hasMethod('__construct')) {
$object = $class->newInstanceArgs($args);
} else {
$object = $class->newInstance();
}
return $object->filter($value);
}
}
require_once 'Zend/Filter/Exception.php';
throw new Zend_Filter_Exception("Filter class not found from basename '$classBaseName'");
}
}
PK pG[��J�I �I Rest/Server.phpnu &1i� <?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_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Server_Interface
*/
require_once 'Zend/Server/Interface.php';
/**
* Zend_Server_Reflection
*/
require_once 'Zend/Server/Reflection.php';
/**
* Zend_Rest_Server_Exception
*/
require_once 'Zend/Rest/Server/Exception.php';
/**
* Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
/**
* @category Zend
* @package Zend_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Server implements Zend_Server_Interface
{
/**
* Class Constructor Args
* @var array
*/
protected $_args = array();
/**
* @var string Encoding
*/
protected $_encoding = 'UTF-8';
/**
* @var array An array of Zend_Server_Reflect_Method
*/
protected $_functions = array();
/**
* @var array Array of headers to send
*/
protected $_headers = array();
/**
* @var array PHP's Magic Methods, these are ignored
*/
protected static $magicMethods = array(
'__construct',
'__destruct',
'__get',
'__set',
'__call',
'__sleep',
'__wakeup',
'__isset',
'__unset',
'__tostring',
'__clone',
'__set_state',
);
/**
* @var string Current Method
*/
protected $_method;
/**
* @var Zend_Server_Reflection
*/
protected $_reflection = null;
/**
* Whether or not {@link handle()} should send output or return the response.
* @var boolean Defaults to false
*/
protected $_returnResponse = false;
/**
* Constructor
*/
public function __construct()
{
set_exception_handler(array($this, "fault"));
$this->_reflection = new Zend_Server_Reflection();
}
/**
* Set XML encoding
*
* @param string $encoding
* @return Zend_Rest_Server
*/
public function setEncoding($encoding)
{
$this->_encoding = (string) $encoding;
return $this;
}
/**
* Get XML encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Lowercase a string
*
* Lowercase's a string by reference
*
* @param string $value
* @param string $key
* @return string Lower cased string
*/
public static function lowerCase(&$value, &$key)
{
return $value = strtolower($value);
}
/**
* Whether or not to return a response
*
* If called without arguments, returns the value of the flag. If called
* with an argument, sets the flag.
*
* When 'return response' is true, {@link handle()} will not send output,
* but will instead return the response from the dispatched function/method.
*
* @param boolean $flag
* @return boolean|Zend_Rest_Server Returns Zend_Rest_Server when used to set the flag; returns boolean flag value otherwise.
*/
public function returnResponse($flag = null)
{
if (null == $flag) {
return $this->_returnResponse;
}
$this->_returnResponse = ($flag) ? true : false;
return $this;
}
/**
* Implement Zend_Server_Interface::handle()
*
* @param array $request
* @throws Zend_Rest_Server_Exception
* @return string|void
*/
public function handle($request = false)
{
$this->_headers = array('Content-Type: text/xml');
if (!$request) {
$request = $_REQUEST;
}
if (isset($request['method'])) {
$this->_method = $request['method'];
if (isset($this->_functions[$this->_method])) {
if ($this->_functions[$this->_method] instanceof Zend_Server_Reflection_Function || $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method && $this->_functions[$this->_method]->isPublic()) {
$request_keys = array_keys($request);
array_walk($request_keys, array(__CLASS__, "lowerCase"));
$request = array_combine($request_keys, $request);
$func_args = $this->_functions[$this->_method]->getParameters();
$calling_args = array();
foreach ($func_args as $arg) {
if (isset($request[strtolower($arg->getName())])) {
$calling_args[] = $request[strtolower($arg->getName())];
} elseif ($arg->isOptional()) {
$calling_args[] = $arg->getDefaultValue();
}
}
foreach ($request as $key => $value) {
if (substr($key, 0, 3) == 'arg') {
$key = str_replace('arg', '', $key);
$calling_args[$key] = $value;
}
}
// Sort arguments by key -- @see ZF-2279
ksort($calling_args);
$result = false;
if (count($calling_args) < count($func_args)) {
$result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Requires ' . count($func_args) . ', ' . count($calling_args) . ' given.'), 400);
}
if (!$result && $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method) {
// Get class
$class = $this->_functions[$this->_method]->getDeclaringClass()->getName();
if ($this->_functions[$this->_method]->isStatic()) {
// for some reason, invokeArgs() does not work the same as
// invoke(), and expects the first argument to be an object.
// So, using a callback if the method is static.
$result = $this->_callStaticMethod($class, $calling_args);
} else {
// Object method
$result = $this->_callObjectMethod($class, $calling_args);
}
} elseif (!$result) {
try {
$result = call_user_func_array($this->_functions[$this->_method]->getName(), $calling_args); //$this->_functions[$this->_method]->invokeArgs($calling_args);
} catch (Exception $e) {
$result = $this->fault($e);
}
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
404
);
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
404
);
}
} else {
require_once "Zend/Rest/Server/Exception.php";
$result = $this->fault(
new Zend_Rest_Server_Exception("No Method Specified."),
404
);
}
if ($result instanceof SimpleXMLElement) {
$response = $result->asXML();
} elseif ($result instanceof DOMDocument) {
$response = $result->saveXML();
} elseif ($result instanceof DOMNode) {
$response = $result->ownerDocument->saveXML($result);
} elseif (is_array($result) || is_object($result)) {
$response = $this->_handleStruct($result);
} else {
$response = $this->_handleScalar($result);
}
if (!$this->returnResponse()) {
if (!headers_sent()) {
foreach ($this->_headers as $header) {
header($header);
}
}
echo $response;
return;
}
return $response;
}
/**
* Implement Zend_Server_Interface::setClass()
*
* @param string $classname Class name
* @param string $namespace Class namespace (unused)
* @param array $argv An array of Constructor Arguments
*/
public function setClass($classname, $namespace = '', $argv = array())
{
$this->_args = $argv;
foreach ($this->_reflection->reflectClass($classname, $argv)->getMethods() as $method) {
$this->_functions[$method->getName()] = $method;
}
}
/**
* Handle an array or object result
*
* @param array|object $struct Result Value
* @return string XML Response
*/
protected function _handleStruct($struct)
{
$function = $this->_functions[$this->_method];
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
$method = $function->getName();
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$root = $dom->createElement($class);
$method = $dom->createElement($method);
$root->appendChild($method);
} else {
$root = $dom->createElement($method);
$method = $root;
}
$root->setAttribute('generator', 'zend');
$root->setAttribute('version', '1.0');
$dom->appendChild($root);
$this->_structValue($struct, $dom, $method);
$struct = (array) $struct;
if (!isset($struct['status'])) {
$status = $dom->createElement('status', 'success');
$method->appendChild($status);
}
return $dom->saveXML();
}
/**
* Recursively iterate through a struct
*
* Recursively iterates through an associative array or object's properties
* to build XML response.
*
* @param mixed $struct
* @param DOMDocument $dom
* @param DOMElement $parent
* @return void
*/
protected function _structValue($struct, DOMDocument $dom, DOMElement $parent)
{
$struct = (array) $struct;
foreach ($struct as $key => $value) {
if ($value === false) {
$value = 0;
} elseif ($value === true) {
$value = 1;
}
if (ctype_digit((string) $key)) {
$key = 'key_' . $key;
}
if (is_array($value) || is_object($value)) {
$element = $dom->createElement($key);
$this->_structValue($value, $dom, $element);
} else {
$element = $dom->createElement($key);
$element->appendChild($dom->createTextNode($value));
}
$parent->appendChild($element);
}
}
/**
* Handle a single value
*
* @param string|int|boolean $value Result value
* @return string XML Response
*/
protected function _handleScalar($value)
{
$function = $this->_functions[$this->_method];
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
$method = $function->getName();
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$xml = $dom->createElement($class);
$methodNode = $dom->createElement($method);
$xml->appendChild($methodNode);
} else {
$xml = $dom->createElement($method);
$methodNode = $xml;
}
$xml->setAttribute('generator', 'zend');
$xml->setAttribute('version', '1.0');
$dom->appendChild($xml);
if ($value === false) {
$value = 0;
} elseif ($value === true) {
$value = 1;
}
if (isset($value)) {
$element = $dom->createElement('response');
$element->appendChild($dom->createTextNode($value));
$methodNode->appendChild($element);
} else {
$methodNode->appendChild($dom->createElement('response'));
}
$methodNode->appendChild($dom->createElement('status', 'success'));
return $dom->saveXML();
}
/**
* Implement Zend_Server_Interface::fault()
*
* Creates XML error response, returning DOMDocument with response.
*
* @param string|Exception $fault Message
* @param int $code Error Code
* @return DOMDocument
*/
public function fault($exception = null, $code = null)
{
if (isset($this->_functions[$this->_method])) {
$function = $this->_functions[$this->_method];
} elseif (isset($this->_method)) {
$function = $this->_method;
} else {
$function = 'rest';
}
if ($function instanceof Zend_Server_Reflection_Method) {
$class = $function->getDeclaringClass()->getName();
} else {
$class = false;
}
if ($function instanceof Zend_Server_Reflection_Function_Abstract) {
$method = $function->getName();
} else {
$method = $function;
}
$dom = new DOMDocument('1.0', $this->getEncoding());
if ($class) {
$xml = $dom->createElement($class);
$xmlMethod = $dom->createElement($method);
$xml->appendChild($xmlMethod);
} else {
$xml = $dom->createElement($method);
$xmlMethod = $xml;
}
$xml->setAttribute('generator', 'zend');
$xml->setAttribute('version', '1.0');
$dom->appendChild($xml);
$xmlResponse = $dom->createElement('response');
$xmlMethod->appendChild($xmlResponse);
if ($exception instanceof Exception) {
$element = $dom->createElement('message');
$element->appendChild($dom->createTextNode($exception->getMessage()));
$xmlResponse->appendChild($element);
$code = $exception->getCode();
} elseif (!is_null($exception) || 'rest' == $function) {
$xmlResponse->appendChild($dom->createElement('message', 'An unknown error occured. Please try again.'));
} else {
$xmlResponse->appendChild($dom->createElement('message', 'Call to ' . $method . ' failed.'));
}
$xmlMethod->appendChild($xmlResponse);
$xmlMethod->appendChild($dom->createElement('status', 'failed'));
// Headers to send
if (is_null($code) || (404 != $code))
{
$this->_headers[] = 'HTTP/1.0 400 Bad Request';
} else {
$this->_headers[] = 'HTTP/1.0 404 File Not Found';
}
return $dom;
}
/**
* Retrieve any HTTP extra headers set by the server
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Implement Zend_Server_Interface::addFunction()
*
* @param string $function Function Name
* @param string $namespace Function namespace (unused)
*/
public function addFunction($function, $namespace = '')
{
if (!is_array($function)) {
$function = (array) $function;
}
foreach ($function as $func) {
if (is_callable($func) && !in_array($func, self::$magicMethods)) {
$this->_functions[$func] = $this->_reflection->reflectFunction($func);
} else {
throw new Zend_Rest_Server_Exception("Invalid Method Added to Service.");
}
}
}
/**
* Implement Zend_Server_Interface::getFunctions()
*
* @return array An array of Zend_Server_Reflection_Method's
*/
public function getFunctions()
{
return $this->_functions;
}
/**
* Implement Zend_Server_Interface::loadFunctions()
*
* @todo Implement
* @param array $functions
*/
public function loadFunctions($functions)
{
}
/**
* Implement Zend_Server_Interface::setPersistence()
*
* @todo Implement
* @param int $mode
*/
public function setPersistence($mode)
{
}
/**
* Call a static class method and return the result
*
* @param string $class
* @param array $args
* @return mixed
*/
protected function _callStaticMethod($class, array $args)
{
try {
$result = call_user_func_array(array($class, $this->_functions[$this->_method]->getName()), $args);
} catch (Exception $e) {
$result = $this->fault($e);
}
return $result;
}
/**
* Call an instance method of an object
*
* @param string $class
* @param array $args
* @return mixed
* @throws Zend_Rest_Server_Exception For invalid class name
*/
protected function _callObjectMethod($class, array $args)
{
try {
if ($this->_functions[$this->_method]->getDeclaringClass()->getConstructor()) {
$object = $this->_functions[$this->_method]->getDeclaringClass()->newInstanceArgs($this->_args);
} else {
$object = $this->_functions[$this->_method]->getDeclaringClass()->newInstance();
}
} catch (Exception $e) {
echo $e->getMessage();
throw new Zend_Rest_Server_Exception('Error instantiating class ' . $class . ' to invoke method ' . $this->_functions[$this->_method]->getName(), 500);
}
try {
$result = $this->_functions[$this->_method]->invokeArgs($object, $args);
} catch (Exception $e) {
$result = $this->fault($e);
}
return $result;
}
}
PK pG[�"}�1 1 Rest/Server/Exception.phpnu &1i� <?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.
*
* @package Zend_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Rest_Exception
*/
require_once 'Zend/Rest/Exception.php';
/**
* Zend_Rest_Server_Exception
*
* @package Zend_Rest
* @subpackage Server
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Server_Exception extends Zend_Rest_Exception
{
}
PK pG[P�0sD D Rest/Client/Exception.phpnu &1i� <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Rest_Exception
*/
require_once 'Zend/Rest/Exception.php';
/**
* Zend_Rest_Server_Exception
*
* @package Zend_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Client_Exception extends Zend_Rest_Exception
{
}
PK pG[��c c Rest/Client/Result/Exception.phpnu &1i� <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Rest_Client_Exception
*/
require_once "Zend/Rest/Client/Exception.php";
class Zend_Rest_Client_Result_Exception extends Zend_Rest_Client_Exception{}PK pG[ڈx 0 0 Rest/Client/Result.phpnu &1i� <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Client_Result implements IteratorAggregate {
/**
* @var SimpleXMLElement
*/
protected $_sxml;
/**
* Constructor
*
* @param string $data XML Result
* @return void
*/
public function __construct($data)
{
set_error_handler(array($this, 'handleXmlErrors'));
$this->_sxml = simplexml_load_string($data);
if($this->_sxml === false) {
$this->handleXmlErrors(0, "An error occured while parsing the REST response with simplexml.");
} else {
restore_error_handler();
}
}
/**
* Temporary error handler for parsing REST responses.
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @param array $errcontext
* @throws Zend_Result_Client_Result_Exception
*/
public function handleXmlErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
{
restore_error_handler();
require_once "Zend/Rest/Client/Result/Exception.php";
throw new Zend_Rest_Client_Result_Exception("REST Response Error: ".$errstr);
}
/**
* Casts a SimpleXMLElement to its appropriate PHP value
*
* @param SimpleXMLElement $value
* @return mixed
*/
public function toValue(SimpleXMLElement $value)
{
$node = dom_import_simplexml($value);
return $node->nodeValue;
}
/**
* Get Property Overload
*
* @param string $name
* @return null|SimpleXMLElement|array Null if not found, SimpleXMLElement if only one value found, array of Zend_Rest_Client_Result objects otherwise
*/
public function __get($name)
{
if (isset($this->_sxml->{$name})) {
return $this->_sxml->{$name};
}
$result = $this->_sxml->xpath("//$name");
$count = count($result);
if ($count == 0) {
return null;
} elseif ($count == 1) {
return $result[0];
} else {
return $result;
}
}
/**
* Cast properties to PHP values
*
* For arrays, loops through each element and casts to a value as well.
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if (null !== ($value = $this->__get($method))) {
if (!is_array($value)) {
return $this->toValue($value);
} else {
$return = array();
foreach ($value as $element) {
$return[] = $this->toValue($element);
}
return $return;
}
}
return null;
}
/**
* Isset Overload
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
if (isset($this->_sxml->{$name})) {
return true;
}
$result = $this->_sxml->xpath("//$name");
if (sizeof($result) > 0) {
return true;
}
return false;
}
/**
* Implement IteratorAggregate::getIterator()
*
* @return SimpleXMLIterator
*/
public function getIterator()
{
return $this->_sxml;
}
/**
* Get Request Status
*
* @return boolean
*/
public function getStatus()
{
$status = $this->_sxml->xpath('//status/text()');
$status = strtolower($status[0]);
if (ctype_alpha($status) && $status == 'success') {
return true;
} elseif (ctype_alpha($status) && $status != 'success') {
return false;
} else {
return (bool) $status;
}
}
public function isError()
{
$status = $this->getStatus();
if ($status) {
return false;
} else {
return true;
}
}
public function isSuccess()
{
$status = $this->getStatus();
if ($status) {
return true;
} else {
return false;
}
}
/**
* toString overload
*
* Be sure to only call this when the result is a single value!
*
* @return string
*/
public function __toString()
{
if (!$this->getStatus()) {
$message = $this->_sxml->xpath('//message');
return (string) $message[0];
} else {
$result = $this->_sxml->xpath('//response');
if (sizeof($result) > 1) {
return (string) "An error occured.";
} else {
return (string) $result[0];
}
}
}
}
PK pG[���� � Rest/Exception.phpnu &1i� <?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_Rest
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Rest
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Exception extends Zend_Exception
{}
PK pG[�~�� � Rest/Client.phpnu &1i� <?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_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Service_Abstract */
require_once 'Zend/Service/Abstract.php';
/** Zend_Rest_Client_Result */
require_once 'Zend/Rest/Client/Result.php';
/** Zend_Uri */
require_once 'Zend/Uri.php';
/**
* @category Zend
* @package Zend_Rest
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Rest_Client extends Zend_Service_Abstract
{
/**
* Data for the query
* @var array
*/
protected $_data = array();
/**
* Zend_Uri of this web service
* @var Zend_Uri_Http
*/
protected $_uri = null;
/**
* Constructor
*
* @param string|Zend_Uri_Http $uri URI for the web service
* @return void
*/
public function __construct($uri = null)
{
if (!empty($uri)) {
$this->setUri($uri);
}
}
/**
* Set the URI to use in the request
*
* @param string|Zend_Uri_Http $uri URI for the web service
* @return Zend_Rest_Client
*/
public function setUri($uri)
{
if ($uri instanceof Zend_Uri_Http) {
$this->_uri = $uri;
} else {
$this->_uri = Zend_Uri::factory($uri);
}
return $this;
}
/**
* Retrieve the current request URI object
*
* @return Zend_Uri_Http
*/
public function getUri()
{
return $this->_uri;
}
/**
* Call a remote REST web service URI and return the Zend_Http_Response object
*
* @param string $path The path to append to the URI
* @throws Zend_Rest_Client_Exception
* @return void
*/
final private function _prepareRest($path)
{
// Get the URI object and configure it
if (!$this->_uri instanceof Zend_Uri_Http) {
require_once 'Zend/Rest/Client/Exception.php';
throw new Zend_Rest_Client_Exception('URI object must be set before performing call');
}
$uri = $this->_uri->getUri();
if ($path[0] != '/' && $uri[strlen($uri)-1] != '/') {
$path = '/' . $path;
}
$this->_uri->setPath($path);
/**
* Get the HTTP client and configure it for the endpoint URI. Do this each time
* because the Zend_Http_Client instance is shared among all Zend_Service_Abstract subclasses.
*/
self::getHttpClient()->resetParameters()->setUri($this->_uri);
}
/**
* Performs an HTTP GET request to the $path.
*
* @param string $path
* @param array $query Array of GET parameters
* @return Zend_Http_Response
*/
final public function restGet($path, array $query = null)
{
$this->_prepareRest($path);
$client = self::getHttpClient();
$client->setParameterGet($query);
return $client->request('GET');
}
/**
* Perform a POST or PUT
*
* Performs a POST or PUT request. Any data provided is set in the HTTP
* client. String data is pushed in as raw POST data; array or object data
* is pushed in as POST parameters.
*
* @param mixed $method
* @param mixed $data
* @return Zend_Http_Response
*/
protected function _performPost($method, $data = null)
{
$client = self::getHttpClient();
if (is_string($data)) {
$client->setRawData($data);
} elseif (is_array($data) || is_object($data)) {
$client->setParameterPost((array) $data);
}
return $client->request($method);
}
/**
* Performs an HTTP POST request to $path.
*
* @param string $path
* @param mixed $data Raw data to send
* @return Zend_Http_Response
*/
final public function restPost($path, $data = null)
{
$this->_prepareRest($path);
return $this->_performPost('POST', $data);
}
/**
* Performs an HTTP PUT request to $path.
*
* @param string $path
* @param mixed $data Raw data to send in request
* @return Zend_Http_Response
*/
final public function restPut($path, $data = null)
{
$this->_prepareRest($path);
return $this->_performPost('PUT', $data);
}
/**
* Performs an HTTP DELETE request to $path.
*
* @param string $path
* @return Zend_Http_Response
*/
final public function restDelete($path)
{
$this->_prepareRest($path);
return self::getHttpClient()->request('DELETE');
}
/**
* Method call overload
*
* Allows calling REST actions as object methods; however, you must
* follow-up by chaining the request with a request to an HTTP request
* method (post, get, delete, put):
* <code>
* $response = $rest->sayHello('Foo', 'Manchu')->get();
* </code>
*
* Or use them together, but in sequential calls:
* <code>
* $rest->sayHello('Foo', 'Manchu');
* $response = $rest->get();
* </code>
*
* @param string $method Method name
* @param array $args Method args
* @return Zend_Rest_Client_Result|Zend_Rest_Client Zend_Rest_Client if using
* a remote method, Zend_Rest_Client_Result if using an HTTP request method
*/
public function __call($method, $args)
{
$methods = array('post', 'get', 'delete', 'put');
if (in_array(strtolower($method), $methods)) {
if (!isset($args[0])) {
$args[0] = $this->_uri->getPath();
}
$this->_data['rest'] = 1;
$data = array_slice($args, 1) + $this->_data;
$response = $this->{'rest' . $method}($args[0], $data);
$this->_data = array();//Initializes for next Rest method.
return new Zend_Rest_Client_Result($response->getBody());
} else {
// More than one arg means it's definitely a Zend_Rest_Server
if (sizeof($args) == 1) {
// Uses first called function name as method name
if (!isset($this->_data['method'])) {
$this->_data['method'] = $method;
$this->_data['arg1'] = $args[0];
}
$this->_data[$method] = $args[0];
} else {
$this->_data['method'] = $method;
if (sizeof($args) > 0) {
foreach ($args as $key => $arg) {
$key = 'arg' . $key;
$this->_data[$key] = $arg;
}
}
}
return $this;
}
}
}
PK pG[D'$�5 5
Dom/Query.phpnu &1i� <?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_Dom
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Dom_Query_Css2Xpath
*/
require_once 'Zend/Dom/Query/Css2Xpath.php';
/**
* @see Zend_Dom_Query_Result
*/
require_once 'Zend/Dom/Query/Result.php';
/**
* Query DOM structures based on CSS selectors and/or XPath
*
* @package Zend_Dom
* @subpackage Query
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dom_Query
{
/**#@+
* @const string Document types
*/
const DOC_XML = 'docXml';
const DOC_HTML = 'docHtml';
const DOC_XHTML = 'docXhtml';
/**#@-*/
/**
* @var string
*/
protected $_document;
/**
* Document type
* @var string
*/
protected $_docType;
/**
* Constructor
*
* @param null|string $document
* @return void
*/
public function __construct($document = null)
{
if (null !== $document) {
$this->setDocument($document);
}
}
/**
* Set document to query
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocument($document)
{
if ('<?xml' == substr(trim($document), 0, 5)) {
return $this->setDocumentXml($document);
}
if (strstr($document, 'DTD XHTML')) {
return $this->setDocumentXhtml($document);
}
return $this->setDocumentHtml($document);
}
/**
* Register HTML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentHtml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_HTML;
return $this;
}
/**
* Register XHTML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentXhtml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_XHTML;
return $this;
}
/**
* Register XML document
*
* @param string $document
* @return Zend_Dom_Query
*/
public function setDocumentXml($document)
{
$this->_document = (string) $document;
$this->_docType = self::DOC_XML;
return $this;
}
/**
* Retrieve current document
*
* @return string
*/
public function getDocument()
{
return $this->_document;
}
/**
* Get document type
*
* @return string
*/
public function getDocumentType()
{
return $this->_docType;
}
/**
* Perform a CSS selector query
*
* @param string $query
* @return Zend_Dom_Query_Result
*/
public function query($query)
{
$xpathQuery = Zend_Dom_Query_Css2Xpath::transform($query);
return $this->queryXpath($xpathQuery, $query);
}
/**
* Perform an XPath query
*
* @param string $xpathQuery
* @param string $query CSS selector query
* @return Zend_Dom_Query_Result
*/
public function queryXpath($xpathQuery, $query = null)
{
if (null === ($document = $this->getDocument())) {
require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception('Cannot query; no document registered');
}
$domDoc = new DOMDocument;
$type = $this->getDocumentType();
switch ($type) {
case self::DOC_XML:
$success = @$domDoc->loadXML($document);
break;
case self::DOC_HTML:
case self::DOC_XHTML:
default:
$success = @$domDoc->loadHTML($document);
break;
}
if (!$success) {
require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception(sprintf('Error parsing document (type == %s)', $type));
}
$nodeList = $this->_getNodeList($domDoc, $xpathQuery);
return new Zend_Dom_Query_Result($query, $xpathQuery, $domDoc, $nodeList);
}
/**
* Prepare node list
*
* @param DOMDocument $document
* @param string|array $xpathQuery
* @return array
*/
protected function _getNodeList($document, $xpathQuery)
{
$xpath = new DOMXPath($document);
$xpathQuery = (string) $xpathQuery;
if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) {
foreach ($matches[1] as $attribute) {
$queryString = '//*[' . $attribute . ']';
$attributeName = substr($attribute, 1);
$nodes = $xpath->query($queryString);
foreach ($nodes as $node) {
$attr = $node->attributes->getNamedItem($attributeName);
$attr->value = ' ' . $attr->value . ' ';
}
}
}
return $xpath->query($xpathQuery);
}
}
PK pG[�ox= = Dom/Exception.phpnu &1i� <?php
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* Zend_Dom Exceptions
*
* @package Zend_Dom
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
*/
class Zend_Dom_Exception extends Zend_Exception
{
}
PK pG[w-_� Dom/Query/Css2Xpath.phpnu &1i� <?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_Dom
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Transform CSS selectors to XPath
*
* @package Zend_Dom
* @subpackage Query
* @copyright Copyright (C) 2007 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: Css2Xpath.php 11013 2008-08-24 21:06:20Z thomas $
*/
class Zend_Dom_Query_Css2Xpath
{
/**
* Transform CSS expression to XPath
*
* @param string $path
* @return string
*/
public static function transform($path)
{
$path = (string) $path;
if (strstr($path, ',')) {
$paths = explode(',', $path);
$expressions = array();
foreach ($paths as $path) {
$xpath = self::transform(trim($path));
if (is_string($xpath)) {
$expressions[] = $xpath;
} elseif (is_array($xpath)) {
$expressions = array_merge($expressions, $xpath);
}
}
return $expressions;
}
$paths = array('//');
$segments = preg_split('/\s+/', $path);
foreach ($segments as $key => $segment) {
$pathSegment = self::_tokenize($segment);
if (0 == $key) {
if (0 === strpos($pathSegment, '[contains(@class')) {
$paths[0] .= '*' . $pathSegment;
} else {
$paths[0] .= $pathSegment;
}
continue;
}
if (0 === strpos($pathSegment, '[contains(@class')) {
foreach ($paths as $key => $xpath) {
$paths[$key] .= '//*' . $pathSegment;
$paths[] = $xpath . $pathSegment;
}
} else {
foreach ($paths as $key => $xpath) {
$paths[$key] .= '//' . $pathSegment;
}
}
}
if (1 == count($paths)) {
return $paths[0];
}
return implode(' | ', $paths);
}
/**
* Tokenize CSS expressions to XPath
*
* @param string $expression
* @return string
*/
protected static function _tokenize($expression)
{
// Child selectors
$expression = str_replace('>', '/', $expression);
// IDs
$expression = preg_replace('|#([a-z][a-z0-9_-]*)|i', '[@id=\'$1\']', $expression);
$expression = preg_replace('|(?<![a-z0-9_-])(\[@id=)|i', '*$1', $expression);
// arbitrary attribute strict equality
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[@" . strtolower($matches[2]) . "=\'" . $matches[3] . "\']";'
),
$expression
);
}
// arbitrary attribute contains full word
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)~=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)~=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[contains(@" . strtolower($matches[2]) . ", \' $matches[3] \')]";'
),
$expression
);
}
// arbitrary attribute contains specified content
if (preg_match('|([a-z]+)\[([a-z0-9_-]+)\*=[\'"]([^\'"]+)[\'"]\]|i', $expression)) {
$expression = preg_replace_callback(
'|([a-z]+)\[([a-z0-9_-]+)\*=[\'"]([^\'"]+)[\'"]\]|i',
create_function(
'$matches',
'return $matches[1] . "[contains(@" . strtolower($matches[2]) . ", \'" . $matches[3] . "\')]";'
),
$expression
);
}
// Classes
$expression = preg_replace('|\.([a-z][a-z0-9_-]*)|i', "[contains(@class, ' \$1 ')]", $expression);
return $expression;
}
}
PK pG[% �Z� � Dom/Query/Result.phpnu &1i� <?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_Dom
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Results for DOM XPath query
*
* @package Zend_Dom
* @subpackage Query
* @uses Iterator
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: Result.php 12507 2008-11-10 16:29:09Z matthew $
*/
class Zend_Dom_Query_Result implements Iterator,Countable
{
/**
* Number of results
* @var int
*/
protected $_count;
/**
* CSS Selector query
* @var string
*/
protected $_cssQuery;
/**
* @var DOMDocument
*/
protected $_document;
/**
* @var DOMNodeList
*/
protected $_nodeList;
/**
* Current iterator position
* @var int
*/
protected $_position = 0;
/**
* @var DOMXPath
*/
protected $_xpath;
/**
* XPath query
* @var string
*/
protected $_xpathQuery;
/**
* Constructor
*
* @param string $cssQuery
* @param string|array $xpathQuery
* @param DOMDocument $document
* @param DOMNodeList $nodeList
* @return void
*/
public function __construct($cssQuery, $xpathQuery, DOMDocument $document, DOMNodeList $nodeList)
{
$this->_cssQuery = $cssQuery;
$this->_xpathQuery = $xpathQuery;
$this->_document = $document;
$this->_nodeList = $nodeList;
}
/**
* Retrieve CSS Query
*
* @return string
*/
public function getCssQuery()
{
return $this->_cssQuery;
}
/**
* Retrieve XPath query
*
* @return string
*/
public function getXpathQuery()
{
return $this->_xpathQuery;
}
/**
* Retrieve DOMDocument
*
* @return DOMDocument
*/
public function getDocument()
{
return $this->_document;
}
/**
* Iterator: rewind to first element
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
return $this->_nodeList->item(0);
}
/**
* Iterator: is current position valid?
*
* @return bool
*/
public function valid()
{
if (in_array($this->_position, range(0, $this->_nodeList->length - 1)) && $this->_nodeList->length > 0) {
return true;
}
return false;
}
/**
* Iterator: return current element
*
* @return DOMElement
*/
public function current()
{
return $this->_nodeList->item($this->_position);
}
/**
* Iterator: return key of current element
*
* @return int
*/
public function key()
{
return $this->_position;
}
/**
* Iterator: move to next element
*
* @return void
*/
public function next()
{
++$this->_position;
return $this->_nodeList->item($this->_position);
}
/**
* Countable: get count
*
* @return int
*/
public function count()
{
return $this->_nodeList->length;
}
}
PK pG[�3$ $ Mail/Message/Interface.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Message_Interface
{
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines();
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag);
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags();
}PK pG[�ZN@S
S
Mail/Message/File.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Message.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* Zend_Mail_Part
*/
require_once 'Zend/Mail/Part/File.php';
/**
* Zend_Mail_Message_Interface
*/
require_once 'Zend/Mail/Message/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 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
{
/**
* flags for this message
* @var array
*/
protected $_flags = array();
/**
* Public constructor
*
* In addition to the parameters of Zend_Mail_Part::__construct() this constructor supports:
* - flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
*
* @param string $rawMessage full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (!empty($params['flags'])) {
// set key and value to the same value for easy lookup
$this->_flags = array_combine($params['flags'], $params['flags']);
}
parent::__construct($params);
}
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines()
{
return $this->_topLines;
}
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag)
{
return isset($this->_flags[$flag]);
}
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags()
{
return $this->_flags;
}
}
PK pG[Z{ƒ� � Mail/Transport/Sendmail.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Sendmail.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Transport_Abstract
*/
require_once 'Zend/Mail/Transport/Abstract.php';
/**
* Class for sending eMails via the PHP internal mail() function
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 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
{
/**
* Subject
* @var string
* @access public
*/
public $subject = null;
/**
* Config options for sendmail parameters
*
* @var string
*/
public $parameters;
/**
* EOL character string
* @var string
* @access public
*/
public $EOL = PHP_EOL;
/**
* Constructor.
*
* @param string $parameters OPTIONAL (Default: null)
* @return void
*/
public function __construct($parameters = null)
{
$this->parameters = $parameters;
}
/**
* Send mail using PHP native mail()
*
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception on mail() failure
*/
public function _sendMail()
{
if ($this->parameters === null) {
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
} else {
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header,
$this->parameters);
}
if (!$result) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Unable to send mail');
}
}
/**
* Format and fix headers
*
* mail() uses its $to and $subject arguments to set the To: and Subject:
* headers, respectively. This method strips those out as a sanity check to
* prevent duplicate header entries.
*
* @access protected
* @param array $headers
* @return void
* @throws Zend_Mail_Transport_Exception
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
// mail() uses its $to parameter to set the To: header, and the $subject
// parameter to set the Subject: header. We need to strip them out.
if (0 === strpos(PHP_OS, 'WIN')) {
// If the current recipients list is empty, throw an error
if (empty($this->recipients)) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To addresses');
}
} else {
// All others, simply grab the recipients and unset the To: header
if (!isset($headers['To'])) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To header');
}
unset($headers['To']['append']);
$this->recipients = implode(',', $headers['To']);
}
// Remove recipient header
unset($headers['To']);
// Remove subject header, if present
if (isset($headers['Subject'])) {
unset($headers['Subject']);
}
// Prepare headers
parent::_prepareHeaders($headers);
}
}
PK pG[]^�F� � Mail/Transport/Exception.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
/**
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 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
{}
PK pG[� ���( �( Mail/Transport/Abstract.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* Abstract for sending eMails through different
* ways of transport
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 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
{
/**
* Mail body
* @var string
* @access public
*/
public $body = '';
/**
* MIME boundary
* @var string
* @access public
*/
public $boundary = '';
/**
* Mail header string
* @var string
* @access public
*/
public $header = '';
/**
* Array of message headers
* @var array
* @access protected
*/
protected $_headers = array();
/**
* Message is a multipart message
* @var boolean
* @access protected
*/
protected $_isMultipart = false;
/**
* Zend_Mail object
* @var false|Zend_Mail
* @access protected
*/
protected $_mail = false;
/**
* Array of message parts
* @var array
* @access protected
*/
protected $_parts = array();
/**
* Recipients string
* @var string
* @access public
*/
public $recipients = '';
/**
* EOL character string used by transport
* @var string
* @access public
*/
public $EOL = "\r\n";
/**
* Send an email independent from the used transport
*
* The requisite information for the email will be found in the following
* properties:
*
* - {@link $recipients} - list of recipients (string)
* - {@link $header} - message header
* - {@link $body} - message body
*/
abstract protected function _sendMail();
/**
* Return all mail headers as an array
*
* If a boundary is given, a multipart header is generated with a
* Content-Type of either multipart/alternative or multipart/mixed depending
* on the mail parts present in the {@link $_mail Zend_Mail object} present.
*
* @param string $boundary
* @return array
*/
protected function _getHeaders($boundary)
{
if (null !== $boundary) {
// Build multipart mail
$type = $this->_mail->getType();
if (!$type) {
if ($this->_mail->hasAttachments) {
$type = Zend_Mime::MULTIPART_MIXED;
} elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) {
$type = Zend_Mime::MULTIPART_ALTERNATIVE;
} else {
$type = Zend_Mime::MULTIPART_MIXED;
}
}
$this->_headers['Content-Type'] = array(
$type . '; charset="' . $this->_mail->getCharset() . '";'
. $this->EOL
. " " . 'boundary="' . $boundary . '"'
);
$this->_headers['MIME-Version'] = array('1.0');
$this->boundary = $boundary;
}
return $this->_headers;
}
/**
* Prepend header name to header value
*
* @param string $item
* @param string $key
* @param string $prefix
* @static
* @access protected
* @return void
*/
protected static function _formatHeader(&$item, $key, $prefix)
{
$item = $prefix . ': ' . $item;
}
/**
* Prepare header string for use in transport
*
* Prepares and generates {@link $header} based on the headers provided.
*
* @param mixed $headers
* @access protected
* @return void
* @throws Zend_Mail_Transport_Exception if any header lines exceed 998
* characters
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing Zend_Mail object in _mail property');
}
$this->header = '';
foreach ($headers as $header => $content) {
if (isset($content['append'])) {
unset($content['append']);
$value = implode(',' . $this->EOL . ' ', $content);
$this->header .= $header . ': ' . $value . $this->EOL;
} else {
array_walk($content, array(get_class($this), '_formatHeader'), $header);
$this->header .= implode($this->EOL, $content) . $this->EOL;
}
}
// Sanity check on headers -- should not be > 998 characters
$sane = true;
foreach (explode($this->EOL, $this->header) as $line) {
if (strlen(trim($line)) > 998) {
$sane = false;
break;
}
}
if (!$sane) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Exception('At least one mail header line is too long');
}
}
/**
* Generate MIME compliant message from the current configuration
*
* If both a text and HTML body are present, generates a
* multipart/alternative Zend_Mime_Part containing the headers and contents
* of each. Otherwise, uses whichever of the text or HTML parts present.
*
* The content part is then prepended to the list of Zend_Mime_Parts for
* this message.
*
* @return void
*/
protected function _buildBody()
{
if (($text = $this->_mail->getBodyText())
&& ($html = $this->_mail->getBodyHtml()))
{
// Generate unique boundary for multipart/alternative
$mime = new Zend_Mime(null);
$boundaryLine = $mime->boundaryLine($this->EOL);
$boundaryEnd = $mime->mimeEnd($this->EOL);
$text->disposition = false;
$html->disposition = false;
$body = $boundaryLine
. $text->getHeaders($this->EOL)
. $this->EOL
. $text->getContent($this->EOL)
. $this->EOL
. $boundaryLine
. $html->getHeaders($this->EOL)
. $this->EOL
. $html->getContent($this->EOL)
. $this->EOL
. $boundaryEnd;
$mp = new Zend_Mime_Part($body);
$mp->type = Zend_Mime::MULTIPART_ALTERNATIVE;
$mp->boundary = $mime->boundary();
$this->_isMultipart = true;
// Ensure first part contains text alternatives
array_unshift($this->_parts, $mp);
// Get headers
$this->_headers = $this->_mail->getHeaders();
return;
}
// If not multipart, then get the body
if (false !== ($body = $this->_mail->getBodyHtml())) {
array_unshift($this->_parts, $body);
} elseif (false !== ($body = $this->_mail->getBodyText())) {
array_unshift($this->_parts, $body);
}
if (!$body) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('No body specified');
}
// Get headers
$this->_headers = $this->_mail->getHeaders();
$headers = $body->getHeadersArray($this->EOL);
foreach ($headers as $header) {
// Headers in Zend_Mime_Part are kept as arrays with two elements, a
// key and a value
$this->_headers[$header[0]] = array($header[1]);
}
}
/**
* Send a mail using this transport
*
* @param Zend_Mail $mail
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception if mail is empty
*/
public function send(Zend_Mail $mail)
{
$this->_isMultipart = false;
$this->_mail = $mail;
$this->_parts = $mail->getParts();
$mime = $mail->getMime();
// Build body content
$this->_buildBody();
// Determine number of parts and boundary
$count = count($this->_parts);
$boundary = null;
if ($count < 1) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Empty mail cannot be sent');
}
if ($count > 1) {
// Multipart message; create new MIME object and boundary
$mime = new Zend_Mime($this->_mail->getMimeBoundary());
$boundary = $mime->boundary();
} elseif ($this->_isMultipart) {
// multipart/alternative -- grab boundary
$boundary = $this->_parts[0]->boundary;
}
// Determine recipients, and prepare headers
$this->recipients = implode(',', $mail->getRecipients());
$this->_prepareHeaders($this->_getHeaders($boundary));
// Create message body
// This is done so that the same Zend_Mail object can be used in
// multiple transports
$message = new Zend_Mime_Message();
$message->setParts($this->_parts);
$message->setMime($mime);
$this->body = $message->generateMessage($this->EOL);
// Send to transport!
$this->_sendMail();
}
}
PK pG[(x�a� � Mail/Transport/Smtp.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Smtp.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* @see Zend_Mail_Transport_Abstract
*/
require_once 'Zend/Mail/Transport/Abstract.php';
/**
* SMTP connection object
*
* Loads an instance of Zend_Mail_Protocol_Smtp and forwards smtp transactions
*
* @category Zend
* @package Zend_Mail
* @subpackage Transport
* @copyright Copyright (c) 2005-2008 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
{
/**
* EOL character string used by transport
* @var string
* @access public
*/
public $EOL = "\n";
/**
* Remote smtp hostname or i.p.
*
* @var string
*/
protected $_host;
/**
* Port number
*
* @var integer|null
*/
protected $_port;
/**
* Local client hostname or i.p.
*
* @var string
*/
protected $_name = 'localhost';
/**
* Authentication type OPTIONAL
*
* @var string
*/
protected $_auth;
/**
* Config options for authentication
*
* @var array
*/
protected $_config;
/**
* Instance of Zend_Mail_Protocol_Smtp
*
* @var Zend_Mail_Protocol_Smtp
*/
protected $_connection;
/**
* Constructor.
*
* @param string $host OPTIONAL (Default: 127.0.0.1)
* @param array|null $config OPTIONAL (Default: null)
* @return void
*/
public function __construct($host = '127.0.0.1', Array $config = array())
{
if (isset($config['name'])) {
$this->_name = $config['name'];
}
if (isset($config['port'])) {
$this->_port = $config['port'];
}
if (isset($config['auth'])) {
$this->_auth = $config['auth'];
}
$this->_host = $host;
$this->_config = $config;
}
/**
* Class destructor to ensure all open connections are closed
*
* @return void
*/
public function __destruct()
{
if ($this->_connection instanceof Zend_Mail_Protocol_Smtp) {
try {
$this->_connection->quit();
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore
}
$this->_connection->disconnect();
}
}
/**
* Sets the connection protocol instance
*
* @param Zend_Mail_Protocol_Abstract $client
*
* @return void
*/
public function setConnection(Zend_Mail_Protocol_Abstract $connection)
{
$this->_connection = $connection;
}
/**
* Gets the connection protocol instance
*
* @return Zend_Mail_Protocol|null
*/
public function getConnection()
{
return $this->_connection;
}
/**
* Send an email via the SMTP connection protocol
*
* The connection via the protocol adapter is made just-in-time to allow a
* developer to add a custom adapter if required before mail is sent.
*
* @return void
*/
public function _sendMail()
{
// If sending multiple messages per session use existing adapter
if (!($this->_connection instanceof Zend_Mail_Protocol_Smtp)) {
// Check if authentication is required and determine required class
$connectionClass = 'Zend_Mail_Protocol_Smtp';
if ($this->_auth) {
$connectionClass .= '_Auth_' . ucwords($this->_auth);
}
Zend_Loader::loadClass($connectionClass);
$this->setConnection(new $connectionClass($this->_host, $this->_port, $this->_config));
$this->_connection->connect();
$this->_connection->helo($this->_name);
} else {
// Reset connection to ensure reliable transaction
$this->_connection->rset();
}
// Set mail return path from sender email address
$this->_connection->mail($this->_mail->getReturnPath());
// Set recipient forward paths
foreach ($this->_mail->getRecipients() as $recipient) {
$this->_connection->rcpt($recipient);
}
// Issue DATA command to client
$this->_connection->data($this->header . Zend_Mime::LINEEND . $this->body);
}
/**
* Format and fix headers
*
* Some SMTP servers do not strip BCC headers. Most clients do it themselves as do we.
*
* @access protected
* @param array $headers
* @return void
* @throws Zend_Transport_Exception
*/
protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
unset($headers['Bcc']);
// Prepare headers
parent::_prepareHeaders($headers);
}
}
PK pG[--�� � Mail/Message.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Message.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* Zend_Mail_Part
*/
require_once 'Zend/Mail/Part.php';
/**
* Zend_Mail_Message_Interface
*/
require_once 'Zend/Mail/Message/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 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
{
/**
* flags for this message
* @var array
*/
protected $_flags = array();
/**
* Public constructor
*
* In addition to the parameters of Zend_Mail_Part::__construct() this constructor supports:
* - file filename or file handle of a file with raw message content
* - flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
*
* @param string $rawMessage full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (isset($params['file'])) {
if (!is_resource($params['file'])) {
$params['raw'] = @file_get_contents($params['file']);
if ($params['raw'] === false) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('could not open file');
}
} else {
$params['raw'] = stream_get_contents($params['file']);
}
}
if (!empty($params['flags'])) {
// set key and value to the same value for easy lookup
$this->_flags = array_combine($params['flags'], $params['flags']);
}
parent::__construct($params);
}
/**
* return toplines as found after headers
*
* @return string toplines
*/
public function getTopLines()
{
return $this->_topLines;
}
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag)
{
return isset($this->_flags[$flag]);
}
/**
* get all set flags
*
* @return array array with flags, key and value are the same for easy lookup
*/
public function getFlags()
{
return $this->_flags;
}
}
PK pG[w2-+ + Mail/Part/File.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Part.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mime_Decode
*/
require_once 'Zend/Mime/Decode.php';
/**
* @see Zend_Mail_Part
*/
require_once 'Zend/Mail/Part.php';
/**
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 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
{
protected $_contentPos = array();
protected $_partPos = array();
protected $_fh;
/**
* Public constructor
*
* This handler supports the following params:
* - file filename or open file handler with message content (required)
* - startPos start position of message or part in file (default: current position)
* - endPos end position of message or part in file (default: end of file)
*
* @param array $params full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (empty($params['file'])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no file given in params');
}
if (!is_resource($params['file'])) {
$this->_fh = fopen($params['file'], 'r');
} else {
$this->_fh = $params['file'];
}
if (!$this->_fh) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('could not open file');
}
if (isset($params['startPos'])) {
fseek($this->_fh, $params['startPos']);
}
$header = '';
$endPos = isset($params['endPos']) ? $params['endPos'] : null;
while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) {
$header .= $line;
}
Zend_Mime_Decode::splitMessage($header, $this->_headers, $null);
$this->_contentPos[0] = ftell($this->_fh);
if ($endPos !== null) {
$this->_contentPos[1] = $endPos;
} else {
fseek($this->_fh, 0, SEEK_END);
$this->_contentPos[1] = ftell($this->_fh);
}
if (!$this->isMultipart()) {
return;
}
$boundary = $this->getHeaderField('content-type', 'boundary');
if (!$boundary) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no boundary found in content type to split message');
}
$part = array();
$pos = $this->_contentPos[0];
fseek($this->_fh, $pos);
while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) {
$line = fgets($this->_fh);
if ($line === false) {
if (feof($this->_fh)) {
break;
}
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('error reading file');
}
$lastPos = $pos;
$pos = ftell($this->_fh);
$line = trim($line);
if ($line == '--' . $boundary) {
if ($part) {
// not first part
$part[1] = $lastPos;
$this->_partPos[] = $part;
}
$part = array($pos);
} else if ($line == '--' . $boundary . '--') {
$part[1] = $lastPos;
$this->_partPos[] = $part;
break;
}
}
$this->_countParts = count($this->_partPos);
}
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent($stream = null)
{
fseek($this->_fh, $this->_contentPos[0]);
if ($stream !== null) {
return stream_copy_to_stream($this->_fh, $stream, $this->_contentPos[1] - $this->_contentPos[0]);
}
$length = $this->_contentPos[1] - $this->_contentPos[0];
return $length < 1 ? '' : fread($this->_fh, $length);
}
/**
* Return size of part
*
* Quite simple implemented currently (not decoding). Handle with care.
*
* @return int size
*/
public function getSize() {
return $this->_contentPos[1] - $this->_contentPos[0];
}
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num)
{
--$num;
if (!isset($this->_partPos[$num])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
return new self(array('file' => $this->_fh, 'startPos' => $this->_partPos[$num][0],
'endPos' => $this->_partPos[$num][1]));
}
}
PK pG[�rL\� � Mail/Part/Interface.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Storage
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Mail_Part_Interface extends RecursiveIterator
{
/**
* Check if part is a multipart message
*
* @return bool if part is multipart
*/
public function isMultipart();
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent();
/**
* Return size of part
*
* @return int size
*/
public function getSize();
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num);
/**
* Count parts of a multipart part
*
* @return int number of sub-parts
*/
public function countParts();
/**
* Get all headers
*
* The returned headers are as saved internally. All names are lowercased. The value is a string or an array
* if a header with the same name occurs more than once.
*
* @return array headers as array(name => value)
*/
public function getHeaders();
/**
* Get a header in specificed format
*
* Internally headers that occur more than once are saved as array, all other as string. If $format
* is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim).
*
* @param string $name name of header, matches case-insensitive, but camel-case is replaced with dashes
* @param string $format change type of return value to 'string' or 'array'
* @return string|array value of header in wanted or internal format
* @throws Zend_Mail_Exception
*/
public function getHeader($name, $format = null);
/**
* Get a specific field from a header like content type or all fields as array
*
* If the header occurs more than once, only the value from the first header
* is returned.
*
* Throws a Zend_Mail_Exception if the requested header does not exist. If
* the specific header field does not exist, returns null.
*
* @param string $name name of header, like in getHeader()
* @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned
* @param string $firstName key name for the first part
* @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
* @throws Zend_Exception, Zend_Mail_Exception
*/
public function getHeaderField($name, $wantedPart = 0, $firstName = 0);
/**
* Getter for mail headers - name is matched in lowercase
*
* This getter is short for Zend_Mail_Part::getHeader($name, 'string')
*
* @see Zend_Mail_Part::getHeader()
*
* @param string $name header name
* @return string value of header
* @throws Zend_Mail_Exception
*/
public function __get($name);
/**
* magic method to get content of part
*
* @return string content
*/
public function __toString();
}PK pG[�&�nm m Mail/Storage.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Storage.php 9099 2008-03-30 19:35:47Z thomas $
*/
/**
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Mail_Storage
{
// maildir and IMAP flags, using IMAP names, where possible to be able to distinguish between IMAP
// system flags and other flags
const FLAG_PASSED = 'Passed';
const FLAG_SEEN = '\Seen';
const FLAG_ANSWERED = '\Answered';
const FLAG_FLAGGED = '\Flagged';
const FLAG_DELETED = '\Deleted';
const FLAG_DRAFT = '\Draft';
const FLAG_RECENT = '\Recent';
}
PK pG[���Y5 Y5
Mail/Part.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Part.php 12519 2008-11-10 18:41:24Z alexander $
*/
/**
* @see Zend_Mime_Decode
*/
require_once 'Zend/Mime/Decode.php';
/**
* @see Zend_Mail_Part_Interface
*/
require_once 'Zend/Mail/Part/Interface.php';
/**
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2008 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
{
/**
* headers of part as array
* @var null|array
*/
protected $_headers;
/**
* raw part body
* @var null|string
*/
protected $_content;
/**
* toplines as fetched with headers
* @var string
*/
protected $_topLines = '';
/**
* parts of multipart message
* @var array
*/
protected $_parts = array();
/**
* count of parts of a multipart message
* @var null|int
*/
protected $_countParts;
/**
* current position of iterator
* @var int
*/
protected $_iterationPos = 1;
/**
* mail handler, if late fetch is active
* @var null|Zend_Mail_Storage_Abstract
*/
protected $_mail;
/**
* message number for mail handler
* @var int
*/
protected $_messageNum = 0;
/**
* Public constructor
*
* Zend_Mail_Part supports different sources for content. The possible params are:
* - handler a instance of Zend_Mail_Storage_Abstract for late fetch
* - id number of message for handler
* - raw raw content with header and body as string
* - headers headers as array (name => value) or string, if a content part is found it's used as toplines
* - noToplines ignore content found after headers in param 'headers'
* - content content as string
*
* @param array $params full message with or without headers
* @throws Zend_Mail_Exception
*/
public function __construct(array $params)
{
if (isset($params['handler'])) {
if (!$params['handler'] instanceof Zend_Mail_Storage_Abstract) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('handler is not a valid mail handler');
}
if (!isset($params['id'])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('need a message id with a handler');
}
$this->_mail = $params['handler'];
$this->_messageNum = $params['id'];
}
if (isset($params['raw'])) {
Zend_Mime_Decode::splitMessage($params['raw'], $this->_headers, $this->_content);
} else if (isset($params['headers'])) {
if (is_array($params['headers'])) {
$this->_headers = $params['headers'];
} else {
if (!empty($params['noToplines'])) {
Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $null);
} else {
Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $this->_topLines);
}
}
if (isset($params['content'])) {
$this->_content = $params['content'];
}
}
}
/**
* Check if part is a multipart message
*
* @return bool if part is multipart
*/
public function isMultipart()
{
try {
return stripos($this->contentType, 'multipart/') === 0;
} catch(Zend_Mail_Exception $e) {
return false;
}
}
/**
* Body of part
*
* If part is multipart the raw content of this part with all sub parts is returned
*
* @return string body
* @throws Zend_Mail_Exception
*/
public function getContent()
{
if ($this->_content !== null) {
return $this->_content;
}
if ($this->_mail) {
return $this->_mail->getRawContent($this->_messageNum);
} else {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no content');
}
}
/**
* Return size of part
*
* Quite simple implemented currently (not decoding). Handle with care.
*
* @return int size
*/
public function getSize() {
return strlen($this->getContent());
}
/**
* Cache content and split in parts if multipart
*
* @return null
* @throws Zend_Mail_Exception
*/
protected function _cacheContent()
{
// caching content if we can't fetch parts
if ($this->_content === null && $this->_mail) {
$this->_content = $this->_mail->getRawContent($this->_messageNum);
}
if (!$this->isMultipart()) {
return;
}
// split content in parts
$boundary = $this->getHeaderField('content-type', 'boundary');
if (!$boundary) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('no boundary found in content type to split message');
}
$parts = Zend_Mime_Decode::splitMessageStruct($this->_content, $boundary);
if ($parts === null) {
return;
}
$counter = 1;
foreach ($parts as $part) {
$this->_parts[$counter++] = new self(array('headers' => $part['header'], 'content' => $part['body']));
}
}
/**
* Get part of multipart message
*
* @param int $num number of part starting with 1 for first part
* @return Zend_Mail_Part wanted part
* @throws Zend_Mail_Exception
*/
public function getPart($num)
{
if (isset($this->_parts[$num])) {
return $this->_parts[$num];
}
if (!$this->_mail && $this->_content === null) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
if ($this->_mail && $this->_mail->hasFetchPart) {
// TODO: fetch part
// return
}
$this->_cacheContent();
if (!isset($this->_parts[$num])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('part not found');
}
return $this->_parts[$num];
}
/**
* Count parts of a multipart part
*
* @return int number of sub-parts
*/
public function countParts()
{
if ($this->_countParts) {
return $this->_countParts;
}
$this->_countParts = count($this->_parts);
if ($this->_countParts) {
return $this->_countParts;
}
if ($this->_mail && $this->_mail->hasFetchPart) {
// TODO: fetch part
// return
}
$this->_cacheContent();
$this->_countParts = count($this->_parts);
return $this->_countParts;
}
/**
* Get all headers
*
* The returned headers are as saved internally. All names are lowercased. The value is a string or an array
* if a header with the same name occurs more than once.
*
* @return array headers as array(name => value)
*/
public function getHeaders()
{
if ($this->_headers === null) {
if (!$this->_mail) {
$this->_headers = array();
} else {
$part = $this->_mail->getRawHeader($this->_messageNum);
Zend_Mime_Decode::splitMessage($part, $this->_headers, $null);
}
}
return $this->_headers;
}
/**
* Get a header in specificed format
*
* Internally headers that occur more than once are saved as array, all other as string. If $format
* is set to string implode is used to concat the values (with Zend_Mime::LINEEND as delim).
*
* @param string $name name of header, matches case-insensitive, but camel-case is replaced with dashes
* @param string $format change type of return value to 'string' or 'array'
* @return string|array value of header in wanted or internal format
* @throws Zend_Mail_Exception
*/
public function getHeader($name, $format = null)
{
if ($this->_headers === null) {
$this->getHeaders();
}
$lowerName = strtolower($name);
if (!isset($this->_headers[$lowerName])) {
$lowerName = strtolower(preg_replace('%([a-z])([A-Z])%', '\1-\2', $name));
if (!isset($this->_headers[$lowerName])) {
/**
* @see Zend_Mail_Exception
*/
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception("no Header with Name $name found");
}
}
$name = $lowerName;
$header = $this->_headers[$name];
switch ($format) {
case 'string':
if (is_array($header)) {
$header = implode(Zend_Mime::LINEEND, $header);
}
break;
case 'array':
$header = (array)$header;
default:
// do nothing
}
return $header;
}
/**
* Get a specific field from a header like content type or all fields as array
*
* If the header occurs more than once, only the value from the first header
* is returned.
*
* Throws a Zend_Mail_Exception if the requested header does not exist. If
* the specific header field does not exist, returns null.
*
* @param string $name name of header, like in getHeader()
* @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned
* @param string $firstName key name for the first part
* @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
* @throws Zend_Exception, Zend_Mail_Exception
*/
public function getHeaderField($name, $wantedPart = 0, $firstName = 0) {
return Zend_Mime_Decode::splitHeaderField(current($this->getHeader($name, 'array')), $wantedPart, $firstName);
}
/**
* Getter for mail headers - name is matched in lowercase
*
* This getter is short for Zend_Mail_Part::getHeader($name, 'string')
*
* @see Zend_Mail_Part::getHeader()
*
* @param string $name header name
* @return string value of header
* @throws Zend_Mail_Exception
*/
public function __get($name)
{
return $this->getHeader($name, 'string');
}
/**
* magic method to get content of part
*
* @return string content
*/
public function __toString()
{
return $this->getContent();
}
/**
* implements RecursiveIterator::hasChildren()
*
* @return bool current element has children/is multipart
*/
public function hasChildren()
{
$current = $this->current();
return $current && $current instanceof Zend_Mail_Part && $current->isMultipart();
}
/**
* implements RecursiveIterator::getChildren()
*
* @return Zend_Mail_Part same as self::current()
*/
public function getChildren()
{
return $this->current();
}
/**
* implements Iterator::valid()
*
* @return bool check if there's a current element
*/
public function valid()
{
if ($this->_countParts === null) {
$this->countParts();
}
return $this->_iterationPos && $this->_iterationPos <= $this->_countParts;
}
/**
* implements Iterator::next()
*
* @return null
*/
public function next()
{
++$this->_iterationPos;
}
/**
* implements Iterator::key()
*
* @return string key/number of current part
*/
public function key()
{
return $this->_iterationPos;
}
/**
* implements Iterator::current()
*
* @return Zend_Mail_Part current part
*/
public function current()
{
return $this->getPart($this->_iterationPos);
}
/**
* implements Iterator::rewind()
*
* @return null
*/
public function rewind()
{
$this->countParts();
$this->_iterationPos = 1;
}
}
PK pG[�]z�2 �2 Mail/Protocol/Pop3.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Pop3.php 12539 2008-11-11 02:47:17Z yoshida@zend.co.jp $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Mail_Protocol_Pop3
{
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
/**
* saves if server supports top
* @var null|bool
*/
public $hasTop = null;
/**
* socket to pop3
* @var null|resource
*/
protected $_socket;
/**
* greeting timestamp for apop
* @var null|string
*/
protected $_timestamp;
/**
* Public constructor
*
* @param string $host hostname of IP address of POP3 server, if given connect() is called
* @param int|null $port port of POP3 server, null for default (110 or 995 for ssl)
* @param bool|string $ssl use ssl? 'SSL', 'TLS' or false
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($host = '', $port = null, $ssl = false)
{
if ($host) {
$this->connect($host, $port, $ssl);
}
}
/**
* Public destructor
*/
public function __destruct()
{
$this->logout();
}
/**
* Open connection to POP3 server
*
* @param string $host hostname of IP address of POP3 server
* @param int|null $port of POP3 server, default is 110 (995 for ssl)
* @param string|bool $ssl use 'SSL', 'TLS' or false
* @return string welcome message
* @throws Zend_Mail_Protocol_Exception
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
}
if ($port === null) {
$port = $ssl == 'SSL' ? 995 : 110;
}
$errno = 0;
$errstr = '';
$this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
if (!$this->_socket) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot connect to host : ' . $errno . ' : ' . $errstr);
}
$welcome = $this->readResponse();
strtok($welcome, '<');
$this->_timestamp = strtok('>');
if (!strpos($this->_timestamp, '@')) {
$this->_timestamp = null;
} else {
$this->_timestamp = '<' . $this->_timestamp . '>';
}
if ($ssl === 'TLS') {
$this->request('STLS');
$result = stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot enable TLS');
}
}
return $welcome;
}
/**
* Send a request
*
* @param string $request your request without newline
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function sendRequest($request)
{
$result = @fputs($this->_socket, $request . "\r\n");
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('send failed - connection closed?');
}
}
/**
* read a response
*
* @param boolean $multiline response has multiple lines and should be read until "<nl>.<nl>"
* @return string response
* @throws Zend_Mail_Protocol_Exception
*/
public function readResponse($multiline = false)
{
$result = @fgets($this->_socket);
if (!is_string($result)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('read failed - connection closed?');
}
$result = trim($result);
if (strpos($result, ' ')) {
list($status, $message) = explode(' ', $result, 2);
} else {
$status = $result;
$message = '';
}
if ($status != '+OK') {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('last request failed');
}
if ($multiline) {
$message = '';
$line = fgets($this->_socket);
while ($line && rtrim($line, "\r\n") != '.') {
if ($line[0] == '.') {
$line = substr($line, 1);
}
$message .= $line;
$line = fgets($this->_socket);
};
}
return $message;
}
/**
* Send request and get resposne
*
* @see sendRequest(), readResponse()
*
* @param string $request request
* @param bool $multiline multiline response?
* @return string result from readResponse()
* @throws Zend_Mail_Protocol_Exception
*/
public function request($request, $multiline = false)
{
$this->sendRequest($request);
return $this->readResponse($multiline);
}
/**
* End communication with POP3 server (also closes socket)
*
* @return null
*/
public function logout()
{
if (!$this->_socket) {
return;
}
try {
$this->request('QUIT');
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore error - we're closing the socket anyway
}
fclose($this->_socket);
$this->_socket = null;
}
/**
* Get capabilities from POP3 server
*
* @return array list of capabilities
* @throws Zend_Mail_Protocol_Exception
*/
public function capa()
{
$result = $this->request('CAPA', true);
return explode("\n", $result);
}
/**
* Login to POP3 server. Can use APOP
*
* @param string $user username
* @param string $password password
* @param bool $try_apop should APOP be tried?
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function login($user, $password, $tryApop = true)
{
if ($tryApop && $this->_timestamp) {
try {
$this->request("APOP $user " . md5($this->_timestamp . $password));
return;
} catch (Zend_Mail_Protocol_Exception $e) {
// ignore
}
}
$result = $this->request("USER $user");
$result = $this->request("PASS $password");
}
/**
* Make STAT call for message count and size sum
*
* @param int $messages out parameter with count of messages
* @param int $octets out parameter with size in octects of messages
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function status(&$messages, &$octets)
{
$messages = 0;
$octets = 0;
$result = $this->request('STAT');
list($messages, $octets) = explode(' ', $result);
}
/**
* Make LIST call for size of message(s)
*
* @param int|null $msgno number of message, null for all
* @return int|array size of given message or list with array(num => size)
* @throws Zend_Mail_Protocol_Exception
*/
public function getList($msgno = null)
{
if ($msgno !== null) {
$result = $this->request("LIST $msgno");
list(, $result) = explode(' ', $result);
return (int)$result;
}
$result = $this->request('LIST', true);
$messages = array();
$line = strtok($result, "\n");
while ($line) {
list($no, $size) = explode(' ', trim($line));
$messages[(int)$no] = (int)$size;
$line = strtok("\n");
}
return $messages;
}
/**
* Make UIDL call for getting a uniqueid
*
* @param int|null $msgno number of message, null for all
* @return string|array uniqueid of message or list with array(num => uniqueid)
* @throws Zend_Mail_Protocol_Exception
*/
public function uniqueid($msgno = null)
{
if ($msgno !== null) {
$result = $this->request("UIDL $msgno");
list(, $result) = explode(' ', $result);
return $result;
}
$result = $this->request('UIDL', true);
$result = explode("\n", $result);
$messages = array();
foreach ($result as $line) {
if (!$line) {
continue;
}
list($no, $id) = explode(' ', trim($line), 2);
$messages[(int)$no] = $id;
}
return $messages;
}
/**
* Make TOP call for getting headers and maybe some body lines
* This method also sets hasTop - before it it's not known if top is supported
*
* The fallback makes normale RETR call, which retrieves the whole message. Additional
* lines are not removed.
*
* @param int $msgno number of message
* @param int $lines number of wanted body lines (empty line is inserted after header lines)
* @param bool $fallback fallback with full retrieve if top is not supported
* @return string message headers with wanted body lines
* @throws Zend_Mail_Protocol_Exception
*/
public function top($msgno, $lines = 0, $fallback = false)
{
if ($this->hasTop === false) {
if ($fallback) {
return $this->retrieve($msgno);
} else {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('top not supported and no fallback wanted');
}
}
$this->hasTop = true;
$lines = (!$lines || $lines < 1) ? 0 : (int)$lines;
try {
$result = $this->request("TOP $msgno $lines", true);
} catch (Zend_Mail_Protocol_Exception $e) {
$this->hasTop = false;
if ($fallback) {
$result = $this->retrieve($msgno);
} else {
throw $e;
}
}
return $result;
}
/**
* Make a RETR call for retrieving a full message with headers and body
*
* @deprecated since 1.1.0; this method has a typo - please use retrieve()
* @param int $msgno message number
* @return string message
* @throws Zend_Mail_Protocol_Exception
*/
public function retrive($msgno)
{
return $this->retrieve($msgno);
}
/**
* Make a RETR call for retrieving a full message with headers and body
*
* @param int $msgno message number
* @return string message
* @throws Zend_Mail_Protocol_Exception
*/
public function retrieve($msgno)
{
$result = $this->request("RETR $msgno", true);
return $result;
}
/**
* Make a NOOP call, maybe needed for keeping the server happy
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function noop()
{
$this->request('NOOP');
}
/**
* Make a DELE count to remove a message
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function delete($msgno)
{
$this->request("DELE $msgno");
}
/**
* Make RSET call, which rollbacks delete requests
*
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function undelete()
{
$this->request('RSET');
}
}
PK pG[4<�� � ! Mail/Protocol/Smtp/Auth/Login.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Login.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs LOGIN authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 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
{
/**
* LOGIN username
*
* @var string
*/
protected $_username;
/**
* LOGIN password
*
* @var string
*/
protected $_password;
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* Perform LOGIN authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH LOGIN');
$this->_expect(334);
$this->_send(base64_encode($this->_username));
$this->_expect(334);
$this->_send(base64_encode($this->_password));
$this->_expect(235);
$this->_auth = true;
}
}
PK pG[�9��[ [ # Mail/Protocol/Smtp/Auth/Crammd5.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Crammd5.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs CRAM-MD5 authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 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
{
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* @todo Perform CRAM-MD5 authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH CRAM-MD5');
$challenge = $this->_expect(334);
$challenge = base64_decode($challenge);
$digest = $this->_hmacMd5($this->_password, $challenge);
$this->_send(base64_encode($this->_username . ' ' . $digest));
$this->_expect(235);
$this->_auth = true;
}
/**
* Prepare CRAM-MD5 response to server's ticket
*
* @param string $key Challenge key (usually password)
* @param string $data Challenge data
* @param string $block Length of blocks
* @return string
*/
protected function _hmacMd5($key, $data, $block = 64)
{
if (strlen($key) > 64) {
$key = pack('H32', md5($key));
} elseif (strlen($key) < 64) {
$key = str_pad($key, $block, chr(0));
}
$k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
$inner = pack('H32', md5($k_ipad . $data));
$digest = md5($k_opad . $inner);
return $digest;
}
}
PK pG[�OmЩ � ! Mail/Protocol/Smtp/Auth/Plain.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Plain.php 8064 2008-02-16 10:58:39Z thomas $
*/
/**
* @see Zend_Mail_Protocol_Smtp
*/
require_once 'Zend/Mail/Protocol/Smtp.php';
/**
* Performs PLAIN authentication
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 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
{
/**
* PLAIN username
*
* @var string
*/
protected $_username;
/**
* PLAIN password
*
* @var string
*/
protected $_password;
/**
* Constructor.
*
* @param string $host (Default: 127.0.0.1)
* @param int $port (Default: null)
* @param array $config Auth-specific parameters
* @return void
*/
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (is_array($config)) {
if (isset($config['username'])) {
$this->_username = $config['username'];
}
if (isset($config['password'])) {
$this->_password = $config['password'];
}
}
parent::__construct($host, $port, $config);
}
/**
* Perform PLAIN authentication with supplied credentials
*
* @return void
*/
public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH PLAIN');
$this->_expect(334);
$this->_send(base64_encode(chr(0) . $this->_username . chr(0) . $this->_password));
$this->_expect(235);
$this->_auth = true;
}
}
PK pG[!�Ӈg. g. Mail/Protocol/Smtp.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Smtp.php 11196 2008-09-02 00:56:25Z yoshida@zend.co.jp $
*/
/**
* @see Zend_Mime
*/
require_once 'Zend/Mime.php';
/**
* @see Zend_Mail_Protocol_Abstract
*/
require_once 'Zend/Mail/Protocol/Abstract.php';
/**
* Smtp implementation of Zend_Mail_Protocol_Abstract
*
* Minimum implementation according to RFC2821: EHLO, MAIL FROM, RCPT TO, DATA, RSET, NOOP, QUIT
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 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
{
/**
* The transport method for the socket
*
* @var string
*/
protected $_transport = 'tcp';
/**
* Indicates that a session is requested to be secure
*
* @var string
*/
protected $_secure;
/**
* Indicates an smtp session has been started by the HELO command
*
* @var boolean
*/
protected $_sess = false;
/**
* Indicates the HELO command has been issues
*
* @var unknown_type
*/
protected $_helo = false;
/**
* Indicates an smtp AUTH has been issued and authenticated
*
* @var unknown_type
*/
protected $_auth = false;
/**
* Indicates a MAIL command has been issued
*
* @var unknown_type
*/
protected $_mail = false;
/**
* Indicates one or more RCTP commands have been issued
*
* @var unknown_type
*/
protected $_rcpt = false;
/**
* Indicates that DATA has been issued and sent
*
* @var unknown_type
*/
protected $_data = null;
/**
* Constructor.
*
* @param string $host
* @param integer $port
* @param array $config
* @return void
* @throws Zend_Mail_Protocol_Exception
*/
public function __construct($host = '127.0.0.1', $port = null, array $config = array())
{
if (isset($config['ssl'])) {
switch (strtolower($config['ssl'])) {
case 'tls':
$this->_secure = 'tls';
break;
case 'ssl':
$this->_transport = 'ssl';
$this->_secure = 'ssl';
if ($port == null) {
$port = 465;
}
break;
default:
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($config['ssl'] . ' is unsupported SSL type');
break;
}
}
// If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null.
if ($port == null) {
if (($port = ini_get('smtp_port')) == '') {
$port = 25;
}
}
parent::__construct($host, $port);
}
/**
* Connect to the server with the parameters given in the constructor.
*
* @return boolean
*/
public function connect()
{
return $this->_connect($this->_transport . '://' . $this->_host . ':'. $this->_port);
}
/**
* Initiate HELO/EHLO sequence and set flag to indicate valid smtp session
*
* @param string $host The client hostname or IP address (default: 127.0.0.1)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function helo($host = '127.0.0.1')
{
// Respect RFC 2821 and disallow HELO attempts if session is already initiated.
if ($this->_sess === true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Cannot issue HELO to existing session');
}
// Validate client hostname
if (!$this->_validHost->isValid($host)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
}
// Initiate helo sequence
$this->_expect(220, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_ehlo($host);
// If a TLS session is required, commence negotiation
if ($this->_secure == 'tls') {
$this->_send('STARTTLS');
$this->_expect(220, 180);
if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Unable to connect via TLS');
}
$this->_ehlo($host);
}
$this->_startSession();
$this->auth();
}
/**
* Send EHLO or HELO depending on capabilities of smtp host
*
* @param string $host The client hostname or IP address (default: 127.0.0.1)
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
protected function _ehlo($host)
{
// Support for older, less-compliant remote servers. Tries multiple attempts of EHLO or HELO.
try {
$this->_send('EHLO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
} catch (Zend_Mail_Protocol_Exception $e) {
$this->_send('HELO ' . $host);
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
} catch (Zend_Mail_Protocol_Exception $e) {
throw $e;
}
}
/**
* Issues MAIL command
*
* @param string $from Sender mailbox
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function mail($from)
{
if ($this->_sess !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('A valid session has not been started');
}
$this->_send('MAIL FROM:<' . $from . '>');
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
// Set mail to true, clear recipients and any existing data flags as per 4.1.1.2 of RFC 2821
$this->_mail = true;
$this->_rcpt = false;
$this->_data = false;
}
/**
* Issues RCPT command
*
* @param string $to Receiver(s) mailbox
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function rcpt($to)
{
if ($this->_mail !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No sender reverse path has been supplied');
}
// Set rcpt to true, as per 4.1.1.3 of RFC 2821
$this->_send('RCPT TO:<' . $to . '>');
$this->_expect(array(250, 251), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_rcpt = true;
}
/**
* Issues DATA command
*
* @param string $data
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function data($data)
{
// Ensure recipients have been set
if ($this->_rcpt !== true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('No recipient forward path has been supplied');
}
$this->_send('DATA');
$this->_expect(354, 120); // Timeout set for 2 minutes as per RFC 2821 4.5.3.2
foreach (explode(Zend_Mime::LINEEND, $data) as $line) {
if (strpos($line, '.') === 0) {
// Escape lines prefixed with a '.'
$line = '.' . $line;
}
$this->_send($line);
}
$this->_send('.');
$this->_expect(250, 600); // Timeout set for 10 minutes as per RFC 2821 4.5.3.2
$this->_data = true;
}
/**
* Issues the RSET command end validates answer
*
* Can be used to restore a clean smtp communication state when a transaction has been cancelled or commencing a new transaction.
*
* @return void
*/
public function rset()
{
$this->_send('RSET');
// MS ESMTP doesn't follow RFC, see [ZF-1377]
$this->_expect(array(250, 220));
$this->_mail = false;
$this->_rcpt = false;
$this->_data = false;
}
/**
* Issues the NOOP command end validates answer
*
* Not used by Zend_Mail, could be used to keep a connection alive or check if it is still open.
*
* @return void
*/
public function noop()
{
$this->_send('NOOP');
$this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
}
/**
* Issues the VRFY command end validates answer
*
* Not used by Zend_Mail.
*
* @param string $user User Name or eMail to verify
* @return void
*/
public function vrfy($user)
{
$this->_send('VRFY ' . $user);
$this->_expect(array(250, 251, 252), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
}
/**
* Issues the QUIT command and clears the current session
*
* @return void
*/
public function quit()
{
if ($this->_sess) {
$this->_send('QUIT');
$this->_expect(221, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
$this->_stopSession();
}
}
/**
* Default authentication method
*
* This default method is implemented by AUTH adapters to properly authenticate to a remote host.
*
* @throws Zend_Mail_Protocol_Exception
* @return void
*/
public function auth()
{
if ($this->_auth === true) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Already authenticated for this session');
}
}
/**
* Closes connection
*
* @return void
*/
public function disconnect()
{
$this->_disconnect();
}
/**
* Start mail session
*
* @return void
*/
protected function _startSession()
{
$this->_sess = true;
}
/**
* Stop mail session
*
* @return void
*/
protected function _stopSession()
{
$this->_sess = false;
}
}
PK pG[�Va�k �k Mail/Protocol/Imap.phpnu &1i� <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Imap.php 12539 2008-11-11 02:47:17Z yoshida@zend.co.jp $
*/
/**
* @category Zend
* @package Zend_Mail
* @subpackage Protocol
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Mail_Protocol_Imap
{
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
/**
* socket to imap server
* @var resource|null
*/
protected $_socket;
/**
* counter for request tag
* @var int
*/
protected $_tagCount = 0;
/**
* Public constructor
*
* @param string $host hostname of IP address of IMAP server, if given connect() is called
* @param int|null $port port of IMAP server, null for default (143 or 993 for ssl)
* @param bool $ssl use ssl? 'SSL', 'TLS' or false
* @throws Zend_Mail_Protocol_Exception
*/
function __construct($host = '', $port = null, $ssl = false)
{
if ($host) {
$this->connect($host, $port, $ssl);
}
}
/**
* Public destructor
*/
public function __destruct()
{
$this->logout();
}
/**
* Open connection to POP3 server
*
* @param string $host hostname of IP address of POP3 server
* @param int|null $port of IMAP server, default is 143 (993 for ssl)
* @param string|bool $ssl use 'SSL', 'TLS' or false
* @return string welcome message
* @throws Zend_Mail_Protocol_Exception
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
}
if ($port === null) {
$port = $ssl === 'SSL' ? 993 : 143;
}
$errno = 0;
$errstr = '';
$this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
if (!$this->_socket) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot connect to host : ' . $errno . ' : ' . $errstr);
}
if (!$this->_assumedNextLine('* OK')) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('host doesn\'t allow connection');
}
if ($ssl === 'TLS') {
$result = $this->requestAndResponse('STARTTLS');
$result = $result && stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot enable TLS');
}
}
}
/**
* get the next line from socket with error checking, but nothing else
*
* @return string next line
* @throws Zend_Mail_Protocol_Exception
*/
protected function _nextLine()
{
$line = @fgets($this->_socket);
if ($line === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot read - connection closed?');
}
return $line;
}
/**
* get next line and assume it starts with $start. some requests give a simple
* feedback so we can quickly check if we can go on.
*
* @param string $start the first bytes we assume to be in the next line
* @return bool line starts with $start
* @throws Zend_Mail_Protocol_Exception
*/
protected function _assumedNextLine($start)
{
$line = $this->_nextLine();
return strpos($line, $start) === 0;
}
/**
* get next line and split the tag. that's the normal case for a response line
*
* @param string $tag tag of line is returned by reference
* @return string next line
* @throws Zend_Mail_Protocol_Exception
*/
protected function _nextTaggedLine(&$tag)
{
$line = $this->_nextLine();
// seperate tag from line
list($tag, $line) = explode(' ', $line, 2);
return $line;
}
/**
* split a given line in tokens. a token is literal of any form or a list
*
* @param string $line line to decode
* @return array tokens, literals are returned as string, lists as array
* @throws Zend_Mail_Protocol_Exception
*/
protected function _decodeLine($line)
{
$tokens = array();
$stack = array();
/*
We start to decode the response here. The unterstood tokens are:
literal
"literal" or also "lit\\er\"al"
{bytes}<NL>literal
(literals*)
All tokens are returned in an array. Literals in braces (the last unterstood
token in the list) are returned as an array of tokens. I.e. the following response:
"foo" baz {3}<NL>bar ("f\\\"oo" bar)
would be returned as:
array('foo', 'baz', 'bar', array('f\\\"oo', 'bar'));
// TODO: add handling of '[' and ']' to parser for easier handling of response text
*/
// replace any trailling <NL> including spaces with a single space
$line = rtrim($line) . ' ';
while (($pos = strpos($line, ' ')) !== false) {
$token = substr($line, 0, $pos);
while ($token[0] == '(') {
array_push($stack, $tokens);
$tokens = array();
$token = substr($token, 1);
}
if ($token[0] == '"') {
if (preg_match('%^"((.|\\\\|\\")*?)" *%', $line, $matches)) {
$tokens[] = $matches[1];
$line = substr($line, strlen($matches[0]));
continue;
}
}
if ($token[0] == '{') {
$endPos = strpos($token, '}');
$chars = substr($token, 1, $endPos - 1);
if (is_numeric($chars)) {
$token = '';
while (strlen($token) < $chars) {
$token .= $this->_nextLine();
}
$line = '';
if (strlen($token) > $chars) {
$line = substr($token, $chars);
$token = substr($token, 0, $chars);
} else {
$line .= $this->_nextLine();
}
$tokens[] = $token;
$line = trim($line) . ' ';
continue;
}
}
if ($stack && $token[strlen($token) - 1] == ')') {
// closing braces are not seperated by spaces, so we need to count them
$braces = strlen($token);
$token = rtrim($token, ')');
// only count braces if more than one
$braces -= strlen($token) + 1;
// only add if token had more than just closing braces
if ($token) {
$tokens[] = $token;
}
$token = $tokens;
$tokens = array_pop($stack);
// special handline if more than one closing brace
while ($braces-- > 0) {
$tokens[] = $token;
$token = $tokens;
$tokens = array_pop($stack);
}
}
$tokens[] = $token;
$line = substr($line, $pos + 1);
}
// maybe the server forgot to send some closing braces
while ($stack) {
$child = $tokens;
$tokens = array_pop($stack);
$tokens[] = $child;
}
return $tokens;
}
/**
* read a response "line" (could also be more than one real line if response has {..}<NL>)
* and do a simple decode
*
* @param array|string $tokens decoded tokens are returned by reference, if $dontParse
* is true the unparsed line is returned here
* @param string $wantedTag check for this tag for response code. Default '*' is
* continuation tag.
* @param bool $dontParse if true only the unparsed line is returned $tokens
* @return bool if returned tag matches wanted tag
* @throws Zend_Mail_Protocol_Exception
*/
public function readLine(&$tokens = array(), $wantedTag = '*', $dontParse = false)
{
$line = $this->_nextTaggedLine($tag);
if (!$dontParse) {
$tokens = $this->_decodeLine($line);
} else {
$tokens = $line;
}
// if tag is wanted tag we might be at the end of a multiline response
return $tag == $wantedTag;
}
/**
* read all lines of response until given tag is found (last line of response)
*
* @param string $tag the tag of your request
* @param string|array $filter you can filter the response so you get only the
* given response lines
* @param bool $dontParse if true every line is returned unparsed instead of
* the decoded tokens
* @return null|bool|array tokens if success, false if error, null if bad request
* @throws Zend_Mail_Protocol_Exception
*/
public function readResponse($tag, $dontParse = false)
{
$lines = array();
while (!$this->readLine($tokens, $tag, $dontParse)) {
$lines[] = $tokens;
}
if ($dontParse) {
// last to chars are still needed for response code
$tokens = array(substr($tokens, 0, 2));
}
// last line has response code
if ($tokens[0] == 'OK') {
return $lines ? $lines : true;
} else if ($tokens[0] == 'NO'){
return false;
}
return null;
}
/**
* send a request
*
* @param string $command your request command
* @param array $tokens additional parameters to command, use escapeString() to prepare
* @param string $tag provide a tag otherwise an autogenerated is returned
* @return null
* @throws Zend_Mail_Protocol_Exception
*/
public function sendRequest($command, $tokens = array(), &$tag = null)
{
if (!$tag) {
++$this->_tagCount;
$tag = 'TAG' . $this->_tagCount;
}
$line = $tag . ' ' . $command;
foreach ($tokens as $token) {
if (is_array($token)) {
if (@fputs($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot write - connection closed?');
}
if (!$this->_assumedNextLine('+ ')) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot send literal string');
}
$line = $token[1];
} else {
$line .= ' ' . $token;
}
}
if (@fputs($this->_socket, $line . "\r\n") === false) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('cannot write - connection closed?');
}
}
/**
* send a request and get response at once
*
* @param string $command command as in sendRequest()
* @param array $tokens parameters as in sendRequest()
* @param bool $dontParse if true unparsed lines are returned instead of tokens
* @return mixed response as in readResponse()
* @throws Zend_Mail_Protocol_Exception
*/
public function requestAndResponse($command, $tokens = array(), $dontParse = false)
{
$this->sendRequest($command, $tokens, $tag);
$response = $this->readResponse($tag, $dontParse);
return $response;
}
/**
* escape one or more literals i.e. for sendRequest
*
* @param string|array $string the literal/-s
* @return string|array escape literals, literals with newline ar returned
* as array('{size}', 'string');
*/
public function escapeString($string)
{
if (func_num_args() < 2) {
if (strpos($string, "\n") !== false) {
return array('{' . strlen($string) . '}', $string);
} else {
return '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $string) . '"';
}
}
$result = array();
foreach (func_get_args() as $string) {
$result[] = $this->escapeString($string);
}
return $result;
}
/**
* escape a list with literals or lists
*
* @param array $list list with literals or lists as PHP array
* @return string escaped list for imap
*/
public function escapeList($list)
{
$result = array();
foreach ($list as $k => $v) {
if (!is_array($v)) {
// $result[] = $this->escapeString($v);
$result[] = $v;
continue;
}
$result[] = $this->escapeList($v);
}
return '(' . implode(' ', $result) . ')';
}
/**
* Login to IMAP server.
*
* @param string $user username
* @param string $password password
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function login($user, $password)
{
return $this->requestAndResponse('LOGIN', $this->escapeString($user, $password), true);
}
/**
* logout of imap server
*
* @return bool success
*/
public function logout()
{
$result = false;
if ($this->_socket) {
try {
$result = $this->requestAndResponse('LOGOUT', array(), true);
} catch (Zend_Mail_Protocol_Exception $e) {
// ignoring exception
}
fclose($this->_socket);
$this->_socket = null;
}
return $result;
}
/**
* Get capabilities from IMAP server
*
* @return array list of capabilities
* @throws Zend_Mail_Protocol_Exception
*/
public function capability()
{
$response = $this->requestAndResponse('CAPABILITY');
if (!$response) {
return $response;
}
$capabilities = array();
foreach ($response as $line) {
$capabilities = array_merge($capabilities, $line);
}
return $capabilities;
}
/**
* Examine and select have the same response. The common code for both
* is in this method
*
* @param string $command can be 'EXAMINE' or 'SELECT' and this is used as command
* @param string $box which folder to change to or examine
* @return bool|array false if error, array with returned information
* otherwise (flags, exists, recent, uidvalidity)
* @throws Zend_Mail_Protocol_Exception
*/
public function examineOrSelect($command = 'EXAMINE', $box = 'INBOX')
{
$this->sendRequest($command, array($this->escapeString($box)), $tag);
$result = array();
while (!$this->readLine($tokens, $tag)) {
if ($tokens[0] == 'FLAGS') {
array_shift($tokens);
$result['flags'] = $tokens;
continue;
}
switch ($tokens[1]) {
case 'EXISTS':
case 'RECENT':
$result[strtolower($tokens[1])] = $tokens[0];
break;
case '[UIDVALIDITY':
$result['uidvalidity'] = (int)$tokens[2];
break;
default:
// ignore
}
}
if ($tokens[0] != 'OK') {
return false;
}
return $result;
}
/**
* change folder
*
* @param string $box change to this folder
* @return bool|array see examineOrselect()
* @throws Zend_Mail_Protocol_Exception
*/
public function select($box = 'INBOX')
{
return $this->examineOrSelect('SELECT', $box);
}
/**
* examine folder
*
* @param string $box examine this folder
* @return bool|array see examineOrselect()
* @throws Zend_Mail_Protocol_Exception
*/
public function examine($box = 'INBOX')
{
return $this->examineOrSelect('EXAMINE', $box);
}
/**
* fetch one or more items of one or more messages
*
* @param string|array $items items to fetch from message(s) as string (if only one item)
* or array of strings
* @param int $from message for items or start message if $to !== null
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @return string|array if only one item of one message is fetched it's returned as string
* if items of one message are fetched it's returned as (name => value)
* if one items of messages are fetched it's returned as (msgno => value)
* if items of messages are fetchted it's returned as (msgno => (name => value))
* @throws Zend_Mail_Protocol_Exception
*/
public function fetch($items, $from, $to = null)
{
if (is_array($from)) {
$set = implode(',', $from);
} else if ($to === null) {
$set = (int)$from;
} else if ($to === INF) {
$set = (int)$from . ':*';
} else {
$set = (int)$from . ':' . (int)$to;
}
$items = (array)$items;
$itemList = $this->escapeList($items);
$this->sendRequest('FETCH', array($set, $itemList), $tag);
$result = array();
while (!$this->readLine($tokens, $tag)) {
// ignore other responses
if ($tokens[1] != 'FETCH') {
continue;
}
// ignore other messages
if ($to === null && !is_array($from) && $tokens[0] != $from) {
continue;
}
// if we only want one item we return that one directly
if (count($items) == 1) {
if ($tokens[2][0] == $items[0]) {
$data = $tokens[2][1];
} else {
// maybe the server send an other field we didn't wanted
$count = count($tokens[2]);
// we start with 2, because 0 was already checked
for ($i = 2; $i < $count; $i += 2) {
if ($tokens[2][$i] != $items[0]) {
continue;
}
$data = $tokens[2][$i + 1];
break;
}
}
} else {
$data = array();
while (key($tokens[2]) !== null) {
$data[current($tokens[2])] = next($tokens[2]);
next($tokens[2]);
}
}
// if we want only one message we can ignore everything else and just return
if ($to === null && !is_array($from) && $tokens[0] == $from) {
// we still need to read all lines
while (!$this->readLine($tokens, $tag));
return $data;
}
$result[$tokens[0]] = $data;
}
if ($to === null && !is_array($from)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('the single id was not found in response');
}
return $result;
}
/**
* get mailbox list
*
* this method can't be named after the IMAP command 'LIST', as list is a reserved keyword
*
* @param string $reference mailbox reference for list
* @param string $mailbox mailbox name match with wildcards
* @return array mailboxes that matched $mailbox as array(globalName => array('delim' => .., 'flags' => ..))
* @throws Zend_Mail_Protocol_Exception
*/
public function listMailbox($reference = '', $mailbox = '*')
{
$result = array();
$list = $this->requestAndResponse('LIST', $this->escapeString($reference, $mailbox));
if (!$list || $list === true) {
return $result;
}
foreach ($list as $item) {
if (count($item) != 4 || $item[0] != 'LIST') {
continue;
}
$result[$item[3]] = array('delim' => $item[2], 'flags' => $item[1]);
}
return $result;
}
/**
* set flags
*
* @param array $flags flags to set, add or remove - see $mode
* @param int $from message for items or start message if $to !== null
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @param string|null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given
* @param bool $silent if false the return values are the new flags for the wanted messages
* @return bool|array new flags if $silent is false, else true or false depending on success
* @throws Zend_Mail_Protocol_Exception
*/
public function store(array $flags, $from, $to = null, $mode = null, $silent = true)
{
$item = 'FLAGS';
if ($mode == '+' || $mode == '-') {
$item = $mode . $item;
}
if ($silent) {
$item .= '.SILENT';
}
$flags = $this->escapeList($flags);
$set = (int)$from;
if ($to != null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
$result = $this->requestAndResponse('STORE', array($set, $item, $flags), $silent);
if ($silent) {
return $result ? true : false;
}
$tokens = $result;
$result = array();
foreach ($tokens as $token) {
if ($token[1] != 'FETCH' || $token[2][0] != 'FLAGS') {
continue;
}
$result[$token[0]] = $token[2][1];
}
return $result;
}
/**
* append a new message to given folder
*
* @param string $folder name of target folder
* @param string $message full message content
* @param array $flags flags for new message
* @param string $date date for new message
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function append($folder, $message, $flags = null, $date = null)
{
$tokens = array();
$tokens[] = $this->escapeString($folder);
if ($flags !== null) {
$tokens[] = $this->escapeList($flags);
}
if ($date !== null) {
$tokens[] = $this->escapeString($date);
}
$tokens[] = $this->escapeString($message);
return $this->requestAndResponse('APPEND', $tokens, true);
}
/**
* copy message set from current folder to other folder
*
* @param string $folder destination folder
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @return bool success
* @throws Zend_Mail_Protocol_Exception
*/
public function copy($folder, $from, $to = null)
{
$set = (int)$from;
if ($to != null) {
$set .= ':' . ($to == INF ? '*' : (int)$to);
}
return $this->requestAndResponse('COPY', array($set, $this->escapeString($folder)), true);
}
/**
* create a new folder (and parent folders if needed)
*
* @param string $folder folder name
* @return bool success
*/
public function create($folder)
{
return $this->requestAndResponse('CREATE', array($this->escapeString($folder)), true);
}
/**
* rename an existing folder
*
* @param string $old old name
* @param string $new new name
* @return bool success
*/
public function rename($old, $new)
{
return $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
}
/**
* remove a folder
*
* @param string $folder folder name
* @return bool success
*/
public function delete($folder)
{
return $this->requestAndResponse('DELETE', array($this->escapeString($folder)), true);
}
/**
* permanently remove messages
*
* @return bool success
*/
public function expunge()
{
// TODO: parse response?
return $this->requestAndResponse('EXPUNGE');
}
/**
* send noop
*
* @return bool success
*/
public function noop()
{
// TODO: parse response
return $this->requestAndResponse('NOOP');
}
/**
* do a search request
*
* This method is currently marked as internal as the API might change and is not
* safe if you don't take precautions.
*
* @internal
* @return array message ids
*/
public function search(array $params)
{
$response = $this->requestAndResponse('SEARCH', $params);
if (!$response) {
return $response;
}
foreach ($response as $ids) {
if ($ids[0] == 'SEARCH') {
array_shift($ids);
return $ids;
}
}
return array();
}
}
PK pG[�`���&