From 3326ee2a4d46934b97800a70299db1a633ef82c3 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 10 Jul 2010 02:06:56 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Piwik=20=E5=88=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit +YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@439 a2543c7e-f6e9-4f8a-8bff-1ffc34733512 --- oss/piwik/trunk/libs/Zend/Auth.php | 169 + oss/piwik/trunk/libs/Zend/Cache.php | 250 ++ oss/piwik/trunk/libs/Zend/Config.php | 484 +++ oss/piwik/trunk/libs/Zend/Db.php | 281 ++ oss/piwik/trunk/libs/Zend/Exception.php | 95 + oss/piwik/trunk/libs/Zend/Feed.php | 411 +++ oss/piwik/trunk/libs/Zend/Loader.php | 329 ++ oss/piwik/trunk/libs/Zend/Log.php | 425 +++ oss/piwik/trunk/libs/Zend/Mail.php | 1261 +++++++ oss/piwik/trunk/libs/Zend/Mime.php | 365 +++ oss/piwik/trunk/libs/Zend/Registry.php | 209 ++ oss/piwik/trunk/libs/Zend/Session.php | 880 +++++ oss/piwik/trunk/libs/Zend/Uri.php | 204 ++ oss/piwik/trunk/libs/Zend/Validate.php | 290 ++ .../trunk/libs/Zend/Validate/Abstract.php | 456 +++ oss/piwik/trunk/libs/Zend/Validate/Alnum.php | 150 + oss/piwik/trunk/libs/Zend/Validate/Alpha.php | 150 + .../trunk/libs/Zend/Validate/Barcode.php | 217 ++ .../Zend/Validate/Barcode/AdapterAbstract.php | 315 ++ .../Validate/Barcode/AdapterInterface.php | 68 + .../libs/Zend/Validate/Barcode/Code25.php | 64 + .../Validate/Barcode/Code25interleaved.php | 64 + .../libs/Zend/Validate/Barcode/Code39.php | 100 + .../libs/Zend/Validate/Barcode/Code39ext.php | 58 + .../libs/Zend/Validate/Barcode/Code93.php | 120 + .../libs/Zend/Validate/Barcode/Code93ext.php | 58 + .../libs/Zend/Validate/Barcode/Ean12.php | 52 + .../libs/Zend/Validate/Barcode/Ean13.php | 52 + .../libs/Zend/Validate/Barcode/Ean14.php | 52 + .../libs/Zend/Validate/Barcode/Ean18.php | 52 + .../trunk/libs/Zend/Validate/Barcode/Ean2.php | 58 + .../trunk/libs/Zend/Validate/Barcode/Ean5.php | 58 + .../trunk/libs/Zend/Validate/Barcode/Ean8.php | 69 + .../libs/Zend/Validate/Barcode/Gtin12.php | 52 + .../libs/Zend/Validate/Barcode/Gtin13.php | 52 + .../libs/Zend/Validate/Barcode/Gtin14.php | 52 + .../libs/Zend/Validate/Barcode/Identcode.php | 52 + .../Zend/Validate/Barcode/Intelligentmail.php | 58 + .../trunk/libs/Zend/Validate/Barcode/Issn.php | 119 + .../libs/Zend/Validate/Barcode/Itf14.php | 52 + .../libs/Zend/Validate/Barcode/Leitcode.php | 52 + .../libs/Zend/Validate/Barcode/Planet.php | 52 + .../libs/Zend/Validate/Barcode/Postnet.php | 52 + .../libs/Zend/Validate/Barcode/Royalmail.php | 121 + .../trunk/libs/Zend/Validate/Barcode/Sscc.php | 52 + .../trunk/libs/Zend/Validate/Barcode/Upca.php | 52 + .../trunk/libs/Zend/Validate/Barcode/Upce.php | 69 + .../trunk/libs/Zend/Validate/Between.php | 224 ++ .../trunk/libs/Zend/Validate/Callback.php | 174 + oss/piwik/trunk/libs/Zend/Validate/Ccnum.php | 112 + .../trunk/libs/Zend/Validate/CreditCard.php | 317 ++ oss/piwik/trunk/libs/Zend/Validate/Date.php | 259 ++ .../trunk/libs/Zend/Validate/Db/Abstract.php | 298 ++ .../libs/Zend/Validate/Db/NoRecordExists.php | 51 + .../libs/Zend/Validate/Db/RecordExists.php | 51 + oss/piwik/trunk/libs/Zend/Validate/Digits.php | 91 + .../trunk/libs/Zend/Validate/EmailAddress.php | 560 ++++ .../trunk/libs/Zend/Validate/Exception.php | 34 + .../trunk/libs/Zend/Validate/File/Count.php | 284 ++ .../trunk/libs/Zend/Validate/File/Crc32.php | 179 + .../Zend/Validate/File/ExcludeExtension.php | 94 + .../Zend/Validate/File/ExcludeMimeType.php | 109 + .../trunk/libs/Zend/Validate/File/Exists.php | 203 ++ .../libs/Zend/Validate/File/Extension.php | 232 ++ .../libs/Zend/Validate/File/FilesSize.php | 164 + .../trunk/libs/Zend/Validate/File/Hash.php | 194 ++ .../libs/Zend/Validate/File/ImageSize.php | 364 ++ .../libs/Zend/Validate/File/IsCompressed.php | 149 + .../trunk/libs/Zend/Validate/File/IsImage.php | 173 + .../trunk/libs/Zend/Validate/File/Md5.php | 183 ++ .../libs/Zend/Validate/File/MimeType.php | 392 +++ .../libs/Zend/Validate/File/NotExists.php | 84 + .../trunk/libs/Zend/Validate/File/Sha1.php | 181 + .../trunk/libs/Zend/Validate/File/Size.php | 404 +++ .../trunk/libs/Zend/Validate/File/Upload.php | 245 ++ .../libs/Zend/Validate/File/WordCount.php | 101 + oss/piwik/trunk/libs/Zend/Validate/Float.php | 134 + .../trunk/libs/Zend/Validate/GreaterThan.php | 124 + oss/piwik/trunk/libs/Zend/Validate/Hex.php | 72 + .../trunk/libs/Zend/Validate/Hostname.php | 740 +++++ .../trunk/libs/Zend/Validate/Hostname/Biz.php | 2917 +++++++++++++++++ .../trunk/libs/Zend/Validate/Hostname/Cn.php | 2199 +++++++++++++ .../trunk/libs/Zend/Validate/Hostname/Com.php | 198 ++ .../trunk/libs/Zend/Validate/Hostname/Jp.php | 739 +++++ oss/piwik/trunk/libs/Zend/Validate/Iban.php | 223 ++ .../trunk/libs/Zend/Validate/Identical.php | 164 + .../trunk/libs/Zend/Validate/InArray.php | 204 ++ oss/piwik/trunk/libs/Zend/Validate/Int.php | 148 + .../trunk/libs/Zend/Validate/Interface.php | 54 + oss/piwik/trunk/libs/Zend/Validate/Ip.php | 191 ++ oss/piwik/trunk/libs/Zend/Validate/Isbn.php | 279 ++ .../trunk/libs/Zend/Validate/LessThan.php | 122 + .../trunk/libs/Zend/Validate/NotEmpty.php | 237 ++ .../trunk/libs/Zend/Validate/PostCode.php | 210 ++ oss/piwik/trunk/libs/Zend/Validate/Regex.php | 147 + .../libs/Zend/Validate/Sitemap/Changefreq.php | 95 + .../libs/Zend/Validate/Sitemap/Lastmod.php | 88 + .../trunk/libs/Zend/Validate/Sitemap/Loc.php | 87 + .../libs/Zend/Validate/Sitemap/Priority.php | 82 + .../trunk/libs/Zend/Validate/StringLength.php | 253 ++ oss/piwik/trunk/libs/Zend/Version.php | 53 + 101 files changed, 24419 insertions(+) create mode 100644 oss/piwik/trunk/libs/Zend/Auth.php create mode 100644 oss/piwik/trunk/libs/Zend/Cache.php create mode 100644 oss/piwik/trunk/libs/Zend/Config.php create mode 100644 oss/piwik/trunk/libs/Zend/Db.php create mode 100644 oss/piwik/trunk/libs/Zend/Exception.php create mode 100644 oss/piwik/trunk/libs/Zend/Feed.php create mode 100644 oss/piwik/trunk/libs/Zend/Loader.php create mode 100644 oss/piwik/trunk/libs/Zend/Log.php create mode 100644 oss/piwik/trunk/libs/Zend/Mail.php create mode 100644 oss/piwik/trunk/libs/Zend/Mime.php create mode 100644 oss/piwik/trunk/libs/Zend/Registry.php create mode 100644 oss/piwik/trunk/libs/Zend/Session.php create mode 100644 oss/piwik/trunk/libs/Zend/Uri.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Abstract.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Alnum.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Alpha.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/AdapterAbstract.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/AdapterInterface.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code25.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code25interleaved.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code39.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code39ext.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code93.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Code93ext.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean12.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean13.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean14.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean18.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean2.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean5.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Ean8.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Gtin12.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Gtin13.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Gtin14.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Identcode.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Intelligentmail.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Issn.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Itf14.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Leitcode.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Planet.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Postnet.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Royalmail.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Sscc.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Upca.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Barcode/Upce.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Between.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Callback.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Ccnum.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/CreditCard.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Date.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Db/Abstract.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Db/NoRecordExists.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Db/RecordExists.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Digits.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/EmailAddress.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Exception.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Count.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Crc32.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/ExcludeExtension.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/ExcludeMimeType.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Exists.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Extension.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/FilesSize.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Hash.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/ImageSize.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/IsCompressed.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/IsImage.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Md5.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/MimeType.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/NotExists.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Sha1.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Size.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/Upload.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/File/WordCount.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Float.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/GreaterThan.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hex.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hostname.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hostname/Biz.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hostname/Cn.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hostname/Com.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Hostname/Jp.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Iban.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Identical.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/InArray.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Int.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Interface.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Ip.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Isbn.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/LessThan.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/NotEmpty.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/PostCode.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Regex.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Sitemap/Changefreq.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Sitemap/Lastmod.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Sitemap/Loc.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/Sitemap/Priority.php create mode 100644 oss/piwik/trunk/libs/Zend/Validate/StringLength.php create mode 100644 oss/piwik/trunk/libs/Zend/Version.php diff --git a/oss/piwik/trunk/libs/Zend/Auth.php b/oss/piwik/trunk/libs/Zend/Auth.php new file mode 100644 index 00000000..47d47445 --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Auth.php @@ -0,0 +1,169 @@ +_storage) { + /** + * @see Zend_Auth_Storage_Session + */ + // require_once 'Zend/Auth/Storage/Session.php'; + $this->setStorage(new Zend_Auth_Storage_Session()); + } + + return $this->_storage; + } + + /** + * Sets the persistent storage handler + * + * @param Zend_Auth_Storage_Interface $storage + * @return Zend_Auth Provides a fluent interface + */ + public function setStorage(Zend_Auth_Storage_Interface $storage) + { + $this->_storage = $storage; + return $this; + } + + /** + * Authenticates against the supplied adapter + * + * @param Zend_Auth_Adapter_Interface $adapter + * @return Zend_Auth_Result + */ + public function authenticate(Zend_Auth_Adapter_Interface $adapter) + { + $result = $adapter->authenticate(); + + /** + * ZF-7546 - prevent multiple succesive calls from storing inconsistent results + * Ensure storage has clean state + */ + if ($this->hasIdentity()) { + $this->clearIdentity(); + } + + if ($result->isValid()) { + $this->getStorage()->write($result->getIdentity()); + } + + return $result; + } + + /** + * Returns true if and only if an identity is available from storage + * + * @return boolean + */ + public function hasIdentity() + { + return !$this->getStorage()->isEmpty(); + } + + /** + * Returns the identity from storage or null if no identity is available + * + * @return mixed|null + */ + public function getIdentity() + { + $storage = $this->getStorage(); + + if ($storage->isEmpty()) { + return null; + } + + return $storage->read(); + } + + /** + * Clears the identity from persistent storage + * + * @return void + */ + public function clearIdentity() + { + $this->getStorage()->clear(); + } +} diff --git a/oss/piwik/trunk/libs/Zend/Cache.php b/oss/piwik/trunk/libs/Zend/Cache.php new file mode 100644 index 00000000..761be75e --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Cache.php @@ -0,0 +1,250 @@ +setBackend($backendObject); + return $frontendObject; + } + + /** + * Frontend Constructor + * + * @param string $backend + * @param array $backendOptions + * @param boolean $customBackendNaming + * @param boolean $autoload + * @return Zend_Cache_Backend + */ + public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false) + { + if (!$customBackendNaming) { + $backend = self::_normalizeName($backend); + } + if (in_array($backend, Zend_Cache::$standardBackends)) { + // we use a standard backend + $backendClass = 'Zend_Cache_Backend_' . $backend; + // security controls are explicit + // require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php'; + } else { + // we use a custom backend + if (!preg_match('~^[\w]+$~D', $backend)) { + Zend_Cache::throwException("Invalid backend name [$backend]"); + } + if (!$customBackendNaming) { + // we use this boolean to avoid an API break + $backendClass = 'Zend_Cache_Backend_' . $backend; + } else { + $backendClass = $backend; + } + if (!$autoload) { + $file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php'; + if (!(self::_isReadable($file))) { + self::throwException("file $file not found in include_path"); + } + // require_once $file; + } + } + return new $backendClass($backendOptions); + } + + /** + * Backend Constructor + * + * @param string $frontend + * @param array $frontendOptions + * @param boolean $customFrontendNaming + * @param boolean $autoload + * @return Zend_Cache_Core|Zend_Cache_Frontend + */ + public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false) + { + if (!$customFrontendNaming) { + $frontend = self::_normalizeName($frontend); + } + if (in_array($frontend, self::$standardFrontends)) { + // we use a standard frontend + // For perfs reasons, with frontend == 'Core', we can interact with the Core itself + $frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend; + // security controls are explicit + // require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php'; + } else { + // we use a custom frontend + if (!preg_match('~^[\w]+$~D', $frontend)) { + Zend_Cache::throwException("Invalid frontend name [$frontend]"); + } + if (!$customFrontendNaming) { + // we use this boolean to avoid an API break + $frontendClass = 'Zend_Cache_Frontend_' . $frontend; + } else { + $frontendClass = $frontend; + } + if (!$autoload) { + $file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php'; + if (!(self::_isReadable($file))) { + self::throwException("file $file not found in include_path"); + } + // require_once $file; + } + } + return new $frontendClass($frontendOptions); + } + + /** + * Throw an exception + * + * Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic + * @param string $msg Message for the exception + * @throws Zend_Cache_Exception + */ + public static function throwException($msg, Exception $e = null) + { + // For perfs reasons, we use this dynamic inclusion + // require_once 'Zend/Cache/Exception.php'; + throw new Zend_Cache_Exception($msg, 0, $e); + } + + /** + * Normalize frontend and backend names to allow multiple words TitleCased + * + * @param string $name Name to normalize + * @return string + */ + protected static function _normalizeName($name) + { + $name = ucfirst(strtolower($name)); + $name = str_replace(array('-', '_', '.'), ' ', $name); + $name = ucwords($name); + $name = str_replace(' ', '', $name); + if (stripos($name, 'ZendServer') === 0) { + $name = 'ZendServer_' . substr($name, strlen('ZendServer')); + } + + return $name; + } + + /** + * Returns TRUE if the $filename is readable, or FALSE otherwise. + * This function uses the PHP include_path, where PHP's is_readable() + * does not. + * + * Note : this method comes from Zend_Loader (see #ZF-2891 for details) + * + * @param string $filename + * @return boolean + */ + private static function _isReadable($filename) + { + if (!$fh = @fopen($filename, 'r', true)) { + return false; + } + @fclose($fh); + return true; + } + +} diff --git a/oss/piwik/trunk/libs/Zend/Config.php b/oss/piwik/trunk/libs/Zend/Config.php new file mode 100644 index 00000000..0ba76392 --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Config.php @@ -0,0 +1,484 @@ +_allowModifications = (boolean) $allowModifications; + $this->_loadedSection = null; + $this->_index = 0; + $this->_data = array(); + foreach ($array as $key => $value) { + if (is_array($value)) { + $this->_data[$key] = new self($value, $this->_allowModifications); + } else { + $this->_data[$key] = $value; + } + } + $this->_count = count($this->_data); + } + + /** + * Retrieve a value and return $default if there is no element set. + * + * @param string $name + * @param mixed $default + * @return mixed + */ + public function get($name, $default = null) + { + $result = $default; + if (array_key_exists($name, $this->_data)) { + $result = $this->_data[$name]; + } + return $result; + } + + /** + * Magic function so that $obj->value will work. + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + return $this->get($name); + } + + /** + * Only allow setting of a property if $allowModifications + * was set to true on construction. Otherwise, throw an exception. + * + * @param string $name + * @param mixed $value + * @throws Zend_Config_Exception + * @return void + */ + public function __set($name, $value) + { + if ($this->_allowModifications) { + if (is_array($value)) { + $this->_data[$name] = new self($value, true); + } else { + $this->_data[$name] = $value; + } + $this->_count = count($this->_data); + } else { + /** @see Zend_Config_Exception */ + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Zend_Config is read only'); + } + } + + /** + * Deep clone of this instance to ensure that nested Zend_Configs + * are also cloned. + * + * @return void + */ + public function __clone() + { + $array = array(); + foreach ($this->_data as $key => $value) { + if ($value instanceof Zend_Config) { + $array[$key] = clone $value; + } else { + $array[$key] = $value; + } + } + $this->_data = $array; + } + + /** + * Return an associative array of the stored data. + * + * @return array + */ + public function toArray() + { + $array = array(); + $data = $this->_data; + foreach ($data as $key => $value) { + if ($value instanceof Zend_Config) { + $array[$key] = $value->toArray(); + } else { + $array[$key] = $value; + } + } + return $array; + } + + /** + * Support isset() overloading on PHP 5.1 + * + * @param string $name + * @return boolean + */ + public function __isset($name) + { + return isset($this->_data[$name]); + } + + /** + * Support unset() overloading on PHP 5.1 + * + * @param string $name + * @throws Zend_Config_Exception + * @return void + */ + public function __unset($name) + { + if ($this->_allowModifications) { + unset($this->_data[$name]); + $this->_count = count($this->_data); + $this->_skipNextIteration = true; + } else { + /** @see Zend_Config_Exception */ + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Zend_Config is read only'); + } + + } + + /** + * Defined by Countable interface + * + * @return int + */ + public function count() + { + return $this->_count; + } + + /** + * Defined by Iterator interface + * + * @return mixed + */ + public function current() + { + $this->_skipNextIteration = false; + return current($this->_data); + } + + /** + * Defined by Iterator interface + * + * @return mixed + */ + public function key() + { + return key($this->_data); + } + + /** + * Defined by Iterator interface + * + */ + public function next() + { + if ($this->_skipNextIteration) { + $this->_skipNextIteration = false; + return; + } + next($this->_data); + $this->_index++; + } + + /** + * Defined by Iterator interface + * + */ + public function rewind() + { + $this->_skipNextIteration = false; + reset($this->_data); + $this->_index = 0; + } + + /** + * Defined by Iterator interface + * + * @return boolean + */ + public function valid() + { + return $this->_index < $this->_count; + } + + /** + * Returns the section name(s) loaded. + * + * @return mixed + */ + public function getSectionName() + { + if(is_array($this->_loadedSection) && count($this->_loadedSection) == 1) { + $this->_loadedSection = $this->_loadedSection[0]; + } + return $this->_loadedSection; + } + + /** + * Returns true if all sections were loaded + * + * @return boolean + */ + public function areAllSectionsLoaded() + { + return $this->_loadedSection === null; + } + + + /** + * Merge another Zend_Config with this one. The items + * in $merge will override the same named items in + * the current config. + * + * @param Zend_Config $merge + * @return Zend_Config + */ + public function merge(Zend_Config $merge) + { + foreach($merge as $key => $item) { + if(array_key_exists($key, $this->_data)) { + if($item instanceof Zend_Config && $this->$key instanceof Zend_Config) { + $this->$key = $this->$key->merge(new Zend_Config($item->toArray(), !$this->readOnly())); + } else { + $this->$key = $item; + } + } else { + if($item instanceof Zend_Config) { + $this->$key = new Zend_Config($item->toArray(), !$this->readOnly()); + } else { + $this->$key = $item; + } + } + } + + return $this; + } + + /** + * Prevent any more modifications being made to this instance. Useful + * after merge() has been used to merge multiple Zend_Config objects + * into one object which should then not be modified again. + * + */ + public function setReadOnly() + { + $this->_allowModifications = false; + foreach ($this->_data as $key => $value) { + if ($value instanceof Zend_Config) { + $value->setReadOnly(); + } + } + } + + /** + * Returns if this Zend_Config object is read only or not. + * + * @return boolean + */ + public function readOnly() + { + return !$this->_allowModifications; + } + + /** + * Get the current extends + * + * @return array + */ + public function getExtends() + { + return $this->_extends; + } + + /** + * Set an extend for Zend_Config_Writer + * + * @param string $extendingSection + * @param string $extendedSection + * @return void + */ + public function setExtend($extendingSection, $extendedSection = null) + { + if ($extendedSection === null && isset($this->_extends[$extendingSection])) { + unset($this->_extends[$extendingSection]); + } else if ($extendedSection !== null) { + $this->_extends[$extendingSection] = $extendedSection; + } + } + + /** + * Throws an exception if $extendingSection may not extend $extendedSection, + * and tracks the section extension if it is valid. + * + * @param string $extendingSection + * @param string $extendedSection + * @throws Zend_Config_Exception + * @return void + */ + protected function _assertValidExtend($extendingSection, $extendedSection) + { + // detect circular section inheritance + $extendedSectionCurrent = $extendedSection; + while (array_key_exists($extendedSectionCurrent, $this->_extends)) { + if ($this->_extends[$extendedSectionCurrent] == $extendingSection) { + /** @see Zend_Config_Exception */ + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Illegal circular inheritance detected'); + } + $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent]; + } + // remember that this section extends another section + $this->_extends[$extendingSection] = $extendedSection; + } + + /** + * Handle any errors from simplexml_load_file or parse_ini_file + * + * @param integer $errno + * @param string $errstr + * @param string $errfile + * @param integer $errline + */ + protected function _loadFileErrorHandler($errno, $errstr, $errfile, $errline) + { + if ($this->_loadFileErrorStr === null) { + $this->_loadFileErrorStr = $errstr; + } else { + $this->_loadFileErrorStr .= (PHP_EOL . $errstr); + } + } + + /** + * Merge two arrays recursively, overwriting keys of the same name + * in $firstArray with the value in $secondArray. + * + * @param mixed $firstArray First array + * @param mixed $secondArray Second array to merge into first array + * @return array + */ + protected function _arrayMergeRecursive($firstArray, $secondArray) + { + if (is_array($firstArray) && is_array($secondArray)) { + foreach ($secondArray as $key => $value) { + if (isset($firstArray[$key])) { + $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); + } else { + if($key === 0) { + $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); + } else { + $firstArray[$key] = $value; + } + } + } + } else { + $firstArray = $secondArray; + } + + return $firstArray; + } +} \ No newline at end of file diff --git a/oss/piwik/trunk/libs/Zend/Db.php b/oss/piwik/trunk/libs/Zend/Db.php new file mode 100644 index 00000000..9bbf1e79 --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Db.php @@ -0,0 +1,281 @@ +toArray(); + } + + /* + * Convert Zend_Config argument to plain string + * adapter name and separate config object. + */ + if ($adapter instanceof Zend_Config) { + if (isset($adapter->params)) { + $config = $adapter->params->toArray(); + } + if (isset($adapter->adapter)) { + $adapter = (string) $adapter->adapter; + } else { + $adapter = null; + } + } + + /* + * Verify that adapter parameters are in an array. + */ + if (!is_array($config)) { + /** + * @see Zend_Db_Exception + */ + // require_once 'Zend/Db/Exception.php'; + throw new Zend_Db_Exception('Adapter parameters must be in an array or a Zend_Config object'); + } + + /* + * Verify that an adapter name has been specified. + */ + if (!is_string($adapter) || empty($adapter)) { + /** + * @see Zend_Db_Exception + */ + // require_once 'Zend/Db/Exception.php'; + throw new Zend_Db_Exception('Adapter name must be specified in a string'); + } + + /* + * Form full adapter class name + */ + $adapterNamespace = 'Zend_Db_Adapter'; + if (isset($config['adapterNamespace'])) { + if ($config['adapterNamespace'] != '') { + $adapterNamespace = $config['adapterNamespace']; + } + unset($config['adapterNamespace']); + } + + // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606 + $adapterName = $adapterNamespace . '_'; + $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter)))); + + /* + * Load the adapter class. This throws an exception + * if the specified class cannot be loaded. + */ + // if (!class_exists($adapterName)) { + // require_once 'Zend/Loader.php'; + // Zend_Loader::loadClass($adapterName); + // } + + /* + * Create an instance of the adapter class. + * Pass the config to the adapter class constructor. + */ + $dbAdapter = new $adapterName($config); + + /* + * Verify that the object created is a descendent of the abstract adapter type. + */ + if (! $dbAdapter instanceof Zend_Db_Adapter_Abstract) { + /** + * @see Zend_Db_Exception + */ + // require_once 'Zend/Db/Exception.php'; + throw new Zend_Db_Exception("Adapter class '$adapterName' does not extend Zend_Db_Adapter_Abstract"); + } + + return $dbAdapter; + } + +} diff --git a/oss/piwik/trunk/libs/Zend/Exception.php b/oss/piwik/trunk/libs/Zend/Exception.php new file mode 100644 index 00000000..bbfb792e --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Exception.php @@ -0,0 +1,95 @@ +_previous = $previous; + } else { + parent::__construct($msg, (int) $code, $previous); + } + } + + /** + * Overloading + * + * For PHP < 5.3.0, provides access to the getPrevious() method. + * + * @param string $method + * @param array $args + * @return mixed + */ + public function __call($method, array $args) + { + if ('getprevious' == strtolower($method)) { + return $this->_getPrevious(); + } + return null; + } + + /** + * String representation of the exception + * + * @return string + */ + public function __toString() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) { + if (null !== ($e = $this->getPrevious())) { + return $e->__toString() + . "\n\nNext " + . parent::__toString(); + } + } + return parent::__toString(); + } + + /** + * Returns previous Exception + * + * @return Exception|null + */ + protected function _getPrevious() + { + return $this->_previous; + } +} diff --git a/oss/piwik/trunk/libs/Zend/Feed.php b/oss/piwik/trunk/libs/Zend/Feed.php new file mode 100644 index 00000000..5e4d7b08 --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Feed.php @@ -0,0 +1,411 @@ + 'http://a9.com/-/spec/opensearchrss/1.0/', + 'atom' => 'http://www.w3.org/2005/Atom', + 'rss' => 'http://blogs.law.harvard.edu/tech/rss', + ); + + + /** + * Set the HTTP client instance + * + * Sets the HTTP client object to use for retrieving the feeds. + * + * @param Zend_Http_Client $httpClient + * @return void + */ + public static function setHttpClient(Zend_Http_Client $httpClient) + { + self::$_httpClient = $httpClient; + } + + + /** + * Gets the HTTP client object. If none is set, a new Zend_Http_Client will be used. + * + * @return Zend_Http_Client_Abstract + */ + public static function getHttpClient() + { + if (!self::$_httpClient instanceof Zend_Http_Client) { + /** + * @see Zend_Http_Client + */ + // require_once 'Zend/Http/Client.php'; + self::$_httpClient = new Zend_Http_Client(); + } + + return self::$_httpClient; + } + + + /** + * Toggle using POST instead of PUT and DELETE HTTP methods + * + * Some feed implementations do not accept PUT and DELETE HTTP + * methods, or they can't be used because of proxies or other + * measures. This allows turning on using POST where PUT and + * DELETE would normally be used; in addition, an + * X-Method-Override header will be sent with a value of PUT or + * DELETE as appropriate. + * + * @param boolean $override Whether to override PUT and DELETE. + * @return void + */ + public static function setHttpMethodOverride($override = true) + { + self::$_httpMethodOverride = $override; + } + + + /** + * Get the HTTP override state + * + * @return boolean + */ + public static function getHttpMethodOverride() + { + return self::$_httpMethodOverride; + } + + + /** + * Get the full version of a namespace prefix + * + * Looks up a prefix (atom:, etc.) in the list of registered + * namespaces and returns the full namespace URI if + * available. Returns the prefix, unmodified, if it's not + * registered. + * + * @return string + */ + public static function lookupNamespace($prefix) + { + return isset(self::$_namespaces[$prefix]) ? + self::$_namespaces[$prefix] : + $prefix; + } + + + /** + * Add a namespace and prefix to the registered list + * + * Takes a prefix and a full namespace URI and adds them to the + * list of registered namespaces for use by + * Zend_Feed::lookupNamespace(). + * + * @param string $prefix The namespace prefix + * @param string $namespaceURI The full namespace URI + * @return void + */ + public static function registerNamespace($prefix, $namespaceURI) + { + self::$_namespaces[$prefix] = $namespaceURI; + } + + + /** + * Imports a feed located at $uri. + * + * @param string $uri + * @throws Zend_Feed_Exception + * @return Zend_Feed_Abstract + */ + public static function import($uri) + { + $client = self::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()); + } + $feed = $response->getBody(); + return self::importString($feed); + } + + + /** + * Imports a feed represented by $string. + * + * @param string $string + * @throws Zend_Feed_Exception + * @return Zend_Feed_Abstract + */ + public static function importString($string) + { + // Load the feed as an XML DOMDocument object + $libxml_errflag = libxml_use_internal_errors(true); + $doc = new DOMDocument; + if (trim($string) == '') { + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Document/string being imported' + . ' is an Empty string or comes from an empty HTTP response'); + } + $status = $doc->loadXML($string); + libxml_use_internal_errors($libxml_errflag); + + + if (!$status) { + // prevent the class to generate an undefined variable notice (ZF-2590) + // Build error message + $error = libxml_get_last_error(); + if ($error && $error->message) { + $errormsg = "DOMDocument cannot parse XML: {$error->message}"; + } else { + $errormsg = "DOMDocument cannot parse XML"; + } + + + /** + * @see Zend_Feed_Exception + */ + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception($errormsg); + } + + // Try to find the base feed element or a single of an Atom feed + if ($doc->getElementsByTagName('feed')->item(0) || + $doc->getElementsByTagName('entry')->item(0)) { + /** + * @see Zend_Feed_Atom + */ + // require_once 'Zend/Feed/Atom.php'; + // return a newly created Zend_Feed_Atom object + return new Zend_Feed_Atom(null, $string); + } + + // Try to find the base feed element of an RSS feed + if ($doc->getElementsByTagName('channel')->item(0)) { + /** + * @see Zend_Feed_Rss + */ + // require_once 'Zend/Feed/Rss.php'; + // return a newly created Zend_Feed_Rss object + return new Zend_Feed_Rss(null, $string); + } + + // $string does not appear to be a valid feed of the supported types + /** + * @see Zend_Feed_Exception + */ + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid or unsupported feed format'); + } + + + /** + * Imports a feed from a file located at $filename. + * + * @param string $filename + * @throws Zend_Feed_Exception + * @return Zend_Feed_Abstract + */ + public static function importFile($filename) + { + @ini_set('track_errors', 1); + $feed = @file_get_contents($filename); + @ini_restore('track_errors'); + if ($feed === false) { + /** + * @see Zend_Feed_Exception + */ + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg"); + } + return self::importString($feed); + } + + + /** + * Attempts to find feeds at $uri referenced by tags. Returns an + * array of the feeds referenced at $uri. + * + * @todo Allow findFeeds() to follow one, but only one, code 302. + * + * @param string $uri + * @throws Zend_Feed_Exception + * @return array + */ + public static function findFeeds($uri) + { + // Get the HTTP response from $uri and save the contents + $client = self::getHttpClient(); + $client->setUri($uri); + $response = $client->request(); + if ($response->getStatus() !== 200) { + /** + * @see Zend_Feed_Exception + */ + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus()); + } + $contents = $response->getBody(); + + // Parse the contents for appropriate tags + @ini_set('track_errors', 1); + $pattern = '~(]+)/?>~i'; + $result = @preg_match_all($pattern, $contents, $matches); + @ini_restore('track_errors'); + if ($result === false) { + /** + * @see Zend_Feed_Exception + */ + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception("Internal error: $php_errormsg"); + } + + // Try to fetch a feed for each link tag that appears to refer to a feed + $feeds = array(); + if (isset($matches[1]) && count($matches[1]) > 0) { + foreach ($matches[1] as $link) { + // force string to be an utf-8 one + if (!mb_check_encoding($link, 'UTF-8')) { + $link = mb_convert_encoding($link, 'UTF-8'); + } + $xml = @simplexml_load_string(rtrim($link, ' /') . ' />'); + if ($xml === false) { + continue; + } + $attributes = $xml->attributes(); + if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) { + continue; + } + if (!isset($attributes['type']) || + !@preg_match('~^application/(?:atom|rss|rdf)\+xml~', $attributes['type'])) { + continue; + } + if (!isset($attributes['href'])) { + continue; + } + try { + // checks if we need to canonize the given uri + try { + $uri = Zend_Uri::factory((string) $attributes['href']); + } catch (Zend_Uri_Exception $e) { + // canonize the uri + $path = (string) $attributes['href']; + $query = $fragment = ''; + if (substr($path, 0, 1) != '/') { + // add the current root path to this one + $path = rtrim($client->getUri()->getPath(), '/') . '/' . $path; + } + if (strpos($path, '?') !== false) { + list($path, $query) = explode('?', $path, 2); + } + if (strpos($query, '#') !== false) { + list($query, $fragment) = explode('#', $query, 2); + } + $uri = Zend_Uri::factory($client->getUri(true)); + $uri->setPath($path); + $uri->setQuery($query); + $uri->setFragment($fragment); + } + + $feed = self::import($uri); + } catch (Exception $e) { + continue; + } + $feeds[$uri->getUri()] = $feed; + } + } + + // Return the fetched feeds + return $feeds; + } + + /** + * Construct a new Zend_Feed_Abstract object from a custom array + * + * @param array $data + * @param string $format (rss|atom) the requested output format + * @return Zend_Feed_Abstract + */ + public static function importArray(array $data, $format = 'atom') + { + $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); + // if (!class_exists($obj)) { + // require_once 'Zend/Loader.php'; + // Zend_Loader::loadClass($obj); + // } + + /** + * @see Zend_Feed_Builder + */ + // require_once 'Zend/Feed/Builder.php'; + return new $obj(null, null, new Zend_Feed_Builder($data)); + } + + /** + * Construct a new Zend_Feed_Abstract object from a Zend_Feed_Builder_Interface data source + * + * @param Zend_Feed_Builder_Interface $builder this object will be used to extract the data of the feed + * @param string $format (rss|atom) the requested output format + * @return Zend_Feed_Abstract + */ + public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom') + { + $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); + // if (!class_exists($obj)) { + // require_once 'Zend/Loader.php'; + // Zend_Loader::loadClass($obj); + // } + return new $obj(null, null, $builder); + } +} diff --git a/oss/piwik/trunk/libs/Zend/Loader.php b/oss/piwik/trunk/libs/Zend/Loader.php new file mode 100644 index 00000000..b5ae731e --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Loader.php @@ -0,0 +1,329 @@ + $dir) { + if ($dir == '.') { + $dirs[$key] = $dirPath; + } else { + $dir = rtrim($dir, '\\/'); + $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; + } + } + $file = basename($file); + self::loadFile($file, $dirs, true); + } else { + self::loadFile($file, null, true); + } + + if (!class_exists($class, false) && !interface_exists($class, false)) { + // require_once 'Zend/Exception.php'; + throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file"); + } + } + + /** + * Loads a PHP file. This is a wrapper for PHP's include() function. + * + * $filename must be the complete filename, including any + * extension such as ".php". Note that a security check is performed that + * does not permit extended characters in the filename. This method is + * intended for loading Zend Framework files. + * + * If $dirs is a string or an array, it will search the directories + * in the order supplied, and attempt to load the first matching file. + * + * If the file was not found in the $dirs, or if no $dirs were specified, + * it will attempt to load it from PHP's include_path. + * + * If $once is TRUE, it will use include_once() instead of include(). + * + * @param string $filename + * @param string|array $dirs - OPTIONAL either a path or array of paths + * to search. + * @param boolean $once + * @return boolean + * @throws Zend_Exception + */ + public static function loadFile($filename, $dirs = null, $once = false) + { + self::_securityCheck($filename); + + /** + * Search in provided directories, as well as include_path + */ + $incPath = false; + if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) { + if (is_array($dirs)) { + $dirs = implode(PATH_SEPARATOR, $dirs); + } + $incPath = get_include_path(); + set_include_path($dirs . PATH_SEPARATOR . $incPath); + } + + /** + * Try finding for the plain filename in the include_path. + */ + if ($once) { + include_once $filename; + } else { + include $filename; + } + + /** + * If searching in directories, reset include_path + */ + if ($incPath) { + set_include_path($incPath); + } + + return true; + } + + /** + * Returns TRUE if the $filename is readable, or FALSE otherwise. + * This function uses the PHP include_path, where PHP's is_readable() + * does not. + * + * Note from ZF-2900: + * If you use custom error handler, please check whether return value + * from error_reporting() is zero or not. + * At mark of fopen() can not suppress warning if the handler is used. + * + * @param string $filename + * @return boolean + */ + public static function isReadable($filename) + { + if (is_readable($filename)) { + // Return early if the filename is readable without needing the + // include_path + return true; + } + + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' + && preg_match('/^[a-z]:/i', $filename) + ) { + // If on windows, and path provided is clearly an absolute path, + // return false immediately + return false; + } + + foreach (self::explodeIncludePath() as $path) { + if ($path == '.') { + if (is_readable($filename)) { + return true; + } + continue; + } + $file = $path . '/' . $filename; + if (is_readable($file)) { + return true; + } + } + return false; + } + + /** + * Explode an include path into an array + * + * If no path provided, uses current include_path. Works around issues that + * occur when the path includes stream schemas. + * + * @param string|null $path + * @return array + */ + public static function explodeIncludePath($path = null) + { + if (null === $path) { + $path = get_include_path(); + } + + if (PATH_SEPARATOR == ':') { + // On *nix systems, include_paths which include paths with a stream + // schema cannot be safely explode'd, so we have to be a bit more + // intelligent in the approach. + $paths = preg_split('#:(?!//)#', $path); + } else { + $paths = explode(PATH_SEPARATOR, $path); + } + return $paths; + } + + /** + * spl_autoload() suitable implementation for supporting class autoloading. + * + * Attach to spl_autoload() using the following: + * + * spl_autoload_register(array('Zend_Loader', 'autoload')); + * + * + * @deprecated Since 1.8.0 + * @param string $class + * @return string|false Class name on success; false on failure + */ + public static function autoload($class) + { + trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE); + try { + @self::loadClass($class); + return $class; + } catch (Exception $e) { + return false; + } + } + + /** + * Register {@link autoload()} with spl_autoload() + * + * @deprecated Since 1.8.0 + * @param string $class (optional) + * @param boolean $enabled (optional) + * @return void + * @throws Zend_Exception if spl_autoload() is not found + * or if the specified class does not have an autoload() method. + */ + public static function registerAutoload($class = 'Zend_Loader', $enabled = true) + { + trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE); + // require_once 'Zend/Loader/Autoloader.php'; + $autoloader = Zend_Loader_Autoloader::getInstance(); + $autoloader->setFallbackAutoloader(true); + + if ('Zend_Loader' != $class) { + self::loadClass($class); + $methods = get_class_methods($class); + if (!in_array('autoload', (array) $methods)) { + // require_once 'Zend/Exception.php'; + throw new Zend_Exception("The class \"$class\" does not have an autoload() method"); + } + + $callback = array($class, 'autoload'); + + if ($enabled) { + $autoloader->pushAutoloader($callback); + } else { + $autoloader->removeAutoloader($callback); + } + } + } + + /** + * Ensure that filename does not contain exploits + * + * @param string $filename + * @return void + * @throws Zend_Exception + */ + protected static function _securityCheck($filename) + { + /** + * Security check + */ + if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) { + // require_once 'Zend/Exception.php'; + throw new Zend_Exception('Security check: Illegal character in filename'); + } + } + + /** + * Attempt to include() the file. + * + * include() is not prefixed with the @ operator because if + * the file is loaded and contains a parse error, execution + * will halt silently and this is difficult to debug. + * + * Always set display_errors = Off on production servers! + * + * @param string $filespec + * @param boolean $once + * @return boolean + * @deprecated Since 1.5.0; use loadFile() instead + */ + protected static function _includeFile($filespec, $once = false) + { + if ($once) { + return include_once $filespec; + } else { + return include $filespec ; + } + } +} diff --git a/oss/piwik/trunk/libs/Zend/Log.php b/oss/piwik/trunk/libs/Zend/Log.php new file mode 100644 index 00000000..471c0e3c --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Log.php @@ -0,0 +1,425 @@ +_priorities = array_flip($r->getConstants()); + + if ($writer !== null) { + $this->addWriter($writer); + } + } + + /** + * Factory to construct the logger and one or more writers + * based on the configuration array + * + * @param array|Zend_Config Array or instance of Zend_Config + * @return Zend_Log + */ + static public function factory($config = array()) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config) || empty($config)) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config'); + } + + $log = new Zend_Log; + + if (!is_array(current($config))) { + $log->addWriter(current($config)); + } else { + foreach($config as $writer) { + $log->addWriter($writer); + } + } + + return $log; + } + + + /** + * Construct a writer object based on a configuration array + * + * @param array $spec config array with writer spec + * @return Zend_Log_Writer_Abstract + */ + protected function _constructWriterFromConfig($config) + { + $writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace); + + if (!$writer instanceof Zend_Log_Writer_Abstract) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("{$writerName} does not extend Zend_Log_Writer_Abstract!"); + } + + if (isset($config['filterName'])) { + $filter = $this->_constructFilterFromConfig($config); + $writer->addFilter($filter); + } + + return $writer; + } + + /** + * Construct filter object from configuration array or Zend_Config object + * + * @param array|Zend_Config $config Zend_Config or Array + * @return Zend_Log_Filter_Interface + */ + protected function _constructFilterFromConfig($config) + { + $filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace); + + if (!$filter instanceof Zend_Log_Filter_Interface) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("{$filterName} does not implement Zend_Log_Filter_Interface"); + } + + return $filter; + } + + /** + * Construct a filter or writer from config + * + * @param string $type 'writer' of 'filter' + * @param mixed $config Zend_Config or Array + * @param string $namespace + * @return object + */ + protected function _constructFromConfig($type, $config, $namespace) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config) || empty($config)) { + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Configuration must be an array or instance of Zend_Config' + ); + } + + $params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array(); + $className = $this->getClassName($config, $type, $namespace); + // if (!class_exists($className)) { + // require_once 'Zend/Loader.php'; + // Zend_Loader::loadClass($className); + // } + + $reflection = new ReflectionClass($className); + if (!$reflection->implementsInterface('Zend_Log_FactoryInterface')) { + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Driver does not implement Zend_Log_FactoryInterface and can not be constructed from config.' + ); + } + + return call_user_func(array($className, 'factory'), $params); + } + + /** + * Get the writer or filter full classname + * + * @param array $config + * @param string $type filter|writer + * @param string $defaultNamespace + * @return string full classname + */ + protected function getClassName($config, $type, $defaultNamespace) + { + if (!isset($config[ $type . 'Name' ])) { + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("Specify {$type}Name in the configuration array"); + } + $className = $config[ $type . 'Name' ]; + + $namespace = $defaultNamespace; + if (isset($config[ $type . 'Namespace' ])) { + $namespace = $config[ $type . 'Namespace' ]; + } + + $fullClassName = $namespace . '_' . $className; + return $fullClassName; + } + + /** + * Class destructor. Shutdown log writers + * + * @return void + */ + public function __destruct() + { + foreach($this->_writers as $writer) { + $writer->shutdown(); + } + } + + /** + * Undefined method handler allows a shortcut: + * $log->priorityName('message') + * instead of + * $log->log('message', Zend_Log::PRIORITY_NAME) + * + * @param string $method priority name + * @param string $params message to log + * @return void + * @throws Zend_Log_Exception + */ + public function __call($method, $params) + { + $priority = strtoupper($method); + if (($priority = array_search($priority, $this->_priorities)) !== false) { + switch (count($params)) { + case 0: + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Missing log message'); + case 1: + $message = array_shift($params); + $extras = null; + break; + default: + $message = array_shift($params); + $extras = array_shift($params); + break; + } + $this->log($message, $priority, $extras); + } else { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Bad log priority'); + } + } + + /** + * Log a message at a priority + * + * @param string $message Message to log + * @param integer $priority Priority of message + * @param mixed $extras Extra information to log in event + * @return void + * @throws Zend_Log_Exception + */ + public function log($message, $priority, $extras = null) + { + // sanity checks + if (empty($this->_writers)) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('No writers were added'); + } + + if (! isset($this->_priorities[$priority])) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Bad log priority'); + } + + // pack into event required by filters and writers + $event = array_merge(array('timestamp' => date('c'), + 'message' => $message, + 'priority' => $priority, + 'priorityName' => $this->_priorities[$priority]), + $this->_extras); + + // Check to see if any extra information was passed + if (!empty($extras)) { + $info = array(); + if (is_array($extras)) { + foreach ($extras as $key => $value) { + if (is_string($key)) { + $event[$key] = $value; + } else { + $info[] = $value; + } + } + } else { + $info = $extras; + } + if (!empty($info)) { + $event['info'] = $info; + } + } + + // abort if rejected by the global filters + foreach ($this->_filters as $filter) { + if (! $filter->accept($event)) { + return; + } + } + + // send to each writer + foreach ($this->_writers as $writer) { + $writer->write($event); + } + } + + /** + * Add a custom priority + * + * @param string $name Name of priority + * @param integer $priority Numeric priority + * @throws Zend_Log_InvalidArgumentException + */ + public function addPriority($name, $priority) + { + // Priority names must be uppercase for predictability. + $name = strtoupper($name); + + if (isset($this->_priorities[$priority]) + || array_search($name, $this->_priorities)) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Existing priorities cannot be overwritten'); + } + + $this->_priorities[$priority] = $name; + } + + /** + * Add a filter that will be applied before all log writers. + * Before a message will be received by any of the writers, it + * must be accepted by all filters added with this method. + * + * @param int|Zend_Log_Filter_Interface $filter + * @return void + */ + public function addFilter($filter) + { + if (is_integer($filter)) { + /** @see Zend_Log_Filter_Priority */ + // require_once 'Zend/Log/Filter/Priority.php'; + $filter = new Zend_Log_Filter_Priority($filter); + + } elseif ($filter instanceof Zend_Config || is_array($filter)) { + $filter = $this->_constructFilterFromConfig($filter); + + } elseif(! $filter instanceof Zend_Log_Filter_Interface) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Invalid filter provided'); + } + + $this->_filters[] = $filter; + } + + /** + * Add a writer. A writer is responsible for taking a log + * message and writing it out to storage. + * + * @param mixed $writer Zend_Log_Writer_Abstract or Config array + * @return void + */ + public function addWriter($writer) + { + if (is_array($writer) || $writer instanceof Zend_Config) { + $writer = $this->_constructWriterFromConfig($writer); + } + + if (!$writer instanceof Zend_Log_Writer_Abstract) { + /** @see Zend_Log_Exception */ + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Writer must be an instance of Zend_Log_Writer_Abstract' + . ' or you should pass a configuration array' + ); + } + + $this->_writers[] = $writer; + } + + /** + * Set an extra item to pass to the log writers. + * + * @param $name Name of the field + * @param $value Value of the field + * @return void + */ + public function setEventItem($name, $value) { + $this->_extras = array_merge($this->_extras, array($name => $value)); + } +} diff --git a/oss/piwik/trunk/libs/Zend/Mail.php b/oss/piwik/trunk/libs/Zend/Mail.php new file mode 100644 index 00000000..81d1b505 --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Mail.php @@ -0,0 +1,1261 @@ +_charset = $charset; + } + + /** + * Return charset string + * + * @return string + */ + public function getCharset() + { + return $this->_charset; + } + + /** + * Set content type + * + * Should only be used for manually setting multipart content types. + * + * @param string $type Content type + * @return Zend_Mail Implements fluent interface + * @throws Zend_Mail_Exception for types not supported by Zend_Mime + */ + public function setType($type) + { + $allowed = array( + Zend_Mime::MULTIPART_ALTERNATIVE, + Zend_Mime::MULTIPART_MIXED, + Zend_Mime::MULTIPART_RELATED, + ); + if (!in_array($type, $allowed)) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Invalid content type "' . $type . '"'); + } + + $this->_type = $type; + return $this; + } + + /** + * Get content type of the message + * + * @return string + */ + public function getType() + { + return $this->_type; + } + + /** + * Set an arbitrary mime boundary for the message + * + * If not set, Zend_Mime will generate one. + * + * @param string $boundary + * @return Zend_Mail Provides fluent interface + */ + public function setMimeBoundary($boundary) + { + $this->_mimeBoundary = $boundary; + + return $this; + } + + /** + * Return the boundary string used for the message + * + * @return string + */ + public function getMimeBoundary() + { + return $this->_mimeBoundary; + } + + /** + * Return encoding of mail headers + * + * @deprecated use {@link getHeaderEncoding()} instead + * @return string + */ + public function getEncodingOfHeaders() + { + return $this->getHeaderEncoding(); + } + + /** + * Return the encoding of mail headers + * + * Either Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64 + * + * @return string + */ + public function getHeaderEncoding() + { + return $this->_headerEncoding; + } + + /** + * Set the encoding of mail headers + * + * @deprecated Use {@link setHeaderEncoding()} instead. + * @param string $encoding + * @return Zend_Mail + */ + public function setEncodingOfHeaders($encoding) + { + return $this->setHeaderEncoding($encoding); + } + + /** + * Set the encoding of mail headers + * + * @param string $encoding Zend_Mime::ENCODING_QUOTEDPRINTABLE or Zend_Mime::ENCODING_BASE64 + * @return Zend_Mail Provides fluent interface + */ + public function setHeaderEncoding($encoding) + { + $allowed = array( + Zend_Mime::ENCODING_BASE64, + Zend_Mime::ENCODING_QUOTEDPRINTABLE + ); + if (!in_array($encoding, $allowed)) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Invalid encoding "' . $encoding . '"'); + } + $this->_headerEncoding = $encoding; + + return $this; + } + + /** + * Sets the text body for the message. + * + * @param string $txt + * @param string $charset + * @param string $encoding + * @return Zend_Mail Provides fluent interface + */ + public function setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE) + { + if ($charset === null) { + $charset = $this->_charset; + } + + $mp = new Zend_Mime_Part($txt); + $mp->encoding = $encoding; + $mp->type = Zend_Mime::TYPE_TEXT; + $mp->disposition = Zend_Mime::DISPOSITION_INLINE; + $mp->charset = $charset; + + $this->_bodyText = $mp; + + return $this; + } + + /** + * Return text body Zend_Mime_Part or string + * + * @param bool textOnly Whether to return just the body text content or the MIME part; defaults to false, the MIME part + * @return false|Zend_Mime_Part|string + */ + public function getBodyText($textOnly = false) + { + if ($textOnly && $this->_bodyText) { + $body = $this->_bodyText; + return $body->getContent(); + } + + return $this->_bodyText; + } + + /** + * Sets the HTML body for the message + * + * @param string $html + * @param string $charset + * @param string $encoding + * @return Zend_Mail Provides fluent interface + */ + public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE) + { + if ($charset === null) { + $charset = $this->_charset; + } + + $mp = new Zend_Mime_Part($html); + $mp->encoding = $encoding; + $mp->type = Zend_Mime::TYPE_HTML; + $mp->disposition = Zend_Mime::DISPOSITION_INLINE; + $mp->charset = $charset; + + $this->_bodyHtml = $mp; + + return $this; + } + + /** + * Return Zend_Mime_Part representing body HTML + * + * @param bool $htmlOnly Whether to return the body HTML only, or the MIME part; defaults to false, the MIME part + * @return false|Zend_Mime_Part|string + */ + public function getBodyHtml($htmlOnly = false) + { + if ($htmlOnly && $this->_bodyHtml) { + $body = $this->_bodyHtml; + return $body->getContent(); + } + + return $this->_bodyHtml; + } + + /** + * Adds an existing attachment to the mail message + * + * @param Zend_Mime_Part $attachment + * @return Zend_Mail Provides fluent interface + */ + public function addAttachment(Zend_Mime_Part $attachment) + { + $this->addPart($attachment); + $this->hasAttachments = true; + + return $this; + } + + /** + * Creates a Zend_Mime_Part attachment + * + * Attachment is automatically added to the mail object after creation. The + * attachment object is returned to allow for further manipulation. + * + * @param string $body + * @param string $mimeType + * @param string $disposition + * @param string $encoding + * @param string $filename OPTIONAL A filename for the attachment + * @return Zend_Mime_Part Newly created Zend_Mime_Part object (to allow + * advanced settings) + */ + public function createAttachment($body, + $mimeType = Zend_Mime::TYPE_OCTETSTREAM, + $disposition = Zend_Mime::DISPOSITION_ATTACHMENT, + $encoding = Zend_Mime::ENCODING_BASE64, + $filename = null) + { + + $mp = new Zend_Mime_Part($body); + $mp->encoding = $encoding; + $mp->type = $mimeType; + $mp->disposition = $disposition; + $mp->filename = $filename; + + $this->addAttachment($mp); + + return $mp; + } + + /** + * Return a count of message parts + * + * @return integer + */ + public function getPartCount() + { + return count($this->_parts); + } + + /** + * Encode header fields + * + * Encodes header content according to RFC1522 if it contains non-printable + * characters. + * + * @param string $value + * @return string + */ + protected function _encodeHeader($value) + { + if (Zend_Mime::isPrintable($value) === false) { + if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) { + $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); + } else { + $value = Zend_Mime::encodeBase64Header($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); + } + } + + return $value; + } + + /** + * Add a header to the message + * + * Adds a header to this message. If append is true and the header already + * exists, raises a flag indicating that the header should be appended. + * + * @param string $headerName + * @param string $value + * @param bool $append + */ + protected function _storeHeader($headerName, $value, $append = false) + { + if (isset($this->_headers[$headerName])) { + $this->_headers[$headerName][] = $value; + } else { + $this->_headers[$headerName] = array($value); + } + + if ($append) { + $this->_headers[$headerName]['append'] = true; + } + + } + + /** + * Clear header from the message + * + * @param string $headerName + */ + protected function _clearHeader($headerName) + { + if (isset($this->_headers[$headerName])){ + unset($this->_headers[$headerName]); + } + } + + /** + * Helper function for adding a recipient and the corresponding header + * + * @param string $headerName + * @param string $email + * @param string $name + */ + protected function _addRecipientAndHeader($headerName, $email, $name) + { + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + // prevent duplicates + $this->_recipients[$email] = 1; + $this->_storeHeader($headerName, $this->_formatAddress($email, $name), true); + } + + /** + * Adds To-header and recipient, $email can be an array, or a single string address + * + * @param string|array $email + * @param string $name + * @return Zend_Mail Provides fluent interface + */ + public function addTo($email, $name='') + { + if (!is_array($email)) { + $email = array($name => $email); + } + + foreach ($email as $n => $recipient) { + $this->_addRecipientAndHeader('To', $recipient, is_int($n) ? '' : $n); + $this->_to[] = $recipient; + } + + return $this; + } + + /** + * Adds Cc-header and recipient, $email can be an array, or a single string address + * + * @param string|array $email + * @param string $name + * @return Zend_Mail Provides fluent interface + */ + public function addCc($email, $name='') + { + if (!is_array($email)) { + $email = array($name => $email); + } + + foreach ($email as $n => $recipient) { + $this->_addRecipientAndHeader('Cc', $recipient, is_int($n) ? '' : $n); + } + + return $this; + } + + /** + * Adds Bcc recipient, $email can be an array, or a single string address + * + * @param string|array $email + * @return Zend_Mail Provides fluent interface + */ + public function addBcc($email) + { + if (!is_array($email)) { + $email = array($email); + } + + foreach ($email as $recipient) { + $this->_addRecipientAndHeader('Bcc', $recipient, ''); + } + + return $this; + } + + /** + * Return list of recipient email addresses + * + * @return array (of strings) + */ + public function getRecipients() + { + return array_keys($this->_recipients); + } + + /** + * Clears list of recipient email addresses + * + * @return Zend_Mail Provides fluent interface + */ + public function clearRecipients() + { + $this->_recipients = array(); + $this->_to = array(); + + $this->_clearHeader('To'); + $this->_clearHeader('Cc'); + $this->_clearHeader('Bcc'); + + return $this; + } + + /** + * Sets From-header and sender of the message + * + * @param string $email + * @param string $name + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception if called subsequent times + */ + public function setFrom($email, $name = null) + { + if (null !== $this->_from) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('From Header set twice'); + } + + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + $this->_from = $email; + $this->_storeHeader('From', $this->_formatAddress($email, $name), true); + + return $this; + } + + /** + * Set Reply-To Header + * + * @param string $email + * @param string $name + * @return Zend_Mail + * @throws Zend_Mail_Exception if called more than one time + */ + public function setReplyTo($email, $name = null) + { + if (null !== $this->_replyTo) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Reply-To Header set twice'); + } + + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + $this->_replyTo = $email; + $this->_storeHeader('Reply-To', $this->_formatAddress($email, $name), true); + + return $this; + } + + /** + * Returns the sender of the mail + * + * @return string + */ + public function getFrom() + { + return $this->_from; + } + + /** + * Returns the current Reply-To address of the message + * + * @return string|null Reply-To address, null when not set + */ + public function getReplyTo() + { + return $this->_replyTo; + } + + /** + * Clears the sender from the mail + * + * @return Zend_Mail Provides fluent interface + */ + public function clearFrom() + { + $this->_from = null; + $this->_clearHeader('From'); + + return $this; + } + + /** + * Clears the current Reply-To address from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearReplyTo() + { + $this->_replyTo = null; + $this->_clearHeader('Reply-To'); + + return $this; + } + + /** + * Sets Default From-email and name of the message + * + * @param string $email + * @param string Optional $name + * @return void + */ + public static function setDefaultFrom($email, $name = null) + { + self::$_defaultFrom = array('email' => $email, 'name' => $name); + } + + /** + * Returns the default sender of the mail + * + * @return null|array Null if none was set. + */ + public static function getDefaultFrom() + { + return self::$_defaultFrom; + } + + /** + * Clears the default sender from the mail + * + * @return void + */ + public static function clearDefaultFrom() + { + self::$_defaultFrom = null; + } + + /** + * Sets From-name and -email based on the defaults + * + * @return Zend_Mail Provides fluent interface + */ + public function setFromToDefaultFrom() { + $from = self::getDefaultFrom(); + if($from === null) { + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception( + 'No default From Address set to use'); + } + + $this->setFrom($from['email'], $from['name']); + + return $this; + } + + /** + * Sets Default ReplyTo-address and -name of the message + * + * @param string $email + * @param string Optional $name + * @return void + */ + public static function setDefaultReplyTo($email, $name = null) + { + self::$_defaultReplyTo = array('email' => $email, 'name' => $name); + } + + /** + * Returns the default Reply-To Address and Name of the mail + * + * @return null|array Null if none was set. + */ + public static function getDefaultReplyTo() + { + return self::$_defaultReplyTo; + } + + /** + * Clears the default ReplyTo-address and -name from the mail + * + * @return void + */ + public static function clearDefaultReplyTo() + { + self::$_defaultReplyTo = null; + } + + /** + * Sets ReplyTo-name and -email based on the defaults + * + * @return Zend_Mail Provides fluent interface + */ + public function setReplyToFromDefault() { + $replyTo = self::getDefaultReplyTo(); + if($replyTo === null) { + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception( + 'No default Reply-To Address set to use'); + } + + $this->setReplyTo($replyTo['email'], $replyTo['name']); + + return $this; + } + + /** + * Sets the Return-Path header of the message + * + * @param string $email + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception if set multiple times + */ + public function setReturnPath($email) + { + if ($this->_returnPath === null) { + $email = $this->_filterEmail($email); + $this->_returnPath = $email; + $this->_storeHeader('Return-Path', $email, false); + } else { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Return-Path Header set twice'); + } + return $this; + } + + /** + * Returns the current Return-Path address of the message + * + * If no Return-Path header is set, returns the value of {@link $_from}. + * + * @return string + */ + public function getReturnPath() + { + if (null !== $this->_returnPath) { + return $this->_returnPath; + } + + return $this->_from; + } + + /** + * Clears the current Return-Path address from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearReturnPath() + { + $this->_returnPath = null; + $this->_clearHeader('Return-Path'); + + return $this; + } + + /** + * Sets the subject of the message + * + * @param string $subject + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception + */ + public function setSubject($subject) + { + if ($this->_subject === null) { + $subject = $this->_filterOther($subject); + $this->_subject = $this->_encodeHeader($subject); + $this->_storeHeader('Subject', $this->_subject); + } else { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Subject set twice'); + } + return $this; + } + + /** + * Returns the encoded subject of the message + * + * @return string + */ + public function getSubject() + { + return $this->_subject; + } + + /** + * Clears the encoded subject from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearSubject() + { + $this->_subject = null; + $this->_clearHeader('Subject'); + + return $this; + } + + /** + * Sets Date-header + * + * @param timestamp|string|Zend_Date $date + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception if called subsequent times or wrong date format. + */ + public function setDate($date = null) + { + if ($this->_date === null) { + if ($date === null) { + $date = date('r'); + } else if (is_int($date)) { + $date = date('r', $date); + } else if (is_string($date)) { + $date = strtotime($date); + if ($date === false || $date < 0) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('String representations of Date Header must be ' . + 'strtotime()-compatible'); + } + $date = date('r', $date); + } else if ($date instanceof Zend_Date) { + $date = $date->get(Zend_Date::RFC_2822); + } else { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception(__METHOD__ . ' only accepts UNIX timestamps, Zend_Date objects, ' . + ' and strtotime()-compatible strings'); + } + $this->_date = $date; + $this->_storeHeader('Date', $date); + } else { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Date Header set twice'); + } + return $this; + } + + /** + * Returns the formatted date of the message + * + * @return string + */ + public function getDate() + { + return $this->_date; + } + + /** + * Clears the formatted date from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearDate() + { + $this->_date = null; + $this->_clearHeader('Date'); + + return $this; + } + + /** + * Sets the Message-ID of the message + * + * @param boolean|string $id + * true :Auto + * false :No set + * null :No set + * string:Sets given string (Angle brackets is not necessary) + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception + */ + public function setMessageId($id = true) + { + if ($id === null || $id === false) { + return $this; + } elseif ($id === true) { + $id = $this->createMessageId(); + } + + if ($this->_messageId === null) { + $id = $this->_filterOther($id); + $this->_messageId = $id; + $this->_storeHeader('Message-Id', '<' . $this->_messageId . '>'); + } else { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Message-ID set twice'); + } + + return $this; + } + + /** + * Returns the Message-ID of the message + * + * @return string + */ + public function getMessageId() + { + return $this->_messageId; + } + + + /** + * Clears the Message-ID from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearMessageId() + { + $this->_messageId = null; + $this->_clearHeader('Message-Id'); + + return $this; + } + + /** + * Creates the Message-ID + * + * @return string + */ + public function createMessageId() { + + $time = time(); + + if ($this->_from !== null) { + $user = $this->_from; + } elseif (isset($_SERVER['REMOTE_ADDR'])) { + $user = $_SERVER['REMOTE_ADDR']; + } else { + $user = getmypid(); + } + + $rand = mt_rand(); + + if ($this->_recipients !== array()) { + $recipient = array_rand($this->_recipients); + } else { + $recipient = 'unknown'; + } + + if (isset($_SERVER["SERVER_NAME"])) { + $hostName = $_SERVER["SERVER_NAME"]; + } else { + $hostName = php_uname('n'); + } + + return sha1($time . $user . $rand . $recipient) . '@' . $hostName; + } + + /** + * Add a custom header to the message + * + * @param string $name + * @param string $value + * @param boolean $append + * @return Zend_Mail Provides fluent interface + * @throws Zend_Mail_Exception on attempts to create standard headers + */ + public function addHeader($name, $value, $append = false) + { + $prohibit = array('to', 'cc', 'bcc', 'from', 'subject', + 'reply-to', 'return-path', + 'date', 'message-id', + ); + if (in_array(strtolower($name), $prohibit)) { + /** + * @see Zend_Mail_Exception + */ + // require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Cannot set standard header from addHeader()'); + } + + $value = $this->_filterOther($value); + $value = $this->_encodeHeader($value); + $this->_storeHeader($name, $value, $append); + + return $this; + } + + /** + * Return mail headers + * + * @return void + */ + public function getHeaders() + { + return $this->_headers; + } + + /** + * Sends this email using the given transport or a previously + * set DefaultTransport or the internal mail function if no + * default transport had been set. + * + * @param Zend_Mail_Transport_Abstract $transport + * @return Zend_Mail Provides fluent interface + */ + public function send($transport = null) + { + if ($transport === null) { + if (! self::$_defaultTransport instanceof Zend_Mail_Transport_Abstract) { + // require_once 'Zend/Mail/Transport/Sendmail.php'; + $transport = new Zend_Mail_Transport_Sendmail(); + } else { + $transport = self::$_defaultTransport; + } + } + + if ($this->_date === null) { + $this->setDate(); + } + + if(null === $this->_from && null !== self::getDefaultFrom()) { + $this->setFromToDefaultFrom(); + } + + if(null === $this->_replyTo && null !== self::getDefaultReplyTo()) { + $this->setReplyToFromDefault(); + } + + $transport->send($this); + + return $this; + } + + /** + * Filter of email data + * + * @param string $email + * @return string + */ + protected function _filterEmail($email) + { + $rule = array("\r" => '', + "\n" => '', + "\t" => '', + '"' => '', + ',' => '', + '<' => '', + '>' => '', + ); + + return strtr($email, $rule); + } + + /** + * Filter of name data + * + * @param string $name + * @return string + */ + protected function _filterName($name) + { + $rule = array("\r" => '', + "\n" => '', + "\t" => '', + '"' => "'", + '<' => '[', + '>' => ']', + ); + + return trim(strtr($name, $rule)); + } + + /** + * Filter of other data + * + * @param string $data + * @return string + */ + protected function _filterOther($data) + { + $rule = array("\r" => '', + "\n" => '', + "\t" => '', + ); + + return strtr($data, $rule); + } + + /** + * Formats e-mail address + * + * @param string $email + * @param string $name + * @return string + */ + protected function _formatAddress($email, $name) + { + if ($name === '' || $name === null || $name === $email) { + return $email; + } else { + $encodedName = $this->_encodeHeader($name); + if ($encodedName === $name && + ((strpos($name, '@') !== false) || (strpos($name, ',') !== false))) { + $format = '"%s" <%s>'; + } else { + $format = '%s <%s>'; + } + return sprintf($format, $encodedName, $email); + } + } + +} diff --git a/oss/piwik/trunk/libs/Zend/Mime.php b/oss/piwik/trunk/libs/Zend/Mime.php new file mode 100644 index 00000000..aa3582ef --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Mime.php @@ -0,0 +1,365 @@ + $lineLength) { + $ptr = $lineLength; + } + + // Ensure we are not splitting across an encoded character + $pos = strrpos(substr($str, 0, $ptr), '='); + if ($pos !== false && $pos >= $ptr - 2) { + $ptr = $pos; + } + + // Check if there is a space at the end of the line and rewind + if ($ptr > 0 && $str[$ptr - 1] == ' ') { + --$ptr; + } + + // Add string and continue + $out .= substr($str, 0, $ptr) . '=' . $lineEnd; + $str = substr($str, $ptr); + } + + $out = rtrim($out, $lineEnd); + $out = rtrim($out, '='); + return $out; + } + + /** + * Converts a string into quoted printable format. + * + * @param string $str + * @return string + */ + private static function _encodeQuotedPrintable($str) + { + $str = str_replace('=', '=3D', $str); + $str = str_replace(self::$qpKeys, self::$qpReplaceValues, $str); + $str = rtrim($str); + return $str; + } + + /** + * Encode a given string with the QUOTED_PRINTABLE mechanism for Mail Headers. + * + * Mail headers depend on an extended quoted printable algorithm otherwise + * a range of bugs can occur. + * + * @param string $str + * @param string $charset + * @param int $lineLength Defaults to {@link LINELENGTH} + * @param int $lineEnd Defaults to {@link LINEEND} + * @return string + */ + public static function encodeQuotedPrintableHeader($str, $charset, + $lineLength = self::LINELENGTH, + $lineEnd = self::LINEEND) + { + // Reduce line-length by the length of the required delimiter, charsets and encoding + $prefix = sprintf('=?%s?Q?', $charset); + $lineLength = $lineLength-strlen($prefix)-3; + + $str = self::_encodeQuotedPrintable($str); + + // Mail-Header required chars have to be encoded also: + $str = str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $str); + + // initialize first line, we need it anyways + $lines = array(0 => ""); + + // Split encoded text into separate lines + $tmp = ""; + while(strlen($str) > 0) { + $currentLine = max(count($lines)-1, 0); + $token = self::getNextQuotedPrintableToken($str); + $str = substr($str, strlen($token)); + + $tmp .= $token; + if($token == '=20') { + // only if we have a single char token or space, we can append the + // tempstring it to the current line or start a new line if necessary. + if(strlen($lines[$currentLine].$tmp) > $lineLength) { + $lines[$currentLine+1] = $tmp; + } else { + $lines[$currentLine] .= $tmp; + } + $tmp = ""; + } + // don't forget to append the rest to the last line + if(strlen($str) == 0) { + $lines[$currentLine] .= $tmp; + } + } + + // assemble the lines together by pre- and appending delimiters, charset, encoding. + for($i = 0; $i < count($lines); $i++) { + $lines[$i] = " ".$prefix.$lines[$i]."?="; + } + $str = trim(implode($lineEnd, $lines)); + return $str; + } + + /** + * Retrieves the first token from a quoted printable string. + * + * @param string $str + * @return string + */ + private static function getNextQuotedPrintableToken($str) + { + if(substr($str, 0, 1) == "=") { + $token = substr($str, 0, 3); + } else { + $token = substr($str, 0, 1); + } + return $token; + } + + /** + * Encode a given string in mail header compatible base64 encoding. + * + * @param string $str + * @param string $charset + * @param int $lineLength Defaults to {@link LINELENGTH} + * @param int $lineEnd Defaults to {@link LINEEND} + * @return string + */ + public static function encodeBase64Header($str, + $charset, + $lineLength = self::LINELENGTH, + $lineEnd = self::LINEEND) + { + $prefix = '=?' . $charset . '?B?'; + $suffix = '?='; + $remainingLength = $lineLength - strlen($prefix) - strlen($suffix); + + $encodedValue = self::encodeBase64($str, $remainingLength, $lineEnd); + $encodedValue = str_replace($lineEnd, $suffix . $lineEnd . ' ' . $prefix, $encodedValue); + $encodedValue = $prefix . $encodedValue . $suffix; + return $encodedValue; + } + + /** + * Encode a given string in base64 encoding and break lines + * according to the maximum linelength. + * + * @param string $str + * @param int $lineLength Defaults to {@link LINELENGTH} + * @param int $lineEnd Defaults to {@link LINEEND} + * @return string + */ + public static function encodeBase64($str, + $lineLength = self::LINELENGTH, + $lineEnd = self::LINEEND) + { + return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd)); + } + + /** + * Constructor + * + * @param null|string $boundary + * @access public + * @return void + */ + public function __construct($boundary = null) + { + // This string needs to be somewhat unique + if ($boundary === null) { + $this->_boundary = '=_' . md5(microtime(1) . self::$makeUnique++); + } else { + $this->_boundary = $boundary; + } + } + + /** + * Encode the given string with the given encoding. + * + * @param string $str + * @param string $encoding + * @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND} + * @return string + */ + public static function encode($str, $encoding, $EOL = self::LINEEND) + { + switch ($encoding) { + case self::ENCODING_BASE64: + return self::encodeBase64($str, self::LINELENGTH, $EOL); + + case self::ENCODING_QUOTEDPRINTABLE: + return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL); + + default: + /** + * @todo 7Bit and 8Bit is currently handled the same way. + */ + return $str; + } + } + + /** + * Return a MIME boundary + * + * @access public + * @return string + */ + public function boundary() + { + return $this->_boundary; + } + + /** + * Return a MIME boundary line + * + * @param mixed $EOL Defaults to {@link LINEEND} + * @access public + * @return string + */ + public function boundaryLine($EOL = self::LINEEND) + { + return $EOL . '--' . $this->_boundary . $EOL; + } + + /** + * Return MIME ending + * + * @access public + * @return string + */ + public function mimeEnd($EOL = self::LINEEND) + { + return $EOL . '--' . $this->_boundary . '--' . $EOL; + } +} diff --git a/oss/piwik/trunk/libs/Zend/Registry.php b/oss/piwik/trunk/libs/Zend/Registry.php new file mode 100644 index 00000000..845ef66b --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Registry.php @@ -0,0 +1,209 @@ +offsetExists($index)) { + // require_once 'Zend/Exception.php'; + throw new Zend_Exception("No entry is registered for key '$index'"); + } + + return $instance->offsetGet($index); + } + + /** + * setter method, basically same as offsetSet(). + * + * This method can be called from an object of type Zend_Registry, or it + * can be called statically. In the latter case, it uses the default + * static instance stored in the class. + * + * @param string $index The location in the ArrayObject in which to store + * the value. + * @param mixed $value The object to store in the ArrayObject. + * @return void + */ + public static function set($index, $value) + { + $instance = self::getInstance(); + $instance->offsetSet($index, $value); + } + + /** + * Returns TRUE if the $index is a named value in the registry, + * or FALSE if $index was not found in the registry. + * + * @param string $index + * @return boolean + */ + public static function isRegistered($index) + { + if (self::$_registry === null) { + return false; + } + return self::$_registry->offsetExists($index); + } + + /** + * Constructs a parent ArrayObject with default + * ARRAY_AS_PROPS to allow acces as an object + * + * @param array $array data array + * @param integer $flags ArrayObject flags + */ + 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/oss/piwik/trunk/libs/Zend/Session.php b/oss/piwik/trunk/libs/Zend/Session.php new file mode 100644 index 00000000..e361d15d --- /dev/null +++ b/oss/piwik/trunk/libs/Zend/Session.php @@ -0,0 +1,880 @@ +0 - already called session_regenerate_id() + * + * @var int + */ + private static $_regenerateIdState = 0; + + /** + * Private list of php's ini values for ext/session + * null values will default to the php.ini value, otherwise + * the value below will overwrite the default ini value, unless + * the user has set an option explicity with setOptions() + * + * @var array + */ + private static $_defaultOptions = array( + 'save_path' => null, + 'name' => null, /* this should be set to a unique value for each application */ + 'save_handler' => null, + //'auto_start' => null, /* intentionally excluded (see manual) */ + 'gc_probability' => null, + 'gc_divisor' => null, + 'gc_maxlifetime' => null, + 'serialize_handler' => null, + 'cookie_lifetime' => null, + 'cookie_path' => null, + 'cookie_domain' => null, + 'cookie_secure' => null, + 'cookie_httponly' => null, + 'use_cookies' => null, + 'use_only_cookies' => 'on', + 'referer_check' => null, + 'entropy_file' => null, + 'entropy_length' => null, + 'cache_limiter' => null, + 'cache_expire' => null, + 'use_trans_sid' => null, + 'bug_compat_42' => null, + 'bug_compat_warn' => null, + 'hash_function' => null, + 'hash_bits_per_character' => null + ); + + /** + * List of options pertaining to Zend_Session that can be set by developers + * using Zend_Session::setOptions(). This list intentionally duplicates + * the individual declaration of static "class" variables by the same names. + * + * @var array + */ + private static $_localOptions = array( + 'strict' => '_strict', + 'remember_me_seconds' => '_rememberMeSeconds', + 'throw_startup_exceptions' => '_throwStartupExceptions' + ); + + /** + * Whether or not write close has been performed. + * + * @var bool + */ + private static $_writeClosed = false; + + /** + * Whether or not session id cookie has been deleted + * + * @var bool + */ + private static $_sessionCookieDeleted = false; + + /** + * Whether or not session has been destroyed via session_destroy() + * + * @var bool + */ + private static $_destroyed = false; + + /** + * Whether or not session must be initiated before usage + * + * @var bool + */ + private static $_strict = false; + + /** + * Default number of seconds the session will be remembered for when asked to be remembered + * + * @var int + */ + private static $_rememberMeSeconds = 1209600; // 2 weeks + + /** + * Whether the default options listed in Zend_Session::$_localOptions have been set + * + * @var bool + */ + private static $_defaultOptionsSet = false; + + /** + * A reference to the set session save handler + * + * @var Zend_Session_SaveHandler_Interface + */ + private static $_saveHandler = null; + + + /** + * Constructor overriding - make sure that a developer cannot instantiate + */ + protected function __construct() + { + } + + + /** + * setOptions - set both the class specified + * + * @param array $userOptions - pass-by-keyword style array of