PMCORE-3843
This commit is contained in:
committed by
Mauricio Veliz
parent
ff4ed98f63
commit
824ead24fe
167
thirdparty/pear/Benchmark/Iterate.php
vendored
167
thirdparty/pear/Benchmark/Iterate.php
vendored
@@ -1,167 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +------------------------------------------------------------------------+
|
||||
// | PEAR :: Benchmark |
|
||||
// +------------------------------------------------------------------------+
|
||||
// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
|
||||
// +------------------------------------------------------------------------+
|
||||
// | This source file is subject to the New BSD license, That is bundled |
|
||||
// | with this package in the file LICENSE, and is available through |
|
||||
// | the world-wide-web at |
|
||||
// | http://www.opensource.org/licenses/bsd-license.php |
|
||||
// | If you did not receive a copy of the new BSDlicense and are unable |
|
||||
// | to obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
|
||||
//
|
||||
|
||||
require_once 'Benchmark/Timer.php';
|
||||
|
||||
/**
|
||||
* Provides timing and profiling information.
|
||||
*
|
||||
* Example 1
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Iterate.php';
|
||||
*
|
||||
* $benchmark = new Benchmark_Iterate;
|
||||
*
|
||||
* function foo($string) {
|
||||
* print $string . '<br>';
|
||||
* }
|
||||
*
|
||||
* $benchmark->run(100, 'foo', 'test');
|
||||
* $result = $benchmark->get();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Example 2
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Iterate.php';
|
||||
*
|
||||
* $benchmark = new Benchmark_Iterate;
|
||||
*
|
||||
* class MyClass {
|
||||
* function foo($string) {
|
||||
* print $string . '<br>';
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $benchmark->run(100, 'myclass::foo', 'test');
|
||||
* $result = $benchmark->get();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Example 3
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Iterate.php';
|
||||
*
|
||||
* $benchmark = new Benchmark_Iterate;
|
||||
*
|
||||
* class MyClass {
|
||||
* function foo($string) {
|
||||
* print $string . '<br>';
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $o = new MyClass();
|
||||
*
|
||||
* $benchmark->run(100, 'o->foo', 'test');
|
||||
* $result = $benchmark->get();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
|
||||
* @category Benchmarking
|
||||
* @package Benchmark
|
||||
*/
|
||||
class Benchmark_Iterate extends Benchmark_Timer {
|
||||
/**
|
||||
* Benchmarks a function or method.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function run() {
|
||||
$arguments = func_get_args();
|
||||
$iterations = array_shift($arguments);
|
||||
$function_name = array_shift($arguments);
|
||||
|
||||
if (strstr($function_name, '::')) {
|
||||
$function_name = explode('::', $function_name);
|
||||
$objectmethod = $function_name[1];
|
||||
}
|
||||
|
||||
if (strstr($function_name, '->')) {
|
||||
$function_name = explode('->', $function_name);
|
||||
$objectname = $function_name[0];
|
||||
|
||||
$object = $GLOBALS[$objectname];
|
||||
$objectmethod = $function_name[1];
|
||||
|
||||
for ($i = 1; $i <= $iterations; $i++) {
|
||||
$this->setMarker('start_' . $i);
|
||||
call_user_func_array(array($object, $function_name[1]), $arguments);
|
||||
$this->setMarker('end_' . $i);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $iterations; $i++) {
|
||||
$this->setMarker('start_' . $i);
|
||||
call_user_func_array($function_name, $arguments);
|
||||
$this->setMarker('end_' . $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns benchmark result.
|
||||
*
|
||||
* $result[x ] = execution time of iteration x
|
||||
* $result['mean' ] = mean execution time
|
||||
* $result['iterations'] = number of iterations
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function get($simple_output = false) {
|
||||
$result = array();
|
||||
$total = 0;
|
||||
|
||||
$iterations = count($this->markers)/2;
|
||||
|
||||
for ($i = 1; $i <= $iterations; $i++) {
|
||||
$time = $this->timeElapsed('start_'.$i , 'end_'.$i);
|
||||
|
||||
if (extension_loaded('bcmath')) {
|
||||
$total = bcadd($total, $time, 6);
|
||||
} else {
|
||||
$total = $total + $time;
|
||||
}
|
||||
|
||||
if (!$simple_output) {
|
||||
$result[$i] = $time;
|
||||
}
|
||||
}
|
||||
|
||||
if (extension_loaded('bcmath')) {
|
||||
$result['mean'] = bcdiv($total, $iterations, 6);
|
||||
} else {
|
||||
$result['mean'] = $total / $iterations;
|
||||
}
|
||||
|
||||
$result['iterations'] = $iterations;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
447
thirdparty/pear/Benchmark/Profiler.php
vendored
447
thirdparty/pear/Benchmark/Profiler.php
vendored
@@ -1,447 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PEAR :: Benchmark |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the New BSD license, That is bundled |
|
||||
// | with this package in the file LICENSE, and is available through |
|
||||
// | the world-wide-web at |
|
||||
// | http://www.opensource.org/licenses/bsd-license.php |
|
||||
// | If you did not receive a copy of the new BSDlicense and are unable |
|
||||
// | to obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Profiler.php,v 1.2 2007/05/24 05:23:20 anant Exp $
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Provides timing and profiling information.
|
||||
*
|
||||
* Example 1: Automatic profiling start, stop, and output.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Profiler.php';
|
||||
*
|
||||
* $profiler = new Benchmark_Profiler(TRUE);
|
||||
*
|
||||
* function myFunction() {
|
||||
* global $profiler;
|
||||
* $profiler->enterSection('myFunction');
|
||||
* //do something
|
||||
* $profiler->leaveSection('myFunction');
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* //do something
|
||||
* myFunction();
|
||||
* //do more
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Example 2: Manual profiling start, stop, and output.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Profiler.php';
|
||||
*
|
||||
* $profiler = new Benchmark_Profiler();
|
||||
*
|
||||
* function myFunction() {
|
||||
* global $profiler;
|
||||
* $profiler->enterSection('myFunction');
|
||||
* //do something
|
||||
* $profiler->leaveSection('myFunction');
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* $profiler->start();
|
||||
* //do something
|
||||
* myFunction();
|
||||
* //do more
|
||||
* $profiler->stop();
|
||||
* $profiler->display();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @author Matthias Englert <Matthias.Englert@gmx.de>
|
||||
* @copyright Copyright © 2002-2005 Matthias Englert <Matthias.Englert@gmx.de>
|
||||
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
|
||||
* @category Benchmarking
|
||||
* @package Benchmark
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class Benchmark_Profiler extends PEAR {
|
||||
/**
|
||||
* Contains the total ex. time of each section
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_sections = array();
|
||||
|
||||
/**
|
||||
* Calling stack
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_stack = array();
|
||||
|
||||
/**
|
||||
* Notes how often a section was entered
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_numberOfCalls = array();
|
||||
|
||||
/**
|
||||
* Notes for each section how much time is spend in sub-sections
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_subSectionsTime = array();
|
||||
|
||||
/**
|
||||
* Notes for each section how often it calls which section
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_calls = array();
|
||||
|
||||
/**
|
||||
* Notes for each section how often it was called by which section
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_callers = array();
|
||||
|
||||
/**
|
||||
* Auto-starts and stops profiler
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_auto = FALSE;
|
||||
|
||||
/**
|
||||
* Max marker name length for non-html output
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $_maxStringLength = 0;
|
||||
|
||||
/**
|
||||
* Constructor, starts profiling recording
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Benchmark_Profiler($auto = FALSE) {
|
||||
$this->_auto = $auto;
|
||||
|
||||
if ($this->_auto) {
|
||||
$this->start();
|
||||
}
|
||||
|
||||
$this->PEAR();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close method, stop profiling recording and display output.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function close() {
|
||||
if (isset($this->_auto) && $this->_auto) {
|
||||
$this->stop();
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns profiling informations for a given section.
|
||||
*
|
||||
* @param string $section
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function getSectionInformations($section = 'Global') {
|
||||
if (isset($this->_sections[$section])) {
|
||||
$calls = array();
|
||||
|
||||
if (isset($this->_calls[$section])) {
|
||||
$calls = $this->_calls[$section];
|
||||
}
|
||||
|
||||
$callers = array();
|
||||
|
||||
if (isset($this->_callers[$section])) {
|
||||
$callers = $this->_callers[$section];
|
||||
}
|
||||
|
||||
$informations = array();
|
||||
|
||||
$informations['time'] = $this->_sections[$section];
|
||||
if (isset($this->_sections['Global'])) {
|
||||
$informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', '');
|
||||
} else {
|
||||
$informations['percentage'] = 'N/A';
|
||||
}
|
||||
$informations['calls'] = $calls;
|
||||
$informations['num_calls'] = $this->_numberOfCalls[$section];
|
||||
$informations['callers'] = $callers;
|
||||
|
||||
if (isset($this->_subSectionsTime[$section])) {
|
||||
$informations['netto_time'] = $this->_sections[$section] - $this->_subSectionsTime[$section];
|
||||
} else {
|
||||
$informations['netto_time'] = $this->_sections[$section];
|
||||
}
|
||||
|
||||
return $informations;
|
||||
} else {
|
||||
$this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns profiling informations for all sections.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function getAllSectionsInformations() {
|
||||
$informations = array();
|
||||
|
||||
foreach($this->_sections as $section => $time) {
|
||||
$informations[$section] = $this->getSectionInformations($section);
|
||||
}
|
||||
|
||||
return $informations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted profiling information.
|
||||
*
|
||||
* @param string output format (auto, plain or html), default auto
|
||||
* @see display()
|
||||
* @access private
|
||||
*/
|
||||
function _getOutput($format) {
|
||||
|
||||
/* Quickly find out the maximun length: Ineffecient, but will do for now! */
|
||||
$informations = $this->getAllSectionsInformations();
|
||||
$names = array_keys($informations);
|
||||
|
||||
$maxLength = 0;
|
||||
foreach ($names as $name)
|
||||
{
|
||||
if ($maxLength < strlen($name)) {
|
||||
$maxLength = strlen($name);
|
||||
}
|
||||
}
|
||||
$this->_maxStringLength = $maxLength;
|
||||
|
||||
if ($format == 'auto') {
|
||||
if (function_exists('version_compare') &&
|
||||
version_compare(phpversion(), '4.1', 'ge')) {
|
||||
$format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
|
||||
} else {
|
||||
global $HTTP_SERVER_VARS;
|
||||
$format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
|
||||
}
|
||||
}
|
||||
|
||||
if ($format == 'html') {
|
||||
$out = '<table style="border: 1px solid #000000; ">'."\n";
|
||||
$out .=
|
||||
'<tr><td> </td><td align="center"><b>total ex. time</b></td>'.
|
||||
'<td align="center"><b>netto ex. time</b></td>'.
|
||||
'<td align="center"><b>#calls</b></td><td align="center"><b>%</b></td>'.
|
||||
'<td align="center"><b>calls</b></td><td align="center"><b>callers</b></td></tr>'.
|
||||
"\n";
|
||||
} else {
|
||||
$dashes = $out = str_pad("\n", ($this->_maxStringLength + 75), '-', STR_PAD_LEFT);
|
||||
$out .= str_pad('Section', $this->_maxStringLength + 10);
|
||||
$out .= str_pad("Total Ex Time", 22);
|
||||
$out .= str_pad("Netto Ex Time", 22);
|
||||
$out .= str_pad("#Calls", 10);
|
||||
$out .= "Percentage\n";
|
||||
$out .= $dashes;
|
||||
}
|
||||
|
||||
foreach($informations as $name => $values) {
|
||||
$percentage = $values['percentage'];
|
||||
$calls_str = "";
|
||||
|
||||
foreach($values['calls'] as $key => $val) {
|
||||
if ($calls_str) {
|
||||
$calls_str .= ", ";
|
||||
}
|
||||
|
||||
$calls_str .= "$key ($val)";
|
||||
}
|
||||
|
||||
$callers_str = "";
|
||||
|
||||
foreach($values['callers'] as $key => $val) {
|
||||
if ($callers_str) {
|
||||
$callers_str .= ", ";
|
||||
}
|
||||
|
||||
$callers_str .= "$key ($val)";
|
||||
}
|
||||
|
||||
if ($format == 'html') {
|
||||
$out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>";
|
||||
if (is_numeric($values['percentage'])) {
|
||||
$out .= "<td align=\"right\">{$values['percentage']}%</td>\n";
|
||||
} else {
|
||||
$out .= "<td align=\"right\">{$values['percentage']}</td>\n";
|
||||
}
|
||||
$out .= "<td>$calls_str</td><td>$callers_str</td></tr>";
|
||||
} else {
|
||||
$out .= str_pad($name, $this->_maxStringLength + 10);
|
||||
$out .= str_pad($values['time'], 22);
|
||||
$out .= str_pad($values['netto_time'], 22);
|
||||
$out .= str_pad($values['num_calls'], 10);
|
||||
if (is_numeric($values['percentage'])) {
|
||||
$out .= str_pad($values['percentage']."%\n", 8, ' ', STR_PAD_LEFT);
|
||||
} else {
|
||||
$out .= str_pad($values['percentage']."\n", 8, ' ', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($format == 'html') {
|
||||
return $out . '</table>';
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted profiling information.
|
||||
*
|
||||
* @param string output format (auto, plain or html), default auto
|
||||
* @access public
|
||||
*/
|
||||
function display($format = 'auto') {
|
||||
echo $this->_getOutput($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters "Global" section.
|
||||
*
|
||||
* @see enterSection(), stop()
|
||||
* @access public
|
||||
*/
|
||||
function start() {
|
||||
$this->enterSection('Global');
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves "Global" section.
|
||||
*
|
||||
* @see leaveSection(), start()
|
||||
* @access public
|
||||
*/
|
||||
function stop() {
|
||||
$this->leaveSection('Global');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters code section.
|
||||
*
|
||||
* @param string name of the code section
|
||||
* @see start(), leaveSection()
|
||||
* @access public
|
||||
*/
|
||||
function enterSection($name) {
|
||||
if (count($this->_stack)) {
|
||||
if (isset($this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]])) {
|
||||
$this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]]++;
|
||||
} else {
|
||||
$this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) {
|
||||
$this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++;
|
||||
} else {
|
||||
$this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1;
|
||||
}
|
||||
} else {
|
||||
if ($name != 'Global') {
|
||||
$this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->_numberOfCalls[$name])) {
|
||||
$this->_numberOfCalls[$name]++;
|
||||
} else {
|
||||
$this->_numberOfCalls[$name] = 1;
|
||||
}
|
||||
|
||||
array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves code section.
|
||||
*
|
||||
* @param string name of the marker to be set
|
||||
* @see stop(), enterSection()
|
||||
* @access public
|
||||
*/
|
||||
function leaveSection($name) {
|
||||
$microtime = $this->_getMicrotime();
|
||||
|
||||
if (!count($this->_stack)) {
|
||||
$this->raiseError("tried to leave section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
|
||||
}
|
||||
|
||||
$x = array_pop($this->_stack);
|
||||
|
||||
if ($x["name"] != $name) {
|
||||
$this->raiseError("reached end of section $name but expecting end of " . $x["name"]."\n", NULL, PEAR_ERROR_DIE);
|
||||
}
|
||||
|
||||
if (isset($this->_sections[$name])) {
|
||||
$this->_sections[$name] += $microtime - $x["time"];
|
||||
} else {
|
||||
$this->_sections[$name] = $microtime - $x["time"];
|
||||
}
|
||||
|
||||
$parent = array_pop($this->_stack);
|
||||
|
||||
if (isset($parent)) {
|
||||
if (isset($this->_subSectionsTime[$parent['name']])) {
|
||||
$this->_subSectionsTime[$parent['name']] += $microtime - $x['time'];
|
||||
} else {
|
||||
$this->_subSectionsTime[$parent['name']] = $microtime - $x['time'];
|
||||
}
|
||||
|
||||
array_push($this->_stack, $parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for microtime().
|
||||
*
|
||||
* @return float
|
||||
* @access private
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function _getMicrotime() {
|
||||
$microtime = explode(' ', microtime());
|
||||
return $microtime[1] . substr($microtime[0], 1);
|
||||
}
|
||||
}
|
||||
321
thirdparty/pear/Benchmark/Timer.php
vendored
321
thirdparty/pear/Benchmark/Timer.php
vendored
@@ -1,321 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +------------------------------------------------------------------------+
|
||||
// | PEAR :: Benchmark |
|
||||
// +------------------------------------------------------------------------+
|
||||
// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
|
||||
// +------------------------------------------------------------------------+
|
||||
// | This source file is subject to the New BSD license, That is bundled |
|
||||
// | with this package in the file LICENSE, and is available through |
|
||||
// | the world-wide-web at |
|
||||
// | http://www.opensource.org/licenses/bsd-license.php |
|
||||
// | If you did not receive a copy of the new BSDlicense and are unable |
|
||||
// | to obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Timer.php,v 1.2 2007/05/24 05:23:20 anant Exp $
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Provides timing and profiling information.
|
||||
*
|
||||
* Example 1: Automatic profiling start, stop, and output.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Timer.php';
|
||||
*
|
||||
* $timer = new Benchmark_Timer(TRUE);
|
||||
* $timer->setMarker('Marker 1');
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Example 2: Manual profiling start, stop, and output.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Benchmark/Timer.php';
|
||||
*
|
||||
* $timer = new Benchmark_Timer();
|
||||
* $timer->start();
|
||||
* $timer->setMarker('Marker 1');
|
||||
* $timer->stop();
|
||||
*
|
||||
* $timer->display(); // to output html formated
|
||||
* // AND/OR :
|
||||
* $profiling = $timer->getProfiling(); // get the profiler info as an associative array
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @author Ludovico Magnocavallo <ludo@sumatrasolutions.com>
|
||||
* @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
|
||||
* @category Benchmarking
|
||||
* @package Benchmark
|
||||
*/
|
||||
class Benchmark_Timer extends PEAR {
|
||||
/**
|
||||
* Contains the markers.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $markers = array();
|
||||
|
||||
/**
|
||||
* Auto-start and stop timer.
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $auto = FALSE;
|
||||
|
||||
/**
|
||||
* Max marker name length for non-html output.
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $maxStringLength = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param boolean $auto
|
||||
* @access public
|
||||
*/
|
||||
function Benchmark_Timer($auto = FALSE) {
|
||||
$this->auto = $auto;
|
||||
|
||||
if ($this->auto) {
|
||||
$this->start();
|
||||
}
|
||||
|
||||
$this->PEAR();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close method. Stop timer and display output.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function close() {
|
||||
if ($this->auto) {
|
||||
$this->stop();
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "Start" marker.
|
||||
*
|
||||
* @see setMarker(), stop()
|
||||
* @access public
|
||||
*/
|
||||
function start() {
|
||||
$this->setMarker('Start');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "Stop" marker.
|
||||
*
|
||||
* @see setMarker(), start()
|
||||
* @access public
|
||||
*/
|
||||
function stop() {
|
||||
$this->setMarker('Stop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set marker.
|
||||
*
|
||||
* @param string $name Name of the marker to be set.
|
||||
* @see start(), stop()
|
||||
* @access public
|
||||
*/
|
||||
function setMarker($name) {
|
||||
$this->markers[$name] = $this->_getMicrotime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time elapsed betweens two markers.
|
||||
*
|
||||
* @param string $start start marker, defaults to "Start"
|
||||
* @param string $end end marker, defaults to "Stop"
|
||||
* @return double $time_elapsed time elapsed between $start and $end
|
||||
* @access public
|
||||
*/
|
||||
function timeElapsed($start = 'Start', $end = 'Stop') {
|
||||
if ($end == 'Stop' && !isset($this->markers['Stop'])) {
|
||||
$this->markers['Stop'] = $this->_getMicrotime();
|
||||
}
|
||||
$end = isset($this->markers[$end]) ? $this->markers[$end] : 0;
|
||||
$start = isset($this->markers[$start]) ? $this->markers[$start] : 0;
|
||||
|
||||
if (extension_loaded('bcmath')) {
|
||||
return bcsub($end, $start, 6);
|
||||
} else {
|
||||
return $end - $start;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns profiling information.
|
||||
*
|
||||
* $profiling[x]['name'] = name of marker x
|
||||
* $profiling[x]['time'] = time index of marker x
|
||||
* $profiling[x]['diff'] = execution time from marker x-1 to this marker x
|
||||
* $profiling[x]['total'] = total execution time up to marker x
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function getProfiling() {
|
||||
$i = $total = 0;
|
||||
$result = array();
|
||||
$temp = reset($this->markers);
|
||||
$this->maxStringLength = 0;
|
||||
|
||||
foreach ($this->markers as $marker => $time) {
|
||||
if (extension_loaded('bcmath')) {
|
||||
$diff = bcsub($time, $temp, 6);
|
||||
$total = bcadd($total, $diff, 6);
|
||||
} else {
|
||||
$diff = $time - $temp;
|
||||
$total = $total + $diff;
|
||||
}
|
||||
|
||||
$result[$i]['name'] = $marker;
|
||||
$result[$i]['time'] = $time;
|
||||
$result[$i]['diff'] = $diff;
|
||||
$result[$i]['total'] = $total;
|
||||
|
||||
$this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength);
|
||||
|
||||
$temp = $time;
|
||||
$i++;
|
||||
}
|
||||
|
||||
$result[0]['diff'] = '-';
|
||||
$result[0]['total'] = '-';
|
||||
$this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength);
|
||||
$this->maxStringLength += 2;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted profiling information.
|
||||
*
|
||||
* @param boolean $showTotal Optionnaly includes total in output, default no
|
||||
* @param string $format output format (auto, plain or html), default auto
|
||||
* @return string
|
||||
* @see getProfiling()
|
||||
* @access public
|
||||
*/
|
||||
function getOutput($showTotal = FALSE, $format = 'auto') {
|
||||
if ($format == 'auto') {
|
||||
if (function_exists('version_compare') &&
|
||||
version_compare(phpversion(), '4.1', 'ge'))
|
||||
{
|
||||
$format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
|
||||
} else {
|
||||
global $HTTP_SERVER_VARS;
|
||||
$format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
|
||||
}
|
||||
}
|
||||
|
||||
$total = $this->TimeElapsed();
|
||||
$result = $this->getProfiling();
|
||||
$dashes = '';
|
||||
|
||||
if ($format == 'html') {
|
||||
$out = '<table border="1">'."\n";
|
||||
$out .= '<tr><td> </td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'.
|
||||
($showTotal ?
|
||||
'<td align="center"><b>elapsed</b></td><td align="center"><b>%</b></td>'
|
||||
: '')."</tr>\n";
|
||||
} else {
|
||||
$dashes = $out = str_pad("\n",
|
||||
$this->maxStringLength + ($showTotal ? 70 : 45), '-', STR_PAD_LEFT);
|
||||
$out .= str_pad('marker', $this->maxStringLength) .
|
||||
str_pad("time index", 22) .
|
||||
str_pad("ex time", 16) .
|
||||
str_pad("perct ", 8) .
|
||||
($showTotal ? ' '.str_pad("elapsed", 16)."perct" : '')."\n" .
|
||||
$dashes;
|
||||
}
|
||||
|
||||
foreach ($result as $k => $v) {
|
||||
$perc = (($v['diff'] * 100) / $total);
|
||||
$tperc = (($v['total'] * 100) / $total);
|
||||
|
||||
if ($format == 'html') {
|
||||
$out .= "<tr><td><b>" . $v['name'] .
|
||||
"</b></td><td>" . $v['time'] .
|
||||
"</td><td>" . $v['diff'] .
|
||||
"</td><td align=\"right\">" . number_format($perc, 2, '.', '') .
|
||||
"%</td>".
|
||||
($showTotal ?
|
||||
"<td>" . $v['total'] .
|
||||
"</td><td align=\"right\">" .
|
||||
number_format($tperc, 2, '.', '') .
|
||||
"%</td>" : '').
|
||||
"</tr>\n";
|
||||
} else {
|
||||
$out .= str_pad($v['name'], $this->maxStringLength, ' ') .
|
||||
str_pad($v['time'], 22) .
|
||||
str_pad($v['diff'], 14) .
|
||||
str_pad(number_format($perc, 2, '.', '')."%",8, ' ', STR_PAD_LEFT) .
|
||||
($showTotal ? ' '.
|
||||
str_pad($v['total'], 14) .
|
||||
str_pad(number_format($tperc, 2, '.', '')."%",
|
||||
8, ' ', STR_PAD_LEFT) : '').
|
||||
"\n";
|
||||
}
|
||||
|
||||
$out .= $dashes;
|
||||
}
|
||||
|
||||
if ($format == 'html') {
|
||||
$out .= "<tr style='background: silver;'><td><b>total</b></td><td>-</td><td>${total}</td><td>100.00%</td>".($showTotal ? "<td>-</td><td>-</td>" : "")."</tr>\n";
|
||||
$out .= "</table>\n";
|
||||
} else {
|
||||
$out .= str_pad('total', $this->maxStringLength);
|
||||
$out .= str_pad('-', 22);
|
||||
$out .= str_pad($total, 15);
|
||||
$out .= "100.00%\n";
|
||||
$out .= $dashes;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the information returned by getOutput().
|
||||
*
|
||||
* @param boolean $showTotal Optionnaly includes total in output, default no
|
||||
* @param string $format output format (auto, plain or html), default auto
|
||||
* @see getOutput()
|
||||
* @access public
|
||||
*/
|
||||
function display($showTotal = FALSE, $format = 'auto') {
|
||||
print $this->getOutput($showTotal, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for microtime().
|
||||
*
|
||||
* @return float
|
||||
* @access private
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function _getMicrotime() {
|
||||
$microtime = explode(' ', microtime());
|
||||
return $microtime[1] . substr($microtime[0], 1);
|
||||
}
|
||||
}
|
||||
285
thirdparty/pear/CMD.php
vendored
285
thirdparty/pear/CMD.php
vendored
@@ -1,285 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Anders Johannsen <anders@johannsen.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
define('CMD_RCSID', '$Id: CMD.php,v 1.5 2002/12/31 16:18:22 sebastian Exp $');
|
||||
|
||||
/**
|
||||
* The Cmd:: class implements an abstraction for various ways
|
||||
* of executing commands (directly using the backtick operator,
|
||||
* as a background task after the script has terminated using
|
||||
* register_shutdown_function() or as a detached process using nohup).
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
* @version $Revision: 1.5 $
|
||||
**/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
|
||||
class Cmd extends PEAR
|
||||
{
|
||||
var $arrSetting = array();
|
||||
var $arrConstant = array();
|
||||
var $arrCommand = array();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Defines all necessary constants and sets defaults
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
**/
|
||||
|
||||
function Cmd ()
|
||||
{
|
||||
// Defining constants
|
||||
$this->arrConstant = array ("CMD_SEQUENCE",
|
||||
"CMD_SHUTDOWN",
|
||||
"CMD_SHELL",
|
||||
"CMD_OUTPUT",
|
||||
"CMD_NOHUP",
|
||||
"CMD_VERBOSE"
|
||||
);
|
||||
|
||||
foreach ($this->arrConstant as $key => $value) {
|
||||
if (!defined($value)) {
|
||||
define($value, $key);
|
||||
}
|
||||
}
|
||||
|
||||
// Setting default values
|
||||
$this->arrSetting[CMD_SEQUENCE] = true;
|
||||
$this->arrSetting[CMD_SHUTDOWN] = false;
|
||||
$this->arrSetting[CMD_OUTPUT] = false;
|
||||
$this->arrSetting[CMD_NOHUP] = false;
|
||||
$this->arrSetting[CMD_VERBOSE] = false;
|
||||
|
||||
$arrShell = array ("sh", "bash", "zsh", "tcsh", "csh", "ash", "sash", "esh", "ksh");
|
||||
|
||||
foreach ($arrShell as $shell) {
|
||||
if ($this->arrSetting[CMD_SHELL] = $this->which($shell)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->arrSetting[CMD_SHELL])) {
|
||||
$this->raiseError("No shell found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets any option
|
||||
*
|
||||
* The options are currently:
|
||||
* CMD_SHUTDOWN : Execute commands via a shutdown function
|
||||
* CMD_SHELL : Path to shell
|
||||
* CMD_OUTPUT : Output stdout from process
|
||||
* CMD_NOHUP : Use nohup to detach process
|
||||
* CMD_VERBOSE : Print errors to stdout
|
||||
*
|
||||
* @param $option is a constant, which corresponds to the
|
||||
* option that should be changed
|
||||
*
|
||||
* @param $setting is the value of the option currently
|
||||
* being toggled.
|
||||
*
|
||||
* @return bool true if succes, else false
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
*
|
||||
**/
|
||||
|
||||
function setOption ($option, $setting)
|
||||
{
|
||||
if (empty($this->arrConstant[$option])) {
|
||||
$this->raiseError("No such option: $option");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
switch ($option) {
|
||||
case CMD_OUTPUT:
|
||||
case CMD_SHUTDOWN:
|
||||
case CMD_VERBOSE:
|
||||
case CMD_SEQUENCE:
|
||||
$this->arrSetting[$option] = $setting;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case CMD_SHELL:
|
||||
if (is_executable($setting)) {
|
||||
$this->arrSetting[$option] = $setting;
|
||||
return true;
|
||||
} else {
|
||||
$this->raiseError("No such shell: $setting");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CMD_NOHUP:
|
||||
if (empty($setting)) {
|
||||
$this->arrSetting[$option] = false;
|
||||
|
||||
} else if ($location = $this->which("nohup")) {
|
||||
$this->arrSetting[$option] = true;
|
||||
|
||||
} else {
|
||||
$this->raiseError("Nohup was not found on your system");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add command for execution
|
||||
*
|
||||
* @param $command accepts both arrays and regular strings
|
||||
*
|
||||
* @return bool true if succes, else false
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
*
|
||||
**/
|
||||
|
||||
function command($command)
|
||||
{
|
||||
if (is_array($command)) {
|
||||
foreach ($command as $key => $value) {
|
||||
$this->arrCommand[] = $value;
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (is_string($command)) {
|
||||
$this->arrCommand[] = $command;
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->raiseError("Argument not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the code according to given options
|
||||
*
|
||||
* @return bool true if succes, else false
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
*
|
||||
**/
|
||||
|
||||
function exec()
|
||||
{
|
||||
// Warning about impossible mix of options
|
||||
if (!empty($this->arrSetting[CMD_OUTPUT])) {
|
||||
if (!empty($this->arrSetting[CMD_SHUTDOWN]) || !empty($this->arrSetting[CMD_NOHUP])) {
|
||||
$this->raiseError("Error: Commands executed via shutdown functions or nohup cannot return output");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Building command
|
||||
$strCommand = implode(";", $this->arrCommand);
|
||||
|
||||
$strExec = "echo '$strCommand' | ".$this->arrSetting[CMD_SHELL];
|
||||
|
||||
if (empty($this->arrSetting[CMD_OUTPUT])) {
|
||||
$strExec = $strExec . ' > /dev/null';
|
||||
}
|
||||
|
||||
if (!empty($this->arrSetting[CMD_NOHUP])) {
|
||||
$strExec = 'nohup ' . $strExec;
|
||||
}
|
||||
|
||||
// Executing
|
||||
if (!empty($this->arrSetting[CMD_SHUTDOWN])) {
|
||||
$line = "system(\"$strExec\");";
|
||||
$function = create_function('', $line);
|
||||
register_shutdown_function($function);
|
||||
return true;
|
||||
} else {
|
||||
return `$strExec`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Errorhandler. If option CMD_VERBOSE is true,
|
||||
* the error is printed to stdout, otherwise it
|
||||
* is avaliable in lastError
|
||||
*
|
||||
* @return bool always returns true
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
**/
|
||||
|
||||
function raiseError($strError)
|
||||
{
|
||||
if (!empty($this->arrSetting[CMD_VERBOSE])) {
|
||||
echo $strError;
|
||||
} else {
|
||||
$this->lastError = $strError;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Functionality similiar to unix 'which'. Searches the path
|
||||
* for the specified program.
|
||||
*
|
||||
* @param $cmd name of the executable to search for
|
||||
*
|
||||
* @return string returns the full path if found,
|
||||
* false if not
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @author Anders Johannsen <anders@johannsen.com>
|
||||
**/
|
||||
|
||||
function which($cmd)
|
||||
{
|
||||
global $HTTP_ENV_VARS;
|
||||
|
||||
$arrPath = explode(":", $HTTP_ENV_VARS['PATH']);
|
||||
|
||||
foreach ($arrPath as $path) {
|
||||
$location = $path . "/" . $cmd;
|
||||
|
||||
if (is_executable($location)) {
|
||||
return $location;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
8
thirdparty/pear/CODING_STANDARDS
vendored
8
thirdparty/pear/CODING_STANDARDS
vendored
@@ -1,8 +0,0 @@
|
||||
===========================================================================
|
||||
|| PEAR Coding Standards ||
|
||||
===========================================================================
|
||||
|
||||
$Id: CODING_STANDARDS,v 1.14 2002/01/24 15:02:05 cox Exp $
|
||||
|
||||
This document is no longer maintained, see
|
||||
http://pear.php.net/manual/ instead.
|
||||
251
thirdparty/pear/Console/Getopt.php
vendored
251
thirdparty/pear/Console/Getopt.php
vendored
@@ -1,251 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at the following url: |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Andrei Zmievski <andrei@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Getopt.php 6820 2007-06-20 13:35:30Z kevin_fourie $
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Command-line options parsing class.
|
||||
*
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
*
|
||||
*/
|
||||
class Console_Getopt {
|
||||
/**
|
||||
* Parses the command-line options.
|
||||
*
|
||||
* The first parameter to this function should be the list of command-line
|
||||
* arguments without the leading reference to the running program.
|
||||
*
|
||||
* The second parameter is a string of allowed short options. Each of the
|
||||
* option letters can be followed by a colon ':' to specify that the option
|
||||
* requires an argument, or a double colon '::' to specify that the option
|
||||
* takes an optional argument.
|
||||
*
|
||||
* The third argument is an optional array of allowed long options. The
|
||||
* leading '--' should not be included in the option name. Options that
|
||||
* require an argument should be followed by '=', and options that take an
|
||||
* option argument should be followed by '=='.
|
||||
*
|
||||
* The return value is an array of two elements: the list of parsed
|
||||
* options and the list of non-option command-line arguments. Each entry in
|
||||
* the list of parsed options is a pair of elements - the first one
|
||||
* specifies the option, and the second one specifies the option argument,
|
||||
* if there was one.
|
||||
*
|
||||
* Long and short options can be mixed.
|
||||
*
|
||||
* Most of the semantics of this function are based on GNU getopt_long().
|
||||
*
|
||||
* @param array $args an array of command-line arguments
|
||||
* @param string $short_options specifies the list of allowed short options
|
||||
* @param array $long_options specifies the list of allowed long options
|
||||
*
|
||||
* @return array two-element array containing the list of parsed options and
|
||||
* the non-option arguments
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
public static function getopt2($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function expects $args to start with the script name (POSIX-style).
|
||||
* Preserved for backwards compatibility.
|
||||
* @see getopt2()
|
||||
*/
|
||||
function getopt($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual implementation of the argument parsing code.
|
||||
*/
|
||||
public static function doGetopt($version, $args, $short_options, $long_options = null)
|
||||
{
|
||||
// in case you pass directly readPHPArgv() as the first arg
|
||||
if (PEAR::isError($args)) {
|
||||
return $args;
|
||||
}
|
||||
if (empty($args)) {
|
||||
return array(array(), array());
|
||||
}
|
||||
$opts = array();
|
||||
$non_opts = array();
|
||||
|
||||
settype($args, 'array');
|
||||
|
||||
if ($long_options) {
|
||||
sort($long_options);
|
||||
}
|
||||
|
||||
/*
|
||||
* Preserve backwards compatibility with callers that relied on
|
||||
* erroneous POSIX fix.
|
||||
*/
|
||||
if ($version < 2) {
|
||||
if (isset($args[0]{0}) && $args[0]{0} != '-') {
|
||||
array_shift($args);
|
||||
}
|
||||
}
|
||||
|
||||
reset($args);
|
||||
while (list($i, $arg) = each($args)) {
|
||||
|
||||
/* The special element '--' means explicit end of
|
||||
options. Treat the rest of the arguments as non-options
|
||||
and end the loop. */
|
||||
if ($arg == '--') {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
|
||||
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
} else {
|
||||
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
||||
return array($opts, $non_opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
public static function _parseShortOption($arg, $short_options, &$opts, &$args)
|
||||
{
|
||||
for ($i = 0; $i < strlen($arg); $i++) {
|
||||
$opt = $arg{$i};
|
||||
$opt_arg = null;
|
||||
|
||||
/* Try to find the short option in the specifier string. */
|
||||
if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
|
||||
{
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
|
||||
}
|
||||
|
||||
if (strlen($spec) > 1 && $spec{1} == ':') {
|
||||
if (strlen($spec) > 2 && $spec{2} == ':') {
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
/* Option takes an optional argument. Use the remainder of
|
||||
the arg string if there is anything left. */
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Option requires an argument. Use the remainder of the arg
|
||||
string if there is anything left. */
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
} else if (list(, $opt_arg) = each($args))
|
||||
/* Else use the next argument. */;
|
||||
else
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
}
|
||||
|
||||
$opts[] = array($opt, $opt_arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseLongOption($arg, $long_options, &$opts, &$args)
|
||||
{
|
||||
@list($opt, $opt_arg) = explode('=', $arg);
|
||||
$opt_len = strlen($opt);
|
||||
|
||||
for ($i = 0; $i < count($long_options); $i++) {
|
||||
$long_opt = $long_options[$i];
|
||||
$opt_start = substr($long_opt, 0, $opt_len);
|
||||
|
||||
/* Option doesn't match. Go on to the next one. */
|
||||
if ($opt_start != $opt)
|
||||
continue;
|
||||
|
||||
$opt_rest = substr($long_opt, $opt_len);
|
||||
|
||||
/* Check that the options uniquely matches one of the allowed
|
||||
options. */
|
||||
if ($opt_rest != '' && $opt{0} != '=' &&
|
||||
$i + 1 < count($long_options) &&
|
||||
$opt == substr($long_options[$i+1], 0, $opt_len)) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
|
||||
}
|
||||
|
||||
if (substr($long_opt, -1) == '=') {
|
||||
if (substr($long_opt, -2) != '==') {
|
||||
/* Long option requires an argument.
|
||||
Take the next argument if one wasn't specified. */;
|
||||
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
|
||||
}
|
||||
}
|
||||
} else if ($opt_arg) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
|
||||
}
|
||||
|
||||
$opts[] = array('--' . $opt, $opt_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely read the $argv PHP array across different PHP configurations.
|
||||
* Will take care on register_globals and register_argc_argv ini directives
|
||||
*
|
||||
* @access public
|
||||
* @return mixed the $argv PHP array or PEAR error if not registered
|
||||
*/
|
||||
function readPHPArgv()
|
||||
{
|
||||
global $argv;
|
||||
if (!is_array($argv)) {
|
||||
if (!@is_array($_SERVER['argv'])) {
|
||||
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
|
||||
return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
|
||||
}
|
||||
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
|
||||
}
|
||||
return $_SERVER['argv'];
|
||||
}
|
||||
return $argv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
225
thirdparty/pear/DB/dbase.php
vendored
225
thirdparty/pear/DB/dbase.php
vendored
@@ -1,225 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: dbase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// XXX legend:
|
||||
// You have to compile your PHP with the --enable-dbase option
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's dbase
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: dbase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
*/
|
||||
class DB_dbase extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $res_row = array();
|
||||
var $result = 0;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* DB_mysql constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function DB_dbase()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'dbase';
|
||||
$this->dbsyntax = 'dbase';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => false,
|
||||
'transactions' => false,
|
||||
'limit' => false
|
||||
);
|
||||
$this->errorcode_map = array();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('dbase')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
$this->dsn = $dsninfo;
|
||||
|
||||
$ini = ini_get('track_errors');
|
||||
if ($ini) {
|
||||
$conn = @dbase_open($dsninfo['database'], 0);
|
||||
} else {
|
||||
ini_set('track_errors', 1);
|
||||
$conn = @dbase_open($dsninfo['database'], 0);
|
||||
ini_set('track_errors', $ini);
|
||||
}
|
||||
if (!$conn) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
|
||||
null, null, strip_tags($php_errormsg));
|
||||
}
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @dbase_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &query()
|
||||
|
||||
function &query($query = null)
|
||||
{
|
||||
// emulate result resources
|
||||
$this->res_row[(int)$this->result] = 0;
|
||||
$tmp =& new DB_result($this, $this->result++);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum === null) {
|
||||
$rownum = $this->res_row[(int)$result]++;
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @dbase_get_record_with_names($this->connection, $rownum);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @dbase_get_record($this->connection, $rownum);
|
||||
}
|
||||
if (!$arr) {
|
||||
return null;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
function numCols($foo)
|
||||
{
|
||||
return @dbase_numfields($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
function numRows($foo)
|
||||
{
|
||||
return @dbase_numrecords($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteSmart()
|
||||
|
||||
/**
|
||||
* Format input so it can be safely used in a query
|
||||
*
|
||||
* @param mixed $in data to be quoted
|
||||
*
|
||||
* @return mixed Submitted variable's type = returned value:
|
||||
* + null = the string <samp>NULL</samp>
|
||||
* + boolean = <samp>T</samp> if true or
|
||||
* <samp>F</samp> if false. Use the <kbd>Logical</kbd>
|
||||
* data type.
|
||||
* + integer or double = the unquoted number
|
||||
* + other (including strings and numeric strings) =
|
||||
* the data with single quotes escaped by preceeding
|
||||
* single quotes then the whole string is encapsulated
|
||||
* between single quotes
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function quoteSmart($in)
|
||||
{
|
||||
if (is_int($in) || is_double($in)) {
|
||||
return $in;
|
||||
} elseif (is_bool($in)) {
|
||||
return $in ? 'T' : 'F';
|
||||
} elseif (is_null($in)) {
|
||||
return 'NULL';
|
||||
} else {
|
||||
return "'" . $this->escapeSimple($in) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
655
thirdparty/pear/DB/fbsql.php
vendored
655
thirdparty/pear/DB/fbsql.php
vendored
@@ -1,655 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Frank M. Kromann <frank@frontbase.com> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: fbsql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// XXX legend:
|
||||
//
|
||||
// XXX ERRORMSG: The error message from the fbsql function should
|
||||
// be registered here.
|
||||
//
|
||||
// TODO/wishlist:
|
||||
// longReadlen
|
||||
// binmode
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's FrontBase
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: fbsql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Frank M. Kromann <frank@frontbase.com>
|
||||
*/
|
||||
class DB_fbsql extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $num_rows = array();
|
||||
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* DB_fbsql constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function DB_fbsql()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'fbsql';
|
||||
$this->dbsyntax = 'fbsql';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => true,
|
||||
'limit' => 'emulate'
|
||||
);
|
||||
$this->errorcode_map = array(
|
||||
1004 => DB_ERROR_CANNOT_CREATE,
|
||||
1005 => DB_ERROR_CANNOT_CREATE,
|
||||
1006 => DB_ERROR_CANNOT_CREATE,
|
||||
1007 => DB_ERROR_ALREADY_EXISTS,
|
||||
1008 => DB_ERROR_CANNOT_DROP,
|
||||
1046 => DB_ERROR_NODBSELECTED,
|
||||
1050 => DB_ERROR_ALREADY_EXISTS,
|
||||
1051 => DB_ERROR_NOSUCHTABLE,
|
||||
1054 => DB_ERROR_NOSUCHFIELD,
|
||||
1062 => DB_ERROR_ALREADY_EXISTS,
|
||||
1064 => DB_ERROR_SYNTAX,
|
||||
1100 => DB_ERROR_NOT_LOCKED,
|
||||
1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
1146 => DB_ERROR_NOSUCHTABLE,
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $persistent (optional) whether the connection should
|
||||
* be persistent
|
||||
* @access public
|
||||
* @return int DB_OK on success, a DB error on failure
|
||||
*/
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('fbsql')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
|
||||
$php_errormsg = '';
|
||||
$connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect';
|
||||
|
||||
if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username'],
|
||||
$dsninfo['password']);
|
||||
} elseif ($dbhost && $dsninfo['username']) {
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username']);
|
||||
} elseif ($dbhost) {
|
||||
$conn = @$connect_function($dbhost);
|
||||
} else {
|
||||
$conn = false;
|
||||
}
|
||||
if (!$conn) {
|
||||
if (empty($php_errormsg)) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED);
|
||||
} else {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
|
||||
null, $php_errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!fbsql_select_db($dsninfo['database'], $conn)) {
|
||||
return $this->fbsqlRaiseError();
|
||||
}
|
||||
}
|
||||
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Log out and disconnect from the database.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if not connected.
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @fbsql_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Send a query to fbsql and return the results as a fbsql resource
|
||||
* identifier.
|
||||
*
|
||||
* @param the SQL query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return mixed returns a valid fbsql result for successful SELECT
|
||||
* queries, DB_OK for other successful queries. A DB error is
|
||||
* returned on failure.
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$this->last_query = $query;
|
||||
$query = $this->modifyQuery($query);
|
||||
$result = @fbsql_query("$query;", $this->connection);
|
||||
if (!$result) {
|
||||
return $this->fbsqlRaiseError();
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
if (DB::isManip($query)) {
|
||||
return DB_OK;
|
||||
}
|
||||
$numrows = $this->numrows($result);
|
||||
if (is_object($numrows)) {
|
||||
return $numrows;
|
||||
}
|
||||
$this->num_rows[(int)$result] = $numrows;
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal fbsql result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return @fbsql_next_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@fbsql_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @fbsql_fetch_array($result, FBSQL_ASSOC);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @fbsql_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
$errno = @fbsql_errno($this->connection);
|
||||
if (!$errno) {
|
||||
return null;
|
||||
}
|
||||
return $this->fbsqlRaiseError($errno);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with $result.
|
||||
*
|
||||
* @param $result fbsql result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
return @fbsql_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
function autoCommit($onoff=false)
|
||||
{
|
||||
if ($onoff) {
|
||||
$this->query("SET COMMIT TRUE");
|
||||
} else {
|
||||
$this->query("SET COMMIT FALSE");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
function commit()
|
||||
{
|
||||
@fbsql_commit();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
function rollback()
|
||||
{
|
||||
@fbsql_rollback();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Get the number of columns in a result set.
|
||||
*
|
||||
* @param $result fbsql result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of columns per row in $result
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @fbsql_num_fields($result);
|
||||
|
||||
if (!$cols) {
|
||||
return $this->fbsqlRaiseError();
|
||||
}
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Get the number of rows in a result set.
|
||||
*
|
||||
* @param $result fbsql result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of rows in $result
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @fbsql_num_rows($result);
|
||||
if ($rows === null) {
|
||||
return $this->fbsqlRaiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query. For other queries, this function returns 0.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (DB::isManip($this->last_query)) {
|
||||
$result = @fbsql_affected_rows($this->connection);
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Get the native error code of the last error (if any) that
|
||||
* occured on the current connection.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int native fbsql error code
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
return @fbsql_errno($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$repeat = 0;
|
||||
do {
|
||||
$result = $this->query("INSERT INTO ${seqname} (id) VALUES (NULL)");
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||
$repeat = 1;
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
$repeat = 0;
|
||||
}
|
||||
} while ($repeat);
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
return @fbsql_insert_id($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object is returned if
|
||||
* problems arise.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::createSequence()
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("CREATE TABLE ${seqname} ".
|
||||
'(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
|
||||
' PRIMARY KEY(id))');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. DB_Error if problems.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::dropSequence()
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("DROP TABLE ${seqname} RESTRICT");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyQuery()
|
||||
|
||||
function modifyQuery($query)
|
||||
{
|
||||
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
||||
// "DELETE FROM table" gives 0 affected rows in fbsql.
|
||||
// This little hack lets you know how many rows were deleted.
|
||||
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
||||
$query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
||||
'DELETE FROM \1 WHERE 1=1', $query);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteSmart()
|
||||
|
||||
/**
|
||||
* Format input so it can be safely used in a query
|
||||
*
|
||||
* @param mixed $in data to be quoted
|
||||
*
|
||||
* @return mixed Submitted variable's type = returned value:
|
||||
* + null = the string <samp>NULL</samp>
|
||||
* + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
|
||||
* + integer or double = the unquoted number
|
||||
* + other (including strings and numeric strings) =
|
||||
* the data escaped according to MySQL's settings
|
||||
* then encapsulated between single quotes
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function quoteSmart($in)
|
||||
{
|
||||
if (is_int($in) || is_double($in)) {
|
||||
return $in;
|
||||
} elseif (is_bool($in)) {
|
||||
return $in ? 'TRUE' : 'FALSE';
|
||||
} elseif (is_null($in)) {
|
||||
return 'NULL';
|
||||
} else {
|
||||
return "'" . $this->escapeSimple($in) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fbsqlRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see DB_common::errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function fbsqlRaiseError($errno = null)
|
||||
{
|
||||
if ($errno === null) {
|
||||
$errno = $this->errorCode(fbsql_errno($this->connection));
|
||||
}
|
||||
return $this->raiseError($errno, null, null, null,
|
||||
@fbsql_error($this->connection));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null) {
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
$id = @fbsql_list_fields($this->dsn['database'],
|
||||
$result, $this->connection);
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->fbsqlRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @fbsql_num_fields($id);
|
||||
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $case_func(@fbsql_field_table($id, $i));
|
||||
$res[$i]['name'] = $case_func(@fbsql_field_name($id, $i));
|
||||
$res[$i]['type'] = @fbsql_field_type($id, $i);
|
||||
$res[$i]['len'] = @fbsql_field_len($id, $i);
|
||||
$res[$i]['flags'] = @fbsql_field_flags($id, $i);
|
||||
}
|
||||
} else { // full
|
||||
$res["num_fields"]= $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $case_func(@fbsql_field_table($id, $i));
|
||||
$res[$i]['name'] = $case_func(@fbsql_field_name($id, $i));
|
||||
$res[$i]['type'] = @fbsql_field_type($id, $i);
|
||||
$res[$i]['len'] = @fbsql_field_len($id, $i);
|
||||
$res[$i]['flags'] = @fbsql_field_flags($id, $i);
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@fbsql_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return 'select "table_name" from information_schema.tables';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
784
thirdparty/pear/DB/ibase.php
vendored
784
thirdparty/pear/DB/ibase.php
vendored
@@ -1,784 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Sterling Hughes <sterling@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ibase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// Bugs:
|
||||
// - If dbsyntax is not firebird, the limitQuery may fail
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's Interbase
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: ibase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
*/
|
||||
class DB_ibase extends DB_common
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $autocommit = 1;
|
||||
var $manip_query = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
function DB_ibase()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'ibase';
|
||||
$this->dbsyntax = 'ibase';
|
||||
$this->features = array(
|
||||
'prepare' => true,
|
||||
'pconnect' => true,
|
||||
'transactions' => true,
|
||||
'limit' => false
|
||||
);
|
||||
// just a few of the tons of Interbase error codes listed in the
|
||||
// Language Reference section of the Interbase manual
|
||||
$this->errorcode_map = array(
|
||||
-104 => DB_ERROR_SYNTAX,
|
||||
-150 => DB_ERROR_ACCESS_VIOLATION,
|
||||
-151 => DB_ERROR_ACCESS_VIOLATION,
|
||||
-155 => DB_ERROR_NOSUCHTABLE,
|
||||
88 => DB_ERROR_NOSUCHTABLE,
|
||||
-157 => DB_ERROR_NOSUCHFIELD,
|
||||
-158 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
-170 => DB_ERROR_MISMATCH,
|
||||
-171 => DB_ERROR_MISMATCH,
|
||||
-172 => DB_ERROR_INVALID,
|
||||
-204 => DB_ERROR_INVALID,
|
||||
-205 => DB_ERROR_NOSUCHFIELD,
|
||||
-206 => DB_ERROR_NOSUCHFIELD,
|
||||
-208 => DB_ERROR_INVALID,
|
||||
-219 => DB_ERROR_NOSUCHTABLE,
|
||||
-297 => DB_ERROR_CONSTRAINT,
|
||||
-530 => DB_ERROR_CONSTRAINT,
|
||||
-607 => DB_ERROR_NOSUCHTABLE,
|
||||
-803 => DB_ERROR_CONSTRAINT,
|
||||
-551 => DB_ERROR_ACCESS_VIOLATION,
|
||||
-552 => DB_ERROR_ACCESS_VIOLATION,
|
||||
-922 => DB_ERROR_NOSUCHDB,
|
||||
-923 => DB_ERROR_CONNECT_FAILED,
|
||||
-924 => DB_ERROR_CONNECT_FAILED
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('interbase')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
$this->dsn = $dsninfo;
|
||||
$dbhost = $dsninfo['hostspec'] ?
|
||||
($dsninfo['hostspec'] . ':' . $dsninfo['database']) :
|
||||
$dsninfo['database'];
|
||||
|
||||
$connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
|
||||
|
||||
$params = array();
|
||||
$params[] = $dbhost;
|
||||
$params[] = $dsninfo['username'] ? $dsninfo['username'] : null;
|
||||
$params[] = $dsninfo['password'] ? $dsninfo['password'] : null;
|
||||
$params[] = isset($dsninfo['charset']) ? $dsninfo['charset'] : null;
|
||||
$params[] = isset($dsninfo['buffers']) ? $dsninfo['buffers'] : null;
|
||||
$params[] = isset($dsninfo['dialect']) ? $dsninfo['dialect'] : null;
|
||||
$params[] = isset($dsninfo['role']) ? $dsninfo['role'] : null;
|
||||
|
||||
$conn = @call_user_func_array($connect_function, $params);
|
||||
if (!$conn) {
|
||||
return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED);
|
||||
}
|
||||
$this->connection = $conn;
|
||||
if ($this->dsn['dbsyntax'] == 'firebird') {
|
||||
$this->features['limit'] = 'alter';
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @ibase_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
$query = $this->modifyQuery($query);
|
||||
$result = @ibase_query($this->connection, $query);
|
||||
if (!$result) {
|
||||
return $this->ibaseRaiseError();
|
||||
}
|
||||
if ($this->autocommit && $ismanip) {
|
||||
@ibase_commit($this->connection);
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
return $ismanip ? DB_OK : $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyLimitQuery()
|
||||
|
||||
/**
|
||||
* This method is used by backends to alter limited queries
|
||||
* Uses the new FIRST n SKIP n Firebird 1.0 syntax, so it is
|
||||
* only compatible with Firebird 1.x
|
||||
*
|
||||
* @param string $query query to modify
|
||||
* @param integer $from the row to start to fetching
|
||||
* @param integer $count the numbers of rows to fetch
|
||||
*
|
||||
* @return the new (modified) query
|
||||
* @author Ludovico Magnocavallo <ludo@sumatrasolutions.com>
|
||||
* @access private
|
||||
*/
|
||||
function modifyLimitQuery($query, $from, $count, $params = array())
|
||||
{
|
||||
if ($this->dsn['dbsyntax'] == 'firebird') {
|
||||
//$from++; // SKIP starts from 1, ie SKIP 1 starts from the first record
|
||||
// (cox) Seems that SKIP starts in 0
|
||||
$query = preg_replace('/^\s*select\s(.*)$/is',
|
||||
"SELECT FIRST $count SKIP $from $1", $query);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal ibase result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
return $this->ibaseRaiseError(DB_ERROR_NOT_CAPABLE);
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
if (function_exists('ibase_fetch_assoc')) {
|
||||
$arr = @ibase_fetch_assoc($result);
|
||||
} else {
|
||||
$arr = get_object_vars(ibase_fetch_object($result));
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @ibase_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
if ($errmsg = @ibase_errmsg()) {
|
||||
return $this->ibaseRaiseError(null, $errmsg);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
function freeResult($result)
|
||||
{
|
||||
return @ibase_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeQuery()
|
||||
|
||||
function freeQuery($query)
|
||||
{
|
||||
@ibase_free_query($query);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @ibase_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->ibaseRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ prepare()
|
||||
|
||||
/**
|
||||
* Prepares a query for multiple execution with execute().
|
||||
*
|
||||
* prepare() requires a generic query as string like <code>
|
||||
* INSERT INTO numbers VALUES (?, ?, ?)
|
||||
* </code>. The <kbd>?</kbd> characters are placeholders.
|
||||
*
|
||||
* Three types of placeholders can be used:
|
||||
* + <kbd>?</kbd> a quoted scalar value, i.e. strings, integers
|
||||
* + <kbd>!</kbd> value is inserted 'as is'
|
||||
* + <kbd>&</kbd> requires a file name. The file's contents get
|
||||
* inserted into the query (i.e. saving binary
|
||||
* data in a db)
|
||||
*
|
||||
* Use backslashes to escape placeholder characters if you don't want
|
||||
* them to be interpreted as placeholders. Example: <code>
|
||||
* "UPDATE foo SET col=? WHERE col='over \& under'"
|
||||
* </code>
|
||||
*
|
||||
* @param string $query query to be prepared
|
||||
* @return mixed DB statement resource on success. DB_Error on failure.
|
||||
*/
|
||||
function prepare($query)
|
||||
{
|
||||
$tokens = preg_split('/((?<!\\\)[&?!])/', $query, -1,
|
||||
PREG_SPLIT_DELIM_CAPTURE);
|
||||
$token = 0;
|
||||
$types = array();
|
||||
$newquery = '';
|
||||
|
||||
foreach ($tokens as $key => $val) {
|
||||
switch ($val) {
|
||||
case '?':
|
||||
$types[$token++] = DB_PARAM_SCALAR;
|
||||
break;
|
||||
case '&':
|
||||
$types[$token++] = DB_PARAM_OPAQUE;
|
||||
break;
|
||||
case '!':
|
||||
$types[$token++] = DB_PARAM_MISC;
|
||||
break;
|
||||
default:
|
||||
$tokens[$key] = preg_replace('/\\\([&?!])/', "\\1", $val);
|
||||
$newquery .= $tokens[$key] . '?';
|
||||
}
|
||||
}
|
||||
|
||||
$newquery = substr($newquery, 0, -1);
|
||||
$this->last_query = $query;
|
||||
$newquery = $this->modifyQuery($newquery);
|
||||
$stmt = @ibase_prepare($this->connection, $newquery);
|
||||
$this->prepare_types[(int)$stmt] = $types;
|
||||
$this->manip_query[(int)$stmt] = DB::isManip($query);
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ execute()
|
||||
|
||||
/**
|
||||
* Executes a DB statement prepared with prepare().
|
||||
*
|
||||
* @param resource $stmt a DB statement resource returned from prepare()
|
||||
* @param mixed $data array, string or numeric data to be used in
|
||||
* execution of the statement. Quantity of items
|
||||
* passed must match quantity of placeholders in
|
||||
* query: meaning 1 for non-array items or the
|
||||
* quantity of elements in the array.
|
||||
* @return object a new DB_Result or a DB_Error when fail
|
||||
* @see DB_ibase::prepare()
|
||||
* @access public
|
||||
*/
|
||||
function &execute($stmt, $data = array())
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
$data = array($data);
|
||||
}
|
||||
|
||||
$types =& $this->prepare_types[(int)$stmt];
|
||||
if (count($types) != count($data)) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_MISMATCH);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($data as $key => $value) {
|
||||
if ($types[$i] == DB_PARAM_MISC) {
|
||||
/*
|
||||
* ibase doesn't seem to have the ability to pass a
|
||||
* parameter along unchanged, so strip off quotes from start
|
||||
* and end, plus turn two single quotes to one single quote,
|
||||
* in order to avoid the quotes getting escaped by
|
||||
* ibase and ending up in the database.
|
||||
*/
|
||||
$data[$key] = preg_replace("/^'(.*)'$/", "\\1", $data[$key]);
|
||||
$data[$key] = str_replace("''", "'", $data[$key]);
|
||||
} elseif ($types[$i] == DB_PARAM_OPAQUE) {
|
||||
$fp = @fopen($data[$key], 'rb');
|
||||
if (!$fp) {
|
||||
$tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
return $tmp;
|
||||
}
|
||||
$data[$key] = fread($fp, filesize($data[$key]));
|
||||
fclose($fp);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
array_unshift($data, $stmt);
|
||||
|
||||
$res = call_user_func_array('ibase_execute', $data);
|
||||
if (!$res) {
|
||||
$tmp =& $this->ibaseRaiseError();
|
||||
return $tmp;
|
||||
}
|
||||
/* XXX need this?
|
||||
if ($this->autocommit && $this->manip_query[(int)$stmt]) {
|
||||
@ibase_commit($this->connection);
|
||||
}*/
|
||||
if ($this->manip_query[(int)$stmt]) {
|
||||
$tmp = DB_OK;
|
||||
} else {
|
||||
$tmp =& new DB_result($this, $res);
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with a prepared query.
|
||||
*
|
||||
* @param $stmt The interbase_query resource type
|
||||
*
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freePrepared($stmt)
|
||||
{
|
||||
if (!is_resource($stmt)) {
|
||||
return false;
|
||||
}
|
||||
@ibase_free_query($stmt);
|
||||
unset($this->prepare_tokens[(int)$stmt]);
|
||||
unset($this->prepare_types[(int)$stmt]);
|
||||
unset($this->manip_query[(int)$stmt]);
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
$this->autocommit = $onoff ? 1 : 0;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
function commit()
|
||||
{
|
||||
return @ibase_commit($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
function rollback()
|
||||
{
|
||||
return @ibase_rollback($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ transactionInit()
|
||||
|
||||
function transactionInit($trans_args = 0)
|
||||
{
|
||||
return $trans_args ? @ibase_trans($trans_args, $this->connection) : @ibase_trans();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$sqn = strtoupper($this->getSequenceName($seq_name));
|
||||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
|
||||
. 'FROM RDB$GENERATORS '
|
||||
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result)) {
|
||||
$repeat = 1;
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
$repeat = 0;
|
||||
}
|
||||
} while ($repeat);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$arr = $result->fetchRow(DB_FETCHMODE_ORDERED);
|
||||
$result->free();
|
||||
return $arr[0];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ createSequence()
|
||||
|
||||
/**
|
||||
* Create the sequence
|
||||
*
|
||||
* @param string $seq_name the name of the sequence
|
||||
* @return mixed DB_OK on success or DB error on error
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$sqn = strtoupper($this->getSequenceName($seq_name));
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("CREATE GENERATOR ${sqn}");
|
||||
$this->popErrorHandling();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Drop a sequence
|
||||
*
|
||||
* @param string $seq_name the name of the sequence
|
||||
* @return mixed DB_OK on success or DB error on error
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
$sqn = strtoupper($this->getSequenceName($seq_name));
|
||||
return $this->query('DELETE FROM RDB$GENERATORS '
|
||||
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _ibaseFieldFlags()
|
||||
|
||||
/**
|
||||
* get the Flags of a Field
|
||||
*
|
||||
* @param string $field_name the name of the field
|
||||
* @param string $table_name the name of the table
|
||||
*
|
||||
* @return string The flags of the field ("primary_key", "unique_key", "not_null"
|
||||
* "default", "computed" and "blob" are supported)
|
||||
* @access private
|
||||
*/
|
||||
function _ibaseFieldFlags($field_name, $table_name)
|
||||
{
|
||||
$sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
|
||||
.' FROM RDB$INDEX_SEGMENTS I'
|
||||
.' JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
|
||||
.' WHERE I.RDB$FIELD_NAME=\'' . $field_name . '\''
|
||||
.' AND UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\'';
|
||||
|
||||
$result = @ibase_query($this->connection, $sql);
|
||||
if (!$result) {
|
||||
return $this->ibaseRaiseError();
|
||||
}
|
||||
|
||||
$flags = '';
|
||||
if ($obj = @ibase_fetch_object($result)) {
|
||||
@ibase_free_result($result);
|
||||
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'PRIMARY KEY') {
|
||||
$flags .= 'primary_key ';
|
||||
}
|
||||
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'UNIQUE') {
|
||||
$flags .= 'unique_key ';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
|
||||
.' R.RDB$DEFAULT_SOURCE AS DSOURCE,'
|
||||
.' F.RDB$FIELD_TYPE AS FTYPE,'
|
||||
.' F.RDB$COMPUTED_SOURCE AS CSOURCE'
|
||||
.' FROM RDB$RELATION_FIELDS R '
|
||||
.' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
|
||||
.' WHERE UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\''
|
||||
.' AND R.RDB$FIELD_NAME=\'' . $field_name . '\'';
|
||||
|
||||
$result = @ibase_query($this->connection, $sql);
|
||||
if (!$result) {
|
||||
return $this->ibaseRaiseError();
|
||||
}
|
||||
if ($obj = @ibase_fetch_object($result)) {
|
||||
@ibase_free_result($result);
|
||||
if (isset($obj->NFLAG)) {
|
||||
$flags .= 'not_null ';
|
||||
}
|
||||
if (isset($obj->DSOURCE)) {
|
||||
$flags .= 'default ';
|
||||
}
|
||||
if (isset($obj->CSOURCE)) {
|
||||
$flags .= 'computed ';
|
||||
}
|
||||
if (isset($obj->FTYPE) && $obj->FTYPE == 261) {
|
||||
$flags .= 'blob ';
|
||||
}
|
||||
}
|
||||
|
||||
return trim($flags);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||
* is a table name.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
$id = @ibase_query($this->connection,
|
||||
"SELECT * FROM $result WHERE 1=0");
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->ibaseRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @ibase_num_fields($id);
|
||||
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$info = @ibase_field_info($id, $i);
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func($info['name']);
|
||||
$res[$i]['type'] = $info['type'];
|
||||
$res[$i]['len'] = $info['length'];
|
||||
$res[$i]['flags'] = ($got_string) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
|
||||
}
|
||||
} else { // full
|
||||
$res['num_fields']= $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$info = @ibase_field_info($id, $i);
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func($info['name']);
|
||||
$res[$i]['type'] = $info['type'];
|
||||
$res[$i]['len'] = $info['length'];
|
||||
$res[$i]['flags'] = ($got_string) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@ibase_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ ibaseRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $db_errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @param string $native_errmsg text of error message if known
|
||||
* @return object DB error object
|
||||
* @see DB_common::errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function &ibaseRaiseError($db_errno = null, $native_errmsg = null)
|
||||
{
|
||||
if ($native_errmsg === null) {
|
||||
$native_errmsg = @ibase_errmsg();
|
||||
}
|
||||
// memo for the interbase php module hackers: we need something similar
|
||||
// to mysql_errno() to retrieve error codes instead of this ugly hack
|
||||
if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_errmsg, $m)) {
|
||||
$native_errno = (int)$m[2];
|
||||
} else {
|
||||
$native_errno = null;
|
||||
}
|
||||
// try to map the native error to the DB one
|
||||
if ($db_errno === null) {
|
||||
if ($native_errno) {
|
||||
// try to interpret Interbase error code (that's why we need ibase_errno()
|
||||
// in the interbase module to return the real error code)
|
||||
switch ($native_errno) {
|
||||
case -204:
|
||||
if (is_int(strpos($m[3], 'Table unknown'))) {
|
||||
$db_errno = DB_ERROR_NOSUCHTABLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$db_errno = $this->errorCode($native_errno);
|
||||
}
|
||||
} else {
|
||||
$error_regexps = array(
|
||||
'/[tT]able not found/' => DB_ERROR_NOSUCHTABLE,
|
||||
'/[tT]able .* already exists/' => DB_ERROR_ALREADY_EXISTS,
|
||||
'/validation error for column .* value "\*\*\* null/' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'/violation of [\w ]+ constraint/' => DB_ERROR_CONSTRAINT,
|
||||
'/conversion error from string/' => DB_ERROR_INVALID_NUMBER,
|
||||
'/no permission for/' => DB_ERROR_ACCESS_VIOLATION,
|
||||
'/arithmetic exception, numeric overflow, or string truncation/' => DB_ERROR_DIVZERO
|
||||
);
|
||||
foreach ($error_regexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $native_errmsg)) {
|
||||
$db_errno = $code;
|
||||
$native_errno = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tmp =& $this->raiseError($db_errno, null, null, null, $native_errmsg);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
579
thirdparty/pear/DB/ifx.php
vendored
579
thirdparty/pear/DB/ifx.php
vendored
@@ -1,579 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: ifx.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// Legend:
|
||||
// For more info on Informix errors see:
|
||||
// http://www.informix.com/answers/english/ierrors.htm
|
||||
//
|
||||
// TODO:
|
||||
// - set needed env Informix vars on connect
|
||||
// - implement native prepare/execute
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's Informix
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: ifx.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
*/
|
||||
class DB_ifx extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $affected = 0;
|
||||
var $dsn = array();
|
||||
var $transaction_opcount = 0;
|
||||
var $autocommit = true;
|
||||
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
function DB_ifx()
|
||||
{
|
||||
$this->phptype = 'ifx';
|
||||
$this->dbsyntax = 'ifx';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => true,
|
||||
'limit' => 'emulate'
|
||||
);
|
||||
$this->errorcode_map = array(
|
||||
'-201' => DB_ERROR_SYNTAX,
|
||||
'-206' => DB_ERROR_NOSUCHTABLE,
|
||||
'-217' => DB_ERROR_NOSUCHFIELD,
|
||||
'-239' => DB_ERROR_CONSTRAINT,
|
||||
'-253' => DB_ERROR_SYNTAX,
|
||||
'-292' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'-310' => DB_ERROR_ALREADY_EXISTS,
|
||||
'-329' => DB_ERROR_NODBSELECTED,
|
||||
'-346' => DB_ERROR_CONSTRAINT,
|
||||
'-386' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'-391' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'-554' => DB_ERROR_SYNTAX,
|
||||
'-691' => DB_ERROR_CONSTRAINT,
|
||||
'-703' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'-1204' => DB_ERROR_INVALID_DATE,
|
||||
'-1205' => DB_ERROR_INVALID_DATE,
|
||||
'-1206' => DB_ERROR_INVALID_DATE,
|
||||
'-1209' => DB_ERROR_INVALID_DATE,
|
||||
'-1210' => DB_ERROR_INVALID_DATE,
|
||||
'-1212' => DB_ERROR_INVALID_DATE,
|
||||
'-1213' => DB_ERROR_INVALID_NUMBER,
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $persistent (optional) whether the connection should
|
||||
* be persistent
|
||||
*
|
||||
* @return int DB_OK on success, a DB error code on failure
|
||||
*/
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('informix') &&
|
||||
!DB::assertExtension('Informix'))
|
||||
{
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
$this->dsn = $dsninfo;
|
||||
$dbhost = $dsninfo['hostspec'] ? '@' . $dsninfo['hostspec'] : '';
|
||||
$dbname = $dsninfo['database'] ? $dsninfo['database'] . $dbhost : '';
|
||||
$user = $dsninfo['username'] ? $dsninfo['username'] : '';
|
||||
$pw = $dsninfo['password'] ? $dsninfo['password'] : '';
|
||||
|
||||
$connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect';
|
||||
|
||||
$this->connection = @$connect_function($dbname, $user, $pw);
|
||||
if (!is_resource($this->connection)) {
|
||||
return $this->ifxraiseError(DB_ERROR_CONNECT_FAILED);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Log out and disconnect from the database.
|
||||
*
|
||||
* @return bool true on success, false if not connected.
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @ifx_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Send a query to Informix and return the results as a
|
||||
* Informix resource identifier.
|
||||
*
|
||||
* @param $query the SQL query
|
||||
*
|
||||
* @return int returns a valid Informix result for successful SELECT
|
||||
* queries, DB_OK for other successful queries. A DB error code
|
||||
* is returned on failure.
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
$this->affected = null;
|
||||
if (preg_match('/(SELECT)/i', $query)) { //TESTME: Use !DB::isManip()?
|
||||
// the scroll is needed for fetching absolute row numbers
|
||||
// in a select query result
|
||||
$result = @ifx_query($query, $this->connection, IFX_SCROLL);
|
||||
} else {
|
||||
if (!$this->autocommit && $ismanip) {
|
||||
if ($this->transaction_opcount == 0) {
|
||||
$result = @ifx_query('BEGIN WORK', $this->connection);
|
||||
if (!$result) {
|
||||
return $this->ifxraiseError();
|
||||
}
|
||||
}
|
||||
$this->transaction_opcount++;
|
||||
}
|
||||
$result = @ifx_query($query, $this->connection);
|
||||
}
|
||||
if (!$result) {
|
||||
return $this->ifxraiseError();
|
||||
}
|
||||
$this->affected = @ifx_affected_rows($result);
|
||||
// Determine which queries should return data, and which
|
||||
// should return an error code only.
|
||||
if (preg_match('/(SELECT)/i', $query)) {
|
||||
return $result;
|
||||
}
|
||||
// XXX Testme: free results inside a transaction
|
||||
// may cause to stop it and commit the work?
|
||||
|
||||
// Result has to be freed even with a insert or update
|
||||
@ifx_free_result($result);
|
||||
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal ifx result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the last query.
|
||||
* if the last query was a select, returns 0.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (DB::isManip($this->last_query)) {
|
||||
return $this->affected;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if (($rownum !== null) && ($rownum < 0)) {
|
||||
return null;
|
||||
}
|
||||
if ($rownum === null) {
|
||||
/*
|
||||
* Even though fetch_row() should return the next row if
|
||||
* $rownum is null, it doesn't in all cases. Bug 598.
|
||||
*/
|
||||
$rownum = 'NEXT';
|
||||
} else {
|
||||
// Index starts at row 1, unlike most DBMS's starting at 0.
|
||||
$rownum++;
|
||||
}
|
||||
if (!$arr = @ifx_fetch_row($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
if ($fetchmode !== DB_FETCHMODE_ASSOC) {
|
||||
$i=0;
|
||||
$order = array();
|
||||
foreach ($arr as $val) {
|
||||
$order[$i++] = $val;
|
||||
}
|
||||
$arr = $order;
|
||||
} elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
|
||||
$this->options['portability'] & DB_PORTABILITY_LOWERCASE)
|
||||
{
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
function numRows($result)
|
||||
{
|
||||
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Get the number of columns in a result set.
|
||||
*
|
||||
* @param $result Informix result identifier
|
||||
*
|
||||
* @return int the number of columns per row in $result
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
if (!$cols = @ifx_num_fields($result)) {
|
||||
return $this->ifxraiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with $result.
|
||||
*
|
||||
* @param $result Informix result identifier
|
||||
*
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
return @ifx_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enable/disable automatic commits
|
||||
*/
|
||||
function autoCommit($onoff = true)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
$this->autocommit = $onoff ? true : false;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
$result = @ifx_query('COMMIT WORK', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->ifxRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
$result = @ifx_query('ROLLBACK WORK', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->ifxRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ ifxraiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see errorNative()
|
||||
* @see errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function ifxraiseError($errno = null)
|
||||
{
|
||||
if ($errno === null) {
|
||||
$errno = $this->errorCode(ifx_error());
|
||||
}
|
||||
|
||||
return $this->raiseError($errno, null, null, null,
|
||||
$this->errorNative());
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorCode()
|
||||
|
||||
/**
|
||||
* Map native error codes to DB's portable ones.
|
||||
*
|
||||
* Requires that the DB implementation's constructor fills
|
||||
* in the <var>$errorcode_map</var> property.
|
||||
*
|
||||
* @param string $nativecode error code returned by the database
|
||||
* @return int a portable DB error code, or DB_ERROR if this DB
|
||||
* implementation has no mapping for the given error code.
|
||||
*/
|
||||
function errorCode($nativecode)
|
||||
{
|
||||
if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
|
||||
$code = $match[1];
|
||||
if (isset($this->errorcode_map[$code])) {
|
||||
return $this->errorcode_map[$code];
|
||||
}
|
||||
}
|
||||
return DB_ERROR;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Get the native error message of the last error (if any) that
|
||||
* occured on the current connection.
|
||||
*
|
||||
* @return int native Informix error code
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
return @ifx_error() . ' ' . @ifx_errormsg();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return 'select tabname from systables where tabid >= 100';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* NOTE: only supports 'table' if <var>$result</var> is a table name.
|
||||
*
|
||||
* If analyzing a query result and the result has duplicate field names,
|
||||
* an error will be raised saying
|
||||
* <samp>can't distinguish duplicate field names</samp>.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @since 1.6.0
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
$id = @ifx_query("SELECT * FROM $result WHERE 1=0",
|
||||
$this->connection);
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->ifxRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
$flds = @ifx_fieldproperties($id);
|
||||
$count = @ifx_num_fields($id);
|
||||
|
||||
if (count($flds) != $count) {
|
||||
return $this->raiseError("can't distinguish duplicate field names");
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
foreach ($flds as $key => $value) {
|
||||
$props = explode(';', $value);
|
||||
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func($key);
|
||||
$res[$i]['type'] = $props[0];
|
||||
$res[$i]['len'] = $props[1];
|
||||
$res[$i]['flags'] = $props[4] == 'N' ? 'not_null' : '';
|
||||
$i++;
|
||||
}
|
||||
|
||||
} else { // full
|
||||
$res['num_fields'] = $count;
|
||||
|
||||
foreach ($flds as $key => $value) {
|
||||
$props = explode(';', $value);
|
||||
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func($key);
|
||||
$res[$i]['type'] = $props[0];
|
||||
$res[$i]['len'] = $props[1];
|
||||
$res[$i]['flags'] = $props[4] == 'N' ? 'not_null' : '';
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@ifx_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
242
thirdparty/pear/DB/msql.php
vendored
242
thirdparty/pear/DB/msql.php
vendored
@@ -1,242 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Sterling Hughes <sterling@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: msql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's Mini-SQL
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: msql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
*/
|
||||
class DB_msql extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
function DB_msql()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'msql';
|
||||
$this->dbsyntax = 'msql';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => false,
|
||||
'limit' => 'emulate'
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('msql')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
|
||||
$connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
|
||||
|
||||
if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
|
||||
$conn = $connect_function($dbhost, $dsninfo['username'],
|
||||
$dsninfo['password']);
|
||||
} elseif ($dbhost && $dsninfo['username']) {
|
||||
$conn = $connect_function($dbhost, $dsninfo['username']);
|
||||
} else {
|
||||
$conn = $connect_function($dbhost);
|
||||
}
|
||||
if (!$conn) {
|
||||
$this->raiseError(DB_ERROR_CONNECT_FAILED);
|
||||
}
|
||||
if (!@msql_select_db($dsninfo['database'], $conn)){
|
||||
return $this->raiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @msql_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$this->last_query = $query;
|
||||
$query = $this->modifyQuery($query);
|
||||
$result = @msql_query($query, $this->connection);
|
||||
if (!$result) {
|
||||
return $this->raiseError();
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
return DB::isManip($query) ? DB_OK : $result;
|
||||
}
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal msql result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@msql_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @msql_fetch_array($result, MSQL_ASSOC);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @msql_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
if ($error = @msql_error()) {
|
||||
return $this->raiseError($error);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
function freeResult($result)
|
||||
{
|
||||
return @msql_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @msql_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->raiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @msql_num_rows($result);
|
||||
if (!$rows) {
|
||||
return $this->raiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affected()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by a query.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
return @msql_affected_rows($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
738
thirdparty/pear/DB/mssql.php
vendored
738
thirdparty/pear/DB/mssql.php
vendored
@@ -1,738 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Sterling Hughes <sterling@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: mssql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's Microsoft SQL Server
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: mssql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
*/
|
||||
class DB_mssql extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $transaction_opcount = 0;
|
||||
var $autocommit = true;
|
||||
var $_db = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
function DB_mssql()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'mssql';
|
||||
$this->dbsyntax = 'mssql';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => true,
|
||||
'limit' => 'emulate'
|
||||
);
|
||||
// XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
|
||||
$this->errorcode_map = array(
|
||||
170 => DB_ERROR_SYNTAX,
|
||||
207 => DB_ERROR_NOSUCHFIELD,
|
||||
208 => DB_ERROR_NOSUCHTABLE,
|
||||
245 => DB_ERROR_INVALID_NUMBER,
|
||||
515 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
547 => DB_ERROR_CONSTRAINT,
|
||||
2627 => DB_ERROR_CONSTRAINT,
|
||||
2714 => DB_ERROR_ALREADY_EXISTS,
|
||||
3701 => DB_ERROR_NOSUCHTABLE,
|
||||
8134 => DB_ERROR_DIVZERO,
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('mssql') && !DB::assertExtension('sybase')
|
||||
&& !DB::assertExtension('sybase_ct'))
|
||||
{
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
$this->dsn = $dsninfo;
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
//$dbhost .= $dsninfo['port'] ? ',' . $dsninfo['port'] : '';
|
||||
|
||||
$dbhost .= $dsninfo['port'] ? ':' . $dsninfo['port'] : ':1433';
|
||||
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
|
||||
|
||||
if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username'], $dsninfo['password']);
|
||||
}elseif ($dbhost && $dsninfo['username']){
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username']);
|
||||
} else {
|
||||
$conn = @$connect_function($dbhost);
|
||||
}
|
||||
if (!$conn) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
|
||||
null, @mssql_get_last_message());
|
||||
}
|
||||
if ($dsninfo['database']) {
|
||||
if (!@mssql_select_db($dsninfo['database'], $conn)) {
|
||||
return $this->raiseError(DB_ERROR_NODBSELECTED, null, null,
|
||||
null, @mssql_get_last_message());
|
||||
}
|
||||
$this->_db = $dsninfo['database'];
|
||||
}
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @mssql_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$query = $this->modifyQuery($query);
|
||||
if (!$this->autocommit && $ismanip) {
|
||||
if ($this->transaction_opcount == 0) {
|
||||
$result = @mssql_query('BEGIN TRAN', $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
$this->transaction_opcount++;
|
||||
}
|
||||
$result = @mssql_query($query, $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
return $ismanip ? DB_OK : $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal mssql result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return @mssql_next_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@mssql_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @mssql_fetch_array($result, MSSQL_ASSOC);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @mssql_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
/* This throws informative error messages,
|
||||
don't use it for now
|
||||
if ($msg = @mssql_get_last_message()) {
|
||||
return $this->raiseError($msg);
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
function freeResult($result)
|
||||
{
|
||||
return @mssql_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @mssql_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @mssql_num_rows($result);
|
||||
if ($rows === false) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enable/disable automatic commits
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
$this->autocommit = $onoff ? true : false;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @mssql_query('COMMIT TRAN', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @mssql_query('ROLLBACK TRAN', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the last query.
|
||||
* if the last query was a select, returns 0.
|
||||
*
|
||||
* @return number of rows affected by the last query or DB_ERROR
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (DB::isManip($this->last_query)) {
|
||||
$res = @mssql_query('select @@rowcount', $this->connection);
|
||||
if (!$res) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
$ar = @mssql_fetch_row($res);
|
||||
if (!$ar) {
|
||||
$result = 0;
|
||||
} else {
|
||||
@mssql_free_result($res);
|
||||
$result = $ar[0];
|
||||
}
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("INSERT INTO $seqname (vapor) VALUES (0)");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
($result->getCode() == DB_ERROR || $result->getCode() == DB_ERROR_NOSUCHTABLE))
|
||||
{
|
||||
$repeat = 1;
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
} elseif (!DB::isError($result)) {
|
||||
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
$repeat = 0;
|
||||
} else {
|
||||
$repeat = false;
|
||||
}
|
||||
} while ($repeat);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$result = $result->fetchRow(DB_FETCHMODE_ORDERED);
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object is returned if
|
||||
* problems arise.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::createSequence()
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("CREATE TABLE $seqname ".
|
||||
'([id] [int] IDENTITY (1, 1) NOT NULL ,' .
|
||||
'[vapor] [int] NULL)');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. DB_Error if problems.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::dropSequence()
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("DROP TABLE $seqname");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Determine MS SQL Server error code by querying @@ERROR.
|
||||
*
|
||||
* @return mixed mssql's native error code or DB_ERROR if unknown.
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
$res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
|
||||
if (!$res) {
|
||||
return DB_ERROR;
|
||||
}
|
||||
$row = @mssql_fetch_row($res);
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorCode()
|
||||
|
||||
/**
|
||||
* Determine PEAR::DB error code from mssql's native codes.
|
||||
*
|
||||
* If <var>$nativecode</var> isn't known yet, it will be looked up.
|
||||
*
|
||||
* @param mixed $nativecode mssql error code, if known
|
||||
* @return integer an error number from a DB error constant
|
||||
* @see errorNative()
|
||||
*/
|
||||
function errorCode($nativecode = null)
|
||||
{
|
||||
if (!$nativecode) {
|
||||
$nativecode = $this->errorNative();
|
||||
}
|
||||
if (isset($this->errorcode_map[$nativecode])) {
|
||||
return $this->errorcode_map[$nativecode];
|
||||
} else {
|
||||
return DB_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ mssqlRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $code PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see errorCode()
|
||||
* @see errorNative()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function mssqlRaiseError($code = null)
|
||||
{
|
||||
$message = @mssql_get_last_message();
|
||||
if (!$code) {
|
||||
$code = $this->errorNative();
|
||||
}
|
||||
return $this->raiseError($this->errorCode($code), null, null, null,
|
||||
"$code - $message");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||
* is a table name.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$id = @mssql_query("SELECT * FROM $result WHERE 1=0",
|
||||
$this->connection);
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @mssql_num_fields($id);
|
||||
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func(@mssql_field_name($id, $i));
|
||||
$res[$i]['type'] = @mssql_field_type($id, $i);
|
||||
$res[$i]['len'] = @mssql_field_length($id, $i);
|
||||
// We only support flags for tables
|
||||
$res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
|
||||
}
|
||||
|
||||
} else { // full
|
||||
$res['num_fields']= $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $got_string ? $case_func($result) : '';
|
||||
$res[$i]['name'] = $case_func(@mssql_field_name($id, $i));
|
||||
$res[$i]['type'] = @mssql_field_type($id, $i);
|
||||
$res[$i]['len'] = @mssql_field_length($id, $i);
|
||||
// We only support flags for tables
|
||||
$res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@mssql_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return "select name from sysobjects where type = 'U' order by name";
|
||||
case 'views':
|
||||
return "select name from sysobjects where type = 'V'";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _mssql_field_flags()
|
||||
|
||||
/**
|
||||
* Get the flags for a field, currently supports "not_null", "primary_key",
|
||||
* "auto_increment" (mssql identity), "timestamp" (mssql timestamp),
|
||||
* "unique_key" (mssql unique index, unique check or primary_key) and
|
||||
* "multiple_key" (multikey index)
|
||||
*
|
||||
* mssql timestamp is NOT similar to the mysql timestamp so this is maybe
|
||||
* not useful at all - is the behaviour of mysql_field_flags that primary
|
||||
* keys are alway unique? is the interpretation of multiple_key correct?
|
||||
*
|
||||
* @param string The table name
|
||||
* @param string The field
|
||||
* @author Joern Barthel <j_barthel@web.de>
|
||||
* @access private
|
||||
*/
|
||||
function _mssql_field_flags($table, $column)
|
||||
{
|
||||
static $tableName = null;
|
||||
static $flags = array();
|
||||
|
||||
if ($table != $tableName) {
|
||||
|
||||
$flags = array();
|
||||
$tableName = $table;
|
||||
|
||||
// get unique and primary keys
|
||||
$res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC);
|
||||
|
||||
foreach ($res as $val) {
|
||||
$keys = explode(', ', $val['index_keys']);
|
||||
|
||||
if (sizeof($keys) > 1) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'multiple_key');
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($val['index_description'], 'primary key')) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'primary_key');
|
||||
}
|
||||
} elseif (strpos($val['index_description'], 'unique')) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'unique_key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get auto_increment, not_null and timestamp
|
||||
$res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC);
|
||||
|
||||
foreach ($res as $val) {
|
||||
$val = array_change_key_case($val, CASE_LOWER);
|
||||
if ($val['nullable'] == '0') {
|
||||
$this->_add_flag($flags[$val['column_name']], 'not_null');
|
||||
}
|
||||
if (strpos($val['type_name'], 'identity')) {
|
||||
$this->_add_flag($flags[$val['column_name']], 'auto_increment');
|
||||
}
|
||||
if (strpos($val['type_name'], 'timestamp')) {
|
||||
$this->_add_flag($flags[$val['column_name']], 'timestamp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($column, $flags)) {
|
||||
return(implode(' ', $flags[$column]));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _add_flag()
|
||||
|
||||
/**
|
||||
* Adds a string to the flags array if the flag is not yet in there
|
||||
* - if there is no flag present the array is created.
|
||||
*
|
||||
* @param reference Reference to the flag-array
|
||||
* @param value The flag value
|
||||
* @access private
|
||||
* @author Joern Barthel <j_barthel@web.de>
|
||||
*/
|
||||
function _add_flag(&$array, $value)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
$array = array($value);
|
||||
} elseif (!in_array($value, $array)) {
|
||||
array_push($array, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteIdentifier()
|
||||
|
||||
/**
|
||||
* Quote a string so it can be safely used as a table / column name
|
||||
*
|
||||
* Quoting style depends on which database driver is being used.
|
||||
*
|
||||
* @param string $str identifier name to be quoted
|
||||
*
|
||||
* @return string quoted identifier string
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @access public
|
||||
*/
|
||||
function quoteIdentifier($str)
|
||||
{
|
||||
return '[' . str_replace(']', ']]', $str) . ']';
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
916
thirdparty/pear/DB/mysql.php
vendored
916
thirdparty/pear/DB/mysql.php
vendored
@@ -1,916 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <ssb@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: mysql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// XXX legend:
|
||||
//
|
||||
// XXX ERRORMSG: The error message from the mysql function should
|
||||
// be registered here.
|
||||
//
|
||||
// TODO/wishlist:
|
||||
// longReadlen
|
||||
// binmode
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's MySQL
|
||||
* extension.
|
||||
*
|
||||
* This is for MySQL versions 4.0 and below.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: mysql.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
*/
|
||||
class DB_mysql extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $num_rows = array();
|
||||
var $transaction_opcount = 0;
|
||||
var $autocommit = true;
|
||||
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
|
||||
var $_db = false;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* DB_mysql constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function DB_mysql()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'mysql';
|
||||
$this->dbsyntax = 'mysql';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => true,
|
||||
'limit' => 'alter'
|
||||
);
|
||||
$this->errorcode_map = array(
|
||||
1004 => DB_ERROR_CANNOT_CREATE,
|
||||
1005 => DB_ERROR_CANNOT_CREATE,
|
||||
1006 => DB_ERROR_CANNOT_CREATE,
|
||||
1007 => DB_ERROR_ALREADY_EXISTS,
|
||||
1008 => DB_ERROR_CANNOT_DROP,
|
||||
1022 => DB_ERROR_ALREADY_EXISTS,
|
||||
1046 => DB_ERROR_NODBSELECTED,
|
||||
1048 => DB_ERROR_CONSTRAINT,
|
||||
1050 => DB_ERROR_ALREADY_EXISTS,
|
||||
1051 => DB_ERROR_NOSUCHTABLE,
|
||||
1054 => DB_ERROR_NOSUCHFIELD,
|
||||
1062 => DB_ERROR_ALREADY_EXISTS,
|
||||
1064 => DB_ERROR_SYNTAX,
|
||||
1100 => DB_ERROR_NOT_LOCKED,
|
||||
1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
1146 => DB_ERROR_NOSUCHTABLE,
|
||||
1216 => DB_ERROR_CONSTRAINT,
|
||||
1217 => DB_ERROR_CONSTRAINT,
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $persistent (optional) whether the connection should
|
||||
* be persistent
|
||||
* @access public
|
||||
* @return int DB_OK on success, a DB error on failure
|
||||
*/
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('mysql')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
$this->dsn = $dsninfo;
|
||||
if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') {
|
||||
$dbhost = ':' . $dsninfo['socket'];
|
||||
} else {
|
||||
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
if ($dsninfo['port']) {
|
||||
$dbhost .= ':' . $dsninfo['port'];
|
||||
}
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
|
||||
|
||||
if ($dbhost && $dsninfo['username'] && isset($dsninfo['password'])) {
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username'],
|
||||
$dsninfo['password']);
|
||||
} elseif ($dbhost && $dsninfo['username']) {
|
||||
$conn = @$connect_function($dbhost, $dsninfo['username']);
|
||||
} elseif ($dbhost) {
|
||||
$conn = @$connect_function($dbhost);
|
||||
} else {
|
||||
$conn = false;
|
||||
}
|
||||
if (!$conn) {
|
||||
if (($err = @mysql_error()) != '') {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
|
||||
null, $err);
|
||||
} elseif (empty($php_errormsg)) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED);
|
||||
} else {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
|
||||
null, $php_errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!@mysql_select_db($dsninfo['database'], $conn)) {
|
||||
switch(mysql_errno($conn)) {
|
||||
case 1049:
|
||||
return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,
|
||||
null, @mysql_error($conn));
|
||||
case 1044:
|
||||
return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,
|
||||
null, @mysql_error($conn));
|
||||
default:
|
||||
return $this->raiseError(DB_ERROR, null, null,
|
||||
null, @mysql_error($conn));
|
||||
}
|
||||
}
|
||||
// fix to allow calls to different databases in the same script
|
||||
$this->_db = $dsninfo['database'];
|
||||
}
|
||||
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Log out and disconnect from the database.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if not connected.
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @mysql_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Send a query to MySQL and return the results as a MySQL resource
|
||||
* identifier.
|
||||
*
|
||||
* @param the SQL query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return mixed returns a valid MySQL result for successful SELECT
|
||||
* queries, DB_OK for other successful queries. A DB error is
|
||||
* returned on failure.
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
$query = $this->modifyQuery($query);
|
||||
if ($this->_db) {
|
||||
if (!@mysql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
if (!$this->autocommit && $ismanip) {
|
||||
if ($this->transaction_opcount == 0) {
|
||||
$result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
|
||||
$result = @mysql_query('BEGIN', $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
}
|
||||
$this->transaction_opcount++;
|
||||
}
|
||||
$result = @mysql_query($query, $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
if (is_resource($result)) {
|
||||
$numrows = $this->numrows($result);
|
||||
if (is_object($numrows)) {
|
||||
return $numrows;
|
||||
}
|
||||
$this->num_rows[(int)$result] = $numrows;
|
||||
return $result;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal mysql result pointer to the next available result
|
||||
*
|
||||
* This method has not been implemented yet.
|
||||
*
|
||||
* @param a valid sql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@mysql_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @mysql_fetch_array($result, MYSQL_ASSOC);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @mysql_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
// See: http://bugs.php.net/bug.php?id=22328
|
||||
// for why we can't check errors on fetching
|
||||
return null;
|
||||
/*
|
||||
$errno = @mysql_errno($this->connection);
|
||||
if (!$errno) {
|
||||
return null;
|
||||
}
|
||||
return $this->mysqlRaiseError($errno);
|
||||
*/
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
/*
|
||||
* Even though this DBMS already trims output, we do this because
|
||||
* a field might have intentional whitespace at the end that
|
||||
* gets removed by DB_PORTABILITY_RTRIM under another driver.
|
||||
*/
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with $result.
|
||||
*
|
||||
* @param $result MySQL result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
unset($this->num_rows[(int)$result]);
|
||||
return @mysql_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Get the number of columns in a result set.
|
||||
*
|
||||
* @param $result MySQL result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of columns per row in $result
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @mysql_num_fields($result);
|
||||
|
||||
if (!$cols) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Get the number of rows in a result set.
|
||||
*
|
||||
* @param $result MySQL result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of rows in $result
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @mysql_num_rows($result);
|
||||
if ($rows === null) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enable/disable automatic commits
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
$this->autocommit = $onoff ? true : false;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if ($this->_db) {
|
||||
if (!@mysql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
$result = @mysql_query('COMMIT', $this->connection);
|
||||
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if ($this->_db) {
|
||||
if (!@mysql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
$result = @mysql_query('ROLLBACK', $this->connection);
|
||||
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mysqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query. For other queries, this function returns 0.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (DB::isManip($this->last_query)) {
|
||||
return @mysql_affected_rows($this->connection);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Get the native error code of the last error (if any) that
|
||||
* occured on the current connection.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int native MySQL error code
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
return @mysql_errno($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
do {
|
||||
$repeat = 0;
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("UPDATE ${seqname} ".
|
||||
'SET id=LAST_INSERT_ID(id+1)');
|
||||
$this->popErrorHandling();
|
||||
if ($result === DB_OK) {
|
||||
/** COMMON CASE **/
|
||||
$id = @mysql_insert_id($this->connection);
|
||||
if ($id != 0) {
|
||||
return $id;
|
||||
}
|
||||
/** EMPTY SEQ TABLE **/
|
||||
// Sequence table must be empty for some reason, so fill it and return 1
|
||||
// Obtain a user-level lock
|
||||
$result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
if ($result == 0) {
|
||||
// Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error
|
||||
return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
|
||||
}
|
||||
|
||||
// add the default value
|
||||
$result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)");
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
|
||||
// Release the lock
|
||||
$result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
// We know what the result will be, so no need to try again
|
||||
return 1;
|
||||
|
||||
/** ONDEMAND TABLE CREATION **/
|
||||
} elseif ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE)
|
||||
{
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
} else {
|
||||
$repeat = 1;
|
||||
}
|
||||
|
||||
/** BACKWARDS COMPAT **/
|
||||
} elseif (DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
// see _BCsequence() comment
|
||||
$result = $this->_BCsequence($seqname);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$repeat = 1;
|
||||
}
|
||||
} while ($repeat);
|
||||
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ createSequence()
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object is returned if
|
||||
* problems arise.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::createSequence()
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$res = $this->query("CREATE TABLE ${seqname} ".
|
||||
'(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
|
||||
' PRIMARY KEY(id))');
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
// insert yields value 1, nextId call will generate ID 2
|
||||
$res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
// so reset to zero
|
||||
return $this->query("UPDATE ${seqname} SET id = 0;");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. DB_Error if problems.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::dropSequence()
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _BCsequence()
|
||||
|
||||
/**
|
||||
* Backwards compatibility with old sequence emulation implementation
|
||||
* (clean up the dupes)
|
||||
*
|
||||
* @param string $seqname The sequence name to clean up
|
||||
* @return mixed DB_Error or true
|
||||
*/
|
||||
function _BCsequence($seqname)
|
||||
{
|
||||
// Obtain a user-level lock... this will release any previous
|
||||
// application locks, but unlike LOCK TABLES, it does not abort
|
||||
// the current transaction and is much less frequently used.
|
||||
$result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
if ($result == 0) {
|
||||
// Failed to get the lock, can't do the conversion, bail
|
||||
// with a DB_ERROR_NOT_LOCKED error
|
||||
return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
|
||||
}
|
||||
|
||||
$highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
|
||||
if (DB::isError($highest_id)) {
|
||||
return $highest_id;
|
||||
}
|
||||
// This should kill all rows except the highest
|
||||
// We should probably do something if $highest_id isn't
|
||||
// numeric, but I'm at a loss as how to handle that...
|
||||
$result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id");
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// If another thread has been waiting for this lock,
|
||||
// it will go thru the above procedure, but will have no
|
||||
// real effect
|
||||
$result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteIdentifier()
|
||||
|
||||
/**
|
||||
* Quote a string so it can be safely used as a table or column name
|
||||
*
|
||||
* Quoting style depends on which database driver is being used.
|
||||
*
|
||||
* MySQL can't handle the backtick character (<kbd>`</kbd>) in
|
||||
* table or column names.
|
||||
*
|
||||
* @param string $str identifier name to be quoted
|
||||
*
|
||||
* @return string quoted identifier string
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @access public
|
||||
* @internal
|
||||
*/
|
||||
function quoteIdentifier($str)
|
||||
{
|
||||
return '`' . $str . '`';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quote()
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in release 1.6.0
|
||||
* @internal
|
||||
*/
|
||||
function quote($str) {
|
||||
return $this->quoteSmart($str);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ escapeSimple()
|
||||
|
||||
/**
|
||||
* Escape a string according to the current DBMS's standards
|
||||
*
|
||||
* @param string $str the string to be escaped
|
||||
*
|
||||
* @return string the escaped string
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function escapeSimple($str) {
|
||||
if (function_exists('mysql_real_escape_string')) {
|
||||
return @mysql_real_escape_string($str, $this->connection);
|
||||
} else {
|
||||
return @mysql_escape_string($str);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyQuery()
|
||||
|
||||
function modifyQuery($query)
|
||||
{
|
||||
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
||||
// "DELETE FROM table" gives 0 affected rows in MySQL.
|
||||
// This little hack lets you know how many rows were deleted.
|
||||
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
||||
$query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
||||
'DELETE FROM \1 WHERE 1=1', $query);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyLimitQuery()
|
||||
|
||||
function modifyLimitQuery($query, $from, $count, $params = array())
|
||||
{
|
||||
if (DB::isManip($query)) {
|
||||
return $query . " LIMIT $count";
|
||||
} else {
|
||||
return $query . " LIMIT $from, $count";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ mysqlRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see DB_common::errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function mysqlRaiseError($errno = null)
|
||||
{
|
||||
if ($errno === null) {
|
||||
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
||||
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
|
||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
|
||||
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
|
||||
} else {
|
||||
// Doing this in case mode changes during runtime.
|
||||
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
|
||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
|
||||
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
|
||||
}
|
||||
$errno = $this->errorCode(mysql_errno($this->connection));
|
||||
}
|
||||
return $this->raiseError($errno, null, null, null,
|
||||
@mysql_errno($this->connection) . ' ** ' .
|
||||
@mysql_error($this->connection));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null) {
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
$id = @mysql_list_fields($this->dsn['database'],
|
||||
$result, $this->connection);
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @mysql_num_fields($id);
|
||||
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
|
||||
$res[$i]['name'] = $case_func(@mysql_field_name($id, $i));
|
||||
$res[$i]['type'] = @mysql_field_type($id, $i);
|
||||
$res[$i]['len'] = @mysql_field_len($id, $i);
|
||||
$res[$i]['flags'] = @mysql_field_flags($id, $i);
|
||||
}
|
||||
} else { // full
|
||||
$res['num_fields']= $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
|
||||
$res[$i]['name'] = $case_func(@mysql_field_name($id, $i));
|
||||
$res[$i]['type'] = @mysql_field_type($id, $i);
|
||||
$res[$i]['len'] = @mysql_field_len($id, $i);
|
||||
$res[$i]['flags'] = @mysql_field_flags($id, $i);
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@mysql_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return 'SHOW TABLES';
|
||||
case 'views':
|
||||
return DB_ERROR_NOT_CAPABLE;
|
||||
case 'users':
|
||||
$sql = 'select distinct User from user';
|
||||
if ($this->dsn['database'] != 'mysql') {
|
||||
$dsn = $this->dsn;
|
||||
$dsn['database'] = 'mysql';
|
||||
if (DB::isError($db = DB::connect($dsn))) {
|
||||
return $db;
|
||||
}
|
||||
$sql = $db->getCol($sql);
|
||||
$db->disconnect();
|
||||
// XXX Fixme the mysql driver should take care of this
|
||||
if (!@mysql_select_db($this->dsn['database'], $this->connection)) {
|
||||
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
case 'databases':
|
||||
return 'SHOW DATABASES';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
695
thirdparty/pear/DB/sqlite.php
vendored
695
thirdparty/pear/DB/sqlite.php
vendored
@@ -1,695 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Urs Gehrig <urs@circle.ch> |
|
||||
// | Mika Tuupola <tuupola@appelsiini.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: sqlite.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for the SQLite
|
||||
* PECL extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: sqlite.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Urs Gehrig <urs@circle.ch>
|
||||
* @author Mika Tuupola <tuupola@appelsiini.net>
|
||||
*/
|
||||
class DB_sqlite extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $_lasterror = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor for this class.
|
||||
*
|
||||
* Error codes according to sqlite_exec. Error Codes specification is
|
||||
* in the {@link http://sqlite.org/c_interface.html online manual}.
|
||||
*
|
||||
* This errorhandling based on sqlite_exec is not yet implemented.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function DB_sqlite()
|
||||
{
|
||||
|
||||
$this->DB_common();
|
||||
$this->phptype = 'sqlite';
|
||||
$this->dbsyntax = 'sqlite';
|
||||
$this->features = array (
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => false,
|
||||
'limit' => 'alter'
|
||||
);
|
||||
|
||||
// SQLite data types, http://www.sqlite.org/datatypes.html
|
||||
$this->keywords = array (
|
||||
'BLOB' => '',
|
||||
'BOOLEAN' => '',
|
||||
'CHARACTER' => '',
|
||||
'CLOB' => '',
|
||||
'FLOAT' => '',
|
||||
'INTEGER' => '',
|
||||
'KEY' => '',
|
||||
'NATIONAL' => '',
|
||||
'NUMERIC' => '',
|
||||
'NVARCHAR' => '',
|
||||
'PRIMARY' => '',
|
||||
'TEXT' => '',
|
||||
'TIMESTAMP' => '',
|
||||
'UNIQUE' => '',
|
||||
'VARCHAR' => '',
|
||||
'VARYING' => ''
|
||||
);
|
||||
$this->errorcode_map = array(
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to a database represented by a file.
|
||||
*
|
||||
* @param $dsn the data source name; the file is taken as
|
||||
* database; "sqlite://root:@host/test.db?mode=0644"
|
||||
* @param $persistent (optional) whether the connection should
|
||||
* be persistent
|
||||
* @access public
|
||||
* @return int DB_OK on success, a DB error on failure
|
||||
*/
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('sqlite')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!file_exists($dsninfo['database'])) {
|
||||
if (!touch($dsninfo['database'])) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
|
||||
}
|
||||
if (!isset($dsninfo['mode']) ||
|
||||
!is_numeric($dsninfo['mode']))
|
||||
{
|
||||
$mode = 0644;
|
||||
} else {
|
||||
$mode = octdec($dsninfo['mode']);
|
||||
}
|
||||
if (!chmod($dsninfo['database'], $mode)) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
|
||||
}
|
||||
if (!file_exists($dsninfo['database'])) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
if (!is_file($dsninfo['database'])) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_INVALID);
|
||||
}
|
||||
if (!is_readable($dsninfo['database'])) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
}
|
||||
} else {
|
||||
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
|
||||
if (!($conn = @$connect_function($dsninfo['database']))) {
|
||||
return $this->sqliteRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$this->connection = $conn;
|
||||
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Log out and disconnect from the database.
|
||||
*
|
||||
* @access public
|
||||
* @return bool true on success, false if not connected.
|
||||
* @todo fix return values
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @sqlite_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Send a query to SQLite and returns the results as a SQLite resource
|
||||
* identifier.
|
||||
*
|
||||
* @param the SQL query
|
||||
* @access public
|
||||
* @return mixed returns a valid SQLite result for successful SELECT
|
||||
* queries, DB_OK for other successful queries. A DB error is
|
||||
* returned on failure.
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
$query = $this->_modifyQuery($query);
|
||||
ini_set('track_errors', true);
|
||||
$result = @sqlite_query($query, $this->connection);
|
||||
ini_restore('track_errors');
|
||||
$this->_lasterror = isset($php_errormsg) ? $php_errormsg : '';
|
||||
$this->result = $result;
|
||||
if (!$this->result) {
|
||||
return $this->sqliteRaiseError(null);
|
||||
}
|
||||
|
||||
/* sqlite_query() seems to allways return a resource */
|
||||
/* so cant use that. Using $ismanip instead */
|
||||
if (!$ismanip) {
|
||||
$numRows = $this->numRows($result);
|
||||
|
||||
/* if numRows() returned PEAR_Error */
|
||||
if (is_object($numRows)) {
|
||||
return $numRows;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal sqlite result pointer to the next available result.
|
||||
*
|
||||
* @param a valid sqlite result resource
|
||||
* @access public
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@sqlite_seek($this->result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @sqlite_fetch_array($result, SQLITE_ASSOC);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @sqlite_fetch_array($result, SQLITE_NUM);
|
||||
}
|
||||
if (!$arr) {
|
||||
/* See: http://bugs.php.net/bug.php?id=22328 */
|
||||
return null;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
/*
|
||||
* Even though this DBMS already trims output, we do this because
|
||||
* a field might have intentional whitespace at the end that
|
||||
* gets removed by DB_PORTABILITY_RTRIM under another driver.
|
||||
*/
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with $result.
|
||||
*
|
||||
* @param $result SQLite result identifier
|
||||
* @access public
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freeResult(&$result)
|
||||
{
|
||||
// XXX No native free?
|
||||
if (!is_resource($result)) {
|
||||
return false;
|
||||
}
|
||||
$result = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Gets the number of columns in a result set.
|
||||
*
|
||||
* @return number of columns in a result set
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @sqlite_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->sqliteRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by a query.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @sqlite_num_rows($result);
|
||||
if (!is_integer($rows)) {
|
||||
return $this->raiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affected()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by a query.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
return @sqlite_changes($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Get the native error string of the last error (if any) that
|
||||
* occured on the current connection.
|
||||
*
|
||||
* This is used to retrieve more meaningfull error messages DB_pgsql
|
||||
* way since sqlite_last_error() does not provide adequate info.
|
||||
*
|
||||
* @return string native SQLite error message
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
return($this->_lasterror);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorCode()
|
||||
|
||||
/**
|
||||
* Determine PEAR::DB error code from the database's text error message.
|
||||
*
|
||||
* @param string $errormsg error message returned from the database
|
||||
* @return integer an error number from a DB error constant
|
||||
*/
|
||||
function errorCode($errormsg)
|
||||
{
|
||||
static $error_regexps;
|
||||
if (!isset($error_regexps)) {
|
||||
$error_regexps = array(
|
||||
'/^no such table:/' => DB_ERROR_NOSUCHTABLE,
|
||||
'/^table .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
|
||||
'/PRIMARY KEY must be unique/i' => DB_ERROR_CONSTRAINT,
|
||||
'/is not unique/' => DB_ERROR_CONSTRAINT,
|
||||
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
|
||||
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'/^no such column:/' => DB_ERROR_NOSUCHFIELD,
|
||||
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX
|
||||
);
|
||||
}
|
||||
foreach ($error_regexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $errormsg)) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
// Fall back to DB_ERROR if there was no mapping.
|
||||
return DB_ERROR;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. DB_Error if problems.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::dropSequence()
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("DROP TABLE $seqname");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object is returned if
|
||||
* problems arise.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::createSequence()
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$query = 'CREATE TABLE ' . $seqname .
|
||||
' (id INTEGER UNSIGNED PRIMARY KEY) ';
|
||||
$result = $this->query($query);
|
||||
if (DB::isError($result)) {
|
||||
return($result);
|
||||
}
|
||||
$query = "CREATE TRIGGER ${seqname}_cleanup AFTER INSERT ON $seqname
|
||||
BEGIN
|
||||
DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID();
|
||||
END ";
|
||||
$result = $this->query($query);
|
||||
if (DB::isError($result)) {
|
||||
return($result);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
|
||||
do {
|
||||
$repeat = 0;
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("INSERT INTO $seqname (id) VALUES (NULL)");
|
||||
$this->popErrorHandling();
|
||||
if ($result === DB_OK) {
|
||||
$id = @sqlite_last_insert_rowid($this->connection);
|
||||
if ($id != 0) {
|
||||
return $id;
|
||||
}
|
||||
} elseif ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE)
|
||||
{
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
} else {
|
||||
$repeat = 1;
|
||||
}
|
||||
}
|
||||
} while ($repeat);
|
||||
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info.
|
||||
*
|
||||
* Refer to the online manual at http://sqlite.org/sqlite.html.
|
||||
*
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type, $args=array())
|
||||
{
|
||||
if (!is_array($args))
|
||||
return $this->raiseError('no key specified', null, null, null,
|
||||
'Argument has to be an array.');
|
||||
switch (strtolower($type)) {
|
||||
case 'master':
|
||||
return 'SELECT * FROM sqlite_master;';
|
||||
case 'tables':
|
||||
return "SELECT name FROM sqlite_master WHERE type='table' "
|
||||
. 'UNION ALL SELECT name FROM sqlite_temp_master '
|
||||
. "WHERE type='table' ORDER BY name;";
|
||||
case 'schema':
|
||||
return 'SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL '
|
||||
. 'SELECT * FROM sqlite_temp_master) '
|
||||
. "WHERE type!='meta' ORDER BY tbl_name, type DESC, name;";
|
||||
case 'schemax':
|
||||
case 'schema_x':
|
||||
/*
|
||||
* Use like:
|
||||
* $res = $db->query($db->getSpecialQuery('schema_x', array('table' => 'table3')));
|
||||
*/
|
||||
return 'SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL '
|
||||
. 'SELECT * FROM sqlite_temp_master) '
|
||||
. "WHERE tbl_name LIKE '{$args['table']}' AND type!='meta' "
|
||||
. 'ORDER BY type DESC, name;';
|
||||
case 'alter':
|
||||
/*
|
||||
* SQLite does not support ALTER TABLE; this is a helper query
|
||||
* to handle this. 'table' represents the table name, 'rows'
|
||||
* the news rows to create, 'save' the row(s) to keep _with_
|
||||
* the data.
|
||||
*
|
||||
* Use like:
|
||||
* $args = array(
|
||||
* 'table' => $table,
|
||||
* 'rows' => "id INTEGER PRIMARY KEY, firstname TEXT, surname TEXT, datetime TEXT",
|
||||
* 'save' => "NULL, titel, content, datetime"
|
||||
* );
|
||||
* $res = $db->query( $db->getSpecialQuery('alter', $args));
|
||||
*/
|
||||
$rows = strtr($args['rows'], $this->keywords);
|
||||
|
||||
$q = array(
|
||||
'BEGIN TRANSACTION',
|
||||
"CREATE TEMPORARY TABLE {$args['table']}_backup ({$args['rows']})",
|
||||
"INSERT INTO {$args['table']}_backup SELECT {$args['save']} FROM {$args['table']}",
|
||||
"DROP TABLE {$args['table']}",
|
||||
"CREATE TABLE {$args['table']} ({$args['rows']})",
|
||||
"INSERT INTO {$args['table']} SELECT {$rows} FROM {$args['table']}_backup",
|
||||
"DROP TABLE {$args['table']}_backup",
|
||||
'COMMIT',
|
||||
);
|
||||
|
||||
// This is a dirty hack, since the above query will no get executed with a single
|
||||
// query call; so here the query method will be called directly and return a select instead.
|
||||
foreach ($q as $query) {
|
||||
$this->query($query);
|
||||
}
|
||||
return "SELECT * FROM {$args['table']};";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getDbFileStats()
|
||||
|
||||
/**
|
||||
* Get the file stats for the current database.
|
||||
*
|
||||
* Possible arguments are dev, ino, mode, nlink, uid, gid, rdev, size,
|
||||
* atime, mtime, ctime, blksize, blocks or a numeric key between
|
||||
* 0 and 12.
|
||||
*
|
||||
* @param string $arg Array key for stats()
|
||||
* @return mixed array on an unspecified key, integer on a passed arg and
|
||||
* false at a stats error.
|
||||
*/
|
||||
function getDbFileStats($arg = '')
|
||||
{
|
||||
$stats = stat($this->dsn['database']);
|
||||
if ($stats == false) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($stats)) {
|
||||
if (is_numeric($arg)) {
|
||||
if (((int)$arg <= 12) & ((int)$arg >= 0)) {
|
||||
return false;
|
||||
}
|
||||
return $stats[$arg ];
|
||||
}
|
||||
if (array_key_exists(trim($arg), $stats)) {
|
||||
return $stats[$arg ];
|
||||
}
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ escapeSimple()
|
||||
|
||||
/**
|
||||
* Escape a string according to the current DBMS's standards
|
||||
*
|
||||
* In SQLite, this makes things safe for inserts/updates, but may
|
||||
* cause problems when performing text comparisons against columns
|
||||
* containing binary data. See the
|
||||
* {@link http://php.net/sqlite_escape_string PHP manual} for more info.
|
||||
*
|
||||
* @param string $str the string to be escaped
|
||||
*
|
||||
* @return string the escaped string
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @see DB_common::escapeSimple()
|
||||
* @internal
|
||||
*/
|
||||
function escapeSimple($str) {
|
||||
return @sqlite_escape_string($str);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyLimitQuery()
|
||||
|
||||
function modifyLimitQuery($query, $from, $count, $params = array())
|
||||
{
|
||||
$query = $query . " LIMIT $count OFFSET $from";
|
||||
return $query;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ modifyQuery()
|
||||
|
||||
/**
|
||||
* "DELETE FROM table" gives 0 affected rows in SQLite.
|
||||
*
|
||||
* This little hack lets you know how many rows were deleted.
|
||||
*
|
||||
* @param string $query The SQL query string
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function _modifyQuery($query)
|
||||
{
|
||||
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
||||
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
||||
$query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
||||
'DELETE FROM \1 WHERE 1=1', $query);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ sqliteRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see errorNative()
|
||||
* @see errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function sqliteRaiseError($errno = null)
|
||||
{
|
||||
|
||||
$native = $this->errorNative();
|
||||
if ($errno === null) {
|
||||
$errno = $this->errorCode($native);
|
||||
}
|
||||
|
||||
$errorcode = @sqlite_last_error($this->connection);
|
||||
$userinfo = "$errorcode ** $this->last_query";
|
||||
|
||||
return $this->raiseError($errno, null, null, $userinfo, $native);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
495
thirdparty/pear/DB/storage.php
vendored
495
thirdparty/pear/DB/storage.php
vendored
@@ -1,495 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Stig Bakken <stig@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: storage.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
require_once 'DB.php';
|
||||
|
||||
/**
|
||||
* Provides an object interface to a table row.
|
||||
*
|
||||
* It lets you add, delete and change rows using objects rather than SQL
|
||||
* statements.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: storage.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Stig Bakken <stig@php.net>
|
||||
*/
|
||||
class DB_storage extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/** the name of the table (or view, if the backend database supports
|
||||
updates in views) we hold data from */
|
||||
var $_table = null;
|
||||
|
||||
/** which column(s) in the table contains primary keys, can be a
|
||||
string for single-column primary keys, or an array of strings
|
||||
for multiple-column primary keys */
|
||||
var $_keycolumn = null;
|
||||
|
||||
/** DB connection handle used for all transactions */
|
||||
var $_dbh = null;
|
||||
|
||||
/** an assoc with the names of database fields stored as properties
|
||||
in this object */
|
||||
var $_properties = array();
|
||||
|
||||
/** an assoc with the names of the properties in this object that
|
||||
have been changed since they were fetched from the database */
|
||||
var $_changes = array();
|
||||
|
||||
/** flag that decides if data in this object can be changed.
|
||||
objects that don't have their table's key column in their
|
||||
property lists will be flagged as read-only. */
|
||||
var $_readonly = false;
|
||||
|
||||
/** function or method that implements a validator for fields that
|
||||
are set, this validator function returns true if the field is
|
||||
valid, false if not */
|
||||
var $_validator = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $table string the name of the database table
|
||||
*
|
||||
* @param $keycolumn mixed string with name of key column, or array of
|
||||
* strings if the table has a primary key of more than one column
|
||||
*
|
||||
* @param $dbh object database connection object
|
||||
*
|
||||
* @param $validator mixed function or method used to validate
|
||||
* each new value, called with three parameters: the name of the
|
||||
* field/column that is changing, a reference to the new value and
|
||||
* a reference to this object
|
||||
*
|
||||
*/
|
||||
function DB_storage($table, $keycolumn, &$dbh, $validator = null)
|
||||
{
|
||||
$this->PEAR('DB_Error');
|
||||
$this->_table = $table;
|
||||
$this->_keycolumn = $keycolumn;
|
||||
$this->_dbh = $dbh;
|
||||
$this->_readonly = false;
|
||||
$this->_validator = $validator;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _makeWhere()
|
||||
|
||||
/**
|
||||
* Utility method to build a "WHERE" clause to locate ourselves in
|
||||
* the table.
|
||||
*
|
||||
* XXX future improvement: use rowids?
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _makeWhere($keyval = null)
|
||||
{
|
||||
if (is_array($this->_keycolumn)) {
|
||||
if ($keyval === null) {
|
||||
for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
|
||||
$keyval[] = $this->{$this->_keycolumn[$i]};
|
||||
}
|
||||
}
|
||||
$whereclause = '';
|
||||
for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
|
||||
if ($i > 0) {
|
||||
$whereclause .= ' AND ';
|
||||
}
|
||||
$whereclause .= $this->_keycolumn[$i];
|
||||
if (is_null($keyval[$i])) {
|
||||
// there's not much point in having a NULL key,
|
||||
// but we support it anyway
|
||||
$whereclause .= ' IS NULL';
|
||||
} else {
|
||||
$whereclause .= ' = ' . $this->_dbh->quote($keyval[$i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($keyval === null) {
|
||||
$keyval = @$this->{$this->_keycolumn};
|
||||
}
|
||||
$whereclause = $this->_keycolumn;
|
||||
if (is_null($keyval)) {
|
||||
// there's not much point in having a NULL key,
|
||||
// but we support it anyway
|
||||
$whereclause .= ' IS NULL';
|
||||
} else {
|
||||
$whereclause .= ' = ' . $this->_dbh->quote($keyval);
|
||||
}
|
||||
}
|
||||
return $whereclause;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setup()
|
||||
|
||||
/**
|
||||
* Method used to initialize a DB_storage object from the
|
||||
* configured table.
|
||||
*
|
||||
* @param $keyval mixed the key[s] of the row to fetch (string or array)
|
||||
*
|
||||
* @return int DB_OK on success, a DB error if not
|
||||
*/
|
||||
function setup($keyval)
|
||||
{
|
||||
$whereclause = $this->_makeWhere($keyval);
|
||||
$query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause;
|
||||
$sth = $this->_dbh->query($query);
|
||||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
|
||||
if (DB::isError($row)) {
|
||||
return $row;
|
||||
}
|
||||
if (!$row) {
|
||||
return $this->raiseError(null, DB_ERROR_NOT_FOUND, null, null,
|
||||
$query, null, true);
|
||||
}
|
||||
foreach ($row as $key => $value) {
|
||||
$this->_properties[$key] = true;
|
||||
$this->$key = $value;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ insert()
|
||||
|
||||
/**
|
||||
* Create a new (empty) row in the configured table for this
|
||||
* object.
|
||||
*/
|
||||
function insert($newpk)
|
||||
{
|
||||
if (is_array($this->_keycolumn)) {
|
||||
$primarykey = $this->_keycolumn;
|
||||
} else {
|
||||
$primarykey = array($this->_keycolumn);
|
||||
}
|
||||
settype($newpk, "array");
|
||||
for ($i = 0; $i < sizeof($primarykey); $i++) {
|
||||
$pkvals[] = $this->_dbh->quote($newpk[$i]);
|
||||
}
|
||||
|
||||
$sth = $this->_dbh->query("INSERT INTO $this->_table (" .
|
||||
implode(",", $primarykey) . ") VALUES(" .
|
||||
implode(",", $pkvals) . ")");
|
||||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
if (sizeof($newpk) == 1) {
|
||||
$newpk = $newpk[0];
|
||||
}
|
||||
$this->setup($newpk);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
|
||||
/**
|
||||
* Output a simple description of this DB_storage object.
|
||||
* @return string object description
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$info = strtolower(get_class($this));
|
||||
$info .= " (table=";
|
||||
$info .= $this->_table;
|
||||
$info .= ", keycolumn=";
|
||||
if (is_array($this->_keycolumn)) {
|
||||
$info .= "(" . implode(",", $this->_keycolumn) . ")";
|
||||
} else {
|
||||
$info .= $this->_keycolumn;
|
||||
}
|
||||
$info .= ", dbh=";
|
||||
if (is_object($this->_dbh)) {
|
||||
$info .= $this->_dbh->toString();
|
||||
} else {
|
||||
$info .= "null";
|
||||
}
|
||||
$info .= ")";
|
||||
if (sizeof($this->_properties)) {
|
||||
$info .= " [loaded, key=";
|
||||
$keyname = $this->_keycolumn;
|
||||
if (is_array($keyname)) {
|
||||
$info .= "(";
|
||||
for ($i = 0; $i < sizeof($keyname); $i++) {
|
||||
if ($i > 0) {
|
||||
$info .= ",";
|
||||
}
|
||||
$info .= $this->$keyname[$i];
|
||||
}
|
||||
$info .= ")";
|
||||
} else {
|
||||
$info .= $this->$keyname;
|
||||
}
|
||||
$info .= "]";
|
||||
}
|
||||
if (sizeof($this->_changes)) {
|
||||
$info .= " [modified]";
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dump()
|
||||
|
||||
/**
|
||||
* Dump the contents of this object to "standard output".
|
||||
*/
|
||||
function dump()
|
||||
{
|
||||
foreach ($this->_properties as $prop => $foo) {
|
||||
print "$prop = ";
|
||||
print htmlentities($this->$prop);
|
||||
print "<br />\n";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &create()
|
||||
|
||||
/**
|
||||
* Static method used to create new DB storage objects.
|
||||
* @param $data assoc. array where the keys are the names
|
||||
* of properties/columns
|
||||
* @return object a new instance of DB_storage or a subclass of it
|
||||
*/
|
||||
function &create($table, &$data)
|
||||
{
|
||||
$classname = strtolower(get_class($this));
|
||||
$obj =& new $classname($table);
|
||||
foreach ($data as $name => $value) {
|
||||
$obj->_properties[$name] = true;
|
||||
$obj->$name = &$value;
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ loadFromQuery()
|
||||
|
||||
/**
|
||||
* Loads data into this object from the given query. If this
|
||||
* object already contains table data, changes will be saved and
|
||||
* the object re-initialized first.
|
||||
*
|
||||
* @param $query SQL query
|
||||
*
|
||||
* @param $params parameter list in case you want to use
|
||||
* prepare/execute mode
|
||||
*
|
||||
* @return int DB_OK on success, DB_WARNING_READ_ONLY if the
|
||||
* returned object is read-only (because the object's specified
|
||||
* key column was not found among the columns returned by $query),
|
||||
* or another DB error code in case of errors.
|
||||
*/
|
||||
// XXX commented out for now
|
||||
/*
|
||||
function loadFromQuery($query, $params = null)
|
||||
{
|
||||
if (sizeof($this->_properties)) {
|
||||
if (sizeof($this->_changes)) {
|
||||
$this->store();
|
||||
$this->_changes = array();
|
||||
}
|
||||
$this->_properties = array();
|
||||
}
|
||||
$rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params);
|
||||
if (DB::isError($rowdata)) {
|
||||
return $rowdata;
|
||||
}
|
||||
reset($rowdata);
|
||||
$found_keycolumn = false;
|
||||
while (list($key, $value) = each($rowdata)) {
|
||||
if ($key == $this->_keycolumn) {
|
||||
$found_keycolumn = true;
|
||||
}
|
||||
$this->_properties[$key] = true;
|
||||
$this->$key = &$value;
|
||||
unset($value); // have to unset, or all properties will
|
||||
// refer to the same value
|
||||
}
|
||||
if (!$found_keycolumn) {
|
||||
$this->_readonly = true;
|
||||
return DB_WARNING_READ_ONLY;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
// }}}
|
||||
// {{{ set()
|
||||
|
||||
/**
|
||||
* Modify an attriute value.
|
||||
*/
|
||||
function set($property, $newvalue)
|
||||
{
|
||||
// only change if $property is known and object is not
|
||||
// read-only
|
||||
if ($this->_readonly) {
|
||||
return $this->raiseError(null, DB_WARNING_READ_ONLY, null,
|
||||
null, null, null, true);
|
||||
}
|
||||
if (@isset($this->_properties[$property])) {
|
||||
if (empty($this->_validator)) {
|
||||
$valid = true;
|
||||
} else {
|
||||
$valid = @call_user_func($this->_validator,
|
||||
$this->_table,
|
||||
$property,
|
||||
$newvalue,
|
||||
$this->$property,
|
||||
$this);
|
||||
}
|
||||
if ($valid) {
|
||||
$this->$property = $newvalue;
|
||||
if (empty($this->_changes[$property])) {
|
||||
$this->_changes[$property] = 0;
|
||||
} else {
|
||||
$this->_changes[$property]++;
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError(null, DB_ERROR_INVALID, null,
|
||||
null, "invalid field: $property",
|
||||
null, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null,
|
||||
null, "unknown field: $property",
|
||||
null, true);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &get()
|
||||
|
||||
/**
|
||||
* Fetch an attribute value.
|
||||
*
|
||||
* @param string attribute name
|
||||
*
|
||||
* @return attribute contents, or null if the attribute name is
|
||||
* unknown
|
||||
*/
|
||||
function &get($property)
|
||||
{
|
||||
// only return if $property is known
|
||||
if (isset($this->_properties[$property])) {
|
||||
return $this->$property;
|
||||
}
|
||||
$tmp = null;
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _DB_storage()
|
||||
|
||||
/**
|
||||
* Destructor, calls DB_storage::store() if there are changes
|
||||
* that are to be kept.
|
||||
*/
|
||||
function _DB_storage()
|
||||
{
|
||||
if (sizeof($this->_changes)) {
|
||||
$this->store();
|
||||
}
|
||||
$this->_properties = array();
|
||||
$this->_changes = array();
|
||||
$this->_table = null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ store()
|
||||
|
||||
/**
|
||||
* Stores changes to this object in the database.
|
||||
*
|
||||
* @return DB_OK or a DB error
|
||||
*/
|
||||
function store()
|
||||
{
|
||||
foreach ($this->_changes as $name => $foo) {
|
||||
$params[] = &$this->$name;
|
||||
$vars[] = $name . ' = ?';
|
||||
}
|
||||
if ($vars) {
|
||||
$query = 'UPDATE ' . $this->_table . ' SET ' .
|
||||
implode(', ', $vars) . ' WHERE ' .
|
||||
$this->_makeWhere();
|
||||
$stmt = $this->_dbh->prepare($query);
|
||||
$res = $this->_dbh->execute($stmt, $params);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
$this->_changes = array();
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ remove()
|
||||
|
||||
/**
|
||||
* Remove the row represented by this object from the database.
|
||||
*
|
||||
* @return mixed DB_OK or a DB error
|
||||
*/
|
||||
function remove()
|
||||
{
|
||||
if ($this->_readonly) {
|
||||
return $this->raiseError(null, DB_WARNING_READ_ONLY, null,
|
||||
null, null, null, true);
|
||||
}
|
||||
$query = 'DELETE FROM ' . $this->_table .' WHERE '.
|
||||
$this->_makeWhere();
|
||||
$res = $this->_dbh->query($query);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
foreach ($this->_properties as $prop => $foo) {
|
||||
unset($this->$prop);
|
||||
}
|
||||
$this->_properties = array();
|
||||
$this->_changes = array();
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
835
thirdparty/pear/DB/sybase.php
vendored
835
thirdparty/pear/DB/sybase.php
vendored
@@ -1,835 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Sterling Hughes <sterling@php.net> |
|
||||
// | Ant<6E>nio Carlos Ven<65>ncio J<>nior <floripa@php.net> |
|
||||
// | Maintainer: Daniel Convissor <danielc@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: sybase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
|
||||
|
||||
// TODO
|
||||
// - This driver may fail with multiple connections under the same
|
||||
// user/pass/host and different databases
|
||||
|
||||
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* Database independent query interface definition for PHP's Sybase
|
||||
* extension.
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: sybase.php 3355 2005-06-11 22:14:40Z nbm $
|
||||
* @category Database
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Ant<6E>nio Carlos Ven<65>ncio J<>nior <floripa@php.net>
|
||||
*/
|
||||
class DB_sybase extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
var $connection;
|
||||
var $phptype, $dbsyntax;
|
||||
var $prepare_tokens = array();
|
||||
var $prepare_types = array();
|
||||
var $transaction_opcount = 0;
|
||||
var $autocommit = true;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* DB_sybase constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function DB_sybase()
|
||||
{
|
||||
$this->DB_common();
|
||||
$this->phptype = 'sybase';
|
||||
$this->dbsyntax = 'sybase';
|
||||
$this->features = array(
|
||||
'prepare' => false,
|
||||
'pconnect' => true,
|
||||
'transactions' => false,
|
||||
'limit' => 'emulate'
|
||||
);
|
||||
$this->errorcode_map = array(
|
||||
);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to a database and log in as the specified user.
|
||||
*
|
||||
* @param $dsn the data source name (see DB::parseDSN for syntax)
|
||||
* @param $persistent (optional) whether the connection should
|
||||
* be persistent
|
||||
* @access public
|
||||
* @return int DB_OK on success, a DB error on failure
|
||||
*/
|
||||
function connect($dsninfo, $persistent = false)
|
||||
{
|
||||
if (!DB::assertExtension('sybase') &&
|
||||
!DB::assertExtension('sybase_ct'))
|
||||
{
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsninfo;
|
||||
|
||||
$interface = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
|
||||
$connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
|
||||
$dsninfo['password'] = !empty($dsninfo['password']) ? $dsninfo['password'] : false;
|
||||
$dsninfo['charset'] = isset($dsninfo['charset']) ? $dsninfo['charset'] : false;
|
||||
$dsninfo['appname'] = isset($dsninfo['appname']) ? $dsninfo['appname'] : false;
|
||||
|
||||
if ($interface && $dsninfo['username']) {
|
||||
$conn = @$connect_function($interface, $dsninfo['username'],
|
||||
$dsninfo['password'],
|
||||
$dsninfo['charset'],
|
||||
$dsninfo['appname']);
|
||||
} else {
|
||||
$conn = false;
|
||||
}
|
||||
|
||||
if (!$conn) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED);
|
||||
}
|
||||
|
||||
if ($dsninfo['database']) {
|
||||
if (!@sybase_select_db($dsninfo['database'], $conn)) {
|
||||
return $this->raiseError(DB_ERROR_NODBSELECTED, null,
|
||||
null, null, @sybase_get_last_message());
|
||||
}
|
||||
$this->_db = $dsninfo['database'];
|
||||
}
|
||||
|
||||
$this->connection = $conn;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Log out and disconnect from the database.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if not connected.
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @sybase_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Get the last server error messge (if any)
|
||||
*
|
||||
* @return string sybase last error message
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
return @sybase_get_last_message();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorCode()
|
||||
|
||||
/**
|
||||
* Determine PEAR::DB error code from the database's text error message.
|
||||
*
|
||||
* @param string $errormsg error message returned from the database
|
||||
* @return integer an error number from a DB error constant
|
||||
*/
|
||||
function errorCode($errormsg)
|
||||
{
|
||||
static $error_regexps;
|
||||
if (!isset($error_regexps)) {
|
||||
$error_regexps = array(
|
||||
'/Incorrect syntax near/'
|
||||
=> DB_ERROR_SYNTAX,
|
||||
'/^Unclosed quote before the character string [\"\'].*[\"\']\./'
|
||||
=> DB_ERROR_SYNTAX,
|
||||
'/Implicit conversion from datatype [\"\'].+[\"\'] to [\"\'].+[\"\'] is not allowed\./'
|
||||
=> DB_ERROR_INVALID_NUMBER,
|
||||
'/Cannot drop the table [\"\'].+[\"\'], because it doesn\'t exist in the system catalogs\./'
|
||||
=> DB_ERROR_NOSUCHTABLE,
|
||||
'/Only the owner of object [\"\'].+[\"\'] or a user with System Administrator \(SA\) role can run this command\./'
|
||||
=> DB_ERROR_ACCESS_VIOLATION,
|
||||
'/^.+ permission denied on object .+, database .+, owner .+/'
|
||||
=> DB_ERROR_ACCESS_VIOLATION,
|
||||
'/^.* permission denied, database .+, owner .+/'
|
||||
=> DB_ERROR_ACCESS_VIOLATION,
|
||||
'/[^.*] not found\./'
|
||||
=> DB_ERROR_NOSUCHTABLE,
|
||||
'/There is already an object named/'
|
||||
=> DB_ERROR_ALREADY_EXISTS,
|
||||
'/Invalid column name/'
|
||||
=> DB_ERROR_NOSUCHFIELD,
|
||||
'/does not allow null values/'
|
||||
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'/Command has been aborted/'
|
||||
=> DB_ERROR_CONSTRAINT,
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($error_regexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $errormsg)) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
return DB_ERROR;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ sybaseRaiseError()
|
||||
|
||||
/**
|
||||
* Gather information about an error, then use that info to create a
|
||||
* DB error object and finally return that object.
|
||||
*
|
||||
* @param integer $errno PEAR error number (usually a DB constant) if
|
||||
* manually raising an error
|
||||
* @return object DB error object
|
||||
* @see errorNative()
|
||||
* @see errorCode()
|
||||
* @see DB_common::raiseError()
|
||||
*/
|
||||
function sybaseRaiseError($errno = null)
|
||||
{
|
||||
$native = $this->errorNative();
|
||||
if ($errno === null) {
|
||||
$errno = $this->errorCode($native);
|
||||
}
|
||||
return $this->raiseError($errno, null, null, null, $native);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Send a query to Sybase and return the results as a Sybase resource
|
||||
* identifier.
|
||||
*
|
||||
* @param the SQL query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return mixed returns a valid Sybase result for successful SELECT
|
||||
* queries, DB_OK for other successful queries. A DB error is
|
||||
* returned on failure.
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = DB::isManip($query);
|
||||
$this->last_query = $query;
|
||||
if (!@sybase_select_db($this->_db, $this->connection)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$query = $this->modifyQuery($query);
|
||||
if (!$this->autocommit && $ismanip) {
|
||||
if ($this->transaction_opcount == 0) {
|
||||
$result = @sybase_query('BEGIN TRANSACTION', $this->connection);
|
||||
if (!$result) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
}
|
||||
$this->transaction_opcount++;
|
||||
}
|
||||
$result = @sybase_query($query, $this->connection);
|
||||
if (!$result) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
if (is_resource($result)) {
|
||||
$numrows = $this->numRows($result);
|
||||
if (is_object($numrows)) {
|
||||
return $numrows;
|
||||
}
|
||||
$this->num_rows[(int)$result] = $numrows;
|
||||
return $result;
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
return $ismanip ? DB_OK : $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal sybase result pointer to the next available result
|
||||
*
|
||||
* @param a valid sybase result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Fetch a row and insert the data into an existing array.
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* @param resource $result query result identifier
|
||||
* @param array $arr (reference) array where data from the row
|
||||
* should be placed
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch
|
||||
*
|
||||
* @return mixed DB_OK on success, null when end of result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
* @access private
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum=null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@sybase_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
if (function_exists('sybase_fetch_assoc')) {
|
||||
$arr = @sybase_fetch_assoc($result);
|
||||
} else {
|
||||
if ($arr = @sybase_fetch_array($result)) {
|
||||
foreach ($arr as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
unset($arr[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @sybase_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
// reported not work as seems that sybase_get_last_message()
|
||||
// always return a message here
|
||||
//if ($errmsg = @sybase_get_last_message()) {
|
||||
// return $this->sybaseRaiseError($errmsg);
|
||||
//} else {
|
||||
return null;
|
||||
//}
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Free the internal resources associated with $result.
|
||||
*
|
||||
* @param $result Sybase result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return bool true on success, false if $result is invalid
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
unset($this->num_rows[(int)$result]);
|
||||
return @sybase_free_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Get the number of columns in a result set.
|
||||
*
|
||||
* @param $result Sybase result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of columns per row in $result
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @sybase_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Get the number of rows in a result set.
|
||||
*
|
||||
* @param $result Sybase result identifier
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int the number of rows in $result
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @sybase_num_rows($result);
|
||||
if ($rows === false) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows affected by the data manipulation
|
||||
* query. For other queries, this function returns 0.
|
||||
*
|
||||
* @return number of rows affected by the last query
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (DB::isManip($this->last_query)) {
|
||||
$result = @sybase_affected_rows($this->connection);
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence. DB_Error if problem.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::nextID()
|
||||
* @access public
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
if (!@sybase_select_db($this->_db, $this->connection)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("INSERT INTO $seqname (vapor) VALUES (0)");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
($result->getCode() == DB_ERROR || $result->getCode() == DB_ERROR_NOSUCHTABLE))
|
||||
{
|
||||
$repeat = 1;
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
} elseif (!DB::isError($result)) {
|
||||
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
$repeat = 0;
|
||||
} else {
|
||||
$repeat = false;
|
||||
}
|
||||
} while ($repeat);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$result = $result->fetchRow(DB_FETCHMODE_ORDERED);
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object is returned if
|
||||
* problems arise.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::createSequence()
|
||||
* @access public
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("CREATE TABLE $seqname ".
|
||||
'(id numeric(10,0) IDENTITY NOT NULL ,' .
|
||||
'vapor int NULL)');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. DB_Error if problems.
|
||||
*
|
||||
* @internal
|
||||
* @see DB_common::dropSequence()
|
||||
* @access public
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
return $this->query("DROP TABLE $seqname");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Returns the query needed to get some backend info
|
||||
* @param string $type What kind of info you want to retrieve
|
||||
* @return string The SQL query string
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return "select name from sysobjects where type = 'U' order by name";
|
||||
case 'views':
|
||||
return "select name from sysobjects where type = 'V'";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enable/disable automatic commits
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
$this->autocommit = $onoff ? true : false;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@sybase_select_db($this->_db, $this->connection)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @sybase_query('COMMIT', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Roll back (undo) the current transaction.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@sybase_select_db($this->_db, $this->connection)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @sybase_query('ROLLBACK', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->sybaseRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set.
|
||||
*
|
||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||
* is a table name.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table
|
||||
* @param int $mode a valid tableInfo mode
|
||||
* @return array an associative array with the information requested
|
||||
* or an error object if something is wrong
|
||||
* @access public
|
||||
* @internal
|
||||
* @since 1.6.0
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} elseif (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
if (!@sybase_select_db($this->_db, $this->connection)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$id = @sybase_query("SELECT * FROM $result WHERE 1=0",
|
||||
$this->connection);
|
||||
$got_string = true;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->sybaseRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @sybase_num_fields($id);
|
||||
|
||||
// made this IF due to performance (one if is faster than $count if's)
|
||||
if (!$mode) {
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$f = @sybase_fetch_field($id, $i);
|
||||
|
||||
// column_source is often blank
|
||||
if ($got_string) {
|
||||
$res[$i]['table'] = $case_func($result);
|
||||
} else {
|
||||
$res[$i]['table'] = $case_func($f->column_source);
|
||||
}
|
||||
$res[$i]['name'] = $case_func($f->name);
|
||||
$res[$i]['type'] = $f->type;
|
||||
$res[$i]['len'] = $f->max_length;
|
||||
if ($res[$i]['table']) {
|
||||
$res[$i]['flags'] = $this->_sybase_field_flags(
|
||||
$res[$i]['table'], $res[$i]['name']);
|
||||
} else {
|
||||
$res[$i]['flags'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// get full info
|
||||
|
||||
$res['num_fields'] = $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$f = @sybase_fetch_field($id, $i);
|
||||
|
||||
// column_source is often blank
|
||||
if ($got_string) {
|
||||
$res[$i]['table'] = $case_func($result);
|
||||
} else {
|
||||
$res[$i]['table'] = $case_func($f->column_source);
|
||||
}
|
||||
$res[$i]['name'] = $case_func($f->name);
|
||||
$res[$i]['type'] = $f->type;
|
||||
$res[$i]['len'] = $f->max_length;
|
||||
if ($res[$i]['table']) {
|
||||
$res[$i]['flags'] = $this->_sybase_field_flags(
|
||||
$res[$i]['table'], $res[$i]['name']);
|
||||
} else {
|
||||
$res[$i]['flags'] = '';
|
||||
}
|
||||
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@sybase_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _sybase_field_flags()
|
||||
|
||||
/**
|
||||
* Get the flags for a field.
|
||||
*
|
||||
* Currently supports:
|
||||
* + <samp>unique_key</samp> (unique index, unique check or primary_key)
|
||||
* + <samp>multiple_key</samp> (multi-key index)
|
||||
*
|
||||
* @param string $table table name
|
||||
* @param string $column field name
|
||||
* @return string space delimited string of flags. Empty string if none.
|
||||
* @access private
|
||||
*/
|
||||
function _sybase_field_flags($table, $column)
|
||||
{
|
||||
static $tableName = null;
|
||||
static $flags = array();
|
||||
|
||||
if ($table != $tableName) {
|
||||
$flags = array();
|
||||
$tableName = $table;
|
||||
|
||||
// get unique/primary keys
|
||||
$res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC);
|
||||
|
||||
if (!isset($res[0]['index_description'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($res as $val) {
|
||||
$keys = explode(', ', trim($val['index_keys']));
|
||||
|
||||
if (sizeof($keys) > 1) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'multiple_key');
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($val['index_description'], 'unique')) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'unique_key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (array_key_exists($column, $flags)) {
|
||||
return(implode(' ', $flags[$column]));
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _add_flag()
|
||||
|
||||
/**
|
||||
* Adds a string to the flags array if the flag is not yet in there
|
||||
* - if there is no flag present the array is created.
|
||||
*
|
||||
* @param array $array reference of flags array to add a value to
|
||||
* @param mixed $value value to add to the flag array
|
||||
* @access private
|
||||
*/
|
||||
function _add_flag(&$array, $value)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
$array = array($value);
|
||||
} elseif (!in_array($value, $array)) {
|
||||
array_push($array, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteIdentifier()
|
||||
|
||||
/**
|
||||
* Quote a string so it can be safely used as a table / column name
|
||||
*
|
||||
* Quoting style depends on which database driver is being used.
|
||||
*
|
||||
* @param string $str identifier name to be quoted
|
||||
*
|
||||
* @return string quoted identifier string
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @access public
|
||||
*/
|
||||
function quoteIdentifier($str)
|
||||
{
|
||||
return '[' . str_replace(']', ']]', $str) . ']';
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
343
thirdparty/pear/HTTP/HTTP.php
vendored
343
thirdparty/pear/HTTP/HTTP.php
vendored
@@ -1,343 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PEAR :: HTTP |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is available at http://www.php.net/license/3_0.txt |
|
||||
// | If you did not receive a copy of the PHP license and are unable |
|
||||
// | to obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@fast.no> |
|
||||
// | Sterling Hughes <sterling@php.net> |
|
||||
// | Tomas V.V.Cox <cox@idecnet.com> |
|
||||
// | Richard Heyes <richard@php.net> |
|
||||
// | Philippe Jausions <Philippe.Jausions@11abacus.com> |
|
||||
// | Michael Wallner <mike@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: HTTP.php,v 1.35 2004/09/21 15:28:07 mike Exp $
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
*
|
||||
* HTTP utility functions
|
||||
*
|
||||
* @package HTTP
|
||||
* @category HTTP
|
||||
* @license PHP License
|
||||
* @access public
|
||||
* @version $Revision: 1.35 $
|
||||
*/
|
||||
class HTTP
|
||||
{
|
||||
/**
|
||||
* Date
|
||||
*
|
||||
* Format a RFC compliant GMT date HTTP header. This function honors the
|
||||
* "y2k_compliance" php.ini directive and formats the GMT date corresponding
|
||||
* to either RFC850 or RFC822.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return mixed GMT date string, or false for an invalid $time parameter
|
||||
* @param mixed $time unix timestamp or date (default = current time)
|
||||
*/
|
||||
function Date($time = null)
|
||||
{
|
||||
if (!isset($time)) {
|
||||
$time = time();
|
||||
} elseif (!is_numeric($time) && (-1 === $time = strtotime($time))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// RFC822 or RFC850
|
||||
$format = ini_get('y2k_compliance') ? 'D, d M Y' : 'l, d-M-y';
|
||||
|
||||
return gmdate($format .' H:i:s \G\M\T', $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negotiate Language
|
||||
*
|
||||
* Negotiate language with the user's browser through the Accept-Language
|
||||
* HTTP header or the user's host address. Language codes are generally in
|
||||
* the form "ll" for a language spoken in only one country, or "ll-CC" for a
|
||||
* language spoken in a particular country. For example, U.S. English is
|
||||
* "en-US", while British English is "en-UK". Portugese as spoken in
|
||||
* Portugal is "pt-PT", while Brazilian Portugese is "pt-BR".
|
||||
*
|
||||
* Quality factors in the Accept-Language: header are supported, e.g.:
|
||||
* Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8
|
||||
*
|
||||
* <code>
|
||||
* require_once 'HTTP.php';
|
||||
* $langs = array(
|
||||
* 'en' => 'locales/en',
|
||||
* 'en-US'=> 'locales/en',
|
||||
* 'en-UK'=> 'locales/en',
|
||||
* 'de' => 'locales/de',
|
||||
* 'de-DE'=> 'locales/de',
|
||||
* 'de-AT'=> 'locales/de',
|
||||
* );
|
||||
* $neg = HTTP::negotiateLanguage($langs);
|
||||
* $dir = $langs[$neg];
|
||||
* </code>
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string The negotiated language result or the supplied default.
|
||||
* @param array $supported An associative array of supported languages,
|
||||
* whose values must evaluate to true.
|
||||
* @param string $default The default language to use if none is found.
|
||||
*/
|
||||
function negotiateLanguage($supported, $default = 'en-US')
|
||||
{
|
||||
$supp = array();
|
||||
foreach ($supported as $lang => $isSupported) {
|
||||
if ($isSupported) {
|
||||
$supp[strToLower($lang)] = $lang;
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($supp)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) {
|
||||
@list($l, $q) = array_map('strtolower',
|
||||
array_map('trim', explode(';', $lang)));
|
||||
if (isset($supp[$l])) {
|
||||
if (isset($q)) {
|
||||
$matches[$l] = (float) str_replace('q=', '', $q);
|
||||
} else {
|
||||
$matches[$l] = 1000 - count($matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($matches)) {
|
||||
asort($matches, SORT_NUMERIC);
|
||||
return $supp[array_pop(array_keys($matches))];
|
||||
}
|
||||
|
||||
if (isset($_SERVER['REMOTE_HOST'])) {
|
||||
$lang = strtolower(array_pop(explode('.', $_SERVER['REMOTE_HOST'])));
|
||||
if (isset($supp[$lang])) {
|
||||
return $supp[$lang];
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Head
|
||||
*
|
||||
* Sends a "HEAD" HTTP command to a server and returns the headers
|
||||
* as an associative array. Example output could be:
|
||||
* <code>
|
||||
* Array
|
||||
* (
|
||||
* [response_code] => 200 // The HTTP response code
|
||||
* [response] => HTTP/1.1 200 OK // The full HTTP response string
|
||||
* [Date] => Fri, 11 Jan 2002 01:41:44 GMT
|
||||
* [Server] => Apache/1.3.20 (Unix) PHP/4.1.1
|
||||
* [X-Powered-By] => PHP/4.1.1
|
||||
* [Connection] => close
|
||||
* [Content-Type] => text/html
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @see HTTP_Client::head()
|
||||
* @see HTTP_Request
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return mixed Returns associative array of response headers on success
|
||||
* or PEAR error on failure.
|
||||
* @param string $url A valid URL, e.g.: http://pear.php.net/credits.php
|
||||
* @param integer $timeout Timeout in seconds (default = 10)
|
||||
*/
|
||||
function head($url, $timeout = 10)
|
||||
{
|
||||
$p = parse_url($url);
|
||||
if (!isset($p['scheme'])) {
|
||||
$p = parse_url(HTTP::absoluteURI($url));
|
||||
} elseif ($p['scheme'] != 'http') {
|
||||
return HTTP::raiseError('Unsupported protocol: '. $p['scheme']);
|
||||
}
|
||||
|
||||
$port = isset($p['port']) ? $p['port'] : 80;
|
||||
|
||||
if (!$fp = @fsockopen($p['host'], $port, $eno, $estr, $timeout)) {
|
||||
return HTTP::raiseError("Connection error: $estr ($eno)");
|
||||
}
|
||||
|
||||
$path = !empty($p['path']) ? $p['path'] : '/';
|
||||
$path .= !empty($p['query']) ? '?' . $p['query'] : '';
|
||||
|
||||
fputs($fp, "HEAD $path HTTP/1.0\r\n");
|
||||
fputs($fp, 'Host: ' . $p['host'] . ':' . $port . "\r\n");
|
||||
fputs($fp, "Connection: close\r\n\r\n");
|
||||
|
||||
$response = rtrim(fgets($fp, 4096));
|
||||
if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $response, $status)) {
|
||||
$headers['response_code'] = $status[1];
|
||||
}
|
||||
$headers['response'] = $response;
|
||||
|
||||
while ($line = fgets($fp, 4096)) {
|
||||
if (!trim($line)) {
|
||||
break;
|
||||
}
|
||||
if (($pos = strpos($line, ':')) !== false) {
|
||||
$header = substr($line, 0, $pos);
|
||||
$value = trim(substr($line, $pos + 1));
|
||||
$headers[$header] = $value;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* This function redirects the client. This is done by issuing
|
||||
* a "Location" header and exiting if wanted. If you set $rfc2616 to true
|
||||
* HTTP will output a hypertext note with the location of the redirect.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return mixed Returns true on succes (or exits) or false if headers
|
||||
* have already been sent.
|
||||
* @param string $url URL where the redirect should go to.
|
||||
* @param bool $exit Whether to exit immediately after redirection.
|
||||
* @param bool $rfc2616 Wheter to output a hypertext note where we're
|
||||
* redirecting to (Redirecting to <a href="...">...</a>.)
|
||||
*/
|
||||
function redirect($url, $exit = true, $rfc2616 = false)
|
||||
{
|
||||
if (headers_sent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = HTTP::absoluteURI($url);
|
||||
header('Location: '. $url);
|
||||
|
||||
if ($rfc2616 && @$_SERVER['REQUEST_METHOD'] != 'HEAD') {
|
||||
printf('Redirecting to: <a href="%s">%s</a>.', $url, $url);
|
||||
}
|
||||
if ($exit) {
|
||||
exit;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute URI
|
||||
*
|
||||
* This function returns the absolute URI for the partial URL passed.
|
||||
* The current scheme (HTTP/HTTPS), host server, port, current script
|
||||
* location are used if necessary to resolve any relative URLs.
|
||||
*
|
||||
* Offsets potentially created by PATH_INFO are taken care of to resolve
|
||||
* relative URLs to the current script.
|
||||
*
|
||||
* You can choose a new protocol while resolving the URI. This is
|
||||
* particularly useful when redirecting a web browser using relative URIs
|
||||
* and to switch from HTTP to HTTPS, or vice-versa, at the same time.
|
||||
*
|
||||
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
|
||||
* @static
|
||||
* @access public
|
||||
* @return string The absolute URI.
|
||||
* @param string $url Absolute or relative URI the redirect should go to.
|
||||
* @param string $protocol Protocol to use when redirecting URIs.
|
||||
* @param integer $port A new port number.
|
||||
*/
|
||||
function absoluteURI($url = null, $protocol = null, $port = null)
|
||||
{
|
||||
// Mess around with already absolute URIs
|
||||
if (preg_match('!^([a-z0-9]+)://!i', $url)) {
|
||||
if (empty($protocol) && empty($port)) {
|
||||
return $url;
|
||||
}
|
||||
if (!empty($protocol)) {
|
||||
$url = $protocol .':'. array_pop(explode(':', $url, 2));
|
||||
}
|
||||
if (!empty($port)) {
|
||||
$url = preg_replace('!^(([a-z0-9]+)://[^/:]+)(:[\d]+)?!i',
|
||||
'\1:'. $port, $url);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
$host = 'localhost';
|
||||
if (!empty($_SERVER['HTTP_HOST'])) {
|
||||
list($host) = explode(':', $_SERVER['HTTP_HOST']);
|
||||
} elseif (!empty($_SERVER['SERVER_NAME'])) {
|
||||
list($host) = explode(':', $_SERVER['SERVER_NAME']);
|
||||
}
|
||||
|
||||
if (empty($protocol)) {
|
||||
$protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
if (!isset($port) || $port != intval($port)) {
|
||||
$port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
|
||||
}
|
||||
}
|
||||
|
||||
if ($protocol == 'http' && $port == 80) {
|
||||
unset($port);
|
||||
}
|
||||
if ($protocol == 'https' && $port == 443) {
|
||||
unset($port);
|
||||
}
|
||||
|
||||
$server = $protocol .'://'. $host . (isset($port) ? ':'. $port : '');
|
||||
|
||||
if (!strlen($url)) {
|
||||
$url = isset($_SERVER['REQUEST_URI']) ?
|
||||
$_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
|
||||
}
|
||||
|
||||
if ($url{0} == '/') {
|
||||
return $server . $url;
|
||||
}
|
||||
|
||||
// Check for PATH_INFO
|
||||
if (isset($_SERVER['PATH_INFO'])) {
|
||||
$path = dirname(substr($_SERVER['PHP_SELF'], 0, -strlen($_SERVER['PATH_INFO'])));
|
||||
} else {
|
||||
$path = dirname($_SERVER['PHP_SELF']);
|
||||
}
|
||||
|
||||
if (substr($path, -1) != '/') {
|
||||
$path .= '/';
|
||||
}
|
||||
|
||||
return $server . strtr($path, '\\', '/') . $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise Error
|
||||
*
|
||||
* Lazy raising of PEAR_Errors.
|
||||
*
|
||||
* @static
|
||||
* @access protected
|
||||
* @return object PEAR_Error
|
||||
* @param mixed $error
|
||||
* @param int $code
|
||||
*/
|
||||
function raiseError($error = null, $code = null)
|
||||
{
|
||||
require_once 'PEAR.php';
|
||||
return PEAR::raiseError($error, $code);
|
||||
}
|
||||
}
|
||||
?>
|
||||
1205
thirdparty/pear/HTTP/Request.php
vendored
1205
thirdparty/pear/HTTP/Request.php
vendored
File diff suppressed because it is too large
Load Diff
2089
thirdparty/pear/HTTP/WebDAV/Server.php
vendored
2089
thirdparty/pear/HTTP/WebDAV/Server.php
vendored
File diff suppressed because it is too large
Load Diff
720
thirdparty/pear/HTTP/WebDAV/Server/Filesystem.php
vendored
720
thirdparty/pear/HTTP/WebDAV/Server/Filesystem.php
vendored
@@ -1,720 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "HTTP/WebDAV/Server.php";
|
||||
|
||||
/**
|
||||
* Filesystem access using WebDAV
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server
|
||||
{
|
||||
/**
|
||||
* Root directory for WebDAV access
|
||||
*
|
||||
* Defaults to webserver document root (set by ServeRequest)
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $base = "";
|
||||
|
||||
/**
|
||||
* MySQL Host where property and locking information is stored
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $db_host = "localhost";
|
||||
|
||||
/**
|
||||
* MySQL database for property/locking information storage
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $db_name = "webdav";
|
||||
|
||||
/**
|
||||
* MySQL user for property/locking db access
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $db_user = "root";
|
||||
|
||||
/**
|
||||
* MySQL password for property/locking db access
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $db_passwd = "";
|
||||
|
||||
/**
|
||||
* Serve a webdav request
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
*/
|
||||
function ServeRequest($base = false)
|
||||
{
|
||||
// special treatment for litmus compliance test
|
||||
// reply on its identifier header
|
||||
// not needed for the test itself but eases debugging
|
||||
if (function_exists("apache_request_headers")) {
|
||||
foreach(apache_request_headers() as $key => $value) {
|
||||
if (stristr($key,"litmus")) {
|
||||
error_log("Litmus test $value");
|
||||
header("X-Litmus-reply: ".$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set root directory, defaults to webserver document root if not set
|
||||
if ($base) {
|
||||
$this->base = realpath($base); // TODO throw if not a directory
|
||||
} else if (!$this->base) {
|
||||
$this->base = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
// establish connection to property/locking db
|
||||
//mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
|
||||
//mysql_select_db($this->db_name) or die(mysql_error());
|
||||
// TODO throw on connection problems
|
||||
|
||||
// let the base class do all the work
|
||||
parent::ServeRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* No authentication is needed here
|
||||
*
|
||||
* @access private
|
||||
* @param string HTTP Authentication type (Basic, Digest, ...)
|
||||
* @param string Username
|
||||
* @param string Password
|
||||
* @return bool true on successful authentication
|
||||
*/
|
||||
function check_auth($type, $user, $pass)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PROPFIND method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @param array return array for file properties
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PROPFIND(&$options, &$files)
|
||||
{
|
||||
// get absolute fs path to requested resource
|
||||
$fspath = $this->base . $options["path"];
|
||||
|
||||
// sanity check
|
||||
if (!file_exists($fspath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare property array
|
||||
$files["files"] = array();
|
||||
|
||||
// store information for the requested path itself
|
||||
$files["files"][] = $this->fileinfo($options["path"]);
|
||||
|
||||
// information for contained resources requested?
|
||||
if (!empty($options["depth"])) { // TODO check for is_dir() first?
|
||||
|
||||
// make sure path ends with '/'
|
||||
$options["path"] = $this->_slashify($options["path"]);
|
||||
|
||||
// try to open directory
|
||||
$handle = @opendir($fspath);
|
||||
|
||||
if ($handle) {
|
||||
// ok, now get all its contents
|
||||
while ($filename = readdir($handle)) {
|
||||
if ($filename != "." && $filename != "..") {
|
||||
$files["files"][] = $this->fileinfo($options["path"].$filename);
|
||||
}
|
||||
}
|
||||
// TODO recursion needed if "Depth: infinite"
|
||||
}
|
||||
}
|
||||
|
||||
// ok, all done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get properties for a single file/resource
|
||||
*
|
||||
* @param string resource path
|
||||
* @return array resource properties
|
||||
*/
|
||||
function fileinfo($path)
|
||||
{
|
||||
// map URI path to filesystem path
|
||||
$fspath = $this->base . $path;
|
||||
|
||||
// create result array
|
||||
$info = array();
|
||||
// TODO remove slash append code when base clase is able to do it itself
|
||||
$info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path;
|
||||
$info["props"] = array();
|
||||
|
||||
// no special beautified displayname here ...
|
||||
$info["props"][] = $this->mkprop("displayname", strtoupper($path));
|
||||
|
||||
// creation and modification time
|
||||
$info["props"][] = $this->mkprop("creationdate", filectime($fspath));
|
||||
$info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
|
||||
|
||||
// type and size (caller already made sure that path exists)
|
||||
if (is_dir($fspath)) {
|
||||
// directory (WebDAV collection)
|
||||
$info["props"][] = $this->mkprop("resourcetype", "collection");
|
||||
$info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
|
||||
} else {
|
||||
// plain file (WebDAV resource)
|
||||
$info["props"][] = $this->mkprop("resourcetype", "");
|
||||
if (is_readable($fspath)) {
|
||||
$info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
|
||||
} else {
|
||||
$info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
|
||||
}
|
||||
$info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
|
||||
}
|
||||
|
||||
// get additional properties from database
|
||||
$query = "SELECT ns, name, value FROM properties WHERE path = '$path'";
|
||||
$res = mysql_query($query);
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
|
||||
}
|
||||
mysql_free_result($res);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* detect if a given program is found in the search PATH
|
||||
*
|
||||
* helper function used by _mimetype() to detect if the
|
||||
* external 'file' utility is available
|
||||
*
|
||||
* @param string program name
|
||||
* @param string optional search path, defaults to $PATH
|
||||
* @return bool true if executable program found in path
|
||||
*/
|
||||
function _can_execute($name, $path = false)
|
||||
{
|
||||
// path defaults to PATH from environment if not set
|
||||
if ($path === false) {
|
||||
$path = getenv("PATH");
|
||||
}
|
||||
|
||||
// check method depends on operating system
|
||||
if (!strncmp(PHP_OS, "WIN", 3)) {
|
||||
// on Windows an appropriate COM or EXE file needs to exist
|
||||
$exts = array(".exe", ".com");
|
||||
$check_fn = "file_exists";
|
||||
} else {
|
||||
// anywhere else we look for an executable file of that name
|
||||
$exts = array("");
|
||||
$check_fn = "is_executable";
|
||||
}
|
||||
|
||||
// now check the directories in the path for the program
|
||||
foreach (explode(PATH_SEPARATOR, $path) as $dir) {
|
||||
// skip invalid path entries
|
||||
if (!file_exists($dir)) continue;
|
||||
if (!is_dir($dir)) continue;
|
||||
|
||||
// and now look for the file
|
||||
foreach ($exts as $ext) {
|
||||
if ($check_fn("$dir/$name".$ext)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* try to detect the mime type of a file
|
||||
*
|
||||
* @param string file path
|
||||
* @return string guessed mime type
|
||||
*/
|
||||
function _mimetype($fspath)
|
||||
{
|
||||
if (@is_dir($fspath)) {
|
||||
// directories are easy
|
||||
return "httpd/unix-directory";
|
||||
} else if (function_exists("mime_content_type")) {
|
||||
// use mime magic extension if available
|
||||
$mime_type = mime_content_type($fspath);
|
||||
} else if ($this->_can_execute("file")) {
|
||||
// it looks like we have a 'file' command,
|
||||
// lets see it it does have mime support
|
||||
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
|
||||
$reply = fgets($fp);
|
||||
pclose($fp);
|
||||
|
||||
// popen will not return an error if the binary was not found
|
||||
// and find may not have mime support using "-i"
|
||||
// so we test the format of the returned string
|
||||
|
||||
// the reply begins with the requested filename
|
||||
if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
|
||||
$reply = substr($reply, strlen($fspath)+2);
|
||||
// followed by the mime type (maybe including options)
|
||||
if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
|
||||
$mime_type = $matches[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($mime_type)) {
|
||||
// Fallback solution: try to guess the type by the file extension
|
||||
// TODO: add more ...
|
||||
// TODO: it has been suggested to delegate mimetype detection
|
||||
// to apache but this has at least three issues:
|
||||
// - works only with apache
|
||||
// - needs file to be within the document tree
|
||||
// - requires apache mod_magic
|
||||
// TODO: can we use the registry for this on Windows?
|
||||
// OTOH if the server is Windos the clients are likely to
|
||||
// be Windows, too, and tend do ignore the Content-Type
|
||||
// anyway (overriding it with information taken from
|
||||
// the registry)
|
||||
// TODO: have a seperate PEAR class for mimetype detection?
|
||||
switch (strtolower(strrchr(basename($fspath), "."))) {
|
||||
case ".html":
|
||||
$mime_type = "text/html";
|
||||
break;
|
||||
case ".gif":
|
||||
$mime_type = "image/gif";
|
||||
break;
|
||||
case ".jpg":
|
||||
$mime_type = "image/jpeg";
|
||||
break;
|
||||
default:
|
||||
$mime_type = "application/octet-stream";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $mime_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET method handler
|
||||
*
|
||||
* @param array parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function GET(&$options)
|
||||
{
|
||||
// get absolute fs path to requested resource
|
||||
$fspath = $this->base . $options["path"];
|
||||
|
||||
// sanity check
|
||||
if (!file_exists($fspath)) return false;
|
||||
|
||||
// is this a collection?
|
||||
if (is_dir($fspath)) {
|
||||
return $this->GetDir($fspath, $options);
|
||||
}
|
||||
|
||||
// detect resource type
|
||||
$options['mimetype'] = $this->_mimetype($fspath);
|
||||
|
||||
// detect modification time
|
||||
// see rfc2518, section 13.7
|
||||
// some clients seem to treat this as a reverse rule
|
||||
// requiering a Last-Modified header if the getlastmodified header was set
|
||||
$options['mtime'] = filemtime($fspath);
|
||||
|
||||
// detect resource size
|
||||
$options['size'] = filesize($fspath);
|
||||
|
||||
// no need to check result here, it is handled by the base class
|
||||
$options['stream'] = fopen($fspath, "r");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET method handler for directories
|
||||
*
|
||||
* This is a very simple mod_index lookalike.
|
||||
* See RFC 2518, Section 8.4 on GET/HEAD for collections
|
||||
*
|
||||
* @param string directory path
|
||||
* @return void function has to handle HTTP response itself
|
||||
*/
|
||||
function GetDir($fspath, &$options)
|
||||
{
|
||||
$path = $this->_slashify($options["path"]);
|
||||
if ($path != $options["path"]) {
|
||||
header("Location: ".$this->base_uri.$path);
|
||||
exit;
|
||||
}
|
||||
|
||||
// fixed width directory column format
|
||||
$format = "%15s %-19s %-s\n";
|
||||
|
||||
$handle = @opendir($fspath);
|
||||
if (!$handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "<html><head><title>Index of ".htmlspecialchars($options['path'])."</title></head>\n";
|
||||
|
||||
echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
|
||||
|
||||
echo "<pre>";
|
||||
printf($format, "Size", "Last modified", "Filename");
|
||||
echo "<hr>";
|
||||
|
||||
while ($filename = readdir($handle)) {
|
||||
if ($filename != "." && $filename != "..") {
|
||||
$fullpath = $fspath."/".$filename;
|
||||
$name = htmlspecialchars($filename);
|
||||
printf($format,
|
||||
number_format(filesize($fullpath)),
|
||||
strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
|
||||
"<a href='$this->base_uri$path$name'>$name</a>");
|
||||
}
|
||||
}
|
||||
|
||||
echo "</pre>";
|
||||
|
||||
closedir($handle);
|
||||
|
||||
echo "</html>\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT method handler
|
||||
*
|
||||
* @param array parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PUT(&$options)
|
||||
{
|
||||
$fspath = $this->base . $options["path"];
|
||||
|
||||
if (!@is_dir(dirname($fspath))) {
|
||||
return "409 Conflict";
|
||||
}
|
||||
|
||||
$options["new"] = ! file_exists($fspath);
|
||||
|
||||
$fp = fopen($fspath, "w");
|
||||
|
||||
return $fp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MKCOL method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function MKCOL($options)
|
||||
{
|
||||
$path = $this->base .$options["path"];
|
||||
$parent = dirname($path);
|
||||
$name = basename($path);
|
||||
|
||||
if (!file_exists($parent)) {
|
||||
return "409 Conflict";
|
||||
}
|
||||
|
||||
if (!is_dir($parent)) {
|
||||
return "403 Forbidden";
|
||||
}
|
||||
|
||||
if ( file_exists($parent."/".$name) ) {
|
||||
return "405 Method not allowed";
|
||||
}
|
||||
|
||||
if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
|
||||
return "415 Unsupported media type";
|
||||
}
|
||||
|
||||
$stat = mkdir ($parent."/".$name,0777);
|
||||
if (!$stat) {
|
||||
return "403 Forbidden";
|
||||
}
|
||||
|
||||
return ("201 Created");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DELETE method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function DELETE($options)
|
||||
{
|
||||
$path = $this->base . "/" .$options["path"];
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return "404 Not found";
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
$query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
|
||||
mysql_query($query);
|
||||
PearSystem::rm("-rf $path");
|
||||
} else {
|
||||
unlink ($path);
|
||||
}
|
||||
$query = "DELETE FROM properties WHERE path = '$options[path]'";
|
||||
mysql_query($query);
|
||||
|
||||
return "204 No Content";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MOVE method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function MOVE($options)
|
||||
{
|
||||
return $this->COPY($options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* COPY method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function COPY($options, $del=false)
|
||||
{
|
||||
// TODO Property updates still broken (Litmus should detect this?)
|
||||
|
||||
if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
|
||||
return "415 Unsupported media type";
|
||||
}
|
||||
|
||||
// no copying to different WebDAV Servers yet
|
||||
if (isset($options["dest_url"])) {
|
||||
return "502 bad gateway";
|
||||
}
|
||||
|
||||
$source = $this->base .$options["path"];
|
||||
if (!file_exists($source)) return "404 Not found";
|
||||
|
||||
$dest = $this->base . $options["dest"];
|
||||
|
||||
$new = !file_exists($dest);
|
||||
$existing_col = false;
|
||||
|
||||
if (!$new) {
|
||||
if ($del && is_dir($dest)) {
|
||||
if (!$options["overwrite"]) {
|
||||
return "412 precondition failed";
|
||||
}
|
||||
$dest .= basename($source);
|
||||
if (file_exists($dest)) {
|
||||
$options["dest"] .= basename($source);
|
||||
} else {
|
||||
$new = true;
|
||||
$existing_col = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$new) {
|
||||
if ($options["overwrite"]) {
|
||||
$stat = $this->DELETE(array("path" => $options["dest"]));
|
||||
if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
|
||||
return $stat;
|
||||
}
|
||||
} else {
|
||||
return "412 precondition failed";
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dir($source) && ($options["depth"] != "infinity")) {
|
||||
// RFC 2518 Section 9.2, last paragraph
|
||||
return "400 Bad request";
|
||||
}
|
||||
|
||||
if ($del) {
|
||||
if (!rename($source, $dest)) {
|
||||
return "500 Internal server error";
|
||||
}
|
||||
$destpath = $this->_unslashify($options["dest"]);
|
||||
if (is_dir($source)) {
|
||||
$query = "UPDATE properties
|
||||
SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
|
||||
WHERE path LIKE '".$this->_slashify($options["path"])."%'";
|
||||
mysql_query($query);
|
||||
}
|
||||
|
||||
$query = "UPDATE properties
|
||||
SET path = '".$destpath."'
|
||||
WHERE path = '".$options["path"]."'";
|
||||
mysql_query($query);
|
||||
} else {
|
||||
if (is_dir($source)) {
|
||||
$files = PearSystem::find($source);
|
||||
$files = array_reverse($files);
|
||||
} else {
|
||||
$files = array($source);
|
||||
}
|
||||
|
||||
if (!is_array($files) || empty($files)) {
|
||||
return "500 Internal server error";
|
||||
}
|
||||
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) {
|
||||
$file = $this->_slashify($file);
|
||||
}
|
||||
|
||||
$destfile = str_replace($source, $dest, $file);
|
||||
|
||||
if (is_dir($file)) {
|
||||
if (!is_dir($destfile)) {
|
||||
// TODO "mkdir -p" here? (only natively supported by PHP 5)
|
||||
if (!mkdir($destfile)) {
|
||||
return "409 Conflict";
|
||||
}
|
||||
} else {
|
||||
error_log("existing dir '$destfile'");
|
||||
}
|
||||
} else {
|
||||
if (!copy($file, $destfile)) {
|
||||
return "409 Conflict";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = "INSERT INTO properties SELECT ... FROM properties WHERE path = '".$options['path']."'";
|
||||
}
|
||||
|
||||
return ($new && !$existing_col) ? "201 Created" : "204 No Content";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LOCK method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function LOCK(&$options)
|
||||
{
|
||||
if (isset($options["update"])) { // Lock Update
|
||||
$query = "UPDATE locks SET expires = ".(time()+300);
|
||||
mysql_query($query);
|
||||
|
||||
if (mysql_affected_rows()) {
|
||||
$options["timeout"] = 300; // 5min hardcoded
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$options["timeout"] = time()+300; // 5min. hardcoded
|
||||
|
||||
$query = "INSERT INTO locks
|
||||
SET token = '$options[locktoken]'
|
||||
, path = '$options[path]'
|
||||
, owner = '$options[owner]'
|
||||
, expires = '$options[timeout]'
|
||||
, exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0")
|
||||
;
|
||||
mysql_query($query);
|
||||
|
||||
return mysql_affected_rows() ? "200 OK" : "409 Conflict";
|
||||
}
|
||||
|
||||
/**
|
||||
* UNLOCK method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function UNLOCK(&$options)
|
||||
{
|
||||
$query = "DELETE FROM locks
|
||||
WHERE path = '$options[path]'
|
||||
AND token = '$options[token]'";
|
||||
mysql_query($query);
|
||||
|
||||
return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
|
||||
}
|
||||
|
||||
/**
|
||||
* checkLock() helper
|
||||
*
|
||||
* @param string resource path to check for locks
|
||||
* @return bool true on success
|
||||
*/
|
||||
function checkLock($path)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
$query = "SELECT owner, token, expires, exclusivelock
|
||||
FROM locks
|
||||
WHERE path = '$path'
|
||||
";
|
||||
$res = mysql_query($query);
|
||||
|
||||
if ($res) {
|
||||
$row = mysql_fetch_array($res);
|
||||
mysql_free_result($res);
|
||||
|
||||
if ($row) {
|
||||
$result = array( "type" => "write",
|
||||
"scope" => $row["exclusivelock"] ? "exclusive" : "shared",
|
||||
"depth" => 0,
|
||||
"owner" => $row['owner'],
|
||||
"token" => $row['token'],
|
||||
"expires" => $row['expires']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create database tables for property and lock storage
|
||||
*
|
||||
* @param void
|
||||
* @return bool true on success
|
||||
*/
|
||||
function create_database()
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,237 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
|
||||
// | Christian Stocker <chregu@bitflux.ch> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: _parse_lockinfo.php,v 1.2 2004/01/05 12:32:40 hholzgra Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* helper class for parsing LOCK request bodies
|
||||
*
|
||||
* @package HTTP_WebDAV_Server
|
||||
* @author Hartmut Holzgraefe <hholzgra@php.net>
|
||||
* @version 0.99.1dev
|
||||
*/
|
||||
class _parse_lockinfo
|
||||
{
|
||||
/**
|
||||
* success state flag
|
||||
*
|
||||
* @var bool
|
||||
* @access public
|
||||
*/
|
||||
var $success = false;
|
||||
|
||||
/**
|
||||
* lock type, currently only "write"
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locktype = "";
|
||||
|
||||
/**
|
||||
* lock scope, "shared" or "exclusive"
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lockscope = "";
|
||||
|
||||
/**
|
||||
* lock owner information
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $owner = "";
|
||||
|
||||
/**
|
||||
* flag that is set during lock owner read
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $collect_owner = false;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string path of stream to read
|
||||
* @access public
|
||||
*/
|
||||
function _parse_lockinfo($path)
|
||||
{
|
||||
// we assume success unless problems occur
|
||||
$this->success = true;
|
||||
|
||||
// remember if any input was parsed
|
||||
$had_input = false;
|
||||
|
||||
// open stream
|
||||
$f_in = fopen($path, "r");
|
||||
if (!$f_in) {
|
||||
$this->success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// create namespace aware parser
|
||||
$xml_parser = xml_parser_create_ns("UTF-8", " ");
|
||||
|
||||
// set tag and data handlers
|
||||
xml_set_element_handler($xml_parser,
|
||||
array(&$this, "_startElement"),
|
||||
array(&$this, "_endElement"));
|
||||
xml_set_character_data_handler($xml_parser,
|
||||
array(&$this, "_data"));
|
||||
|
||||
// we want a case sensitive parser
|
||||
xml_parser_set_option($xml_parser,
|
||||
XML_OPTION_CASE_FOLDING, false);
|
||||
|
||||
// parse input
|
||||
while($this->success && !feof($f_in)) {
|
||||
$line = fgets($f_in);
|
||||
if (is_string($line)) {
|
||||
$had_input = true;
|
||||
$this->success &= xml_parse($xml_parser, $line, false);
|
||||
}
|
||||
}
|
||||
|
||||
// finish parsing
|
||||
if($had_input) {
|
||||
$this->success &= xml_parse($xml_parser, "", true);
|
||||
}
|
||||
|
||||
// check if required tags where found
|
||||
$this->success &= !empty($this->locktype);
|
||||
$this->success &= !empty($this->lockscope);
|
||||
|
||||
// free parser resource
|
||||
xml_parser_free($xml_parser);
|
||||
|
||||
// close input stream
|
||||
fclose($f_in);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* tag start handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
* @param array tag attributes
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _startElement($parser, $name, $attrs)
|
||||
{
|
||||
// namespace handling
|
||||
if (strstr($name, " ")) {
|
||||
list($ns, $tag) = explode(" ", $name);
|
||||
} else {
|
||||
$ns = "";
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
|
||||
if ($this->collect_owner) {
|
||||
// everything within the <owner> tag needs to be collected
|
||||
$ns_short = "";
|
||||
$ns_attr = "";
|
||||
if ($ns) {
|
||||
if ($ns == "DAV:") {
|
||||
$ns_short = "D:";
|
||||
} else {
|
||||
$ns_attr = " xmlns='$ns'";
|
||||
}
|
||||
}
|
||||
$this->owner .= "<$ns_short$tag$ns_attr>";
|
||||
} else if ($ns == "DAV:") {
|
||||
// parse only the essential tags
|
||||
switch ($tag) {
|
||||
case "write":
|
||||
$this->locktype = $tag;
|
||||
break;
|
||||
case "exclusive":
|
||||
case "shared":
|
||||
$this->lockscope = $tag;
|
||||
break;
|
||||
case "owner":
|
||||
$this->collect_owner = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* data handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string data
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _data($parser, $data)
|
||||
{
|
||||
// only the <owner> tag has data content
|
||||
if ($this->collect_owner) {
|
||||
$this->owner .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* tag end handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _endElement($parser, $name)
|
||||
{
|
||||
// namespace handling
|
||||
if (strstr($name, " ")) {
|
||||
list($ns, $tag) = explode(" ", $name);
|
||||
} else {
|
||||
$ns = "";
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
// <owner> finished?
|
||||
if (($ns == "DAV:") && ($tag == "owner")) {
|
||||
$this->collect_owner = false;
|
||||
}
|
||||
|
||||
// within <owner> we have to collect everything
|
||||
if ($this->collect_owner) {
|
||||
$ns_short = "";
|
||||
$ns_attr = "";
|
||||
if ($ns) {
|
||||
if ($ns == "DAV:") {
|
||||
$ns_short = "D:";
|
||||
} else {
|
||||
$ns_attr = " xmlns='$ns'";
|
||||
}
|
||||
}
|
||||
$this->owner .= "</$ns_short$tag$ns_attr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
|
||||
// | Christian Stocker <chregu@bitflux.ch> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: _parse_propfind.php,v 1.2 2004/01/05 12:33:22 hholzgra Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* helper class for parsing PROPFIND request bodies
|
||||
*
|
||||
* @package HTTP_WebDAV_Server
|
||||
* @author Hartmut Holzgraefe <hholzgra@php.net>
|
||||
* @version 0.99.1dev
|
||||
*/
|
||||
class _parse_propfind
|
||||
{
|
||||
/**
|
||||
* success state flag
|
||||
*
|
||||
* @var bool
|
||||
* @access public
|
||||
*/
|
||||
var $success = false;
|
||||
|
||||
/**
|
||||
* found properties are collected here
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $props = false;
|
||||
|
||||
/**
|
||||
* internal tag nesting depth counter
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $depth = 0;
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function _parse_propfind($path)
|
||||
{
|
||||
// success state flag
|
||||
$this->success = true;
|
||||
|
||||
// property storage array
|
||||
$this->props = array();
|
||||
|
||||
// internal tag depth counter
|
||||
$this->depth = 0;
|
||||
|
||||
// remember if any input was parsed
|
||||
$had_input = false;
|
||||
|
||||
// open input stream
|
||||
$f_in = fopen($path, "r");
|
||||
if (!$f_in) {
|
||||
$this->success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// create XML parser
|
||||
$xml_parser = xml_parser_create_ns("UTF-8", " ");
|
||||
|
||||
// set tag and data handlers
|
||||
xml_set_element_handler($xml_parser,
|
||||
array(&$this, "_startElement"),
|
||||
array(&$this, "_endElement"));
|
||||
|
||||
// we want a case sensitive parser
|
||||
xml_parser_set_option($xml_parser,
|
||||
XML_OPTION_CASE_FOLDING, false);
|
||||
|
||||
|
||||
// parse input
|
||||
while($this->success && !feof($f_in)) {
|
||||
$line = fgets($f_in);
|
||||
if (is_string($line)) {
|
||||
$had_input = true;
|
||||
$this->success &= xml_parse($xml_parser, $line, false);
|
||||
}
|
||||
}
|
||||
|
||||
// finish parsing
|
||||
if($had_input) {
|
||||
$this->success &= xml_parse($xml_parser, "", true);
|
||||
}
|
||||
|
||||
// free parser
|
||||
xml_parser_free($xml_parser);
|
||||
|
||||
// close input stream
|
||||
fclose($f_in);
|
||||
|
||||
// if no input was parsed it was a request
|
||||
if(!count($this->props)) $this->props = "all"; // default
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* start tag handler
|
||||
*
|
||||
* @access private
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
* @param array tag attributes
|
||||
*/
|
||||
function _startElement($parser, $name, $attrs)
|
||||
{
|
||||
// name space handling
|
||||
if (strstr($name, " ")) {
|
||||
list($ns, $tag) = explode(" ", $name);
|
||||
if ($ns == "")
|
||||
$this->success = false;
|
||||
} else {
|
||||
$ns = "";
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
// special tags at level 1: <allprop> and <propname>
|
||||
if ($this->depth == 1) {
|
||||
if ($tag == "allprop")
|
||||
$this->props = "all";
|
||||
|
||||
if ($tag == "propname")
|
||||
$this->props = "names";
|
||||
}
|
||||
|
||||
// requested properties are found at level 2
|
||||
if ($this->depth == 2) {
|
||||
$prop = array("name" => $tag);
|
||||
if ($ns)
|
||||
$prop["xmlns"] = $ns;
|
||||
$this->props[] = $prop;
|
||||
}
|
||||
|
||||
// increment depth count
|
||||
$this->depth++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* end tag handler
|
||||
*
|
||||
* @access private
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
*/
|
||||
function _endElement($parser, $name)
|
||||
{
|
||||
// here we only need to decrement the depth count
|
||||
$this->depth--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,214 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
|
||||
// | Christian Stocker <chregu@bitflux.ch> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: _parse_proppatch.php,v 1.3 2004/01/05 12:41:34 hholzgra Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* helper class for parsing PROPPATCH request bodies
|
||||
*
|
||||
* @package HTTP_WebDAV_Server
|
||||
* @author Hartmut Holzgraefe <hholzgra@php.net>
|
||||
* @version 0.99.1dev
|
||||
*/
|
||||
class _parse_proppatch
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var
|
||||
* @access
|
||||
*/
|
||||
var $success;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var
|
||||
* @access
|
||||
*/
|
||||
var $props;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var
|
||||
* @access
|
||||
*/
|
||||
var $depth;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var
|
||||
* @access
|
||||
*/
|
||||
var $mode;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var
|
||||
* @access
|
||||
*/
|
||||
var $current;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string path of input stream
|
||||
* @access public
|
||||
*/
|
||||
function _parse_proppatch($path)
|
||||
{
|
||||
$this->success = true;
|
||||
|
||||
$this->depth = 0;
|
||||
$this->props = array();
|
||||
$had_input = false;
|
||||
|
||||
$f_in = fopen($path, "r");
|
||||
if (!$f_in) {
|
||||
$this->success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$xml_parser = xml_parser_create_ns("UTF-8", " ");
|
||||
|
||||
xml_set_element_handler($xml_parser,
|
||||
array(&$this, "_startElement"),
|
||||
array(&$this, "_endElement"));
|
||||
|
||||
xml_set_character_data_handler($xml_parser,
|
||||
array(&$this, "_data"));
|
||||
|
||||
xml_parser_set_option($xml_parser,
|
||||
XML_OPTION_CASE_FOLDING, false);
|
||||
|
||||
while($this->success && !feof($f_in)) {
|
||||
$line = fgets($f_in);
|
||||
if (is_string($line)) {
|
||||
$had_input = true;
|
||||
$this->success &= xml_parse($xml_parser, $line, false);
|
||||
}
|
||||
}
|
||||
|
||||
if($had_input) {
|
||||
$this->success &= xml_parse($xml_parser, "", true);
|
||||
}
|
||||
|
||||
xml_parser_free($xml_parser);
|
||||
|
||||
fclose($f_in);
|
||||
}
|
||||
|
||||
/**
|
||||
* tag start handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
* @param array tag attributes
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _startElement($parser, $name, $attrs)
|
||||
{
|
||||
if (strstr($name, " ")) {
|
||||
list($ns, $tag) = explode(" ", $name);
|
||||
if ($ns == "")
|
||||
$this->success = false;
|
||||
} else {
|
||||
$ns = "";
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
if ($this->depth == 1) {
|
||||
$this->mode = $tag;
|
||||
}
|
||||
|
||||
if ($this->depth == 3) {
|
||||
$prop = array("name" => $tag);
|
||||
$this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
|
||||
if ($this->mode == "set") {
|
||||
$this->current["val"] = ""; // default set val
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->depth >= 4) {
|
||||
$this->current["val"] .= "<$tag";
|
||||
foreach ($attr as $key => $val) {
|
||||
$this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"';
|
||||
}
|
||||
$this->current["val"] .= ">";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->depth++;
|
||||
}
|
||||
|
||||
/**
|
||||
* tag end handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string tag name
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _endElement($parser, $name)
|
||||
{
|
||||
if (strstr($name, " ")) {
|
||||
list($ns, $tag) = explode(" ", $name);
|
||||
if ($ns == "")
|
||||
$this->success = false;
|
||||
} else {
|
||||
$ns = "";
|
||||
$tag = $name;
|
||||
}
|
||||
|
||||
$this->depth--;
|
||||
|
||||
if ($this->depth >= 4) {
|
||||
$this->current["val"] .= "</$tag>";
|
||||
}
|
||||
|
||||
if ($this->depth == 3) {
|
||||
if (isset($this->current)) {
|
||||
$this->props[] = $this->current;
|
||||
unset($this->current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* input data handler
|
||||
*
|
||||
* @param resource parser
|
||||
* @param string data
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _data($parser, $data) {
|
||||
if (isset($this->current)) {
|
||||
$this->current["val"] .= $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
239
thirdparty/pear/Log/sqlite.php
vendored
239
thirdparty/pear/Log/sqlite.php
vendored
@@ -1,239 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* $Header: /repository/pear/Log/Log/sqlite.php,v 1.5 2005/12/05 05:38:31 jon Exp $
|
||||
*
|
||||
* @version $Revision: 1.5 $
|
||||
* @package Log
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Log_sqlite class is a concrete implementation of the Log::
|
||||
* abstract class which sends messages to an Sqlite database.
|
||||
* Each entry occupies a separate row in the database.
|
||||
*
|
||||
* This implementation uses PHP native Sqlite functions.
|
||||
*
|
||||
* CREATE TABLE log_table (
|
||||
* id INTEGER PRIMARY KEY NOT NULL,
|
||||
* logtime NOT NULL,
|
||||
* ident CHAR(16) NOT NULL,
|
||||
* priority INT NOT NULL,
|
||||
* message
|
||||
* );
|
||||
*
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Jon Parise <jon@php.net>
|
||||
* @since Log 1.8.3
|
||||
* @package Log
|
||||
*
|
||||
* @example sqlite.php Using the Sqlite handler.
|
||||
*/
|
||||
class Log_sqlite extends Log
|
||||
{
|
||||
/**
|
||||
* Array containing the connection defaults
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array('mode' => 0666,
|
||||
'persistent' => false);
|
||||
|
||||
/**
|
||||
* Object holding the database handle.
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $_db = null;
|
||||
|
||||
/**
|
||||
* Flag indicating that we're using an existing database connection.
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_existingConnection = false;
|
||||
|
||||
/**
|
||||
* String holding the database table to use.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_table = 'log_table';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new sql logging object.
|
||||
*
|
||||
* @param string $name The target SQL table.
|
||||
* @param string $ident The identification field.
|
||||
* @param mixed $conf Can be an array of configuration options used
|
||||
* to open a new database connection
|
||||
* or an already opened sqlite connection.
|
||||
* @param int $level Log messages up to and including this level.
|
||||
* @access public
|
||||
*/
|
||||
function Log_sqlite($name, $ident = '', &$conf, $level = PEAR_LOG_DEBUG)
|
||||
{
|
||||
$this->_id = $this->encryptOld(microtime());
|
||||
$this->_table = $name;
|
||||
$this->_ident = $ident;
|
||||
$this->_mask = Log::UPTO($level);
|
||||
|
||||
if (is_array($conf)) {
|
||||
foreach ($conf as $k => $opt) {
|
||||
$this->_options[$k] = $opt;
|
||||
}
|
||||
} else {
|
||||
// If an existing database connection was provided, use it.
|
||||
$this->_db =& $conf;
|
||||
$this->_existingConnection = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a connection to the database, if it has not already
|
||||
* been opened. This is implicitly called by log(), if necessary.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
* @access public
|
||||
*/
|
||||
function open()
|
||||
{
|
||||
if (is_resource($this->_db)) {
|
||||
$this->_opened = true;
|
||||
return $this->_createTable();
|
||||
} else {
|
||||
/* Set the connection function based on the 'persistent' option. */
|
||||
if (empty($this->_options['persistent'])) {
|
||||
$connectFunction = 'sqlite_open';
|
||||
} else {
|
||||
$connectFunction = 'sqlite_popen';
|
||||
}
|
||||
|
||||
/* Attempt to connect to the database. */
|
||||
if ($this->_db = $connectFunction($this->_options['filename'],
|
||||
(int)$this->_options['mode'],
|
||||
$error)) {
|
||||
$this->_opened = true;
|
||||
return $this->_createTable();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the connection to the database if it is still open and we were
|
||||
* the ones that opened it. It is the caller's responsible to close an
|
||||
* existing connection that was passed to us via $conf['db'].
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
* @access public
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
/* We never close existing connections. */
|
||||
if ($this->_existingConnection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->_opened) {
|
||||
$this->_opened = false;
|
||||
sqlite_close($this->_db);
|
||||
}
|
||||
|
||||
return ($this->_opened === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts $message to the currently open database. Calls open(),
|
||||
* if necessary. Also passes the message along to any Log_observer
|
||||
* instances that are observing this Log.
|
||||
*
|
||||
* @param mixed $message String or object containing the message to log.
|
||||
* @param string $priority The priority of the message. Valid
|
||||
* values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
|
||||
* PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
|
||||
* PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
|
||||
* @return boolean True on success or false on failure.
|
||||
* @access public
|
||||
*/
|
||||
function log($message, $priority = null)
|
||||
{
|
||||
/* If a priority hasn't been specified, use the default value. */
|
||||
if ($priority === null) {
|
||||
$priority = $this->_priority;
|
||||
}
|
||||
|
||||
/* Abort early if the priority is above the maximum logging level. */
|
||||
if (!$this->_isMasked($priority)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If the connection isn't open and can't be opened, return failure. */
|
||||
if (!$this->_opened && !$this->open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Extract the string representation of the message.
|
||||
$message = $this->_extractMessage($message);
|
||||
|
||||
// Build the SQL query for this log entry insertion.
|
||||
$q = sprintf('INSERT INTO [%s] (logtime, ident, priority, message) ' .
|
||||
"VALUES ('%s', '%s', %d, '%s')",
|
||||
$this->_table,
|
||||
strftime('%Y-%m-%d %H:%M:%S', time()),
|
||||
sqlite_escape_string($this->_ident),
|
||||
$priority,
|
||||
sqlite_escape_string($message));
|
||||
if (!($res = @sqlite_unbuffered_query($this->_db, $q))) {
|
||||
return false;
|
||||
}
|
||||
$this->_announce(array('priority' => $priority, 'message' => $message));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the log table exists and creates it if necessary.
|
||||
*
|
||||
* @return boolean True on success or false on failure.
|
||||
* @access private
|
||||
*/
|
||||
function _createTable()
|
||||
{
|
||||
$q = "SELECT name FROM sqlite_master WHERE name='" . $this->_table .
|
||||
"' AND type='table'";
|
||||
|
||||
$res = sqlite_query($this->_db, $q);
|
||||
|
||||
if (sqlite_num_rows($res) == 0) {
|
||||
$q = 'CREATE TABLE [' . $this->_table . '] (' .
|
||||
'id INTEGER PRIMARY KEY NOT NULL, ' .
|
||||
'logtime NOT NULL, ' .
|
||||
'ident CHAR(16) NOT NULL, ' .
|
||||
'priority INT NOT NULL, ' .
|
||||
'message)';
|
||||
|
||||
if (!($res = sqlite_unbuffered_query($this->_db, $q))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function encryptOld($string)
|
||||
{
|
||||
if (!class_exists('G')) {
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
return G::encryptOld($string);
|
||||
}
|
||||
|
||||
}
|
||||
80
thirdparty/pear/Net/CheckIP.php
vendored
80
thirdparty/pear/Net/CheckIP.php
vendored
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2002-2006 Martin Jansen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* $Id: CheckIP.php,v 1.8 2006/12/15 17:42:26 mj Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to validate the syntax of IPv4 adresses
|
||||
*
|
||||
* Usage:
|
||||
* <?php
|
||||
* require_once "Net/CheckIP.php";
|
||||
*
|
||||
* if (Net_CheckIP::check_ip("your_ip_goes_here")) {
|
||||
* // Syntax of the IP is ok
|
||||
* }
|
||||
* ?>
|
||||
*
|
||||
* @author Martin Jansen <mj@php.net>
|
||||
* @author Guido Haeger <gh-lists@ecora.de>
|
||||
* @package Net_CheckIP
|
||||
* @version 1.1
|
||||
* @access public
|
||||
*/
|
||||
class Net_CheckIP
|
||||
{
|
||||
|
||||
/**
|
||||
* Validate the syntax of the given IP adress
|
||||
*
|
||||
* This function splits the IP address in 4 pieces
|
||||
* (separated by ".") and checks for each piece
|
||||
* if it's an integer value between 0 and 255.
|
||||
* If all 4 parameters pass this test, the function
|
||||
* returns true.
|
||||
*
|
||||
* @param string $ip IP adress
|
||||
* @return bool true if syntax is valid, otherwise false
|
||||
*/
|
||||
function check_ip($ip)
|
||||
{
|
||||
$oct = explode('.', $ip);
|
||||
if (count($oct) != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
if (!preg_match("/^[0-9]+$/", $oct[$i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($oct[$i] < 0 || $oct[$i] > 255) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
876
thirdparty/pear/Net/Curl.php
vendored
876
thirdparty/pear/Net/Curl.php
vendored
@@ -1,876 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* An Object Oriented interface to PHP's cURL extension
|
||||
*
|
||||
* PHP version 5.1.0+
|
||||
*
|
||||
* Copyright (c) 2007, The PEAR Group
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of the The PEAR Group nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_Curl
|
||||
* @author David Costa <gurugeek@php.net>
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @author Philippe Jausions <jausions@php.net>
|
||||
* @copyright 1997-2008 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Revision: 1.15 $
|
||||
* @link http://pear.php.net/package/Net_Curl
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include PEAR package for error handling
|
||||
*/
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Object-oriented implementation of the Curl extension
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_Curl
|
||||
* @author David Costa <gurugeek@php.net>
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @author Philippe Jausions <jausions@php.net>
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @link http://pear.php.net/package/Net_Curl
|
||||
*/
|
||||
class Net_Curl
|
||||
{
|
||||
// {{{ Public Properties
|
||||
/**
|
||||
* The URL for cURL to work with
|
||||
*
|
||||
* @var string $url
|
||||
* @access public
|
||||
*/
|
||||
var $url;
|
||||
|
||||
/**
|
||||
* The Username for standard HTTP Authentication
|
||||
*
|
||||
* @var string $username
|
||||
* @access public
|
||||
*/
|
||||
var $username = '';
|
||||
|
||||
/**
|
||||
* The Password for standard HTTP Authentication
|
||||
*
|
||||
* @var string $password
|
||||
* @access public
|
||||
*/
|
||||
var $password = '';
|
||||
|
||||
/**
|
||||
* The SSL version for the transfer
|
||||
*
|
||||
* @var integer $sslVersion
|
||||
* @access public
|
||||
*/
|
||||
var $sslVersion;
|
||||
|
||||
/**
|
||||
* The filename of the SSL certificate
|
||||
*
|
||||
* @var string $sslCert
|
||||
* @access public
|
||||
*/
|
||||
var $sslCert;
|
||||
|
||||
/**
|
||||
* The password corresponding to the certificate
|
||||
* in the $sslCert property
|
||||
*
|
||||
* @var string $sslCertPasswd
|
||||
* @access public
|
||||
*/
|
||||
var $sslCertPasswd;
|
||||
|
||||
/**
|
||||
* User Agent string when making an HTTP request
|
||||
*
|
||||
* @var string $userAgent
|
||||
* @access public
|
||||
*/
|
||||
var $userAgent;
|
||||
|
||||
/**
|
||||
* Whether or not to include the header in the results
|
||||
* of the CURL transfer
|
||||
*
|
||||
* @var boolean $header
|
||||
*/
|
||||
var $header = false;
|
||||
|
||||
/**
|
||||
* Whether or not to output debug information while executing a
|
||||
* curl transfer
|
||||
*
|
||||
* @var boolean $verbose
|
||||
* @access public
|
||||
*/
|
||||
var $verbose = false;
|
||||
|
||||
/**
|
||||
* Whether or not to display a progress meter for the current transfer
|
||||
*
|
||||
* @var boolean $progress
|
||||
* @access public
|
||||
*/
|
||||
var $progress = false;
|
||||
|
||||
/**
|
||||
* Whether or not to suppress error messages
|
||||
*
|
||||
* @var boolean $mute
|
||||
* @access public
|
||||
*/
|
||||
var $mute = false;
|
||||
|
||||
/**
|
||||
* Whether or not to follow HTTP Location headers.
|
||||
*
|
||||
* @var boolean $followLocation
|
||||
* @access public
|
||||
*/
|
||||
var $followLocation = true;
|
||||
|
||||
/**
|
||||
* Whether or not to follow HTTP Location headers.
|
||||
*
|
||||
* @var boolean $follow_location
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
var $follow_location = false;
|
||||
|
||||
/**
|
||||
* Time allowed for current transfer, in seconds. 0 means no limit
|
||||
*
|
||||
* @var int $timeout
|
||||
* @access public
|
||||
*/
|
||||
var $timeout = 0;
|
||||
|
||||
/**
|
||||
* Whether or not to return the results of the
|
||||
* current transfer
|
||||
*
|
||||
* @var boolean $returnTransfer
|
||||
* @access public
|
||||
*/
|
||||
var $returnTransfer = true;
|
||||
|
||||
/**
|
||||
* Whether or not to return the results of the
|
||||
* current transfer
|
||||
*
|
||||
* @var boolean $return_transfer
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
var $return_transfer = false;
|
||||
|
||||
/**
|
||||
* The type of transfer to perform (ie. 'POST', 'GET', 'PUT', etc)
|
||||
*
|
||||
* @var string $type
|
||||
* @access public
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* The file to upload (PUT, or FTP methods)
|
||||
*
|
||||
* @var string $file
|
||||
* @access public
|
||||
*/
|
||||
var $file;
|
||||
|
||||
/**
|
||||
* The file size of the file pointed to by the $file
|
||||
* property
|
||||
*
|
||||
* @var integer $fileSize
|
||||
* @access public
|
||||
*/
|
||||
var $fileSize;
|
||||
|
||||
/**
|
||||
* The file size of the file pointed to by the $file
|
||||
* property
|
||||
*
|
||||
* @var integer $file_size
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
var $file_size = false;
|
||||
|
||||
|
||||
/**
|
||||
* The cookies to send to the remote site
|
||||
*
|
||||
* @var array $cookies
|
||||
* @access public
|
||||
*/
|
||||
var $cookies = array();
|
||||
|
||||
/**
|
||||
* Additional HTTP headers to send to the remote site
|
||||
*
|
||||
* @var array $httpHeaders
|
||||
* @access public
|
||||
*/
|
||||
var $httpHeaders = null;
|
||||
|
||||
/**
|
||||
* Additional HTTP headers to send to the remote site
|
||||
*
|
||||
* @var array $http_headers
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
var $http_headers = false;
|
||||
|
||||
/**
|
||||
* The fields to send in a 'POST' request
|
||||
*
|
||||
* @var array $fields
|
||||
* @access public
|
||||
*/
|
||||
var $fields;
|
||||
|
||||
/**
|
||||
* The proxy server to go through
|
||||
*
|
||||
* @var string $proxy
|
||||
* @access public
|
||||
*/
|
||||
var $proxy;
|
||||
|
||||
/**
|
||||
* The username for the Proxy server
|
||||
*
|
||||
* @var string $proxyUser
|
||||
* @access public
|
||||
*/
|
||||
var $proxyUser;
|
||||
|
||||
/**
|
||||
* The password for the Proxy server
|
||||
*
|
||||
* @var string $proxyPassword
|
||||
* @access public
|
||||
*/
|
||||
var $proxyPassword;
|
||||
|
||||
/**
|
||||
* $verifyPeer
|
||||
*
|
||||
* FALSE to stop CURL from verifying the peer's certificate.
|
||||
* Alternate certificates to verify against can be specified
|
||||
* with the CURLOPT_CAINFO option or a certificate directory
|
||||
* can be specified with the CURLOPT_CAPATH option.
|
||||
* CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE
|
||||
* if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).
|
||||
*
|
||||
* @var boolean $verifyPeer
|
||||
* @access public
|
||||
*/
|
||||
var $verifyPeer = true;
|
||||
|
||||
/**
|
||||
* $verifyHost
|
||||
*
|
||||
* 0 : to stop CURL from verifying the host's certificate.
|
||||
* 1 : to check the existence of a common name in the SSL peer certificate.
|
||||
* 2 : to check the existence of a common name and also verify that it
|
||||
* matches the hostname provided.
|
||||
*
|
||||
* @var bool $verifyHost
|
||||
* @access public
|
||||
*/
|
||||
var $verifyHost = 2;
|
||||
|
||||
/**
|
||||
* $caInfo
|
||||
*
|
||||
* Set value for CURLOPT_CAINFO. The name of a file holding one or more
|
||||
* certificates to verify the peer with. This only makes sense when used
|
||||
* in combination with CURLOPT_SSL_VERIFYPEER. curl-ca-bundle.crt is
|
||||
* avaible on the Curl website http://curl.haxx.se/ for download inside
|
||||
* the packages.
|
||||
*
|
||||
* @var string $caInfo
|
||||
* @access public
|
||||
*/
|
||||
var $caInfo = '';
|
||||
|
||||
/**
|
||||
* $caPath
|
||||
*
|
||||
* Set value for CURLOPT_CAPATH. A directory that holds multiple CA
|
||||
* certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
|
||||
*
|
||||
* @var string $caPath
|
||||
* @access public
|
||||
*/
|
||||
var $caPath;
|
||||
// }}}
|
||||
// {{{ Private Properties
|
||||
/**
|
||||
* The current curl handle
|
||||
*
|
||||
* @var resource $_ch
|
||||
* @access private
|
||||
* @see Net_Curl::create()
|
||||
*/
|
||||
var $_ch = null;
|
||||
|
||||
/**
|
||||
* The file upload resource
|
||||
*
|
||||
* The CURLOPT_INFILE requires a file resource and not just a file name.
|
||||
* This is used by execute to open the file.
|
||||
*
|
||||
* @var resource $_fp
|
||||
* @access private
|
||||
* @see Net_Curl::execute()
|
||||
*/
|
||||
var $_fp = null;
|
||||
// }}}
|
||||
|
||||
// {{{ __construct($url = '', $userAgent = '')
|
||||
/**
|
||||
* The Net_Curl PHP 5.x constructor, called when a new Net_Curl object
|
||||
* is initialized (also called via 4.x constructor)
|
||||
*
|
||||
* @param string $url The URL to fetch (can be set using the $url
|
||||
* property as well)
|
||||
* @param string $userAgent The userAgent string (can be set using the
|
||||
* $userAgent property as well)
|
||||
*
|
||||
* @access public
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @return void
|
||||
*/
|
||||
function __construct($url = '', $userAgent = '')
|
||||
{
|
||||
if (is_string($url) && strlen($url)) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
if (is_string($userAgent) && strlen($userAgent)) {
|
||||
$this->userAgent = $userAgent;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ Net_Curl($url = '', $userAgent = '')
|
||||
/**
|
||||
* Net_Curl
|
||||
*
|
||||
* PHP 4.x constructor.
|
||||
*
|
||||
* @param string $url The URL to fetch (can be set using the $url
|
||||
* property as well)
|
||||
* @param string $userAgent The userAgent string (can be set using the
|
||||
* $userAgent property as well)
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function Net_Curl($url = '', $userAgent = '')
|
||||
{
|
||||
$this->__construct($url, $userAgent);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ execute()
|
||||
/**
|
||||
* Executes a prepared CURL transfer
|
||||
*
|
||||
* Run this function to execute your cURL request. If all goes well you
|
||||
* should get a string (the output from the remote host regarding your
|
||||
* request) or true (if you choose to output directly to the browser). If
|
||||
* something fails then PEAR_Error is returned.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'Net/Curl.php';
|
||||
*
|
||||
* $curl = new Net_Curl('http://www.example.com');
|
||||
* $curl->fields = array('foo' => '1', 'bar' => 'apple');
|
||||
* $result = $curl->execute();
|
||||
* if (!PEAR::isError($result)) {
|
||||
* echo $result;
|
||||
* }
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @access public
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @return PEAR_Error on failure, true/result on success
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function execute()
|
||||
{
|
||||
// Create cURL handle if it hasn't already been created
|
||||
if (!is_resource($this->_ch)) {
|
||||
$result = $this->create();
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Map the deprecated variables and throw a bunch of errors
|
||||
$this->_mapDeprecatedVariables();
|
||||
|
||||
// Default return value is true.
|
||||
$ret = true;
|
||||
|
||||
// Basic stuff
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_URL, $this->url);
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_HEADER, $this->header);
|
||||
|
||||
// Whether or not to return the transfer contents
|
||||
if ($this->returnTransfer === true || $this->mute === true) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
// HTTP Authentication
|
||||
if ($this->username != '') {
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_USERPWD,
|
||||
$this->username . ':' . $this->password);
|
||||
}
|
||||
|
||||
// SSL Checks
|
||||
if (isset($this->sslVersion)) {
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_SSLVERSION,
|
||||
$this->sslVersion);
|
||||
}
|
||||
|
||||
if (isset($this->sslCert)) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_SSLCERT, $this->sslCert);
|
||||
}
|
||||
|
||||
if (isset($this->sslCertPasswd)) {
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_SSLCERTPASSWD,
|
||||
$this->sslCertPasswd);
|
||||
}
|
||||
|
||||
// Proxy Related checks
|
||||
if (isset($this->proxy)) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_PROXY, $this->proxy);
|
||||
}
|
||||
|
||||
if (isset($this->proxyUser) || isset($this->proxyPassword)) {
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_PROXYUSERPWD,
|
||||
$this->proxyUser . ':' . $this->proxyPassword);
|
||||
}
|
||||
|
||||
if (is_bool($this->verifyPeer)) {
|
||||
if (!$this->setOption(CURLOPT_SSL_VERIFYPEER, $this->verifyPeer)) {
|
||||
return PEAR::raiseError('Error setting CURLOPT_SSL_VERIFYPEER');
|
||||
}
|
||||
}
|
||||
|
||||
if (is_numeric($this->verifyHost) && $this->verifyHost >= 0 &&
|
||||
$this->verifyHost <= 2) {
|
||||
if (!$this->setOption(CURLOPT_SSL_VERIFYHOST, $this->verifyHost)) {
|
||||
return PEAR::raiseError('Error setting CURLOPT_SSL_VERIFYPEER');
|
||||
}
|
||||
}
|
||||
|
||||
if (is_bool($this->verifyPeer) && $this->verifyPeer == true) {
|
||||
if (isset($this->caInfo) && strlen($this->caInfo)) {
|
||||
if (file_exists($this->caInfo)) {
|
||||
if (!$this->setOption(CURLOPT_CAINFO, $this->caInfo)) {
|
||||
return PEAR::raiseError('Error setting CURLOPT_CAINFO');
|
||||
}
|
||||
} else {
|
||||
return PEAR::raiseError('Could not find CA info: '.
|
||||
$this->caInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->caPath) && is_string($this->caPath)) {
|
||||
if (!$this->setOption(CURLOPT_CAPATH, $this->caPath)) {
|
||||
return PEAR::raiseError('Error setting CURLOPT_CAPATH');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer type
|
||||
if (isset($this->type)) {
|
||||
switch (strtolower($this->type)) {
|
||||
case 'post':
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_POST, true);
|
||||
break;
|
||||
case 'put':
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_PUT, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer upload, etc. related
|
||||
if (isset($this->file)) {
|
||||
if (!file_exists($this->file)) {
|
||||
return PEAR::raiseError('File does not exist: '.$this->file);
|
||||
}
|
||||
|
||||
$this->_fp = fopen($this->file, 'r');
|
||||
if (!is_resource($this->_fp)) {
|
||||
return PEAR::raiseError('Could not open file: '.$this->file);
|
||||
}
|
||||
|
||||
if (!isset($this->fileSize)) {
|
||||
$this->fileSize = filesize($this->file);
|
||||
}
|
||||
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_INFILE, $this->_fp);
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_INFILESIZE, $this->fileSize);
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_UPLOAD, true);
|
||||
}
|
||||
|
||||
if (isset($this->fields)) {
|
||||
$sets = null;
|
||||
if (!isset($this->type)) {
|
||||
$this->type = 'post';
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_POST, true);
|
||||
}
|
||||
|
||||
// If fields is an array then turn it into a string. Sometimes
|
||||
// cURL doesn't like fields as an array.
|
||||
// Exception: if a value is prefixed with "@" and the rest of the
|
||||
// value resolves to an existing file, then pass
|
||||
// the values as the original array.
|
||||
if (is_array($this->fields)) {
|
||||
$sets = array();
|
||||
foreach ($this->fields as $key => $val) {
|
||||
if (strlen($val) > 1 && $val{0} == '@') {
|
||||
$file = substr($val, 1);
|
||||
if (is_file($file) && is_readable($file)) {
|
||||
$sets = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sets[] = urlencode($key) . '=' . urlencode($val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($sets)) {
|
||||
$fields = implode('&', $sets);
|
||||
} else {
|
||||
$fields = $this->fields;
|
||||
}
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $fields);
|
||||
}
|
||||
|
||||
// Error related
|
||||
if ($this->progress === true) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_PROGRESS, true);
|
||||
}
|
||||
|
||||
if ($this->verbose === true) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_VERBOSE, true);
|
||||
}
|
||||
|
||||
// If a Location: header is passed then follow it
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_FOLLOWLOCATION,
|
||||
$this->followLocation);
|
||||
|
||||
// If a timeout is set and is greater then zero then set it
|
||||
if (is_numeric($this->timeout) && $this->timeout > 0) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||
}
|
||||
|
||||
if (isset($this->userAgent)) {
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_USERAGENT, $this->userAgent);
|
||||
}
|
||||
|
||||
// Cookies
|
||||
if (is_array($this->cookies) && count($this->cookies)) {
|
||||
$cookieData = '';
|
||||
foreach ($this->cookies as $name => $value) {
|
||||
$cookieData .= $name . '=' . $value . ';';
|
||||
}
|
||||
|
||||
$ret = curl_setopt($this->_ch, CURLOPT_COOKIE, $cookieData);
|
||||
}
|
||||
|
||||
// Other HTTP headers
|
||||
if ($this->httpHeaders !== null) {
|
||||
if (is_array($this->httpHeaders)) {
|
||||
$ret = curl_setopt($this->_ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
$this->httpHeaders);
|
||||
} else {
|
||||
return PEAR::raiseError('Net_Curl::$httpHeaders must be an array');
|
||||
}
|
||||
}
|
||||
|
||||
$ret = curl_exec($this->_ch);
|
||||
|
||||
// Close the file before we return anything
|
||||
if (is_resource($this->_fp)) {
|
||||
fclose($this->_fp);
|
||||
}
|
||||
|
||||
if (curl_errno($this->_ch)) {
|
||||
return PEAR::raiseError(curl_error($this->_ch), curl_errno($this->_ch));
|
||||
}
|
||||
|
||||
// Check to make sure we get a 2XX/3XX code and not a 404 or something.
|
||||
$info = $this->getInfo();
|
||||
if (!isset($info['http_code'])) {
|
||||
return PEAR::raiseError('Unknown or invalid HTTP response');
|
||||
} else {
|
||||
$type = substr($info['http_code'], 0, 1);
|
||||
if ($type != 2 && $type != 3) {
|
||||
return PEAR::raiseError('Unexpected HTTP code: ' .
|
||||
$info['http_code']);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ setOption($option, $value)
|
||||
/**
|
||||
* Sets an option for your cURL session. Please note that the cURL handler
|
||||
* is NOT created before execute(). This is for error checking purposes.
|
||||
* You should use setOption() in the following manner:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
*
|
||||
* require_once 'Net/Curl.php';
|
||||
* $curl = new Net_Curl('http://www.example.com');
|
||||
* $check = $curl->create();
|
||||
* if (!PEAR::isError($check)) {
|
||||
* $curl->setOption(CURLOPT_FOO, 'bar');
|
||||
* $result = $curl->execute();
|
||||
* if (!PEAR::isError($result)) {
|
||||
* echo $result;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @param int $option cURL constant (ie. CURLOPT_URL)
|
||||
* @param mixed $value The option's value
|
||||
*
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function setOption($option, $value)
|
||||
{
|
||||
if (is_resource($this->_ch)) {
|
||||
return curl_setopt($this->_ch, $option, $value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ getInfo()
|
||||
/**
|
||||
* Returns the info from the cURL session. PEAR_Error if you try and run
|
||||
* this before you execute the session.
|
||||
*
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @access public
|
||||
* @return mixed PEAR_Error if there is no resource, info on success
|
||||
*/
|
||||
function getInfo()
|
||||
{
|
||||
if (is_resource($this->_ch)) {
|
||||
return curl_getinfo($this->_ch);
|
||||
}
|
||||
|
||||
return PEAR::isError('cURL handler does not exist!');
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ create()
|
||||
/**
|
||||
* Creates a cURL resource. If curl_init() doesn't exist or we could not
|
||||
* create a resource it will error out.
|
||||
*
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @return boolean TRUE on success, PEAR_Error on failure
|
||||
*/
|
||||
function create()
|
||||
{
|
||||
if (!PEAR::loadExtension('curl')) {
|
||||
return PEAR::raiseError('CURL extension is not available');
|
||||
}
|
||||
if (!function_exists('curl_init')) {
|
||||
return PEAR::raiseError('Function curl_init() not found');
|
||||
}
|
||||
|
||||
$this->_ch = curl_init();
|
||||
if (!is_resource($this->_ch)) {
|
||||
return PEAR::raiseError('Could not initialize cURL handler');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ verboseAll()
|
||||
/**
|
||||
* Sets verbose output
|
||||
*
|
||||
* Turns on super debugging mode by not suppressing errors, turning on
|
||||
* verbose mode, showing headers and displaying progress.
|
||||
*
|
||||
* @access public
|
||||
* @author David Costa <gurugeek@php.net>
|
||||
* @return void
|
||||
*/
|
||||
function verboseAll()
|
||||
{
|
||||
$this->verbose = true;
|
||||
$this->mute = false;
|
||||
$this->header = true;
|
||||
$this->progress = true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ verbose_all()
|
||||
/**
|
||||
* Sets verbose output
|
||||
*
|
||||
* @access public
|
||||
* @author David Costa <gurugeek@php.net>
|
||||
* @return void
|
||||
* @deprecated
|
||||
*/
|
||||
function verbose_all()
|
||||
{
|
||||
$this->verboseAll();
|
||||
PEAR::raiseError('Net_Curl::verbose_all() is deprecated! Please use Net_Curl::verboseAll()'." <br />\n", null, PEAR_ERROR_PRINT);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ close()
|
||||
/**
|
||||
* Closes the curl transfer and finishes the object (kinda ;)
|
||||
*
|
||||
* @access public
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @return void
|
||||
* @since PHP 4.0.5
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if (is_resource($this->_ch)) {
|
||||
curl_close($this->_ch);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _mapDeprecatedVariables()
|
||||
/**
|
||||
* Maps deprecated variables into the appropriate places. It also throws
|
||||
* the necessary notices.
|
||||
*
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _mapDeprecatedVariables()
|
||||
{
|
||||
$bad = array();
|
||||
if ($this->follow_location !== false) {
|
||||
if ($this->follow_location > 0) {
|
||||
$this->followLocation = true;
|
||||
} else {
|
||||
$this->followLocation = false;
|
||||
}
|
||||
|
||||
$bad[] = array('follow_location', 'followLocation');
|
||||
}
|
||||
|
||||
if ($this->return_transfer !== false) {
|
||||
if ($this->return_transfer > 0) {
|
||||
$this->returnTransfer = true;
|
||||
} else {
|
||||
$this->returnTransfer = false;
|
||||
}
|
||||
|
||||
$bad[] = array('return_transfer', 'returnTransfer');
|
||||
}
|
||||
|
||||
if ($this->file_size !== false) {
|
||||
$this->fileSize = $this->file_size;
|
||||
$bad[] = array('file_size', 'fileSize');
|
||||
}
|
||||
|
||||
if ($this->http_headers !== false) {
|
||||
$this->httpHeaders = $this->http_headers;
|
||||
$bad[] = array('http_headers', 'httpHeaders');
|
||||
}
|
||||
|
||||
foreach ($bad as $map) {
|
||||
PEAR::raiseError('Net_Curl::$'. $map[0]. ' is deprecated! Please use Net_Curl::$'.$map[1]." instead! <br />\n", null, PEAR_ERROR_PRINT);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ __destruct()
|
||||
/**
|
||||
* PHP 5.x destructor.
|
||||
*
|
||||
* Runs Net_Curl::close() to make sure we close our cURL connection.
|
||||
*
|
||||
* @author Joe Stump <joe@joestump.net>
|
||||
* @see Net_Curl::close()
|
||||
*/
|
||||
function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
647
thirdparty/pear/Net/DIME.php
vendored
647
thirdparty/pear/Net/DIME.php
vendored
@@ -1,647 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <shane@caraveo.com> |
|
||||
// | Ralf Hofmann <ralf.hofmann@verdisoft.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: DIME.php,v 1.5 2002/09/29 01:55:16 shane Exp $
|
||||
//
|
||||
|
||||
require_once 'PEAR.php';
|
||||
/**
|
||||
*
|
||||
* DIME Encoding/Decoding
|
||||
*
|
||||
* What is it?
|
||||
* This class enables you to manipulate and build
|
||||
* a DIME encapsulated message.
|
||||
*
|
||||
* http://www.ietf.org/internet-drafts/draft-nielsen-dime-02.txt
|
||||
*
|
||||
* 09/18/02 Ralf - A huge number of changes to be compliant
|
||||
* with the DIME Specification Release 17 June 2002
|
||||
*
|
||||
* TODO: lots of stuff needs to be tested.
|
||||
* Definitily have to go through DIME spec and
|
||||
* make things work right, most importantly, sec 3.3
|
||||
* make examples, document
|
||||
*
|
||||
* see test/dime_mesage_test.php for example of usage
|
||||
*
|
||||
* @author Shane Caraveo <shane@caraveo.com>,
|
||||
* Ralf Hofmann <ralf.hofmann@verdisoft.com>
|
||||
* @version $Revision: 1.5 $
|
||||
* @package Net_DIME
|
||||
*/
|
||||
define('NET_DIME_TYPE_UNCHANGED',0x00);
|
||||
define('NET_DIME_TYPE_MEDIA',0x01);
|
||||
define('NET_DIME_TYPE_URI',0x02);
|
||||
define('NET_DIME_TYPE_UNKNOWN',0x03);
|
||||
define('NET_DIME_TYPE_NONE',0x04);
|
||||
|
||||
define('NET_DIME_VERSION',0x0001);
|
||||
|
||||
define('NET_DIME_RECORD_HEADER',12);
|
||||
|
||||
define('NET_DIME_FLAGS', 0);
|
||||
define('NET_DIME_OPTS_LEN', 1);
|
||||
define('NET_DIME_ID_LEN', 2);
|
||||
define('NET_DIME_TYPE_LEN', 3);
|
||||
define('NET_DIME_DATA_LEN', 4);
|
||||
define('NET_DIME_OPTS', 5);
|
||||
define('NET_DIME_ID', 6);
|
||||
define('NET_DIME_TYPE', 7);
|
||||
define('NET_DIME_DATA', 8);
|
||||
|
||||
class Net_DIME_Record extends PEAR
|
||||
{
|
||||
// these are used to hold the padded length
|
||||
var $OPTS_LENGTH = 0;
|
||||
var $ID_LENGTH = 0;
|
||||
var $TYPE_LENGTH = 0;
|
||||
var $DATA_LENGTH = 0;
|
||||
var $_haveOpts = FALSE;
|
||||
var $_haveID = FALSE;
|
||||
var $_haveType = FALSE;
|
||||
var $_haveData = FALSE;
|
||||
var $debug = FALSE;
|
||||
var $padstr = "\0";
|
||||
/**
|
||||
* Elements
|
||||
* [NET_DIME_FLAGS], 16 bits: VERSION:MB:ME:CF:TYPE_T
|
||||
* [NET_DIME_OPTS_LEN], 16 bits: OPTIONS_LENGTH
|
||||
* [NET_DIME_ID_LEN], 16 bits: ID_LENGTH
|
||||
* [NET_DIME_TYPE_LEN], 16 bits: TYPE_LENGTH
|
||||
* [NET_DIME_DATA_LEN], 32 bits: DATA_LENGTH
|
||||
* [NET_DIME_OPTS] : OPTIONS
|
||||
* [NET_DIME_ID] : ID
|
||||
* [NET_DIME_TYPE] : TYPE
|
||||
* [NET_DIME_DATA] : DATA
|
||||
*/
|
||||
var $Elements = array(NET_DIME_FLAGS => 0, NET_DIME_OPTS_LEN => 0,
|
||||
NET_DIME_ID_LEN => 0, NET_DIME_TYPE_LEN => 0,
|
||||
NET_DIME_DATA_LEN => 0,
|
||||
NET_DIME_OPTS => '',
|
||||
NET_DIME_ID => '',
|
||||
NET_DIME_TYPE => '',
|
||||
NET_DIME_DATA => '');
|
||||
|
||||
function Net_DIME_Record($debug = FALSE)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
if ($debug) $this->padstr = '*';
|
||||
}
|
||||
|
||||
function setMB()
|
||||
{
|
||||
$this->Elements[NET_DIME_FLAGS] |= 0x0400;
|
||||
}
|
||||
|
||||
function setME()
|
||||
{
|
||||
$this->Elements[NET_DIME_FLAGS] |= 0x0200;
|
||||
}
|
||||
|
||||
function setCF()
|
||||
{
|
||||
$this->Elements[NET_DIME_FLAGS] |= 0x0100;
|
||||
}
|
||||
|
||||
function isChunk()
|
||||
{
|
||||
return $this->Elements[NET_DIME_FLAGS] & 0x0100;
|
||||
}
|
||||
|
||||
function isEnd()
|
||||
{
|
||||
return $this->Elements[NET_DIME_FLAGS] & 0x0200;
|
||||
}
|
||||
|
||||
function isStart()
|
||||
{
|
||||
return $this->Elements[NET_DIME_FLAGS] & 0x0400;
|
||||
}
|
||||
|
||||
function getID()
|
||||
{
|
||||
return $this->Elements[NET_DIME_ID];
|
||||
}
|
||||
|
||||
function getType()
|
||||
{
|
||||
return $this->Elements[NET_DIME_TYPE];
|
||||
}
|
||||
|
||||
function getData()
|
||||
{
|
||||
return $this->Elements[NET_DIME_DATA];
|
||||
}
|
||||
|
||||
function getDataLength()
|
||||
{
|
||||
return $this->Elements[NET_DIME_DATA_LEN];
|
||||
}
|
||||
|
||||
function setType($typestring, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$typelen = strlen($typestring) & 0xFFFF;
|
||||
$type = $type << 4;
|
||||
$this->Elements[NET_DIME_FLAGS] = ($this->Elements[NET_DIME_FLAGS] & 0xFF0F) | $type;
|
||||
$this->Elements[NET_DIME_TYPE_LEN] = $typelen;
|
||||
$this->TYPE_LENGTH = $this->_getPadLength($typelen);
|
||||
$this->Elements[NET_DIME_TYPE] = $typestring;
|
||||
}
|
||||
|
||||
function generateID()
|
||||
{
|
||||
if(!class_exists('G')){
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
$id = G::encryptOld(time());
|
||||
$this->setID($id);
|
||||
return $id;
|
||||
}
|
||||
|
||||
function setID($id)
|
||||
{
|
||||
$idlen = strlen($id) & 0xFFFF;
|
||||
$this->Elements[NET_DIME_ID_LEN] = $idlen;
|
||||
$this->ID_LENGTH = $this->_getPadLength($idlen);
|
||||
$this->Elements[NET_DIME_ID] = $id;
|
||||
}
|
||||
|
||||
function setData($data, $size=0)
|
||||
{
|
||||
$datalen = $size?$size:strlen($data);
|
||||
$this->Elements[NET_DIME_DATA_LEN] = $datalen;
|
||||
$this->DATA_LENGTH = $this->_getPadLength($datalen);
|
||||
$this->Elements[NET_DIME_DATA] = $data;
|
||||
}
|
||||
|
||||
function encode()
|
||||
{
|
||||
// insert version
|
||||
$this->Elements[NET_DIME_FLAGS] = ($this->Elements[NET_DIME_FLAGS] & 0x07FF) | (NET_DIME_VERSION << 11);
|
||||
|
||||
// the real dime encoding
|
||||
$format = '%c%c%c%c%c%c%c%c%c%c%c%c'.
|
||||
'%'.$this->OPTS_LENGTH.'s'.
|
||||
'%'.$this->ID_LENGTH.'s'.
|
||||
'%'.$this->TYPE_LENGTH.'s'.
|
||||
'%'.$this->DATA_LENGTH.'s';
|
||||
return sprintf($format,
|
||||
($this->Elements[NET_DIME_FLAGS]&0x0000FF00)>>8,
|
||||
($this->Elements[NET_DIME_FLAGS]&0x000000FF),
|
||||
($this->Elements[NET_DIME_OPTS_LEN]&0x0000FF00)>>8,
|
||||
($this->Elements[NET_DIME_OPTS_LEN]&0x000000FF),
|
||||
($this->Elements[NET_DIME_ID_LEN]&0x0000FF00)>>8,
|
||||
($this->Elements[NET_DIME_ID_LEN]&0x000000FF),
|
||||
($this->Elements[NET_DIME_TYPE_LEN]&0x0000FF00)>>8,
|
||||
($this->Elements[NET_DIME_TYPE_LEN]&0x000000FF),
|
||||
($this->Elements[NET_DIME_DATA_LEN]&0xFF000000)>>24,
|
||||
($this->Elements[NET_DIME_DATA_LEN]&0x00FF0000)>>16,
|
||||
($this->Elements[NET_DIME_DATA_LEN]&0x0000FF00)>>8,
|
||||
($this->Elements[NET_DIME_DATA_LEN]&0x000000FF),
|
||||
str_pad($this->Elements[NET_DIME_OPTS], $this->OPTS_LENGTH, $this->padstr),
|
||||
str_pad($this->Elements[NET_DIME_ID], $this->ID_LENGTH, $this->padstr),
|
||||
str_pad($this->Elements[NET_DIME_TYPE], $this->TYPE_LENGTH, $this->padstr),
|
||||
str_pad($this->Elements[NET_DIME_DATA], $this->DATA_LENGTH, $this->padstr));
|
||||
}
|
||||
|
||||
function _getPadLength($len)
|
||||
{
|
||||
$pad = 0;
|
||||
if ($len) {
|
||||
$pad = $len % 4;
|
||||
if ($pad) $pad = 4 - $pad;
|
||||
}
|
||||
return $len + $pad;
|
||||
}
|
||||
|
||||
function decode(&$data)
|
||||
{
|
||||
// REAL DIME decoding
|
||||
$this->Elements[NET_DIME_FLAGS] = (hexdec(bin2hex($data[0]))<<8) + hexdec(bin2hex($data[1]));
|
||||
$this->Elements[NET_DIME_OPTS_LEN] = (hexdec(bin2hex($data[2]))<<8) + hexdec(bin2hex($data[3]));
|
||||
$this->Elements[NET_DIME_ID_LEN] = (hexdec(bin2hex($data[4]))<<8) + hexdec(bin2hex($data[5]));
|
||||
$this->Elements[NET_DIME_TYPE_LEN] = (hexdec(bin2hex($data[6]))<<8) + hexdec(bin2hex($data[7]));
|
||||
$this->Elements[NET_DIME_DATA_LEN] = (hexdec(bin2hex($data[8]))<<24) +
|
||||
(hexdec(bin2hex($data[9]))<<16) +
|
||||
(hexdec(bin2hex($data[10]))<<8) +
|
||||
hexdec(bin2hex($data[11]));
|
||||
$p = 12;
|
||||
|
||||
$version = (($this->Elements[NET_DIME_FLAGS]>>11) & 0x001F);
|
||||
|
||||
if ($version == NET_DIME_VERSION)
|
||||
{
|
||||
$this->OPTS_LENGTH = $this->_getPadLength($this->Elements[NET_DIME_OPTS_LEN]);
|
||||
$this->ID_LENGTH = $this->_getPadLength($this->Elements[NET_DIME_ID_LEN]);
|
||||
$this->TYPE_LENGTH = $this->_getPadLength($this->Elements[NET_DIME_TYPE_LEN]);
|
||||
$this->DATA_LENGTH = $this->_getPadLength($this->Elements[NET_DIME_DATA_LEN]);
|
||||
|
||||
$datalen = strlen($data);
|
||||
$this->Elements[NET_DIME_OPTS] = substr($data,$p,$this->Elements[NET_DIME_OPTS_LEN]);
|
||||
$this->_haveOpts = (strlen($this->Elements[NET_DIME_OPTS]) == $this->Elements[NET_DIME_OPTS_LEN]);
|
||||
if ($this->_haveOpts) {
|
||||
$p += $this->OPTS_LENGTH;
|
||||
$this->Elements[NET_DIME_ID] = substr($data,$p,$this->Elements[NET_DIME_ID_LEN]);
|
||||
$this->_haveID = (strlen($this->Elements[NET_DIME_ID]) == $this->Elements[NET_DIME_ID_LEN]);
|
||||
if ($this->_haveID) {
|
||||
$p += $this->ID_LENGTH;
|
||||
$this->Elements[NET_DIME_TYPE] = substr($data,$p,$this->Elements[NET_DIME_TYPE_LEN]);
|
||||
$this->_haveType = (strlen($this->Elements[NET_DIME_TYPE]) == $this->Elements[NET_DIME_TYPE_LEN]);
|
||||
if ($this->_haveType) {
|
||||
$p += $this->TYPE_LENGTH;
|
||||
$this->Elements[NET_DIME_DATA] = substr($data,$p,$this->Elements[NET_DIME_DATA_LEN]);
|
||||
$this->_haveData = (strlen($this->Elements[NET_DIME_DATA]) == $this->Elements[NET_DIME_DATA_LEN]);
|
||||
if ($this->_haveData) {
|
||||
$p += $this->DATA_LENGTH;
|
||||
} else {
|
||||
$p += strlen($this->Elements[NET_DIME_DATA]);
|
||||
}
|
||||
} else {
|
||||
$p += strlen($this->Elements[NET_DIME_TYPE]);
|
||||
}
|
||||
} else {
|
||||
$p += strlen($this->Elements[NET_DIME_ID]);
|
||||
}
|
||||
} else {
|
||||
$p += strlen($this->Elements[NET_DIME_OPTS]);
|
||||
}
|
||||
}
|
||||
return substr($data, $p);
|
||||
}
|
||||
|
||||
function addData(&$data)
|
||||
{
|
||||
$datalen = strlen($data);
|
||||
$p = 0;
|
||||
if (!$this->_haveOpts) {
|
||||
$have = strlen($this->Elements[NET_DIME_OPTS]);
|
||||
$this->Elements[NET_DIME_OPTS] .= substr($data,$p,$this->Elements[NET_DIME_OPTS_LEN]-$have);
|
||||
$this->_haveOpts = (strlen($this->Elements[NET_DIME_OPTS]) == $this->Elements[DIME_OTPS_LEN]);
|
||||
if (!$this->_haveOpts) return NULL;
|
||||
$p += $this->OPTS_LENGTH-$have;
|
||||
}
|
||||
if (!$this->_haveID) {
|
||||
$have = strlen($this->Elements[NET_DIME_ID]);
|
||||
$this->Elements[NET_DIME_ID] .= substr($data,$p,$this->Elements[NET_DIME_ID_LEN]-$have);
|
||||
$this->_haveID = (strlen($this->Elements[NET_DIME_ID]) == $this->Elements[NET_DIME_ID_LEN]);
|
||||
if (!$this->_haveID) return NULL;
|
||||
$p += $this->ID_LENGTH-$have;
|
||||
}
|
||||
if (!$this->_haveType && $p < $datalen) {
|
||||
$have = strlen($this->Elements[NET_DIME_TYPE]);
|
||||
$this->Elements[NET_DIME_TYPE] .= substr($data,$p,$this->Elements[NET_DIME_TYPE_LEN]-$have);
|
||||
$this->_haveType = (strlen($this->Elements[NET_DIME_TYPE]) == $this->Elements[NET_DIME_TYPE_LEN]);
|
||||
if (!$this->_haveType) return NULL;
|
||||
$p += $this->TYPE_LENGTH-$have;
|
||||
}
|
||||
if (!$this->_haveData && $p < $datalen) {
|
||||
$have = strlen($this->Elements[NET_DIME_DATA]);
|
||||
$this->Elements[NET_DIME_DATA] .= substr($data,$p,$this->Elements[NET_DIME_DATA_LEN]-$have);
|
||||
$this->_haveData = (strlen($this->Elements[NET_DIME_DATA]) == $this->Elements[NET_DIME_DATA_LEN]);
|
||||
if (!$this->_haveData) return NULL;
|
||||
$p += $this->DATA_LENGTH-$have;
|
||||
}
|
||||
return substr($data,$p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Net_DIME_Message extends PEAR
|
||||
{
|
||||
|
||||
var $record_size = 4096;
|
||||
#var $records =array();
|
||||
var $parts = array();
|
||||
var $currentPart = -1;
|
||||
var $stream = NULL;
|
||||
var $_currentRecord;
|
||||
var $_proc = array();
|
||||
var $type;
|
||||
var $typestr;
|
||||
var $mb = 1;
|
||||
var $me = 0;
|
||||
var $cf = 0;
|
||||
var $id = NULL;
|
||||
var $debug = FALSE;
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* this currently takes a file pointer as provided
|
||||
* by fopen
|
||||
*
|
||||
* TODO: integrate with the php streams stuff
|
||||
*/
|
||||
function Net_DIME_Message($stream=NULL, $record_size = 4096, $debug = FALSE)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$this->record_size = $record_size;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
function _makeRecord(&$data, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$record = new Net_DIME_Record($this->debug);
|
||||
if ($this->mb) {
|
||||
$record->setMB();
|
||||
// all subsequent records are not message begin!
|
||||
$this->mb = 0;
|
||||
}
|
||||
if ($this->me) $record->setME();
|
||||
if ($this->cf) $record->setCF();
|
||||
$record->setData($data);
|
||||
$record->setType($typestr,$type);
|
||||
if ($id) $record->setID($id);
|
||||
#if ($this->debug) {
|
||||
# print str_replace('\0','*',$record->encode());
|
||||
#}
|
||||
return $record->encode();
|
||||
}
|
||||
|
||||
function startChunk(&$data, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
if(!class_exists('G')){
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
$this->me = 0;
|
||||
$this->cf = 1;
|
||||
$this->type = $type;
|
||||
$this->typestr = $typestr;
|
||||
if ($id) {
|
||||
$this->id = $id;
|
||||
} else {
|
||||
$this->id = G::encryptOld(time());
|
||||
}
|
||||
return $this->_makeRecord($data, $this->typestr, $this->id, $this->type);
|
||||
}
|
||||
|
||||
function doChunk(&$data)
|
||||
{
|
||||
$this->me = 0;
|
||||
$this->cf = 1;
|
||||
return $this->_makeRecord($data, NULL, NULL, NET_DIME_TYPE_UNCHANGED);
|
||||
}
|
||||
|
||||
function endChunk()
|
||||
{
|
||||
$this->cf = 0;
|
||||
$data = NULL;
|
||||
$rec = $this->_makeRecord($data, NULL, NULL, NET_DIME_TYPE_UNCHANGED);
|
||||
$this->id = 0;
|
||||
$this->cf = 0;
|
||||
$this->id = 0;
|
||||
$this->type = NET_DIME_TYPE_UNKNOWN;
|
||||
$this->typestr = NULL;
|
||||
return $rec;
|
||||
}
|
||||
|
||||
function endMessage()
|
||||
{
|
||||
$this->me = 1;
|
||||
$data = NULL;
|
||||
$rec = $this->_makeRecord($data, NULL, NULL, NET_DIME_TYPE_NONE);
|
||||
$this->me = 0;
|
||||
$this->mb = 1;
|
||||
$this->id = 0;
|
||||
return $rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* sendRecord
|
||||
*
|
||||
* given a chunk of data, it creates DIME records
|
||||
* and writes them to the stream
|
||||
*
|
||||
*/
|
||||
function sendData(&$data, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$len = strlen($data);
|
||||
if ($len > $this->record_size) {
|
||||
$chunk = substr($data, 0, $this->record_size);
|
||||
$p = $this->record_size;
|
||||
$rec = $this->startChunk($chunk,$typestr,$id,$type);
|
||||
fwrite($this->stream, $rec);
|
||||
while ($p < $len) {
|
||||
$chunk = substr($data, $p, $this->record_size);
|
||||
$p += $this->record_size;
|
||||
$rec = $this->doChunk($chunk);
|
||||
fwrite($this->stream, $rec);
|
||||
}
|
||||
$rec = $this->endChunk();
|
||||
fwrite($this->stream, $rec);
|
||||
return;
|
||||
}
|
||||
$rec = $this->_makeRecord($data, $typestr,$id,$type);
|
||||
fwrite($this->stream, $rec);
|
||||
}
|
||||
|
||||
function sendEndMessage()
|
||||
{
|
||||
$rec = $this->endMessage();
|
||||
fwrite($this->stream, $rec);
|
||||
}
|
||||
|
||||
/**
|
||||
* sendFile
|
||||
*
|
||||
* given a filename, it reads the file,
|
||||
* creates records and writes them to the stream
|
||||
*
|
||||
*/
|
||||
function sendFile($filename, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$f = fopen($filename, "rb");
|
||||
if ($f) {
|
||||
if ($data = fread($f, $this->record_size)) {
|
||||
$this->startChunk($data,$typestr,$id,$type);
|
||||
}
|
||||
while ($data = fread($f, $this->record_size)) {
|
||||
$this->doChunk($data,$typestr,$id,$type);
|
||||
}
|
||||
$this->endChunk();
|
||||
fclose($f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* encodeData
|
||||
*
|
||||
* given data, encode it in DIME
|
||||
*
|
||||
*/
|
||||
function encodeData($data, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$len = strlen($data);
|
||||
$resp = '';
|
||||
if ($len > $this->record_size) {
|
||||
$chunk = substr($data, 0, $this->record_size);
|
||||
$p = $this->record_size;
|
||||
$resp .= $this->startChunk($chunk,$typestr,$id,$type);
|
||||
while ($p < $len) {
|
||||
$chunk = substr($data, $p, $this->record_size);
|
||||
$p += $this->record_size;
|
||||
$resp .= $this->doChunk($chunk);
|
||||
}
|
||||
$resp .= $this->endChunk();
|
||||
} else {
|
||||
$resp .= $this->_makeRecord($data, $typestr,$id,$type);
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* sendFile
|
||||
*
|
||||
* given a filename, it reads the file,
|
||||
* creates records and writes them to the stream
|
||||
*
|
||||
*/
|
||||
function encodeFile($filename, $typestr='', $id=NULL, $type=NET_DIME_TYPE_UNKNOWN)
|
||||
{
|
||||
$f = fopen($filename, "rb");
|
||||
if ($f) {
|
||||
if ($data = fread($f, $this->record_size)) {
|
||||
$resp = $this->startChunk($data,$typestr,$id,$type);
|
||||
}
|
||||
while ($data = fread($f, $this->record_size)) {
|
||||
$resp = $this->doChunk($data,$typestr,$id,$type);
|
||||
}
|
||||
$resp = $this->endChunk();
|
||||
fclose($f);
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* _processData
|
||||
*
|
||||
* creates Net_DIME_Records from provided data
|
||||
*
|
||||
*/
|
||||
function _processData(&$data)
|
||||
{
|
||||
$leftover = NULL;
|
||||
if (!$this->_currentRecord) {
|
||||
$this->_currentRecord = new Net_DIME_Record($this->debug);
|
||||
$data = $this->_currentRecord->decode($data);
|
||||
} else {
|
||||
$data = $this->_currentRecord->addData($data);
|
||||
}
|
||||
|
||||
if ($this->_currentRecord->_haveData) {
|
||||
if (count($this->parts)==0 && !$this->_currentRecord->isStart()) {
|
||||
// raise an error!
|
||||
return PEAR::raiseError('First Message is not a DIME begin record!');
|
||||
}
|
||||
|
||||
if ($this->_currentRecord->isEnd() && $this->_currentRecord->getDataLength()==0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($this->currentPart < 0 && !$this->_currentRecord->isChunk()) {
|
||||
$this->parts[] = array();
|
||||
$this->currentPart = count($this->parts)-1;
|
||||
$this->parts[$this->currentPart]['id'] = $this->_currentRecord->getID();
|
||||
$this->parts[$this->currentPart]['type'] = $this->_currentRecord->getType();
|
||||
$this->parts[$this->currentPart]['data'] = $this->_currentRecord->getData();
|
||||
$this->currentPart = -1;
|
||||
} else {
|
||||
if ($this->currentPart < 0) {
|
||||
$this->parts[] = array();
|
||||
$this->currentPart = count($this->parts)-1;
|
||||
$this->parts[$this->currentPart]['id'] = $this->_currentRecord->getID();
|
||||
$this->parts[$this->currentPart]['type'] = $this->_currentRecord->getType();
|
||||
$this->parts[$this->currentPart]['data'] = $this->_currentRecord->getData();
|
||||
} else {
|
||||
$this->parts[$this->currentPart]['data'] .= $this->_currentRecord->getData();
|
||||
if (!$this->_currentRecord->isChunk()) {
|
||||
// we reached the end of the chunk
|
||||
$this->currentPart = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#$this->records[] = $this->_currentRecord;
|
||||
if (!$this->_currentRecord->isEnd()) $this->_currentRecord = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* decodeData
|
||||
*
|
||||
* decodes a DIME encrypted string of data
|
||||
*
|
||||
*/
|
||||
function decodeData(&$data) {
|
||||
while (strlen($data) >= NET_DIME_RECORD_HEADER) {
|
||||
$err = $this->_processData($data);
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read
|
||||
*
|
||||
* reads the stream and creates
|
||||
* an array of records
|
||||
*
|
||||
* it can accept the start of a previously read buffer
|
||||
* this is usefull in situations where you need to read
|
||||
* headers before discovering that the data is DIME encoded
|
||||
* such as in the case of reading an HTTP response.
|
||||
*/
|
||||
function read($buf=NULL)
|
||||
{
|
||||
while ($data = fread($this->stream, 8192)) {
|
||||
if ($buf) {
|
||||
$data = $buf.$data;
|
||||
$buf = NULL;
|
||||
}
|
||||
if ($this->debug)
|
||||
echo "read: ".strlen($data)." bytes\n";
|
||||
$err = $this->decodeData($data);
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
|
||||
// store any leftover data to be used again
|
||||
// should be < NET_DIME_RECORD_HEADER bytes
|
||||
$buf = $data;
|
||||
}
|
||||
if (!$this->_currentRecord || !$this->_currentRecord->isEnd()) {
|
||||
return PEAR::raiseError('reached stream end without end record');
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
2346
thirdparty/pear/Net/FTP.php
vendored
2346
thirdparty/pear/Net/FTP.php
vendored
File diff suppressed because it is too large
Load Diff
116
thirdparty/pear/Net/FTP/Observer.php
vendored
116
thirdparty/pear/Net/FTP/Observer.php
vendored
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Net_FTP observer.
|
||||
*
|
||||
* This class implements the Observer part of a Subject-Observer
|
||||
* design pattern. It listens to the events sent by a Net_FTP instance.
|
||||
* This module had many influences from the Log_observer code.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Networking
|
||||
* @package FTP
|
||||
* @author Tobias Schlitt <toby@php.net>
|
||||
* @author Laurent Laville <pear@laurent-laville.org>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @copyright 1997-2008 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Observer.php,v 1.4.2.1 2008/01/07 14:21:22 jschippers Exp $
|
||||
* @link http://pear.php.net/package/Net_FTP
|
||||
* @since File available since Release 0.0.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements the Observer part of a Subject-Observer
|
||||
* design pattern. It listens to the events sent by a Net_FTP instance.
|
||||
* This module had many influences from the Log_observer code.
|
||||
*
|
||||
* @category Networking
|
||||
* @package FTP
|
||||
* @author Laurent Laville <pear@laurent-laville.org>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @author Tobias Schlitt <toby@php.net>
|
||||
* @copyright 1997-2008 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.3.7
|
||||
* @link http://pear.php.net/package/Net_FTP
|
||||
* @since 1.3.0.0
|
||||
* @access public
|
||||
*
|
||||
* @example observer_upload.php An example of Net_FTP_Observer implementation.
|
||||
*/
|
||||
class Net_FTP_Observer
|
||||
{
|
||||
/**
|
||||
* Instance-specific unique identification number.
|
||||
*
|
||||
* @var integer
|
||||
* @since 1.3.0
|
||||
* @access private
|
||||
*/
|
||||
var $_id;
|
||||
|
||||
/**
|
||||
* Creates a new basic Net_FTP_Observer instance.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
*/
|
||||
function Net_FTP_Observer()
|
||||
{
|
||||
$this->_id = $this->encryptOld(microtime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the listener's identifier
|
||||
*
|
||||
* @return string The listener's identifier
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
*/
|
||||
function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a stub method to make sure that Net_FTP_Observer classes do
|
||||
* something when they are notified of a message. The default behavior
|
||||
* is to just do nothing.
|
||||
* You should override this method.
|
||||
*
|
||||
* @param mixed $event A hash describing the net event.
|
||||
*
|
||||
* @since 1.3.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function notify($event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function encryptOld($string)
|
||||
{
|
||||
if (!class_exists('G')) {
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
return G::encryptOld($string);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
800
thirdparty/pear/Net/FTP/Socket.php
vendored
800
thirdparty/pear/Net/FTP/Socket.php
vendored
@@ -1,800 +0,0 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Net_FTP socket implementation of FTP functions.
|
||||
*
|
||||
* The functions in this file emulate the ext/FTP functions through
|
||||
* ext/Socket.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Networking
|
||||
* @package FTP
|
||||
* @author Tobias Schlitt <toby@php.net>
|
||||
* @copyright 1997-2008 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Socket.php,v 1.5.2.2 2008/04/22 19:47:08 jschippers Exp $
|
||||
* @link http://pear.php.net/package/Net_FTP
|
||||
* @since File available since Release 0.0.1
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
/**
|
||||
* Default FTP extension constants
|
||||
*/
|
||||
define('FTP_ASCII', 0);
|
||||
define('FTP_TEXT', 0);
|
||||
define('FTP_BINARY', 1);
|
||||
define('FTP_IMAGE', 1);
|
||||
define('FTP_TIMEOUT_SEC', 0);
|
||||
|
||||
/**
|
||||
* What needs to be done overall?
|
||||
* #1 Install the rest of these functions
|
||||
* #2 Document better
|
||||
* #3 Alot of other things I don't remember
|
||||
*/
|
||||
|
||||
/*
|
||||
* !!! NOTE !!!
|
||||
* Most of the comment's are "not working",
|
||||
* meaning they are not all up-to-date
|
||||
* !!! NOTE !!!
|
||||
*/
|
||||
|
||||
/**
|
||||
* &resource ftp_connect ( string host [, int port [, int timeout ] ] );
|
||||
*
|
||||
* Opens an FTP connection and return resource or false on failure.
|
||||
*
|
||||
* FTP Success respons code: 220
|
||||
*
|
||||
* @param string $host Host to connect to
|
||||
* @param int $port Optional, port to connect to
|
||||
* @param int $timeout Optional, seconds until function timeouts
|
||||
*
|
||||
* @todo The FTP extension has ftp_get_option() function which returns the
|
||||
* timeout variable. This function needs to be created and contain it as
|
||||
* static variable.
|
||||
* @todo The FTP extension has ftp_set_option() function which sets the
|
||||
* timeout variable. This function needs to be created and called here.
|
||||
* @access public
|
||||
* @return &resource
|
||||
*/
|
||||
function &ftp_connect($host, $port = 21, $timeout = 90)
|
||||
{
|
||||
$false = false; // We are going to return refrence (E_STRICT)
|
||||
|
||||
if (!is_string($host) || !is_integer($port) || !is_integer($timeout)) {
|
||||
return $false;
|
||||
}
|
||||
|
||||
$control = @fsockopen($host, $port, $iError, $sError,
|
||||
$timeout);
|
||||
$GLOBALS['_NET_FTP']['timeout'] = $timeout;
|
||||
|
||||
if (!is_resource($control)) {
|
||||
return $false;
|
||||
}
|
||||
|
||||
stream_set_blocking($control, true);
|
||||
stream_set_timeout($control, $timeout);
|
||||
|
||||
do {
|
||||
$content[] = fgets($control, 8129);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes'] > 0);
|
||||
|
||||
if (substr($content[count($content)-1], 0, 3) == 220) {
|
||||
return $control;
|
||||
}
|
||||
|
||||
return $false;
|
||||
}
|
||||
|
||||
/**
|
||||
* boolean ftp_login ( resource stream, string username, string password );
|
||||
*
|
||||
* Logs in to an given FTP connection stream.
|
||||
* Returns TRUE on success or FALSE on failure.
|
||||
*
|
||||
* NOTE:
|
||||
* Username and password are *not* optional. Function will *not*
|
||||
* assume "anonymous" if username and/or password is empty
|
||||
*
|
||||
* FTP Success respons code: 230
|
||||
*
|
||||
* @param resource &$control FTP resource to login to
|
||||
* @param string $username FTP Username to be used
|
||||
* @param string $password FTP Password to be used
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_login(&$control, $username, $password)
|
||||
{
|
||||
if (!is_resource($control) || is_null($username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'USER '.$username."\r\n");
|
||||
$contents = array();
|
||||
do {
|
||||
$contents[] = fgets($control, 8192);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes'] > 0);
|
||||
|
||||
if (substr($contents[count($contents)-1], 0, 3) != 331) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'PASS '.$password."\r\n");
|
||||
$contents = array();
|
||||
do {
|
||||
$contents[] = fgets($control, 8192);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes']);
|
||||
|
||||
if (substr($contents[count($contents)-1], 0, 3) == 230) {
|
||||
return true;
|
||||
}
|
||||
|
||||
trigger_error('ftp_login() [<a href="function.ftp-login">function.ftp-login'.
|
||||
'</a>]: '.$contents[count($contents)-1], E_USER_WARNING);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* boolean ftp_quit ( resource stream );
|
||||
*
|
||||
* Closes FTP connection.
|
||||
* Returns TRUE or FALSE on error.
|
||||
*
|
||||
* NOTE: The PHP function ftp_quit is *alias* to ftp_close, here it is
|
||||
* the *other-way-around* ( ftp_close() is alias to ftp_quit() ).
|
||||
*
|
||||
* NOTE:
|
||||
* resource is set to null since unset() can't unset the variable.
|
||||
*
|
||||
* @param resource &$control FTP resource
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_quit(&$control)
|
||||
{
|
||||
if (!is_resource($control)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'QUIT'."\r\n");
|
||||
fclose($control);
|
||||
$control = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias to ftp_quit()
|
||||
*
|
||||
* @param resource &$control FTP resource
|
||||
*
|
||||
* @see ftp_quit()
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_close(&$control)
|
||||
{
|
||||
return ftp_quit($control);
|
||||
}
|
||||
|
||||
/**
|
||||
* string ftp_pwd ( resource stream );
|
||||
*
|
||||
* Gets the current directory name.
|
||||
* Returns the current directory.
|
||||
*
|
||||
* Needs data connection: NO
|
||||
* Success response code: 257
|
||||
*
|
||||
* @param resource &$control FTP resource
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function ftp_pwd(&$control)
|
||||
{
|
||||
if (!is_resource($control)) {
|
||||
return $control;
|
||||
}
|
||||
|
||||
fputs($control, 'PWD'."\r\n");
|
||||
|
||||
$content = array();
|
||||
do {
|
||||
$content[] = fgets($control, 8192);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes'] > 0);
|
||||
|
||||
if (substr($cont = $content[count($content)-1], 0, 3) == 257) {
|
||||
$pos = strpos($cont, '"')+1;
|
||||
$pos2 = strrpos($cont, '"') - $pos;
|
||||
$path = substr($cont, $pos, $pos2);
|
||||
return $path;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* boolean ftp_chdir ( resource stream, string directory );
|
||||
*
|
||||
* Changes the current directory to the specified directory.
|
||||
* Returns TRUE on success or FALSE on failure.
|
||||
*
|
||||
* FTP success response code: 250
|
||||
* Needs data connection: NO
|
||||
*
|
||||
* @param resource &$control FTP stream
|
||||
* @param string $pwd Directory name
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_chdir(&$control, $pwd)
|
||||
{
|
||||
if (!is_resource($control) || !is_string($pwd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'CWD '.$pwd."\r\n");
|
||||
$content = array();
|
||||
do {
|
||||
$content[] = fgets($control, 8192);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes'] > 0);
|
||||
|
||||
if (substr($content[count($content)-1], 0, 3) == 250) {
|
||||
return true;
|
||||
}
|
||||
|
||||
trigger_error('ftp_chdir() [<a
|
||||
href="function.ftp-chdir">function.ftp-chdir</a>]:
|
||||
' .$content[count($content)-1], E_USER_WARNING);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$_NET_FTP = array();
|
||||
$_NET_FTP['USE_PASSIVE'] = false;
|
||||
$_NET_FTP['DATA'] = null;
|
||||
|
||||
/**
|
||||
* boolean ftp_pasv ( resource stream, boolean passive );
|
||||
*
|
||||
* Toggles passive mode ON/OFF.
|
||||
* Returns TRUE on success or FALSE on failure.
|
||||
*
|
||||
* Comment:
|
||||
* Although my lack of C knowlege I checked how the PHP FTP extension
|
||||
* do things here. Seems like they create the data connection and store
|
||||
* it in object for other functions to use.
|
||||
* This is now done here.
|
||||
*
|
||||
* FTP success response code: 227
|
||||
*
|
||||
* @param stream &$control FTP stream
|
||||
* @param boolean $pasv True to switch to passive, false for active mode
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_pasv(&$control, $pasv)
|
||||
{
|
||||
if (!is_resource($control) || !is_bool($pasv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If data connection exists, destroy it
|
||||
if (isset($GLOBALS['_NET_FTP']['DATA'])) {
|
||||
fclose($GLOBALS['_NET_FTP']['DATA']);
|
||||
$GLOBALS['_NET_FTP']['DATA'] = null;
|
||||
|
||||
do {
|
||||
fgets($control, 16);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes'] > 0);
|
||||
}
|
||||
|
||||
// Are we suppost to create active or passive connection?
|
||||
if (!$pasv) {
|
||||
$GLOBALS['_NET_FTP']['USE_PASSIVE'] = false;
|
||||
// Pick random "low bit"
|
||||
$low = rand(39, 250);
|
||||
// Pick random "high bit"
|
||||
$high = rand(39, 250);
|
||||
// Lowest possible port would be; 10023
|
||||
// Highest possible port would be; 64246
|
||||
|
||||
$port = ($low<<8)+$high;
|
||||
$ip = str_replace('.', ',', $_SERVER['SERVER_ADDR']);
|
||||
$s = $ip.','.$low.','.$high;
|
||||
|
||||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
if (is_resource($socket)) {
|
||||
if (socket_bind($socket, '0.0.0.0', $port)) {
|
||||
if (socket_listen($socket)) {
|
||||
$GLOBALS['_NET_FTP']['DATA'] = &$socket;
|
||||
fputs($control, 'PORT '.$s."\r\n");
|
||||
$line = fgets($control, 512);
|
||||
if (substr($line, 0, 3) == 200) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since we are here, we are suppost to create passive data connection.
|
||||
$i = fputs($control, 'PASV' ."\r\n");
|
||||
|
||||
$content = array();
|
||||
do {
|
||||
$content[] = fgets($control, 128);
|
||||
$array = socket_get_status($control);
|
||||
} while ($array['unread_bytes']);
|
||||
|
||||
if (substr($cont = $content[count($content)-1], 0, 3) != 227) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pos = strpos($cont, '(')+1;
|
||||
$pos2 = strrpos($cont, ')')-$pos;
|
||||
$string = substr($cont, $pos, $pos2);
|
||||
|
||||
$array = explode(',', $string);
|
||||
// IP we are connecting to
|
||||
$ip = $array[0]. '.' .$array[1]. '.' .$array[2]. '.' .$array[3];
|
||||
// Port ( 256*lowbit + highbit
|
||||
$port = ($array[4] << 8)+$array[5];
|
||||
|
||||
// Our data connection
|
||||
$data = fsockopen($ip, $port, $iError, $sError,
|
||||
$GLOBALS['_NET_FTP']['timeout']);
|
||||
|
||||
if (is_resource($data)) {
|
||||
$GLOBALS['_NET_FTP']['USE_PASSIVE'] = true;
|
||||
$GLOBALS['_NET_FTP']['DATA'] = &$data;
|
||||
stream_set_blocking($data, true);
|
||||
stream_set_timeout($data, $GLOBALS['_NET_FTP']['timeout']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* array ftp_rawlist ( resource stream, string directory [,bool recursive] );
|
||||
*
|
||||
* Returns a detailed list of files in the given directory.
|
||||
*
|
||||
* Needs data connection: YES
|
||||
*
|
||||
* @param integer &$control FTP resource
|
||||
* @param string $pwd Path to retrieve
|
||||
* @param boolean $recursive Optional, retrieve recursive listing
|
||||
*
|
||||
* @todo Enable the recursive feature.
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function ftp_rawlist(&$control, $pwd, $recursive = false)
|
||||
{
|
||||
if (!is_resource($control) || !is_string($pwd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
|
||||
!is_resource($GLOBALS['_NET_FTP']['DATA'])) {
|
||||
ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);
|
||||
}
|
||||
fputs($control, 'LIST '.$pwd."\r\n");
|
||||
|
||||
$msg = fgets($control, 512);
|
||||
if (substr($msg, 0, 3) == 425) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = &$GLOBALS['_NET_FTP']['DATA'];
|
||||
if (!$GLOBALS['_NET_FTP']['USE_PASSIVE']) {
|
||||
$data = &socket_accept($data);
|
||||
}
|
||||
|
||||
$content = array();
|
||||
|
||||
switch ($GLOBALS['_NET_FTP']['USE_PASSIVE']) {
|
||||
case true:
|
||||
while (true) {
|
||||
$string = rtrim(fgets($data, 1024));
|
||||
|
||||
if ($string=='') {
|
||||
break;
|
||||
}
|
||||
|
||||
$content[] = $string;
|
||||
}
|
||||
|
||||
fclose($data);
|
||||
break;
|
||||
|
||||
case false:
|
||||
$string = socket_read($data, 1024, PHP_BINARY_READ);
|
||||
|
||||
$content = explode("\n", $string);
|
||||
unset($content[count($content)-1]);
|
||||
|
||||
socket_close($GLOBALS['_NET_FTP']['DATA']);
|
||||
socket_close($data);
|
||||
break;
|
||||
}
|
||||
|
||||
$data = $GLOBALS['_NET_FTP']['DATA'] = null;
|
||||
|
||||
$f = fgets($control, 1024);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* string ftp_systype ( resource stream );
|
||||
*
|
||||
* Gets system type identifier of remote FTP server
|
||||
* Returns the remote system type
|
||||
*
|
||||
* @param resource &$control FTP resource
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function ftp_systype(&$control)
|
||||
{
|
||||
if (!is_resource($control)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'SYST'."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
|
||||
if (substr($line, 0, 3) != 215) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$os = substr($line, 4, strpos($line, ' ', 4)-4);
|
||||
return $os;
|
||||
}
|
||||
|
||||
/**
|
||||
* boolean ftp_alloc ( resource stream, integer bytes [, string &message ] );
|
||||
*
|
||||
* Allocates space for a file to be uploaded
|
||||
* Return TRUE on success or FALSE on failure
|
||||
*
|
||||
* NOTE; Many FTP servers do not support this command and/or don't need it.
|
||||
*
|
||||
* FTP success respons key: Belive it's 200
|
||||
* Needs data connection: NO
|
||||
*
|
||||
* @param resource &$control FTP stream
|
||||
* @param integer $int Space to allocate
|
||||
* @param string &$msg Optional, textual representation of the servers response
|
||||
* will be returned by reference
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_alloc(&$control, $int, &$msg = null)
|
||||
{
|
||||
if (!is_resource($control) || !is_integer($int)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'ALLO '.$int.' R '.$int."\r\n");
|
||||
|
||||
$msg = rtrim(fgets($control, 256));
|
||||
|
||||
$code = substr($msg, 0, 3);
|
||||
if ($code == 200 || $code == 202) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* bool ftp_put ( resource stream, string remote_file, string local_file,
|
||||
* int mode [, int startpos ] );
|
||||
*
|
||||
* Uploads a file to the FTP server
|
||||
* Returns TRUE on success or FALSE on failure.
|
||||
*
|
||||
* NOTE:
|
||||
* The transfer mode specified must be either FTP_ASCII or FTP_BINARY.
|
||||
*
|
||||
* @param resource &$control FTP stream
|
||||
* @param string $remote Remote file to write
|
||||
* @param string $local Local file to upload
|
||||
* @param integer $mode Upload mode, FTP_ASCI || FTP_BINARY
|
||||
* @param integer $pos Optional, start upload at position
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_put(&$control, $remote, $local, $mode, $pos = 0)
|
||||
{
|
||||
if (!is_resource($control) || !is_readable($local) ||
|
||||
!is_integer($mode) || !is_integer($pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$types = array (
|
||||
0 => 'A',
|
||||
1 => 'I'
|
||||
);
|
||||
$windows = array (
|
||||
0 => 't',
|
||||
1 => 'b'
|
||||
);
|
||||
|
||||
/**
|
||||
* TYPE values:
|
||||
* A ( ASCII )
|
||||
* I ( BINARY )
|
||||
* E ( EBCDIC )
|
||||
* L ( BYTE )
|
||||
*/
|
||||
|
||||
if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
|
||||
!is_resource($GLOBALS['_NET_FTP']['DATA'])) {
|
||||
ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);
|
||||
|
||||
}
|
||||
// Establish data connection variable
|
||||
$data = &$GLOBALS['_NET_FTP']['DATA'];
|
||||
|
||||
// Decide TYPE to use
|
||||
fputs($control, 'TYPE '.$types[$mode]."\r\n");
|
||||
$line = fgets($control, 256); // "Type set to TYPE"
|
||||
if (substr($line, 0, 3) != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'STOR '.$remote."\r\n");
|
||||
sleep(1);
|
||||
$line = fgets($control, 256); // "Opening TYPE mode data connect."
|
||||
|
||||
if (substr($line, 0, 3) != 150) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Creating resource to $local file
|
||||
$fp = fopen($local, 'r'. $windows[$mode]);
|
||||
if (!is_resource($fp)) {
|
||||
$fp = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loop throu that file and echo it to the data socket
|
||||
$i = 0;
|
||||
switch ($GLOBALS['_NET_FTP']['USE_PASSIVE']) {
|
||||
case false:
|
||||
$data = &socket_accept($data);
|
||||
while (!feof($fp)) {
|
||||
$i += socket_write($data, fread($fp, 10240), 10240);
|
||||
}
|
||||
socket_close($data);
|
||||
break;
|
||||
|
||||
case true:
|
||||
while (!feof($fp)) {
|
||||
$i += fputs($data, fread($fp, 10240), 10240);
|
||||
}
|
||||
|
||||
fclose($data);
|
||||
break;
|
||||
}
|
||||
|
||||
$data = null;
|
||||
do {
|
||||
$line = fgets($control, 256);
|
||||
} while (substr($line, 0, 4) != "226 ");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a remote file to a local file
|
||||
* Returns TRUE on success or FALSE on failure
|
||||
*
|
||||
* @param integer &$control Stream ID
|
||||
* @param string $local Local filename
|
||||
* @param string $remote Remote filename
|
||||
* @param integer $mode Transfer mode (FTP_ASCII or FTP_BINARY)
|
||||
* @param integer $resume Resume the file transfer or not
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_get(&$control, $local, $remote, $mode, $resume = 0, $wr='w')
|
||||
{
|
||||
if (!class_exists('G')) {
|
||||
$realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
|
||||
$docuroot = explode('/', $realdocuroot);
|
||||
array_pop($docuroot);
|
||||
$pathhome = implode('/', $docuroot) . '/';
|
||||
array_pop($docuroot);
|
||||
$pathTrunk = implode('/', $docuroot) . '/';
|
||||
require_once($pathTrunk . 'gulliver/system/class.g.php');
|
||||
}
|
||||
|
||||
$filter = new InputFilter();
|
||||
if (!is_resource($control) || !is_writable(dirname($local)) ||
|
||||
!is_integer($mode) || !is_integer($resume)) {
|
||||
return false;
|
||||
}
|
||||
$types = array (
|
||||
0 => 'A',
|
||||
1 => 'I'
|
||||
);
|
||||
$windows = array (
|
||||
0 => 't',
|
||||
1 => 'b'
|
||||
);
|
||||
|
||||
if (!isset($GLOBALS['_NET_FTP']['DATA']) ||
|
||||
!is_resource($GLOBALS['_NET_FTP'][ 'DATA'])) {
|
||||
ftp_pasv($control, $GLOBALS['_NET_FTP']['USE_PASSIVE']);
|
||||
}
|
||||
$data = &$GLOBALS['NET_FTP']['DATA'];
|
||||
|
||||
fputs($control, 'TYPE '.$types[$mode]."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
if (substr($line, 0, 3) != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(is_file($filter->validatePath($local))) {
|
||||
$var = $wr.$windows[$mode];
|
||||
$fp = fopen($filter->validatePath($local), $var);
|
||||
} else {
|
||||
$fp = false;
|
||||
}
|
||||
|
||||
if (!is_resource($fp)) {
|
||||
$fp = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes to the parent directory
|
||||
* Returns TRUE on success or FALSE on failure
|
||||
*
|
||||
* @param integer &$control Stream ID
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_cdup(&$control)
|
||||
{
|
||||
fputs($control, 'CDUP'."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
|
||||
if (substr($line, 0, 3) != 250) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set permissions on a file via FTP
|
||||
* Returns the new file permission on success or false on error
|
||||
*
|
||||
* NOTE: This command is *not* supported by the standard
|
||||
* NOTE: This command not ready!
|
||||
*
|
||||
* @param integer &$control Stream ID
|
||||
* @param integer $mode Octal value
|
||||
* @param string $file File to change permissions on
|
||||
*
|
||||
* @todo Figure out a way to chmod files via FTP
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function ftp_chmod(&$control, $mode, $file)
|
||||
{
|
||||
if (!is_resource($control) || !is_integer($mode) || !is_string($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// chmod not in the standard, proftpd doesn't recognize it
|
||||
// use SITE CHMOD?
|
||||
fputs($control, 'SITE CHMOD '.$mode. ' ' .$file."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
|
||||
if (substr($line, 0, 3) == 200) {
|
||||
return $mode;
|
||||
}
|
||||
|
||||
trigger_error('ftp_chmod() [<a
|
||||
href="function.ftp-chmod">function.ftp-chmod</a>]: ' .
|
||||
rtrim($line), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file on the FTP server
|
||||
* Returns TRUE on success or FALSE on failure
|
||||
*
|
||||
* @param integer &$control Stream ID
|
||||
* @param string $path File to delete
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_delete(&$control, $path)
|
||||
{
|
||||
if (!is_resource($control) || !is_string($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($control, 'DELE '.$path."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
|
||||
if (substr($line, 0, 3) == 250) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests execution of a program on the FTP server
|
||||
* NOTE; SITE EXEC is *not* supported by the standart
|
||||
* Returns TRUE on success or FALSE on error
|
||||
*
|
||||
* @param integer &$control Stream ID
|
||||
* @param string $cmd Command to send
|
||||
*
|
||||
* @access public
|
||||
* @todo Look a littlebit better into this
|
||||
* @return boolean
|
||||
*/
|
||||
function ftp_exec(&$control, $cmd)
|
||||
{
|
||||
if (!is_resource($control) || !is_string($cmd)) {
|
||||
return false;
|
||||
}
|
||||
// Command not defined in the standart
|
||||
// proftpd doesn't recognize SITE EXEC (only help,chgrp,chmod and ratio)
|
||||
fputs($control, 'SITE EXEC '.$cmd."\r\n");
|
||||
$line = fgets($control, 256);
|
||||
|
||||
// php.net/ftp_exec uses respons code 200 to verify if command was sent
|
||||
// successfully or not, so we'll just do the same
|
||||
if (substr($line, 0, 3) == 200) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
101
thirdparty/pear/Net/IDNA.php
vendored
101
thirdparty/pear/Net/IDNA.php
vendored
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
// {{{ license
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or modify |
|
||||
// | it under the terms of the GNU Lesser General Public License as |
|
||||
// | published by the Free Software Foundation; either version 2.1 of the |
|
||||
// | License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, but |
|
||||
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
||||
// | USA. |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
/**
|
||||
* Encode/decode Internationalized Domain Names.
|
||||
* Factory class to get correct implementation either for php4 or php5.
|
||||
*
|
||||
* @author Markus Nix <mnix@docuverse.de>
|
||||
* @author Matthias Sommerfeld <mso@phlylabs.de>
|
||||
* @package Net
|
||||
* @version $Id: IDNA.php,v 1.1 2008/03/22 12:39:37 neufeind Exp $
|
||||
*/
|
||||
|
||||
class Net_IDNA
|
||||
{
|
||||
// {{{ factory
|
||||
/**
|
||||
* Attempts to return a concrete IDNA instance for either php4 or php5.
|
||||
*
|
||||
* @param array $params Set of paramaters
|
||||
* @return object IDNA The newly created concrete Log instance, or an
|
||||
* false on an error.
|
||||
* @access public
|
||||
*/
|
||||
function &getInstance($params = array())
|
||||
{
|
||||
$version = explode( '.', phpversion() );
|
||||
$handler = ((int)$version[0] > 4) ? 'php5' : 'php4';
|
||||
$class = 'Net_IDNA_' . $handler;
|
||||
$classfile = 'Net/IDNA/' . $handler . '.php';
|
||||
|
||||
/*
|
||||
* Attempt to include our version of the named class, but don't treat
|
||||
* a failure as fatal. The caller may have already included their own
|
||||
* version of the named class.
|
||||
*/
|
||||
@include_once $classfile;
|
||||
|
||||
/* If the class exists, return a new instance of it. */
|
||||
if (class_exists($class)) {
|
||||
$instance = &new $class($params);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ singleton
|
||||
/**
|
||||
* Attempts to return a concrete IDNA instance for either php4 or php5,
|
||||
* only creating a new instance if no IDNA instance with the same
|
||||
* parameters currently exists.
|
||||
*
|
||||
* @param array $params Set of paramaters
|
||||
* @return object IDNA The newly created concrete Log instance, or an
|
||||
* false on an error.
|
||||
* @access public
|
||||
*/
|
||||
function &singleton($params = array())
|
||||
{
|
||||
static $instances;
|
||||
if (!isset($instances)) {
|
||||
$instances = array();
|
||||
}
|
||||
|
||||
$signature = serialize($params);
|
||||
if (!isset($instances[$signature])) {
|
||||
$instances[$signature] = &Net_IDNA::getInstance($params);
|
||||
}
|
||||
|
||||
return $instances[$signature];
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
3233
thirdparty/pear/Net/IDNA/php5.php
vendored
3233
thirdparty/pear/Net/IDNA/php5.php
vendored
File diff suppressed because it is too large
Load Diff
458
thirdparty/pear/Net/IPv4.php
vendored
458
thirdparty/pear/Net/IPv4.php
vendored
@@ -1,458 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Class to provide IPv4 calculations
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_IPv4
|
||||
* @author Eric Kilfoil <edk@ypass.net>
|
||||
* @author Marco Kaiser <bate@php.net>
|
||||
* @author Florian Anderiasch <fa@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: IPv4.php,v 1.11 2005/11/29 12:56:35 fa Exp $
|
||||
* @link http://pear.php.net/package/Net_IPv4
|
||||
*/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
// {{{ GLOBALS
|
||||
/**
|
||||
* Map of bitmasks to subnets
|
||||
*
|
||||
* This array contains every valid netmask. The index of the dot quad
|
||||
* netmask value is the corresponding CIDR notation (bitmask).
|
||||
*
|
||||
* @global array $GLOBALS['Net_IPv4_Netmask_Map']
|
||||
*/
|
||||
$GLOBALS['Net_IPv4_Netmask_Map'] = array(
|
||||
0 => "0.0.0.0",
|
||||
1 => "128.0.0.0",
|
||||
2 => "192.0.0.0",
|
||||
3 => "224.0.0.0",
|
||||
4 => "240.0.0.0",
|
||||
5 => "248.0.0.0",
|
||||
6 => "252.0.0.0",
|
||||
7 => "254.0.0.0",
|
||||
8 => "255.0.0.0",
|
||||
9 => "255.128.0.0",
|
||||
10 => "255.192.0.0",
|
||||
11 => "255.224.0.0",
|
||||
12 => "255.240.0.0",
|
||||
13 => "255.248.0.0",
|
||||
14 => "255.252.0.0",
|
||||
15 => "255.254.0.0",
|
||||
16 => "255.255.0.0",
|
||||
17 => "255.255.128.0",
|
||||
18 => "255.255.192.0",
|
||||
19 => "255.255.224.0",
|
||||
20 => "255.255.240.0",
|
||||
21 => "255.255.248.0",
|
||||
22 => "255.255.252.0",
|
||||
23 => "255.255.254.0",
|
||||
24 => "255.255.255.0",
|
||||
25 => "255.255.255.128",
|
||||
26 => "255.255.255.192",
|
||||
27 => "255.255.255.224",
|
||||
28 => "255.255.255.240",
|
||||
29 => "255.255.255.248",
|
||||
30 => "255.255.255.252",
|
||||
31 => "255.255.255.254",
|
||||
32 => "255.255.255.255"
|
||||
);
|
||||
// }}}
|
||||
// {{{ Net_IPv4
|
||||
|
||||
/**
|
||||
* Class to provide IPv4 calculations
|
||||
*
|
||||
* Provides methods for validating IP addresses, calculating netmasks,
|
||||
* broadcast addresses, network addresses, conversion routines, etc.
|
||||
*
|
||||
* @category Net
|
||||
* @package Net_IPv4
|
||||
* @author Eric Kilfoil <edk@ypass.net>
|
||||
* @author Marco Kaiser <bate@php.net>
|
||||
* @author Florian Anderiasch <fa@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: 1.3.0
|
||||
* @link http://pear.php.net/package/Net_IPv4
|
||||
* @access public
|
||||
*/
|
||||
class Net_IPv4
|
||||
{
|
||||
// {{{ properties
|
||||
var $ip = "";
|
||||
var $bitmask = false;
|
||||
var $netmask = "";
|
||||
var $network = "";
|
||||
var $broadcast = "";
|
||||
var $long = 0;
|
||||
|
||||
// }}}
|
||||
// {{{ validateIP()
|
||||
|
||||
/**
|
||||
* Validate the syntax of the given IP adress
|
||||
*
|
||||
* Using the PHP long2ip() and ip2long() functions, convert the IP
|
||||
* address from a string to a long and back. If the original still
|
||||
* matches the converted IP address, it's a valid address. This
|
||||
* function does not allow for IP addresses to be formatted as long
|
||||
* integers.
|
||||
*
|
||||
* @param string $ip IP address in the format x.x.x.x
|
||||
* @return bool true if syntax is valid, otherwise false
|
||||
*/
|
||||
function validateIP($ip)
|
||||
{
|
||||
if ($ip == long2ip(ip2long($ip))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ check_ip()
|
||||
|
||||
/**
|
||||
* Validate the syntax of the given IP address (compatibility)
|
||||
*
|
||||
* This function is identical to Net_IPv4::validateIP(). It is included
|
||||
* merely for compatibility reasons.
|
||||
*
|
||||
* @param string $ip IP address
|
||||
* @return bool true if syntax is valid, otherwise false
|
||||
*/
|
||||
function check_ip($ip)
|
||||
{
|
||||
return $this->validateIP($ip);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ validateNetmask()
|
||||
|
||||
/**
|
||||
* Validate the syntax of a four octet netmask
|
||||
*
|
||||
* There are 33 valid netmask values. This function will compare the
|
||||
* string passed as $netmask to the predefined 33 values and return
|
||||
* true or false. This is most likely much faster than performing the
|
||||
* calculation to determine the validity of the netmask.
|
||||
*
|
||||
* @param string $netmask Netmask
|
||||
* @return bool true if syntax is valid, otherwise false
|
||||
*/
|
||||
function validateNetmask($netmask)
|
||||
{
|
||||
if (! in_array($netmask, $GLOBALS['Net_IPv4_Netmask_Map'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ parseAddress()
|
||||
|
||||
/**
|
||||
* Parse a formatted IP address
|
||||
*
|
||||
* Given a network qualified IP address, attempt to parse out the parts
|
||||
* and calculate qualities of the address.
|
||||
*
|
||||
* The following formats are possible:
|
||||
*
|
||||
* [dot quad ip]/[ bitmask ]
|
||||
* [dot quad ip]/[ dot quad netmask ]
|
||||
* [dot quad ip]/[ hex string netmask ]
|
||||
*
|
||||
* The first would be [IP Address]/[BitMask]:
|
||||
* 192.168.0.0/16
|
||||
*
|
||||
* The second would be [IP Address] [Subnet Mask in dot quad notation]:
|
||||
* 192.168.0.0/255.255.0.0
|
||||
*
|
||||
* The third would be [IP Address] [Subnet Mask as Hex string]
|
||||
* 192.168.0.0/ffff0000
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $cidr = '192.168.0.50/16';
|
||||
* $net = Net_IPv4::parseAddress($cidr);
|
||||
* echo $net->network; // 192.168.0.0
|
||||
* echo $net->ip; // 192.168.0.50
|
||||
* echo $net->broadcast; // 192.168.255.255
|
||||
* echo $net->bitmask; // 16
|
||||
* echo $net->long; // 3232235520 (long/double version of 192.168.0.50)
|
||||
* echo $net->netmask; // 255.255.0.0
|
||||
*
|
||||
* @param string $ip IP address netmask combination
|
||||
* @return object true if syntax is valid, otherwise false
|
||||
*/
|
||||
function parseAddress($address)
|
||||
{
|
||||
$myself = new Net_IPv4;
|
||||
if (strchr($address, "/")) {
|
||||
$parts = explode("/", $address);
|
||||
if (! $myself->validateIP($parts[0])) {
|
||||
return PEAR::raiseError("invalid IP address");
|
||||
}
|
||||
$myself->ip = $parts[0];
|
||||
|
||||
// Check the style of netmask that was entered
|
||||
/*
|
||||
* a hexadecimal string was entered
|
||||
*/
|
||||
if (preg_match("/([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/", $parts[1], $regs)) {
|
||||
// hexadecimal string
|
||||
$myself->netmask = hexdec($regs[1]) . "." . hexdec($regs[2]) . "." .
|
||||
hexdec($regs[3]) . "." . hexdec($regs[4]);
|
||||
|
||||
/*
|
||||
* a standard dot quad netmask was entered.
|
||||
*/
|
||||
} else if (strchr($parts[1], ".")) {
|
||||
if (! $myself->validateNetmask($parts[1])) {
|
||||
return PEAR::raiseError("invalid netmask value");
|
||||
}
|
||||
$myself->netmask = $parts[1];
|
||||
|
||||
/*
|
||||
* a CIDR bitmask type was entered
|
||||
*/
|
||||
} else if ($parts[1] >= 0 && $parts[1] <= 32) {
|
||||
// bitmask was entered
|
||||
$myself->bitmask = $parts[1];
|
||||
|
||||
/*
|
||||
* Some unknown format of netmask was entered
|
||||
*/
|
||||
} else {
|
||||
return PEAR::raiseError("invalid netmask value");
|
||||
}
|
||||
$myself->calculate();
|
||||
return $myself;
|
||||
} else if ($myself->validateIP($address)) {
|
||||
$myself->ip = $address;
|
||||
return $myself;
|
||||
} else {
|
||||
return PEAR::raiseError("invalid IP address");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ calculate()
|
||||
|
||||
/**
|
||||
* Calculates network information based on an IP address and netmask.
|
||||
*
|
||||
* Fully populates the object properties based on the IP address and
|
||||
* netmask/bitmask properties. Once these two fields are populated,
|
||||
* calculate() will perform calculations to determine the network and
|
||||
* broadcast address of the network.
|
||||
*
|
||||
* @return mixed true if no errors occured, otherwise PEAR_Error object
|
||||
*/
|
||||
function calculate()
|
||||
{
|
||||
$validNM = $GLOBALS['Net_IPv4_Netmask_Map'];
|
||||
|
||||
if (! is_a($this, "net_ipv4")) {
|
||||
$myself = new Net_IPv4;
|
||||
return PEAR::raiseError("cannot calculate on uninstantiated Net_IPv4 class");
|
||||
}
|
||||
|
||||
/* Find out if we were given an ip address in dot quad notation or
|
||||
* a network long ip address. Whichever was given, populate the
|
||||
* other field
|
||||
*/
|
||||
if (strlen($this->ip)) {
|
||||
if (! $this->validateIP($this->ip)) {
|
||||
return PEAR::raiseError("invalid IP address");
|
||||
}
|
||||
$this->long = $this->ip2double($this->ip);
|
||||
} else if (is_numeric($this->long)) {
|
||||
$this->ip = long2ip($this->long);
|
||||
} else {
|
||||
return PEAR::raiseError("ip address not specified");
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if we were supplied with a bitmask or a netmask.
|
||||
* Populate the other field as needed.
|
||||
*/
|
||||
if (strlen($this->bitmask)) {
|
||||
$this->netmask = $validNM[$this->bitmask];
|
||||
} else if (strlen($this->netmask)) {
|
||||
$validNM_rev = array_flip($validNM);
|
||||
$this->bitmask = $validNM_rev[$this->netmask];
|
||||
} else {
|
||||
return PEAR::raiseError("netmask or bitmask are required for calculation");
|
||||
}
|
||||
$this->network = long2ip(ip2long($this->ip) & ip2long($this->netmask));
|
||||
$this->broadcast = long2ip(ip2long($this->ip) |
|
||||
(ip2long($this->netmask) ^ ip2long("255.255.255.255")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getNetmask()
|
||||
|
||||
function getNetmask($length)
|
||||
{
|
||||
if (! PEAR::isError($ipobj = Net_IPv4::parseAddress("0.0.0.0/" . $length))) {
|
||||
$mask = $ipobj->netmask;
|
||||
unset($ipobj);
|
||||
return $mask;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getNetLength()
|
||||
|
||||
function getNetLength($netmask)
|
||||
{
|
||||
if (! PEAR::isError($ipobj = Net_IPv4::parseAddress("0.0.0.0/" . $netmask))) {
|
||||
$bitmask = $ipobj->bitmask;
|
||||
unset($ipobj);
|
||||
return $bitmask;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSubnet()
|
||||
|
||||
function getSubnet($ip, $netmask)
|
||||
{
|
||||
if (! PEAR::isError($ipobj = Net_IPv4::parseAddress($ip . "/" . $netmask))) {
|
||||
$net = $ipobj->network;
|
||||
unset($ipobj);
|
||||
return $net;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ inSameSubnet()
|
||||
|
||||
function inSameSubnet($ip1, $ip2)
|
||||
{
|
||||
if (! is_object($ip1) || strcasecmp(get_class($ip1), 'net_ipv4') <> 0) {
|
||||
$ipobj1 = Net_IPv4::parseAddress($ip1);
|
||||
if (PEAR::isError($ipobj)) {
|
||||
return PEAR::raiseError("IP addresses must be an understood format or a Net_IPv4 object");
|
||||
}
|
||||
}
|
||||
if (! is_object($ip2) || strcasecmp(get_class($ip2), 'net_ipv4') <> 0) {
|
||||
$ipobj2 = Net_IPv4::parseAddress($ip2);
|
||||
if (PEAR::isError($ipobj)) {
|
||||
return PEAR::raiseError("IP addresses must be an understood format or a Net_IPv4 object");
|
||||
}
|
||||
}
|
||||
if ($ipobj1->network == $ipobj2->network &&
|
||||
$ipobj1->bitmask == $ipobj2->bitmask) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ atoh()
|
||||
|
||||
/**
|
||||
* Converts a dot-quad formatted IP address into a hexadecimal string
|
||||
* @param string $addr IP-adress in dot-quad format
|
||||
* @return mixed false if invalid IP and hexadecimal representation as string if valid
|
||||
*/
|
||||
function atoh($addr)
|
||||
{
|
||||
if (! Net_IPv4::validateIP($addr)) {
|
||||
return false;
|
||||
}
|
||||
$ap = explode(".", $addr);
|
||||
return sprintf("%02x%02x%02x%02x", $ap[0], $ap[1], $ap[2], $ap[3]);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ htoa()
|
||||
|
||||
/**
|
||||
* Converts a hexadecimal string into a dot-quad formatted IP address
|
||||
* @param string $addr IP-adress in hexadecimal format
|
||||
* @return mixed false if invalid IP and dot-quad formatted IP as string if valid
|
||||
*/
|
||||
function htoa($addr)
|
||||
{
|
||||
if (preg_match("/([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/",
|
||||
$addr, $regs)) {
|
||||
return hexdec($regs[1]) . "." . hexdec($regs[2]) . "." .
|
||||
hexdec($regs[3]) . "." . hexdec($regs[4]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ ip2double()
|
||||
|
||||
/**
|
||||
* Converts an IP address to a PHP double. Better than ip2long because
|
||||
* a long in PHP is a signed integer.
|
||||
* @param string $ip dot-quad formatted IP adress
|
||||
* @return float IP adress as double - positive value unlike ip2long
|
||||
*/
|
||||
function ip2double($ip)
|
||||
{
|
||||
return (double)(sprintf("%u", ip2long($ip)));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ ipInNetwork()
|
||||
|
||||
/**
|
||||
* Determines whether or not the supplied IP is within the supplied network.
|
||||
*
|
||||
* This function determines whether an IP address is within a network.
|
||||
* The IP address ($ip) must be supplied in dot-quad format, and the
|
||||
* network ($network) may be either a string containing a CIDR
|
||||
* formatted network definition, or a Net_IPv4 object.
|
||||
*
|
||||
* @param string $ip A dot quad representation of an IP address
|
||||
* @param string $network A string representing the network in CIDR format or a Net_IPv4 object.
|
||||
* @return bool true if the IP address exists within the network
|
||||
*/
|
||||
function ipInNetwork($ip, $network)
|
||||
{
|
||||
if (! is_object($network) || strcasecmp(get_class($network), 'net_ipv4') <> 0) {
|
||||
$network = Net_IPv4::parseAddress($network);
|
||||
}
|
||||
|
||||
$net = Net_IPv4::ip2double($network->network);
|
||||
$bcast = Net_IPv4::ip2double($network->broadcast);
|
||||
$ip = Net_IPv4::ip2double($ip);
|
||||
unset($network);
|
||||
if ($ip >= $net && $ip <= $bcast) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* vim: sts=4 ts=4 sw=4 cindent fdm=marker
|
||||
*/
|
||||
?>
|
||||
218
thirdparty/pear/Net/IPv6.php
vendored
218
thirdparty/pear/Net/IPv6.php
vendored
@@ -1,218 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Alexander Merz <alexander.merz@web.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: IPv6.php,v 1.12 2005/09/01 12:42:00 alexmerz Exp $
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@t-online.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @package Net_IPv6
|
||||
* @version $Id: IPv6.php,v 1.12 2005/09/01 12:42:00 alexmerz Exp $
|
||||
* @access public
|
||||
*/
|
||||
class Net_IPv6 {
|
||||
|
||||
// {{{ Uncompress()
|
||||
|
||||
/**
|
||||
* Uncompresses an IPv6 adress
|
||||
*
|
||||
* RFC 2373 allows you to compress zeros in an adress to '::'. This
|
||||
* function expects an valid IPv6 adress and expands the '::' to
|
||||
* the required zeros.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @access public
|
||||
* @see Compress()
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-adress (hex format)
|
||||
* @return string the uncompressed IPv6-adress (hex format)
|
||||
*/
|
||||
function Uncompress($ip) {
|
||||
$uip = $ip;
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (false !== strpos($ip, '::') ) {
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
if(""==$ip1) {
|
||||
$c1 = -1;
|
||||
} else {
|
||||
$pos = 0;
|
||||
if(0 < ($pos = substr_count($ip1, ':'))) {
|
||||
$c1 = $pos;
|
||||
} else {
|
||||
$c1 = 0;
|
||||
}
|
||||
}
|
||||
if(""==$ip2) {
|
||||
$c2 = -1;
|
||||
} else {
|
||||
$pos = 0;
|
||||
if(0 < ($pos = substr_count($ip2, ':'))) {
|
||||
$c2 = $pos;
|
||||
} else {
|
||||
$c2 = 0;
|
||||
}
|
||||
}
|
||||
if(strstr($ip2, '.')) {
|
||||
$c2++;
|
||||
}
|
||||
if(-1 == $c1 && -1 == $c2) { // ::
|
||||
$uip = "0:0:0:0:0:0:0:0";
|
||||
} else if(-1==$c1) { // ::xxx
|
||||
$fill = str_repeat('0:', 7-$c2);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
} else if(-1==$c2) { // xxx::
|
||||
$fill = str_repeat(':0', 7-$c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
} else { // xxx::xxx
|
||||
$fill = str_repeat(':0:', 6-$c2-$c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
$uip = str_replace('::', ':', $uip);
|
||||
}
|
||||
}
|
||||
return $uip;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ Compress()
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 adress
|
||||
*
|
||||
* RFC 2373 allows you to compress zeros in an adress to '::'. This
|
||||
* function expects an valid IPv6 adress and compresses successive zeros
|
||||
* to '::'
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @access public
|
||||
* @see Uncompress()
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-adress (hex format)
|
||||
* @return string the compressed IPv6-adress (hex format)
|
||||
* @author elfrink at introweb dot nl
|
||||
*/
|
||||
function Compress($ip) {
|
||||
$cip = $ip;
|
||||
|
||||
if (!strstr($ip, '::')) {
|
||||
$ipp = explode(':',$ip);
|
||||
for($i=0; $i<count($ipp); $i++) {
|
||||
$ipp[$i] = dechex(hexdec($ipp[$i]));
|
||||
}
|
||||
$cip = ':' . join(':',$ipp) . ':';
|
||||
preg_match_all("/(:0)+/", $cip, $zeros);
|
||||
if (count($zeros[0])>0) {
|
||||
$match = '';
|
||||
foreach($zeros[0] as $zero) {
|
||||
if (strlen($zero) > strlen($match))
|
||||
$match = $zero;
|
||||
}
|
||||
$cip = preg_replace('/' . $match . '/', ':', $cip, 1);
|
||||
}
|
||||
$cip = preg_replace('/((^:)|(:$))/', '' ,$cip);
|
||||
$cip = preg_replace('/((^:)|(:$))/', '::' ,$cip);
|
||||
}
|
||||
return $cip;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ SplitV64()
|
||||
|
||||
/**
|
||||
* Splits an IPv6 adress into the IPv6 and a possible IPv4 part
|
||||
*
|
||||
* RFC 2373 allows you to note the last two parts of an IPv6 adress as
|
||||
* an IPv4 compatible adress
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-adress (hex format)
|
||||
* @return array [0] contains the IPv6 part, [1] the IPv4 part (hex format)
|
||||
*/
|
||||
function SplitV64($ip) {
|
||||
$ip = Net_IPv6::Uncompress($ip);
|
||||
if (strstr($ip, '.')) {
|
||||
$pos = strrpos($ip, ':');
|
||||
$ip{$pos} = '_';
|
||||
$ipPart = explode('_', $ip);
|
||||
return $ipPart;
|
||||
} else {
|
||||
return array($ip, "");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ checkIPv6
|
||||
|
||||
/**
|
||||
* Checks an IPv6 adress
|
||||
*
|
||||
* Checks if the given IP is IPv6-compatible
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-adress
|
||||
* @return boolean true if $ip is an IPv6 adress
|
||||
*/
|
||||
function checkIPv6($ip) {
|
||||
|
||||
$ipPart = Net_IPv6::SplitV64($ip);
|
||||
$count = 0;
|
||||
if (!empty($ipPart[0])) {
|
||||
$ipv6 =explode(':', $ipPart[0]);
|
||||
for ($i = 0; $i < count($ipv6); $i++) {
|
||||
$dec = hexdec($ipv6[$i]);
|
||||
$hex = strtoupper(preg_replace("/^[0]{1,3}(.*[0-9a-fA-F])$/", "\\1", $ipv6[$i]));
|
||||
if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex == strtoupper(dechex($dec))) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (8 == $count) {
|
||||
return true;
|
||||
} elseif (6 == $count and !empty($ipPart[1])) {
|
||||
$ipv4 = explode('.',$ipPart[1]);
|
||||
$count = 0;
|
||||
for ($i = 0; $i < count($ipv4); $i++) {
|
||||
if ($ipv4[$i] >= 0 && (integer)$ipv4[$i] <= 255 && preg_match("/^\d{1,3}$/", $ipv4[$i])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (4 == $count) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
806
thirdparty/pear/Net/JSON.php
vendored
806
thirdparty/pear/Net/JSON.php
vendored
@@ -1,806 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Converts to and from JSON format.
|
||||
*
|
||||
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
||||
* format. It is easy for humans to read and write. It is easy for machines
|
||||
* to parse and generate. It is based on a subset of the JavaScript
|
||||
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
||||
* This feature can also be found in Python. JSON is a text format that is
|
||||
* completely language independent but uses conventions that are familiar
|
||||
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
||||
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
||||
* ideal data-interchange language.
|
||||
*
|
||||
* This package provides a simple encoder and decoder for JSON notation. It
|
||||
* is intended for use with client-side Javascript applications that make
|
||||
* use of HTTPRequest to perform server communication functions - data can
|
||||
* be encoded into JSON notation for use in a client-side javascript, or
|
||||
* decoded from incoming Javascript requests. JSON format is native to
|
||||
* Javascript, and can be directly eval()'ed with no further parsing
|
||||
* overhead
|
||||
*
|
||||
* All strings should be in ASCII or UTF-8 format!
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met: Redistributions of source code must retain the
|
||||
* above copyright notice, this list of conditions and the following
|
||||
* disclaimer. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* @category
|
||||
* @package Services_JSON
|
||||
* @author Michal Migurski <mike-json@teczno.com>
|
||||
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
||||
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
||||
* @copyright 2005 Michal Migurski
|
||||
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_SLICE', 1);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_STR', 2);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_ARR', 3);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_OBJ', 4);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_CMT', 5);
|
||||
|
||||
/**
|
||||
* Behavior switch for Services_JSON::decode()
|
||||
*/
|
||||
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
||||
|
||||
/**
|
||||
* Behavior switch for Services_JSON::decode()
|
||||
*/
|
||||
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
||||
|
||||
/**
|
||||
* Converts to and from JSON format.
|
||||
*
|
||||
* Brief example of use:
|
||||
*
|
||||
* <code>
|
||||
* // create a new instance of Services_JSON
|
||||
* $json = new Services_JSON();
|
||||
*
|
||||
* // convert a complexe value to JSON notation, and send it to the browser
|
||||
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
||||
* $output = $json->encode($value);
|
||||
*
|
||||
* print($output);
|
||||
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
||||
*
|
||||
* // accept incoming POST data, assumed to be in JSON notation
|
||||
* $input = file_get_contents('php://input', 1000000);
|
||||
* $value = $json->decode($input);
|
||||
* </code>
|
||||
*/
|
||||
class Services_JSON
|
||||
{
|
||||
/**
|
||||
* constructs a new JSON instance
|
||||
*
|
||||
* @param int $use object behavior flags; combine with boolean-OR
|
||||
*
|
||||
* possible values:
|
||||
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
||||
* "{...}" syntax creates associative arrays
|
||||
* instead of objects in decode().
|
||||
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
||||
* Values which can't be encoded (e.g. resources)
|
||||
* appear as NULL instead of throwing errors.
|
||||
* By default, a deeply-nested resource will
|
||||
* bubble up with an error, so all return values
|
||||
* from encode() should be checked with isError()
|
||||
*/
|
||||
function Services_JSON($use = 0)
|
||||
{
|
||||
$this->use = $use;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-16 char to one UTF-8 char
|
||||
*
|
||||
* Normally should be handled by mb_convert_encoding, but
|
||||
* provides a slower PHP-only method for installations
|
||||
* that lack the multibye string extension.
|
||||
*
|
||||
* @param string $utf16 UTF-16 character
|
||||
* @return string UTF-8 character
|
||||
* @access private
|
||||
*/
|
||||
function utf162utf8($utf16)
|
||||
{
|
||||
// oh please oh please oh please oh please oh please
|
||||
if(function_exists('mb_convert_encoding')) {
|
||||
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
||||
}
|
||||
|
||||
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
||||
|
||||
switch(true) {
|
||||
case ((0x7F & $bytes) == $bytes):
|
||||
// this case should never be reached, because we are in ASCII range
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0x7F & $bytes);
|
||||
|
||||
case (0x07FF & $bytes) == $bytes:
|
||||
// return a 2-byte UTF-8 character
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
||||
. chr(0x80 | ($bytes & 0x3F));
|
||||
|
||||
case (0xFFFF & $bytes) == $bytes:
|
||||
// return a 3-byte UTF-8 character
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
||||
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
||||
. chr(0x80 | ($bytes & 0x3F));
|
||||
}
|
||||
|
||||
// ignoring UTF-32 for now, sorry
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-8 char to one UTF-16 char
|
||||
*
|
||||
* Normally should be handled by mb_convert_encoding, but
|
||||
* provides a slower PHP-only method for installations
|
||||
* that lack the multibye string extension.
|
||||
*
|
||||
* @param string $utf8 UTF-8 character
|
||||
* @return string UTF-16 character
|
||||
* @access private
|
||||
*/
|
||||
function utf82utf16($utf8)
|
||||
{
|
||||
// oh please oh please oh please oh please oh please
|
||||
if(function_exists('mb_convert_encoding')) {
|
||||
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
||||
}
|
||||
|
||||
switch(strlen($utf8)) {
|
||||
case 1:
|
||||
// this case should never be reached, because we are in ASCII range
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return $utf8;
|
||||
|
||||
case 2:
|
||||
// return a UTF-16 character from a 2-byte UTF-8 char
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0x07 & (ord($utf8{0}) >> 2))
|
||||
. chr((0xC0 & (ord($utf8{0}) << 6))
|
||||
| (0x3F & ord($utf8{1})));
|
||||
|
||||
case 3:
|
||||
// return a UTF-16 character from a 3-byte UTF-8 char
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr((0xF0 & (ord($utf8{0}) << 4))
|
||||
| (0x0F & (ord($utf8{1}) >> 2)))
|
||||
. chr((0xC0 & (ord($utf8{1}) << 6))
|
||||
| (0x7F & ord($utf8{2})));
|
||||
}
|
||||
|
||||
// ignoring UTF-32 for now, sorry
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* encodes an arbitrary variable into JSON format
|
||||
*
|
||||
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
||||
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
||||
* if var is a strng, note that encode() always expects it
|
||||
* to be in ASCII or UTF-8 format!
|
||||
*
|
||||
* @return mixed JSON string representation of input var or an error if a problem occurs
|
||||
* @access public
|
||||
*/
|
||||
function encode($var)
|
||||
{
|
||||
switch (gettype($var)) {
|
||||
case 'boolean':
|
||||
return $var ? 'true' : 'false';
|
||||
|
||||
case 'NULL':
|
||||
return 'null';
|
||||
|
||||
case 'integer':
|
||||
return (int) $var;
|
||||
|
||||
case 'double':
|
||||
case 'float':
|
||||
return (float) $var;
|
||||
|
||||
case 'string':
|
||||
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
||||
$ascii = '';
|
||||
$strlen_var = strlen($var);
|
||||
|
||||
/*
|
||||
* Iterate over every character in the string,
|
||||
* escaping with a slash or encoding to UTF-8 where necessary
|
||||
*/
|
||||
for ($c = 0; $c < $strlen_var; ++$c) {
|
||||
|
||||
$ord_var_c = ord($var{$c});
|
||||
|
||||
switch (true) {
|
||||
case $ord_var_c == 0x08:
|
||||
$ascii .= '\b';
|
||||
break;
|
||||
case $ord_var_c == 0x09:
|
||||
$ascii .= '\t';
|
||||
break;
|
||||
case $ord_var_c == 0x0A:
|
||||
$ascii .= '\n';
|
||||
break;
|
||||
case $ord_var_c == 0x0C:
|
||||
$ascii .= '\f';
|
||||
break;
|
||||
case $ord_var_c == 0x0D:
|
||||
$ascii .= '\r';
|
||||
break;
|
||||
|
||||
case $ord_var_c == 0x22:
|
||||
case $ord_var_c == 0x2F:
|
||||
case $ord_var_c == 0x5C:
|
||||
// double quote, slash, slosh
|
||||
$ascii .= '\\'.$var{$c};
|
||||
break;
|
||||
|
||||
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
||||
// characters U-00000000 - U-0000007F (same as ASCII)
|
||||
$ascii .= $var{$c};
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xE0) == 0xC0):
|
||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
||||
$c += 1;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xF0) == 0xE0):
|
||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}));
|
||||
$c += 2;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xF8) == 0xF0):
|
||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}));
|
||||
$c += 3;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xFC) == 0xF8):
|
||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}),
|
||||
ord($var{$c + 4}));
|
||||
$c += 4;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xFE) == 0xFC):
|
||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}),
|
||||
ord($var{$c + 4}),
|
||||
ord($var{$c + 5}));
|
||||
$c += 5;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return '"'.$ascii.'"';
|
||||
|
||||
case 'array':
|
||||
/*
|
||||
* As per JSON spec if any array key is not an integer
|
||||
* we must treat the the whole array as an object. We
|
||||
* also try to catch a sparsely populated associative
|
||||
* array with numeric keys here because some JS engines
|
||||
* will create an array with empty indexes up to
|
||||
* max_index which can cause memory issues and because
|
||||
* the keys, which may be relevant, will be remapped
|
||||
* otherwise.
|
||||
*
|
||||
* As per the ECMA and JSON specification an object may
|
||||
* have any string as a property. Unfortunately due to
|
||||
* a hole in the ECMA specification if the key is a
|
||||
* ECMA reserved word or starts with a digit the
|
||||
* parameter is only accessible using ECMAScript's
|
||||
* bracket notation.
|
||||
*/
|
||||
|
||||
// treat as a JSON object
|
||||
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
||||
$properties = array_map(array($this, 'name_value'),
|
||||
array_keys($var),
|
||||
array_values($var));
|
||||
|
||||
foreach($properties as $property) {
|
||||
if(Services_JSON::isError($property)) {
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
|
||||
return '{' . join(',', $properties) . '}';
|
||||
}
|
||||
|
||||
// treat it like a regular array
|
||||
$elements = array_map(array($this, 'encode'), $var);
|
||||
|
||||
foreach($elements as $element) {
|
||||
if(Services_JSON::isError($element)) {
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
return '[' . join(',', $elements) . ']';
|
||||
|
||||
case 'object':
|
||||
$vars = get_object_vars($var);
|
||||
|
||||
$properties = array_map(array($this, 'name_value'),
|
||||
array_keys($vars),
|
||||
array_values($vars));
|
||||
|
||||
foreach($properties as $property) {
|
||||
if(Services_JSON::isError($property)) {
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
|
||||
return '{' . join(',', $properties) . '}';
|
||||
|
||||
default:
|
||||
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
||||
? 'null'
|
||||
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* array-walking function for use in generating JSON-formatted name-value pairs
|
||||
*
|
||||
* @param string $name name of key to use
|
||||
* @param mixed $value reference to an array element to be encoded
|
||||
*
|
||||
* @return string JSON-formatted name-value pair, like '"name":value'
|
||||
* @access private
|
||||
*/
|
||||
function name_value($name, $value)
|
||||
{
|
||||
$encoded_value = $this->encode($value);
|
||||
|
||||
if(Services_JSON::isError($encoded_value)) {
|
||||
return $encoded_value;
|
||||
}
|
||||
|
||||
return $this->encode(strval($name)) . ':' . $encoded_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* reduce a string by removing leading and trailing comments and whitespace
|
||||
*
|
||||
* @param $str string string value to strip of comments and whitespace
|
||||
*
|
||||
* @return string string value stripped of comments and whitespace
|
||||
* @access private
|
||||
*/
|
||||
function reduce_string($str)
|
||||
{
|
||||
$str = preg_replace(array(
|
||||
|
||||
// eliminate single line comments in '// ...' form
|
||||
'#^\s*//(.+)$#m',
|
||||
|
||||
// eliminate multi-line comments in '/* ... */' form, at start of string
|
||||
'#^\s*/\*(.+)\*/#Us',
|
||||
|
||||
// eliminate multi-line comments in '/* ... */' form, at end of string
|
||||
'#/\*(.+)\*/\s*$#Us'
|
||||
|
||||
), '', $str);
|
||||
|
||||
// eliminate extraneous space
|
||||
return trim($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes a JSON string into appropriate variable
|
||||
*
|
||||
* @param string $str JSON-formatted string
|
||||
*
|
||||
* @return mixed number, boolean, string, array, or object
|
||||
* corresponding to given JSON input string.
|
||||
* See argument 1 to Services_JSON() above for object-output behavior.
|
||||
* Note that decode() always returns strings
|
||||
* in ASCII or UTF-8 format!
|
||||
* @access public
|
||||
*/
|
||||
function decode($str)
|
||||
{
|
||||
$str = $this->reduce_string($str);
|
||||
|
||||
switch (strtolower($str)) {
|
||||
case 'true':
|
||||
return true;
|
||||
|
||||
case 'false':
|
||||
return false;
|
||||
|
||||
case 'null':
|
||||
return null;
|
||||
|
||||
default:
|
||||
$m = array();
|
||||
|
||||
if (is_numeric($str)) {
|
||||
// Lookie-loo, it's a number
|
||||
|
||||
// This would work on its own, but I'm trying to be
|
||||
// good about returning integers where appropriate:
|
||||
// return (float)$str;
|
||||
|
||||
// Return float or int, as appropriate
|
||||
return ((float)$str == (integer)$str)
|
||||
? (integer)$str
|
||||
: (float)$str;
|
||||
|
||||
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
||||
// STRINGS RETURNED IN UTF-8 FORMAT
|
||||
$delim = substr($str, 0, 1);
|
||||
$chrs = substr($str, 1, -1);
|
||||
$utf8 = '';
|
||||
$strlen_chrs = strlen($chrs);
|
||||
|
||||
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
||||
|
||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||
$ord_chrs_c = ord($chrs{$c});
|
||||
|
||||
switch (true) {
|
||||
case $substr_chrs_c_2 == '\b':
|
||||
$utf8 .= chr(0x08);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\t':
|
||||
$utf8 .= chr(0x09);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\n':
|
||||
$utf8 .= chr(0x0A);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\f':
|
||||
$utf8 .= chr(0x0C);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\r':
|
||||
$utf8 .= chr(0x0D);
|
||||
++$c;
|
||||
break;
|
||||
|
||||
case $substr_chrs_c_2 == '\\"':
|
||||
case $substr_chrs_c_2 == '\\\'':
|
||||
case $substr_chrs_c_2 == '\\\\':
|
||||
case $substr_chrs_c_2 == '\\/':
|
||||
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
||||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
||||
$utf8 .= $chrs{++$c};
|
||||
}
|
||||
break;
|
||||
|
||||
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
||||
// single, escaped unicode character
|
||||
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
||||
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
||||
$utf8 .= $this->utf162utf8($utf16);
|
||||
$c += 5;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
||||
$utf8 .= $chrs{$c};
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xE0) == 0xC0:
|
||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 2);
|
||||
++$c;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xF0) == 0xE0:
|
||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 3);
|
||||
$c += 2;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xF8) == 0xF0:
|
||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 4);
|
||||
$c += 3;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xFC) == 0xF8:
|
||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 5);
|
||||
$c += 4;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xFE) == 0xFC:
|
||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 6);
|
||||
$c += 5;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $utf8;
|
||||
|
||||
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
||||
// array, or object notation
|
||||
|
||||
if ($str{0} == '[') {
|
||||
$stk = array(SERVICES_JSON_IN_ARR);
|
||||
$arr = array();
|
||||
} else {
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||
$obj = array();
|
||||
} else {
|
||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||
$obj = new stdClass();
|
||||
}
|
||||
}
|
||||
|
||||
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
||||
'where' => 0,
|
||||
'delim' => false));
|
||||
|
||||
$chrs = substr($str, 1, -1);
|
||||
$chrs = $this->reduce_string($chrs);
|
||||
|
||||
if ($chrs == '') {
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
return $arr;
|
||||
|
||||
} else {
|
||||
return $obj;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//print("\nparsing {$chrs}\n");
|
||||
|
||||
$strlen_chrs = strlen($chrs);
|
||||
|
||||
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
||||
|
||||
$top = end($stk);
|
||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||
|
||||
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
||||
// found a comma that is not inside a string, array, etc.,
|
||||
// OR we've reached the end of the character list
|
||||
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
||||
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
||||
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
// we are in an array, so just push an element onto the stack
|
||||
array_push($arr, $this->decode($slice));
|
||||
|
||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||
// we are in an object, so figure
|
||||
// out the property name and set an
|
||||
// element in an associative array,
|
||||
// for now
|
||||
$parts = array();
|
||||
|
||||
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||
// "name":value pair
|
||||
$key = $this->decode($parts[1]);
|
||||
$val = $this->decode($parts[2]);
|
||||
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$obj[$key] = $val;
|
||||
} else {
|
||||
$obj->$key = $val;
|
||||
}
|
||||
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||
// name:value pair, where name is unquoted
|
||||
$key = $parts[1];
|
||||
$val = $this->decode($parts[2]);
|
||||
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$obj[$key] = $val;
|
||||
} else {
|
||||
$obj->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
||||
// found a quote, and we are not inside a string
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
||||
//print("Found start of string at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == $top['delim']) &&
|
||||
($top['what'] == SERVICES_JSON_IN_STR) &&
|
||||
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
||||
// found a quote, we're in a string, and it's not escaped
|
||||
// we know that it's not escaped becase there is _not_ an
|
||||
// odd number of backslashes at the end of the string so far
|
||||
array_pop($stk);
|
||||
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($chrs{$c} == '[') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a left-bracket, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
||||
//print("Found start of array at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
||||
// found a right-bracket, and we're in an array
|
||||
array_pop($stk);
|
||||
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($chrs{$c} == '{') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a left-brace, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
||||
//print("Found start of object at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
||||
// found a right-brace, and we're in an object
|
||||
array_pop($stk);
|
||||
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($substr_chrs_c_2 == '/*') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a comment start, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
||||
$c++;
|
||||
//print("Found start of comment at {$c}\n");
|
||||
|
||||
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
||||
// found a comment end, and we're in one now
|
||||
array_pop($stk);
|
||||
$c++;
|
||||
|
||||
for ($i = $top['where']; $i <= $c; ++$i)
|
||||
$chrs = substr_replace($chrs, ' ', $i, 1);
|
||||
|
||||
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
return $arr;
|
||||
|
||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Ultimately, this should just call PEAR::isError()
|
||||
*/
|
||||
function isError($data, $code = null)
|
||||
{
|
||||
if (class_exists('pear')) {
|
||||
return PEAR::isError($data, $code);
|
||||
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
||||
is_subclass_of($data, 'services_json_error'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('PEAR_Error')) {
|
||||
|
||||
class Services_JSON_Error extends PEAR_Error
|
||||
{
|
||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||
$mode = null, $options = null, $userinfo = null)
|
||||
{
|
||||
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* @todo Ultimately, this class shall be descended from PEAR_Error
|
||||
*/
|
||||
class Services_JSON_Error
|
||||
{
|
||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||
$mode = null, $options = null, $userinfo = null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1065
thirdparty/pear/Net/LDAP.php
vendored
1065
thirdparty/pear/Net/LDAP.php
vendored
File diff suppressed because it is too large
Load Diff
524
thirdparty/pear/Net/LDAP/Entry.php
vendored
524
thirdparty/pear/Net/LDAP/Entry.php
vendored
@@ -1,524 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Net_LDAP |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or |
|
||||
// | modify it under the terms of the GNU Lesser General Public |
|
||||
// | License as published by the Free Software Foundation; either |
|
||||
// | version 2.1 of the License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, |
|
||||
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Authors: Tarjej Huse |
|
||||
// +--------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Entry.php 4831 2006-02-06 09:59:09Z nbm $
|
||||
|
||||
/**
|
||||
* This class represents an LDAP entry
|
||||
*
|
||||
* @package Net_LDAP
|
||||
* @author Tarjei Huse
|
||||
* @version $Revision: 4831 $
|
||||
*/
|
||||
class Net_LDAP_Entry extends PEAR
|
||||
{
|
||||
/**#@+
|
||||
* Array of the attributes
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_attrs = array();
|
||||
|
||||
/**
|
||||
* Array of attributes to be deleted upon update()
|
||||
*/
|
||||
var $_delAttrs = array();
|
||||
|
||||
/**
|
||||
* Array of attributes to be modified upon update()
|
||||
*/
|
||||
var $_modAttrs = array();
|
||||
|
||||
/**
|
||||
* Array of attributes to be added upon update()
|
||||
*/
|
||||
var $_addAttrs = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* The distinguished name of the entry
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $_dn = '';
|
||||
|
||||
/**
|
||||
* LDAP resource link
|
||||
*
|
||||
* @access private
|
||||
* @var resource
|
||||
*/
|
||||
var $_link = null;
|
||||
|
||||
/**
|
||||
* Value of old DN if DN has changed
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $_olddn = '';
|
||||
|
||||
/**#@+
|
||||
* Array of errors for debugging class
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $_error = array();
|
||||
|
||||
/**
|
||||
* updatechecks
|
||||
*/
|
||||
var $updateCheck = array('newdn' => false,
|
||||
'modify' => false,
|
||||
'newEntry' => true
|
||||
); // since the entry is not changed before the update();
|
||||
|
||||
/**
|
||||
* Net_LDAP_Schema object TO BE REMOVED
|
||||
*/
|
||||
var $_schema;
|
||||
/**#@-*/
|
||||
|
||||
/** Constructor
|
||||
*
|
||||
* @param - link - ldap_resource_link, dn = string entry dn, attributes - array entry attributes array.
|
||||
* @return - none
|
||||
**/
|
||||
function Net_LDAP_Entry($link = null, $dn = null, $attributes = null)
|
||||
{
|
||||
if (!is_null($link)) {
|
||||
$this->_link = $link;
|
||||
}
|
||||
if (!is_null($dn)) {
|
||||
$this->_set_dn($dn);
|
||||
}
|
||||
if (is_array($attributes) && count($attributes) > 0) {
|
||||
$this->_set_attributes($attributes);
|
||||
} else {
|
||||
$this->updateCheck['newEntry'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reasourcelink to the ldapserver.
|
||||
*
|
||||
* @access private
|
||||
* @param resource LDAP link
|
||||
*/
|
||||
function _set_link(&$link)
|
||||
{
|
||||
$this->_link = $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the entrys DN
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
*/
|
||||
function _set_dn($dn)
|
||||
{
|
||||
$this->_dn = $dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the internal array of the entrys attributes.
|
||||
*
|
||||
* @access private
|
||||
* @param array
|
||||
*/
|
||||
function _set_attributes($attributes= array())
|
||||
{
|
||||
$this->_attrs = $attributes;
|
||||
// this is the sign that the entry exists in the first place:
|
||||
$this->updateCheck['newEntry'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes [count] entries from the array.
|
||||
*
|
||||
* remove all the count elements in the array:
|
||||
* Used before ldap_modify, ldap_add
|
||||
*
|
||||
* @access private
|
||||
* @return array Cleaned array of attributes
|
||||
*/
|
||||
function _clean_entry()
|
||||
{
|
||||
$attributes = array();
|
||||
|
||||
for ($i=0; $i < $this->_attrs['count'] ; $i++) {
|
||||
|
||||
$attr = $this->_attrs[$i];
|
||||
|
||||
if ($this->_attrs[$attr]['count'] == 1) {
|
||||
$attributes[$this->_attrs[$i]] = $this->_attrs[$attr][0];
|
||||
} else {
|
||||
$attributes[$attr] = $this->_attrs[$attr];
|
||||
unset ($attributes[ $attr ]['count']);
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an assosiative array of all the attributes in the array
|
||||
*
|
||||
* attributes - returns an assosiative array of all the attributes in the array
|
||||
* of the form array ('attributename'=>'singelvalue' , 'attribute'=>array('multiple','values'))
|
||||
*
|
||||
* @param none
|
||||
* @return array Array of attributes and values.
|
||||
*/
|
||||
function attributes()
|
||||
{
|
||||
return $this->_clean_entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one or more attribute to the entry
|
||||
*
|
||||
* The values given will be added to the values which already exist for the given attributes.
|
||||
* usage:
|
||||
* $entry->add ( array('sn'=>'huse',objectclass=>array(top,posixAccount)))
|
||||
*
|
||||
* @param array Array of attributes
|
||||
* @return mixed Net_Ldap_Error if error, else true.
|
||||
*/
|
||||
function add($attr = array())
|
||||
{
|
||||
if (!isset($this->_attrs['count'])) {
|
||||
$this->_attrs['count'] = 0;
|
||||
}
|
||||
if (!is_array($attr)) {
|
||||
return $this->raiseError("Net_LDAP::add : the parameter supplied is not an array, $attr", 1000);
|
||||
}
|
||||
/* if you passed an empty array, that is your problem! */
|
||||
if (count ($attr)==0) {
|
||||
return true;
|
||||
}
|
||||
foreach ($attr as $k => $v ) {
|
||||
// empty entrys should not be added to the entry.
|
||||
if ($v == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->exists($k)) {
|
||||
if (!is_array($this->_attrs[$k])) {
|
||||
return $this->raiseError("Possible malformed array as parameter to Net_LDAP::add().");
|
||||
}
|
||||
array_push($this->_attrs[$k],$v);
|
||||
$this->_attrs[$k]['count']++;
|
||||
} else {
|
||||
$this->_attrs[$k][0] = $v;
|
||||
$this->_attrs[$k]['count'] = 1;
|
||||
$this->_attrs[$this->_attrs['count']] = $k;
|
||||
$this->_attrs['count']++;
|
||||
}
|
||||
// Fix for bug #952
|
||||
if (empty($this->_addAttrs[$k])) {
|
||||
$this->_addAttrs[$k] = array();
|
||||
}
|
||||
if (false == is_array($v)) {
|
||||
$v = array($v);
|
||||
}
|
||||
foreach ($v as $value) {
|
||||
array_push($this->_addAttrs[$k], $value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or get the DN for the object
|
||||
*
|
||||
* If a new dn is supplied, this will move the object when running $obj->update();
|
||||
*
|
||||
* @param string DN
|
||||
*/
|
||||
function dn($newdn = '')
|
||||
{
|
||||
if ($newdn == '') {
|
||||
return $this->_dn;
|
||||
}
|
||||
|
||||
$this->_olddn = $this->_dn;
|
||||
$this->_dn = $newdn;
|
||||
$this->updateCheck['newdn'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a certain attribute exists in the directory
|
||||
*
|
||||
* @param string attribute name.
|
||||
* @return boolean
|
||||
*/
|
||||
function exists($attr)
|
||||
{
|
||||
if (array_key_exists($attr, $this->_attrs)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_value get the values for a attribute
|
||||
*
|
||||
* returns either an array or a string
|
||||
* possible values for option:
|
||||
* alloptions - returns an array with the values + a countfield.
|
||||
* i.e.: array (count=>1, 'sn'=>'huse');
|
||||
* single - returns the, first value in the array as a string.
|
||||
*
|
||||
* @param $attr string attribute name
|
||||
* @param $options array
|
||||
*/
|
||||
function get_value($attr = '', $options = '')
|
||||
{
|
||||
if (array_key_exists($attr, $this->_attrs)) {
|
||||
|
||||
if ($options == 'single') {
|
||||
if (is_array($this->_attrs[$attr])) {
|
||||
return $this->_attrs[$attr][0];
|
||||
} else {
|
||||
return $this->_attrs[$attr];
|
||||
}
|
||||
}
|
||||
|
||||
$value = $this->_attrs[$attr];
|
||||
|
||||
if (!$options == 'alloptions') {
|
||||
unset ($value['count']);
|
||||
}
|
||||
return $value;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add/delete/modify attributes
|
||||
*
|
||||
* this function tries to do all the things that replace(),delete() and add() does on an object.
|
||||
* Syntax:
|
||||
* array ( 'attribute' => newval, 'delattribute' => '', newattrivute => newval);
|
||||
* Note: You cannot use this function to modify parts of an attribute. You must modify the whole attribute.
|
||||
* You may call the function many times before running $entry->update();
|
||||
*
|
||||
* @param array attributes to be modified
|
||||
* @return mixed errorObject if failure, true if success.
|
||||
*/
|
||||
function modify($attrs = array()) {
|
||||
|
||||
if (!is_array($attrs) || count ($attrs) < 1 ) {
|
||||
return $this->raiseError("You did not supply an array as expected",1000);
|
||||
}
|
||||
|
||||
foreach ($attrs as $k => $v) {
|
||||
// empty values are deleted (ldap v3 handling is in update() )
|
||||
if ($v == '' && $this->exists($k)) {
|
||||
$this->_delAttrs[$k] = '';
|
||||
continue;
|
||||
}
|
||||
/* existing attributes are modified*/
|
||||
if ($this->exists($k) ) {
|
||||
if (is_array($v)) {
|
||||
$this->_modAttrs[$k] = $v;
|
||||
} else {
|
||||
$this->_modAttrs[$k][0] = $v;
|
||||
}
|
||||
} else {
|
||||
/* new ones are created */
|
||||
if (is_array($v) ) {
|
||||
// an empty array is deleted...
|
||||
if (count($v) == 0 ) {
|
||||
$this->_delAttrs[$k] = '';
|
||||
} else {
|
||||
$this->_addAttrs[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
// dont't add empty attributes
|
||||
if ($v != null) $this->_addAttrs[$k][0] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* replace a certain attributes value
|
||||
*
|
||||
* replace - replace a certain attributes value
|
||||
* example:
|
||||
* $entry->replace(array('uid'=>array('tarjei')));
|
||||
*
|
||||
* @param array attributes to be replaced
|
||||
* @return mixed error if failure, true if sucess.
|
||||
*/
|
||||
function replace($attrs = array() )
|
||||
{
|
||||
foreach ($attrs as $k => $v) {
|
||||
|
||||
if ($this->exists($k)) {
|
||||
|
||||
if (is_array($v)) {
|
||||
$this->_attrs[$k] = $v;
|
||||
$this->_attrs[$k]['count'] = count($v);
|
||||
$this->_modAttrs[$k] = $v;
|
||||
} else {
|
||||
$this->_attrs[$k]['count'] = 1;
|
||||
$this->_attrs[$k][0] = $v;
|
||||
$this->_modAttrs[$k][0] = $v;
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError("Attribute $k does not exist",16); // 16 = no such attribute exists.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete attributes
|
||||
*
|
||||
* Use this function to delete certain attributes from an object.
|
||||
*
|
||||
* @param - array of attributes to be deleted
|
||||
* @return mixed Net_Ldap_Error if failure, true if success.
|
||||
*/
|
||||
function delete($attrs = array())
|
||||
{
|
||||
foreach ($attrs as $k => $v) {
|
||||
|
||||
if ($this->exists ($k)) {
|
||||
// if v is a null, then remove the whole attribute, else only the value.
|
||||
if ($v == '') {
|
||||
unset($this->_attrs[$k]);
|
||||
$this->_delAttrs[$k] = "";
|
||||
// else we remove only the correct value.
|
||||
} else {
|
||||
for ($i = 0;$i< $this->_attrs[$k]['count'];$i++) {
|
||||
if ($this->_attrs[$k][$i] == $v ) {
|
||||
unset ($this->_attrs[$k][$i]);
|
||||
$this->_delAttrs[$k] = $v;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->raiseError("You tried to delete a nonexisting attribute!",16);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* update the Entry in LDAP
|
||||
*
|
||||
* After modifying an object, you must run update() to
|
||||
* make the updates on the ldap server. Before that, they only exists in the object.
|
||||
*
|
||||
* @param object Net_LDAP
|
||||
* @return mixed Net_LDAP_Error object on failure or true on success
|
||||
*/
|
||||
function update ($ldapObject = null)
|
||||
{
|
||||
if ($ldapObject == null && $this->_link == null ) {
|
||||
$this->raiseError("No link to database");
|
||||
}
|
||||
|
||||
if ($ldapObject != null) {
|
||||
$this->_link =& $ldapObject->_link;
|
||||
}
|
||||
|
||||
//if it's a new
|
||||
if ($this->updateCheck['newdn'] && !$this->updateCheck['newEntry']) {
|
||||
if (@ldap_get_option( $this->_link, LDAP_OPT_PROTOCOL_VERSION, $version) && $version != 3) {
|
||||
return $this->raiseError("Moving or renaming an dn is only supported in LDAP V3!", 80);
|
||||
}
|
||||
|
||||
$newparent = ldap_explode_dn($this->_dn, 0);
|
||||
unset($newparent['count']);
|
||||
$relativeDn = array_shift($newparent);
|
||||
$newparent = join(',', $newparent);
|
||||
|
||||
if (!@ldap_rename($this->_link, $this->_olddn, $relativeDn, $newparent, true)) {
|
||||
return $this->raiseError("DN not renamed: " . ldap_error($this->_link), ldap_errno($this->_link));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->updateCheck['newEntry']) {
|
||||
//print "<br>"; print_r($this->_clean_entry());
|
||||
|
||||
if (!@ldap_add($this->_link, $this->dn(), $this->_clean_entry()) ) {
|
||||
return $this->raiseError("Entry" . $this->dn() . " not added!" .
|
||||
ldap_error($this->_link), ldap_errno($this->_link));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
// update existing entry
|
||||
} else {
|
||||
$this->_error['first'] = $this->_modAttrs;
|
||||
$this->_error['count'] = count($this->_modAttrs);
|
||||
|
||||
// modified attributes
|
||||
if (( count($this->_modAttrs)>0) &&
|
||||
!ldap_modify($this->_link, $this->dn(), $this->_modAttrs))
|
||||
{
|
||||
return $this->raiseError("Entry " . $this->dn() . " not modified(attribs not modified): " .
|
||||
ldap_error($this->_link),ldap_errno($this->_link));
|
||||
}
|
||||
|
||||
// attributes to be deleted
|
||||
if (( count($this->_delAttrs) > 0 ))
|
||||
{
|
||||
// in ldap v3 we need to supply the old attribute values for deleting
|
||||
if (@ldap_get_option( $this->_link, LDAP_OPT_PROTOCOL_VERSION, $version) && $version == 3) {
|
||||
foreach ( $this->_delAttrs as $k => $v ) {
|
||||
if ( $v == '' && $this->exists($k) ) {
|
||||
$this->_delAttrs[$k] = $this->get_value( $k );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !ldap_mod_del($this->_link, $this->dn(), $this->_delAttrs) ) {
|
||||
return $this->raiseError("Entry " . $this->dn() . " not modified (attributes not deleted): " .
|
||||
ldap_error($this->_link),ldap_errno($this->_link));
|
||||
}
|
||||
}
|
||||
|
||||
// new attributes
|
||||
if ((count($this->_addAttrs)) > 0 && !ldap_modify($this->_link, $this->dn(), $this->_addAttrs)) {
|
||||
return $this->raiseError( "Entry " . $this->dn() . " not modified (attributes not added): " .
|
||||
ldap_error($this->_link),ldap_errno($this->_link));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
192
thirdparty/pear/Net/LDAP/RootDSE.php
vendored
192
thirdparty/pear/Net/LDAP/RootDSE.php
vendored
@@ -1,192 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Net_LDAP |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or |
|
||||
// | modify it under the terms of the GNU Lesser General Public |
|
||||
// | License as published by the Free Software Foundation; either |
|
||||
// | version 2.1 of the License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, |
|
||||
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Authors: Jan Wagner |
|
||||
// +--------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: RootDSE.php 4831 2006-02-06 09:59:09Z nbm $
|
||||
|
||||
/**
|
||||
* Getting the rootDSE entry of a LDAP server
|
||||
*
|
||||
* @package Net_LDAP
|
||||
* @author Jan Wagner <wagner@netsols.de>
|
||||
* @version $Revision: 4831 $
|
||||
*/
|
||||
class Net_LDAP_RootDSE extends PEAR
|
||||
{
|
||||
/**
|
||||
* @access private
|
||||
* @var object Net_LDAP_Entry
|
||||
**/
|
||||
var $_entry;
|
||||
|
||||
/**
|
||||
* class constructor
|
||||
*
|
||||
* @param object Net_LDAP_Entry
|
||||
*/
|
||||
function Net_LDAP_RootDSE(&$entry)
|
||||
{
|
||||
$this->_entry = $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the requested attribute value
|
||||
*
|
||||
* Same usuage as Net_LDAP_Entry::get_value()
|
||||
*
|
||||
* @access public
|
||||
* @param string Attribute name
|
||||
* @param array Array of options
|
||||
* @return mixed Net_LDAP_Error object or attribute values
|
||||
* @see Net_LDAP_Entry::get_value()
|
||||
*/
|
||||
function getValue($attr = '', $options = '')
|
||||
{
|
||||
return $this->_entry->get_value($attr, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of getValue() for perl-ldap interface
|
||||
*
|
||||
* @see getValue()
|
||||
*/
|
||||
function get_value()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'getValue' ), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the extension is supported
|
||||
*
|
||||
* @access public
|
||||
* @param array Array of oids to check
|
||||
* @return boolean
|
||||
*/
|
||||
function supportedExtension($oids)
|
||||
{
|
||||
return $this->_checkAttr($oids, 'supportedExtension');
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of supportedExtension() for perl-ldap interface
|
||||
*
|
||||
* @see supportedExtension()
|
||||
*/
|
||||
function supported_extension()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'supportedExtension'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the version is supported
|
||||
*
|
||||
* @access public
|
||||
* @param array Versions to check
|
||||
* @return boolean
|
||||
*/
|
||||
function supportedVersion($versions)
|
||||
{
|
||||
return $this->_checkAttr($versions, 'supportedLDAPVersion');
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of supportedVersion() for perl-ldap interface
|
||||
*
|
||||
* @see supportedVersion()
|
||||
*/
|
||||
function supported_version()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'supportedVersion'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the control is supported
|
||||
*
|
||||
* @access public
|
||||
* @param array Control oids to check
|
||||
* @return boolean
|
||||
*/
|
||||
function supportedControl($oids)
|
||||
{
|
||||
return $this->_checkAttr($oids, 'supportedControl');
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of supportedControl() for perl-ldap interface
|
||||
*
|
||||
* @see supportedControl()
|
||||
*/
|
||||
function supported_control()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'supportedControl' ), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the sasl mechanism is supported
|
||||
*
|
||||
* @access public
|
||||
* @param array SASL mechanisms to check
|
||||
* @return boolean
|
||||
*/
|
||||
function supportedSASLMechanism($mechlist)
|
||||
{
|
||||
return $this->_checkAttr($mechlist, 'supportedSASLMechanisms');
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of supportedSASLMechanism() for perl-ldap interface
|
||||
*
|
||||
* @see supportedSASLMechanism()
|
||||
*/
|
||||
function supported_sasl_mechanism()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'supportedSASLMechanism'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for existance of value in attribute
|
||||
*
|
||||
* @access private
|
||||
* @param array $values values to check
|
||||
* @param attr $attr attribute name
|
||||
* @return boolean
|
||||
*/
|
||||
function _checkAttr($values, $attr)
|
||||
{
|
||||
if (!is_array($values)) $values = array($values);
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (!@in_array($value, $this->get_value($attr))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
355
thirdparty/pear/Net/LDAP/Schema.php
vendored
355
thirdparty/pear/Net/LDAP/Schema.php
vendored
@@ -1,355 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Net_LDAP |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or |
|
||||
// | modify it under the terms of the GNU Lesser General Public |
|
||||
// | License as published by the Free Software Foundation; either |
|
||||
// | version 2.1 of the License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, |
|
||||
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Authors: Jan Wagner |
|
||||
// +--------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Schema.php 4831 2006-02-06 09:59:09Z nbm $
|
||||
|
||||
/**
|
||||
* Load an LDAP Schema and provide information
|
||||
*
|
||||
* This class takes a Subschema entry, parses this information
|
||||
* and makes it available in an array. Most of the code has been
|
||||
* inspired by perl-ldap( http://perl-ldap.sourceforge.net).
|
||||
* You will find portions of their implementation in here.
|
||||
*
|
||||
* @package Net_LDAP
|
||||
* @author Jan Wagner <wagner@netsols.de>
|
||||
* @version $Revision: 4831 $
|
||||
*/
|
||||
class Net_LDAP_Schema extends PEAR
|
||||
{
|
||||
/**
|
||||
* Map of entry types to ldap attributes of subschema entry
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $types = array('attribute' => 'attributeTypes',
|
||||
'ditcontentrule' => 'dITContentRules',
|
||||
'ditstructurerule' => 'dITStructureRules',
|
||||
'matchingrule' => 'matchingRules',
|
||||
'matchingruleuse' => 'matchingRuleUse',
|
||||
'nameform' => 'nameForms',
|
||||
'objectclass' => 'objectClasses',
|
||||
'syntax' => 'ldapSyntaxes');
|
||||
|
||||
/**#@+
|
||||
* Array of entries belonging to this type
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_attributeTypes = array();
|
||||
var $_matchingRules = array();
|
||||
var $_matchingRuleUse = array();
|
||||
var $_ldapSyntaxes = array();
|
||||
var $_objectClasses = array();
|
||||
var $_dITContentRules = array();
|
||||
var $_dITStructureRules = array();
|
||||
var $_nameForms = array();
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* hash of all fetched oids
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_oids = array();
|
||||
|
||||
/**
|
||||
* constructor of the class
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function Net_LDAP_Schema()
|
||||
{
|
||||
$this->PEAR('Net_LDAP_Error'); // default error class
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hash of entries for the given type
|
||||
*
|
||||
* Returns a hash of entry for th givene type. Types may be:
|
||||
* objectclasses, attributes, ditcontentrules, ditstructurerules, matchingrules,
|
||||
* matchingruleuses, nameforms, syntaxes
|
||||
*
|
||||
* @access public
|
||||
* @param string Type to fetch
|
||||
* @return mixed Array or Net_LDAP_Error
|
||||
*/
|
||||
function &getAll($type)
|
||||
{
|
||||
$map = array('objectclasses' => &$this->_objectClasses,
|
||||
'attributes' => &$this->_attributeTypes,
|
||||
'ditcontentrules' => &$this->_dITContentRules,
|
||||
'ditstructurerules' => &$this->_dITStructureRules,
|
||||
'matchingrules' => &$this->_matchingRules,
|
||||
'matchingruleuses' => &$this->_matchingRuleUse,
|
||||
'nameforms' => &$this->_nameForms,
|
||||
'syntaxes' => &$this->_ldapSyntaxes );
|
||||
|
||||
$key = strtolower($type);
|
||||
return ((key_exists($key, $map)) ? $map[$key] : $this->raiseError("Unknown type $type"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a specific entry
|
||||
*
|
||||
* @access public
|
||||
* @param string Type of name
|
||||
* @param string Name or OID to fetch
|
||||
* @return mixed Entry or Net_LDAP_Error
|
||||
*/
|
||||
function &get($type, $name)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (false == key_exists($type, $this->types)) {
|
||||
return $this->raiseError("No such type $type");
|
||||
}
|
||||
|
||||
$name = strtolower($name);
|
||||
$type_var = &$this->{'_' . $this->types[$type]};
|
||||
|
||||
if( key_exists($name, $type_var)) {
|
||||
return $type_var[$name];
|
||||
} elseif(key_exists($name, $this->_oids) && $this->_oids[$name]['type'] == $type) {
|
||||
return $this->_oids[$name];
|
||||
} else {
|
||||
return $this->raiseError("Could not find $type $name");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches attributes that MAY be present in the given objectclass
|
||||
*
|
||||
* @access public
|
||||
* @param string Name or OID of objectclass
|
||||
* @return mixed Array with attributes or Net_LDAP_Error
|
||||
*/
|
||||
function may($oc)
|
||||
{
|
||||
return $this->_getAttr($oc, 'may');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches attributes that MUST be present in the given objectclass
|
||||
*
|
||||
* @access public
|
||||
* @param string Name or OID of objectclass
|
||||
* @return mixed Array with attributes or Net_LDAP_Error
|
||||
*/
|
||||
function must($oc)
|
||||
{
|
||||
return $this->_getAttr($oc, 'must');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the given attribute from the given objectclass
|
||||
*
|
||||
* @access private
|
||||
* @param string Name or OID of objectclass
|
||||
* @param string Name of attribute to fetch
|
||||
* @return mixed The attribute or Net_LDAP_Error
|
||||
*/
|
||||
function _getAttr($oc, $attr)
|
||||
{
|
||||
$oc = strtolower($oc);
|
||||
if (key_exists($oc, $this->_objectClasses) && key_exists($attr, $this->_objectClasses[$oc])) {
|
||||
return $this->_objectClasses[$oc][$attr];
|
||||
}
|
||||
elseif (key_exists($oc, $this->_oids) &&
|
||||
$this->_oids[$oc]['type'] == 'objectclass' &&
|
||||
key_exists($attr, $this->_oids[$oc])) {
|
||||
return $this->_oids[$oc][$attr];
|
||||
} else {
|
||||
return $this->raiseError("Could not find $attr attributes for $oc ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name(s) of the immediate superclass(es)
|
||||
*
|
||||
* @param string Name or OID of objectclass
|
||||
* @return mixed Array of names or Net_LDAP_Error
|
||||
*/
|
||||
function superclass($oc)
|
||||
{
|
||||
$o = $this->get('objectclass', $oc);
|
||||
if (Net_LDAP::isError($o)) {
|
||||
return $o;
|
||||
}
|
||||
return (key_exists('sup', $o) ? $o['sup'] : array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the schema of the given Subschema entry
|
||||
*
|
||||
* @access public
|
||||
* @param object Net_LDAP_Entry Subschema entry
|
||||
*/
|
||||
function parse(&$entry)
|
||||
{
|
||||
foreach ($this->types as $type => $attr)
|
||||
{
|
||||
// initialize map type to entry
|
||||
$type_var = '_' . $attr;
|
||||
$this->{$type_var} = array();
|
||||
|
||||
// get values for this type
|
||||
$values = $entry->get_value($attr);
|
||||
|
||||
if (is_array($values))
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
|
||||
unset($schema_entry); // this was a real mess without it
|
||||
|
||||
// get the schema entry
|
||||
$schema_entry = $this->_parse_entry($value);
|
||||
|
||||
// set the type
|
||||
$schema_entry['type'] = $type;
|
||||
|
||||
// save a ref in $_oids
|
||||
$this->_oids[$schema_entry['oid']] =& $schema_entry;
|
||||
|
||||
// save refs for all names in type map
|
||||
$names = $schema_entry['aliases'];
|
||||
array_push($names, $schema_entry['name']);
|
||||
foreach ($names as $name) {
|
||||
$this->{$type_var}[strtolower($name)] =& $schema_entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parses an attribute value into a schema entry
|
||||
*
|
||||
* @access private
|
||||
* @param string Attribute value
|
||||
* @return mixed Schema entry array or false
|
||||
*/
|
||||
function &_parse_entry($value)
|
||||
{
|
||||
// tokens that have no value associated
|
||||
$noValue = array('single-value',
|
||||
'obsolete',
|
||||
'collective',
|
||||
'no-user-modification',
|
||||
'abstract',
|
||||
'structural',
|
||||
'auxiliary');
|
||||
|
||||
// tokens that can have multiple values
|
||||
$multiValue = array('must', 'may', 'sup');
|
||||
|
||||
$schema_entry = array('aliases' => array()); // initilization
|
||||
|
||||
$tokens = $this->_tokenize($value); // get an array of tokens
|
||||
|
||||
// remove surrounding brackets
|
||||
if ($tokens[0] == '(') array_shift($tokens);
|
||||
if ($tokens[count($tokens) - 1] == ')') array_pop($tokens); // -1 doesnt work on arrays :-(
|
||||
|
||||
$schema_entry['oid'] = array_shift($tokens); // first token is the oid
|
||||
|
||||
// cycle over the tokens until none are left
|
||||
while (count($tokens) > 0) {
|
||||
$token = strtolower(array_shift($tokens));
|
||||
if (in_array($token, $noValue)) {
|
||||
$schema_entry[$token] = 1; // single value token
|
||||
} else {
|
||||
// this one follows a string or a list if it is multivalued
|
||||
if (($schema_entry[$token] = array_shift($tokens)) == '(') {
|
||||
// this creates the list of values and cycles through the tokens
|
||||
// until the end of the list is reached ')'
|
||||
$schema_entry[$token] = array();
|
||||
while ($tmp = array_shift($tokens)) {
|
||||
if ($tmp == ')') break;
|
||||
if ($tmp != '$') array_push($schema_entry[$token], $tmp);
|
||||
}
|
||||
}
|
||||
// create a array if the value should be multivalued but was not
|
||||
if (in_array($token, $multiValue ) && !is_array($schema_entry[$token])) {
|
||||
$schema_entry[$token] = array($schema_entry[$token]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// get max length from syntax
|
||||
if (key_exists('syntax', $schema_entry)) {
|
||||
if (preg_match('/{(\d+)}/', $schema_entry['syntax'], $matches)) {
|
||||
$schema_entry['max_length'] = $matches[1];
|
||||
}
|
||||
}
|
||||
// force a name
|
||||
if (empty($schema_entry['name'])) {
|
||||
$schema_entry['name'] = $schema_entry['oid'];
|
||||
}
|
||||
// make one name the default and put the other ones into aliases
|
||||
if (is_array($schema_entry['name'])) {
|
||||
$aliases = $schema_entry['name'];
|
||||
$schema_entry['name'] = array_shift($aliases);
|
||||
$schema_entry['aliases'] = $aliases;
|
||||
}
|
||||
return $schema_entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* tokenizes the given value into an array of tokens
|
||||
*
|
||||
* @access private
|
||||
* @param string String to parse
|
||||
* @return array Array of tokens
|
||||
*/
|
||||
function _tokenize($value)
|
||||
{
|
||||
$tokens = array(); // array of tokens
|
||||
$matches = array(); // matches[0] full pattern match, [1,2,3] subpatterns
|
||||
|
||||
// this one is taken from perl-ldap, modified for php
|
||||
$pattern = "/\s* (?:([()]) | ([^'\s()]+) | '((?:[^']+|'[^\s)])*)') \s*/x";
|
||||
|
||||
/**
|
||||
* This one matches one big pattern wherin only one of the three subpatterns matched
|
||||
* We are interested in the subpatterns that matched. If it matched its value will be
|
||||
* non-empty and so it is a token. Tokens may be round brackets, a string, or a string
|
||||
* enclosed by '
|
||||
*/
|
||||
preg_match_all($pattern, $value, $matches);
|
||||
|
||||
for ($i = 0; $i < count($matches[0]); $i++) { // number of tokens (full pattern match)
|
||||
for ($j = 1; $j < 4; $j++) { // each subpattern
|
||||
if (null != trim($matches[$j][$i])) { // pattern match in this subpattern
|
||||
$tokens[$i] = trim($matches[$j][$i]); // this is the token
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
245
thirdparty/pear/Net/LDAP/Search.php
vendored
245
thirdparty/pear/Net/LDAP/Search.php
vendored
@@ -1,245 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Net_LDAP |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or |
|
||||
// | modify it under the terms of the GNU Lesser General Public |
|
||||
// | License as published by the Free Software Foundation; either |
|
||||
// | version 2.1 of the License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, |
|
||||
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Authors: Tarjej Huse |
|
||||
// +--------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Search.php 4831 2006-02-06 09:59:09Z nbm $
|
||||
|
||||
/**
|
||||
* Result set of an LDAP search
|
||||
*
|
||||
* @author Tarjei Huse
|
||||
* @version $Revision: 4831 $
|
||||
* @package Net_LDAP
|
||||
*/
|
||||
class Net_LDAP_Search extends PEAR
|
||||
{
|
||||
/**
|
||||
* Search result identifier
|
||||
*
|
||||
* @access private
|
||||
* @var resource
|
||||
*/
|
||||
var $_search;
|
||||
|
||||
/**
|
||||
* LDAP resource link
|
||||
*
|
||||
* @access private
|
||||
* @var resource
|
||||
*/
|
||||
var $_link;
|
||||
|
||||
/**
|
||||
* Array of entries
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_entries = array();
|
||||
|
||||
/**
|
||||
* Result entry identifier
|
||||
*
|
||||
* @access private
|
||||
* @var resource
|
||||
*/
|
||||
var $_elink = null;
|
||||
|
||||
/**
|
||||
* The errorcode the search got
|
||||
*
|
||||
* Some errorcodes might be of interest, but might not be best handled as errors.
|
||||
* examples: 4 - LDAP_SIZELIMIT_EXCEEDED - indecates a huge search.
|
||||
* Incomplete results are returned. If you just want to check if there's anything in the search.
|
||||
* than this is a point to handle.
|
||||
* 32 - no such object - search here returns a count of 0.
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $_errorCode = 0; // if not set - sucess!
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access protected
|
||||
* @param resource Search result identifier
|
||||
* @param resource Link identifier
|
||||
*/
|
||||
function Net_LDAP_Search (&$search, &$link)
|
||||
{
|
||||
$this->_setSearch($search, $link);
|
||||
$this->_errorCode = ldap_errno($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an assosiative array of entry objects
|
||||
*
|
||||
* @return array Array of entry objects.
|
||||
*/
|
||||
function entries()
|
||||
{
|
||||
if ($this->count() == 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$this->_elink = @ldap_first_entry( $this->_link,$this->_search);
|
||||
$entry = new Net_LDAP_Entry($this->_link,
|
||||
@ldap_get_dn($this->_link, $this->_elink),
|
||||
@ldap_get_attributes($this->_link, $this->_elink));
|
||||
array_push($this->_entries, $entry);
|
||||
|
||||
while ($this->_elink = @ldap_next_entry($this->_link,$this->_elink)) {
|
||||
$entry = new Net_LDAP_Entry($this->_link,
|
||||
@ldap_get_dn($this->_link, $this->_elink),
|
||||
@ldap_get_attributes($this->_link, $this->_elink));
|
||||
array_push($this->_entries, $entry);
|
||||
}
|
||||
return $this->_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next entry in the searchresult.
|
||||
*
|
||||
* @return mixed Net_LDAP_Entry object or false
|
||||
*/
|
||||
function shiftEntry()
|
||||
{
|
||||
if ($this->count() == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($this->_elink)) {
|
||||
$this->_elink = @ldap_first_entry($this->_link, $this->_search);
|
||||
$entry = new Net_LDAP_Entry($this->_link,
|
||||
ldap_get_dn($this->_link, $this->_elink),
|
||||
ldap_get_attributes($this->_link, $this->_elink));
|
||||
} else {
|
||||
if (!$this->_elink = ldap_next_entry($this->_link, $this->_elink)) {
|
||||
return false;
|
||||
}
|
||||
$entry = new Net_LDAP_Entry($this->_link,
|
||||
ldap_get_dn($this->_link,$this->_elink),
|
||||
ldap_get_attributes($this->_link,$this->_elink));
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* alias function of shiftEntry() for perl-ldap interface
|
||||
*
|
||||
* @see shiftEntry()
|
||||
*/
|
||||
function shift_entry()
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'shiftEntry'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last entry of the searchset. NOT IMPLEMENTED
|
||||
*
|
||||
* @return object Net_LDAP_Error
|
||||
*/
|
||||
function pop_entry ()
|
||||
{
|
||||
$this->raiseError("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return entries sorted NOT IMPLEMENTED
|
||||
*
|
||||
* @param array Array of sort attributes
|
||||
* @return object Net_LDAP_Error
|
||||
*/
|
||||
function sorted ($attrs = array())
|
||||
{
|
||||
$this->raiseError("Not impelented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return entries as object NOT IMPLEMENTED
|
||||
*
|
||||
* @return object Net_LDAP_Error
|
||||
*/
|
||||
function as_struct ()
|
||||
{
|
||||
$this->raiseError("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the searchobjects resourcelinks
|
||||
*
|
||||
* @access private
|
||||
* @param resource Search result identifier
|
||||
* @param resource Resource link identifier
|
||||
*/
|
||||
function _setSearch(&$search,&$link)
|
||||
{
|
||||
$this->_search = $search;
|
||||
$this->_link = $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of entries in the searchresult
|
||||
*
|
||||
* @return int Number of entries in search.
|
||||
*/
|
||||
function count()
|
||||
{
|
||||
/* this catches the situation where OL returned errno 32 = no such object! */
|
||||
if (!$this->_search) {
|
||||
return 0;
|
||||
}
|
||||
return @ldap_count_entries($this->_link, $this->_search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the errorcode the object got in its search.
|
||||
*
|
||||
* @return int The ldap error number.
|
||||
*/
|
||||
function getErrorCode()
|
||||
{
|
||||
return $this->_errorCode;
|
||||
}
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function _Net_LDAP_Search()
|
||||
{
|
||||
@ldap_free_result($this->_search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes search result
|
||||
*/
|
||||
function done()
|
||||
{
|
||||
$this->_Net_LDAP_Search();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
132
thirdparty/pear/Net/LDAP/Util.php
vendored
132
thirdparty/pear/Net/LDAP/Util.php
vendored
@@ -1,132 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Net_LDAP |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or |
|
||||
// | modify it under the terms of the GNU Lesser General Public |
|
||||
// | License as published by the Free Software Foundation; either |
|
||||
// | version 2.1 of the License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, |
|
||||
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// +--------------------------------------------------------------------------+
|
||||
// | Authors: Jan Wagner |
|
||||
// +--------------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Util.php 4831 2006-02-06 09:59:09Z nbm $
|
||||
|
||||
/**
|
||||
* Utility Class for Net_LDAP
|
||||
*
|
||||
* @package Net_LDAP
|
||||
* @author Jan Wagner <wagner@netsols.de>
|
||||
* @version $Revision: 4831 $
|
||||
*/
|
||||
class Net_LDAP_Util extends PEAR
|
||||
{
|
||||
/**
|
||||
* Reference to LDAP object
|
||||
*
|
||||
* @access private
|
||||
* @var object Net_LDAP
|
||||
*/
|
||||
var $_ldap = null;
|
||||
|
||||
/**
|
||||
* Net_LDAP_Schema object
|
||||
*
|
||||
* @access private
|
||||
* @var object Net_LDAP_Schema
|
||||
*/
|
||||
var $_schema = null;
|
||||
|
||||
/**
|
||||
* Constructur
|
||||
*
|
||||
* Takes an LDAP object by reference and saves it. Then the schema will be fetched.
|
||||
*
|
||||
* @access public
|
||||
* @param object Net_LDAP
|
||||
*/
|
||||
function Net_LDAP_Util(&$ldap)
|
||||
{
|
||||
if (is_object($ldap) && (strtolower(get_class($ldap)) == 'net_ldap')) {
|
||||
$this->_ldap = $ldap;
|
||||
$this->_schema = $this->_ldap->schema();
|
||||
if (Net_LDAP::isError($this->_schema)) $this->_schema = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes given attributes to UTF8 if needed
|
||||
*
|
||||
* This function takes attributes in an array and then checks against the schema if they need
|
||||
* UTF8 encoding. If that is so, they will be encoded. An encoded array will be returned and
|
||||
* can be used for adding or modifying.
|
||||
*
|
||||
* @access public
|
||||
* @param array Array of attributes
|
||||
* @return array Array of UTF8 encoded attributes
|
||||
*/
|
||||
function utf8Encode($attributes)
|
||||
{
|
||||
return $this->_utf8($attributes, 'utf8_encode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the given attribute values
|
||||
*
|
||||
* @access public
|
||||
* @param array Array of attributes
|
||||
* @return array Array with decoded attribute values
|
||||
*/
|
||||
function utf8Decode($attributes)
|
||||
{
|
||||
return $this->_utf8($attributes, 'utf8_decode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes or decodes attribute values if needed
|
||||
*
|
||||
* @access private
|
||||
* @param array Array of attributes
|
||||
* @param array Function to apply to attribute values
|
||||
* @return array Array of attributes with function applied to values
|
||||
*/
|
||||
function _utf8($attributes, $function)
|
||||
{
|
||||
if (!$this->_ldap || !$this->_schema || !function_exists($function)) {
|
||||
return $attributes;
|
||||
}
|
||||
if (is_array($attributes) && count($attributes) > 0) {
|
||||
foreach( $attributes as $k => $v ) {
|
||||
$attr = $this->_schema->get('attribute', $k);
|
||||
if (Net_LDAP::isError($attr)) {
|
||||
continue;
|
||||
}
|
||||
if (false !== strpos($attr['syntax'], '1.3.6.1.4.1.1466.115.121.1.15')) {
|
||||
if (is_array($v)) {
|
||||
foreach ($v as $ak => $av ) {
|
||||
$v[$ak] = call_user_func($function, $av );
|
||||
}
|
||||
} else {
|
||||
$v = call_user_func($function, $v);
|
||||
}
|
||||
}
|
||||
$attributes[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
38
thirdparty/pear/Net/LDAP/fg.php
vendored
38
thirdparty/pear/Net/LDAP/fg.php
vendored
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../../config/dmsDefaults.php');
|
||||
require_once(KT_LIB_DIR . '/authentication/authenticationutil.inc.php');
|
||||
require_once(KT_LIB_DIR . '/authentication/authenticationsource.inc.php');
|
||||
|
||||
require_once('Net/LDAP.php');
|
||||
|
||||
$oKTConfig =& KTConfig::getSingleton();
|
||||
|
||||
$oAuthenticator = KTAuthenticationUtil::getAuthenticatorForSource(2);
|
||||
|
||||
$config = array(
|
||||
'dn' => $oAuthenticator->sSearchUser,
|
||||
'password' => $oAuthenticator->sSearchPassword,
|
||||
'host' => $oAuthenticator->sLdapServer,
|
||||
'base' => $oAuthenticator->sBaseDN,
|
||||
);
|
||||
|
||||
$oLdap =& Net_LDAP::connect($config);
|
||||
if (PEAR::isError($oLdap)) {
|
||||
var_dump($oLdap);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$aParams = array(
|
||||
'scope' => 'sub',
|
||||
'attributes' => array('cn', 'dn', 'displayClass'),
|
||||
);
|
||||
$rootDn = $oAuthenticator->sBaseDN;
|
||||
if (is_array($rootDn)) {
|
||||
$rootDn = join(",", $rootDn);
|
||||
}
|
||||
$oResults = $oLdap->search($rootDn, '(objectClass=group)', $aParams);
|
||||
foreach ($oResults->entries() as $oEntry) {
|
||||
var_dump($oEntry->dn());
|
||||
}
|
||||
|
||||
1240
thirdparty/pear/Net/POP3.php
vendored
1240
thirdparty/pear/Net/POP3.php
vendored
File diff suppressed because it is too large
Load Diff
1082
thirdparty/pear/Net/SMTP.php
vendored
1082
thirdparty/pear/Net/SMTP.php
vendored
File diff suppressed because it is too large
Load Diff
576
thirdparty/pear/Net/Socket.php
vendored
576
thirdparty/pear/Net/Socket.php
vendored
@@ -1,576 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@php.net> |
|
||||
// | Chuck Hagenbuch <chuck@horde.org> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Socket.php,v 1.31 2007/05/04 04:30:29 chagenbu Exp $
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
define('NET_SOCKET_READ', 1);
|
||||
define('NET_SOCKET_WRITE', 2);
|
||||
define('NET_SOCKET_ERROR', 4);
|
||||
|
||||
/**
|
||||
* Generalized Socket class.
|
||||
*
|
||||
* @version 1.1
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
*/
|
||||
class Net_Socket extends PEAR {
|
||||
|
||||
/**
|
||||
* Socket file pointer.
|
||||
* @var resource $fp
|
||||
*/
|
||||
var $fp = null;
|
||||
|
||||
/**
|
||||
* Whether the socket is blocking. Defaults to true.
|
||||
* @var boolean $blocking
|
||||
*/
|
||||
var $blocking = true;
|
||||
|
||||
/**
|
||||
* Whether the socket is persistent. Defaults to false.
|
||||
* @var boolean $persistent
|
||||
*/
|
||||
var $persistent = false;
|
||||
|
||||
/**
|
||||
* The IP address to connect to.
|
||||
* @var string $addr
|
||||
*/
|
||||
var $addr = '';
|
||||
|
||||
/**
|
||||
* The port number to connect to.
|
||||
* @var integer $port
|
||||
*/
|
||||
var $port = 0;
|
||||
|
||||
/**
|
||||
* Number of seconds to wait on socket connections before assuming
|
||||
* there's no more data. Defaults to no timeout.
|
||||
* @var integer $timeout
|
||||
*/
|
||||
var $timeout = false;
|
||||
|
||||
/**
|
||||
* Number of bytes to read at a time in readLine() and
|
||||
* readAll(). Defaults to 2048.
|
||||
* @var integer $lineLength
|
||||
*/
|
||||
var $lineLength = 2048;
|
||||
|
||||
/**
|
||||
* Connect to the specified port. If called when the socket is
|
||||
* already connected, it disconnects and connects again.
|
||||
*
|
||||
* @param string $addr IP address or host name.
|
||||
* @param integer $port TCP port number.
|
||||
* @param boolean $persistent (optional) Whether the connection is
|
||||
* persistent (kept open between requests
|
||||
* by the web server).
|
||||
* @param integer $timeout (optional) How long to wait for data.
|
||||
* @param array $options See options for stream_context_create.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return boolean | PEAR_Error True on success or a PEAR_Error on failure.
|
||||
*/
|
||||
function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
@fclose($this->fp);
|
||||
$this->fp = null;
|
||||
}
|
||||
|
||||
if (!$addr) {
|
||||
return $this->raiseError('$addr cannot be empty');
|
||||
} elseif (strspn($addr, '.0123456789') == strlen($addr) ||
|
||||
strstr($addr, '/') !== false) {
|
||||
$this->addr = $addr;
|
||||
} else {
|
||||
$this->addr = @gethostbyname($addr);
|
||||
}
|
||||
|
||||
$this->port = $port % 65536;
|
||||
|
||||
if ($persistent !== null) {
|
||||
$this->persistent = $persistent;
|
||||
}
|
||||
|
||||
if ($timeout !== null) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
if ($options && function_exists('stream_context_create')) {
|
||||
if ($this->timeout) {
|
||||
$timeout = $this->timeout;
|
||||
} else {
|
||||
$timeout = 0;
|
||||
}
|
||||
$context = stream_context_create($options);
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
|
||||
} else {
|
||||
if ($this->timeout) {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
|
||||
} else {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fp) {
|
||||
return $this->raiseError($errstr, $errno);
|
||||
}
|
||||
|
||||
$this->fp = $fp;
|
||||
|
||||
return $this->setBlocking($this->blocking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from the peer, closes the socket.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
@fclose($this->fp);
|
||||
$this->fp = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the socket is in blocking mode.
|
||||
*
|
||||
* @access public
|
||||
* @return boolean The current blocking mode.
|
||||
*/
|
||||
function isBlocking()
|
||||
{
|
||||
return $this->blocking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the socket connection should be blocking or
|
||||
* not. A read call to a non-blocking socket will return immediately
|
||||
* if there is no data available, whereas it will block until there
|
||||
* is data for blocking sockets.
|
||||
*
|
||||
* @param boolean $mode True for blocking sockets, false for nonblocking.
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setBlocking($mode)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$this->blocking = $mode;
|
||||
socket_set_blocking($this->fp, $this->blocking);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout value on socket descriptor,
|
||||
* expressed in the sum of seconds and microseconds
|
||||
*
|
||||
* @param integer $seconds Seconds.
|
||||
* @param integer $microseconds Microseconds.
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setTimeout($seconds, $microseconds)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return socket_set_timeout($this->fp, $seconds, $microseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file buffering size on the stream.
|
||||
* See php's stream_set_write_buffer for more information.
|
||||
*
|
||||
* @param integer $size Write buffer size.
|
||||
* @access public
|
||||
* @return mixed on success or an PEAR_Error object otherwise
|
||||
*/
|
||||
function setWriteBuffer($size)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$returned = stream_set_write_buffer($this->fp, $code);
|
||||
if ($returned == 0) {
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError('Cannot set write buffer.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about an existing socket resource.
|
||||
* Currently returns four entries in the result array:
|
||||
*
|
||||
* <p>
|
||||
* timed_out (bool) - The socket timed out waiting for data<br>
|
||||
* blocked (bool) - The socket was blocked<br>
|
||||
* eof (bool) - Indicates EOF event<br>
|
||||
* unread_bytes (int) - Number of bytes left in the socket buffer<br>
|
||||
* </p>
|
||||
*
|
||||
* @access public
|
||||
* @return mixed Array containing information about existing socket resource or an error object otherwise
|
||||
*/
|
||||
function getStatus()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return socket_get_status($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specified line of data
|
||||
*
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function gets($size)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return @fgets($this->fp, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a specified amount of data. This is guaranteed to return,
|
||||
* and has the added benefit of getting everything in one fread()
|
||||
* chunk; if you know the size of the data you're getting
|
||||
* beforehand, this is definitely the way to go.
|
||||
*
|
||||
* @param integer $size The number of bytes to read from the socket.
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function read($size)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return @fread($this->fp, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a specified amount of data.
|
||||
*
|
||||
* @param string $data Data to write.
|
||||
* @param integer $blocksize Amount of data to write at once.
|
||||
* NULL means all at once.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function write($data, $blocksize = null)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
if (is_null($blocksize) && !OS_WINDOWS) {
|
||||
return fwrite($this->fp, $data);
|
||||
} else {
|
||||
if (is_null($blocksize)) {
|
||||
$blocksize = 1024;
|
||||
}
|
||||
|
||||
$pos = 0;
|
||||
$size = strlen($data);
|
||||
while ($pos < $size) {
|
||||
$written = @fwrite($this->fp, substr($data, $pos, $blocksize));
|
||||
if ($written === false) {
|
||||
return false;
|
||||
}
|
||||
$pos += $written;
|
||||
}
|
||||
|
||||
return $pos;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a line of data to the socket, followed by a trailing "\r\n".
|
||||
*
|
||||
* @access public
|
||||
* @return mixed fputs result, or an error
|
||||
*/
|
||||
function writeLine($data)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return fwrite($this->fp, $data . "\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for end-of-file on a socket descriptor.
|
||||
*
|
||||
* Also returns true if the socket is disconnected.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function eof()
|
||||
{
|
||||
return (!is_resource($this->fp) || feof($this->fp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 byte of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readByte()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return ord(@fread($this->fp, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a word of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 word of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readWord()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 2);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an int of data
|
||||
*
|
||||
* @access public
|
||||
* @return integer 1 int of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readInt()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 4);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8) +
|
||||
(ord($buf[2]) << 16) + (ord($buf[3]) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a zero-terminated string of data
|
||||
*
|
||||
* @access public
|
||||
* @return string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readString()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$string = '';
|
||||
while (($char = @fread($this->fp, 1)) != "\x00") {
|
||||
$string .= $char;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an IP Address and returns it in a dot formated string
|
||||
*
|
||||
* @access public
|
||||
* @return Dot formated string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readIPAddress()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 4);
|
||||
return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]),
|
||||
ord($buf[2]), ord($buf[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read until either the end of the socket or a newline, whichever
|
||||
* comes first. Strips the trailing newline from the returned data.
|
||||
*
|
||||
* @access public
|
||||
* @return All available data up to a newline, without that
|
||||
* newline, or until the end of the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readLine()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$line = '';
|
||||
$timeout = time() + $this->timeout;
|
||||
while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) {
|
||||
$line .= @fgets($this->fp, $this->lineLength);
|
||||
if (substr($line, -1) == "\n") {
|
||||
return rtrim($line, "\r\n");
|
||||
}
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read until the socket closes, or until there is no more data in
|
||||
* the inner PHP buffer. If the inner buffer is empty, in blocking
|
||||
* mode we wait for at least 1 byte of data. Therefore, in
|
||||
* blocking mode, if there is no data at all to be read, this
|
||||
* function will never exit (unless the socket is closed on the
|
||||
* remote end).
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return string All data until the socket closes, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readAll()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$data = '';
|
||||
while (!feof($this->fp)) {
|
||||
$data .= @fread($this->fp, $this->lineLength);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the equivalent of the select() system call on the socket
|
||||
* with a timeout specified by tv_sec and tv_usec.
|
||||
*
|
||||
* @param integer $state Which of read/write/error to check for.
|
||||
* @param integer $tv_sec Number of seconds for timeout.
|
||||
* @param integer $tv_usec Number of microseconds for timeout.
|
||||
*
|
||||
* @access public
|
||||
* @return False if select fails, integer describing which of read/write/error
|
||||
* are ready, or PEAR_Error if not connected.
|
||||
*/
|
||||
function select($state, $tv_sec, $tv_usec = 0)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$read = null;
|
||||
$write = null;
|
||||
$except = null;
|
||||
if ($state & NET_SOCKET_READ) {
|
||||
$read[] = $this->fp;
|
||||
}
|
||||
if ($state & NET_SOCKET_WRITE) {
|
||||
$write[] = $this->fp;
|
||||
}
|
||||
if ($state & NET_SOCKET_ERROR) {
|
||||
$except[] = $this->fp;
|
||||
}
|
||||
if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = 0;
|
||||
if (count($read)) {
|
||||
$result |= NET_SOCKET_READ;
|
||||
}
|
||||
if (count($write)) {
|
||||
$result |= NET_SOCKET_WRITE;
|
||||
}
|
||||
if (count($except)) {
|
||||
$result |= NET_SOCKET_ERROR;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns encryption on/off on a connected socket.
|
||||
*
|
||||
* @param bool $enabled Set this parameter to true to enable encryption
|
||||
* and false to disable encryption.
|
||||
* @param integer $type Type of encryption. See
|
||||
* http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values.
|
||||
*
|
||||
* @access public
|
||||
* @return false on error, true on success and 0 if there isn't enough data and the
|
||||
* user should try again (non-blocking sockets only). A PEAR_Error object
|
||||
* is returned if the socket is not connected
|
||||
*/
|
||||
function enableCrypto($enabled, $type)
|
||||
{
|
||||
if (version_compare(phpversion(), "5.1.0", ">=")) {
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
return @stream_socket_enable_crypto($this->fp, $enabled, $type);
|
||||
} else {
|
||||
return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
485
thirdparty/pear/Net/URL.php
vendored
485
thirdparty/pear/Net/URL.php
vendored
@@ -1,485 +0,0 @@
|
||||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2004, Richard Heyes |
|
||||
// | All rights reserved. |
|
||||
// | |
|
||||
// | Redistribution and use in source and binary forms, with or without |
|
||||
// | modification, are permitted provided that the following conditions |
|
||||
// | are met: |
|
||||
// | |
|
||||
// | o Redistributions of source code must retain the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer. |
|
||||
// | o Redistributions in binary form must reproduce the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer in the |
|
||||
// | documentation and/or other materials provided with the distribution.|
|
||||
// | o The names of the authors may not be used to endorse or promote |
|
||||
// | products derived from this software without specific prior written |
|
||||
// | permission. |
|
||||
// | |
|
||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||
// | |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Author: Richard Heyes <richard at php net> |
|
||||
// +-----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: URL.php,v 1.49 2007/06/28 14:43:07 davidc Exp $
|
||||
//
|
||||
// Net_URL Class
|
||||
|
||||
|
||||
class Net_URL
|
||||
{
|
||||
var $options = array('encode_query_keys' => false);
|
||||
/**
|
||||
* Full url
|
||||
* @var string
|
||||
*/
|
||||
var $url;
|
||||
|
||||
/**
|
||||
* Protocol
|
||||
* @var string
|
||||
*/
|
||||
var $protocol;
|
||||
|
||||
/**
|
||||
* Username
|
||||
* @var string
|
||||
*/
|
||||
var $username;
|
||||
|
||||
/**
|
||||
* Password
|
||||
* @var string
|
||||
*/
|
||||
var $password;
|
||||
|
||||
/**
|
||||
* Host
|
||||
* @var string
|
||||
*/
|
||||
var $host;
|
||||
|
||||
/**
|
||||
* Port
|
||||
* @var integer
|
||||
*/
|
||||
var $port;
|
||||
|
||||
/**
|
||||
* Path
|
||||
* @var string
|
||||
*/
|
||||
var $path;
|
||||
|
||||
/**
|
||||
* Query string
|
||||
* @var array
|
||||
*/
|
||||
var $querystring;
|
||||
|
||||
/**
|
||||
* Anchor
|
||||
* @var string
|
||||
*/
|
||||
var $anchor;
|
||||
|
||||
/**
|
||||
* Whether to use []
|
||||
* @var bool
|
||||
*/
|
||||
var $useBrackets;
|
||||
|
||||
/**
|
||||
* PHP4 Constructor
|
||||
*
|
||||
* @see __construct()
|
||||
*/
|
||||
function Net_URL($url = null, $useBrackets = true)
|
||||
{
|
||||
$this->__construct($url, $useBrackets);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP5 Constructor
|
||||
*
|
||||
* Parses the given url and stores the various parts
|
||||
* Defaults are used in certain cases
|
||||
*
|
||||
* @param string $url Optional URL
|
||||
* @param bool $useBrackets Whether to use square brackets when
|
||||
* multiple querystrings with the same name
|
||||
* exist
|
||||
*/
|
||||
function __construct($url = null, $useBrackets = true)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->useBrackets = $useBrackets;
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
function initialize()
|
||||
{
|
||||
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
|
||||
|
||||
$this->user = '';
|
||||
$this->pass = '';
|
||||
$this->host = '';
|
||||
$this->port = 80;
|
||||
$this->path = '';
|
||||
$this->querystring = array();
|
||||
$this->anchor = '';
|
||||
|
||||
// Only use defaults if not an absolute URL given
|
||||
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) {
|
||||
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
|
||||
|
||||
/**
|
||||
* Figure out host/port
|
||||
*/
|
||||
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&
|
||||
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))
|
||||
{
|
||||
$host = $matches[1];
|
||||
if (!empty($matches[3])) {
|
||||
$port = $matches[3];
|
||||
} else {
|
||||
$port = $this->getStandardPort($this->protocol);
|
||||
}
|
||||
}
|
||||
|
||||
$this->user = '';
|
||||
$this->pass = '';
|
||||
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
|
||||
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
|
||||
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
|
||||
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
|
||||
$this->anchor = '';
|
||||
}
|
||||
|
||||
// Parse the url and store the various parts
|
||||
if (!empty($this->url)) {
|
||||
$urlinfo = parse_url($this->url);
|
||||
|
||||
// Default querystring
|
||||
$this->querystring = array();
|
||||
|
||||
foreach ($urlinfo as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'scheme':
|
||||
$this->protocol = $value;
|
||||
$this->port = $this->getStandardPort($value);
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
case 'pass':
|
||||
case 'host':
|
||||
case 'port':
|
||||
$this->$key = $value;
|
||||
break;
|
||||
|
||||
case 'path':
|
||||
if ($value{0} == '/') {
|
||||
$this->path = $value;
|
||||
} else {
|
||||
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
|
||||
$this->path = sprintf('%s/%s', $path, $value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'query':
|
||||
$this->querystring = $this->_parseRawQueryString($value);
|
||||
break;
|
||||
|
||||
case 'fragment':
|
||||
$this->anchor = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns full url
|
||||
*
|
||||
* @return string Full url
|
||||
* @access public
|
||||
*/
|
||||
function getURL()
|
||||
{
|
||||
$querystring = $this->getQueryString();
|
||||
|
||||
$this->url = $this->protocol . '://'
|
||||
. $this->user . (!empty($this->pass) ? ':' : '')
|
||||
. $this->pass . (!empty($this->user) ? '@' : '')
|
||||
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
|
||||
. $this->path
|
||||
. (!empty($querystring) ? '?' . $querystring : '')
|
||||
. (!empty($this->anchor) ? '#' . $this->anchor : '');
|
||||
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or updates a querystring item (URL parameter).
|
||||
* Automatically encodes parameters with rawurlencode() if $preencoded
|
||||
* is false.
|
||||
* You can pass an array to $value, it gets mapped via [] in the URL if
|
||||
* $this->useBrackets is activated.
|
||||
*
|
||||
* @param string $name Name of item
|
||||
* @param string $value Value of item
|
||||
* @param bool $preencoded Whether value is urlencoded or not, default = not
|
||||
* @access public
|
||||
*/
|
||||
function addQueryString($name, $value, $preencoded = false)
|
||||
{
|
||||
if ($this->getOption('encode_query_keys')) {
|
||||
$name = rawurlencode($name);
|
||||
}
|
||||
|
||||
if ($preencoded) {
|
||||
$this->querystring[$name] = $value;
|
||||
} else {
|
||||
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a querystring item
|
||||
*
|
||||
* @param string $name Name of item
|
||||
* @access public
|
||||
*/
|
||||
function removeQueryString($name)
|
||||
{
|
||||
if ($this->getOption('encode_query_keys')) {
|
||||
$name = rawurlencode($name);
|
||||
}
|
||||
|
||||
if (isset($this->querystring[$name])) {
|
||||
unset($this->querystring[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the querystring to literally what you supply
|
||||
*
|
||||
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
|
||||
* @access public
|
||||
*/
|
||||
function addRawQueryString($querystring)
|
||||
{
|
||||
$this->querystring = $this->_parseRawQueryString($querystring);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns flat querystring
|
||||
*
|
||||
* @return string Querystring
|
||||
* @access public
|
||||
*/
|
||||
function getQueryString()
|
||||
{
|
||||
if (!empty($this->querystring)) {
|
||||
foreach ($this->querystring as $name => $value) {
|
||||
// Encode var name
|
||||
$name = rawurlencode($name);
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
|
||||
}
|
||||
} elseif (!is_null($value)) {
|
||||
$querystring[] = $name . '=' . $value;
|
||||
} else {
|
||||
$querystring[] = $name;
|
||||
}
|
||||
}
|
||||
$querystring = implode(ini_get('arg_separator.output'), $querystring);
|
||||
} else {
|
||||
$querystring = '';
|
||||
}
|
||||
|
||||
return $querystring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses raw querystring and returns an array of it
|
||||
*
|
||||
* @param string $querystring The querystring to parse
|
||||
* @return array An array of the querystring data
|
||||
* @access private
|
||||
*/
|
||||
function _parseRawQuerystring($querystring)
|
||||
{
|
||||
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$return = array();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
$value = substr($part, strpos($part, '=') + 1);
|
||||
$key = substr($part, 0, strpos($part, '='));
|
||||
} else {
|
||||
$value = null;
|
||||
$key = $part;
|
||||
}
|
||||
|
||||
if (!$this->getOption('encode_query_keys')) {
|
||||
$key = rawurldecode($key);
|
||||
}
|
||||
|
||||
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
|
||||
$key = $matches[1];
|
||||
$idx = $matches[2];
|
||||
|
||||
// Ensure is an array
|
||||
if (empty($return[$key]) || !is_array($return[$key])) {
|
||||
$return[$key] = array();
|
||||
}
|
||||
|
||||
// Add data
|
||||
if ($idx === '') {
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key][$idx] = $value;
|
||||
}
|
||||
} elseif (!$this->useBrackets AND !empty($return[$key])) {
|
||||
$return[$key] = (array)$return[$key];
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves //, ../ and ./ from a path and returns
|
||||
* the result. Eg:
|
||||
*
|
||||
* /foo/bar/../boo.php => /foo/boo.php
|
||||
* /foo/bar/../../boo.php => /boo.php
|
||||
* /foo/bar/.././/boo.php => /foo/boo.php
|
||||
*
|
||||
* This method can also be called statically.
|
||||
*
|
||||
* @param string $path URL path to resolve
|
||||
* @return string The result
|
||||
*/
|
||||
function resolvePath($path)
|
||||
{
|
||||
$path = explode('/', str_replace('//', '/', $path));
|
||||
|
||||
for ($i=0; $i<count($path); $i++) {
|
||||
if ($path[$i] == '.') {
|
||||
unset($path[$i]);
|
||||
$path = array_values($path);
|
||||
$i--;
|
||||
|
||||
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
|
||||
unset($path[$i]);
|
||||
unset($path[$i-1]);
|
||||
$path = array_values($path);
|
||||
$i -= 2;
|
||||
|
||||
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
|
||||
unset($path[$i]);
|
||||
$path = array_values($path);
|
||||
$i--;
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('/', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the standard port number for a protocol
|
||||
*
|
||||
* @param string $scheme The protocol to lookup
|
||||
* @return integer Port number or NULL if no scheme matches
|
||||
*
|
||||
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
|
||||
*/
|
||||
function getStandardPort($scheme)
|
||||
{
|
||||
switch (strtolower($scheme)) {
|
||||
case 'http': return 80;
|
||||
case 'https': return 443;
|
||||
case 'ftp': return 21;
|
||||
case 'imap': return 143;
|
||||
case 'imaps': return 993;
|
||||
case 'pop3': return 110;
|
||||
case 'pop3s': return 995;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the URL to a particular protocol
|
||||
*
|
||||
* @param string $protocol Protocol to force the URL to
|
||||
* @param integer $port Optional port (standard port is used by default)
|
||||
*/
|
||||
function setProtocol($protocol, $port = null)
|
||||
{
|
||||
$this->protocol = $protocol;
|
||||
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option
|
||||
*
|
||||
* This function set an option
|
||||
* to be used thorough the script.
|
||||
*
|
||||
* @access public
|
||||
* @param string $optionName The optionname to set
|
||||
* @param string $value The value of this option.
|
||||
*/
|
||||
function setOption($optionName, $value)
|
||||
{
|
||||
if (!array_key_exists($optionName, $this->options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->options[$optionName] = $value;
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option
|
||||
*
|
||||
* This function gets an option
|
||||
* from the $this->options array
|
||||
* and return it's value.
|
||||
*
|
||||
* @access public
|
||||
* @param string $opionName The name of the option to retrieve
|
||||
* @see $this->options
|
||||
*/
|
||||
function getOption($optionName)
|
||||
{
|
||||
if (!isset($this->options[$optionName])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->options[$optionName];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
813
thirdparty/pear/Net/URL2.php
vendored
813
thirdparty/pear/Net/URL2.php
vendored
@@ -1,813 +0,0 @@
|
||||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2007-2008, Christian Schmidt, Peytz & Co. A/S |
|
||||
// | All rights reserved. |
|
||||
// | |
|
||||
// | Redistribution and use in source and binary forms, with or without |
|
||||
// | modification, are permitted provided that the following conditions |
|
||||
// | are met: |
|
||||
// | |
|
||||
// | o Redistributions of source code must retain the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer. |
|
||||
// | o Redistributions in binary form must reproduce the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer in the |
|
||||
// | documentation and/or other materials provided with the distribution.|
|
||||
// | o The names of the authors may not be used to endorse or promote |
|
||||
// | products derived from this software without specific prior written |
|
||||
// | permission. |
|
||||
// | |
|
||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||
// | |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Author: Christian Schmidt <schmidt at php dot net> |
|
||||
// +-----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: URL2.php,v 1.10 2008/04/26 21:57:08 schmidt Exp $
|
||||
//
|
||||
// Net_URL2 Class (PHP5 Only)
|
||||
|
||||
// This code is released under the BSD License - http://www.opensource.org/licenses/bsd-license.php
|
||||
/**
|
||||
* @license BSD License
|
||||
*/
|
||||
class Net_URL2
|
||||
{
|
||||
/**
|
||||
* Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
|
||||
* is true.
|
||||
*/
|
||||
const OPTION_STRICT = 'strict';
|
||||
|
||||
/**
|
||||
* Represent arrays in query using PHP's [] notation. Default is true.
|
||||
*/
|
||||
const OPTION_USE_BRACKETS = 'use_brackets';
|
||||
|
||||
/**
|
||||
* URL-encode query variable keys. Default is true.
|
||||
*/
|
||||
const OPTION_ENCODE_KEYS = 'encode_keys';
|
||||
|
||||
/**
|
||||
* Query variable separators when parsing the query string. Every character
|
||||
* is considered a separator. Default is specified by the
|
||||
* arg_separator.input php.ini setting (this defaults to "&").
|
||||
*/
|
||||
const OPTION_SEPARATOR_INPUT = 'input_separator';
|
||||
|
||||
/**
|
||||
* Query variable separator used when generating the query string. Default
|
||||
* is specified by the arg_separator.output php.ini setting (this defaults
|
||||
* to "&").
|
||||
*/
|
||||
const OPTION_SEPARATOR_OUTPUT = 'output_separator';
|
||||
|
||||
/**
|
||||
* Default options corresponds to how PHP handles $_GET.
|
||||
*/
|
||||
private $options = array(
|
||||
self::OPTION_STRICT => true,
|
||||
self::OPTION_USE_BRACKETS => true,
|
||||
self::OPTION_ENCODE_KEYS => true,
|
||||
self::OPTION_SEPARATOR_INPUT => 'x&',
|
||||
self::OPTION_SEPARATOR_OUTPUT => 'x&',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $scheme = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $userinfo = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $host = false;
|
||||
|
||||
/**
|
||||
* @var int|bool
|
||||
*/
|
||||
private $port = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path = '';
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $query = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $fragment = false;
|
||||
|
||||
/**
|
||||
* @param string $url an absolute or relative URL
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($url, $options = null)
|
||||
{
|
||||
$this->setOption(self::OPTION_SEPARATOR_INPUT,
|
||||
ini_get('arg_separator.input'));
|
||||
$this->setOption(self::OPTION_SEPARATOR_OUTPUT,
|
||||
ini_get('arg_separator.output'));
|
||||
if (is_array($options)) {
|
||||
foreach ($options as $optionName => $value) {
|
||||
$this->setOption($optionName);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('@^([a-z][a-z0-9.+-]*):@i', $url, $reg)) {
|
||||
$this->scheme = $reg[1];
|
||||
$url = substr($url, strlen($reg[0]));
|
||||
}
|
||||
|
||||
if (preg_match('@^//([^/#?]+)@', $url, $reg)) {
|
||||
$this->setAuthority($reg[1]);
|
||||
$url = substr($url, strlen($reg[0]));
|
||||
}
|
||||
|
||||
$i = strcspn($url, '?#');
|
||||
$this->path = substr($url, 0, $i);
|
||||
$url = substr($url, $i);
|
||||
|
||||
if (preg_match('@^\?([^#]*)@', $url, $reg)) {
|
||||
$this->query = $reg[1];
|
||||
$url = substr($url, strlen($reg[0]));
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
$this->fragment = substr($url, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scheme, e.g. "http" or "urn", or false if there is no
|
||||
* scheme specified, i.e. if this is a relative URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|bool $scheme
|
||||
*
|
||||
* @return void
|
||||
* @see getScheme()
|
||||
*/
|
||||
public function setScheme($scheme)
|
||||
{
|
||||
$this->scheme = $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user part of the userinfo part (the part preceding the first
|
||||
* ":"), or false if there is no userinfo part.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->userinfo !== false ? preg_replace('@:.*$@', '', $this->userinfo) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password part of the userinfo part (the part after the first
|
||||
* ":"), or false if there is no userinfo part (i.e. the URL does not
|
||||
* contain "@" in front of the hostname) or the userinfo part does not
|
||||
* contain ":".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->userinfo !== false ? substr(strstr($this->userinfo, ':'), 1) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the userinfo part, or false if there is none, i.e. if the
|
||||
* authority part does not contain "@".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUserinfo()
|
||||
{
|
||||
return $this->userinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the userinfo part. If two arguments are passed, they are combined
|
||||
* in the userinfo part as username ":" password.
|
||||
*
|
||||
* @param string|bool $userinfo userinfo or username
|
||||
* @param string|bool $password
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUserinfo($userinfo, $password = false)
|
||||
{
|
||||
$this->userinfo = $userinfo;
|
||||
if ($password !== false) {
|
||||
$this->userinfo .= ':' . $password;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host part, or false if there is no authority part, e.g.
|
||||
* relative URLs.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|bool $host
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number, or false if there is no port number specified,
|
||||
* i.e. if the default port is to be used.
|
||||
*
|
||||
* @return int|bool
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|bool $port
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->port = intval($port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
|
||||
* false if there is no authority none.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getAuthority()
|
||||
{
|
||||
if (!$this->host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$authority = '';
|
||||
|
||||
if ($this->userinfo !== false) {
|
||||
$authority .= $this->userinfo . '@';
|
||||
}
|
||||
|
||||
$authority .= $this->host;
|
||||
|
||||
if ($this->port !== false) {
|
||||
$authority .= ':' . $this->port;
|
||||
}
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|false $authority
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthority($authority)
|
||||
{
|
||||
$this->user = false;
|
||||
$this->pass = false;
|
||||
$this->host = false;
|
||||
$this->port = false;
|
||||
if (preg_match('@^(([^\@]+)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
|
||||
if ($reg[1]) {
|
||||
$this->userinfo = $reg[2];
|
||||
}
|
||||
|
||||
$this->host = $reg[3];
|
||||
if (isset($reg[5])) {
|
||||
$this->port = intval($reg[5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path part (possibly an empty string).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string (excluding the leading "?"), or false if "?"
|
||||
* isn't present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
* @see self::getQueryVariables()
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|bool $query
|
||||
*
|
||||
* @return void
|
||||
* @see self::setQueryVariables()
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fragment name, or false if "#" isn't present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getFragment()
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|bool $fragment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFragment($fragment)
|
||||
{
|
||||
$this->fragment = $fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string like an array as the variables would appear in
|
||||
* $_GET in a PHP script.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryVariables()
|
||||
{
|
||||
$pattern = '/[' .
|
||||
preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
|
||||
']/';
|
||||
$parts = preg_split($pattern, $this->query, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$return = array();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
list($key, $value) = explode('=', $part, 2);
|
||||
} else {
|
||||
$key = $part;
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$key = rawurldecode($key);
|
||||
}
|
||||
$value = rawurldecode($value);
|
||||
|
||||
if ($this->getOption(self::OPTION_USE_BRACKETS) &&
|
||||
preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
|
||||
|
||||
$key = $matches[1];
|
||||
$idx = $matches[2];
|
||||
|
||||
// Ensure is an array
|
||||
if (empty($return[$key]) || !is_array($return[$key])) {
|
||||
$return[$key] = array();
|
||||
}
|
||||
|
||||
// Add data
|
||||
if ($idx === '') {
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key][$idx] = $value;
|
||||
}
|
||||
} elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
|
||||
&& !empty($return[$key])
|
||||
) {
|
||||
$return[$key] = (array) $return[$key];
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array (name => value) array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setQueryVariables(array $array)
|
||||
{
|
||||
if (!$array) {
|
||||
$this->query = false;
|
||||
} else {
|
||||
foreach ($array as $name => $value) {
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$name = rawurlencode($name);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
|
||||
? sprintf('%s[%s]=%s', $name, $k, $v)
|
||||
: ($name . '=' . $v);
|
||||
}
|
||||
} elseif (!is_null($value)) {
|
||||
$parts[] = $name . '=' . $value;
|
||||
} else {
|
||||
$parts[] = $name;
|
||||
}
|
||||
}
|
||||
$this->query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
|
||||
$parts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setQueryVariable($name, $value)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
$array[$name] = $value;
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetQueryVariable($name)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
unset($array[$name]);
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getURL()
|
||||
{
|
||||
// See RFC 3986, section 5.3
|
||||
$url = "";
|
||||
|
||||
if ($this->scheme !== false) {
|
||||
$url .= $this->scheme . ':';
|
||||
}
|
||||
|
||||
$authority = $this->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$url .= '//' . $authority;
|
||||
}
|
||||
$url .= $this->path;
|
||||
|
||||
if ($this->query !== false) {
|
||||
$url .= '?' . $this->query;
|
||||
}
|
||||
|
||||
if ($this->fragment !== false) {
|
||||
$url .= '#' . $this->fragment;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized string representation of this URL. This is useful
|
||||
* for comparison of URLs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNormalizedURL()
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->normalize();
|
||||
return $url->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized Net_URL2 instance.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function normalize()
|
||||
{
|
||||
// See RFC 3886, section 6
|
||||
|
||||
// Schemes are case-insensitive
|
||||
if ($this->scheme) {
|
||||
$this->scheme = strtolower($this->scheme);
|
||||
}
|
||||
|
||||
// Hostnames are case-insensitive
|
||||
if ($this->host) {
|
||||
$this->host = strtolower($this->host);
|
||||
}
|
||||
|
||||
// Remove default port number for known schemes (RFC 3986, section 6.2.3)
|
||||
if ($this->port &&
|
||||
$this->scheme &&
|
||||
$this->port == getservbyname($this->scheme, 'tcp')) {
|
||||
|
||||
$this->port = false;
|
||||
}
|
||||
|
||||
// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
|
||||
foreach (array('userinfo', 'host', 'path') as $part) {
|
||||
if ($this->$part) {
|
||||
$this->$part = preg_replace('/%[0-9a-f]{2}/ie', 'strtoupper("\0")', $this->$part);
|
||||
}
|
||||
}
|
||||
|
||||
// Path segment normalization (RFC 3986, section 6.2.2.3)
|
||||
$this->path = self::removeDotSegments($this->path);
|
||||
|
||||
// Scheme based normalization (RFC 3986, section 6.2.3)
|
||||
if ($this->host && !$this->path) {
|
||||
$this->path = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this instance represents an absolute URL.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAbsolute()
|
||||
{
|
||||
return (bool) $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Net_URL2 instance representing an absolute URL relative to
|
||||
* this URL.
|
||||
*
|
||||
* @param Net_URL2|string $reference relative URL
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function resolve($reference)
|
||||
{
|
||||
if (is_string($reference)) {
|
||||
$reference = new self($reference);
|
||||
}
|
||||
if (!$this->isAbsolute()) {
|
||||
throw new Exception('Base-URL must be absolute');
|
||||
}
|
||||
|
||||
// A non-strict parser may ignore a scheme in the reference if it is
|
||||
// identical to the base URI's scheme.
|
||||
if (!$this->getOption(self::OPTION_STRICT) && $reference->scheme == $this->scheme) {
|
||||
$reference->scheme = false;
|
||||
}
|
||||
|
||||
$target = new self('');
|
||||
if ($reference->scheme !== false) {
|
||||
$target->scheme = $reference->scheme;
|
||||
$target->setAuthority($reference->getAuthority());
|
||||
$target->path = self::removeDotSegments($reference->path);
|
||||
$target->query = $reference->query;
|
||||
} else {
|
||||
$authority = $reference->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$target->setAuthority($authority);
|
||||
$target->path = self::removeDotSegments($reference->path);
|
||||
$target->query = $reference->query;
|
||||
} else {
|
||||
if ($reference->path == '') {
|
||||
$target->path = $this->path;
|
||||
if ($reference->query !== false) {
|
||||
$target->query = $reference->query;
|
||||
} else {
|
||||
$target->query = $this->query;
|
||||
}
|
||||
} else {
|
||||
if (substr($reference->path, 0, 1) == '/') {
|
||||
$target->path = self::removeDotSegments($reference->path);
|
||||
} else {
|
||||
// Merge paths (RFC 3986, section 5.2.3)
|
||||
if ($this->host !== false && $this->path == '') {
|
||||
$target->path = '/' . $this->path;
|
||||
} else {
|
||||
$i = strrpos($this->path, '/');
|
||||
if ($i !== false) {
|
||||
$target->path = substr($this->path, 0, $i + 1);
|
||||
}
|
||||
$target->path .= $reference->path;
|
||||
}
|
||||
$target->path = self::removeDotSegments($target->path);
|
||||
}
|
||||
$target->query = $reference->query;
|
||||
}
|
||||
$target->setAuthority($this->getAuthority());
|
||||
}
|
||||
$target->scheme = $this->scheme;
|
||||
}
|
||||
|
||||
$target->fragment = $reference->fragment;
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes dots as described in RFC 3986, section 5.2.4, e.g.
|
||||
* "/foo/../bar/baz" => "/bar/baz"
|
||||
*
|
||||
* @param string $path a path
|
||||
*
|
||||
* @return string a path
|
||||
*/
|
||||
private static function removeDotSegments($path)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
// Make sure not to be trapped in an infinite loop due to a bug in this
|
||||
// method
|
||||
$j = 0;
|
||||
while ($path && $j++ < 100) {
|
||||
// Step A
|
||||
if (substr($path, 0, 2) == './') {
|
||||
$path = substr($path, 2);
|
||||
} elseif (substr($path, 0, 3) == '../') {
|
||||
$path = substr($path, 3);
|
||||
|
||||
// Step B
|
||||
} elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
|
||||
$path = '/' . substr($path, 3);
|
||||
|
||||
// Step C
|
||||
} elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
|
||||
$path = '/' . substr($path, 4);
|
||||
$i = strrpos($output, '/');
|
||||
$output = $i === false ? '' : substr($output, 0, $i);
|
||||
|
||||
// Step D
|
||||
} elseif ($path == '.' || $path == '..') {
|
||||
$path = '';
|
||||
|
||||
// Step E
|
||||
} else {
|
||||
$i = strpos($path, '/');
|
||||
if ($i === 0) {
|
||||
$i = strpos($path, '/', 1);
|
||||
}
|
||||
if ($i === false) {
|
||||
$i = strlen($path);
|
||||
}
|
||||
$output .= substr($path, 0, $i);
|
||||
$path = substr($path, $i);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the canonical URL of the
|
||||
* currently executing PHP script.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCanonical()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['PHP_SELF']);
|
||||
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
$url->host = $_SERVER['SERVER_NAME'];
|
||||
$port = intval($_SERVER['SERVER_PORT']);
|
||||
if ($url->scheme == 'http' && $port != 80 ||
|
||||
$url->scheme == 'https' && $port != 443) {
|
||||
|
||||
$url->port = $port;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL used to retrieve the current request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRequestedURL()
|
||||
{
|
||||
return self::getRequested()->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the URL used to retrieve the
|
||||
* current request.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public static function getRequested()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['REQUEST_URI']);
|
||||
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
// Set host and possibly port
|
||||
$url->setAuthority($_SERVER['HTTP_HOST']);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified option.
|
||||
*
|
||||
* @param string $optionName a self::OPTION_ constant
|
||||
* @param mixed $value option value
|
||||
*
|
||||
* @return void
|
||||
* @see self::OPTION_STRICT
|
||||
* @see self::OPTION_USE_BRACKETS
|
||||
* @see self::OPTION_ENCODE_KEYS
|
||||
*/
|
||||
function setOption($optionName, $value)
|
||||
{
|
||||
if (!array_key_exists($optionName, $this->options)) {
|
||||
return false;
|
||||
}
|
||||
$this->options[$optionName] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified option.
|
||||
*
|
||||
* @param string $optionName The name of the option to retrieve
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getOption($optionName)
|
||||
{
|
||||
return isset($this->options[$optionName])
|
||||
? $this->options[$optionName] : false;
|
||||
}
|
||||
}
|
||||
967
thirdparty/pear/Net/UserAgent/Detect.php
vendored
967
thirdparty/pear/Net/UserAgent/Detect.php
vendored
@@ -1,967 +0,0 @@
|
||||
<?php
|
||||
// {{{ license
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.2 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2007 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Dan Allen <dan@mojavelinux.com> |
|
||||
// | Jason Rust <jrust@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
// $Id: Detect.php,v 1.26 2007/09/19 21:31:54 jrust Exp $
|
||||
|
||||
// }}}
|
||||
// {{{ constants
|
||||
|
||||
define('NET_USERAGENT_DETECT_BROWSER', 'browser');
|
||||
define('NET_USERAGENT_DETECT_OS', 'os');
|
||||
define('NET_USERAGENT_DETECT_FEATURES', 'features');
|
||||
define('NET_USERAGENT_DETECT_QUIRKS', 'quirks');
|
||||
define('NET_USERAGENT_DETECT_ACCEPT', 'accept');
|
||||
define('NET_USERAGENT_DETECT_ALL', 'all');
|
||||
|
||||
// }}}
|
||||
// {{{ class Net_UserAgent_Detect
|
||||
|
||||
/**
|
||||
* The Net_UserAgent_Detect object does a number of tests on an HTTP user
|
||||
* agent string. The results of these tests are available via methods of
|
||||
* the object. Note that all methods in this class can be called
|
||||
* statically. The constructor and singleton methods are only retained
|
||||
* for BC.
|
||||
*
|
||||
* This module is based upon the JavaScript browser detection code
|
||||
* available at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html.
|
||||
* This module had many influences from the lib/Browser.php code in
|
||||
* version 1.3 of Horde.
|
||||
*
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @author Dan Allen <dan@mojavelinux.com>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @author Jon Parise <jon@horde.org>
|
||||
* @package Net_UserAgent
|
||||
*/
|
||||
|
||||
// }}}
|
||||
class Net_UserAgent_Detect {
|
||||
// {{{ constructor
|
||||
|
||||
function Net_UserAgent_Detect($in_userAgent = null, $in_detect = null)
|
||||
{
|
||||
$this->detect($in_userAgent, $in_detect);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ singleton
|
||||
|
||||
/**
|
||||
* To be used in place of the contructor to return only open instance.
|
||||
*
|
||||
* @access public
|
||||
* @return object Net_UserAgent_Detect instance
|
||||
*/
|
||||
function &singleton($in_userAgent = null, $in_detect = null)
|
||||
{
|
||||
static $instance;
|
||||
|
||||
if (!isset($instance)) {
|
||||
$instance = new Net_UserAgent_Detect($in_userAgent, $in_detect);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ detect()
|
||||
|
||||
/**
|
||||
* Detect the user agent and prepare flags, features and quirks
|
||||
* based on what is found
|
||||
*
|
||||
* This is the core of the Net_UserAgent_Detect class. It moves its
|
||||
* way through the user agent string setting up the flags based on
|
||||
* the vendors and versions of the browsers, determining the OS and
|
||||
* setting up the features and quirks owned by each of the relevant
|
||||
* clients. Note that if you are going to be calling methods of
|
||||
* this class statically then set all the parameters using th
|
||||
* setOption()
|
||||
*
|
||||
* @param string $in_userAgent (optional) User agent override.
|
||||
* @param mixed $in_detect (optional) The level of checking to do.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function detect($in_userAgent = null, $in_detect = null)
|
||||
{
|
||||
static $hasRun;
|
||||
$options = &Net_UserAgent_Detect::_getStaticProperty('options');
|
||||
if (!empty($hasRun) && empty($options['re-evaluate'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hasRun = true;
|
||||
// {{{ set up static properties
|
||||
|
||||
$in_userAgent = isset($options['userAgent']) && is_null($in_userAgent) ? $options['userAgent'] : $in_userAgent;
|
||||
$in_detect = isset($options['detectOptions']) && is_null($in_detect) ? $options['detectOptions'] : $in_detect;
|
||||
|
||||
// User agent string that is being analyzed
|
||||
$userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent');
|
||||
|
||||
// Array that stores all of the flags for the vendor and version
|
||||
// of the different browsers
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
$browser = array_flip(array('ns', 'ns2', 'ns3', 'ns4', 'ns4up', 'nav', 'ns6', 'belowns6', 'ns6up', 'firefox', 'firefox0.x', 'firefox1.x', 'firefox1.5', 'firefox2.x', 'gecko', 'ie', 'ie3', 'ie4', 'ie4up', 'ie5', 'ie5_5', 'ie5up', 'ie6', 'belowie6', 'ie6up', 'ie7', 'ie7up', 'opera', 'opera2', 'opera3', 'opera4', 'opera5', 'opera6', 'opera7', 'opera8', 'opera9', 'opera5up', 'opera6up', 'opera7up', 'belowopera8', 'opera8up', 'opera9up', 'aol', 'aol3', 'aol4', 'aol5', 'aol6', 'aol7', 'aol8', 'webtv', 'aoltv', 'tvnavigator', 'hotjava', 'hotjava3', 'hotjava3up', 'konq', 'safari', 'netgem', 'webdav', 'icab'));
|
||||
|
||||
// Array that stores all of the flags for the operating systems,
|
||||
// and in some cases the versions of those operating systems (windows)
|
||||
$os = &Net_UserAgent_Detect::_getStaticProperty('os');
|
||||
$os = array_flip(array('win', 'win95', 'win16', 'win31', 'win9x', 'win98', 'wince', 'winme', 'win2k', 'winxp', 'winnt', 'win2003', 'os2', 'mac', 'mac68k', 'macppc', 'linux', 'unix', 'vms', 'sun', 'sun4', 'sun5', 'suni86', 'irix', 'irix5', 'irix6', 'hpux', 'hpux9', 'hpux10', 'aix', 'aix1', 'aix2', 'aix3', 'aix4', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'freebsd', 'bsd'));
|
||||
|
||||
// Array which stores known issues with the given client that can
|
||||
// be used for on the fly tweaking so that the client may recieve
|
||||
// the proper handling of this quirk.
|
||||
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
|
||||
$quirks = array(
|
||||
'must_cache_forms' => false,
|
||||
'popups_disabled' => false,
|
||||
'empty_file_input_value' => false,
|
||||
'cache_ssl_downloads' => false,
|
||||
'scrollbar_in_way' => false,
|
||||
'break_disposition_header' => false,
|
||||
'nested_table_render_bug' => false);
|
||||
|
||||
// Array that stores credentials for each of the browser/os
|
||||
// combinations. These allow quick access to determine if the
|
||||
// current client has a feature that is going to be implemented
|
||||
// in the script.
|
||||
$features = &Net_UserAgent_Detect::_getStaticProperty('features');
|
||||
$features = array(
|
||||
'javascript' => false,
|
||||
'dhtml' => false,
|
||||
'dom' => false,
|
||||
'sidebar' => false,
|
||||
'gecko' => false,
|
||||
'svg' => false,
|
||||
'css2' => false,
|
||||
'ajax' => false);
|
||||
|
||||
// The leading identifier is the very first term in the user
|
||||
// agent string, which is used to identify clients which are not
|
||||
// Mosaic-based browsers.
|
||||
$leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier');
|
||||
|
||||
// The full version of the client as supplied by the very first
|
||||
// numbers in the user agent
|
||||
$version = &Net_UserAgent_Detect::_getStaticProperty('version');
|
||||
$version = 0;
|
||||
|
||||
// The major part of the client version, which is the integer
|
||||
// value of the version.
|
||||
$majorVersion = &Net_UserAgent_Detect::_getStaticProperty('majorVersion');
|
||||
$majorVersion = 0;
|
||||
|
||||
// The minor part of the client version, which is the decimal
|
||||
// parts of the version
|
||||
$subVersion = &Net_UserAgent_Detect::_getStaticProperty('subVersion');
|
||||
$subVersion = 0;
|
||||
|
||||
// }}}
|
||||
// detemine what user agent we are using
|
||||
if (is_null($in_userAgent)) {
|
||||
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
||||
}
|
||||
elseif (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'])) {
|
||||
$userAgent = $GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
|
||||
}
|
||||
else {
|
||||
$userAgent = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$userAgent = $in_userAgent;
|
||||
}
|
||||
|
||||
// get the lowercase version for case-insensitive searching
|
||||
$agt = strtolower($userAgent);
|
||||
|
||||
// figure out what we need to look for
|
||||
$detectOptions = array(NET_USERAGENT_DETECT_BROWSER,
|
||||
NET_USERAGENT_DETECT_OS, NET_USERAGENT_DETECT_FEATURES,
|
||||
NET_USERAGENT_DETECT_QUIRKS, NET_USERAGENT_DETECT_ACCEPT,
|
||||
NET_USERAGENT_DETECT_ALL);
|
||||
$detect = is_null($in_detect) ? NET_USERAGENT_DETECT_ALL : $in_detect;
|
||||
settype($detect, 'array');
|
||||
foreach($detectOptions as $option) {
|
||||
if (in_array($option, $detect)) {
|
||||
$detectFlags[$option] = true;
|
||||
}
|
||||
else {
|
||||
$detectFlags[$option] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize the arrays of browsers and operating systems
|
||||
|
||||
// Get the type and version of the client
|
||||
if (preg_match(";^([[:alnum:]]+)[ /\(]*[[:alpha:]]*([\d]*)(\.[\d\.]*);", $agt, $matches)) {
|
||||
list(, $leadingIdentifier, $majorVersion, $subVersion) = $matches;
|
||||
}
|
||||
|
||||
if (empty($leadingIdentifier)) {
|
||||
$leadingIdentifier = 'Unknown';
|
||||
}
|
||||
|
||||
$version = $majorVersion . $subVersion;
|
||||
|
||||
// Browser type
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_BROWSER]) {
|
||||
$browser['webdav'] = ($agt == 'microsoft data access internet publishing provider dav' || $agt == 'microsoft data access internet publishing provider protocol discovery');
|
||||
$browser['konq'] = $browser['safari'] = (strpos($agt, 'konqueror') !== false || strpos($agt, 'safari') !== false);
|
||||
$browser['text'] = strpos($agt, 'links') !== false || strpos($agt, 'lynx') !== false || strpos($agt, 'w3m') !== false;
|
||||
$browser['ns'] = strpos($agt, 'mozilla') !== false && !(strpos($agt, 'spoofer') !== false) && !(strpos($agt, 'compatible') !== false) && !(strpos($agt, 'hotjava') !== false) && !(strpos($agt, 'opera') !== false) && !(strpos($agt, 'webtv') !== false) ? 1 : 0;
|
||||
$browser['netgem'] = strpos($agt, 'netgem') !== false;
|
||||
$browser['icab'] = strpos($agt, 'icab') !== false;
|
||||
$browser['ns2'] = $browser['ns'] && $majorVersion == 2;
|
||||
$browser['ns3'] = $browser['ns'] && $majorVersion == 3;
|
||||
$browser['ns4'] = $browser['ns'] && $majorVersion == 4;
|
||||
$browser['ns4up'] = $browser['ns'] && $majorVersion >= 4;
|
||||
// determine if this is a Netscape Navigator
|
||||
$browser['nav'] = $browser['belowns6'] = $browser['ns'] && $majorVersion < 5;
|
||||
$browser['ns6'] = !$browser['konq'] && $browser['ns'] && $majorVersion == 5;
|
||||
$browser['ns6up'] = $browser['ns6'] && $majorVersion >= 5;
|
||||
$browser['gecko'] = strpos($agt, 'gecko') !== false && !$browser['konq'];
|
||||
$browser['firefox'] = $browser['gecko'] && strpos($agt, 'firefox') !== false;
|
||||
$browser['firefox0.x'] = $browser['firefox'] && strpos($agt, 'firefox/0.') !== false;
|
||||
$browser['firefox1.x'] = $browser['firefox'] && strpos($agt, 'firefox/1.') !== false;
|
||||
$browser['firefox1.5'] = $browser['firefox'] && strpos($agt, 'firefox/1.5') !== false;
|
||||
$browser['firefox2.x'] = $browser['firefox'] && strpos($agt, 'firefox/2.') !== false;
|
||||
$browser['ie'] = strpos($agt, 'msie') !== false && !(strpos($agt, 'opera') !== false);
|
||||
$browser['ie3'] = $browser['ie'] && $majorVersion < 4;
|
||||
$browser['ie4'] = $browser['ie'] && $majorVersion == 4 && (strpos($agt, 'msie 4') !== false);
|
||||
$browser['ie4up'] = $browser['ie'] && !$browser['ie3'];
|
||||
$browser['ie5'] = $browser['ie4up'] && (strpos($agt, 'msie 5') !== false);
|
||||
$browser['ie5_5'] = $browser['ie4up'] && (strpos($agt, 'msie 5.5') !== false);
|
||||
$browser['ie5up'] = $browser['ie4up'] && !$browser['ie3'] && !$browser['ie4'];
|
||||
$browser['ie5_5up'] = $browser['ie5up'] && !$browser['ie5'];
|
||||
$browser['ie6'] = strpos($agt, 'msie 6') !== false;
|
||||
$browser['ie6up'] = $browser['ie5up'] && !$browser['ie5'] && !$browser['ie5_5'];
|
||||
$browser['ie7'] = strpos($agt, 'msie 7') !== false;
|
||||
$browser['ie7up'] = $browser['ie6up'] && !$browser['ie6'];
|
||||
$browser['belowie6']= $browser['ie'] && !$browser['ie6up'];
|
||||
$browser['opera'] = strpos($agt, 'opera') !== false;
|
||||
$browser['opera2'] = strpos($agt, 'opera 2') !== false || strpos($agt, 'opera/2') !== false;
|
||||
$browser['opera3'] = strpos($agt, 'opera 3') !== false || strpos($agt, 'opera/3') !== false;
|
||||
$browser['opera4'] = strpos($agt, 'opera 4') !== false || strpos($agt, 'opera/4') !== false;
|
||||
$browser['opera5'] = strpos($agt, 'opera 5') !== false || strpos($agt, 'opera/5') !== false;
|
||||
$browser['opera6'] = strpos($agt, 'opera 6') !== false || strpos($agt, 'opera/6') !== false;
|
||||
$browser['opera7'] = strpos($agt, 'opera 7') !== false || strpos($agt, 'opera/7') !== false;
|
||||
$browser['opera8'] = strpos($agt, 'opera 8') !== false || strpos($agt, 'opera/8') !== false;
|
||||
$browser['opera9'] = strpos($agt, 'opera 9') !== false || strpos($agt, 'opera/9') !== false;
|
||||
$browser['opera5up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'];
|
||||
$browser['opera6up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'];
|
||||
$browser['opera7up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'];
|
||||
$browser['opera8up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'] && !$browser['opera7'];
|
||||
$browser['opera9up'] = $browser['opera'] && !$browser['opera2'] && !$browser['opera3'] && !$browser['opera4'] && !$browser['opera5'] && !$browser['opera6'] && !$browser['opera7'] && !$browser['opera8'];
|
||||
$browser['belowopera8'] = $browser['opera'] && !$browser['opera8up'];
|
||||
$browser['aol'] = strpos($agt, 'aol') !== false;
|
||||
$browser['aol3'] = $browser['aol'] && $browser['ie3'];
|
||||
$browser['aol4'] = $browser['aol'] && $browser['ie4'];
|
||||
$browser['aol5'] = strpos($agt, 'aol 5') !== false;
|
||||
$browser['aol6'] = strpos($agt, 'aol 6') !== false;
|
||||
$browser['aol7'] = strpos($agt, 'aol 7') !== false || strpos($agt, 'aol7') !== false;
|
||||
$browser['aol8'] = strpos($agt, 'aol 8') !== false || strpos($agt, 'aol8') !== false;
|
||||
$browser['webtv'] = strpos($agt, 'webtv') !== false;
|
||||
$browser['aoltv'] = $browser['tvnavigator'] = strpos($agt, 'navio') !== false || strpos($agt, 'navio_aoltv') !== false;
|
||||
$browser['hotjava'] = strpos($agt, 'hotjava') !== false;
|
||||
$browser['hotjava3'] = $browser['hotjava'] && $majorVersion == 3;
|
||||
$browser['hotjava3up'] = $browser['hotjava'] && $majorVersion >= 3;
|
||||
$browser['iemobile'] = strpos($agt, 'iemobile') !== false || strpos($agt, 'windows ce') !== false && (strpos($agt, 'ppc') !== false || strpos($agt, 'smartphone') !== false);
|
||||
}
|
||||
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] ||
|
||||
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) {
|
||||
// Javascript Check
|
||||
if ($browser['ns2'] || $browser['ie3']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.0);
|
||||
}
|
||||
elseif ($browser['iemobile']) {
|
||||
// no javascript
|
||||
}
|
||||
elseif ($browser['opera5up']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.3);
|
||||
}
|
||||
elseif ($browser['opera'] || $browser['ns3']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.1);
|
||||
}
|
||||
elseif (($browser['ns4'] && ($version <= 4.05)) || $browser['ie4']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.2);
|
||||
}
|
||||
elseif (($browser['ie5up'] && strpos($agt, 'mac') !== false) || $browser['konq']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.4);
|
||||
}
|
||||
// I can't believe IE6 still has javascript 1.3, what a shitty browser
|
||||
elseif (($browser['ns4'] && ($version > 4.05)) || $browser['ie5up'] || $browser['hotjava3up']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.3);
|
||||
}
|
||||
elseif ($browser['ns6up'] || $browser['gecko'] || $browser['netgem']) {
|
||||
Net_UserAgent_Detect::setFeature('javascript', 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
/** OS Check **/
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_OS]) {
|
||||
$os['win'] = strpos($agt, 'win') !== false || strpos($agt, '16bit') !== false;
|
||||
$os['win95'] = strpos($agt, 'win95') !== false || strpos($agt, 'windows 95') !== false;
|
||||
$os['win16'] = strpos($agt, 'win16') !== false || strpos($agt, '16bit') !== false || strpos($agt, 'windows 3.1') !== false || strpos($agt, 'windows 16-bit') !== false;
|
||||
$os['win31'] = strpos($agt, 'windows 3.1') !== false || strpos($agt, 'win16') !== false || strpos($agt, 'windows 16-bit') !== false;
|
||||
$os['winme'] = strpos($agt, 'win 9x 4.90') !== false;
|
||||
$os['wince'] = strpos($agt, 'windows ce') !== false;
|
||||
$os['win2k'] = strpos($agt, 'windows nt 5.0') !== false;
|
||||
$os['winxp'] = strpos($agt, 'windows nt 5.1') !== false;
|
||||
$os['win2003'] = strpos($agt, 'windows nt 5.2') !== false;
|
||||
$os['win98'] = strpos($agt, 'win98') !== false || strpos($agt, 'windows 98') !== false;
|
||||
$os['win9x'] = $os['win95'] || $os['win98'];
|
||||
$os['winnt'] = (strpos($agt, 'winnt') !== false || strpos($agt, 'windows nt') !== false) && strpos($agt, 'windows nt 5') === false;
|
||||
$os['win32'] = $os['win95'] || $os['winnt'] || $os['win98'] || $majorVersion >= 4 && strpos($agt, 'win32') !== false || strpos($agt, '32bit') !== false;
|
||||
$os['os2'] = strpos($agt, 'os/2') !== false || strpos($agt, 'ibm-webexplorer') !== false;
|
||||
$os['mac'] = strpos($agt, 'mac') !== false;
|
||||
$os['mac68k'] = $os['mac'] && (strpos($agt, '68k') !== false || strpos($agt, '68000') !== false);
|
||||
$os['macppc'] = $os['mac'] && (strpos($agt, 'ppc') !== false || strpos($agt, 'powerpc') !== false);
|
||||
$os['sun'] = strpos($agt, 'sunos') !== false;
|
||||
$os['sun4'] = strpos($agt, 'sunos 4') !== false;
|
||||
$os['sun5'] = strpos($agt, 'sunos 5') !== false;
|
||||
$os['suni86'] = $os['sun'] && strpos($agt, 'i86') !== false;
|
||||
$os['irix'] = strpos($agt, 'irix') !== false;
|
||||
$os['irix5'] = strpos($agt, 'irix 5') !== false;
|
||||
$os['irix6'] = strpos($agt, 'irix 6') !== false || strpos($agt, 'irix6') !== false;
|
||||
$os['hpux'] = strpos($agt, 'hp-ux') !== false;
|
||||
$os['hpux9'] = $os['hpux'] && strpos($agt, '09.') !== false;
|
||||
$os['hpux10'] = $os['hpux'] && strpos($agt, '10.') !== false;
|
||||
$os['aix'] = strpos($agt, 'aix') !== false;
|
||||
$os['aix1'] = strpos($agt, 'aix 1') !== false;
|
||||
$os['aix2'] = strpos($agt, 'aix 2') !== false;
|
||||
$os['aix3'] = strpos($agt, 'aix 3') !== false;
|
||||
$os['aix4'] = strpos($agt, 'aix 4') !== false;
|
||||
$os['linux'] = strpos($agt, 'inux') !== false;
|
||||
$os['sco'] = strpos($agt, 'sco') !== false || strpos($agt, 'unix_sv') !== false;
|
||||
$os['unixware'] = strpos($agt, 'unix_system_v') !== false;
|
||||
$os['mpras'] = strpos($agt, 'ncr') !== false;
|
||||
$os['reliant'] = strpos($agt, 'reliant') !== false;
|
||||
$os['dec'] = strpos($agt, 'dec') !== false || strpos($agt, 'osf1') !== false || strpos($agt, 'dec_alpha') !== false || strpos($agt, 'alphaserver') !== false || strpos($agt, 'ultrix') !== false || strpos($agt, 'alphastation') !== false;
|
||||
$os['sinix'] = strpos($agt, 'sinix') !== false;
|
||||
$os['freebsd'] = strpos($agt, 'freebsd') !== false;
|
||||
$os['bsd'] = strpos($agt, 'bsd') !== false;
|
||||
$os['unix'] = strpos($agt, 'x11') !== false || strpos($agt, 'unix') !== false || $os['sun'] || $os['irix'] || $os['hpux'] || $os['sco'] || $os['unixware'] || $os['mpras'] || $os['reliant'] || $os['dec'] || $os['sinix'] || $os['aix'] || $os['linux'] || $os['bsd'] || $os['freebsd'];
|
||||
$os['vms'] = strpos($agt, 'vax') !== false || strpos($agt, 'openvms') !== false;
|
||||
}
|
||||
|
||||
// Setup the quirks
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] ||
|
||||
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_QUIRKS])) {
|
||||
if ($browser['konq']) {
|
||||
Net_UserAgent_Detect::setQuirk('empty_file_input_value');
|
||||
}
|
||||
|
||||
if ($browser['ie']) {
|
||||
Net_UserAgent_Detect::setQuirk('cache_ssl_downloads');
|
||||
}
|
||||
|
||||
if ($browser['ie6']) {
|
||||
Net_UserAgent_Detect::setQuirk('scrollbar_in_way');
|
||||
}
|
||||
|
||||
if ($browser['ie5']) {
|
||||
Net_UserAgent_Detect::setQuirk('break_disposition_header');
|
||||
}
|
||||
|
||||
if ($browser['ie7']) {
|
||||
Net_UserAgent_Detect::setQuirk('popups_disabled');
|
||||
}
|
||||
|
||||
if ($browser['ns6']) {
|
||||
Net_UserAgent_Detect::setQuirk('popups_disabled');
|
||||
Net_UserAgent_Detect::setQuirk('must_cache_forms');
|
||||
}
|
||||
|
||||
if ($browser['nav'] && $subVersion < .79) {
|
||||
Net_UserAgent_Detect::setQuirk('nested_table_render_bug');
|
||||
}
|
||||
}
|
||||
|
||||
// Set features
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] ||
|
||||
($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) {
|
||||
if ($browser['gecko']) {
|
||||
preg_match(';gecko/([\d]+)\b;i', $agt, $matches);
|
||||
Net_UserAgent_Detect::setFeature('gecko', $matches[1]);
|
||||
}
|
||||
|
||||
if ($browser['gecko'] || ($browser['ie5up'] && !$browser['iemobile']) || $browser['konq'] || $browser['opera8up'] && !$os['wince']) {
|
||||
Net_UserAgent_Detect::setFeature('ajax');
|
||||
}
|
||||
|
||||
if ($browser['ns6up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) {
|
||||
Net_UserAgent_Detect::setFeature('dom');
|
||||
}
|
||||
|
||||
if ($browser['ie4up'] || $browser['ns4up'] || $browser['opera5up'] || $browser['konq'] || $browser['netgem']) {
|
||||
Net_UserAgent_Detect::setFeature('dhtml');
|
||||
}
|
||||
|
||||
if ($browser['firefox1.5'] || $browser['firefox2.x'] || $browser['opera9up']) {
|
||||
Net_UserAgent_Detect::setFeature('svg');
|
||||
}
|
||||
|
||||
if ($browser['gecko'] || $browser['ns6up'] || $browser['ie5up'] || $browser['konq'] || $browser['opera7up']) {
|
||||
Net_UserAgent_Detect::setFeature('css2');
|
||||
}
|
||||
}
|
||||
|
||||
if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_ACCEPT]) {
|
||||
$mimetypes = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT'), 0, strpos(getenv('HTTP_ACCEPT') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
|
||||
Net_UserAgent_Detect::setAcceptType((array) $mimetypes, 'mimetype');
|
||||
|
||||
$languages = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, strpos(getenv('HTTP_ACCEPT_LANGUAGE') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
|
||||
if (empty($languages)) {
|
||||
$languages = 'en';
|
||||
}
|
||||
|
||||
Net_UserAgent_Detect::setAcceptType((array) $languages, 'language');
|
||||
|
||||
$encodings = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_ENCODING'), 0, strpos(getenv('HTTP_ACCEPT_ENCODING') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
|
||||
Net_UserAgent_Detect::setAcceptType((array) $encodings, 'encoding');
|
||||
|
||||
$charsets = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_CHARSET'), 0, strpos(getenv('HTTP_ACCEPT_CHARSET') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY);
|
||||
Net_UserAgent_Detect::setAcceptType((array) $charsets, 'charset');
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setOption()
|
||||
|
||||
/**
|
||||
* Sets a class option. The available settings are:
|
||||
* o 'userAgent' => The user agent string to detect (useful for
|
||||
* checking a string manually).
|
||||
* o 'detectOptions' => The level of checking to do. A single level
|
||||
* or an array of options. Default is NET_USERAGENT_DETECT_ALL.
|
||||
*
|
||||
* @param string $in_field The option field (userAgent or detectOptions)
|
||||
* @param mixed $in_value The value for the field
|
||||
*/
|
||||
function setOption($in_field, $in_value)
|
||||
{
|
||||
$options = &Net_UserAgent_Detect::_getStaticProperty('options');
|
||||
$options[$in_field] = $in_value;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isBrowser()
|
||||
|
||||
/**
|
||||
* Look up the provide browser flag and return a boolean value
|
||||
*
|
||||
* Given one of the flags listed in the properties, this function will return
|
||||
* the value associated with that flag.
|
||||
*
|
||||
* @param string $in_match flag to lookup
|
||||
*
|
||||
* @access public
|
||||
* @return boolean whether or not the browser satisfies this flag
|
||||
*/
|
||||
function isBrowser($in_match)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
return isset($browser[strtolower($in_match)]) ? $browser[strtolower($in_match)] : false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getBrowser()
|
||||
|
||||
/**
|
||||
* Since simply returning the "browser" is somewhat ambiguous since there
|
||||
* are different ways to classify the browser, this function works by taking
|
||||
* an expect list and returning the string of the first match, so put the important
|
||||
* ones first in the array.
|
||||
*
|
||||
* @param array $in_expectList the browser flags to search for
|
||||
*
|
||||
* @access public
|
||||
* @return string first flag that matches
|
||||
*/
|
||||
function getBrowser($in_expectList)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
foreach((array) $in_expectList as $brwsr) {
|
||||
if (!empty($browser[strtolower($brwsr)])) {
|
||||
return $brwsr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getBrowserString()
|
||||
|
||||
/**
|
||||
* This function returns the vendor string corresponding to the flag.
|
||||
*
|
||||
* Either use the default matches or pass in an associative array of
|
||||
* flags and corresponding vendor strings. This function will find
|
||||
* the highest version flag and return the vendor string corresponding
|
||||
* to the appropriate flag. Be sure to pass in the flags in ascending order
|
||||
* if you want a basic matches first, followed by more detailed matches.
|
||||
*
|
||||
* @param array $in_vendorStrings (optional) array of flags matched with vendor strings
|
||||
*
|
||||
* @access public
|
||||
* @return string vendor string matches appropriate flag
|
||||
*/
|
||||
function getBrowserString($in_vendorStrings = null)
|
||||
{
|
||||
if (is_null($in_vendorStrings)) {
|
||||
$in_vendorStrings = array (
|
||||
'ie' => 'Microsoft Internet Explorer',
|
||||
'ie4up' => 'Microsoft Internet Explorer 4.x',
|
||||
'ie5up' => 'Microsoft Internet Explorer 5.x',
|
||||
'ie6up' => 'Microsoft Internet Explorer 6.x',
|
||||
'ie7up' => 'Microsoft Internet Explorer 7.x',
|
||||
'opera4' => 'Opera 4.x',
|
||||
'opera5up' => 'Opera 5.x',
|
||||
'nav' => 'Netscape Navigator',
|
||||
'ns4' => 'Netscape 4.x',
|
||||
'ns6up' => 'Mozilla/Netscape 6.x',
|
||||
'firefox0.x' => 'Firefox 0.x',
|
||||
'firefox1.x' => 'Firefox 1.x',
|
||||
'firefox1.5' => 'Firefox 1.5',
|
||||
'firefox2.x' => 'Firefox 2.x',
|
||||
'konq' => 'Konqueror/Safari',
|
||||
'netgem' => 'Netgem/iPlayer');
|
||||
}
|
||||
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
foreach((array) $in_vendorStrings as $flag => $string) {
|
||||
if (!empty($browser[$flag])) {
|
||||
$vendorString = $string;
|
||||
}
|
||||
}
|
||||
|
||||
// if there are no matches just use the user agent leading idendifier (usually Mozilla)
|
||||
if (!isset($vendorString)) {
|
||||
$leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier');
|
||||
$vendorString = $leadingIdentifier;
|
||||
}
|
||||
|
||||
return $vendorString;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isIE()
|
||||
|
||||
/**
|
||||
* Determine if the browser is an Internet Explorer browser
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not this browser is an ie browser
|
||||
*/
|
||||
function isIE()
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
return !empty($browser['ie']);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isNavigator()
|
||||
|
||||
/**
|
||||
* Determine if the browser is a Netscape Navigator browser
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not this browser is a Netscape Navigator browser
|
||||
*/
|
||||
function isNavigator()
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
return !empty($browser['nav']);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isNetscape()
|
||||
|
||||
/**
|
||||
* Determine if the browser is a Netscape or Mozilla browser
|
||||
*
|
||||
* Note that this function is not the same as isNavigator, since the
|
||||
* new Mozilla browsers are still sponsered by Netscape, and hence are
|
||||
* Netscape products, but not the original Navigators
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not this browser is a Netscape product
|
||||
*/
|
||||
function isNetscape()
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$browser = &Net_UserAgent_Detect::_getStaticProperty('browser');
|
||||
return !empty($browser['ns4up']);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isOS()
|
||||
|
||||
/**
|
||||
* Look up the provide OS flag and return a boolean value
|
||||
*
|
||||
* Given one of the flags listed in the properties, this function will return
|
||||
* the value associated with that flag for the operating system.
|
||||
*
|
||||
* @param string $in_match flag to lookup
|
||||
*
|
||||
* @access public
|
||||
* @return boolean whether or not the OS satisfies this flag
|
||||
*/
|
||||
function isOS($in_match)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$os = &Net_UserAgent_Detect::_getStaticProperty('os');
|
||||
return isset($os[strtolower($in_match)]) ? $os[strtolower($in_match)] : false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOS()
|
||||
|
||||
/**
|
||||
* Since simply returning the "os" is somewhat ambiguous since there
|
||||
* are different ways to classify the browser, this function works by taking
|
||||
* an expect list and returning the string of the first match, so put the important
|
||||
* ones first in the array.
|
||||
*
|
||||
* @access public
|
||||
* @return string first flag that matches
|
||||
*/
|
||||
function getOS($in_expectList)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$os = &Net_UserAgent_Detect::_getStaticProperty('os');
|
||||
foreach((array) $in_expectList as $expectOs) {
|
||||
if (!empty($os[strtolower($expectOs)])) {
|
||||
return $expectOs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOSString()
|
||||
|
||||
/**
|
||||
* This function returns the os string corresponding to the flag.
|
||||
*
|
||||
* Either use the default matches or pass in an associative array of
|
||||
* flags and corresponding os strings. This function will find
|
||||
* the highest version flag and return the os string corresponding
|
||||
* to the appropriate flag. Be sure to pass in the flags in ascending order
|
||||
* if you want a basic matches first, followed by more detailed matches.
|
||||
*
|
||||
* @param array $in_osStrings (optional) array of flags matched with os strings
|
||||
*
|
||||
* @access public
|
||||
* @return string os string matches appropriate flag
|
||||
*/
|
||||
function getOSString($in_osStrings = null)
|
||||
{
|
||||
if (is_null($in_osStrings)) {
|
||||
$in_osStrings = array(
|
||||
'win' => 'Microsoft Windows',
|
||||
'wince' => 'Microsoft Windows CE',
|
||||
'win9x' => 'Microsoft Windows 9x',
|
||||
'winme' => 'Microsoft Windows Millenium',
|
||||
'win2k' => 'Microsoft Windows 2000',
|
||||
'winnt' => 'Microsoft Windows NT',
|
||||
'winxp' => 'Microsoft Windows XP',
|
||||
'win2003' => 'Microsoft Windows 2003',
|
||||
'mac' => 'Macintosh',
|
||||
'unix' => 'Linux/Unix');
|
||||
}
|
||||
|
||||
Net_UserAgent_Detect::detect();
|
||||
$osString = 'Unknown';
|
||||
|
||||
$os = &Net_UserAgent_Detect::_getStaticProperty('os');
|
||||
foreach((array) $in_osStrings as $flag => $string) {
|
||||
if (!empty($os[$flag])) {
|
||||
$osString = $string;
|
||||
}
|
||||
}
|
||||
|
||||
return $osString;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setQuirk()
|
||||
|
||||
/**
|
||||
* Set a unique behavior for the current browser.
|
||||
*
|
||||
* Many client browsers do some really funky things, and this
|
||||
* mechanism allows the coder to determine if an excepetion must
|
||||
* be made with the current client.
|
||||
*
|
||||
* @param string $in_quirk The quirk to set
|
||||
* @param string $in_hasQuirk (optional) Does the browser have the quirk?
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setQuirk($in_quirk, $in_hasQuirk = true)
|
||||
{
|
||||
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
|
||||
$hasQuirk = !empty($in_hasQuirk);
|
||||
$quirks[strtolower($in_quirk)] = $hasQuirk;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ hasQuirk()
|
||||
|
||||
/**
|
||||
* Check a unique behavior for the current browser.
|
||||
*
|
||||
* Many client browsers do some really funky things, and this
|
||||
* mechanism allows the coder to determine if an excepetion must
|
||||
* be made with the current client.
|
||||
*
|
||||
* @param string $in_quirk The quirk to detect
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not browser has this quirk
|
||||
*/
|
||||
function hasQuirk($in_quirk)
|
||||
{
|
||||
return (bool) Net_UserAgent_Detect::getQuirk($in_quirk);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getQuirk()
|
||||
|
||||
/**
|
||||
* Get the unique behavior for the current browser.
|
||||
*
|
||||
* Many client browsers do some really funky things, and this
|
||||
* mechanism allows the coder to determine if an excepetion must
|
||||
* be made with the current client.
|
||||
*
|
||||
* @param string $in_quirk The quirk to detect
|
||||
*
|
||||
* @access public
|
||||
* @return string value of the quirk, in this case usually a boolean
|
||||
*/
|
||||
function getQuirk($in_quirk)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$quirks = &Net_UserAgent_Detect::_getStaticProperty('quirks');
|
||||
return isset($quirks[strtolower($in_quirk)]) ? $quirks[strtolower($in_quirk)] : null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setFeature()
|
||||
|
||||
/**
|
||||
* Set capabilities for the current browser.
|
||||
*
|
||||
* Since the capabilities of client browsers vary widly, this interface
|
||||
* helps keep track of the core features of a client, such as if the client
|
||||
* supports dhtml, dom, javascript, etc.
|
||||
*
|
||||
* @param string $in_feature The feature to set
|
||||
* @param string $in_hasFeature (optional) Does the browser have the feature?
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setFeature($in_feature, $in_hasFeature = true)
|
||||
{
|
||||
$features = &Net_UserAgent_Detect::_getStaticProperty('features');
|
||||
$features[strtolower($in_feature)] = $in_hasFeature;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ hasFeature()
|
||||
|
||||
/**
|
||||
* Check the capabilities for the current browser.
|
||||
*
|
||||
* Since the capabilities of client browsers vary widly, this interface
|
||||
* helps keep track of the core features of a client, such as if the client
|
||||
* supports dhtml, dom, javascript, etc.
|
||||
*
|
||||
* @param string $in_feature The feature to detect
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not the current client has this feature
|
||||
*/
|
||||
function hasFeature($in_feature)
|
||||
{
|
||||
return (bool) Net_UserAgent_Detect::getFeature($in_feature);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getFeature()
|
||||
|
||||
/**
|
||||
* Get the capabilities for the current browser.
|
||||
*
|
||||
* Since the capabilities of client browsers vary widly, this interface
|
||||
* helps keep track of the core features of a client, such as if the client
|
||||
* supports dhtml, dom, javascript, etc.
|
||||
*
|
||||
* @param string $in_feature The feature to detect
|
||||
*
|
||||
* @access public
|
||||
* @return string value of the feature requested
|
||||
*/
|
||||
function getFeature($in_feature)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$features = &Net_UserAgent_Detect::_getStaticProperty('features');
|
||||
return isset($features[strtolower($in_feature)]) ? $features[strtolower($in_feature)] : null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getAcceptType()
|
||||
|
||||
/**
|
||||
* Retrive the accept type for the current browser.
|
||||
*
|
||||
* To keep track of the mime-types, languages, charsets and encodings
|
||||
* that each browser accepts we use associative arrays for each type.
|
||||
* This function works like getBrowser() as it takes an expect list
|
||||
* and returns the first match. For instance, to find the language
|
||||
* you would pass in your allowed languages and see if any of the
|
||||
* languages set in the browser match.
|
||||
*
|
||||
* @param string $in_expectList values to check
|
||||
* @param string $in_type type of accept
|
||||
*
|
||||
* @access public
|
||||
* @return string the first matched value
|
||||
*/
|
||||
function getAcceptType($in_expectList, $in_type)
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$type = strtolower($in_type);
|
||||
|
||||
if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') {
|
||||
$typeArray = &Net_UserAgent_Detect::_getStaticProperty($type);
|
||||
foreach((array) $in_expectList as $match) {
|
||||
if (!empty($typeArray[$match])) {
|
||||
return $match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setAcceptType()
|
||||
|
||||
/**
|
||||
* Set the accept types for the current browser.
|
||||
*
|
||||
* To keep track of the mime-types, languages, charsets and encodings
|
||||
* that each browser accepts we use associative arrays for each type.
|
||||
* This function takes and array of accepted values for the type and
|
||||
* records them for retrieval.
|
||||
*
|
||||
* @param array $in_values values of the accept type
|
||||
* @param string $in_type type of accept
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setAcceptType($in_values, $in_type)
|
||||
{
|
||||
$type = strtolower($in_type);
|
||||
|
||||
if ($type == 'mimetype' || $type == 'language' || $type == 'charset' || $type == 'encoding') {
|
||||
$typeArray = &Net_UserAgent_Detect::_getStaticProperty($type);
|
||||
foreach((array) $in_values as $value) {
|
||||
$typeArray[$value] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ hasAcceptType()
|
||||
|
||||
/**
|
||||
* Check the accept types for the current browser.
|
||||
*
|
||||
* To keep track of the mime-types, languages, charsets and encodings
|
||||
* that each browser accepts we use associative arrays for each type.
|
||||
* This function checks the array for the given type and determines if
|
||||
* the browser accepts it.
|
||||
*
|
||||
* @param string $in_value values to check
|
||||
* @param string $in_type type of accept
|
||||
*
|
||||
* @access public
|
||||
* @return bool whether or not the value is accept for this type
|
||||
*/
|
||||
function hasAcceptType($in_value, $in_type)
|
||||
{
|
||||
return (bool) Net_UserAgent_Detect::getAcceptType((array) $in_value, $in_type);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getUserAgent()
|
||||
|
||||
/**
|
||||
* Return the user agent string that is being worked on
|
||||
*
|
||||
* @access public
|
||||
* @return string user agent
|
||||
*/
|
||||
function getUserAgent()
|
||||
{
|
||||
Net_UserAgent_Detect::detect();
|
||||
$userAgent = &Net_UserAgent_Detect::_getStaticProperty('userAgent');
|
||||
return $userAgent;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _getStaticProperty()
|
||||
|
||||
/**
|
||||
* Copy of getStaticProperty() from PEAR.php to avoid having to
|
||||
* include PEAR.php
|
||||
*
|
||||
* @access private
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
function &_getStaticProperty($var)
|
||||
{
|
||||
static $properties;
|
||||
return $properties[$var];
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
123
thirdparty/pear/Net/UserAgent/Detect/APC.php
vendored
123
thirdparty/pear/Net/UserAgent/Detect/APC.php
vendored
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.2 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Lucas Nealan <lucas@facebook.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
// $Id: APC.php,v 1.1 2007/09/19 21:35:22 jrust Exp $
|
||||
|
||||
require_once 'Net_UserAgent/detect.php';
|
||||
|
||||
class Net_UserAgent_Detect_APC extends Net_UserAgent_Detect
|
||||
{
|
||||
var $key = '';
|
||||
|
||||
function Net_UserAgent_Detect_APC($in_userAgent = null, $in_detect = null, $ua_cache_window = 600)
|
||||
{
|
||||
$data = '';
|
||||
$restored = false;
|
||||
$ua_cache_timeout = apc_fetch('useragent:cache_timeout'); // don't cache after time period
|
||||
|
||||
if(!class_exists('G')){
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
if ($ua_cache_window > 0) {
|
||||
if (!$ua_cache_timeout) {
|
||||
// check apc uptime and disable after x mins
|
||||
$apc_data = apc_cache_info('file', true);
|
||||
|
||||
if (isset($apc_data['start_time'])) {
|
||||
$uptime = $apc_data['start_time'];
|
||||
|
||||
if (time() - $uptime > $ua_cache_window) { // timeout and disable after 10 minutes of uptime
|
||||
apc_store('useragent:cache_timeout', true);
|
||||
$ua_cache_timeout = true; // don't cache this one either
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->key) {
|
||||
$key_flags = '';
|
||||
if ($in_detect !== null) {
|
||||
$key_flags = implode('-', $in_detect);
|
||||
}
|
||||
$this->key = 'useragent:'.G::encryptOld($in_userAgent.$key_flags);
|
||||
}
|
||||
|
||||
if ($data = apc_fetch($this->key)) {
|
||||
$success = null;
|
||||
$data = unserialize($data);
|
||||
if ($data) {
|
||||
$restored = $this->cache_restore($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$this->detect($in_userAgent, $in_detect);
|
||||
|
||||
if ($ua_cache_window > 0 && !$ua_cache_timeout) {
|
||||
$this->cache_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function &singleton($in_userAgent = null, $in_detect = null)
|
||||
{
|
||||
static $instance;
|
||||
|
||||
if (!isset($instance)) {
|
||||
$instance = new Net_UserAgent_Detect_APC($in_userAgent, $in_detect);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function cache_restore($cache)
|
||||
{
|
||||
if (is_array($cache)) {
|
||||
foreach($cache as $prop => $value) {
|
||||
$ptr = Net_UserAgent_Detect::_getStaticProperty($prop);
|
||||
$ptr = $value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function cache_save()
|
||||
{
|
||||
if ($this->key) {
|
||||
$data = array('browser' => Net_UserAgent_Detect::_getStaticProperty('browser'),
|
||||
'features' => Net_UserAgent_Detect::_getStaticProperty('features'),
|
||||
'leadingIdentifier' => Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'),
|
||||
'majorVersion' => Net_UserAgent_Detect::_getStaticProperty('majorVersion'),
|
||||
'options' => Net_UserAgent_Detect::_getStaticProperty('options'),
|
||||
'os' => Net_UserAgent_Detect::_getStaticProperty('os'),
|
||||
'quirks' => Net_UserAgent_Detect::_getStaticProperty('quirks'),
|
||||
'subVersion' => Net_UserAgent_Detect::_getStaticProperty('subVersion'),
|
||||
'userAgent' => Net_UserAgent_Detect::_getStaticProperty('userAgent'),
|
||||
'version' => Net_UserAgent_Detect::_getStaticProperty('version'),
|
||||
);
|
||||
apc_store($this->key, serialize($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
145
thirdparty/pear/Numbers/Words.php
vendored
145
thirdparty/pear/Numbers/Words.php
vendored
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Words.php,v 1.7 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* The Numbers_Words class provides method to convert arabic numerals to
|
||||
* words (also with currency name).
|
||||
*
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
// {{{ Numbers_Words
|
||||
|
||||
/**
|
||||
* The Numbers_Words class provides method to convert arabic numerals to words.
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words
|
||||
{
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that should be converted to a words representation
|
||||
*
|
||||
* @param string $locale Language name abbreviation. Optional. Defaults to en_US.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $locale = 'en_US') {
|
||||
|
||||
include_once("Numbers/Words/lang.${locale}.php");
|
||||
|
||||
$classname = "Numbers_Words_${locale}";
|
||||
|
||||
if (!class_exists($classname)) {
|
||||
return Numbers_Words::raiseError("Unable to include the Numbers/Words/lang.${locale}.php file");
|
||||
}
|
||||
|
||||
$methods = get_class_methods($classname);
|
||||
|
||||
if (!in_array('toWords', $methods) && !in_array('towords', $methods)) {
|
||||
return Numbers_Words::raiseError("Unable to find toWords method in '$classname' class");
|
||||
}
|
||||
|
||||
@$obj =& new $classname;
|
||||
|
||||
return trim($obj->toWords($num));
|
||||
}
|
||||
// }}}
|
||||
// {{{ toCurrency()
|
||||
/**
|
||||
* Converts a currency value to word representation (1.02 => one dollar two cents)
|
||||
* If the number has not any fraction part, the "cents" number is omitted.
|
||||
*
|
||||
* @param float $num A float/integer number representing currency value
|
||||
*
|
||||
* @param string $locale Language name abbreviation. Optional. Defaults to en_US.
|
||||
*
|
||||
* @param string $int_curr International currency symbol
|
||||
* as defined by the ISO 4217 standard (three characters).
|
||||
* E.g. 'EUR', 'USD', 'PLN'. Optional.
|
||||
* Defaults to $def_currency defined in the language class.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toCurrency($num, $locale = 'en_US', $int_curr = '') {
|
||||
$ret = $num;
|
||||
|
||||
@include_once("Numbers/Words/lang.${locale}.php");
|
||||
|
||||
$classname = "Numbers_Words_${locale}";
|
||||
|
||||
if (!class_exists($classname)) {
|
||||
return Numbers_Words::raiseError("Unable to include the Numbers/Words/lang.${locale}.php file");
|
||||
}
|
||||
|
||||
$methods = get_class_methods($classname);
|
||||
|
||||
if (!in_array('toCurrencyWords', $methods) && !in_array('tocurrencywords', $methods)) {
|
||||
return Numbers_Words::raiseError("Unable to find toCurrencyWords method in '$classname' class");
|
||||
}
|
||||
|
||||
@$obj =& new $classname;
|
||||
|
||||
if (strpos($num, '.') === false)
|
||||
{
|
||||
$ret = trim($obj->toCurrencyWords($int_curr, $num));
|
||||
} else {
|
||||
$currency = explode('.', $num, 2);
|
||||
$ret = trim($obj->toCurrencyWords($int_curr, $currency[0], $currency[1]));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
// {{{ raiseError()
|
||||
/**
|
||||
* Trigger a PEAR error
|
||||
*
|
||||
* To improve performances, the PEAR.php file is included dynamically.
|
||||
*
|
||||
* @param string error message
|
||||
*/
|
||||
function raiseError($msg)
|
||||
{
|
||||
include_once('PEAR.php');
|
||||
return PEAR::raiseError($msg);
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
// }}}
|
||||
?>
|
||||
505
thirdparty/pear/Numbers/Words/lang.bg.php
vendored
505
thirdparty/pear/Numbers/Words/lang.bg.php
vendored
@@ -1,505 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Kouber Saparev <kouber@saparev.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Bulgarian.
|
||||
*
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_bg extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'bg';
|
||||
|
||||
/**
|
||||
* Language name in English.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Bulgarian';
|
||||
|
||||
/**
|
||||
* Native language name.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
|
||||
/**
|
||||
* Some miscellaneous words and language constructs.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_misc_strings = array(
|
||||
'deset'=>'<27><><EFBFBD><EFBFBD><EFBFBD>', // "ten"
|
||||
'edinadeset'=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', // "eleven"
|
||||
'na'=>'<27><>', // liaison particle for 12 to 19
|
||||
'sto'=>'<27><><EFBFBD>', // "hundred"
|
||||
'sta'=>'<27><><EFBFBD>', // suffix for 2 and 3 hundred
|
||||
'stotin'=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', // suffix for 4 to 9 hundred
|
||||
'hiliadi'=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' // plural form of "thousand"
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* The words for digits (except zero). Note that, there are three genders for them (neuter, masculine and feminine).
|
||||
* The words for 3 to 9 (masculine) and for 2 to 9 (feminine) are the same as neuter, so they're filled
|
||||
* in the _initDigits() method, which is invoked from the constructor.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0=>array(1=>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), // neuter
|
||||
1=>array(1=>'<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD>'), // masculine
|
||||
-1=>array(1=>'<27><><EFBFBD><EFBFBD>') // feminine
|
||||
);
|
||||
|
||||
/**
|
||||
* A flag, that determines if the _digits array is filled for masculine and feminine genders.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_digits_initialized = false;
|
||||
|
||||
/**
|
||||
* A flag, that determines if the "and" word is placed already before the last non-empty group of digits.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_last_and = false;
|
||||
|
||||
/**
|
||||
* The word for zero.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_zero = '<27><><EFBFBD><EFBFBD>';
|
||||
|
||||
/**
|
||||
* The word for infinity.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_infinity = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
|
||||
/**
|
||||
* The word for the "and" language construct.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_and = '<27>';
|
||||
|
||||
/**
|
||||
* The word separator.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The word for the minus sign.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = '<27><><EFBFBD><EFBFBD><EFBFBD>'; // minus sign
|
||||
|
||||
/**
|
||||
* The plural suffix (except for thousand).
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_plural = '<27>'; // plural suffix
|
||||
|
||||
/**
|
||||
* The suffixes for exponents (singular).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => '',
|
||||
3 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
6 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
9 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
12 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
15 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
18 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
21 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
24 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
27 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
30 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
33 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
36 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
39 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
42 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
45 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
48 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
51 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
54 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
57 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
60 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
63 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
66 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
69 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
72 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
75 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
78 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
81 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
84 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
87 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
90 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
93 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
96 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
99 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
102 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
105 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
108 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
111 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
114 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
117 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
120 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
123 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
126 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
129 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
132 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
135 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
138 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
141 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
144 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
147 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
150 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
153 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
156 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
159 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
162 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
165 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
168 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
171 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
174 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
177 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
180 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
183 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
186 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
189 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
192 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
195 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
198 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
201 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
204 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
207 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
210 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
213 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
216 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
219 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
222 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
225 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
228 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
231 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
234 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
237 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
240 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
243 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
246 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
249 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
252 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
255 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
258 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
261 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
264 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
267 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
270 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
273 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
276 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
279 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
282 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
285 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
288 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
291 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
294 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
297 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
300 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
303 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
// }}}
|
||||
|
||||
// {{{ Numbers_Words_bg()
|
||||
|
||||
/**
|
||||
* The class constructor, used for calling the _initDigits method.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access public
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
* @see function _initDigits
|
||||
*/
|
||||
function Numbers_Words_bg() {
|
||||
$this->_initDigits();
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _initDigits()
|
||||
|
||||
/**
|
||||
* Fills the _digits array for masculine and feminine genders with
|
||||
* corresponding references to neuter words (when they're the same).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access private
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
*/
|
||||
function _initDigits() {
|
||||
if (!$this->_digits_initialized) {
|
||||
for ($i=3; $i<=9; $i++) {
|
||||
$this->_digits[1][$i] =& $this->_digits[0][$i];
|
||||
}
|
||||
for ($i=2; $i<=9; $i++) {
|
||||
$this->_digits[-1][$i] =& $this->_digits[0][$i];
|
||||
}
|
||||
$this->_digits_initialized = true;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _splitNumber()
|
||||
|
||||
/**
|
||||
* Split a number to groups of three-digit numbers.
|
||||
*
|
||||
* @param mixed $num An integer or its string representation
|
||||
* that need to be split
|
||||
*
|
||||
* @return array Groups of three-digit numbers.
|
||||
*
|
||||
* @access private
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
|
||||
function _splitNumber($num)
|
||||
{
|
||||
if (is_string($num)) {
|
||||
$ret = array();
|
||||
$strlen = strlen($num);
|
||||
$first = substr($num, 0, $strlen%3);
|
||||
preg_match_all('/\d{3}/', substr($num, $strlen%3, $strlen), $m);
|
||||
$ret =& $m[0];
|
||||
if ($first) array_unshift($ret, $first);
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _showDigitsGroup()
|
||||
|
||||
/**
|
||||
* Converts a three-digit number to its word representation
|
||||
* in Bulgarian language.
|
||||
*
|
||||
* @param integer $num An integer between 1 and 999 inclusive.
|
||||
*
|
||||
* @param integer $gender An integer which represents the gender of
|
||||
* the current digits group.
|
||||
* 0 - neuter
|
||||
* 1 - masculine
|
||||
* -1 - feminine
|
||||
*
|
||||
* @param boolean $last A flag that determines if the current digits group
|
||||
* is the last one.
|
||||
*
|
||||
* @return string The words for the given number.
|
||||
*
|
||||
* @access private
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
*/
|
||||
function _showDigitsGroup($num, $gender = 0, $last = false)
|
||||
{
|
||||
/* A storage array for the return string.
|
||||
Positions 1, 3, 5 are intended for digit words
|
||||
and everything else (0, 2, 4) for "and" words.
|
||||
Both of the above types are optional, so the size of
|
||||
the array may vary.
|
||||
*/
|
||||
$ret = array();
|
||||
|
||||
// extract the value of each digit from the three-digit number
|
||||
$e = $num%10; // ones
|
||||
$d = ($num-$e)%100/10; // tens
|
||||
$s = ($num-$d*10-$e)%1000/100; // hundreds
|
||||
|
||||
// process the "hundreds" digit.
|
||||
if ($s) {
|
||||
switch ($s) {
|
||||
case 1:
|
||||
$ret[1] = $this->_misc_strings['sto'];
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
$ret[1] = $this->_digits[0][$s].$this->_misc_strings['sta'];
|
||||
break;
|
||||
default:
|
||||
$ret[1] = $this->_digits[0][$s].$this->_misc_strings['stotin'];
|
||||
}
|
||||
}
|
||||
|
||||
// process the "tens" digit, and optionally the "ones" digit.
|
||||
if ($d) {
|
||||
// in the case of 1, the "ones" digit also must be processed
|
||||
if ($d==1) {
|
||||
if (!$e) {
|
||||
$ret[3] = $this->_misc_strings['deset']; // ten
|
||||
} else {
|
||||
if ($e==1) {
|
||||
$ret[3] = $this->_misc_strings['edinadeset']; // eleven
|
||||
} else {
|
||||
$ret[3] = $this->_digits[1][$e].$this->_misc_strings['na'].$this->_misc_strings['deset']; // twelve - nineteen
|
||||
}
|
||||
// the "ones" digit is alredy processed, so skip a second processment
|
||||
$e = 0;
|
||||
}
|
||||
} else {
|
||||
$ret[3] = $this->_digits[1][$d].$this->_misc_strings['deset']; // twenty - ninety
|
||||
}
|
||||
}
|
||||
|
||||
// process the "ones" digit
|
||||
if ($e) {
|
||||
$ret[5] = $this->_digits[$gender][$e];
|
||||
}
|
||||
|
||||
// put "and" where needed
|
||||
if (count($ret)>1) {
|
||||
if ($e) {
|
||||
$ret[4] = $this->_and;
|
||||
} else {
|
||||
$ret[2] = $this->_and;
|
||||
}
|
||||
}
|
||||
|
||||
// put "and" optionally in the case this is the last non-empty group
|
||||
if ($last) {
|
||||
if (!$s||count($ret)==1) {
|
||||
$ret[0] = $this->_and;
|
||||
}
|
||||
$this->_last_and = true;
|
||||
}
|
||||
|
||||
// sort the return array so that "and" constructs go to theirs appropriate places
|
||||
ksort($ret);
|
||||
|
||||
return implode($this->_sep, $ret);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Bulgarian language.
|
||||
*
|
||||
* @param integer $num An integer between 9.99*-10^302 and 9.99*10^302 (999 centillions)
|
||||
* that need to be converted to words
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
*/
|
||||
function toWords($num = 0)
|
||||
{
|
||||
$ret = array();
|
||||
$ret_minus = '';
|
||||
|
||||
// check if $num is a valid non-zero number
|
||||
if (!$num || preg_match('/^-?0+$/', $num) || !preg_match('/^-?\d+$/', $num)) return $this->_zero;
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret_minus = $this->_minus . $this->_sep;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// if the absolute value is greater than 9.99*10^302, return infinity
|
||||
if (strlen($num)>306) {
|
||||
return $ret_minus . $this->_infinity;
|
||||
}
|
||||
|
||||
// strip excessive zero signs
|
||||
$num = ltrim($num, '0');
|
||||
|
||||
// split $num to groups of three-digit numbers
|
||||
$num_groups = $this->_splitNumber($num);
|
||||
|
||||
$sizeof_numgroups = count($num_groups);
|
||||
|
||||
// go through the groups in reverse order, so that the last group could be determined
|
||||
for ($i=$sizeof_numgroups-1, $j=1; $i>=0; $i--, $j++) {
|
||||
if (!isset($ret[$j])) {
|
||||
$ret[$j] = '';
|
||||
}
|
||||
|
||||
// what is the corresponding exponent for the current group
|
||||
$pow = $sizeof_numgroups-$i;
|
||||
|
||||
// skip processment for empty groups
|
||||
if ($num_groups[$i]!='000') {
|
||||
if ($num_groups[$i]>1) {
|
||||
if ($pow==1) {
|
||||
$ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 0, !$this->_last_and && $i).$this->_sep;
|
||||
$ret[$j] .= $this->_exponent[($pow-1)*3];
|
||||
} elseif ($pow==2) {
|
||||
$ret[$j] .= $this->_showDigitsGroup($num_groups[$i], -1, !$this->_last_and && $i).$this->_sep;
|
||||
$ret[$j] .= $this->_misc_strings['hiliadi'].$this->_sep;
|
||||
} else {
|
||||
$ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 1, !$this->_last_and && $i).$this->_sep;
|
||||
$ret[$j] .= $this->_exponent[($pow-1)*3].$this->_plural.$this->_sep;
|
||||
}
|
||||
} else {
|
||||
if ($pow==1) {
|
||||
$ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 0, !$this->_last_and && $i).$this->_sep;
|
||||
} elseif ($pow==2) {
|
||||
$ret[$j] .= $this->_exponent[($pow-1)*3].$this->_sep;
|
||||
} else {
|
||||
$ret[$j] .= $this->_digits[1][1].$this->_sep.$this->_exponent[($pow-1)*3].$this->_sep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret_minus . rtrim(implode('', array_reverse($ret)), $this->_sep);
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
318
thirdparty/pear/Numbers/Words/lang.de.php
vendored
318
thirdparty/pear/Numbers/Words/lang.de.php
vendored
@@ -1,318 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.de.php,v 1.5 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in German language.
|
||||
//
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for translating numbers into German.
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into German.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_de extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'de';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'German';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Deutsch';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'Minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names partly based on:
|
||||
* http://german.about.com/library/blzahlenaud.htm
|
||||
* http://www3.osk.3web.ne.jp/~nagatani/common/zahlwort.htm
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('tausend','tausend'),
|
||||
6 => array('Millione','Millionen'),
|
||||
9 => array('Milliarde','Milliarden'),
|
||||
12 => array('Billion','Billionen'),
|
||||
15 => array('Billiarde','Billiarden'),
|
||||
18 => array('Trillion','Trillionen'),
|
||||
21 => array('Trilliarde','Trilliarden'),
|
||||
24 => array('Quadrillion','Quadrillionen'),
|
||||
27 => array('Quadrilliarde','Quadrilliarden'),
|
||||
30 => array('Quintillion','Quintillionen'),
|
||||
33 => array('Quintilliarde','Quintilliarden'),
|
||||
36 => array('Sextillion','Sextillionen'),
|
||||
39 => array('Sextilliarde','Sextilliarden'),
|
||||
42 => array('Septillion','Septillionen'),
|
||||
45 => array('Septilliarde','Septilliarden'),
|
||||
48 => array('Oktillion','Oktillionen'), // oder Octillionen
|
||||
51 => array('Oktilliarde','Oktilliarden'),
|
||||
54 => array('Nonillion','Nonillionen'),
|
||||
57 => array('Nonilliarde','Nonilliarden'),
|
||||
60 => array('Dezillion','Dezillionen'),
|
||||
63 => array('Dezilliarde','Dezilliarden'),
|
||||
120 => array('Vigintillion','Vigintillionen'),
|
||||
123 => array('Vigintilliarde','Vigintilliarden'),
|
||||
600 => array('Zentillion','Zentillionen'), // oder Centillion
|
||||
603 => array('Zentilliarde','Zentilliarden')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'null', 'ein', 'zwei', 'drei', 'vier',
|
||||
'f<>nf', 'sechs', 'sieben', 'acht', 'neun'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = '';
|
||||
|
||||
/**
|
||||
* The exponent word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep2 = ' ';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in German language.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundert';
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
if ($t > 0) {
|
||||
$ret .= $this->_digits[$d] . 'und';
|
||||
} else {
|
||||
$ret .= $this->_digits[$d];
|
||||
if ($d == 1)
|
||||
if ($power == 0)
|
||||
$ret .= 's'; // fuer eins
|
||||
else
|
||||
$ret .= 'e'; // fuer eine
|
||||
}
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 5:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'zig';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'siebzig';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sechzig';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'vierzig';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'drei<65>ig';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'zwanzig';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'zehn';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'elf';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'zw<7A>lf';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 8:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'zehn';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sechzehn';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'siebzehn';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
if ($power == 3)
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
elseif ($d == 1 && ($t+$h) == 0)
|
||||
$ret .= $this->_sep2 . $lev[0] . $this->_sep2;
|
||||
else
|
||||
$ret .= $this->_sep2 . $lev[1] . $this->_sep2;
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
349
thirdparty/pear/Numbers/Words/lang.ee.php
vendored
349
thirdparty/pear/Numbers/Words/lang.ee.php
vendored
@@ -1,349 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Erkki Saarniit <erkki@center.ee> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.ee.php,v 1.5 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Estonian language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Estonian.
|
||||
*
|
||||
* @author Erkki Saarniit
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Estonian.
|
||||
*
|
||||
* @author Erkki Saarniit
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_ee extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'ee';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Estonian';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'eesti keel';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'miinus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names partly based on:
|
||||
* http://home.earthlink.net/~mrob/pub/math/largenum.html
|
||||
* http://mathforum.org/dr.math/faq/faq.large.numbers.html
|
||||
* http://www.mazes.com/AmericanNumberingSystem.html
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('tuhat'),
|
||||
6 => array('miljon'),
|
||||
9 => array('miljard'),
|
||||
12 => array('triljon'),
|
||||
15 => array('kvadriljon'),
|
||||
18 => array('kvintiljon'),
|
||||
21 => array('sekstiljon'),
|
||||
24 => array('septiljon'),
|
||||
27 => array('oktiljon'),
|
||||
30 => array('noniljon'),
|
||||
33 => array('dekiljon'),
|
||||
36 => array('undekiljon'),
|
||||
39 => array('duodekiljon'),
|
||||
42 => array('tredekiljon'),
|
||||
45 => array('kvattuordekiljon'),
|
||||
48 => array('kvindekiljon'),
|
||||
51 => array('seksdekiljon'),
|
||||
54 => array('septendekiljon'),
|
||||
57 => array('oktodekiljon'),
|
||||
60 => array('novemdekiljon'),
|
||||
63 => array('vigintiljon'),
|
||||
66 => array('unvigintiljon'),
|
||||
69 => array('duovigintiljon'),
|
||||
72 => array('trevigintiljon'),
|
||||
75 => array('kvattuorvigintiljon'),
|
||||
78 => array('kvinvigintiljon'),
|
||||
81 => array('seksvigintiljon'),
|
||||
84 => array('septenvigintiljon'),
|
||||
87 => array('oktovigintiljon'),
|
||||
90 => array('novemvigintiljon'),
|
||||
93 => array('trigintiljon'),
|
||||
96 => array('untrigintiljon'),
|
||||
99 => array('duotrigintiljon'),
|
||||
102 => array('trestrigintiljon'),
|
||||
105 => array('kvattuortrigintiljon'),
|
||||
108 => array('kvintrigintiljon'),
|
||||
111 => array('sekstrigintiljon'),
|
||||
114 => array('septentrigintiljon'),
|
||||
117 => array('oktotrigintiljon'),
|
||||
120 => array('novemtrigintiljon'),
|
||||
123 => array('kvadragintiljon'),
|
||||
126 => array('unkvadragintiljon'),
|
||||
129 => array('duokvadragintiljon'),
|
||||
132 => array('trekvadragintiljon'),
|
||||
135 => array('kvattuorkvadragintiljon'),
|
||||
138 => array('kvinkvadragintiljon'),
|
||||
141 => array('sekskvadragintiljon'),
|
||||
144 => array('septenkvadragintiljon'),
|
||||
147 => array('oktokvadragintiljon'),
|
||||
150 => array('novemkvadragintiljon'),
|
||||
153 => array('kvinkvagintiljon'),
|
||||
156 => array('unkvinkvagintiljon'),
|
||||
159 => array('duokvinkvagintiljon'),
|
||||
162 => array('trekvinkvagintiljon'),
|
||||
165 => array('kvattuorkvinkvagintiljon'),
|
||||
168 => array('kvinkvinkvagintiljon'),
|
||||
171 => array('sekskvinkvagintiljon'),
|
||||
174 => array('septenkvinkvagintiljon'),
|
||||
177 => array('oktokvinkvagintiljon'),
|
||||
180 => array('novemkvinkvagintiljon'),
|
||||
183 => array('seksagintiljon'),
|
||||
186 => array('unseksagintiljon'),
|
||||
189 => array('duoseksagintiljon'),
|
||||
192 => array('treseksagintiljon'),
|
||||
195 => array('kvattuorseksagintiljon'),
|
||||
198 => array('kvinseksagintiljon'),
|
||||
201 => array('seksseksagintiljon'),
|
||||
204 => array('septenseksagintiljon'),
|
||||
207 => array('oktoseksagintiljon'),
|
||||
210 => array('novemseksagintiljon'),
|
||||
213 => array('septuagintiljon'),
|
||||
216 => array('unseptuagintiljon'),
|
||||
219 => array('duoseptuagintiljon'),
|
||||
222 => array('treseptuagintiljon'),
|
||||
225 => array('kvattuorseptuagintiljon'),
|
||||
228 => array('kvinseptuagintiljon'),
|
||||
231 => array('seksseptuagintiljon'),
|
||||
234 => array('septenseptuagintiljon'),
|
||||
237 => array('oktoseptuagintiljon'),
|
||||
240 => array('novemseptuagintiljon'),
|
||||
243 => array('oktogintiljon'),
|
||||
246 => array('unoktogintiljon'),
|
||||
249 => array('duooktogintiljon'),
|
||||
252 => array('treoktogintiljon'),
|
||||
255 => array('kvattuoroktogintiljon'),
|
||||
258 => array('kvinoktogintiljon'),
|
||||
261 => array('seksoktogintiljon'),
|
||||
264 => array('septoktogintiljon'),
|
||||
267 => array('oktooktogintiljon'),
|
||||
270 => array('novemoktogintiljon'),
|
||||
273 => array('nonagintiljon'),
|
||||
276 => array('unnonagintiljon'),
|
||||
279 => array('duononagintiljon'),
|
||||
282 => array('trenonagintiljon'),
|
||||
285 => array('kvattuornonagintiljon'),
|
||||
288 => array('kvinnonagintiljon'),
|
||||
291 => array('seksnonagintiljon'),
|
||||
294 => array('septennonagintiljon'),
|
||||
297 => array('oktononagintiljon'),
|
||||
300 => array('novemnonagintiljon'),
|
||||
303 => array('kentiljon'),
|
||||
309 => array('duokentiljon'),
|
||||
312 => array('trekentiljon'),
|
||||
366 => array('primo-vigesimo-kentiljon'),
|
||||
402 => array('trestrigintakentiljon'),
|
||||
603 => array('dukentiljon'),
|
||||
624 => array('septendukentiljon'),
|
||||
2421 => array('seksoktingentiljon'),
|
||||
3003 => array('milliljon'),
|
||||
3000003 => array('milli-milliljon')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'null', '<27>ks', 'kaks', 'kolm', 'neli',
|
||||
'viis', 'kuus', 'seitse', 'kaheksa', '<27>heksa'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Estonian language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
$ret .= $this->_sep . $this->_digits[$h] . 'sada';
|
||||
|
||||
}
|
||||
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
case 6:
|
||||
case 5:
|
||||
case 4:
|
||||
case 3:
|
||||
case 2:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'k<>mmend';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'k<>mme';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'teist';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($t != 1 && $d > 0) {
|
||||
if ($t > 1) {
|
||||
$ret .= ' ' . $this->_digits[$d];
|
||||
} else {
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
$ret .= $this->_sep . $lev[0].($num != 1 && $power!= 3 ? 'it' : '');
|
||||
}
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
307
thirdparty/pear/Numbers/Words/lang.en_100.php
vendored
307
thirdparty/pear/Numbers/Words/lang.en_100.php
vendored
@@ -1,307 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.en_100.php,v 1.6 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Donald Knuth system, in English language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Donald Knuth system, in English language.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Donald Knuth system, in English language.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_en_100 extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'en_100';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'English (Donald Knuth system)';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'English (Donald Knuth system)';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names based on:
|
||||
* http://home.earthlink.net/~mrob/pub/math/largenum.html
|
||||
* Donald Knuth system (power of 2)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
2 => array('hundred'),
|
||||
4 => array('myriad'),
|
||||
8 => array('myllion'),
|
||||
16 => array('byllion'),
|
||||
32 => array('tryllion'),
|
||||
64 => array('quadryllion'),
|
||||
128 => array('quintyllion'),
|
||||
256 => array('sextyllion'),
|
||||
512 => array('septyllion'),
|
||||
1024 => array('octyllion'),
|
||||
2048 => array('nonyllion'),
|
||||
4096 => array('decyllion'),
|
||||
8192 => array('undecyllion'),
|
||||
16384 => array('duodecyllion'),
|
||||
32768 => array('tredecyllion'),
|
||||
65536 => array('quattuordecyllion'),
|
||||
131072 => array('quindecyllion'),
|
||||
262144 => array('sexdecyllion'),
|
||||
524288 => array('septendecyllion'),
|
||||
1048576 => array('octodecyllion'),
|
||||
2097152 => array('novemdecyllion'),
|
||||
4194304 => array('vigintyllion')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'zero', 'one', 'two', 'three', 'four',
|
||||
'five', 'six', 'seven', 'eight', 'nine'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Donald Knuth system, in English language.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, ''); // $cursuffix);
|
||||
// normally cursuffix is added at the end, but not here
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
|
||||
|
||||
// in English only - add ' and' for [1-9]01..[1-9]99
|
||||
// (also for 1001..1099, 10001..10099 but it is harder)
|
||||
// for now it is switched off, maybe some language purists
|
||||
// can force me to enable it, or to remove it completely
|
||||
// if (($t + $d) > 0)
|
||||
// $ret .= $this->_sep . 'and';
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 7:
|
||||
case 6:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'ty';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighty';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifty';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'forty';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirty';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twenty';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'ten';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'eleven';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twelve';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirteen';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'teen';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifteen';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighteen';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
// add minus sign between [2-9] and digit
|
||||
if ($t > 1) {
|
||||
$ret .= '-' . $this->_digits[$d];
|
||||
} else {
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
308
thirdparty/pear/Numbers/Words/lang.en_GB.php
vendored
308
thirdparty/pear/Numbers/Words/lang.en_GB.php
vendored
@@ -1,308 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.en_GB.php,v 1.7 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in British English language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into British English.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into British English.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_en_GB extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'en_GB';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'British English';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'British English';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names partly based on:
|
||||
* http://www.users.dircon.co.uk/~shaunf/shaun/numbers/millions.htm
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('thousand'),
|
||||
6 => array('million'),
|
||||
12 => array('billion'),
|
||||
18 => array('trillion'),
|
||||
24 => array('quadrillion'),
|
||||
30 => array('quintillion'),
|
||||
36 => array('sextillion'),
|
||||
42 => array('septillion'),
|
||||
48 => array('octillion'),
|
||||
54 => array('nonillion'),
|
||||
60 => array('decillion'),
|
||||
66 => array('undecillion'),
|
||||
72 => array('duodecillion'),
|
||||
78 => array('tredecillion'),
|
||||
84 => array('quattuordecillion'),
|
||||
90 => array('quindecillion'),
|
||||
96 => array('sexdecillion'),
|
||||
102 => array('septendecillion'),
|
||||
108 => array('octodecillion'),
|
||||
114 => array('novemdecillion'),
|
||||
120 => array('vigintillion'),
|
||||
192 => array('duotrigintillion'),
|
||||
600 => array('centillion')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'zero', 'one', 'two', 'three', 'four',
|
||||
'five', 'six', 'seven', 'eight', 'nine'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in British English language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
|
||||
|
||||
// in English only - add ' and' for [1-9]01..[1-9]99
|
||||
// (also for 1001..1099, 10001..10099 but it is harder)
|
||||
// for now it is switched off, maybe some language purists
|
||||
// can force me to enable it, or to remove it completely
|
||||
// if (($t + $d) > 0)
|
||||
// $ret .= $this->_sep . 'and';
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 7:
|
||||
case 6:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'ty';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighty';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifty';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'forty';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirty';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twenty';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'ten';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'eleven';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twelve';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirteen';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'teen';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifteen';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighteen';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
// add minus sign between [2-9] and digit
|
||||
if ($t > 1) {
|
||||
$ret .= '-' . $this->_digits[$d];
|
||||
} else {
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
509
thirdparty/pear/Numbers/Words/lang.en_US.php
vendored
509
thirdparty/pear/Numbers/Words/lang.en_US.php
vendored
@@ -1,509 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.en_US.php,v 1.7 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in American English language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into American English.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into American English.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_en_US extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'en_US';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'American English';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'American English';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names partly based on:
|
||||
* http://home.earthlink.net/~mrob/pub/math/largenum.html
|
||||
* http://mathforum.org/dr.math/faq/faq.large.numbers.html
|
||||
* http://www.mazes.com/AmericanNumberingSystem.html
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('thousand'),
|
||||
6 => array('million'),
|
||||
9 => array('billion'),
|
||||
12 => array('trillion'),
|
||||
15 => array('quadrillion'),
|
||||
18 => array('quintillion'),
|
||||
21 => array('sextillion'),
|
||||
24 => array('septillion'),
|
||||
27 => array('octillion'),
|
||||
30 => array('nonillion'),
|
||||
33 => array('decillion'),
|
||||
36 => array('undecillion'),
|
||||
39 => array('duodecillion'),
|
||||
42 => array('tredecillion'),
|
||||
45 => array('quattuordecillion'),
|
||||
48 => array('quindecillion'),
|
||||
51 => array('sexdecillion'),
|
||||
54 => array('septendecillion'),
|
||||
57 => array('octodecillion'),
|
||||
60 => array('novemdecillion'),
|
||||
63 => array('vigintillion'),
|
||||
66 => array('unvigintillion'),
|
||||
69 => array('duovigintillion'),
|
||||
72 => array('trevigintillion'),
|
||||
75 => array('quattuorvigintillion'),
|
||||
78 => array('quinvigintillion'),
|
||||
81 => array('sexvigintillion'),
|
||||
84 => array('septenvigintillion'),
|
||||
87 => array('octovigintillion'),
|
||||
90 => array('novemvigintillion'),
|
||||
93 => array('trigintillion'),
|
||||
96 => array('untrigintillion'),
|
||||
99 => array('duotrigintillion'),
|
||||
// 100 => array('googol') - not latin name
|
||||
// 10^googol = 1 googolplex
|
||||
102 => array('trestrigintillion'),
|
||||
105 => array('quattuortrigintillion'),
|
||||
108 => array('quintrigintillion'),
|
||||
111 => array('sextrigintillion'),
|
||||
114 => array('septentrigintillion'),
|
||||
117 => array('octotrigintillion'),
|
||||
120 => array('novemtrigintillion'),
|
||||
123 => array('quadragintillion'),
|
||||
126 => array('unquadragintillion'),
|
||||
129 => array('duoquadragintillion'),
|
||||
132 => array('trequadragintillion'),
|
||||
135 => array('quattuorquadragintillion'),
|
||||
138 => array('quinquadragintillion'),
|
||||
141 => array('sexquadragintillion'),
|
||||
144 => array('septenquadragintillion'),
|
||||
147 => array('octoquadragintillion'),
|
||||
150 => array('novemquadragintillion'),
|
||||
153 => array('quinquagintillion'),
|
||||
156 => array('unquinquagintillion'),
|
||||
159 => array('duoquinquagintillion'),
|
||||
162 => array('trequinquagintillion'),
|
||||
165 => array('quattuorquinquagintillion'),
|
||||
168 => array('quinquinquagintillion'),
|
||||
171 => array('sexquinquagintillion'),
|
||||
174 => array('septenquinquagintillion'),
|
||||
177 => array('octoquinquagintillion'),
|
||||
180 => array('novemquinquagintillion'),
|
||||
183 => array('sexagintillion'),
|
||||
186 => array('unsexagintillion'),
|
||||
189 => array('duosexagintillion'),
|
||||
192 => array('tresexagintillion'),
|
||||
195 => array('quattuorsexagintillion'),
|
||||
198 => array('quinsexagintillion'),
|
||||
201 => array('sexsexagintillion'),
|
||||
204 => array('septensexagintillion'),
|
||||
207 => array('octosexagintillion'),
|
||||
210 => array('novemsexagintillion'),
|
||||
213 => array('septuagintillion'),
|
||||
216 => array('unseptuagintillion'),
|
||||
219 => array('duoseptuagintillion'),
|
||||
222 => array('treseptuagintillion'),
|
||||
225 => array('quattuorseptuagintillion'),
|
||||
228 => array('quinseptuagintillion'),
|
||||
231 => array('sexseptuagintillion'),
|
||||
234 => array('septenseptuagintillion'),
|
||||
237 => array('octoseptuagintillion'),
|
||||
240 => array('novemseptuagintillion'),
|
||||
243 => array('octogintillion'),
|
||||
246 => array('unoctogintillion'),
|
||||
249 => array('duooctogintillion'),
|
||||
252 => array('treoctogintillion'),
|
||||
255 => array('quattuoroctogintillion'),
|
||||
258 => array('quinoctogintillion'),
|
||||
261 => array('sexoctogintillion'),
|
||||
264 => array('septoctogintillion'),
|
||||
267 => array('octooctogintillion'),
|
||||
270 => array('novemoctogintillion'),
|
||||
273 => array('nonagintillion'),
|
||||
276 => array('unnonagintillion'),
|
||||
279 => array('duononagintillion'),
|
||||
282 => array('trenonagintillion'),
|
||||
285 => array('quattuornonagintillion'),
|
||||
288 => array('quinnonagintillion'),
|
||||
291 => array('sexnonagintillion'),
|
||||
294 => array('septennonagintillion'),
|
||||
297 => array('octononagintillion'),
|
||||
300 => array('novemnonagintillion'),
|
||||
303 => array('centillion'),
|
||||
309 => array('duocentillion'),
|
||||
312 => array('trecentillion'),
|
||||
366 => array('primo-vigesimo-centillion'),
|
||||
402 => array('trestrigintacentillion'),
|
||||
603 => array('ducentillion'),
|
||||
624 => array('septenducentillion'),
|
||||
// bug on a earthlink page: 903 => array('trecentillion'),
|
||||
2421 => array('sexoctingentillion'),
|
||||
3003 => array('millillion'),
|
||||
3000003 => array('milli-millillion')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'zero', 'one', 'two', 'three', 'four',
|
||||
'five', 'six', 'seven', 'eight', 'nine'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The currency names (based on the below links,
|
||||
* informations from central bank websites and on encyclopedias)
|
||||
*
|
||||
* @var array
|
||||
* @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
|
||||
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
|
||||
* @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
|
||||
* @access private
|
||||
*/
|
||||
var $_currency_names = array(
|
||||
'ALL' => array(array('lek'), array('qindarka')),
|
||||
'AUD' => array(array('Australian dollar'), array('cent')),
|
||||
'BAM' => array(array('convertible marka'), array('fenig')),
|
||||
'BGN' => array(array('lev'), array('stotinka')),
|
||||
'BRL' => array(array('real'), array('centavos')),
|
||||
'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
|
||||
'CAD' => array(array('Canadian dollar'), array('cent')),
|
||||
'CHF' => array(array('Swiss franc'), array('rapp')),
|
||||
'CYP' => array(array('Cypriot pound'), array('cent')),
|
||||
'CZK' => array(array('Czech koruna'), array('halerz')),
|
||||
'DKK' => array(array('Danish krone'), array('ore')),
|
||||
'EEK' => array(array('kroon'), array('senti')),
|
||||
'EUR' => array(array('euro'), array('euro-cent')),
|
||||
'GBP' => array(array('pound', 'pounds'), array('pence')),
|
||||
'HKD' => array(array('Hong Kong dollar'), array('cent')),
|
||||
'HRK' => array(array('Croatian kuna'), array('lipa')),
|
||||
'HUF' => array(array('forint'), array('filler')),
|
||||
'ISK' => array(array('Icelandic kr<6B>na'), array('aurar')),
|
||||
'JPY' => array(array('yen'), array('sen')),
|
||||
'LTL' => array(array('litas'), array('cent')),
|
||||
'LVL' => array(array('lat'), array('sentim')),
|
||||
'MKD' => array(array('Macedonian dinar'), array('deni')),
|
||||
'MTL' => array(array('Maltese lira'), array('centym')),
|
||||
'NOK' => array(array('Norwegian krone'), array('oere')),
|
||||
'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
|
||||
'ROL' => array(array('Romanian leu'), array('bani')),
|
||||
'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
|
||||
'SEK' => array(array('Swedish krona'), array('oere')),
|
||||
'SIT' => array(array('Tolar'), array('stotinia')),
|
||||
'SKK' => array(array('Slovak koruna'), array()),
|
||||
'TRL' => array(array('lira'), array('kuru<72>')),
|
||||
'UAH' => array(array('hryvna'), array('cent')),
|
||||
'USD' => array(array('dollar'), array('cent')),
|
||||
'YUM' => array(array('dinars'), array('para')),
|
||||
'ZAR' => array(array('rand'), array('cent')),
|
||||
'MXN' => array(array('Mexican Peso'), array('cent'))
|
||||
);
|
||||
|
||||
/**
|
||||
* The default currency name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $def_currency = 'USD'; // Polish zloty
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in American English language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
|
||||
|
||||
// in English only - add ' and' for [1-9]01..[1-9]99
|
||||
// (also for 1001..1099, 10001..10099 but it is harder)
|
||||
// for now it is switched off, maybe some language purists
|
||||
// can force me to enable it, or to remove it completely
|
||||
// if (($t + $d) > 0)
|
||||
// $ret .= $this->_sep . 'and';
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 7:
|
||||
case 6:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'ty';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighty';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifty';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'forty';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirty';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twenty';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'ten';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'eleven';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'twelve';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'thirteen';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'teen';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'fifteen';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'eighteen';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
// add minus sign between [2-9] and digit
|
||||
if ($t > 1) {
|
||||
$ret .= '-' . $this->_digits[$d];
|
||||
} else {
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
// {{{ toCurrency()
|
||||
|
||||
/**
|
||||
* Converts a currency value to its word representation
|
||||
* (with monetary units) in English language
|
||||
*
|
||||
* @param integer $int_curr An international currency symbol
|
||||
* as defined by the ISO 4217 standard (three characters)
|
||||
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
||||
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
||||
* Optional. Defaults to false.
|
||||
*
|
||||
* @return string The corresponding word representation for the currency
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since Numbers_Words 0.4
|
||||
*/
|
||||
function toCurrencyWords($int_curr, $decimal, $fraction = false) {
|
||||
$int_curr = strtoupper($int_curr);
|
||||
if (!isset($this->_currency_names[$int_curr])) {
|
||||
$int_curr = $this->def_currency;
|
||||
}
|
||||
$curr_names = $this->_currency_names[$int_curr];
|
||||
$ret = trim($this->toWords($decimal));
|
||||
$lev = ($decimal == 1) ? 0 : 1;
|
||||
if ($lev > 0) {
|
||||
if (count($curr_names[0]) > 1) {
|
||||
$ret .= $this->_sep . $curr_names[0][$lev];
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[0][0] . 's';
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[0][0];
|
||||
}
|
||||
|
||||
if ($fraction !== false) {
|
||||
$ret .= $this->_sep . trim($this->toWords($fraction));
|
||||
$lev = ($fraction == 1) ? 0 : 1;
|
||||
if ($lev > 0) {
|
||||
if (count($curr_names[1]) > 1) {
|
||||
$ret .= $this->_sep . $curr_names[1][$lev];
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[1][0] . 's';
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[1][0];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
343
thirdparty/pear/Numbers/Words/lang.es.php
vendored
343
thirdparty/pear/Numbers/Words/lang.es.php
vendored
@@ -1,343 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Xavier Noguer |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Spanish (Castellano).
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Spanish (Castellano).
|
||||
*
|
||||
* @author Xavier Noguer
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Spanish (Castellano).
|
||||
* It supports up to decallones (10^6).
|
||||
* It doesn't support spanish tonic accents (acentos).
|
||||
*
|
||||
* @author Xavier Noguer
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_es extends Numbers_Words
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'es';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Spanish';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Espa<70>ol';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'menos';
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array('',''),
|
||||
3 => array('mil','mil'),
|
||||
6 => array('mill<6C>n','millones'),
|
||||
12 => array('bill<6C>n','billones'),
|
||||
18 => array('tril<69>n','trillones'),
|
||||
24 => array('cuatrill<6C>n','cuatrillones'),
|
||||
30 => array('quintill<6C>n','quintillones'),
|
||||
36 => array('sextill<6C>n','sextillones'),
|
||||
42 => array('septill<6C>n','septillones'),
|
||||
48 => array('octall<6C>n','octallones'),
|
||||
54 => array('nonall<6C>n','nonallones'),
|
||||
60 => array('decall<6C>n','decallones'),
|
||||
);
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'cero', 'uno', 'dos', 'tres', 'cuatro',
|
||||
'cinco', 'seis', 'siete', 'ocho', 'nueve'
|
||||
);
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Spanish (Castellano).
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that should be converted to a words representation
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* For example toWords(12,3) should give "doce mil".
|
||||
* Optional, defaults to 0.
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Xavier Noguer
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0)
|
||||
{
|
||||
// The return string;
|
||||
$ret = '';
|
||||
|
||||
// add a the word for the minus sign if necessary
|
||||
if (substr($num, 0, 1) == '-')
|
||||
{
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
|
||||
// strip excessive zero signs
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 6)
|
||||
{
|
||||
$current_power = 6;
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$power]))
|
||||
{
|
||||
// convert the number above the first 6 digits
|
||||
// with it's corresponding $power.
|
||||
$snum = substr($num, 0, -6);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$ret .= $this->toWords($snum, $power + 6);
|
||||
}
|
||||
}
|
||||
$num = substr($num, -6);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
elseif ($num == 0 || $num == '') {
|
||||
return(' '.$this->_digits[0]);
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
else {
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
|
||||
// See if we need "thousands"
|
||||
$thousands = floor($num / 1000);
|
||||
if ($thousands == 1) {
|
||||
$ret .= $this->_sep . 'mil';
|
||||
}
|
||||
elseif ($thousands > 1) {
|
||||
$ret .= $this->toWords($thousands, 3);
|
||||
}
|
||||
|
||||
// values for digits, tens and hundreds
|
||||
$h = floor(($num / 100) % 10);
|
||||
$t = floor(($num / 10) % 10);
|
||||
$d = floor($num % 10);
|
||||
|
||||
// cientos: doscientos, trescientos, etc...
|
||||
switch ($h)
|
||||
{
|
||||
case 1:
|
||||
if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
|
||||
$ret .= $this->_sep . 'cien';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'ciento';
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
$ret .= $this->_sep . $this->_digits[$h] . 'cientos';
|
||||
break;
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'quinientos';
|
||||
break;
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'setecientos';
|
||||
break;
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'novecientos';
|
||||
break;
|
||||
}
|
||||
|
||||
// decenas: veinte, treinta, etc...
|
||||
switch ($t)
|
||||
{
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'noventa';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'ochenta';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'setenta';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sesenta';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'cincuenta';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'cuarenta';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'treinta';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if ($d == 0) {
|
||||
$ret .= $this->_sep . 'veinte';
|
||||
}
|
||||
else {
|
||||
if (($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep . 'veinti<74>n';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'veinti' . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d)
|
||||
{
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'diez';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'once';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'doce';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trece';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'catorce';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'quince';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'dieci' . $this->_digits[$d];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// add digits only if it is a multiple of 10 and not 1x or 2x
|
||||
if (($t != 1) and ($t != 2) and ($d > 0))
|
||||
{
|
||||
if($t != 0) // don't add 'y' for numbers below 10
|
||||
{
|
||||
// use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.' y un';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.'y '.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.'un';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0)
|
||||
{
|
||||
if (isset($this->_exponent[$power])) {
|
||||
$lev = $this->_exponent[$power];
|
||||
}
|
||||
|
||||
if (!isset($lev) || !is_array($lev)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if it's only one use the singular suffix
|
||||
if (($d == 1) and ($t == 0) and ($h == 0)) {
|
||||
$suffix = $lev[0];
|
||||
}
|
||||
else {
|
||||
$suffix = $lev[1];
|
||||
}
|
||||
if ($num != 0) {
|
||||
$ret .= $this->_sep . $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
470
thirdparty/pear/Numbers/Words/lang.es_AR.php
vendored
470
thirdparty/pear/Numbers/Words/lang.es_AR.php
vendored
@@ -1,470 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Martin Marrese <mmare@mecon.gov.ar> |
|
||||
// | Based On: lang_es.php - Xavier Noguer |
|
||||
// +----------------------------------------------------------------------+
|
||||
// $Id: lang.es_AR.php 503 2004-02-23 19:25:42Z mmarre $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Argentinian Spanish
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Argentinian Spanish.
|
||||
*
|
||||
* @author Martin Marrese
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Argentinian Spanish.
|
||||
* It supports up to decallones (10^6).
|
||||
* It doesn't support spanish tonic accents (acentos).
|
||||
*
|
||||
* @author Martin Marrese
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_es_AR extends Numbers_Words
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'es_AR';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Spanish';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Espa<70>ol';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'menos';
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array('',''),
|
||||
3 => array('mil','mil'),
|
||||
6 => array('mill<6C>n','millones'),
|
||||
12 => array('bill<6C>n','billones'),
|
||||
18 => array('tril<69>n','trillones'),
|
||||
24 => array('cuatrill<6C>n','cuatrillones'),
|
||||
30 => array('quintill<6C>n','quintillones'),
|
||||
36 => array('sextill<6C>n','sextillones'),
|
||||
42 => array('septill<6C>n','septillones'),
|
||||
48 => array('octall<6C>n','octallones'),
|
||||
54 => array('nonall<6C>n','nonallones'),
|
||||
60 => array('decall<6C>n','decallones'),
|
||||
);
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'cero', 'uno', 'dos', 'tres', 'cuatro',
|
||||
'cinco', 'seis', 'siete', 'ocho', 'nueve'
|
||||
);
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The currency names (based on the below links,
|
||||
* informations from central bank websites and on encyclopedias)
|
||||
*
|
||||
* @var array
|
||||
* @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
|
||||
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
|
||||
* @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
|
||||
* @access private
|
||||
*/
|
||||
var $_currency_names = array(
|
||||
'ALL' => array(array('lek'), array('qindarka')),
|
||||
'AUD' => array(array('Australian dollar'), array('cent')),
|
||||
'ARS' => array(array('Peso'), array ('centavo')),
|
||||
'BAM' => array(array('convertible marka'), array('fenig')),
|
||||
'BGN' => array(array('lev'), array('stotinka')),
|
||||
'BRL' => array(array('real'), array('centavos')),
|
||||
'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
|
||||
'CAD' => array(array('Canadian dollar'), array('cent')),
|
||||
'CHF' => array(array('Swiss franc'), array('rapp')),
|
||||
'CYP' => array(array('Cypriot pound'), array('cent')),
|
||||
'CZK' => array(array('Czech koruna'), array('halerz')),
|
||||
'DKK' => array(array('Danish krone'), array('ore')),
|
||||
'EEK' => array(array('kroon'), array('senti')),
|
||||
'EUR' => array(array('euro'), array('euro-cent')),
|
||||
'GBP' => array(array('pound', 'pounds'), array('pence')),
|
||||
'HKD' => array(array('Hong Kong dollar'), array('cent')),
|
||||
'HRK' => array(array('Croatian kuna'), array('lipa')),
|
||||
'HUF' => array(array('forint'), array('filler')),
|
||||
'ISK' => array(array('Icelandic kr<6B>na'), array('aurar')),
|
||||
'JPY' => array(array('yen'), array('sen')),
|
||||
'LTL' => array(array('litas'), array('cent')),
|
||||
'LVL' => array(array('lat'), array('sentim')),
|
||||
'MKD' => array(array('Macedonian dinar'), array('deni')),
|
||||
'MTL' => array(array('Maltese lira'), array('centym')),
|
||||
'NOK' => array(array('Norwegian krone'), array('oere')),
|
||||
'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
|
||||
'ROL' => array(array('Romanian leu'), array('bani')),
|
||||
'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
|
||||
'SEK' => array(array('Swedish krona'), array('oere')),
|
||||
'SIT' => array(array('Tolar'), array('stotinia')),
|
||||
'SKK' => array(array('Slovak koruna'), array()),
|
||||
'TRL' => array(array('lira'), array('kuru<72>')),
|
||||
'UAH' => array(array('hryvna'), array('cent')),
|
||||
'USD' => array(array('dolar', 'D<>LARES'), array('centavo')),
|
||||
'YUM' => array(array('dinars'), array('para')),
|
||||
'ZAR' => array(array('rand'), array('cent')),
|
||||
'MXN' => array(array('Peso Mexicano', 'Pesos Mexicanos'), array('centavo'))
|
||||
);
|
||||
|
||||
/**
|
||||
* The default currency name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $def_currency = 'ARS'; // Argentinian Peso
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Argentinian Spanish.
|
||||
*
|
||||
* @param float $num An float between -infinity and infinity inclusive :)
|
||||
* that should be converted to a words representation
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* For example toWords(12,3) should give "doce mil".
|
||||
* Optional, defaults to 0.
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Martin Marrese
|
||||
*/
|
||||
function toWords($num, $power = 0)
|
||||
{
|
||||
// The return string;
|
||||
$ret = '';
|
||||
|
||||
// add a the word for the minus sign if necessary
|
||||
if (substr($num, 0, 1) == '-')
|
||||
{
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
|
||||
// strip excessive zero signs
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
$num_tmp = split ('\.', $num);
|
||||
|
||||
$num = $num_tmp[0];
|
||||
$dec = (@$num_tmp[1]) ? $num_tmp[1] : '';
|
||||
|
||||
if (strlen($num) > 6)
|
||||
{
|
||||
$current_power = 6;
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$power]))
|
||||
{
|
||||
// convert the number above the first 6 digits
|
||||
// with it's corresponding $power.
|
||||
$snum = substr($num, 0, -6);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$ret .= $this->toWords($snum, $power + 6);
|
||||
}
|
||||
}
|
||||
$num = substr($num, -6);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
elseif ($num == 0 || $num == '') {
|
||||
return(' '.$this->_digits[0]);
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
else {
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
|
||||
// See if we need "thousands"
|
||||
$thousands = floor($num / 1000);
|
||||
if ($thousands == 1) {
|
||||
$ret .= $this->_sep . 'mil';
|
||||
}
|
||||
elseif ($thousands > 1) {
|
||||
$ret .= $this->toWords($thousands, 3);
|
||||
}
|
||||
|
||||
// values for digits, tens and hundreds
|
||||
$h = floor(($num / 100) % 10);
|
||||
$t = floor(($num / 10) % 10);
|
||||
$d = floor($num % 10);
|
||||
|
||||
// cientos: doscientos, trescientos, etc...
|
||||
switch ($h)
|
||||
{
|
||||
case 1:
|
||||
if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
|
||||
$ret .= $this->_sep . 'cien';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'ciento';
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
$ret .= $this->_sep . $this->_digits[$h] . 'cientos';
|
||||
break;
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'quinientos';
|
||||
break;
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'setecientos';
|
||||
break;
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'novecientos';
|
||||
break;
|
||||
}
|
||||
|
||||
// decenas: veinte, treinta, etc...
|
||||
switch ($t)
|
||||
{
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'noventa';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'ochenta';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'setenta';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sesenta';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'cincuenta';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'cuarenta';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'treinta';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if ($d == 0) {
|
||||
$ret .= $this->_sep . 'veinte';
|
||||
}
|
||||
else {
|
||||
if (($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep . 'veinti<74>n';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'veinti' . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d)
|
||||
{
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'diez';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'once';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'doce';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trece';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'catorce';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'quince';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
case 7:
|
||||
case 9:
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'dieci' . $this->_digits[$d];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// add digits only if it is a multiple of 10 and not 1x or 2x
|
||||
if (($t != 1) and ($t != 2) and ($d > 0))
|
||||
{
|
||||
if($t != 0) // don't add 'y' for numbers below 10
|
||||
{
|
||||
// use 'un' instead of 'uno' when there is a suffix ('mil', 'millones', etc...)
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.' y un';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.'y '.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.'un';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0)
|
||||
{
|
||||
if (isset($this->_exponent[$power])) {
|
||||
$lev = $this->_exponent[$power];
|
||||
}
|
||||
|
||||
if (!isset($lev) || !is_array($lev)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if it's only one use the singular suffix
|
||||
if (($d == 1) and ($t == 0) and ($h == 0)) {
|
||||
$suffix = $lev[0];
|
||||
}
|
||||
else {
|
||||
$suffix = $lev[1];
|
||||
}
|
||||
if ($num != 0) {
|
||||
$ret .= $this->_sep . $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
if ($dec) {
|
||||
$dec = $this->toWords(trim($dec));
|
||||
$ret.= ' con ' . trim ($dec);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ toCurrency()
|
||||
|
||||
/**
|
||||
* Converts a currency value to its word representation
|
||||
* (with monetary units) in Agentinian Spanish language
|
||||
*
|
||||
* @param integer $int_curr An international currency symbol
|
||||
* as defined by the ISO 4217 standard (three characters)
|
||||
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
||||
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
||||
* Optional. Defaults to false.
|
||||
*
|
||||
* @return string The corresponding word representation for the currency
|
||||
*
|
||||
* @access public
|
||||
* @author Martin Marrese
|
||||
*/
|
||||
function toCurrencyWords($int_curr, $decimal, $fraction = false) {
|
||||
$int_curr = strtoupper($int_curr);
|
||||
if (!isset($this->_currency_names[$int_curr])) {
|
||||
$int_curr = $this->def_currency;
|
||||
}
|
||||
$curr_names = $this->_currency_names[$int_curr];
|
||||
$ret .= $this->_sep . trim($this->toWords($decimal));
|
||||
$lev = ($decimal == 1) ? 0 : 1;
|
||||
|
||||
if ($lev > 0) {
|
||||
if (count($curr_names[0]) > 1) {
|
||||
$ret .= $this->_sep . $curr_names[0][$lev];
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[0][0] . 's';
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[0][0];
|
||||
}
|
||||
|
||||
|
||||
if ($fraction !== false) {
|
||||
$ret .= $this->_sep .'con'. $this->_sep . trim($this->toWords($fraction));
|
||||
$lev = ($fraction == 1) ? 0 : 1;
|
||||
if ($lev > 0) {
|
||||
if (count($curr_names[1]) > 1) {
|
||||
$ret .= $this->_sep . $curr_names[1][$lev];
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[1][0] . 's';
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_sep . $curr_names[1][0];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
439
thirdparty/pear/Numbers/Words/lang.fr.php
vendored
439
thirdparty/pear/Numbers/Words/lang.fr.php
vendored
@@ -1,439 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Kouber Saparev <kouber@saparev.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into French.
|
||||
*
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_fr extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'fr';
|
||||
|
||||
/**
|
||||
* Language name in English.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'French';
|
||||
|
||||
/**
|
||||
* Native language name.
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Fran<61>ais';
|
||||
|
||||
/**
|
||||
* The words for some numbers.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_misc_numbers = array(
|
||||
10=>'dix', // 10
|
||||
'onze', // 11
|
||||
'douze', // 12
|
||||
'treize', // 13
|
||||
'quatorze', // 14
|
||||
'quinze', // 15
|
||||
'seize', // 16
|
||||
20=>'vingt', // 20
|
||||
30=>'trente', // 30
|
||||
40=>'quarante', // 40
|
||||
50=>'cinquante',// 50
|
||||
60=>'soixante', // 60
|
||||
100=>'cent' // 100
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* The words for digits (except zero).
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(1=>"un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf");
|
||||
|
||||
/**
|
||||
* The word for zero.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_zero = 'z<>ro';
|
||||
|
||||
/**
|
||||
* The word for infinity.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_infinity = 'infini';
|
||||
|
||||
/**
|
||||
* The word for the "and" language construct.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_and = 'et';
|
||||
|
||||
/**
|
||||
* The word separator.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The dash liaison.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_dash = '-';
|
||||
|
||||
/**
|
||||
* The word for the minus sign.
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'moins'; // minus sign
|
||||
|
||||
/**
|
||||
* The plural suffix (except for hundred).
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_plural = 's'; // plural suffix
|
||||
|
||||
/**
|
||||
* The suffixes for exponents (singular).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => '',
|
||||
3 => 'mille',
|
||||
6 => 'million',
|
||||
9 => 'milliard',
|
||||
12 => 'trillion',
|
||||
15 => 'quadrillion',
|
||||
18 => 'quintillion',
|
||||
21 => 'sextillion',
|
||||
24 => 'septillion',
|
||||
27 => 'octillion',
|
||||
30 => 'nonillion',
|
||||
33 => 'decillion',
|
||||
36 => 'undecillion',
|
||||
39 => 'duodecillion',
|
||||
42 => 'tredecillion',
|
||||
45 => 'quattuordecillion',
|
||||
48 => 'quindecillion',
|
||||
51 => 'sexdecillion',
|
||||
54 => 'septendecillion',
|
||||
57 => 'octodecillion',
|
||||
60 => 'novemdecillion',
|
||||
63 => 'vigintillion',
|
||||
66 => 'unvigintillion',
|
||||
69 => 'duovigintillion',
|
||||
72 => 'trevigintillion',
|
||||
75 => 'quattuorvigintillion',
|
||||
78 => 'quinvigintillion',
|
||||
81 => 'sexvigintillion',
|
||||
84 => 'septenvigintillion',
|
||||
87 => 'octovigintillion',
|
||||
90 => 'novemvigintillion',
|
||||
93 => 'trigintillion',
|
||||
96 => 'untrigintillion',
|
||||
99 => 'duotrigintillion',
|
||||
102 => 'trestrigintillion',
|
||||
105 => 'quattuortrigintillion',
|
||||
108 => 'quintrigintillion',
|
||||
111 => 'sextrigintillion',
|
||||
114 => 'septentrigintillion',
|
||||
117 => 'octotrigintillion',
|
||||
120 => 'novemtrigintillion',
|
||||
123 => 'quadragintillion',
|
||||
126 => 'unquadragintillion',
|
||||
129 => 'duoquadragintillion',
|
||||
132 => 'trequadragintillion',
|
||||
135 => 'quattuorquadragintillion',
|
||||
138 => 'quinquadragintillion',
|
||||
141 => 'sexquadragintillion',
|
||||
144 => 'septenquadragintillion',
|
||||
147 => 'octoquadragintillion',
|
||||
150 => 'novemquadragintillion',
|
||||
153 => 'quinquagintillion',
|
||||
156 => 'unquinquagintillion',
|
||||
159 => 'duoquinquagintillion',
|
||||
162 => 'trequinquagintillion',
|
||||
165 => 'quattuorquinquagintillion',
|
||||
168 => 'quinquinquagintillion',
|
||||
171 => 'sexquinquagintillion',
|
||||
174 => 'septenquinquagintillion',
|
||||
177 => 'octoquinquagintillion',
|
||||
180 => 'novemquinquagintillion',
|
||||
183 => 'sexagintillion',
|
||||
186 => 'unsexagintillion',
|
||||
189 => 'duosexagintillion',
|
||||
192 => 'tresexagintillion',
|
||||
195 => 'quattuorsexagintillion',
|
||||
198 => 'quinsexagintillion',
|
||||
201 => 'sexsexagintillion',
|
||||
204 => 'septensexagintillion',
|
||||
207 => 'octosexagintillion',
|
||||
210 => 'novemsexagintillion',
|
||||
213 => 'septuagintillion',
|
||||
216 => 'unseptuagintillion',
|
||||
219 => 'duoseptuagintillion',
|
||||
222 => 'treseptuagintillion',
|
||||
225 => 'quattuorseptuagintillion',
|
||||
228 => 'quinseptuagintillion',
|
||||
231 => 'sexseptuagintillion',
|
||||
234 => 'septenseptuagintillion',
|
||||
237 => 'octoseptuagintillion',
|
||||
240 => 'novemseptuagintillion',
|
||||
243 => 'octogintillion',
|
||||
246 => 'unoctogintillion',
|
||||
249 => 'duooctogintillion',
|
||||
252 => 'treoctogintillion',
|
||||
255 => 'quattuoroctogintillion',
|
||||
258 => 'quinoctogintillion',
|
||||
261 => 'sexoctogintillion',
|
||||
264 => 'septoctogintillion',
|
||||
267 => 'octooctogintillion',
|
||||
270 => 'novemoctogintillion',
|
||||
273 => 'nonagintillion',
|
||||
276 => 'unnonagintillion',
|
||||
279 => 'duononagintillion',
|
||||
282 => 'trenonagintillion',
|
||||
285 => 'quattuornonagintillion',
|
||||
288 => 'quinnonagintillion',
|
||||
291 => 'sexnonagintillion',
|
||||
294 => 'septennonagintillion',
|
||||
297 => 'octononagintillion',
|
||||
300 => 'novemnonagintillion',
|
||||
303 => 'centillion'
|
||||
);
|
||||
// }}}
|
||||
|
||||
// {{{ _splitNumber()
|
||||
|
||||
/**
|
||||
* Split a number to groups of three-digit numbers.
|
||||
*
|
||||
* @param mixed $num An integer or its string representation
|
||||
* that need to be split
|
||||
*
|
||||
* @return array Groups of three-digit numbers.
|
||||
*
|
||||
* @access private
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
|
||||
function _splitNumber($num)
|
||||
{
|
||||
if (is_string($num)) {
|
||||
$ret = array();
|
||||
$strlen = strlen($num);
|
||||
$first = substr($num, 0, $strlen%3);
|
||||
preg_match_all('/\d{3}/', substr($num, $strlen%3, $strlen), $m);
|
||||
$ret =& $m[0];
|
||||
if ($first) array_unshift($ret, $first);
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _showDigitsGroup()
|
||||
|
||||
/**
|
||||
* Converts a three-digit number to its word representation
|
||||
* in French language.
|
||||
*
|
||||
* @param integer $num An integer between 1 and 999 inclusive.
|
||||
*
|
||||
* @param boolean $last A flag, that determines if it is the last group of digits -
|
||||
* this is used to accord the plural suffix of the "hundreds".
|
||||
* Example: 200 = "deux cents", but 200000 = "deux cent mille".
|
||||
*
|
||||
*
|
||||
* @return string The words for the given number.
|
||||
*
|
||||
* @access private
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
*/
|
||||
function _showDigitsGroup($num, $last = false)
|
||||
{
|
||||
$ret = '';
|
||||
|
||||
// extract the value of each digit from the three-digit number
|
||||
$e = $num%10; // ones
|
||||
$d = ($num-$e)%100/10; // tens
|
||||
$s = ($num-$d*10-$e)%1000/100; // hundreds
|
||||
|
||||
// process the "hundreds" digit.
|
||||
if ($s) {
|
||||
if ($s>1) {
|
||||
$ret .= $this->_digits[$s].$this->_sep.$this->_misc_numbers[100];
|
||||
if ($last && !$e && !$d) {
|
||||
$ret .= $this->_plural;
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_misc_numbers[100];
|
||||
}
|
||||
$ret .= $this->_sep;
|
||||
}
|
||||
|
||||
// process the "tens" digit, and optionally the "ones" digit.
|
||||
if ($d) {
|
||||
// in the case of 1, the "ones" digit also must be processed
|
||||
if ($d==1) {
|
||||
if ($e<=6) {
|
||||
$ret .= $this->_misc_numbers[10+$e];
|
||||
} else {
|
||||
$ret .= $this->_misc_numbers[10].'-'.$this->_digits[$e];
|
||||
}
|
||||
$e = 0;
|
||||
} elseif ($d>5) {
|
||||
if ($d<8) {
|
||||
$ret .= $this->_misc_numbers[60];
|
||||
$resto = $d*10+$e-60;
|
||||
if ($e==1) {
|
||||
$ret .= $this->_sep.$this->_and.$this->_sep;
|
||||
}
|
||||
elseif ($resto) {
|
||||
$ret .= $this->_dash;
|
||||
}
|
||||
|
||||
if ($resto) {
|
||||
$ret .= $this->_showDigitsGroup($resto);
|
||||
}
|
||||
$e = 0;
|
||||
} else {
|
||||
$ret .= $this->_digits[4].$this->_dash.$this->_misc_numbers[20];
|
||||
$resto = $d*10+$e-80;
|
||||
if ($resto) {
|
||||
$ret .= $this->_dash;
|
||||
$ret .= $this->_showDigitsGroup($resto);
|
||||
$e = 0;
|
||||
} else {
|
||||
$ret .= $this->_plural;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret .= $this->_misc_numbers[$d*10];
|
||||
}
|
||||
}
|
||||
|
||||
// process the "ones" digit
|
||||
if ($e) {
|
||||
if ($d) {
|
||||
if ($e==1) {
|
||||
$ret .= $this->_sep.$this->_and.$this->_sep;
|
||||
} else {
|
||||
$ret .= $this->_dash;
|
||||
}
|
||||
}
|
||||
$ret .= $this->_digits[$e];
|
||||
}
|
||||
|
||||
// strip excessive separators
|
||||
$ret = rtrim($ret, $this->_sep);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in French language.
|
||||
*
|
||||
* @param integer $num An integer (or its string representation) between 9.99*-10^302
|
||||
* and 9.99*10^302 (999 centillions) that need to be converted to words
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Kouber Saparev <kouber@saparev.com>
|
||||
*/
|
||||
function toWords($num = 0)
|
||||
{
|
||||
$ret = '';
|
||||
|
||||
// check if $num is a valid non-zero number
|
||||
if (!$num || preg_match('/^-?0+$/', $num) || !preg_match('/^-?\d+$/', $num)) return $this->_zero;
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_minus . $this->_sep;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// if the absolute value is greater than 9.99*10^302, return infinity
|
||||
if (strlen($num)>306) {
|
||||
return $ret . $this->_infinity;
|
||||
}
|
||||
|
||||
// strip excessive zero signs
|
||||
$num = ltrim($num, '0');
|
||||
|
||||
// split $num to groups of three-digit numbers
|
||||
$num_groups = $this->_splitNumber($num);
|
||||
|
||||
$sizeof_numgroups = count($num_groups);
|
||||
|
||||
foreach ($num_groups as $i=>$number) {
|
||||
// what is the corresponding exponent for the current group
|
||||
$pow = $sizeof_numgroups-$i;
|
||||
|
||||
// skip processment for empty groups
|
||||
if ($number!='000') {
|
||||
if ($number!=1 || $pow!=2) {
|
||||
$ret .= $this->_showDigitsGroup($number, $i+1==$sizeof_numgroups).$this->_sep;
|
||||
}
|
||||
$ret .= $this->_exponent[($pow-1)*3];
|
||||
if ($pow>2 && $number>1) {
|
||||
$ret .= $this->_plural;
|
||||
}
|
||||
$ret .= $this->_sep;
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($ret, $this->_sep);
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
277
thirdparty/pear/Numbers/Words/lang.id.php
vendored
277
thirdparty/pear/Numbers/Words/lang.id.php
vendored
@@ -1,277 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Ernas M. Jamil <ernasm@samba.co.id> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.en_GB.php,v 1.3 2002/11/26 10:33:35 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Indonesian language.
|
||||
//
|
||||
|
||||
require_once("PEAR.php");
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Indonesian.
|
||||
*
|
||||
* @author Ernas M. Jamil
|
||||
*/
|
||||
class Numbers_Words_id extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
*/
|
||||
var $locale = 'id';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
*/
|
||||
var $lang = 'Indonesia Language';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
*/
|
||||
var $lang_native = 'Bahasa Indonesia';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names partly based on:
|
||||
* http://www.users.dircon.co.uk/~shaunf/shaun/numbers/millions.htm
|
||||
* @var array
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('ribu'),
|
||||
6 => array('juta'),
|
||||
9 => array('milyar'),
|
||||
12 => array('trilyun'),
|
||||
24 => array('quadrillion'),
|
||||
30 => array('quintillion'),
|
||||
36 => array('sextillion'),
|
||||
42 => array('septillion'),
|
||||
48 => array('octillion'),
|
||||
54 => array('nonillion'),
|
||||
60 => array('decillion'),
|
||||
66 => array('undecillion'),
|
||||
72 => array('duodecillion'),
|
||||
78 => array('tredecillion'),
|
||||
84 => array('quattuordecillion'),
|
||||
90 => array('quindecillion'),
|
||||
96 => array('sexdecillion'),
|
||||
102 => array('septendecillion'),
|
||||
108 => array('octodecillion'),
|
||||
114 => array('novemdecillion'),
|
||||
120 => array('vigintillion'),
|
||||
192 => array('duotrigintillion'),
|
||||
600 => array('centillion')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'nol', 'satu', 'dua', 'tiga', 'empat',
|
||||
'lima', 'enam', 'tujuh', 'delapan', 'sembilan'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Indonesian language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Ernas M. Jamil
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 4) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = $th = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 4:
|
||||
$th = (int)substr($num,-4,1);
|
||||
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($th) {
|
||||
if ($th==1)
|
||||
$ret .= $this->_sep . 'seribu';
|
||||
else
|
||||
$ret .= $this->_sep . $this->_digits[$th] . $this->_sep . 'ribu';
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
if ($h==1)
|
||||
$ret .= $this->_sep . 'seratus';
|
||||
else
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'ratus';
|
||||
|
||||
// in English only - add ' and' for [1-9]01..[1-9]99
|
||||
// (also for 1001..1099, 10001..10099 but it is harder)
|
||||
// for now it is switched off, maybe some language purists
|
||||
// can force me to enable it, or to remove it completely
|
||||
// if (($t + $d) > 0)
|
||||
// $ret .= $this->_sep . 'and';
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
case 6:
|
||||
case 5:
|
||||
case 4:
|
||||
case 3:
|
||||
case 2:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . ' puluh';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'sepuluh';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'sebelas';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . ' belas';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
// add minus sign between [2-9] and digit
|
||||
if ($t > 1) {
|
||||
$ret .= ' ' . $this->_digits[$d];
|
||||
} else {
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
348
thirdparty/pear/Numbers/Words/lang.it_IT.php
vendored
348
thirdparty/pear/Numbers/Words/lang.it_IT.php
vendored
@@ -1,348 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Filippo Beltramini, Davide Caironi |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Italian.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Italian.
|
||||
*
|
||||
* @author Filippo Beltramini <phil@esight.it>
|
||||
* @author Davide Caironi <cairo@esight.it>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Italian.
|
||||
* It supports up to quadrilions
|
||||
*
|
||||
* @author Filippo Beltramini <phil@esight.it>
|
||||
* @author Davide Caironi <cairo@esight.it>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_it_IT extends Numbers_Words
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'it_IT';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Italian';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Italiano';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'meno ';
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array('',''),
|
||||
3 => array('mille','mila'),
|
||||
6 => array('milione','miloni'),
|
||||
12 => array('miliardo','miliardi'),
|
||||
18 => array('trillone','trilloni'),
|
||||
24 => array('quadrilione','quadrilioni'),
|
||||
);
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'zero', 'uno', 'due', 'tre', 'quattro',
|
||||
'cinque', 'sei', 'sette', 'otto', 'nove'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = '';
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in italiano.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that should be converted to a words representation
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* For example toWords(12,3) should give "doce mil".
|
||||
* Optional, defaults to 0.
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Filippo Beltramini
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0)
|
||||
{
|
||||
// The return string;
|
||||
$ret = '';
|
||||
|
||||
// add a the word for the minus sign if necessary
|
||||
if (substr($num, 0, 1) == '-')
|
||||
{
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
|
||||
// strip excessive zero signs
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 6)
|
||||
{
|
||||
$current_power = 6;
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$power]))
|
||||
{
|
||||
// convert the number above the first 6 digits
|
||||
// with it's corresponding $power.
|
||||
$snum = substr($num, 0, -6);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$ret .= $this->toWords($snum, $power + 6);
|
||||
}
|
||||
}
|
||||
$num = substr($num, -6);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
elseif ($num == 0 || $num == '') {
|
||||
return(' '.$this->_digits[0].' ');
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
else {
|
||||
$current_power = strlen($num);
|
||||
}
|
||||
|
||||
// See if we need "thousands"
|
||||
$thousands = floor($num / 1000);
|
||||
if ($thousands == 1) {
|
||||
$ret .= $this->_sep . 'mille' . $this->_sep;
|
||||
}
|
||||
elseif ($thousands > 1) {
|
||||
$ret .= $this->toWords($thousands, 3) . $this->_sep;//. 'mil' . $this->_sep;
|
||||
}
|
||||
|
||||
// values for digits, tens and hundreds
|
||||
$h = floor(($num / 100) % 10);
|
||||
$t = floor(($num / 10) % 10);
|
||||
$d = floor($num % 10);
|
||||
|
||||
// centinaia: duecento, trecento, etc...
|
||||
switch ($h)
|
||||
{
|
||||
case 1:
|
||||
if (($d == 0) and ($t == 0)) { // is it's '100' use 'cien'
|
||||
$ret .= $this->_sep . 'cento';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'cento';
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
case 8:
|
||||
$ret .= $this->_sep . $this->_digits[$h] . 'cento';
|
||||
break;
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'cinquecento';
|
||||
break;
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'settecento';
|
||||
break;
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'novecento';
|
||||
break;
|
||||
}
|
||||
|
||||
// decine: venti trenta, etc...
|
||||
switch ($t)
|
||||
{
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'novanta';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'ottanta';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'settanta';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sessanta';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'cinquanta';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'quaranta';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trenta';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if ($d == 0) {
|
||||
$ret .= $this->_sep . 'venti';
|
||||
}
|
||||
else {
|
||||
if (($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep . 'ventuno';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep . 'venti' . $this->_digits[$d];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d)
|
||||
{
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'dieci';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'undici';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'dodici';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'tredici';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'quattordici';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'quindici';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sedici';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'diciassette';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'diciotto';
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'diciannove';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// add digits only if it is a multiple of 10 and not 1x or 2x
|
||||
if (($t != 1) and ($t != 2) and ($d > 0))
|
||||
{
|
||||
if($t != 0) // don't add 'e' for numbers below 10
|
||||
{
|
||||
// use 'un' instead of 'uno' when there is a suffix ('mila', 'milloni', etc...)
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.' e un';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.''.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(($power > 0) and ($d == 1)) {
|
||||
$ret .= $this->_sep.'un ';
|
||||
}
|
||||
else {
|
||||
$ret .= $this->_sep.$this->_digits[$d];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($power > 0)
|
||||
{
|
||||
if (isset($this->_exponent[$power])) {
|
||||
$lev = $this->_exponent[$power];
|
||||
}
|
||||
|
||||
if (!isset($lev) || !is_array($lev)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if it's only one use the singular suffix
|
||||
if (($d == 1) and ($t == 0) and ($h == 0)) {
|
||||
$suffix = $lev[0];
|
||||
}
|
||||
else {
|
||||
$suffix = $lev[1];
|
||||
}
|
||||
if ($num != 0) {
|
||||
$ret .= $this->_sep . $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
310
thirdparty/pear/Numbers/Words/lang.lt.php
vendored
310
thirdparty/pear/Numbers/Words/lang.lt.php
vendored
@@ -1,310 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Laurynas Butkus |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Lithuanian language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Lithuanian.
|
||||
*
|
||||
* @author Laurynas Butkus
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Lithuanian.
|
||||
*
|
||||
* @author Laurynas Butkus
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_lt extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'lt';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Lithuanian';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'lietuvi<76>kai';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('t<>kstantis','t<>kstan<61>iai','t<>kstan<61>i<EFBFBD>'),
|
||||
6 => array('milijonas','milijonai','milijon<6F>'),
|
||||
9 => array('bilijonas','bilijonai','bilijon<6F>'),
|
||||
12 => array('trilijonas','trilijonai','trilijon<6F>'),
|
||||
15 => array('kvadrilijonas','kvadrilijonai','kvadrilijon<6F>'),
|
||||
18 => array('kvintilijonas','kvintilijonai','kvintilijon<6F>')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'nulis', 'vienas', 'du', 'trys', 'keturi',
|
||||
'penki', '<27>e<EFBFBD>i', 'septyni', 'a<>tuoni', 'devyni'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The default currency name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $def_currency = 'LTL';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Lithuanian language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Laurynas Butkus <lauris@night.lt>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $h > 1 )
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . '<27>imtai';
|
||||
elseif ( $h )
|
||||
$ret .= $this->_sep . '<27>imtas';
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'devyniasde<64>imt';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'a<>tuoniasde<64>imt';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'septyniasde<64>imt';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . '<27>e<EFBFBD>iasde<64>imt';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'penkiasde<64>imt';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'keturiasde<64>imt';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trisde<64>imt';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'dvide<64>imt';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'de<64>imt';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'vienuolika';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'dvylika';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trylika';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'keturiolika';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'penkiolika';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . '<27>e<EFBFBD>iolika';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'septyniolika';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'a<>tuoniolika';
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'devyniolika';
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
if ( $d > 1 || !$power || $t )
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
//echo " $t $d <br>";
|
||||
|
||||
if ( $t == 1 || ( $t > 0 && $d == 0 ) )
|
||||
$ret .= $this->_sep . $lev[2];
|
||||
elseif ( $d > 1 )
|
||||
$ret .= $this->_sep . $lev[1];
|
||||
else
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
513
thirdparty/pear/Numbers/Words/lang.pl.php
vendored
513
thirdparty/pear/Numbers/Words/lang.pl.php
vendored
@@ -1,513 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.pl.php,v 1.9 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Polish.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Polish.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Polish.
|
||||
*
|
||||
* @author Piotr Klaban
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_pl extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'pl';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Polish';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'polski';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* Names based on:
|
||||
* mathematical tables, my memory, and also:
|
||||
* http://ux1.math.us.edu.pl/~szyjewski/FAQ/liczby/iony.htm
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
// pot<6F>ga dziesi<73>tki => liczba pojedyncza, podw<64>jna, mnoga
|
||||
0 => array('','',''),
|
||||
3 => array('tysi<73>c','tysi<73>ce','tysi<73>cy'),
|
||||
6 => array('milion','miliony','milion<6F>w'),
|
||||
9 => array('miliard','miliardy','miliard<72>w'),
|
||||
12 => array('bilion','biliony','bilion<6F>w'),
|
||||
15 => array('biliard','biliardy','biliard<72>w'),
|
||||
18 => array('trylion','tryliony','trylion<6F>w'),
|
||||
21 => array('tryliard','tryliardy','tryliard<72>w'),
|
||||
24 => array('kwadrylion','kwadryliony','kwadrylion<6F>w'),
|
||||
27 => array('kwadryliard','kwadryliardy','kwadryliard<72>w'),
|
||||
30 => array('kwintylion','kwintyliony','kwintylion<6F>w'),
|
||||
33 => array('kwintyliiard','kwintyliardy','kwintyliard<72>w'),
|
||||
36 => array('sekstylion','sekstyliony','sekstylion<6F>w'),
|
||||
39 => array('sekstyliard','sekstyliardy','sekstyliard<72>w'),
|
||||
42 => array('septylion','septyliony','septylion<6F>w'),
|
||||
45 => array('septyliard','septyliardy','septyliard<72>w'),
|
||||
48 => array('oktylion','oktyliony','oktylion<6F>w'),
|
||||
51 => array('oktyliard','oktyliardy','oktyliard<72>w'),
|
||||
54 => array('nonylion','nonyliony','nonylion<6F>w'),
|
||||
57 => array('nonyliard','nonyliardy','nonyliard<72>w'),
|
||||
60 => array('decylion','decyliony','decylion<6F>w'),
|
||||
63 => array('decyliard','decyliardy','decyliard<72>w'),
|
||||
100 => array('centylion','centyliony','centylion<6F>w'),
|
||||
103 => array('centyliard','centyliardy','centyliard<72>w'),
|
||||
120 => array('wicylion','wicylion','wicylion'),
|
||||
123 => array('wicyliard','wicyliardy','wicyliard<72>w'),
|
||||
180 => array('trycylion','trycylion','trycylion'),
|
||||
183 => array('trycyliard','trycyliardy','trycyliard<72>w'),
|
||||
240 => array('kwadragilion','kwadragilion','kwadragilion'),
|
||||
243 => array('kwadragiliard','kwadragiliardy','kwadragiliard<72>w'),
|
||||
300 => array('kwinkwagilion','kwinkwagilion','kwinkwagilion'),
|
||||
303 => array('kwinkwagiliard','kwinkwagiliardy','kwinkwagiliard<72>w'),
|
||||
360 => array('seskwilion','seskwilion','seskwilion'),
|
||||
363 => array('seskwiliard','seskwiliardy','seskwiliard<72>w'),
|
||||
420 => array('septagilion','septagilion','septagilion'),
|
||||
423 => array('septagiliard','septagiliardy','septagiliard<72>w'),
|
||||
480 => array('oktogilion','oktogilion','oktogilion'),
|
||||
483 => array('oktogiliard','oktogiliardy','oktogiliard<72>w'),
|
||||
540 => array('nonagilion','nonagilion','nonagilion'),
|
||||
543 => array('nonagiliard','nonagiliardy','nonagiliard<72>w'),
|
||||
600 => array('centylion','centyliony','centylion<6F>w'),
|
||||
603 => array('centyliard','centyliardy','centyliard<72>w'),
|
||||
6000018 => array('milinilitrylion','milinilitryliony','milinilitrylion<6F>w')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'zero', 'jeden', 'dwa', 'trzy', 'cztery',
|
||||
'pi<70><69>', 'sze<7A><65>', 'siedem', 'osiem', 'dziewi<77><69>'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The currency names (based on the below links,
|
||||
* informations from central bank websites and on encyclopedias)
|
||||
*
|
||||
* @var array
|
||||
* @link http://www.xe.com/iso4217.htm Currency codes
|
||||
* @link http://www.republika.pl/geographia/peuropy.htm Europe review
|
||||
* @link http://pieniadz.hoga.pl/waluty_objasnienia.asp Currency service
|
||||
* @access private
|
||||
*/
|
||||
var $_currency_names = array(
|
||||
'ALL' => array(array('lek','leki','lek<65>w'), array('quindarka','quindarki','quindarek')),
|
||||
'AUD' => array(array('dolar australijski', 'dolary australijskie', 'dolar<61>w australijskich'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'BAM' => array(array('marka','marki','marek'), array('fenig','fenigi','fenig<69>w')),
|
||||
'BGN' => array(array('lew','lewy','lew'), array('stotinka','stotinki','stotinek')),
|
||||
'BRL' => array(array('real','reale','real<61>w'), array('centavos','centavos','centavos')),
|
||||
'BYR' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
|
||||
'CAD' => array(array('dolar kanadyjski', 'dolary kanadyjskie', 'dolar<61>w kanadyjskich'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'CHF' => array(array('frank szwajcarski','franki szwajcarskie','frank<6E>w szwajcarskich'), array('rapp','rappy','rapp<70>w')),
|
||||
'CYP' => array(array('funt cypryjski','funty cypryjskie','funt<6E>w cypryjskich'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'CZK' => array(array('korona czeska','korony czeskie','koron czeskich'), array('halerz','halerze','halerzy')),
|
||||
'DKK' => array(array('korona du<64>ska','korony du<64>skie','koron du<64>skich'), array('ore','ore','ore')),
|
||||
'EEK' => array(array('korona esto<74>ska','korony esto<74>skie','koron esto<74>skich'), array('senti','senti','senti')),
|
||||
'EUR' => array(array('euro', 'euro', 'euro'), array('eurocent', 'eurocenty', 'eurocent<6E>w')),
|
||||
'GBP' => array(array('funt szterling','funty szterlingi','funt<6E>w szterling<6E>w'), array('pens','pensy','pens<6E>w')),
|
||||
'HKD' => array(array('dolar Hongkongu','dolary Hongkongu','dolar<61>w Hongkongu'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'HRK' => array(array('kuna','kuny','kun'), array('lipa','lipy','lip')),
|
||||
'HUF' => array(array('forint','forinty','forint<6E>w'), array('filler','fillery','filler<65>w')),
|
||||
'ISK' => array(array('korona islandzka','korony islandzkie','koron islandzkich'), array('aurar','aurar','aurar')),
|
||||
'JPY' => array(array('jen','jeny','jen<65>w'), array('sen','seny','sen<65>w')),
|
||||
'LTL' => array(array('lit','lity','lit<69>w'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'LVL' => array(array('<27>at','<27>aty','<27>at<61>w'), array('sentim','sentimy','sentim<69>w')),
|
||||
'MKD' => array(array('denar','denary','denar<61>w'), array('deni','deni','deni')),
|
||||
'MTL' => array(array('lira malta<74>ska','liry malta<74>skie','lir malta<74>skich'), array('centym','centymy','centym<79>w')),
|
||||
'NOK' => array(array('korona norweska','korony norweskie','koron norweskich'), array('oere','oere','oere')),
|
||||
'PLN' => array(array('z<>oty', 'z<>ote', 'z<>otych'), array('grosz', 'grosze', 'groszy')),
|
||||
'ROL' => array(array('lej','leje','lei'), array('bani','bani','bani')),
|
||||
'RUB' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
|
||||
'SEK' => array(array('korona szwedzka','korony szwedzkie','koron szweckich'), array('oere','oere','oere')),
|
||||
'SIT' => array(array('tolar','tolary','tolar<61>w'), array('stotinia','stotinie','stotini')),
|
||||
'SKK' => array(array('korona s<>owacka','korony s<>owackie','koron s<>owackich'), array('halerz','halerze','halerzy')),
|
||||
'TRL' => array(array('lira turecka','liry tureckie','lir tureckich'), array('kurusza','kurysze','kuruszy')),
|
||||
'UAH' => array(array('hrywna','hrywna','hrywna'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'USD' => array(array('dolar','dolary','dolar<61>w'), array('cent', 'centy', 'cent<6E>w')),
|
||||
'YUM' => array(array('dinar','dinary','dinar<61>w'), array('para','para','para')),
|
||||
'ZAR' => array(array('rand','randy','rand<6E>w'), array('cent', 'centy', 'cent<6E>w'))
|
||||
);
|
||||
|
||||
/**
|
||||
* The default currency name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $def_currency = 'PLN'; // Polish zloty
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Polish language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($h) {
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'dziewi<77><69>set';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'osiemset';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'siedemset';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'sze<7A><65>set';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'pi<70><69>set';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'czterysta';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trzysta';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'dwie<69>cie';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'sto';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($t) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
case 6:
|
||||
case 5:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'dziesi<73>t';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'czterdzie<69>ci';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trzydzie<69>ci';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'dwadzie<69>cia';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'dziesi<73><69>';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'jedena<6E>cie';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 7:
|
||||
case 8:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'na<6E>cie';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'czterna<6E>cie';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$ret .= $this->_sep . 'pi<70>tna<6E>cie';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$ret .= $this->_sep . 'szesna<6E>cie';
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'dziewi<77>tna<6E>cie';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0)
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
|
||||
if ($t == 1)
|
||||
$d = 0;
|
||||
|
||||
if (( $h + $t ) > 0 && $d == 1)
|
||||
$d = 0;
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
switch ($d) {
|
||||
case 1:
|
||||
$suf = $lev[0];
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
$suf = $lev[1];
|
||||
break;
|
||||
case 0:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
$suf = $lev[2];
|
||||
break;
|
||||
}
|
||||
$ret .= $this->_sep . $suf;
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
// {{{ toCurrency()
|
||||
|
||||
/**
|
||||
* Converts a currency value to its word representation
|
||||
* (with monetary units) in Polish language
|
||||
*
|
||||
* @param integer $int_curr An international currency symbol
|
||||
* as defined by the ISO 4217 standard (three characters)
|
||||
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
||||
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
||||
* Optional. Defaults to false.
|
||||
*
|
||||
* @return string The corresponding word representation for the currency
|
||||
*
|
||||
* @access public
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since Numbers_Words 0.4
|
||||
*/
|
||||
function toCurrencyWords($int_curr, $decimal, $fraction = false) {
|
||||
$int_curr = strtoupper($int_curr);
|
||||
if (!isset($this->_currency_names[$int_curr])) {
|
||||
$int_curr = $this->def_currency;
|
||||
}
|
||||
$curr_names = $this->_currency_names[$int_curr];
|
||||
$ret = trim($this->toWords($decimal));
|
||||
$lev = $this->_get_numlevel($decimal);
|
||||
$ret .= $this->_sep . $curr_names[0][$lev];
|
||||
|
||||
if ($fraction !== false) {
|
||||
$ret .= $this->_sep . trim($this->toWords($fraction));
|
||||
$lev = $this->_get_numlevel($fraction);
|
||||
$ret .= $this->_sep . $curr_names[1][$lev];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
// {{{ _get_numlevel()
|
||||
|
||||
/**
|
||||
* Returns grammatical "level" of the number - this is necessary
|
||||
* for choosing the right suffix for exponents and currency names.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive
|
||||
* that need to be converted to words
|
||||
*
|
||||
* @return integer The grammatical "level" of the number.
|
||||
*
|
||||
* @access private
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @since Numbers_Words 0.4
|
||||
*/
|
||||
function _get_numlevel($num) {
|
||||
$num = (int)substr($num,-3);
|
||||
$h = $t = $d = $lev = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return $lev;
|
||||
break;
|
||||
}
|
||||
if ($t == 1)
|
||||
$d = 0;
|
||||
|
||||
if (( $h + $t ) > 0 && $d == 1)
|
||||
$d = 0;
|
||||
|
||||
switch ($d) {
|
||||
case 1:
|
||||
$lev = 0;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
$lev = 1;
|
||||
break;
|
||||
default:
|
||||
$lev = 2;
|
||||
}
|
||||
return $lev;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
241
thirdparty/pear/Numbers/Words/lang.pt_BR.php
vendored
241
thirdparty/pear/Numbers/Words/lang.pt_BR.php
vendored
@@ -1,241 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Marcelo Subtil Marcal <jason@conectiva.com.br> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.pt_BR.php,v 1.6 2003/09/29 12:23:58 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Brazilian Portuguese language.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Brazilian Portuguese.
|
||||
*
|
||||
* @author Marcelo Subtil Marcal <jason@conectiva.com.br>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once "Numbers/Words.php";
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Brazilian Portuguese.
|
||||
*
|
||||
* @author Marcelo Subtil Marcal <jason@conectiva.com.br>
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_pt_BR extends Numbers_Words
|
||||
{
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'pt_BR';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Brazilian Portuguese';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Portugu<67>s Brasileiro';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'menos';
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_unidade = array(
|
||||
'',
|
||||
'um',
|
||||
'dois',
|
||||
'tr<74>s',
|
||||
'quatro',
|
||||
'cinco',
|
||||
'seis',
|
||||
'sete',
|
||||
'oito',
|
||||
'nove'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing numbers 10-19.
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_dezena10 = array(
|
||||
'dez',
|
||||
'onze',
|
||||
'doze',
|
||||
'treze',
|
||||
'quatorze',
|
||||
'quinze',
|
||||
'dezesseis',
|
||||
'dezessete',
|
||||
'dezoito',
|
||||
'dezenove'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing numbers for 10,20,...,90.
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_dezena = array(
|
||||
'',
|
||||
'dez',
|
||||
'vinte',
|
||||
'trinta',
|
||||
'quarenta',
|
||||
'cinquenta',
|
||||
'sessenta',
|
||||
'setenta',
|
||||
'oitenta',
|
||||
'noventa'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing numbers for hundrets.
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_centena = array(
|
||||
'',
|
||||
'cem',
|
||||
'duzentos',
|
||||
'trezentos',
|
||||
'quatrocentos',
|
||||
'quinhentos',
|
||||
'seiscentos',
|
||||
'setecentos',
|
||||
'oitocentos',
|
||||
'novecentos'
|
||||
);
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_expoente = array(
|
||||
'',
|
||||
'mil',
|
||||
'milh<6C>o',
|
||||
'bilh<6C>o',
|
||||
'trilh<6C>o',
|
||||
'quatrilh<6C>o',
|
||||
'quintilh<6C>o',
|
||||
'sextilh<6C>o',
|
||||
'setilh<6C>o',
|
||||
'octilh<6C>o',
|
||||
'nonilh<6C>o',
|
||||
'decilh<6C>o',
|
||||
'undecilh<6C>o',
|
||||
'dodecilh<6C>o',
|
||||
'tredecilh<6C>o',
|
||||
'quatuordecilh<6C>o',
|
||||
'quindecilh<6C>o',
|
||||
'sedecilh<6C>o',
|
||||
'septendecilh<6C>o'
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Brazilian Portuguese language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access public
|
||||
* @author Marcelo Subtil Marcal <jason@conectiva.com.br>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num) {
|
||||
|
||||
$ret = '';
|
||||
|
||||
$num = trim($num);
|
||||
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
while (strlen($num) % 3 != 0) {
|
||||
$num = "0" . $num;
|
||||
}
|
||||
|
||||
$num = ereg_replace("(...)", "\\1.", $num);
|
||||
$num = ereg_replace("\.$", "", $num);
|
||||
|
||||
$inteiro = explode(".", $num);
|
||||
|
||||
for ($i = 0; $i < count($inteiro); $i++) {
|
||||
$ret .= (($inteiro[$i] > 100) && ($inteiro[$i] < 200)) ? "cento" : $this->_centena[$inteiro[$i][0]];
|
||||
$ret .= ($inteiro[$i][0] && ($inteiro[$i][1] || $inteiro[$i][2])) ? " e " : "";
|
||||
$ret .= ($inteiro[$i][1] < 2) ? "" : $this->_dezena[$inteiro[$i][1]];
|
||||
$ret .= (($inteiro[$i][1] > 1) && ($inteiro[$i][2])) ? " e " : "";
|
||||
$ret .= ($inteiro > 0) ? ( ($inteiro[$i][1] == 1) ? $this->_dezena10[$inteiro[$i][2]] : $this->_unidade[$inteiro[$i][2]] ) : "";
|
||||
$ret .= $inteiro[$i] > 0 ? " " . ($inteiro[$i] > 1 ? str_replace("<EFBFBD>o", "<EFBFBD>es", $this->_expoente[count($inteiro)-1-$i]) : $this->_expoente[count($inteiro)-1-$i]) : "";
|
||||
|
||||
if ($ret && (isset($inteiro[$i+1]))) {
|
||||
if ($inteiro[$i+1] != "000") {
|
||||
$ret .= ($i+1) == (count($inteiro)-1) ? " e " : ", ";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ret ? " $ret" : " zero";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
616
thirdparty/pear/Numbers/Words/lang.ru.php
vendored
616
thirdparty/pear/Numbers/Words/lang.ru.php
vendored
@@ -1,616 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// | Andrey Demenev <demenev@on-line.jar.ru> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Russian language.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Russian.
|
||||
*
|
||||
* @author Andrey Demenev
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Russian.
|
||||
*
|
||||
* @author Andrey Demenev
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_ru extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'ru';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Russian';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = '<27><><EFBFBD><EFBFBD><EFBFBD>'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular)
|
||||
* Names partly based on:
|
||||
* http://home.earthlink.net/~mrob/pub/math/largenum.html
|
||||
* http://mathforum.org/dr.math/faq/faq.large.numbers.html
|
||||
* http://www.mazes.com/AmericanNumberingSystem.html
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => '',
|
||||
6 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
9 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
12 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
15 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
18 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
21 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
24 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
27 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
30 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
33 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
36 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
39 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
42 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
45 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
48 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
51 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
54 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
57 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
60 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
63 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
66 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
69 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
72 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
75 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
78 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
81 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
84 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
87 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
90 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
93 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
96 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
99 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
102 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
105 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
108 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
111 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
114 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
117 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
120 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
123 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
126 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
129 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
132 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
135 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
138 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
141 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
144 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
147 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
150 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
153 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
156 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
159 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
162 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
165 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
168 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
171 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
174 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
177 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
180 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
183 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
186 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
189 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
192 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
195 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
198 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
201 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
204 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
207 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
210 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
213 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
216 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
219 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
222 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
225 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
228 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
231 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
234 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
237 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
240 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
243 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
246 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
249 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
252 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
255 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
258 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
261 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
264 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
267 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
270 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
273 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
276 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
279 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
282 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
285 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
288 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
291 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
294 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
297 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
300 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
303 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the teens' :) names
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_teens = array(
|
||||
11=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
12=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
13=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
14=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
15=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
16=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
17=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
18=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
19=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the tens' names
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_tens = array(
|
||||
2=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
3=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
4=>'<27><><EFBFBD><EFBFBD><EFBFBD>',
|
||||
5=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
6=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
7=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
8=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
9=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the hundreds' names
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_hundreds = array(
|
||||
1=>'<27><><EFBFBD>',
|
||||
2=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
3=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
4=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
5=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
6=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
7=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
8=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
9=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits
|
||||
* for neutral, male and female
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
array('<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array('<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array('<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = ' ';
|
||||
|
||||
/**
|
||||
* The currency names (based on the below links,
|
||||
* informations from central bank websites and on encyclopedias)
|
||||
*
|
||||
* @var array
|
||||
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
|
||||
* @link http://www.rusimpex.ru/Content/Reference/Refinfo/valuta.htm Foreign currencies names
|
||||
* @link http://www.cofe.ru/Finance/money.asp Currencies names
|
||||
* @access private
|
||||
*/
|
||||
var $_currency_names = array(
|
||||
'ALL' => array(
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'AUD' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'BGN' => array(
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'BRL' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'BYR' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CAD' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CHF' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CYP' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CZK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'DKK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'EEK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'EUR' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CYP' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'CAD' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'HRK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'HUF' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'ISK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'JPY' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'LTL' => array(
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'LVL' => array(
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'MKD' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'MTL' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'NOK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(0,'<27><><EFBFBD>','<27><><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'PLN' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'ROL' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>')
|
||||
),
|
||||
// both RUR and RUR are used, I use RUB for shorter form
|
||||
'RUB' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'RUR' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'SEK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD>','<27><><EFBFBD>','<27><><EFBFBD>')
|
||||
),
|
||||
'SIT' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'SKK' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'),
|
||||
array(0,'','','')
|
||||
),
|
||||
'TRL' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'UAH' => array(
|
||||
array(2,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'USD' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'YUM' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD>')
|
||||
),
|
||||
'ZAR' => array(
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'),
|
||||
array(1,'<27><><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The default currency name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $def_currency = 'RUB'; // Russian rouble
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Russian language
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $gender Gender of string, 0=neutral, 1=male, 2=female.
|
||||
* Optional, defaults to 1.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Andrey Demenev <demenev@on-line.jar.ru>
|
||||
*/
|
||||
function toWords($num, $gender = 1)
|
||||
{
|
||||
return $this->_toWordsWithCase($num, $dummy, $gender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Russian language and determines the case of string.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $case A variable passed by reference which is set to case
|
||||
* of the word associated with the number
|
||||
* @param integer $gender Gender of string, 0=neutral, 1=male, 2=female.
|
||||
* Optional, defaults to 1.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Andrey Demenev <demenev@on-line.jar.ru>
|
||||
*/
|
||||
function _toWordsWithCase($num, &$case, $gender = 1)
|
||||
{
|
||||
$ret = '';
|
||||
$case = 3;
|
||||
|
||||
$num = trim($num);
|
||||
|
||||
$sign = "";
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$sign = $this->_minus . $this->_sep;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
while (strlen($num) % 3) $num = '0' . $num;
|
||||
if ($num == 0 || $num == '') {
|
||||
$ret .= $this->_digits[$gender][0];
|
||||
}
|
||||
|
||||
else {
|
||||
$power = 0;
|
||||
while ($power < strlen($num)) {
|
||||
if (!$power) {
|
||||
$groupgender = $gender;
|
||||
} elseif ($power == 3) {
|
||||
$groupgender = 2;
|
||||
} else {
|
||||
$groupgender = 1;
|
||||
}
|
||||
$group = $this->_groupToWords(substr($num,-$power-3,3),$groupgender,$_case);
|
||||
if (!$power) {
|
||||
$case = $_case;
|
||||
}
|
||||
if ($power == 3) {
|
||||
if ($_case == 1) {
|
||||
$group .= $this->_sep . '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
} elseif ($_case == 2) {
|
||||
$group .= $this->_sep . '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
} else {
|
||||
$group .= $this->_sep . '<27><><EFBFBD><EFBFBD><EFBFBD>';
|
||||
}
|
||||
} elseif ($group && $power>3 && isset($this->_exponent[$power])) {
|
||||
$group .= $this->_sep . $this->_exponent[$power];
|
||||
if ($_case == 2) {
|
||||
$group .= '<27>';
|
||||
} elseif ($_case == 3) {
|
||||
$group .= '<27><>';
|
||||
}
|
||||
}
|
||||
if ($group) {
|
||||
$ret = $group . $this->_sep . $ret;
|
||||
}
|
||||
$power+=3;
|
||||
}
|
||||
}
|
||||
|
||||
return $sign . $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _groupToWords()
|
||||
|
||||
/**
|
||||
* Converts a group of 3 digits to its word representation
|
||||
* in Russian language.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $gender Gender of string, 0=neutral, 1=male, 2=female.
|
||||
* @param integer $case A variable passed by reference which is set to case
|
||||
* of the word associated with the number
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Andrey Demenev <demenev@on-line.jar.ru>
|
||||
*/
|
||||
function _groupToWords($num, $gender, &$case)
|
||||
{
|
||||
$ret = '';
|
||||
$case = 3;
|
||||
if ((int)$num == 0) {
|
||||
$ret = '';
|
||||
} elseif ($num < 10) {
|
||||
$ret = $this->_digits[$gender][(int)$num];
|
||||
if ($num == 1) $case = 1;
|
||||
elseif ($num < 5) $case = 2;
|
||||
else $case = 3;
|
||||
} else {
|
||||
$num = str_pad($num,3,'0',STR_PAD_LEFT);
|
||||
$hundreds = (int)$num{0};
|
||||
if ($hundreds) {
|
||||
$ret = $this->_hundreds[$hundreds];
|
||||
if (substr($num,1) != '00') {
|
||||
$ret .= $this->_sep;
|
||||
}
|
||||
$case = 3;
|
||||
}
|
||||
$tens=(int)$num{1};
|
||||
$ones=(int)$num{2};
|
||||
if ($tens || $ones) {
|
||||
if ($tens == 1 && $ones == 0) $ret .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||
elseif ($tens < 2) $ret .= $this->_teens[$ones+10];
|
||||
else {
|
||||
$ret .= $this->_tens[(int)$tens];
|
||||
if ($ones > 0) {
|
||||
$ret .= $this->_sep
|
||||
.$this->_digits[$gender][$ones];
|
||||
if ($ones == 1) {
|
||||
$case = 1;
|
||||
} elseif ($ones < 5) {
|
||||
$case = 2;
|
||||
} else {
|
||||
$case = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
// {{{ toCurrencyWords()
|
||||
|
||||
/**
|
||||
* Converts a currency value to its word representation
|
||||
* (with monetary units) in Russian language
|
||||
*
|
||||
* @param integer $int_curr An international currency symbol
|
||||
* as defined by the ISO 4217 standard (three characters)
|
||||
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
||||
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
||||
* Optional. Defaults to false.
|
||||
*
|
||||
* @return string The corresponding word representation for the currency
|
||||
*
|
||||
* @access public
|
||||
* @author Andrey Demenev <demenev@on-line.jar.ru>
|
||||
*/
|
||||
function toCurrencyWords($int_curr, $decimal, $fraction = false)
|
||||
{
|
||||
$int_curr = strtoupper($int_curr);
|
||||
if (!isset($this->_currency_names[$int_curr])) {
|
||||
$int_curr = $this->def_currency;
|
||||
}
|
||||
$curr_names = $this->_currency_names[$int_curr];
|
||||
$ret = trim($this->_toWordsWithCase($decimal, $case, 0, '', $curr_names[0][0]));
|
||||
$ret .= $this->_sep . $curr_names[0][$case];
|
||||
|
||||
if ($fraction !== false) {
|
||||
$ret .= $this->_sep . trim($this->_toWordsWithCase($fraction, $case, 0, '', $curr_names[1][0]));
|
||||
$ret .= $this->_sep . $curr_names[1][$case];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
310
thirdparty/pear/Numbers/Words/lang.sv.php
vendored
310
thirdparty/pear/Numbers/Words/lang.sv.php
vendored
@@ -1,310 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Piotr Klaban <makler@man.torun.pl> |
|
||||
// | Robin Ericsson <robin.ericsson@profecta.se> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: lang.de.php,v 1.1.1.1 2004/03/10 10:33:10 makler Exp $
|
||||
//
|
||||
// Numbers_Words class extension to spell numbers in Swedish language.
|
||||
//
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for translating numbers into Swedish.
|
||||
* @author Robin Ericsson
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include needed files
|
||||
*/
|
||||
require_once("Numbers/Words.php");
|
||||
|
||||
/**
|
||||
* Class for translating numbers into Swedish.
|
||||
*
|
||||
* @author Robin Ericsson
|
||||
* @package Numbers_Words
|
||||
*/
|
||||
class Numbers_Words_sv extends Numbers_Words
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Locale name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $locale = 'sv';
|
||||
|
||||
/**
|
||||
* Language name in English
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang = 'Swedish';
|
||||
|
||||
/**
|
||||
* Native language name
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $lang_native = 'Svenska';
|
||||
|
||||
/**
|
||||
* The word for the minus sign
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_minus = 'Minus'; // minus sign
|
||||
|
||||
/**
|
||||
* The sufixes for exponents (singular and plural)
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_exponent = array(
|
||||
0 => array(''),
|
||||
3 => array('tusen', 'tusen'),
|
||||
6 => array('miljon','miljoner'),
|
||||
9 => array('miljard','miljarder'),
|
||||
12 => array('biljon','biljoner'),
|
||||
15 => array('biljard','biljarder'),
|
||||
18 => array('triljon','triljoner'),
|
||||
21 => array('triljard','triljarder'),
|
||||
24 => array('kvadriljon','kvadriljoner'),
|
||||
27 => array('kvadriljard','kvadriljarder'),
|
||||
30 => array('kvintiljon','kvintiljoner'),
|
||||
33 => array('kvintiljard','kvintiljarder'),
|
||||
36 => array('sextiljon','sextiljoner'),
|
||||
39 => array('sextiljard','sextiljarder'),
|
||||
42 => array('septiljon','septiljoner'),
|
||||
45 => array('septiljard','septiljarder'),
|
||||
48 => array('oktiljon','oktiljoner'),
|
||||
51 => array('oktiljard','oktiljarder'),
|
||||
54 => array('noniljon','noniljoner'),
|
||||
57 => array('noniljard','noniljarder'),
|
||||
60 => array('dekiljon','dekiljoner'),
|
||||
63 => array('dekiljard','dekiljarder'),
|
||||
120 => array('vigintiljon','vigintiljoner'),
|
||||
123 => array('vigintiljard','vigintiljarder'),
|
||||
600 => array('centiljon','centiljoner'),
|
||||
603 => array('centiljard','centiljarder')
|
||||
);
|
||||
|
||||
/**
|
||||
* The array containing the digits (indexed by the digits themselves).
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_digits = array(
|
||||
0 => 'noll', 'ett', 'tv<74>', 'tre', 'fyra',
|
||||
'fem', 'sex', 'sju', '<27>tta', 'nio'
|
||||
);
|
||||
|
||||
/**
|
||||
* The word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep = '';
|
||||
|
||||
/**
|
||||
* The exponent word separator
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_sep2 = ' ';
|
||||
|
||||
// }}}
|
||||
// {{{ toWords()
|
||||
|
||||
/**
|
||||
* Converts a number to its word representation
|
||||
* in Swedish language.
|
||||
*
|
||||
* @param integer $num An integer between -infinity and infinity inclusive :)
|
||||
* that need to be converted to words
|
||||
* @param integer $power The power of ten for the rest of the number to the right.
|
||||
* Optional, defaults to 0.
|
||||
* @param integer $powsuffix The power name to be added to the end of the return string.
|
||||
* Used internally. Optional, defaults to ''.
|
||||
*
|
||||
* @return string The corresponding word representation
|
||||
*
|
||||
* @access private
|
||||
* @author Piotr Klaban <makler@man.torun.pl>
|
||||
* @author Robin Ericsson <lobbin@localhost.nu>
|
||||
* @since PHP 4.2.3
|
||||
*/
|
||||
function toWords($num, $power = 0, $powsuffix = '') {
|
||||
$ret = '';
|
||||
|
||||
// add a minus sign
|
||||
if (substr($num, 0, 1) == '-') {
|
||||
$ret = $this->_sep . $this->_minus;
|
||||
$num = substr($num, 1);
|
||||
}
|
||||
|
||||
// strip excessive zero signs and spaces
|
||||
$num = trim($num);
|
||||
$num = preg_replace('/^0+/','',$num);
|
||||
|
||||
if (strlen($num) > 3) {
|
||||
$maxp = strlen($num)-1;
|
||||
$curp = $maxp;
|
||||
for ($p = $maxp; $p > 0; --$p) { // power
|
||||
|
||||
// check for highest power
|
||||
if (isset($this->_exponent[$p])) {
|
||||
// send substr from $curp to $p
|
||||
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
$snum = preg_replace('/^0+/','',$snum);
|
||||
if ($snum !== '') {
|
||||
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
||||
if ($powsuffix != '')
|
||||
$cursuffix .= $this->_sep . $powsuffix;
|
||||
$ret .= $this->toWords($snum, $p, $cursuffix);
|
||||
}
|
||||
$curp = $p - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
||||
if ($num == 0) {
|
||||
return $ret;
|
||||
}
|
||||
} elseif ($num == 0 || $num == '') {
|
||||
return $this->_sep . $this->_digits[0];
|
||||
}
|
||||
|
||||
$h = $t = $d = 0;
|
||||
|
||||
switch(strlen($num)) {
|
||||
case 3:
|
||||
$h = (int)substr($num,-3,1);
|
||||
|
||||
case 2:
|
||||
$t = (int)substr($num,-2,1);
|
||||
|
||||
case 1:
|
||||
$d = (int)substr($num,-1,1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($h) {
|
||||
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundra';
|
||||
}
|
||||
|
||||
// ten, twenty etc.
|
||||
switch ($t) {
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
$ret .= $this->_sep . $this->_digits[$t] . 'tio';
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'nittio';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . '<27>ttio';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'fyrtio';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'trettio';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'tjugo';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
switch ($d) {
|
||||
case 0:
|
||||
$ret .= $this->_sep . 'tio';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$ret .= $this->_sep . 'elva';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$ret .= $this->_sep . 'tolv';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$ret .= $this->_sep . 'tretton';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$ret .= $this->_sep . 'fjorton';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
$ret .= $this->_sep . $this->_digits[$d] . 'ton';
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$ret .= $this->_sep . 'sjutton';
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$ret .= $this->_sep . 'arton';
|
||||
break;
|
||||
case 9:
|
||||
$ret .= $this->_sep . 'nitton';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
||||
// add minus sign between [2-9] and digit
|
||||
$ret .= $this->_sep . $this->_digits[$d];
|
||||
}
|
||||
|
||||
if ($power > 0) {
|
||||
if (isset($this->_exponent[$power]))
|
||||
$lev = $this->_exponent[$power];
|
||||
|
||||
if (!isset($lev) || !is_array($lev))
|
||||
return null;
|
||||
|
||||
$ret .= $this->_sep . $lev[0];
|
||||
}
|
||||
|
||||
if ($powsuffix != '')
|
||||
$ret .= $this->_sep . $powsuffix;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
410
thirdparty/pear/OLE/OLE.php
vendored
410
thirdparty/pear/OLE/OLE.php
vendored
@@ -1,410 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: OLE.php,v 1.7 2003/08/21 15:15:40 xnoguer Exp $
|
||||
|
||||
|
||||
/**
|
||||
* Constants for OLE package
|
||||
*/
|
||||
define('OLE_PPS_TYPE_ROOT', 5);
|
||||
define('OLE_PPS_TYPE_DIR', 1);
|
||||
define('OLE_PPS_TYPE_FILE', 2);
|
||||
define('OLE_DATA_SIZE_SMALL', 0x1000);
|
||||
define('OLE_LONG_INT_SIZE', 4);
|
||||
define('OLE_PPS_SIZE', 0x80);
|
||||
|
||||
require_once('PEAR.php');
|
||||
require_once 'OLE/PPS.php';
|
||||
|
||||
/**
|
||||
* OLE package base class.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE extends PEAR
|
||||
{
|
||||
/**
|
||||
* The file handle for reading an OLE container
|
||||
* @var resource
|
||||
*/
|
||||
var $_file_handle;
|
||||
|
||||
/**
|
||||
* Array of PPS's found on the OLE container
|
||||
* @var array
|
||||
*/
|
||||
var $_list;
|
||||
|
||||
/**
|
||||
* Creates a new OLE object
|
||||
* Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();)
|
||||
* @access public
|
||||
*/
|
||||
function OLE()
|
||||
{
|
||||
$this->_list = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an OLE container from the contents of the file given.
|
||||
*
|
||||
* @acces public
|
||||
* @param string $file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function read($file)
|
||||
{
|
||||
/* consider storing offsets as constants */
|
||||
$big_block_size_offset = 30;
|
||||
$iBdbCnt_offset = 44;
|
||||
$bd_start_offset = 68;
|
||||
|
||||
$fh = @fopen($file, "r");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't open file $file");
|
||||
}
|
||||
$this->_file_handle = $fh;
|
||||
|
||||
/* begin reading OLE attributes */
|
||||
fseek($fh, 0);
|
||||
$signature = fread($fh, 8);
|
||||
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
|
||||
return $this->raiseError("File doesn't seem to be an OLE container.");
|
||||
}
|
||||
fseek($fh, $big_block_size_offset);
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$big_block_size = pow(2, $packed_array['']);
|
||||
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$small_block_size = pow(2, $packed_array['']);
|
||||
$i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
fseek($fh, $iBdbCnt_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iBdbCnt = $packed_array[''];
|
||||
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$pps_wk_start = $packed_array[''];
|
||||
|
||||
fseek($fh, $bd_start_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_start = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_count = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iAll = $packed_array['']; // this may be wrong
|
||||
/* create OLE_PPS objects from */
|
||||
$ret = $this->_readPpsWks($pps_wk_start, $big_block_size);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor (using PEAR)
|
||||
* Just closes the file handle on the OLE file.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _OLE()
|
||||
{
|
||||
fclose($this->_file_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about all PPS's on the OLE container from the PPS WK's
|
||||
* creates an OLE_PPS object for each one.
|
||||
*
|
||||
* @access private
|
||||
* @param integer $pps_wk_start Position inside the OLE file where PPS WK's start
|
||||
* @param integer $big_block_size Size of big blobks in the OLE file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function _readPpsWks($pps_wk_start, $big_block_size)
|
||||
{
|
||||
$pointer = ($pps_wk_start + 1) * $big_block_size;
|
||||
while (1)
|
||||
{
|
||||
fseek($this->_file_handle, $pointer);
|
||||
$pps_wk = fread($this->_file_handle, OLE_PPS_SIZE);
|
||||
if (strlen($pps_wk) != OLE_PPS_SIZE) {
|
||||
break; // Excel likes to add a trailing byte sometimes
|
||||
//return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk));
|
||||
}
|
||||
$name_length = unpack("c", substr($pps_wk, 64, 2)); // FIXME (2 bytes??)
|
||||
$name_length = $name_length[''] - 2;
|
||||
$name = substr($pps_wk, 0, $name_length);
|
||||
$type = unpack("c", substr($pps_wk, 66, 1));
|
||||
if (($type[''] != OLE_PPS_TYPE_ROOT) and
|
||||
($type[''] != OLE_PPS_TYPE_DIR) and
|
||||
($type[''] != OLE_PPS_TYPE_FILE))
|
||||
{
|
||||
return $this->raiseError("PPS at $pointer has unknown type: {$type['']}");
|
||||
}
|
||||
$prev = unpack("V", substr($pps_wk, 68, 4));
|
||||
$next = unpack("V", substr($pps_wk, 72, 4));
|
||||
$dir = unpack("V", substr($pps_wk, 76, 4));
|
||||
// there is no magic number, it can take different values.
|
||||
//$magic = unpack("V", strrev(substr($pps_wk, 92, 4)));
|
||||
$time_1st = substr($pps_wk, 100, 8);
|
||||
$time_2nd = substr($pps_wk, 108, 8);
|
||||
$start_block = unpack("V", substr($pps_wk, 116, 4));
|
||||
$size = unpack("V", substr($pps_wk, 120, 4));
|
||||
// _data member will point to position in file!!
|
||||
// OLE_PPS object is created with an empty children array!!
|
||||
$this->_list[] = new OLE_PPS(null, '', $type[''], $prev[''], $next[''],
|
||||
$dir[''], OLE::OLE2LocalDate($time_1st),
|
||||
OLE::OLE2LocalDate($time_2nd),
|
||||
($start_block[''] + 1) * $big_block_size, array());
|
||||
// give it a size
|
||||
$this->_list[count($this->_list) - 1]->Size = $size[''];
|
||||
// check if the PPS tree (starting from root) is complete
|
||||
if ($this->_ppsTreeComplete(0)) {
|
||||
break;
|
||||
}
|
||||
$pointer += OLE_PPS_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It checks whether the PPS tree is complete (all PPS's read)
|
||||
* starting with the given PPS (not necessarily root)
|
||||
*
|
||||
* @access private
|
||||
* @param integer $index The index of the PPS from which we are checking
|
||||
* @return boolean Whether the PPS tree for the given PPS is complete
|
||||
*/
|
||||
function _ppsTreeComplete($index)
|
||||
{
|
||||
if ($this->_list[$index]->NextPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->NextPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->NextPps);
|
||||
}
|
||||
}
|
||||
if ($this->_list[$index]->DirPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->DirPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->DirPps);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a File PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return bool true if it's a File PPS, false otherwise
|
||||
*/
|
||||
function isFile($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return ($this->_list[$index]->Type == OLE_PPS_TYPE_FILE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a Root PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS.
|
||||
* @return bool true if it's a Root PPS, false otherwise
|
||||
*/
|
||||
function isRoot($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return ($this->_list[$index]->Type == OLE_PPS_TYPE_ROOT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the total number of PPS's found in the OLE container.
|
||||
*
|
||||
* @access public
|
||||
* @return integer The total number of PPS's found in the OLE container
|
||||
*/
|
||||
function ppsTotal()
|
||||
{
|
||||
return count($this->_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data from a PPS
|
||||
* If there is no PPS for the index given, it will return an empty string.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @param integer $position The position from which to start reading
|
||||
* (relative to the PPS)
|
||||
* @param integer $length The amount of bytes to read (at most)
|
||||
* @return string The binary string containing the data requested
|
||||
*/
|
||||
function getData($index, $position, $length)
|
||||
{
|
||||
// if position is not valid return empty string
|
||||
if (!isset($this->_list[$index]) or ($position >= $this->_list[$index]->Size) or ($position < 0)) {
|
||||
return '';
|
||||
}
|
||||
// Beware!!! _data member is actually a position
|
||||
fseek($this->_file_handle, $this->_list[$index]->_data + $position);
|
||||
return fread($this->_file_handle, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data length from a PPS
|
||||
* If there is no PPS for the index given, it will return 0.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return integer The amount of bytes in data the PPS has
|
||||
*/
|
||||
function getDataLength($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return $this->_list[$index]->Size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to transform ASCII text to Unicode
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ascii The ASCII string to transform
|
||||
* @return string The string in Unicode
|
||||
*/
|
||||
function Asc2Ucs($ascii)
|
||||
{
|
||||
$rawname = '';
|
||||
for ($i = 0; $i < strlen($ascii); $i++) {
|
||||
$rawname .= $ascii{$i}."\x00";
|
||||
}
|
||||
return $rawname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function
|
||||
* Returns a string for the OLE container with the date given
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $date A timestamp
|
||||
* @return string The string for the OLE container
|
||||
*/
|
||||
function LocalDate2OLE($date = null)
|
||||
{
|
||||
if (!isset($date)) {
|
||||
return "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
|
||||
// factor used for separating numbers into 4 bytes parts
|
||||
$factor = pow(2,32);
|
||||
|
||||
// days from 1-1-1601 until the beggining of UNIX era
|
||||
$days = 134774;
|
||||
// calculate seconds
|
||||
$big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
|
||||
date("m",$date),date("d",$date),date("Y",$date));
|
||||
// multiply just to make MS happy
|
||||
$big_date *= 10000000;
|
||||
|
||||
$high_part = floor($big_date/$factor);
|
||||
// lower 4 bytes
|
||||
$low_part = floor((($big_date/$factor) - $high_part)*$factor);
|
||||
|
||||
// Make HEX string
|
||||
$res = '';
|
||||
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$hex = $low_part % 0x100;
|
||||
$res .= pack('c', $hex);
|
||||
$low_part /= 0x100;
|
||||
}
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$hex = $high_part % 0x100;
|
||||
$res .= pack('c', $hex);
|
||||
$high_part /= 0x100;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp from an OLE container's date
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $string A binary string with the encoded date
|
||||
* @return string The timestamp corresponding to the string
|
||||
*/
|
||||
function OLE2LocalDate($string)
|
||||
{
|
||||
if (strlen($string) != 8) {
|
||||
return new PEAR_Error("Expecting 8 byte string");
|
||||
}
|
||||
|
||||
// factor used for separating numbers into 4 bytes parts
|
||||
$factor = pow(2,32);
|
||||
$high_part = 0;
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$high_part += $al[''];
|
||||
if ($i < 3) {
|
||||
$high_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$low_part = 0;
|
||||
for ($i=4; $i<8; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$low_part += $al[''];
|
||||
if ($i < 7) {
|
||||
$low_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$big_date = ($high_part*$factor) + $low_part;
|
||||
// translate to seconds
|
||||
$big_date /= 10000000;
|
||||
|
||||
// days from 1-1-1601 until the beggining of UNIX era
|
||||
$days = 134774;
|
||||
|
||||
// translate to seconds from beggining of UNIX era
|
||||
$big_date -= $days*24*3600;
|
||||
return floor($big_date);
|
||||
}
|
||||
}
|
||||
?>
|
||||
219
thirdparty/pear/OLE/PPS.php
vendored
219
thirdparty/pear/OLE/PPS.php
vendored
@@ -1,219 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: PPS.php,v 1.5 2003/12/14 18:12:28 xnoguer Exp $
|
||||
|
||||
|
||||
require_once('PEAR.php');
|
||||
require_once('OLE.php');
|
||||
|
||||
/**
|
||||
* Class for creating PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS extends PEAR
|
||||
{
|
||||
/**
|
||||
* The PPS index
|
||||
* @var integer
|
||||
*/
|
||||
var $No;
|
||||
|
||||
/**
|
||||
* The PPS name (in Unicode)
|
||||
* @var string
|
||||
*/
|
||||
var $Name;
|
||||
|
||||
/**
|
||||
* The PPS type. Dir, Root or File
|
||||
* @var integer
|
||||
*/
|
||||
var $Type;
|
||||
|
||||
/**
|
||||
* The index of the previous PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $PrevPps;
|
||||
|
||||
/**
|
||||
* The index of the next PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $NextPps;
|
||||
|
||||
/**
|
||||
* The index of it's first child if this is a Dir or Root PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $DirPps;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time1st;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time2nd;
|
||||
|
||||
/**
|
||||
* Starting block (small or big) for this PPS's data inside the container
|
||||
* @var integer
|
||||
*/
|
||||
var $_StartBlock;
|
||||
|
||||
/**
|
||||
* The size of the PPS's data (in bytes)
|
||||
* @var integer
|
||||
*/
|
||||
var $Size;
|
||||
|
||||
/**
|
||||
* The PPS's data (only used if it's not using a temporary file)
|
||||
* @var string
|
||||
*/
|
||||
var $_data;
|
||||
|
||||
/**
|
||||
* Array of child PPS's (only used by Root and Dir PPS's)
|
||||
* @var array
|
||||
*/
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $No The PPS index
|
||||
* @param string $name The PPS name (in Unicode)
|
||||
* @param integer $type The PPS type. Dir, Root or File
|
||||
* @param integer $prev The index of the previous PPS
|
||||
* @param integer $next The index of the next PPS
|
||||
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
* @param array $children Array containing children PPS for this PPS
|
||||
*/
|
||||
function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
|
||||
{
|
||||
$this->No = $No;
|
||||
$this->Name = $name;
|
||||
$this->Type = $type;
|
||||
$this->PrevPps = $prev;
|
||||
$this->NextPps = $next;
|
||||
$this->DirPps = $dir;
|
||||
$this->Time1st = $time_1st;
|
||||
$this->Time2nd = $time_2nd;
|
||||
$this->_data = $data;
|
||||
$this->children = $children;
|
||||
if ($data != '') {
|
||||
$this->Size = strlen($data);
|
||||
}
|
||||
else {
|
||||
$this->Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of data saved for this PPS
|
||||
*
|
||||
* @access private
|
||||
* @return integer The amount of data (in bytes)
|
||||
*/
|
||||
function _DataLen()
|
||||
{
|
||||
if (!isset($this->_data)) {
|
||||
return 0;
|
||||
}
|
||||
if (isset($this->_PPS_FILE))
|
||||
{
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
$stats = fstat($this->_PPS_FILE);
|
||||
return $stats[7];
|
||||
}
|
||||
else {
|
||||
return strlen($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with the PPS's WK (What is a WK?)
|
||||
*
|
||||
* @access private
|
||||
* @return string The binary string
|
||||
*/
|
||||
function _getPpsWk()
|
||||
{
|
||||
$ret = $this->Name;
|
||||
for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
|
||||
$ret .= "\x00";
|
||||
}
|
||||
$ret .= pack("v", strlen($this->Name) + 2) // 66
|
||||
. pack("c", $this->Type) // 67
|
||||
. pack("c", 0x00) //UK // 68
|
||||
. pack("V", $this->PrevPps) //Prev // 72
|
||||
. pack("V", $this->NextPps) //Next // 76
|
||||
. pack("V", $this->DirPps) //Dir // 80
|
||||
. "\x00\x09\x02\x00" // 84
|
||||
. "\x00\x00\x00\x00" // 88
|
||||
. "\xc0\x00\x00\x00" // 92
|
||||
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
|
||||
. "\x00\x00\x00\x00" // 100
|
||||
. OLE::LocalDate2OLE($this->Time1st) // 108
|
||||
. OLE::LocalDate2OLE($this->Time2nd) // 116
|
||||
. pack("V", isset($this->_StartBlock)?
|
||||
$this->_StartBlock:0) // 120
|
||||
. pack("V", $this->Size) // 124
|
||||
. pack("V", 0); // 128
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates index and pointers to previous, next and children PPS's for this
|
||||
* PPS. I don't think it'll work with Dir PPS's.
|
||||
*
|
||||
* @access private
|
||||
* @param array &$pps_array Reference to the array of PPS's for the whole OLE
|
||||
* container
|
||||
* @return integer The index for this PPS
|
||||
*/
|
||||
function _savePpsSetPnt(&$pps_array)
|
||||
{
|
||||
$pps_array[count($pps_array)] = &$this;
|
||||
$this->No = count($pps_array) - 1;
|
||||
$this->PrevPps = 0xFFFFFFFF;
|
||||
$this->NextPps = 0xFFFFFFFF;
|
||||
if (count($this->children) > 0) {
|
||||
$this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
|
||||
}
|
||||
else {
|
||||
$this->DirPps = 0xFFFFFFFF;
|
||||
}
|
||||
return $this->No;
|
||||
}
|
||||
}
|
||||
?>
|
||||
114
thirdparty/pear/OLE/PPS/File.php
vendored
114
thirdparty/pear/OLE/PPS/File.php
vendored
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: File.php,v 1.8 2003/12/12 21:10:10 xnoguer Exp $
|
||||
|
||||
|
||||
require_once ('OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating File PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_File extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param string $name The name of the file (in Unicode)
|
||||
* @see OLE::Asc2Ucs()
|
||||
*/
|
||||
function OLE_PPS_File($name)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
$name,
|
||||
OLE_PPS_TYPE_FILE,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization method. Has to be called right after OLE_PPS_File().
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success. PEAR_Error on failure
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
|
||||
$fh = @fopen($this->_tmp_filename, "w+b");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't create temporary file");
|
||||
}
|
||||
$this->_PPS_FILE = $fh;
|
||||
if ($this->_PPS_FILE) {
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to PPS
|
||||
*
|
||||
* @access public
|
||||
* @param string $data The data to append
|
||||
*/
|
||||
function append($data)
|
||||
{
|
||||
if ($this->_PPS_FILE) {
|
||||
fwrite($this->_PPS_FILE, $data);
|
||||
}
|
||||
else {
|
||||
$this->_data .= $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
519
thirdparty/pear/OLE/PPS/Root.php
vendored
519
thirdparty/pear/OLE/PPS/Root.php
vendored
@@ -1,519 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Root.php,v 1.7 2003/12/12 21:10:10 xnoguer Exp $
|
||||
|
||||
|
||||
require_once ('OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating Root PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_Root extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
*/
|
||||
function OLE_PPS_Root($time_1st, $time_2nd, $raChild)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
OLE::Asc2Ucs('Root Entry'),
|
||||
OLE_PPS_TYPE_ROOT,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$time_1st,
|
||||
$time_2nd,
|
||||
null,
|
||||
$raChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for saving the whole OLE container (including files).
|
||||
* In fact, if called with an empty argument (or '-'), it saves to a
|
||||
* temporary file and then outputs it's contents to stdout.
|
||||
*
|
||||
* @param string $filename The name of the file where to save the OLE container
|
||||
* @access public
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function save($filename)
|
||||
{
|
||||
// Initial Setting for saving
|
||||
$this->_BIG_BLOCK_SIZE = pow(2,
|
||||
((isset($this->_BIG_BLOCK_SIZE))? $this->_adjust2($this->_BIG_BLOCK_SIZE) : 9));
|
||||
$this->_SMALL_BLOCK_SIZE= pow(2,
|
||||
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
|
||||
|
||||
// Open temp file if we are sending output to stdout
|
||||
if (($filename == '-') or ($filename == ''))
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
|
||||
$this->_FILEH_ = @fopen($this->_tmp_filename,"w+b");
|
||||
if ($this->_FILEH_ == false) {
|
||||
return $this->raiseError("Can't create temporary file.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_FILEH_ = @fopen($filename, "wb");
|
||||
if ($this->_FILEH_ == false) {
|
||||
return $this->raiseError("Can't open $filename. It may be in use or protected.");
|
||||
}
|
||||
}
|
||||
// Make an array of PPS's (for Save)
|
||||
$aList = array();
|
||||
$this->_savePpsSetPnt($aList);
|
||||
// calculate values for header
|
||||
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
|
||||
// Save Header
|
||||
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
|
||||
// Make Small Data string (write SBD)
|
||||
$this->_data = $this->_makeSmallData($aList);
|
||||
|
||||
// Write BB
|
||||
$this->_saveBigData($iSBDcnt, $aList);
|
||||
// Write PPS
|
||||
$this->_savePps($aList);
|
||||
// Write Big Block Depot and BDList and Adding Header informations
|
||||
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
// Close File, send it to stdout if necessary
|
||||
if(($filename == '-') or ($filename == ''))
|
||||
{
|
||||
fseek($this->_FILEH_, 0);
|
||||
fpassthru($this->_FILEH_);
|
||||
@fclose($this->_FILEH_);
|
||||
// Delete the temporary file.
|
||||
@unlink($this->_tmp_filename);
|
||||
}
|
||||
else {
|
||||
@fclose($this->_FILEH_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate some numbers
|
||||
*
|
||||
* @access private
|
||||
* @param array $raList Reference to an array of PPS's
|
||||
* @return array The array of numbers
|
||||
*/
|
||||
function _calcSize(&$raList)
|
||||
{
|
||||
// Calculate Basic Setting
|
||||
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
|
||||
$iSmallLen = 0;
|
||||
$iSBcnt = 0;
|
||||
for ($i = 0; $i < count($raList); $i++) {
|
||||
if($raList[$i]->Type == OLE_PPS_TYPE_FILE) {
|
||||
$raList[$i]->Size = $raList[$i]->_DataLen();
|
||||
if($raList[$i]->Size < OLE_DATA_SIZE_SMALL) {
|
||||
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
|
||||
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
|
||||
}
|
||||
else {
|
||||
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
|
||||
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
|
||||
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
|
||||
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
|
||||
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
|
||||
(( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
$iCnt = count($raList);
|
||||
$iBdCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
|
||||
$iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
|
||||
|
||||
return array($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for caculating a magic value for block sizes
|
||||
*
|
||||
* @access private
|
||||
* @param integer $i2 The argument
|
||||
* @see save()
|
||||
* @return integer
|
||||
*/
|
||||
function _adjust2($i2)
|
||||
{
|
||||
$iWk = log($i2)/log(2);
|
||||
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save OLE header
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iSBDcnt
|
||||
* @param integer $iBBcnt
|
||||
* @param integer $iPPScnt
|
||||
*/
|
||||
function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
|
||||
// Calculate Basic Setting
|
||||
$iBlCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
|
||||
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
$iBdExL = 0;
|
||||
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
|
||||
$iAllW = $iAll;
|
||||
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
|
||||
|
||||
// Calculate BD count
|
||||
if ($iBdCnt >$i1stBdL)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
$iBdExL++;
|
||||
$iAllW++;
|
||||
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
|
||||
if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save Header
|
||||
fwrite($FILE,
|
||||
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. pack("v", 0x3b)
|
||||
. pack("v", 0x03)
|
||||
. pack("v", -2)
|
||||
. pack("v", 9)
|
||||
. pack("v", 6)
|
||||
. pack("v", 0)
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. pack("V", $iBdCnt)
|
||||
. pack("V", $iBBcnt+$iSBDcnt) //ROOT START
|
||||
. pack("V", 0)
|
||||
. pack("V", 0x1000)
|
||||
. pack("V", 0) //Small Block Depot
|
||||
. pack("V", 1)
|
||||
);
|
||||
// Extra BDList Start, Count
|
||||
if ($iBdCnt < $i1stBdL)
|
||||
{
|
||||
fwrite($FILE,
|
||||
pack("V", -2). // Extra BDList Start
|
||||
pack("V", 0) // Extra BDList Count
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
|
||||
}
|
||||
|
||||
// BDList
|
||||
for ($i=0; $i<$i1stBdL and $i < $iBdCnt; $i++) {
|
||||
fwrite($FILE, pack("V", $iAll+$i));
|
||||
}
|
||||
if ($i < $i1stBdL)
|
||||
{
|
||||
for ($j = 0; $j < ($i1stBdL-$i); $j++) {
|
||||
fwrite($FILE, (pack("V", -1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving big data (PPS's with data bigger than OLE_DATA_SIZE_SMALL)
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iStBlk
|
||||
* @param array &$raList Reference to array of PPS's
|
||||
*/
|
||||
function _saveBigData($iStBlk, &$raList)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
|
||||
// cycle through PPS's
|
||||
for ($i = 0; $i < count($raList); $i++)
|
||||
{
|
||||
if($raList[$i]->Type != OLE_PPS_TYPE_DIR)
|
||||
{
|
||||
$raList[$i]->Size = $raList[$i]->_DataLen();
|
||||
if(($raList[$i]->Size >= OLE_DATA_SIZE_SMALL) or
|
||||
(($raList[$i]->Type == OLE_PPS_TYPE_ROOT) and isset($raList[$i]->_data)))
|
||||
{
|
||||
// Write Data
|
||||
if(isset($raList[$i]->_PPS_FILE))
|
||||
{
|
||||
$iLen = 0;
|
||||
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
|
||||
while($sBuff = fread($raList[$i]->_PPS_FILE, 4096))
|
||||
{
|
||||
$iLen += strlen($sBuff);
|
||||
fwrite($FILE, $sBuff);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fwrite($FILE, $raList[$i]->_data);
|
||||
}
|
||||
|
||||
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)
|
||||
{
|
||||
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); $j++) {
|
||||
fwrite($FILE, "\x00");
|
||||
}
|
||||
}
|
||||
// Set For PPS
|
||||
$raList[$i]->_StartBlock = $iStBlk;
|
||||
$iStBlk +=
|
||||
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
|
||||
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
}
|
||||
// Close file for each PPS, and unlink it
|
||||
if (isset($raList[$i]->_PPS_FILE))
|
||||
{
|
||||
@fclose($raList[$i]->_PPS_FILE);
|
||||
$raList[$i]->_PPS_FILE = null;
|
||||
@unlink($raList[$i]->_tmp_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get small data (PPS's with data smaller than OLE_DATA_SIZE_SMALL)
|
||||
*
|
||||
* @access private
|
||||
* @param array &$raList Reference to array of PPS's
|
||||
*/
|
||||
function _makeSmallData(&$raList)
|
||||
{
|
||||
$sRes = '';
|
||||
$FILE = $this->_FILEH_;
|
||||
$iSmBlk = 0;
|
||||
|
||||
for ($i = 0; $i < count($raList); $i++)
|
||||
{
|
||||
// Make SBD, small data string
|
||||
if ($raList[$i]->Type == OLE_PPS_TYPE_FILE)
|
||||
{
|
||||
if ($raList[$i]->Size <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($raList[$i]->Size < OLE_DATA_SIZE_SMALL)
|
||||
{
|
||||
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
|
||||
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
|
||||
// Add to SBD
|
||||
for ($j = 0; $j < ($iSmbCnt-1); $j++) {
|
||||
fwrite($FILE, pack("V", $j+$iSmBlk+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
|
||||
// Add to Data String(this will be written for RootEntry)
|
||||
if ($raList[$i]->_PPS_FILE)
|
||||
{
|
||||
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
|
||||
while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
|
||||
$sRes .= $sBuff;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sRes .= $raList[$i]->_data;
|
||||
}
|
||||
if($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)
|
||||
{
|
||||
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); $j++) {
|
||||
$sRes .= "\x00";
|
||||
}
|
||||
}
|
||||
// Set for PPS
|
||||
$raList[$i]->_StartBlock = $iSmBlk;
|
||||
$iSmBlk += $iSmbCnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
|
||||
if($iSmBlk % $iSbCnt)
|
||||
{
|
||||
for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all the PPS's WKs
|
||||
*
|
||||
* @access private
|
||||
* @param array $raList Reference to an array with all PPS's
|
||||
*/
|
||||
function _savePps(&$raList)
|
||||
{
|
||||
// Save each PPS WK
|
||||
for ($i = 0; $i < count($raList); $i++) {
|
||||
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
|
||||
}
|
||||
// Adjust for Block
|
||||
$iCnt = count($raList);
|
||||
$iBCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
|
||||
if ($iCnt % $iBCnt)
|
||||
{
|
||||
for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) * OLE_PPS_SIZE); $i++) {
|
||||
fwrite($this->_FILEH_, "\x00");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving Big Block Depot
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iSbdSize
|
||||
* @param integer $iBsize
|
||||
* @param integer $iPpsCnt
|
||||
*/
|
||||
function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
// Calculate Basic Setting
|
||||
$iBbCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
|
||||
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
$iBdExL = 0;
|
||||
$iAll = $iBsize + $iPpsCnt + $iSbdSize;
|
||||
$iAllW = $iAll;
|
||||
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
|
||||
// Calculate BD count
|
||||
if ($iBdCnt >$i1stBdL)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
$iBdExL++;
|
||||
$iAllW++;
|
||||
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
|
||||
if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Making BD
|
||||
// Set for SBD
|
||||
if ($iSbdSize > 0)
|
||||
{
|
||||
for ($i = 0; $i<($iSbdSize-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
}
|
||||
// Set for B
|
||||
for ($i = 0; $i<($iBsize-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+$iSbdSize+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
|
||||
// Set for PPS
|
||||
for ($i = 0; $i<($iPpsCnt-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
// Set for BBD itself ( 0xFFFFFFFD : BBD)
|
||||
for ($i=0; $i<$iBdCnt;$i++) {
|
||||
fwrite($FILE, pack("V", 0xFFFFFFFD));
|
||||
}
|
||||
// Set for ExtraBDList
|
||||
for ($i=0; $i<$iBdExL;$i++) {
|
||||
fwrite($FILE, pack("V", 0xFFFFFFFC));
|
||||
}
|
||||
// Adjust for Block
|
||||
if (($iAllW + $iBdCnt) % $iBbCnt)
|
||||
{
|
||||
for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
// Extra BDList
|
||||
if ($iBdCnt > $i1stBdL)
|
||||
{
|
||||
$iN=0;
|
||||
$iNb=0;
|
||||
for ($i=$i1stBdL;$i<$iBdCnt; $i++, $iN++)
|
||||
{
|
||||
if ($iN>=($iBbCnt-1))
|
||||
{
|
||||
$iN = 0;
|
||||
$iNb++;
|
||||
fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb));
|
||||
}
|
||||
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
|
||||
}
|
||||
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1))
|
||||
{
|
||||
for ($i = 0; $i < (($iBbCnt-1) - (($iBdCnt-$i1stBdL) % ($iBbCnt-1))); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
18
thirdparty/pear/README
vendored
18
thirdparty/pear/README
vendored
@@ -1,18 +0,0 @@
|
||||
PEAR - PHP Extension and Application Repository
|
||||
===============================================
|
||||
Dedicated to Malin Bakken, born 1999-11-21
|
||||
|
||||
WHAT IS PEAR?
|
||||
|
||||
PEAR is a code repository for PHP extensions and PHP library code
|
||||
similar to TeX's CTAN and Perl's CPAN.
|
||||
|
||||
The intention behind PEAR is to provide a means for library code
|
||||
authors to organize their code in a defined way shared by other
|
||||
developers, and to give the PHP community a single source for such
|
||||
code.
|
||||
|
||||
|
||||
DOCUMENTATION
|
||||
|
||||
Documentation for PEAR can be found at http://pear.php.net/manual/.
|
||||
1116
thirdparty/pear/SOAP/Base.php
vendored
1116
thirdparty/pear/SOAP/Base.php
vendored
File diff suppressed because it is too large
Load Diff
855
thirdparty/pear/SOAP/Client.php
vendored
855
thirdparty/pear/SOAP/Client.php
vendored
@@ -1,855 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file contains the code for the SOAP client.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 2.02 of the PHP license,
|
||||
* that is bundled with this package in the file LICENSE, and is available at
|
||||
* through the world-wide-web at http://www.php.net/license/2_02.txt. If you
|
||||
* did not receive a copy of the PHP license and are unable to obtain it
|
||||
* through the world-wide-web, please send a note to license@php.net so we can
|
||||
* mail you a copy immediately.
|
||||
*
|
||||
* @category Web Services
|
||||
* @package SOAP
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
|
||||
* @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more
|
||||
* @author Chuck Hagenbuch <chuck@horde.org> Maintenance
|
||||
* @author Jan Schneider <jan@horde.org> Maintenance
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.php.net/license/2_02.txt PHP License 2.02
|
||||
* @link http://pear.php.net/package/SOAP
|
||||
*/
|
||||
|
||||
require_once 'SOAP/Value.php';
|
||||
require_once 'SOAP/Base.php';
|
||||
require_once 'SOAP/Transport.php';
|
||||
require_once 'SOAP/WSDL.php';
|
||||
require_once 'SOAP/Fault.php';
|
||||
require_once 'SOAP/Parser.php';
|
||||
|
||||
// Arnaud: the following code was taken from DataObject and adapted to suit
|
||||
|
||||
// this will be horrifically slow!!!!
|
||||
// NOTE: Overload SEGFAULTS ON PHP4 + Zend Optimizer
|
||||
// these two are BC/FC handlers for call in PHP4/5
|
||||
|
||||
if (!class_exists('SOAP_Client_Overload')) {
|
||||
if (substr(zend_version(), 0, 1) > 1) {
|
||||
class SOAP_Client_Overload extends SOAP_Base {
|
||||
function __call($method, $args)
|
||||
{
|
||||
$return = null;
|
||||
$this->_call($method, $args, $return);
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!function_exists('clone')) {
|
||||
eval('function clone($t) { return $t; }');
|
||||
}
|
||||
eval('
|
||||
class SOAP_Client_Overload extends SOAP_Base {
|
||||
function __call($method, $args, &$return)
|
||||
{
|
||||
return $this->_call($method, $args, $return);
|
||||
}
|
||||
}');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SOAP Client Class
|
||||
*
|
||||
* This class is the main interface for making soap requests.
|
||||
*
|
||||
* basic usage:<code>
|
||||
* $soapclient = new SOAP_Client( string path [ , boolean wsdl] );
|
||||
* echo $soapclient->call( string methodname [ , array parameters] );
|
||||
* </code>
|
||||
* or, if using PHP 5+ or the overload extension:<code>
|
||||
* $soapclient = new SOAP_Client( string path [ , boolean wsdl] );
|
||||
* echo $soapclient->methodname( [ array parameters] );
|
||||
* </code>
|
||||
*
|
||||
* Originally based on SOAPx4 by Dietrich Ayala
|
||||
* http://dietrich.ganx4.com/soapx4
|
||||
*
|
||||
* @access public
|
||||
* @package SOAP
|
||||
* @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
|
||||
* @author Stig Bakken <ssb@fast.no> Conversion to PEAR
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
|
||||
*/
|
||||
class SOAP_Client extends SOAP_Client_Overload
|
||||
{
|
||||
/**
|
||||
* Communication endpoint.
|
||||
*
|
||||
* Currently the following transport formats are supported:
|
||||
* - HTTP
|
||||
* - SMTP
|
||||
*
|
||||
* Example endpoints:
|
||||
* http://www.example.com/soap/server.php
|
||||
* https://www.example.com/soap/server.php
|
||||
* mailto:soap@example.com
|
||||
*
|
||||
* @see SOAP_Client()
|
||||
* @var string
|
||||
*/
|
||||
var $_endpoint = '';
|
||||
|
||||
/**
|
||||
* The SOAP PORT name that is used by the client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_portName = '';
|
||||
|
||||
/**
|
||||
* Endpoint type e.g. 'wdsl'.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_endpointType = '';
|
||||
|
||||
/**
|
||||
* The received xml.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $xml;
|
||||
|
||||
/**
|
||||
* The outgoing and incoming data stream for debugging.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $wire;
|
||||
|
||||
/**
|
||||
* The outgoing data stream for debugging.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_last_request = null;
|
||||
|
||||
/**
|
||||
* The incoming data stream for debugging.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_last_response = null;
|
||||
|
||||
/**
|
||||
* Options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_options = array('trace' => false);
|
||||
|
||||
/**
|
||||
* The character encoding used for XML parser, etc.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_encoding = SOAP_DEFAULT_ENCODING;
|
||||
|
||||
/**
|
||||
* The array of SOAP_Headers that we are sending.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $headersOut = null;
|
||||
|
||||
/**
|
||||
* The headers we recieved back in the response.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $headersIn = null;
|
||||
|
||||
/**
|
||||
* Options for the HTTP_Request class (see HTTP/Request.php).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_proxy_params = array();
|
||||
|
||||
/**
|
||||
* The SOAP_Transport instance.
|
||||
*
|
||||
* @var SOAP_Transport
|
||||
*/
|
||||
var $_soap_transport = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $endpoint An URL.
|
||||
* @param boolean $wsdl Whether the endpoint is a WSDL file.
|
||||
* @param string $portName The service's port name to use.
|
||||
* @param array $proxy_params Options for the HTTP_Request class
|
||||
* @see HTTP_Request
|
||||
* @param boolean|string $cache Use WSDL caching? The cache directory if
|
||||
* a string.
|
||||
*/
|
||||
function SOAP_Client($endpoint, $wsdl = false, $portName = false,
|
||||
$proxy_params = array(), $cache = false)
|
||||
{
|
||||
parent::SOAP_Base('Client');
|
||||
|
||||
$this->_endpoint = $endpoint;
|
||||
$this->_portName = $portName;
|
||||
$this->_proxy_params = $proxy_params;
|
||||
|
||||
// This hack should perhaps be removed as it might cause unexpected
|
||||
// behaviour.
|
||||
$wsdl = $wsdl
|
||||
? $wsdl
|
||||
: strtolower(substr($endpoint, -4)) == 'wsdl';
|
||||
|
||||
// make values
|
||||
if ($wsdl) {
|
||||
$this->_endpointType = 'wsdl';
|
||||
// instantiate wsdl class
|
||||
$this->_wsdl = new SOAP_WSDL($this->_endpoint,
|
||||
$this->_proxy_params,
|
||||
$cache);
|
||||
if ($this->_wsdl->fault) {
|
||||
$this->_raiseSoapFault($this->_wsdl->fault);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _reset()
|
||||
{
|
||||
$this->xml = null;
|
||||
$this->wire = null;
|
||||
$this->_last_request = null;
|
||||
$this->_last_response = null;
|
||||
$this->headersIn = null;
|
||||
$this->headersOut = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character encoding.
|
||||
*
|
||||
* Limited to 'UTF-8', 'US_ASCII' and 'ISO-8859-1'.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string encoding
|
||||
*
|
||||
* @return mixed SOAP_Fault on error.
|
||||
*/
|
||||
function setEncoding($encoding)
|
||||
{
|
||||
if (in_array($encoding, $this->_encodings)) {
|
||||
$this->_encoding = $encoding;
|
||||
return;
|
||||
}
|
||||
return $this->_raiseSoapFault('Invalid Encoding');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a header to the envelope.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param SOAP_Header $soap_value A SOAP_Header or an array with the
|
||||
* elements 'name', 'namespace',
|
||||
* 'mustunderstand', and 'actor' to send
|
||||
* as a header.
|
||||
*/
|
||||
function addHeader($soap_value)
|
||||
{
|
||||
// Add a new header to the message.
|
||||
if (is_a($soap_value, 'SOAP_Header')) {
|
||||
$this->headersOut[] = $soap_value;
|
||||
} elseif (is_array($soap_value)) {
|
||||
// name, value, namespace, mustunderstand, actor
|
||||
$this->headersOut[] = new SOAP_Header($soap_value[0],
|
||||
null,
|
||||
$soap_value[1],
|
||||
$soap_value[2],
|
||||
$soap_value[3]);
|
||||
} else {
|
||||
$this->_raiseSoapFault('Invalid parameter provided to addHeader(). Must be an array or a SOAP_Header.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a method on the SOAP endpoint.
|
||||
*
|
||||
* The namespace parameter is overloaded to accept an array of options
|
||||
* that can contain data necessary for various transports if it is used as
|
||||
* an array, it MAY contain a namespace value and a soapaction value. If
|
||||
* it is overloaded, the soapaction parameter is ignored and MUST be
|
||||
* placed in the options array. This is done to provide backwards
|
||||
* compatibility with current clients, but may be removed in the future.
|
||||
* The currently supported values are:<pre>
|
||||
* namespace
|
||||
* soapaction
|
||||
* timeout (HTTP socket timeout)
|
||||
* transfer-encoding (SMTP, Content-Transfer-Encoding: header)
|
||||
* from (SMTP, From: header)
|
||||
* subject (SMTP, Subject: header)
|
||||
* headers (SMTP, hash of extra SMTP headers)
|
||||
* </pre>
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $method The method to call.
|
||||
* @param array $params The method parameters.
|
||||
* @param string|array $namespace Namespace or hash with options.
|
||||
* @param string $soapAction
|
||||
*
|
||||
* @return mixed The method result or a SOAP_Fault on error.
|
||||
*/
|
||||
function &call($method, &$params, $namespace = false, $soapAction = false)
|
||||
{
|
||||
$this->headersIn = null;
|
||||
$this->_last_request = null;
|
||||
$this->_last_response = null;
|
||||
$this->wire = null;
|
||||
$this->xml = null;
|
||||
|
||||
$soap_data = $this->_generate($method, $params, $namespace, $soapAction);
|
||||
if (PEAR::isError($soap_data)) {
|
||||
$fault = $this->_raiseSoapFault($soap_data);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
// _generate() may have changed the endpoint if the WSDL has more
|
||||
// than one service, so we need to see if we need to generate a new
|
||||
// transport to hook to a different URI. Since the transport protocol
|
||||
// can also change, we need to get an entirely new object. This could
|
||||
// probably be optimized.
|
||||
if (!$this->_soap_transport ||
|
||||
$this->_endpoint != $this->_soap_transport->url) {
|
||||
$this->_soap_transport =& SOAP_Transport::getTransport($this->_endpoint);
|
||||
if (PEAR::isError($this->_soap_transport)) {
|
||||
$fault =& $this->_soap_transport;
|
||||
$this->_soap_transport = null;
|
||||
$fault = $this->_raiseSoapFault($fault);
|
||||
return $fault;
|
||||
}
|
||||
}
|
||||
$this->_soap_transport->encoding = $this->_encoding;
|
||||
|
||||
// Send the message.
|
||||
$transport_options = array_merge_recursive($this->_proxy_params,
|
||||
$this->_options);
|
||||
$this->xml = $this->_soap_transport->send($soap_data, $transport_options);
|
||||
|
||||
// Save the wire information for debugging.
|
||||
if ($this->_options['trace']) {
|
||||
$this->_last_request = $this->_soap_transport->outgoing_payload;
|
||||
$this->_last_response = $this->_soap_transport->incoming_payload;
|
||||
$this->wire = $this->getWire();
|
||||
}
|
||||
if ($this->_soap_transport->fault) {
|
||||
$fault = $this->_raiseSoapFault($this->xml);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
if (isset($this->_options['result']) &&
|
||||
$this->_options['result'] != 'parse') {
|
||||
return $this->xml;
|
||||
}
|
||||
|
||||
$this->__result_encoding = $this->_soap_transport->result_encoding;
|
||||
|
||||
$result = &$this->parseResponse($this->xml, $this->__result_encoding,
|
||||
$this->_soap_transport->attachments);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option to use with the transport layers.
|
||||
*
|
||||
* For example:
|
||||
* <code>
|
||||
* $soapclient->setOpt('curl', CURLOPT_VERBOSE, 1)
|
||||
* </code>
|
||||
* to pass a specific option to curl if using an SSL connection.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $category Category to which the option applies or option
|
||||
* name.
|
||||
* @param string $option An option name if $category is a category name,
|
||||
* an option value if $category is an option name.
|
||||
* @param string $value An option value if $category is a category
|
||||
* name.
|
||||
*/
|
||||
function setOpt($category, $option, $value = null)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
if (!isset($this->_options[$category])) {
|
||||
$this->_options[$category] = array();
|
||||
}
|
||||
$this->_options[$category][$option] = $value;
|
||||
} else {
|
||||
$this->_options[$category] = $option;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call method supporting the overload extension.
|
||||
*
|
||||
* If the overload extension is loaded, you can call the client class with
|
||||
* a soap method name:
|
||||
* <code>
|
||||
* $soap = new SOAP_Client(....);
|
||||
* $value = $soap->getStockQuote('MSFT');
|
||||
* </code>
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $method The method to call.
|
||||
* @param array $params The method parameters.
|
||||
* @param mixed $return_value Will get the method's return value
|
||||
* assigned.
|
||||
*
|
||||
* @return boolean Always true.
|
||||
*/
|
||||
function _call($method, $params, &$return_value)
|
||||
{
|
||||
// Overloading lowercases the method name, we need to look into the
|
||||
// WSDL and try to find the correct method name to get the correct
|
||||
// case for the call.
|
||||
if ($this->_wsdl) {
|
||||
$this->_wsdl->matchMethod($method);
|
||||
}
|
||||
|
||||
$return_value =& $this->call($method, $params);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getLastRequest().
|
||||
*/
|
||||
function &__getlastrequest()
|
||||
{
|
||||
$request = $this->getLastRequest();
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XML content of the last SOAP request.
|
||||
*
|
||||
* @return string The last request.
|
||||
*/
|
||||
function getLastRequest()
|
||||
{
|
||||
return $this->_last_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getLastResponse().
|
||||
*/
|
||||
function &__getlastresponse()
|
||||
{
|
||||
$response =& $this->getLastResponse;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XML content of the last SOAP response.
|
||||
*
|
||||
* @return string The last response.
|
||||
*/
|
||||
function getLastResponse()
|
||||
{
|
||||
return $this->_last_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use setUse().
|
||||
*/
|
||||
function __use($use)
|
||||
{
|
||||
$this->setUse($use);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SOAP encoding.
|
||||
*
|
||||
* @param string $use Either 'literal' or 'encoded' (section 5).
|
||||
*/
|
||||
function setUse($use)
|
||||
{
|
||||
$this->_options['use'] = $use;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use setStyle().
|
||||
*/
|
||||
function __style($style)
|
||||
{
|
||||
$this->setStyle($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SOAP encoding style.
|
||||
*
|
||||
* @param string $style Either 'document' or 'rpc'.
|
||||
*/
|
||||
function setStyle($style)
|
||||
{
|
||||
$this->_options['style'] = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use setTrace().
|
||||
*/
|
||||
function __trace($level)
|
||||
{
|
||||
$this->setTrace($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to trace the traffic on the transport level.
|
||||
*
|
||||
* @see getWire()
|
||||
*
|
||||
* @param boolean $trace
|
||||
*/
|
||||
function setTrace($trace)
|
||||
{
|
||||
$this->_options['trace'] = $trace;
|
||||
}
|
||||
|
||||
function _generate($method, &$params, $namespace = false,
|
||||
$soapAction = false)
|
||||
{
|
||||
$this->fault = null;
|
||||
$this->_options['input'] = 'parse';
|
||||
$this->_options['result'] = 'parse';
|
||||
$this->_options['parameters'] = false;
|
||||
|
||||
if ($params && gettype($params) != 'array') {
|
||||
$params = array($params);
|
||||
}
|
||||
|
||||
if (gettype($namespace) == 'array') {
|
||||
foreach ($namespace as $optname => $opt) {
|
||||
$this->_options[strtolower($optname)] = $opt;
|
||||
}
|
||||
if (isset($this->_options['namespace'])) {
|
||||
$namespace = $this->_options['namespace'];
|
||||
} else {
|
||||
$namespace = false;
|
||||
}
|
||||
} else {
|
||||
// We'll place $soapAction into our array for usage in the
|
||||
// transport.
|
||||
$this->_options['soapaction'] = $soapAction;
|
||||
$this->_options['namespace'] = $namespace;
|
||||
}
|
||||
|
||||
if ($this->_endpointType == 'wsdl') {
|
||||
$this->_setSchemaVersion($this->_wsdl->xsd);
|
||||
|
||||
// Get port name.
|
||||
if (!$this->_portName) {
|
||||
$this->_portName = $this->_wsdl->getPortName($method);
|
||||
}
|
||||
if (PEAR::isError($this->_portName)) {
|
||||
return $this->_raiseSoapFault($this->_portName);
|
||||
}
|
||||
|
||||
// Get endpoint.
|
||||
$this->_endpoint = $this->_wsdl->getEndpoint($this->_portName);
|
||||
if (PEAR::isError($this->_endpoint)) {
|
||||
return $this->_raiseSoapFault($this->_endpoint);
|
||||
}
|
||||
|
||||
// Get operation data.
|
||||
$opData = $this->_wsdl->getOperationData($this->_portName, $method);
|
||||
|
||||
if (PEAR::isError($opData)) {
|
||||
return $this->_raiseSoapFault($opData);
|
||||
}
|
||||
$namespace = $opData['namespace'];
|
||||
$this->_options['style'] = $opData['style'];
|
||||
$this->_options['use'] = $opData['input']['use'];
|
||||
$this->_options['soapaction'] = $opData['soapAction'];
|
||||
|
||||
// Set input parameters.
|
||||
if ($this->_options['input'] == 'parse') {
|
||||
$this->_options['parameters'] = $opData['parameters'];
|
||||
$nparams = array();
|
||||
if (isset($opData['input']['parts']) &&
|
||||
count($opData['input']['parts'])) {
|
||||
foreach ($opData['input']['parts'] as $name => $part) {
|
||||
$xmlns = '';
|
||||
$attrs = array();
|
||||
// Is the name a complex type?
|
||||
if (isset($part['element'])) {
|
||||
$xmlns = $this->_wsdl->namespaces[$part['namespace']];
|
||||
$part = $this->_wsdl->elements[$part['namespace']][$part['type']];
|
||||
$name = $part['name'];
|
||||
}
|
||||
if (isset($params[$name]) ||
|
||||
$this->_wsdl->getDataHandler($name, $part['namespace'])) {
|
||||
$nparams[$name] =& $params[$name];
|
||||
} else {
|
||||
// We now force an associative array for
|
||||
// parameters if using WSDL.
|
||||
return $this->_raiseSoapFault("The named parameter $name is not in the call parameters.");
|
||||
}
|
||||
if (gettype($nparams[$name]) != 'object' ||
|
||||
!is_a($nparams[$name], 'SOAP_Value')) {
|
||||
// Type is likely a qname, split it apart, and get
|
||||
// the type namespace from WSDL.
|
||||
$qname = new QName($part['type']);
|
||||
if ($qname->ns) {
|
||||
$type_namespace = $this->_wsdl->namespaces[$qname->ns];
|
||||
} elseif (isset($part['namespace'])) {
|
||||
$type_namespace = $this->_wsdl->namespaces[$part['namespace']];
|
||||
} else {
|
||||
$type_namespace = null;
|
||||
}
|
||||
$qname->namespace = $type_namespace;
|
||||
$pqname = $name;
|
||||
if ($xmlns) {
|
||||
$pqname = '{' . $xmlns . '}' . $name;
|
||||
}
|
||||
$nparams[$name] = new SOAP_Value($pqname,
|
||||
$qname->fqn(),
|
||||
$nparams[$name],
|
||||
$attrs);
|
||||
} else {
|
||||
// WSDL fixups to the SOAP value.
|
||||
}
|
||||
}
|
||||
}
|
||||
$params =& $nparams;
|
||||
unset($nparams);
|
||||
}
|
||||
} else {
|
||||
$this->_setSchemaVersion(SOAP_XML_SCHEMA_VERSION);
|
||||
}
|
||||
|
||||
// Serialize the message.
|
||||
$this->_section5 = (!isset($this->_options['use']) ||
|
||||
$this->_options['use'] != 'literal');
|
||||
|
||||
if (!isset($this->_options['style']) ||
|
||||
$this->_options['style'] == 'rpc') {
|
||||
$this->_options['style'] = 'rpc';
|
||||
$this->docparams = true;
|
||||
$mqname = new QName($method, $namespace);
|
||||
$methodValue = new SOAP_Value($mqname->fqn(), 'Struct', $params);
|
||||
$soap_msg = $this->makeEnvelope($methodValue,
|
||||
$this->headersOut,
|
||||
$this->_encoding,
|
||||
$this->_options);
|
||||
} else {
|
||||
if (!$params) {
|
||||
$mqname = new QName($method, $namespace);
|
||||
$mynull = null;
|
||||
$params = new SOAP_Value($mqname->fqn(), 'Struct', $mynull);
|
||||
} elseif ($this->_options['input'] == 'parse') {
|
||||
if (is_array($params)) {
|
||||
$nparams = array();
|
||||
$keys = array_keys($params);
|
||||
foreach ($keys as $k) {
|
||||
if (gettype($params[$k]) != 'object') {
|
||||
$nparams[] = new SOAP_Value($k,
|
||||
false,
|
||||
$params[$k]);
|
||||
} else {
|
||||
$nparams[] =& $params[$k];
|
||||
}
|
||||
}
|
||||
$params =& $nparams;
|
||||
}
|
||||
if ($this->_options['parameters']) {
|
||||
$mqname = new QName($method, $namespace);
|
||||
$params = new SOAP_Value($mqname->fqn(),
|
||||
'Struct',
|
||||
$params);
|
||||
}
|
||||
}
|
||||
$soap_msg = $this->makeEnvelope($params,
|
||||
$this->headersOut,
|
||||
$this->_encoding,
|
||||
$this->_options);
|
||||
}
|
||||
unset($this->headersOut);
|
||||
|
||||
if (PEAR::isError($soap_msg)) {
|
||||
return $this->_raiseSoapFault($soap_msg);
|
||||
}
|
||||
|
||||
// Handle MIME or DIME encoding.
|
||||
// TODO: DIME encoding should move to the transport, do it here for
|
||||
// now and for ease of getting it done.
|
||||
if (count($this->_attachments)) {
|
||||
if ((isset($this->_options['attachments']) &&
|
||||
$this->_options['attachments'] == 'Mime') ||
|
||||
isset($this->_options['Mime'])) {
|
||||
$soap_msg = $this->_makeMimeMessage($soap_msg, $this->_encoding);
|
||||
} else {
|
||||
// default is dime
|
||||
$soap_msg = $this->_makeDIMEMessage($soap_msg, $this->_encoding);
|
||||
$this->_options['headers']['Content-Type'] = 'application/dime';
|
||||
}
|
||||
if (PEAR::isError($soap_msg)) {
|
||||
return $this->_raiseSoapFault($soap_msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate client.
|
||||
if (is_array($soap_msg)) {
|
||||
$soap_data = $soap_msg['body'];
|
||||
if (count($soap_msg['headers'])) {
|
||||
if (isset($this->_options['headers'])) {
|
||||
$this->_options['headers'] = array_merge($this->_options['headers'], $soap_msg['headers']);
|
||||
} else {
|
||||
$this->_options['headers'] = $soap_msg['headers'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$soap_data = $soap_msg;
|
||||
}
|
||||
|
||||
return $soap_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use parseResponse().
|
||||
*/
|
||||
function &__parse(&$response, $encoding, &$attachments)
|
||||
{
|
||||
return $this->parseResponse($response, $encoding, $attachments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a SOAP response.
|
||||
*
|
||||
* @see SOAP_Parser::
|
||||
*
|
||||
* @param string $response XML content of SOAP response.
|
||||
* @param string $encoding Character set encoding, defaults to 'UTF-8'.
|
||||
* @param array $attachments List of attachments.
|
||||
*/
|
||||
function &parseResponse($response, $encoding, &$attachments)
|
||||
{
|
||||
// Parse the response.
|
||||
$response = new SOAP_Parser($response, $encoding, $attachments);
|
||||
if ($response->fault) {
|
||||
$fault =& $this->_raiseSoapFault($response->fault);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
// Return array of parameters.
|
||||
$return =& $response->getResponse();
|
||||
$headers =& $response->getHeaders();
|
||||
if ($headers) {
|
||||
$this->headersIn =& $this->_decodeResponse($headers, false);
|
||||
}
|
||||
|
||||
$decoded = &$this->_decodeResponse($return);
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a complex SOAP_Value into a PHP Array
|
||||
*
|
||||
* @param SOAP_Value $response value object
|
||||
* @param boolean $shift FIXME
|
||||
* @return Array
|
||||
*/
|
||||
function &_decodeResponse($response, $shift = true)
|
||||
{
|
||||
if (!$response) {
|
||||
$decoded = null;
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
// Check for valid response.
|
||||
if (PEAR::isError($response)) {
|
||||
$fault =& $this->_raiseSoapFault($response);
|
||||
return $fault;
|
||||
} elseif (!is_a($response, 'soap_value')) {
|
||||
$fault =& $this->_raiseSoapFault("Didn't get SOAP_Value object back from client");
|
||||
return $fault;
|
||||
}
|
||||
|
||||
// Decode to native php datatype.
|
||||
$returnArray =& $this->_decode($response);
|
||||
|
||||
// Fault?
|
||||
if (PEAR::isError($returnArray)) {
|
||||
$fault =& $this->_raiseSoapFault($returnArray);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
if (is_object($returnArray) &&
|
||||
strcasecmp(get_class($returnArray), 'stdClass') == 0) {
|
||||
$returnArray = get_object_vars($returnArray);
|
||||
}
|
||||
if (is_array($returnArray)) {
|
||||
if (isset($returnArray['faultcode']) ||
|
||||
isset($returnArray['SOAP-ENV:faultcode'])) {
|
||||
$faultcode = $faultstring = $faultdetail = $faultactor = '';
|
||||
foreach ($returnArray as $k => $v) {
|
||||
if (stristr($k, 'faultcode')) $faultcode = $v;
|
||||
if (stristr($k, 'faultstring')) $faultstring = $v;
|
||||
if (stristr($k, 'detail')) $faultdetail = $v;
|
||||
if (stristr($k, 'faultactor')) $faultactor = $v;
|
||||
}
|
||||
$fault =& $this->_raiseSoapFault($faultstring, $faultdetail, $faultactor, $faultcode);
|
||||
return $fault;
|
||||
}
|
||||
// Return array of return values.
|
||||
if ($shift && count($returnArray) == 1) {
|
||||
$decoded = array_shift($returnArray);
|
||||
return $decoded;
|
||||
}
|
||||
return $returnArray;
|
||||
}
|
||||
return $returnArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getWire().
|
||||
*/
|
||||
function __get_wire()
|
||||
{
|
||||
return $this->getWire();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the outgoing and incoming traffic on the transport level.
|
||||
*
|
||||
* Tracing has to be enabled.
|
||||
*
|
||||
* @see setTrace()
|
||||
*
|
||||
* @return string The complete traffic between the client and the server.
|
||||
*/
|
||||
function getWire()
|
||||
{
|
||||
if ($this->_options['trace'] &&
|
||||
($this->_last_request || $this->_last_response)) {
|
||||
return "OUTGOING:\n\n" .
|
||||
$this->_last_request .
|
||||
"\n\nINCOMING\n\n" .
|
||||
preg_replace("/></",">\r\n<", $this->_last_response);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
383
thirdparty/pear/SOAP/Disco.php
vendored
383
thirdparty/pear/SOAP/Disco.php
vendored
@@ -1,383 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file contains the code for the DISCO server, providing DISO and WSDL
|
||||
* services.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 2.02 of the PHP license,
|
||||
* that is bundled with this package in the file LICENSE, and is available at
|
||||
* through the world-wide-web at http://www.php.net/license/2_02.txt. If you
|
||||
* did not receive a copy of the PHP license and are unable to obtain it
|
||||
* through the world-wide-web, please send a note to license@php.net so we can
|
||||
* mail you a copy immediately.
|
||||
*
|
||||
* @category Web Services
|
||||
* @package SOAP
|
||||
* @author Dmitri Vinogradov <dimitri@vinogradov.de>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @author Jan Schneider <jan@horde.org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.php.net/license/2_02.txt PHP License 2.02
|
||||
* @link http://pear.php.net/package/SOAP
|
||||
*/
|
||||
|
||||
require_once 'SOAP/Base.php';
|
||||
|
||||
class SOAP_DISCO_Server extends SOAP_Base_Object {
|
||||
|
||||
var $namespaces = array(SCHEMA_WSDL => 'wsdl', SCHEMA_SOAP => 'soap');
|
||||
var $import_ns = array();
|
||||
var $wsdl = '';
|
||||
var $disco = '';
|
||||
var $_wsdl = array();
|
||||
var $_disco = array();
|
||||
var $_service_name = '';
|
||||
var $_service_ns = '';
|
||||
var $_service_desc = '';
|
||||
var $_portname = '';
|
||||
var $_bindingname = '';
|
||||
var $soap_server = NULL;
|
||||
|
||||
|
||||
function SOAP_DISCO_Server($soap_server, $service_name, $service_desc = '',
|
||||
$import_ns = null)
|
||||
{
|
||||
parent::SOAP_Base_Object('Server');
|
||||
|
||||
if ( !is_object($soap_server)
|
||||
|| !get_class($soap_server) == 'soap_server') return;
|
||||
|
||||
$this->_service_name = $service_name;
|
||||
$this->_service_ns = "urn:$service_name";
|
||||
$this->_service_desc = $service_desc;
|
||||
$this->import_ns = isset($import_ns) ? $import_ns : $this->import_ns;
|
||||
$this->soap_server = $soap_server;
|
||||
$this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
|
||||
}
|
||||
|
||||
function getDISCO()
|
||||
{
|
||||
$this->_generate_DISCO();
|
||||
return $this->disco;
|
||||
}
|
||||
|
||||
function getWSDL()
|
||||
{
|
||||
$this->_generate_WSDL();
|
||||
return $this->wsdl;
|
||||
}
|
||||
|
||||
function _generate_DISCO()
|
||||
{
|
||||
// DISCO
|
||||
$this->_disco['disco:discovery']['attr']['xmlns:disco'] = SCHEMA_DISCO;
|
||||
$this->_disco['disco:discovery']['attr']['xmlns:scl'] = SCHEMA_DISCO_SCL;
|
||||
$this->_disco['disco:discovery']['scl:contractRef']['attr']['ref'] =
|
||||
(array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on')
|
||||
? 'https://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl'
|
||||
: 'http://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl';
|
||||
|
||||
// generate disco xml
|
||||
$this->_generate_DISCO_XML($this->_disco);
|
||||
}
|
||||
|
||||
function _generate_WSDL()
|
||||
{
|
||||
// WSDL
|
||||
if (is_array($this->soap_server->_namespaces)) {
|
||||
// need to get: typens, xsd & SOAP-ENC
|
||||
$flipped = array_flip($this->soap_server->_namespaces);
|
||||
$this->namespaces[$this->_service_ns] = 'tns';
|
||||
$this->namespaces[$flipped['xsd']] = 'xsd';
|
||||
$this->namespaces[$flipped['SOAP-ENC']] = 'SOAP-ENC';
|
||||
}
|
||||
|
||||
// DEFINITIONS
|
||||
$this->_wsdl['definitions']['attr']['name'] = $this->_service_name;
|
||||
$this->_wsdl['definitions']['attr']['targetNamespace'] = $this->_service_ns;
|
||||
foreach ($this->namespaces as $ns => $prefix) {
|
||||
$this->_wsdl['definitions']['attr']['xmlns:' . $prefix] = $ns;
|
||||
}
|
||||
$this->_wsdl['definitions']['attr']['xmlns'] = SCHEMA_WSDL;
|
||||
|
||||
// Import namespaces. Seems to not work yet: wsdl.exe fom .NET can't
|
||||
// handle imported complete wsdl-definitions.
|
||||
if (count($this->import_ns)) {
|
||||
$i = 0;
|
||||
foreach ($this->import_ns as $_ns => $_location) {
|
||||
$this->_wsdl['definitions']['import'][$i]['attr']['location'] = $_location;
|
||||
$this->_wsdl['definitions']['import'][$i]['attr']['namespace'] = $_ns;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$this->_wsdl['definitions']['types']['attr']['xmlns']='http://schemas.xmlsoap.org/wsdl/';
|
||||
$this->_wsdl['definitions']['types']['schema']=array();
|
||||
|
||||
// Placeholder for messages
|
||||
$this->_wsdl['definitions']['message'] = array();
|
||||
|
||||
// PORTTYPE-NAME
|
||||
$this->_portname = $this->_service_name . 'Port';
|
||||
$this->_wsdl['definitions']['portType']['attr']['name'] = $this->_portname;
|
||||
|
||||
// BINDING-NAME
|
||||
$this->_bindingname = $this->_service_name . 'Binding';
|
||||
$this->_wsdl['definitions']['binding']['attr']['name'] = $this->_bindingname;
|
||||
$this->_wsdl['definitions']['binding']['attr']['type'] = 'tns:' . $this->_portname;
|
||||
$this->_wsdl['definitions']['binding']['soap:binding']['attr']['style'] = 'rpc';
|
||||
$this->_wsdl['definitions']['binding']['soap:binding']['attr']['transport'] = SCHEMA_SOAP_HTTP;
|
||||
|
||||
// SERVICE
|
||||
$this->_wsdl['definitions']['service']['attr']['name'] = $this->_service_name . 'Service';
|
||||
$this->_wsdl['definitions']['service']['documentation']['attr'] = '';
|
||||
$this->_wsdl['definitions']['service']['documentation'] = htmlentities($this->_service_desc);
|
||||
$this->_wsdl['definitions']['service']['port']['attr']['name'] = $this->_portname;
|
||||
$this->_wsdl['definitions']['service']['port']['attr']['binding'] = 'tns:' . $this->_bindingname;
|
||||
$this->_wsdl['definitions']['service']['port']['soap:address']['attr']['location'] =
|
||||
(array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on')
|
||||
? 'https://' . $this->host . $_SERVER['PHP_SELF']
|
||||
: 'http://' . $this->host . $_SERVER['PHP_SELF'];
|
||||
|
||||
//
|
||||
$dispatch_keys = array_keys($this->soap_server->dispatch_objects);
|
||||
$dc = count($dispatch_keys);
|
||||
for ($di = 0; $di < $dc; $di++) {
|
||||
$namespace = $dispatch_keys[$di];
|
||||
$namespace_objects =& $this->soap_server->dispatch_objects[$namespace];
|
||||
$oc = count($namespace_objects);
|
||||
for ($oi = 0; $oi < $oc; $oi++) {
|
||||
$object = $namespace_objects[$oi];
|
||||
// types definitions
|
||||
$this->addSchemaFromMap($object->__typedef);
|
||||
// MESSAGES
|
||||
$this->addMethodsFromMap($object->__dispatch_map, $namespace, get_class($object));
|
||||
}
|
||||
}
|
||||
if (isset($this->soap_server->dispatch_map)) {
|
||||
$this->addMethodsFromMap($this->soap_server->dispatch_map, $namespace);
|
||||
}
|
||||
|
||||
// generate wsdl
|
||||
$this->_generate_WSDL_XML();
|
||||
}
|
||||
|
||||
function &_getSchema($namespace)
|
||||
{
|
||||
// SCHEMA
|
||||
$c = count($this->_wsdl['definitions']['types']['schema']);
|
||||
for($i = 0; $i < $c; $i++) {
|
||||
if ($this->_wsdl['definitions']['types']['schema'][$i]['attr']['targetNamespace'] == $namespace) {
|
||||
return $this->_wsdl['definitions']['types']['schema'][$i];
|
||||
}
|
||||
}
|
||||
|
||||
// don't have this namespace
|
||||
$schema = array();
|
||||
$schema['attr'] = array();
|
||||
$schema['complexType'] = array();
|
||||
$schema['attr']['xmlns'] = array_search('xsd',$this->namespaces);
|
||||
$schema['attr']['targetNamespace'] = $namespace;
|
||||
$this->_wsdl['definitions']['types']['schema'][] =& $schema;
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
function addSchemaFromMap(&$map)
|
||||
{
|
||||
if (!$map) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($map as $_type_name => $_type_def) {
|
||||
list($typens,$type) = $this->_getTypeNs($_type_name);
|
||||
if ($typens == 'xsd') {
|
||||
// cannot add to xsd, lets use method_namespace
|
||||
$typens = 'tns';
|
||||
}
|
||||
$schema =& $this->_getSchema(array_search($typens, $this->namespaces));
|
||||
if (!$this->_ifComplexTypeExists($schema['complexType'], $type)) {
|
||||
$ctype =& $schema['complexType'][];
|
||||
$ctype['attr']['name'] = $type;
|
||||
foreach ($_type_def as $_varname => $_vartype) {
|
||||
if (!is_int($_varname)) {
|
||||
list($_vartypens,$_vartype) = $this->_getTypeNs($_vartype);
|
||||
$ctype['all']['attr'] = '';
|
||||
$el =& $ctype['all']['element'][];
|
||||
$el['attr']['name'] = $_varname;
|
||||
$el['attr']['type'] = $_vartypens . ':' . $_vartype;
|
||||
} else {
|
||||
$ctype['complexContent']['attr'] = '';
|
||||
$ctype['complexContent']['restriction']['attr']['base'] = 'SOAP-ENC:Array';
|
||||
foreach ($_vartype as $array_type) {
|
||||
list($_vartypens, $_vartype) = $this->_getTypeNs($array_type);
|
||||
$ctype['complexContent']['restriction']['attribute']['attr']['ref'] = 'SOAP-ENC:arrayType';
|
||||
$ctype['complexContent']['restriction']['attribute']['attr']['wsdl:arrayType'] = $_vartypens . ':' . $_vartype . '[]';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMethodsFromMap(&$map, $namespace, $classname = null)
|
||||
{
|
||||
if (!$map) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($map as $method_name => $method_types) {
|
||||
if (array_key_exists('namespace', $method_types)) {
|
||||
$method_namespace = $method_types['namespace'];
|
||||
} else {
|
||||
$method_namespace = $namespace;
|
||||
}
|
||||
|
||||
// INPUT
|
||||
$input_message = array('attr' => array('name' => $method_name . 'Request'));
|
||||
if (isset($method_types['in']) && is_array($method_types['in'])) {
|
||||
foreach ($method_types['in'] as $name => $type) {
|
||||
list($typens, $type) = $this->_getTypeNs($type);
|
||||
$part = array();
|
||||
$part['attr']['name'] = $name;
|
||||
$part['attr']['type'] = $typens . ':' . $type;
|
||||
$input_message['part'][] = $part;
|
||||
}
|
||||
}
|
||||
$this->_wsdl['definitions']['message'][] = $input_message;
|
||||
|
||||
// OUTPUT
|
||||
$output_message = array('attr' => array('name' => $method_name . 'Response'));
|
||||
if (isset($method_types['out']) && is_array($method_types['out'])) {
|
||||
foreach ($method_types['out'] as $name => $type) {
|
||||
list($typens, $type) = $this->_getTypeNs($type);
|
||||
$part = array();
|
||||
$part['attr']['name'] = $name;
|
||||
$part['attr']['type'] = $typens . ':' . $type;
|
||||
$output_message['part'][] = $part;
|
||||
}
|
||||
}
|
||||
$this->_wsdl['definitions']['message'][] = $output_message;
|
||||
|
||||
// PORTTYPES
|
||||
$operation = array();
|
||||
$operation['attr']['name'] = $method_name;
|
||||
// INPUT
|
||||
$operation['input']['attr']['message'] = 'tns:' . $input_message['attr']['name'];
|
||||
// OUTPUT
|
||||
$operation['output']['attr']['message'] = 'tns:' . $output_message['attr']['name'];
|
||||
$this->_wsdl['definitions']['portType']['operation'][] = $operation;
|
||||
|
||||
// BINDING
|
||||
$binding = array();
|
||||
$binding['attr']['name'] = $method_name;
|
||||
$action = $method_namespace . '#' . ($classname ? $classname . '#' : '') . $method_name;
|
||||
$binding['soap:operation']['attr']['soapAction'] = $action;
|
||||
// INPUT
|
||||
$binding['input']['attr'] = '';
|
||||
$binding['input']['soap:body']['attr']['use'] = 'encoded';
|
||||
$binding['input']['soap:body']['attr']['namespace'] = $method_namespace;
|
||||
$binding['input']['soap:body']['attr']['encodingStyle'] = SOAP_SCHEMA_ENCODING;
|
||||
// OUTPUT
|
||||
$binding['output']['attr'] = '';
|
||||
$binding['output']['soap:body']['attr']['use'] = 'encoded';
|
||||
$binding['output']['soap:body']['attr']['namespace'] = $method_namespace;
|
||||
$binding['output']['soap:body']['attr']['encodingStyle'] = SOAP_SCHEMA_ENCODING;
|
||||
$this->_wsdl['definitions']['binding']['operation'][] = $binding;
|
||||
}
|
||||
}
|
||||
|
||||
function _generate_DISCO_XML($disco_array)
|
||||
{
|
||||
$disco = '<?xml version="1.0"?>';
|
||||
foreach ($disco_array as $key => $val) {
|
||||
$disco .= $this->_arrayToNode($key,$val);
|
||||
}
|
||||
$this->disco = $disco;
|
||||
}
|
||||
|
||||
function _generate_WSDL_XML()
|
||||
{
|
||||
$wsdl = '<?xml version="1.0"?>';
|
||||
foreach ($this->_wsdl as $key => $val) {
|
||||
$wsdl .= $this->_arrayToNode($key, $val);
|
||||
}
|
||||
$this->wsdl = $wsdl;
|
||||
}
|
||||
|
||||
function _arrayToNode($node_name = '', $array)
|
||||
{
|
||||
$return = '';
|
||||
if (is_array($array)) {
|
||||
// we have a node if there's key 'attr'
|
||||
if (array_key_exists('attr',$array)) {
|
||||
$return .= "<$node_name";
|
||||
if (is_array($array['attr'])) {
|
||||
foreach ($array['attr'] as $attr_name => $attr_value) {
|
||||
$return .= " $attr_name=\"$attr_value\"";
|
||||
}
|
||||
}
|
||||
|
||||
// unset 'attr' and proceed other childs...
|
||||
unset($array['attr']);
|
||||
|
||||
if (count($array) > 0) {
|
||||
$i = 0;
|
||||
foreach ($array as $child_node_name => $child_node_value) {
|
||||
$return .= $i == 0 ? ">\n" : '';
|
||||
$return .= $this->_arrayToNode($child_node_name,$child_node_value);
|
||||
$i++;
|
||||
}
|
||||
$return .= "</$node_name>\n";
|
||||
} else {
|
||||
$return .= " />\n";
|
||||
}
|
||||
} else {
|
||||
// we have no 'attr' key in array - so it's list of nodes with
|
||||
// the same name ...
|
||||
foreach ($array as $child_node_name => $child_node_value) {
|
||||
$return .= $this->_arrayToNode($node_name,$child_node_value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $array is not an array
|
||||
if ($array !='') {
|
||||
// and its not empty
|
||||
$return .= "<$node_name>$array</$node_name>\n";
|
||||
} else {
|
||||
// and its empty...
|
||||
$return .= "<$node_name />\n";
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function _getTypeNs($type)
|
||||
{
|
||||
preg_match_all("'\{(.*)\}'sm", $type, $m);
|
||||
if (isset($m[1][0]) && $m[1][0] != '') {
|
||||
if (!array_key_exists($m[1][0],$this->namespaces)) {
|
||||
$ns_pref = 'ns' . count($this->namespaces);
|
||||
$this->namespaces[$m[1][0]] = $ns_pref;
|
||||
$this->_wsdl['definitions']['attr']['xmlns:' . $ns_pref] = $m[1][0];
|
||||
}
|
||||
$typens = $this->namespaces[$m[1][0]];
|
||||
$type = ereg_replace($m[0][0],'',$type);
|
||||
} else {
|
||||
$typens = 'xsd';
|
||||
}
|
||||
return array($typens,$type);
|
||||
}
|
||||
|
||||
function _ifComplexTypeExists($typesArray, $type_name)
|
||||
{
|
||||
if (is_array($typesArray)) {
|
||||
foreach ($typesArray as $type_data) {
|
||||
if ($type_data['attr']['name'] == $type_name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
127
thirdparty/pear/SOAP/Fault.php
vendored
127
thirdparty/pear/SOAP/Fault.php
vendored
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file contains the SOAP_Fault class, used for all error objects in this
|
||||
* package.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 2.02 of the PHP license,
|
||||
* that is bundled with this package in the file LICENSE, and is available at
|
||||
* through the world-wide-web at http://www.php.net/license/2_02.txt. If you
|
||||
* did not receive a copy of the PHP license and are unable to obtain it
|
||||
* through the world-wide-web, please send a note to license@php.net so we can
|
||||
* mail you a copy immediately.
|
||||
*
|
||||
* @category Web Services
|
||||
* @package SOAP
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
|
||||
* @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more
|
||||
* @author Chuck Hagenbuch <chuck@horde.org> Maintenance
|
||||
* @author Jan Schneider <jan@horde.org> Maintenance
|
||||
* @copyright 2003-2006 The PHP Group
|
||||
* @license http://www.php.net/license/2_02.txt PHP License 2.02
|
||||
* @link http://pear.php.net/package/SOAP
|
||||
*/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* PEAR::Error wrapper used to match SOAP Faults to PEAR Errors
|
||||
*
|
||||
* SOAP_Fault transmissions normally contain a complete backtrace of the
|
||||
* error. Revealing these details in a public web services is a bad idea
|
||||
* because it can be used by attackers. Backtrace information can be kept out
|
||||
* of SOAP_Fault responses by putting the following code in your script after
|
||||
* your "require_once 'SOAP/Server.php';" line:
|
||||
*
|
||||
* <code>
|
||||
* $skiptrace =& PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
|
||||
* $skiptrace = true;
|
||||
* </code>
|
||||
*
|
||||
* @package SOAP
|
||||
* @access public
|
||||
* @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
|
||||
*/
|
||||
class SOAP_Fault extends PEAR_Error
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $faultstring Message string for fault.
|
||||
* @param mixed $faultcode The faultcode.
|
||||
* @param mixed $faultactor
|
||||
* @param mixed $detail @see PEAR_Error
|
||||
* @param array $mode @see PEAR_Error
|
||||
* @param array $options @see PEAR_Error
|
||||
*/
|
||||
function SOAP_Fault($faultstring = 'unknown error', $faultcode = 'Client',
|
||||
$faultactor = null, $detail = null, $mode = null,
|
||||
$options = null)
|
||||
{
|
||||
parent::PEAR_Error($faultstring, $faultcode, $mode, $options, $detail);
|
||||
if ($faultactor) {
|
||||
$this->error_message_prefix = $faultactor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a SOAP XML message that can be sent as a server response.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function message($encoding = SOAP_DEFAULT_ENCODING)
|
||||
{
|
||||
$msg = new SOAP_Base();
|
||||
$params = array();
|
||||
$params[] = new SOAP_Value('faultcode', 'QName', 'SOAP-ENV:' . $this->code);
|
||||
$params[] = new SOAP_Value('faultstring', 'string', $this->message);
|
||||
$params[] = new SOAP_Value('faultactor', 'anyURI', $this->error_message_prefix);
|
||||
if (isset($this->backtrace)) {
|
||||
$params[] = new SOAP_Value('detail', 'string', $this->backtrace);
|
||||
} else {
|
||||
$params[] = new SOAP_Value('detail', 'string', $this->userinfo);
|
||||
}
|
||||
|
||||
$methodValue = new SOAP_Value('{' . SOAP_ENVELOP . '}Fault', 'Struct', $params);
|
||||
$headers = null;
|
||||
return $msg->makeEnvelope($methodValue, $headers, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple native PHP array containing the fault data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFault()
|
||||
{
|
||||
$fault = new stdClass();
|
||||
$fault->faultcode = $this->code;
|
||||
$fault->faultstring = $this->message;
|
||||
$fault->faultactor = $this->error_message_prefix;
|
||||
$fault->detail = $this->userinfo;
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SOAP actor for the fault.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getActor()
|
||||
{
|
||||
return $this->error_message_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fault detail.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getDetail()
|
||||
{
|
||||
return $this->userinfo;
|
||||
}
|
||||
|
||||
}
|
||||
4
thirdparty/pear/SOAP/Interop/config.php.dist
vendored
4
thirdparty/pear/SOAP/Interop/config.php.dist
vendored
@@ -1,4 +0,0 @@
|
||||
<?php
|
||||
// configuration items
|
||||
$interopConfig['DSN'] = 'mysql://user@localhost/soapinterop';
|
||||
$interopConfig['basedir'] = '/soap_interop/';
|
||||
94
thirdparty/pear/SOAP/Interop/index.php
vendored
94
thirdparty/pear/SOAP/Interop/index.php
vendored
@@ -1,94 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>PEAR SOAP Interop</title>
|
||||
</head>
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
require_once 'registrationAndNotification.php';
|
||||
|
||||
$tests = array('Round 2 Base',
|
||||
'Round 2 Group B',
|
||||
'Round 2 Group C',
|
||||
'Round 3 Group D Compound 1',
|
||||
'Round 3 Group D Compound 2',
|
||||
'Round 3 Group D DocLit',
|
||||
'Round 3 Group D DocLitParams',
|
||||
'Round 3 Group D Import 1',
|
||||
'Round 3 Group D Import 2',
|
||||
'Round 3 Group D Import 3',
|
||||
'Round 3 Group D RpcEnc'
|
||||
);
|
||||
|
||||
// get our endpoint
|
||||
$baseurl = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$interopConfig['basedir'];
|
||||
?>
|
||||
<body>
|
||||
|
||||
<h2 align='center'>PEAR SOAP Interop</h2>
|
||||
<p>Welcome to the PEAR SOAP Interop pages. These pages are set up for
|
||||
SOAP Builder interop tests.</p>
|
||||
<table width="90%" border="1" cellspacing="0" cellpadding="2" align="center">
|
||||
<?php
|
||||
|
||||
foreach ($tests as $test) {
|
||||
$ep = getLocalInteropServer($test,0,$baseurl);
|
||||
echo "<tr><td>$test</td><td>\n";
|
||||
echo "WSDL: <a href=\"{$ep->wsdlURL}\">{$ep->wsdlURL}</a><br>\n";
|
||||
echo "Endpoint: {$ep->endpointURL}<br>\n";
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
</table>
|
||||
<h3>Interop Client</h3>
|
||||
|
||||
<p>
|
||||
Notes:
|
||||
Tests are done both "Direct" and with "WSDL". WSDL tests use the supplied interop WSDL
|
||||
to run the tests against. The Direct method uses an internal prebuilt list of methods and parameters
|
||||
for the test.</p>
|
||||
<p>
|
||||
Tests are also run against two methods of generating method parameters. The first, 'php', attempts
|
||||
to directly serialize PHP variables into soap values. The second method, 'soapval', uses a SOAP_Value
|
||||
class to define what the type of the value is. The second method is more interopable than the first
|
||||
by nature.
|
||||
</p>
|
||||
|
||||
<h3>Interop Client Test Results</h3>
|
||||
<p>This is a database of the current test results using PEAR SOAP Clients against interop servers.</p>
|
||||
<p>
|
||||
More detail (wire) about errors (marked yellow or red) can be obtained by clicking on the
|
||||
link in the result box. If we have an HTTP error
|
||||
attempting to connect to the endpoint, we will mark all consecutive attempts as errors, and skip
|
||||
testing that endpoint. This reduces the time it takes to run the tests if a server is unavailable.
|
||||
WSDLCACHE errors mean we cannot retreive the WSDL file specified for the endpoint.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Base&type=php&wsdl=0">Base results using PHP native types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Base&type=soapval&wsdl=0">Base results using SOAP types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Base&type=php&wsdl=1">Base results using PHP native types with WSDL</a></li>
|
||||
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+B&type=php&wsdl=0">Group B results using PHP native types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+B&type=soapval&wsdl=0">Group B results using SOAP types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+B&type=php&wsdl=1">Group B results using PHP native types with WSDL</a></li>
|
||||
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+C&type=php&wsdl=0">Group C results using PHP native types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+C&type=soapval&wsdl=0">Group C results using SOAP types</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+2+Group+C&type=php&wsdl=1">Group C results using PHP native types with WSDL</a></li>
|
||||
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+Compound+1&type=php&wsdl=1">Group D Compound 1 results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+Compound+2&type=php&wsdl=1">Group D Compound 2 results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+DocLit&type=php&wsdl=1">Group D DocLit results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+DocLitParams&type=php&wsdl=1">Group D DocLitParams results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+Import+1&type=php&wsdl=1">Group D Import 1 results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+Import+2&type=php&wsdl=1">Group D Import 2 results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+Import+3&type=php&wsdl=1">Group D Import 3 results using PHP native types with WSDL</a></li>
|
||||
<li><a href="interop_client_results.php?test=Round+3+Group+D+RpcEnc&type=php&wsdl=1">Group D RpcEnc results using PHP native types with WSDL</a></li>
|
||||
|
||||
<li><a href="interop_client_results.php">Show All Results</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
155
thirdparty/pear/SOAP/Interop/interop_Round2Base.php
vendored
155
thirdparty/pear/SOAP/Interop/interop_Round2Base.php
vendored
@@ -1,155 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
|
||||
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_Round2Base.php,v 1.9 2007/01/26 00:06:11 yunosh Exp $
|
||||
//
|
||||
require_once 'params_classes.php';
|
||||
|
||||
function &generateFault($short, $long)
|
||||
{
|
||||
$params = array(
|
||||
'faultcode' => 'Server',
|
||||
'faultstring' => $short,
|
||||
'detail' => $long
|
||||
);
|
||||
|
||||
$faultmsg = new SOAP_Message('Fault', $params, 'http://schemas.xmlsoap.org/soap/envelope/');
|
||||
return $faultmsg;
|
||||
}
|
||||
|
||||
function hex2bin($data)
|
||||
{
|
||||
$len = strlen($data);
|
||||
return pack('H' . $len, $data);
|
||||
}
|
||||
|
||||
|
||||
class SOAP_Interop_Base {
|
||||
|
||||
function echoString($inputString)
|
||||
{
|
||||
return new SOAP_Value('outputString', 'string', $inputString);
|
||||
}
|
||||
|
||||
function echoStringArray($inputStringArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputStringArray) {
|
||||
foreach($inputStringArray as $s) {
|
||||
$ra[] = new SOAP_Value('item', 'string', $s);
|
||||
}
|
||||
}
|
||||
return new SOAP_Value('outputStringArray', null, $ra);
|
||||
}
|
||||
|
||||
|
||||
function echoInteger($inputInteger)
|
||||
{
|
||||
return new SOAP_Value('outputInteger', 'int', (integer)$inputInteger);
|
||||
}
|
||||
|
||||
function echoIntegerArray($inputIntegerArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputIntegerArray) {
|
||||
foreach ($inputIntegerArray as $i) {
|
||||
$ra[] = new SOAP_Value('item', 'int', $i);
|
||||
}
|
||||
}
|
||||
return new SOAP_Value('outputIntArray', null, $ra);
|
||||
}
|
||||
|
||||
function echoFloat($inputFloat)
|
||||
{
|
||||
return new SOAP_Value('outputFloat', 'float', (float)$inputFloat);
|
||||
}
|
||||
|
||||
function echoFloatArray($inputFloatArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputFloatArray) {
|
||||
foreach($inputFloatArray as $float) {
|
||||
$ra[] = new SOAP_Value('item', 'float', (FLOAT)$float);
|
||||
}
|
||||
}
|
||||
return new SOAP_Value('outputFloatArray', null, $ra);
|
||||
}
|
||||
|
||||
function echoStruct($inputStruct)
|
||||
{
|
||||
if (is_object($inputStruct) && strtolower(get_class($inputStruct)) == 'soapstruct') {
|
||||
return $inputStruct->__to_soap();
|
||||
}
|
||||
return $inputStruct;
|
||||
}
|
||||
|
||||
function echoStructArray($inputStructArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputStructArray) {
|
||||
$c = count($inputStructArray);
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$ra[] = $this->echoStruct($inputStructArray[$i]);
|
||||
}
|
||||
}
|
||||
return $ra;
|
||||
}
|
||||
|
||||
function echoVoid()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function echoBase64($b_encoded)
|
||||
{
|
||||
return new SOAP_Value('return', 'base64Binary', base64_encode(base64_decode($b_encoded)));
|
||||
}
|
||||
|
||||
function echoDate($timeInstant)
|
||||
{
|
||||
require_once 'SOAP/Type/dateTime.php';
|
||||
$dt = new SOAP_Type_dateTime($timeInstant);
|
||||
if ($dt->toUnixtime() != -1) {
|
||||
$value = $dt->toSOAP();
|
||||
return new SOAP_Value('return', 'dateTime', $value);
|
||||
} else {
|
||||
return new SOAP_Fault("Value $timeInstant is not a dateTime value");
|
||||
}
|
||||
}
|
||||
|
||||
function echoHexBinary($hb)
|
||||
{
|
||||
return new SOAP_Value('return', 'hexBinary', bin2hex(hex2bin($hb)));
|
||||
}
|
||||
|
||||
function echoDecimal($dec)
|
||||
{
|
||||
return new SOAP_Value('return', 'decimal', (float)$dec);
|
||||
}
|
||||
|
||||
function echoBoolean($boolean)
|
||||
{
|
||||
return new SOAP_Value('return', 'boolean', $boolean);
|
||||
}
|
||||
|
||||
function echoMimeAttachment($stuff)
|
||||
{
|
||||
return new SOAP_Attachment('return', 'application/octet-stream', null, $stuff);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
|
||||
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_Round2GroupB.php,v 1.9 2007/01/22 14:53:21 yunosh Exp $
|
||||
//
|
||||
require_once 'params_classes.php';
|
||||
|
||||
class SOAP_Interop_GroupB {
|
||||
|
||||
var $__dispatch_map = array();
|
||||
|
||||
function SOAP_Interop_GroupB()
|
||||
{
|
||||
$this->__dispatch_map['echoStructAsSimpleTypes'] =
|
||||
array('in' => array('inputStruct' => 'SOAPStruct'),
|
||||
'out' => array('outputString' => 'string', 'outputInteger' => 'int', 'outputFloat' => 'float'));
|
||||
$this->__dispatch_map['echoSimpleTypesAsStruct'] =
|
||||
array('in' => array('inputString' => 'string', 'inputInteger' => 'int', 'inputFloat' => 'float'),
|
||||
'out' => array('return' => 'SOAPStruct'));
|
||||
$this->__dispatch_map['echoNestedStruct'] =
|
||||
array('in' => array('inputStruct' => 'SOAPStructStruct'),
|
||||
'out' => array('return' => 'SOAPStructStruct'));
|
||||
$this->__dispatch_map['echo2DStringArray'] =
|
||||
array('in' => array('input2DStringArray' => 'ArrayOfString2D'),
|
||||
'out' => array('return' => 'ArrayOfString2D'));
|
||||
$this->__dispatch_map['echoNestedArray'] =
|
||||
array('in' => array('inputString' => 'SOAPArrayStruct'),
|
||||
'out' => array('return' => 'SOAPArrayStruct'));
|
||||
}
|
||||
|
||||
/* this private function is called on by SOAP_Server to determine any
|
||||
* special dispatch information that might be necessary. This, for
|
||||
* example, can be used to set up a dispatch map for functions that return
|
||||
* multiple OUT parameters. */
|
||||
function __dispatch($methodname)
|
||||
{
|
||||
if (array_key_exists($methodname,$this->__dispatch_map)) {
|
||||
return $this->__dispatch_map[$methodname];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function echoStructAsSimpleTypes ($struct)
|
||||
{
|
||||
// Convert a SOAPStruct to an array.
|
||||
return array(
|
||||
new SOAP_Value('outputString','string',$struct->varString),
|
||||
new SOAP_Value('outputInteger','int',$struct->varInt),
|
||||
new SOAP_Value('outputFloat','float',$struct->varFloat));
|
||||
}
|
||||
|
||||
function echoSimpleTypesAsStruct($string, $int, $float)
|
||||
{
|
||||
// Convert a input into struct.
|
||||
$v = new SOAPStruct($string, $int, $float);
|
||||
return new SOAP_Value('return', '{http://soapinterop.org/xsd}SOAPStruct', $v);
|
||||
}
|
||||
|
||||
function echoNestedStruct($struct)
|
||||
{
|
||||
$separator = "\n";
|
||||
$methods = get_class_methods($struct);
|
||||
$arr_str = $separator . strtolower(implode($separator, $methods));
|
||||
$string = $separator . '__to_soap' . $separator;
|
||||
if (strpos($arr_str, $string) !== false) {
|
||||
return $struct->__to_soap();
|
||||
}
|
||||
return $struct;
|
||||
}
|
||||
|
||||
function echo2DStringArray($array)
|
||||
{
|
||||
$ret = new SOAP_Value('return', 'Array', $array);
|
||||
$ret->options['flatten'] = true;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function echoNestedArray($array)
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_Round2GroupC.php,v 1.5 2007/01/22 14:53:21 yunosh Exp $
|
||||
//
|
||||
require_once 'SOAP/Value.php';
|
||||
|
||||
class SOAP_Interop_GroupC_Headers {
|
||||
|
||||
function echoMeStringRequest($string)
|
||||
{
|
||||
return new SOAP_Value('{http://soapinterop.org/echoheader/}echoMeStringResponse', 'string', $string);
|
||||
}
|
||||
|
||||
function echoMeStructRequest($struct)
|
||||
{
|
||||
return new SOAP_Value('{http://soapinterop.org/echoheader/}echoMeStructResponse', 'SOAPStruct', $struct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_Round3GroupD.php,v 1.5 2007/01/22 14:53:21 yunosh Exp $
|
||||
//
|
||||
require_once 'params_classes.php';
|
||||
|
||||
// http://www.whitemesa.com/r3/interop3.html
|
||||
// http://www.whitemesa.com/r3/plan.html
|
||||
|
||||
class SOAP_Interop_GroupD {
|
||||
|
||||
// wsdlns:SoapInteropEmptySABinding
|
||||
function echoString($inputString)
|
||||
{
|
||||
return new SOAP_Value('outputString', 'string', $inputString);
|
||||
}
|
||||
|
||||
function echoStringArray($inputStringArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputStringArray) {
|
||||
foreach ($inputStringArray as $s) {
|
||||
$ra[] = new SOAP_Value('item', 'string', $s);
|
||||
}
|
||||
}
|
||||
return new SOAP_Value('outputStringArray', null, $ra);
|
||||
}
|
||||
|
||||
function echoStruct($inputStruct)
|
||||
{
|
||||
return $inputStruct->to_soap();
|
||||
}
|
||||
|
||||
function echoStructArray($inputStructArray)
|
||||
{
|
||||
$ra = array();
|
||||
if ($inputStructArray) {
|
||||
$c = count($inputStructArray);
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$ra[] = $inputStructArray[$i]->to_soap();
|
||||
}
|
||||
}
|
||||
return $ra;
|
||||
}
|
||||
|
||||
function echoVoid()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function echoPerson()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function x_Document(&$document)
|
||||
{
|
||||
return new SOAP_Value('result_Document', '{http://soapinterop.org/xsd}x_Document', $document);
|
||||
}
|
||||
|
||||
function echoEmployee()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
805
thirdparty/pear/SOAP/Interop/interop_client.php
vendored
805
thirdparty/pear/SOAP/Interop/interop_client.php
vendored
@@ -1,805 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_client.php,v 1.16 2007/01/26 17:21:26 yunosh Exp $
|
||||
//
|
||||
require_once 'DB.php'; // PEAR/DB
|
||||
require_once 'SOAP/Client.php';
|
||||
|
||||
require_once 'config.php';
|
||||
require_once 'interop_test_functions.php';
|
||||
require_once 'interop_test.php';
|
||||
require_once 'params_Round2Base.php';
|
||||
require_once 'params_Round2GroupB.php';
|
||||
require_once 'params_Round2GroupC.php';
|
||||
require_once 'params_Round3GroupD.php';
|
||||
require_once 'registrationAndNotification.php';
|
||||
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
$INTEROP_LOCAL_SERVER = false;
|
||||
|
||||
class Interop_Client
|
||||
{
|
||||
// database DNS
|
||||
var $DSN;
|
||||
|
||||
// our central interop server, where we can get the list of endpoints
|
||||
var $registrationDB;
|
||||
|
||||
// our local endpoint, will always get added to the database for all tests
|
||||
var $localEndpoint;
|
||||
|
||||
// specify testing
|
||||
var $currentTest = ''; // see $tests above
|
||||
var $paramType = 'php'; // 'php' or 'soapval'
|
||||
var $useWSDL = false; // true: do wsdl tests
|
||||
var $numServers = 0; // 0: all
|
||||
var $specificEndpoint = ''; // test only this endpoint
|
||||
var $testMethod = ''; // test only this method
|
||||
var $skipEndpointList = array(); // endpoints to skip
|
||||
var $nosave = false;
|
||||
var $client_type = 'pear'; // name of client
|
||||
|
||||
// debug output
|
||||
var $show = 1;
|
||||
var $debug = 0;
|
||||
var $showFaults = 0; // used in result table output
|
||||
|
||||
// PRIVATE VARIABLES
|
||||
var $dbc = null;
|
||||
var $totals = array();
|
||||
var $tests = array('Round 2 Base',
|
||||
'Round 2 Group B',
|
||||
'Round 2 Group C',
|
||||
'Round 3 Group D Compound 1',
|
||||
'Round 3 Group D Compound 2',
|
||||
'Round 3 Group D DocLit',
|
||||
'Round 3 Group D DocLitParams',
|
||||
'Round 3 Group D Import 1',
|
||||
'Round 3 Group D Import 2',
|
||||
'Round 3 Group D Import 3',
|
||||
'Round 3 Group D RpcEnc'
|
||||
);
|
||||
var $paramTypes = array('php', 'soapval');
|
||||
var $endpoints = array();
|
||||
|
||||
function Interop_Client() {
|
||||
global $interopConfig;
|
||||
$this->DSN = $interopConfig['DSN'];
|
||||
$this->registrationDB =& new SOAP_Interop_registrationDB();
|
||||
|
||||
// XXX for now, share the database for results also
|
||||
$this->dbc =& $this->registrationDB->dbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetchEndpoints
|
||||
* retreive endpoints interop server
|
||||
*
|
||||
* @return boolean result
|
||||
* @access private
|
||||
*/
|
||||
function fetchEndpoints($name = 'Round 2 Base') {
|
||||
$service =& $this->registrationDB->findService($name);
|
||||
$this->endpoints =& $this->registrationDB->getServerList($service->id,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* getEndpoints
|
||||
* retreive endpoints from either database or interop server
|
||||
*
|
||||
* @param string name (see local var $tests)
|
||||
* @param boolean all (if false, only get valid endpoints, status=1)
|
||||
* @return boolean result
|
||||
* @access private
|
||||
*/
|
||||
function getEndpoints($name = 'Round 2 Base', $all = 0) {
|
||||
$service =& $this->registrationDB->findService($name);
|
||||
$this->endpoints =& $this->registrationDB->getServerList($service->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreives results from the database and stuffs them into the endpoint
|
||||
* array.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function getResults($test = 'Round 2 Base', $type = 'php', $wsdl = 0)
|
||||
{
|
||||
// Be sure we have the right endpoints for this test result.
|
||||
$this->getEndpoints($test);
|
||||
$c = count($this->endpoints);
|
||||
|
||||
// Retreive the results and put them into the endpoint info.
|
||||
$sql = "SELECT * FROM results WHERE class='$test' AND type='$type' AND wsdl=$wsdl";
|
||||
$results = $this->dbc->getAll($sql, null, DB_FETCHMODE_ASSOC);
|
||||
for ($j = 0, $rc = count($results); $j < $rc; ++$j) {
|
||||
$result = $results[$j];
|
||||
// Find the endpoint.
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
if ($this->endpoints[$i]->id == $result['endpoint']) {
|
||||
// Store the info.
|
||||
if (!isset($this->endpoints[$i]->methods)) {
|
||||
$this->endpoints[$i]->methods = array();
|
||||
}
|
||||
$this->endpoints[$i]->methods[$result['function']] = $result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the results of a method test into the database.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _saveResults($endpoint_id, &$soap_test)
|
||||
{
|
||||
if ($this->nosave) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result =& $soap_test->result;
|
||||
$wire = $result['wire'];
|
||||
if ($result['success']) {
|
||||
$success = 'OK';
|
||||
$error = '';
|
||||
} else {
|
||||
$success = $result['fault']->faultcode;
|
||||
$error = $result['fault']->faultstring;
|
||||
if (!$wire) {
|
||||
$wire = $result['fault']->faultdetail;
|
||||
}
|
||||
if (!$wire) {
|
||||
$wire = $result['fault']->faultstring;
|
||||
}
|
||||
}
|
||||
|
||||
$test_name = $soap_test->test_name;
|
||||
// add header info to the test name
|
||||
if ($soap_test->headers) {
|
||||
foreach ($soap_test->headers as $h) {
|
||||
$destination = 0;
|
||||
if (is_object($h) && strtolower(get_class($h)) == 'soap_header') {
|
||||
if ($h->attributes['SOAP-ENV:actor'] == 'http://schemas.xmlsoap.org/soap/actor/next') {
|
||||
$destination = 1;
|
||||
}
|
||||
$test_name .= ":{$h->name},$destination,{$h->attributes['SOAP-ENV:mustUnderstand']}";
|
||||
} else {
|
||||
if (!$h[3] ||
|
||||
$h[3] == 'http://schemas.xmlsoap.org/soap/actor/next') {
|
||||
$destination = 1;
|
||||
}
|
||||
if (!$h[2]) {
|
||||
$h[2] = 0;
|
||||
}
|
||||
$qn = new QName($h[0]);
|
||||
$test_name .= ":{$qn->name},$destination," . (int)$h[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM results WHERE endpoint = ? AND class = ? AND type = ? AND wsdl = ? AND client = ? AND function = ?';
|
||||
$values = array($endpoint_id, $this->currentTest, $this->paramType,
|
||||
$this->useWSDL, $this->client_type, $test_name);
|
||||
$res = $this->dbc->query($sql, $values);
|
||||
if (DB::isError($res)) {
|
||||
die($res->getMessage());
|
||||
}
|
||||
if (is_object($res)) {
|
||||
$res->free();
|
||||
}
|
||||
|
||||
$sql = 'INSERT INTO results (client, endpoint, stamp, class, type, wsdl, function, result, error, wire) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
$values = array($this->client_type, $endpoint_id, time(),
|
||||
$this->currentTest, $this->paramType, $this->useWSDL,
|
||||
$test_name, $success, $error,
|
||||
$wire ? $wire : '');
|
||||
//echo "\n".$sql;
|
||||
$res = $this->dbc->query($sql, $values);
|
||||
if (DB::isError($res)) {
|
||||
die($res->getMessage());
|
||||
}
|
||||
if (is_object($res)) {
|
||||
$res->free();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two PHP types for a match.
|
||||
*
|
||||
* @param mixed $expect
|
||||
* @param mixed $test_result
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function compareResult(&$expect, &$result, $type = null)
|
||||
{
|
||||
$expect_type = gettype($expect);
|
||||
$result_type = gettype($result);
|
||||
if ($expect_type == 'array' && $result_type == 'array') {
|
||||
// compare arrays
|
||||
return array_compare($expect, $result);
|
||||
}
|
||||
if ($type == 'float') {
|
||||
// We'll only compare to 3 digits of precision.
|
||||
return number_compare($expect, $result);
|
||||
}
|
||||
if ($type == 'boolean') {
|
||||
return boolean_compare($expect, $result);
|
||||
}
|
||||
return string_compare($expect, $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a method on an endpoint and stores its results to the database.
|
||||
*
|
||||
* @param array $endpoint_info
|
||||
* @param SOAP_Test $soap_test
|
||||
*
|
||||
* @return boolean result
|
||||
*/
|
||||
function doEndpointMethod(&$endpoint_info, &$soap_test)
|
||||
{
|
||||
$ok = false;
|
||||
|
||||
// Prepare a holder for the test results.
|
||||
$soap_test->result['class'] = $this->currentTest;
|
||||
$soap_test->result['type'] = $this->paramType;
|
||||
$soap_test->result['wsdl'] = $this->useWSDL;
|
||||
$opdata = null;
|
||||
//global $soap_value_total;
|
||||
//echo "SOAP VALUES TEST-START: $soap_value_total\n";
|
||||
|
||||
if ($this->useWSDL) {
|
||||
if ($endpoint_info->wsdlURL) {
|
||||
if (!$endpoint_info->client) {
|
||||
if (0 /* dynamic client */) {
|
||||
$endpoint_info->wsdl = new SOAP_WSDL($endpoint_info->wsdlURL);
|
||||
$endpoint_info->wsdl->trace=1;
|
||||
$endpoint_info->client = $endpoint_info->wsdl->getProxy('', $endpoint_info->name);
|
||||
} else {
|
||||
$endpoint_info->client = new SOAP_Client($endpoint_info->wsdlURL, 1);
|
||||
}
|
||||
$endpoint_info->client->_auto_translation = true;
|
||||
}
|
||||
if ($endpoint_info->client->_wsdl->_isfault()) {
|
||||
$fault = $endpoint_info->client->_wsdl->fault->getFault();
|
||||
$detail = $fault->faultstring . "\n\n" . $fault->faultdetail;
|
||||
$soap_test->setResult(0,
|
||||
'WSDL',
|
||||
$detail,
|
||||
$fault->faultstring,
|
||||
$fault);
|
||||
return false;
|
||||
}
|
||||
if ($soap_test->service) {
|
||||
$endpoint_info->client->_wsdl->setService($soap_test->service);
|
||||
}
|
||||
$soap =& $endpoint_info->client;
|
||||
//$port = $soap->_wsdl->getPortName($soap_test->method_name);
|
||||
//$opdata = $soap->_wsdl->getOperationData($port, $soap_test->method_name);
|
||||
} else {
|
||||
$fault = array('faultcode' => 'WSDL',
|
||||
'faultstring' => "no WSDL defined for $endpoint");
|
||||
$soap_test->setResult(0,
|
||||
'WSDL',
|
||||
$fault->faultstring,
|
||||
$fault->faultstring,
|
||||
$fault);
|
||||
return false;
|
||||
}
|
||||
$options = array('trace' => 1);
|
||||
} else {
|
||||
$namespace = $soapaction = 'http://soapinterop.org/';
|
||||
// Hack to make tests work with MS SoapToolkit.
|
||||
// It's the only one that uses this soapaction, and breaks if
|
||||
// it isn't right. Can't wait for soapaction to be fully deprecated
|
||||
// 8/25/2002, seems this is fixed now
|
||||
//if ($this->currentTest == 'Round 2 Base' &&
|
||||
// strstr($endpoint_info->name,'MS SOAP ToolKit 2.0')) {
|
||||
// $soapaction = 'urn:soapinterop';
|
||||
//}
|
||||
if (!$endpoint_info->client) {
|
||||
$endpoint_info->client = new SOAP_Client($endpoint_info->endpointURL);
|
||||
$endpoint_info->client->_auto_translation = true;
|
||||
}
|
||||
$soap = &$endpoint_info->client;
|
||||
$options = array('namespace' => $namespace,
|
||||
'soapaction' => $soapaction,
|
||||
'trace' => 1);
|
||||
}
|
||||
|
||||
// Add headers to the test.
|
||||
if ($soap_test->headers) {
|
||||
// $header is already a SOAP_Header class
|
||||
$soap->headersOut = array();
|
||||
$soap->headersIn = array();
|
||||
for ($i = 0, $hc = count($soap_test->headers); $i < $hc; $i++) {
|
||||
$soap->addHeader($soap_test->headers[$i]);
|
||||
}
|
||||
}
|
||||
$soap->setEncoding($soap_test->encoding);
|
||||
|
||||
//if ($opdata) {
|
||||
// if (isset($opdata['style']))
|
||||
// $options['style'] = $opdata['style'];
|
||||
// if (isset($opdata['soapAction']))
|
||||
// $options['soapaction'] = $opdata['soapAction'];
|
||||
// if (isset($opdata['input']) &&
|
||||
// isset($opdata['input']['use']))
|
||||
// $options['use'] = $opdata['input']['use'];
|
||||
// if (isset($opdata['input']) &&
|
||||
// isset($opdata['input']['namespace']))
|
||||
// $options['namespace'] = $soap->_wsdl->namespaces[$opdata['input']['namespace']];
|
||||
//}
|
||||
//if ($this->useWSDL) {
|
||||
// $wsdlcall = '$return = $soap->'.$soap_test->method_name.'(';
|
||||
// $args = '';
|
||||
// if ($soap_test->method_params) {
|
||||
// $pnames = array_keys($soap_test->method_params);
|
||||
// foreach ($pnames as $argname) {
|
||||
// if ($args) $args .=',';
|
||||
// $args .= '$soap_test->method_params[\''.$argname.'\']';
|
||||
// }
|
||||
// }
|
||||
// $wsdlcall = $wsdlcall.$args.');';
|
||||
// eval($wsdlcall);
|
||||
//} else {
|
||||
$return =& $soap->call($soap_test->method_name, $soap_test->method_params, $options);
|
||||
//}
|
||||
|
||||
if (!PEAR::isError($return)) {
|
||||
if (is_array($soap_test->method_params) &&
|
||||
count($soap_test->method_params) == 1) {
|
||||
$sent = array_shift(array_values($soap_test->method_params));
|
||||
} else {
|
||||
$sent = $soap_test->method_params;
|
||||
}
|
||||
|
||||
// Compare header results.
|
||||
$header_result = array();
|
||||
$headers_ok = true;
|
||||
if ($soap_test->headers) {
|
||||
// $header is already a SOAP_Header class
|
||||
for ($i = 0, $hc = count($soap_test->headers); $i < $hc; $i++) {
|
||||
$header = $soap_test->headers[$i];
|
||||
if (is_object($header) && strtolower(get_class($header)) != 'soap_header') {
|
||||
// Assume it's an array.
|
||||
$header = new SOAP_Header($header[0], null, $header[1], $header[2], $header[3], $header[4]);
|
||||
}
|
||||
$expect = $soap_test->headers_expect[$header->name];
|
||||
$header_result[$header->name] = array();
|
||||
// XXX need to fix need_result to identify the actor correctly
|
||||
$need_result = $hresult ||
|
||||
($header->attributes['SOAP-ENV:actor'] == 'http://schemas.xmlsoap.org/soap/actor/next'
|
||||
&& $header->attributes['SOAP-ENV:mustUnderstand']);
|
||||
if ($expect) {
|
||||
$hresult = $soap->headersIn[key($expect)];
|
||||
$ok = !$need_result || $this->compareResult($hresult ,$expect[key($expect)]);
|
||||
} else {
|
||||
$hresult = $soap->headersIn[$header->name];
|
||||
$expect =& $soap->_decode($header);
|
||||
$ok = !$need_result || $this->compareResult($hresult ,$expect);
|
||||
}
|
||||
$header_result[$header->name]['ok'] = $ok;
|
||||
if (!$ok) {
|
||||
$headers_ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We need to decode what we sent so we can compare!
|
||||
if (gettype($sent) == 'object' &&
|
||||
(strtolower(get_class($sent)) == 'soap_value' ||
|
||||
is_subclass_of($sent, 'soap_value'))) {
|
||||
$sent_d =& $soap->_decode($sent);
|
||||
} else {
|
||||
$sent_d =& $sent;
|
||||
}
|
||||
|
||||
// compare the results with what we sent
|
||||
$ok = $this->compareResult($sent_d, $return, $sent->type);
|
||||
$expected = $sent_d;
|
||||
unset($sent_d);
|
||||
unset($sent);
|
||||
if (!$ok && $soap_test->expect) {
|
||||
$ok = $this->compareResult($soap_test->expect, $return);
|
||||
$expected = $soap_test->expect;
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
if (!$headers_ok) {
|
||||
$fault = new stdClass();
|
||||
$fault->faultcode = 'HEADER';
|
||||
$fault->faultstring = 'The returned result did not match what we expected to receive';
|
||||
$soap_test->setResult(0,
|
||||
$fault->faultcode,
|
||||
$soap->getWire(),
|
||||
$fault->faultstring,
|
||||
$fault);
|
||||
} else {
|
||||
$soap_test->setResult(1, 'OK', $soap->getWire());
|
||||
$success = true;
|
||||
}
|
||||
} else {
|
||||
$fault = new stdClass();
|
||||
$fault->faultcode = 'RESULT';
|
||||
$fault->faultstring = 'The returned result did not match what we expected to receive';
|
||||
$fault->faultdetail = "RETURNED:\n" . var_export($return, true) . "\n\nEXPECTED:\n" . var_export($expected, true);
|
||||
$soap_test->setResult(0,
|
||||
$fault->faultcode,
|
||||
$soap->getWire(),
|
||||
$fault->faultstring,
|
||||
$fault);
|
||||
}
|
||||
} else {
|
||||
$fault = $return->getFault();
|
||||
if ($soap_test->expect_fault) {
|
||||
$ok = 1;
|
||||
$res = 'OK';
|
||||
} else {
|
||||
$ok = 0;
|
||||
$res = $fault->faultcode;
|
||||
}
|
||||
$soap_test->setResult($ok,
|
||||
$res,
|
||||
$soap->getWire(),
|
||||
$fault->faultstring,
|
||||
$fault);
|
||||
}
|
||||
$soap->_reset();
|
||||
unset($return);
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a single round of tests.
|
||||
*/
|
||||
function doTest()
|
||||
{
|
||||
global $soap_tests;
|
||||
|
||||
$empty_string = '';
|
||||
// Get endpoints for this test.
|
||||
if (!$this->currentTest) {
|
||||
die("Asked to run a test, but no testname!\n");
|
||||
}
|
||||
$this->getEndpoints($this->currentTest);
|
||||
// Clear totals.
|
||||
$this->totals = array();
|
||||
|
||||
for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
|
||||
$endpoint_info = $this->endpoints[$i];
|
||||
// If we specify an endpoint, skip until we find it.
|
||||
if (($this->specificEndpoint &&
|
||||
$endpoint_info->name != $this->specificEndpoint) ||
|
||||
($this->useWSDL && !$endpoint_info->wsdlURL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$skipendpoint = false;
|
||||
$this->totals['servers']++;
|
||||
//$endpoint_info['tests'] = array();
|
||||
|
||||
if ($this->show) {
|
||||
echo "Processing {$endpoint_info->name} at {$endpoint_info->endpointURL}\n";
|
||||
}
|
||||
|
||||
for ($ti = 0, $tc = count($soap_tests[$this->currentTest]); $ti < $tc; ++$ti) {
|
||||
$soap_test = $soap_tests[$this->currentTest][$ti];
|
||||
|
||||
// Only run the type of test we're looking for (php or
|
||||
// soapval).
|
||||
if ($soap_test->type != $this->paramType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this is in our skip list, skip it.
|
||||
if (in_array($endpoint_info->name, $this->skipEndpointList)) {
|
||||
$skipendpoint = true;
|
||||
$skipfault = new stdClass();
|
||||
$skipfault->faultcode = 'SKIP';
|
||||
$skipfault->faultstring = 'endpoint skipped';
|
||||
$soap_test->setResult(0,
|
||||
$skipfault->faultcode,
|
||||
$empty_string,
|
||||
$skipfault->faultstring,
|
||||
$skipfault);
|
||||
//$endpoint_info['tests'][] = &$soap_test;
|
||||
//$soap_test->showTestResult($this->debug);
|
||||
//$this->_saveResults($endpoint_info['id'], $soap_test->method_name);
|
||||
$soap_test->result = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we're looking for a specific method, skip unless we have
|
||||
// it.
|
||||
if ($this->testMethod &&
|
||||
strcmp($this->testMethod, $soap_test->test_name) != 0) {
|
||||
continue;
|
||||
}
|
||||
if ($this->testMethod &&
|
||||
$this->currentTest == 'Round 2 Group C') {
|
||||
// We have to figure things out now.
|
||||
if (!preg_match('/(.*):(.*),(\d),(\d)/', $this->testMethod, $m)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is the header in the headers list?
|
||||
$gotit = false;
|
||||
$thc = count($soap_test->headers);
|
||||
for ($thi = 0; $thi < $thc; $thi++) {
|
||||
$header = $soap_test->headers[$thi];
|
||||
if (is_object($header) && strtolower(get_class($header)) == 'soap_header') {
|
||||
if ($header->name == $m[2]) {
|
||||
$gotit = $header->attributes['SOAP-ENV:actor'] == ($m[3] ? SOAP_TEST_ACTOR_NEXT : SOAP_TEST_ACTOR_OTHER);
|
||||
$gotit = $gotit && $header->attributes['SOAP-ENV:mustUnderstand'] == $m[4];
|
||||
}
|
||||
} elseif ($header[0] == $m[2]) {
|
||||
$gotit = $gotit && $header[3] == ($m[3] ? SOAP_TEST_ACTOR_NEXT : SOAP_TEST_ACTOR_OTHER);
|
||||
$gotit = $gotit && $header[4] == $m[4];
|
||||
}
|
||||
}
|
||||
if (!$gotit) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are skipping the rest of the tests (due to error)
|
||||
// note a fault.
|
||||
if ($skipendpoint) {
|
||||
$soap_test->setResult(0,
|
||||
$skipfault->faultcode,
|
||||
$empty_string,
|
||||
$skipfault->faultstring,
|
||||
$skipfault);
|
||||
//$endpoint_info['tests'][] = &$soap_test;
|
||||
$this->totals['fail']++;
|
||||
} else {
|
||||
// Run the endpoint test.
|
||||
unset($soap_test->result);
|
||||
if ($this->doEndpointMethod($endpoint_info, $soap_test)) {
|
||||
$this->totals['success']++;
|
||||
} else {
|
||||
$skipendpoint = $soap_test->result['fault']->faultcode == 'HTTP';
|
||||
$skipfault = $skipendpoint ? $soap_test->result['fault'] : null;
|
||||
$this->totals['fail']++;
|
||||
}
|
||||
//$endpoint_info['tests'][] = &$soap_test;
|
||||
}
|
||||
$soap_test->showTestResult($this->debug);
|
||||
$this->_saveResults($endpoint_info->id, $soap_test);
|
||||
$soap_test->reset();
|
||||
$this->totals['calls']++;
|
||||
}
|
||||
unset($endpoint_info->client);
|
||||
if ($this->numservers && ++$i >= $this->numservers) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doGroupTests() {
|
||||
$dowsdl = array(0,1);
|
||||
foreach($dowsdl as $usewsdl) {
|
||||
$this->useWSDL = $usewsdl;
|
||||
foreach($this->paramTypes as $ptype) {
|
||||
// skip a pointless test
|
||||
if ($usewsdl && $ptype == 'soapval') break;
|
||||
if (stristr($this->currentTest, 'Round 3') && !$usewsdl) break;
|
||||
$this->paramType = $ptype;
|
||||
$this->doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Go all out. This takes time.
|
||||
*/
|
||||
function doTests()
|
||||
{
|
||||
// The mother of all interop tests.
|
||||
$dowsdl = array(0, 1);
|
||||
foreach ($this->tests as $test) {
|
||||
$this->currentTest = $test;
|
||||
foreach ($dowsdl as $usewsdl) {
|
||||
$this->useWSDL = $usewsdl;
|
||||
foreach ($this->paramTypes as $ptype) {
|
||||
// Skip a pointless test.
|
||||
if ($usewsdl && $ptype == 'soapval') {
|
||||
break;
|
||||
}
|
||||
if (stristr($this->currentTest, 'Round 3') && !$usewsdl) {
|
||||
break;
|
||||
}
|
||||
$this->paramType = $ptype;
|
||||
$this->doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function getMethodList($test = 'base')
|
||||
{
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_ORDERED);
|
||||
// Retreive the results and put them into the endpoint info.
|
||||
$sql = "SELECT DISTINCT(function) FROM results WHERE client='$this->client_type' AND class='$test' ORDER BY function";
|
||||
$results = $this->dbc->getAll($sql);
|
||||
$ar = array();
|
||||
foreach($results as $result) {
|
||||
$ar[] = $result[0];
|
||||
}
|
||||
return $ar;
|
||||
}
|
||||
|
||||
function outputTable()
|
||||
{
|
||||
$methods = $this->getMethodList($this->currentTest);
|
||||
if (!$methods) {
|
||||
return;
|
||||
}
|
||||
$this->getResults($this->currentTest,$this->paramType,$this->useWSDL);
|
||||
|
||||
echo "<b>Testing $this->currentTest ";
|
||||
if ($this->useWSDL) {
|
||||
echo "using WSDL ";
|
||||
} else {
|
||||
echo "using Direct calls ";
|
||||
}
|
||||
echo "with $this->paramType values</b><br>\n";
|
||||
|
||||
// Calculate totals for this table.
|
||||
$this->totals['success'] = 0;
|
||||
$this->totals['fail'] = 0;
|
||||
$this->totals['result'] = 0;
|
||||
$this->totals['wsdl'] = 0;
|
||||
$this->totals['connect'] = 0;
|
||||
$this->totals['servers'] = 0; //count($this->endpoints);
|
||||
for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
|
||||
$endpoint_info = $this->endpoints[$i];
|
||||
if (!$endpoint_info->name) {
|
||||
continue;
|
||||
}
|
||||
if (count($endpoint_info->methods) > 0) {
|
||||
$this->totals['servers']++;
|
||||
foreach ($methods as $method) {
|
||||
$r = $endpoint_info->methods[$method]['result'];
|
||||
if ($r == 'OK') {
|
||||
$this->totals['success']++;
|
||||
} elseif (stristr($r, 'result')) {
|
||||
$this->totals['result']++;
|
||||
} elseif (stristr($r, 'wsdlcache')) {
|
||||
$this->totals['connect']++;
|
||||
} elseif (stristr($r, 'wsdl')) {
|
||||
$this->totals['wsdl']++;
|
||||
} elseif (stristr($r, 'http')) {
|
||||
$this->totals['connect']++;
|
||||
} else {
|
||||
$this->totals['fail']++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//unset($this->endpoints[$i]);
|
||||
}
|
||||
}
|
||||
$this->totals['calls'] = count($methods) * $this->totals['servers'];
|
||||
|
||||
//if ($this->totals['fail'] == $this->totals['calls']) {
|
||||
// // assume tests have not run, skip outputing table
|
||||
// echo "No Data Available<br>\n";
|
||||
// return;
|
||||
//}
|
||||
|
||||
echo "\n\n<b>Servers: {$this->totals['servers']} Calls: {$this->totals['calls']} Success: {$this->totals['success']} <br>\n"
|
||||
. "System-Fail: {$this->totals['fail']} Result-Failure: {$this->totals['result']} Connect-Failure: {$this->totals['connect']} WSDL-Failure: {$this->totals['wsdl']} </b><br>\n"
|
||||
|
||||
. "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"
|
||||
. "<tr><td class=\"BLANK\">Endpoint</td>\n";
|
||||
foreach ($methods as $method) {
|
||||
$info = explode(':', $method);
|
||||
echo "<td class='BLANK' valign='top'>";
|
||||
foreach ($info as $m) {
|
||||
$hi = explode(',', $m);
|
||||
echo '<b>'. $hi[0] . "</b><br>\n";
|
||||
if (count($hi) > 1) {
|
||||
echo " Actor="
|
||||
. ($hi[1] ? 'Target' : 'Not Target')
|
||||
. "<br>\n MustUnderstand=$hi[2]<br>\n";
|
||||
}
|
||||
}
|
||||
echo "</td>\n";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
$faults = array();
|
||||
$fi = 0;
|
||||
for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
|
||||
$endpoint_info = $this->endpoints[$i];
|
||||
if (!$endpoint_info->name) {
|
||||
continue;
|
||||
}
|
||||
if ($endpoint_info->wsdlURL) {
|
||||
echo "<tr><td class=\"BLANK\"><a href=\"{$endpoint_info->wsdlURL}\">{$endpoint_info->name}</a></td>\n";
|
||||
} else {
|
||||
echo "<tr><td class=\"BLANK\">{$endpoint_info->name}</td>\n";
|
||||
}
|
||||
foreach ($methods as $method) {
|
||||
$id = $endpoint_info->methods[$method]['id'];
|
||||
$r = $endpoint_info->methods[$method]['result'];
|
||||
$e = $endpoint_info->methods[$method]['error'];
|
||||
if ($e) {
|
||||
$faults[$fi++] = $e;
|
||||
}
|
||||
if ($r) {
|
||||
echo "<td class='$r'><a href='$PHP_SELF?wire=$id'>$r</a></td>\n";
|
||||
} else {
|
||||
echo "<td class='untested'>untested</td>\n";
|
||||
}
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table><br>\n";
|
||||
if ($this->showFaults && count($faults) > 0) {
|
||||
echo "<b>ERROR Details:</b><br>\n<ul>\n";
|
||||
// output more error detail
|
||||
foreach ($faults as $fault) {
|
||||
echo '<li>' . htmlspecialchars($fault) . "</li>\n";
|
||||
}
|
||||
}
|
||||
echo "</ul><br><br>\n";
|
||||
}
|
||||
|
||||
function outputTables()
|
||||
{
|
||||
$dowsdl = array(0, 1);
|
||||
foreach($this->tests as $test) {
|
||||
$this->currentTest = $test;
|
||||
foreach ($dowsdl as $usewsdl) {
|
||||
$this->useWSDL = $usewsdl;
|
||||
foreach ($this->paramTypes as $ptype) {
|
||||
// Skip a pointless test.
|
||||
if ($usewsdl && $ptype == 'soapval') {
|
||||
break;
|
||||
}
|
||||
if (stristr($this->currentTest, 'Round 3') && !$usewsdl) {
|
||||
break;
|
||||
}
|
||||
$this->paramType = $ptype;
|
||||
$this->outputTable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showWire($id)
|
||||
{
|
||||
$results = $this->dbc->getAll("SELECT * FROM results WHERE id=$id", null, DB_FETCHMODE_ASSOC );
|
||||
//$wire = preg_replace("/>/",">\n",$results[0]['wire']);
|
||||
$wire = $results[0]['wire'];
|
||||
echo "<pre>\n" . htmlspecialchars($wire) . "</pre>\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
// NOTE: do not run this directly under a web server, as it will take a very long
|
||||
// time to execute. Run from a command line or something, and redirect output
|
||||
// to an html file.
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_client_results.php,v 1.3 2003/04/07 00:51:17 shane Exp $
|
||||
//
|
||||
require_once 'interop_client.php';
|
||||
?>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
TD { background-color: Red; }
|
||||
TD.BLANK { background-color: White; }
|
||||
TD.OK { background-color: Lime; }
|
||||
TD.RESULT { background-color: Green; }
|
||||
TD.untested { background-color: White; }
|
||||
TD.CONNECT { background-color: Yellow; }
|
||||
TD.TRANSPORT { background-color: Yellow; }
|
||||
TD.WSDL { background-color: Yellow; }
|
||||
TD.WSDLCACHE { background-color: Yellow; }
|
||||
TD.WSDLPARSER { background-color: Yellow; }
|
||||
TD.HTTP { background-color: Yellow; }
|
||||
TD.SMTP { background-color: Yellow; }
|
||||
</style>
|
||||
<title>PEAR-PHP SOAP Interop Tests</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="White" text="Black">
|
||||
<h2 align="center">SOAP Client Interop Test Results: Round2</h2>
|
||||
|
||||
<a href="index.php">Back to Interop Index</a><br>
|
||||
<p> </p>
|
||||
|
||||
<?php
|
||||
$iop =& new Interop_Client();
|
||||
|
||||
if ($_GET['detail'] == 1) $iop->showFaults = 1;
|
||||
|
||||
if ($_GET['wire']) {
|
||||
$iop->showWire($_GET['wire']);
|
||||
} else {
|
||||
$iop->getEndpoints();
|
||||
$iop->getResults();
|
||||
|
||||
if ($_GET['test']) {
|
||||
$iop->currentTest = $_GET['test'];
|
||||
$iop->useWSDL = $_GET['wsdl']?$_GET['wsdl']:0;
|
||||
$iop->paramType = $_GET['type']?$_GET['type']:'php';
|
||||
$iop->outputTable();
|
||||
} else {
|
||||
$iop->outputTables();
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
205
thirdparty/pear/SOAP/Interop/interop_client_run.php
vendored
205
thirdparty/pear/SOAP/Interop/interop_client_run.php
vendored
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
// this script is usefull for quickly testing stuff, use the 'pretty' file for html output
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_client_run.php,v 1.11 2007/01/26 15:03:24 yunosh Exp $
|
||||
//
|
||||
|
||||
if (isset($_SERVER['SERVER_NAME'])) {
|
||||
die("full test run cannot be done via webserver.");
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require 'Console/Getopt.php';
|
||||
require_once 'interop_client.php';
|
||||
|
||||
$INTEROP_LOCAL_SERVER = TRUE;// add local server to endpoints
|
||||
|
||||
$iop =& new Interop_Client();
|
||||
|
||||
// debug output
|
||||
$iop->show = 1;
|
||||
$iop->debug = 0;
|
||||
$iop->showFaults = 0; // used in result table output
|
||||
$restrict = null;
|
||||
|
||||
$args = Console_Getopt::getopt($_SERVER['argv'],
|
||||
'c:dehl:m:np:r:s:t:v:wq',
|
||||
array('help'));
|
||||
if (PEAR::isError($args)) {
|
||||
echo "\n" . $args->getMessage() . "\n\n";
|
||||
help();
|
||||
exit;
|
||||
}
|
||||
|
||||
function help() {
|
||||
print <<<END
|
||||
interop_client_run.php [options]
|
||||
-c pear|php-soap client type (not implemented yet)
|
||||
-d turn on debug output
|
||||
-e fetch interop test information
|
||||
-h this help
|
||||
-l list comma seperated list of endpoint names to skip
|
||||
-m method_name specific soap method to test
|
||||
-n do not save results to database
|
||||
-p t|e print list of [t]ests or [e]ndpoints
|
||||
-r string restrict tests to those whose name starts with...
|
||||
-s server_name test a specific server
|
||||
-t test_name run a specific set of tests
|
||||
-v php|soapval run tests with specific param types (requires -t)
|
||||
-w run wsdl tests only (requires -t)
|
||||
-q do not run tests
|
||||
|
||||
END;
|
||||
}
|
||||
|
||||
function print_test_names()
|
||||
{
|
||||
global $iop;
|
||||
print "Interop tests supported:\n";
|
||||
foreach ($iop->tests as $test) {
|
||||
print " $test\n";
|
||||
}
|
||||
}
|
||||
|
||||
function print_endpoint_names()
|
||||
{
|
||||
global $iop;
|
||||
|
||||
if (!class_exists('G')) {
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
|
||||
$filter = new InputFilter();
|
||||
$currTest = $filter->xssFilterHard($iop->currentTest);
|
||||
|
||||
if (!$iop->getEndpoints($iop->currentTest)) {
|
||||
die("Unable to retrieve endpoints for $currTest\n");
|
||||
}
|
||||
print "Interop Servers for $currTestt:\n";
|
||||
foreach ($iop->endpoints as $server) {
|
||||
print " $server->name\n";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($args[0] as $arg) {
|
||||
switch($arg[0]) {
|
||||
case 'c':
|
||||
$iop->client_type = $arg[1];
|
||||
break;
|
||||
case 'd':
|
||||
$iop->debug = true;
|
||||
break;
|
||||
case 'e':
|
||||
$iop->fetchEndpoints();
|
||||
break;
|
||||
case 'h':
|
||||
case '--help':
|
||||
help();
|
||||
exit(0);
|
||||
case 'l':
|
||||
$iop->skipEndpointList = explode(',', $arg[1]);
|
||||
break;
|
||||
case 'm':
|
||||
$iop->testMethod = $arg[1];
|
||||
break;
|
||||
case 'n':
|
||||
$iop->nosave = true;
|
||||
break;
|
||||
case 'p':
|
||||
if ($arg[1] == 't') {
|
||||
print_test_names();
|
||||
} elseif ($arg[1] == 'e') {
|
||||
if (!$iop->currentTest) {
|
||||
print "You need to specify a test with -t\n";
|
||||
exit(0);
|
||||
}
|
||||
print_endpoint_names();
|
||||
} else {
|
||||
die("invalid print argument\n");
|
||||
}
|
||||
exit(0);
|
||||
case 'r':
|
||||
$restrict = $arg[1];
|
||||
break;
|
||||
case 's':
|
||||
$iop->specificEndpoint = $arg[1];
|
||||
break;
|
||||
case 't':
|
||||
$iop->currentTest = $arg[1];
|
||||
break;
|
||||
case 'v':
|
||||
if ($arg[1] != 'php' && $arg[1] != 'soapval') {
|
||||
|
||||
if (!class_exists('G')) {
|
||||
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
|
||||
$docuroot = explode( '/', $realdocuroot );
|
||||
array_pop( $docuroot );
|
||||
$pathhome = implode( '/', $docuroot ) . '/';
|
||||
array_pop( $docuroot );
|
||||
$pathTrunk = implode( '/', $docuroot ) . '/';
|
||||
require_once($pathTrunk.'gulliver/system/class.g.php');
|
||||
}
|
||||
|
||||
$filter = new InputFilter();
|
||||
$arg[1] = $filter->xssFilterHard($arg[1]);
|
||||
|
||||
die('Incorrect value for argument v: ' . $arg[1] . "\n");
|
||||
}
|
||||
$iop->paramType = $arg[1];
|
||||
break;
|
||||
case 'w':
|
||||
$iop->useWSDL = true;
|
||||
break;
|
||||
case 'q':
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// These are endpoints that are listed in the interop server, but do not realy
|
||||
// exist any longer.
|
||||
$bad = array('Spheon JSOAP', 'Phalanx', 'SilverStream', 'SOAPx4 (PHP)',
|
||||
'Virtuoso (development)', 'Zolera SOAP Infrastructure');
|
||||
$iop->skipEndpointList = array_merge($iop->skipEndpointList, $bad);
|
||||
|
||||
if ($restrict) {
|
||||
$tests = $iop->tests;
|
||||
$iop->tests = array();
|
||||
foreach ($tests as $test) {
|
||||
if (stristr($test, $restrict)) {
|
||||
$iop->tests[] = $test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($iop->currentTest) {
|
||||
$iop->doTest(); // run a single set of tests using above options
|
||||
} else {
|
||||
// $iop->doGroupTests(); // run a group of tests set in $currentTest
|
||||
$iop->doTests(); // run all tests, ignore above options
|
||||
}
|
||||
|
||||
echo "done\n";
|
||||
@@ -1,76 +0,0 @@
|
||||
# Database soapinterop running on localhost
|
||||
|
||||
# phpMyAdmin MySQL-Dump
|
||||
# version 2.2.5
|
||||
# http://phpwizard.net/phpMyAdmin/
|
||||
# http://phpmyadmin.sourceforge.net/ (download page)
|
||||
#
|
||||
# Host: localhost
|
||||
# Generation Time: Aug 31, 2002 at 06:36 PM
|
||||
# Server version: 3.23.49
|
||||
# PHP Version: 4.2.1
|
||||
# Database : `soapinterop`
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table `clientinfo`
|
||||
#
|
||||
|
||||
CREATE TABLE clientinfo (
|
||||
id char(40) NOT NULL default '',
|
||||
name char(100) NOT NULL default '',
|
||||
version char(20) NOT NULL default '',
|
||||
resultsURL char(255) NOT NULL default ''
|
||||
) TYPE=InnoDB;
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table `results`
|
||||
#
|
||||
|
||||
CREATE TABLE results (
|
||||
id int(11) NOT NULL auto_increment,
|
||||
client varchar(100) NOT NULL default '0',
|
||||
endpoint int(11) NOT NULL default '0',
|
||||
stamp int(11) NOT NULL default '0',
|
||||
class varchar(50) NOT NULL default '',
|
||||
type varchar(10) default NULL,
|
||||
wsdl int(11) NOT NULL default '0',
|
||||
function varchar(255) NOT NULL default '',
|
||||
result varchar(25) NOT NULL default '',
|
||||
error text,
|
||||
wire text NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) TYPE=InnoDB;
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table `serverinfo`
|
||||
#
|
||||
|
||||
CREATE TABLE serverinfo (
|
||||
id int(11) NOT NULL auto_increment,
|
||||
service_id char(40) NOT NULL default '',
|
||||
name char(100) NOT NULL default '',
|
||||
version char(20) NOT NULL default '',
|
||||
endpointURL char(255) NOT NULL default '',
|
||||
wsdlURL char(255) NOT NULL default '',
|
||||
PRIMARY KEY (id)
|
||||
) TYPE=InnoDB;
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table `services`
|
||||
#
|
||||
|
||||
CREATE TABLE services (
|
||||
id char(40) NOT NULL default '',
|
||||
name char(50) NOT NULL default '',
|
||||
description char(255) NOT NULL default '',
|
||||
wsdlURL char(255) NOT NULL default '',
|
||||
websiteURL char(255) NOT NULL default '',
|
||||
PRIMARY KEY (id)
|
||||
) TYPE=InnoDB;
|
||||
|
||||
|
||||
|
||||
137
thirdparty/pear/SOAP/Interop/interop_test.php
vendored
137
thirdparty/pear/SOAP/Interop/interop_test.php
vendored
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: interop_test.php,v 1.10 2007/01/26 17:21:44 yunosh Exp $
|
||||
//
|
||||
require_once 'SOAP/Value.php';
|
||||
|
||||
define('SOAP_TEST_ACTOR_NEXT','http://schemas.xmlsoap.org/soap/actor/next');
|
||||
define('SOAP_TEST_ACTOR_OTHER','http://some/other/actor');
|
||||
|
||||
class SOAP_Interop_Test {
|
||||
|
||||
var $type = 'php';
|
||||
var $test_name = null;
|
||||
var $method_name = null;
|
||||
var $method_params = null;
|
||||
var $expect = null;
|
||||
var $expect_fault = false;
|
||||
var $headers = null;
|
||||
var $headers_expect = null;
|
||||
var $result = array();
|
||||
var $show = 1;
|
||||
var $debug = 0;
|
||||
var $encoding = SOAP_DEFAULT_ENCODING;
|
||||
|
||||
/**
|
||||
* If multiple services, this sets to a specific service.
|
||||
*/
|
||||
var $service = null;
|
||||
|
||||
function SOAP_Interop_Test($methodname, $params, $expect = null)
|
||||
{
|
||||
if (strchr($methodname, '(')) {
|
||||
preg_match('/(.*)\((.*)\)/', $methodname, $matches);
|
||||
$this->test_name = $methodname;
|
||||
$this->method_name = $matches[1];
|
||||
} else {
|
||||
$this->test_name = $this->method_name = $methodname;
|
||||
}
|
||||
$this->method_params = $params;
|
||||
$this->expect = $expect;
|
||||
|
||||
// determine test type
|
||||
if ($params) {
|
||||
$v = array_values($params);
|
||||
if (gettype($v[0]) == 'object' &&
|
||||
strtolower(get_class($v[0])) == 'soap_value') {
|
||||
$this->type = 'soapval';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setResult($ok, $result, $wire, $error = '', $fault = null)
|
||||
{
|
||||
$this->result['success'] = $ok;
|
||||
$this->result['result'] = $result;
|
||||
$this->result['error'] = $error;
|
||||
$this->result['wire'] = $wire;
|
||||
$this->result['fault'] = $fault;
|
||||
}
|
||||
|
||||
function reset()
|
||||
{
|
||||
$this->result = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints simple output about a methods result.
|
||||
*/
|
||||
function showTestResult($debug = 0)
|
||||
{
|
||||
// Debug output
|
||||
if ($debug) {
|
||||
$this->show = 1;
|
||||
echo str_repeat('-', 50) . "\n";
|
||||
}
|
||||
|
||||
echo "Testing $this->test_name: ";
|
||||
if ($this->headers) {
|
||||
$hc = count($this->headers);
|
||||
for ($i = 0; $i < $hc; $i++) {
|
||||
$h = $this->headers[$i];
|
||||
if (strtolower(get_class($h)) == 'soap_header') {
|
||||
echo "\n {$h->name},{$h->attributes['SOAP-ENV:actor']},{$h->attributes['SOAP-ENV:mustUnderstand']} : ";
|
||||
} else {
|
||||
if (!$h[4]) {
|
||||
$h[4] = SOAP_TEST_ACTOR_NEXT;
|
||||
}
|
||||
if (!$h[3]) {
|
||||
$h[3] = 0;
|
||||
}
|
||||
echo "\n $h[0],$h[4],$h[3] : ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "method params: ";
|
||||
print_r($this->params);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$ok = $this->result['success'];
|
||||
if ($ok) {
|
||||
echo "SUCCESS\n";
|
||||
} else {
|
||||
$fault = $this->result['fault'];
|
||||
if ($fault) {
|
||||
echo "FAILED: [{$fault->faultcode}] {$fault->faultstring}\n";
|
||||
if (!empty($fault->faultdetail)) {
|
||||
echo $fault->faultdetail . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "FAILED: " . $this->result['result'] . "\n";
|
||||
}
|
||||
}
|
||||
if ($debug) {
|
||||
echo "\n" . $this->result['wire'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
require_once("SOAP/Parser.php");
|
||||
require_once("SOAP/Value.php");
|
||||
|
||||
function number_compare($f1, $f2)
|
||||
{
|
||||
# figure out which has the least fractional digits
|
||||
preg_match('/.*?\.(.*)/',$f1,$m1);
|
||||
preg_match('/.*?\.(.*)/',$f2,$m2);
|
||||
#print_r($m1);
|
||||
# always use at least 2 digits of precision
|
||||
$d = max(min(strlen(count($m1)?$m1[1]:'0'),strlen(count($m2)?$m2[1]:'0')),2);
|
||||
if ($d > 3) $d = 3;
|
||||
$f1 = round($f1, $d);
|
||||
$f2 = round($f2, $d);
|
||||
return bccomp($f1, $f2, $d) == 0;
|
||||
}
|
||||
|
||||
function boolean_compare($f1, $f2)
|
||||
{
|
||||
if (($f1 == 'true' || $f1 === TRUE || $f1 != 0) &&
|
||||
($f2 == 'true' || $f2 === TRUE || $f2 != 0)) return TRUE;
|
||||
if (($f1 == 'false' || $f1 === FALSE || $f1 == 0) &&
|
||||
($f2 == 'false' || $f2 === FALSE || $f2 == 0)) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function string_compare($e1, $e2)
|
||||
{
|
||||
if (is_numeric($e1) && is_numeric($e2)) {
|
||||
return number_compare($e1, $e2);
|
||||
}
|
||||
# handle dateTime comparison
|
||||
$e1_type = gettype($e1);
|
||||
$e2_type = gettype($e2);
|
||||
$ok = FALSE;
|
||||
if ($e1_type == "string") {
|
||||
require_once 'SOAP/Type/dateTime.php';
|
||||
$dt =& new SOAP_Type_dateTime();
|
||||
$ok = $dt->compare($e1, $e2) == 0;
|
||||
}
|
||||
return $ok || $e1 == $e2 || strcasecmp(trim($e1), trim($e2)) == 0;
|
||||
}
|
||||
|
||||
function array_compare(&$ar1, &$ar2)
|
||||
{
|
||||
if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return FALSE;
|
||||
# first a shallow diff
|
||||
if (count($ar1) != count($ar2)) return FALSE;
|
||||
$diff = array_diff($ar1, $ar2);
|
||||
if (count($diff) == 0) return TRUE;
|
||||
|
||||
# diff failed, do a full check of the array
|
||||
foreach ($ar1 as $k => $v) {
|
||||
#print "comparing $v == $ar2[$k]\n";
|
||||
if (gettype($v) == "array") {
|
||||
if (!array_compare($v, $ar2[$k])) return FALSE;
|
||||
} else {
|
||||
if (!string_compare($v, $ar2[$k])) return FALSE;
|
||||
if ($type == 'float')
|
||||
# we'll only compare to 3 digits of precision
|
||||
$ok = number_compare($expect, $result,3);
|
||||
if ($type == 'boolean')
|
||||
$ok = boolean_compare($expect, $result);
|
||||
else
|
||||
$ok = string_compare($expect, $result);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
function &parseMessage($msg)
|
||||
{
|
||||
# strip line endings
|
||||
#$msg = preg_replace('/\r|\n/', ' ', $msg);
|
||||
$response =& new SOAP_Parser($msg);
|
||||
if ($response->fault) {
|
||||
return $response->fault->getFault();
|
||||
}
|
||||
$return =& $response->getResponse();
|
||||
$v =& $response->decode($return);
|
||||
if (gettype($v) == 'array' && count($v)==1) {
|
||||
return array_shift($v);
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
230
thirdparty/pear/SOAP/Interop/params_Round2Base.php
vendored
230
thirdparty/pear/SOAP/Interop/params_Round2Base.php
vendored
@@ -1,230 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_Round2Base.php,v 1.6 2007/01/26 14:54:51 yunosh Exp $
|
||||
//
|
||||
|
||||
require_once 'params_values.php';
|
||||
require_once 'interop_test.php';
|
||||
define('INTEROP_R2BASE', 'Round 2 Base');
|
||||
|
||||
//***********************************************************
|
||||
// Base echoString
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString',
|
||||
array('inputString' => $string),
|
||||
$soap_test_null);
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString',
|
||||
array('inputString' => $string_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString(null)',
|
||||
array('inputString' => $string_null));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString(null)',
|
||||
array('inputString' => $string_null_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString(entities)',
|
||||
array('inputString' => $string_entities));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoString(entities)',
|
||||
array('inputString' => $string_entities_soapval));
|
||||
$test = new SOAP_Interop_Test(
|
||||
'echoString(utf-8)',
|
||||
array('inputString' => $string_utf8));
|
||||
$test->encoding = 'UTF-8';
|
||||
$soap_tests[INTEROP_R2BASE][] = $test;
|
||||
unset($test);
|
||||
|
||||
$test = new SOAP_Interop_Test(
|
||||
'echoString(utf-8)',
|
||||
array('inputString' => $string_utf8_soapval));
|
||||
$test->encoding = 'UTF-8';
|
||||
$soap_tests[INTEROP_R2BASE][] = $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// Base echoStringArray
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray',
|
||||
array('inputStringArray' => $string_array));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray',
|
||||
array('inputStringArray' => $string_array_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray(one)',
|
||||
array('inputStringArray' => $string_array_one));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray(one)',
|
||||
array('inputStringArray' => $string_array_one_soapval));
|
||||
// null array test
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray(null)',
|
||||
array('inputStringArray' => $string_array_null));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStringArray(null)',
|
||||
array('inputStringArray' => $string_array_null_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoInteger
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoInteger',
|
||||
array('inputInteger' => $integer));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoInteger',
|
||||
array('inputInteger' => $integer_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoIntegerArray
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoIntegerArray',
|
||||
array('inputIntegerArray' => $integer_array));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoIntegerArray',
|
||||
array('inputIntegerArray' => $integer_array_soapval));
|
||||
|
||||
// null array test
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoIntegerArray(null)',
|
||||
array('inputIntegerArray' => $integer_array_null));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoIntegerArray(null)',
|
||||
array('inputIntegerArray' => $integer_array_null_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoFloat
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoFloat',
|
||||
array('inputFloat' => $float));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoFloat',
|
||||
array('inputFloat' => $float_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoFloatArray
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoFloatArray',
|
||||
array('inputFloatArray' => $float_array));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoFloatArray',
|
||||
array('inputFloatArray' => $float_array_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoStruct
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStruct',
|
||||
array('inputStruct' => $soapstruct));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStruct',
|
||||
array('inputStruct' => $soapstruct_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoStructArray
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStructArray',
|
||||
array('inputStructArray' => $soapstruct_array));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoStructArray',
|
||||
array('inputStructArray' => $soapstruct_array_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoVoid
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test('echoVoid', null);
|
||||
$test = new SOAP_Interop_Test('echoVoid', null);
|
||||
$test->type = 'soapval';
|
||||
$soap_tests[INTEROP_R2BASE][] = $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// Base echoBase64
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBase64',
|
||||
array('inputBase64' => $base64),
|
||||
'Nebraska');
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBase64',
|
||||
array('inputBase64' => $base64_soapval),
|
||||
'Nebraska');
|
||||
|
||||
//***********************************************************
|
||||
// Base echoHexBinary
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoHexBinary',
|
||||
array('inputHexBinary' => $hexBin));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoHexBinary',
|
||||
array('inputHexBinary' => $hexBin_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoDecimal
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoDecimal',
|
||||
array('inputDecimal' => $decimal));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoDecimal',
|
||||
array('inputDecimal' => $decimal_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoDate
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoDate',
|
||||
array('inputDate' => $dateTime));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoDate',
|
||||
array('inputDate' => $dateTime_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// Base echoBoolean
|
||||
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(TRUE)',
|
||||
array('inputBoolean' => $boolean_true));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(TRUE)',
|
||||
array('inputBoolean' => $boolean_true_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(FALSE)',
|
||||
array('inputBoolean' => $boolean_false));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(FALSE)',
|
||||
array('inputBoolean' => $boolean_false_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(1)',
|
||||
array('inputBoolean' => $boolean_one));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(1)',
|
||||
array('inputBoolean' => $boolean_one_soapval));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(0)',
|
||||
array('inputBoolean' => $boolean_zero));
|
||||
$soap_tests[INTEROP_R2BASE][] = new SOAP_Interop_Test(
|
||||
'echoBoolean(0)',
|
||||
array('inputBoolean' => $boolean_zero_soapval));
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_Round2GroupB.php,v 1.4 2003/04/07 00:51:17 shane Exp $
|
||||
//
|
||||
require_once 'params_values.php';
|
||||
require_once 'interop_test.php';
|
||||
define('INTEROP_R2GROUPB','Round 2 Group B');
|
||||
//***********************************************************
|
||||
// GroupB echoStructAsSimpleTypes
|
||||
|
||||
$expect = array(
|
||||
'outputString'=>'arg',
|
||||
'outputInteger'=>34,
|
||||
'outputFloat'=>325.325
|
||||
);
|
||||
$soap_tests[INTEROP_R2GROUPB][] =
|
||||
new SOAP_Interop_Test('echoStructAsSimpleTypes',
|
||||
array('inputStruct' => &$soapstruct), $expect);
|
||||
$soap_tests[INTEROP_R2GROUPB][] =
|
||||
new SOAP_Interop_Test('echoStructAsSimpleTypes',
|
||||
array('inputStruct' => &$soapstruct_soapval), $expect);
|
||||
|
||||
//***********************************************************
|
||||
// GroupB echoSimpleTypesAsStruct
|
||||
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoSimpleTypesAsStruct',
|
||||
$simpletypes, $soapstruct);
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoSimpleTypesAsStruct',
|
||||
$simpletypes_soapval, $soapstruct);
|
||||
|
||||
//***********************************************************
|
||||
// GroupB echo2DStringArray
|
||||
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echo2DStringArray',
|
||||
array('input2DStringArray' => &$multidimarray));
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echo2DStringArray',
|
||||
array('input2DStringArray' => &$multidimarray_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// GroupB echoNestedStruct
|
||||
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoNestedStruct',
|
||||
array('inputStruct' => &$soapstructstruct));
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoNestedStruct',
|
||||
array('inputStruct' => &$soapstructstruct_soapval));
|
||||
|
||||
//***********************************************************
|
||||
// GroupB echoNestedArray
|
||||
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoNestedArray',
|
||||
array('inputStruct' => &$soaparraystruct));
|
||||
$soap_tests[INTEROP_R2GROUPB][] =& new SOAP_Interop_Test('echoNestedArray',
|
||||
array('inputStruct' => &$soaparraystruct_soapval));
|
||||
|
||||
|
||||
?>
|
||||
235
thirdparty/pear/SOAP/Interop/params_Round2GroupC.php
vendored
235
thirdparty/pear/SOAP/Interop/params_Round2GroupC.php
vendored
@@ -1,235 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_Round2GroupC.php,v 1.4 2003/04/07 00:51:17 shane Exp $
|
||||
//
|
||||
require_once 'params_values.php';
|
||||
require_once 'interop_test.php';
|
||||
define('INTEROP_R2GROUPC','Round 2 Group C');
|
||||
//***********************************************************
|
||||
// echoMeStringRequest php val tests
|
||||
|
||||
// echoMeStringRequest with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeStringRequest', &$string, 0,SOAP_TEST_ACTOR_NEXT);
|
||||
$test->headers_expect['echoMeStringRequest'] = array('echoMeStringResponse'=>&$string);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeStringRequest', &$string, 1,SOAP_TEST_ACTOR_NEXT);
|
||||
$test->headers_expect['echoMeStringRequest'] = array('echoMeStringResponse'=>&$string);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeStringRequest', &$string, 0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStringRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeStringRequest', &$string, 1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStringRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// echoMeStringRequest soapval tests
|
||||
|
||||
// echoMeStringRequest with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeStringRequest', 'string', $string);
|
||||
$test->headers_expect['echoMeStringRequest'] = array('echoMeStringResponse'=>&$string);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeStringRequest', 'string', $string, 1);
|
||||
$test->type = 'soapval'; // force a soapval version of this test
|
||||
$test->headers_expect['echoMeStringRequest'] = array('echoMeStringResponse'=>&$string);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeStringRequest', 'string', $string, 0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStringRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeStringRequest', 'string', $string, 1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStringRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStringRequest with endpoint header destination, must understand,
|
||||
// invalid namespace, should recieve a fault
|
||||
#$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
#$test->type = 'soapval';
|
||||
#$test->headers[] =& new SOAP_Header('{http://unknown.org/echoheader/}echoMeStringRequest', 'string', 'hello world', 1);
|
||||
#$test->headers_expect['echoMeStringRequest'] = array();
|
||||
#$test->expect_fault = TRUE;
|
||||
#$soap_tests[INTEROP_R2GROUPC][] = $test;
|
||||
|
||||
//***********************************************************
|
||||
// php val tests
|
||||
// echoMeStructRequest with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE);
|
||||
$test->headers_expect['echoMeStructRequest'] =
|
||||
array('echoMeStructResponse'=> &$soapstruct);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,1);
|
||||
$test->headers_expect['echoMeStructRequest'] =
|
||||
array('echoMeStructResponse'=> &$soapstruct);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStructRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStructRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// soapval tests
|
||||
// echoMeStructRequest with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE);
|
||||
$test->headers_expect['echoMeStructRequest'] =
|
||||
array('echoMeStructResponse'=> &$soapstruct);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,1);
|
||||
$test->headers_expect['echoMeStructRequest'] =
|
||||
array('echoMeStructResponse'=> &$soapstruct);
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStructRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeStructRequest with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest',TRUE,1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeStructRequest'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// echoMeUnknown php val tests
|
||||
// echoMeUnknown with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeUnknown', $string,0,SOAP_TEST_ACTOR_NEXT);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeUnknown', $string,1,SOAP_TEST_ACTOR_NEXT);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$test->expect_fault = TRUE;
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeUnknown', $string,0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->headers[] = array('{http://soapinterop.org/echoheader/}echoMeUnknown', $string, 1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
//***********************************************************
|
||||
// echoMeUnknown soapval tests
|
||||
// echoMeUnknown with endpoint as header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeUnknown','string',$string);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint as header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeUnknown','string',$string,1);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$test->expect_fault = TRUE;
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint NOT header destination, doesn't have to understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeUnknown','string',$string, 0, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
// echoMeUnknown with endpoint NOT header destination, must understand
|
||||
$test =& new SOAP_Interop_Test('echoVoid', NULL);
|
||||
$test->type = 'soapval';
|
||||
$test->headers[] =& new SOAP_Header('{http://soapinterop.org/echoheader/}echoMeUnknown','string',$string, 1, SOAP_TEST_ACTOR_OTHER);
|
||||
$test->headers_expect['echoMeUnknown'] = array();
|
||||
$soap_tests[INTEROP_R2GROUPC][] =& $test;
|
||||
unset($test);
|
||||
|
||||
|
||||
?>
|
||||
121
thirdparty/pear/SOAP/Interop/params_Round3GroupD.php
vendored
121
thirdparty/pear/SOAP/Interop/params_Round3GroupD.php
vendored
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_Round3GroupD.php,v 1.7 2003/04/14 01:40:21 shane Exp $
|
||||
//
|
||||
require_once 'params_values.php';
|
||||
require_once 'interop_test.php';
|
||||
define('INTEROP_R3D_COMPOUND1','Round 3 Group D Compound 1');
|
||||
define('INTEROP_R3D_COMPOUND2','Round 3 Group D Compound 2');
|
||||
define('INTEROP_R3D_DOCLIT','Round 3 Group D DocLit');
|
||||
define('INTEROP_R3D_DOCLIT_PARAM','Round 3 Group D DocLitParams');
|
||||
define('INTEROP_R3D_IMPORT1','Round 3 Group D Import 1');
|
||||
define('INTEROP_R3D_IMPORT2','Round 3 Group D Import 2');
|
||||
define('INTEROP_R3D_IMPORT3','Round 3 Group D Import 3');
|
||||
define('INTEROP_R3D_RPCENC','Round 3 Group D RpcEnc');
|
||||
//***********************************************************
|
||||
// GroupD
|
||||
|
||||
# COMPOUND 1 tests
|
||||
# http://www.whitemesa.net/wsdl/r3/compound1.wsdl
|
||||
$test =& new SOAP_Interop_Test('echoPerson', array('x_Person'=>&$person));
|
||||
$test->type = 'php'; // force to php testing
|
||||
$soap_tests[INTEROP_R3D_COMPOUND1][] = &$test;
|
||||
unset($test);
|
||||
|
||||
$test =& new SOAP_Interop_Test('echoDocument', array('x_Document'=>'Test Document Here'));
|
||||
$test->type = 'php'; // force to php testing
|
||||
$soap_tests[INTEROP_R3D_COMPOUND1][] = &$test;
|
||||
unset($test);
|
||||
|
||||
# COMPOUND 2 tests
|
||||
# http://www.whitemesa.net/wsdl/r3/compound2.wsdl
|
||||
$test =& new SOAP_Interop_Test('echoEmployee', array('x_Employee'=>&$employee));
|
||||
$test->type = 'php'; // force to php testing
|
||||
$soap_tests[INTEROP_R3D_COMPOUND2][] = &$test;
|
||||
unset($test);
|
||||
|
||||
# DOC LIT Tests
|
||||
# http://www.whitemesa.net/wsdl/r3/interoptestdoclit.wsdl
|
||||
$soap_tests[INTEROP_R3D_DOCLIT][] =&
|
||||
new SOAP_Interop_Test('echoString',
|
||||
array('echoStringParam' => &$string));
|
||||
$soap_tests[INTEROP_R3D_DOCLIT][] =&
|
||||
new SOAP_Interop_Test('echoStringArray',
|
||||
array('echoStringArrayParam' => &$string_array));
|
||||
$soap_tests[INTEROP_R3D_DOCLIT][] =&
|
||||
new SOAP_Interop_Test('echoStruct',
|
||||
array('echoStructParam' => &$soapstruct));
|
||||
#$soap_tests[INTEROP_R3D_DOCLIT][] =
|
||||
# new SOAP_Interop_Test('echoVoid', NULL);
|
||||
|
||||
# DOC LIT w/Params Tests
|
||||
# http://www.whitemesa.net/wsdl/r3/interoptestdoclitparameters.wsdl
|
||||
$soap_tests[INTEROP_R3D_DOCLIT_PARAM][] =&
|
||||
new SOAP_Interop_Test('echoString',
|
||||
array('param0' => $string));
|
||||
$soap_tests[INTEROP_R3D_DOCLIT_PARAM][] =&
|
||||
new SOAP_Interop_Test('echoStringArray',
|
||||
array('param0' => &$string_array));
|
||||
$soap_tests[INTEROP_R3D_DOCLIT_PARAM][] =&
|
||||
new SOAP_Interop_Test('echoStruct',
|
||||
array('param0' => &$soapstruct));
|
||||
$soap_tests[INTEROP_R3D_DOCLIT_PARAM][] =&
|
||||
new SOAP_Interop_Test('echoVoid', NULL);
|
||||
|
||||
# IMPORT 1 tests
|
||||
# http://www.whitemesa.net/wsdl/r3/import1.wsdl
|
||||
$soap_tests[INTEROP_R3D_IMPORT1][] =&
|
||||
new SOAP_Interop_Test('echoString',
|
||||
array('x' => &$string));
|
||||
|
||||
# IMPORT 2 tests
|
||||
# http://www.whitemesa.net/wsdl/r3/import2.wsdl
|
||||
$soap_tests[INTEROP_R3D_IMPORT2][] =&
|
||||
new SOAP_Interop_Test('echoStruct',
|
||||
array('inputStruct' => &$soapstruct));
|
||||
|
||||
# IMPORT 2 tests
|
||||
# http://www.whitemesa.net/wsdl/r3/import3.wsdl
|
||||
$test =& new SOAP_Interop_Test('echoStruct',
|
||||
array('inputStruct' => &$soapstruct));
|
||||
$test->service = 'Import3';
|
||||
$soap_tests[INTEROP_R3D_IMPORT3][] = &$test;
|
||||
unset($test);
|
||||
|
||||
$test =& new SOAP_Interop_Test('echoStructArray',
|
||||
array('inputArray' =>&$soapstruct_array));
|
||||
$test->service = 'Import3';
|
||||
$soap_tests[INTEROP_R3D_IMPORT3][] = &$test;
|
||||
unset($test);
|
||||
|
||||
# RPC ENCODED Tests
|
||||
# http://www.whitemesa.net/wsdl/r3/interoptestdoclitparameters.wsdl
|
||||
$soap_tests[INTEROP_R3D_RPCENC][] =&
|
||||
new SOAP_Interop_Test('echoString',
|
||||
array('param0' => &$string));
|
||||
$soap_tests[INTEROP_R3D_RPCENC][] =&
|
||||
new SOAP_Interop_Test('echoStringArray',
|
||||
array('param0' => &$string_array));
|
||||
$soap_tests[INTEROP_R3D_RPCENC][] =&
|
||||
new SOAP_Interop_Test('echoStruct',
|
||||
array('param0' => &$soapstruct));
|
||||
$soap_tests[INTEROP_R3D_RPCENC][] =&
|
||||
new SOAP_Interop_Test('echoVoid', NULL);
|
||||
|
||||
?>
|
||||
162
thirdparty/pear/SOAP/Interop/params_classes.php
vendored
162
thirdparty/pear/SOAP/Interop/params_classes.php
vendored
@@ -1,162 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_classes.php,v 1.8 2007/01/21 16:15:00 yunosh Exp $
|
||||
//
|
||||
require_once 'SOAP/Value.php';
|
||||
|
||||
class SOAPStruct {
|
||||
var $varString;
|
||||
var $varInt;
|
||||
var $varFloat;
|
||||
function SOAPStruct($s=NULL, $i=NULL, $f=NULL) {
|
||||
$this->varString = $s;
|
||||
$this->varInt = $i;
|
||||
$this->varFloat = $f;
|
||||
}
|
||||
|
||||
function __to_soap($name = 'inputStruct', $header=false, $mustUnderstand=0, $actor='http://schemas.xmlsoap.org/soap/actor/next')
|
||||
{
|
||||
$inner[] = new SOAP_Value('varString','string',$this->varString);
|
||||
$inner[] = new SOAP_Value('varInt','int',$this->varInt);
|
||||
$inner[] = new SOAP_Value('varFloat','float',$this->varFloat);
|
||||
if ($header) {
|
||||
return new SOAP_Header($name,'{http://soapinterop.org/xsd}SOAPStruct',$inner,$mustUnderstand,$actor);
|
||||
}
|
||||
return new SOAP_Value($name,'{http://soapinterop.org/xsd}SOAPStruct',$inner);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class SOAPStructStruct {
|
||||
var $varString;
|
||||
var $varInt;
|
||||
var $varFloat;
|
||||
var $varStruct;
|
||||
function SOAPStructStruct($s=NULL, $i=NULL, $f=NULL, $ss=NULL) {
|
||||
// XXX unfortunately, a copy of $ss will occure here
|
||||
// ze2 can fix this I think
|
||||
$this->varString = $s;
|
||||
$this->varInt = $i;
|
||||
$this->varFloat = $f;
|
||||
$this->varStruct = $ss;
|
||||
}
|
||||
|
||||
function __to_soap($name = 'inputStruct')
|
||||
{
|
||||
$v[] = new SOAP_Value('varString','string',$this->varString);
|
||||
$v[] = new SOAP_Value('varInt','int',$this->varInt);
|
||||
$v[] = new SOAP_Value('varFloat','float',$this->varFloat);
|
||||
$v[] = $this->varStruct->__to_soap('varStruct');
|
||||
return new SOAP_Value($name,'{http://soapinterop.org/xsd}SOAPStructStruct',$v);
|
||||
}
|
||||
}
|
||||
|
||||
class SOAPArrayStruct {
|
||||
var $varString;
|
||||
var $varInt;
|
||||
var $varFloat;
|
||||
var $varArray;
|
||||
function SOAPArrayStruct($s=NULL, $i=NULL, $f=NULL, $ss=NULL) {
|
||||
// XXX unfortunately, a copy of $ss will occure here
|
||||
// ze2 can fix this I think
|
||||
$this->varString = $s;
|
||||
$this->varInt = $i;
|
||||
$this->varFloat = $f;
|
||||
$this->varArray = $ss;
|
||||
}
|
||||
|
||||
function __to_soap($name = 'inputStruct')
|
||||
{
|
||||
$ar = array();
|
||||
$c = count($this->varArray);
|
||||
for ($i=0; $i<$c; $i++) {
|
||||
$ar[] = new SOAP_Value('item','string',$this->varArray[$i]);
|
||||
}
|
||||
$v[] = new SOAP_Value('varString','string',$this->varString);
|
||||
$v[] = new SOAP_Value('varInt','int',$this->varInt);
|
||||
$v[] = new SOAP_Value('varFloat','float',$this->varFloat);
|
||||
$v[] = new SOAP_Value('varArray',false,$ar);
|
||||
|
||||
return new SOAP_Value($name,'{http://soapinterop.org/xsd}SOAPArrayStruct',$v);
|
||||
}
|
||||
}
|
||||
|
||||
class Person {
|
||||
var $Age;
|
||||
var $ID;
|
||||
var $Name;
|
||||
var $Male;
|
||||
function Person($a=NULL, $i=NULL, $n=NULL, $m=NULL) {
|
||||
$this->Age = $a;
|
||||
$this->ID = $i;
|
||||
$this->Name = $n;
|
||||
$this->Male = $m;
|
||||
}
|
||||
|
||||
function __set_attribute($key, $value)
|
||||
{
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
function __to_soap($name = 'x_Person',$ns = 'http://soapinterop.org/xsd', $compound2=false)
|
||||
{
|
||||
if (!$compound2) {
|
||||
$v[] = new SOAP_Value("\{$ns}Age",'double',$this->Age);
|
||||
$v[] = new SOAP_Value("\{$ns}ID",'float',$this->ID);
|
||||
return new SOAP_Value("\{$ns}$name",'Person',
|
||||
$v,array('Name'=>$this->Name,'Male'=>$this->Male));
|
||||
} else
|
||||
$v[] = new SOAP_Value("\{$ns}Name",'string',$this->Name);
|
||||
$v[] = new SOAP_Value("\{$ns}Male",'boolean',$this->Male);
|
||||
return new SOAP_Value("\{$ns}$name",'Person',$v);
|
||||
}
|
||||
}
|
||||
|
||||
class x_Person extends Person {
|
||||
function x_Person($a=NULL, $i=NULL, $n=NULL, $m=NULL) {
|
||||
$parent->Person($a,$i,$n,$m);
|
||||
}
|
||||
}
|
||||
|
||||
class Employee {
|
||||
var $ID;
|
||||
var $salary;
|
||||
var $person; // class person2
|
||||
function Employee($person=NULL,$id=NULL,$salary=NULL) {
|
||||
$this->person = $person;
|
||||
$this->ID = $id;
|
||||
$this->salary = $salary;
|
||||
}
|
||||
|
||||
function __to_soap($name = 'x_Employee', $ns='http://soapinterop.org/employee')
|
||||
{
|
||||
$person = $this->person->__to_soap('person','http://soapinterop.org/person',true);
|
||||
$person->namespace = $ns;
|
||||
$va[] = $person;
|
||||
$va[] = new SOAP_Value("\{$ns}salary",'double',$this->salary);
|
||||
$va[] = new SOAP_Value("\{$ns}ID",'int',$this->ID);
|
||||
return new SOAP_Value("\{$ns}$name",'Employee',$va);
|
||||
}
|
||||
}
|
||||
|
||||
class x_Employee extends Employee {
|
||||
function x_Employee($person=NULL,$id=NULL,$salary=NULL) {
|
||||
$parent->Employee($person,$id,$salary);
|
||||
}
|
||||
}
|
||||
173
thirdparty/pear/SOAP/Interop/params_values.php
vendored
173
thirdparty/pear/SOAP/Interop/params_values.php
vendored
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: params_values.php,v 1.7 2007/01/26 15:18:21 yunosh Exp $
|
||||
//
|
||||
|
||||
require_once 'SOAP/Value.php';
|
||||
require_once 'params_classes.php';
|
||||
|
||||
$soap_test_null = null;
|
||||
|
||||
$string = 'Hello World';
|
||||
$string_soapval = new SOAP_Value('inputString', 'string', $string);
|
||||
$string_null = null;
|
||||
$string_null_soapval = new SOAP_Value('inputString', 'string', $string_null);
|
||||
$string_entities = "this is a test <hello>\n";
|
||||
$string_entities_soapval = new SOAP_Value('inputString', 'string', $string_entities);
|
||||
$string_utf8 = utf8_encode('ỗÈéóÒ₧⅜ỗỸ');
|
||||
$string_utf8_soapval = new SOAP_Value('inputString', 'string', $string_utf8);
|
||||
$string_array = array('good', 'bad');
|
||||
$string_array_soapval = new SOAP_Value(
|
||||
'inputStringArray',
|
||||
'Array',
|
||||
array(new SOAP_Value('item', 'string', 'good'),
|
||||
new SOAP_Value('item', 'string', 'bad')));
|
||||
|
||||
$string_array_one = array('good');
|
||||
$string_array_one_soapval = new SOAP_Value(
|
||||
'inputStringArray',
|
||||
'Array',
|
||||
array(new SOAP_Value('item', 'string', 'good')));
|
||||
|
||||
$string_array_null = null;
|
||||
$string_array_null_soapval = new SOAP_Value('inputStringArray', 'Array', null);
|
||||
$string_array_null_soapval->arrayType='{http://www.w3.org/2001/XMLSchema}string';
|
||||
|
||||
$integer = 12345;
|
||||
$integer_soapval = new SOAP_Value('inputInteger', 'int', $integer);
|
||||
$integer_array = array(1, 234324324, 2);
|
||||
$integer_array_soapval = new SOAP_Value(
|
||||
'inputIntegerArray',
|
||||
'Array',
|
||||
array(new SOAP_Value('item', 'int', 1),
|
||||
new SOAP_Value('item', 'int', 234324324),
|
||||
new SOAP_Value('item', 'int', 2)));
|
||||
|
||||
$integer_array_null = null;
|
||||
$integer_array_null_soapval = new SOAP_Value('inputIntegerArray', 'Array', null);
|
||||
$integer_array_null_soapval->arrayType='{http://www.w3.org/2001/XMLSchema}int';
|
||||
|
||||
$float = 123.45;
|
||||
$float_soapval = new SOAP_Value('inputFloat', 'float', $float);
|
||||
$float_array = array(1.0, 2343.24324, -2.5);
|
||||
$float_array_soapval = new SOAP_Value(
|
||||
'inputFloatArray',
|
||||
'Array',
|
||||
array(new SOAP_Value('item', 'float', 1.0),
|
||||
new SOAP_Value('item', 'float', 2343.24324),
|
||||
new SOAP_Value('item', 'float', -2.5)));
|
||||
|
||||
$float_array_null = null;
|
||||
$float_array_null_soapval = new SOAP_Value('inputFloatArray', 'Array', null);
|
||||
$float_array_null_soapval->arrayType='{http://www.w3.org/2001/XMLSchema}float';
|
||||
|
||||
$soapstruct = new SOAPStruct('arg', 34, 325.325);
|
||||
$soapstruct_soapval = $soapstruct->__to_soap();
|
||||
$soapstruct_header_soapval = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest');
|
||||
$soapstruct_array = array($soapstruct, $soapstruct, $soapstruct);
|
||||
$soapstruct_array_soapval = new SOAP_Value(
|
||||
'inputStructArray',
|
||||
'Array',
|
||||
array($soapstruct_soapval,
|
||||
$soapstruct_soapval,
|
||||
$soapstruct_soapval));
|
||||
|
||||
$soapstructstruct = new SOAPStructStruct('arg', 34, 325.325, $soapstruct);
|
||||
$soapstructstruct_soapval = $soapstructstruct->__to_soap();
|
||||
$soapstructstruct_array = array($soapstructstruct, $soapstructstruct, $soapstructstruct);
|
||||
$soapstructstruct_array_soapval = new SOAP_Value(
|
||||
'inputStructArray',
|
||||
'Array',
|
||||
array($soapstructstruct_soapval,
|
||||
$soapstructstruct_soapval,
|
||||
$soapstructstruct_soapval));
|
||||
|
||||
$soaparraystruct = new SOAPArrayStruct('arg', 34, 325.325,
|
||||
array('good', 'bad', 'ugly'));
|
||||
$soaparraystruct_soapval = $soaparraystruct->__to_soap();
|
||||
$soaparraystruct_array = array($soaparraystruct, $soaparraystruct, $soaparraystruct);
|
||||
$soaparraystruct_array_soapval = new SOAP_Value(
|
||||
'inputStructArray',
|
||||
'Array',
|
||||
array($soaparraystruct_soapval,
|
||||
$soaparraystruct_soapval,
|
||||
$soaparraystruct_soapval));
|
||||
|
||||
$simpletypes = array(
|
||||
'inputString'=>'arg',
|
||||
'inputInteger'=>34,
|
||||
'inputFloat'=>325.325
|
||||
);
|
||||
|
||||
$simpletypes_soapval = array();
|
||||
$simpletypes_soapval[] = new SOAP_Value('inputString', 'string', 'arg');
|
||||
$simpletypes_soapval[] = new SOAP_Value('inputInteger', 'int', 34);
|
||||
$simpletypes_soapval[] = new SOAP_Value('inputFloat', 'float', 325.325);
|
||||
|
||||
$base64 = 'TmVicmFza2E=';
|
||||
$base64_soapval = new SOAP_Value('inputBase64', 'base64Binary', $base64);
|
||||
|
||||
$hexBin = '736F61707834';
|
||||
$hexBin_soapval = new SOAP_Value('inputHexBinary', 'hexBinary', $hexBin);
|
||||
|
||||
$decimal = 12345.67890;
|
||||
$decimal_soapval =new SOAP_Value('inputDecimal', 'decimal', $decimal);
|
||||
|
||||
$dateTime = '2001-05-24T17:31:41Z';
|
||||
$dateTime_soapval = new SOAP_Value('inputDate', 'dateTime', $dateTime);
|
||||
|
||||
$boolean_true = true;
|
||||
$boolean_true_soapval = new SOAP_Value('inputBoolean', 'boolean', true);
|
||||
$boolean_false = false;
|
||||
$boolean_false_soapval = new SOAP_Value('inputBoolean', 'boolean', false);
|
||||
$boolean_one = 1;
|
||||
$boolean_one_soapval = new SOAP_Value('inputBoolean', 'boolean', 1);
|
||||
$boolean_zero = 0;
|
||||
$boolean_zero_soapval = new SOAP_Value('inputBoolean', 'boolean', 0);
|
||||
|
||||
// XXX I know this isn't quite right, need to deal with this better
|
||||
function &make_2d($x, $y)
|
||||
{
|
||||
$a = array();
|
||||
for ($_x = 0; $_x < $x; $_x++) {
|
||||
$a[$_x] = array();
|
||||
for ($_y = 0; $_y < $y; $_y++) {
|
||||
$a[$_x][$_y] = "x{$_x}y{$_y}";
|
||||
}
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
$multidimarray = make_2d(3, 3);
|
||||
$multidimarray_soapval = new SOAP_Value(
|
||||
'input2DStringArray',
|
||||
'Array',
|
||||
array(array(new SOAP_Value('item', 'string', 'row0col0'),
|
||||
new SOAP_Value('item', 'string', 'row0col1'),
|
||||
new SOAP_Value('item', 'string', 'row0col2')),
|
||||
array(new SOAP_Value('item', 'string', 'row1col0'),
|
||||
new SOAP_Value('item', 'string', 'row1col1'),
|
||||
new SOAP_Value('item', 'string', 'row1col2'))));
|
||||
$multidimarray_soapval->options['flatten'] = true;
|
||||
|
||||
// Round2GroupC values
|
||||
$_person = new Person(32, 12345, 'Shane', true);
|
||||
$person = $_person->__to_soap();
|
||||
$_employee = new Employee($_person, 12345, 1000000.00);
|
||||
$employee = $_employee->__to_soap();
|
||||
23
thirdparty/pear/SOAP/Interop/readme.txt
vendored
23
thirdparty/pear/SOAP/Interop/readme.txt
vendored
@@ -1,23 +0,0 @@
|
||||
Round 2 Interop Test files
|
||||
|
||||
Resources:
|
||||
http://www.whitemesa.com/interop.htm
|
||||
http://www.whitemesa.com/r3/interop3.html
|
||||
http://www.pocketsoap.com/registration/
|
||||
|
||||
Requires an SQL database, schema for MySQL is in interop_database.sql.
|
||||
|
||||
Run interop_client_run.php to store test results.
|
||||
View index.php to see test results.
|
||||
|
||||
To setup an interop server:
|
||||
|
||||
1. Copy config.php.dist to config.php.
|
||||
2. Web server must alias url /soap_interop/ to the pear/SOAP_Interop
|
||||
directory. The alias url can be set in config.php.
|
||||
3. index.php should be set for the default document.
|
||||
4. MySQL should be set up, with a database called interop, schema is in
|
||||
interop_database.sql. Database name, user, and password can be set in
|
||||
config.php.
|
||||
5. interop_client_run.php should not be left under the web root, it is
|
||||
available for manual testing.
|
||||
@@ -1,473 +0,0 @@
|
||||
<?php
|
||||
require_once 'DB.php'; // PEAR/DB
|
||||
require_once 'SOAP/Client.php';
|
||||
require_once 'config.php';
|
||||
|
||||
class clientInfo {
|
||||
var $name;
|
||||
var $version;
|
||||
var $resultsURL;
|
||||
|
||||
function clientInfo($ar=NULL) {
|
||||
if (is_array($ar)) {
|
||||
foreach ($ar as $k=>$v) {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class serverInfo {
|
||||
var $id;
|
||||
var $service_id;
|
||||
var $name;
|
||||
var $version;
|
||||
var $endpointURL;
|
||||
var $wsdlURL;
|
||||
|
||||
function serverInfo($ar=NULL) {
|
||||
if (is_array($ar)) {
|
||||
foreach ($ar as $k=>$v) {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Service {
|
||||
var $id;
|
||||
var $name;
|
||||
var $description;
|
||||
var $wsdlURL;
|
||||
var $websiteURL;
|
||||
|
||||
function Service($ar=NULL) {
|
||||
if (is_array($ar)) {
|
||||
foreach ($ar as $k=>$v) {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class subscriberInfo {
|
||||
var $notificationID;
|
||||
var $expires; /* dateTime */
|
||||
}
|
||||
|
||||
class ChangeItem {
|
||||
var $id;
|
||||
var $timestamp; /* dateTime */
|
||||
var $headline;
|
||||
var $notes;
|
||||
var $url;
|
||||
}
|
||||
|
||||
function getLocalInteropServer($testname,$id,$localBaseUrl='http://localhost/soap_interop/') {
|
||||
$localServer = array();
|
||||
$localServer['service_id']=$id;
|
||||
$localServer['name']='Local PEAR::SOAP';
|
||||
$localServer['version']=SOAP_LIBRARY_VERSION;
|
||||
switch ($testname) {
|
||||
case 'Round 2 Base':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round2Base.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/interop.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 2 Group B':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round2GroupB.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/interopB.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 2 Group C':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round2GroupC.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/echoheadersvc.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D EmptySA':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDEmptySA.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/emptysa.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D Compound 1':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDCompound1.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/compound1.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D Compound 2':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDCompound2.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/compound2.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D DocLit':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDDocLit.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/InteropTestDocLit.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D DocLitParams':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDDocLitParams.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/InteropTestDocLitParameters.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D Import 1':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDImport1.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/import1.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D Import 2':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDImport2.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/import2.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D Import 3':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDImport3.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/import3.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
case 'Round 3 Group D RpcEnc':
|
||||
$localServer['endpointURL']=$localBaseUrl.'server_Round3GroupDRpcEnc.php';
|
||||
$localServer['wsdlURL']=$localBaseUrl.'wsdl/InteropTestRpcEnc.wsdl.php';
|
||||
return new serverInfo($localServer);
|
||||
#case 'Round 3 Group E DocLit':
|
||||
#case 'Round 3 Group E RpcEnc':
|
||||
#case 'Round 3 Group F Extensibility':
|
||||
#case 'Round 3 Group F ExtensibilityRequired':
|
||||
#case 'Round 3 Group F Headers':
|
||||
#case 'Round 4 DIME/Doc Attachments':
|
||||
#case 'Round 4 DIME/RPC Attachments':
|
||||
#case 'Round 4 MIME/Doc Attachments':
|
||||
#case 'Round 4 SwA/RPC Attachments':
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
class SOAP_Interop_registrationAndNotificationService_ServicesPort extends SOAP_Client {
|
||||
function SOAP_Interop_registrationAndNotificationService_ServicesPort() {
|
||||
$this->SOAP_Client("http://soap.4s4c.com/registration/soap.asp", 0);
|
||||
$this->_auto_translation = true;
|
||||
}
|
||||
function &ServiceList() {
|
||||
return $this->call("ServiceList",
|
||||
$v = NULL,
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/services',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/services#ServiceList',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &Servers($serviceID) {
|
||||
return $this->call("Servers",
|
||||
$v = array("serviceID"=>$serviceID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/services',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/services#Servers',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &Clients($serviceID) {
|
||||
return $this->call("Clients",
|
||||
$v = array("serviceID"=>$serviceID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/services',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/services#Clients',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
}
|
||||
class SOAP_Interop_registrationAndNotificationService_ClientsPort extends SOAP_Client {
|
||||
function SOAP_Interop_registrationAndNotificationService_ClientsPort() {
|
||||
$this->SOAP_Client("http://soap.4s4c.com/registration/soap.asp", 0);
|
||||
$this->_auto_translation = true;
|
||||
}
|
||||
function &RegisterClient($serviceID, $clientInfo) {
|
||||
return $this->call("RegisterClient",
|
||||
$v = array("serviceID"=>$serviceID, "clientInfo"=>$clientInfo),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/clients',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/clients#RegisterClient',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &UpdateClient($clientID, $clientInfo) {
|
||||
return $this->call("UpdateClient",
|
||||
$v = array("clientID"=>$clientID, "clientInfo"=>$clientInfo),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/clients',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/clients#UpdateClient',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &RemoveClient($clientID) {
|
||||
return $this->call("RemoveClient",
|
||||
$v = array("clientID"=>$clientID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/clients',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/clients#RemoveClient',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
}
|
||||
class SOAP_Interop_registrationAndNotificationService_ServersPort extends SOAP_Client {
|
||||
function SOAP_Interop_registrationAndNotificationService_ServersPort() {
|
||||
$this->SOAP_Client("http://soap.4s4c.com/registration/soap.asp", 0);
|
||||
$this->_auto_translation = true;
|
||||
}
|
||||
function &RegisterServer($serviceID, $serverInfo) {
|
||||
return $this->call("RegisterServer",
|
||||
$v = array("serviceID"=>$serviceID, "serverInfo"=>$serverInfo),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/servers',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/servers#RegisterServer',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &UpdateServer($serverID, $serverInfo) {
|
||||
return $this->call("UpdateServer",
|
||||
$v = array("serverID"=>$serverID, "serverInfo"=>$serverInfo),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/servers',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/servers#UpdateServer',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &RemoveServer($serverID) {
|
||||
return $this->call("RemoveServer",
|
||||
$v = array("serverID"=>$serverID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/servers',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/servers#RemoveServer',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
}
|
||||
class SOAP_Interop_registrationAndNotificationService_SubscriberPort extends SOAP_Client {
|
||||
function SOAP_Interop_registrationAndNotificationService_SubscriberPort() {
|
||||
$this->SOAP_Client("http://soap.4s4c.com/registration/soap.asp", 0);
|
||||
$this->_auto_translation = true;
|
||||
}
|
||||
function &Subscribe($serviceID, $ServerChanges, $ClientChanges, $NotificationURL) {
|
||||
return $this->call("Subscribe",
|
||||
$v = array("serviceID"=>$serviceID, "ServerChanges"=>$ServerChanges, "ClientChanges"=>$ClientChanges, "NotificationURL"=>$NotificationURL),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/subscriber',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/subscriber#Subscribe',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &Renew($notificationID) {
|
||||
return $this->call("Renew",
|
||||
$v = array("notificationID"=>$notificationID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/subscriber',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/subscriber#Renew',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
function &Cancel($notificationID) {
|
||||
return $this->call("Cancel",
|
||||
$v = array("notificationID"=>$notificationID),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/subscriber',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/subscriber#Cancel',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
}
|
||||
class SOAP_Interop_registrationAndNotificationService_ChangeLogPort extends SOAP_Client {
|
||||
function SOAP_Interop_registrationAndNotificationService_ChangeLogPort() {
|
||||
$this->SOAP_Client("http://soap.4s4c.com/registration/soap.asp", 0);
|
||||
$this->_auto_translation = true;
|
||||
}
|
||||
function &RecentChanges($MaxEntries) {
|
||||
return $this->call("RecentChanges",
|
||||
$v = array("MaxEntries"=>$MaxEntries),
|
||||
array('namespace'=>'http://soap.pocketsoap.com/registration/changeLog',
|
||||
'soapaction'=>'http://soap.pocketsoap.com/registration/changeLog#RecentChanges',
|
||||
'style'=>'rpc',
|
||||
'use'=>'encoded'));
|
||||
}
|
||||
}
|
||||
|
||||
class SOAP_Interop_registrationDB {
|
||||
var $DSN;
|
||||
var $dbc = NULL;
|
||||
|
||||
var $client; // soap_client
|
||||
var $services;
|
||||
var $currentServiceId;
|
||||
var $servers;
|
||||
var $clients;
|
||||
|
||||
function SOAP_Interop_registrationDB()
|
||||
{
|
||||
global $interopConfig;
|
||||
$this->DSN = $interopConfig['DSN'];
|
||||
$this->client =& new SOAP_Interop_registrationAndNotificationService_ServicesPort();
|
||||
$this->connectDB();
|
||||
$this->getServiceList();
|
||||
}
|
||||
|
||||
function connectDB()
|
||||
{
|
||||
if (!$this->dbc)
|
||||
$this->dbc =& DB::connect($this->DSN, true);
|
||||
if (PEAR::isError($this->dbc)) {
|
||||
echo $this->dbc->getMessage();
|
||||
$this->dbc = NULL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function updateDB()
|
||||
{
|
||||
$this->updateServiceDb();
|
||||
$this->updateServerDb();
|
||||
$this->updateClientsDb();
|
||||
}
|
||||
|
||||
function &retreiveServiceList()
|
||||
{
|
||||
if (!$this->services) {
|
||||
$this->services =& $this->client->ServiceList();
|
||||
}
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
function &retreiveServerList($serviceID)
|
||||
{
|
||||
if (!$this->servers || $this->currentServiceId != $serviceID) {
|
||||
$this->currentServiceId = $serviceID;
|
||||
$this->servers =& $this->client->Servers($serviceID);
|
||||
}
|
||||
return $this->servers;
|
||||
}
|
||||
|
||||
function &retreiveClientList($serviceID)
|
||||
{
|
||||
if (!$this->clients || $this->currentServiceId != $serviceID) {
|
||||
$this->currentServiceId = $serviceID;
|
||||
$this->clients =& $this->client->Clients($serviceID);
|
||||
}
|
||||
return $this->clients;
|
||||
}
|
||||
|
||||
function updateServiceDb()
|
||||
{
|
||||
if (!$this->connectDB()) return false;
|
||||
$this->retreiveServiceList();
|
||||
echo "Updating Services\n";
|
||||
foreach ($this->services as $service) {
|
||||
$res = $this->dbc->getRow("select id from services where id='{$service->id}'");
|
||||
if ($res && !PEAR::isError($res)) {
|
||||
$res = $this->dbc->query("update services set name='{$service->name}',".
|
||||
"description='{$service->description}',wsdlURL='{$service->wsdlURL}',".
|
||||
"websiteURL='{$service->websiteURL}' where id='{$service->id}'");
|
||||
} else {
|
||||
$res = $this->dbc->query("insert into services (id,name,description,wsdlURL,websiteURL) ".
|
||||
"values('{$service->id}','{$service->name}','{$service->description}','{$service->wsdlURL}','{$service->websiteURL}')");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _updateOrAddServer($id, $server) {
|
||||
$res = $this->dbc->getRow("select * from serverinfo where service_id='$id' and name='{$server->name}'");
|
||||
if ($res && !PEAR::isError($res)) {
|
||||
$res = $this->dbc->query("update serverinfo set ".
|
||||
"version='{$server->version}', ".
|
||||
"endpointURL='{$server->endpointURL}', ".
|
||||
"wsdlURL='{$server->wsdlURL}' where id={$res->id}");
|
||||
} else {
|
||||
$res = $this->dbc->query("insert into serverinfo (service_id,name,version,endpointURL,wsdlURL) ".
|
||||
"values('$id','{$server->name}','{$server->version}','{$server->endpointURL}','{$server->wsdlURL}')");
|
||||
}
|
||||
if (PEAR::isError($res)) {
|
||||
echo $res->toString() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function updateServerDb()
|
||||
{
|
||||
global $INTEROP_LOCAL_SERVER;
|
||||
if (!$this->connectDB()) return false;
|
||||
$this->retreiveServiceList();
|
||||
$c = count($this->services);
|
||||
for ($i=0;$i<$c;$i++) {
|
||||
$this->retreiveServerList($this->services[$i]->id);
|
||||
echo "Updating Servers for {$this->services[$i]->name}\n";
|
||||
if (!$this->servers) continue;
|
||||
foreach ($this->servers as $server) {
|
||||
$this->_updateOrAddServer($this->services[$i]->id, $server);
|
||||
}
|
||||
// add the local server now
|
||||
if ($INTEROP_LOCAL_SERVER) {
|
||||
$server = getLocalInteropServer($this->services[$i]->name, $this->services[$i]->id);
|
||||
if ($server) {
|
||||
$this->_updateOrAddServer($this->services[$i]->id, $server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateClientsDb()
|
||||
{
|
||||
if (!$this->connectDB()) return false;
|
||||
$this->retreiveServiceList();
|
||||
foreach ($this->services as $service) {
|
||||
$this->retreiveClientList($service->id);
|
||||
echo "Updating Clients for {$service->name}\n";
|
||||
if (!$this->clients) continue;
|
||||
foreach ($this->clients as $client) {
|
||||
$res = $this->dbc->getRow("select id from clientinfo where id='{$service->id}' and name='{$client->name}'");
|
||||
if ($res && !PEAR::isError($res)) {
|
||||
$res = $this->dbc->query("update clientinfo set ".
|
||||
"version='{$client->version}', ".
|
||||
"resultsURL='{$client->resultsURL}' where ".
|
||||
"id='{$service->id}',name='{$client->name}'");
|
||||
} else {
|
||||
$res = $this->dbc->query("insert into clientinfo (id,name,version,resultsURL) ".
|
||||
"values('{$service->id}','{$client->name}','{$client->version}','{$client->resultsURL}')");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function &getServiceList($forcefetch=FALSE)
|
||||
{
|
||||
if (!$forcefetch && !$this->services) {
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_OBJECT,'Service');
|
||||
$this->services = $this->dbc->getAll('select * from services',NULL, DB_FETCHMODE_OBJECT );
|
||||
}
|
||||
if ($forcefetch || !$this->services) {
|
||||
$this->updateServiceDb();
|
||||
}
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
function &getServerList($serviceID,$forcefetch=FALSE)
|
||||
{
|
||||
if (!$forcefetch && (!$this->servers || $this->currentServiceId != $serviceID)) {
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_OBJECT,'serverInfo');
|
||||
$this->servers = $this->dbc->getAll("select * from serverinfo where service_id = '$serviceID'",NULL, DB_FETCHMODE_OBJECT );
|
||||
}
|
||||
if ($forcefetch || !$this->servers) {
|
||||
$this->updateServerDb();
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_OBJECT,'serverInfo');
|
||||
$this->servers = $this->dbc->getAll("select * from serverinfo where service_id = '$serviceID'",NULL, DB_FETCHMODE_OBJECT );
|
||||
if (!$this->servers) {
|
||||
die("Error retrieving server list!\n");
|
||||
}
|
||||
}
|
||||
return $this->servers;
|
||||
}
|
||||
|
||||
function &getClientList($serviceID,$forcefetch=FALSE)
|
||||
{
|
||||
if (!$forcefetch && (!$this->clients || $this->currentServiceId != $serviceID)) {
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_OBJECT,'clientInfo');
|
||||
$this->clients = $this->dbc->getAll("select * from clientinfo where id = '$serviceID'",NULL, DB_FETCHMODE_OBJECT );
|
||||
}
|
||||
if ($forcefetch || !$this->clients) {
|
||||
$this->updateClientDb();
|
||||
$this->dbc->setFetchMode(DB_FETCHMODE_OBJECT,'clientInfo');
|
||||
$this->clients = $this->dbc->getAll("select * from clientinfo where id = '$serviceID'",NULL, DB_FETCHMODE_OBJECT );
|
||||
if (!$this->clients) {
|
||||
die("Error retrieving client list!\n");
|
||||
}
|
||||
}
|
||||
return $this->clients;
|
||||
}
|
||||
|
||||
function &findService($serviceName)
|
||||
{
|
||||
$this->getServiceList();
|
||||
$c = count($this->services);
|
||||
for ($i=0 ; $i<$c; $i++) {
|
||||
if (strcmp($serviceName, $this->services[$i]->name)==0) return $this->services[$i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#$reg =& new SOAP_Interop_registrationAndNotificationDB();
|
||||
#$reg->updateDB();
|
||||
//print_r($l);
|
||||
?>
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
|
||||
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: server_Round2Base.php,v 1.5 2003/08/05 16:56:43 arnaud Exp $
|
||||
//
|
||||
require_once 'SOAP/Server.php';
|
||||
require_once 'interop_Round2Base.php';
|
||||
|
||||
$base =& new SOAP_Interop_Base();
|
||||
$server =& new SOAP_Server;
|
||||
$server->_auto_translation = true;
|
||||
|
||||
$server->addObjectMap($base,'http://soapinterop.org/');
|
||||
$server->service(isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:NULL);
|
||||
|
||||
$test = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:ns4="http://soapinterop.org/"
|
||||
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<SOAP-ENV:Body>
|
||||
|
||||
<ns4:echoStruct>
|
||||
<inputStruct>
|
||||
<varString xsi:type="xsd:string">arg</varString>
|
||||
<varInt xsi:type="xsd:int">34</varInt>
|
||||
<varFloat xsi:type="xsd:float">325.325</varFloat></inputStruct></ns4:echoStruct>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>';
|
||||
#$server->service($test,'',TRUE);
|
||||
|
||||
?>
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
|
||||
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: server_Round2GroupB.php,v 1.5 2003/08/05 16:56:43 arnaud Exp $
|
||||
//
|
||||
require_once 'SOAP/Server.php';
|
||||
require_once 'interop_Round2GroupB.php';
|
||||
|
||||
$groupb =& new SOAP_Interop_GroupB();
|
||||
$server =& new SOAP_Server;
|
||||
$server->_auto_translation = true;
|
||||
|
||||
$server->addObjectMap($groupb,'http://soapinterop.org/');
|
||||
$server->service(isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:NULL);
|
||||
|
||||
$test = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:ns4="http://soapinterop.org/"
|
||||
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<SOAP-ENV:Body>
|
||||
|
||||
<ns4:echoNestedStruct>
|
||||
<inputStruct>
|
||||
<varString xsi:type="xsd:string">arg</varString>
|
||||
<varInt xsi:type="xsd:int">34</varInt>
|
||||
<varFloat xsi:type="xsd:float">325.325</varFloat>
|
||||
<varStruct>
|
||||
<varString xsi:type="xsd:string">arg</varString>
|
||||
<varInt xsi:type="xsd:int">34</varInt>
|
||||
<varFloat xsi:type="xsd:float">325.325</varFloat></varStruct></inputStruct></ns4:echoNestedStruct>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>';
|
||||
#$server->service($test,'',TRUE);
|
||||
|
||||
?>
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: server_Round2GroupC.php,v 1.5 2003/08/05 16:56:43 arnaud Exp $
|
||||
//
|
||||
require_once 'SOAP/Server.php';
|
||||
require_once 'interop_Round2Base.php';
|
||||
require_once 'interop_Round2GroupC.php';
|
||||
|
||||
$groupc_headers =& new SOAP_Interop_GroupC_Headers();
|
||||
$base =& new SOAP_Interop_Base();
|
||||
$server =& new SOAP_Server;
|
||||
$server->_auto_translation = true;
|
||||
|
||||
$server->addObjectMap($groupc_headers,'http://soapinterop.org/echoheader/');
|
||||
$server->addObjectMap($base,'http://soapinterop.org/');
|
||||
$server->service(isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:NULL);
|
||||
?>
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: server_Round3GroupD.php,v 1.4 2005/04/01 16:18:00 chagenbu Exp $
|
||||
//
|
||||
require_once 'SOAP/Server.php';
|
||||
require_once 'interop_Round3GroupD.php';
|
||||
|
||||
// http://www.whitemesa.com/r3/interop3.html
|
||||
// http://www.whitemesa.com/r3/plan.html
|
||||
|
||||
$groupd = new SOAP_Interop_GroupD();
|
||||
$server = new SOAP_Server;
|
||||
$server->_auto_translation = true;
|
||||
|
||||
$server->addObjectMap($groupd, 'http://soapinterop/');
|
||||
$server->addObjectMap($groupd, 'http://soapinterop.org/xsd');
|
||||
|
||||
$server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : NULL);
|
||||
|
||||
$test = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:ns4="http://soapinterop.org/xsd"
|
||||
>
|
||||
<SOAP-ENV:Body>
|
||||
|
||||
<ns4:x_Document>Test Document Here</ns4:x_Document>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>';
|
||||
#$server->service($test,'',TRUE);
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: server_Round3GroupDCompound1.php,v 1.5 2007/01/22 14:53:22 yunosh Exp $
|
||||
//
|
||||
require_once 'SOAP/Server.php';
|
||||
require_once 'params_classes.php';
|
||||
|
||||
// http://www.whitemesa.com/r3/interop3.html
|
||||
// http://www.whitemesa.com/r3/plan.html
|
||||
|
||||
class SOAP_Interop_GroupDCompound1 {
|
||||
|
||||
function echoPerson($person)
|
||||
{
|
||||
return $person->__to_soap('result_Person');
|
||||
}
|
||||
|
||||
function echoDocument($document)
|
||||
{
|
||||
$ns = '{http://soapinterop.org/xsd}';
|
||||
return new SOAP_Value($ns . 'result_Document', $ns . 'x_Document', $document);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// http://www.whitemesa.com/r3/interop3.html
|
||||
// http://www.whitemesa.com/r3/plan.html
|
||||
|
||||
$options = array('use' => 'literal', 'style' => 'document');
|
||||
$groupd = new SOAP_Interop_GroupDCompound1();
|
||||
$server = new SOAP_Server($options);
|
||||
$server->_auto_translation = true;
|
||||
|
||||
$server->addObjectMap($groupd, 'http://soapinterop/');
|
||||
$server->addObjectMap($groupd, 'http://soapinterop.org/xsd');
|
||||
|
||||
$server->bind('http://localhost/soap_interop/wsdl/compound1.wsdl.php');
|
||||
if (isset($_SERVER['SERVER_NAME'])) {
|
||||
$server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : null);
|
||||
} else {
|
||||
// allows command line testing of specific request
|
||||
$test = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:ns4="http://soapinterop.org/xsd"
|
||||
>
|
||||
<SOAP-ENV:Body>
|
||||
|
||||
<ns4:x_Document>Test Document Here</ns4:x_Document>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>';
|
||||
$server->service($test, '', true);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user