Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vtiger/vtigercrm
  • varma/vtigercrm
  • alanbell/vtigercrm
  • mariusz.krzaczkowski/vtigercrm
  • manu.k/vtigercrm
  • adrgranado/vtigercrm
  • uma.s/vtigercrm
  • sardoj/vtigercrm
  • preexo/vtigercrm
  • david.valminos/vtigercrm
  • luca.saba/vtigercrm
  • dubwise/vtigercrm
  • valmir.ttcasolucoes/vtigercrm
  • lord_alan/vtigercrm
  • adrien.futschik/vtigercrm
  • edonit.rexhepi/vtigercrm
  • robert.heinze/vtigercrm
  • nrdimatteo/vtigercrm
  • sebastianzahan/vtigercrm
  • Miky/vtigercrm
  • germanf/vtigercrm
  • bernhardkau1/vtigercrm
  • olegtsoy/vtigercrm
  • grandel/vtigercrm
  • mario.thummler/vtigercrm
  • sutharsan/vtigercrm
  • james.douglas/vtigercrm
  • vikas/vtigercrm
  • jeffmchristensen/vtigercrm
  • lukasz.g/vtigercrm
  • nicolas.gasnier/vtigercrm
  • hamish.theitcompany/vtigercrm
  • engrbm87/vtigercrm
  • Quoc/vtigercrm
  • peter.maria.engeli/vtigercrm
  • kiranraju.j/vtigercrm
  • manuel.lozano/vtigercrm
  • dhaupin/vtigercrm
  • Ragupathyranesh/vtigercrm
  • Stefanbauer/vtigercrm
  • ruben.estrada/vtigercrm
  • sg_mwi1/vtigercrm
  • khaluk/vtigercrm
  • franzfroemel/vtigercrm
  • milan9615/vtigercrm
  • carlos.martin/vtigercrm
  • cmaggi/vtigercrm
  • Soltoon.theLeader/vtigercrm
  • alex.kaplun/vtigercrm
  • navid.hosseini/vtigercrm
  • maie/vtigercrm
  • simonetravaglini/vtigercrm
  • bertrand.wattel/vtigercrm
  • balaji.m/vtigercrm
  • mclarke4/vtigercrm
  • lajeeshk/vtigercrm
  • liam/vtigercrm
  • novikov.sergey/vtigercrm
  • johnwayne.williamson/vtigercrm
  • florian.strahberger-schramm/vtigercrm
  • daniel.schaefer/vtigercrm
  • christopher.gunther/vtigercrm
  • adrien.faveraux/vtigercrm
  • carsten.brandt/vtigercrm
  • stephane.molano/vtigercrm
  • krastan.petrov/vtigercrm
  • alfredo.bravo/vtigercrm
  • flipflop.Joe/vtigercrm
  • mirko.stagni/vtigercrm
  • remigio.ruberto/vtigercrm
  • gautam.dhudashiya/vtigercrm
  • manish.devitechnosolutions1/vtigercrm
  • matinbeigi/vtigercrm
  • devs/vtigercrm
  • happy.dev/vtigercrm
  • m.gigon/vtigercrm
  • manuelmigone/vtigercrm
  • eduardo.gqf/vtigercrm
  • elsayedEl-araby/vtigercrm
  • mirza.mehran/vtigercrm
  • maurice.courtois/vtigercrm
  • zuhri.utama/vtigercrm
  • shilpa.k/vtigercrm
  • Ignazio/vtigercrm
  • code80team/vtigercrm
  • code80/vtigercrm
  • nilay.automatesmb/cache
  • greeshma.kk/vtigercrm
  • vijay.tilak/vtigercrm
  • Paolo.Palamini/vtigercrm
  • estevan/vtigercrm
  • mobilcmcdk/vtigercrm
  • massimiliano.vessi/vtigercrm
  • daniel.voelskow/vtigercrm
  • james1/vtigercrm
  • lokesh.s/vtigercrm
  • rdb/vtigercrm
  • neftaliyagua/vtigercrm
  • angelo.paglialonga/vtigercrm
  • webmarka/vtigercrm
  • javanile/vtigercrm
  • akshath/vtigercrm
  • Hemanth/vtigercrm
  • opencrmitalia/vtigercrm
  • direzione/vtigercrm
  • umadas306/vtigercrm
  • jd-wraptec/vtigercrm
  • felipe.camacho/vtigercrm
  • Martin.allen/vtigercrm
  • amit.r/vtigercrm
  • vicus/vtigercrm
  • dev.osmi/vtigercrm
  • laurent.guillout/vtigercrm
  • christian.blaeul/vtigercrm
  • ap.js100/vtigercrm
  • yoann.mourot/vtigercrm-temp
  • christian.cruz/vtigercrm
  • zyli/vtigercrm
  • kaushik.p/vtigercrm
  • Madhuk/vtigercrm
  • cinakzm/vtigercrm
  • raquel.martinez/vtigercrm
  • tosajibadhi/vtigercrm
  • melvin.i/vtigercrm-melvin
  • ashashingadia/vtigercrm
  • stefanwarnat/vtigercrm
  • saran.s/vtigercrm
  • eduardomozart/vtigercrm
  • Daniel.Lennartz1/vtigercrm
  • juergen.fassmann/vtigercrm
  • Michel.Ram/vtigercrm
  • vincenzo.bruno/vtigercrm
  • Hitesh.Solanki/vtigercrm
133 results
Show changes
Showing
with 0 additions and 2419 deletions
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Hmac
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Hmac.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt
*/
require_once 'Zend/Crypt.php';
/**
* PHP implementation of the RFC 2104 Hash based Message Authentication Code
* algorithm.
*
* @todo Patch for refactoring failed tests (key block sizes >80 using internal algo)
* @todo Check if mhash() is a required alternative (will be PECL-only soon)
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Hmac extends Zend_Crypt
{
/**
* The key to use for the hash
*
* @var string
*/
protected static $_key = null;
/**
* pack() format to be used for current hashing method
*
* @var string
*/
protected static $_packFormat = null;
/**
* Hashing algorithm; can be the md5/sha1 functions or any algorithm name
* listed in the output of PHP 5.1.2+ hash_algos().
*
* @var string
*/
protected static $_hashAlgorithm = 'md5';
/**
* List of algorithms supported my mhash()
*
* @var array
*/
protected static $_supportedMhashAlgorithms = array('adler32',' crc32', 'crc32b', 'gost',
'haval128', 'haval160', 'haval192', 'haval256', 'md4', 'md5', 'ripemd160',
'sha1', 'sha256', 'tiger', 'tiger128', 'tiger160');
/**
* Constants representing the output mode of the hash algorithm
*/
const STRING = 'string';
const BINARY = 'binary';
/**
* Performs a HMAC computation given relevant details such as Key, Hashing
* algorithm, the data to compute MAC of, and an output format of String,
* Binary notation or BTWOC.
*
* @param string $key
* @param string $hash
* @param string $data
* @param string $output
* @param boolean $internal
* @return string
*/
public static function compute($key, $hash, $data, $output = self::STRING)
{
// set the key
if (!isset($key) || empty($key)) {
require_once 'Zend/Crypt/Hmac/Exception.php';
throw new Zend_Crypt_Hmac_Exception('provided key is null or empty');
}
self::$_key = $key;
// set the hash
self::_setHashAlgorithm($hash);
// perform hashing and return
return self::_hash($data, $output);
}
/**
* Setter for the hash method.
*
* @param string $hash
* @return Zend_Crypt_Hmac
*/
protected static function _setHashAlgorithm($hash)
{
if (!isset($hash) || empty($hash)) {
require_once 'Zend/Crypt/Hmac/Exception.php';
throw new Zend_Crypt_Hmac_Exception('provided hash string is null or empty');
}
$hash = strtolower($hash);
$hashSupported = false;
if (function_exists('hash_algos') && in_array($hash, hash_algos())) {
$hashSupported = true;
}
if ($hashSupported === false && function_exists('mhash') && in_array($hash, self::$_supportedAlgosMhash)) {
$hashSupported = true;
}
if ($hashSupported === false) {
require_once 'Zend/Crypt/Hmac/Exception.php';
throw new Zend_Crypt_Hmac_Exception('hash algorithm provided is not supported on this PHP installation; please enable the hash or mhash extensions');
}
self::$_hashAlgorithm = $hash;
}
/**
* Perform HMAC and return the keyed data
*
* @param string $data
* @param string $output
* @param bool $internal Option to not use hash() functions for testing
* @return string
*/
protected static function _hash($data, $output = self::STRING, $internal = false)
{
if (function_exists('hash_hmac')) {
if ($output == self::BINARY) {
return hash_hmac(self::$_hashAlgorithm, $data, self::$_key, 1);
}
return hash_hmac(self::$_hashAlgorithm, $data, self::$_key);
}
if (function_exists('mhash')) {
if ($output == self::BINARY) {
return mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
}
$bin = mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
return bin2hex($bin);
}
}
/**
* Since MHASH accepts an integer constant representing the hash algorithm
* we need to make a small detour to get the correct integer matching our
* algorithm's name.
*
* @param string $hashAlgorithm
* @return integer
*/
protected static function _getMhashDefinition($hashAlgorithm)
{
for ($i = 0; $i <= mhash_count(); $i++)
{
$types[mhash_get_hash_name($i)] = $i;
}
return $types[strtoupper($hashAlgorithm)];
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Hmac
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Hmac_Exception extends Zend_Crypt_Exception
{
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Math.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Math_BigInteger
*/
require_once 'Zend/Crypt/Math/BigInteger.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math extends Zend_Crypt_Math_BigInteger
{
/**
* Generate a pseudorandom number within the given range.
* Will attempt to read from a systems RNG if it exists or else utilises
* a simple random character to maximum length process. Simplicity
* is a factor better left for development...
*
* @param string|int $minimum
* @param string|int $maximum
* @return string
*/
public function rand($minimum, $maximum)
{
if (file_exists('/dev/urandom')) {
$frandom = fopen('/dev/urandom', 'r');
if ($frandom !== false) {
return fread($frandom, strlen($maximum) - 1);
}
}
if (strlen($maximum) < 4) {
return mt_rand($minimum, $maximum - 1);
}
$rand = '';
$i2 = strlen($maximum) - 1;
for ($i = 1;$i < $i2;$i++) {
$rand .= mt_rand(0,9);
}
$rand .= mt_rand(0,9);
return $rand;
}
/**
* Get the big endian two's complement of a given big integer in
* binary notation
*
* @param string $long
* @return string
*/
public function btwoc($long) {
if (ord($long[0]) > 127) {
return "\x00" . $long;
}
return $long;
}
/**
* Translate a binary form into a big integer string
*
* @param string $binary
* @return string
*/
public function fromBinary($binary) {
return $this->_math->binaryToInteger($binary);
}
/**
* Translate a big integer string into a binary form
*
* @param string $integer
* @return string
*/
public function toBinary($integer)
{
return $this->_math->integerToBinary($integer);
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: BigInteger.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* Support for arbitrary precision mathematics in PHP.
*
* Zend_Crypt_Math_BigInteger is a wrapper across three PHP extensions: bcmath, gmp
* and big_int. Since each offer similar functionality, but availability of
* each differs across installations of PHP, this wrapper attempts to select
* the fastest option available and encapsulate a subset of its functionality
* which all extensions share in common.
*
* This class requires one of the three extensions to be available. BCMATH
* while the slowest, is available by default under Windows, and under Unix
* if PHP is compiled with the flag "--enable-bcmath". GMP requires the gmp
* library from http://www.swox.com/gmp/ and PHP compiled with the "--with-gmp"
* flag. BIG_INT support is available from a big_int PHP library available from
* only from PECL (a Windows port is not available).
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math_BigInteger
{
/**
* Holds an instance of one of the three arbitrary precision wrappers.
*
* @var Zend_Crypt_Math_BigInteger_Interface
*/
protected $_math = null;
/**
* Constructor; a Factory which detects a suitable PHP extension for
* arbitrary precision math and instantiates the suitable wrapper
* object.
*
* @param string $extension
* @throws Zend_Crypt_Math_BigInteger_Exception
*/
public function __construct($extension = null)
{
if ($extension !== null && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) {
require_once('Zend/Crypt/Math/BigInteger/Exception.php');
throw new Zend_Crypt_Math_BigInteger_Exception('Invalid extension type; please use one of bcmath, gmp or bigint');
}
$this->_loadAdapter($extension);
}
/**
* Redirect all public method calls to the wrapped extension object.
*
* @param string $methodName
* @param array $args
* @throws Zend_Crypt_Math_BigInteger_Exception
*/
public function __call($methodName, $args)
{
if(!method_exists($this->_math, $methodName)) {
require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
throw new Zend_Crypt_Math_BigInteger_Exception('invalid method call: ' . get_class($this->_math) . '::' . $methodName . '() does not exist');
}
return call_user_func_array(array($this->_math, $methodName), $args);
}
/**
* @param string $extension
* @throws Zend_Crypt_Math_BigInteger_Exception
*/
protected function _loadAdapter($extension = null)
{
if ($extension === null) {
if (extension_loaded('gmp')) {
$extension = 'gmp';
//} elseif (extension_loaded('big_int')) {
// $extension = 'big_int';
} else {
$extension = 'bcmath';
}
}
if($extension == 'gmp' && extension_loaded('gmp')) {
require_once 'Zend/Crypt/Math/BigInteger/Gmp.php';
$this->_math = new Zend_Crypt_Math_BigInteger_Gmp();
//} elseif($extension == 'bigint' && extension_loaded('big_int')) {
// require_once 'Zend/Crypt_Math/BigInteger/Bigint.php';
// $this->_math = new Zend_Crypt_Math_BigInteger_Bigint();
} elseif ($extension == 'bcmath' && extension_loaded('bcmath')) {
require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
$this->_math = new Zend_Crypt_Math_BigInteger_Bcmath();
} else {
require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
throw new Zend_Crypt_Math_BigInteger_Exception($extension . ' big integer precision math support not detected');
}
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Bcmath.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Math_BigInteger_Interface
*/
require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
/**
* Support for arbitrary precision mathematics in PHP.
*
* Zend_Crypt_Math_BigInteger_Bcmath is a wrapper across the PHP BCMath
* extension.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math_BigInteger_Bcmath implements Zend_Crypt_Math_BigInteger_Interface
{
/**
* Initialise a big integer into an extension specific type. This is not
* applicable to BCMath.
* @param string $operand
* @param int $base
* @return string
*/
public function init($operand, $base = 10)
{
return $operand;
}
/**
* Adds two arbitrary precision numbers
*
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function add($left_operand, $right_operand)
{
return bcadd($left_operand, $right_operand);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function subtract($left_operand, $right_operand)
{
return bcsub($left_operand, $right_operand);
}
/**
* Compare two big integers and returns result as an integer where 0 means
* both are identical, 1 that left_operand is larger, or -1 that
* right_operand is larger.
* @param string $left_operand
* @param string $right_operand
* @return int
*/
public function compare($left_operand, $right_operand)
{
return bccomp($left_operand, $right_operand);
}
/**
* Divide two big integers and return result or NULL if the denominator
* is zero.
* @param string $left_operand
* @param string $right_operand
* @return string|null
*/
public function divide($left_operand, $right_operand)
{
return bcdiv($left_operand, $right_operand);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function modulus($left_operand, $modulus)
{
return bcmod($left_operand, $modulus);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function multiply($left_operand, $right_operand)
{
return bcmul($left_operand, $right_operand);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function pow($left_operand, $right_operand)
{
return bcpow($left_operand, $right_operand);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function powmod($left_operand, $right_operand, $modulus)
{
return bcpowmod($left_operand, $right_operand, $modulus);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function sqrt($operand)
{
return bcsqrt($operand);
}
public function binaryToInteger($operand)
{
$result = '0';
while (strlen($operand)) {
$ord = ord(substr($operand, 0, 1));
$result = bcadd(bcmul($result, 256), $ord);
$operand = substr($operand, 1);
}
return $result;
}
public function integerToBinary($operand)
{
$cmp = bccomp($operand, 0);
$return = '';
if ($cmp == 0) {
return "\0";
}
while (bccomp($operand, 0) > 0) {
$return = chr(bcmod($operand, 256)) . $return;
$operand = bcdiv($operand, 256);
}
if (ord($return[0]) > 127) {
$return = "\0" . $return;
}
return $return;
}
/**public function integerToBinary($operand)
{
$return = '';
while(bccomp($operand, '0')) {
$return .= chr(bcmod($operand, '256'));
$operand = bcdiv($operand, '256');
}
return $return;
}**/ // Prior version for referenced offset
public function hexToDecimal($operand)
{
$return = '0';
while(strlen($hex)) {
$hex = hexdec(substr($operand, 0, 4));
$dec = bcadd(bcmul($return, 65536), $hex);
$operand = substr($operand, 4);
}
return $return;
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Math_Exception
*/
require_once 'Zend/Crypt/Math/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math_BigInteger_Exception extends Zend_Crypt_Math_Exception
{
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Gmp.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Math_BigInteger_Interface
*/
require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
/**
* Support for arbitrary precision mathematics in PHP.
*
* Zend_Crypt_Math_BigInteger_Gmp is a wrapper across the PHP BCMath
* extension.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math_BigInteger_Gmp implements Zend_Crypt_Math_BigInteger_Interface
{
/**
* Initialise a big integer into an extension specific type.
* @param string $operand
* @param int $base
* @return string
*/
public function init($operand, $base = 10)
{
return $operand;
}
/**
* Adds two arbitrary precision numbers
*
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function add($left_operand, $right_operand)
{
$result = gmp_add($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function subtract($left_operand, $right_operand)
{
$result = gmp_sub($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* Compare two big integers and returns result as an integer where 0 means
* both are identical, 1 that left_operand is larger, or -1 that
* right_operand is larger.
* @param string $left_operand
* @param string $right_operand
* @return int
*/
public function compare($left_operand, $right_operand)
{
$result = gmp_cmp($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* Divide two big integers and return result or NULL if the denominator
* is zero.
* @param string $left_operand
* @param string $right_operand
* @return string|null
*/
public function divide($left_operand, $right_operand)
{
$result = gmp_div($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function modulus($left_operand, $modulus)
{
$result = gmp_mod($left_operand, $modulus);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function multiply($left_operand, $right_operand)
{
$result = gmp_mul($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function pow($left_operand, $right_operand)
{
$result = gmp_pow($left_operand, $right_operand);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function powmod($left_operand, $right_operand, $modulus)
{
$result = gmp_powm($left_operand, $right_operand, $modulus);
return gmp_strval($result);
}
/**
* @param string $left_operand
* @param string $right_operand
* @return string
*/
public function sqrt($operand)
{
$result = gmp_sqrt($operand);
return gmp_strval($result);
}
public function binaryToInteger($operand)
{
$result = '0';
while (strlen($operand)) {
$ord = ord(substr($operand, 0, 1));
$result = gmp_add(gmp_mul($result, 256), $ord);
$operand = substr($operand, 1);
}
return gmp_strval($result);
}
public function integerToBinary($operand)
{
$bigInt = gmp_strval($operand, 16);
if (strlen($bigInt) % 2 != 0) {
$bigInt = '0' . $bigInt;
} else if ($bigInt[0] > '7') {
$bigInt = '00' . $bigInt;
}
$return = pack("H*", $bigInt);
return $return;
}
public function hexToDecimal($operand)
{
$return = '0';
while(strlen($hex)) {
$hex = hexdec(substr($operand, 0, 4));
$dec = gmp_add(gmp_mul($return, 65536), $hex);
$operand = substr($operand, 4);
}
return $return;
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* Support for arbitrary precision mathematics in PHP.
*
* Interface for a wrapper across any PHP extension supporting arbitrary
* precision maths.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Crypt_Math_BigInteger_Interface
{
public function init($operand, $base = 10);
public function add($left_operand, $right_operand);
public function subtract($left_operand, $right_operand);
public function compare($left_operand, $right_operand);
public function divide($left_operand, $right_operand);
public function modulus($left_operand, $modulus);
public function multiply($left_operand, $right_operand);
public function pow($left_operand, $right_operand);
public function powmod($left_operand, $right_operand, $modulus);
public function sqrt($operand);
public function binaryToInteger($operand);
public function integerToBinary($operand);
public function hexToDecimal($operand);
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Math_Exception extends Zend_Crypt_Exception
{
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Rsa
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Rsa.php 24808 2012-05-17 19:56:09Z rob $
*/
/**
* @see Zend_Crypt_Rsa_Key_Private
*/
require_once 'Zend/Crypt/Rsa/Key/Private.php';
/**
* @see Zend_Crypt_Rsa_Key_Public
*/
require_once 'Zend/Crypt/Rsa/Key/Public.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Rsa
{
const BINARY = 'binary';
const BASE64 = 'base64';
protected $_privateKey;
protected $_publicKey;
/**
* @var string
*/
protected $_pemString;
protected $_pemPath;
protected $_certificateString;
protected $_certificatePath;
protected $_hashAlgorithm;
protected $_passPhrase;
/**
* Class constructor
*
* @param array $options
* @throws Zend_Crypt_Rsa_Exception
*/
public function __construct(array $options = null)
{
if (!extension_loaded('openssl')) {
require_once 'Zend/Crypt/Rsa/Exception.php';
throw new Zend_Crypt_Rsa_Exception('Zend_Crypt_Rsa requires openssl extension to be loaded.');
}
// Set _hashAlgorithm property when we are sure, that openssl extension is loaded
// and OPENSSL_ALGO_SHA1 constant is available
$this->_hashAlgorithm = OPENSSL_ALGO_SHA1;
if (isset($options)) {
$this->setOptions($options);
}
}
public function setOptions(array $options)
{
if (isset($options['passPhrase'])) {
$this->_passPhrase = $options['passPhrase'];
}
foreach ($options as $option=>$value) {
switch ($option) {
case 'pemString':
$this->setPemString($value);
break;
case 'pemPath':
$this->setPemPath($value);
break;
case 'certificateString':
$this->setCertificateString($value);
break;
case 'certificatePath':
$this->setCertificatePath($value);
break;
case 'hashAlgorithm':
$this->setHashAlgorithm($value);
break;
}
}
}
public function getPrivateKey()
{
return $this->_privateKey;
}
public function getPublicKey()
{
return $this->_publicKey;
}
/**
* @param string $data
* @param Zend_Crypt_Rsa_Key_Private $privateKey
* @param string $format
* @return string
*/
public function sign($data, Zend_Crypt_Rsa_Key_Private $privateKey = null, $format = null)
{
$signature = '';
if (isset($privateKey)) {
$opensslKeyResource = $privateKey->getOpensslKeyResource();
} else {
$opensslKeyResource = $this->_privateKey->getOpensslKeyResource();
}
$result = openssl_sign(
$data, $signature,
$opensslKeyResource,
$this->getHashAlgorithm()
);
if ($format == self::BASE64) {
return base64_encode($signature);
}
return $signature;
}
/**
* @param string $data
* @param string $signature
* @param string $format
* @return string
*/
public function verifySignature($data, $signature, $format = null)
{
if ($format == self::BASE64) {
$signature = base64_decode($signature);
}
$result = openssl_verify($data, $signature,
$this->getPublicKey()->getOpensslKeyResource(),
$this->getHashAlgorithm());
return $result;
}
/**
* @param string $data
* @param Zend_Crypt_Rsa_Key $key
* @param string $format
* @return string
*/
public function encrypt($data, Zend_Crypt_Rsa_Key $key, $format = null)
{
$encrypted = '';
$function = 'openssl_public_encrypt';
if ($key instanceof Zend_Crypt_Rsa_Key_Private) {
$function = 'openssl_private_encrypt';
}
$function($data, $encrypted, $key->getOpensslKeyResource());
if ($format == self::BASE64) {
return base64_encode($encrypted);
}
return $encrypted;
}
/**
* @param string $data
* @param Zend_Crypt_Rsa_Key $key
* @param string $format
* @return string
*/
public function decrypt($data, Zend_Crypt_Rsa_Key $key, $format = null)
{
$decrypted = '';
if ($format == self::BASE64) {
$data = base64_decode($data);
}
$function = 'openssl_private_decrypt';
if ($key instanceof Zend_Crypt_Rsa_Key_Public) {
$function = 'openssl_public_decrypt';
}
$function($data, $decrypted, $key->getOpensslKeyResource());
return $decrypted;
}
/**
* @param array $configargs
*
* @throws Zend_Crypt_Rsa_Exception
*
* @return ArrayObject
*/
public function generateKeys(array $configargs = null)
{
$config = null;
$passPhrase = null;
if ($configargs !== null) {
if (isset($configargs['passPhrase'])) {
$passPhrase = $configargs['passPhrase'];
unset($configargs['passPhrase']);
}
$config = $this->_parseConfigArgs($configargs);
}
$privateKey = null;
$publicKey = null;
$resource = openssl_pkey_new($config);
if (!$resource) {
require_once 'Zend/Crypt/Rsa/Exception.php';
throw new Zend_Crypt_Rsa_Exception('Failed to generate a new private key');
}
// above fails on PHP 5.3
openssl_pkey_export($resource, $private, $passPhrase);
$privateKey = new Zend_Crypt_Rsa_Key_Private($private, $passPhrase);
$details = openssl_pkey_get_details($resource);
$publicKey = new Zend_Crypt_Rsa_Key_Public($details['key']);
$return = new ArrayObject(array(
'privateKey'=>$privateKey,
'publicKey'=>$publicKey
), ArrayObject::ARRAY_AS_PROPS);
return $return;
}
/**
* @param string $value
*/
public function setPemString($value)
{
$this->_pemString = $value;
try {
$this->_privateKey = new Zend_Crypt_Rsa_Key_Private($this->_pemString, $this->_passPhrase);
$this->_publicKey = $this->_privateKey->getPublicKey();
} catch (Zend_Crypt_Exception $e) {
$this->_privateKey = null;
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_pemString);
}
}
public function setPemPath($value)
{
$this->_pemPath = $value;
$this->setPemString(file_get_contents($this->_pemPath));
}
public function setCertificateString($value)
{
$this->_certificateString = $value;
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_certificateString, $this->_passPhrase);
}
public function setCertificatePath($value)
{
$this->_certificatePath = $value;
$this->setCertificateString(file_get_contents($this->_certificatePath));
}
public function setHashAlgorithm($name)
{
switch (strtolower($name)) {
case 'md2':
$this->_hashAlgorithm = OPENSSL_ALGO_MD2;
break;
case 'md4':
$this->_hashAlgorithm = OPENSSL_ALGO_MD4;
break;
case 'md5':
$this->_hashAlgorithm = OPENSSL_ALGO_MD5;
break;
case 'sha1':
$this->_hashAlgorithm = OPENSSL_ALGO_SHA1;
break;
case 'dss1':
$this->_hashAlgorithm = OPENSSL_ALGO_DSS1;
break;
}
}
/**
* @return string
*/
public function getPemString()
{
return $this->_pemString;
}
public function getPemPath()
{
return $this->_pemPath;
}
public function getCertificateString()
{
return $this->_certificateString;
}
public function getCertificatePath()
{
return $this->_certificatePath;
}
public function getHashAlgorithm()
{
return $this->_hashAlgorithm;
}
protected function _parseConfigArgs(array $config = null)
{
$configs = array();
if (isset($config['private_key_bits'])) {
$configs['private_key_bits'] = $config['private_key_bits'];
}
if (isset($config['privateKeyBits'])) {
$configs['private_key_bits'] = $config['privateKeyBits'];
}
if (!empty($configs)) {
return $configs;
}
return null;
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Math
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Rsa_Exception extends Zend_Crypt_Exception
{
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Rsa
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Key.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Rsa_Key implements Countable
{
/**
* @var string
*/
protected $_pemString = null;
/**
* Bits, key string and type of key
*
* @var array
*/
protected $_details = array();
/**
* Key Resource
*
* @var resource
*/
protected $_opensslKeyResource = null;
/**
* Retrieves key resource
*
* @return resource
*/
public function getOpensslKeyResource()
{
return $this->_opensslKeyResource;
}
/**
* @return string
* @throws Zend_Crypt_Exception
*/
public function toString()
{
if (!empty($this->_pemString)) {
return $this->_pemString;
} elseif (!empty($this->_certificateString)) {
return $this->_certificateString;
}
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception('No public key string representation is available');
}
/**
* @return string
*/
public function __toString()
{
return $this->toString();
}
public function count()
{
return $this->_details['bits'];
}
public function getType()
{
return $this->_details['type'];
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Rsa
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Private.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Rsa_Key
*/
require_once 'Zend/Crypt/Rsa/Key.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
{
protected $_publicKey = null;
public function __construct($pemString, $passPhrase = null)
{
$this->_pemString = $pemString;
$this->_parse($passPhrase);
}
/**
* @param string $passPhrase
* @throws Zend_Crypt_Exception
*/
protected function _parse($passPhrase)
{
$result = openssl_get_privatekey($this->_pemString, $passPhrase);
if (!$result) {
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception('Unable to load private key');
}
$this->_opensslKeyResource = $result;
$this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
}
public function getPublicKey()
{
if ($this->_publicKey === null) {
/**
* @see Zend_Crypt_Rsa_Key_Public
*/
require_once 'Zend/Crypt/Rsa/Key/Public.php';
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
}
return $this->_publicKey;
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage Rsa
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Public.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Rsa_Key
*/
require_once 'Zend/Crypt/Rsa/Key.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Rsa_Key_Public extends Zend_Crypt_Rsa_Key
{
protected $_certificateString = null;
public function __construct($string)
{
$this->_parse($string);
}
/**
* @param string $string
* @throws Zend_Crypt_Exception
*/
protected function _parse($string)
{
if (preg_match("/^-----BEGIN CERTIFICATE-----/", $string)) {
$this->_certificateString = $string;
} else {
$this->_pemString = $string;
}
$result = openssl_get_publickey($string);
if (!$result) {
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception('Unable to load public key');
}
//openssl_pkey_export($result, $public);
//$this->_pemString = $public;
$this->_opensslKeyResource = $result;
$this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
}
public function getCertificate()
{
return $this->_certificateString;
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Gdata.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* Zend_Gdata_App
*/
require_once 'Zend/Gdata/App.php';
/**
* Provides functionality to interact with Google data APIs
* Subclasses exist to implement service-specific features
*
* As the Google data API protocol is based upon the Atom Publishing Protocol
* (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes
*
* @link http://code.google.com/apis/gdata/overview.html
*
* @category Zend
* @package Zend_Gdata
* @subpackage Gdata
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Gdata extends Zend_Gdata_App
{
/**
* Service name for use with Google's authentication mechanisms
*
* @var string
*/
const AUTH_SERVICE_NAME = 'xapi';
/**
* Default URI to which to POST.
*
* @var string
*/
protected $_defaultPostUri = null;
/**
* Packages to search for classes when using magic __call method, in order.
*
* @var array
*/
protected $_registeredPackages = array(
'Zend_Gdata_Kind',
'Zend_Gdata_Extension',
'Zend_Gdata',
'Zend_Gdata_App_Extension',
'Zend_Gdata_App');
/**
* Namespaces used for Gdata data
*
* @var array
*/
public static $namespaces = array(
array('gd', 'http://schemas.google.com/g/2005', 1, 0),
array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0),
array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0),
array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0)
);
/**
* Client object used to communicate
*
* @var Zend_Gdata_HttpClient
*/
protected $_httpClient;
/**
* Client object used to communicate in static context
*
* @var Zend_Gdata_HttpClient
*/
protected static $_staticHttpClient = null;
/**
* Create Gdata object
*
* @param Zend_Http_Client $client
* @param string $applicationId The identity of the app in the form of
* Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
parent::__construct($client, $applicationId);
}
/**
* Imports a feed located at $uri.
*
* @param string $uri
* @param Zend_Http_Client $client The client used for communication
* @param string $className The class which is used as the return type
* @throws Zend_Gdata_App_Exception
* @return string|Zend_Gdata_App_Feed Returns string only if the object
* mapping has been disabled explicitly
* by passing false to the
* useObjectMapping() function.
*/
public static function import($uri, $client = null,
$className='Zend_Gdata_Feed')
{
$app = new Zend_Gdata($client);
$requestData = $app->decodeRequest('GET', $uri);
$response = $app->performHttpRequest($requestData['method'], $requestData['url']);
$feedContent = $response->getBody();
$feed = self::importString($feedContent, $className);
if ($client != null) {
$feed->setHttpClient($client);
}
return $feed;
}
/**
* Retrieve feed as string or object
*
* @param mixed $location The location as string or Zend_Gdata_Query
* @param string $className The class type to use for returning the feed
* @throws Zend_Gdata_App_InvalidArgumentException
* @return string|Zend_Gdata_App_Feed Returns string only if the object
* mapping has been disabled explicitly
* by passing false to the
* useObjectMapping() function.
*/
public function getFeed($location, $className='Zend_Gdata_Feed')
{
if (is_string($location)) {
$uri = $location;
} elseif ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You must specify the location as either a string URI ' .
'or a child of Zend_Gdata_Query');
}
return parent::getFeed($uri, $className);
}
/**
* Retrieve entry as string or object
*
* @param mixed $location The location as string or Zend_Gdata_Query
* @throws Zend_Gdata_App_InvalidArgumentException
* @return string|Zend_Gdata_App_Entry Returns string only if the object
* mapping has been disabled explicitly
* by passing false to the
* useObjectMapping() function.
*/
public function getEntry($location, $className='Zend_Gdata_Entry')
{
if (is_string($location)) {
$uri = $location;
} elseif ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'You must specify the location as either a string URI ' .
'or a child of Zend_Gdata_Query');
}
return parent::getEntry($uri, $className);
}
/**
* Performs a HTTP request using the specified method.
*
* Overrides the definition in the parent (Zend_Gdata_App)
* and uses the Zend_Gdata_HttpClient functionality
* to filter the HTTP requests and responses.
*
* @param string $method The HTTP method for the request -
* 'GET', 'POST', 'PUT', 'DELETE'
* @param string $url The URL to which this request is being performed,
* or null if found in $data
* @param array $headers An associative array of HTTP headers
* for this request
* @param string $body The body of the HTTP request
* @param string $contentType The value for the content type of the
* request body
* @param int $remainingRedirects Number of redirects to follow
* if requests results in one
* @return Zend_Http_Response The response object
*/
public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
{
if ($this->_httpClient instanceof Zend_Gdata_HttpClient) {
$filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType);
$method = $filterResult['method'];
$url = $filterResult['url'];
$body = $filterResult['body'];
$headers = $filterResult['headers'];
$contentType = $filterResult['contentType'];
return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
} else {
return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
}
}
/**
* Determines whether service object is authenticated.
*
* @return boolean True if service object is authenticated, false otherwise.
*/
public function isAuthenticated()
{
$client = parent::getHttpClient();
if ($client->getClientLoginToken() ||
$client->getAuthSubToken()) {
return true;
}
return false;
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Gdata
*/
require_once 'Zend/Gdata.php';
/**
* @see Zend_Gdata_Analytics_AccountEntry
*/
require_once 'Zend/Gdata/Analytics/AccountEntry.php';
/**
* @see Zend_Gdata_Analytics_AccountFeed
*/
require_once 'Zend/Gdata/Analytics/AccountFeed.php';
/**
* @see Zend_Gdata_Analytics_DataEntry
*/
require_once 'Zend/Gdata/Analytics/DataEntry.php';
/**
* @see Zend_Gdata_Analytics_DataFeed
*/
require_once 'Zend/Gdata/Analytics/DataFeed.php';
/**
* @see Zend_Gdata_Analytics_DataQuery
*/
require_once 'Zend/Gdata/Analytics/DataQuery.php';
/**
* @see Zend_Gdata_Analytics_AccountQuery
*/
require_once 'Zend/Gdata/Analytics/AccountQuery.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
*/
class Zend_Gdata_Analytics extends Zend_Gdata
{
const AUTH_SERVICE_NAME = 'analytics';
const ANALYTICS_FEED_URI = 'https://www.googleapis.com/analytics/v2.4/data';
const ANALYTICS_ACCOUNT_FEED_URI = 'https://www.googleapis.com/analytics/v2.4/management/accounts';
public static $namespaces = array(
array('analytics', 'http://schemas.google.com/analytics/2009', 1, 0),
array('ga', 'http://schemas.google.com/ga/2009', 1, 0)
);
/**
* Create Gdata object
*
* @param Zend_Http_Client $client
* @param string $applicationId The identity of the app in the form of
* Company-AppName-Version
*/
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
{
$this->registerPackage('Zend_Gdata_Analytics');
$this->registerPackage('Zend_Gdata_Analytics_Extension');
parent::__construct($client, $applicationId);
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
}
/**
* Retrieve account feed object
*
* @param string|Zend_Uri_Uri $uri
* @return Zend_Gdata_Analytics_AccountFeed
*/
public function getAccountFeed($uri = self::ANALYTICS_ACCOUNT_FEED_URI)
{
if ($uri instanceof Query) {
$uri = $uri->getQueryUrl();
}
return parent::getFeed($uri, 'Zend_Gdata_Analytics_AccountFeed');
}
/**
* Retrieve data feed object
*
* @param string|Zend_Uri_Uri $uri
* @return Zend_Gdata_Analytics_DataFeed
*/
public function getDataFeed($uri = self::ANALYTICS_FEED_URI)
{
if ($uri instanceof Query) {
$uri = $uri->getQueryUrl();
}
return parent::getFeed($uri, 'Zend_Gdata_Analytics_DataFeed');
}
/**
* Returns a new DataQuery object.
*
* @return Zend_Gdata_Analytics_DataQuery
*/
public function newDataQuery()
{
return new Zend_Gdata_Analytics_DataQuery();
}
/**
* Returns a new AccountQuery object.
*
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function newAccountQuery()
{
return new Zend_Gdata_Analytics_AccountQuery();
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @see Zend_Gdata_Analytics_Extension_Dimension
*/
require_once 'Zend/Gdata/Analytics/Extension/Dimension.php';
/**
* @see Zend_Gdata_Analytics_Extension_Metric
*/
require_once 'Zend/Gdata/Analytics/Extension/Metric.php';
/**
* @see Zend_Gdata_Analytics_Extension_Property
*/
require_once 'Zend/Gdata/Analytics/Extension/Property.php';
/**
* @see Zend_Gdata_Analytics_Extension_TableId
*/
require_once 'Zend/Gdata/Analytics/Extension/TableId.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
*/
class Zend_Gdata_Analytics_AccountEntry extends Zend_Gdata_Entry
{
protected $_accountId;
protected $_accountName;
protected $_profileId;
protected $_webPropertyId;
protected $_currency;
protected $_timezone;
protected $_tableId;
protected $_profileName;
protected $_goal;
/**
* @see Zend_Gdata_Entry::__construct()
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
parent::__construct($element);
}
/**
* @param DOMElement $child
* @return void
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName){
case $this->lookupNamespace('analytics') . ':' . 'property';
$property = new Zend_Gdata_Analytics_Extension_Property();
$property->transferFromDOM($child);
$this->{$property->getName()} = $property;
break;
case $this->lookupNamespace('analytics') . ':' . 'tableId';
$tableId = new Zend_Gdata_Analytics_Extension_TableId();
$tableId->transferFromDOM($child);
$this->_tableId = $tableId;
break;
case $this->lookupNamespace('ga') . ':' . 'goal';
$goal = new Zend_Gdata_Analytics_Extension_Goal();
$goal->transferFromDOM($child);
$this->_goal = $goal;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Gdata_Feed
*/
require_once 'Zend/Gdata/Feed.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
*/
class Zend_Gdata_Analytics_AccountFeed extends Zend_Gdata_Feed
{
/**
* The classname for individual feed elements.
*
* @var string
*/
protected $_entryClassName = 'Zend_Gdata_Analytics_AccountEntry';
/**
* The classname for the feed.
*
* @var string
*/
protected $_feedClassName = 'Zend_Gdata_Analytics_AccountFeed';
/**
* @see Zend_GData_Feed::__construct()
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
parent::__construct($element);
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Gdata_Query
*/
require_once 'Zend/Gdata/Query.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
*/
class Zend_Gdata_Analytics_AccountQuery extends Zend_Gdata_Query
{
const ANALYTICS_FEED_URI = 'https://www.googleapis.com/analytics/v2.4/management/accounts';
/**
* The default URI used for feeds.
*/
protected $_defaultFeedUri = self::ANALYTICS_FEED_URI;
/**
* @var string
*/
protected $_accountId = '~all';
/**
* @var string
*/
protected $_webpropertyId = '~all';
/**
* @var string
*/
protected $_profileId = '~all';
/**
* @var bool
*/
protected $_webproperties = false;
/**
* @var bool
*/
protected $_profiles = false;
/**
* @var bool
*/
protected $_goals = false;
/**
* @param string $accountId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function setAccountId($accountId)
{
$this->_accountId = $accountId;
return $this;
}
/**
* @return string
*/
public function getAccountId()
{
return $this->_accountId;
}
/**
* @param string $webpropertyId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function setWebpropertyId($webpropertyId)
{
$this->_webpropertyId = $webpropertyId;
return $this;
}
/**
* @return string
*/
public function getWebpropertyId()
{
return $this->_webpropertyId;
}
/**
* @param string $profileId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function setProfileId($profileId)
{
$this->_profileId = $profileId;
return $this;
}
/**
* @return string
*/
public function getProfileId()
{
return $this->_profileId;
}
/**
* @param string $accountId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function webproperties($accountId = '~all')
{
$this->_webproperties = true;
$this->setAccountId($accountId);
return $this;
}
/**
* @param string $webpropertyId
* @param string $accountId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function profiles($webpropertyId = '~all', $accountId = '~all')
{
$this->_profiles = true;
if (null !== $accountId) {
$this->setAccountId($accountId);
}
$this->setWebpropertyId($webpropertyId);
return $this;
}
/**
* @param string $webpropertyId
* @param string $accountId
* @param string $accountId
* @return Zend_Gdata_Analytics_AccountQuery
*/
public function goals($profileId = '~all', $webpropertyId = '~all', $accountId = '~all')
{
$this->_goals = true;
if (null !== $accountId) {
$this->setAccountId($accountId);
}
if (null !== $webpropertyId) {
$this->setWebpropertyId($webpropertyId);
}
$this->setProfileId($profileId);
return $this;
}
/**
* @return string url
*/
public function getQueryUrl()
{
$url = $this->_defaultFeedUri;
// add account id
if ($this->_webproperties or $this->_profiles or $this->_goals) {
$url .= '/' . $this->_accountId . '/webproperties';
}
if ($this->_profiles or $this->_goals) {
$url .= '/' . $this->_webpropertyId . '/profiles';
}
if ($this->_goals) {
$url .= '/' . $this->_profileId . '/goals';
}
$url .= $this->getQueryString();
return $url;
}
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Gdata_Entry
*/
require_once 'Zend/Gdata/Entry.php';
/**
* @category Zend
* @package Zend_Gdata
* @subpackage Analytics
*/
class Zend_Gdata_Analytics_DataEntry extends Zend_Gdata_Entry
{
/**
* @var array
*/
protected $_dimensions = array();
/**
* @var array
*/
protected $_metrics = array();
/**
* @param DOMElement $element
*/
public function __construct($element = null)
{
$this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
parent::__construct($element);
}
/**
* @param DOMElement $child
* @return void
*/
protected function takeChildFromDOM($child)
{
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
switch ($absoluteNodeName) {
case $this->lookupNamespace('analytics') . ':' . 'dimension';
$dimension = new Zend_Gdata_Analytics_Extension_Dimension();
$dimension->transferFromDOM($child);
$this->_dimensions[] = $dimension;
break;
case $this->lookupNamespace('analytics') . ':' . 'metric';
$metric = new Zend_Gdata_Analytics_Extension_Metric();
$metric->transferFromDOM($child);
$this->_metrics[] = $metric;
break;
default:
parent::takeChildFromDOM($child);
break;
}
}
/**
* @param string $name
* @return mixed
*/
public function getDimension($name)
{
foreach ($this->_dimensions as $dimension) {
if ($dimension->getName() == $name) {
return $dimension;
}
}
return null;
}
/**
* @param string $name
* @return mixed
*/
public function getMetric($name)
{
foreach ($this->_metrics as $metric) {
if ($metric->getName() == $name) {
return $metric;
}
}
return null;
}
/**
* @param string $name
* @return mixed
*/
public function getValue($name)
{
if (null !== ($metric = $this->getMetric($name))) {
return $metric;
}
return $this->getDimension($name);
}
}