diff --git a/.gitignore b/.gitignore index 1f14d26aa2..5d23c53d69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .vagrant tests/Zend/Db/Table/_files/cachefiles/* tests/Zend/Auth/Adapter/OpenId/_files/* diff --git a/library/Zend/Barcode/Object/Upce.php b/library/Zend/Barcode/Object/Upce.php index cbb5b9bd3e..8302b698f1 100644 --- a/library/Zend/Barcode/Object/Upce.php +++ b/library/Zend/Barcode/Object/Upce.php @@ -84,8 +84,8 @@ protected function _getDefaultOptions() public function getText() { $text = parent::getText(); - if ($text{0} != 1) { - $text{0} = 0; + if ($text[0] != 1) { + $text[0] = 0; } return $text; } @@ -222,8 +222,8 @@ protected function _validateText($value, $options = array()) public function getChecksum($text) { $text = $this->_addLeadingZeros($text, true); - if ($text{0} != 1) { - $text{0} = 0; + if ($text[0] != 1) { + $text[0] = 0; } return parent::getChecksum($text); } diff --git a/library/Zend/Cache/Backend.php b/library/Zend/Cache/Backend.php index 83f1af5f12..3d99e0939c 100644 --- a/library/Zend/Cache/Backend.php +++ b/library/Zend/Cache/Backend.php @@ -76,7 +76,7 @@ public function __construct(array $options = array()) public function setDirectives($directives) { if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); - while (list($name, $value) = each($directives)) { + foreach ($directives as $name => $value) { if (!is_string($name)) { Zend_Cache::throwException("Incorrect option name : $name"); } diff --git a/library/Zend/Controller/Action.php b/library/Zend/Controller/Action.php index 9508e74711..86abc67fe4 100644 --- a/library/Zend/Controller/Action.php +++ b/library/Zend/Controller/Action.php @@ -785,7 +785,7 @@ protected function _redirect($url, array $options = array()) /** * Redirect to another URL * - * Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}. + * Proxies to @see Zend_Controller_Action_Helper_Redirector::gotoUrl() * * @param string $url * @param array $options Options to be used when redirecting diff --git a/library/Zend/Db/Adapter/Pdo/Pgsql.php b/library/Zend/Db/Adapter/Pdo/Pgsql.php index abd5e637b0..efb74cd145 100644 --- a/library/Zend/Db/Adapter/Pdo/Pgsql.php +++ b/library/Zend/Db/Adapter/Pdo/Pgsql.php @@ -156,7 +156,7 @@ public function describeTable($tableName, $schemaName = null) t.typname AS type, a.atttypmod, FORMAT_TYPE(a.atttypid, a.atttypmod) AS complete_type, - d.adsrc AS default_value, + pg_get_expr(d.adbin, d.adrelid) AS default_value, a.attnotnull AS notnull, a.attlen AS length, co.contype, diff --git a/library/Zend/Feed/Atom.php b/library/Zend/Feed/Atom.php index 2ee08cef6a..67b56e7748 100644 --- a/library/Zend/Feed/Atom.php +++ b/library/Zend/Feed/Atom.php @@ -255,7 +255,7 @@ protected function _mapFeedHeaders($array) * The following nodes are constructed for each feed entry * * url to feed entry - * entry title + * entry title * last update * * short text diff --git a/library/Zend/Feed/Rss.php b/library/Zend/Feed/Rss.php index 5035d35d77..9db54b8755 100644 --- a/library/Zend/Feed/Rss.php +++ b/library/Zend/Feed/Rss.php @@ -379,7 +379,7 @@ private function _buildiTunes(DOMElement $root, $array) * * The following nodes are constructed for each feed entry * - * entry title + * entry title * url to feed entry * url to feed entry * short text diff --git a/library/Zend/Filter/Compress/Zip.php b/library/Zend/Filter/Compress/Zip.php index 9921fe9648..9c71a88444 100644 --- a/library/Zend/Filter/Compress/Zip.php +++ b/library/Zend/Filter/Compress/Zip.php @@ -237,7 +237,7 @@ public function decompress($content) for ($i = 0; $i < $zip->numFiles; $i++) { $statIndex = $zip->statIndex($i); $currName = $statIndex['name']; - if (($currName{0} == '/') || + if (($currName[0] == '/') || (substr($currName, 0, 2) == '..') || (substr($currName, 0, 4) == './..') ) diff --git a/library/Zend/Form.php b/library/Zend/Form.php index 0512dc850b..ebd2fd0a22 100644 --- a/library/Zend/Form.php +++ b/library/Zend/Form.php @@ -2077,7 +2077,7 @@ public function clearDisplayGroups() * @param array $values * @return Zend_Form */ - public function populate(array $values) + public function populate(array $values=[]) { return $this->setDefaults($values); } @@ -2981,7 +2981,7 @@ public function setSubFormDecorators(array $decorators) * @param Zend_View_Interface $view * @return string */ - public function render(Zend_View_Interface $view = null) + public function render($view = null) { if (null !== $view) { $this->setView($view); diff --git a/library/Zend/Form/Decorator/FormErrors.php b/library/Zend/Form/Decorator/FormErrors.php index 29ca94e729..568b91dc5d 100644 --- a/library/Zend/Form/Decorator/FormErrors.php +++ b/library/Zend/Form/Decorator/FormErrors.php @@ -464,6 +464,8 @@ public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $vie } } + $label = strip_tags($label); + if ($this->getEscape()) { $label = $view->escape($label); } diff --git a/library/Zend/Form/DisplayGroup.php b/library/Zend/Form/DisplayGroup.php index a18f236437..03d09f6ad1 100644 --- a/library/Zend/Form/DisplayGroup.php +++ b/library/Zend/Form/DisplayGroup.php @@ -1179,4 +1179,28 @@ protected function _loadDecorator(array $decorator, $name) return $instance; } + + /** + * Custom Actionstep Hack + * @return $this + */ + public function setLayoutOutline() { + $class = $this->getDecorator('Fieldset')->getOption('class'); + $class .= ' as-form-group--outlined'; + $this->getDecorator('Fieldset')->setOption('class', $class); + return $this; + } + + + /** + * Custom Actionstep Hack + * @return $this + */ + public function setLayoutIndented() { + $class = $this->getDecorator('Fieldset')->getOption('class'); + $class .= ' as-form-group--indented'; + $this->getDecorator('Fieldset')->setOption('class', $class); + return $this; + } + } diff --git a/library/Zend/Form/Element.php b/library/Zend/Form/Element.php index 26bad9af3b..a7ef0fc003 100644 --- a/library/Zend/Form/Element.php +++ b/library/Zend/Form/Element.php @@ -573,7 +573,7 @@ public function getId() * Set element value * * @param mixed $value - * @return Zend_Form_Element + * @return $this */ public function setValue($value) { @@ -852,10 +852,10 @@ public function getType() * * @param string $name * @param mixed $value - * @return Zend_Form_Element + * @return $this * @throws Zend_Form_Exception for invalid $name values */ - public function setAttrib($name, $value) + public function setAttrib($name, $value=null) { $name = (string) $name; if ('_' == $name[0]) { diff --git a/library/Zend/Http/Client/Adapter/Proxy.php b/library/Zend/Http/Client/Adapter/Proxy.php index 090e570cba..2874b1ea5c 100644 --- a/library/Zend/Http/Client/Adapter/Proxy.php +++ b/library/Zend/Http/Client/Adapter/Proxy.php @@ -296,12 +296,24 @@ protected function connectHandshake( // If all is good, switch socket to secure mode. We have to fall back // through the different modes + + /** + * Lance: Update to use TLS 1.2 + */ $modes = array( + STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, STREAM_CRYPTO_METHOD_TLS_CLIENT, - STREAM_CRYPTO_METHOD_SSLv3_CLIENT, - STREAM_CRYPTO_METHOD_SSLv23_CLIENT, - STREAM_CRYPTO_METHOD_SSLv2_CLIENT + STREAM_CRYPTO_METHOD_SSLv3_CLIENT ); + + /** + * Lance: Set verify peer etc to false, otherwise proxy calls will always fail. + * Was defaulted to false in PHP when this library was created, but since php 5.6 it is enabled by default, so needs hack to fix. + * @see https://stackoverflow.com/questions/33497040/zend-unable-to-connect-to-https-server-through-proxy + */ + stream_context_set_option($this->socket, "ssl", "verify_peer", false); + stream_context_set_option($this->socket, "ssl", "verify_peer_name", false); + stream_context_set_option($this->socket, "ssl", "allow_self_signed", false); $success = false; foreach($modes as $mode) { diff --git a/library/Zend/Http/UserAgent/Features/Adapter/WurflApi.php b/library/Zend/Http/UserAgent/Features/Adapter/WurflApi.php new file mode 100644 index 0000000000..291c1ccfef --- /dev/null +++ b/library/Zend/Http/UserAgent/Features/Adapter/WurflApi.php @@ -0,0 +1,103 @@ +wurflFile($c['wurfl']['main-file']) + ->wurflPatch($c['wurfl']['patches']) + ->persistence($c['persistence']['provider'], $c['persistence']['dir']); + } + + $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); + $wurflManager = $wurflManagerFactory->create(); + break; + default: + require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception(sprintf( + 'Unknown API version "%s"', + $config['wurfl_api_version'] + )); + } + + $device = $wurflManager->getDeviceForHttpRequest(array_change_key_case($request, CASE_UPPER)); + $features = $device->getAllCapabilities(); + return $features; + } +} diff --git a/library/Zend/Json/Decoder.php b/library/Zend/Json/Decoder.php index 8a79f0cdd2..cc83115199 100644 --- a/library/Zend/Json/Decoder.php +++ b/library/Zend/Json/Decoder.php @@ -552,7 +552,7 @@ protected static function _utf162utf8($utf16) return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); } - $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); + $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); switch (true) { case ((0x7F & $bytes) == $bytes): diff --git a/library/Zend/Json/Encoder.php b/library/Zend/Json/Encoder.php index fbf5b53cca..9013b285c3 100644 --- a/library/Zend/Json/Encoder.php +++ b/library/Zend/Json/Encoder.php @@ -558,17 +558,17 @@ protected static function _utf82utf16($utf8) case 2: // return a UTF-16 character from a 2-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0x07 & (ord($utf8{0}) >> 2)) - . chr((0xC0 & (ord($utf8{0}) << 6)) - | (0x3F & ord($utf8{1}))); + return chr(0x07 & (ord($utf8[0]) >> 2)) + . chr((0xC0 & (ord($utf8[0]) << 6)) + | (0x3F & ord($utf8[1]))); case 3: // return a UTF-16 character from a 3-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr((0xF0 & (ord($utf8{0}) << 4)) - | (0x0F & (ord($utf8{1}) >> 2))) - . chr((0xC0 & (ord($utf8{1}) << 6)) - | (0x7F & ord($utf8{2}))); + return chr((0xF0 & (ord($utf8[0]) << 4)) + | (0x0F & (ord($utf8[1]) >> 2))) + . chr((0xC0 & (ord($utf8[1]) << 6)) + | (0x7F & ord($utf8[2]))); } // ignoring UTF-32 for now, sorry diff --git a/library/Zend/Loader/Autoloader.php b/library/Zend/Loader/Autoloader.php index 06e70232fd..a30ccf8aeb 100644 --- a/library/Zend/Loader/Autoloader.php +++ b/library/Zend/Loader/Autoloader.php @@ -115,6 +115,10 @@ public static function autoload($class) { $self = self::getInstance(); + if (strpos($class, "Google") !== false && defined('USE_MONO_GOOGLE') && USE_MONO_GOOGLE === 1) { + return false; + } + foreach ($self->getClassAutoloaders($class) as $autoloader) { if ($autoloader instanceof Zend_Loader_Autoloader_Interface) { if ($autoloader->autoload($class)) { diff --git a/library/Zend/Mail.php b/library/Zend/Mail.php index 264d9790b6..9d90c32314 100644 --- a/library/Zend/Mail.php +++ b/library/Zend/Mail.php @@ -578,8 +578,12 @@ public function addTo($email, $name='') } foreach ($email as $n => $recipient) { - $this->_addRecipientAndHeader('To', $recipient, is_int($n) ? '' : $n); - $this->_to[] = $recipient; + // Custom hack - trim recipient and check for empty + $recipient = trim($recipient); + if (!empty($recipient)) { + $this->_addRecipientAndHeader('To', $recipient, is_int($n) ? '' : $n); + $this->_to[] = $recipient; + } } return $this; diff --git a/library/Zend/Mail/Header/HeaderValue.php b/library/Zend/Mail/Header/HeaderValue.php index d75d59fa11..a1ae6a8656 100644 --- a/library/Zend/Mail/Header/HeaderValue.php +++ b/library/Zend/Mail/Header/HeaderValue.php @@ -130,7 +130,7 @@ public static function assertValid($value) { if (! self::isValid($value)) { require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception('Invalid header value detected'); + throw new Zend_Mail_Exception('Invalid header value detected: ' . $value); } } } diff --git a/library/Zend/Mail/Part.php b/library/Zend/Mail/Part.php index ca881a791e..70b73799c7 100644 --- a/library/Zend/Mail/Part.php +++ b/library/Zend/Mail/Part.php @@ -148,7 +148,7 @@ public function __construct(array $params) } else if (isset($params['headers'])) { if (is_array($params['headers'])) { $this->_headers = $params['headers']; - $this->_validateHeaders($this->_headers); + //$this->_validateHeaders($this->_headers); } else { if (!empty($params['noToplines'])) { Zend_Mime_Decode::splitMessage($params['headers'], $this->_headers, $null, "\r\n"); @@ -597,6 +597,7 @@ protected function _validateHeaders(array $headers, $assertNames = true) continue; } + $value = str_replace("\r\n", "\r", $value); Zend_Mail_Header_HeaderValue::assertValid($value); } } diff --git a/library/Zend/Mail/Protocol/Pop3.php b/library/Zend/Mail/Protocol/Pop3.php index 9a76228792..a5928cd862 100644 --- a/library/Zend/Mail/Protocol/Pop3.php +++ b/library/Zend/Mail/Protocol/Pop3.php @@ -93,23 +93,30 @@ public function connect($host, $port = null, $ssl = false) if ($ssl == 'SSL') { $host = 'ssl://' . $host; } - + if ($port === null) { $port = $ssl == 'SSL' ? 995 : 110; } - - $errno = 0; + + $errno = 0; $errstr = ''; - $this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION); + if (defined("ZEND_OVERRIDE_POP3_CONNECTION_TIMEOUT")) { + $timeout = ZEND_OVERRIDE_POP3_CONNECTION_TIMEOUT; + } else { + $timeout = self::TIMEOUT_CONNECTION; + } + $this->_socket = @fsockopen($host, $port, $errno, $errstr, $timeout); 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; error = ' . $errstr . - ' (errno = ' . $errno . ' )'); + throw new Zend_Mail_Protocol_Exception( + 'cannot connect to host; error = ' . $errstr . + ' (errno = ' . $errno . ' )' + ); } - + $welcome = $this->readResponse(); strtok($welcome, '<'); @@ -187,7 +194,8 @@ public function readResponse($multiline = false) * @see Zend_Mail_Protocol_Exception */ require_once 'Zend/Mail/Protocol/Exception.php'; - throw new Zend_Mail_Protocol_Exception('last request failed'); + // Custom Hack - Add additional info to exception: + throw new Zend_Mail_Protocol_Exception('last request failed: ' . $status . ' ' . $message); } if ($multiline) { diff --git a/library/Zend/Mail/Protocol/Smtp.php b/library/Zend/Mail/Protocol/Smtp.php index 9dd3568b25..beecb346ab 100644 --- a/library/Zend/Mail/Protocol/Smtp.php +++ b/library/Zend/Mail/Protocol/Smtp.php @@ -312,12 +312,44 @@ public function data($data) $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; + /** + * Custom hack in place as Zend uses explode() on a 30MB string which creates an extra 150MB of memory usage! geesh! + * Instead of explode, we'll just use strpos + substr, which is actually faster and uses virtual no extra memory. + */ + $start= 0; + $nextLineEnd = strpos($data, Zend_Mime::LINEEND, $start); + + if ($useLancesHack=true) { + while ($nextLineEnd !== false ) { + $line = substr($data, $start, $nextLineEnd-$start); + if (strpos($line, '.') === 0) { + // Escape lines prefixed with a '.' + $line = '.' . $line; + } + $this->_send($line); + + $start = $nextLineEnd + strlen(Zend_Mime::LINEEND); + $nextLineEnd = strpos($data, Zend_Mime::LINEEND, $start); + } + if ($start < strlen($data)) { + $line = substr($data, $start); + if (!empty($line)) { + if (strpos($line, '.') === 0) { + // Escape lines prefixed with a '.' + $line = '.' . $line; + } + $this->_send($line); + } + } + } else { + + foreach (explode(Zend_Mime::LINEEND, $data) as $line) { + if (strpos($line, '.') === 0) { + // Escape lines prefixed with a '.' + $line = '.' . $line; + } + $this->_send($line); } - $this->_send($line); } $this->_send('.'); diff --git a/library/Zend/Mail/Storage/Abstract.php b/library/Zend/Mail/Storage/Abstract.php index beb8fb6fb7..e25dc29b22 100644 --- a/library/Zend/Mail/Storage/Abstract.php +++ b/library/Zend/Mail/Storage/Abstract.php @@ -144,15 +144,6 @@ abstract public function getRawHeader($id, $part = null, $topLines = 0); */ abstract public function getRawContent($id, $part = null); - /** - * Create instance with parameters - * - * @param array $params mail reader specific parameters - * @throws Zend_Mail_Storage_Exception - */ - abstract public function __construct($params); - - /** * Destructor calls close() and therefore closes the resource. */ @@ -161,7 +152,6 @@ public function __destruct() $this->close(); } - /** * Close resource for mail lib. If you need to control, when the resource * is closed. Otherwise the destructor would call this. diff --git a/library/Zend/Mime/Decode.php b/library/Zend/Mime/Decode.php index caf03e1e16..7407f5b7fb 100644 --- a/library/Zend/Mime/Decode.php +++ b/library/Zend/Mime/Decode.php @@ -162,14 +162,20 @@ public static function splitMessage( } } - $headers = iconv_mime_decode_headers( - $headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR + $decodedHeaders = iconv_mime_decode_headers( + $headers, ICONV_MIME_DECODE_STRICT ); - if ($headers === false) { + if ($decodedHeaders === false) { // an error occurs during the decoding - return; + $decodedHeaders = iconv_mime_decode_headers( + $headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR + ); + if ($decodedHeaders === false) { + return; + } } + $headers = $decodedHeaders; // normalize header names foreach ($headers as $name => $header) { @@ -191,6 +197,10 @@ public static function splitMessage( $header ); } + if (isset($headers['content-type']) && isset($headers['contenttype'])) { + // bug fix + unset($headers['contenttype']); + } } /** diff --git a/library/Zend/Oauth/Token.php b/library/Zend/Oauth/Token.php index 08f23e5c12..33ea877c24 100644 --- a/library/Zend/Oauth/Token.php +++ b/library/Zend/Oauth/Token.php @@ -175,11 +175,16 @@ public function getParam($key) } return null; } - + + public function getParams() + { + return $this->_params; + } + /** * Sets the value for a Token. * - * @param string $token + * @param string $token * @return Zend_Oauth_Token */ public function setToken($token) diff --git a/library/Zend/Pdf/Cmap.php b/library/Zend/Pdf/Cmap.php index 29ca4adab0..821993c93e 100644 --- a/library/Zend/Pdf/Cmap.php +++ b/library/Zend/Pdf/Cmap.php @@ -189,19 +189,6 @@ public static function cmapWithTypeData($cmapType, $cmapData) } - /* Abstract Methods */ - - /** - * Object constructor - * - * Parses the raw binary table data. Throws an exception if the table is - * malformed. - * - * @param string $cmapData Raw binary cmap table data. - * @throws Zend_Pdf_Exception - */ - abstract public function __construct($cmapData); - /** * Returns an array of glyph numbers corresponding to the Unicode characters. * diff --git a/library/Zend/Registry.php b/library/Zend/Registry.php index 837b05ae50..4eab42fe93 100644 --- a/library/Zend/Registry.php +++ b/library/Zend/Registry.php @@ -194,16 +194,4 @@ public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS) { parent::__construct($array, $flags); } - - /** - * @param string $index - * @returns mixed - * - * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960). - */ - public function offsetExists($index) - { - return array_key_exists($index, $this); - } - } diff --git a/library/Zend/Service/Amazon/S3.php b/library/Zend/Service/Amazon/S3.php index 613c95045a..1c16c69ccb 100755 --- a/library/Zend/Service/Amazon/S3.php +++ b/library/Zend/Service/Amazon/S3.php @@ -130,7 +130,7 @@ public function _validBucketName($bucket) throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" must be between 3 and 255 characters long"); } - if (preg_match('/[^a-z0-9\._-]/', $bucket)) { + if (preg_match('/[^a-z0-9A-Z\._-]/', $bucket)) { /** * @see Zend_Service_Amazon_S3_Exception */ diff --git a/library/Zend/Service/Twitter.php b/library/Zend/Service/Twitter.php deleted file mode 100755 index 836d3b8cad..0000000000 --- a/library/Zend/Service/Twitter.php +++ /dev/null @@ -1,1307 +0,0 @@ -toArray(); - } - if (!is_array($options)) { - $options = array(); - } - - $this->options = $options; - - if (isset($options['username'])) { - $this->setUsername($options['username']); - } - - $accessToken = false; - if (isset($options['accessToken'])) { - $accessToken = $options['accessToken']; - } elseif (isset($options['access_token'])) { - $accessToken = $options['access_token']; - } - - $oauthOptions = array(); - if (isset($options['oauthOptions'])) { - $oauthOptions = $options['oauthOptions']; - } elseif (isset($options['oauth_options'])) { - $oauthOptions = $options['oauth_options']; - } - $oauthOptions['siteUrl'] = self::OAUTH_BASE_URI; - - $httpClientOptions = array(); - if (isset($options['httpClientOptions'])) { - $httpClientOptions = $options['httpClientOptions']; - } elseif (isset($options['http_client_options'])) { - $httpClientOptions = $options['http_client_options']; - } - - // If we have an OAuth access token, use the HTTP client it provides - if ($accessToken && is_array($accessToken) - && (isset($accessToken['token']) && isset($accessToken['secret'])) - ) { - $token = new Zend_Oauth_Token_Access(); - $token->setToken($accessToken['token']); - $token->setTokenSecret($accessToken['secret']); - $accessToken = $token; - } - if ($accessToken && $accessToken instanceof Zend_Oauth_Token_Access) { - $oauthOptions['token'] = $accessToken; - $this->setHttpClient($accessToken->getHttpClient($oauthOptions, self::OAUTH_BASE_URI, $httpClientOptions)); - return; - } - - // See if we were passed an http client - if (isset($options['httpClient']) && null === $httpClient) { - $httpClient = $options['httpClient']; - } elseif (isset($options['http_client']) && null === $httpClient) { - $httpClient = $options['http_client']; - } - if ($httpClient instanceof Zend_Http_Client) { - $this->httpClient = $httpClient; - } else { - $this->setHttpClient(new Zend_Http_Client(null, $httpClientOptions)); - } - - // Set the OAuth consumer - if ($consumer === null) { - $consumer = new Zend_Oauth_Consumer($oauthOptions); - } - $this->oauthConsumer = $consumer; - } - - /** - * Proxy service methods - * - * @param string $type - * @return Twitter - * @throws Exception\DomainException If method not in method types list - */ - public function __get($type) - { - $type = strtolower($type); - $type = str_replace('_', '', $type); - if (!in_array($type, $this->methodTypes)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Invalid method type "' . $type . '"' - ); - } - $this->methodType = $type; - return $this; - } - - /** - * Method overloading - * - * @param string $method - * @param array $params - * @return mixed - * @throws Exception\BadMethodCallException if unable to find method - */ - public function __call($method, $params) - { - if (method_exists($this->oauthConsumer, $method)) { - $return = call_user_func_array(array($this->oauthConsumer, $method), $params); - if ($return instanceof Zend_Oauth_Token_Access) { - $this->setHttpClient($return->getHttpClient($this->options)); - } - return $return; - } - if (empty($this->methodType)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Invalid method "' . $method . '"' - ); - } - - $test = str_replace('_', '', strtolower($method)); - $test = $this->methodType . $test; - if (!method_exists($this, $test)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Invalid method "' . $test . '"' - ); - } - - return call_user_func_array(array($this, $test), $params); - } - - /** - * Set HTTP client - * - * @param Zend_Http_Client $client - * @return self - */ - public function setHttpClient(Zend_Http_Client $client) - { - $this->httpClient = $client; - $this->httpClient->setHeaders(array('Accept-Charset' => 'ISO-8859-1,utf-8')); - return $this; - } - - /** - * Get the HTTP client - * - * Lazy loads one if none present - * - * @return Zend_Http_Client - */ - public function getHttpClient() - { - if (null === $this->httpClient) { - $this->setHttpClient(new Zend_Http_Client()); - } - return $this->httpClient; - } - - /** - * Retrieve username - * - * @return string - */ - public function getUsername() - { - return $this->username; - } - - /** - * Set username - * - * @param string $value - * @return self - */ - public function setUsername($value) - { - $this->username = $value; - return $this; - } - - /** - * Checks for an authorised state - * - * @return bool - */ - public function isAuthorised() - { - if ($this->getHttpClient() instanceof Zend_Oauth_Client) { - return true; - } - return false; - } - - /** - * Verify Account Credentials - * - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function accountVerifyCredentials() - { - $this->init(); - $response = $this->get('account/verify_credentials'); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Returns the number of api requests you have left per hour. - * - * @todo Have a separate payload object to represent rate limits - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function applicationRateLimitStatus() - { - $this->init(); - $response = $this->get('application/rate_limit_status'); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Blocks the user specified in the ID parameter as the authenticating user. - * Destroys a friendship to the blocked user if it exists. - * - * @param integer|string $id The ID or screen name of a user to block. - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function blocksCreate($id) - { - $this->init(); - $path = 'blocks/create'; - $params = $this->createUserParameter($id, array()); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Un-blocks the user specified in the ID parameter for the authenticating user - * - * @param integer|string $id The ID or screen_name of the user to un-block. - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function blocksDestroy($id) - { - $this->init(); - $path = 'blocks/destroy'; - $params = $this->createUserParameter($id, array()); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Returns an array of user ids that the authenticating user is blocking - * - * @param integer $cursor Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results. - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function blocksIds($cursor = -1) - { - $this->init(); - $path = 'blocks/ids'; - $response = $this->get($path, array('cursor' => $cursor)); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Returns an array of user objects that the authenticating user is blocking - * - * @param integer $cursor Optional. Specifies the cursor position at which to begin listing ids; defaults to first "page" of results. - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function blocksList($cursor = -1) - { - $this->init(); - $path = 'blocks/list'; - $response = $this->get($path, array('cursor' => $cursor)); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Destroy a direct message - * - * @param int $id ID of message to destroy - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function directMessagesDestroy($id) - { - $this->init(); - $path = 'direct_messages/destroy'; - $params = array('id' => $this->validInteger($id)); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Retrieve direct messages for the current user - * - * $options may include one or more of the following keys - * - count: return page X of results - * - since_id: return statuses only greater than the one specified - * - max_id: return statuses with an ID less than (older than) or equal to that specified - * - include_entities: setting to false will disable embedded entities - * - skip_status:setting to true, "t", or 1 will omit the status in returned users - * - * @param array $options - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function directMessagesMessages(array $options = array()) - { - $this->init(); - $path = 'direct_messages'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'count': - $params['count'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - case 'skip_status': - $params['skip_status'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Send a direct message to a user - * - * @param int|string $user User to whom to send message - * @param string $text Message to send to user - * @throws Exception\InvalidArgumentException if message is empty - * @throws Exception\OutOfRangeException if message is too long - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function directMessagesNew($user, $text) - { - $this->init(); - $path = 'direct_messages/new'; - - $len = iconv_strlen($text, 'UTF-8'); - if (0 == $len) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Direct message must contain at least one character' - ); - } elseif (140 < $len) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Direct message must contain no more than 140 characters' - ); - } - - $params = $this->createUserParameter($user, array()); - $params['text'] = $text; - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Retrieve list of direct messages sent by current user - * - * $options may include one or more of the following keys - * - count: return page X of results - * - page: return starting at page - * - since_id: return statuses only greater than the one specified - * - max_id: return statuses with an ID less than (older than) or equal to that specified - * - include_entities: setting to false will disable embedded entities - * - * @param array $options - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function directMessagesSent(array $options = array()) - { - $this->init(); - $path = 'direct_messages/sent'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'count': - $params['count'] = (int) $value; - break; - case 'page': - $params['page'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Mark a status as a favorite - * - * @param int $id Status ID you want to mark as a favorite - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function favoritesCreate($id) - { - $this->init(); - $path = 'favorites/create'; - $params = array('id' => $this->validInteger($id)); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Remove a favorite - * - * @param int $id Status ID you want to de-list as a favorite - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function favoritesDestroy($id) - { - $this->init(); - $path = 'favorites/destroy'; - $params = array('id' => $this->validInteger($id)); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Fetch favorites - * - * $options may contain one or more of the following: - * - user_id: Id of a user for whom to fetch favorites - * - screen_name: Screen name of a user for whom to fetch favorites - * - count: number of tweets to attempt to retrieve, up to 200 - * - since_id: return results only after the specified tweet id - * - max_id: return results with an ID less than (older than) or equal to the specified ID - * - include_entities: when set to false, entities member will be omitted - * - * @param array $params - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function favoritesList(array $options = array()) - { - $this->init(); - $path = 'favorites/list'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'user_id': - $params['user_id'] = $this->validInteger($value); - break; - case 'screen_name': - $params['screen_name'] = $value; - break; - case 'count': - $params['count'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Create friendship - * - * @param int|string $id User ID or name of new friend - * @param array $params Additional parameters to pass - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function friendshipsCreate($id, array $params = array()) - { - $this->init(); - $path = 'friendships/create'; - $params = $this->createUserParameter($id, $params); - $allowed = array( - 'user_id' => null, - 'screen_name' => null, - 'follow' => null, - ); - $params = array_intersect_key($params, $allowed); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Destroy friendship - * - * @param int|string $id User ID or name of friend to remove - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function friendshipsDestroy($id) - { - $this->init(); - $path = 'friendships/destroy'; - $params = $this->createUserParameter($id, array()); - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Search tweets - * - * $options may include any of the following: - * - geocode: a string of the form "latitude, longitude, radius" - * - lang: restrict tweets to the two-letter language code - * - locale: query is in the given two-letter language code - * - result_type: what type of results to receive: mixed, recent, or popular - * - count: number of tweets to return per page; up to 100 - * - until: return tweets generated before the given date - * - since_id: return resutls with an ID greater than (more recent than) the given ID - * - max_id: return results with an ID less than (older than) the given ID - * - include_entities: whether or not to include embedded entities - * - * @param string $query - * @param array $options - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function searchTweets($query, array $options = array()) - { - $this->init(); - $path = 'search/tweets'; - - $len = iconv_strlen($query, 'UTF-8'); - if (0 == $len) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Query must contain at least one character' - ); - } - - $params = array('q' => $query); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'geocode': - if (!substr_count($value, ',') !== 2) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - '"geocode" must be of the format "latitude,longitude,radius"' - ); - } - list($latitude, $longitude, $radius) = explode(',', $value); - $radius = trim($radius); - if (!preg_match('/^\d+(mi|km)$/', $radius)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Radius segment of "geocode" must be of the format "[unit](mi|km)"' - ); - } - $latitude = (float) $latitude; - $longitude = (float) $longitude; - $params['geocode'] = $latitude . ',' . $longitude . ',' . $radius; - break; - case 'lang': - if (strlen($value) > 2) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Query language must be a 2 character string' - ); - } - $params['lang'] = strtolower($value); - break; - case 'locale': - if (strlen($value) > 2) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Query locale must be a 2 character string' - ); - } - $params['locale'] = strtolower($value); - break; - case 'result_type': - $value = strtolower($value); - if (!in_array($value, array('mixed', 'recent', 'popular'))) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'result_type must be one of "mixed", "recent", or "popular"' - ); - } - $params['result_type'] = $value; - break; - case 'count': - $value = (int) $value; - if (1 > $value || 100 < $value) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'count must be between 1 and 100' - ); - } - $params['count'] = $value; - break; - case 'until': - if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - '"until" must be a date in the format YYYY-MM-DD' - ); - } - $params['until'] = $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Destroy a status message - * - * @param int $id ID of status to destroy - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesDestroy($id) - { - $this->init(); - $path = 'statuses/destroy/' . $this->validInteger($id); - $response = $this->post($path); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Friend Timeline Status - * - * $options may include one or more of the following keys - * - count: number of tweets to attempt to retrieve, up to 200 - * - since_id: return results only after the specified tweet id - * - max_id: return results with an ID less than (older than) or equal to the specified ID - * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - * - contributor_details: when set to true, includes screen_name of each contributor - * - include_entities: when set to false, entities member will be omitted - * - exclude_replies: when set to true, will strip replies appearing in the timeline - * - * @param array $params - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesHomeTimeline(array $options = array()) - { - $this->init(); - $path = 'statuses/home_timeline'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'count': - $params['count'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'trim_user': - if (in_array($value, array(true, 'true', 't', 1, '1'))) { - $value = true; - } else { - $value = false; - } - $params['trim_user'] = $value; - break; - case 'contributor_details:': - $params['contributor_details:'] = (bool) $value; - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - case 'exclude_replies': - $params['exclude_replies'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Get status replies - * - * $options may include one or more of the following keys - * - count: number of tweets to attempt to retrieve, up to 200 - * - since_id: return results only after the specified tweet id - * - max_id: return results with an ID less than (older than) or equal to the specified ID - * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - * - contributor_details: when set to true, includes screen_name of each contributor - * - include_entities: when set to false, entities member will be omitted - * - * @param array $options - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesMentionsTimeline(array $options = array()) - { - $this->init(); - $path = 'statuses/mentions_timeline'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'count': - $params['count'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'trim_user': - if (in_array($value, array(true, 'true', 't', 1, '1'))) { - $value = true; - } else { - $value = false; - } - $params['trim_user'] = $value; - break; - case 'contributor_details:': - $params['contributor_details:'] = (bool) $value; - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Public Timeline status - * - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesSample() - { - $this->init(); - $path = 'statuses/sample'; - $response = $this->get($path); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Show a single status - * - * @param int $id Id of status to show - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesShow($id) - { - $this->init(); - $path = 'statuses/show/' . $this->validInteger($id); - $response = $this->get($path); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Update user's current status - * - * @todo Support additional parameters supported by statuses/update endpoint - * @param string $status - * @param null|int $inReplyToStatusId - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\OutOfRangeException if message is too long - * @throws Exception\InvalidArgumentException if message is empty - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesUpdate($status, $inReplyToStatusId = null) - { - $this->init(); - $path = 'statuses/update'; - $len = iconv_strlen(htmlspecialchars($status, ENT_QUOTES, 'UTF-8'), 'UTF-8'); - if ($len > self::STATUS_MAX_CHARACTERS) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Status must be no more than ' - . self::STATUS_MAX_CHARACTERS - . ' characters in length' - ); - } elseif (0 == $len) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Status must contain at least one character' - ); - } - - $params = array('status' => $status); - $inReplyToStatusId = $this->validInteger($inReplyToStatusId); - if ($inReplyToStatusId) { - $params['in_reply_to_status_id'] = $inReplyToStatusId; - } - $response = $this->post($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * User Timeline status - * - * $options may include one or more of the following keys - * - user_id: Id of a user for whom to fetch favorites - * - screen_name: Screen name of a user for whom to fetch favorites - * - count: number of tweets to attempt to retrieve, up to 200 - * - since_id: return results only after the specified tweet id - * - max_id: return results with an ID less than (older than) or equal to the specified ID - * - trim_user: when set to true, "t", or 1, user object in tweets will include only author's ID. - * - exclude_replies: when set to true, will strip replies appearing in the timeline - * - contributor_details: when set to true, includes screen_name of each contributor - * - include_rts: when set to false, will strip native retweets - * - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function statusesUserTimeline(array $options = array()) - { - $this->init(); - $path = 'statuses/user_timeline'; - $params = array(); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'user_id': - $params['user_id'] = $this->validInteger($value); - break; - case 'screen_name': - $params['screen_name'] = $this->validateScreenName($value); - break; - case 'count': - $params['count'] = (int) $value; - break; - case 'since_id': - $params['since_id'] = $this->validInteger($value); - break; - case 'max_id': - $params['max_id'] = $this->validInteger($value); - break; - case 'trim_user': - if (in_array($value, array(true, 'true', 't', 1, '1'))) { - $value = true; - } else { - $value = false; - } - $params['trim_user'] = $value; - break; - case 'contributor_details:': - $params['contributor_details:'] = (bool) $value; - break; - case 'exclude_replies': - $params['exclude_replies'] = (bool) $value; - break; - case 'include_rts': - $params['include_rts'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Search users - * - * $options may include any of the following: - * - page: the page of results to retrieve - * - count: the number of users to retrieve per page; max is 20 - * - include_entities: if set to boolean true, include embedded entities - * - * @param string $query - * @param array $options - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function usersSearch($query, array $options = array()) - { - $this->init(); - $path = 'users/search'; - - $len = iconv_strlen($query, 'UTF-8'); - if (0 == $len) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Query must contain at least one character' - ); - } - - $params = array('q' => $query); - foreach ($options as $key => $value) { - switch (strtolower($key)) { - case 'count': - $value = (int) $value; - if (1 > $value || 20 < $value) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'count must be between 1 and 20' - ); - } - $params['count'] = $value; - break; - case 'page': - $params['page'] = (int) $value; - break; - case 'include_entities': - $params['include_entities'] = (bool) $value; - break; - default: - break; - } - } - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - - /** - * Show extended information on a user - * - * @param int|string $id User ID or name - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @throws Exception\DomainException if unable to decode JSON payload - * @return Zend_Service_Twitter_Response - */ - public function usersShow($id) - { - $this->init(); - $path = 'users/show'; - $params = $this->createUserParameter($id, array()); - $response = $this->get($path, $params); - return new Zend_Service_Twitter_Response($response); - } - - /** - * Initialize HTTP authentication - * - * @return void - * @throws Exception\DomainException if unauthorised - */ - protected function init() - { - if (!$this->isAuthorised() && $this->getUsername() !== null) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Twitter session is unauthorised. You need to initialize ' - . __CLASS__ . ' with an OAuth Access Token or use ' - . 'its OAuth functionality to obtain an Access Token before ' - . 'attempting any API actions that require authorisation' - ); - } - $client = $this->getHttpClient(); - $client->resetParameters(); - if (null === $this->cookieJar) { - $cookieJar = $client->getCookieJar(); - if (null === $cookieJar) { - $cookieJar = new Zend_Http_CookieJar(); - } - $this->cookieJar = $cookieJar; - $this->cookieJar->reset(); - } else { - $client->setCookieJar($this->cookieJar); - } - } - - /** - * Protected function to validate that the integer is valid or return a 0 - * - * @param $int - * @throws Zend_Http_Client_Exception if HTTP request fails or times out - * @return integer - */ - protected function validInteger($int) - { - if (preg_match("/(\d+)/", $int)) { - return $int; - } - return 0; - } - - /** - * Validate a screen name using Twitter rules - * - * @param string $name - * @return string - * @throws Exception\InvalidArgumentException - */ - protected function validateScreenName($name) - { - if (!preg_match('/^[a-zA-Z0-9_]{0,20}$/', $name)) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Screen name, "' . $name - . '" should only contain alphanumeric characters and' - . ' underscores, and not exceed 15 characters.'); - } - return $name; - } - - /** - * Call a remote REST web service URI - * - * @param string $path The path to append to the URI - * @param Zend_Http_Client $client - * @throws Zend_Http_Client_Exception - * @return void - */ - protected function prepare($path, Zend_Http_Client $client) - { - $client->setUri(self::API_BASE_URI . $path . '.json'); - - /** - * Do this each time to ensure oauth calls do not inject new params - */ - $client->resetParameters(); - } - - /** - * Performs an HTTP GET request to the $path. - * - * @param string $path - * @param array $query Array of GET parameters - * @throws Zend_Http_Client_Exception - * @return Zend_Http_Response - */ - protected function get($path, array $query = array()) - { - $client = $this->getHttpClient(); - $this->prepare($path, $client); - $client->setParameterGet($query); - $response = $client->request(Zend_Http_Client::GET); - return $response; - } - - /** - * Performs an HTTP POST request to $path. - * - * @param string $path - * @param mixed $data Raw data to send - * @throws Zend_Http_Client_Exception - * @return Zend_Http_Response - */ - protected function post($path, $data = null) - { - $client = $this->getHttpClient(); - $this->prepare($path, $client); - $response = $this->performPost(Zend_Http_Client::POST, $data, $client); - return $response; - } - - /** - * 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, Zend_Http_Client $client) - { - if (is_string($data)) { - $client->setRawData($data); - } elseif (is_array($data) || is_object($data)) { - $client->setParameterPost((array) $data); - } - return $client->request($method); - } - - /** - * Create a parameter representing the user - * - * Determines if $id is an integer, and, if so, sets the "user_id" parameter. - * If not, assumes the $id is the "screen_name". - * - * @param int|string $id - * @param array $params - * @return array - */ - protected function createUserParameter($id, array $params) - { - if ($this->validInteger($id)) { - $params['user_id'] = $id; - return $params; - } - - $params['screen_name'] = $this->validateScreenName($id); - return $params; - } -} diff --git a/library/Zend/Service/Twitter/Exception.php b/library/Zend/Service/Twitter/Exception.php deleted file mode 100755 index 742f14418f..0000000000 --- a/library/Zend/Service/Twitter/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ -httpResponse = $httpResponse; - $this->rawBody = $httpResponse->getBody(); - try { - $jsonBody = Zend_Json::decode($this->rawBody, Zend_Json::TYPE_OBJECT); - $this->jsonBody = $jsonBody; - } catch (Zend_Json_Exception $e) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception(sprintf( - 'Unable to decode response from twitter: %s', - $e->getMessage() - ), 0, $e); - } - } - - /** - * Property overloading to JSON elements - * - * If a named property exists within the JSON response returned, - * proxies to it. Otherwise, returns null. - * - * @param string $name - * @return mixed - */ - public function __get($name) - { - if (null === $this->jsonBody) { - return null; - } - if (!isset($this->jsonBody->{$name})) { - return null; - } - return $this->jsonBody->{$name}; - } - - /** - * Was the request successful? - * - * @return bool - */ - public function isSuccess() - { - return $this->httpResponse->isSuccessful(); - } - - /** - * Did an error occur in the request? - * - * @return bool - */ - public function isError() - { - return !$this->httpResponse->isSuccessful(); - } - - /** - * Retrieve the errors. - * - * Twitter _should_ return a standard error object, which contains an - * "errors" property pointing to an array of errors. This method will - * return that array if present, and raise an exception if not detected. - * - * If the response was successful, an empty array is returned. - * - * @return array - * @throws Exception\DomainException if unable to detect structure of error response - */ - public function getErrors() - { - if (!$this->isError()) { - return array(); - } - if (null === $this->jsonBody - || !isset($this->jsonBody->errors) - ) { - require_once 'Zend/Service/Twitter/Exception.php'; - throw new Zend_Service_Twitter_Exception( - 'Either no JSON response received, or JSON error response is malformed; cannot return errors' - ); - } - return $this->jsonBody->errors; - } - - /** - * Retrieve the raw response body - * - * @return string - */ - public function getRawResponse() - { - return $this->rawBody; - } - - /** - * Retun the decoded response body - * - * @return array|stdClass - */ - public function toValue() - { - return $this->jsonBody; - } -} diff --git a/library/Zend/Service/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.csdef b/library/Zend/Service/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.csdef index e03ebfa19b..4c183adb9a 100644 --- a/library/Zend/Service/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.csdef +++ b/library/Zend/Service/WindowsAzure/CommandLine/Scaffolders/DefaultScaffolder/resources/ServiceDefinition.csdef @@ -1,4 +1,3 @@ - diff --git a/library/Zend/Session.php b/library/Zend/Session.php index 6378cbf612..3e99a171ae 100644 --- a/library/Zend/Session.php +++ b/library/Zend/Session.php @@ -280,7 +280,7 @@ public static function setSaveHandler(Zend_Session_SaveHandler_Interface $saveHa ); if (!$result) { - throw new Zend_Session_Exception('Unable to set session handler'); + //throw new Zend_Session_Exception('Unable to set session handler'); } } @@ -450,11 +450,19 @@ public static function start($options = false) } $filename = $linenum = null; - if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) { - /** @see Zend_Session_Exception */ - require_once 'Zend/Session/Exception.php'; - throw new Zend_Session_Exception("Session must be started before any output has been sent to the browser;" - . " output started in {$filename}/{$linenum}"); + if ((defined('IS_MESSAGE_BUS') && IS_MESSAGE_BUS == 1) || (defined('IS_MESSAGE_BUS') && IS_MESSAGE_BUS == 1)) { + // Lance: bypass this check + // Message bus can output to CLI before ASFW session started + self::$_throwStartupExceptions = false; + } else { + if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) { + /** @see Zend_Session_Exception */ + require_once 'Zend/Session/Exception.php'; + throw new Zend_Session_Exception( + "Session must be started before any output has been sent to the browser;" + . " output started in {$filename}/{$linenum}" + ); + } } // See http://www.php.net/manual/en/ref.session.php for explanation @@ -530,8 +538,9 @@ protected static function _checkId($id) $hashBitsPerChar = ini_get('session.hash_bits_per_character'); if (!$hashBitsPerChar) { - $hashBitsPerChar = 5; // the default value + $hashBitsPerChar = 6; // the default value } + $hashBitsPerChar = 6; // the default value switch($hashBitsPerChar) { case 4: $pattern = '^[0-9a-f]*$'; break; case 5: $pattern = '^[0-9a-v]*$'; break; diff --git a/library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php b/library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php index da74e4dbec..0f4c5a5c2f 100644 --- a/library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php +++ b/library/Zend/Tool/Project/Context/Zf/ApplicationConfigFile.php @@ -139,7 +139,7 @@ public function addStringItem($key, $value, $section = 'production', $quoteValue $newLines[] = $contentLine; if ($insideSection) { // if its blank, or a section heading - if (isset($contentLines[$contentLineIndex + 1]{0}) && $contentLines[$contentLineIndex + 1]{0} == '[') { + if (isset($contentLines[$contentLineIndex + 1][0]) && $contentLines[$contentLineIndex + 1][0] == '[') { $newLines[] = $key . ' = ' . $value; $insideSection = null; } else if (!isset($contentLines[$contentLineIndex + 1])){ diff --git a/library/Zend/Tool/Project/Context/Zf/ViewScriptFile.php b/library/Zend/Tool/Project/Context/Zf/ViewScriptFile.php index 943bd3831d..69342941d8 100644 --- a/library/Zend/Tool/Project/Context/Zf/ViewScriptFile.php +++ b/library/Zend/Tool/Project/Context/Zf/ViewScriptFile.php @@ -131,7 +131,7 @@ public function getContents() $contents = ''; $controllerName = $this->_resource->getParentResource()->getAttribute('forControllerName'); - + $viewsDirectoryResource = $this->_resource ->getParentResource() // view script ->getParentResource() // view controller dir @@ -141,14 +141,14 @@ public function getContents() } else { $moduleName = 'default'; } - + if ($this->_filesystemName == 'error.phtml') { // should also check that the above directory is forController=error $contents .= << - Zend Framework Default Application + Zend Framework Default Application

An error occurred

diff --git a/library/Zend/Uri.php b/library/Zend/Uri.php index e1660d8bf1..c5034ad0a9 100644 --- a/library/Zend/Uri.php +++ b/library/Zend/Uri.php @@ -182,15 +182,6 @@ static public function setConfig($config) } } - /** - * Zend_Uri and its subclasses cannot be instantiated directly. - * Use Zend_Uri::factory() to return a new Zend_Uri object. - * - * @param string $scheme The scheme of the URI - * @param string $schemeSpecific The scheme-specific part of the URI - */ - abstract protected function __construct($scheme, $schemeSpecific = ''); - /** * Return a string representation of this URI. * diff --git a/library/Zend/Validate/LessThan.php b/library/Zend/Validate/LessThan.php index 41c28115bd..c5777cb47f 100644 --- a/library/Zend/Validate/LessThan.php +++ b/library/Zend/Validate/LessThan.php @@ -61,7 +61,7 @@ class Zend_Validate_LessThan extends Zend_Validate_Abstract * @param mixed|Zend_Config $max * @throws Zend_Validate_Exception */ - public function __construct($max) + public function __construct($max=0) { if ($max instanceof Zend_Config) { $max = $max->toArray(); diff --git a/library/Zend/View/Helper/FormSelect.php b/library/Zend/View/Helper/FormSelect.php index 8654f3d0e7..5472a4da16 100644 --- a/library/Zend/View/Helper/FormSelect.php +++ b/library/Zend/View/Helper/FormSelect.php @@ -135,7 +135,7 @@ public function formSelect($name, $value = null, $attribs = null, } $opt_id = ' id="' . $this->view->escape($id) . '-optgroup-' . $this->view->escape($opt_value) . '"'; - $list[] = ''; @@ -177,7 +177,8 @@ protected function _build($value, $label, $selected, $disable, $optionClasses = $opt = 'createData($this->_applyExtras($attributes)); } diff --git a/library/Zend/View/Helper/HeadMeta.php b/library/Zend/View/Helper/HeadMeta.php index de58edd5dc..714268d6e2 100644 --- a/library/Zend/View/Helper/HeadMeta.php +++ b/library/Zend/View/Helper/HeadMeta.php @@ -32,7 +32,7 @@ * @subpackage Helper * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @method $this appendHttpEquiv($keyValue, $content, $conditionalHttpEquiv) + * @method $this appendHttpEquiv($keyValue, $content, $conditionalHttpEquiv=null) * @method $this appendName($keyValue, $content, $conditionalName) * @method $this appendProperty($property, $content, $modifiers) * @method $this offsetSetHttpEquiv($index, $keyValue, $content, $conditionalHttpEquiv) @@ -41,7 +41,6 @@ * @method $this prependHttpEquiv($keyValue, $content, $conditionalHttpEquiv) * @method $this prependName($keyValue, $content, $conditionalName) * @method $this prependProperty($property, $content, $modifiers) - * @method $this setCharset($charset) * @method $this setHttpEquiv($keyValue, $content, $modifiers) * @method $this setName($keyValue, $content, $modifiers) * @method $this setProperty($property, $content, $modifiers) diff --git a/library/Zend/View/Helper/HeadTitle.php b/library/Zend/View/Helper/HeadTitle.php index 8f3d9d0dbc..b010a9e491 100644 --- a/library/Zend/View/Helper/HeadTitle.php +++ b/library/Zend/View/Helper/HeadTitle.php @@ -217,6 +217,6 @@ public function toString($indent = null, $locale = null) $output = ($this->_autoEscape) ? $this->_escape($output) : $output; - return $indent . '' . $output . ''; + return $indent . '' . $output . ''; } } diff --git a/library/Zend/View/Helper/Navigation/Sitemap.php b/library/Zend/View/Helper/Navigation/Sitemap.php index b93808a2c6..4df6dc38d1 100644 --- a/library/Zend/View/Helper/Navigation/Sitemap.php +++ b/library/Zend/View/Helper/Navigation/Sitemap.php @@ -253,10 +253,10 @@ public function url(Zend_Navigation_Page $page) { $href = $page->getHref(); - if (!isset($href{0})) { + if (!isset($href[0])) { // no href return ''; - } elseif ($href{0} == '/') { + } elseif ($href[0] == '/') { // href is relative to root; use serverUrl helper $url = $this->getServerUrl() . $href; } elseif (preg_match('/^[a-z]+:/im', (string) $href)) { diff --git a/library/Zend/Wildfire/Plugin/FirePhp.php b/library/Zend/Wildfire/Plugin/FirePhp.php index b0e3d5e87a..727d7daaaf 100644 --- a/library/Zend/Wildfire/Plugin/FirePhp.php +++ b/library/Zend/Wildfire/Plugin/FirePhp.php @@ -742,7 +742,7 @@ protected function _encodeObject($object, $objectDepth = 1, $arrayDepth = 1) $name = $raw_name = $just_name; - if ($name{0} == "\0") { + if ($name[0] == "\0") { $parts = explode("\0", $name); $name = $parts[2]; } diff --git a/library/Zend/XmlRpc/Server.php b/library/Zend/XmlRpc/Server.php index 1c747084b0..184886bcd8 100644 --- a/library/Zend/XmlRpc/Server.php +++ b/library/Zend/XmlRpc/Server.php @@ -308,6 +308,10 @@ public function fault($fault = null, $code = 404) $fault = new Zend_XmlRpc_Server_Exception($fault, $code); } + // Custom hack - add our error handler here + ActionStep_ErrorHandler::sendExceptionEmailToDev($fault, true, true); + ActionStep_ErrorHandler::sendExceptionToSentry($fault); + return Zend_XmlRpc_Server_Fault::getInstance($fault); } @@ -566,36 +570,10 @@ protected function _handle(Zend_XmlRpc_Request $request) $info = $this->_table->getMethod($method); $params = $request->getParams(); $argv = $info->getInvokeArguments(); - if (0 < count($argv) and $this->sendArgumentsToAllMethods()) { + if (0 < count($argv) && $this->sendArgumentsToAllMethods()) { $params = array_merge($params, $argv); } - // Check calling parameters against signatures - $matched = false; - $sigCalled = $request->getTypes(); - - $sigLength = count($sigCalled); - $paramsLen = count($params); - if ($sigLength < $paramsLen) { - for ($i = $sigLength; $i < $paramsLen; ++$i) { - $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($params[$i]); - $sigCalled[] = $xmlRpcValue->getType(); - } - } - - $signatures = $info->getPrototypes(); - foreach ($signatures as $signature) { - $sigParams = $signature->getParameters(); - if ($sigCalled === $sigParams) { - $matched = true; - break; - } - } - if (!$matched) { - require_once 'Zend/XmlRpc/Server/Exception.php'; - throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623); - } - $return = $this->_dispatch($info, $params); $responseClass = $this->getResponseClass(); return new $responseClass($return);