* @author Vincent Blavet <vincent@phpconcept.net>
* @copyright 1997-2008 The Authors
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Tar.php 287963 2009-09-02 08:18:55Z mrook $
+ * @version CVS: $Id: Tar.php 295988 2010-03-09 08:39:37Z mrook $
* @link http://pear.php.net/package/Archive_Tar
*/
* Creates a (compressed) Tar archive
*
* @author Vincent Blavet <vincent@phpconcept.net>
-* @version $Revision: 287963 $
+* @version $Revision: 295988 $
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package Archive_Tar
*/
*/
var $_temp_tarname='';
+ /**
+ * @var string regular expression for ignoring files or directories
+ */
+ var $_ignore_regexp='';
+
// {{{ constructor
/**
* Archive_Tar Class constructor. This flavour of the constructor only
}
// }}}
+ // {{{ setIgnoreRegexp()
+ /**
+ * This method sets the regular expression for ignoring files and directories
+ * at import, for example:
+ * $arch->setIgnoreRegexp("#CVS|\.svn#");
+ * @param string $regexp regular expression defining which files or directories to ignore
+ * @access public
+ */
+ function setIgnoreRegexp($regexp)
+ {
+ $this->_ignore_regexp = $regexp;
+ }
+ // }}}
+
+ // {{{ setIgnoreList()
+ /**
+ * This method sets the regular expression for ignoring all files and directories
+ * matching the filenames in the array list at import, for example:
+ * $arch->setIgnoreList(array('CVS', '.svn', 'bin/tool'));
+ * @param array $list a list of file or directory names to ignore
+ * @access public
+ */
+ function setIgnoreList($list)
+ {
+ $regexp = str_replace(array('#', '.', '^', '$'), array('\#', '\.', '\^', '\$'), $list);
+ $regexp = '#/'.join('$|/', $list).'#';
+ $this->setIgnoreRegexp($regexp);
+ }
+ // }}}
+
// {{{ _error()
function _error($p_message)
{
for ($i=0; $i<$p_len; $i++)
$this->_readBlock();
} else if ($this->_compress_type == 'none')
- @fseek($this->_file, ftell($this->_file)+($p_len*512));
+ @fseek($this->_file, $p_len*512, SEEK_CUR);
else
$this->_error('Unknown or missing compression type ('
.$this->_compress_type.')');
if ($v_filename == '')
continue;
+ // ----- ignore files and directories matching the ignore regular expression
+ if ($this->_ignore_regexp && preg_match($this->_ignore_regexp, '/'.$v_filename)) {
+ $this->_warning("File '$v_filename' ignored");
+ continue;
+ }
+
if (!file_exists($v_filename)) {
$this->_warning("File '$v_filename' does not exist");
continue;
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 289651 $
+ * @version Release: @package_version@ File: $Revision: 289651 $
* @link http://pear.php.net/package/Auth
*/
class Auth {
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 289651 $
+ * @version Release: @package_version@ File: $Revision: 289651 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id: Container.php 237449 2007-06-12 03:11:27Z aashley $
+ * @version CVS: $Id: Container.php 294935 2010-02-12 00:05:45Z clockwerx $
* @link http://pear.php.net/package/Auth
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 294935 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @since File available since Release 1.4.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 256753 $
+ * @version Release: @package_version@ File: $Revision: 256753 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container_DB extends Auth_Container
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 256753 $
+ * @version Release: @package_version@ File: $Revision: 256753 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container_File extends Auth_Container
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.4.0
*/
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container_LDAP extends Auth_Container
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 256753 $
+ * @version Release: @package_version@ File: $Revision: 256753 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.3
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 256753 $
+ * @version Release: @package_version@ File: $Revision: 256753 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 289653 $
+ * @version Release: @package_version@ File: $Revision: 289653 $
* @since File available since Release 1.5.0
*/
* @author Adam Harvey <aharvey@php.net>
* @copyright 2001-2007 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 289652 $
+ * @version Release: @package_version@ File: $Revision: 289652 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id: SAP.php 289654 2009-10-15 04:52:48Z aashley $
+ * @version CVS: $Id: SAP.php 302205 2010-08-14 14:08:08Z clockwerx $
* @link http://pear.php.net/package/Auth
* @since File available since Release 1.4.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 289654 $
+ * @version Release: @package_version@ File: $Revision: 302205 $
* @since Class available since Release 1.4.0
*/
class Auth_Container_SAP extends Auth_Container {
}
$err = explode("n", $sap_error);
foreach ($err AS $line) {
- $item = split(':', $line);
+ $item = explode(':', $line);
$error[strtolower(trim($item[0]))] = trim($item[1]);
}
$error['all'] = $sap_error;
* @package Auth
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.3
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 238999 $
+ * @version Release: @package_version@ File: $Revision: 238999 $
* @since Class available since Release 1.4.0
*/
class Auth_Container_SOAP5 extends Auth_Container
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.2.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version Release: 1.6.2 File: $Revision: 237449 $
+ * @version Release: @package_version@ File: $Revision: 237449 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
// | Author: Richard Heyes <richard@php.net> |
// +-----------------------------------------------------------------------+
//
-// $Id: DigestMD5.php 286826 2009-08-05 06:25:54Z cweiske $
+// $Id: DigestMD5.php 294702 2010-02-07 16:03:55Z cweiske $
/**
* Implmentation of DIGEST-MD5 SASL mechanism
*/
function _getCnonce()
{
- if (file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) {
+ if (@file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) {
return base64_encode(fread($fd, 32));
- } elseif (file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) {
+ } elseif (@file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) {
return base64_encode(fread($fd, 32));
} else {
<?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 $
-//
+/**
+ * Iterate.php
+ *
+ * PHP version 4
+ *
+ * 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.
+ *
+ * @category Benchmarking
+ * @package Benchmark
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @version CVS: $Id: Iterate.php 268884 2008-11-12 20:57:49Z clockwerx $
+ * @link http://pear.php.net/package/Benchmark
+ */
require_once 'Benchmark/Timer.php';
* ?>
* </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
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @link http://pear.php.net/package/Benchmark
*/
-class Benchmark_Iterate extends Benchmark_Timer {
+class Benchmark_Iterate extends Benchmark_Timer
+{
+
/**
* Benchmarks a function or method.
*
* @access public
+ * @return void
*/
- function run() {
+ 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];
+ $function_name = explode('::', $function_name);
+ $objectmethod = $function_name[1];
}
if (strstr($function_name, '->')) {
- $function_name = explode('->', $function_name);
- $objectname = $function_name[0];
+ list($objectname, $objectmethod) = explode('->', $function_name);
$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);
+ call_user_func_array(array($object, $objectmethod), $arguments);
$this->setMarker('end_' . $i);
}
* $result['mean' ] = mean execution time
* $result['iterations'] = number of iterations
*
+ * @param bool $simple_output Show just the total
+ *
* @return array
* @access public
*/
- function get($simple_output = false) {
+ 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);
+ $time = $this->timeElapsed('start_'.$i, 'end_'.$i);
if (extension_loaded('bcmath')) {
$total = bcadd($total, $time, 6);
<?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 $
-//
+/**
+ * Benchmark
+ *
+ * PHP version 4
+ *
+ * 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.
+ *
+ * @category Benchmarking
+ * @package Benchmark
+ * @author Matthias Englert <Matthias.Englert@gmx.de>
+ * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @version CVS: $Id: Profiler.php 268884 2008-11-12 20:57:49Z clockwerx $
+ * @link http://pear.php.net/package/Benchmark
+ */
require_once 'PEAR.php';
* <?php
* require_once 'Benchmark/Profiler.php';
*
- * $profiler = new Benchmark_Profiler(TRUE);
+ * $profiler = new Benchmark_Profiler(true);
*
* function myFunction() {
* global $profiler;
* ?>
* </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
+ * @author Matthias Englert <Matthias.Englert@gmx.de>
+ * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @link http://pear.php.net/package/Benchmark
* @since 1.2.0
*/
-class Benchmark_Profiler extends PEAR {
+class Benchmark_Profiler extends PEAR
+{
+
/**
* Contains the total ex. time of each section
*
* @var boolean
* @access private
*/
- var $_auto = FALSE;
+ var $_auto = false;
/**
* Max marker name length for non-html output
/**
* Constructor, starts profiling recording
*
+ * @param bool $auto Automatically start benchmarking
+ *
* @access public
*/
- function Benchmark_Profiler($auto = FALSE) {
+ function Benchmark_Profiler($auto = false)
+ {
$this->_auto = $auto;
if ($this->_auto) {
* Close method, stop profiling recording and display output.
*
* @access public
+ * @return void
*/
- function close() {
+ function close()
+ {
if (isset($this->_auto) && $this->_auto) {
$this->stop();
$this->display();
/**
* Returns profiling informations for a given section.
*
- * @param string $section
+ * @param string $section Section to retrieve
+ *
* @return array
* @access public
*/
- function getSectionInformations($section = 'Global') {
+ function getSectionInformations($section = 'Global')
+ {
if (isset($this->_sections[$section])) {
$calls = array();
$informations = array();
- $informations['time'] = $this->_sections[$section];
if (isset($this->_sections['Global'])) {
- $informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', '');
+ $value = $this->_sections[$section] / $this->_sections['Global'];
+ $value = $value * 100;
+
+ $informations['percentage'] = number_format($value, 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];
- }
+ $informations['time'] = $this->_sections[$section];
+ $informations['calls'] = $calls;
+ $informations['num_calls'] = $this->_numberOfCalls[$section];
+ $informations['callers'] = $callers;
+
+ $value = $this->_sections[$section];
+
+ if (isset($this->_subSectionsTime[$section])) {
+ $value -= $this->_subSectionsTime[$section];
+ }
+
+ $informations['netto_time'] = $value;
return $informations;
} else {
- $this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING);
+ $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
+ * @return array
*/
- function getAllSectionsInformations() {
+ function getAllSectionsInformations()
+ {
$informations = array();
- foreach($this->_sections as $section => $time) {
+ foreach ($this->_sections as $section => $time) {
$informations[$section] = $this->getSectionInformations($section);
}
/**
* Returns formatted profiling information.
*
- * @param string output format (auto, plain or html), default auto
+ * @param string $format output format (auto, plain or html), default auto
+ *
* @see display()
* @access private
+ * @return string
*/
- function _getOutput($format) {
+ 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)
- {
+ foreach ($names as $name) {
if ($maxLength < strlen($name)) {
$maxLength = strlen($name);
}
$format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
} else {
global $HTTP_SERVER_VARS;
- $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
+ $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
+
+ $format = $use_html ? 'html' : 'plain';
}
}
if ($format == 'html') {
- $out = '<table style="border: 1px solid #000000; ">'."\n";
+ $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>'.
+ '<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);
+ $dashes = str_pad("\n", ($this->_maxStringLength + 75), '-',
+ STR_PAD_LEFT);
+
+ $out = $dashes;
$out .= str_pad('Section', $this->_maxStringLength + 10);
$out .= str_pad("Total Ex Time", 22);
$out .= str_pad("Netto Ex Time", 22);
$out .= $dashes;
}
- foreach($informations as $name => $values) {
+ foreach ($informations as $name => $values) {
$percentage = $values['percentage'];
- $calls_str = "";
+ $calls_str = "";
- foreach($values['calls'] as $key => $val) {
+ foreach ($values['calls'] as $key => $val) {
if ($calls_str) {
$calls_str .= ", ";
}
$callers_str = "";
- foreach($values['callers'] as $key => $val) {
+ foreach ($values['callers'] as $key => $val) {
if ($callers_str) {
$callers_str .= ", ";
- }
+ }
$callers_str .= "$key ($val)";
}
+ $percentage = $values['percentage'];
+ if (is_numeric($values['percentage'])) {
+ $percentage .= '%';
+ }
+
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 .= "<tr>";
+ $out .= "<td><b>$name</b></td>";
+ $out .= "<td>{$values['time']}</td>";
+ $out .= "<td>{$values['netto_time']}</td>";
+ $out .= "<td>{$values['num_calls']}</td>";
+ $out .= "<td>{$percentage}</td>";
+
+
$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);
- }
+ $out .= str_pad($values['num_calls'], 10);
+ $out .= str_pad($percentage . "\n", 8, ' ', STR_PAD_LEFT);
}
}
/**
* Returns formatted profiling information.
*
- * @param string output format (auto, plain or html), default auto
+ * @param string $format output format (auto, plain or html), default auto
+ *
* @access public
+ * @return void
*/
- function display($format = 'auto') {
+ function display($format = 'auto')
+ {
echo $this->_getOutput($format);
}
*
* @see enterSection(), stop()
* @access public
+ * @return void
*/
- function start() {
+ function start()
+ {
$this->enterSection('Global');
}
*
* @see leaveSection(), start()
* @access public
+ * @return void
*/
- function stop() {
+ function stop()
+ {
$this->leaveSection('Global');
}
/**
* Enters code section.
*
- * @param string name of the code section
+ * @param string $name The code section
+ *
* @see start(), leaveSection()
* @access public
+ * @return void
*/
- function enterSection($name) {
+ 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"]]++;
+ $item = end($this->_stack);
+
+ if (isset($this->_callers[$name][$item["name"]])) {
+ $this->_callers[$name][$item]++;
} else {
- $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1;
+ $this->_callers[$name][$item] = 1;
}
- if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) {
- $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++;
+ if (isset($this->_calls[$item][$name])) {
+ $this->_calls[$item["name"]][$name]++;
} else {
- $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1;
+ $this->_calls[$item["name"]][$name] = 1;
}
} else {
if ($name != 'Global') {
- $this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
+ $msg = "tried to enter section " . $name
+ . " but profiling was not started\n";
+
+ $this->raiseError($msg, null, PEAR_ERROR_DIE);
}
}
$this->_numberOfCalls[$name] = 1;
}
- array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime()));
+ $data = array("name" => $name, "time" => $this->_getMicrotime());
+ array_push($this->_stack, $data);
}
/**
* Leaves code section.
*
- * @param string name of the marker to be set
- * @see stop(), enterSection()
+ * @param string $name The marker to be set
+ *
+ * @see stop(), enterSection()
* @access public
+ * @return void
*/
- function leaveSection($name) {
+ 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);
+ $msg = "tried to leave section " . $name
+ . " but profiling was not started\n";
+
+ $this->raiseError($msg, 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);
+ $msg = "reached end of section " . $name
+ . " but expecting end of " . $x["name"] . "\n";
+
+ $this->raiseError($msg, null, PEAR_ERROR_DIE);
}
if (isset($this->_sections[$name])) {
$parent = array_pop($this->_stack);
- if (isset($parent)) {
+ if (isset($parent)) {
if (isset($this->_subSectionsTime[$parent['name']])) {
$this->_subSectionsTime[$parent['name']] += $microtime - $x['time'];
} else {
* @access private
* @since 1.3.0
*/
- function _getMicrotime() {
+ function _getMicrotime()
+ {
$microtime = explode(' ', microtime());
return $microtime[1] . substr($microtime[0], 1);
}
<?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 $
-//
-
+/**
+ * Timer.php
+ *
+ * PHP version 4
+ *
+ * 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.
+ *
+ * @category Benchmarking
+ * @package Benchmark
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @version CVS: $Id: Timer.php 268884 2008-11-12 20:57:49Z clockwerx $
+ * @link http://pear.php.net/package/Benchmark
+ */
require_once 'PEAR.php';
/**
*
* $timer->display(); // to output html formated
* // AND/OR :
- * $profiling = $timer->getProfiling(); // get the profiler info as an associative array
+ * $profiling = $timer->getProfiling(); // get profiler info as associative array
* ?>
* </code>
*
+ * @category Benchmarking
+ * @package Benchmark
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @author Ludovico Magnocavallo <ludo@sumatrasolutions.com>
- * @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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
+ * @link http://pear.php.net/package/Benchmark
*/
-class Benchmark_Timer extends PEAR {
+class Benchmark_Timer extends PEAR
+{
/**
* Contains the markers.
*
* @var boolean
* @access private
*/
- var $auto = FALSE;
+ var $auto = false;
/**
* Max marker name length for non-html output.
/**
* Constructor.
*
- * @param boolean $auto
+ * @param boolean $auto Automatically start timer
+ *
* @access public
*/
- function Benchmark_Timer($auto = FALSE) {
+ function Benchmark_Timer($auto = false)
+ {
$this->auto = $auto;
if ($this->auto) {
* Close method. Stop timer and display output.
*
* @access public
+ * @return void
*/
- function close() {
+ function close()
+ {
if ($this->auto) {
$this->stop();
$this->display();
*
* @see setMarker(), stop()
* @access public
+ * @return void
*/
- function start() {
+ function start()
+ {
$this->setMarker('Start');
}
*
* @see setMarker(), start()
* @access public
+ * @return void
*/
- function stop() {
+ function stop()
+ {
$this->setMarker('Stop');
}
/**
* Set marker.
*
- * @param string $name Name of the marker to be set.
+ * @param string $name Name of the marker to be set.
+ *
* @see start(), stop()
* @access public
+ * @return void
*/
- function setMarker($name) {
+ 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"
+ * @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') {
+ 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;
+ $end = isset($this->markers[$end]) ? $this->markers[$end] : 0;
$start = isset($this->markers[$start]) ? $this->markers[$start] : 0;
if (extension_loaded('bcmath')) {
* @return array
* @access public
*/
- function getProfiling() {
+ function getProfiling()
+ {
$i = $total = 0;
+
$result = array();
- $temp = reset($this->markers);
+ $temp = reset($this->markers);
+
$this->maxStringLength = 0;
foreach ($this->markers as $marker => $time) {
$result[$i]['diff'] = $diff;
$result[$i]['total'] = $total;
- $this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength);
+ $longer = strlen($marker) > $this->maxStringLength;
+
+ if ($longer) {
+ $this->maxStringLength = strlen($marker) + 1;
+ }
$temp = $time;
$i++;
}
- $result[0]['diff'] = '-';
+ $result[0]['diff'] = '-';
$result[0]['total'] = '-';
- $this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength);
+
+ $longer = strlen('total') > $this->maxStringLength;
+
+ if ($longer) {
+ $this->maxStringLength = strlen('total');
+ }
+
$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
+ * @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') {
+ function getOutput($showTotal = false, $format = 'auto')
+ {
if ($format == 'auto') {
if (function_exists('version_compare') &&
- version_compare(phpversion(), '4.1', 'ge'))
- {
+ 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';
- }
+ $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
+
+ $format = $use_html ? 'html' : 'plain';
+ }
}
$total = $this->TimeElapsed();
$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";
+ $out = '<table border="1">'."\n";
+ $out .= '<tr>';
+ $out .= '<td> </td>';
+ $out .= '<td align="center"><b>time index</b></td>';
+ $out .= '<td align="center"><b>ex time</b></td>';
+ $out .= '<td align="center"><b>%</b></td>';
+
+ if ($showTotal) {
+ $out .= '<td align="center"><b>elapsed</b></td>';
+ $out .= '<td align="center"><b>%</b></td>';
+ }
+
+ $out .= "</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) .
}
foreach ($result as $k => $v) {
- $perc = (($v['diff'] * 100) / $total);
+ $perc = (($v['diff'] * 100) / $total);
$tperc = (($v['total'] * 100) / $total);
+ $percentage = number_format($perc, 2, '.', '')."%";
+
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>".
+ "</td><td align=\"right\">" . $percentage .
+ "</td>".
($showTotal ?
"<td>" . $v['total'] .
"</td><td align=\"right\">" .
"%</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) .
+ str_pad($percentage, 8, ' ', STR_PAD_LEFT) .
($showTotal ? ' '.
str_pad($v['total'], 14) .
str_pad(number_format($tperc, 2, '.', '')."%",
}
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 .= "<tr style='background: silver;'>";
+ $out .= "<td><b>total</b></td>";
+ $out .= "<td>-</td>";
+ $out .= "<td>${total}</td>";
+ $out .= "<td>100.00%</td>";
+ $out .= ($showTotal ? "<td>-</td><td>-</td>" : "");
+ $out .= "</tr>\n";
$out .= "</table>\n";
} else {
$out .= str_pad('total', $this->maxStringLength);
/**
* 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
+ * @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
+ * @return void
*/
- function display($showTotal = FALSE, $format = 'auto') {
+ function display($showTotal = false, $format = 'auto')
+ {
print $this->getOutput($showTotal, $format);
}
* @access private
* @since 1.3.0
*/
- function _getMicrotime() {
+ function _getMicrotime()
+ {
$microtime = explode(' ', microtime());
return $microtime[1] . substr($microtime[0], 1);
}
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Cache.php,v 1.9 2008/10/07 08:58:46 dufuz Exp $
+// $Id: Cache.php 267047 2008-10-07 08:58:46Z dufuz $
require_once 'PEAR.php';
require_once 'Cache/Error.php';
* bad circumstances (especially with the file container)
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: Cache.php,v 1.9 2008/10/07 08:58:46 dufuz Exp $
+* @version $Id: Cache.php 267047 2008-10-07 08:58:46Z dufuz $
* @package Cache
* @access public
*/
// | Authors: Richard Heyes <richard@phpguru.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Application.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
+// $Id: Application.php 178289 2005-01-26 09:47:28Z dufuz $
require_once 'Cache.php';
// | Christian Stocker <chregu@phant.ch> |
// +----------------------------------------------------------------------+
//
-// $Id: Container.php,v 1.9 2008/10/07 09:04:49 dufuz Exp $
+// $Id: Container.php 293863 2010-01-23 03:46:52Z clockwerx $
require_once 'Cache/Error.php';
* not recommended!
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: Container.php,v 1.9 2008/10/07 09:04:49 dufuz Exp $
+* @version $Id: Container.php 293863 2010-01-23 03:46:52Z clockwerx $
* @package Cache
* @access public
* @abstract
/**
* Starts the garbage collection.
*
+ * @param int $gc_maxlifetime The maximum lifetime (seconds) for a cache
+ * entry. Implemented by containers,
+ *
* @access public
* @abstract
*/
- function garbageCollection()
+ function garbageCollection($gc_maxlifetime)
{
$this->flushPreload();
} // end func garbageCollection
// | Chuck Hagenbuch <chuck@horde.org> |
// +----------------------------------------------------------------------+
//
-// $Id: db.php,v 1.8 2005/01/26 09:42:30 dufuz Exp $
+// $Id: db.php 178288 2005-01-26 09:42:30Z dufuz $
require_once 'DB.php';
require_once 'Cache/Container.php';
* )
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
-* @version $Id: db.php,v 1.8 2005/01/26 09:42:30 dufuz Exp $
+* @version $Id: db.php 178288 2005-01-26 09:42:30Z dufuz $
* @package Cache
*/
class Cache_Container_db extends Cache_Container
// | Authors: Christian Stocker <chregu@phant.ch> |
// +----------------------------------------------------------------------+
//
-// $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $
+// $Id: dbx.php 268860 2008-11-12 14:56:26Z clockwerx $
require_once 'Cache/Container.php';
* )
*
* @author Christian Stocker <chregu@phant.ch>
-* @version $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $
+* @version $Id: dbx.php 268860 2008-11-12 14:56:26Z clockwerx $
* @package Cache
*/
class Cache_Container_dbx extends Cache_Container
* @var string
*/
var $password = '';
-
- /**
- * DBx handle object
- *
- * @var object DBx handle
- */
- var $db;
/**
}
}
}
-?>
\ No newline at end of file
+?>
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: file.php,v 1.18 2006/01/31 13:40:00 bate Exp $
+// $Id: file.php 293864 2010-01-23 03:49:21Z clockwerx $
require_once 'Cache/Container.php';
* Stores cache contents in a file.
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: file.php,v 1.18 2006/01/31 13:40:00 bate Exp $
+* @version $Id: file.php 293864 2010-01-23 03:49:21Z clockwerx $
*/
class Cache_Container_file extends Cache_Container
{
$dir = $this->cache_dir . $group . '/';
if (is_writeable($this->cache_dir)) {
if (!file_exists($dir)) {
- mkdir($dir, 0755);
+ mkdir($dir, 0755, true);
clearstatcache();
}
} else {
// | Author: Lorenzo Alberton <l.alberton at quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $
+// $Id: mdb.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'MDB.php';
require_once 'Cache/Container.php';
* ------------------------------------------
*
* @author Lorenzo Alberton <l.alberton at quipo.it>
-* @version $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $
+* @version $Id: mdb.php 174777 2004-12-15 09:09:33Z dufuz $
* @package Cache
*/
class Cache_Container_mdb extends Cache_Container
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// +----------------------------------------------------------------------+
//
-// $Id: msession.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
+// $Id: msession.php 178289 2005-01-26 09:47:28Z dufuz $
require_once 'Cache/Container.php';
* WARNING: experimental, untested
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: msession.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
+* @version $Id: msession.php 178289 2005-01-26 09:47:28Z dufuz $
*/
class Cache_Container_msession extends Cache_Container
{
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $
+// $Id: phplib.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'Cache/Container.php';
*
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>, Sebastian Bergmann <sb@sebastian-bergmann.de>
-* @version $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $
+* @version $Id: phplib.php 174777 2004-12-15 09:09:33Z dufuz $
* @package Cache
* @see save()
*/
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: shm.php,v 1.6 2005/05/25 10:00:41 dufuz Exp $
+// $Id: shm.php 186977 2005-05-25 10:00:41Z dufuz $
require_once 'Cache/Container.php';
* caching algorithm using PHP.
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: shm.php,v 1.6 2005/05/25 10:00:41 dufuz Exp $
+* @version $Id: shm.php 186977 2005-05-25 10:00:41Z dufuz $
* @package Cache
*/
class Cache_Container_shm extends Cache_Container
// | Ian Eure <ieure@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: trifile.php,v 1.5 2005/04/18 19:05:01 dufuz Exp $
+// $Id: trifile.php 184642 2005-04-18 19:05:01Z dufuz $
require_once 'Cache/Container/file.php';
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Error.php,v 1.4 2004/12/15 09:09:33 dufuz Exp $
+// $Id: Error.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'PEAR.php';
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Function.php,v 1.8 2004/12/15 09:09:33 dufuz Exp $
+// $Id: Function.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'Cache.php';
* @module Function_Cache
* @modulegroup Function_Cache
* @package Cache
-* @version $Revision: 1.8 $
+* @version $Revision: 174777 $
* @access public
*/
class Cache_Function extends Cache
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Graphics.php,v 1.7 2005/01/26 09:47:28 dufuz Exp $
+// $Id: Graphics.php 178289 2005-01-26 09:47:28Z dufuz $
require_once 'Cache.php';
* the output buffer. Modify it if required!
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: Graphics.php,v 1.7 2005/01/26 09:47:28 dufuz Exp $
+* @version $Id: Graphics.php 178289 2005-01-26 09:47:28Z dufuz $
* @package Cache
*/
class Cache_Graphics extends Cache
// | Authors: Fabien MARTY <fabien.marty@free.fr> |
// +----------------------------------------------------------------------+
//
-// $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $
+// $Id: HTTP_Request.php 174777 2004-12-15 09:09:33Z dufuz $
require_once 'Cache.php';
require_once 'HTTP/Request.php';
* ?>
*
* @author Fabien MARTY <fabien.marty@free.fr>
-* @version $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $
+* @version $Id: HTTP_Request.php 174777 2004-12-15 09:09:33Z dufuz $
* @package Cache
*/
// | Vinai Kopp <kopp@netzarbeiter.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Output.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
+// $Id: Output.php 178289 2005-01-26 09:47:28Z dufuz $
require_once 'Cache.php';
*
* Based upon a case study from Christian Stocker and inspired by jpcache.
*
-* @version $Id: OutputCompression.php,v 1.9 2005/01/26 09:47:28 dufuz Exp $
+* @version $Id: OutputCompression.php 178289 2005-01-26 09:47:28Z dufuz $
* @author Ulf Wendel <ulf.wendel@phpdoc.de>, Christian Stocker <chregu@phant.ch>
* @access public
* @package Cache
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Config.php,v 1.22 2006/12/22 00:35:34 aashley Exp $
+// $Id: Config.php 306597 2010-12-24 05:11:09Z aharvey $
require_once('PEAR.php');
require_once('Config/Container.php');
*/
function Config()
{
- $this->container =& new Config_Container('section', 'root');
+ $this->container = new Config_Container('section', 'root');
} // end constructor
/**
if ($rootContainer->getName() === 'root' && $rootContainer->getType() === 'section') {
$this->container =& $rootContainer;
} else {
- $this->container =& new Config_Container('section', 'root');
+ $this->container = new Config_Container('section', 'root');
$this->container->addItem($rootContainer);
}
return true;
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +---------------------------------------------------------------------+
//
-// $Id: Container.php,v 1.41 2006/05/30 06:37:28 aashley Exp $
+// $Id: Container.php 306597 2010-12-24 05:11:09Z aharvey $
require_once 'Config.php';
*/
function &createItem($type, $name, $content, $attributes = null, $where = 'bottom', $target = null)
{
- $item =& new Config_Container($type, $name, $content, $attributes);
+ $item = new Config_Container($type, $name, $content, $attributes);
$result =& $this->addItem($item, $where, $target);
return $result;
} // end func &createItem
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Apache.php,v 1.11 2005/12/24 02:34:39 aashley Exp $
+// $Id: Apache.php 203595 2005-12-24 02:34:39Z aashley $
/**
* Simple config parser for apache httpd.conf files
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: GenericConf.php,v 1.7 2005/12/24 02:24:30 aashley Exp $
+// $Id: GenericConf.php 306537 2010-12-21 08:09:34Z cweiske $
/**
* Config parser for generic .conf files like
foreach ($lines as $line) {
$n++;
if (!preg_match('/^\s*'.$this->options['comment'].'/', $line) &&
- preg_match('/^\s*(.*)\s+'.$this->options['newline'].'\s*$/', $line, $match)) {
+ preg_match('/^\s*(.*)'.$this->options['newline'].'\s*$/', $line, $match)) {
// directive on more than one line
- $lastline .= $match[1].' ';
+ $lastline .= $match[1];
continue;
}
if ($lastline != '') {
} elseif (preg_match('/^\s*$/', $line)) {
// a blank line
$currentSection->createBlank();
- } elseif (preg_match('/^\s*(\w+)'.$this->options['equals'].'\s*((.*?)|)\s*$/', $line, $match)) {
+ } elseif (preg_match('/^\s*([\w-]+)\s*'.$this->options['equals'].'\s*((.*?)|)\s*$/', $line, $match)) {
// a directive
$currentSection->createDirective($match[1], $match[2]);
} else {
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: IniCommented.php,v 1.26 2006/05/30 06:51:05 aashley Exp $
+// $Id: IniCommented.php 306554 2010-12-21 20:04:20Z cweiske $
/**
* Config parser for PHP .ini files with comments
class Config_Container_IniCommented {
/**
- * This class options
- * Not used at the moment
- *
- * @var array
- */
- var $options = array();
+ * Options for this class:
+ * - linebreak - Character to use as new line break when serializing
+ *
+ * @var array
+ */
+ var $options = array(
+ 'linebreak' => "\n"
+ );
/**
* Constructor
*/
function Config_Container_IniCommented($options = array())
{
- $this->options = $options;
+ $this->options = array_merge($this->options, $options);
} // end constructor
/**
{
$return = true;
if (!file_exists($datasrc)) {
- return PEAR::raiseError("Datasource file does not exist.", null, PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ 'Datasource file does not exist.',
+ null, PEAR_ERROR_RETURN
+ );
}
$lines = file($datasrc);
+ if ($lines === false) {
+ return PEAR::raiseError(
+ 'File could not be read',
+ null, PEAR_ERROR_RETURN
+ );
+ }
+
$n = 0;
$lastline = '';
$currentSection =& $obj->container;
if ($state == 'normal' &&
isset($return[$returnpos]) &&
!empty($return[$returnpos][1])) {
- return PEAR::raiseError("invalid ini syntax, quotes cannot follow text '$text'",
- null, PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ 'invalid ini syntax, quotes cannot follow'
+ . " text '$text'",
+ null, PEAR_ERROR_RETURN
+ );
}
if ($returnpos >= 0 && isset($return[$returnpos])) {
// trim any unnecessary whitespace in earlier entries
}
break;
default :
- PEAR::raiseError("::_quoteAndCommaParser oops, state missing", null, PEAR_ERROR_DIE);
+ PEAR::raiseError(
+ "::_quoteAndCommaParser oops, state missing",
+ null, PEAR_ERROR_DIE
+ );
break;
}
} else {
if (!isset($return[$returnpos])) {
$return[$returnpos] = array('normal', '');
}
- // add this character to the current ini segment if non-empty, or if in a quote
+ // add this character to the current ini segment if
+ // non-empty, or if in a quote
if ($state == 'quote') {
$return[$returnpos][1] .= $char;
} elseif (!empty($return[$returnpos][1]) ||
}
} else {
if (trim($char) != '') {
- return PEAR::raiseError("invalid ini syntax, text after a quote not allowed '$text'",
- null, PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ 'invalid ini syntax, text after a quote'
+ . " not allowed '$text'",
+ null, PEAR_ERROR_RETURN
+ );
}
}
}
}
switch ($obj->type) {
case 'blank':
- $string = "\n";
+ $string = $this->options['linebreak'];
break;
case 'comment':
- $string = ';'.$obj->content."\n";
+ $string = ';'.$obj->content . $this->options['linebreak'];
break;
case 'directive':
$count = $obj->parent->countChildren('directive', $obj->name);
strpos($content, '=') !== false ||
strpos($content, '"') !== false ||
strpos($content, '%') !== false ||
- strpos($content, '~') !== false) {
+ strpos($content, '~') !== false ||
+ strpos($content, '!') !== false ||
+ strpos($content, '|') !== false ||
+ strpos($content, '&') !== false ||
+ strpos($content, '(') !== false ||
+ strpos($content, ')') !== false ||
+ $content === 'none') {
$content = '"'.addslashes($content).'"';
}
if ($count > 1) {
}
if ($childrenCount[$obj->name] == $count-1) {
// Clean the static for future calls to toString
- $string .= $commaString[$obj->name].$content."\n";
+ $string .= $commaString[$obj->name] . $content
+ . $this->options['linebreak'];
unset($childrenCount[$obj->name]);
unset($commaString[$obj->name]);
} else {
$commaString[$obj->name] .= $content.', ';
}
} else {
- $string = $obj->name.' = '.$content."\n";
+ $string = $obj->name.' = '.$content . $this->options['linebreak'];
}
break;
case 'section':
if (!$obj->isRoot()) {
- $string = '['.$obj->name."]\n";
+ $string = '[' . $obj->name . ']' . $this->options['linebreak'];
}
if (count($obj->children) > 0) {
for ($i = 0; $i < count($obj->children); $i++) {
<?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: Bertrand Mansion <bmansion@mamasam.com> |
-// +----------------------------------------------------------------------+
-//
-// $Id: IniFile.php,v 1.17 2005/12/24 02:36:56 aashley Exp $
+/**
+ * Part of the PEAR Config package
+ *
+ * PHP Version 4
+ *
+ * @category Configuration
+ * @package Config
+ * @author Bertrand Mansion <bmansion@mamasam.com>
+ * @license http://www.php.net/license PHP License
+ * @link http://pear.php.net/package/Config
+ */
/**
-* Config parser for PHP .ini files
-* Faster because it uses parse_ini_file() but get rid of comments,
-* quotes, types and converts On, Off, True, False, Yes, No to 0 and 1.
-*
-* @author Bertrand Mansion <bmansion@mamasam.com>
-* @package Config
-*/
-class Config_Container_IniFile {
+ * Config parser for PHP .ini files
+ * Faster because it uses parse_ini_file() but get rid of comments,
+ * quotes, types and converts On, Off, True, False, Yes, No to 0 and 1.
+ *
+ * Empty lines and comments are not preserved.
+ *
+ * @category Configuration
+ * @package Config
+ * @author Bertrand Mansion <bmansion@mamasam.com>
+ * @license http://www.php.net/license PHP License
+ * @link http://pear.php.net/package/Config
+ */
+class Config_Container_IniFile
+{
/**
- * This class options
- * Not used at the moment
- *
- * @var array
+ * This class options
+ * Not used at the moment
+ *
+ * @var array
*/
var $options = array();
/**
- * Constructor
- *
- * @access public
- * @param string $options (optional)Options to be used by renderer
- */
+ * Constructor
+ *
+ * @param string $options (optional)Options to be used by renderer
+ *
+ * @access public
+ */
function Config_Container_IniFile($options = array())
{
$this->options = $options;
} // end constructor
/**
- * Parses the data of the given configuration file
- *
- * @access public
- * @param string $datasrc path to the configuration file
- * @param object $obj reference to a config object
- * @return mixed returns a PEAR_ERROR, if error occurs or true if ok
- */
+ * Parses the data of the given configuration file
+ *
+ * @param string $datasrc path to the configuration file
+ * @param object &$obj reference to a config object
+ *
+ * @return mixed Returns a PEAR_ERROR, if error occurs or true if ok
+ *
+ * @access public
+ */
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!file_exists($datasrc)) {
- return PEAR::raiseError("Datasource file does not exist.", null, PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ "Datasource file does not exist.",
+ null, PEAR_ERROR_RETURN
+ );
}
$currentSection =& $obj->container;
$confArray = parse_ini_file($datasrc, true);
if (!$confArray) {
- return PEAR::raiseError("File '$datasrc' does not contain configuration data.", null, PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ "File '$datasrc' does not contain configuration data.",
+ null, PEAR_ERROR_RETURN
+ );
}
foreach ($confArray as $key => $value) {
if (is_array($value)) {
$currentSection =& $obj->container->createSection($key);
foreach ($value as $directive => $content) {
// try to split the value if comma found
- if (strpos($content, '"') === false) {
+ if (!is_array($content) && strpos($content, '"') === false) {
$values = preg_split('/\s*,\s+/', $content);
if (count($values) > 1) {
foreach ($values as $k => $v) {
} // end func parseDatasrc
/**
- * Returns a formatted string of the object
- * @param object $obj Container object to be output as string
- * @access public
- * @return string
- */
+ * Returns a formatted string of the object
+ *
+ * @param object &$obj Container object to be output as string
+ *
+ * @return string
+ *
+ * @access public
+ */
function toString(&$obj)
{
static $childrenCount, $commaString;
$string = '';
}
switch ($obj->type) {
- case 'blank':
- $string = "\n";
- break;
- case 'comment':
- $string = ';'.$obj->content."\n";
- break;
- case 'directive':
- $count = $obj->parent->countChildren('directive', $obj->name);
- $content = $obj->content;
- if ($content === false) {
- $content = '0';
- } elseif ($content === true) {
- $content = '1';
- } elseif (strlen(trim($content)) < strlen($content) ||
- strpos($content, ',') !== false ||
- strpos($content, ';') !== false ||
- strpos($content, '=') !== false ||
- strpos($content, '"') !== false ||
- strpos($content, '%') !== false ||
- strpos($content, '~') !== false) {
- $content = '"'.addslashes($content).'"';
- }
+ case 'blank':
+ $string = "\n";
+ break;
+ case 'comment':
+ $string = ';'.$obj->content."\n";
+ break;
+ case 'directive':
+ $count = $obj->parent->countChildren('directive', $obj->name);
+ $content = $obj->content;
+ if (!is_array($content)) {
+ $content = $this->contentToString($content);
if ($count > 1) {
// multiple values for a directive are separated by a comma
if (isset($childrenCount[$obj->name])) {
} else {
$string = $obj->name.'='.$content."\n";
}
- break;
- case 'section':
- if (!$obj->isRoot()) {
- $string = '['.$obj->name."]\n";
- }
- if (count($obj->children) > 0) {
- for ($i = 0; $i < count($obj->children); $i++) {
- $string .= $this->toString($obj->getChild($i));
+ } else {
+ //array
+ $string = '';
+ $n = 0;
+ foreach ($content as $contentKey => $contentValue) {
+ if (is_integer($contentKey) && $contentKey == $n) {
+ $stringKey = '';
+ ++$n;
+ } else {
+ $stringKey = $contentKey;
}
+ $string .= $obj->name . '[' . $stringKey . ']='
+ . $this->contentToString($contentValue) . "\n";
}
- break;
- default:
- $string = '';
+ }
+ break;
+ case 'section':
+ if (!$obj->isRoot()) {
+ $string = '['.$obj->name."]\n";
+ }
+ if (count($obj->children) > 0) {
+ for ($i = 0; $i < count($obj->children); $i++) {
+ $string .= $this->toString($obj->getChild($i));
+ }
+ }
+ break;
+ default:
+ $string = '';
}
return $string;
} // end func toString
+
+
+
+ /**
+ * Converts a given content variable to a string that can
+ * be used as value in a ini file
+ *
+ * @param mixed $content Value
+ *
+ * @return string $content String to be used as ini value
+ */
+ function contentToString($content)
+ {
+ if ($content === false) {
+ $content = '0';
+ } else if ($content === true) {
+ $content = '1';
+ } else if (strlen(trim($content)) < strlen($content)
+ || strpos($content, ',') !== false
+ || strpos($content, ';') !== false
+ || strpos($content, '=') !== false
+ || strpos($content, '"') !== false
+ || strpos($content, '%') !== false
+ || strpos($content, '~') !== false
+ || strpos($content, '!') !== false
+ || strpos($content, '|') !== false
+ || strpos($content, '&') !== false
+ || strpos($content, '(') !== false
+ || strpos($content, ')') !== false
+ || $content === 'none'
+ ) {
+ $content = '"'.addslashes($content).'"';
+ }
+ return $content;
+ }
+
} // end class Config_Container_IniFile
?>
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: PHPArray.php,v 1.32 2007/06/12 05:24:19 aashley Exp $
+// $Id: PHPArray.php 306488 2010-12-20 08:45:09Z cweiske $
/**
* Config parser for common PHP configuration array
break;
default:
if (is_array($value)) {
- if ($this->options['duplicateDirectives'] == true && is_integer(key($value))) {
+ if ($this->options['duplicateDirectives'] == true
+ //speed (first/one key is numeric)
+ && is_integer(key($value))
+ //accuracy (all keys are numeric)
+ && 1 == count(array_unique(array_map('is_numeric', array_keys($value))))
+ ) {
foreach ($value as $nestedValue) {
if (is_array($nestedValue)) {
$section =& $container->createSection($key);
$string .= $obj->content;
} elseif (is_bool($obj->content)) {
$string .= ($obj->content) ? 'true' : 'false';
+ } elseif ($obj->content === null) {
+ $string .= 'null';
}
$string .= ";\n";
$string .= $attrString;
<?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: Phillip Oertel <me@phillipoertel.com> |
-// +----------------------------------------------------------------------+
-//
-// $Id: PHPConstants.php,v 1.3 2005/12/24 02:24:30 aashley Exp $
-
/**
-* Config parser for PHP constant files
-*
-* @author Phillip Oertel <me@phillipoertel.com>
-* @package Config
-* @version 0.1 (not submitted)
-*/
-
+ * Part of the PEAR Config package
+ *
+ * PHP Version 4
+ *
+ * @category Configuration
+ * @package Config
+ * @author Phillip Oertel <me@phillipoertel.com>
+ * @license http://www.php.net/license PHP License
+ * @version SVN: $Id: PHPConstants.php 306571 2010-12-22 06:50:39Z cweiske $
+ * @link http://pear.php.net/package/Config
+ */
require_once 'Config/Container.php';
-class Config_Container_PHPConstants extends Config_Container {
-
+/**
+ * Config parser for PHP constant files
+ *
+ * @category Configuration
+ * @package Config
+ * @author Phillip Oertel <me@phillipoertel.com>
+ * @license http://www.php.net/license PHP License
+ * @link http://pear.php.net/package/Config
+ */
+class Config_Container_PHPConstants extends Config_Container
+{
/**
- * This class options
- * Not used at the moment
- *
- * @var array
- */
- var $options = array();
+ * Valid config options:
+ * - "lowercase" - boolean - config names are lowercased when reading them
+ *
+ * @var array
+ */
+ var $options = array(
+ 'lowercase' => false
+ );
/**
- * Constructor
- *
- * @access public
- * @param string $options (optional)Options to be used by renderer
- */
+ * Constructor
+ *
+ * @param string $options (optional)Options to be used by renderer
+ *
+ * @access public
+ */
function Config_Container_PHPConstants($options = array())
{
- $this->options = $options;
+ $this->options = array_merge($this->options, $options);
} // end constructor
/**
- * Parses the data of the given configuration file
- *
- * @access public
- * @param string $datasrc path to the configuration file
- * @param object $obj reference to a config object
- * @return mixed returns a PEAR_ERROR, if error occurs or true if ok
- */
+ * Parses the data of the given configuration file
+ *
+ * @param string $datasrc Path to the configuration file
+ * @param object &$obj Reference to a config object
+ *
+ * @return mixed PEAR_ERROR, if error occurs or true if ok
+ *
+ * @access public
+ */
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!file_exists($datasrc)) {
- return PEAR::raiseError("Datasource file does not exist.", null,
- PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ 'Datasource file does not exist.',
+ null, PEAR_ERROR_RETURN
+ );
}
$fileContent = file_get_contents($datasrc, true);
if (!$fileContent) {
- return PEAR::raiseError("File '$datasrc' could not be read.", null,
- PEAR_ERROR_RETURN);
+ return PEAR::raiseError(
+ "File '$datasrc' could not be read.",
+ null, PEAR_ERROR_RETURN
+ );
}
$rows = explode("\n", $fileContent);
}
// comments
- if (preg_match("/^\/\/\s*(.+)$/", $line, $matches) ||
- preg_match("/^#\s*(.+)$/", $line, $matches)) {
+ if (preg_match("/^\/\/\s*(.+)$/", $line, $matches)
+ || preg_match("/^#\s*(.+)$/", $line, $matches)
+ ) {
$obj->container->createComment(trim($matches[1]));
continue;
}
$regex = "/^\s*define\s*\('([A-Z1-9_]+)',\s*'*(.[^\']*)'*\)/";
preg_match($regex, $line, $matches);
if (!empty($matches)) {
- $obj->container->createDirective(trim($matches[1]),
- trim($matches[2]));
+ $name = trim($matches[1]);
+ if ($this->options['lowercase']) {
+ $name = strtolower($name);
+ }
+ $obj->container->createDirective(
+ $name, trim($matches[2])
+ );
}
}
} // end func parseDatasrc
/**
- * Returns a formatted string of the object
- * @param object $obj Container object to be output as string
- * @access public
- * @return string
- */
- function toString(&$obj)
- {
- $string = '';
-
- switch ($obj->type)
- {
- case 'blank':
- $string = "\n";
- break;
-
- case 'comment':
- $string = '// '.$obj->content."\n";
- break;
-
- case 'directive':
- $content = $obj->content;
- // don't quote numeric values, true/false and constants
- if (!is_numeric($content) && !in_array($content, array('false',
- 'true')) && !preg_match('/^[A-Z_]+$/', $content)) {
- $content = "'".$content."'";
- }
- $string = 'define(\''.$obj->name.'\', '.$content.');'.chr(10);
- break;
-
- case 'section':
- if (!$obj->isRoot()) {
- $string = chr(10);
- $string .= '//'.chr(10);
- $string .= '// '.$obj->name.chr(10);
- $string .= '//'.chr(10);
- }
- if (count($obj->children) > 0) {
- for ($i = 0, $max = count($obj->children); $i < $max; $i++) {
- $string .= $this->toString($obj->getChild($i));
- }
- }
- break;
- default:
- $string = '';
- }
- return $string;
- } // end func toString
+ * Returns a formatted string of the object
+ *
+ * @param object &$obj Container object to be output as string
+ *
+ * @return string
+ *
+ * @access public
+ */
+ function toString(&$obj)
+ {
+ $string = '';
+
+ switch ($obj->type)
+ {
+ case 'blank':
+ $string = "\n";
+ break;
+
+ case 'comment':
+ $string = '// '.$obj->content."\n";
+ break;
+
+ case 'directive':
+ $content = $obj->content;
+ // don't quote numeric values, true/false and constants
+ if (is_bool($content)) {
+ $content = var_export($content, true);
+ } else if (!is_numeric($content)
+ && !in_array($content, array('false', 'true'))
+ && !preg_match('/^[A-Z_]+$/', $content)
+ ) {
+ $content = "'" . str_replace("'", '\\\'', $content) . "'";
+ }
+ $string = 'define('
+ . '\'' . strtoupper($obj->name) . '\''
+ . ', ' . $content . ');'
+ . chr(10);
+ break;
+
+ case 'section':
+ if (!$obj->isRoot()) {
+ $string = chr(10);
+ $string .= '//'.chr(10);
+ $string .= '// '.$obj->name.chr(10);
+ $string .= '//'.chr(10);
+ }
+ if (count($obj->children) > 0) {
+ for ($i = 0, $max = count($obj->children); $i < $max; $i++) {
+ $string .= $this->toString($obj->getChild($i));
+ }
+ }
+ break;
+ default:
+ $string = '';
+ }
+ return $string;
+ } // end func toString
/**
- * Writes the configuration to a file
- *
- * @param mixed datasrc info on datasource such as path to the file
- * @param string configType (optional)type of configuration
- * @access public
- * @return string
- */
+ * Writes the configuration to a file
+ *
+ * @param mixed $datasrc Info on datasource such as path to the file
+ * @param string &$obj Configuration object to write
+ *
+ * @return mixed PEAR_Error on failure or boolean true if all went well
+ *
+ * @access public
+ */
function writeDatasrc($datasrc, &$obj)
{
$fp = @fopen($datasrc, 'w');
- if ($fp) {
- $string = "<?php";
- $string .= "\n\n";
- $string .= '/**' . chr(10);
- $string .= ' *' . chr(10);
- $string .= ' * AUTOMATICALLY GENERATED CODE -
- DO NOT EDIT BY HAND' . chr(10);
- $string .= ' *' . chr(10);
- $string .= '**/' . chr(10);
- $string .= $this->toString($obj);
- $string .= "\n?>"; // <? : Fix my syntax coloring
-
- $len = strlen($string);
- @flock($fp, LOCK_EX);
- @fwrite($fp, $string, $len);
- @flock($fp, LOCK_UN);
- @fclose($fp);
-
- // need an error check here
-
- return true;
- } else {
- return PEAR::raiseError('Cannot open datasource for writing.', 1,
- PEAR_ERROR_RETURN);
+ if (!$fp) {
+ return PEAR::raiseError(
+ 'Cannot open datasource for writing.',
+ 1, PEAR_ERROR_RETURN
+ );
}
+
+ $string = "<?php";
+ $string .= "\n\n";
+ $string .= '/**' . chr(10);
+ $string .= ' *' . chr(10);
+ $string .= ' * AUTOMATICALLY GENERATED CODE - DO NOT EDIT BY HAND' . chr(10);
+ $string .= ' *' . chr(10);
+ $string .= '**/' . chr(10);
+ $string .= $this->toString($obj);
+ $string .= "\n?>"; // <? : Fix my syntax coloring
+
+ $len = strlen($string);
+ @flock($fp, LOCK_EX);
+ @fwrite($fp, $string, $len);
+ @flock($fp, LOCK_UN);
+ @fclose($fp);
+
+ // need an error check here
+
+ return true;
} // end func writeDatasrc
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: XML.php,v 1.15 2005/12/24 02:24:30 aashley Exp $
+// $Id: XML.php 203592 2005-12-24 02:24:30Z aashley $
require_once('XML/Parser.php');
require_once('XML/Util.php');
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
-// +----------------------------------------------------------------------+
-// | PHP Version 5 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2004 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,v 1.4 2007/06/12 14:58:56 cellog Exp $
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 1997-2004 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.
+ *
+ * @category Console
+ * @package Console_Getopt
+ * @author Andrei Zmievski <andrei@php.net>
+ * @license http://www.php.net/license/3_0.txt PHP 3.0
+ * @version CVS: $Id: Getopt.php 306067 2010-12-08 00:13:31Z dufuz $
+ * @link http://pear.php.net/package/Console_Getopt
+ */
require_once 'PEAR.php';
/**
* Command-line options parsing class.
*
- * @author Andrei Zmievski <andrei@php.net>
- *
+ * @category Console
+ * @package Console_Getopt
+ * @author Andrei Zmievski <andrei@php.net>
+ * @license http://www.php.net/license/3_0.txt PHP 3.0
+ * @link http://pear.php.net/package/Console_Getopt
*/
-class Console_Getopt {
+class Console_Getopt
+{
+
/**
* Parses the command-line options.
*
*
* 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
+ * @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
+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
*
* @return array two-element array containing the list of parsed options and
* the non-option arguments
- *
* @access public
- *
*/
- function getopt2($args, $short_options, $long_options = null)
+ function getopt2($args, $short_options, $long_options = null, $skip_unknown = false)
{
- return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
+ return Console_Getopt::doGetopt(2, $args, $short_options, $long_options, $skip_unknown);
}
/**
* This function expects $args to start with the script name (POSIX-style).
* Preserved for backwards compatibility.
+ *
+ * @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
+ *
* @see getopt2()
- */
- function getopt($args, $short_options, $long_options = null)
+ * @return array two-element array containing the list of parsed options and
+ * the non-option arguments
+ */
+ function getopt($args, $short_options, $long_options = null, $skip_unknown = false)
{
- return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
+ return Console_Getopt::doGetopt(1, $args, $short_options, $long_options, $skip_unknown);
}
/**
* The actual implementation of the argument parsing code.
+ *
+ * @param int $version Version to use
+ * @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
+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
+ *
+ * @return array
*/
- function doGetopt($version, $args, $short_options, $long_options = null)
+ function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
{
// 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();
+
+ $non_opts = $opts = array();
settype($args, 'array');
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. */
$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))
+ $error = Console_Getopt::_parseLongOption(substr($arg, 2),
+ $long_options,
+ $opts,
+ $args,
+ $skip_unknown);
+ if (PEAR::isError($error)) {
return $error;
+ }
} elseif ($arg == '-') {
// - is stdin
$non_opts = array_merge($non_opts, array_slice($args, $i));
break;
} else {
- $error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
- if (PEAR::isError($error))
+ $error = Console_Getopt::_parseShortOption(substr($arg, 1),
+ $short_options,
+ $opts,
+ $args,
+ $skip_unknown);
+ if (PEAR::isError($error)) {
return $error;
+ }
}
}
}
/**
- * @access private
+ * Parse short option
+ *
+ * @param string $arg Argument
+ * @param string[] $short_options Available short options
+ * @param string[][] &$opts
+ * @param string[] &$args
+ * @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
*
+ * @access private
+ * @return void
*/
- function _parseShortOption($arg, $short_options, &$opts, &$args)
+ function _parseShortOption($arg, $short_options, &$opts, &$args, $skip_unknown)
{
for ($i = 0; $i < strlen($arg); $i++) {
- $opt = $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 (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') {
+ if ($skip_unknown === true) {
+ break;
+ }
+
+ $msg = "Console_Getopt: unrecognized option -- $opt";
+ return PEAR::raiseError($msg);
}
if (strlen($spec) > 1 && $spec{1} == ':') {
break;
} else if (list(, $opt_arg) = each($args)) {
/* Else use the next argument. */;
- if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
- return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
+ if (Console_Getopt::_isShortOpt($opt_arg)
+ || Console_Getopt::_isLongOpt($opt_arg)) {
+ $msg = "option requires an argument --$opt";
+ return PEAR::raiseError("Console_Getopt:" . $msg);
}
} else {
- return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
+ $msg = "option requires an argument --$opt";
+ return PEAR::raiseError("Console_Getopt:" . $msg);
}
}
}
}
/**
- * @access private
+ * Checks if an argument is a short option
*
+ * @param string $arg Argument to check
+ *
+ * @access private
+ * @return bool
*/
function _isShortOpt($arg)
{
- return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
+ return strlen($arg) == 2 && $arg[0] == '-'
+ && preg_match('/[a-zA-Z]/', $arg[1]);
}
/**
- * @access private
+ * Checks if an argument is a long option
*
+ * @param string $arg Argument to check
+ *
+ * @access private
+ * @return bool
*/
function _isLongOpt($arg)
{
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
- preg_match('/[a-zA-Z]+$/', substr($arg, 2));
+ preg_match('/[a-zA-Z]+$/', substr($arg, 2));
}
/**
- * @access private
+ * Parse long option
*
+ * @param string $arg Argument
+ * @param string[] $long_options Available long options
+ * @param string[][] &$opts
+ * @param string[] &$args
+ *
+ * @access private
+ * @return void|PEAR_Error
*/
- function _parseLongOption($arg, $long_options, &$opts, &$args)
+ function _parseLongOption($arg, $long_options, &$opts, &$args, $skip_unknown)
{
@list($opt, $opt_arg) = explode('=', $arg, 2);
+
$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);
+
$long_opt_name = str_replace('=', '', $long_opt);
/* Option doesn't match. Go on to the next one. */
continue;
}
- $opt_rest = substr($long_opt, $opt_len);
+ $opt_rest = substr($long_opt, $opt_len);
/* Check that the options uniquely matches one of the allowed
options. */
} else {
$next_option_rest = '';
}
+
if ($opt_rest != '' && $opt{0} != '=' &&
$i + 1 < count($long_options) &&
$opt == substr($long_options[$i+1], 0, $opt_len) &&
$next_option_rest != '' &&
$next_option_rest{0} != '=') {
- return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
+
+ $msg = "Console_Getopt: option --$opt is ambiguous";
+ return PEAR::raiseError($msg);
}
if (substr($long_opt, -1) == '=') {
/* 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");
+ $msg = "Console_Getopt: option requires an argument --$opt";
+ return PEAR::raiseError($msg);
}
- if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
- return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
+
+ if (Console_Getopt::_isShortOpt($opt_arg)
+ || Console_Getopt::_isLongOpt($opt_arg)) {
+ $msg = "Console_Getopt: option requires an argument --$opt";
+ return PEAR::raiseError($msg);
}
}
} else if ($opt_arg) {
- return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
+ $msg = "Console_Getopt: option --$opt doesn't allow an argument";
+ return PEAR::raiseError($msg);
}
$opts[] = array('--' . $opt, $opt_arg);
return;
}
+ if ($skip_unknown === true) {
+ 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
- */
+ * 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?)");
+ $msg = "Could not read cmd args (register_argc_argv=Off?)";
+ return PEAR::raiseError("Console_Getopt: " . $msg);
}
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
}
return $argv;
}
-}
-
-
\ No newline at end of file
+}
\ No newline at end of file
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: DB.php,v 1.88 2007/08/12 05:27:25 aharvey Exp $
+ * @version CVS: $Id: DB.php 315557 2011-08-26 14:32:35Z danielc $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB
*/
function apiVersion()
{
- return '1.7.13';
+ return '1.7.14';
}
// }}}
*/
function isError($value)
{
- return is_a($value, 'DB_Error');
+ return is_object($value) && is_a($value, 'DB_Error');
}
// }}}
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_Error extends PEAR_Error
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_result
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
* @see DB_common::setFetchMode()
*/
* @access private
* @var string
*/
- var $_DB_DataObject_version = "@version@";
+ var $_DB_DataObject_version = "1.9.6";
/**
* The Database table (used by table extends)
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: common.php,v 1.143 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: common.php 315557 2011-08-26 14:32:35Z danielc $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_common extends PEAR
function __wakeup()
{
if ($this->was_connected) {
- $this->connect($this->dsn, $this->options);
+ $this->connect($this->dsn, $this->options['persistent']);
}
}
return $query;
}
$result = $this->query($query, $params);
- if (is_a($result, 'DB_result')) {
+ if (is_object($result) && is_a($result, 'DB_result')) {
$result->setOption('limit_from', $from);
$result->setOption('limit_count', $count);
}
* query and native error code.
* @param mixed native error code, integer or string depending the
* backend
+ * @param mixed dummy parameter for E_STRICT compatibility with
+ * PEAR::raiseError
+ * @param mixed dummy parameter for E_STRICT compatibility with
+ * PEAR::raiseError
*
* @return object the PEAR_Error object
*
* @see PEAR_Error
*/
function &raiseError($code = DB_ERROR, $mode = null, $options = null,
- $userinfo = null, $nativecode = null)
+ $userinfo = null, $nativecode = null, $dummy1 = null,
+ $dummy2 = null)
{
// The error is yet a DB error object
if (is_object($code)) {
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: dbase.php,v 1.45 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: dbase.php 242771 2007-09-21 13:40:42Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_dbase extends DB_common
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: fbsql.php,v 1.88 2007/07/06 05:19:21 aharvey Exp $
+ * @version CVS: $Id: fbsql.php 239211 2007-07-06 05:19:21Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
* @since Class functional since Release 1.7.0
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: ibase.php,v 1.116 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: ibase.php 277804 2009-03-26 07:16:31Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
* @since Class became stable in Release 1.7.0
*/
$error_regexps = array(
'/generator .* is not defined/'
=> DB_ERROR_SYNTAX, // for compat. w ibase_errcode()
+ '/violation of [\w ]+ constraint/i'
+ => DB_ERROR_CONSTRAINT,
'/table.*(not exist|not found|unknown)/i'
=> DB_ERROR_NOSUCHTABLE,
'/table .* already exists/i'
=> DB_ERROR_NOT_FOUND,
'/validation error for column .* value "\*\*\* null/i'
=> DB_ERROR_CONSTRAINT_NOT_NULL,
- '/violation of [\w ]+ constraint/i'
- => DB_ERROR_CONSTRAINT,
'/conversion error from string/i'
=> DB_ERROR_INVALID_NUMBER,
'/no permission for/i'
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: ifx.php,v 1.75 2007/07/06 05:19:21 aharvey Exp $
+ * @version CVS: $Id: ifx.php 302738 2010-08-24 03:06:52Z clockwerx $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_ifx extends DB_common
*/
function errorCode($nativecode)
{
- if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
+ if (preg_match('/SQLCODE=(.*)]/', $nativecode, $match)) {
$code = $match[1];
if (isset($this->errorcode_map[$code])) {
return $this->errorcode_map[$code];
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: msql.php,v 1.64 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: msql.php 242771 2007-09-21 13:40:42Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
* @since Class not functional until Release 1.7.0
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: mssql.php,v 1.92 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: mssql.php 306603 2010-12-24 06:05:07Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_mssql extends DB_common
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
}
+ // }}}
+ // {{{ escapeSimple()
+
+ /**
+ * Escapes a string in a manner suitable for SQL Server.
+ *
+ * @param string $str the string to be escaped
+ * @return string the escaped string
+ *
+ * @see DB_common::quoteSmart()
+ * @since Method available since Release 1.6.0
+ */
+ function escapeSimple($str)
+ {
+ return str_replace(
+ array("'", "\\\r\n", "\\\n"),
+ array("''", "\\\\\r\n\r\n", "\\\\\n\n"),
+ $str
+ );
+ }
+
// }}}
// {{{ quoteIdentifier()
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: mysql.php,v 1.126 2007/09/21 13:32:52 aharvey Exp $
+ * @version CVS: $Id: mysql.php 242769 2007-09-21 13:32:52Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_mysql extends DB_common
}
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);
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: mysqli.php,v 1.82 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: mysqli.php 315557 2011-08-26 14:32:35Z danielc $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
* @since Class functional since Release 1.6.3
*/
$got_string = false;
}
- if (!is_a($id, 'mysqli_result')) {
+ if (!is_object($id) || !is_a($id, 'mysqli_result')) {
return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: oci8.php,v 1.115 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: oci8.php 293241 2010-01-08 05:00:28Z danielc $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_oci8 extends DB_common
if (isset($this->prepare_types[(int)$stmt])) {
unset($this->prepare_types[(int)$stmt]);
unset($this->manip_query[(int)$stmt]);
+ unset($this->_prepared_queries[(int)$stmt]);
} else {
return false;
}
$tmp = $this->oci8RaiseError($stmt);
return $tmp;
}
- $this->last_query = str_replace(':bind'.$i, $this->quoteSmart($data[$key]), $this->last_query);
+ $this->last_query = preg_replace("/:bind$i(?!\d)/",
+ $this->quoteSmart($data[$key]), $this->last_query, 1);
$i++;
}
if ($this->autocommit) {
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: odbc.php,v 1.81 2007/07/06 05:19:21 aharvey Exp $
+ * @version CVS: $Id: odbc.php 239211 2007-07-06 05:19:21Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_odbc extends DB_common
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: pgsql.php,v 1.138 2007/09/21 13:40:41 aharvey Exp $
+ * @version CVS: $Id: pgsql.php 306604 2010-12-24 06:09:35Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_pgsql extends DB_common
* CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
* GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
* REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
- * UNLISTEN, UPDATE, VACUUM
+ * UNLISTEN, UPDATE, VACUUM, WITH
*/
if ($ismanip) {
$this->affected = @pg_affected_rows($result);
return DB_OK;
- } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW)\s/si',
+ } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si',
$query))
{
$this->row[(int)$result] = 0; // reset the row counter.
}
// }}}
+ // {{{ _checkManip()
+
+ /**
+ * Checks if the given query is a manipulation query. This also takes into
+ * account the _next_query_manip flag and sets the _last_query_manip flag
+ * (and resets _next_query_manip) according to the result.
+ *
+ * @param string The query to check.
+ *
+ * @return boolean true if the query is a manipulation query, false
+ * otherwise
+ *
+ * @access protected
+ */
+ function _checkManip($query)
+ {
+ return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
+ || parent::_checkManip($query));
+ }
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
- * @version CVS: $Id: sqlite.php,v 1.117 2007/09/21 14:23:28 aharvey Exp $
+ * @version CVS: $Id: sqlite.php 306605 2010-12-24 06:22:59Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_sqlite extends DB_common
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
'/^no such column:/' => DB_ERROR_NOSUCHFIELD,
+ '/no column named/' => DB_ERROR_NOSUCHFIELD,
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
$flags = '';
if ($id[$i]['pk']) {
$flags .= 'primary_key ';
+ if (strtoupper($type) == 'INTEGER') {
+ $flags .= 'auto_increment ';
+ }
}
if ($id[$i]['notnull']) {
$flags .= 'not_null ';
* @author Stig Bakken <stig@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: storage.php,v 1.24 2007/08/12 05:27:25 aharvey Exp $
+ * @version CVS: $Id: storage.php 241120 2007-08-12 05:27:25Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Stig Bakken <stig@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_storage extends PEAR
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: sybase.php,v 1.87 2007/09/21 13:40:42 aharvey Exp $
+ * @version CVS: $Id: sybase.php 242771 2007-09-21 13:40:42Z aharvey $
* @link http://pear.php.net/package/DB
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: 1.7.13
+ * @version Release: 1.7.14
* @link http://pear.php.net/package/DB
*/
class DB_sybase extends DB_common
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * File\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category File\r
- * @package File\r
- * @author Richard Heyes <richard@php.net>\r
- * @author Tal Peer <tal@php.net>\r
- * @author Michael Wallner <mike@php.net>\r
- * @copyright 2002-2005 The Authors\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: File.php,v 1.38 2007/03/24 16:38:56 dufuz Exp $\r
- * @link http://pear.php.net/package/File\r
- */\r
-\r
-/**\r
- * Requires PEAR\r
- */\r
-require_once 'PEAR.php';\r
-\r
-/**\r
- * The default number of bytes for reading\r
- */\r
-if (!defined('FILE_DEFAULT_READSIZE')) {\r
- define('FILE_DEFAULT_READSIZE', 1024, true);\r
-}\r
-\r
-/**\r
- * The maximum number of bytes for reading lines\r
- */\r
-if (!defined('FILE_MAX_LINE_READSIZE')) {\r
- define('FILE_MAX_LINE_READSIZE', 40960, true);\r
-}\r
-\r
-/**\r
- * Whether file locks should block\r
- */\r
-if (!defined('FILE_LOCKS_BLOCK')) {\r
- define('FILE_LOCKS_BLOCK', true, true);\r
-}\r
-\r
-/**\r
- * Mode to use for reading from files\r
- */\r
-define('FILE_MODE_READ', 'rb', true);\r
-\r
-/**\r
- * Mode to use for truncating files, then writing\r
- */\r
-define('FILE_MODE_WRITE', 'wb', true);\r
-\r
-/**\r
- * Mode to use for appending to files\r
- */\r
-define('FILE_MODE_APPEND', 'ab', true);\r
-\r
-/**\r
- * Use this when a shared (read) lock is required\r
- */\r
-define('FILE_LOCK_SHARED', LOCK_SH | (FILE_LOCKS_BLOCK ? 0 : LOCK_NB), true);\r
-\r
-/**\r
- * Use this when an exclusive (write) lock is required\r
- */\r
-define('FILE_LOCK_EXCLUSIVE', LOCK_EX | (FILE_LOCKS_BLOCK ? 0 : LOCK_NB), true);\r
-\r
-/**\r
- * Class for handling files\r
- *\r
- * A class with common functions for writing,\r
- * reading and handling files and directories\r
- *\r
- * @author Richard Heyes <richard@php.net>\r
- * @author Tal Peer <tal@php.net>\r
- * @author Michael Wallner <mike@php.net>\r
- * @access public\r
- * @package File\r
- *\r
- * @static\r
- */\r
-class File extends PEAR\r
-{\r
- /**\r
- * Destructor\r
- *\r
- * Unlocks any locked file pointers and closes all filepointers\r
- *\r
- * @access private\r
- */\r
- function _File()\r
- {\r
- File::closeAll();\r
- }\r
-\r
- /**\r
- * Handles file pointers. If a file pointer needs to be opened,\r
- * it will be. If it already exists (based on filename and mode)\r
- * then the existing one will be returned.\r
- *\r
- * @access private\r
- * @param string $filename Filename to be used\r
- * @param string $mode Mode to open the file in\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error on error or file pointer resource on success\r
- */\r
- function _getFilePointer($filename, $mode, $lock = false)\r
- {\r
- $filePointers = &PEAR::getStaticProperty('File', 'filePointers');\r
-\r
- // Win32 is case-insensitive\r
- if (OS_WINDOWS) {\r
- $filename = strtolower($filename);\r
- }\r
-\r
- // check if file pointer already exists\r
- if (!isset($filePointers[$filename][$mode]) ||\r
- !is_resource($filePointers[$filename][$mode])) {\r
-\r
- // check if we can open the file in the desired mode\r
- switch ($mode)\r
- {\r
- case FILE_MODE_READ:\r
- if (!preg_match('/^.+(?<!file):\/\//i', $filename) &&\r
- !file_exists($filename)) {\r
- return PEAR::raiseError("File does not exist: $filename");\r
- }\r
- break;\r
-\r
- case FILE_MODE_APPEND:\r
- case FILE_MODE_WRITE:\r
- if (file_exists($filename)) {\r
- if (!is_writable($filename)) {\r
- return PEAR::raiseError("File is not writable: $filename");\r
- }\r
- } elseif (!is_writable($dir = dirname($filename))) {\r
- return PEAR::raiseError("Cannot create file in directory: $dir");\r
- }\r
- break;\r
-\r
- default:\r
- return PEAR::raiseError("Invalid access mode: $mode");\r
- }\r
-\r
- // open file\r
- $filePointers[$filename][$mode] = @fopen($filename, $mode);\r
- if (!is_resource($filePointers[$filename][$mode])) {\r
- return PEAR::raiseError('Failed to open file: ' . $filename);\r
- }\r
- }\r
-\r
- // lock file\r
- if ($lock) {\r
- $lock = $mode == FILE_MODE_READ ? FILE_LOCK_SHARED : FILE_LOCK_EXCLUSIVE;\r
- $locks = &PEAR::getStaticProperty('File', 'locks');\r
- if (@flock($filePointers[$filename][$mode], $lock)) {\r
- $locks[] = &$filePointers[$filename][$mode];\r
- } elseif (FILE_LOCKS_BLOCK) {\r
- return PEAR::raiseError("File already locked: $filename");\r
- } else {\r
- return PEAR::raiseError("Could not lock file: $filename");\r
- }\r
- }\r
-\r
- return $filePointers[$filename][$mode];\r
- }\r
-\r
- /**\r
- * Reads an entire file and returns it.\r
- * Uses file_get_contents if available.\r
- *\r
- * @access public\r
- * @param string $filename Name of file to read from\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error if an error has occured or a string with the contents of the the file\r
- */\r
- function readAll($filename, $lock = false)\r
- {\r
- if (false === $file = @file_get_contents($filename)) {\r
- return PEAR::raiseError("Cannot read file: $filename");\r
- }\r
- return $file;\r
- }\r
-\r
- /**\r
- * Returns a specified number of bytes of a file.\r
- * Defaults to FILE_DEFAULT_READSIZE. If $size is 0, all file will be read.\r
- *\r
- * @access public\r
- * @param string $filename Name of file to read from\r
- * @param integer $size Bytes to read\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error on error or a string which contains the data read\r
- * Will also return false upon EOF\r
- */\r
- function read($filename, $size = FILE_DEFAULT_READSIZE, $lock = false)\r
- {\r
- static $filePointers;\r
-\r
- if ($size == 0) {\r
- return File::readAll($filename, $lock);\r
- }\r
-\r
- if (!isset($filePointers[$filename]) ||\r
- !is_resource($filePointers[$filename])) {\r
- $fp = File::_getFilePointer($filename, FILE_MODE_READ, $lock);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- $filePointers[$filename] = $fp;\r
- } else {\r
- $fp = $filePointers[$filename];\r
- }\r
-\r
- return !feof($fp) ? fread($fp, $size) : false;\r
- }\r
-\r
- /**\r
- * Writes the given data to the given filename.\r
- * Defaults to no lock, append mode.\r
- *\r
- * @access public\r
- * @param string $filename Name of file to write to\r
- * @param string $data Data to write to file\r
- * @param string $mode Mode to open file in\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error on error or number of bytes written to file.\r
- */\r
- function write($filename, $data, $mode = FILE_MODE_APPEND, $lock = false)\r
- {\r
- $fp = File::_getFilePointer($filename, $mode, $lock);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- if (false === $bytes = @fwrite($fp, $data, strlen($data))) {\r
- return PEAR::raiseError("Cannot write data: '$data' to file: '$filename'");\r
- }\r
-\r
- return $bytes;\r
- }\r
-\r
- /**\r
- * Reads and returns a single character from given filename\r
- *\r
- * @access public\r
- * @param string $filename Name of file to read from\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error on error or one character of the specified file\r
- */\r
- function readChar($filename, $lock = false)\r
- {\r
- return File::read($filename, 1, $lock);\r
- }\r
-\r
- /**\r
- * Writes a single character to a file\r
- *\r
- * @access public\r
- * @param string $filename Name of file to write to\r
- * @param string $char Character to write\r
- * @param string $mode Mode to use when writing\r
- * @param mixed $lock Type of lock to use\r
- * @return mixed PEAR_Error on error, or 1 on success\r
- */\r
- function writeChar($filename, $char, $mode = FILE_MODE_APPEND, $lock = false)\r
- {\r
- $fp = File::_getFilePointer($filename, $mode, $lock);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- if (false === @fwrite($fp, $char, 1)) {\r
- return PEAR::raiseError("Cannot write data: '$data' to file: '$filename'");\r
- }\r
-\r
- return 1;\r
- }\r
-\r
- /**\r
- * Returns a line of the file (without trailing CRLF).\r
- * Maximum read line length is FILE_MAX_LINE_READSIZE.\r
- *\r
- * @access public\r
- * @param string $filename Name of file to read from\r
- * @param boolean $lock Whether file should be locked\r
- * @return mixed PEAR_Error on error or a string containing the line read from file\r
- */\r
- function readLine($filename, $lock = false)\r
- {\r
- static $filePointers; // Used to prevent unnecessary calls to _getFilePointer()\r
-\r
- if (!isset($filePointers[$filename]) ||\r
- !is_resource($filePointers[$filename])) {\r
- $fp = File::_getFilePointer($filename, FILE_MODE_READ, $lock);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- $filePointers[$filename] = $fp;\r
- } else {\r
- $fp = $filePointers[$filename];\r
- }\r
-\r
- if (feof($fp)) {\r
- return false;\r
- }\r
-\r
- return rtrim(fgets($fp, FILE_MAX_LINE_READSIZE), "\r\n");\r
- }\r
-\r
- /**\r
- * Writes a single line, appending a LF (by default)\r
- *\r
- * @access public\r
- * @param string $filename Name of file to write to\r
- * @param string $line Line of data to be written to file\r
- * @param string $mode Write mode, can be either FILE_MODE_WRITE or FILE_MODE_APPEND\r
- * @param string $crlf The CRLF your system is using. UNIX = \n Windows = \r\n Mac = \r\r
- * @param mixed $lock Whether to lock the file\r
- * @return mixed PEAR_Error on error or number of bytes written to file (including appended crlf)\r
- */\r
- function writeLine($filename, $line, $mode = FILE_MODE_APPEND, $crlf = "\n", $lock = false)\r
- {\r
- $fp = File::_getFilePointer($filename, $mode, $lock);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- if (false === $bytes = fwrite($fp, $line . $crlf)) {\r
- return PEAR::raiseError("Cannot write data: '$data' to file: '$file'");\r
- }\r
-\r
- return $bytes;\r
- }\r
-\r
- /**\r
- * This rewinds a filepointer to the start of a file\r
- *\r
- * @access public\r
- * @param string $filename The filename\r
- * @param string $mode Mode the file was opened in\r
- * @return mixed PEAR Error on error, true on success\r
- */\r
- function rewind($filename, $mode)\r
- {\r
- $fp = File::_getFilePointer($filename, $mode);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- if (!@rewind($fp)) {\r
- return PEAR::raiseError("Cannot rewind file: $filename");\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Closes all open file pointers\r
- *\r
- * @access public\r
- * @return void\r
- */\r
- function closeAll()\r
- {\r
- $locks = &PEAR::getStaticProperty('File', 'locks');\r
- $filePointers = &PEAR::getStaticProperty('File', 'filePointers');\r
-\r
- // unlock files\r
- for ($i = 0, $c = count($locks); $i < $c; $i++) {\r
- is_resource($locks[$i]) and @flock($locks[$i], LOCK_UN);\r
- }\r
-\r
- // close files\r
- if (!empty($filePointers)) {\r
- foreach ($filePointers as $fname => $modes) {\r
- foreach (array_keys($modes) as $mode) {\r
- if (is_resource($filePointers[$fname][$mode])) {\r
- @fclose($filePointers[$fname][$mode]);\r
- }\r
- unset($filePointers[$fname][$mode]);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * This closes an open file pointer\r
- *\r
- * @access public\r
- * @param string $filename The filename that was opened\r
- * @param string $mode Mode the file was opened in\r
- * @return mixed PEAR Error on error, true otherwise\r
- */\r
- function close($filename, $mode)\r
- {\r
- $filePointers = &PEAR::getStaticProperty('File', 'filePointers');\r
-\r
- if (OS_WINDOWS) {\r
- $filename = strToLower($filename);\r
- }\r
-\r
- if (!isset($filePointers[$filename][$mode])) {\r
- return true;\r
- }\r
-\r
- $fp = $filePointers[$filename][$mode];\r
- unset($filePointers[$filename][$mode]);\r
-\r
- if (is_resource($fp)) {\r
- // unlock file\r
- @flock($fp, LOCK_UN);\r
- // close file\r
- if (!@fclose($fp)) {\r
- return PEAR::raiseError("Cannot close file: $filename");\r
- }\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * This unlocks a locked file pointer.\r
- *\r
- * @access public\r
- * @param string $filename The filename that was opened\r
- * @param string $mode Mode the file was opened in\r
- * @return mixed PEAR Error on error, true otherwise\r
- */\r
- function unlock($filename, $mode)\r
- {\r
- $fp = File::_getFilePointer($filename, $mode);\r
- if (PEAR::isError($fp)) {\r
- return $fp;\r
- }\r
-\r
- if (!@flock($fp, LOCK_UN)) {\r
- return PEAR::raiseError("Cacnnot unlock file: $filename");\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * @deprecated\r
- */\r
- function stripTrailingSeparators($path, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- if ($path === $separator) {\r
- return $path;\r
- }\r
- return rtrim($path, $separator);\r
- }\r
-\r
- /**\r
- * @deprecated\r
- */\r
- function stripLeadingSeparators($path, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- if ($path === $separator) {\r
- return $path;\r
- }\r
- return ltrim($path, $separator);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::buildPath() instead.\r
- */\r
- function buildPath($parts, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::buildPath($parts, $separator);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::skipRoot() instead.\r
- */\r
- function skipRoot($path)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::skipRoot($path);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::tmpDir() instead.\r
- */\r
- function getTempDir()\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::tmpDir();\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::tmpFile() instead.\r
- */\r
- function getTempFile($dirname = null)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::tmpFile($dirname);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::isAbsolute() instead.\r
- */\r
- function isAbsolute($path)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::isAbsolute($path);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::relativePath() instead.\r
- */\r
- function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::relativePath($path, $root, $separator);\r
- }\r
-\r
- /**\r
- * @deprecated Use File_Util::realpath() instead.\r
- */\r
- function realpath($path, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- require_once 'File/Util.php';\r
- return File_Util::realpath($path, $separator);\r
- }\r
-}\r
-\r
-PEAR::registerShutdownFunc(array('File', '_File'));\r
-\r
-?>\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * File
+ *
+ * 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 File
+ * @package File
+ * @author Richard Heyes <richard@php.net>
+ * @author Tal Peer <tal@php.net>
+ * @author Michael Wallner <mike@php.net>
+ * @copyright 2002-2005 The Authors
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version CVS: $Id: File.php,v 1.38 2007/03/24 16:38:56 dufuz Exp $
+ * @link http://pear.php.net/package/File
+ */
+
+/**
+ * Requires PEAR
+ */
+require_once 'PEAR.php';
+
+/**
+ * The default number of bytes for reading
+ */
+if (!defined('FILE_DEFAULT_READSIZE')) {
+ define('FILE_DEFAULT_READSIZE', 1024, true);
+}
+
+/**
+ * The maximum number of bytes for reading lines
+ */
+if (!defined('FILE_MAX_LINE_READSIZE')) {
+ define('FILE_MAX_LINE_READSIZE', 40960, true);
+}
+
+/**
+ * Whether file locks should block
+ */
+if (!defined('FILE_LOCKS_BLOCK')) {
+ define('FILE_LOCKS_BLOCK', true, true);
+}
+
+/**
+ * Mode to use for reading from files
+ */
+define('FILE_MODE_READ', 'rb', true);
+
+/**
+ * Mode to use for truncating files, then writing
+ */
+define('FILE_MODE_WRITE', 'wb', true);
+
+/**
+ * Mode to use for appending to files
+ */
+define('FILE_MODE_APPEND', 'ab', true);
+
+/**
+ * Use this when a shared (read) lock is required
+ */
+define('FILE_LOCK_SHARED', LOCK_SH | (FILE_LOCKS_BLOCK ? 0 : LOCK_NB), true);
+
+/**
+ * Use this when an exclusive (write) lock is required
+ */
+define('FILE_LOCK_EXCLUSIVE', LOCK_EX | (FILE_LOCKS_BLOCK ? 0 : LOCK_NB), true);
+
+/**
+ * Class for handling files
+ *
+ * A class with common functions for writing,
+ * reading and handling files and directories
+ *
+ * @author Richard Heyes <richard@php.net>
+ * @author Tal Peer <tal@php.net>
+ * @author Michael Wallner <mike@php.net>
+ * @access public
+ * @package File
+ *
+ * @static
+ */
+class File extends PEAR
+{
+ /**
+ * Destructor
+ *
+ * Unlocks any locked file pointers and closes all filepointers
+ *
+ * @access private
+ */
+ function _File()
+ {
+ File::closeAll();
+ }
+
+ /**
+ * Handles file pointers. If a file pointer needs to be opened,
+ * it will be. If it already exists (based on filename and mode)
+ * then the existing one will be returned.
+ *
+ * @access private
+ * @param string $filename Filename to be used
+ * @param string $mode Mode to open the file in
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error on error or file pointer resource on success
+ */
+ function _getFilePointer($filename, $mode, $lock = false)
+ {
+ $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
+
+ // Win32 is case-insensitive
+ if (OS_WINDOWS) {
+ $filename = strtolower($filename);
+ }
+
+ // check if file pointer already exists
+ if (!isset($filePointers[$filename][$mode]) ||
+ !is_resource($filePointers[$filename][$mode])) {
+
+ // check if we can open the file in the desired mode
+ switch ($mode)
+ {
+ case FILE_MODE_READ:
+ if (!preg_match('/^.+(?<!file):\/\//i', $filename) &&
+ !file_exists($filename)) {
+ return PEAR::raiseError("File does not exist: $filename");
+ }
+ break;
+
+ case FILE_MODE_APPEND:
+ case FILE_MODE_WRITE:
+ if (file_exists($filename)) {
+ if (!is_writable($filename)) {
+ return PEAR::raiseError("File is not writable: $filename");
+ }
+ } elseif (!is_writable($dir = dirname($filename))) {
+ return PEAR::raiseError("Cannot create file in directory: $dir");
+ }
+ break;
+
+ default:
+ return PEAR::raiseError("Invalid access mode: $mode");
+ }
+
+ // open file
+ $filePointers[$filename][$mode] = @fopen($filename, $mode);
+ if (!is_resource($filePointers[$filename][$mode])) {
+ return PEAR::raiseError('Failed to open file: ' . $filename);
+ }
+ }
+
+ // lock file
+ if ($lock) {
+ $lock = $mode == FILE_MODE_READ ? FILE_LOCK_SHARED : FILE_LOCK_EXCLUSIVE;
+ $locks = &PEAR::getStaticProperty('File', 'locks');
+ if (@flock($filePointers[$filename][$mode], $lock)) {
+ $locks[] = &$filePointers[$filename][$mode];
+ } elseif (FILE_LOCKS_BLOCK) {
+ return PEAR::raiseError("File already locked: $filename");
+ } else {
+ return PEAR::raiseError("Could not lock file: $filename");
+ }
+ }
+
+ return $filePointers[$filename][$mode];
+ }
+
+ /**
+ * Reads an entire file and returns it.
+ * Uses file_get_contents if available.
+ *
+ * @access public
+ * @param string $filename Name of file to read from
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error if an error has occured or a string with the contents of the the file
+ */
+ function readAll($filename, $lock = false)
+ {
+ if (false === $file = @file_get_contents($filename)) {
+ return PEAR::raiseError("Cannot read file: $filename");
+ }
+ return $file;
+ }
+
+ /**
+ * Returns a specified number of bytes of a file.
+ * Defaults to FILE_DEFAULT_READSIZE. If $size is 0, all file will be read.
+ *
+ * @access public
+ * @param string $filename Name of file to read from
+ * @param integer $size Bytes to read
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error on error or a string which contains the data read
+ * Will also return false upon EOF
+ */
+ function read($filename, $size = FILE_DEFAULT_READSIZE, $lock = false)
+ {
+ static $filePointers;
+
+ if ($size == 0) {
+ return File::readAll($filename, $lock);
+ }
+
+ if (!isset($filePointers[$filename]) ||
+ !is_resource($filePointers[$filename])) {
+ $fp = File::_getFilePointer($filename, FILE_MODE_READ, $lock);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ $filePointers[$filename] = $fp;
+ } else {
+ $fp = $filePointers[$filename];
+ }
+
+ return !feof($fp) ? fread($fp, $size) : false;
+ }
+
+ /**
+ * Writes the given data to the given filename.
+ * Defaults to no lock, append mode.
+ *
+ * @access public
+ * @param string $filename Name of file to write to
+ * @param string $data Data to write to file
+ * @param string $mode Mode to open file in
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error on error or number of bytes written to file.
+ */
+ function write($filename, $data, $mode = FILE_MODE_APPEND, $lock = false)
+ {
+ $fp = File::_getFilePointer($filename, $mode, $lock);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ if (false === $bytes = @fwrite($fp, $data, strlen($data))) {
+ return PEAR::raiseError("Cannot write data: '$data' to file: '$filename'");
+ }
+
+ return $bytes;
+ }
+
+ /**
+ * Reads and returns a single character from given filename
+ *
+ * @access public
+ * @param string $filename Name of file to read from
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error on error or one character of the specified file
+ */
+ function readChar($filename, $lock = false)
+ {
+ return File::read($filename, 1, $lock);
+ }
+
+ /**
+ * Writes a single character to a file
+ *
+ * @access public
+ * @param string $filename Name of file to write to
+ * @param string $char Character to write
+ * @param string $mode Mode to use when writing
+ * @param mixed $lock Type of lock to use
+ * @return mixed PEAR_Error on error, or 1 on success
+ */
+ function writeChar($filename, $char, $mode = FILE_MODE_APPEND, $lock = false)
+ {
+ $fp = File::_getFilePointer($filename, $mode, $lock);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ if (false === @fwrite($fp, $char, 1)) {
+ return PEAR::raiseError("Cannot write data: '$data' to file: '$filename'");
+ }
+
+ return 1;
+ }
+
+ /**
+ * Returns a line of the file (without trailing CRLF).
+ * Maximum read line length is FILE_MAX_LINE_READSIZE.
+ *
+ * @access public
+ * @param string $filename Name of file to read from
+ * @param boolean $lock Whether file should be locked
+ * @return mixed PEAR_Error on error or a string containing the line read from file
+ */
+ function readLine($filename, $lock = false)
+ {
+ static $filePointers; // Used to prevent unnecessary calls to _getFilePointer()
+
+ if (!isset($filePointers[$filename]) ||
+ !is_resource($filePointers[$filename])) {
+ $fp = File::_getFilePointer($filename, FILE_MODE_READ, $lock);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ $filePointers[$filename] = $fp;
+ } else {
+ $fp = $filePointers[$filename];
+ }
+
+ if (feof($fp)) {
+ return false;
+ }
+
+ return rtrim(fgets($fp, FILE_MAX_LINE_READSIZE), "\r\n");
+ }
+
+ /**
+ * Writes a single line, appending a LF (by default)
+ *
+ * @access public
+ * @param string $filename Name of file to write to
+ * @param string $line Line of data to be written to file
+ * @param string $mode Write mode, can be either FILE_MODE_WRITE or FILE_MODE_APPEND
+ * @param string $crlf The CRLF your system is using. UNIX = \n Windows = \r\n Mac = \r
+ * @param mixed $lock Whether to lock the file
+ * @return mixed PEAR_Error on error or number of bytes written to file (including appended crlf)
+ */
+ function writeLine($filename, $line, $mode = FILE_MODE_APPEND, $crlf = "\n", $lock = false)
+ {
+ $fp = File::_getFilePointer($filename, $mode, $lock);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ if (false === $bytes = fwrite($fp, $line . $crlf)) {
+ return PEAR::raiseError("Cannot write data: '$data' to file: '$file'");
+ }
+
+ return $bytes;
+ }
+
+ /**
+ * This rewinds a filepointer to the start of a file
+ *
+ * @access public
+ * @param string $filename The filename
+ * @param string $mode Mode the file was opened in
+ * @return mixed PEAR Error on error, true on success
+ */
+ function rewind($filename, $mode)
+ {
+ $fp = File::_getFilePointer($filename, $mode);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ if (!@rewind($fp)) {
+ return PEAR::raiseError("Cannot rewind file: $filename");
+ }
+
+ return true;
+ }
+
+ /**
+ * Closes all open file pointers
+ *
+ * @access public
+ * @return void
+ */
+ function closeAll()
+ {
+ $locks = &PEAR::getStaticProperty('File', 'locks');
+ $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
+
+ // unlock files
+ for ($i = 0, $c = count($locks); $i < $c; $i++) {
+ is_resource($locks[$i]) and @flock($locks[$i], LOCK_UN);
+ }
+
+ // close files
+ if (!empty($filePointers)) {
+ foreach ($filePointers as $fname => $modes) {
+ foreach (array_keys($modes) as $mode) {
+ if (is_resource($filePointers[$fname][$mode])) {
+ @fclose($filePointers[$fname][$mode]);
+ }
+ unset($filePointers[$fname][$mode]);
+ }
+ }
+ }
+ }
+
+ /**
+ * This closes an open file pointer
+ *
+ * @access public
+ * @param string $filename The filename that was opened
+ * @param string $mode Mode the file was opened in
+ * @return mixed PEAR Error on error, true otherwise
+ */
+ function close($filename, $mode)
+ {
+ $filePointers = &PEAR::getStaticProperty('File', 'filePointers');
+
+ if (OS_WINDOWS) {
+ $filename = strToLower($filename);
+ }
+
+ if (!isset($filePointers[$filename][$mode])) {
+ return true;
+ }
+
+ $fp = $filePointers[$filename][$mode];
+ unset($filePointers[$filename][$mode]);
+
+ if (is_resource($fp)) {
+ // unlock file
+ @flock($fp, LOCK_UN);
+ // close file
+ if (!@fclose($fp)) {
+ return PEAR::raiseError("Cannot close file: $filename");
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * This unlocks a locked file pointer.
+ *
+ * @access public
+ * @param string $filename The filename that was opened
+ * @param string $mode Mode the file was opened in
+ * @return mixed PEAR Error on error, true otherwise
+ */
+ function unlock($filename, $mode)
+ {
+ $fp = File::_getFilePointer($filename, $mode);
+ if (PEAR::isError($fp)) {
+ return $fp;
+ }
+
+ if (!@flock($fp, LOCK_UN)) {
+ return PEAR::raiseError("Cacnnot unlock file: $filename");
+ }
+
+ return true;
+ }
+
+ /**
+ * @deprecated
+ */
+ function stripTrailingSeparators($path, $separator = DIRECTORY_SEPARATOR)
+ {
+ if ($path === $separator) {
+ return $path;
+ }
+ return rtrim($path, $separator);
+ }
+
+ /**
+ * @deprecated
+ */
+ function stripLeadingSeparators($path, $separator = DIRECTORY_SEPARATOR)
+ {
+ if ($path === $separator) {
+ return $path;
+ }
+ return ltrim($path, $separator);
+ }
+
+ /**
+ * @deprecated Use File_Util::buildPath() instead.
+ */
+ function buildPath($parts, $separator = DIRECTORY_SEPARATOR)
+ {
+ require_once 'File/Util.php';
+ return File_Util::buildPath($parts, $separator);
+ }
+
+ /**
+ * @deprecated Use File_Util::skipRoot() instead.
+ */
+ function skipRoot($path)
+ {
+ require_once 'File/Util.php';
+ return File_Util::skipRoot($path);
+ }
+
+ /**
+ * @deprecated Use File_Util::tmpDir() instead.
+ */
+ function getTempDir()
+ {
+ require_once 'File/Util.php';
+ return File_Util::tmpDir();
+ }
+
+ /**
+ * @deprecated Use File_Util::tmpFile() instead.
+ */
+ function getTempFile($dirname = null)
+ {
+ require_once 'File/Util.php';
+ return File_Util::tmpFile($dirname);
+ }
+
+ /**
+ * @deprecated Use File_Util::isAbsolute() instead.
+ */
+ function isAbsolute($path)
+ {
+ require_once 'File/Util.php';
+ return File_Util::isAbsolute($path);
+ }
+
+ /**
+ * @deprecated Use File_Util::relativePath() instead.
+ */
+ function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
+ {
+ require_once 'File/Util.php';
+ return File_Util::relativePath($path, $root, $separator);
+ }
+
+ /**
+ * @deprecated Use File_Util::realpath() instead.
+ */
+ function realpath($path, $separator = DIRECTORY_SEPARATOR)
+ {
+ require_once 'File/Util.php';
+ return File_Util::realpath($path, $separator);
+ }
+}
+
+PEAR::registerShutdownFunc(array('File', '_File'));
+
+?>
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * File::CSV\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category File\r
- * @package File\r
- * @author Tomas V.V.Cox <cox@idecnet.com>\r
- * @author Helgi Þormar <dufuz@php.net>\r
- * @copyright 2004-2005 The Authors\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: CSV.php,v 1.41 2007/05/20 12:25:14 dufuz Exp $\r
- * @link http://pear.php.net/package/File\r
- */\r
-\r
-require_once 'PEAR.php';\r
-require_once 'File.php';\r
-\r
-/**\r
-* File class for handling CSV files (Comma Separated Values), a common format\r
-* for exchanging data.\r
-*\r
-* TODO:\r
-* - Usage example and Doc\r
-* - Use getPointer() in discoverFormat\r
-* - Add a line counter for being able to output better error reports\r
-* - Store the last error in GLOBALS and add File_CSV::getLastError()\r
-*\r
-* Wish:\r
-* - Other methods like readAll(), writeAll(), numFields(), numRows()\r
-* - Try to detect if a CSV has header or not in discoverFormat() (not possible with CSV)\r
-*\r
-* Known Bugs:\r
-* (they has been analyzed but for the moment the impact in the speed for\r
-* properly handle this uncommon cases is too high and won't be supported)\r
-* - A field which is composed only by a single quoted separator (ie -> ;";";)\r
-* is not handled properly\r
-* - When there is exactly one field minus than the expected number and there\r
-* is a field with a separator inside, the parser will throw the "wrong count" error\r
-*\r
-* Info about CSV and links to other sources\r
-* http://www.shaftek.org/publications/drafts/mime-csv/draft-shafranovich-mime-csv-00.html#appendix\r
-*\r
-* @author Tomas V.V.Cox <cox@idecnet.com>\r
-* @author Helgi Þormar <dufuz@php.net>\r
-* @package File\r
-*/\r
-class File_CSV\r
-{\r
- /**\r
- * This raiseError method works in a different way. It will always return\r
- * false (an error occurred) but it will call PEAR::raiseError() before\r
- * it. If no default PEAR global handler is set, will trigger an error.\r
- *\r
- * @param string $error The error message\r
- * @return bool always false\r
- */\r
- function raiseError($error)\r
- {\r
- // If a default PEAR Error handler is not set trigger the error\r
- // XXX Add a PEAR::isSetHandler() method?\r
- if ($GLOBALS['_PEAR_default_error_mode'] == PEAR_ERROR_RETURN) {\r
- PEAR::raiseError($error, null, PEAR_ERROR_TRIGGER, E_USER_WARNING);\r
- } else {\r
- PEAR::raiseError($error);\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Checks the configuration given by the user\r
- *\r
- * @access private\r
- * @param string &$error The error will be written here if any\r
- * @param array &$conf The configuration assoc array\r
- * @return string error Returns a error message\r
- */\r
- function _conf(&$error, &$conf)\r
- {\r
- // check conf\r
- if (!is_array($conf)) {\r
- return $error = 'Invalid configuration';\r
- }\r
-\r
- if (!isset($conf['fields']) || !(int)$conf['fields']) {\r
- return $error = 'The number of fields must be numeric (the "fields" key)';\r
- }\r
-\r
- if (isset($conf['sep'])) {\r
- if (strlen($conf['sep']) != 1) {\r
- return $error = 'Separator can only be one char';\r
- }\r
- } elseif ($conf['fields'] > 1) {\r
- return $error = 'Missing separator (the "sep" key)';\r
- }\r
-\r
- if (isset($conf['quote'])) {\r
- if (strlen($conf['quote']) != 1) {\r
- return $error = 'The quote char must be one char (the "quote" key)';\r
- }\r
- } else {\r
- $conf['quote'] = null;\r
- }\r
-\r
- if (!isset($conf['crlf'])) {\r
- $conf['crlf'] = "\n";\r
- }\r
-\r
- if (!isset($conf['eol2unix'])) {\r
- $conf['eol2unix'] = true;\r
- }\r
- }\r
-\r
- /**\r
- * Return or create the file descriptor associated with a file\r
- *\r
- * @param string $file The name of the file\r
- * @param array &$conf The configuration\r
- * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)\r
- * @param boolean $reset if passed as true and resource for the file exists\r
- * than the file pointer will be moved to the beginning\r
- *\r
- * @return mixed A file resource or false\r
- */\r
- function getPointer($file, &$conf, $mode = FILE_MODE_READ, $reset = false)\r
- {\r
- static $resources = array();\r
- static $config;\r
- if (isset($resources[$file][$mode])) {\r
- $conf = $config;\r
- if ($reset) {\r
- fseek($resources[$file][$mode], 0);\r
- }\r
- return $resources[$file][$mode];\r
- }\r
- File_CSV::_conf($error, $conf);\r
- if ($error) {\r
- return File_CSV::raiseError($error);\r
- }\r
- $config = $conf;\r
- PEAR::pushErrorHandling(PEAR_ERROR_RETURN);\r
- $fp = File::_getFilePointer($file, $mode);\r
- PEAR::popErrorHandling();\r
- if (PEAR::isError($fp)) {\r
- return File_CSV::raiseError($fp);\r
- }\r
- $resources[$file][$mode] = $fp;\r
- return $fp;\r
- }\r
-\r
- /**\r
- * Unquote data\r
- *\r
- * @param string $field The data to unquote\r
- * @param string $quote The quote char\r
- * @return string the unquoted data\r
- */\r
- function unquote($field, $quote)\r
- {\r
- // Trim first the string.\r
- $field = trim($field);\r
- $quote = trim($quote);\r
-\r
- // Incase null fields (form: ;;)\r
- if (!strlen($field)) {\r
- return $field;\r
- }\r
-\r
- // excel compat\r
- if ($field[0] == '=' && $field[1] == '"') {\r
- $field = str_replace('="', '"', $field);\r
- }\r
-\r
- $field_len = strlen($field);\r
- if ($quote && $field[0] == $quote && $field[$field_len - 1] == $quote) {\r
- // Get rid of escaping quotes\r
- $new = $prev = $c = '';\r
- for ($i = 0; $i < $field_len; ++$i) {\r
- $prev = $c;\r
- $c = $field[$i];\r
- // Deal with escaping quotes\r
- if ($c == $quote && $prev == $quote) {\r
- $c = '';\r
- }\r
-\r
- $new .= $c;\r
- }\r
- $field = substr($new, 1, -1);\r
- }\r
-\r
- return $field;\r
- }\r
-\r
- /**\r
- * Reads a row of data as an array from a CSV file. It's able to\r
- * read memo fields with multiline data.\r
- *\r
- * @param string $file The filename where to write the data\r
- * @param array &$conf The configuration of the dest CSV\r
- *\r
- * @return mixed Array with the data read or false on error/no more data\r
- */\r
- function readQuoted($file, &$conf)\r
- {\r
- if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_READ)) {\r
- return false;\r
- }\r
-\r
- $buff = $old = $prev = $c = '';\r
- $ret = array();\r
- $i = 1;\r
- $in_quote = false;\r
- $quote = $conf['quote'];\r
- $f = $conf['fields'];\r
- $sep = $conf['sep'];\r
- while (false !== $ch = fgetc($fp)) {\r
- $old = $prev;\r
- $prev = $c;\r
- $c = $ch;\r
-\r
- // Common case\r
- if ($c != $quote && $c != $sep && $c != "\n" && $c != "\r") {\r
- $buff .= $c;\r
- continue;\r
- }\r
-\r
- // Start quote.\r
- if (\r
- $in_quote === false &&\r
- $quote && $c == $quote &&\r
- (\r
- $prev == $sep || $prev == "\n" || $prev === null ||\r
- $prev == "\r" || $prev == '' || $prev == ' '\r
- || $prev == '=' //excel compat\r
- )\r
- ) {\r
- $in_quote = true;\r
- // excel compat, removing the = part but only if we are in a quote\r
- if ($prev == '=') {\r
- $buff{strlen($buff) - 1} = '';\r
- }\r
- }\r
-\r
- if ($in_quote) {\r
-\r
- // When does the quote end, make sure it's not double quoted\r
- if ($c == $sep && $prev == $quote && $old != $quote) {\r
- $in_quote = false;\r
- } elseif ($c == $sep && $buff == $quote.$quote) {\r
- // In case we are dealing with double quote but empty value\r
- $in_quote = false;\r
- } elseif ($c == "\n" || $c == "\r") {\r
- $sub = ($prev == "\r") ? 2 : 1;\r
- $buff_len = strlen($buff);\r
- if (\r
- $buff_len >= $sub &&\r
- $buff[$buff_len - $sub] == $quote\r
- ) {\r
- $in_quote = false;\r
- }\r
- }\r
- }\r
-\r
- if (!$in_quote && ($c == $sep || $c == "\n" || $c == "\r") && $prev != '') {\r
- // More fields than expected\r
- if ($c == $sep && (count($ret) + 1) == $f) {\r
- // Seek the pointer into linebreak character.\r
- while (true) {\r
- $c = fgetc($fp);\r
- if ($c == "\n" || $c == "\r" || $c == '') {\r
- break;\r
- }\r
- }\r
-\r
- // Insert last field value.\r
- $ret[] = File_CSV::unquote($buff, $quote);\r
- return $ret;\r
- }\r
-\r
- // Less fields than expected\r
- if (($c == "\n" || $c == "\r") && $i != $f) {\r
- // Insert last field value.\r
- $ret[] = File_CSV::unquote($buff, $quote);\r
- if (count($ret) == 1 && empty($ret[0])) {\r
- return array();\r
- }\r
-\r
- // Pair the array elements to fields count. - inserting empty values\r
- $ret_count = count($ret);\r
- $sum = ($f - 1) - ($ret_count - 1);\r
- $data = array_merge($ret, array_fill($ret_count, $sum, ''));\r
- return $data;\r
- }\r
-\r
- if ($prev == "\r") {\r
- $buff = substr($buff, 0, -1);\r
- }\r
-\r
- // Convert EOL character to Unix EOL (LF).\r
- if ($conf['eol2unix']) {\r
- $buff = preg_replace('/(\r\n|\r)$/', "\n", $buff);\r
- }\r
-\r
- $ret[] = File_CSV::unquote($buff, $quote);\r
- if (count($ret) == $f) {\r
- return $ret;\r
- }\r
- $buff = '';\r
- ++$i;\r
- continue;\r
- }\r
- $buff .= $c;\r
- }\r
-\r
- /* If it's the end of the file and we still have something in buffer\r
- * then we process it since files can have no CL/FR at the end\r
- */\r
- $feof = feof($fp);\r
- if ($feof && !in_array($buff, array("\r", "\n", "\r\n")) && strlen($buff) > 0) {\r
- $ret[] = File_CSV::unquote($buff, $quote);\r
- if (count($ret) == $f) {\r
- return $ret;\r
- }\r
- }\r
-\r
- return !$feof ? $ret : false;\r
- }\r
-\r
- /**\r
- * Reads a "row" from a CSV file and return it as an array\r
- *\r
- * @param string $file The CSV file\r
- * @param array &$conf The configuration of the dest CSV\r
- *\r
- * @return mixed Array or false\r
- */\r
- function read($file, &$conf)\r
- {\r
- static $headers = array();\r
- if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_READ)) {\r
- return false;\r
- }\r
-\r
- // The size is limited to 4K\r
- if (!$line = fgets($fp, 4096)) {\r
- return false;\r
- }\r
-\r
- $fields = $conf['fields'] == 1 ? array($line) : explode($conf['sep'], $line);\r
-\r
- $nl = array("\n", "\r", "\r\n");\r
- if (in_array($fields[count($fields) - 1], $nl)) {\r
- array_pop($fields);\r
- }\r
-\r
- $field_count = count($fields);\r
- $last =& $fields[$field_count - 1];\r
- $len = strlen($last);\r
- if (\r
- $field_count != $conf['fields'] ||\r
- $conf['quote'] &&\r
- (\r
- $len !== 0 && $last[$len - 1] == "\n"\r
- &&\r
- (\r
- ($last[0] == $conf['quote']\r
- && $last[strlen(rtrim($last)) - 1] != $conf['quote'])\r
- ||\r
- // excel support\r
- ($last[0] == '=' && $last[1] == $conf['quote'])\r
- ||\r
- // if the row has spaces before the quote\r
- preg_match('|^\s+'.preg_quote($conf['quote']) .'|Ums', $last, $match)\r
- )\r
- )\r
- // XXX perhaps there is a separator inside a quoted field\r
- //preg_match("|{$conf['quote']}.*{$conf['sep']}.*{$conf['quote']}|U", $line)\r
- ) {\r
- fseek($fp, -1 * strlen($line), SEEK_CUR);\r
- return File_CSV::readQuoted($file, $conf);\r
- } else {\r
- foreach ($fields as $k => $v) {\r
- $fields[$k] = File_CSV::unquote($v, $conf['quote']);\r
- }\r
- }\r
-\r
- if (isset($conf['header']) && empty($headers)) {\r
- // read the first row and assign to $headers\r
- $headers = $fields;\r
- return $headers;\r
- }\r
-\r
- if ($field_count != $conf['fields']) {\r
- File_CSV::raiseError("Read wrong fields number count: '". $field_count .\r
- "' expected ".$conf['fields']);\r
- return true;\r
- }\r
-\r
- if (!empty($headers)) {\r
- $tmp = array();\r
- foreach ($fields as $k => $v) {\r
- $tmp[$headers[$k]] = $v;\r
- }\r
- $fields = $tmp;\r
- }\r
-\r
- return $fields;\r
- }\r
-\r
- /**\r
- * Internal use only, will be removed in the future\r
- *\r
- * @param string $str The string to debug\r
- * @access private\r
- */\r
- function _dbgBuff($str)\r
- {\r
- if (strpos($str, "\r") !== false) {\r
- $str = str_replace("\r", "_r_", $str);\r
- }\r
- if (strpos($str, "\n") !== false) {\r
- $str = str_replace("\n", "_n_", $str);\r
- }\r
- if (strpos($str, "\t") !== false) {\r
- $str = str_replace("\t", "_t_", $str);\r
- }\r
- if ($str === null) {\r
- $str = '_NULL_';\r
- }\r
- if ($str === '') {\r
- $str = 'Empty string';\r
- }\r
- echo "buff: ($str)\n";\r
- }\r
-\r
- /**\r
- * Writes a struc (array) in a file as CSV\r
- *\r
- * @param string $file The filename where to write the data\r
- * @param array $fields Ordered array with the data\r
- * @param array &$conf The configuration of the dest CSV\r
- *\r
- * @return bool True on success false otherwise\r
- */\r
- function write($file, $fields, &$conf)\r
- {\r
- if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_WRITE)) {\r
- return false;\r
- }\r
-\r
- $field_count = count($fields);\r
- if ($field_count != $conf['fields']) {\r
- File_CSV::raiseError("Wrong fields number count: '". $field_count .\r
- "' expected ".$conf['fields']);\r
- return true;\r
- }\r
-\r
- $write = '';\r
- for ($i = 0; $i < $field_count; ++$i) {\r
- // only quote if the field contains a sep\r
- if (!is_numeric($fields[$i]) && $conf['quote']\r
- && isset($conf['sep']) && strpos($fields[$i], $conf['sep'])\r
- ) {\r
- $write .= $conf['quote'] . $fields[$i] . $conf['quote'];\r
- } else {\r
- $write .= $fields[$i];\r
- }\r
-\r
- $write .= ($i < ($field_count - 1)) ? $conf['sep']: $conf['crlf'];\r
- }\r
-\r
- if (!fwrite($fp, $write, strlen($write))) {\r
- return File_CSV::raiseError('Can not write to file');\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Discover the format of a CSV file (the number of fields, the separator\r
- * and if it quote string fields)\r
- *\r
- * @param string the CSV file name\r
- * @param array extra separators that should be checked for.\r
- * @return mixed Assoc array or false\r
- */\r
- function discoverFormat($file, $extraSeps = array())\r
- {\r
- if (!$fp = @fopen($file, 'rb')) {\r
- return File_CSV::raiseError("Could not open file: $file");\r
- }\r
-\r
- // Set auto detect line ending for Mac EOL support\r
- $oldini = ini_get('auto_detect_line_endings');\r
- if ($oldini != '1') {\r
- ini_set('auto_detect_line_endings', '1');\r
- }\r
-\r
- // Take the first 30 lines and store the number of ocurrences\r
- // for each separator in each line\r
- $lines = '';\r
- for ($i = 0; $i < 30 && $line = fgets($fp, 4096); $i++) {\r
- $lines .= $line;\r
- }\r
- fclose($fp);\r
-\r
- if ($oldini != '1') {\r
- ini_set('auto_detect_line_endings', $oldini);\r
- }\r
-\r
- $seps = array("\t", ';', ':', ',');\r
- $seps = array_merge($seps, $extraSeps);\r
- $matches = array();\r
- $quotes = '"\'';\r
- \r
- $lines = str_replace('""', '', $lines);\r
- while ($lines != ($newLines = preg_replace('|((["\'])[^"]*(\2))|', '\2_\2', $lines))){\r
- $lines = $newLines;\r
- }\r
-\r
- $eol = strpos($lines, "\r") ? "\r" : "\n";\r
- $lines = explode($eol, $lines);\r
- foreach ($lines as $line) {\r
- $orgLine = $line;\r
- foreach ($seps as $sep) {\r
- $line = preg_replace("|^[^$quotes$sep]*$sep*([$quotes][^$quotes]*[$quotes])|sm", '_', $orgLine);\r
- // Find all seps that are within qoutes\r
- ///FIXME ... counts legitimit lines as bad ones\r
-\r
- // In case there's a whitespace infront the field\r
- $regex = '|\s*?';\r
- // Match the first quote (optional), also optionally match = since it's excel stuff\r
- $regex.= "(?:\=?[$quotes])";\r
- $regex.= '(.*';\r
- // Don't match a sep if we are inside a quote\r
- // also don't accept the sep if it has a quote on the either side\r
- ///FIXME has to be possible if we are inside a quote! (tests fail because of this)\r
- $regex.= "(?:[^$quotes])$sep(?:[^$quotes])";\r
- $regex.= '.*)';\r
- // Close quote (if it's present) and the sep (optional, could be end of line)\r
- $regex.= "(?:[$quotes](?:$sep?))|Ums";\r
- preg_match_all($regex, $line, $match);\r
- // Finding all seps, within quotes or not\r
- $sep_count = substr_count($line, $sep);\r
- // Real count\r
- $matches[$sep][] = $sep_count - count($match[0]);\r
- }\r
- }\r
-\r
- $final = array();\r
- // Group the results by amount of equal ocurrences\r
- foreach ($matches as $sep => $res) {\r
- $times = array();\r
- $times[0] = 0;\r
- foreach ($res as $k => $num) {\r
- if ($num > 0) {\r
- $times[$num] = (isset($times[$num])) ? $times[$num] + 1 : 1;\r
- }\r
- }\r
- arsort($times);\r
-\r
- // Use max fields count.\r
- $fields[$sep] = max(array_flip($times));\r
- $amount[$sep] = $times[key($times)];\r
- }\r
-\r
- arsort($amount);\r
- $sep = key($amount);\r
-\r
- $conf['fields'] = $fields[$sep] + 1;\r
- $conf['sep'] = $sep;\r
-\r
- // Test if there are fields with quotes around in the first 30 lines\r
- $quote = null;\r
-\r
- $string = implode('', $lines);\r
- foreach (array('"', '\'') as $q) {\r
- if (preg_match_all("|$sep(?:\s*?)(\=?[$q]).*([$q])$sep|Us", $string, $match)) {\r
- if ($match[1][0] == $match[2][0]) {\r
- $quote = $match[1][0];\r
- break;\r
- }\r
- }\r
-\r
- if (\r
- preg_match_all("|^(\=?[$q]).*([$q])$sep{0,1}|Ums", $string, $match)\r
- || preg_match_all("|(\=?[$q]).*([$q])$sep\s$|Ums", $string, $match)\r
- ) {\r
- if ($match[1][0] == $match[2][0]) {\r
- $quote = $match[1][0];\r
- break;\r
- }\r
- }\r
- }\r
-\r
- $conf['quote'] = $quote;\r
- return $conf;\r
- }\r
-\r
- /**\r
- * Front to call getPointer and moving the resource to the\r
- * beginning of the file\r
- * Reset it if you like.\r
- *\r
- * @param string $file The name of the file\r
- * @param array &$conf The configuration\r
- * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)\r
- *\r
- * @return boolean true on success false on failure\r
- */\r
- function resetPointer($file, &$conf, $mode)\r
- {\r
- if (!File_CSV::getPointer($file, $conf, $mode, true)) {\r
- return false;\r
- }\r
-\r
- return true;\r
- }\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * File::CSV
+ *
+ * PHP versions 4 and 5
+ *
+ * Copyright (c) 2002-2008,
+ * Tomas V.V.Cox <cox@idecnet.com>,
+ * Helgi Þormar Þorbjörnsson <helgi@php.net>
+ * 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.
+ *
+ * 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 File
+ * @package File
+ * @author Tomas V.V.Cox <cox@idecnet.com>
+ * @author Helgi Þormar Þorbjörnsson <helgi@php.net>
+ * @copyright 2004-2011 The Authors
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: CSV.php 309245 2011-03-15 02:02:41Z dufuz $
+ * @link http://pear.php.net/package/File
+ */
+
+require_once 'PEAR.php';
+require_once 'File.php';
+
+/**
+ * File class for handling CSV files (Comma Separated Values), a common format
+ * for exchanging data.
+ *
+ * TODO:
+ * - Usage example and Doc
+ * - Use getPointer() in discoverFormat
+ * - Add a line counter for being able to output better error reports
+ * - Store the last error in GLOBALS and add File_CSV::getLastError()
+ *
+ * Wish:
+ * - Other methods like readAll(), writeAll(), numFields(), numRows()
+ * - Try to detect if a CSV has header or not in discoverFormat() (not possible with CSV)
+ *
+ * Known Bugs:
+ * (they has been analyzed but for the moment the impact in the speed for
+ * properly handle this uncommon cases is too high and won't be supported)
+ * - A field which is composed only by a single quoted separator (ie -> ;";";)
+ * is not handled properly
+ * - When there is exactly one field minus than the expected number and there
+ * is a field with a separator inside, the parser will throw the "wrong count" error
+ *
+ * Info about CSV and links to other sources
+ * http://rfc.net/rfc4180.html
+ *
+ * @author Tomas V.V.Cox <cox@idecnet.com>
+ * @author Helgi Þormar Þorbjörnsson <helgi@php.net>
+ * @package File
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ */
+class File_CSV
+{
+ /**
+ * This raiseError method works in a different way. It will always return
+ * false (an error occurred) but it will call PEAR::raiseError() before
+ * it. If no default PEAR global handler is set, will trigger an error.
+ *
+ * @param string $error The error message
+ * @return bool always false
+ */
+ function raiseError($error)
+ {
+ // If a default PEAR Error handler is not set trigger the error
+ // XXX Add a PEAR::isSetHandler() method?
+ if ($GLOBALS['_PEAR_default_error_mode'] == PEAR_ERROR_RETURN) {
+ PEAR::raiseError($error, null, PEAR_ERROR_TRIGGER, E_USER_WARNING);
+ } else {
+ PEAR::raiseError($error);
+ }
+ return false;
+ }
+
+ /**
+ * Checks the configuration given by the user
+ *
+ * @access private
+ * @param string &$error The error will be written here if any
+ * @param array &$conf The configuration assoc array
+ * @return string error Returns a error message
+ */
+ function _conf(&$error, &$conf)
+ {
+ // check conf
+ if (!is_array($conf)) {
+ return $error = 'Invalid configuration';
+ }
+
+ if (!isset($conf['fields']) || !(int)$conf['fields']) {
+ return $error = 'The number of fields must be numeric (the "fields" key)';
+ }
+
+ if (isset($conf['sep'])) {
+ if (strlen($conf['sep']) !== 1) {
+ return $error = 'Separator can only be one char';
+ }
+ } elseif ($conf['fields'] > 1) {
+ return $error = 'Missing separator (the "sep" key)';
+ } else {
+ // to avoid undefined index notices
+ $conf['sep'] = ',';
+ }
+
+ if (isset($conf['quote'])) {
+ if (strlen($conf['quote']) !== 1) {
+ return $error = 'The quote char must be one char (the "quote" key)';
+ }
+ } else {
+ $conf['quote'] = '"';
+ }
+
+ if (!isset($conf['crlf'])) {
+ $conf['crlf'] = "\n";
+ }
+
+ if (!isset($conf['eol2unix'])) {
+ $conf['eol2unix'] = true;
+ }
+ }
+
+ /**
+ * Return or create the file descriptor associated with a file
+ *
+ * @param string $file The name of the file
+ * @param array &$conf The configuration
+ * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)
+ * @param boolean $reset if passed as true and resource for the file exists
+ * than the file pointer will be moved to the beginning
+ *
+ * @return mixed A file resource or false
+ */
+ function getPointer($file, &$conf, $mode = FILE_MODE_READ, $reset = false)
+ {
+ static $resources = array();
+ if (isset($resources[$file][$mode])) {
+ if ($reset) {
+ fseek($resources[$file][$mode], 0);
+ }
+
+ return $resources[$file][$mode];
+ }
+
+ File_CSV::_conf($error, $conf);
+ if ($error) {
+ return File_CSV::raiseError($error);
+ }
+
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $fp = File::_getFilePointer($file, $mode);
+ PEAR::popErrorHandling();
+ if (PEAR::isError($fp)) {
+ return File_CSV::raiseError($fp);
+ }
+
+ $resources[$file][$mode] = $fp;
+ return $fp;
+ }
+
+ /**
+ * Unquote data
+ *
+ * @param array|string $data The data to unquote
+ * @param string $quote The quote char
+ * @return string the unquoted data
+ */
+ function unquote($data, $quote)
+ {
+ $isString = false;
+ if (!is_array($data)) {
+ $data = array($data);
+ $isString = true;
+ }
+
+ // Get rid of escaped quotes
+ $data = str_replace($quote.$quote, $quote, $data);
+
+ $tmp = array();
+ foreach ($data as $key => $field) {
+ // Trim first the string.
+ $field = trim($field);
+
+ // Incase null fields (form: ;;)
+ $field_len = strlen($field);
+ if (!$field_len) {
+ if ($isString) {
+ return $field;
+ }
+ $tmp[$key] = $field;
+ continue;
+ }
+
+ // excel compat
+ if ($field[0] === '=' && $field[1] === '"') {
+ $field = str_replace('="', '"', $field);
+ --$field_len;
+ }
+
+ if ($field[0] === $quote && $field[$field_len - 1] === $quote) {
+ // Get rid of quotes around the field
+ $field = substr($field, 1, -1);
+ }
+
+ if ($isString) {
+ $tmp = $field;
+ } else {
+ $tmp[$key] = $field;
+ }
+ }
+
+ return $tmp;
+ }
+
+ /**
+ * Reads a row of data as an array from a CSV file. It's able to
+ * read memo fields with multiline data.
+ *
+ * @param string $file The filename where to write the data
+ * @param array &$conf The configuration of the dest CSV
+ *
+ * @return mixed Array with the data read or false on error/no more data
+ */
+ function readQuoted($file, &$conf)
+ {
+ if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_READ)) {
+ return false;
+ }
+
+ $buff = $old = $prev = $c = '';
+ $ret = array();
+ $fields = 1;
+ $in_quote = false;
+ $quote = $conf['quote'];
+ $f = (int)$conf['fields'];
+ $sep = $conf['sep'];
+ while (false !== $ch = fgetc($fp)) {
+ $old = $prev;
+ $prev = $c;
+ $c = $ch;
+
+ // Common case
+ if ($c != $quote && $c != $sep && $c != "\n" && $c != "\r") {
+ $buff .= $c;
+ continue;
+ }
+
+ // Start quote.
+ if (
+ $in_quote === false &&
+ $quote && $c == $quote &&
+ (
+ $prev == $sep || $prev == "\n" || $prev === null ||
+ $prev == "\r" || $prev == '' || $prev == ' '
+ || $prev == '=' //excel compat
+ )
+ ) {
+ $in_quote = true;
+ // excel compat, removing the = part but only if we are in a quote
+ if ($prev == '=') {
+ $buff{strlen($buff) - 1} = '';
+ }
+ }
+
+ if ($in_quote) {
+ // When does the quote end, make sure it's not double quoted
+ if ($c == $sep && $prev == $quote && $old != $quote) {
+ $in_quote = false;
+ } elseif ($c == $sep && $buff == $quote.$quote) {
+ // In case we are dealing with double quote but empty value
+ $in_quote = false;
+ } elseif ($c == "\n" || $c == "\r") {
+ $sub = ($prev == "\r") ? 2 : 1;
+ $buff_len = strlen($buff);
+ if (
+ $buff_len >= $sub &&
+ $buff[$buff_len - $sub] == $quote
+ ) {
+ $in_quote = false;
+ }
+ }
+ }
+
+ if (!$in_quote && ($c == $sep || $c == "\n" || $c == "\r")) {
+ $return = File_CSV::_readQuotedFillers($fp, $f, $fields, $ret,
+ $buff, $quote, $c, $sep);
+ if ($return !== false) {
+ return $return;
+ }
+
+ if ($prev == "\r") {
+ $buff = substr($buff, 0, -1);
+ }
+
+ // Convert EOL character to Unix EOL (LF).
+ if ($conf['eol2unix']) {
+ $buff = preg_replace('/(\r\n|\r)$/', "\n", $buff);
+ // Below replaces things everywhere not just EOL
+ //$buff = str_replace(array("\r\n", "\r"), "\n", $buff);
+ }
+
+ $ret[] = File_CSV::unquote($buff, $quote);
+ if (count($ret) === $f) {
+ return $ret;
+ }
+ $buff = '';
+ ++$fields;
+ continue;
+ }
+
+ $buff .= $c;
+ }
+
+ /* If it's the end of the file and we still have something in buffer
+ * then we process it since files can have no CL/FR at the end
+ */
+ $feof = feof($fp);
+ if ($feof && strlen($buff) > 0 && !in_array($buff, array("\r", "\n"))) {
+ $ret[] = File_CSV::unquote($buff, $quote);
+ if (count($ret) == $f) {
+ return $ret;
+ }
+ }
+
+ if ($feof && count($ret) !== $f) {
+ $return = File_CSV::_readQuotedFillers($fp, $f, $fields, $ret,
+ $buff, $quote, $c, $sep);
+ if ($return !== false) {
+ return $return;
+ }
+ }
+
+ return !$feof ? $ret : false;
+ }
+
+ /**
+ * Adds missing fields (empty ones)
+ *
+ * @param resource $fp the file resource
+ * @param string $f
+ * @param integer $fields the field count
+ * @param array $ret the processed fields in a array
+ * @param string $buff the buffer before it gets put through unquote
+ * @param string $quote Quote in use
+ * @param string $c the char currently being worked with
+ * @param string $sep Separator in use
+ *
+ * @access private
+ * @return array | boolean returns false if no data should return out.
+ */
+ function _readQuotedFillers($fp, $f, $fields, $ret, $buff, $quote, &$c, $sep)
+ {
+ // More fields than expected
+ if ($c == $sep && (count($ret) + 1) === $f) {
+ // Seek the pointer into linebreak character.
+ while (true) {
+ $c = fgetc($fp);
+ if ($c == "\n" || $c == "\r" || $c == '') {
+ break;
+ }
+ }
+
+ // Insert last field value.
+ $ret[] = File_CSV::unquote($buff, $quote);
+ return $ret;
+ }
+
+ // Less fields than expected
+ if (($c == "\n" || $c == "\r") && $fields !== $f) {
+ // Insert last field value.
+ $ret[] = File_CSV::unquote($buff, $quote);
+ if (count($ret) === 1 && empty($ret[0])) {
+ return array();
+ }
+
+ // Pair the array elements to fields count. - inserting empty values
+ $ret_count = count($ret);
+ $sum = ($f - 1) - ($ret_count - 1);
+ $data = array_merge($ret, array_fill($ret_count, $sum, ''));
+ return $data;
+ }
+
+ return false;
+ }
+
+ /**
+ * Reads a "row" from a CSV file and return it as an array
+ *
+ * @param string $file The CSV file
+ * @param array &$conf The configuration of the dest CSV
+ *
+ * @return mixed Array or false
+ */
+ function read($file, &$conf)
+ {
+ if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_READ)) {
+ return false;
+ }
+
+ // The size is limited to 4K
+ if (!$line = fgets($fp, 4096)) {
+ return false;
+ }
+
+ if ($conf['fields'] === 1) {
+ $fields = array($line);
+ $field_count = 1;
+ } else {
+ $fields = explode($conf['sep'], $line);
+ $field_count = count($fields);
+ }
+
+ $real_field_count = $field_count - 1;
+ $check_char = $fields[$real_field_count];
+ if ($check_char === "\n" || $check_char === "\r") {
+ array_pop($fields);
+ --$field_count;
+ }
+
+ $last =& $fields[$real_field_count];
+ if (
+ $field_count !== $conf['fields'] || $conf['quote']
+ && (
+ $last !== ''
+ && (
+ ($last[0] === $conf['quote'] && $last[strlen(rtrim($last)) - 1] !== $conf['quote'])
+ // excel support
+ || ($last[0] === '=' && $last[1] === $conf['quote'])
+ // if the row has spaces or other extra chars before the quote
+ //|| preg_match('|^\s+\\' . $conf['quote'] .'|', $last)
+ )
+ )
+ // XXX perhaps there is a separator inside a quoted field
+ // || preg_match("|{$conf['quote']}.*{$conf['sep']}.*{$conf['quote']}|", $line)
+ // The regex above is really slow
+ || ((count(explode(',', $line))) > $field_count)
+ ) {
+ fseek($fp, -1 * strlen($line), SEEK_CUR);
+ $fields = File_CSV::readQuoted($file, $conf);
+ $fields = File_CSV::_processHeaders($fields, $conf);
+ return $fields;
+ }
+
+ $fields = File_CSV::unquote($fields, $conf['quote']);
+
+ if ($field_count != $conf['fields']) {
+ File_CSV::raiseError("Read wrong fields number count: '". $field_count .
+ "' expected ".$conf['fields']);
+ return true;
+ }
+
+ $fields = File_CSV::_processHeaders($fields, $conf);
+ return $fields;
+ }
+
+ /**
+ * Process the field array being passed in and map the array over to
+ * the header values if the configuration is set on.
+ *
+ * @param array $fields The CSV row columns
+ * @param array $conf File_CSV configuration
+ *
+ * @return array Processed array
+ */
+ function _processHeaders($fields, &$conf)
+ {
+ static $headers = array();
+
+ if (isset($conf['header']) && $conf['header'] == true && empty($headers)) {
+ // read the first row and assign to $headers
+ $headers = $fields;
+ return $headers;
+ }
+
+ if (!empty($headers)) {
+ $tmp = array();
+ foreach ($fields as $k => $v) {
+ if (isset($headers[$k])) {
+ $tmp[$headers[$k]] = $v;
+ }
+ }
+ $fields = $tmp;
+ }
+
+ return $fields;
+ }
+
+ /**
+ * Internal use only, will be removed in the future
+ *
+ * @param string $str The string to debug
+ * @access private
+ */
+ function _dbgBuff($str)
+ {
+ if (strpos($str, "\r") !== false) {
+ $str = str_replace("\r", "_r_", $str);
+ }
+ if (strpos($str, "\n") !== false) {
+ $str = str_replace("\n", "_n_", $str);
+ }
+ if (strpos($str, "\t") !== false) {
+ $str = str_replace("\t", "_t_", $str);
+ }
+ if ($str === null) {
+ $str = '_NULL_';
+ }
+ if ($str === '') {
+ $str = 'Empty string';
+ }
+ echo "buff: ($str)\n";
+ }
+
+ /**
+ * Writes a struc (array) in a file as CSV
+ *
+ * @param string $file The filename where to write the data
+ * @param array $fields Ordered array with the data
+ * @param array &$conf The configuration of the dest CSV
+ *
+ * @return bool True on success false otherwise
+ */
+ function write($file, $fields, &$conf)
+ {
+ if (!$fp = File_CSV::getPointer($file, $conf, FILE_MODE_WRITE)) {
+ return false;
+ }
+
+ $field_count = count($fields);
+ if ($field_count != $conf['fields']) {
+ File_CSV::raiseError("Wrong fields number count: '". $field_count .
+ "' expected ".$conf['fields']);
+ return true;
+ }
+
+ $write = '';
+ $quote = $conf['quote'];
+ for ($i = 0; $i < $field_count; ++$i) {
+ // Write a single field
+
+ $quote_field = false;
+ // Only quote this field in the following cases:
+ if (is_numeric($fields[$i])) {
+ // Numeric fields should not be quoted
+ } elseif (isset($conf['sep']) && (strpos($fields[$i], $conf['sep']) !== false)) {
+ // Separator is present in field
+ $quote_field = true;
+ } elseif (strpos($fields[$i], $quote) !== false) {
+ // Quote character is present in field
+ $quote_field = true;
+ } elseif (
+ strpos($fields[$i], "\n") !== false
+ || strpos($fields[$i], "\r") !== false
+ ) {
+ // Newline is present in field
+ $quote_field = true;
+ } elseif (!is_numeric($fields[$i]) && (substr($fields[$i], 0, 1) == " " || substr($fields[$i], -1) == " ")) {
+ // Space found at beginning or end of field value
+ $quote_field = true;
+ }
+
+ if ($quote_field) {
+ // Escape the quote character within the field (e.g. " becomes "")
+ $quoted_value = str_replace($quote, $quote.$quote, $fields[$i]);
+
+ $write .= $quote . $quoted_value . $quote;
+ } else {
+ $write .= $fields[$i];
+ }
+
+ $write .= ($i < ($field_count - 1)) ? $conf['sep']: $conf['crlf'];
+ }
+
+ if (!fwrite($fp, $write, strlen($write))) {
+ return File_CSV::raiseError('Can not write to file');
+ }
+
+ return true;
+ }
+
+ /**
+ * Discover the format of a CSV file (the number of fields, the separator
+ * and if it quote string fields)
+ *
+ * @param string the CSV file name
+ * @param array extra separators that should be checked for.
+ * @return mixed Assoc array or false
+ */
+ function discoverFormat($file, $extraSeps = array())
+ {
+ if (!$fp = @fopen($file, 'rb')) {
+ return File_CSV::raiseError("Could not open file: $file");
+ }
+
+ // Set auto detect line ending for Mac EOL support
+ $oldini = ini_get('auto_detect_line_endings');
+ if ($oldini != '1') {
+ ini_set('auto_detect_line_endings', '1');
+ }
+
+ // Take the first 30 lines and store the number of occurrences
+ // for each separator in each line
+ $lines = '';
+ for ($i = 0; $i < 30 && !feof($fp) && $line = fgets($fp, 4096); $i++) {
+ $lines .= $line;
+ }
+ fclose($fp);
+
+ if ($oldini != '1') {
+ ini_set('auto_detect_line_endings', $oldini);
+ }
+
+ $seps = array("\t", ';', ':', ',');
+ $seps = array_merge($seps, $extraSeps);
+ $matches = array();
+ $quotes = '"\'';
+
+ while ($lines != ($newLines = preg_replace('|((["\'])[^"]*(\2))|', '\2_\2', $lines))) {
+ $lines = $newLines;
+ }
+
+ $eol = strpos($lines, "\r") ? "\r" : "\n";
+ $lines = explode($eol, $lines);
+ foreach ($lines as $line) {
+ $orgLine = $line;
+ foreach ($seps as $sep) {
+ $line = preg_replace("|^[$quotes$sep]*$sep*([$quotes][^$quotes]*[$quotes])|sm", '_', $orgLine);
+ // Find all seps that are within qoutes
+ ///FIXME ... counts legitimit lines as bad ones
+
+ // In case there's a whitespace infront the field
+ $regex = '|\s*?';
+ // Match the first quote (optional), also optionally match = since it's excel stuff
+ $regex.= "(?:\=?[$quotes])";
+ $regex.= '(.*';
+ // Don't match a sep if we are inside a quote
+ // also don't accept the sep if it has a quote on the either side
+ ///FIXME has to be possible if we are inside a quote! (tests fail because of this)
+ $regex.= "(?:[^$quotes])$sep(?:[^$quotes])";
+ $regex.= '.*)';
+ // Close quote (if it's present) and the sep (optional, could be end of line)
+ $regex.= "(?:[$quotes](?:$sep?))|Ums";
+
+ preg_match_all($regex, $line, $match);
+ // Finding all seps, within quotes or not
+ $sep_count = substr_count($line, $sep);
+ // Real count
+ $matches[$sep][] = $sep_count - count($match[0]);
+ }
+ }
+
+ $final = array();
+ // Group the results by amount of equal ocurrences
+ foreach ($matches as $sep => $res) {
+ $times = array();
+ $times[0] = 0;
+ foreach ($res as $k => $num) {
+ if ($num > 0) {
+ $times[$num] = isset($times[$num]) ? $times[$num] + $num : 1;
+ }
+ }
+ arsort($times);
+
+ // Use max fields count.
+ $fields[$sep] = max(array_flip($times));
+ $amount[$sep] = $times[key($times)];
+ }
+
+ arsort($amount);
+ $sep = key($amount);
+
+ $conf['fields'] = $fields[$sep] + 1;
+ $conf['sep'] = $sep;
+
+ // Test if there are fields with quotes around in the first 30 lines
+ $quote = null;
+
+ $string = implode('', $lines);
+ foreach (array('"', '\'') as $q) {
+ if (preg_match_all("|$sep(?:\s*?)(\=?[$q]).*([$q])$sep?|Us", $string, $match)) {
+ if ($match[1][0] == $match[2][0]) {
+ $quote = $match[1][0];
+ break;
+ }
+ }
+
+ if (
+ preg_match_all("|^(\=?[$q]).*([$q])$sep{0,1}|Ums", $string, $match)
+ || preg_match_all("|(\=?[$q]).*([$q])$sep\s$|Ums", $string, $match)
+ ) {
+ if ($match[1][0] == $match[2][0]) {
+ $quote = $match[1][0];
+ break;
+ }
+ }
+ }
+
+ $conf['quote'] = $quote;
+ return $conf;
+ }
+
+ /**
+ * Front to call getPointer and moving the resource to the
+ * beginning of the file
+ * Reset it if you like.
+ *
+ * @param string $file The name of the file
+ * @param array &$conf The configuration
+ * @param string $mode The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)
+ *
+ * @return boolean true on success false on failure
+ */
+ function resetPointer($file, &$conf, $mode)
+ {
+ if (!File_CSV::getPointer($file, $conf, $mode, true)) {
+ return false;
+ }
+
+ return true;
+ }
}
\ No newline at end of file
// | Author: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Find.php,v 1.27 2006/06/30 14:06:16 techtonik Exp $
+// $Id: Find.php 304090 2010-10-05 14:07:34Z clockwerx $
//
require_once 'PEAR.php';
* Commonly needed functions searching directory trees
*
* @access public
-* @version $Id: Find.php,v 1.27 2006/06/30 14:06:16 techtonik Exp $
+* @version $Id: Find.php 304090 2010-10-05 14:07:34Z clockwerx $
* @package File
* @author Sterling Hughes <sterling@php.net>
*/
$matches = null;
}
+ sort($matches);
+
return $matches ;
}
array_push($this->directories, $dir);
}
+ sort($this->directories);
+ sort($this->files);
+
$retval = array($this->directories, $this->files);
return $retval;
}
closedir($dh);
}
-
+
+ sort($retval);
+
while (list($key, $val) = each($retval)) {
$path = $directory . "/" . $val;
}
}
+ sort($matches);
+
return $matches;
}
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * File::Util\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category File\r
- * @package File\r
- * @author Michael Wallner <mike@php.net>\r
- * @copyright 2004-2005 Michael Wallner\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: Util.php,v 1.25 2007/02/20 14:19:08 mike Exp $\r
- * @link http://pear.php.net/package/File\r
- */\r
-\r
-/**#@+\r
- * Sorting Constants\r
- */\r
-define('FILE_SORT_NONE', 0);\r
-define('FILE_SORT_REVERSE', 1);\r
-define('FILE_SORT_NAME', 2);\r
-define('FILE_SORT_SIZE', 4);\r
-define('FILE_SORT_DATE', 8);\r
-define('FILE_SORT_RANDOM', 16);\r
-/**#@-*/\r
-\r
-/**#@+\r
- * Listing Constants\r
- */\r
-define('FILE_LIST_FILES', 1);\r
-define('FILE_LIST_DIRS', 2);\r
-define('FILE_LIST_DOTS', 4);\r
-define('FILE_LIST_ALL', FILE_LIST_FILES | FILE_LIST_DIRS | FILE_LIST_DOTS);\r
-/**#@-*/\r
-\r
-/**\r
- * @ignore\r
- */\r
-define('FILE_WIN32', defined('OS_WINDOWS') ? OS_WINDOWS : !strncasecmp(PHP_OS, 'win', 3));\r
-\r
-/**\r
- * File_Util\r
- *\r
- * File and directory utility functions.\r
- *\r
- * @access public\r
- * @static\r
- */\r
-class File_Util\r
-{\r
- /**\r
- * Returns a string path built from the array $pathParts. Where a join\r
- * occurs multiple separators are removed. Joins using the optional\r
- * separator, defaulting to the PHP DIRECTORY_SEPARATOR constant.\r
- *\r
- * @static\r
- * @access public\r
- * @param array $parts Array containing the parts to be joined\r
- * @param string $separator The directory seperator\r
- */\r
- function buildPath($parts, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- $qs = '/^'. preg_quote($separator, '/') .'+$/';\r
- for ($i = 0, $c = count($parts); $i < $c; $i++) {\r
- if (!strlen($parts[$i]) || preg_match($qs, $parts[$i])) {\r
- unset($parts[$i]);\r
- } elseif (0 == $i) {\r
- $parts[$i] = rtrim($parts[$i], $separator);\r
- } elseif ($c - 1 == $i) {\r
- $parts[$i] = ltrim($parts[$i], $separator);\r
- } else {\r
- $parts[$i] = trim($parts[$i], $separator);\r
- }\r
- }\r
- return implode($separator, $parts);\r
- }\r
-\r
- /**\r
- * Returns a path without leading / or C:\. If this is not\r
- * present the path is returned as is.\r
- *\r
- * @static\r
- * @access public\r
- * @param string $path The path to be processed\r
- * @return string The processed path or the path as is\r
- */\r
- function skipRoot($path)\r
- {\r
- if (File_Util::isAbsolute($path)) {\r
- if (FILE_WIN32) {\r
- return substr($path, $path{3} == '\\' ? 4 : 3);\r
- }\r
- return ltrim($path, '/');\r
- }\r
- return $path;\r
- }\r
-\r
- /**\r
- * Returns the temp directory according to either the TMP, TMPDIR, or\r
- * TEMP env variables. If these are not set it will also check for the\r
- * existence of /tmp, %WINDIR%\temp\r
- *\r
- * @static\r
- * @access public\r
- * @return string The system tmp directory\r
- */\r
- function tmpDir()\r
- {\r
- if (FILE_WIN32) {\r
- if (isset($_ENV['TEMP'])) {\r
- return $_ENV['TEMP'];\r
- }\r
- if (isset($_ENV['TMP'])) {\r
- return $_ENV['TMP'];\r
- }\r
- if (isset($_ENV['windir'])) {\r
- return $_ENV['windir'] . '\\temp';\r
- }\r
- if (isset($_ENV['SystemRoot'])) {\r
- return $_ENV['SystemRoot'] . '\\temp';\r
- }\r
- if (isset($_SERVER['TEMP'])) {\r
- return $_SERVER['TEMP'];\r
- }\r
- if (isset($_SERVER['TMP'])) {\r
- return $_SERVER['TMP'];\r
- }\r
- if (isset($_SERVER['windir'])) {\r
- return $_SERVER['windir'] . '\\temp';\r
- }\r
- if (isset($_SERVER['SystemRoot'])) {\r
- return $_SERVER['SystemRoot'] . '\\temp';\r
- }\r
- return '\temp';\r
- }\r
- if (isset($_ENV['TMPDIR'])) {\r
- return $_ENV['TMPDIR'];\r
- }\r
- if (isset($_SERVER['TMPDIR'])) {\r
- return $_SERVER['TMPDIR'];\r
- }\r
- return '/tmp';\r
- }\r
-\r
- /**\r
- * Returns a temporary filename using tempnam() and File::tmpDir().\r
- *\r
- * @static\r
- * @access public\r
- * @param string $dirname Optional directory name for the tmp file\r
- * @return string Filename and path of the tmp file\r
- */\r
- function tmpFile($dirname = null)\r
- {\r
- if (!isset($dirname)) {\r
- $dirname = File_Util::tmpDir();\r
- }\r
- return tempnam($dirname, 'temp.');\r
- }\r
-\r
- /**\r
- * Returns boolean based on whether given path is absolute or not.\r
- *\r
- * @static\r
- * @access public\r
- * @param string $path Given path\r
- * @return boolean True if the path is absolute, false if it is not\r
- */\r
- function isAbsolute($path)\r
- {\r
- if (preg_match('/(?:\/|\\\)\.\.(?=\/|$)/', $path)) {\r
- return false;\r
- }\r
- if (FILE_WIN32) {\r
- return preg_match('/^[a-zA-Z]:(\\\|\/)/', $path);\r
- }\r
- return ($path{0} == '/') || ($path{0} == '~');\r
- }\r
-\r
- /**\r
- * Checks for a file's existence, taking the current include path \r
- * into consideration\r
- * \r
- * This method can be called statically\r
- * (e.g., File_Util::isIncludable('config.php'))\r
- *\r
- * @param string $file\r
- * @param string $sep the directory separator (optional)\r
- * @return string the includable path\r
- * @access public\r
- * @static \r
- */\r
- function isIncludable($file, $sep = DIRECTORY_SEPARATOR)\r
- {\r
- foreach ((array) explode(PATH_SEPARATOR, ini_get('include_path')) as $path) {\r
- if (file_exists($path .= $sep . $file)) {\r
- return $path;\r
- }\r
- }\r
- if (file_exists($file)) {\r
- return $file;\r
- }\r
- return NULL;\r
- }\r
- \r
- /**\r
- * Get path relative to another path\r
- *\r
- * @static\r
- * @access public\r
- * @return string\r
- * @param string $path\r
- * @param string $root\r
- * @param string $separator\r
- */\r
- function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- $path = File_Util::realpath($path, $separator);\r
- $root = File_Util::realpath($root, $separator);\r
- $dirs = explode($separator, $path);\r
- $comp = explode($separator, $root);\r
-\r
- if (FILE_WIN32) {\r
- if (strcasecmp($dirs[0], $comp[0])) {\r
- return $path;\r
- }\r
- unset($dirs[0], $comp[0]);\r
- }\r
-\r
- foreach ($comp as $i => $part) {\r
- if (isset($dirs[$i]) && $part == $dirs[$i]) {\r
- unset($dirs[$i], $comp[$i]);\r
- } else {\r
- break;\r
- }\r
- }\r
-\r
- return str_repeat('..' . $separator, count($comp)) . implode($separator, $dirs);\r
- }\r
-\r
- /**\r
- * Get real path (works with non-existant paths)\r
- *\r
- * @static\r
- * @access public\r
- * @return string\r
- * @param string $path\r
- * @param string $separator\r
- */\r
- function realPath($path, $separator = DIRECTORY_SEPARATOR)\r
- {\r
- if (!strlen($path)) {\r
- return $separator;\r
- }\r
-\r
- $drive = '';\r
- if (FILE_WIN32) {\r
- $path = preg_replace('/[\\\\\/]/', $separator, $path);\r
- if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {\r
- $drive = $matches[1];\r
- $path = $matches[2];\r
- } else {\r
- $cwd = getcwd();\r
- $drive = substr($cwd, 0, 2);\r
- if ($path{0} !== $separator{0}) {\r
- $path = substr($cwd, 3) . $separator . $path;\r
- }\r
- }\r
- } elseif ($path{0} !== $separator) {\r
- $path = getcwd() . $separator . $path;\r
- }\r
-\r
- $dirStack = array();\r
- foreach (explode($separator, $path) as $dir) {\r
- if (strlen($dir) && $dir !== '.') {\r
- if ($dir == '..') {\r
- array_pop($dirStack);\r
- } else {\r
- $dirStack[] = $dir;\r
- }\r
- }\r
- }\r
-\r
- return $drive . $separator . implode($separator, $dirStack);\r
- }\r
-\r
- /**\r
- * Check whether path is in root path\r
- *\r
- * @static\r
- * @access public\r
- * @return bool\r
- * @param string $path\r
- * @param string $root\r
- */\r
- function pathInRoot($path, $root)\r
- {\r
- static $realPaths = array();\r
-\r
- if (!isset($realPaths[$root])) {\r
- $realPaths[$root] = File_Util::realPath($root);\r
- }\r
-\r
- return false !== strstr(File_Util::realPath($path), $realPaths[$root]);\r
- }\r
-\r
- /**\r
- * List Directory\r
- *\r
- * The final argument, $cb, is a callback that either evaluates to true or\r
- * false and performs a filter operation, or it can also modify the\r
- * directory/file names returned. To achieve the latter effect use as\r
- * follows:\r
- *\r
- * <code>\r
- * <?php\r
- * function uc(&$filename) {\r
- * $filename = strtoupper($filename);\r
- * return true;\r
- * }\r
- * $entries = File_Util::listDir('.', FILE_LIST_ALL, FILE_SORT_NONE, 'uc');\r
- * foreach ($entries as $e) {\r
- * echo $e->name, "\n";\r
- * }\r
- * ?>\r
- * </code>\r
- *\r
- * @static\r
- * @access public\r
- * @return array\r
- * @param string $path\r
- * @param int $list\r
- * @param int $sort\r
- * @param mixed $cb\r
- */\r
- function listDir($path, $list = FILE_LIST_ALL, $sort = FILE_SORT_NONE, $cb = null)\r
- {\r
- if (!strlen($path) || !is_dir($path)) {\r
- return null;\r
- }\r
-\r
- $entries = array();\r
- for ($dir = dir($path); false !== $entry = $dir->read(); ) {\r
- if ($list & FILE_LIST_DOTS || $entry{0} !== '.') {\r
- $isRef = ($entry === '.' || $entry === '..');\r
- $isDir = $isRef || is_dir($path .'/'. $entry);\r
- if ( ((!$isDir && $list & FILE_LIST_FILES) ||\r
- ($isDir && $list & FILE_LIST_DIRS)) &&\r
- (!is_callable($cb) ||\r
- call_user_func_array($cb, array(&$entry)))) {\r
- $entries[] = (object) array(\r
- 'name' => $entry,\r
- 'size' => $isDir ? null : filesize($path .'/'. $entry),\r
- 'date' => filemtime($path .'/'. $entry),\r
- );\r
- }\r
- }\r
- }\r
- $dir->close();\r
-\r
- if ($sort) {\r
- $entries = File_Util::sortFiles($entries, $sort);\r
- }\r
-\r
- return $entries;\r
- }\r
-\r
- /**\r
- * Sort Files\r
- *\r
- * @static\r
- * @access public\r
- * @return array\r
- * @param array $files\r
- * @param int $sort\r
- */\r
- function sortFiles($files, $sort)\r
- {\r
- if (!$files) {\r
- return array();\r
- }\r
-\r
- if (!$sort) {\r
- return $files;\r
- }\r
-\r
- if ($sort === 1) {\r
- return array_reverse($files);\r
- }\r
-\r
- if ($sort & FILE_SORT_RANDOM) {\r
- shuffle($files);\r
- return $files;\r
- }\r
-\r
- $names = array();\r
- $sizes = array();\r
- $dates = array();\r
-\r
- if ($sort & FILE_SORT_NAME) {\r
- $r = &$names;\r
- } elseif ($sort & FILE_SORT_DATE) {\r
- $r = &$dates;\r
- } elseif ($sort & FILE_SORT_SIZE) {\r
- $r = &$sizes;\r
- } else {\r
- asort($files, SORT_REGULAR);\r
- return $files;\r
- }\r
-\r
- $sortFlags = array(\r
- FILE_SORT_NAME => SORT_STRING,\r
- FILE_SORT_DATE => SORT_NUMERIC,\r
- FILE_SORT_SIZE => SORT_NUMERIC,\r
- );\r
-\r
- foreach ($files as $file) {\r
- $names[] = $file->name;\r
- $sizes[] = $file->size;\r
- $dates[] = $file->date;\r
- }\r
-\r
- if ($sort & FILE_SORT_REVERSE) {\r
- arsort($r, $sortFlags[$sort & ~1]);\r
- } else {\r
- asort($r, $sortFlags[$sort]);\r
- }\r
-\r
- $result = array();\r
- foreach ($r as $i => $f) {\r
- $result[] = $files[$i];\r
- }\r
-\r
- return $result;\r
- }\r
-\r
- /**\r
- * Switch File Extension\r
- *\r
- * @static\r
- * @access public\r
- * @return string|array\r
- * @param string|array $filename\r
- * @param string $to new file extension\r
- * @param string $from change only files with this extension\r
- * @param bool $reverse change only files not having $from extension\r
- */\r
- function switchExt($filename, $to, $from = null, $reverse = false)\r
- {\r
- if (is_array($filename)) {\r
- foreach ($filename as $key => $file) {\r
- $filename[$key] = File_Util::switchExt($file, $to, $from);\r
- }\r
- return $filename;\r
- }\r
-\r
- if ($len = strlen($from)) {\r
- $ext = substr($filename, -$len - 1);\r
- $cfn = FILE_WIN32 ? 'strcasecmp' : 'strcmp';\r
- if (!$reverse == $cfn($ext, '.'. $from)) {\r
- return $filename;\r
- }\r
- return substr($filename, 0, -$len - 1) .'.'. $to;\r
- }\r
-\r
- if ($pos = strpos($filename, '.')) {\r
- return substr($filename, 0, $pos) .'.'. $to;\r
- }\r
-\r
- return $filename .'.'. $to;\r
- }\r
-}\r
-\r
-?>\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * File::Util
+ *
+ * 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 File
+ * @package File
+ * @author Michael Wallner <mike@php.net>
+ * @copyright 2004-2005 Michael Wallner
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version CVS: $Id: Util.php 309134 2011-03-12 16:45:50Z dufuz $
+ * @link http://pear.php.net/package/File
+ */
+
+/**#@+
+ * Sorting Constants
+ */
+define('FILE_SORT_NONE', 0);
+define('FILE_SORT_REVERSE', 1);
+define('FILE_SORT_NAME', 2);
+define('FILE_SORT_SIZE', 4);
+define('FILE_SORT_DATE', 8);
+define('FILE_SORT_RANDOM', 16);
+/**#@-*/
+
+/**#@+
+ * Listing Constants
+ */
+define('FILE_LIST_FILES', 1);
+define('FILE_LIST_DIRS', 2);
+define('FILE_LIST_DOTS', 4);
+define('FILE_LIST_ALL', FILE_LIST_FILES | FILE_LIST_DIRS | FILE_LIST_DOTS);
+/**#@-*/
+
+/**
+ * @ignore
+ */
+define('FILE_WIN32', defined('OS_WINDOWS') ? OS_WINDOWS : !strncasecmp(PHP_OS, 'win', 3));
+
+/**
+ * File_Util
+ *
+ * File and directory utility functions.
+ *
+ * @access public
+ * @static
+ */
+class File_Util
+{
+ /**
+ * Returns a string path built from the array $pathParts. Where a join
+ * occurs multiple separators are removed. Joins using the optional
+ * separator, defaulting to the PHP DIRECTORY_SEPARATOR constant.
+ *
+ * @static
+ * @access public
+ * @param array $parts Array containing the parts to be joined
+ * @param string $separator The directory seperator
+ */
+ function buildPath($parts, $separator = DIRECTORY_SEPARATOR)
+ {
+ $qs = '/^'. preg_quote($separator, '/') .'+$/';
+ for ($i = 0, $c = count($parts); $i < $c; $i++) {
+ if (!strlen($parts[$i]) || preg_match($qs, $parts[$i])) {
+ unset($parts[$i]);
+ } elseif (0 == $i) {
+ $parts[$i] = rtrim($parts[$i], $separator);
+ } elseif ($c - 1 == $i) {
+ $parts[$i] = ltrim($parts[$i], $separator);
+ } else {
+ $parts[$i] = trim($parts[$i], $separator);
+ }
+ }
+ return implode($separator, $parts);
+ }
+
+ /**
+ * Returns a path without leading / or C:\. If this is not
+ * present the path is returned as is.
+ *
+ * @static
+ * @access public
+ * @param string $path The path to be processed
+ * @return string The processed path or the path as is
+ */
+ function skipRoot($path)
+ {
+ if (File_Util::isAbsolute($path)) {
+ if (FILE_WIN32) {
+ return substr($path, $path{3} == '\\' ? 4 : 3);
+ }
+ return ltrim($path, '/');
+ }
+ return $path;
+ }
+
+ /**
+ * Returns the temp directory according to either the TMP, TMPDIR, or
+ * TEMP env variables. If these are not set it will also check for the
+ * existence of /tmp, %WINDIR%\temp
+ *
+ * @static
+ * @access public
+ * @return string The system tmp directory
+ */
+ function tmpDir()
+ {
+ if (FILE_WIN32) {
+ if (isset($_ENV['TEMP'])) {
+ return $_ENV['TEMP'];
+ }
+ if (isset($_ENV['TMP'])) {
+ return $_ENV['TMP'];
+ }
+ if (isset($_ENV['windir'])) {
+ return $_ENV['windir'] . '\\temp';
+ }
+ if (isset($_ENV['SystemRoot'])) {
+ return $_ENV['SystemRoot'] . '\\temp';
+ }
+ if (isset($_SERVER['TEMP'])) {
+ return $_SERVER['TEMP'];
+ }
+ if (isset($_SERVER['TMP'])) {
+ return $_SERVER['TMP'];
+ }
+ if (isset($_SERVER['windir'])) {
+ return $_SERVER['windir'] . '\\temp';
+ }
+ if (isset($_SERVER['SystemRoot'])) {
+ return $_SERVER['SystemRoot'] . '\\temp';
+ }
+ return '\temp';
+ }
+ if (isset($_ENV['TMPDIR'])) {
+ return $_ENV['TMPDIR'];
+ }
+ if (isset($_SERVER['TMPDIR'])) {
+ return $_SERVER['TMPDIR'];
+ }
+ return '/tmp';
+ }
+
+ /**
+ * Returns a temporary filename using tempnam() and File::tmpDir().
+ *
+ * @static
+ * @access public
+ * @param string $dirname Optional directory name for the tmp file
+ * @return string Filename and path of the tmp file
+ */
+ function tmpFile($dirname = null)
+ {
+ if (!isset($dirname)) {
+ $dirname = File_Util::tmpDir();
+ }
+ return tempnam($dirname, 'temp.');
+ }
+
+ /**
+ * Returns boolean based on whether given path is absolute or not.
+ *
+ * @static
+ * @access public
+ * @param string $path Given path
+ * @return boolean True if the path is absolute, false if it is not
+ */
+ function isAbsolute($path)
+ {
+ if (preg_match('/(?:\/|\\\)\.\.(?=\/|$)/', $path)) {
+ return false;
+ }
+ if (FILE_WIN32) {
+ return (($path{0} == '/') || preg_match('/^[a-zA-Z]:(\\\|\/)/', $path));
+ }
+ return ($path{0} == '/') || ($path{0} == '~');
+ }
+
+ /**
+ * Checks for a file's existence, taking the current include path
+ * into consideration
+ *
+ * This method can be called statically
+ * (e.g., File_Util::isIncludable('config.php'))
+ *
+ * @param string $file
+ * @param string $sep the directory separator (optional)
+ * @return string the includable path
+ * @access public
+ * @static
+ */
+ function isIncludable($file, $sep = DIRECTORY_SEPARATOR)
+ {
+ foreach ((array) explode(PATH_SEPARATOR, ini_get('include_path')) as $path) {
+ if (file_exists($path .= $sep . $file)) {
+ return $path;
+ }
+ }
+ if (file_exists($file)) {
+ return $file;
+ }
+ return null;
+ }
+
+ /**
+ * Get path relative to another path
+ *
+ * @static
+ * @access public
+ * @return string
+ * @param string $path
+ * @param string $root
+ * @param string $separator
+ */
+ function relativePath($path, $root, $separator = DIRECTORY_SEPARATOR)
+ {
+ $path = File_Util::realpath($path, $separator);
+ $root = File_Util::realpath($root, $separator);
+ $dirs = explode($separator, $path);
+ $comp = explode($separator, $root);
+
+ if (FILE_WIN32) {
+ if (strcasecmp($dirs[0], $comp[0])) {
+ return $path;
+ }
+ unset($dirs[0], $comp[0]);
+ }
+
+ foreach ($comp as $i => $part) {
+ if (isset($dirs[$i]) && $part == $dirs[$i]) {
+ unset($dirs[$i], $comp[$i]);
+ } else {
+ break;
+ }
+ }
+
+ return str_repeat('..' . $separator, count($comp)) . implode($separator, $dirs);
+ }
+
+ /**
+ * Get real path (works with non-existant paths)
+ *
+ * @static
+ * @access public
+ * @return string
+ * @param string $path
+ * @param string $separator
+ */
+ function realPath($path, $separator = DIRECTORY_SEPARATOR)
+ {
+ if (!strlen($path)) {
+ return $separator;
+ }
+
+ $drive = '';
+ $path = preg_replace('/[\\\\\/]/', $separator, $path);
+ if (FILE_WIN32) {
+ if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {
+ $drive = $matches[1];
+ $path = $matches[2];
+ } else {
+ $cwd = getcwd();
+ $drive = substr($cwd, 0, 2);
+ if ($path{0} !== $separator{0}) {
+ $path = substr($cwd, 3) . $separator . $path;
+ }
+ }
+ } elseif ($path{0} !== $separator) {
+ $path = getcwd() . $separator . $path;
+ }
+
+ $dirStack = array();
+ foreach (explode($separator, $path) as $dir) {
+ if (strlen($dir) && $dir !== '.') {
+ if ($dir == '..') {
+ array_pop($dirStack);
+ } else {
+ $dirStack[] = $dir;
+ }
+ }
+ }
+
+ return $drive . $separator . implode($separator, $dirStack);
+ }
+
+ /**
+ * Check whether path is in root path
+ *
+ * @static
+ * @access public
+ * @return bool
+ * @param string $path
+ * @param string $root
+ */
+ function pathInRoot($path, $root)
+ {
+ static $realPaths = array();
+
+ if (!isset($realPaths[$root])) {
+ $realPaths[$root] = File_Util::realPath($root);
+ }
+
+ return false !== strstr(File_Util::realPath($path), $realPaths[$root]);
+ }
+
+ /**
+ * List Directory
+ *
+ * The final argument, $cb, is a callback that either evaluates to true or
+ * false and performs a filter operation, or it can also modify the
+ * directory/file names returned. To achieve the latter effect use as
+ * follows:
+ *
+ * <code>
+ * <?php
+ * function uc(&$filename) {
+ * $filename = strtoupper($filename);
+ * return true;
+ * }
+ * $entries = File_Util::listDir('.', FILE_LIST_ALL, FILE_SORT_NONE, 'uc');
+ * foreach ($entries as $e) {
+ * echo $e->name, "\n";
+ * }
+ * ?>
+ * </code>
+ *
+ * @static
+ * @access public
+ * @return array
+ * @param string $path
+ * @param int $list
+ * @param int $sort
+ * @param mixed $cb
+ */
+ function listDir($path, $list = FILE_LIST_ALL, $sort = FILE_SORT_NONE, $cb = null)
+ {
+ if (!strlen($path) || !is_dir($path)) {
+ return null;
+ }
+
+ $entries = array();
+ for ($dir = dir($path); false !== $entry = $dir->read(); ) {
+ if ($list & FILE_LIST_DOTS || $entry{0} !== '.') {
+ $isRef = ($entry === '.' || $entry === '..');
+ $isDir = $isRef || is_dir($path .'/'. $entry);
+ if ( ((!$isDir && $list & FILE_LIST_FILES) ||
+ ($isDir && $list & FILE_LIST_DIRS)) &&
+ (!is_callable($cb) ||
+ call_user_func_array($cb, array(&$entry)))) {
+ $entries[] = (object) array(
+ 'name' => $entry,
+ 'size' => $isDir ? null : filesize($path .'/'. $entry),
+ 'date' => filemtime($path .'/'. $entry),
+ );
+ }
+ }
+ }
+ $dir->close();
+
+ if ($sort) {
+ $entries = File_Util::sortFiles($entries, $sort);
+ }
+
+ return $entries;
+ }
+
+ /**
+ * Sort Files
+ *
+ * @static
+ * @access public
+ * @return array
+ * @param array $files
+ * @param int $sort
+ */
+ function sortFiles($files, $sort)
+ {
+ if (!$files) {
+ return array();
+ }
+
+ if (!$sort) {
+ return $files;
+ }
+
+ if ($sort === 1) {
+ return array_reverse($files);
+ }
+
+ if ($sort & FILE_SORT_RANDOM) {
+ shuffle($files);
+ return $files;
+ }
+
+ $names = array();
+ $sizes = array();
+ $dates = array();
+
+ if ($sort & FILE_SORT_NAME) {
+ $r = &$names;
+ } elseif ($sort & FILE_SORT_DATE) {
+ $r = &$dates;
+ } elseif ($sort & FILE_SORT_SIZE) {
+ $r = &$sizes;
+ } else {
+ asort($files, SORT_REGULAR);
+ return $files;
+ }
+
+ $sortFlags = array(
+ FILE_SORT_NAME => SORT_STRING,
+ FILE_SORT_DATE => SORT_NUMERIC,
+ FILE_SORT_SIZE => SORT_NUMERIC,
+ );
+
+ foreach ($files as $file) {
+ $names[] = $file->name;
+ $sizes[] = $file->size;
+ $dates[] = $file->date;
+ }
+
+ if ($sort & FILE_SORT_REVERSE) {
+ arsort($r, $sortFlags[$sort & ~1]);
+ } else {
+ asort($r, $sortFlags[$sort]);
+ }
+
+ $result = array();
+ foreach ($r as $i => $f) {
+ $result[] = $files[$i];
+ }
+
+ return $result;
+ }
+
+ /**
+ * Switch File Extension
+ *
+ * @static
+ * @access public
+ * @return string|array
+ * @param string|array $filename
+ * @param string $to new file extension
+ * @param string $from change only files with this extension
+ * @param bool $reverse change only files not having $from extension
+ */
+ function switchExt($filename, $to, $from = null, $reverse = false)
+ {
+ if (is_array($filename)) {
+ foreach ($filename as $key => $file) {
+ $filename[$key] = File_Util::switchExt($file, $to, $from);
+ }
+ return $filename;
+ }
+
+ if ($len = strlen($from)) {
+ $ext = substr($filename, -$len - 1);
+ $cfn = FILE_WIN32 ? 'strcasecmp' : 'strcmp';
+ if (!$reverse == $cfn($ext, '.'. $from)) {
+ return $filename;
+ }
+ return substr($filename, 0, -$len - 1) .'.'. $to;
+ }
+
+ if ($pos = strpos($filename, '.')) {
+ return substr($filename, 0, $pos) .'.'. $to;
+ }
+
+ return $filename .'.'. $to;
+ }
+
+ /**
+ * Returns the filesize using a prefix like "kilo", "mebi" or "giga"
+ *
+ * @author Christian Weiske <cweiske@cweiske.de>
+ *
+ * @param integer $size The size to convert
+ * @param integer $decimals The number of decimals to use
+ * @param boolean $long Use long names (kilobyte) instead of
+ * short ones (kB)
+ * @param boolean $oldStyle If the old style should be used
+ * @param boolean $useBiBytes If the "BiBytes" names should be
+ * used [applies only to !$bOldStyle]
+ *
+ * @return string The filesize in human readable format
+ *
+ * @static
+ */
+ function prefixed(
+ $size, $decimals = 1, $long = false, $oldStyle = true,
+ $useBiBytes = true
+ ) {
+ $base = ($oldStyle || $useBiBytes) ? 1024 : 1000;
+ $names = array(
+ '', 'kilo', 'mega', 'giga', 'tera',
+ 'peta', 'exa', 'zetta', 'yotta'
+ );
+ $max = count($names) - 1;
+
+ for ($a = 0; $size >= $base && $a < $max; $a++) {
+ $size /= $base;
+ }
+
+ $name = ($oldStyle || !$useBiBytes)
+ ? $names[$a]
+ : $names[$a] . 'bi';
+ if (!$long) {
+ $name = $oldStyle || !$useBiBytes
+ ? strtoupper(substr($name, 0, 1))
+ : strtoupper(substr($name, 0, 1)) . 'i';
+ $name .= 'B';
+ } else {
+ $name .= $size == 1 ? 'byte' : 'bytes';
+ }
+
+ return round($size, $decimals) . ' ' . $name;
+ }
+
+}
// | Authors: Alan Knowles <alan@akbkhome> |
// +----------------------------------------------------------------------+
//
-// $Id: Tag.php 315533 2011-08-26 02:39:02Z alan_k $
+// $Id: Tag.php 315544 2011-08-26 09:57:34Z alan_k $
/* FC/BC compatibility with php5 */
if ( (substr(phpversion(),0,1) < 5) && !function_exists('clone')) {
eval('function clone($t) { return $t; }');
* one instance of these exists for each namespace.
*
*
-* @version $Id: Tag.php 315533 2011-08-26 02:39:02Z alan_k $
+* @version $Id: Tag.php 315544 2011-08-26 09:57:34Z alan_k $
*/
class HTML_Template_Flexy_Compiler_Flexy_Tag
// | Authors: Naoki Shima <murahachibu@php.net> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Common.php,v 1.3 2003/01/19 20:02:50 cain Exp $
+// $Id: Common.php 112735 2003-01-19 20:02:50Z cain $
require_once('PEAR.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Jacques Marneweck <jacques@php.net> |
// +----------------------------------------------------------------------+//
-// $Id: af.php,v 1.1 2003/03/13 08:37:32 cain Exp $
+// $Id: af.php 120053 2003-03-13 08:37:32Z cain $
class I18N_Common_af
{
// +----------------------------------------------------------------------+
// | Authors: Tommy Ipsen <tommy.ipsen@nalnet.dk> |
// +----------------------------------------------------------------------+
-// $Id: da_DK.php,v 1.2 2003/08/07 07:45:50 cain Exp $
+// $Id: da_DK.php 136856 2003-08-07 07:45:50Z cain $
class I18N_Common_da_DK
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: de.php,v 1.2 2003/01/04 11:55:26 mj Exp $
+// $Id: de.php 110339 2003-01-04 11:55:29Z mj $
class I18N_Common_de
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: de_AT.php,v 1.2 2003/01/04 11:55:26 mj Exp $
+// $Id: de_AT.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common/de.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: de_DE.php,v 1.2 2003/01/04 11:55:26 mj Exp $
+// $Id: de_DE.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common/de.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: en.php,v 1.3 2003/01/07 11:03:32 cain Exp $
+// $Id: en.php 110869 2003-01-07 11:03:32Z cain $
class I18N_Common_en
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: en_GB.php,v 1.1 2003/04/08 10:32:09 cain Exp $
+// $Id: en_GB.php 122844 2003-04-08 10:32:09Z cain $
require_once('I18N/Common/en.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: en_UK.php,v 1.3 2003/04/08 10:32:09 cain Exp $
+// $Id: en_UK.php 122844 2003-04-08 10:32:09Z cain $
require_once('I18N/Common/en_GB.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: en_US.php,v 1.2 2003/01/04 11:55:27 mj Exp $
+// $Id: en_US.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common/en.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Jacques Marneweck <jacques@php.net> |
// +----------------------------------------------------------------------+//
-// $Id: en_ZA.php,v 1.1 2003/03/13 08:37:32 cain Exp $
+// $Id: en_ZA.php 120053 2003-03-13 08:37:32Z cain $
require_once('I18N/Common/en.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: es.php,v 1.3 2003/01/04 11:55:27 mj Exp $
+// $Id: es.php 110339 2003-01-04 11:55:29Z mj $
class I18N_Common_es
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: es_ES.php,v 1.2 2003/01/04 11:55:27 mj Exp $
+// $Id: es_ES.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common/es.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: fr.php,v 1.4 2003/03/11 02:56:48 pajoye Exp $
+// $Id: fr.php 119834 2003-03-11 02:56:48Z pajoye $
class I18N_Common_fr
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: fr_FR.php,v 1.2 2003/01/04 11:55:27 mj Exp $
+// $Id: fr_FR.php 110339 2003-01-04 11:55:29Z mj $
require_once 'I18N/Common/fr.php';
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Kovács Gergely <kgergely@dkgeast.hu> |
// +----------------------------------------------------------------------+
-// $Id: hu.php,v 1.2 2003/05/21 10:45:16 cain Exp $
+// $Id: hu.php 128187 2003-05-21 10:45:16Z cain $
class I18N_Common_hu
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+//
-// $Id: it.php,v 1.1 2003/01/07 17:36:27 cain Exp $
+// $Id: it.php 110934 2003-01-07 17:36:27Z cain $
class I18N_Common_it
{
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+//
-// $Id: it_IT.php,v 1.2 2003/01/07 17:42:57 cain Exp $
+// $Id: it_IT.php 110935 2003-01-07 17:42:57Z cain $
require_once('I18N/Common/it.php');
// | Authors: Jeroen Houben <jeroen@terena.nl> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: nl.php,v 1.1 2003/05/22 15:21:22 cain Exp $
+// $Id: nl.php 128415 2003-05-22 15:21:22Z cain $
class I18N_Common_nl
{
// | Authors: Jeroen Houben <jeroen@terena.nl> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: nl_NL.php,v 1.1 2003/05/22 15:21:22 cain Exp $
+// $Id: nl_NL.php 128415 2003-05-22 15:21:22Z cain $
require_once 'I18N/Common/nl.php';
// | Authors: Piotr Klaban <makler@man.torun.pl> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: pl.php,v 1.2 2003/01/04 11:55:27 mj Exp $
+// $Id: pl.php 110339 2003-01-04 11:55:29Z mj $
class I18N_Common_pl
{
-<?php\r
-// +----------------------------------------------------------------------+\r
-// | PHP version 4.0 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.0 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Authors: Wolfram Kriesing <wk@visionp.de> |\r
-// | Bruno Pedro <bpedro@co.sapo.pt> |\r
-// +----------------------------------------------------------------------+\r
-// $Id: pt.php,v 1.1 2003/05/21 10:35:10 cain Exp $\r
-\r
-class I18N_Common_pt\r
-{\r
- var $days = array('Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado');\r
-\r
- var $daysAbbreviated = array('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb');\r
-\r
- var $monthsAbbreviated = array('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez');\r
-\r
- var $months = array(\r
- 'Janeiro',\r
- 'Fevereiro',\r
- 'Março',\r
- 'Abril',\r
- 'Maio',\r
- 'Junho',\r
- 'Julho',\r
- 'Agosto',\r
- 'Setembro',\r
- 'Outubro',\r
- 'Novembro',\r
- 'Dezembro'\r
- );\r
-\r
- var $dateFormats = array(\r
- I18N_DATETIME_SHORT => 'd/m/y',\r
- I18N_DATETIME_DEFAULT => 'd-M-Y',\r
- I18N_DATETIME_MEDIUM => 'd-M-Y',\r
- I18N_DATETIME_LONG => 'd \d\e F \d\e Y',\r
- I18N_DATETIME_FULL => 'l, d \d\e F \d\e Y'\r
- );\r
- var $timeFormats = array(\r
- I18N_DATETIME_SHORT => 'H:i',\r
- I18N_DATETIME_DEFAULT => 'H:i:s',\r
- I18N_DATETIME_MEDIUM => 'H:i:s',\r
- I18N_DATETIME_LONG => 'H:i:s T O',\r
- I18N_DATETIME_FULL => 'H:i T O'\r
- );\r
-\r
- /**\r
- * the NUMBER stuff\r
- * @var array the same parameters as they have to be passed to the number_format-function\r
- */\r
- var $numberFormat = array(\r
- I18N_NUMBER_FLOAT => array('2',',','.'),\r
- I18N_NUMBER_INTEGER => array('0',',','.')\r
- );\r
-}\r
+<?php
+// +----------------------------------------------------------------------+
+// | PHP version 4.0 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 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: Wolfram Kriesing <wk@visionp.de> |
+// | Bruno Pedro <bpedro@co.sapo.pt> |
+// +----------------------------------------------------------------------+
+// $Id: pt.php 128185 2003-05-21 10:35:10Z cain $
+
+class I18N_Common_pt
+{
+ var $days = array('Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado');
+
+ var $daysAbbreviated = array('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb');
+
+ var $monthsAbbreviated = array('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez');
+
+ var $months = array(
+ 'Janeiro',
+ 'Fevereiro',
+ 'Março',
+ 'Abril',
+ 'Maio',
+ 'Junho',
+ 'Julho',
+ 'Agosto',
+ 'Setembro',
+ 'Outubro',
+ 'Novembro',
+ 'Dezembro'
+ );
+
+ var $dateFormats = array(
+ I18N_DATETIME_SHORT => 'd/m/y',
+ I18N_DATETIME_DEFAULT => 'd-M-Y',
+ I18N_DATETIME_MEDIUM => 'd-M-Y',
+ I18N_DATETIME_LONG => 'd \d\e F \d\e Y',
+ I18N_DATETIME_FULL => 'l, d \d\e F \d\e Y'
+ );
+ var $timeFormats = array(
+ I18N_DATETIME_SHORT => 'H:i',
+ I18N_DATETIME_DEFAULT => 'H:i:s',
+ I18N_DATETIME_MEDIUM => 'H:i:s',
+ I18N_DATETIME_LONG => 'H:i:s T O',
+ I18N_DATETIME_FULL => 'H:i T O'
+ );
+
+ /**
+ * the NUMBER stuff
+ * @var array the same parameters as they have to be passed to the number_format-function
+ */
+ var $numberFormat = array(
+ I18N_NUMBER_FLOAT => array('2',',','.'),
+ I18N_NUMBER_INTEGER => array('0',',','.')
+ );
+}
?>
\ No newline at end of file
-<?php\r
-// +----------------------------------------------------------------------+\r
-// | PHP version 4.0 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.0 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Authors: Antony Dovgal <tony2001@php.net> |\r
-// | |\r
-// +----------------------------------------------------------------------+//\r
-// $Id: ru.php,v 1.2 2003/05/20 12:10:50 cain Exp $\r
-\r
-class I18N_Common_ru\r
-{\r
- var $days = array( '÷ÏÓËÒÅÓÅÎØÅ' , 'ðÏÎÅÄÅÌØÎÉË' , '÷ÔÏÒÎÉË' , 'óÒÅÄÁ' , 'þÅÔ×ÅÒÇ' , 'ðÑÔÎÉÃÁ' , 'óÕÂÂÏÔÁ' );\r
-\r
- var $daysAbbreviated = array( '÷ÓË','ðÎÄ','÷ÔÒ','óÒÄ','þÔ×','ðÔÎ','óÕÂ');\r
-\r
- var $monthsAbbreviated = array( 'ñÎ×' , 'æÅ×' , 'íÁÒ' , 'áÐÒ' , 'íÁÊ' , 'éÀÎ' ,'éÀÌ' , 'á×Ç' , 'óÅÎ' , 'ïËÔ' , 'îÏÑ' , 'äÅË' );\r
-\r
- var $months = array(\r
- 'ñÎ×ÁÒÑ',\r
- 'æÅ×ÒÁÌÑ',\r
- 'íÁÒÔÁ',\r
- 'áÐÒÅÌÑ',\r
- 'íÁÑ',\r
- 'éÀÎÑ',\r
- 'éÀÌÑ',\r
- 'á×ÇÕÓÔÁ',\r
- 'óÅÎÔÑÂÒÑ',\r
- 'ïËÔÑÂÒÑ',\r
- 'îÏÑÂÒÑ',\r
- 'äÅËÁÂÒÑ'\r
- );\r
-\r
- var $dateFormats = array(\r
- I18N_DATETIME_SHORT => 'd/m/y',\r
- I18N_DATETIME_DEFAULT => 'd-M-Y',\r
- I18N_DATETIME_MEDIUM => 'd-M-Y',// ???? what shall medium look like????\r
- I18N_DATETIME_LONG => 'd F Y',\r
- I18N_DATETIME_FULL => 'l, d F Y'\r
- );\r
- var $timeFormats = array(\r
- I18N_DATETIME_SHORT => 'H:i',\r
- I18N_DATETIME_DEFAULT => 'H:i:s',\r
- I18N_DATETIME_MEDIUM => 'H:i:s', // ???? what shall medium look like????\r
- I18N_DATETIME_LONG => 'H:i:s T O',\r
- I18N_DATETIME_FULL => 'H:i \Þ\Á\Ó\Ï\× T O'\r
- ); \r
- \r
- /**\r
- * the NUMBER stuff\r
- * @var array the same parameters as they have to be passed to the number_format-funciton\r
- */\r
- var $numberFormat = array(\r
- I18N_NUMBER_FLOAT => array('3','.',','),\r
- I18N_NUMBER_INTEGER => array('0','.',','),\r
- );\r
- /**\r
- * @var array the first is the currency symbol, second is the international currency symbol\r
- */\r
- var $currencyFormats = array(\r
- I18N_CURRENCY_LOCAL => array( '% Ò.' , '2' , '.' , ',' ),\r
- I18N_CURRENCY_INTERNATIONAL => array( 'RUR %' , '2' , '.' , ',' )\r
- );\r
-\r
-}\r
-?>\r
+<?php
+// +----------------------------------------------------------------------+
+// | PHP version 4.0 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 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: Antony Dovgal <tony2001@php.net> |
+// | |
+// +----------------------------------------------------------------------+//
+// $Id: ru.php 127952 2003-05-20 12:10:50Z cain $
+
+class I18N_Common_ru
+{
+ var $days = array( '÷ÏÓËÒÅÓÅÎØÅ' , 'ðÏÎÅÄÅÌØÎÉË' , '÷ÔÏÒÎÉË' , 'óÒÅÄÁ' , 'þÅÔ×ÅÒÇ' , 'ðÑÔÎÉÃÁ' , 'óÕÂÂÏÔÁ' );
+
+ var $daysAbbreviated = array( '÷ÓË','ðÎÄ','÷ÔÒ','óÒÄ','þÔ×','ðÔÎ','óÕÂ');
+
+ var $monthsAbbreviated = array( 'ñÎ×' , 'æÅ×' , 'íÁÒ' , 'áÐÒ' , 'íÁÊ' , 'éÀÎ' ,'éÀÌ' , 'á×Ç' , 'óÅÎ' , 'ïËÔ' , 'îÏÑ' , 'äÅË' );
+
+ var $months = array(
+ 'ñÎ×ÁÒÑ',
+ 'æÅ×ÒÁÌÑ',
+ 'íÁÒÔÁ',
+ 'áÐÒÅÌÑ',
+ 'íÁÑ',
+ 'éÀÎÑ',
+ 'éÀÌÑ',
+ 'á×ÇÕÓÔÁ',
+ 'óÅÎÔÑÂÒÑ',
+ 'ïËÔÑÂÒÑ',
+ 'îÏÑÂÒÑ',
+ 'äÅËÁÂÒÑ'
+ );
+
+ var $dateFormats = array(
+ I18N_DATETIME_SHORT => 'd/m/y',
+ I18N_DATETIME_DEFAULT => 'd-M-Y',
+ I18N_DATETIME_MEDIUM => 'd-M-Y',// ???? what shall medium look like????
+ I18N_DATETIME_LONG => 'd F Y',
+ I18N_DATETIME_FULL => 'l, d F Y'
+ );
+ var $timeFormats = array(
+ I18N_DATETIME_SHORT => 'H:i',
+ I18N_DATETIME_DEFAULT => 'H:i:s',
+ I18N_DATETIME_MEDIUM => 'H:i:s', // ???? what shall medium look like????
+ I18N_DATETIME_LONG => 'H:i:s T O',
+ I18N_DATETIME_FULL => 'H:i \Þ\Á\Ó\Ï\× T O'
+ );
+
+ /**
+ * the NUMBER stuff
+ * @var array the same parameters as they have to be passed to the number_format-funciton
+ */
+ var $numberFormat = array(
+ I18N_NUMBER_FLOAT => array('3','.',','),
+ I18N_NUMBER_INTEGER => array('0','.',','),
+ );
+ /**
+ * @var array the first is the currency symbol, second is the international currency symbol
+ */
+ var $currencyFormats = array(
+ I18N_CURRENCY_LOCAL => array( '% Ò.' , '2' , '.' , ',' ),
+ I18N_CURRENCY_INTERNATIONAL => array( 'RUR %' , '2' , '.' , ',' )
+ );
+
+}
+?>
-<?php\r// +----------------------------------------------------------------------+\r// | PHP version 4.0 |\r// +----------------------------------------------------------------------+\r// | Copyright (c) 1997-2003 The PHP Group |\r// +----------------------------------------------------------------------+\r// | This source file is subject to version 2.0 of the PHP license, |\r// | that is bundled with this package in the file LICENSE, and is |\r// | available at through the world-wide-web at |\r// | http://www.php.net/license/2_02.txt. |\r// | If you did not receive a copy of the PHP license and are unable to |\r// | obtain it through the world-wide-web, please send a note to |\r// | license@php.net so we can mail you a copy immediately. |\r// +----------------------------------------------------------------------+\r// | Authors: Wolfram Kriesing <wk@visionp.de> |\r// | |\r// +----------------------------------------------------------------------+\r// $Id: sl.php,v 1.1 2003/05/20 13:17:23 cain Exp $\r\rclass I18N_Common_sl\r{\r\r var $days = array( 'Nedelja' , 'Ponedeljek' , 'Torek' , 'Sreda' , 'éetrtek' , 'Petek' , 'Sobota' );\r\r var $daysAbbreviated = array( 'Ned','Pon','Tor','Sre','éet','Pet','Sob');\r\r var $monthsAbbreviated = array( 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'Maj' , 'Jun' ,'Jul' , 'Avg' , 'Sep' , 'Okt' , 'Nov' , 'Dec' );\r\r var $months = array(\r 'Januar',\r 'Februar',\r 'Marc',\r 'April',\r 'Maj',\r 'Junij',\r 'Julij',\r 'Avgust',\r 'September',\r 'Oktober',\r 'November',\r 'December'\r );\r\r var $dateFormats = array(\r I18N_DATETIME_SHORT => 'd/m/y',\r I18N_DATETIME_DEFAULT => 'd.M.Y',\r I18N_DATETIME_MEDIUM => 'd.M.Y',\r I18N_DATETIME_LONG => 'd F Y',\r I18N_DATETIME_FULL => 'l, d F Y'\r );\r var $timeFormats = array(\r I18N_DATETIME_SHORT => 'H:i',\r I18N_DATETIME_DEFAULT => 'H:i:s',\r I18N_DATETIME_MEDIUM => 'H:i:s',\r I18N_DATETIME_LONG => 'H:i:s T O',\r I18N_DATETIME_FULL => 'H:i T O'\r ); \r \r /**\r * the NUMBER stuff\r * @var array the same parameters as they have to be passed to the number_format-funciton\r */\r var $numberFormat = array(\r I18N_NUMBER_FLOAT => array('3',' ','.'),\r I18N_NUMBER_INTEGER => array('0',' ','.'),\r );\r\r}\r?>\r\r
\ No newline at end of file
+<?php
+// +----------------------------------------------------------------------+
+// | PHP version 4.0 |
+// +----------------------------------------------------------------------+
+// | 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: Wolfram Kriesing <wk@visionp.de> |
+// | |
+// +----------------------------------------------------------------------+
+// $Id: sl.php 127965 2003-05-20 13:17:23Z cain $
+
+class I18N_Common_sl
+{
+
+ var $days = array( 'Nedelja' , 'Ponedeljek' , 'Torek' , 'Sreda' , 'éetrtek' , 'Petek' , 'Sobota' );
+
+ var $daysAbbreviated = array( 'Ned','Pon','Tor','Sre','éet','Pet','Sob');
+
+ var $monthsAbbreviated = array( 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'Maj' , 'Jun' ,'Jul' , 'Avg' , 'Sep' , 'Okt' , 'Nov' , 'Dec' );
+
+ var $months = array(
+ 'Januar',
+ 'Februar',
+ 'Marc',
+ 'April',
+ 'Maj',
+ 'Junij',
+ 'Julij',
+ 'Avgust',
+ 'September',
+ 'Oktober',
+ 'November',
+ 'December'
+ );
+
+ var $dateFormats = array(
+ I18N_DATETIME_SHORT => 'd/m/y',
+ I18N_DATETIME_DEFAULT => 'd.M.Y',
+ I18N_DATETIME_MEDIUM => 'd.M.Y',
+ I18N_DATETIME_LONG => 'd F Y',
+ I18N_DATETIME_FULL => 'l, d F Y'
+ );
+ var $timeFormats = array(
+ I18N_DATETIME_SHORT => 'H:i',
+ I18N_DATETIME_DEFAULT => 'H:i:s',
+ I18N_DATETIME_MEDIUM => 'H:i:s',
+ I18N_DATETIME_LONG => 'H:i:s T O',
+ I18N_DATETIME_FULL => 'H:i T O'
+ );
+
+ /**
+ * the NUMBER stuff
+ * @var array the same parameters as they have to be passed to the number_format-funciton
+ */
+ var $numberFormat = array(
+ I18N_NUMBER_FLOAT => array('3',' ','.'),
+ I18N_NUMBER_INTEGER => array('0',' ','.'),
+ );
+
+}
+?>
+
// | Authors: Naoki Shima <murahachibu@php.net> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Country.php,v 1.4 2003/01/04 11:55:23 mj Exp $
+// $Id: Country.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common.php');
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Currency.php,v 1.4 2003/01/28 11:19:35 cain Exp $
+// $Id: Currency.php 113734 2003-01-28 11:19:35Z cain $
require_once 'I18N/Number.php';
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: DateTime.php,v 1.11 2003/08/07 07:46:23 cain Exp $
+// $Id: DateTime.php 136857 2003-08-07 07:46:23Z cain $
require_once 'I18N/Format.php';
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Format.php,v 1.6 2003/07/07 12:50:43 cain Exp $
+// $Id: Format.php 134347 2003-07-07 12:50:43Z cain $
require_once 'PEAR.php';
// | Authors: Naoki Shima <murahachibu@php.net> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Language.php,v 1.2 2003/01/04 11:55:25 mj Exp $
+// $Id: Language.php 110339 2003-01-04 11:55:29Z mj $
require_once('I18N/Common.php');
// | Naoki Shima <naoki@avantexchange.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Common.php,v 1.13 2003/01/04 11:55:28 mj Exp $
+// $Id: Common.php 110339 2003-01-04 11:55:29Z mj $
//
/**
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Translate.php,v 1.13 2003/01/28 19:20:04 cain Exp $
+// $Id: Translate.php 113824 2003-01-28 19:20:04Z cain $
// we have to move this to some more common place in PEAR
// this is just a quick hack here :-)
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
//
-// $Id: determineLanguage.inc.php,v 1.4 2003/01/04 11:55:28 mj Exp $
+// $Id: determineLanguage.inc.php 110339 2003-01-04 11:55:29Z mj $
// we make it very simple for now,
// this should be done using a db one day, either one that "learns" or one which is already a huge dictionary
// | Authors: Naoki Shima <murahachibu@php.net> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Negotiator.php,v 1.4 2003/01/04 11:55:25 mj Exp $
+// $Id: Negotiator.php 110339 2003-01-04 11:55:29Z mj $
/**
*
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | |
// +----------------------------------------------------------------------+//
-// $Id: Number.php,v 1.5 2003/04/09 10:51:11 cain Exp $
+// $Id: Number.php 145353 2003-12-01 23:05:56Z cain $
require_once 'I18N/Format.php';
$format = $this->getFormat();
}
- // normally this is used
- $numberFormat = $this->_localeObj->numberFormat[$format];
// handle custom formats too
if ($format >= I18N_CUSTOM_FORMATS_OFFSET) {
if (isset($this->_customFormats[$format])) {
$numberFormat = $this->_customFormats[$format];
}
+ } else {
+ $numberFormat = $this->_localeObj->numberFormat[$format];
}
return call_user_func_array( 'number_format' , array_merge( array($number),$numberFormat) );
}
* @param string $locale The locale to use.
* @param bool $paranoid Whether to operate in paranoid mode.
*/
- function createLocale($locale = null, $paranoid = false)
+ function &createLocale($locale = null, $paranoid = false)
{
require_once 'I18Nv2/Locale.php';
- $obj = new I18Nv2_Locale($locale, $paranoid);
+ $obj = &new I18Nv2_Locale($locale, $paranoid);
return $obj;
}
* @param string $defEnc default encoding
* @param string $defCtry default country
*/
- function createNegotiator($defLang = 'en', $defEnc = 'iso-8859-1', $defCtry = '')
+ function &createNegotiator($defLang = 'en', $defEnc = 'iso-8859-1', $defCtry = '')
{
require_once 'I18Nv2/Negotiator.php';
- $obj = new I18Nv2_Negotiator($defLang, $defEnc, $defCtry);
+ $obj = &new I18Nv2_Negotiator($defLang, $defEnc, $defCtry);
return $obj;
}
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Canvas based creation of images to facilitate different output formats\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Canvas.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Specfies the path to the system location of font files.\r
- *\r
- * Remember trailing slash!\r
- *\r
- * This is set by default on Windows systems to %SystemRoot%\Fonts\\r
- */\r
-if (!defined('IMAGE_CANVAS_SYSTEM_FONT_PATH')) {\r
- if (isset($_SERVER['SystemRoot'])) {\r
- define('IMAGE_CANVAS_SYSTEM_FONT_PATH', $_SERVER['SystemRoot'] . '/Fonts/');\r
- } else {\r
- /**\r
- * @ignore\r
- */\r
- define('IMAGE_CANVAS_SYSTEM_FONT_PATH', '');\r
- }\r
-}\r
-\r
-/**\r
- * Class for handling different output formats\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- * @abstract\r
- */\r
-class Image_Canvas\r
-{\r
-\r
- /**\r
- * The leftmost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_left = 0;\r
-\r
- /**\r
- * The topmost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_top = 0;\r
-\r
- /**\r
- * The width of the graph\r
- * @var int\r
- * @access private\r
- */\r
- var $_width = 0;\r
-\r
- /**\r
- * The height of the graph\r
- * @var int\r
- * @access private\r
- */\r
- var $_height = 0;\r
-\r
- /**\r
- * Polygon vertex placeholder\r
- * @var array\r
- * @access private\r
- */\r
- var $_polygon = array();\r
-\r
- /**\r
- * The thickness of the line(s)\r
- * @var int\r
- * @access private\r
- */\r
- var $_thickness = 1;\r
-\r
- /**\r
- * The line style\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_lineStyle = 'transparent';\r
-\r
- /**\r
- * The fill style\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_fillStyle = 'transparent';\r
-\r
- /**\r
- * The font options\r
- * @var array\r
- * @access private\r
- */\r
- var $_font = array();\r
-\r
- /**\r
- * The default font\r
- * @var array\r
- * @access private\r
- */\r
- var $_defaultFont = array('name' => 'Courier New', 'color' => 'black', 'size' => 9);\r
-\r
- /**\r
- * Create the canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'width' The width of the graph on the canvas\r
- *\r
- * 'height' The height of the graph on the canvas\r
- *\r
- * 'left' The left offset of the graph on the canvas\r
- *\r
- * 'top' The top offset of the graph on the canvas\r
- *\r
- * @param array $params Parameter array\r
- * @abstract\r
- */\r
- function Image_Canvas($params)\r
- {\r
- if (isset($params['left'])) {\r
- $this->_left = $params['left'];\r
- }\r
-\r
- if (isset($params['top'])) {\r
- $this->_top = $params['top'];\r
- }\r
-\r
- if (isset($params['width'])) {\r
- $this->_width = $params['width'];\r
- }\r
-\r
- if (isset($params['height'])) {\r
- $this->_height = $params['height'];\r
- }\r
- \r
- $this->setDefaultFont($this->_defaultFont);\r
- }\r
-\r
- /**\r
- * Get the x-point from the relative to absolute coordinates\r
- *\r
- * @param float $x The relative x-coordinate (in percentage of total width)\r
- * @return float The x-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getX($x)\r
- {\r
- return floor($this->_left + $x);\r
- }\r
-\r
- /**\r
- * Get the y-point from the relative to absolute coordinates\r
- *\r
- * @param float $y The relative y-coordinate (in percentage of total width)\r
- * @return float The y-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getY($y)\r
- {\r
- return floor($this->_top + $y);\r
- }\r
-\r
- /**\r
- * Get the width of the canvas\r
- *\r
- * @return int The width\r
- */\r
- function getWidth()\r
- {\r
- return $this->_width;\r
- }\r
-\r
- /**\r
- * Get the height of the canvas\r
- *\r
- * @return int The height\r
- */\r
- function getHeight()\r
- {\r
- return $this->_height;\r
- }\r
-\r
- /**\r
- * Sets the thickness of the line(s) to be drawn\r
- *\r
- * @param int $thickness The actual thickness (in pixels)\r
- */\r
- function setLineThickness($thickness)\r
- {\r
- $this->_thickness = $thickness;\r
- }\r
-\r
- /**\r
- * Sets the color of the line(s) to be drawn\r
- *\r
- * @param mixed $color The color of the line\r
- */\r
- function setLineColor($color)\r
- {\r
- $this->_lineStyle = $color;\r
- }\r
-\r
- /**\r
- * Sets the style of the filling of drawn objects.\r
- *\r
- * This method gives simple access to setFillColor(), setFillImage() and\r
- * setGradientFill()\r
- *\r
- * @param mixed $fill The fill style\r
- */\r
- function setFill($fill)\r
- {\r
- if (is_array($fill)) {\r
- $this->setGradientFill($fill);\r
- } elseif (file_exists($fill)) {\r
- $this->setFillImage($fill);\r
- } else {\r
- $this->setFillColor($fill);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the color of the filling of drawn objects\r
- *\r
- * @param mixed $color The fill color\r
- */\r
- function setFillColor($color)\r
- {\r
- $this->_fillStyle = $color;\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling\r
- *\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- }\r
-\r
- /**\r
- * Sets a gradient fill\r
- *\r
- * @param array $gradient Gradient fill options\r
- */\r
- function setGradientFill($gradient)\r
- {\r
- $this->_fillStyle = $gradient;\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- *\r
- * 'name' The name of the font. This name must either be supported\r
- * natively by the canvas or mapped to a font using the font-mapping scheme\r
- *\r
- * 'size' Size in pixels\r
- *\r
- * 'angle' The angle with which to write the text\r
- *\r
- * @param array $fontOptions The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- $this->_font = $fontOptions;\r
-\r
- if (!isset($this->_font['color'])) {\r
- $this->_font['color'] = 'black';\r
- }\r
-\r
- if (!(isset($this->_font['angle'])) || ($this->_font['angle'] === false)) {\r
- $this->_font['angle'] = 0;\r
- }\r
- \r
- if (isset($this->_font['angle'])) {\r
- if ((($this->_font['angle'] > 45) && ($this->_font['angle'] < 135)) ||\r
- (($this->_font['angle'] > 225) && ($this->_font['angle'] < 315))\r
- ) {\r
- $this->_font['vertical'] = true;\r
- }\r
- }\r
- \r
- if ((!isset($this->_font['file'])) && (isset($this->_font['name']))) {\r
- include_once 'Image/Canvas/Tool.php';\r
- $this->_font['file'] = Image_Canvas_Tool::fontMap($this->_font['name']);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the default font options.\r
- *\r
- * The $font array may have the following entries:\r
- *\r
- * 'name' The name of the font. This name must either be supported\r
- * natively by the canvas or mapped to a font using the font-mapping scheme\r
- *\r
- * 'size' Size in pixels\r
- *\r
- * 'angle' The angle with which to write the text\r
- *\r
- * @param array $fontOptions The font options.\r
- */\r
- function setDefaultFont($fontOptions)\r
- {\r
- $this->setFont($fontOptions);\r
- $this->_defaultFont = $this->_font;\r
- }\r
-\r
- /**\r
- * Resets the canvas.\r
- *\r
- * Includes fillstyle, linestyle, thickness and polygon\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- $this->_lineStyle = false;\r
- $this->_fillStyle = false;\r
- $this->_thickness = 1;\r
- $this->_polygon = array();\r
- $this->_font = $this->_defaultFont;\r
- }\r
- \r
- /**\r
- * Reset the canvas.\r
- *\r
- * Includes fillstyle, linestyle, thickness and polygon\r
- */\r
- function reset() \r
- {\r
- $this->_reset();\r
- }\r
- \r
- /**\r
- * Draw a line end\r
- *\r
- * Parameter array:\r
- * 'x': int X point\r
- * 'y': int Y point\r
- * 'end': string The end type of the end\r
- * 'angle': int [optional] The angle with which to draw the end\r
- * @param array $params Parameter array\r
- */\r
- function drawEnd($params) \r
- { \r
- }\r
-\r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'end0': string [optional] The end type of end0 (the start)\r
- * 'end1': string [optional] The end type of end1 (the end)\r
- * 'size0': int [optional] The size of end0\r
- * 'size1': int [optional] The size of end1\r
- * 'color': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- if (isset($params['end0'])) {\r
- $angle = Image_Canvas_Tool::getAngle($x1, $y1, $x0, $y0);\r
- $this->drawEnd(\r
- array(\r
- 'end' => $params['end0'], \r
- 'x' => $params['x0'], \r
- 'y' => $params['y0'], \r
- 'angle' => $angle,\r
- 'color' => (isset($params['color0']) ? $params['color0'] : false),\r
- 'size' => $params['size0']\r
- )\r
- );\r
- } \r
- if (isset($params['end1'])) {\r
- $angle = Image_Canvas_Tool::getAngle($x0, $y0, $x1, $y1);\r
- //print "<pre>"; var_dump($params, $angle); print "</pre>";\r
- $this->drawEnd(\r
- array(\r
- 'end' => $params['end1'], \r
- 'x' => $params['x1'], \r
- 'y' => $params['y1'], \r
- 'angle' => $angle,\r
- 'color' => (isset($params['color1']) ? $params['color1'] : false),\r
- 'size' => $params['size1']\r
- )\r
- );\r
- } \r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Adds vertex to a polygon\r
- *\r
- * Parameter array:\r
- * 'x': int X point\r
- * 'y': int Y point\r
- * 'url': string [optional] URL to link the vertex to (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'alt': string [optional] Alternative text to show in the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'target': string [optional] The link target on the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'mapsize': int [optional] The size of the "map", i.e. the size of the hot spot (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * @param array $params Parameter array\r
- */\r
- function addVertex($params)\r
- {\r
- $params['X'] = $this->_getX($params['x']);\r
- $params['Y'] = $this->_getY($params['y']);\r
- $this->_polygon[] = $params;\r
- }\r
-\r
- /**\r
- * Adds "splined" vertex to a polygon\r
- *\r
- * Parameter array:\r
- * 'x': int X point\r
- * 'y': int Y point\r
- * 'p1x': int X Control point 1\r
- * 'p1y': int Y Control point 1\r
- * 'p2x': int X Control point 2\r
- * 'p2y': int Y Control point 2\r
- * 'url': string [optional] URL to link the vertex to (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'alt': string [optional] Alternative text to show in the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'target': string [optional] The link target on the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * 'mapsize': int [optional] The size of the "map", i.e. the size of the hot spot (must be used with 'map_vertices' in polygon() on a canvas that support image maps)\r
- * @param array $params Parameter array\r
- */\r
- function addSpline($params)\r
- {\r
- $params['X'] = $this->_getX($params['x']);\r
- $params['Y'] = $this->_getY($params['y']);\r
- $params['P1X'] = $this->_getX($params['p1x']);\r
- $params['P1Y'] = $this->_getY($params['p1y']);\r
- $params['P2X'] = $this->_getX($params['p2x']);\r
- $params['P2Y'] = $this->_getY($params['p2y']);\r
- $this->_polygon[] = $params;\r
- }\r
-\r
- /**\r
- * Draws a polygon\r
- *\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params)\r
- {\r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- }\r
-\r
- /**\r
- * Get the height of a text,\r
- *\r
- * @param string $text The text to get the height of\r
- * @return int The height of the text\r
- */\r
- function textHeight($text)\r
- {\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of text\r
- * 'y': int Y-point of text\r
- * 'text': string The text to add\r
- * 'alignment': array [optional] Alignment\r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- $this->_reset();\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of overlayed image\r
- * 'y': int Y-point of overlayed image\r
- * 'filename': string The filename of the image to overlay\r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- }\r
- \r
- /**\r
- * Set clipping to occur\r
- * \r
- * Parameter array:\r
- * \r
- * 'x0': int X point of Upper-left corner\r
- * 'y0': int X point of Upper-left corner\r
- * 'x1': int X point of lower-right corner\r
- * 'y1': int Y point of lower-right corner\r
- */\r
- function setClipping($params = false) \r
- {\r
- } \r
-\r
- /**\r
- * Start a group.\r
- *\r
- * What this does, depends on the canvas/format.\r
- *\r
- * @param string $name The name of the group\r
- */\r
- function startGroup($name = false)\r
- {\r
- }\r
-\r
- /**\r
- * End the "current" group.\r
- *\r
- * What this does, depends on the canvas/format.\r
- */\r
- function endGroup()\r
- {\r
- } \r
-\r
- /**\r
- * Output the result of the canvas to the browser\r
- *\r
- * @param array $params Parameter array, the contents and meaning depends on the actual Canvas\r
- * @abstract\r
- */\r
- function show($params = false)\r
- {\r
- if ($params === false) {\r
- header('Expires: Tue, 2 Jul 1974 17:41:00 GMT'); // Date in the past\r
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified\r
- header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1\r
- header('Pragma: no-cache');\r
- }\r
- }\r
-\r
- /**\r
- * Save the result of the canvas to a file\r
- *\r
- * Parameter array:\r
- * 'filename': string The file to output to\r
- * @param array $params Parameter array, the contents and meaning depends on the actual Canvas\r
- * @abstract\r
- */\r
- function save($params = false)\r
- {\r
- }\r
-\r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * This method implicitly saves the canvas to the filename in the \r
- * filesystem path specified and parses it as URL specified by URL path\r
- * \r
- * Parameter array:\r
- * 'filename': string\r
- * 'filepath': string Path to the file on the file system. Remember the final slash\r
- * 'urlpath': string Path to the file available through an URL. Remember the final slash\r
- */\r
- function toHtml($params)\r
- {\r
- $this->save(array('filename' => $params['filepath'] . $params['filename'])); \r
- }\r
-\r
- /**\r
- * Canvas factory method.\r
- *\r
- * Supported canvass are:\r
- *\r
- * 'png': output in PNG format (using GD)\r
- *\r
- * 'jpg': output in JPEG format (using GD)\r
- *\r
- * 'pdf': output in PDF format (using PDFlib)\r
- *\r
- * 'ps': output in PostScript format (using pslib)\r
- *\r
- * 'svg': output in SVG format\r
- * \r
- * 'swf': output in SWF flash format (using ming extension)\r
- *\r
- * 'imagemap': output as a html image map\r
- *\r
- * An example of usage:\r
- * \r
- * <code>\r
- * <?php\r
- * $Canvas =& Image_Graph::factory('png', \r
- * array('width' => 800, 'height' => 600, 'antialias' => 'native')\r
- * );\r
- * ?>\r
- * </code>\r
- *\r
- * @param string $canvas The canvas type\r
- * @param array $params The parameters for the canvas constructor\r
- * @return Image_Canvas The newly created canvas or\r
- * PEAR_Error on error\r
- * @static\r
- */\r
- function &factory($canvas, $params)\r
- {\r
- $canvas = strtoupper($canvas);\r
- \r
- if (($canvas == 'PNG') || ($canvas == 'GD')) {\r
- $canvas = 'GD_PNG';\r
- }\r
- if (($canvas == 'JPG') || ($canvas == 'JPEG')) {\r
- $canvas = 'GD_JPG';\r
- }\r
- \r
- if ($canvas == 'SWF') {\r
- // return PEAR_Error object if ming extension is not installed\r
- if (!extension_loaded('ming')) {\r
-\r
- require_once 'PEAR.php';\r
-\r
- $error = 'PHP extension ming is required for output in swf format.';\r
- $error .= 'Please install the ming extension (http://de.php.net/ming).';\r
- $error =& new PEAR_Error($error);\r
- return $error;\r
- }\r
- }\r
-\r
- if ($canvas == 'IMAGEMAP') {\r
- $canvas = 'ImageMap';\r
- }\r
-\r
- $class = 'Image_Canvas_'. $canvas;\r
- include_once 'Image/Canvas/'. str_replace('_', '/', $canvas) . '.php';\r
- \r
- $obj =& new $class($params);\r
- return $obj;\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Canvas based creation of images to facilitate different output formats
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Canvas.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Specfies the path to the system location of font files.
+ *
+ * Remember trailing slash!
+ *
+ * This is set by default on Windows systems to %SystemRoot%\Fonts\
+ */
+if (!defined('IMAGE_CANVAS_SYSTEM_FONT_PATH')) {
+ if (isset($_SERVER['SystemRoot'])) {
+ define('IMAGE_CANVAS_SYSTEM_FONT_PATH', $_SERVER['SystemRoot'] . '/Fonts/');
+ } else {
+ /**
+ * @ignore
+ */
+ define('IMAGE_CANVAS_SYSTEM_FONT_PATH', '');
+ }
+}
+
+/**
+ * Class for handling different output formats
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ * @abstract
+ */
+class Image_Canvas
+{
+
+ /**
+ * The leftmost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_left = 0;
+
+ /**
+ * The topmost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_top = 0;
+
+ /**
+ * The width of the graph
+ * @var int
+ * @access private
+ */
+ var $_width = 0;
+
+ /**
+ * The height of the graph
+ * @var int
+ * @access private
+ */
+ var $_height = 0;
+
+ /**
+ * Polygon vertex placeholder
+ * @var array
+ * @access private
+ */
+ var $_polygon = array();
+
+ /**
+ * The thickness of the line(s)
+ * @var int
+ * @access private
+ */
+ var $_thickness = 1;
+
+ /**
+ * The line style
+ * @var mixed
+ * @access private
+ */
+ var $_lineStyle = 'transparent';
+
+ /**
+ * The fill style
+ * @var mixed
+ * @access private
+ */
+ var $_fillStyle = 'transparent';
+
+ /**
+ * The font options
+ * @var array
+ * @access private
+ */
+ var $_font = array();
+
+ /**
+ * The default font
+ * @var array
+ * @access private
+ */
+ var $_defaultFont = array('name' => 'Courier New', 'color' => 'black', 'size' => 9);
+
+ /**
+ * Create the canvas.
+ *
+ * Parameters available:
+ *
+ * 'width' The width of the graph on the canvas
+ *
+ * 'height' The height of the graph on the canvas
+ *
+ * 'left' The left offset of the graph on the canvas
+ *
+ * 'top' The top offset of the graph on the canvas
+ *
+ * @param array $params Parameter array
+ *
+ * @abstract
+ */
+ function Image_Canvas($params)
+ {
+ if (isset($params['left'])) {
+ $this->_left = $params['left'];
+ }
+
+ if (isset($params['top'])) {
+ $this->_top = $params['top'];
+ }
+
+ if (isset($params['width'])) {
+ $this->_width = $params['width'];
+ }
+
+ if (isset($params['height'])) {
+ $this->_height = $params['height'];
+ }
+
+ $this->setDefaultFont($this->_defaultFont);
+ }
+
+ /**
+ * Get the x-point from the relative to absolute coordinates
+ *
+ * @param float $x The relative x-coordinate (in percentage of total width)
+ *
+ * @return float The x-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getX($x)
+ {
+ return floor($this->_left + $x);
+ }
+
+ /**
+ * Get the y-point from the relative to absolute coordinates
+ *
+ * @param float $y The relative y-coordinate (in percentage of total width)
+ *
+ * @return float The y-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getY($y)
+ {
+ return floor($this->_top + $y);
+ }
+
+ /**
+ * Get the width of the canvas
+ *
+ * @return int The width
+ */
+ function getWidth()
+ {
+ return $this->_width;
+ }
+
+ /**
+ * Get the height of the canvas
+ *
+ * @return int The height
+ */
+ function getHeight()
+ {
+ return $this->_height;
+ }
+
+ /**
+ * Sets the thickness of the line(s) to be drawn
+ *
+ * @param int $thickness The actual thickness (in pixels)
+ *
+ * @return void
+ */
+ function setLineThickness($thickness)
+ {
+ $this->_thickness = $thickness;
+ }
+
+ /**
+ * Sets the color of the line(s) to be drawn
+ *
+ * @param mixed $color The color of the line
+ *
+ * @return void
+ */
+ function setLineColor($color)
+ {
+ $this->_lineStyle = $color;
+ }
+
+ /**
+ * Sets the style of the filling of drawn objects.
+ *
+ * This method gives simple access to setFillColor(), setFillImage() and
+ * setGradientFill()
+ *
+ * @param mixed $fill The fill style
+ *
+ * @return void
+ */
+ function setFill($fill)
+ {
+ if (is_array($fill)) {
+ $this->setGradientFill($fill);
+ } elseif (file_exists($fill)) {
+ $this->setFillImage($fill);
+ } else {
+ $this->setFillColor($fill);
+ }
+ }
+
+ /**
+ * Sets the color of the filling of drawn objects
+ *
+ * @param mixed $color The fill color
+ *
+ * @return void
+ */
+ function setFillColor($color)
+ {
+ $this->_fillStyle = $color;
+ }
+
+ /**
+ * Sets an image that should be used for filling
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ }
+
+ /**
+ * Sets a gradient fill
+ *
+ * @param array $gradient Gradient fill options
+ *
+ * @return void
+ */
+ function setGradientFill($gradient)
+ {
+ $this->_fillStyle = $gradient;
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ *
+ * 'name' The name of the font. This name must either be supported
+ * natively by the canvas or mapped to a font using the font-mapping scheme
+ *
+ * 'size' Size in pixels
+ *
+ * 'angle' The angle with which to write the text
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ $this->_font = $fontOptions;
+
+ if (!isset($this->_font['color'])) {
+ $this->_font['color'] = 'black';
+ }
+
+ if (!(isset($this->_font['angle'])) || ($this->_font['angle'] === false)) {
+ $this->_font['angle'] = 0;
+ }
+
+ if (isset($this->_font['angle'])) {
+ if ((($this->_font['angle'] > 45) && ($this->_font['angle'] < 135))
+ || (($this->_font['angle'] > 225) && ($this->_font['angle'] < 315))
+ ) {
+ $this->_font['vertical'] = true;
+ }
+ }
+
+ if ((!isset($this->_font['file'])) && (isset($this->_font['name']))) {
+ include_once 'Image/Canvas/Tool.php';
+ $this->_font['file'] = Image_Canvas_Tool::fontMap($this->_font['name']);
+ }
+ }
+
+ /**
+ * Sets the default font options.
+ *
+ * The $font array may have the following entries:
+ *
+ * 'name' The name of the font. This name must either be supported
+ * natively by the canvas or mapped to a font using the font-mapping scheme
+ *
+ * 'size' Size in pixels
+ *
+ * 'angle' The angle with which to write the text
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setDefaultFont($fontOptions)
+ {
+ $this->setFont($fontOptions);
+ $this->_defaultFont = $this->_font;
+ }
+
+ /**
+ * Resets the canvas.
+ *
+ * Includes fillstyle, linestyle, thickness and polygon
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ $this->_lineStyle = false;
+ $this->_fillStyle = false;
+ $this->_thickness = 1;
+ $this->_polygon = array();
+ $this->_font = $this->_defaultFont;
+ }
+
+ /**
+ * Reset the canvas.
+ *
+ * Includes fillstyle, linestyle, thickness and polygon
+ *
+ * @return void
+ */
+ function reset()
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Draw a line end
+ *
+ * Parameter array:
+ * 'x': int X point
+ * 'y': int Y point
+ * 'end': string The end type of the end
+ * 'angle': int [optional] The angle with which to draw the end
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function drawEnd($params)
+ {
+ }
+
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'end0': string [optional] The end type of end0 (the start)
+ * 'end1': string [optional] The end type of end1 (the end)
+ * 'size0': int [optional] The size of end0
+ * 'size1': int [optional] The size of end1
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ if (isset($params['end0'])) {
+ $angle = Image_Canvas_Tool::getAngle($x1, $y1, $x0, $y0);
+ $this->drawEnd(
+ array(
+ 'end' => $params['end0'],
+ 'x' => $params['x0'],
+ 'y' => $params['y0'],
+ 'angle' => $angle,
+ 'color' => (isset($params['color0']) ? $params['color0'] : false),
+ 'size' => $params['size0']
+ )
+ );
+ }
+ if (isset($params['end1'])) {
+ $angle = Image_Canvas_Tool::getAngle($x0, $y0, $x1, $y1);
+ //print "<pre>"; var_dump($params, $angle); print "</pre>";
+ $this->drawEnd(
+ array(
+ 'end' => $params['end1'],
+ 'x' => $params['x1'],
+ 'y' => $params['y1'],
+ 'angle' => $angle,
+ 'color' => (isset($params['color1']) ? $params['color1'] : false),
+ 'size' => $params['size1']
+ )
+ );
+ }
+ $this->_reset();
+ }
+
+ /**
+ * Adds vertex to a polygon
+ *
+ * Parameter array:
+ * 'x': int X point
+ * 'y': int Y point
+ * 'url': string [optional] URL to link the vertex to (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'alt': string [optional] Alternative text to show in the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'target': string [optional] The link target on the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'mapsize': int [optional] The size of the "map", i.e. the size of the hot spot (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addVertex($params)
+ {
+ $params['X'] = $this->_getX($params['x']);
+ $params['Y'] = $this->_getY($params['y']);
+ $this->_polygon[] = $params;
+ }
+
+ /**
+ * Adds "splined" vertex to a polygon
+ *
+ * Parameter array:
+ * 'x': int X point
+ * 'y': int Y point
+ * 'p1x': int X Control point 1
+ * 'p1y': int Y Control point 1
+ * 'p2x': int X Control point 2
+ * 'p2y': int Y Control point 2
+ * 'url': string [optional] URL to link the vertex to (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'alt': string [optional] Alternative text to show in the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'target': string [optional] The link target on the image map (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ * 'mapsize': int [optional] The size of the "map", i.e. the size of the hot spot (must be used with 'map_vertices' in polygon() on a canvas that support image maps)
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addSpline($params)
+ {
+ $params['X'] = $this->_getX($params['x']);
+ $params['Y'] = $this->_getY($params['y']);
+ $params['P1X'] = $this->_getX($params['p1x']);
+ $params['P1Y'] = $this->_getY($params['p1y']);
+ $params['P2X'] = $this->_getX($params['p2x']);
+ $params['P2Y'] = $this->_getY($params['p2y']);
+ $this->_polygon[] = $params;
+ }
+
+ /**
+ * Draws a polygon
+ *
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params)
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ }
+
+ /**
+ * Get the height of a text,
+ *
+ * @param string $text The text to get the height of
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text)
+ {
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x': int X-point of text
+ * 'y': int Y-point of text
+ * 'text': string The text to add
+ * 'alignment': array [optional] Alignment
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ $this->_reset();
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x': int X-point of overlayed image
+ * 'y': int Y-point of overlayed image
+ * 'filename': string The filename of the image to overlay
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ }
+
+ /**
+ * Set clipping to occur
+ *
+ * Parameter array:
+ *
+ * 'x0': int X point of Upper-left corner
+ * 'y0': int X point of Upper-left corner
+ * 'x1': int X point of lower-right corner
+ * 'y1': int Y point of lower-right corner
+ *
+ * @param array $params Parameter array (x0, y0, x1, y1)
+ *
+ * @return void
+ */
+ function setClipping($params = false)
+ {
+ }
+
+ /**
+ * Start a group.
+ *
+ * What this does, depends on the canvas/format.
+ *
+ * @param string $name The name of the group
+ *
+ * @return void
+ */
+ function startGroup($name = false)
+ {
+ }
+
+ /**
+ * End the "current" group.
+ *
+ * What this does, depends on the canvas/format.
+ *
+ * @return void
+ */
+ function endGroup()
+ {
+ }
+
+ /**
+ * Output the result of the canvas to the browser
+ *
+ * @param array $params Parameter array, the contents and meaning depends on the actual Canvas
+ *
+ * @return void
+ * @abstract
+ */
+ function show($params = false)
+ {
+ if ($params === false) {
+ header('Expires: Tue, 2 Jul 1974 17:41:00 GMT'); // Date in the past
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
+ header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1
+ header('Pragma: no-cache');
+ }
+ }
+
+ /**
+ * Save the result of the canvas to a file
+ *
+ * Parameter array:
+ * 'filename': string The file to output to
+ *
+ * @param array $params Parameter array, the contents and meaning depends on the actual Canvas
+ *
+ * @return void
+ * @abstract
+ */
+ function save($params = false)
+ {
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ * 'filename': string
+ * 'filepath': string Path to the file on the file system. Remember the final slash
+ * 'urlpath': string Path to the file available through an URL. Remember the final slash
+ *
+ * @param array $params Parameter array (filename, filepath, urlpath)
+ *
+ * @return void
+ */
+ function toHtml($params)
+ {
+ $this->save(array('filename' => $params['filepath'] . $params['filename']));
+ }
+
+ /**
+ * Canvas factory method.
+ *
+ * Supported canvass are:
+ *
+ * 'png': output in PNG format (using GD)
+ *
+ * 'jpg': output in JPEG format (using GD)
+ *
+ * 'pdf': output in PDF format (using PDFlib)
+ *
+ * 'ps': output in PostScript format (using pslib)
+ *
+ * 'svg': output in SVG format
+ *
+ * 'swf': output in SWF flash format (using ming extension)
+ *
+ * 'imagemap': output as a html image map
+ *
+ * An example of usage:
+ *
+ * <code>
+ * <?php
+ * $Canvas =& Image_Graph::factory('png',
+ * array('width' => 800, 'height' => 600, 'antialias' => 'native')
+ * );
+ * ?>
+ * </code>
+ *
+ * @param string $canvas The canvas type
+ * @param array $params The parameters for the canvas constructor
+ *
+ * @return Image_Canvas The newly created canvas or
+ * PEAR_Error on error
+ * @static
+ */
+ function &factory($canvas, $params)
+ {
+ $canvas = strtoupper($canvas);
+
+ if (($canvas == 'PNG') || ($canvas == 'GD')) {
+ $canvas = 'GD_PNG';
+ }
+ if (($canvas == 'JPG') || ($canvas == 'JPEG')) {
+ $canvas = 'GD_JPG';
+ }
+
+ if ($canvas == 'SWF') {
+ // return PEAR_Error object if ming extension is not installed
+ if (!extension_loaded('ming')) {
+
+ include_once 'PEAR.php';
+
+ $error = 'PHP extension ming is required for output in swf format.';
+ $error .= 'Please install the ming extension (http://de.php.net/ming).';
+ $error = new PEAR_Error($error);
+ return $error;
+ }
+ }
+
+ if ($canvas == 'IMAGEMAP') {
+ $canvas = 'ImageMap';
+ }
+
+ $class = 'Image_Canvas_'. $canvas;
+ include_once 'Image/Canvas/'. str_replace('_', '/', $canvas) . '.php';
+
+ $obj = new $class($params);
+ return $obj;
+ }
+
+}
+
+?>
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4: */\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> |\r
-// +----------------------------------------------------------------------+\r
-//\r
-// $Id: Color.php 287471 2009-08-18 23:12:01Z clockwerx $\r
-\r
-/**\r
-* Class for color-handling\r
-*\r
-* @author Stefan Neufeind <pear.neufeind@speedpartner.de>\r
-* @package Image_Canvas\r
-* @category images\r
-* @license The PHP License, version 2.02\r
-*/\r
-\r
-/**\r
-* Color class to be extended; from package PEAR::Image_Color\r
-*/\r
-require_once 'Image/Color.php';\r
-\r
-/**\r
-* Class for color-handling\r
-*\r
-* This is used to extend the functionality of the current PEAR::Image_Color v0.4.\r
-* I hope to be allowed to incorporate some of the improvements in a new Image_Color release.\r
-*\r
-* @author Stefan Neufeind <pear.neufeind@speedpartner.de>\r
-* @package Image_Canvas\r
-* @access public\r
-*/\r
-class Image_Canvas_Color extends Image_Color\r
-{\r
- /**\r
- * Allocates a color in the given image.\r
- *\r
- * Userdefined color specifications get translated into\r
- * an array of rgb values.\r
- *\r
- * @param resource GD-resource\r
- * @param mixed any color representation supported by color2RGB()\r
- * @return resource Image color handle\r
- * @see color2RGB()\r
- * @access public\r
- * @static\r
- */\r
- function allocateColor(&$img, $color)\r
- {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
-\r
- if (($color[3] == 255) || (!function_exists("imagecolorallocatealpha"))) {\r
- return imagecolorallocate($img, $color[0], $color[1], $color[2]);\r
- } else {\r
- return imagecolorallocatealpha($img, $color[0], $color[1], $color[2], 127-round(($color[3]*127)/255));\r
- }\r
- }\r
-\r
- /**\r
- * Convert any color-representation into an array of 4 ints (RGBA).\r
- *\r
- * Userdefined color specifications get translated into\r
- * an array of rgb values.\r
- *\r
- * @param mixed any color representation supported by Image_Canvas_Color::color2RGB()\r
- * @return array Array of 4 ints (RGBA-representation)\r
- * @access public\r
- * @static\r
- */\r
- function color2RGB($color)\r
- {\r
- if (is_array($color)) {\r
- if (!is_numeric($color[0])) {\r
- return null; // error\r
- }\r
- if (count($color) == 3) { // assume RGB-color\r
-\r
- // 255 = alpha-value; full opaque\r
- return array((int) $color[0],\r
- (int) $color[1],\r
- (int) $color[2],\r
- 255);\r
- }\r
- if (count($color) == 4) { // assume RGBA-color\r
-\r
- // 255 = alpha-value; full opaque\r
- return array((int) $color[0],\r
- (int) $color[1],\r
- (int) $color[2],\r
- (int) $color[3]);\r
- }\r
- return null; // error\r
- } elseif (is_string($color)) {\r
- $alphaPos = strpos($color, '@');\r
- if ($alphaPos === false) {\r
- $alpha = 255;\r
- } else {\r
- $alphaFloat = (float) substr($color, $alphaPos+1);\r
- // restrict to range 0..1\r
- $alphaFloat = max(min($alphaFloat, 1), 0);\r
- $alpha = (int) round((float) 255 * $alphaFloat);\r
- $color = substr($color, 0, $alphaPos);\r
- }\r
- if ($color[0] == '#') { // hex-color given, e.g. #FFB4B4\r
- $tempColor = parent::hex2rgb($color);\r
- return array((int) $tempColor[0],\r
- (int) $tempColor[1],\r
- (int) $tempColor[2],\r
- $alpha);\r
- }\r
- if (strpos($color,'%') !== false) {\r
- $tempColor = parent::percentageColor2RGB($color);\r
- return array((int) $tempColor[0],\r
- (int) $tempColor[1],\r
- (int) $tempColor[2],\r
- $alpha);\r
- } else {\r
- $tempColor = parent::namedColor2RGB($color);\r
- return array((int) $tempColor[0],\r
- (int) $tempColor[1],\r
- (int) $tempColor[2],\r
- $alpha);\r
- }\r
- } else {\r
- return null; // error\r
- }\r
- }\r
-\r
- /**\r
- * getRange\r
- * Given a degree, you can get the range of colors between one color and\r
- * another color.\r
- *\r
- * @access public\r
- * @param string How much each 'step' between the colors we should take.\r
- * @return array Returns an array of all the colors, one element for each color.\r
- */\r
- function getRange ($degrees)\r
- {\r
- $tempColors = parent::getRange($degrees);\r
-\r
- // now add alpha-channel information\r
- $steps = count($tempColors);\r
- for($counter=0;$counter<$steps;$counter++) {\r
- $tempColors[$counter] = parent::hex2rgb($tempColors[$counter]);\r
- unset($tempColors[$counter]['hex']);\r
- $tempColors[$counter][3] = (int) round(\r
- (((float) $this->color1[3]*($steps-$counter))+\r
- ((float) $this->color2[3]*($counter))\r
- ) / $steps\r
- );\r
- }\r
-\r
- return $tempColors;\r
- }\r
-\r
- /**\r
- * Internal method to correctly set the colors.\r
- *\r
- * @param mixed color 1\r
- * @param mixed color 2\r
- * @access private\r
- */\r
- function _setColors ( $col1, $col2 )\r
- {\r
- $this->color1 = Image_Canvas_Color::color2RGB($col1);\r
- $this->color2 = Image_Canvas_Color::color2RGB($col2);\r
- }\r
-}\r
+<?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 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: Stefan Neufeind <pear.neufeind@speedpartner.de> |
+// +----------------------------------------------------------------------+
+//
+// $Id: Color.php 291771 2009-12-06 17:38:31Z neufeind $
+
+/**
+* Class for color-handling
+*
+* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+* @package Image_Canvas
+* @category images
+* @license The PHP License, version 2.02
+*/
+
+/**
+* Color class to be extended; from package PEAR::Image_Color
+*/
+require_once 'Image/Color.php';
+
+/**
+* Class for color-handling
+*
+* This is used to extend the functionality of the current PEAR::Image_Color v0.4.
+* I hope to be allowed to incorporate some of the improvements in a new Image_Color release.
+*
+* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+* @package Image_Canvas
+* @access public
+*/
+class Image_Canvas_Color extends Image_Color
+{
+ /**
+ * Allocates a color in the given image.
+ *
+ * Userdefined color specifications get translated into
+ * an array of rgb values.
+ *
+ * @param resource &$img GD-resource
+ * @param mixed $color Any color representation supported by color2RGB()
+ *
+ * @return resource Image color handle
+ * @see color2RGB()
+ * @access public
+ * @static
+ */
+ function allocateColor(&$img, $color)
+ {
+ $color = Image_Canvas_Color::color2RGB($color);
+
+ if (($color[3] == 255) || (!function_exists("imagecolorallocatealpha"))) {
+ return imagecolorallocate($img, $color[0], $color[1], $color[2]);
+ } else {
+ return imagecolorallocatealpha($img, $color[0], $color[1], $color[2], 127-round(($color[3]*127)/255));
+ }
+ }
+
+ /**
+ * Convert any color-representation into an array of 4 ints (RGBA).
+ *
+ * Userdefined color specifications get translated into
+ * an array of rgb values.
+ *
+ * @param mixed $color Any color representation supported by Image_Canvas_Color::color2RGB()
+ *
+ * @return array Array of 4 ints (RGBA-representation)
+ * @access public
+ * @static
+ */
+ function color2RGB($color)
+ {
+ if (is_array($color)) {
+ if (!is_numeric($color[0])) {
+ return null; // error
+ }
+ if (count($color) == 3) { // assume RGB-color
+
+ // 255 = alpha-value; full opaque
+ return array((int) $color[0],
+ (int) $color[1],
+ (int) $color[2],
+ 255);
+ }
+ if (count($color) == 4) { // assume RGBA-color
+
+ // 255 = alpha-value; full opaque
+ return array((int) $color[0],
+ (int) $color[1],
+ (int) $color[2],
+ (int) $color[3]);
+ }
+ return null; // error
+ } elseif (is_string($color)) {
+ $alphaPos = strpos($color, '@');
+ if ($alphaPos === false) {
+ $alpha = 255;
+ } else {
+ $alphaFloat = (float) substr($color, $alphaPos+1);
+ // restrict to range 0..1
+ $alphaFloat = max(min($alphaFloat, 1), 0);
+ $alpha = (int) round((float) 255 * $alphaFloat);
+ $color = substr($color, 0, $alphaPos);
+ }
+ if ($color[0] == '#') { // hex-color given, e.g. #FFB4B4
+ $tempColor = parent::hex2rgb($color);
+ return array((int) $tempColor[0],
+ (int) $tempColor[1],
+ (int) $tempColor[2],
+ $alpha);
+ }
+ if (strpos($color, '%') !== false) {
+ $tempColor = parent::percentageColor2RGB($color);
+ return array((int) $tempColor[0],
+ (int) $tempColor[1],
+ (int) $tempColor[2],
+ $alpha);
+ } else {
+ $tempColor = parent::namedColor2RGB($color);
+ return array((int) $tempColor[0],
+ (int) $tempColor[1],
+ (int) $tempColor[2],
+ $alpha);
+ }
+ } else {
+ return null; // error
+ }
+ }
+
+ /**
+ * getRange
+ * Given a degree, you can get the range of colors between one color and
+ * another color.
+ *
+ * @param string $degrees How much each 'step' between the colors we should take.
+ *
+ * @return array Array of all the colors, one element for each color.
+ * @access public
+ */
+ function getRange ($degrees)
+ {
+ $tempColors = parent::getRange($degrees);
+
+ // now add alpha-channel information
+ $steps = count($tempColors);
+ for ($counter=0;$counter<$steps;$counter++) {
+ $tempColors[$counter] = parent::hex2rgb($tempColors[$counter]);
+ unset($tempColors[$counter]['hex']);
+ $tempColors[$counter][3] = (int) round(
+ (((float) $this->color1[3]*($steps-$counter))+
+ ((float) $this->color2[3]*($counter))
+ ) / $steps
+ );
+ }
+
+ return $tempColors;
+ }
+
+ /**
+ * Internal method to correctly set the colors.
+ *
+ * @param mixed $col1 color 1
+ * @param mixed $col2 color 2
+ *
+ * @return void
+ * @access private
+ */
+ function _setColors ( $col1, $col2 )
+ {
+ $this->color1 = Image_Canvas_Color::color2RGB($col1);
+ $this->color2 = Image_Canvas_Color::color2RGB($col2);
+ }
+}
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Class for handling output in GD compatible format.\r
- * \r
- * Supported formats are PNG, JPEG, GIF and WBMP.\r
- *\r
- * Requires PHP extension GD\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: GD.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas/WithMap.php';\r
-\r
-/**\r
- * Include file Image/Canvas/Color.php\r
- */\r
-require_once 'Image/Canvas/Color.php';\r
-\r
-/**\r
- * Canvas class to output using PHP GD support.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- * @abstract\r
- */\r
-class Image_Canvas_GD extends Image_Canvas_WithMap\r
-{\r
-\r
- /**\r
- * The canvas of the graph\r
- * @var resource\r
- * @access private\r
- */\r
- var $_canvas;\r
-\r
- /**\r
- * The canvas to use for tiled filling\r
- * @var resource\r
- * @access private\r
- */\r
- var $_tileImage = null;\r
-\r
- /**\r
- * Is version GD2 installed?\r
- * @var bool\r
- * @access private\r
- */\r
- var $_gd2 = true;\r
-\r
- /**\r
- * Antialiasing?\r
- * \r
- * Possible values 'off', 'driver' and 'native'\r
- * \r
- * @var string\r
- * @access private\r
- */\r
- var $_antialias = 'off';\r
- \r
- var $_alpha = false;\r
- \r
- var $_clipping = array();\r
-\r
- /**\r
- * Create the GD canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'width' The width of the graph on the canvas\r
- *\r
- * 'height' The height of the graph on the canvas\r
- *\r
- * 'left' The left offset of the graph on the canvas\r
- *\r
- * 'top' The top offset of the graph on the canvas\r
- * \r
- * 'antialias' = 'native' enables native GD antialiasing - this\r
- * method has no severe impact on performance (approx +5%). Requires PHP\r
- * 4.3.2 (with bundled GD2)\r
- * \r
- * 'antialias' = {true|'driver'} Image_Graph implemented method. This method\r
- * has a severe impact on performance, drawing an antialiased line this\r
- * way is about XX times slower, with an overall performance impact of\r
- * about +40%. The justification for this method is that if native support\r
- * is not available this can be used, it is also a future feature that this\r
- * method for antialiasing will support line styles.\r
- * \r
- * Use antialiased for best results with a line/area chart having just a few\r
- * datapoints. Native antialiasing does not provide a good appearance with\r
- * short lines, as for example with smoothed charts. Antialiasing does not\r
- * (currently) work with linestyles, neither native nor driver method!\r
- * \r
- * 'noalpha' = true If alpha blending is to be disabled\r
- *\r
- * 'filename' An image to open, on which the graph is created on\r
- *\r
- * 'gd' A GD resource to add the image to, use this option to continue\r
- * working on an already existing GD resource. Make sure this is passed 'by-\r
- * reference' (using &)\r
- * \r
- * 'usemap' Initialize an image map\r
- *\r
- * 'gd' and 'filename' are mutually exclusive with 'gd' as preference\r
- *\r
- * 'width' and 'height' are required unless 'filename' or 'gd' are\r
- * specified, in which case the width and height are taken as the actual\r
- * image width/height. If the latter is the case and 'left' and/or 'top' was\r
- * also specified, the actual 'width'/'height' are altered so that the graph\r
- * fits inside the canvas (i.e 'height' = actual height - top, etc.)\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_GD($param)\r
- {\r
- include_once 'Image/Canvas/Color.php';\r
-\r
- parent::Image_Canvas_WithMap($param);\r
- \r
- $this->_gd2 = ($this->_version() == 2);\r
- $this->_font = array('font' => 1, 'color' => 'black');\r
-\r
- if ((isset($param['gd'])) && (is_resource($param['gd']))) {\r
- $this->_canvas =& $param['gd'];\r
- } elseif (isset($param['filename'])) {\r
- $this->_canvas =& $this->_getGD($param['filename']);\r
- } else {\r
- if ($this->_gd2) {\r
- $this->_canvas = ImageCreateTrueColor(\r
- $this->_width,\r
- $this->_height\r
- );\r
- if ((!isset($param['noalpha'])) || ($param['noalpha'] !== true)) {\r
- ImageAlphaBlending($this->_canvas, true);\r
- $this->_alpha = true;\r
- }\r
- } else {\r
- $this->_canvas = ImageCreate($this->_width, $this->_height);\r
- }\r
- }\r
- \r
- if (isset($param['antialias'])) {\r
- $this->_antialias = $param['antialias'];\r
- }\r
- \r
- if ($this->_antialias === true) {\r
- $this->_antialias = 'driver';\r
- }\r
- \r
- if (($this->_gd2) && ($this->_antialias === 'native') && (function_exists('ImageAntialias'))) {\r
- ImageAntialias($this->_canvas, true);\r
- }\r
- }\r
-\r
- /**\r
- * Get an GD image resource from a file\r
- *\r
- * @param string $filename\r
- * @return mixed The GD image resource\r
- * @access private\r
- */\r
- function &_getGD($filename)\r
- {\r
- $info = getimagesize($filename);\r
- \r
- $result = null;\r
- switch($info[2]) {\r
- case IMG_PNG:\r
- $result =& ImageCreateFromPNG($filename);\r
- break;\r
- \r
- case IMG_JPG:\r
- $result =& ImageCreateFromJPEG($filename);\r
- break;\r
- \r
- case IMG_GIF:\r
- $result =& ImageCreateFromGIF($filename);\r
- break;\r
- }\r
- return $result;\r
- }\r
-\r
- /**\r
- * Get the color index for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int The GD image index of the color\r
- * @access private\r
- */\r
- function _color($color = false)\r
- {\r
- if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {\r
- return ImageColorTransparent($this->_canvas);\r
- } else {\r
- return Image_Canvas_Color::allocateColor($this->_canvas, $color);\r
- }\r
- }\r
-\r
- /**\r
- * Get the GD applicable linestyle\r
- *\r
- * @param mixed $lineStyle The line style to return, false if the one\r
- * explicitly set\r
- * @return mixed A GD compatible linestyle\r
- * @access private\r
- */\r
- function _getLineStyle($lineStyle = false)\r
- {\r
- if ($this->_gd2) {\r
- ImageSetThickness($this->_canvas, $this->_thickness);\r
- }\r
-\r
- if ($lineStyle == 'transparent') {\r
- return false;\r
- } elseif ($lineStyle === false) {\r
- if (is_array($this->_lineStyle)) {\r
- $colors = array();\r
- foreach ($this->_lineStyle as $color) {\r
- if ($color === 'transparent') {\r
- $color = false;\r
- }\r
- $colors[] = $this->_color($color);\r
- }\r
- ImageSetStyle($this->_canvas, $colors);\r
- return IMG_COLOR_STYLED;\r
- } else {\r
- return $this->_color($this->_lineStyle);\r
- }\r
- } else {\r
- return $this->_color($lineStyle);\r
- }\r
- }\r
-\r
- /**\r
- * Get the GD applicable fillstyle\r
- *\r
- * @param mixed $fillStyle The fillstyle to return, false if the one\r
- * explicitly set\r
- * @return mixed A GD compatible fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($fillStyle = false, $x0 = 0, $y0 = 0, $x1 = 0, $y1 = 0)\r
- {\r
- if ($this->_tileImage != null) {\r
- ImageDestroy($this->_tileImage);\r
- $this->_tileImage = null;\r
- }\r
- if ($fillStyle == 'transparent') {\r
- return false;\r
- } elseif ($fillStyle === false) {\r
- if (is_resource($this->_fillStyle)) {\r
- $x = min($x0, $x1);\r
- $y = min($y0, $y1);\r
- $w = abs($x1 - $x0) + 1;\r
- $h = abs($y1 - $y0) + 1;\r
- if ($this->_gd2) {\r
- $this->_tileImage = ImageCreateTrueColor(\r
- $this->getWidth(),\r
- $this->getHeight()\r
- );\r
-\r
- ImageCopyResampled(\r
- $this->_tileImage,\r
- $this->_fillStyle,\r
- $x,\r
- $y,\r
- 0,\r
- 0,\r
- $w,\r
- $h,\r
- ImageSX($this->_fillStyle),\r
- ImageSY($this->_fillStyle)\r
- );\r
- } else {\r
- $this->_tileImage = ImageCreate(\r
- $this->getWidth(),\r
- $this->getHeight()\r
- );\r
-\r
- ImageCopyResized(\r
- $this->_tileImage,\r
- $this->_fillStyle,\r
- $x,\r
- $y,\r
- 0,\r
- 0,\r
- $w,\r
- $h,\r
- ImageSX($this->_fillStyle),\r
- ImageSY($this->_fillStyle)\r
- );\r
- }\r
- ImageSetTile($this->_canvas, $this->_tileImage);\r
- return IMG_COLOR_TILED;\r
- } elseif ((is_array($this->_fillStyle)) && (isset($this->_fillStyle['direction']))) {\r
- $width = abs($x1 - $x0) + 1;\r
- $height = abs($y1 - $y0) + 1;\r
-\r
- switch ($this->_fillStyle['direction']) {\r
- case 'horizontal':\r
- $count = $width;\r
- break;\r
-\r
- case 'vertical':\r
- $count = $height;\r
- break;\r
-\r
- case 'horizontal_mirror':\r
- $count = $width / 2;\r
- break;\r
-\r
- case 'vertical_mirror':\r
- $count = $height / 2;\r
- break;\r
-\r
- case 'diagonal_tl_br':\r
- case 'diagonal_bl_tr':\r
- $count = sqrt($width * $width + $height * $height);\r
- break;\r
-\r
- case 'radial':\r
- $count = max($width, $height, sqrt($width * $width + $height * $height)) + 1;\r
- break;\r
-\r
- }\r
-\r
- $count = round($count);\r
-\r
- if ($this->_gd2) {\r
- $this->_tileImage = ImageCreateTrueColor(\r
- $this->getWidth(),\r
- $this->getHeight()\r
- );\r
- } else {\r
- $this->_tileImage = ImageCreate(\r
- $this->getWidth(),\r
- $this->getHeight()\r
- );\r
- }\r
-\r
-\r
- $startColor = Image_Canvas_Color::color2RGB(\r
- ($this->_fillStyle['direction'] == 'radial' ?\r
- $this->_fillStyle['end'] :\r
- $this->_fillStyle['start']\r
- )\r
- );\r
- $endColor = Image_Canvas_Color::color2RGB(\r
- ($this->_fillStyle['direction'] == 'radial' ?\r
- $this->_fillStyle['start'] :\r
- $this->_fillStyle['end']\r
- )\r
- );\r
-\r
- $redIncrement = ($endColor[0] - $startColor[0]) / $count;\r
- $greenIncrement = ($endColor[1] - $startColor[1]) / $count;\r
- $blueIncrement = ($endColor[2] - $startColor[2]) / $count;\r
-\r
- $color = false;\r
- for ($i = 0; $i < $count; $i ++) {\r
- unset($color);\r
- if ($i == 0) {\r
- $color = $startColor;\r
- unset($color[3]);\r
- } else {\r
- $color[0] = round(($redIncrement * $i) +\r
- $redIncrement + $startColor[0]);\r
- $color[1] = round(($greenIncrement * $i) +\r
- $greenIncrement + $startColor[1]);\r
- $color[2] = round(($blueIncrement * $i) +\r
- $blueIncrement + $startColor[2]);\r
- }\r
- $color = Image_Canvas_Color::allocateColor(\r
- $this->_tileImage,\r
- $color\r
- );\r
-\r
- switch ($this->_fillStyle['direction']) {\r
- case 'horizontal':\r
- ImageLine($this->_tileImage,\r
- $x0 + $i,\r
- $y0,\r
- $x0 + $i,\r
- $y1, $color);\r
- break;\r
-\r
- case 'vertical':\r
- ImageLine($this->_tileImage,\r
- $x0,\r
- $y1 - $i,\r
- $x1,\r
- $y1 - $i, $color);\r
- break;\r
-\r
- case 'horizontal_mirror':\r
- if (($x0 + $i) <= ($x1 - $i)) {\r
- ImageLine($this->_tileImage,\r
- $x0 + $i,\r
- $y0,\r
- $x0 + $i,\r
- $y1, $color);\r
-\r
- ImageLine($this->_tileImage,\r
- $x1 - $i,\r
- $y0,\r
- $x1 - $i,\r
- $y1, $color);\r
- }\r
- break;\r
-\r
- case 'vertical_mirror':\r
- if (($y0 + $i) <= ($y1 - $i)) {\r
- ImageLine($this->_tileImage,\r
- $x0,\r
- $y0 + $i,\r
- $x1,\r
- $y0 + $i, $color);\r
- ImageLine($this->_tileImage,\r
- $x0,\r
- $y1 - $i,\r
- $x1,\r
- $y1 - $i, $color);\r
- }\r
- break;\r
-\r
- case 'diagonal_tl_br':\r
- if (($i > $width) && ($i > $height)) {\r
- $polygon = array (\r
- $x1, $y0 + $i - $width - 1,\r
- $x1, $y1,\r
- $x0 + $i - $height - 1, $y1);\r
- } elseif ($i > $width) {\r
- $polygon = array (\r
- $x0, $y0 + $i,\r
- $x0, $y1,\r
- $x1, $y1,\r
- $x1, $y0 + $i - $width - 1);\r
- } elseif ($i > $height) {\r
- $polygon = array (\r
- $x0 + $i - $height - 1, $y1,\r
- $x1, $y1,\r
- $x1, $y0,\r
- $x0 + $i, $y0);\r
- } else {\r
- $polygon = array (\r
- $x0, $y0 + $i,\r
- $x0, $y1,\r
- $x1, $y1,\r
- $x1, $y0,\r
- $x0 + $i, $y0);\r
- }\r
- ImageFilledPolygon(\r
- $this->_tileImage,\r
- $polygon,\r
- count($polygon) / 2,\r
- $color\r
- );\r
- break;\r
-\r
- case 'diagonal_bl_tr':\r
- if (($i > $width) && ($i > $height)) {\r
- $polygon = array (\r
- $x1, $y1 - $i + $width - 1,\r
- $x1, $y0,\r
- $x0 + $i - $height - 1, $y0);\r
- } elseif ($i > $width) {\r
- $polygon = array (\r
- $x0, $y1 - $i,\r
- $x0, $y0,\r
- $x1, $y0,\r
- $x1, $y1 - $i + $width - 1);\r
- } elseif ($i > $height) {\r
- $polygon = array (\r
- $x0 + $i - $height - 1, $y0,\r
- $x1, $y0,\r
- $x1, $y1,\r
- $x0 + $i, $y1);\r
- } else {\r
- $polygon = array (\r
- $x0, $y1 - $i,\r
- $x0, $y0,\r
- $x1, $y0,\r
- $x1, $y1,\r
- $x0 + $i, $y1);\r
- }\r
- ImageFilledPolygon(\r
- $this->_tileImage,\r
- $polygon,\r
- count($polygon) / 2,\r
- $color\r
- );\r
- break;\r
-\r
- case 'radial':\r
- if (($this->_gd2) && ($i < $count)) {\r
- ImageFilledEllipse(\r
- $this->_tileImage,\r
- $x0 + $width / 2,\r
- $y0 + $height / 2,\r
- $count - $i,\r
- $count - $i,\r
- $color\r
- );\r
- }\r
- break;\r
- }\r
- }\r
- ImageSetTile($this->_canvas, $this->_tileImage);\r
- return IMG_COLOR_TILED;\r
- } else {\r
- return $this->_color($this->_fillStyle);\r
- }\r
- } else {\r
- return $this->_color($fillStyle);\r
- }\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling\r
- *\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- $this->_fillStyle =& $this->_getGD($filename);\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- *\r
- * 'ttf' = the .ttf file (either the basename, filename or full path)\r
- * If 'ttf' is specified, then the following can be specified\r
- *\r
- * 'size' = size in pixels\r
- *\r
- * 'angle' = the angle with which to write the text\r
- *\r
- * @param array $font The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- parent::setFont($fontOptions);\r
-\r
- if (isset($this->_font['ttf'])) {\r
- $this->_font['file'] = str_replace('\\', '/', Image_Canvas_Tool::fontMap($this->_font['ttf']));\r
- } elseif (!isset($this->_font['font'])) {\r
- $this->_font['font'] = 1;\r
- }\r
-\r
- if (!isset($this->_font['color'])) {\r
- $this->_font['color'] = 'black';\r
- }\r
-\r
- if ((isset($this->_font['angle'])) && ($this->_font['angle'] === false)) {\r
- $this->_font['angle'] = 0;\r
- }\r
- }\r
-\r
- /**\r
- * Calculate pixels on a line\r
- *\r
- * @param int $x0 X start point\r
- * @param int $y0 X start point\r
- * @param int $x1 X end point\r
- * @param int $y1 Y end point\r
- * @return array An associated array of x,y points with all pixels on the\r
- * line \r
- * @access private\r
- */\r
- function &_linePixels($x0, $y0, $x1, $y1)\r
- {\r
- $pixels = array();\r
- if (abs($x0 - $x1) > abs($y0 - $y1)) {\r
- if ($x1 != $x0) {\r
- $m = ($y1 - $y0) / ($x1 - $x0);\r
- } else {\r
- $m = 0;\r
- } \r
- $b = $y0 - $m * $x0;\r
- $strx = min($x0, $x1);\r
- $endx = max($x0, $x1);\r
- for ($x = $strx; $x <= $endx; $x++) {\r
- $pixels[] = array('X' => $x, 'Y' => ($m * $x + $b)); \r
- }\r
- } else {\r
- if ($y1 != $y0) {\r
- $m = ($x1 - $x0) / ($y1 - $y0);\r
- } else {\r
- $m = 0;\r
- }\r
- $b = $x0 - $m * $y0;\r
- $stry = min($y0, $y1);\r
- $endy = max($y0, $y1);\r
- for ($y = $stry; $y <= $endy; $y++) {\r
- $pixels[] = array('X' => ($m * $y + $b), 'Y' => $y); \r
- }\r
- }\r
- return $pixels;\r
- }\r
-\r
- /**\r
- * Draws an antialiased line\r
- *\r
- * @param int $x0 X start point\r
- * @param int $y0 X start point\r
- * @param int $x1 X end point\r
- * @param int $y1 Y end point\r
- * @param mixed $color The line color, can be omitted\r
- * @access private\r
- */\r
- function _antialiasedLine($x0, $y0, $x1, $y1, $color = false)\r
- {\r
- if (($line = $this->_getLineStyle($color)) !== false) {\r
- if ($line >= 0) {\r
- $line = ImageColorsForIndex($this->_canvas, $line);\r
- $pixels = &$this->_linePixels($x0, $y0, $x1, $y1);\r
- foreach ($pixels as $point) {\r
- $this->_antialiasedPixel($point['X'], $point['Y'], $line);\r
- }\r
- unset($pixels);\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Draws an antialiased pixel\r
- *\r
- * @param int $x X point\r
- * @param int $y Y point\r
- * @param mixed $color The pixel color\r
- * @access private\r
- */\r
- function _antialiasedPixel($x, $y, $color)\r
- {\r
- $fx = floor($x);\r
- $fy = floor($y);\r
- $cx = ceil($x);\r
- $cy = ceil($y);\r
- $xa = $x - $fx;\r
- $xb = $cx - $x;\r
- $ya = $y - $fy;\r
- $yb = $cy - $y;\r
- if (($cx == $fx) && ($cy == $fy)) {\r
- $this->_antialisedSubPixel($fx, $fy, 0.0, 1.0, $color);\r
- } else {\r
- $this->_antialisedSubPixel($fx, $fy, $xa + $ya, $xb + $yb, $color);\r
- if ($cy != $fy) {\r
- $this->_antialisedSubPixel($fx, $cy, $xa + $yb, $xb + $ya, $color);\r
- }\r
- if ($cx != $fx) {\r
- $this->_antialisedSubPixel($cx, $fy, $xb + $ya, $xa + $yb, $color);\r
- if ($cy != $fy) {\r
- $this->_antialisedSubPixel($cx, $cy, $xb + $yb, $xa + $ya, $color);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Antialias'es the pixel around x,y with weights a,b\r
- *\r
- * @param int $x X point\r
- * @param int $y Y point\r
- * @param int $a The weight of the current color\r
- * @param int $b The weight of the applied/wanted color\r
- * @param mixed $color The pixel color\r
- * @access private\r
- */\r
- function _antialisedSubPixel($x, $y, $a, $b, $color)\r
- {\r
- $x = $this->_getX($x);\r
- $y = $this->_getX($y);\r
- if (($x >=0 ) && ($y >= 0) && ($x < $this->getWidth()) && ($y < $this->getHeight())) {\r
- $tempColor = ImageColorsForIndex($this->_canvas, ImageColorAt($this->_canvas, $x, $y)); \r
- \r
- $newColor[0] = min(255, round($tempColor['red'] * $a + $color['red'] * $b)); \r
- $newColor[1] = min(255, round($tempColor['green'] * $a + $color['green'] * $b)); \r
- $newColor[2] = min(255, round($tempColor['blue'] * $a + $color['blue'] * $b));\r
- //$newColor[3] = 0;\r
- $color = '#';\r
- foreach ($newColor as $acolor) {\r
- $color .= sprintf('%02s', dechex($acolor));\r
- }\r
- $newColor = $this->_color($color);//,'rgb(' . $newColor[0] . ',' . $newColor[1] . ',' . $newColor[2] .')'; \r
- \r
- ImageSetPixel($this->_canvas, $x, $y, $newColor);\r
- }\r
- }\r
- \r
- \r
- /**\r
- * Draw a line end\r
- *\r
- * Parameter array:\r
- * \r
- * 'x': int X point\r
- * \r
- * 'y': int Y point\r
- * \r
- * 'end': string The end type of the end\r
- * \r
- * 'size': int The size of the end\r
- * \r
- * 'color': string The color of the end\r
- * \r
- * 'angle': int [optional] The angle with which to draw the end\r
- * \r
- * @param array $params Parameter array\r
- */\r
- function drawEnd($params) \r
- { \r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $size = $params['size'];\r
- //var_dump($params);\r
- $angle = deg2rad((isset($params['angle']) ? $params['angle'] : 0));\r
- $pi2 = pi() / 2;\r
- switch ($params['end']) {\r
- case 'lollipop':\r
- case 'circle':\r
- $this->ellipse(\r
- array(\r
- 'x' => $x,\r
- 'y' => $y,\r
- 'rx' => $size / 2,\r
- 'ry' => $size / 2,\r
- 'fill' => $params['color'],\r
- 'line' => $params['color'] \r
- )\r
- );\r
- break;\r
- case 'diamond':\r
- $x0 = round($params['x'] + cos($angle) * $size * 0.65);\r
- $y0 = round($params['y'] - sin($angle) * $size * 0.65);\r
- $shape = array(\r
- $x0 + round(cos($angle) * $size * 0.65),\r
- $y0 - round(sin($angle) * $size * 0.65),\r
- $x0 + round(cos($angle + $pi2) * $size * 0.65),\r
- $y0 - round(sin($angle + $pi2) * $size * 0.65),\r
- $x0 + round(cos($angle + pi()) * $size * 0.65),\r
- $y0 - round(sin($angle + pi()) * $size * 0.65),\r
- $x0 + round(cos($angle + 3 * $pi2) * $size * 0.65),\r
- $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65)\r
- );\r
- break;\r
- case 'line':\r
- $this->line(\r
- array(\r
- 'x0' => $x + round(cos($angle + $pi2) * $size / 2),\r
- 'y0' => $y - round(sin($angle + $pi2) * $size / 2),\r
- 'x1' => $x + round(cos($angle + 3 * $pi2) * $size / 2),\r
- 'y1' => $y - round(sin($angle + 3 * $pi2) * $size / 2),\r
- 'color' => $params['color']\r
- )\r
- );\r
- break;\r
- case 'box':\r
- case 'rectangle':\r
- $x0 = round($params['x'] + cos($angle) * $size / 2);\r
- $y0 = round($params['y'] - sin($angle) * $size / 2);\r
- $pi4 = pi() / 4; \r
- $shape = array(\r
- $x0 + round(cos($angle + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + $pi4) * $size / 2),\r
- $x0 + round(cos($angle + $pi2 + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2),\r
- $x0 + round(cos($angle + pi() + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + pi() + $pi4) * $size / 2),\r
- $x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2)\r
- );\r
- break;\r
- case 'arrow': \r
- $shape = array(\r
- $x + cos($angle) * $size,\r
- $y - sin($angle) * $size,\r
- $x + cos($angle + $pi2) * $size * 0.4,\r
- $y - sin($angle + $pi2) * $size * 0.4,\r
- $x + cos($angle + 3 * $pi2) * $size * 0.4,\r
- $y - sin($angle + 3 * $pi2) * $size * 0.4, \r
- );\r
- break;\r
- case 'arrow2': \r
- $shape = array(\r
- $x + round(cos($angle) * $size),\r
- $y - round(sin($angle) * $size),\r
- $x + round(cos($angle + $pi2 + deg2rad(45)) * $size),\r
- $y - round(sin($angle + $pi2 + deg2rad(45)) * $size),\r
- $x,\r
- $y,\r
- $x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size),\r
- $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size), \r
- );\r
- break;\r
- }\r
- \r
- if (isset($shape)) {\r
- // output the shape\r
- if (($fill = $this->_getFillStyle($params['color'])) !== false) {\r
- ImageFilledPolygon($this->_canvas, $shape, count($shape)/2, $fill);\r
- }\r
- }\r
- parent::drawEnd($params);\r
- } \r
- \r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * \r
- * 'x0': int X start point\r
- * \r
- * 'y0': int Y start point\r
- * \r
- * 'x1': int X end point\r
- * \r
- * 'y1': int Y end point\r
- * \r
- * 'color': mixed [optional] The line color\r
- * \r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- \r
- $x0 = $this->_getX($x0);\r
- $y0 = $this->_getY($y0);\r
- $x1 = $this->_getX($x1);\r
- $y1 = $this->_getY($y1);\r
- if (($this->_antialias === 'driver') && ($x0 != $x1) && ($y0 != $y1)) {\r
- $this->_antialiasedLine($x0, $y0, $x1, $y1, $color);\r
- } elseif (($line = $this->_getLineStyle($color)) !== false) { \r
- ImageLine($this->_canvas, $x0, $y0, $x1, $y1, $line);\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * \r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * \r
- * 'fill': mixed [optional] The fill color\r
- * \r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params)\r
- {\r
- include_once 'Image/Canvas/Tool.php';\r
-\r
- $connectEnds = (isset($params['connect']) ? $params['connect'] : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- if (!$connectEnds) {\r
- $fillColor = 'transparent';\r
- }\r
- $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);\r
-\r
- $lastPoint = false;\r
- foreach ($this->_polygon as $point) {\r
- if (($lastPoint) && (isset($lastPoint['P1X'])) &&\r
- (isset($lastPoint['P1Y'])) && (isset($lastPoint['P2X'])) &&\r
- (isset($lastPoint['P2Y'])))\r
- {\r
- $dx = abs($point['X'] - $lastPoint['X']);\r
- $dy = abs($point['Y'] - $lastPoint['Y']);\r
- $d = sqrt($dx * $dx + $dy * $dy);\r
- if ($d > 0) {\r
- $interval = 1 / $d;\r
- for ($t = 0; $t <= 1; $t = $t + $interval) {\r
- $x = Image_Canvas_Tool::bezier(\r
- $t,\r
- $lastPoint['X'],\r
- $lastPoint['P1X'],\r
- $lastPoint['P2X'],\r
- $point['X']\r
- );\r
- \r
- $y = Image_Canvas_Tool::bezier(\r
- $t,\r
- $lastPoint['Y'],\r
- $lastPoint['P1Y'],\r
- $lastPoint['P2Y'],\r
- $point['Y']\r
- );\r
- \r
- if (!isset($low['X'])) {\r
- $low['X'] = $x;\r
- } else {\r
- $low['X'] = min($x, $low['X']);\r
- }\r
- if (!isset($high['X'])) {\r
- $high['X'] = $x;\r
- } else {\r
- $high['X'] = max($x, $high['X']);\r
- }\r
- if (!isset($low['Y'])) {\r
- $low['Y'] = $y;\r
- } else {\r
- $low['Y'] = min($y, $low['Y']);\r
- }\r
- if (!isset($high['Y'])) {\r
- $high['Y'] = $y;\r
- } else {\r
- $high['Y'] = max($y, $high['Y']);\r
- }\r
- $polygon[] = $x;\r
- $polygon[] = $y;\r
- }\r
- if (($t - $interval) < 1) {\r
- $x = Image_Canvas_Tool::bezier(\r
- 1,\r
- $lastPoint['X'],\r
- $lastPoint['P1X'],\r
- $lastPoint['P2X'],\r
- $point['X']\r
- );\r
- \r
- $y = Image_Canvas_Tool::bezier(\r
- 1,\r
- $lastPoint['Y'],\r
- $lastPoint['P1Y'],\r
- $lastPoint['P2Y'],\r
- $point['Y']\r
- );\r
- \r
- $polygon[] = $x;\r
- $polygon[] = $y;\r
- }\r
- }\r
- } else {\r
- if (!isset($low['X'])) {\r
- $low['X'] = $point['X'];\r
- } else {\r
- $low['X'] = min($point['X'], $low['X']);\r
- }\r
- if (!isset($high['X'])) {\r
- $high['X'] = $point['X'];\r
- } else {\r
- $high['X'] = max($point['X'], $high['X']);\r
- }\r
- if (!isset($low['Y'])) {\r
- $low['Y'] = $point['Y'];\r
- } else {\r
- $low['Y'] = min($point['Y'], $low['Y']);\r
- }\r
- if (!isset($high['Y'])) {\r
- $high['Y'] = $point['Y'];\r
- } else {\r
- $high['Y'] = max($point['Y'], $high['Y']);\r
- }\r
-\r
- $polygon[] = $point['X'];\r
- $polygon[] = $point['Y'];\r
- }\r
- $lastPoint = $point;\r
- }\r
-\r
- if ((isset($polygon)) && (is_array($polygon))) {\r
- if ($connectEnds) {\r
- if (($fill = $this->_getFillStyle($fillColor, $low['X'], $low['Y'], $high['X'], $high['Y'])) !== false) {\r
- ImageFilledPolygon($this->_canvas, $polygon, count($polygon)/2, $fill);\r
- }\r
- if ($this->_antialias === 'driver') {\r
- $pfirst = $p0 = false; \r
- reset($polygon);\r
- \r
- while (list(, $x) = each($polygon)) {\r
- list(, $y) = each($polygon);\r
- if ($p0 !== false) {\r
- $this->_antialiasedLine($p0['X'], $p0['Y'], $x, $y, $lineColor);\r
- }\r
- if ($pfirst === false) {\r
- $pfirst = array('X' => $x, 'Y' => $y);\r
- } \r
- $p0 = array('X' => $x, 'Y' => $y);;\r
- }\r
- \r
- $this->_antialiasedLine($p0['X'], $p0['Y'], $pfirst['X'], $pfirst['Y'], $lineColor);\r
- } elseif (($line = $this->_getLineStyle($lineColor)) !== false) {\r
- ImagePolygon($this->_canvas, $polygon, count($polygon)/2, $line);\r
- }\r
- } else {\r
- $prev_point = false;\r
- if ($this->_antialias === 'driver') {\r
- reset($polygon);\r
- while (list(, $x) = each($polygon)) {\r
- list(, $y) = each($polygon);\r
- if ($prev_point) {\r
- $this->_antialiasedLine(\r
- $prev_point['X'],\r
- $prev_point['Y'],\r
- $x,\r
- $y,\r
- $lineColor\r
- ); \r
- }\r
- $prev_point = array('X' => $x, 'Y' => $y);;\r
- }\r
- } elseif (($line = $this->_getLineStyle($lineColor)) !== false) {\r
- reset($polygon);\r
- while (list(, $x) = each($polygon)) {\r
- list(, $y) = each($polygon);\r
- if ($prev_point) {\r
- ImageLine(\r
- $this->_canvas,\r
- $prev_point['X'],\r
- $prev_point['Y'],\r
- $x,\r
- $y,\r
- $line\r
- );\r
- }\r
- $prev_point = array('X' => $x, 'Y' => $y);;\r
- }\r
- }\r
- }\r
- }\r
-\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * \r
- * 'x0': int X start point\r
- * \r
- * 'y0': int Y start point\r
- * \r
- * 'x1': int X end point\r
- * \r
- * 'y1': int Y end point\r
- * \r
- * 'fill': mixed [optional] The fill color\r
- * \r
- * 'line': mixed [optional] The line color\r
- * \r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- if (($fill = $this->_getFillStyle($fillColor, $x0, $y0, $x1, $y1)) !== false) {\r
- ImageFilledRectangle($this->_canvas, $x0, $y0, $x1, $y1, $fill);\r
- }\r
-\r
- if (($line = $this->_getLineStyle($lineColor)) !== false) {\r
- ImageRectangle($this->_canvas, $x0, $y0, $x1, $y1, $line);\r
- }\r
-\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * \r
- * 'x': int X center point\r
- * \r
- * 'y': int Y center point\r
- * \r
- * 'rx': int X radius\r
- * \r
- * 'ry': int Y radius\r
- * \r
- * 'fill': mixed [optional] The fill color\r
- * \r
- * 'line': mixed [optional] The line color\r
- * \r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- if (($fill = $this->_getFillStyle($fillColor, $x - $rx, $y - $ry, $x + $rx, $y + $ry)) !== false) {\r
- ImageFilledEllipse($this->_canvas, $x, $y, $rx * 2, $ry * 2, $fill);\r
- }\r
-\r
- if (($line = $this->_getLineStyle($lineColor)) !== false) {\r
- ImageEllipse($this->_canvas, $x, $y, $rx * 2, $ry * 2, $line);\r
- }\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * \r
- * 'x': int X center point\r
- * \r
- * 'y': int Y center point\r
- * \r
- * 'rx': int X radius\r
- * \r
- * 'ry': int Y radius\r
- * \r
- * 'v1': int The starting angle (in degrees)\r
- * \r
- * 'v2': int The end angle (in degrees)\r
- * \r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * \r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * \r
- * 'fill': mixed [optional] The fill color\r
- * \r
- * 'line': mixed [optional] The line color\r
- * \r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $params['rx'];\r
- $ry = $params['ry'];\r
- $v1 = $params['v1'];\r
- $v2 = $params['v2'];\r
- $srx = (isset($params['srx']) ? $params['srx'] : 0);\r
- $sry = (isset($params['sry']) ? $params['sry'] : 0);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $dA = 0.1;\r
-\r
- if (($srx !== false) && ($sry !== false)) {\r
- $angle = max($v1, $v2);\r
- while ($angle >= min($v1, $v2)) {\r
- $polygon[] = ($x + $srx * cos(deg2rad($angle % 360)));\r
- $polygon[] = ($y + $sry * sin(deg2rad($angle % 360)));\r
- $angle -= $dA;\r
- }\r
- if (($angle + $dA) > min($v1, $v2)) {\r
- $polygon[] = ($x + $srx * cos(deg2rad(min($v1, $v2) % 360)));\r
- $polygon[] = ($y + $sry * sin(deg2rad(min($v1, $v2) % 360)));\r
- }\r
- } else {\r
- $polygon[] = $x;\r
- $polygon[] = $y;\r
- }\r
-\r
- $angle = min($v1, $v2);\r
- while ($angle <= max($v1, $v2)) {\r
- $polygon[] = ($x + $rx * cos(deg2rad($angle % 360)));\r
- $polygon[] = ($y + $ry * sin(deg2rad($angle % 360)));\r
- $angle += $dA;\r
- }\r
-\r
- if (($angle - $dA) < max($v1, $v2)) {\r
- $polygon[] = ($x + $rx * cos(deg2rad(max($v1, $v2) % 360)));\r
- $polygon[] = ($y + $ry * sin(deg2rad(max($v1, $v2) % 360)));\r
- }\r
-\r
- if ((($fill = $this->_getFillStyle($fillColor, $x - $rx - 1, $y - $ry - 1, $x + $rx + 1, $y + $ry + 1)) !== false) && (count($polygon) > 2)) {\r
- ImageFilledPolygon($this->_canvas, $polygon, count($polygon) / 2, $fill);\r
- }\r
-\r
- if (($line = $this->_getLineStyle($lineColor)) !== false) {\r
- ImagePolygon($this->_canvas, $polygon, count($polygon) / 2, $line);\r
- }\r
-\r
- parent::pieSlice($params);\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- if (isset($this->_font['file'])) {\r
- $angle = 0;\r
- if (isset($this->_font['angle'])) {\r
- $angle = $this->_font['angle'];\r
- }\r
- \r
- $width = 0;\r
- $lines = explode("\n", $text);\r
- foreach ($lines as $line) {\r
- $bounds = ImageTTFBBox(\r
- $this->_font['size'],\r
- $angle,\r
- $this->_font['file'],\r
- $text\r
- );\r
- \r
- $x0 = min($bounds[0], $bounds[2], $bounds[4], $bounds[6]);\r
- $x1 = max($bounds[0], $bounds[2], $bounds[4], $bounds[6]);\r
- $width = max(abs($x0 - $x1), $width);\r
- }\r
- return $width;\r
- } else {\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {\r
- return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);\r
- } else {\r
- $width = 0;\r
- $lines = explode("\n", $text);\r
- foreach ($lines as $line) {\r
- $width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));\r
- }\r
- return $width;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get the height of a text.\r
- * \r
- * Note! This method can give some peculiar results, since ImageTTFBBox() returns the total\r
- * bounding box of a text, where ImageTTF() writes the text on the baseline of the text, that\r
- * is 'g', 'p', 'q' and other letters that dig under the baseline will appear to have a larger\r
- * height than they actually do. Have a look at the tests/text.php test case - the first two\r
- * columns, 'left and 'center', both look alright, whereas the last column, 'right', appear\r
- * with a larger space between the first text and the second. This is because the total height\r
- * is actually smaller by exactly the number of pixels that the 'g' digs under the baseline.\r
- * Remove the 'g' from the text and they appear correct. \r
- *\r
- * @param string $text The text to get the height of\r
- * @param bool $force Force the method to calculate the size\r
- * @return int The height of the text\r
- */\r
- function textHeight($text, $force = false)\r
- {\r
- if (isset($this->_font['file'])) {\r
- $angle = 0;\r
- if (isset($this->_font['angle'])) {\r
- $angle = $this->_font['angle'];\r
- }\r
- \r
- $linebreaks = substr_count($text, "\n"); \r
- if (($angle == 0) && ($force === false)) {\r
- /*\r
- * if the angle is 0 simply return the size, due to different\r
- * heights for example for x-axis labels, making the labels\r
- * _not_ appear as written on the same baseline\r
- */ \r
- return $this->_font['size'] + ($this->_font['size'] + 2) * $linebreaks;\r
- }\r
-\r
- $height = 0;\r
- $lines = explode("\n", $text);\r
- foreach ($lines as $line) { \r
- $bounds = ImageTTFBBox(\r
- $this->_font['size'],\r
- $angle,\r
- $this->_font['file'],\r
- $line\r
- );\r
- \r
- $y0 = min($bounds[1], $bounds[3], $bounds[5], $bounds[7]);\r
- $y1 = max($bounds[1], $bounds[3], $bounds[5], $bounds[7]);\r
- $height += abs($y0 - $y1);\r
- }\r
- return $height + $linebreaks * 2;\r
- } else {\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {\r
- $width = 0;\r
- $lines = explode("\n", $text);\r
- foreach ($lines as $line) {\r
- $width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));\r
- }\r
- return $width;\r
- } else {\r
- return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Calculated the absolute bottom-left position of the text, by simulating\r
- * the calculation of the baseline drop.\r
- * @param int $x The relative x position to write the text \r
- * @param int $y The relative y position to write the text\r
- * @param string $text The text to write \r
- * @param array $align The alignment of the text relative to (x, y)\r
- * @returns array An array containing the absolute x and y positions\r
- * @access private\r
- */\r
- function _getAbsolutePosition($x, $y, $text, $align) \r
- {\r
- if ($this->_font['angle'] > 0) {\r
- $w0 = $this->textWidth($text);\r
- $h0 = $this->textHeight($text);\r
- \r
- if ($align['vertical'] == 'bottom') {\r
- $dy = $y - $h0;\r
- }\r
- else if ($align['vertical'] == 'center') {\r
- $dy = $y - $h0 / 2;\r
- }\r
- else if ($align['vertical'] == 'top') {\r
- $dy = $y;\r
- }\r
-\r
- if ($align['horizontal'] == 'right') {\r
- $dx = $x - $w0;\r
- }\r
- else if ($align['horizontal'] == 'center') {\r
- $dx = $x - $w0 / 2;\r
- }\r
- else if ($align['horizontal'] == 'left') {\r
- $dx = $x;\r
- }\r
- \r
- if (($this->_font['angle'] < 180) && ($this->_font['angle'] >= 0)) {\r
- $dy += $h0;\r
- }\r
- if (($this->_font['angle'] >= 90) && ($this->_font['angle'] < 270)) {\r
- $dx += $w0;\r
- } \r
- }\r
- else { \r
- // get the maximum size of normal text above base line - sampled by 'Al'\r
- $size1 = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'Al'); \r
- $height1 = abs($size1[7] - $size1[1]);\r
- \r
- // get the maximum size of all text above base and below line - sampled by 'AlgjpqyQ'\r
- $size2 = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'AlgjpqyQ');\r
- $height2 = abs($size2[7] - $size2[1]);\r
- \r
- // get the size of the text, simulating height above baseline beinh max, by sampling using 'Al'\r
- $size = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'Al' . $text);\r
- $height = abs($size[7] - $size[1]);\r
- \r
- // if all text is above baseline, i.e. height of text compares to max height above (within 10%) \r
- if (abs($height - $height1)/$height1 < 0.1) { \r
- $dHeight = 0; \r
- }\r
- else {\r
- $dHeight = abs($height2 - $height1);\r
- }\r
-\r
- // specifies the bottom-left corner!\r
- $dx = $x + sin(deg2rad($this->_font['angle'])) * $dHeight;\r
- $dy = $y - cos(deg2rad($this->_font['angle'])) * $dHeight;\r
-\r
- if ($align['vertical'] == 'top') {\r
- $dy += $height;\r
- }\r
- else if ($align['vertical'] == 'center') {\r
- $dy += ($height + $dHeight) / 2;\r
- }\r
- else if ($align['vertical'] == 'bottom') {\r
- $dy += $dHeight;\r
- }\r
- \r
- if ($align['horizontal'] == 'center') {\r
- $factor = 0.5;\r
- }\r
- else if ($align['horizontal'] == 'right') {\r
- $factor = 1;\r
- }\r
- else {\r
- $factor = 0;\r
- }\r
- \r
- if ($factor != 0) {\r
- $size = imagettfbbox($this->_font['size'], 0, $this->_font['file'], $text);\r
- $w0 = abs($size[2] - $size[0]); \r
- $dx -= cos(deg2rad($this->_font['angle'])) * $w0 * $factor;\r
- $dy += sin(deg2rad($this->_font['angle'])) * $w0 * $factor;\r
- }\r
- }\r
- \r
- return array('x' => $dx, 'y' => $dy); \r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * \r
- * 'x': int X-point of text\r
- * \r
- * 'y': int Y-point of text\r
- * \r
- * 'text': string The text to add\r
- * \r
- * 'alignment': array [optional] Alignment\r
- * \r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- $x0 = $this->_getX($params['x']);\r
- $y0 = $this->_getY($params['y']);\r
- $text = $params['text'];\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- $text = str_replace("\r", '', $text);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
-\r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if (isset($this->_font['size'])) { \r
- $textHeight = $this->_font['size'] + 2;\r
- }\r
- else {\r
- $textHeight = $this->textHeight('A');\r
- }\r
- $lines = explode("\n", $text); \r
- foreach ($lines as $line) { \r
- $x = $x0; \r
- $y = $y0;\r
- \r
- $y0 += $textHeight + 2;\r
- \r
- if (($color === false) && (isset($this->_font['color']))) {\r
- $color = $this->_font['color'];\r
- }\r
-\r
- if ($color != 'transparent') {\r
- if (isset($this->_font['file'])) { \r
- $result = $this->_getAbsolutePosition($x, $y, $line, $alignment); \r
- ImageTTFText(\r
- $this->_canvas,\r
- $this->_font['size'],\r
- $this->_font['angle'],\r
- $result['x'],\r
- $result['y'],\r
- $this->_color($color),\r
- $this->_font['file'],\r
- $line\r
- );\r
-\r
- } else {\r
- $width = $this->textWidth($line);\r
- $height = $this->textHeight($line);\r
- if ($alignment['horizontal'] == 'right') {\r
- $x -= $width;\r
- }\r
- else if ($alignment['horizontal'] == 'center') {\r
- $x -= $width / 2;\r
- }\r
- if ($alignment['vertical'] == 'bottom') {\r
- $y -= $height;\r
- }\r
- else if ($alignment['vertical'] == 'center') {\r
- $y -= $height / 2;\r
- }\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) { \r
- ImageStringUp(\r
- $this->_canvas,\r
- $this->_font['font'],\r
- $x,\r
- $y + $this->textHeight($text),\r
- $line,\r
- $this->_color($color)\r
- );\r
- } else {\r
- ImageString(\r
- $this->_canvas,\r
- $this->_font['font'],\r
- $x,\r
- $y,\r
- $line,\r
- $this->_color($color)\r
- );\r
- }\r
- }\r
- }\r
- }\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * \r
- * 'x': int X-point of overlayed image\r
- * \r
- * 'y': int Y-point of overlayed image\r
- * \r
- * 'filename': string The filename of the image to overlay\r
- * \r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * \r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * \r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $filename = $params['filename'];\r
- $width = (isset($params['width']) ? $params['width'] : false);\r
- $height = (isset($params['height']) ? $params['height'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
-\r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if (file_exists($filename)) {\r
- if (strtolower(substr($filename, -4)) == '.png') {\r
- $image = ImageCreateFromPNG($filename);\r
- } elseif (strtolower(substr($filename, -4)) == '.gif') {\r
- $image = ImageCreateFromGIF($filename);\r
- } else {\r
- $image = ImageCreateFromJPEG($filename);\r
- }\r
-\r
- $imgWidth = ImageSX($image);\r
- $imgHeight = ImageSY($image);\r
-\r
- $outputWidth = ($width !== false ? $width : $imgWidth);\r
- $outputHeight = ($height !== false ? $height : $imgHeight);\r
- \r
- if ($alignment['horizontal'] == 'right') {\r
- $x -= $outputWidth;\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $x -= $outputWidth / 2;\r
- }\r
-\r
- if ($alignment['vertical'] == 'bottom') {\r
- $y -= $outputHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y -= $outputHeight / 2;\r
- }\r
-\r
- if ((($width !== false) && ($width != $imgWidth)) ||\r
- (($height !== false) && ($height != $imgHeight)))\r
- {\r
- if ($this->_gd2) {\r
- ImageCopyResampled(\r
- $this->_canvas,\r
- $image,\r
- $x,\r
- $y,\r
- 0,\r
- 0,\r
- $width,\r
- $height,\r
- $imgWidth,\r
- $imgHeight\r
- );\r
- } else {\r
- ImageCopyResized(\r
- $this->_canvas,\r
- $image,\r
- $x,\r
- $y,\r
- 0,\r
- 0,\r
- $width,\r
- $height,\r
- $imgWidth,\r
- $imgHeight\r
- );\r
- }\r
- } else {\r
- ImageCopy(\r
- $this->_canvas,\r
- $image,\r
- $x,\r
- $y,\r
- 0,\r
- 0,\r
- $imgWidth,\r
- $imgHeight\r
- );\r
- }\r
- ImageDestroy($image);\r
- }\r
- parent::image($params);\r
- }\r
- \r
- /**\r
- * Set clipping to occur\r
- * \r
- * Parameter array:\r
- * \r
- * 'x0': int X point of Upper-left corner\r
- * 'y0': int X point of Upper-left corner\r
- * 'x1': int X point of lower-right corner\r
- * 'y1': int Y point of lower-right corner\r
- */\r
- function setClipping($params = false) \r
- {\r
- if ($params === false) {\r
- $index = count($this->_clipping) - 1;\r
- if (isset($this->_clipping[$index])) { \r
- $params = $this->_clipping[$index];\r
- $canvas = $params['canvas'];\r
- ImageCopy(\r
- $canvas, \r
- $this->_canvas,\r
- min($params['x0'], $params['x1']),\r
- min($params['y0'], $params['y1']),\r
- min($params['x0'], $params['x1']),\r
- min($params['y0'], $params['y1']),\r
- abs($params['x1'] - $params['x0'] + 1),\r
- abs($params['y1'] - $params['y0'] + 1)\r
- );\r
- $this->_canvas = $canvas;\r
- unset($this->_clipping[$index]);\r
- }\r
- }\r
- else {\r
- $params['canvas'] = $this->_canvas;\r
-\r
- if ($this->_gd2) {\r
- $this->_canvas = ImageCreateTrueColor(\r
- $this->_width,\r
- $this->_height\r
- );\r
- if ($this->_alpha) {\r
- ImageAlphaBlending($this->_canvas, true);\r
- }\r
- } else {\r
- $this->_canvas = ImageCreate($this->_width, $this->_height);\r
- }\r
- \r
- if (($this->_gd2) && ($this->_antialias === 'native')) {\r
- ImageAntialias($this->_canvas, true);\r
- }\r
- \r
- ImageCopy($this->_canvas, $params['canvas'], 0, 0, 0, 0, $this->_width, $this->_height); \r
- \r
- $this->_clipping[count($this->_clipping)] = $params;\r
- }\r
- }\r
- \r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * This method implicitly saves the canvas to the filename in the \r
- * filesystem path specified and parses it as URL specified by URL path\r
- * \r
- * Parameter array:\r
- * \r
- * 'filename' string\r
- * \r
- * 'filepath': string Path to the file on the file system. Remember the final slash\r
- * \r
- * 'urlpath': string Path to the file available through an URL. Remember the final slash\r
- * \r
- * 'alt': string [optional] Alternative text on image\r
- * \r
- * 'cssclass': string [optional] The CSS Stylesheet class\r
- * \r
- * 'border': int [optional] The border width on the image \r
- */\r
- function toHtml($params)\r
- {\r
- parent::toHtml($params);\r
- return '<img src="' . $params['urlpath'] . $params['filename'] . '"' .\r
- (isset($params['alt']) ? ' alt="' . $params['alt'] . '"' : '') .\r
- (isset($params['cssclass']) ? ' class="' . $params['cssclass'] . '"' : '') .\r
- (isset($params['border']) ? ' border="' . $params['border'] . '"' : '') .\r
- (isset($this->_imageMap) ? ' usemap="#' . $params['filename'] . '"' : '') . ' />' .\r
- (isset($this->_imageMap) ? "\n" . $this->_imageMap->toHtml(array('name' => $params['filename'])) : '');\r
- }\r
-\r
- /**\r
- * Resets the canvas.\r
- *\r
- * Include fillstyle, linestyle, thickness and polygon\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- if ($this->_gd2) {\r
- ImageSetThickness($this->_canvas, 1);\r
- }\r
- if ($this->_tileImage != null) {\r
- ImageDestroy($this->_tileImage);\r
- $this->_tileImage = null;\r
- }\r
- parent::_reset();\r
- $this->_font = array('font' => 1, 'color' => 'black');\r
- }\r
-\r
- /**\r
- * Check which version of GD is installed\r
- *\r
- * @return int 0 if GD isn't installed, 1 if GD 1.x is installed and 2 if GD\r
- * 2.x is installed\r
- * @access private\r
- */\r
- function _version()\r
- {\r
- $result = false;\r
- if (function_exists('gd_info')) {\r
- $info = gd_info();\r
- $version = $info['GD Version'];\r
- } else {\r
- ob_start();\r
- phpinfo(8);\r
- $php_info = ob_get_contents();\r
- ob_end_clean();\r
-\r
- if (ereg("<td[^>]*>GD Version *<\/td><td[^>]*>([^<]*)<\/td>",\r
- $php_info, $result))\r
- {\r
- $version = $result[1];\r
- } else {\r
- $version = null;\r
- }\r
- }\r
-\r
- if (ereg('1\.[0-9]{1,2}', $version)) {\r
- return 1;\r
- } elseif (ereg('2\.[0-9]{1,2}', $version)) {\r
- return 2;\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Class for handling output in GD compatible format.
+ *
+ * Supported formats are PNG, JPEG, GIF and WBMP.
+ *
+ * Requires PHP extension GD
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: GD.php 292673 2009-12-26 20:11:28Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas/WithMap.php';
+
+/**
+ * Include file Image/Canvas/Color.php
+ */
+require_once 'Image/Canvas/Color.php';
+
+/**
+ * Canvas class to output using PHP GD support.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ * @abstract
+ */
+class Image_Canvas_GD extends Image_Canvas_WithMap
+{
+
+ /**
+ * The canvas of the graph
+ * @var resource
+ * @access private
+ */
+ var $_canvas;
+
+ /**
+ * The canvas to use for tiled filling
+ * @var resource
+ * @access private
+ */
+ var $_tileImage = null;
+
+ /**
+ * Is version GD2 installed?
+ * @var bool
+ * @access private
+ */
+ var $_gd2 = true;
+
+ /**
+ * Do we need a factor to convert size in pixels to points?
+ * GD2 uses "pt" for font-sizes
+ * @var float
+ * @access private
+ */
+ var $_pxToPtFactor = 1;
+
+ /**
+ * Antialiasing?
+ *
+ * Possible values 'off', 'driver' and 'native'
+ *
+ * @var string
+ * @access private
+ */
+ var $_antialias = 'off';
+
+ var $_alpha = false;
+
+ var $_clipping = array();
+
+ /**
+ * Create the GD canvas.
+ *
+ * Parameters available:
+ *
+ * 'width' The width of the graph on the canvas
+ *
+ * 'height' The height of the graph on the canvas
+ *
+ * 'left' The left offset of the graph on the canvas
+ *
+ * 'top' The top offset of the graph on the canvas
+ *
+ * 'antialias' = 'native' enables native GD antialiasing - this
+ * method has no severe impact on performance (approx +5%). Requires PHP
+ * 4.3.2 (with bundled GD2)
+ *
+ * 'antialias' = {true|'driver'} Image_Graph implemented method. This method
+ * has a severe impact on performance, drawing an antialiased line this
+ * way is about XX times slower, with an overall performance impact of
+ * about +40%. The justification for this method is that if native support
+ * is not available this can be used, it is also a future feature that this
+ * method for antialiasing will support line styles.
+ *
+ * Use antialiased for best results with a line/area chart having just a few
+ * datapoints. Native antialiasing does not provide a good appearance with
+ * short lines, as for example with smoothed charts. Antialiasing does not
+ * (currently) work with linestyles, neither native nor driver method!
+ *
+ * 'noalpha' = true If alpha blending is to be disabled
+ *
+ * 'filename' An image to open, on which the graph is created on
+ *
+ * 'gd' A GD resource to add the image to, use this option to continue
+ * working on an already existing GD resource. Make sure this is passed 'by-
+ * reference' (using &)
+ *
+ * 'usemap' Initialize an image map
+ *
+ * 'gd' and 'filename' are mutually exclusive with 'gd' as preference
+ *
+ * 'width' and 'height' are required unless 'filename' or 'gd' are
+ * specified, in which case the width and height are taken as the actual
+ * image width/height. If the latter is the case and 'left' and/or 'top' was
+ * also specified, the actual 'width'/'height' are altered so that the graph
+ * fits inside the canvas (i.e 'height' = actual height - top, etc.)
+ *
+ * @param array $param Parameter array
+ */
+ function Image_Canvas_GD($param)
+ {
+ include_once 'Image/Canvas/Color.php';
+
+ parent::Image_Canvas_WithMap($param);
+
+ $this->_gd2 = ($this->_version() == 2);
+ $this->_pxToPtFactor = ($this->_gd2 ? (72/96) : 1);
+ $this->_font = array('font' => 1, 'color' => 'black');
+
+ if ((isset($param['gd'])) && (is_resource($param['gd']))) {
+ $this->_canvas =& $param['gd'];
+ } elseif (isset($param['filename'])) {
+ $this->_canvas =& $this->_getGD($param['filename']);
+ } else {
+ if ($this->_gd2) {
+ $this->_canvas = ImageCreateTrueColor(
+ $this->_width,
+ $this->_height
+ );
+ if ((!isset($param['noalpha'])) || ($param['noalpha'] !== true)) {
+ ImageAlphaBlending($this->_canvas, true);
+ $this->_alpha = true;
+ }
+ } else {
+ $this->_canvas = ImageCreate($this->_width, $this->_height);
+ }
+ }
+
+ if (isset($param['antialias'])) {
+ $this->_antialias = $param['antialias'];
+ }
+
+ if ($this->_antialias === true) {
+ $this->_antialias = 'driver';
+ }
+
+ if (($this->_gd2) && ($this->_antialias === 'native') && (function_exists('ImageAntialias'))) {
+ ImageAntialias($this->_canvas, true);
+ }
+ }
+
+ /**
+ * Get an GD image resource from a file
+ *
+ * @param string $filename File to fetch image from
+ *
+ * @return mixed The GD image resource
+ * @access private
+ */
+ function &_getGD($filename)
+ {
+ $info = getimagesize($filename);
+
+ $result = null;
+ switch($info[2]) {
+ case IMG_PNG:
+ $result =& ImageCreateFromPNG($filename);
+ break;
+
+ case IMG_JPG:
+ $result =& ImageCreateFromJPEG($filename);
+ break;
+
+ case IMG_GIF:
+ $result =& ImageCreateFromGIF($filename);
+ break;
+ }
+ return $result;
+ }
+
+ /**
+ * Get the color index for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int The GD image index of the color
+ * @access private
+ */
+ function _color($color = false)
+ {
+ if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {
+ return ImageColorTransparent($this->_canvas);
+ } else {
+ return Image_Canvas_Color::allocateColor($this->_canvas, $color);
+ }
+ }
+
+ /**
+ * Get the GD applicable linestyle
+ *
+ * @param mixed $lineStyle The line style to return, false if the one
+ * explicitly set
+ *
+ * @return mixed A GD compatible linestyle
+ * @access private
+ */
+ function _getLineStyle($lineStyle = false)
+ {
+ if ($this->_gd2) {
+ ImageSetThickness($this->_canvas, $this->_thickness);
+ }
+
+ if ($lineStyle == 'transparent') {
+ return false;
+ } elseif ($lineStyle === false) {
+ if (is_array($this->_lineStyle)) {
+ $colors = array();
+ foreach ($this->_lineStyle as $color) {
+ if ($color === 'transparent') {
+ $color = false;
+ }
+ $colors[] = $this->_color($color);
+ }
+ ImageSetStyle($this->_canvas, $colors);
+ return IMG_COLOR_STYLED;
+ } else {
+ return $this->_color($this->_lineStyle);
+ }
+ } else {
+ return $this->_color($lineStyle);
+ }
+ }
+
+ /**
+ * Get the GD applicable fillstyle
+ *
+ * @param mixed $fillStyle The fillstyle to return, false if the one
+ * explicitly set
+ * @param int $x0 ???
+ * @param int $y0 ???
+ * @param int $x1 ???
+ * @param int $y1 ???
+ *
+ * @return mixed A GD compatible fillstyle
+ * @access private
+ */
+ function _getFillStyle($fillStyle = false, $x0 = 0, $y0 = 0, $x1 = 0, $y1 = 0)
+ {
+ if ($this->_tileImage != null) {
+ ImageDestroy($this->_tileImage);
+ $this->_tileImage = null;
+ }
+ if ($fillStyle == 'transparent') {
+ return false;
+ } elseif ($fillStyle === false) {
+ if (is_resource($this->_fillStyle)) {
+ $x = min($x0, $x1);
+ $y = min($y0, $y1);
+ $w = abs($x1 - $x0) + 1;
+ $h = abs($y1 - $y0) + 1;
+ if ($this->_gd2) {
+ $this->_tileImage = ImageCreateTrueColor(
+ $this->getWidth(),
+ $this->getHeight()
+ );
+
+ ImageCopyResampled(
+ $this->_tileImage,
+ $this->_fillStyle,
+ $x,
+ $y,
+ 0,
+ 0,
+ $w,
+ $h,
+ ImageSX($this->_fillStyle),
+ ImageSY($this->_fillStyle)
+ );
+ } else {
+ $this->_tileImage = ImageCreate(
+ $this->getWidth(),
+ $this->getHeight()
+ );
+
+ ImageCopyResized(
+ $this->_tileImage,
+ $this->_fillStyle,
+ $x,
+ $y,
+ 0,
+ 0,
+ $w,
+ $h,
+ ImageSX($this->_fillStyle),
+ ImageSY($this->_fillStyle)
+ );
+ }
+ ImageSetTile($this->_canvas, $this->_tileImage);
+ return IMG_COLOR_TILED;
+ } elseif ((is_array($this->_fillStyle)) && (isset($this->_fillStyle['direction']))) {
+ $width = abs($x1 - $x0) + 1;
+ $height = abs($y1 - $y0) + 1;
+
+ switch ($this->_fillStyle['direction']) {
+ case 'horizontal':
+ $count = $width;
+ break;
+
+ case 'vertical':
+ $count = $height;
+ break;
+
+ case 'horizontal_mirror':
+ $count = $width / 2;
+ break;
+
+ case 'vertical_mirror':
+ $count = $height / 2;
+ break;
+
+ case 'diagonal_tl_br':
+ case 'diagonal_bl_tr':
+ $count = sqrt($width * $width + $height * $height);
+ break;
+
+ case 'radial':
+ $count = max($width, $height, sqrt($width * $width + $height * $height)) + 1;
+ break;
+
+ }
+
+ $count = round($count);
+
+ if ($this->_gd2) {
+ $this->_tileImage = ImageCreateTrueColor(
+ $this->getWidth(),
+ $this->getHeight()
+ );
+ } else {
+ $this->_tileImage = ImageCreate(
+ $this->getWidth(),
+ $this->getHeight()
+ );
+ }
+
+
+ $startColor = Image_Canvas_Color::color2RGB(
+ ($this->_fillStyle['direction'] == 'radial' ?
+ $this->_fillStyle['end'] :
+ $this->_fillStyle['start']
+ )
+ );
+ $endColor = Image_Canvas_Color::color2RGB(
+ ($this->_fillStyle['direction'] == 'radial' ?
+ $this->_fillStyle['start'] :
+ $this->_fillStyle['end']
+ )
+ );
+
+ $redIncrement = ($endColor[0] - $startColor[0]) / $count;
+ $greenIncrement = ($endColor[1] - $startColor[1]) / $count;
+ $blueIncrement = ($endColor[2] - $startColor[2]) / $count;
+
+ $color = false;
+ for ($i = 0; $i < $count; $i ++) {
+ unset($color);
+ if ($i == 0) {
+ $color = $startColor;
+ unset($color[3]);
+ } else {
+ $color[0] = round(
+ ($redIncrement * $i) +
+ $redIncrement + $startColor[0]
+ );
+ $color[1] = round(
+ ($greenIncrement * $i) +
+ $greenIncrement + $startColor[1]
+ );
+ $color[2] = round(
+ ($blueIncrement * $i) +
+ $blueIncrement + $startColor[2]
+ );
+ }
+ $color = Image_Canvas_Color::allocateColor(
+ $this->_tileImage,
+ $color
+ );
+
+ switch ($this->_fillStyle['direction']) {
+ case 'horizontal':
+ ImageLine(
+ $this->_tileImage,
+ $x0 + $i,
+ $y0,
+ $x0 + $i,
+ $y1, $color
+ );
+ break;
+
+ case 'vertical':
+ ImageLine(
+ $this->_tileImage,
+ $x0,
+ $y1 - $i,
+ $x1,
+ $y1 - $i, $color
+ );
+ break;
+
+ case 'horizontal_mirror':
+ if (($x0 + $i) <= ($x1 - $i)) {
+ ImageLine(
+ $this->_tileImage,
+ $x0 + $i,
+ $y0,
+ $x0 + $i,
+ $y1, $color
+ );
+
+ ImageLine(
+ $this->_tileImage,
+ $x1 - $i,
+ $y0,
+ $x1 - $i,
+ $y1, $color
+ );
+ }
+ break;
+
+ case 'vertical_mirror':
+ if (($y0 + $i) <= ($y1 - $i)) {
+ ImageLine(
+ $this->_tileImage,
+ $x0,
+ $y0 + $i,
+ $x1,
+ $y0 + $i, $color
+ );
+ ImageLine(
+ $this->_tileImage,
+ $x0,
+ $y1 - $i,
+ $x1,
+ $y1 - $i, $color
+ );
+ }
+ break;
+
+ case 'diagonal_tl_br':
+ if (($i > $width) && ($i > $height)) {
+ $polygon = array (
+ $x1, $y0 + $i - $width - 1,
+ $x1, $y1,
+ $x0 + $i - $height - 1, $y1);
+ } elseif ($i > $width) {
+ $polygon = array (
+ $x0, $y0 + $i,
+ $x0, $y1,
+ $x1, $y1,
+ $x1, $y0 + $i - $width - 1);
+ } elseif ($i > $height) {
+ $polygon = array (
+ $x0 + $i - $height - 1, $y1,
+ $x1, $y1,
+ $x1, $y0,
+ $x0 + $i, $y0);
+ } else {
+ $polygon = array (
+ $x0, $y0 + $i,
+ $x0, $y1,
+ $x1, $y1,
+ $x1, $y0,
+ $x0 + $i, $y0);
+ }
+ ImageFilledPolygon(
+ $this->_tileImage,
+ $polygon,
+ count($polygon) / 2,
+ $color
+ );
+ break;
+
+ case 'diagonal_bl_tr':
+ if (($i > $width) && ($i > $height)) {
+ $polygon = array (
+ $x1, $y1 - $i + $width - 1,
+ $x1, $y0,
+ $x0 + $i - $height - 1, $y0);
+ } elseif ($i > $width) {
+ $polygon = array (
+ $x0, $y1 - $i,
+ $x0, $y0,
+ $x1, $y0,
+ $x1, $y1 - $i + $width - 1);
+ } elseif ($i > $height) {
+ $polygon = array (
+ $x0 + $i - $height - 1, $y0,
+ $x1, $y0,
+ $x1, $y1,
+ $x0 + $i, $y1);
+ } else {
+ $polygon = array (
+ $x0, $y1 - $i,
+ $x0, $y0,
+ $x1, $y0,
+ $x1, $y1,
+ $x0 + $i, $y1);
+ }
+ ImageFilledPolygon(
+ $this->_tileImage,
+ $polygon,
+ count($polygon) / 2,
+ $color
+ );
+ break;
+
+ case 'radial':
+ if (($this->_gd2) && ($i < $count)) {
+ ImageFilledEllipse(
+ $this->_tileImage,
+ $x0 + $width / 2,
+ $y0 + $height / 2,
+ $count - $i,
+ $count - $i,
+ $color
+ );
+ }
+ break;
+ }
+ }
+ ImageSetTile($this->_canvas, $this->_tileImage);
+ return IMG_COLOR_TILED;
+ } else {
+ return $this->_color($this->_fillStyle);
+ }
+ } else {
+ return $this->_color($fillStyle);
+ }
+ }
+
+ /**
+ * Sets an image that should be used for filling
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ $this->_fillStyle =& $this->_getGD($filename);
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ *
+ * 'ttf' = the .ttf file (either the basename, filename or full path)
+ * If 'ttf' is specified, then the following can be specified
+ *
+ * 'size' = size in pixels
+ *
+ * 'angle' = the angle with which to write the text
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ parent::setFont($fontOptions);
+
+ if (isset($this->_font['ttf'])) {
+ $this->_font['file'] = str_replace('\\', '/', Image_Canvas_Tool::fontMap($this->_font['ttf']));
+ } elseif (!isset($this->_font['font'])) {
+ $this->_font['font'] = 1;
+ }
+
+ if (!isset($this->_font['color'])) {
+ $this->_font['color'] = 'black';
+ }
+
+ if ((isset($this->_font['angle'])) && ($this->_font['angle'] === false)) {
+ $this->_font['angle'] = 0;
+ }
+ }
+
+ /**
+ * Calculate pixels on a line
+ *
+ * @param int $x0 X start point
+ * @param int $y0 Y start point
+ * @param int $x1 X end point
+ * @param int $y1 Y end point
+ *
+ * @return array An associated array of x,y points with all pixels on the
+ * line
+ * @access private
+ */
+ function &_linePixels($x0, $y0, $x1, $y1)
+ {
+ $pixels = array();
+ if (abs($x0 - $x1) > abs($y0 - $y1)) {
+ if ($x1 != $x0) {
+ $m = ($y1 - $y0) / ($x1 - $x0);
+ } else {
+ $m = 0;
+ }
+ $b = $y0 - $m * $x0;
+ $strx = min($x0, $x1);
+ $endx = max($x0, $x1);
+ for ($x = $strx; $x <= $endx; $x++) {
+ $pixels[] = array('X' => $x, 'Y' => ($m * $x + $b));
+ }
+ } else {
+ if ($y1 != $y0) {
+ $m = ($x1 - $x0) / ($y1 - $y0);
+ } else {
+ $m = 0;
+ }
+ $b = $x0 - $m * $y0;
+ $stry = min($y0, $y1);
+ $endy = max($y0, $y1);
+ for ($y = $stry; $y <= $endy; $y++) {
+ $pixels[] = array('X' => ($m * $y + $b), 'Y' => $y);
+ }
+ }
+ return $pixels;
+ }
+
+ /**
+ * Draws an antialiased line
+ *
+ * @param int $x0 X start point
+ * @param int $y0 Y start point
+ * @param int $x1 X end point
+ * @param int $y1 Y end point
+ * @param mixed $color The line color, can be omitted
+ *
+ * @return void
+ * @access private
+ */
+ function _antialiasedLine($x0, $y0, $x1, $y1, $color = false)
+ {
+ if (($line = $this->_getLineStyle($color)) !== false) {
+ if ($line >= 0) {
+ $line = ImageColorsForIndex($this->_canvas, $line);
+ $pixels = &$this->_linePixels($x0, $y0, $x1, $y1);
+ foreach ($pixels as $point) {
+ $this->_antialiasedPixel($point['X'], $point['Y'], $line);
+ }
+ unset($pixels);
+ }
+ }
+ }
+
+
+ /**
+ * Draws an antialiased pixel
+ *
+ * @param int $x X point
+ * @param int $y Y point
+ * @param mixed $color The pixel color
+ *
+ * @return void
+ * @access private
+ */
+ function _antialiasedPixel($x, $y, $color)
+ {
+ $fx = floor($x);
+ $fy = floor($y);
+ $cx = ceil($x);
+ $cy = ceil($y);
+ $xa = $x - $fx;
+ $xb = $cx - $x;
+ $ya = $y - $fy;
+ $yb = $cy - $y;
+ if (($cx == $fx) && ($cy == $fy)) {
+ $this->_antialisedSubPixel($fx, $fy, 0.0, 1.0, $color);
+ } else {
+ $this->_antialisedSubPixel($fx, $fy, $xa + $ya, $xb + $yb, $color);
+ if ($cy != $fy) {
+ $this->_antialisedSubPixel($fx, $cy, $xa + $yb, $xb + $ya, $color);
+ }
+ if ($cx != $fx) {
+ $this->_antialisedSubPixel($cx, $fy, $xb + $ya, $xa + $yb, $color);
+ if ($cy != $fy) {
+ $this->_antialisedSubPixel($cx, $cy, $xb + $yb, $xa + $ya, $color);
+ }
+ }
+ }
+ }
+
+ /**
+ * Antialias'es the pixel around x,y with weights a,b
+ *
+ * @param int $x X point
+ * @param int $y Y point
+ * @param int $a The weight of the current color
+ * @param int $b The weight of the applied/wanted color
+ * @param mixed $color The pixel color
+ *
+ * @return void
+ * @access private
+ */
+ function _antialisedSubPixel($x, $y, $a, $b, $color)
+ {
+ $x = $this->_getX($x);
+ $y = $this->_getX($y);
+ if (($x >=0 ) && ($y >= 0) && ($x < $this->getWidth()) && ($y < $this->getHeight())) {
+ $tempColor = ImageColorsForIndex($this->_canvas, ImageColorAt($this->_canvas, $x, $y));
+
+ $newColor[0] = min(255, round($tempColor['red'] * $a + $color['red'] * $b));
+ $newColor[1] = min(255, round($tempColor['green'] * $a + $color['green'] * $b));
+ $newColor[2] = min(255, round($tempColor['blue'] * $a + $color['blue'] * $b));
+ //$newColor[3] = 0;
+ $color = '#';
+ foreach ($newColor as $acolor) {
+ $color .= sprintf('%02s', dechex($acolor));
+ }
+ $newColor = $this->_color($color);//,'rgb(' . $newColor[0] . ',' . $newColor[1] . ',' . $newColor[2] .')';
+
+ ImageSetPixel($this->_canvas, $x, $y, $newColor);
+ }
+ }
+
+
+ /**
+ * Draw a line end
+ *
+ * Parameter array:
+ *
+ * 'x': int X point
+ *
+ * 'y': int Y point
+ *
+ * 'end': string The end type of the end
+ *
+ * 'size': int The size of the end
+ *
+ * 'color': string The color of the end
+ *
+ * 'angle': int [optional] The angle with which to draw the end
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function drawEnd($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $size = $params['size'];
+ //var_dump($params);
+ $angle = deg2rad((isset($params['angle']) ? $params['angle'] : 0));
+ $pi2 = pi() / 2;
+ switch ($params['end']) {
+ case 'lollipop':
+ case 'circle':
+ $this->ellipse(
+ array(
+ 'x' => $x,
+ 'y' => $y,
+ 'rx' => $size / 2,
+ 'ry' => $size / 2,
+ 'fill' => $params['color'],
+ 'line' => $params['color']
+ )
+ );
+ break;
+ case 'diamond':
+ $x0 = round($params['x'] + cos($angle) * $size * 0.65);
+ $y0 = round($params['y'] - sin($angle) * $size * 0.65);
+ $shape = array(
+ $x0 + round(cos($angle) * $size * 0.65),
+ $y0 - round(sin($angle) * $size * 0.65),
+ $x0 + round(cos($angle + $pi2) * $size * 0.65),
+ $y0 - round(sin($angle + $pi2) * $size * 0.65),
+ $x0 + round(cos($angle + pi()) * $size * 0.65),
+ $y0 - round(sin($angle + pi()) * $size * 0.65),
+ $x0 + round(cos($angle + 3 * $pi2) * $size * 0.65),
+ $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65)
+ );
+ break;
+ case 'line':
+ $this->line(
+ array(
+ 'x0' => $x + round(cos($angle + $pi2) * $size / 2),
+ 'y0' => $y - round(sin($angle + $pi2) * $size / 2),
+ 'x1' => $x + round(cos($angle + 3 * $pi2) * $size / 2),
+ 'y1' => $y - round(sin($angle + 3 * $pi2) * $size / 2),
+ 'color' => $params['color']
+ )
+ );
+ break;
+ case 'box':
+ case 'rectangle':
+ $x0 = round($params['x'] + cos($angle) * $size / 2);
+ $y0 = round($params['y'] - sin($angle) * $size / 2);
+ $pi4 = pi() / 4;
+ $shape = array(
+ $x0 + round(cos($angle + $pi4) * $size / 2),
+ $y0 - round(sin($angle + $pi4) * $size / 2),
+ $x0 + round(cos($angle + $pi2 + $pi4) * $size / 2),
+ $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2),
+ $x0 + round(cos($angle + pi() + $pi4) * $size / 2),
+ $y0 - round(sin($angle + pi() + $pi4) * $size / 2),
+ $x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2),
+ $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2)
+ );
+ break;
+ case 'arrow':
+ $shape = array(
+ $x + cos($angle) * $size,
+ $y - sin($angle) * $size,
+ $x + cos($angle + $pi2) * $size * 0.4,
+ $y - sin($angle + $pi2) * $size * 0.4,
+ $x + cos($angle + 3 * $pi2) * $size * 0.4,
+ $y - sin($angle + 3 * $pi2) * $size * 0.4,
+ );
+ break;
+ case 'arrow2':
+ $shape = array(
+ $x + round(cos($angle) * $size),
+ $y - round(sin($angle) * $size),
+ $x + round(cos($angle + $pi2 + deg2rad(45)) * $size),
+ $y - round(sin($angle + $pi2 + deg2rad(45)) * $size),
+ $x,
+ $y,
+ $x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size),
+ $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size),
+ );
+ break;
+ }
+
+ if (isset($shape)) {
+ // output the shape
+ if (($fill = $this->_getFillStyle($params['color'])) !== false) {
+ ImageFilledPolygon($this->_canvas, $shape, count($shape)/2, $fill);
+ }
+ }
+ parent::drawEnd($params);
+ }
+
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ *
+ * 'x0': int X start point
+ *
+ * 'y0': int Y start point
+ *
+ * 'x1': int X end point
+ *
+ * 'y1': int Y end point
+ *
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ $color = (isset($params['color']) ? $params['color'] : false);
+
+ $x0 = $this->_getX($x0);
+ $y0 = $this->_getY($y0);
+ $x1 = $this->_getX($x1);
+ $y1 = $this->_getY($y1);
+ if (($this->_antialias === 'driver') && ($x0 != $x1) && ($y0 != $y1)) {
+ $this->_antialiasedLine($x0, $y0, $x1, $y1, $color);
+ } elseif (($line = $this->_getLineStyle($color)) !== false) {
+ ImageLine($this->_canvas, $x0, $y0, $x1, $y1, $line);
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Parameter array:
+ *
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ *
+ * 'fill': mixed [optional] The fill color
+ *
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params)
+ {
+ include_once 'Image/Canvas/Tool.php';
+
+ $connectEnds = (isset($params['connect']) ? $params['connect'] : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ if (!$connectEnds) {
+ $fillColor = 'transparent';
+ }
+ $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);
+
+ $lastPoint = false;
+ foreach ($this->_polygon as $point) {
+ if (($lastPoint) && (isset($lastPoint['P1X']))
+ && (isset($lastPoint['P1Y'])) && (isset($lastPoint['P2X']))
+ && (isset($lastPoint['P2Y']))
+ ) {
+ $dx = abs($point['X'] - $lastPoint['X']);
+ $dy = abs($point['Y'] - $lastPoint['Y']);
+ $d = sqrt($dx * $dx + $dy * $dy);
+ if ($d > 0) {
+ $interval = 1 / $d;
+ for ($t = 0; $t <= 1; $t = $t + $interval) {
+ $x = Image_Canvas_Tool::bezier(
+ $t,
+ $lastPoint['X'],
+ $lastPoint['P1X'],
+ $lastPoint['P2X'],
+ $point['X']
+ );
+
+ $y = Image_Canvas_Tool::bezier(
+ $t,
+ $lastPoint['Y'],
+ $lastPoint['P1Y'],
+ $lastPoint['P2Y'],
+ $point['Y']
+ );
+
+ if (!isset($low['X'])) {
+ $low['X'] = $x;
+ } else {
+ $low['X'] = min($x, $low['X']);
+ }
+ if (!isset($high['X'])) {
+ $high['X'] = $x;
+ } else {
+ $high['X'] = max($x, $high['X']);
+ }
+ if (!isset($low['Y'])) {
+ $low['Y'] = $y;
+ } else {
+ $low['Y'] = min($y, $low['Y']);
+ }
+ if (!isset($high['Y'])) {
+ $high['Y'] = $y;
+ } else {
+ $high['Y'] = max($y, $high['Y']);
+ }
+ $polygon[] = $x;
+ $polygon[] = $y;
+ }
+ if (($t - $interval) < 1) {
+ $x = Image_Canvas_Tool::bezier(
+ 1,
+ $lastPoint['X'],
+ $lastPoint['P1X'],
+ $lastPoint['P2X'],
+ $point['X']
+ );
+
+ $y = Image_Canvas_Tool::bezier(
+ 1,
+ $lastPoint['Y'],
+ $lastPoint['P1Y'],
+ $lastPoint['P2Y'],
+ $point['Y']
+ );
+
+ $polygon[] = $x;
+ $polygon[] = $y;
+ }
+ }
+ } else {
+ if (!isset($low['X'])) {
+ $low['X'] = $point['X'];
+ } else {
+ $low['X'] = min($point['X'], $low['X']);
+ }
+ if (!isset($high['X'])) {
+ $high['X'] = $point['X'];
+ } else {
+ $high['X'] = max($point['X'], $high['X']);
+ }
+ if (!isset($low['Y'])) {
+ $low['Y'] = $point['Y'];
+ } else {
+ $low['Y'] = min($point['Y'], $low['Y']);
+ }
+ if (!isset($high['Y'])) {
+ $high['Y'] = $point['Y'];
+ } else {
+ $high['Y'] = max($point['Y'], $high['Y']);
+ }
+
+ $polygon[] = $point['X'];
+ $polygon[] = $point['Y'];
+ }
+ $lastPoint = $point;
+ }
+
+ if ((isset($polygon)) && (is_array($polygon))) {
+ if ($connectEnds) {
+ if (($fill = $this->_getFillStyle($fillColor, $low['X'], $low['Y'], $high['X'], $high['Y'])) !== false) {
+ ImageFilledPolygon($this->_canvas, $polygon, count($polygon)/2, $fill);
+ }
+ if ($this->_antialias === 'driver') {
+ $pfirst = $p0 = false;
+ reset($polygon);
+
+ while (list(, $x) = each($polygon)) {
+ list(, $y) = each($polygon);
+ if ($p0 !== false) {
+ $this->_antialiasedLine($p0['X'], $p0['Y'], $x, $y, $lineColor);
+ }
+ if ($pfirst === false) {
+ $pfirst = array('X' => $x, 'Y' => $y);
+ }
+ $p0 = array('X' => $x, 'Y' => $y);;
+ }
+
+ $this->_antialiasedLine($p0['X'], $p0['Y'], $pfirst['X'], $pfirst['Y'], $lineColor);
+ } elseif (($line = $this->_getLineStyle($lineColor)) !== false) {
+ ImagePolygon($this->_canvas, $polygon, count($polygon)/2, $line);
+ }
+ } else {
+ $prev_point = false;
+ if ($this->_antialias === 'driver') {
+ reset($polygon);
+ while (list(, $x) = each($polygon)) {
+ list(, $y) = each($polygon);
+ if ($prev_point) {
+ $this->_antialiasedLine(
+ $prev_point['X'],
+ $prev_point['Y'],
+ $x,
+ $y,
+ $lineColor
+ );
+ }
+ $prev_point = array('X' => $x, 'Y' => $y);;
+ }
+ } elseif (($line = $this->_getLineStyle($lineColor)) !== false) {
+ reset($polygon);
+ while (list(, $x) = each($polygon)) {
+ list(, $y) = each($polygon);
+ if ($prev_point) {
+ ImageLine(
+ $this->_canvas,
+ $prev_point['X'],
+ $prev_point['Y'],
+ $x,
+ $y,
+ $line
+ );
+ }
+ $prev_point = array('X' => $x, 'Y' => $y);;
+ }
+ }
+ }
+ }
+
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ *
+ * 'x0': int X start point
+ *
+ * 'y0': int Y start point
+ *
+ * 'x1': int X end point
+ *
+ * 'y1': int Y end point
+ *
+ * 'fill': mixed [optional] The fill color
+ *
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ if (($fill = $this->_getFillStyle($fillColor, $x0, $y0, $x1, $y1)) !== false) {
+ ImageFilledRectangle($this->_canvas, $x0, $y0, $x1, $y1, $fill);
+ }
+
+ if (($line = $this->_getLineStyle($lineColor)) !== false) {
+ ImageRectangle($this->_canvas, $x0, $y0, $x1, $y1, $line);
+ }
+
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ *
+ * 'x': int X center point
+ *
+ * 'y': int Y center point
+ *
+ * 'rx': int X radius
+ *
+ * 'ry': int Y radius
+ *
+ * 'fill': mixed [optional] The fill color
+ *
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ if (($fill = $this->_getFillStyle($fillColor, $x - $rx, $y - $ry, $x + $rx, $y + $ry)) !== false) {
+ ImageFilledEllipse($this->_canvas, $x, $y, $rx * 2, $ry * 2, $fill);
+ }
+
+ if (($line = $this->_getLineStyle($lineColor)) !== false) {
+ ImageEllipse($this->_canvas, $x, $y, $rx * 2, $ry * 2, $line);
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ *
+ * 'x': int X center point
+ *
+ * 'y': int Y center point
+ *
+ * 'rx': int X radius
+ *
+ * 'ry': int Y radius
+ *
+ * 'v1': int The starting angle (in degrees)
+ *
+ * 'v2': int The end angle (in degrees)
+ *
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ *
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ *
+ * 'fill': mixed [optional] The fill color
+ *
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $params['rx'];
+ $ry = $params['ry'];
+ $v1 = $params['v1'];
+ $v2 = $params['v2'];
+ $srx = (isset($params['srx']) ? $params['srx'] : 0);
+ $sry = (isset($params['sry']) ? $params['sry'] : 0);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $dA = 0.1;
+
+ if (($srx !== false) && ($sry !== false)) {
+ $angle = max($v1, $v2);
+ while ($angle >= min($v1, $v2)) {
+ $polygon[] = ($x + $srx * cos(deg2rad($angle % 360)));
+ $polygon[] = ($y + $sry * sin(deg2rad($angle % 360)));
+ $angle -= $dA;
+ }
+ if (($angle + $dA) > min($v1, $v2)) {
+ $polygon[] = ($x + $srx * cos(deg2rad(min($v1, $v2) % 360)));
+ $polygon[] = ($y + $sry * sin(deg2rad(min($v1, $v2) % 360)));
+ }
+ } else {
+ $polygon[] = $x;
+ $polygon[] = $y;
+ }
+
+ $angle = min($v1, $v2);
+ while ($angle <= max($v1, $v2)) {
+ $polygon[] = ($x + $rx * cos(deg2rad($angle % 360)));
+ $polygon[] = ($y + $ry * sin(deg2rad($angle % 360)));
+ $angle += $dA;
+ }
+
+ if (($angle - $dA) < max($v1, $v2)) {
+ $polygon[] = ($x + $rx * cos(deg2rad(max($v1, $v2) % 360)));
+ $polygon[] = ($y + $ry * sin(deg2rad(max($v1, $v2) % 360)));
+ }
+
+ if ((($fill = $this->_getFillStyle($fillColor, $x - $rx - 1, $y - $ry - 1, $x + $rx + 1, $y + $ry + 1)) !== false) && (count($polygon) > 2)) {
+ ImageFilledPolygon($this->_canvas, $polygon, count($polygon) / 2, $fill);
+ }
+
+ if (($line = $this->_getLineStyle($lineColor)) !== false) {
+ ImagePolygon($this->_canvas, $polygon, count($polygon) / 2, $line);
+ }
+
+ parent::pieSlice($params);
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ if (isset($this->_font['file'])) {
+ $angle = 0;
+ if (isset($this->_font['angle'])) {
+ $angle = $this->_font['angle'];
+ }
+
+ $width = 0;
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+ $bounds = ImageTTFBBox(
+ $this->_font['size']*$this->_pxToPtFactor,
+ $angle,
+ $this->_font['file'],
+ $text
+ );
+
+ $x0 = min($bounds[0], $bounds[2], $bounds[4], $bounds[6]);
+ $x1 = max($bounds[0], $bounds[2], $bounds[4], $bounds[6]);
+ $width = max(abs($x0 - $x1), $width);
+ }
+ return $width;
+ } else {
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);
+ } else {
+ $width = 0;
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+ $width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));
+ }
+ return $width;
+ }
+ }
+ }
+
+ /**
+ * Get the height of a text.
+ *
+ * Note! This method can give some peculiar results, since ImageTTFBBox() returns the total
+ * bounding box of a text, where ImageTTF() writes the text on the baseline of the text, that
+ * is 'g', 'p', 'q' and other letters that dig under the baseline will appear to have a larger
+ * height than they actually do. Have a look at the tests/text.php test case - the first two
+ * columns, 'left and 'center', both look alright, whereas the last column, 'right', appear
+ * with a larger space between the first text and the second. This is because the total height
+ * is actually smaller by exactly the number of pixels that the 'g' digs under the baseline.
+ * Remove the 'g' from the text and they appear correct.
+ *
+ * @param string $text The text to get the height of
+ * @param bool $force Force the method to calculate the size
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text, $force = false)
+ {
+ if (isset($this->_font['file'])) {
+ $angle = 0;
+ if (isset($this->_font['angle'])) {
+ $angle = $this->_font['angle'];
+ }
+
+ $linebreaks = substr_count($text, "\n");
+ if (($angle == 0) && ($force === false)) {
+ /*
+ * if the angle is 0 simply return the size, due to different
+ * heights for example for x-axis labels, making the labels
+ * _not_ appear as written on the same baseline
+ */
+ return $this->_font['size'] + ($this->_font['size'] + 2) * $linebreaks;
+ }
+
+ $height = 0;
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+ $bounds = ImageTTFBBox(
+ $this->_font['size']*$this->_pxToPtFactor,
+ $angle,
+ $this->_font['file'],
+ $line
+ );
+
+ $y0 = min($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
+ $y1 = max($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
+ $height += abs($y0 - $y1);
+ }
+ return $height + $linebreaks * 2;
+ } else {
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ $width = 0;
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+ $width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));
+ }
+ return $width;
+ } else {
+ return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);
+ }
+ }
+ }
+
+ /**
+ * Calculated the absolute bottom-left position of the text, by simulating
+ * the calculation of the baseline drop.
+ *
+ * @param int $x The relative x position to write the text
+ * @param int $y The relative y position to write the text
+ * @param string $text The text to write
+ * @param array $align The alignment of the text relative to (x, y)
+ *
+ * @return array An array containing the absolute x and y positions
+ * @access private
+ */
+ function _getAbsolutePosition($x, $y, $text, $align)
+ {
+ if ($this->_font['angle'] > 0) {
+ $w0 = $this->textWidth($text);
+ $h0 = $this->textHeight($text);
+
+ if ($align['vertical'] == 'bottom') {
+ $dy = $y - $h0;
+ } else if ($align['vertical'] == 'center') {
+ $dy = $y - $h0 / 2;
+ } else if ($align['vertical'] == 'top') {
+ $dy = $y;
+ }
+
+ if ($align['horizontal'] == 'right') {
+ $dx = $x - $w0;
+ } else if ($align['horizontal'] == 'center') {
+ $dx = $x - $w0 / 2;
+ } else if ($align['horizontal'] == 'left') {
+ $dx = $x;
+ }
+
+ if (($this->_font['angle'] < 180) && ($this->_font['angle'] >= 0)) {
+ $dy += $h0;
+ }
+ if (($this->_font['angle'] >= 90) && ($this->_font['angle'] < 270)) {
+ $dx += $w0;
+ }
+ } else {
+ // get the maximum size of normal text above base line - sampled by 'Al'
+ $size1 = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'Al');
+ $height1 = abs($size1[7] - $size1[1]);
+
+ // get the maximum size of all text above base and below line - sampled by 'AlgjpqyQ'
+ $size2 = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'AlgjpqyQ');
+ $height2 = abs($size2[7] - $size2[1]);
+
+ // get the size of the text, simulating height above baseline beinh max, by sampling using 'Al'
+ $size = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'Al' . $text);
+ $height = abs($size[7] - $size[1]);
+
+ // if all text is above baseline, i.e. height of text compares to max height above (within 10%)
+ if (abs($height - $height1)/$height1 < 0.1) {
+ $dHeight = 0;
+ } else {
+ $dHeight = abs($height2 - $height1);
+ }
+
+ // specifies the bottom-left corner!
+ $dx = $x + sin(deg2rad($this->_font['angle'])) * $dHeight;
+ $dy = $y - cos(deg2rad($this->_font['angle'])) * $dHeight;
+
+ if ($align['vertical'] == 'top') {
+ $dy += $height;
+ } else if ($align['vertical'] == 'center') {
+ $dy += ($height + $dHeight) / 2;
+ } else if ($align['vertical'] == 'bottom') {
+ $dy += $dHeight;
+ }
+
+ if ($align['horizontal'] == 'center') {
+ $factor = 0.5;
+ } else if ($align['horizontal'] == 'right') {
+ $factor = 1;
+ } else {
+ $factor = 0;
+ }
+
+ if ($factor != 0) {
+ $size = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], $text);
+ $w0 = abs($size[2] - $size[0]);
+ $dx -= cos(deg2rad($this->_font['angle'])) * $w0 * $factor;
+ $dy += sin(deg2rad($this->_font['angle'])) * $w0 * $factor;
+ }
+ }
+
+ return array('x' => $dx, 'y' => $dy);
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ *
+ * 'x': int X-point of text
+ *
+ * 'y': int Y-point of text
+ *
+ * 'text': string The text to add
+ *
+ * 'alignment': array [optional] Alignment
+ *
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ $x0 = $this->_getX($params['x']);
+ $y0 = $this->_getY($params['y']);
+ $text = $params['text'];
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ $text = str_replace("\r", '', $text);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if (isset($this->_font['size'])) {
+ $textHeight = $this->_font['size'] + 2;
+ } else {
+ $textHeight = $this->textHeight('A');
+ }
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+ $x = $x0;
+ $y = $y0;
+
+ $y0 += $textHeight + 2;
+
+ if (($color === false) && (isset($this->_font['color']))) {
+ $color = $this->_font['color'];
+ }
+
+ if ($color != 'transparent') {
+ if (isset($this->_font['file'])) {
+ $result = $this->_getAbsolutePosition($x, $y, $line, $alignment);
+ ImageTTFText(
+ $this->_canvas,
+ $this->_font['size']*$this->_pxToPtFactor,
+ $this->_font['angle'],
+ $result['x'],
+ $result['y'],
+ $this->_color($color),
+ $this->_font['file'],
+ $line
+ );
+ } else {
+ $width = $this->textWidth($line);
+ $height = $this->textHeight($line);
+ if ($alignment['horizontal'] == 'right') {
+ $x -= $width;
+ } else if ($alignment['horizontal'] == 'center') {
+ $x -= $width / 2;
+ }
+ if ($alignment['vertical'] == 'bottom') {
+ $y -= $height;
+ } else if ($alignment['vertical'] == 'center') {
+ $y -= $height / 2;
+ }
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ ImageStringUp(
+ $this->_canvas,
+ $this->_font['font'],
+ $x,
+ $y + $this->textHeight($text),
+ $line,
+ $this->_color($color)
+ );
+ } else {
+ ImageString(
+ $this->_canvas,
+ $this->_font['font'],
+ $x,
+ $y,
+ $line,
+ $this->_color($color)
+ );
+ }
+ }
+ }
+ }
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ *
+ * 'x': int X-point of overlayed image
+ *
+ * 'y': int Y-point of overlayed image
+ *
+ * 'filename': string The filename of the image to overlay
+ *
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ *
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ *
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $filename = $params['filename'];
+ $width = (isset($params['width']) ? $params['width'] : false);
+ $height = (isset($params['height']) ? $params['height'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if (file_exists($filename)) {
+ if (strtolower(substr($filename, -4)) == '.png') {
+ $image = ImageCreateFromPNG($filename);
+ } elseif (strtolower(substr($filename, -4)) == '.gif') {
+ $image = ImageCreateFromGIF($filename);
+ } else {
+ $image = ImageCreateFromJPEG($filename);
+ }
+
+ $imgWidth = ImageSX($image);
+ $imgHeight = ImageSY($image);
+
+ $outputWidth = ($width !== false ? $width : $imgWidth);
+ $outputHeight = ($height !== false ? $height : $imgHeight);
+
+ if ($alignment['horizontal'] == 'right') {
+ $x -= $outputWidth;
+ } elseif ($alignment['horizontal'] == 'center') {
+ $x -= $outputWidth / 2;
+ }
+
+ if ($alignment['vertical'] == 'bottom') {
+ $y -= $outputHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y -= $outputHeight / 2;
+ }
+
+ if ((($width !== false) && ($width != $imgWidth))
+ || (($height !== false) && ($height != $imgHeight))
+ ) {
+ if ($this->_gd2) {
+ ImageCopyResampled(
+ $this->_canvas,
+ $image,
+ $x,
+ $y,
+ 0,
+ 0,
+ $width,
+ $height,
+ $imgWidth,
+ $imgHeight
+ );
+ } else {
+ ImageCopyResized(
+ $this->_canvas,
+ $image,
+ $x,
+ $y,
+ 0,
+ 0,
+ $width,
+ $height,
+ $imgWidth,
+ $imgHeight
+ );
+ }
+ } else {
+ ImageCopy(
+ $this->_canvas,
+ $image,
+ $x,
+ $y,
+ 0,
+ 0,
+ $imgWidth,
+ $imgHeight
+ );
+ }
+ ImageDestroy($image);
+ }
+ parent::image($params);
+ }
+
+ /**
+ * Set clipping to occur
+ *
+ * Parameter array:
+ *
+ * 'x0': int X point of Upper-left corner
+ * 'y0': int X point of Upper-left corner
+ * 'x1': int X point of lower-right corner
+ * 'y1': int Y point of lower-right corner
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function setClipping($params = false)
+ {
+ if ($params === false) {
+ $index = count($this->_clipping) - 1;
+ if (isset($this->_clipping[$index])) {
+ $params = $this->_clipping[$index];
+ $canvas = $params['canvas'];
+ ImageCopy(
+ $canvas,
+ $this->_canvas,
+ min($params['x0'], $params['x1']),
+ min($params['y0'], $params['y1']),
+ min($params['x0'], $params['x1']),
+ min($params['y0'], $params['y1']),
+ abs($params['x1'] - $params['x0'] + 1),
+ abs($params['y1'] - $params['y0'] + 1)
+ );
+ $this->_canvas = $canvas;
+ unset($this->_clipping[$index]);
+ }
+ } else {
+ $params['canvas'] = $this->_canvas;
+
+ if ($this->_gd2) {
+ $this->_canvas = ImageCreateTrueColor(
+ $this->_width,
+ $this->_height
+ );
+ if ($this->_alpha) {
+ ImageAlphaBlending($this->_canvas, true);
+ }
+ } else {
+ $this->_canvas = ImageCreate($this->_width, $this->_height);
+ }
+
+ if (($this->_gd2) && ($this->_antialias === 'native')) {
+ ImageAntialias($this->_canvas, true);
+ }
+
+ ImageCopy($this->_canvas, $params['canvas'], 0, 0, 0, 0, $this->_width, $this->_height);
+
+ $this->_clipping[count($this->_clipping)] = $params;
+ }
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ *
+ * 'filename' string
+ *
+ * 'filepath': string Path to the file on the file system. Remember the final slash
+ *
+ * 'urlpath': string Path to the file available through an URL. Remember the final slash
+ *
+ * 'alt': string [optional] Alternative text on image
+ *
+ * 'cssclass': string [optional] The CSS Stylesheet class
+ *
+ * 'border': int [optional] The border width on the image
+ *
+ * @param array $params Parameter array
+ *
+ * @return string HTML code
+ */
+ function toHtml($params)
+ {
+ parent::toHtml($params);
+ return '<img src="' . $params['urlpath'] . $params['filename'] . '"' .
+ (isset($params['alt']) ? ' alt="' . $params['alt'] . '"' : '') .
+ (isset($params['cssclass']) ? ' class="' . $params['cssclass'] . '"' : '') .
+ (isset($params['border']) ? ' border="' . $params['border'] . '"' : '') .
+ (isset($this->_imageMap) ? ' usemap="#' . $params['filename'] . '"' : '') . ' />' .
+ (isset($this->_imageMap) ? "\n" . $this->_imageMap->toHtml(array('name' => $params['filename'])) : '');
+ }
+
+ /**
+ * Resets the canvas.
+ *
+ * Include fillstyle, linestyle, thickness and polygon
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ if ($this->_gd2) {
+ ImageSetThickness($this->_canvas, 1);
+ }
+ if ($this->_tileImage != null) {
+ ImageDestroy($this->_tileImage);
+ $this->_tileImage = null;
+ }
+ parent::_reset();
+ $this->_font = array('font' => 1, 'color' => 'black');
+ }
+
+ /**
+ * Check which version of GD is installed
+ *
+ * @return int 0 if GD isn't installed, 1 if GD 1.x is installed and 2 if GD
+ * 2.x is installed
+ * @access private
+ */
+ function _version()
+ {
+ $result = false;
+ if (function_exists('gd_info')) {
+ $info = gd_info();
+ $version = $info['GD Version'];
+ } else {
+ ob_start();
+ phpinfo(8);
+ $php_info = ob_get_contents();
+ ob_end_clean();
+
+ if (preg_match("/<td[^>]*>GD Version *<\/td><td[^>]*>([^<]*)<\/td>/", $php_info, $result)
+ ) {
+ $version = $result[1];
+ } else {
+ $version = null;
+ }
+ }
+
+ if (preg_match('/1\.[0-9]{1,2}/', $version)) {
+ return 1;
+ } elseif (preg_match('/2\.[0-9]{1,2}/', $version)) {
+ return 2;
+ } else {
+ return 0;
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Canvas class to handle JPEG format.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: JPG.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Include file Image/Canvas/GD.php\r
- */\r
-require_once 'Image/Canvas/GD.php';\r
-\r
-/**\r
- * JPEG Canvas class.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_GD_JPG extends Image_Canvas_GD\r
-{\r
- \r
- /**\r
- * The JPEG quality\r
- * @var int\r
- * @access private\r
- */\r
- var $_quality = 75;\r
- \r
- /**\r
- * Create the JPEG canvas\r
- * \r
- * Additional parameters other than those available for common {@link\r
- * Image_Graph_Canvas_GD} class are:\r
- * \r
- * 'quality' The JPEG quality in as a percentage value from 0 (lowest\r
- * quality, smallest file) to 100 (highest quality, biggest file)\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_GD_JPG($param)\r
- {\r
- parent::Image_Canvas_GD($param);\r
- \r
- if (isset($param['quality'])) {\r
- $this->_quality = max(0, min(100, $param['quality']));\r
- } \r
-\r
- $this->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_left + $this->_width - 1,\r
- 'y1' => $this->_top + $this->_height - 1,\r
- 'fill' => 'white',\r
- 'line' => 'transparent'\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- header('Content-type: image/jpg');\r
- header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.jpg\"');\r
- ImageJPEG($this->_canvas, '', $this->_quality);\r
- ImageDestroy($this->_canvas);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function save($param = false)\r
- {\r
- parent::save($param);\r
- ImageJPEG($this->_canvas, $param['filename'], $this->_quality);\r
- ImageDestroy($this->_canvas);\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Canvas class to handle JPEG format.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: JPG.php 292376 2009-12-20 21:21:29Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas/GD.php
+ */
+require_once 'Image/Canvas/GD.php';
+
+/**
+ * JPEG Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_GD_JPG extends Image_Canvas_GD
+{
+
+ /**
+ * The JPEG quality
+ * @var int
+ * @access private
+ */
+ var $_quality = 75;
+
+ /**
+ * Create the JPEG canvas
+ *
+ * Additional parameters other than those available for common {@link
+ * Image_Graph_Canvas_GD} class are:
+ *
+ * 'quality' The JPEG quality in as a percentage value from 0 (lowest
+ * quality, smallest file) to 100 (highest quality, biggest file)
+ *
+ * @param array $param Parameter array
+ */
+ function Image_Canvas_GD_JPG($param)
+ {
+ parent::Image_Canvas_GD($param);
+
+ if (isset($param['quality'])) {
+ $this->_quality = max(0, min(100, $param['quality']));
+ }
+
+ $this->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_left + $this->_width - 1,
+ 'y1' => $this->_top + $this->_height - 1,
+ 'fill' => 'white',
+ 'line' => 'transparent'
+ )
+ );
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+ header('Content-type: image/jpg');
+ header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.jpg\"');
+ ImageJPEG($this->_canvas, '', $this->_quality);
+ ImageDestroy($this->_canvas);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function save($param = false)
+ {
+ parent::save($param);
+ ImageJPEG($this->_canvas, $param['filename'], $this->_quality);
+ ImageDestroy($this->_canvas);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Canvas class to handle PNG format.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: PNG.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
- \r
-/**\r
- * Include file Image/Canvas/GD.php\r
- */\r
-require_once 'Image/Canvas/GD.php';\r
-\r
-/**\r
- * PNG Canvas class.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_GD_PNG extends Image_Canvas_GD\r
-{\r
-\r
- /**\r
- * Create the PNG canvas\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_GD_PNG($param)\r
- {\r
- parent::Image_Canvas_GD($param);\r
-\r
- if ((isset($param['transparent'])) && ($param['transparent']) &&\r
- ($this->_gd2)\r
- ) {\r
- if ($param['transparent'] === true) {\r
- $transparent = '#123ABD';\r
- } else {\r
- $transparent = $param['transparent'];\r
- }\r
- $color = $this->_color($transparent);\r
- $trans = ImageColorTransparent($this->_canvas, $color);\r
-\r
- $this->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_left + $this->_width - 1,\r
- 'y1' => $this->_top + $this->_height - 1,\r
- 'fill' => 'opague',\r
- 'line' => 'transparent'\r
- )\r
- );\r
- } else {\r
- $this->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_left + $this->_width - 1,\r
- 'y1' => $this->_top + $this->_height - 1,\r
- 'fill' => 'white',\r
- 'line' => 'transparent'\r
- )\r
- );\r
- }\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- header('Content-type: image/png');\r
- header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.png\"');\r
- ImagePNG($this->_canvas);\r
- ImageDestroy($this->_canvas); \r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function save($param = false)\r
- {\r
- parent::save($param);\r
- ImagePNG($this->_canvas, $param['filename']);\r
- ImageDestroy($this->_canvas);\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Canvas class to handle PNG format.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: PNG.php 292376 2009-12-20 21:21:29Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas/GD.php
+ */
+require_once 'Image/Canvas/GD.php';
+
+/**
+ * PNG Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_GD_PNG extends Image_Canvas_GD
+{
+
+ /**
+ * Create the PNG canvas
+ *
+ * @param array $param Parameter array
+ */
+ function Image_Canvas_GD_PNG($param)
+ {
+ parent::Image_Canvas_GD($param);
+
+ if ((isset($param['transparent'])) && ($param['transparent'])
+ && ($this->_gd2)
+ ) {
+ if ($param['transparent'] === true) {
+ $transparent = '#123ABD';
+ } else {
+ $transparent = $param['transparent'];
+ }
+ $color = $this->_color($transparent);
+ $trans = ImageColorTransparent($this->_canvas, $color);
+
+ $this->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_left + $this->_width - 1,
+ 'y1' => $this->_top + $this->_height - 1,
+ 'fill' => 'opague',
+ 'line' => 'transparent'
+ )
+ );
+ } else {
+ $this->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_left + $this->_width - 1,
+ 'y1' => $this->_top + $this->_height - 1,
+ 'fill' => 'white',
+ 'line' => 'transparent'
+ )
+ );
+ }
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+ header('Content-type: image/png');
+ header('Content-Disposition: inline; filename = \"'. basename($_SERVER['PHP_SELF'], '.php') . '.png\"');
+ ImagePNG($this->_canvas);
+ ImageDestroy($this->_canvas);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function save($param = false)
+ {
+ parent::save($param);
+ ImagePNG($this->_canvas, $param['filename']);
+ ImageDestroy($this->_canvas);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Class for handling output as a HTML imagemap\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: ImageMap.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Class for handling output as a HTML imagemap\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- * @since version 0.2.0\r
- */\r
-class Image_Canvas_ImageMap extends Image_Canvas\r
-{\r
- \r
- /**\r
- * The image map (if any)\r
- * @var array\r
- * @access private\r
- */\r
- var $_map = array();\r
- \r
- /**\r
- * Add a map tag\r
- * @param string $shape The shape, either rect, circle or polygon\r
- * @param string $coords The list of coordinates for the shape\r
- * @param array $params Parameter array\r
- */\r
- function _addMapTag($shape, $coords, $params)\r
- {\r
- if (isset($params['url'])) {\r
- $url = $params['url'];\r
- $target = (isset($params['target']) ? $params['target'] : false);\r
- $alt = (isset($params['alt']) ? $params['alt'] : false);\r
- \r
- $tags = '';\r
- if (isset($params['htmltags'])) {\r
- foreach ($params['htmltags'] as $key => $value) {\r
- $tags .= ' ';\r
- if (strpos($value, '"') !== false) {\r
- $tags .= $key . '=\'' . $value . '\'';\r
- } else {\r
- $tags .= $key . '="' . $value . '"';\r
- }\r
- }\r
- }\r
- \r
- $this->_map[] = \r
- '<area shape="' . $shape . '" coords="' . $coords . '" href="' . $url . '"' .\r
- ($target ? ' target="' . $target . '"' : '') .\r
- ($alt ? ' alt="' . $alt . '"' : '') .\r
- (isset($params['id']) ? ' id="' . $params['id'] . '"' : '') .\r
- $tags .\r
- ' />';\r
- }\r
- } \r
- \r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'color': mixed [optional] The line color\r
- * 'mapsize': int [optional] The size of the image map (surrounding the line)\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- if (isset($params['url'])) {\r
- $mapsize = (isset($params['mapsize']) ? $params['mapsize'] : 2);\r
- $this->_addMapTag(\r
- 'poly', \r
- $this->_getX($params['x0'] - $mapsize) . ',' . \r
- $this->_getY($params['y0'] - $mapsize) . ',' .\r
- $this->_getX($params['x1'] + $mapsize) . ',' .\r
- $this->_getY($params['y1'] - $mapsize) . ',' .\r
- \r
- $this->_getX($params['x1'] + $mapsize) . ',' . \r
- $this->_getY($params['y1'] + $mapsize) . ',' .\r
- $this->_getX($params['x0'] - $mapsize) . ',' .\r
- $this->_getY($params['y0'] + $mapsize),\r
- $params\r
- );\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Draws a polygon\r
- *\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * 'map_vertices': bool [optional] Specifies whether the image map should map the vertices instead of the polygon as a whole\r
- * 'url': string [optional] URL to link the polygon as a whole to (also used for default in case 'map_vertices' is used)\r
- * 'alt': string [optional] Alternative text to show in the image map (also used for default in case 'map_vertices' is used)\r
- * 'target': string [optional] The link target on the image map (also used for default in case 'map_vertices' is used)\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params)\r
- {\r
- if ((isset($params['map_vertices'])) && ($params['map_vertices'] === true)) {\r
- $mapsize = (isset($params['mapsize']) ? $params['mapsize'] : 2);\r
- foreach ($this->_polygon as $point) {\r
- $vertex_param = $params;\r
- if (isset($point['url'])) {\r
- $vertex_param['url'] = $point['url'];\r
- }\r
- if (isset($point['target'])) {\r
- $vertex_param['target'] = $point['target'];\r
- }\r
- if (isset($point['alt'])) {\r
- $vertex_param['alt'] = $point['alt'];\r
- }\r
- $vertex_mapsize = $mapsize;\r
- if (isset($point['mapsize'])) {\r
- $vertex_mapsize = $point['mapsize'];\r
- } \r
- if (isset($point['htmltags'])) {\r
- $vertex_param['htmltags'] = $point['htmltags'];\r
- }\r
- $this->_addMapTag(\r
- 'circle', \r
- $this->_getX($point['X']) . ',' . \r
- $this->_getY($point['Y']) . ',' .\r
- $mapsize,\r
- $vertex_param\r
- );\r
- }\r
- }\r
- else if (isset($params['url'])) {\r
- $points = '';\r
- foreach ($this->_polygon as $point) {\r
- if ($points != '') {\r
- $points .= ',';\r
- }\r
- $points .= $this->_getX($point['X']) . ',' . $this->_getY($point['Y']); \r
- }\r
- $this->_addMapTag('poly', $points, $params);\r
- }\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- if (isset($params['url'])) {\r
- $this->_addMapTag(\r
- 'rect', \r
- $this->_getX($params['x0']) . ',' . \r
- $this->_getY($params['y0']) . ',' .\r
- $this->_getX($params['x1']) . ',' .\r
- $this->_getY($params['y1']),\r
- $params\r
- );\r
- }\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- if (isset($params['url'])) { \r
- if ($params['rx'] == $params['ry']) {\r
- $this->_addMapTag(\r
- 'circle', \r
- $this->_getX($params['x']) . ',' . \r
- $this->_getY($params['y']) . ',' .\r
- $this->_getX($params['rx']),\r
- $params\r
- );\r
- } else {\r
- $points = '';\r
- for ($v = 0; $v <= 360; $v += 30) {\r
- if ($points != '') {\r
- $points .= ',';\r
- }\r
- $points .=\r
- round($this->_getX($params['x']) + $this->_getX($params['rx']) * cos(deg2rad($v % 360))) . ',' .\r
- round($this->_getY($params['y']) + $this->_getX($params['ry']) * sin(deg2rad($v % 360))); \r
- }\r
- $this->_addMapTag(\r
- 'poly',\r
- $points,\r
- $params\r
- );\r
- }\r
- }\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- if (isset($params['url'])) { \r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $params['rx'];\r
- $ry = $params['ry'];\r
- $v1a = $params['v1'];\r
- $v2a = $params['v2'];\r
- $v1 = min($v1a, $v2a);\r
- $v2 = max($v1a, $v2a);\r
- $srx = (isset($params['srx']) ? $params['srx'] : 0);\r
- $sry = (isset($params['sry']) ? $params['sry'] : 0);\r
- \r
- $points = \r
- round(($x + $srx * cos(deg2rad($v1 % 360)))) . ',' .\r
- round(($y + $sry * sin(deg2rad($v1 % 360)))) . ',';\r
- \r
- for ($v = $v1; $v < $v2; $v += 30) {\r
- $points .= \r
- round(($x + $rx * cos(deg2rad($v % 360)))) . ',' .\r
- round(($y + $ry * sin(deg2rad($v % 360)))) . ','; \r
- }\r
- \r
- $points .=\r
- round(($x + $rx * cos(deg2rad($v2 % 360)))) . ',' .\r
- round(($y + $ry * sin(deg2rad($v2 % 360))));\r
- \r
- if (($srx != 0) || ($sry != 0)) {\r
- $points .= ',';\r
- for ($v = $v2; $v > $v1; $v -= 30) { \r
- $points .= \r
- round(($x + $srx * cos(deg2rad($v % 360)))) . ',' .\r
- round(($y + $sry * sin(deg2rad($v % 360)))) . ','; \r
- }\r
-\r
- }\r
- \r
- $this->_addMapTag('poly', $points, $params);\r
- }\r
- parent::pieslice($params);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas to the browser\r
- *\r
- * @param array $params Parameter array, the contents and meaning depends on the actual Canvas\r
- * @abstract\r
- */\r
- function show($params = false)\r
- {\r
- parent::show($params);\r
- if (count($this->_map) > 0) {\r
- print $this->toHtml($params);\r
- }\r
- }\r
-\r
- /**\r
- * Save the result of the canvas to a file\r
- *\r
- * Parameter array:\r
- * 'filename': string The file to output to\r
- * @param array $params Parameter array, the contents and meaning depends on the actual Canvas\r
- * @abstract\r
- */\r
- function save($params = false)\r
- {\r
- parent::save($params);\r
- $file = fopen($params['filename'], 'w+');\r
- fwrite($file, $this->toHtml($params)); \r
- fclose($file);\r
- }\r
- \r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * Parameter array:\r
- * 'name': string The name of the image map\r
- */\r
- function toHtml($params)\r
- {\r
- if (count($this->_map) > 0) {\r
- return '<map name="' . $params['name'] . '" id="' . $params['name'] . '">' . "\n\t" . implode($this->_map, "\n\t") . "\n</map>";\r
- }\r
- return ''; \r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Class for handling output as a HTML imagemap
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: ImageMap.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Class for handling output as a HTML imagemap
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ * @since version 0.2.0
+ */
+class Image_Canvas_ImageMap extends Image_Canvas
+{
+
+ /**
+ * The image map (if any)
+ * @var array
+ * @access private
+ */
+ var $_map = array();
+
+ /**
+ * Add a map tag
+ *
+ * @param string $shape The shape, either rect, circle or polygon
+ * @param string $coords The list of coordinates for the shape
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function _addMapTag($shape, $coords, $params)
+ {
+ if (isset($params['url'])) {
+ $url = $params['url'];
+ $target = (isset($params['target']) ? $params['target'] : false);
+ $alt = (isset($params['alt']) ? $params['alt'] : false);
+
+ $tags = '';
+ if (isset($params['htmltags'])) {
+ foreach ($params['htmltags'] as $key => $value) {
+ $tags .= ' ';
+ if (strpos($value, '"') !== false) {
+ $tags .= $key . '=\'' . $value . '\'';
+ } else {
+ $tags .= $key . '="' . $value . '"';
+ }
+ }
+ }
+
+ $this->_map[] = '<area shape="' . $shape . '" coords="' . $coords . '" href="' . $url . '"' .
+ ($target ? ' target="' . $target . '"' : '') .
+ ($alt ? ' alt="' . $alt . '"' : '') .
+ (isset($params['id']) ? ' id="' . $params['id'] . '"' : '') .
+ $tags .
+ ' />';
+ }
+ }
+
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'color': mixed [optional] The line color
+ * 'mapsize': int [optional] The size of the image map (surrounding the line)
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ if (isset($params['url'])) {
+ $mapsize = (isset($params['mapsize']) ? $params['mapsize'] : 2);
+ $this->_addMapTag(
+ 'poly',
+ $this->_getX($params['x0'] - $mapsize) . ',' .
+ $this->_getY($params['y0'] - $mapsize) . ',' .
+ $this->_getX($params['x1'] + $mapsize) . ',' .
+ $this->_getY($params['y1'] - $mapsize) . ',' .
+ //
+ $this->_getX($params['x1'] + $mapsize) . ',' .
+ $this->_getY($params['y1'] + $mapsize) . ',' .
+ $this->_getX($params['x0'] - $mapsize) . ',' .
+ $this->_getY($params['y0'] + $mapsize),
+ $params
+ );
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Draws a polygon
+ *
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ * 'map_vertices': bool [optional] Specifies whether the image map should map the vertices instead of the polygon as a whole
+ * 'url': string [optional] URL to link the polygon as a whole to (also used for default in case 'map_vertices' is used)
+ * 'alt': string [optional] Alternative text to show in the image map (also used for default in case 'map_vertices' is used)
+ * 'target': string [optional] The link target on the image map (also used for default in case 'map_vertices' is used)
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params)
+ {
+ if ((isset($params['map_vertices'])) && ($params['map_vertices'] === true)) {
+ $mapsize = (isset($params['mapsize']) ? $params['mapsize'] : 2);
+ foreach ($this->_polygon as $point) {
+ $vertex_param = $params;
+ if (isset($point['url'])) {
+ $vertex_param['url'] = $point['url'];
+ }
+ if (isset($point['target'])) {
+ $vertex_param['target'] = $point['target'];
+ }
+ if (isset($point['alt'])) {
+ $vertex_param['alt'] = $point['alt'];
+ }
+ $vertex_mapsize = $mapsize;
+ if (isset($point['mapsize'])) {
+ $vertex_mapsize = $point['mapsize'];
+ }
+ if (isset($point['htmltags'])) {
+ $vertex_param['htmltags'] = $point['htmltags'];
+ }
+ $this->_addMapTag(
+ 'circle',
+ $this->_getX($point['X']) . ',' .
+ $this->_getY($point['Y']) . ',' .
+ $mapsize,
+ $vertex_param
+ );
+ }
+ } else if (isset($params['url'])) {
+ $points = '';
+ foreach ($this->_polygon as $point) {
+ if ($points != '') {
+ $points .= ',';
+ }
+ $points .= $this->_getX($point['X']) . ',' . $this->_getY($point['Y']);
+ }
+ $this->_addMapTag('poly', $points, $params);
+ }
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ if (isset($params['url'])) {
+ $this->_addMapTag(
+ 'rect',
+ $this->_getX($params['x0']) . ',' .
+ $this->_getY($params['y0']) . ',' .
+ $this->_getX($params['x1']) . ',' .
+ $this->_getY($params['y1']),
+ $params
+ );
+ }
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ if (isset($params['url'])) {
+ if ($params['rx'] == $params['ry']) {
+ $this->_addMapTag(
+ 'circle',
+ $this->_getX($params['x']) . ',' .
+ $this->_getY($params['y']) . ',' .
+ $this->_getX($params['rx']),
+ $params
+ );
+ } else {
+ $points = '';
+ for ($v = 0; $v <= 360; $v += 30) {
+ if ($points != '') {
+ $points .= ',';
+ }
+ $points .=
+ round($this->_getX($params['x']) + $this->_getX($params['rx']) * cos(deg2rad($v % 360))) . ',' .
+ round($this->_getY($params['y']) + $this->_getX($params['ry']) * sin(deg2rad($v % 360)));
+ }
+ $this->_addMapTag(
+ 'poly',
+ $points,
+ $params
+ );
+ }
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ if (isset($params['url'])) {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $params['rx'];
+ $ry = $params['ry'];
+ $v1a = $params['v1'];
+ $v2a = $params['v2'];
+ $v1 = min($v1a, $v2a);
+ $v2 = max($v1a, $v2a);
+ $srx = (isset($params['srx']) ? $params['srx'] : 0);
+ $sry = (isset($params['sry']) ? $params['sry'] : 0);
+
+ $points = round(($x + $srx * cos(deg2rad($v1 % 360)))) . ',' .
+ round(($y + $sry * sin(deg2rad($v1 % 360)))) . ',';
+
+ for ($v = $v1; $v < $v2; $v += 30) {
+ $points .= round(($x + $rx * cos(deg2rad($v % 360)))) . ',' .
+ round(($y + $ry * sin(deg2rad($v % 360)))) . ',';
+ }
+
+ $points .=
+ round(($x + $rx * cos(deg2rad($v2 % 360)))) . ',' .
+ round(($y + $ry * sin(deg2rad($v2 % 360))));
+
+ if (($srx != 0) || ($sry != 0)) {
+ $points .= ',';
+ for ($v = $v2; $v > $v1; $v -= 30) {
+ $points .=
+ round(($x + $srx * cos(deg2rad($v % 360)))) . ',' .
+ round(($y + $sry * sin(deg2rad($v % 360)))) . ',';
+ }
+
+ }
+
+ $this->_addMapTag('poly', $points, $params);
+ }
+ parent::pieslice($params);
+ }
+
+ /**
+ * Output the result of the canvas to the browser
+ *
+ * @param array $params Parameter array, the contents and meaning depends on the actual Canvas
+ *
+ * @return void
+ * @abstract
+ */
+ function show($params = false)
+ {
+ parent::show($params);
+ if (count($this->_map) > 0) {
+ print $this->toHtml($params);
+ }
+ }
+
+ /**
+ * Save the result of the canvas to a file
+ *
+ * Parameter array:
+ * 'filename': string The file to output to
+ *
+ * @param array $params Parameter array, the contents and meaning depends on the actual Canvas
+ *
+ * @return void
+ * @abstract
+ */
+ function save($params = false)
+ {
+ parent::save($params);
+ $file = fopen($params['filename'], 'w+');
+ fwrite($file, $this->toHtml($params));
+ fclose($file);
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * Parameter array:
+ * 'name': string The name of the image map
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function toHtml($params)
+ {
+ if (count($this->_map) > 0) {
+ return '<map name="' . $params['name'] . '" id="' . $params['name'] . '">' . "\n\t" . implode($this->_map, "\n\t") . "\n</map>";
+ }
+ return '';
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for handling output in PDF format.\r
- * \r
- * Requires PHP extension PDFlib\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: PDF.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
- \r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas.php';\r
-\r
-/**\r
- * Include file Image/Canvas/Color.php\r
- */\r
-require_once 'Image/Canvas/Color.php';\r
-\r
-/**\r
- * PDF Canvas class.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_PDF extends Image_Canvas\r
-{\r
-\r
- /**\r
- * The PDF document\r
- * @var resource\r
- * @access private\r
- */\r
- var $_pdf;\r
-\r
- /**\r
- * The major version of PDFlib\r
- * @var int\r
- * @access private\r
- */\r
- var $_pdflib;\r
-\r
- /**\r
- * The font\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_pdfFont = false;\r
-\r
- /**\r
- * The width of the page\r
- * @var int\r
- * @access private\r
- */\r
- var $_pageWidth;\r
-\r
- /**\r
- * The height of the page\r
- * @var int\r
- * @access private\r
- */\r
- var $_pageHeight;\r
-\r
- /**\r
- * Create the PDF canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'page' Specify the page/paper format for the graph's page, available\r
- * formats are: A0, A1, A2, A3, A4, A5, A6, B5, letter, legal, ledger,\r
- * 11x17, cd_front, inlay, inlay_nosides\r
- *\r
- * 'align' Alignment of the graph on the page, available options are:\r
- * topleft, topcenter, topright, leftcenter, center, rightcenter,\r
- * leftbottom, centerbottom, rightbottom\r
- *\r
- * 'orientation' Specifies the paper orientation, default is 'portrait' and\r
- * 'landscape' is also supported.\r
- *\r
- * 'creator' The creator tag of the PDF/graph\r
- *\r
- * 'author' The author tag of the PDF/graph\r
- *\r
- * 'title' The title tag of the PDF/graph\r
- *\r
- * 'width' The width of the graph on the page\r
- *\r
- * 'height' The height of the graph on the page\r
- *\r
- * 'left' The left offset of the graph on the page\r
- *\r
- * 'top' The top offset of the graph on the page\r
- *\r
- * 'filename' The PDF file to open/add page to, using 'filename' requires\r
- * the commercial version of PDFlib (http://www.pdflib.com/), this has for\r
- * obvious ($ 450) reasons not been tested\r
- *\r
- * 'pdf' An existing PDFlib PDF document to add the page to\r
- *\r
- * 'add_page' (true/false) Used together with 'pdf', to specify whether the\r
- * canvas should add a new graph page (true) or create the graph on the\r
- * current page (false), default is 'true'\r
- *\r
- * The 'page' and 'width' & 'height' can be mutually omitted, if 'page' is\r
- * omitted the page is created using dimensions of width x height, and if\r
- * width and height are omitted the page dimensions are used for the graph.\r
- *\r
- * If 'pdf' is specified, 'filename', 'creator', 'author' and 'title' has no\r
- * effect.\r
- *\r
- * 'left' and 'top' are overridden by 'align'\r
- *\r
- * It is required either to specify 'width' & 'height' or 'page'.\r
- *\r
- * The PDF format/PDFlib has some limitations on the capabilities, which\r
- * means some functionality available using other canvass (fx. alpha\r
- * blending and gradient fills) are not supported with PDF (see Canvas.txt\r
- * in the docs/ folder for further details)\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_PDF($param)\r
- {\r
- if (isset($param['page'])) {\r
- switch (strtoupper($param['page'])) {\r
- case 'A0':\r
- $this->_pageWidth = 2380;\r
- $this->_pageHeight = 3368;\r
- break;\r
-\r
- case 'A1':\r
- $this->_pageWidth = 1684;\r
- $this->_pageHeight = 2380;\r
- break;\r
-\r
- case 'A2':\r
- $this->_pageWidth = 1190;\r
- $this->_pageHeight = 1684;\r
- break;\r
-\r
- case 'A3':\r
- $this->_pageWidth = 842;\r
- $this->_pageHeight = 1190;\r
- break;\r
-\r
- case 'A4':\r
- $this->_pageWidth = 595;\r
- $this->_pageHeight = 842;\r
- break;\r
-\r
- case 'A5':\r
- $this->_pageWidth = 421;\r
- $this->_pageHeight = 595;\r
- break;\r
-\r
- case 'A6':\r
- $this->_pageWidth = 297;\r
- $this->_pageHeight = 421;\r
- break;\r
-\r
- case 'B5':\r
- $this->_pageWidth = 501;\r
- $this->_pageHeight = 709;\r
- break;\r
-\r
- case 'LETTER':\r
- $this->_pageWidth = 612;\r
- $this->_pageHeight = 792;\r
- break;\r
-\r
- case 'LEGAL':\r
- $this->_pageWidth = 612;\r
- $this->_pageHeight = 1008;\r
- break;\r
-\r
- case 'LEDGER':\r
- $this->_pageWidth = 1224;\r
- $this->_pageHeight = 792;\r
- break;\r
-\r
- case '11X17':\r
- $this->_pageWidth = 792;\r
- $this->_pageHeight = 1224;\r
- break;\r
-\r
- case 'CD_FRONT':\r
- $this->_pageWidth = 337;\r
- $this->_pageHeight = 337;\r
- break;\r
-\r
- case 'INLAY':\r
- $this->_pageWidth = 425;\r
- $this->_pageHeight = 332;\r
- break;\r
-\r
- case 'INLAY_NOSIDES':\r
- $this->_pageWidth = 390;\r
- $this->_pageHeight = 332;\r
- break;\r
- }\r
- }\r
-\r
- if ((isset($param['orientation'])) && (strtoupper($param['orientation']) == 'LANDSCAPE')) {\r
- $w = $this->_pageWidth;\r
- $this->_pageWidth = $this->_pageHeight;\r
- $this->_pageHeight = $w;\r
- }\r
-\r
- parent::Image_Canvas($param);\r
-\r
- if (!$this->_pageWidth) {\r
- $this->_pageWidth = $this->_width;\r
- } elseif (!$this->_width) {\r
- $this->_width = $this->_pageWidth;\r
- }\r
-\r
- if (!$this->_pageHeight) {\r
- $this->_pageHeight = $this->_height;\r
- } elseif (!$this->_height) {\r
- $this->_height = $this->_pageHeight;\r
- }\r
-\r
- $this->_width = min($this->_width, $this->_pageWidth);\r
- $this->_height = min($this->_height, $this->_pageHeight);\r
-\r
- if ((isset($param['align'])) &&\r
- (($this->_width != $this->_pageWidth) || ($this->_height != $this->_pageHeight))\r
- ) {\r
- switch (strtoupper($param['align'])) {\r
- case 'TOPLEFT':\r
- $this->_top = 0;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'TOPCENTER':\r
- $this->_top = 0;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'TOPRIGHT':\r
- $this->_top = 0;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
-\r
- case 'LEFTCENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'CENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'RIGHTCENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
-\r
- case 'LEFTBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'CENTERBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'RIGHTBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
- }\r
- }\r
-\r
- $addPage = true;\r
- if ((isset($param['pdf'])) && (is_resource($param['pdf']))) {\r
- $this->_pdf =& $param['pdf'];\r
- if ((isset($param['add_page'])) && ($param['add_page'] === false)) {\r
- $addPage = false;\r
- }\r
- } else {\r
- $this->_pdf = pdf_new();\r
-\r
- if (isset($param['filename'])) {\r
- pdf_open_file($this->_pdf, $param['filename']);\r
- } else {\r
- pdf_open_file($this->_pdf, '');\r
- }\r
-\r
- pdf_set_parameter($this->_pdf, 'warning', 'true');\r
-\r
- pdf_set_info($this->_pdf, 'Creator', (isset($param['creator']) ? $param['creator'] : 'PEAR::Image_Canvas'));\r
- pdf_set_info($this->_pdf, 'Author', (isset($param['author']) ? $param['author'] : 'Jesper Veggerby'));\r
- pdf_set_info($this->_pdf, 'Title', (isset($param['title']) ? $param['title'] : 'Image_Canvas'));\r
- }\r
-\r
- if ($addPage) {\r
- pdf_begin_page($this->_pdf, $this->_pageWidth, $this->_pageHeight);\r
- }\r
- $this->_reset();\r
-\r
- $this->_pdflib = $this->_version();\r
- }\r
-\r
- /**\r
- * Get the x-point from the relative to absolute coordinates\r
- *\r
- * @param float $x The relative x-coordinate (in percentage of total width)\r
- * @return float The x-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getX($x)\r
- {\r
- return $this->_left + $x;\r
- }\r
-\r
- /**\r
- * Get the y-point from the relative to absolute coordinates\r
- *\r
- * @param float $y The relative y-coordinate (in percentage of total width)\r
- * @return float The y-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getY($y)\r
- {\r
- return $this->_pageHeight - ($this->_top + $y);\r
- }\r
-\r
- /**\r
- * Get the color index for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int The GD image index of the color\r
- * @access private\r
- */\r
- function _color($color = false)\r
- {\r
- if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {\r
- return false;\r
- } else {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- $color[0] = $color[0]/255;\r
- $color[1] = $color[1]/255;\r
- $color[2] = $color[2]/255;\r
- return $color;\r
- }\r
- }\r
-\r
- /**\r
- * Get the PDF linestyle\r
- *\r
- * @param mixed $lineStyle The line style to return, false if the one\r
- * explicitly set\r
- * @return bool True if set (so that a line should be drawn)\r
- * @access private\r
- */\r
- function _setLineStyle($lineStyle = false)\r
- {\r
- if ($lineStyle === false) {\r
- $lineStyle = $this->_lineStyle;\r
- }\r
-\r
- if (($lineStyle == 'transparent') || ($lineStyle === false)) {\r
- return false;\r
- }\r
- \r
- if (is_array($lineStyle)) {\r
- // TODO Implement linestyles in PDFlib (using pdf_setcolor(.., 'pattern'...); ?\r
- reset($lineStyle);\r
- $lineStyle = current($lineStyle);\r
- } \r
-\r
- $color = $this->_color($lineStyle);\r
-\r
- pdf_setlinewidth($this->_pdf, $this->_thickness);\r
- if ($this->_pdflib < 4) {\r
- pdf_setrgbcolor_stroke($this->_pdf, $color[0]/255, $color[1]/255, $color[2]/255);\r
- } else {\r
- pdf_setcolor($this->_pdf, 'stroke', 'rgb', $color[0], $color[1], $color[2], 0);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the PDF fill style\r
- *\r
- * @param mixed $fillStyle The fillstyle to return, false if the one\r
- * explicitly set\r
- * @return bool True if set (so that a line should be drawn)\r
- * @access private\r
- */\r
- function _setFillStyle($fillStyle = false)\r
- {\r
- if ($fillStyle === false) {\r
- $fillStyle = $this->_fillStyle;\r
- }\r
-\r
- if (($fillStyle == 'transparent') || ($fillStyle === false)) {\r
- return false;\r
- }\r
-\r
- $color = $this->_color($fillStyle);\r
-\r
- if ($this->_pdflib < 4) {\r
- pdf_setrgbcolor_fill($this->_pdf, $color[0]/255, $color[1]/255, $color[2]/255);\r
- } else {\r
- pdf_setcolor($this->_pdf, 'fill', 'rgb', $color[0], $color[1], $color[2], 0);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the PDF font\r
- *\r
- * @access private\r
- */\r
- function _setFont()\r
- {\r
- $this->_pdfFont = false;\r
- if (isset($this->_font['name'])) {\r
- pdf_set_parameter($this->_pdf, 'FontOutline', $this->_font['name'] . '=' . $this->_font['file']);\r
- $this->_pdfFont = pdf_findfont($this->_pdf, $this->_font['name'], $this->_font['encoding'], 1);\r
-\r
- if ($this->_pdfFont) {\r
- pdf_setfont($this->_pdf, $this->_pdfFont, $this->_font['size']);\r
- $this->_setFillStyle($this->_font['color']);\r
- }\r
- } else {\r
- $this->_setFillStyle('black');\r
- }\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling.\r
- *\r
- * Image filling is not supported with PDF, filling 'transparent'\r
- *\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- $this->_fillStyle = 'transparent';\r
- }\r
-\r
- /**\r
- * Sets a gradient fill\r
- *\r
- * Gradient filling is not supported with PDF, end color used as solid fill.\r
- *\r
- * @param array $gradient Gradient fill options\r
- */\r
- function setGradientFill($gradient)\r
- {\r
- $this->_fillStyle = $gradient['end'];\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- *\r
- * 'ttf' = the .ttf file (either the basename, filename or full path)\r
- * If 'ttf' is specified, then the following can be specified\r
- *\r
- * 'size' = size in pixels\r
- *\r
- * 'angle' = the angle with which to write the text\r
- *\r
- * @param array $font The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- parent::setFont($fontOptions);\r
-\r
- if (!isset($this->_font['size'])) {\r
- $this->_font['size'] = 12;\r
- }\r
-\r
- if (!isset($this->_font['encoding'])) {\r
- $this->_font['encoding'] = 'winansi';\r
- }\r
-\r
- if (!isset($this->_font['color'])) {\r
- $this->_font['color'] = 'black';\r
- }\r
- }\r
-\r
- /**\r
- * Resets the canvas.\r
- *\r
- * Includes fillstyle, linestyle, thickness and polygon\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- pdf_initgraphics($this->_pdf);\r
- parent::_reset();\r
- }\r
-\r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'color': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- if ($this->_setLineStyle($color)) {\r
- pdf_moveto($this->_pdf, $this->_getX($params['x0']), $this->_getY($params['y0']));\r
- pdf_lineto($this->_pdf, $this->_getX($params['x1']), $this->_getY($params['y1']));\r
- pdf_stroke($this->_pdf);\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params = array())\r
- {\r
- $connectEnds = (isset($params['connect']) ? $params['connect'] : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = false;\r
- if ($connectEnds) {\r
- $fill = $this->_setFillStyle($fillColor);\r
- }\r
-\r
- $first = true;\r
- foreach ($this->_polygon as $point) {\r
- if ($first === true) {\r
- pdf_moveto($this->_pdf, $point['X'], $point['Y']);\r
- $first = $point;\r
- } else {\r
- if (isset($last['P1X'])) {\r
- pdf_curveto($this->_pdf,\r
- $last['P1X'],\r
- $last['P1Y'],\r
- $last['P2X'],\r
- $last['P2Y'],\r
- $point['X'],\r
- $point['Y']\r
- );\r
- } else {\r
- pdf_lineto($this->_pdf,\r
- $point['X'],\r
- $point['Y']\r
- );\r
- }\r
- }\r
- $last = $point;\r
- }\r
-\r
- if ($connectEnds) {\r
- if (isset($last['P1X'])) {\r
- pdf_curveto($this->_pdf,\r
- $last['P1X'],\r
- $last['P1Y'],\r
- $last['P2X'],\r
- $last['P2Y'],\r
- $first['X'],\r
- $first['Y']\r
- );\r
- } else {\r
- pdf_lineto($this->_pdf,\r
- $first['X'],\r
- $first['Y']\r
- );\r
- }\r
- }\r
-\r
- if (($line) && ($fill)) {\r
- pdf_fill_stroke($this->_pdf);\r
- } elseif ($line) {\r
- pdf_stroke($this->_pdf);\r
- } elseif ($fill) {\r
- pdf_fill($this->_pdf);\r
- }\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = $this->_setFillStyle($fillColor);\r
- if (($line) || ($fill)) {\r
- pdf_rect($this->_pdf, min($x0, $x1), min($y0, $y1), abs($x1 - $x0), abs($y1 - $y0));\r
- if (($line) && ($fill)) {\r
- pdf_fill_stroke($this->_pdf);\r
- } elseif ($line) {\r
- pdf_stroke($this->_pdf);\r
- } elseif ($fill) {\r
- pdf_fill($this->_pdf);\r
- }\r
- }\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $x = $params['x'];\r
- $y = $params['y'];\r
- $rx = $params['rx'];\r
- $ry = $params['ry'];\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = $this->_setFillStyle($fillColor);\r
- if (($line) || ($fill)) {\r
- if ($rx == $ry) {\r
- pdf_circle($this->_pdf, $this->_getX($x), $this->_getY($y), $rx);\r
- } else {\r
- pdf_moveto($this->_pdf, $this->_getX($x - $rx), $this->_getY($y));\r
- pdf_curveto($this->_pdf,\r
- $this->_getX($x - $rx), $this->_getY($y),\r
- $this->_getX($x - $rx), $this->_getY($y - $ry),\r
- $this->_getX($x), $this->_getY($y - $ry)\r
- );\r
- pdf_curveto($this->_pdf,\r
- $this->_getX($x), $this->_getY($y - $ry),\r
- $this->_getX($x + $rx), $this->_getY($y - $ry),\r
- $this->_getX($x + $rx), $this->_getY($y)\r
- );\r
- pdf_curveto($this->_pdf,\r
- $this->_getX($x + $rx), $this->_getY($y),\r
- $this->_getX($x + $rx), $this->_getY($y + $ry),\r
- $this->_getX($x), $this->_getY($y + $ry)\r
- );\r
- pdf_curveto($this->_pdf,\r
- $this->_getX($x), $this->_getY($y + $ry),\r
- $this->_getX($x - $rx), $this->_getY($y + $ry),\r
- $this->_getX($x - $rx), $this->_getY($y)\r
- );\r
- }\r
-\r
- if (($line) && ($fill)) {\r
- pdf_fill_stroke($this->_pdf);\r
- } elseif ($line) {\r
- pdf_stroke($this->_pdf);\r
- } elseif ($fill) {\r
- pdf_fill($this->_pdf);\r
- }\r
- }\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
- $v1 = $this->_getX($params['v1']);\r
- $v2 = $this->_getY($params['v2']);\r
- $srx = $this->_getX($params['srx']);\r
- $sry = $this->_getY($params['sry']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- // TODO Implement PDFLIB::pieSlice()\r
- parent::pieslice($params);\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- if ($this->_pdfFont === false) {\r
- return $this->_font['size'] * 0.7 * strlen($text);\r
- } else {\r
- return pdf_stringwidth($this->_pdf, $text, $this->_pdfFont, $this->_font['size']);\r
- }\r
- }\r
-\r
- /**\r
- * Get the height of a text,\r
- *\r
- * @param string $text The text to get the height of\r
- * @return int The height of the text\r
- */\r
- function textHeight($text)\r
- {\r
- if (isset($this->_font['size'])) {\r
- return $this->_font['size'];\r
- } else {\r
- return 12;\r
- }\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of text\r
- * 'y': int Y-point of text\r
- * 'text': string The text to add\r
- * 'alignment': array [optional] Alignment\r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $text = $params['text'];\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- $this->_setFont();\r
-\r
- $textWidth = $this->textWidth($text);\r
- $textHeight = $this->textHeight($text);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
- \r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if ($alignment['horizontal'] == 'right') {\r
- $x = $x - $textWidth;\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $x = $x - ($textWidth / 2);\r
- }\r
-\r
- $y -= $textHeight;\r
-\r
- if ($alignment['vertical'] == 'bottom') {\r
- $y = $y + $textHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y = $y + ($textHeight / 2);\r
- }\r
-\r
- if (($color === false) && (isset($this->_font['color']))) {\r
- $color = $this->_font['color'];\r
- }\r
-\r
- pdf_show_xy($this->_pdf, $text, $x, $y);\r
-\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of overlayed image\r
- * 'y': int Y-point of overlayed image\r
- * 'filename': string The filename of the image to overlay\r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $filename = $params['filename'];\r
- $width = (isset($params['width']) ? $params['width'] : false);\r
- $height = (isset($params['height']) ? $params['height'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- if (substr($filename, -4) == '.png') {\r
- $type = 'png';\r
- } elseif (substr($filename, -4) == '.jpg') {\r
- $type = 'jpeg';\r
- }\r
-\r
- $image = pdf_load_image($this->_pdf, $type, realpath($filename), '');\r
- $width_ = pdf_get_value($this->_pdf, 'imagewidth', $image);\r
- $height_ = pdf_get_value($this->_pdf, 'imageheight', $image);\r
-\r
- $outputWidth = ($width !== false ? $width : $width_);\r
- $outputHeight = ($height !== false ? $height : $height_);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
- \r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if ($alignment['horizontal'] == 'right') {\r
- $x -= $outputWidth;\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $x -= $outputWidth / 2;\r
- }\r
-\r
- if ($alignment['vertical'] == 'top') {\r
- $y += $outputHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y += $outputHeight / 2;\r
- }\r
- \r
- if (($width === false) && ($height === false)) {\r
- $scale = 1;\r
- } else {\r
- $scale = max(($height/$height_), ($width/$width_));\r
- } \r
-\r
- pdf_place_image($this->_pdf, $image, $x, $y, $scale);\r
- pdf_close_image($this->_pdf, $image);\r
- \r
- parent::image($params);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- pdf_end_page($this->_pdf);\r
- pdf_close($this->_pdf);\r
-\r
- $buf = pdf_get_buffer($this->_pdf);\r
- $len = strlen($buf);\r
-\r
- header('Content-type: application/pdf');\r
- header('Content-Length: ' . $len);\r
- header('Content-Disposition: inline; filename=image_graph.pdf');\r
- print $buf;\r
-\r
- pdf_delete($this->_pdf);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function save($param = false)\r
- {\r
- parent::save($param);\r
- pdf_end_page($this->_pdf);\r
- pdf_close($this->_pdf);\r
-\r
- $buf = pdf_get_buffer($this->_pdf);\r
- $len = strlen($buf);\r
-\r
- $fp = @fopen($param['filename'], 'wb');\r
- if ($fp) {\r
- fwrite($fp, $buf, strlen($buf));\r
- fclose($fp);\r
- }\r
- pdf_delete($this->_pdf);\r
- }\r
- \r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * This method implicitly saves the canvas to the filename in the \r
- * filesystem path specified and parses it as URL specified by URL path\r
- * \r
- * Parameter array:\r
- * 'filename': string\r
- * 'filepath': string Path to the file on the file system. Remember the final slash\r
- * 'urlpath': string Path to the file available through an URL. Remember the final slash\r
- * 'title': string The url title\r
- */\r
- function toHtml($params)\r
- {\r
- parent::toHtml($params);\r
- return '<a href="' . $params['urlpath'] . $params['filename'] . '">' . $params['title'] . '</a>'; \r
- } \r
-\r
- /**\r
- * Check which major version of PDFlib is installed\r
- *\r
- * @return int The mahor version number of PDFlib\r
- * @access private\r
- */\r
- function _version()\r
- {\r
- $result = false;\r
- $version = '';\r
- if (function_exists('pdf_get_majorversion')) {\r
- $version = pdf_get_majorversion();\r
- } else if (function_exists('pdf_get_value')) {\r
- $version = pdf_get_value($this->_pdf, 'major', 0); \r
- } else {\r
- ob_start();\r
- phpinfo(8);\r
- $php_info = ob_get_contents();\r
- ob_end_clean();\r
-\r
- if (ereg("<td[^>]*>PDFlib GmbH Version *<\/td><td[^>]*>([^<]*)<\/td>",\r
- $php_info, $result))\r
- {\r
- $version = $result[1];\r
- }\r
- } \r
- \r
- if (ereg('([0-9]{1,2})\.[0-9]{1,2}(\.[0-9]{1,2})?', trim($version), $result)) {\r
- return $result[1];\r
- } else {\r
- return $version;\r
- }\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for handling output in PDF format.
+ *
+ * Requires PHP extension PDFlib
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: PDF.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas.php';
+
+/**
+ * Include file Image/Canvas/Color.php
+ */
+require_once 'Image/Canvas/Color.php';
+
+/**
+ * PDF Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_PDF extends Image_Canvas
+{
+
+ /**
+ * The PDF document
+ * @var resource
+ * @access private
+ */
+ var $_pdf;
+
+ /**
+ * The major version of PDFlib
+ * @var int
+ * @access private
+ */
+ var $_pdflib;
+
+ /**
+ * The font
+ * @var mixed
+ * @access private
+ */
+ var $_pdfFont = false;
+
+ /**
+ * The width of the page
+ * @var int
+ * @access private
+ */
+ var $_pageWidth;
+
+ /**
+ * The height of the page
+ * @var int
+ * @access private
+ */
+ var $_pageHeight;
+
+ /**
+ * Create the PDF canvas.
+ *
+ * Parameters available:
+ *
+ * 'page' Specify the page/paper format for the graph's page, available
+ * formats are: A0, A1, A2, A3, A4, A5, A6, B5, letter, legal, ledger,
+ * 11x17, cd_front, inlay, inlay_nosides
+ *
+ * 'align' Alignment of the graph on the page, available options are:
+ * topleft, topcenter, topright, leftcenter, center, rightcenter,
+ * leftbottom, centerbottom, rightbottom
+ *
+ * 'orientation' Specifies the paper orientation, default is 'portrait' and
+ * 'landscape' is also supported.
+ *
+ * 'creator' The creator tag of the PDF/graph
+ *
+ * 'author' The author tag of the PDF/graph
+ *
+ * 'title' The title tag of the PDF/graph
+ *
+ * 'width' The width of the graph on the page
+ *
+ * 'height' The height of the graph on the page
+ *
+ * 'left' The left offset of the graph on the page
+ *
+ * 'top' The top offset of the graph on the page
+ *
+ * 'filename' The PDF file to open/add page to, using 'filename' requires
+ * the commercial version of PDFlib (http://www.pdflib.com/), this has for
+ * obvious ($ 450) reasons not been tested
+ *
+ * 'pdf' An existing PDFlib PDF document to add the page to
+ *
+ * 'add_page' (true/false) Used together with 'pdf', to specify whether the
+ * canvas should add a new graph page (true) or create the graph on the
+ * current page (false), default is 'true'
+ *
+ * The 'page' and 'width' & 'height' can be mutually omitted, if 'page' is
+ * omitted the page is created using dimensions of width x height, and if
+ * width and height are omitted the page dimensions are used for the graph.
+ *
+ * If 'pdf' is specified, 'filename', 'creator', 'author' and 'title' has no
+ * effect.
+ *
+ * 'left' and 'top' are overridden by 'align'
+ *
+ * It is required either to specify 'width' & 'height' or 'page'.
+ *
+ * The PDF format/PDFlib has some limitations on the capabilities, which
+ * means some functionality available using other canvass (fx. alpha
+ * blending and gradient fills) are not supported with PDF (see Canvas.txt
+ * in the docs/ folder for further details)
+ *
+ * @param array $param Parameter array
+ */
+ function Image_Canvas_PDF($param)
+ {
+ if (isset($param['page'])) {
+ switch (strtoupper($param['page'])) {
+ case 'A0':
+ $this->_pageWidth = 2380;
+ $this->_pageHeight = 3368;
+ break;
+
+ case 'A1':
+ $this->_pageWidth = 1684;
+ $this->_pageHeight = 2380;
+ break;
+
+ case 'A2':
+ $this->_pageWidth = 1190;
+ $this->_pageHeight = 1684;
+ break;
+
+ case 'A3':
+ $this->_pageWidth = 842;
+ $this->_pageHeight = 1190;
+ break;
+
+ case 'A4':
+ $this->_pageWidth = 595;
+ $this->_pageHeight = 842;
+ break;
+
+ case 'A5':
+ $this->_pageWidth = 421;
+ $this->_pageHeight = 595;
+ break;
+
+ case 'A6':
+ $this->_pageWidth = 297;
+ $this->_pageHeight = 421;
+ break;
+
+ case 'B5':
+ $this->_pageWidth = 501;
+ $this->_pageHeight = 709;
+ break;
+
+ case 'LETTER':
+ $this->_pageWidth = 612;
+ $this->_pageHeight = 792;
+ break;
+
+ case 'LEGAL':
+ $this->_pageWidth = 612;
+ $this->_pageHeight = 1008;
+ break;
+
+ case 'LEDGER':
+ $this->_pageWidth = 1224;
+ $this->_pageHeight = 792;
+ break;
+
+ case '11X17':
+ $this->_pageWidth = 792;
+ $this->_pageHeight = 1224;
+ break;
+
+ case 'CD_FRONT':
+ $this->_pageWidth = 337;
+ $this->_pageHeight = 337;
+ break;
+
+ case 'INLAY':
+ $this->_pageWidth = 425;
+ $this->_pageHeight = 332;
+ break;
+
+ case 'INLAY_NOSIDES':
+ $this->_pageWidth = 390;
+ $this->_pageHeight = 332;
+ break;
+ }
+ }
+
+ if ((isset($param['orientation'])) && (strtoupper($param['orientation']) == 'LANDSCAPE')) {
+ $w = $this->_pageWidth;
+ $this->_pageWidth = $this->_pageHeight;
+ $this->_pageHeight = $w;
+ }
+
+ parent::Image_Canvas($param);
+
+ if (!$this->_pageWidth) {
+ $this->_pageWidth = $this->_width;
+ } elseif (!$this->_width) {
+ $this->_width = $this->_pageWidth;
+ }
+
+ if (!$this->_pageHeight) {
+ $this->_pageHeight = $this->_height;
+ } elseif (!$this->_height) {
+ $this->_height = $this->_pageHeight;
+ }
+
+ $this->_width = min($this->_width, $this->_pageWidth);
+ $this->_height = min($this->_height, $this->_pageHeight);
+
+ if ((isset($param['align']))
+ && (($this->_width != $this->_pageWidth) || ($this->_height != $this->_pageHeight))
+ ) {
+ switch (strtoupper($param['align'])) {
+ case 'TOPLEFT':
+ $this->_top = 0;
+ $this->_left = 0;
+ break;
+
+ case 'TOPCENTER':
+ $this->_top = 0;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'TOPRIGHT':
+ $this->_top = 0;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+
+ case 'LEFTCENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = 0;
+ break;
+
+ case 'CENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'RIGHTCENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+
+ case 'LEFTBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = 0;
+ break;
+
+ case 'CENTERBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'RIGHTBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+ }
+ }
+
+ $addPage = true;
+ if ((isset($param['pdf'])) && (is_resource($param['pdf']))) {
+ $this->_pdf =& $param['pdf'];
+ if ((isset($param['add_page'])) && ($param['add_page'] === false)) {
+ $addPage = false;
+ }
+ } else {
+ $this->_pdf = pdf_new();
+
+ if (isset($param['filename'])) {
+ pdf_open_file($this->_pdf, $param['filename']);
+ } else {
+ pdf_open_file($this->_pdf, '');
+ }
+
+ pdf_set_parameter($this->_pdf, 'warning', 'true');
+
+ pdf_set_info($this->_pdf, 'Creator', (isset($param['creator']) ? $param['creator'] : 'PEAR::Image_Canvas'));
+ pdf_set_info($this->_pdf, 'Author', (isset($param['author']) ? $param['author'] : 'Jesper Veggerby'));
+ pdf_set_info($this->_pdf, 'Title', (isset($param['title']) ? $param['title'] : 'Image_Canvas'));
+ }
+
+ if ($addPage) {
+ pdf_begin_page($this->_pdf, $this->_pageWidth, $this->_pageHeight);
+ }
+ $this->_reset();
+
+ $this->_pdflib = $this->_version();
+ }
+
+ /**
+ * Get the x-point from the relative to absolute coordinates
+ *
+ * @param float $x The relative x-coordinate (in percentage of total width)
+ *
+ * @return float The x-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getX($x)
+ {
+ return $this->_left + $x;
+ }
+
+ /**
+ * Get the y-point from the relative to absolute coordinates
+ *
+ * @param float $y The relative y-coordinate (in percentage of total width)
+ *
+ * @return float The y-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getY($y)
+ {
+ return $this->_pageHeight - ($this->_top + $y);
+ }
+
+ /**
+ * Get the color index for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int The GD image index of the color
+ * @access private
+ */
+ function _color($color = false)
+ {
+ if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {
+ return false;
+ } else {
+ $color = Image_Canvas_Color::color2RGB($color);
+ $color[0] = $color[0]/255;
+ $color[1] = $color[1]/255;
+ $color[2] = $color[2]/255;
+ return $color;
+ }
+ }
+
+ /**
+ * Get the PDF linestyle
+ *
+ * @param mixed $lineStyle The line style to return, false if the one
+ * explicitly set
+ *
+ * @return bool True if set (so that a line should be drawn)
+ * @access private
+ */
+ function _setLineStyle($lineStyle = false)
+ {
+ if ($lineStyle === false) {
+ $lineStyle = $this->_lineStyle;
+ }
+
+ if (($lineStyle == 'transparent') || ($lineStyle === false)) {
+ return false;
+ }
+
+ if (is_array($lineStyle)) {
+ // TODO Implement linestyles in PDFlib (using pdf_setcolor(.., 'pattern'...); ?
+ reset($lineStyle);
+ $lineStyle = current($lineStyle);
+ }
+
+ $color = $this->_color($lineStyle);
+
+ pdf_setlinewidth($this->_pdf, $this->_thickness);
+ if ($this->_pdflib < 4) {
+ pdf_setrgbcolor_stroke($this->_pdf, $color[0]/255, $color[1]/255, $color[2]/255);
+ } else {
+ pdf_setcolor($this->_pdf, 'stroke', 'rgb', $color[0], $color[1], $color[2], 0);
+ }
+ return true;
+ }
+
+ /**
+ * Set the PDF fill style
+ *
+ * @param mixed $fillStyle The fillstyle to return, false if the one
+ * explicitly set
+ *
+ * @return bool True if set (so that a line should be drawn)
+ * @access private
+ */
+ function _setFillStyle($fillStyle = false)
+ {
+ if ($fillStyle === false) {
+ $fillStyle = $this->_fillStyle;
+ }
+
+ if (($fillStyle == 'transparent') || ($fillStyle === false)) {
+ return false;
+ }
+
+ $color = $this->_color($fillStyle);
+
+ if ($this->_pdflib < 4) {
+ pdf_setrgbcolor_fill($this->_pdf, $color[0]/255, $color[1]/255, $color[2]/255);
+ } else {
+ pdf_setcolor($this->_pdf, 'fill', 'rgb', $color[0], $color[1], $color[2], 0);
+ }
+ return true;
+ }
+
+ /**
+ * Set the PDF font
+ *
+ * @access private
+ *
+ * @return void
+ */
+ function _setFont()
+ {
+ $this->_pdfFont = false;
+ if (isset($this->_font['name'])) {
+ pdf_set_parameter($this->_pdf, 'FontOutline', $this->_font['name'] . '=' . $this->_font['file']);
+ $this->_pdfFont = pdf_findfont($this->_pdf, $this->_font['name'], $this->_font['encoding'], 1);
+
+ if ($this->_pdfFont) {
+ pdf_setfont($this->_pdf, $this->_pdfFont, $this->_font['size']);
+ $this->_setFillStyle($this->_font['color']);
+ }
+ } else {
+ $this->_setFillStyle('black');
+ }
+ }
+
+ /**
+ * Sets an image that should be used for filling.
+ *
+ * Image filling is not supported with PDF, filling 'transparent'
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ $this->_fillStyle = 'transparent';
+ }
+
+ /**
+ * Sets a gradient fill
+ *
+ * Gradient filling is not supported with PDF, end color used as solid fill.
+ *
+ * @param array $gradient Gradient fill options
+ *
+ * @return void
+ */
+ function setGradientFill($gradient)
+ {
+ $this->_fillStyle = $gradient['end'];
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ *
+ * 'ttf' = the .ttf file (either the basename, filename or full path)
+ * If 'ttf' is specified, then the following can be specified
+ *
+ * 'size' = size in pixels
+ *
+ * 'angle' = the angle with which to write the text
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ parent::setFont($fontOptions);
+
+ if (!isset($this->_font['size'])) {
+ $this->_font['size'] = 12;
+ }
+
+ if (!isset($this->_font['encoding'])) {
+ $this->_font['encoding'] = 'winansi';
+ }
+
+ if (!isset($this->_font['color'])) {
+ $this->_font['color'] = 'black';
+ }
+ }
+
+ /**
+ * Resets the canvas.
+ *
+ * Includes fillstyle, linestyle, thickness and polygon
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ pdf_initgraphics($this->_pdf);
+ parent::_reset();
+ }
+
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $color = (isset($params['color']) ? $params['color'] : false);
+ if ($this->_setLineStyle($color)) {
+ pdf_moveto($this->_pdf, $this->_getX($params['x0']), $this->_getY($params['y0']));
+ pdf_lineto($this->_pdf, $this->_getX($params['x1']), $this->_getY($params['y1']));
+ pdf_stroke($this->_pdf);
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params = array())
+ {
+ $connectEnds = (isset($params['connect']) ? $params['connect'] : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = false;
+ if ($connectEnds) {
+ $fill = $this->_setFillStyle($fillColor);
+ }
+
+ $first = true;
+ foreach ($this->_polygon as $point) {
+ if ($first === true) {
+ pdf_moveto($this->_pdf, $point['X'], $point['Y']);
+ $first = $point;
+ } else {
+ if (isset($last['P1X'])) {
+ pdf_curveto(
+ $this->_pdf,
+ $last['P1X'],
+ $last['P1Y'],
+ $last['P2X'],
+ $last['P2Y'],
+ $point['X'],
+ $point['Y']
+ );
+ } else {
+ pdf_lineto(
+ $this->_pdf,
+ $point['X'],
+ $point['Y']
+ );
+ }
+ }
+ $last = $point;
+ }
+
+ if ($connectEnds) {
+ if (isset($last['P1X'])) {
+ pdf_curveto(
+ $this->_pdf,
+ $last['P1X'],
+ $last['P1Y'],
+ $last['P2X'],
+ $last['P2Y'],
+ $first['X'],
+ $first['Y']
+ );
+ } else {
+ pdf_lineto(
+ $this->_pdf,
+ $first['X'],
+ $first['Y']
+ );
+ }
+ }
+
+ if (($line) && ($fill)) {
+ pdf_fill_stroke($this->_pdf);
+ } elseif ($line) {
+ pdf_stroke($this->_pdf);
+ } elseif ($fill) {
+ pdf_fill($this->_pdf);
+ }
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = $this->_setFillStyle($fillColor);
+ if (($line) || ($fill)) {
+ pdf_rect($this->_pdf, min($x0, $x1), min($y0, $y1), abs($x1 - $x0), abs($y1 - $y0));
+ if (($line) && ($fill)) {
+ pdf_fill_stroke($this->_pdf);
+ } elseif ($line) {
+ pdf_stroke($this->_pdf);
+ } elseif ($fill) {
+ pdf_fill($this->_pdf);
+ }
+ }
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $x = $params['x'];
+ $y = $params['y'];
+ $rx = $params['rx'];
+ $ry = $params['ry'];
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = $this->_setFillStyle($fillColor);
+ if (($line) || ($fill)) {
+ if ($rx == $ry) {
+ pdf_circle($this->_pdf, $this->_getX($x), $this->_getY($y), $rx);
+ } else {
+ pdf_moveto($this->_pdf, $this->_getX($x - $rx), $this->_getY($y));
+ pdf_curveto(
+ $this->_pdf,
+ $this->_getX($x - $rx), $this->_getY($y),
+ $this->_getX($x - $rx), $this->_getY($y - $ry),
+ $this->_getX($x), $this->_getY($y - $ry)
+ );
+ pdf_curveto(
+ $this->_pdf,
+ $this->_getX($x), $this->_getY($y - $ry),
+ $this->_getX($x + $rx), $this->_getY($y - $ry),
+ $this->_getX($x + $rx), $this->_getY($y)
+ );
+ pdf_curveto(
+ $this->_pdf,
+ $this->_getX($x + $rx), $this->_getY($y),
+ $this->_getX($x + $rx), $this->_getY($y + $ry),
+ $this->_getX($x), $this->_getY($y + $ry)
+ );
+ pdf_curveto(
+ $this->_pdf,
+ $this->_getX($x), $this->_getY($y + $ry),
+ $this->_getX($x - $rx), $this->_getY($y + $ry),
+ $this->_getX($x - $rx), $this->_getY($y)
+ );
+ }
+
+ if (($line) && ($fill)) {
+ pdf_fill_stroke($this->_pdf);
+ } elseif ($line) {
+ pdf_stroke($this->_pdf);
+ } elseif ($fill) {
+ pdf_fill($this->_pdf);
+ }
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+ $v1 = $this->_getX($params['v1']);
+ $v2 = $this->_getY($params['v2']);
+ $srx = $this->_getX($params['srx']);
+ $sry = $this->_getY($params['sry']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ // TODO Implement PDFLIB::pieSlice()
+ parent::pieslice($params);
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ if ($this->_pdfFont === false) {
+ return $this->_font['size'] * 0.7 * strlen($text);
+ } else {
+ return pdf_stringwidth($this->_pdf, $text, $this->_pdfFont, $this->_font['size']);
+ }
+ }
+
+ /**
+ * Get the height of a text,
+ *
+ * @param string $text The text to get the height of
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text)
+ {
+ if (isset($this->_font['size'])) {
+ return $this->_font['size'];
+ } else {
+ return 12;
+ }
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x': int X-point of text
+ * 'y': int Y-point of text
+ * 'text': string The text to add
+ * 'alignment': array [optional] Alignment
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $text = $params['text'];
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ $this->_setFont();
+
+ $textWidth = $this->textWidth($text);
+ $textHeight = $this->textHeight($text);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if ($alignment['horizontal'] == 'right') {
+ $x = $x - $textWidth;
+ } elseif ($alignment['horizontal'] == 'center') {
+ $x = $x - ($textWidth / 2);
+ }
+
+ $y -= $textHeight;
+
+ if ($alignment['vertical'] == 'bottom') {
+ $y = $y + $textHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y = $y + ($textHeight / 2);
+ }
+
+ if (($color === false) && (isset($this->_font['color']))) {
+ $color = $this->_font['color'];
+ }
+
+ pdf_show_xy($this->_pdf, $text, $x, $y);
+
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x': int X-point of overlayed image
+ * 'y': int Y-point of overlayed image
+ * 'filename': string The filename of the image to overlay
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $filename = $params['filename'];
+ $width = (isset($params['width']) ? $params['width'] : false);
+ $height = (isset($params['height']) ? $params['height'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ if (substr($filename, -4) == '.png') {
+ $type = 'png';
+ } elseif (substr($filename, -4) == '.jpg') {
+ $type = 'jpeg';
+ }
+
+ $image = pdf_load_image($this->_pdf, $type, realpath($filename), '');
+ $width_ = pdf_get_value($this->_pdf, 'imagewidth', $image);
+ $height_ = pdf_get_value($this->_pdf, 'imageheight', $image);
+
+ $outputWidth = ($width !== false ? $width : $width_);
+ $outputHeight = ($height !== false ? $height : $height_);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if ($alignment['horizontal'] == 'right') {
+ $x -= $outputWidth;
+ } elseif ($alignment['horizontal'] == 'center') {
+ $x -= $outputWidth / 2;
+ }
+
+ if ($alignment['vertical'] == 'top') {
+ $y += $outputHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y += $outputHeight / 2;
+ }
+
+ if (($width === false) && ($height === false)) {
+ $scale = 1;
+ } else {
+ $scale = max(($height/$height_), ($width/$width_));
+ }
+
+ pdf_place_image($this->_pdf, $image, $x, $y, $scale);
+ pdf_close_image($this->_pdf, $image);
+
+ parent::image($params);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+ pdf_end_page($this->_pdf);
+ pdf_close($this->_pdf);
+
+ $buf = pdf_get_buffer($this->_pdf);
+ $len = strlen($buf);
+
+ header('Content-type: application/pdf');
+ header('Content-Length: ' . $len);
+ header('Content-Disposition: inline; filename=image_graph.pdf');
+ print $buf;
+
+ pdf_delete($this->_pdf);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function save($param = false)
+ {
+ parent::save($param);
+ pdf_end_page($this->_pdf);
+ pdf_close($this->_pdf);
+
+ $buf = pdf_get_buffer($this->_pdf);
+ $len = strlen($buf);
+
+ $fp = @fopen($param['filename'], 'wb');
+ if ($fp) {
+ fwrite($fp, $buf, strlen($buf));
+ fclose($fp);
+ }
+ pdf_delete($this->_pdf);
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ * 'filename': string
+ * 'filepath': string Path to the file on the file system. Remember the final slash
+ * 'urlpath': string Path to the file available through an URL. Remember the final slash
+ * 'title': string The url title
+ *
+ * @param array $params Parameter array
+ *
+ * @return string HTML code
+ */
+ function toHtml($params)
+ {
+ parent::toHtml($params);
+ return '<a href="' . $params['urlpath'] . $params['filename'] . '">' . $params['title'] . '</a>';
+ }
+
+ /**
+ * Check which major version of PDFlib is installed
+ *
+ * @return int The mahor version number of PDFlib
+ * @access private
+ */
+ function _version()
+ {
+ $result = false;
+ $version = '';
+ if (function_exists('pdf_get_majorversion')) {
+ $version = pdf_get_majorversion();
+ } else if (function_exists('pdf_get_value')) {
+ $version = pdf_get_value($this->_pdf, 'major', 0);
+ } else {
+ ob_start();
+ phpinfo(8);
+ $php_info = ob_get_contents();
+ ob_end_clean();
+
+ if (preg_match("/<td[^>]*>PDFlib GmbH Version *<\/td><td[^>]*>([^<]*)<\/td>/", $php_info, $result)) {
+ $version = $result[1];
+ }
+ }
+
+ if (preg_match('/([0-9]{1,2})\.[0-9]{1,2}(\.[0-9]{1,2})?/', trim($version), $result)) {
+ return $result[1];
+ } else {
+ return $version;
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for handling output in Postscript format.\r
- * \r
- * Requires PHP extension pslib\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: PS.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
- \r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas.php';\r
-\r
-/**\r
- * Include file Image/Canvas/Color.php\r
- */\r
-require_once 'Image/Canvas/Color.php';\r
-\r
-/**\r
- * PostScript Canvas class.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_PS extends Image_Canvas\r
-{\r
-\r
- /**\r
- * The PostScript document\r
- * @var resource\r
- * @access private\r
- */\r
- var $_ps;\r
-\r
- /**\r
- * The major version of pslib\r
- * @var int\r
- * @access private\r
- */\r
- var $_pslib;\r
-\r
- /**\r
- * The font\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_psFont = false;\r
-\r
- /**\r
- * The width of the page\r
- * @var int\r
- * @access private\r
- */\r
- var $_pageWidth;\r
-\r
- /**\r
- * The height of the page\r
- * @var int\r
- * @access private\r
- */\r
- var $_pageHeight;\r
-\r
- /**\r
- * Create the PostScript canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'page' Specify the page/paper format for the graph's page, available\r
- * formats are: A0, A1, A2, A3, A4, A5, A6, B5, letter, legal, ledger,\r
- * 11x17, cd_front, inlay, inlay_nosides\r
- *\r
- * 'align' Alignment of the graph on the page, available options are:\r
- * topleft, topcenter, topright, leftcenter, center, rightcenter,\r
- * leftbottom, centerbottom, rightbottom\r
- *\r
- * 'orientation' Specifies the paper orientation, default is 'portrait' and\r
- * 'landscape' is also supported.\r
- *\r
- * 'creator' The creator tag of the PostScript/graph\r
- *\r
- * 'author' The author tag of the PostScript/graph\r
- *\r
- * 'title' The title tag of the PostScript/graph\r
- *\r
- * 'width' The width of the graph on the page\r
- *\r
- * 'height' The height of the graph on the page\r
- *\r
- * 'left' The left offset of the graph on the page\r
- *\r
- * 'top' The top offset of the graph on the page\r
- *\r
- * 'filename' The PostScript file to open/add page to, using 'filename' requires\r
- * 'ps' An existing pslib PostScript document to add the page to\r
- *\r
- * 'add_page' (true/false) Used together with 'ps', to specify whether the\r
- * canvas should add a new graph page (true) or create the graph on the\r
- * current page (false), default is 'true'\r
- *\r
- * The 'page' and 'width' & 'height' can be mutually omitted, if 'page' is\r
- * omitted the page is created using dimensions of width x height, and if\r
- * width and height are omitted the page dimensions are used for the graph.\r
- *\r
- * If 'ps' is specified, 'filename', 'creator', 'author' and 'title' has no\r
- * effect.\r
- *\r
- * 'left' and 'top' are overridden by 'align'\r
- *\r
- * It is required either to specify 'width' & 'height' or 'page'.\r
- *\r
- * The PostScript format/pslib has some limitations on the capabilities,\r
- * which means some functionality available using other canvass (fx. alpha\r
- * blending and gradient fills) are not supported with PostScript\r
- * (see Canvas.txt in the docs/ folder for further details)\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_PS($param)\r
- {\r
- if (isset($param['page'])) {\r
- switch (strtoupper($param['page'])) {\r
- case 'A0':\r
- $this->_pageWidth = 2380;\r
- $this->_pageHeight = 3368;\r
- break;\r
-\r
- case 'A1':\r
- $this->_pageWidth = 1684;\r
- $this->_pageHeight = 2380;\r
- break;\r
-\r
- case 'A2':\r
- $this->_pageWidth = 1190;\r
- $this->_pageHeight = 1684;\r
- break;\r
-\r
- case 'A3':\r
- $this->_pageWidth = 842;\r
- $this->_pageHeight = 1190;\r
- break;\r
-\r
- case 'A4':\r
- $this->_pageWidth = 595;\r
- $this->_pageHeight = 842;\r
- break;\r
-\r
- case 'A5':\r
- $this->_pageWidth = 421;\r
- $this->_pageHeight = 595;\r
- break;\r
-\r
- case 'A6':\r
- $this->_pageWidth = 297;\r
- $this->_pageHeight = 421;\r
- break;\r
-\r
- case 'B5':\r
- $this->_pageWidth = 501;\r
- $this->_pageHeight = 709;\r
- break;\r
-\r
- case 'LETTER':\r
- $this->_pageWidth = 612;\r
- $this->_pageHeight = 792;\r
- break;\r
-\r
- case 'LEGAL':\r
- $this->_pageWidth = 612;\r
- $this->_pageHeight = 1008;\r
- break;\r
-\r
- case 'LEDGER':\r
- $this->_pageWidth = 1224;\r
- $this->_pageHeight = 792;\r
- break;\r
-\r
- case '11X17':\r
- $this->_pageWidth = 792;\r
- $this->_pageHeight = 1224;\r
- break;\r
-\r
- case 'CD_FRONT':\r
- $this->_pageWidth = 337;\r
- $this->_pageHeight = 337;\r
- break;\r
-\r
- case 'INLAY':\r
- $this->_pageWidth = 425;\r
- $this->_pageHeight = 332;\r
- break;\r
-\r
- case 'INLAY_NOSIDES':\r
- $this->_pageWidth = 390;\r
- $this->_pageHeight = 332;\r
- break;\r
- }\r
- }\r
-\r
- $this->setDefaultFont(array('name' => 'Helvetica', 'color' => 'black', 'size' => 9));\r
-\r
- if ((isset($param['orientation'])) && (strtoupper($param['orientation']) == 'LANDSCAPE')) {\r
- $w = $this->_pageWidth;\r
- $this->_pageWidth = $this->_pageHeight;\r
- $this->_pageHeight = $w;\r
- }\r
-\r
- parent::Image_Canvas($param);\r
-\r
- if (!$this->_pageWidth) {\r
- $this->_pageWidth = $this->_width;\r
- } elseif (!$this->_width) {\r
- $this->_width = $this->_pageWidth;\r
- }\r
-\r
- if (!$this->_pageHeight) {\r
- $this->_pageHeight = $this->_height;\r
- } elseif (!$this->_height) {\r
- $this->_height = $this->_pageHeight;\r
- }\r
-\r
- $this->_width = min($this->_width, $this->_pageWidth);\r
- $this->_height = min($this->_height, $this->_pageHeight);\r
-\r
- if ((isset($param['align'])) &&\r
- (($this->_width != $this->_pageWidth) || ($this->_height != $this->_pageHeight))\r
- ) {\r
- switch (strtoupper($param['align'])) {\r
- case 'TOPLEFT':\r
- $this->_top = 0;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'TOPCENTER':\r
- $this->_top = 0;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'TOPRIGHT':\r
- $this->_top = 0;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
-\r
- case 'LEFTCENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'CENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'RIGHTCENTER':\r
- $this->_top = ($this->_pageHeight - $this->_height) / 2;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
-\r
- case 'LEFTBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = 0;\r
- break;\r
-\r
- case 'CENTERBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = ($this->_pageWidth - $this->_width) / 2;\r
- break;\r
-\r
- case 'RIGHTBOTTOM':\r
- $this->_top = $this->_pageHeight - $this->_height;\r
- $this->_left = $this->_pageWidth - $this->_width;\r
- break;\r
- }\r
- }\r
-\r
- $addPage = true;\r
- if ((isset($param['ps'])) && (is_resource($param['ps']))) {\r
- $this->_ps =& $param['ps'];\r
- if ((isset($param['add_page'])) && ($param['add_page'] === false)) {\r
- $addPage = false;\r
- }\r
- } else {\r
- $this->_ps = ps_new();\r
-\r
- if (isset($param['filename'])) {\r
- ps_open_file($this->_ps, $param['filename']);\r
- } else {\r
- ps_open_file($this->_ps);\r
- }\r
-\r
- ps_set_parameter($this->_ps, 'warning', 'true');\r
-\r
- ps_set_info($this->_ps, 'Creator', (isset($param['creator']) ? $param['creator'] : 'PEAR::Image_Canvas'));\r
- ps_set_info($this->_ps, 'Author', (isset($param['author']) ? $param['author'] : 'Jesper Veggerby'));\r
- ps_set_info($this->_ps, 'Title', (isset($param['title']) ? $param['title'] : 'Image_Canvas'));\r
- }\r
-\r
- if ($addPage) {\r
- ps_begin_page($this->_ps, $this->_pageWidth, $this->_pageHeight);\r
- }\r
- $this->_reset();\r
-\r
- $this->_pslib = $this->_version();\r
- }\r
-\r
- /**\r
- * Get the x-point from the relative to absolute coordinates\r
- *\r
- * @param float $x The relative x-coordinate (in percentage of total width)\r
- * @return float The x-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getX($x)\r
- {\r
- return $this->_left + $x;\r
- }\r
-\r
- /**\r
- * Get the y-point from the relative to absolute coordinates\r
- *\r
- * @param float $y The relative y-coordinate (in percentage of total width)\r
- * @return float The y-coordinate as applied to the canvas\r
- * @access private\r
- */\r
- function _getY($y)\r
- {\r
- return $this->_pageHeight - ($this->_top + $y);\r
- }\r
-\r
- /**\r
- * Get the color index for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int The GD image index of the color\r
- * @access private\r
- */\r
- function _color($color = false)\r
- {\r
- if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {\r
- return false;\r
- } else {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- $color[0] = $color[0]/255;\r
- $color[1] = $color[1]/255;\r
- $color[2] = $color[2]/255;\r
- return $color;\r
- }\r
- }\r
-\r
- /**\r
- * Get the PostScript linestyle\r
- *\r
- * @param mixed $lineStyle The line style to return, false if the one\r
- * explicitly set\r
- * @return bool True if set (so that a line should be drawn)\r
- * @access private\r
- */\r
- function _setLineStyle($lineStyle = false)\r
- {\r
- if ($lineStyle === false) {\r
- $lineStyle = $this->_lineStyle;\r
- }\r
-\r
- if (($lineStyle == 'transparent') || ($lineStyle === false)) {\r
- return false;\r
- }\r
- \r
- if (is_array($lineStyle)) {\r
- // TODO Implement linestyles in pslib (using ps_setcolor(.., 'pattern'...); ?\r
- reset($lineStyle);\r
- $lineStyle = current($lineStyle);\r
- } \r
-\r
- $color = $this->_color($lineStyle);\r
-\r
- ps_setlinewidth($this->_ps, $this->_thickness);\r
- ps_setcolor($this->_ps, 'stroke', 'rgb', $color[0], $color[1], $color[2], 0);\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the PostScript fill style\r
- *\r
- * @param mixed $fillStyle The fillstyle to return, false if the one\r
- * explicitly set\r
- * @return bool True if set (so that a line should be drawn)\r
- * @access private\r
- */\r
- function _setFillStyle($fillStyle = false)\r
- {\r
- if ($fillStyle === false) {\r
- $fillStyle = $this->_fillStyle;\r
- }\r
-\r
- if (($fillStyle == 'transparent') || ($fillStyle === false)) {\r
- return false;\r
- }\r
-\r
- $color = $this->_color($fillStyle);\r
-\r
- ps_setcolor($this->_ps, 'fill', 'rgb', $color[0], $color[1], $color[2], 0);\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the PostScript font\r
- *\r
- * @access private\r
- */\r
- function _setFont()\r
- {\r
- $this->_psFont = false;\r
- if (isset($this->_font['name'])) {\r
- ps_set_parameter($this->_ps, 'FontOutline', $this->_font['name'] . '=' . $this->_font['file']);\r
- $this->_psFont = ps_findfont($this->_ps, $this->_font['name'], $this->_font['encoding'], $this->_font['embed']);\r
-\r
- if ($this->_psFont) {\r
- ps_setfont($this->_ps, $this->_psFont, $this->_font['size']);\r
- $this->_setFillStyle($this->_font['color']);\r
- }\r
- } else {\r
- $this->_setFillStyle('black');\r
- }\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling.\r
- *\r
- * Image filling is not supported with PostScript, filling 'transparent'\r
- *\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- $this->_fillStyle = 'transparent';\r
- }\r
-\r
- /**\r
- * Sets a gradient fill\r
- *\r
- * Gradient filling is not supported with PostScript, end color used as solid fill.\r
- *\r
- * @param array $gradient Gradient fill options\r
- */\r
- function setGradientFill($gradient)\r
- {\r
- $this->_fillStyle = $gradient['end'];\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- *\r
- * 'ttf' = the .ttf file (either the basename, filename or full path)\r
- * If 'ttf' is specified, then the following can be specified\r
- *\r
- * 'size' = size in pixels\r
- *\r
- * 'angle' = the angle with which to write the text\r
- *\r
- * @param array $font The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- parent::setFont($fontOptions);\r
-\r
- if (!isset($this->_font['size'])) {\r
- $this->_font['size'] = 12;\r
- }\r
-\r
- if (!isset($this->_font['encoding'])) {\r
- $this->_font['encoding'] = null;\r
- }\r
-\r
- if ($this->_font['name'] == 'Helvetica') {\r
- $this->_font['embed'] = 0;\r
- }\r
-\r
- if (!isset($this->_font['color'])) {\r
- $this->_font['color'] = 'black';\r
- }\r
- }\r
-\r
- /**\r
- * Resets the canvas.\r
- *\r
- * Includes fillstyle, linestyle, thickness and polygon\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
-// ps_initgraphics($this->_ps);\r
- parent::_reset();\r
- }\r
-\r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'color': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- if ($this->_setLineStyle($color)) {\r
- ps_moveto($this->_ps, $this->_getX($params['x0']), $this->_getY($params['y0']));\r
- ps_lineto($this->_ps, $this->_getX($params['x1']), $this->_getY($params['y1']));\r
- ps_stroke($this->_ps);\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params = array())\r
- {\r
- $connectEnds = (isset($params['connect']) ? $params['connect'] : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = false;\r
- if ($connectEnds) {\r
- $fill = $this->_setFillStyle($fillColor);\r
- }\r
-\r
- $first = true;\r
- foreach ($this->_polygon as $point) {\r
- if ($first === true) {\r
- ps_moveto($this->_ps, $point['X'], $point['Y']);\r
- $first = $point;\r
- } else {\r
- if (isset($last['P1X'])) {\r
- ps_curveto($this->_ps,\r
- $last['P1X'],\r
- $last['P1Y'],\r
- $last['P2X'],\r
- $last['P2Y'],\r
- $point['X'],\r
- $point['Y']\r
- );\r
- } else {\r
- ps_lineto($this->_ps,\r
- $point['X'],\r
- $point['Y']\r
- );\r
- }\r
- }\r
- $last = $point;\r
- }\r
-\r
- if ($connectEnds) {\r
- if (isset($last['P1X'])) {\r
- ps_curveto($this->_ps,\r
- $last['P1X'],\r
- $last['P1Y'],\r
- $last['P2X'],\r
- $last['P2Y'],\r
- $first['X'],\r
- $first['Y']\r
- );\r
- } else {\r
- ps_lineto($this->_ps,\r
- $first['X'],\r
- $first['Y']\r
- );\r
- }\r
- }\r
-\r
- if (($line) && ($fill)) {\r
- ps_fill_stroke($this->_ps);\r
- } elseif ($line) {\r
- ps_stroke($this->_ps);\r
- } elseif ($fill) {\r
- ps_fill($this->_ps);\r
- }\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = $this->_setFillStyle($fillColor);\r
- if (($line) || ($fill)) {\r
- ps_rect($this->_ps, min($x0, $x1), min($y0, $y1), abs($x1 - $x0), abs($y1 - $y0));\r
- if (($line) && ($fill)) {\r
- ps_fill_stroke($this->_ps);\r
- } elseif ($line) {\r
- ps_stroke($this->_ps);\r
- } elseif ($fill) {\r
- ps_fill($this->_ps);\r
- }\r
- }\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $x = $params['x'];\r
- $y = $params['y'];\r
- $rx = $params['rx'];\r
- $ry = $params['ry'];\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $line = $this->_setLineStyle($lineColor);\r
- $fill = $this->_setFillStyle($fillColor);\r
- if (($line) || ($fill)) {\r
- if ($rx == $ry) {\r
- ps_circle($this->_ps, $this->_getX($x), $this->_getY($y), $rx);\r
- } else {\r
- ps_moveto($this->_ps, $this->_getX($x - $rx), $this->_getY($y));\r
- ps_curveto($this->_ps,\r
- $this->_getX($x - $rx), $this->_getY($y),\r
- $this->_getX($x - $rx), $this->_getY($y - $ry),\r
- $this->_getX($x), $this->_getY($y - $ry)\r
- );\r
- ps_curveto($this->_ps,\r
- $this->_getX($x), $this->_getY($y - $ry),\r
- $this->_getX($x + $rx), $this->_getY($y - $ry),\r
- $this->_getX($x + $rx), $this->_getY($y)\r
- );\r
- ps_curveto($this->_ps,\r
- $this->_getX($x + $rx), $this->_getY($y),\r
- $this->_getX($x + $rx), $this->_getY($y + $ry),\r
- $this->_getX($x), $this->_getY($y + $ry)\r
- );\r
- ps_curveto($this->_ps,\r
- $this->_getX($x), $this->_getY($y + $ry),\r
- $this->_getX($x - $rx), $this->_getY($y + $ry),\r
- $this->_getX($x - $rx), $this->_getY($y)\r
- );\r
- }\r
-\r
- if (($line) && ($fill)) {\r
- ps_fill_stroke($this->_ps);\r
- } elseif ($line) {\r
- ps_stroke($this->_ps);\r
- } elseif ($fill) {\r
- ps_fill($this->_ps);\r
- }\r
- }\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
- $v1 = $this->_getX($params['v1']);\r
- $v2 = $this->_getY($params['v2']);\r
- $srx = $this->_getX($params['srx']);\r
- $sry = $this->_getY($params['sry']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- // TODO Implement pslib::pieSlice()\r
- parent::pieslice($params);\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- if ($this->_psFont === false) {\r
- return $this->_font['size'] * 0.7 * strlen($text);\r
- } else {\r
- return ps_stringwidth($this->_ps, $text, $this->_psFont, $this->_font['size']);\r
- }\r
- }\r
-\r
- /**\r
- * Get the height of a text,\r
- *\r
- * @param string $text The text to get the height of\r
- * @return int The height of the text\r
- */\r
- function textHeight($text)\r
- {\r
- if (isset($this->_font['size'])) {\r
- return $this->_font['size'];\r
- } else {\r
- return 12;\r
- }\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of text\r
- * 'y': int Y-point of text\r
- * 'text': string The text to add\r
- * 'alignment': array [optional] Alignment\r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $text = $params['text'];\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- $this->_setFont();\r
-\r
- $textWidth = $this->textWidth($text);\r
- $textHeight = $this->textHeight($text);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
- \r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if ($alignment['horizontal'] == 'right') {\r
- $x = $x - $textWidth;\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $x = $x - ($textWidth / 2);\r
- }\r
-\r
- $y -= $textHeight;\r
-\r
- if ($alignment['vertical'] == 'bottom') {\r
- $y = $y + $textHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y = $y + ($textHeight / 2);\r
- }\r
-\r
- if (($color === false) && (isset($this->_font['color']))) {\r
- $color = $this->_font['color'];\r
- }\r
-\r
- ps_show_xy($this->_ps, $text, $x, $y);\r
-\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of overlayed image\r
- * 'y': int Y-point of overlayed image\r
- * 'filename': string The filename of the image to overlay\r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $filename = $params['filename'];\r
- $width = (isset($params['width']) ? $params['width'] : false);\r
- $height = (isset($params['height']) ? $params['height'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- if (substr($filename, -4) == '.png') {\r
- $type = 'png';\r
- } elseif (substr($filename, -4) == '.jpg') {\r
- $type = 'jpeg';\r
- }\r
-\r
- $image = ps_open_image_file($this->_ps, $type, realpath($filename), '');\r
- $width_ = ps_get_value($this->_ps, 'imagewidth', $image);\r
- $height_ = ps_get_value($this->_ps, 'imageheight', $image);\r
-\r
- $outputWidth = ($width !== false ? $width : $width_);\r
- $outputHeight = ($height !== false ? $height : $height_);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
- \r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if ($alignment['horizontal'] == 'right') {\r
- $x -= $outputWidth;\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $x -= $outputWidth / 2;\r
- }\r
-\r
- if ($alignment['vertical'] == 'top') {\r
- $y += $outputHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y += $outputHeight / 2;\r
- }\r
- \r
- if (($width === false) && ($height === false)) {\r
- $scale = 1;\r
- } else {\r
- $scale = max(($height/$height_), ($width/$width_));\r
- } \r
-\r
- ps_place_image($this->_ps, $image, $x, $y, $scale);\r
- ps_close_image($this->_ps, $image);\r
- \r
- parent::image($params);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- ps_end_page($this->_ps);\r
- ps_close($this->_ps);\r
-\r
- $buf = ps_get_buffer($this->_ps);\r
- $len = strlen($buf);\r
-\r
- header('Content-type: application/postscript');\r
- header('Content-Length: ' . $len);\r
- header('Content-Disposition: inline; filename=image_graph.ps');\r
- print $buf;\r
-\r
- ps_delete($this->_ps);\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- * @abstract\r
- */\r
- function save($param = false)\r
- {\r
- parent::save($param);\r
- ps_end_page($this->_ps);\r
- ps_close($this->_ps);\r
-\r
- if($param['filename'] == "") {\r
- $buf = ps_get_buffer($this->_ps);\r
- $len = strlen($buf);\r
-\r
- $fp = @fopen($param['filename'], 'wb');\r
- if ($fp) {\r
- fwrite($fp, $buf, strlen($buf));\r
- fclose($fp);\r
- }\r
- }\r
-\r
- ps_delete($this->_ps);\r
- }\r
- \r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * This method implicitly saves the canvas to the filename in the \r
- * filesystem path specified and parses it as URL specified by URL path\r
- * \r
- * Parameter array:\r
- * 'filename': string\r
- * 'filepath': string Path to the file on the file system. Remember the final slash\r
- * 'urlpath': string Path to the file available through an URL. Remember the final slash\r
- * 'title': string The url title\r
- */\r
- function toHtml($params)\r
- {\r
- parent::toHtml($params);\r
- return '<a href="' . $params['urlpath'] . $params['filename'] . '">' . $params['title'] . '</a>'; \r
- } \r
-\r
- /**\r
- * Check which major version of pslib is installed\r
- *\r
- * @return int The mahor version number of pslib\r
- * @access private\r
- */\r
- function _version()\r
- {\r
- $result = false;\r
- $version = '';\r
- if (function_exists('ps_get_majorversion')) {\r
- $version = ps_get_majorversion();\r
- } else if (function_exists('ps_get_value')) {\r
- $version = ps_get_value($this->_ps, 'major', 0); \r
- } else {\r
- ob_start();\r
- phpinfo(8);\r
- $php_info = ob_get_contents();\r
- ob_end_clean();\r
-\r
- if (ereg("<td[^>]*>pslib Version *<\/td><td[^>]*>([^<]*)<\/td>",\r
- $php_info, $result))\r
- {\r
- $version = $result[1];\r
- }\r
- } \r
- \r
- if (ereg('([0-9]{1,2})\.[0-9]{1,2}(\.[0-9]{1,2})?', trim($version), $result)) {\r
- return $result[1];\r
- } else {\r
- return $version;\r
- }\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for handling output in Postscript format.
+ *
+ * Requires PHP extension pslib
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: PS.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas.php';
+
+/**
+ * Include file Image/Canvas/Color.php
+ */
+require_once 'Image/Canvas/Color.php';
+
+/**
+ * PostScript Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_PS extends Image_Canvas
+{
+
+ /**
+ * The PostScript document
+ * @var resource
+ * @access private
+ */
+ var $_ps;
+
+ /**
+ * The major version of pslib
+ * @var int
+ * @access private
+ */
+ var $_pslib;
+
+ /**
+ * The font
+ * @var mixed
+ * @access private
+ */
+ var $_psFont = false;
+
+ /**
+ * The width of the page
+ * @var int
+ * @access private
+ */
+ var $_pageWidth;
+
+ /**
+ * The height of the page
+ * @var int
+ * @access private
+ */
+ var $_pageHeight;
+
+ /**
+ * Create the PostScript canvas.
+ *
+ * Parameters available:
+ *
+ * 'page' Specify the page/paper format for the graph's page, available
+ * formats are: A0, A1, A2, A3, A4, A5, A6, B5, letter, legal, ledger,
+ * 11x17, cd_front, inlay, inlay_nosides
+ *
+ * 'align' Alignment of the graph on the page, available options are:
+ * topleft, topcenter, topright, leftcenter, center, rightcenter,
+ * leftbottom, centerbottom, rightbottom
+ *
+ * 'orientation' Specifies the paper orientation, default is 'portrait' and
+ * 'landscape' is also supported.
+ *
+ * 'creator' The creator tag of the PostScript/graph
+ *
+ * 'author' The author tag of the PostScript/graph
+ *
+ * 'title' The title tag of the PostScript/graph
+ *
+ * 'width' The width of the graph on the page
+ *
+ * 'height' The height of the graph on the page
+ *
+ * 'left' The left offset of the graph on the page
+ *
+ * 'top' The top offset of the graph on the page
+ *
+ * 'filename' The PostScript file to open/add page to, using 'filename' requires
+ * 'ps' An existing pslib PostScript document to add the page to
+ *
+ * 'add_page' (true/false) Used together with 'ps', to specify whether the
+ * canvas should add a new graph page (true) or create the graph on the
+ * current page (false), default is 'true'
+ *
+ * The 'page' and 'width' & 'height' can be mutually omitted, if 'page' is
+ * omitted the page is created using dimensions of width x height, and if
+ * width and height are omitted the page dimensions are used for the graph.
+ *
+ * If 'ps' is specified, 'filename', 'creator', 'author' and 'title' has no
+ * effect.
+ *
+ * 'left' and 'top' are overridden by 'align'
+ *
+ * It is required either to specify 'width' & 'height' or 'page'.
+ *
+ * The PostScript format/pslib has some limitations on the capabilities,
+ * which means some functionality available using other canvass (fx. alpha
+ * blending and gradient fills) are not supported with PostScript
+ * (see Canvas.txt in the docs/ folder for further details)
+ *
+ * @param array $param Parameter array
+ */
+ function Image_Canvas_PS($param)
+ {
+ if (isset($param['page'])) {
+ switch (strtoupper($param['page'])) {
+ case 'A0':
+ $this->_pageWidth = 2380;
+ $this->_pageHeight = 3368;
+ break;
+
+ case 'A1':
+ $this->_pageWidth = 1684;
+ $this->_pageHeight = 2380;
+ break;
+
+ case 'A2':
+ $this->_pageWidth = 1190;
+ $this->_pageHeight = 1684;
+ break;
+
+ case 'A3':
+ $this->_pageWidth = 842;
+ $this->_pageHeight = 1190;
+ break;
+
+ case 'A4':
+ $this->_pageWidth = 595;
+ $this->_pageHeight = 842;
+ break;
+
+ case 'A5':
+ $this->_pageWidth = 421;
+ $this->_pageHeight = 595;
+ break;
+
+ case 'A6':
+ $this->_pageWidth = 297;
+ $this->_pageHeight = 421;
+ break;
+
+ case 'B5':
+ $this->_pageWidth = 501;
+ $this->_pageHeight = 709;
+ break;
+
+ case 'LETTER':
+ $this->_pageWidth = 612;
+ $this->_pageHeight = 792;
+ break;
+
+ case 'LEGAL':
+ $this->_pageWidth = 612;
+ $this->_pageHeight = 1008;
+ break;
+
+ case 'LEDGER':
+ $this->_pageWidth = 1224;
+ $this->_pageHeight = 792;
+ break;
+
+ case '11X17':
+ $this->_pageWidth = 792;
+ $this->_pageHeight = 1224;
+ break;
+
+ case 'CD_FRONT':
+ $this->_pageWidth = 337;
+ $this->_pageHeight = 337;
+ break;
+
+ case 'INLAY':
+ $this->_pageWidth = 425;
+ $this->_pageHeight = 332;
+ break;
+
+ case 'INLAY_NOSIDES':
+ $this->_pageWidth = 390;
+ $this->_pageHeight = 332;
+ break;
+ }
+ }
+
+ $this->setDefaultFont(array('name' => 'Helvetica', 'color' => 'black', 'size' => 9));
+
+ if ((isset($param['orientation'])) && (strtoupper($param['orientation']) == 'LANDSCAPE')) {
+ $w = $this->_pageWidth;
+ $this->_pageWidth = $this->_pageHeight;
+ $this->_pageHeight = $w;
+ }
+
+ parent::Image_Canvas($param);
+
+ if (!$this->_pageWidth) {
+ $this->_pageWidth = $this->_width;
+ } elseif (!$this->_width) {
+ $this->_width = $this->_pageWidth;
+ }
+
+ if (!$this->_pageHeight) {
+ $this->_pageHeight = $this->_height;
+ } elseif (!$this->_height) {
+ $this->_height = $this->_pageHeight;
+ }
+
+ $this->_width = min($this->_width, $this->_pageWidth);
+ $this->_height = min($this->_height, $this->_pageHeight);
+
+ if ((isset($param['align']))
+ && (($this->_width != $this->_pageWidth) || ($this->_height != $this->_pageHeight))
+ ) {
+ switch (strtoupper($param['align'])) {
+ case 'TOPLEFT':
+ $this->_top = 0;
+ $this->_left = 0;
+ break;
+
+ case 'TOPCENTER':
+ $this->_top = 0;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'TOPRIGHT':
+ $this->_top = 0;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+
+ case 'LEFTCENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = 0;
+ break;
+
+ case 'CENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'RIGHTCENTER':
+ $this->_top = ($this->_pageHeight - $this->_height) / 2;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+
+ case 'LEFTBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = 0;
+ break;
+
+ case 'CENTERBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = ($this->_pageWidth - $this->_width) / 2;
+ break;
+
+ case 'RIGHTBOTTOM':
+ $this->_top = $this->_pageHeight - $this->_height;
+ $this->_left = $this->_pageWidth - $this->_width;
+ break;
+ }
+ }
+
+ $addPage = true;
+ if ((isset($param['ps'])) && (is_resource($param['ps']))) {
+ $this->_ps =& $param['ps'];
+ if ((isset($param['add_page'])) && ($param['add_page'] === false)) {
+ $addPage = false;
+ }
+ } else {
+ $this->_ps = ps_new();
+
+ if (isset($param['filename'])) {
+ ps_open_file($this->_ps, $param['filename']);
+ } else {
+ ps_open_file($this->_ps);
+ }
+
+ ps_set_parameter($this->_ps, 'warning', 'true');
+
+ ps_set_info($this->_ps, 'Creator', (isset($param['creator']) ? $param['creator'] : 'PEAR::Image_Canvas'));
+ ps_set_info($this->_ps, 'Author', (isset($param['author']) ? $param['author'] : 'Jesper Veggerby'));
+ ps_set_info($this->_ps, 'Title', (isset($param['title']) ? $param['title'] : 'Image_Canvas'));
+ }
+
+ if ($addPage) {
+ ps_begin_page($this->_ps, $this->_pageWidth, $this->_pageHeight);
+ }
+ $this->_reset();
+
+ $this->_pslib = $this->_version();
+ }
+
+ /**
+ * Get the x-point from the relative to absolute coordinates
+ *
+ * @param float $x The relative x-coordinate (in percentage of total width)
+ *
+ * @return float The x-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getX($x)
+ {
+ return $this->_left + $x;
+ }
+
+ /**
+ * Get the y-point from the relative to absolute coordinates
+ *
+ * @param float $y The relative y-coordinate (in percentage of total width)
+ *
+ * @return float The y-coordinate as applied to the canvas
+ * @access private
+ */
+ function _getY($y)
+ {
+ return $this->_pageHeight - ($this->_top + $y);
+ }
+
+ /**
+ * Get the color index for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int The GD image index of the color
+ * @access private
+ */
+ function _color($color = false)
+ {
+ if (($color === false) || ($color === 'opague') || ($color === 'transparent')) {
+ return false;
+ } else {
+ $color = Image_Canvas_Color::color2RGB($color);
+ $color[0] = $color[0]/255;
+ $color[1] = $color[1]/255;
+ $color[2] = $color[2]/255;
+ return $color;
+ }
+ }
+
+ /**
+ * Get the PostScript linestyle
+ *
+ * @param mixed $lineStyle The line style to return, false if the one
+ * explicitly set
+ *
+ * @return bool True if set (so that a line should be drawn)
+ * @access private
+ */
+ function _setLineStyle($lineStyle = false)
+ {
+ if ($lineStyle === false) {
+ $lineStyle = $this->_lineStyle;
+ }
+
+ if (($lineStyle == 'transparent') || ($lineStyle === false)) {
+ return false;
+ }
+
+ if (is_array($lineStyle)) {
+ // TODO Implement linestyles in pslib (using ps_setcolor(.., 'pattern'...); ?
+ reset($lineStyle);
+ $lineStyle = current($lineStyle);
+ }
+
+ $color = $this->_color($lineStyle);
+
+ ps_setlinewidth($this->_ps, $this->_thickness);
+ ps_setcolor($this->_ps, 'stroke', 'rgb', $color[0], $color[1], $color[2], 0);
+ return true;
+ }
+
+ /**
+ * Set the PostScript fill style
+ *
+ * @param mixed $fillStyle The fillstyle to return, false if the one
+ * explicitly set
+ *
+ * @return bool True if set (so that a line should be drawn)
+ * @access private
+ */
+ function _setFillStyle($fillStyle = false)
+ {
+ if ($fillStyle === false) {
+ $fillStyle = $this->_fillStyle;
+ }
+
+ if (($fillStyle == 'transparent') || ($fillStyle === false)) {
+ return false;
+ }
+
+ $color = $this->_color($fillStyle);
+
+ ps_setcolor($this->_ps, 'fill', 'rgb', $color[0], $color[1], $color[2], 0);
+ return true;
+ }
+
+ /**
+ * Set the PostScript font
+ *
+ * @return void
+ * @access private
+ */
+ function _setFont()
+ {
+ $this->_psFont = false;
+ if (isset($this->_font['name'])) {
+ ps_set_parameter($this->_ps, 'FontOutline', $this->_font['name'] . '=' . $this->_font['file']);
+ $this->_psFont = ps_findfont($this->_ps, $this->_font['name'], $this->_font['encoding'], $this->_font['embed']);
+
+ if ($this->_psFont) {
+ ps_setfont($this->_ps, $this->_psFont, $this->_font['size']);
+ $this->_setFillStyle($this->_font['color']);
+ }
+ } else {
+ $this->_setFillStyle('black');
+ }
+ }
+
+ /**
+ * Sets an image that should be used for filling.
+ *
+ * Image filling is not supported with PostScript, filling 'transparent'
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ $this->_fillStyle = 'transparent';
+ }
+
+ /**
+ * Sets a gradient fill
+ *
+ * Gradient filling is not supported with PostScript, end color used as solid fill.
+ *
+ * @param array $gradient Gradient fill options
+ *
+ * @return void
+ */
+ function setGradientFill($gradient)
+ {
+ $this->_fillStyle = $gradient['end'];
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ *
+ * 'ttf' = the .ttf file (either the basename, filename or full path)
+ * If 'ttf' is specified, then the following can be specified
+ *
+ * 'size' = size in pixels
+ *
+ * 'angle' = the angle with which to write the text
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ parent::setFont($fontOptions);
+
+ if (!isset($this->_font['size'])) {
+ $this->_font['size'] = 12;
+ }
+
+ if (!isset($this->_font['encoding'])) {
+ $this->_font['encoding'] = null;
+ }
+
+ if ($this->_font['name'] == 'Helvetica') {
+ $this->_font['embed'] = 0;
+ }
+
+ if (!isset($this->_font['color'])) {
+ $this->_font['color'] = 'black';
+ }
+ }
+
+ /**
+ * Resets the canvas.
+ *
+ * Includes fillstyle, linestyle, thickness and polygon
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ // ps_initgraphics($this->_ps);
+ parent::_reset();
+ }
+
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $color = (isset($params['color']) ? $params['color'] : false);
+ if ($this->_setLineStyle($color)) {
+ ps_moveto($this->_ps, $this->_getX($params['x0']), $this->_getY($params['y0']));
+ ps_lineto($this->_ps, $this->_getX($params['x1']), $this->_getY($params['y1']));
+ ps_stroke($this->_ps);
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params = array())
+ {
+ $connectEnds = (isset($params['connect']) ? $params['connect'] : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = false;
+ if ($connectEnds) {
+ $fill = $this->_setFillStyle($fillColor);
+ }
+
+ $first = true;
+ foreach ($this->_polygon as $point) {
+ if ($first === true) {
+ ps_moveto($this->_ps, $point['X'], $point['Y']);
+ $first = $point;
+ } else {
+ if (isset($last['P1X'])) {
+ ps_curveto(
+ $this->_ps,
+ $last['P1X'],
+ $last['P1Y'],
+ $last['P2X'],
+ $last['P2Y'],
+ $point['X'],
+ $point['Y']
+ );
+ } else {
+ ps_lineto(
+ $this->_ps,
+ $point['X'],
+ $point['Y']
+ );
+ }
+ }
+ $last = $point;
+ }
+
+ if ($connectEnds) {
+ if (isset($last['P1X'])) {
+ ps_curveto(
+ $this->_ps,
+ $last['P1X'],
+ $last['P1Y'],
+ $last['P2X'],
+ $last['P2Y'],
+ $first['X'],
+ $first['Y']
+ );
+ } else {
+ ps_lineto(
+ $this->_ps,
+ $first['X'],
+ $first['Y']
+ );
+ }
+ }
+
+ if (($line) && ($fill)) {
+ ps_fill_stroke($this->_ps);
+ } elseif ($line) {
+ ps_stroke($this->_ps);
+ } elseif ($fill) {
+ ps_fill($this->_ps);
+ }
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = $this->_setFillStyle($fillColor);
+ if (($line) || ($fill)) {
+ ps_rect($this->_ps, min($x0, $x1), min($y0, $y1), abs($x1 - $x0), abs($y1 - $y0));
+ if (($line) && ($fill)) {
+ ps_fill_stroke($this->_ps);
+ } elseif ($line) {
+ ps_stroke($this->_ps);
+ } elseif ($fill) {
+ ps_fill($this->_ps);
+ }
+ }
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $x = $params['x'];
+ $y = $params['y'];
+ $rx = $params['rx'];
+ $ry = $params['ry'];
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $line = $this->_setLineStyle($lineColor);
+ $fill = $this->_setFillStyle($fillColor);
+ if (($line) || ($fill)) {
+ if ($rx == $ry) {
+ ps_circle($this->_ps, $this->_getX($x), $this->_getY($y), $rx);
+ } else {
+ ps_moveto($this->_ps, $this->_getX($x - $rx), $this->_getY($y));
+ ps_curveto(
+ $this->_ps,
+ $this->_getX($x - $rx), $this->_getY($y),
+ $this->_getX($x - $rx), $this->_getY($y - $ry),
+ $this->_getX($x), $this->_getY($y - $ry)
+ );
+ ps_curveto(
+ $this->_ps,
+ $this->_getX($x), $this->_getY($y - $ry),
+ $this->_getX($x + $rx), $this->_getY($y - $ry),
+ $this->_getX($x + $rx), $this->_getY($y)
+ );
+ ps_curveto(
+ $this->_ps,
+ $this->_getX($x + $rx), $this->_getY($y),
+ $this->_getX($x + $rx), $this->_getY($y + $ry),
+ $this->_getX($x), $this->_getY($y + $ry)
+ );
+ ps_curveto(
+ $this->_ps,
+ $this->_getX($x), $this->_getY($y + $ry),
+ $this->_getX($x - $rx), $this->_getY($y + $ry),
+ $this->_getX($x - $rx), $this->_getY($y)
+ );
+ }
+
+ if (($line) && ($fill)) {
+ ps_fill_stroke($this->_ps);
+ } elseif ($line) {
+ ps_stroke($this->_ps);
+ } elseif ($fill) {
+ ps_fill($this->_ps);
+ }
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+ $v1 = $this->_getX($params['v1']);
+ $v2 = $this->_getY($params['v2']);
+ $srx = $this->_getX($params['srx']);
+ $sry = $this->_getY($params['sry']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ // TODO Implement pslib::pieSlice()
+ parent::pieslice($params);
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ if ($this->_psFont === false) {
+ return $this->_font['size'] * 0.7 * strlen($text);
+ } else {
+ return ps_stringwidth($this->_ps, $text, $this->_psFont, $this->_font['size']);
+ }
+ }
+
+ /**
+ * Get the height of a text,
+ *
+ * @param string $text The text to get the height of
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text)
+ {
+ if (isset($this->_font['size'])) {
+ return $this->_font['size'];
+ } else {
+ return 12;
+ }
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x': int X-point of text
+ * 'y': int Y-point of text
+ * 'text': string The text to add
+ * 'alignment': array [optional] Alignment
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $text = $params['text'];
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ $this->_setFont();
+
+ $textWidth = $this->textWidth($text);
+ $textHeight = $this->textHeight($text);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if ($alignment['horizontal'] == 'right') {
+ $x = $x - $textWidth;
+ } elseif ($alignment['horizontal'] == 'center') {
+ $x = $x - ($textWidth / 2);
+ }
+
+ $y -= $textHeight;
+
+ if ($alignment['vertical'] == 'bottom') {
+ $y = $y + $textHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y = $y + ($textHeight / 2);
+ }
+
+ if (($color === false) && (isset($this->_font['color']))) {
+ $color = $this->_font['color'];
+ }
+
+ ps_show_xy($this->_ps, $text, $x, $y);
+
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x': int X-point of overlayed image
+ * 'y': int Y-point of overlayed image
+ * 'filename': string The filename of the image to overlay
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $filename = $params['filename'];
+ $width = (isset($params['width']) ? $params['width'] : false);
+ $height = (isset($params['height']) ? $params['height'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ if (substr($filename, -4) == '.png') {
+ $type = 'png';
+ } elseif (substr($filename, -4) == '.jpg') {
+ $type = 'jpeg';
+ }
+
+ $image = ps_open_image_file($this->_ps, $type, realpath($filename), '');
+ $width_ = ps_get_value($this->_ps, 'imagewidth', $image);
+ $height_ = ps_get_value($this->_ps, 'imageheight', $image);
+
+ $outputWidth = ($width !== false ? $width : $width_);
+ $outputHeight = ($height !== false ? $height : $height_);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if ($alignment['horizontal'] == 'right') {
+ $x -= $outputWidth;
+ } elseif ($alignment['horizontal'] == 'center') {
+ $x -= $outputWidth / 2;
+ }
+
+ if ($alignment['vertical'] == 'top') {
+ $y += $outputHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y += $outputHeight / 2;
+ }
+
+ if (($width === false) && ($height === false)) {
+ $scale = 1;
+ } else {
+ $scale = max(($height/$height_), ($width/$width_));
+ }
+
+ ps_place_image($this->_ps, $image, $x, $y, $scale);
+ ps_close_image($this->_ps, $image);
+
+ parent::image($params);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+ ps_end_page($this->_ps);
+ ps_close($this->_ps);
+
+ $buf = ps_get_buffer($this->_ps);
+ $len = strlen($buf);
+
+ header('Content-type: application/postscript');
+ header('Content-Length: ' . $len);
+ header('Content-Disposition: inline; filename=image_graph.ps');
+ print $buf;
+
+ ps_delete($this->_ps);
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ * @abstract
+ */
+ function save($param = false)
+ {
+ parent::save($param);
+ ps_end_page($this->_ps);
+ ps_close($this->_ps);
+
+ if ($param['filename'] == "") {
+ $buf = ps_get_buffer($this->_ps);
+ $len = strlen($buf);
+
+ $fp = @fopen($param['filename'], 'wb');
+ if ($fp) {
+ fwrite($fp, $buf, strlen($buf));
+ fclose($fp);
+ }
+ }
+
+ ps_delete($this->_ps);
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ * 'filename': string
+ * 'filepath': string Path to the file on the file system. Remember the final slash
+ * 'urlpath': string Path to the file available through an URL. Remember the final slash
+ * 'title': string The url title
+ *
+ * @param array $params Parameter array
+ *
+ * @return string HTML code
+ */
+ function toHtml($params)
+ {
+ parent::toHtml($params);
+ return '<a href="' . $params['urlpath'] . $params['filename'] . '">' . $params['title'] . '</a>';
+ }
+
+ /**
+ * Check which major version of pslib is installed
+ *
+ * @return int The mahor version number of pslib
+ * @access private
+ */
+ function _version()
+ {
+ $result = false;
+ $version = '';
+ if (function_exists('ps_get_majorversion')) {
+ $version = ps_get_majorversion();
+ } else if (function_exists('ps_get_value')) {
+ $version = ps_get_value($this->_ps, 'major', 0);
+ } else {
+ ob_start();
+ phpinfo(8);
+ $php_info = ob_get_contents();
+ ob_end_clean();
+
+ if (preg_match("/<td[^>]*>pslib Version *<\/td><td[^>]*>([^<]*)<\/td>/", $php_info, $result)
+ ) {
+ $version = $result[1];
+ }
+ }
+
+ if (preg_match('/([0-9]{1,2})\.[0-9]{1,2}(\.[0-9]{1,2})?/', trim($version), $result)) {
+ return $result[1];
+ } else {
+ return $version;
+ }
+ }
+
+}
+
+?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for handling output in SVG format.\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: SVG.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas.php';\r
-\r
-/**\r
- * Include file Image/Canvas/Color.php\r
- */\r
-require_once 'Image/Canvas/Color.php';\r
-\r
-/**\r
- * SVG Canvas class.\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_SVG extends Image_Canvas\r
-{\r
-\r
- /**\r
- * The SVG elements\r
- * @var string\r
- * @access private\r
- */\r
- var $_elements = '';\r
-\r
- /**\r
- * The SVG defines\r
- * @var string\r
- * @access private\r
- */\r
- var $_defs = '';\r
-\r
- /**\r
- * The current indention level\r
- * @var string\r
- * @access private\r
- */\r
- var $_indent = ' ';\r
-\r
- /**\r
- * A unieuq id counter\r
- * @var int\r
- * @access private\r
- */\r
- var $_id = 1;\r
-\r
- /**\r
- * The current group ids\r
- * @var array\r
- * @access private\r
- */\r
- var $_groupIDs = array();\r
- \r
- /**\r
- * The XML encoding (default iso-8859-1)\r
- * @var string\r
- * @access private\r
- */\r
- var $_encoding = 'iso-8859-1'; \r
-\r
- /**\r
- * Create the SVG canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'width' The width of the graph\r
- *\r
- * 'height' The height of the graph\r
- *\r
- * 'encoding' The encoding of the SVG document\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function Image_Canvas_SVG($params)\r
- {\r
- parent::Image_Canvas($params);\r
- $this->_reset();\r
-\r
- if (isset($params['encoding'])) {\r
- $this->_encoding = $params['encoding'];\r
- }\r
- }\r
-\r
- /**\r
- * Add a SVG "element" to the output\r
- *\r
- * @param string $element The element\r
- * @access private\r
- */\r
- function _addElement($element, $params = array()) {\r
- $elementdata = $this->_indent . $element . "\n";\r
- \r
- if (isset($params['url'])) {\r
- $url = $params['url'];\r
- $target = (isset($params['target']) ? $params['target'] : false);\r
- $alt = (isset($params['alt']) ? $params['alt'] : false);\r
- \r
- $tags = '';\r
- if (isset($params['htmltags'])) {\r
- foreach ($params['htmltags'] as $key => $value) {\r
- $tags .= ' ';\r
- if (strpos($value, '"') >= 0) {\r
- $tags .= $key . '=\'' . $value . '\'';\r
- } else {\r
- $tags .= $key . '="' . $value . '"';\r
- }\r
- }\r
- }\r
- \r
- $elementdata =\r
- $this->_indent . '<a xlink:href="' . $url . '"' . ($target ? ' target="' . $target . '"' : '') . '>' . "\n" .\r
- ' ' . $elementdata .\r
- $this->_indent . '</a>' . "\n"; \r
- }\r
- \r
- \r
- $this->_elements .= $elementdata;\r
- }\r
-\r
- /**\r
- * Add a SVG "define" to the output\r
- *\r
- * @param string $def The define\r
- * @access private\r
- */\r
- function _addDefine($def) {\r
- $this->_defs .= ' ' . $def . "\n";\r
- }\r
-\r
- /**\r
- * Get the color index for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int A SVG compatible color\r
- * @access private\r
- */\r
- function _color($color = false)\r
- {\r
- if ($color === false) {\r
- return 'transparent';\r
- } else {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- return 'rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')';\r
- }\r
- }\r
-\r
- /**\r
- * Get the opacity for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int A SVG compatible opacity value\r
- * @access private\r
- */\r
- function _opacity($color = false)\r
- {\r
- if ($color === false) {\r
- return false;\r
- } else {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- if ($color[3] != 255) {\r
- return sprintf('%0.1f', $color[3]/255);\r
- } else {\r
- return false;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get the SVG applicable linestyle\r
- *\r
- * @param mixed $lineStyle The line style to return, false if the one\r
- * explicitly set\r
- * @return mixed A SVG compatible linestyle\r
- * @access private\r
- */\r
- function _getLineStyle($lineStyle = false)\r
- {\r
- $result = '';\r
- if ($lineStyle === false) {\r
- $lineStyle = $this->_lineStyle;\r
- }\r
-\r
- // TODO Linestyles (i.e. fx. dotted) does not work\r
-\r
- if (($lineStyle != 'transparent') && ($lineStyle !== false)) {\r
- $result = 'stroke-width:' . $this->_thickness . ';';\r
- $result .= 'stroke:' .$this->_color($lineStyle) . ';';\r
- if ($opacity = $this->_opacity($lineStyle)) {\r
- $result .= 'stroke-opacity:' . $opacity . ';';\r
- }\r
- }\r
- return $result;\r
- }\r
-\r
- /**\r
- * Get the SVG applicable fillstyle\r
- *\r
- * @param mixed $fillStyle The fillstyle to return, false if the one\r
- * explicitly set\r
- * @return mixed A SVG compatible fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($fillStyle = false)\r
- {\r
- $result = '';\r
- if ($fillStyle === false) {\r
- $fillStyle = $this->_fillStyle;\r
- }\r
-\r
- if (is_array($fillStyle)) {\r
- if ($fillStyle['type'] == 'gradient') {\r
- $id = 'gradient_' . ($this->_id++);\r
- $startColor = $this->_color($fillStyle['start']);\r
- $endColor = $this->_color($fillStyle['end']);\r
- $startOpacity = $this->_opacity($fillStyle['start']);\r
- $endOpacity = $this->_opacity($fillStyle['end']);\r
-\r
- switch ($fillStyle['direction']) {\r
- case 'horizontal':\r
- case 'horizontal_mirror':\r
- $x1 = '0%';\r
- $y1 = '0%';\r
- $x2 = '100%';\r
- $y2 = '0%';\r
- break;\r
-\r
- case 'vertical':\r
- case 'vertical_mirror':\r
- $x1 = '0%';\r
- $y1 = '100%';\r
- $x2 = '0%';\r
- $y2 = '0%';\r
- break;\r
-\r
- case 'diagonal_tl_br':\r
- $x1 = '0%';\r
- $y1 = '0%';\r
- $x2 = '100%';\r
- $y2 = '100%';\r
- break;\r
-\r
- case 'diagonal_bl_tr':\r
- $x1 = '0%';\r
- $y1 = '100%';\r
- $x2 = '100%';\r
- $y2 = '0%';\r
- break;\r
-\r
- case 'radial':\r
- $cx = '50%';\r
- $cy = '50%';\r
- $r = '100%';\r
- $fx = '50%';\r
- $fy = '50%';\r
- break;\r
-\r
- }\r
-\r
- if ($fillStyle['direction'] == 'radial') {\r
- $this->_addDefine(\r
- '<radialGradient id="' . $id . '" cx="' .\r
- $cx .'" cy="' . $cy .'" r="' . $r .'" fx="' .\r
- $fx .'" fy="' . $fy .'">'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="0%" style="stop-color:' .\r
- $startColor. ';' . ($startOpacity ? 'stop-opacity:' .\r
- $startOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="100%" style="stop-color:' .\r
- $endColor. ';' . ($endOpacity ? 'stop-opacity:' .\r
- $endOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- '</radialGradient>'\r
- );\r
- } elseif (($fillStyle['direction'] == 'vertical_mirror') ||\r
- ($fillStyle['direction'] == 'horizontal_mirror'))\r
- {\r
- $this->_addDefine(\r
- '<linearGradient id="' . $id . '" x1="' .\r
- $x1 .'" y1="' . $y1 .'" x2="' . $x2 .'" y2="' .\r
- $y2 .'">'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="0%" style="stop-color:' .\r
- $startColor. ';' . ($startOpacity ? 'stop-opacity:' .\r
- $startOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="50%" style="stop-color:' .\r
- $endColor. ';' . ($endOpacity ? 'stop-opacity:' .\r
- $endOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="100%" style="stop-color:' .\r
- $startColor. ';' . ($startOpacity ? 'stop-opacity:' .\r
- $startOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- '</linearGradient>'\r
- );\r
- } else {\r
- $this->_addDefine(\r
- '<linearGradient id="' . $id . '" x1="' .\r
- $x1 .'" y1="' . $y1 .'" x2="' . $x2 .'" y2="' .\r
- $y2 .'">'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="0%" style="stop-color:' .\r
- $startColor. ';' . ($startOpacity ? 'stop-opacity:' .\r
- $startOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- ' <stop offset="100%" style="stop-color:' .\r
- $endColor. ';' . ($endOpacity ? 'stop-opacity:' .\r
- $endOpacity . ';' : ''). '"/>'\r
- );\r
- $this->_addDefine(\r
- '</linearGradient>'\r
- );\r
- }\r
-\r
- return 'fill:url(#' . $id . ');';\r
- }\r
- } elseif (($fillStyle != 'transparent') && ($fillStyle !== false)) {\r
- $result = 'fill:' . $this->_color($fillStyle) . ';';\r
- if ($opacity = $this->_opacity($fillStyle)) {\r
- $result .= 'fill-opacity:' . $opacity . ';';\r
- }\r
- return $result;\r
- } else {\r
- return 'fill:none;';\r
- }\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling\r
- *\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- }\r
-\r
- /**\r
- * Sets a gradient fill\r
- *\r
- * @param array $gradient Gradient fill options\r
- */\r
- function setGradientFill($gradient)\r
- {\r
- $this->_fillStyle = $gradient;\r
- $this->_fillStyle['type'] = 'gradient';\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- * 'type' = 'ttf' (TrueType) or omitted for default<br>\r
- * If 'type' = 'ttf' then the following can be specified<br>\r
- * 'size' = size in pixels<br>\r
- * 'angle' = the angle with which to write the text\r
- * 'file' = the .ttf file (either the basename, filename or full path)\r
- *\r
- * @param array $font The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- parent::setFont($fontOptions);\r
- if (!isset($this->_font['size'])) {\r
- $this->_font['size'] = 10;\r
- }\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'color': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
-\r
- $style = $this->_getLineStyle($color) . $this->_getFillStyle('transparent');\r
- if ($style != '') {\r
- $this->_addElement(\r
- '<line ' .\r
- 'x1="' . round($x0) . '" ' .\r
- 'y1="' . round($y0) . '" ' .\r
- 'x2="' . round($x1) . '" ' .\r
- 'y2="' . round($y1) . '" ' .\r
- 'style="' . $style . '"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '/>',\r
- $params\r
- );\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params = array())\r
- {\r
- $connectEnds = (isset($params['connect']) ? $params['connect'] : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- if (!$connectEnds) {\r
- $fillColor = 'transparent';\r
- }\r
- $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
-\r
- $first = true;\r
- $spline = false;\r
- $lastpoint = false;\r
- foreach($this->_polygon as $point) {\r
- if ($first) {\r
- $points = 'M';\r
- } elseif (!$spline) {\r
- $points .= ' L';\r
- }\r
- \r
- if (($spline) && ($lastpoint !== false)) {\r
- $points .= ' ' .round($lastpoint['P1X']) . ',' . round($lastpoint['P1Y']) . ' ' .\r
- round($lastpoint['P2X']) . ',' . round($lastpoint['P2Y']);\r
- } \r
-\r
- $points .= ' ' . round($point['X']) . ',' . round($point['Y']);\r
-\r
- if ((isset($point['P1X'])) && (isset($point['P1Y'])) &&\r
- (isset($point['P2X'])) && (isset($point['P2Y'])))\r
- {\r
- if (($first) || (!$spline)) {\r
- $points .= ' C';\r
- }\r
- $lastpoint = $point;\r
- $spline = true;\r
- } else {\r
- $spline = false;\r
- }\r
- $first = false;\r
- }\r
- if ($connectEnds) {\r
- $points .= ' Z';\r
- }\r
- $this->_addElement(\r
- '<path ' .\r
- 'd="' . $points . '" ' .\r
- 'style="' . $style . '"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '/>',\r
- $params\r
- );\r
-\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $x0 = min($this->_getX($params['x0']), $this->_getX($params['x1']));\r
- $y0 = min($this->_getY($params['y0']), $this->_getY($params['y1']));\r
- $x1 = max($this->_getX($params['x0']), $this->_getX($params['x1']));\r
- $y1 = max($this->_getY($params['y0']), $this->_getY($params['y1']));\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
- \r
- $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);\r
- if ($style != '') {\r
- $this->_addElement(\r
- '<rect ' .\r
- 'x="' . round($x0) . '" ' .\r
- 'y="' . round($y0) . '" ' .\r
- 'width="' . round(abs($x1 - $x0)) . '" ' .\r
- 'height="' . round(abs($y1 - $y0)) . '" ' .\r
- 'style="' . $style . '"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '/>',\r
- $params\r
- );\r
- }\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
-\r
- $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);\r
- if ($style != '') {\r
- $this->_addElement(\r
- '<ellipse ' .\r
- 'cx="' . round($x) . '" ' .\r
- 'cy="' . round($y) . '" ' .\r
- 'rx="' . round($rx) . '" ' .\r
- 'ry="' . round($ry) . '" ' .\r
- 'style="' . $style . '"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '/>',\r
- $params\r
- );\r
- }\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
- $v1 = $this->_getX($params['v1']);\r
- $v2 = $this->_getY($params['v2']);\r
- $srx = (isset($params['srx']) ? $this->_getX($params['srx']) : false);\r
- $sry = (isset($params['sry']) ? $this->_getX($params['sry']) : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
-\r
- $dv = max($v2, $v1) - min($v2, $v1);\r
- if ($dv >= 360) {\r
- $this->ellipse($params);\r
- }\r
- else {\r
- $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);\r
- if ($style != '') {\r
- $x1 = ($x + $rx * cos(deg2rad(min($v1, $v2) % 360)));\r
- $y1 = ($y + $ry * sin(deg2rad(min($v1, $v2) % 360)));\r
- $x2 = ($x + $rx * cos(deg2rad(max($v1, $v2) % 360)));\r
- $y2 = ($y + $ry * sin(deg2rad(max($v1, $v2) % 360)));\r
- $this->_addElement(\r
- '<path d="' .\r
- 'M' . round($x) . ',' . round($y) . ' ' .\r
- 'L' . round($x1) . ',' . round($y1) . ' ' .\r
- 'A' . round($rx) . ',' . round($ry) . ($dv > 180 ? ' 0 1,1 ' : ' 0 0,1 ') .\r
- round($x2) . ',' . round($y2) . ' ' .\r
- 'Z" ' .\r
- 'style="' . $style . '"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '/>',\r
- $params\r
- );\r
- }\r
-\r
- parent::pieslice($params);\r
- }\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {\r
- return $this->_font['size'];\r
- } else {\r
- return round($this->_font['size'] * 0.7 * strlen($text));\r
- }\r
- }\r
-\r
- /**\r
- * Get the height of a text,\r
- *\r
- * @param string $text The text to get the height of\r
- * @return int The height of the text\r
- */\r
- function textHeight($text)\r
- {\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {\r
- return round($this->_font['size'] * 0.7 * strlen($text));\r
- } else {\r
- return $this->_font['size'];\r
- }\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of text\r
- * 'y': int Y-point of text\r
- * 'text': string The text to add\r
- * 'alignment': array [optional] Alignment\r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $text = $params['text'];\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
- \r
- $textHeight = $this->textHeight($text);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
- \r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
- \r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
- \r
- $align = '';\r
-\r
- if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {\r
-// $align .= 'writing-mode: tb-rl;';\r
-\r
- if ($alignment['vertical'] == 'bottom') {\r
- $align .= 'text-anchor:end;';\r
- //$y = $y + $textHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- //$y = $y + ($textHeight / 2);\r
- $align .= 'text-anchor:middle;';\r
- }\r
- } else {\r
- if ($alignment['horizontal'] == 'right') {\r
- $align .= 'text-anchor:end;';\r
- } elseif ($alignment['horizontal'] == 'center') {\r
- $align .= 'text-anchor:middle;';\r
- }\r
-\r
- if ($alignment['vertical'] == 'top') {\r
- $y = $y + $textHeight;\r
- } elseif ($alignment['vertical'] == 'center') {\r
- $y = $y + ($textHeight / 2);\r
- }\r
- }\r
-\r
- if (($color === false) && (isset($this->_font['color']))) {\r
- $color = $this->_font['color'];\r
- }\r
-\r
- $textColor = $this->_color($color);\r
- $textOpacity = $this->_opacity($color);\r
-\r
- $this->_addElement(\r
- '<g transform="translate(' . round($x) . ', ' . round($y) . ')">' . "\n" .\r
- $this->_indent . ' <text ' .\r
- 'x="0" ' .\r
- 'y="0" ' .\r
- (isset($this->_font['angle']) && ($this->_font['angle'] > 0) ?\r
- 'transform="rotate(' . (($this->_font['angle'] + 180) % 360) . ')" ' :\r
- ''\r
- ) .\r
- 'style="' .\r
- (isset($this->_font['name']) ?\r
- 'font-family:' . $this->_font['name'] . ';' : '') .\r
- 'font-size:' . $this->_font['size'] . 'px;fill:' .\r
- $textColor . ($textOpacity ? ';fill-opacity:' .\r
- $textOpacity :\r
- ''\r
- ) . ';' . $align . '"' . \r
- ($attrs ? ' ' . $attrs : '') .\r
- '>' .\r
- htmlspecialchars($text) .\r
- '</text>' . "\n" . \r
- $this->_indent . '</g>',\r
- $params\r
- );\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of overlayed image\r
- * 'y': int Y-point of overlayed image\r
- * 'filename': string The filename of the image to overlay\r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $filename = $params['filename'];\r
-\r
- $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;\r
- \r
- list($width, $height, $type, $attr) = getimagesize($filename); \r
- $width = (isset($params['width']) ? $params['width'] : $width);\r
- $height = (isset($params['height']) ? $params['height'] : $height);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- $file = fopen($filename, 'rb');\r
- $filedata = fread($file, filesize($filename));\r
- fclose($file);\r
- \r
- $data = 'data:' . image_type_to_mime_type($type) . ';base64,' . base64_encode($filedata);\r
- \r
- $this->_addElement(\r
- '<image xlink:href="' . $data . '" x="' . $x . '" y="' . $y . '"' .\r
- ($width ? ' width="' . $width . '"' : '') .\r
- ($height ? ' height="' . $height . '"' : '') .\r
- ($attrs ? ' ' . $attrs : '') .\r
- ' preserveAspectRatio="none"/>',\r
- $params\r
- );\r
- parent::image($params);\r
- }\r
-\r
- /**\r
- * Start a group.\r
- * \r
- * What this does, depends on the canvas/format.\r
- *\r
- * @param string $name The name of the group\r
- */\r
- function startGroup($name = false)\r
- {\r
- $name = strtolower(str_replace(' ', '_', $name));\r
- if (in_array($name, $this->_groupIDs)) {\r
- $name .= $this->_id;\r
- $this->_id++;\r
- }\r
- $this->_groupIDs[] = $name;\r
- $this->_addElement('<g id="' . htmlspecialchars($name) . '">');\r
- $this->_indent .= ' '; \r
- }\r
-\r
- /**\r
- * End the "current" group.\r
- * \r
- * What this does, depends on the canvas/format.\r
- */\r
- function endGroup()\r
- {\r
- $this->_indent = substr($this->_indent, 0, -4);\r
- $this->_addElement('</g>');\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- \r
- $attrs = (isset($param['attrs']) && is_array($param['attrs'])) ? $this->_getAttributes($param['attrs']) : null;\r
- \r
- $output = $this->getData($param);\r
-\r
- header('Content-Type: image/svg+xml');\r
- header('Content-Disposition: inline; filename = "' . basename($_SERVER['PHP_SELF'], '.php') . '.svg"');\r
- print $output;\r
- }\r
-\r
- /**\r
- * Output the result of the canvas\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function save($param = false)\r
- {\r
- parent::save($param);\r
-\r
- $output = $this->getData($param);\r
- \r
- $file = fopen($param['filename'], 'w+');\r
- fwrite($file, $output);\r
- fclose($file);\r
- }\r
- \r
- \r
- /**\r
- * Get SVG data\r
- *\r
- * @param array $param Parameter array\r
- *\r
- * @return string\r
- */\r
- function getData($param = false)\r
- {\r
- $attrs = (isset($param['attrs']) && is_array($param['attrs'])) ? $this->_getAttributes($param['attrs']) : null;\r
-\r
- return '<?xml version="1.0" encoding="'. $this->_encoding . '"?>' . "\n" .\r
- '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"' . "\n\t" .\r
- ' "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">' . "\n" .\r
- '<svg width="' . $this->_width . '" height="' . $this->_height .\r
- '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"' .\r
- ($attrs ? ' ' . $attrs : '') .\r
- '>' . "\n" .\r
- ($this->_defs ?\r
- ' <defs>' . "\n" .\r
- $this->_defs .\r
- ' </defs>' . "\n" :\r
- ''\r
- ) .\r
- $this->_elements .\r
- '</svg>';\r
- }\r
- \r
- /**\r
- * Set clipping to occur\r
- * \r
- * Parameter array:\r
- * \r
- * 'x0': int X point of Upper-left corner\r
- * 'y0': int X point of Upper-left corner\r
- * 'x1': int X point of lower-right corner\r
- * 'y1': int Y point of lower-right corner\r
- */\r
- function setClipping($params = false) \r
- {\r
- if ($params === false) {\r
- $this->_addElement('</g>');\r
- } \r
- else {\r
- $group = "clipping_" . $this->_id;\r
- $this->_id++;\r
- $this->_addElement('<g clip-path="url(#' . $group . ')">');\r
- \r
- $this->_addDefine('<clipPath id="' . $group . '">');\r
- $this->_addDefine(' <path d="' .\r
- 'M' . $this->_getX($params['x0']) . ' ' . $this->_getY($params['y0']) . \r
- ' H' . $this->_getX($params['x1']) . \r
- ' V' . $this->_getY($params['y1']) . \r
- ' H' . $this->_getX($params['x0']) . \r
- ' Z"/>');\r
- $this->_addDefine('</clipPath>'); \r
- }\r
- }\r
- \r
- /**\r
- * Get a canvas specific HTML tag.\r
- * \r
- * This method implicitly saves the canvas to the filename in the \r
- * filesystem path specified and parses it as URL specified by URL path\r
- * \r
- * Parameter array:\r
- * 'filename': string\r
- * 'filepath': string Path to the file on the file system. Remember the final slash\r
- * 'urlpath': string Path to the file available through an URL. Remember the final slash\r
- * 'width': int The width in pixels\r
- * 'height': int The height in pixels\r
- */\r
- function toHtml($params)\r
- {\r
- parent::toHtml($params);\r
- return '<embed src="' . $params['urlpath'] . $params['filename'] . '" width=' . $params['width'] . ' height=' . $params['height'] . ' type="image/svg+xml">'; \r
- }\r
-\r
- /**\r
- * Converts array of attributes to string\r
- *\r
- * @param array $attrs Attributes array\r
- * @return array\r
- */\r
- function _getAttributes($attrs)\r
- { \r
- $string = '';\r
- \r
- foreach ($attrs as $key => $value) {\r
- $string .= ' ' . $key . '="' . $value . '"';\r
- }\r
- \r
- return $string;\r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for handling output in SVG format.
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: SVG.php 292672 2009-12-26 19:33:25Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas.php';
+
+/**
+ * Include file Image/Canvas/Color.php
+ */
+require_once 'Image/Canvas/Color.php';
+
+/**
+ * SVG Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_SVG extends Image_Canvas
+{
+
+ /**
+ * The SVG elements
+ * @var string
+ * @access private
+ */
+ var $_elements = '';
+
+ /**
+ * The SVG defines
+ * @var string
+ * @access private
+ */
+ var $_defs = '';
+
+ /**
+ * The current indention level
+ * @var string
+ * @access private
+ */
+ var $_indent = ' ';
+
+ /**
+ * A unieuq id counter
+ * @var int
+ * @access private
+ */
+ var $_id = 1;
+
+ /**
+ * The current group ids
+ * @var array
+ * @access private
+ */
+ var $_groupIDs = array();
+
+ /**
+ * The XML encoding (default iso-8859-1)
+ * @var string
+ * @access private
+ */
+ var $_encoding = 'iso-8859-1';
+
+ /**
+ * Create the SVG canvas.
+ *
+ * Parameters available:
+ *
+ * 'width' The width of the graph
+ *
+ * 'height' The height of the graph
+ *
+ * 'encoding' The encoding of the SVG document
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function Image_Canvas_SVG($params)
+ {
+ parent::Image_Canvas($params);
+ $this->_reset();
+
+ if (isset($params['encoding'])) {
+ $this->_encoding = $params['encoding'];
+ }
+ }
+
+ /**
+ * Add a SVG "element" to the output
+ *
+ * @param string $element The element
+ * @param array $params Parameter array (optional)
+ *
+ * @return void
+ * @access private
+ */
+ function _addElement($element, $params = array())
+ {
+ $elementdata = $this->_indent . $element . "\n";
+
+ if (isset($params['url'])) {
+ $url = $params['url'];
+ $target = (isset($params['target']) ? $params['target'] : false);
+ $alt = (isset($params['alt']) ? $params['alt'] : false);
+
+ $tags = '';
+ if (isset($params['htmltags'])) {
+ foreach ($params['htmltags'] as $key => $value) {
+ $tags .= ' ';
+ if (strpos($value, '"') >= 0) {
+ $tags .= $key . '=\'' . $value . '\'';
+ } else {
+ $tags .= $key . '="' . $value . '"';
+ }
+ }
+ }
+
+ $elementdata = $this->_indent . '<a xlink:href="' . $url . '"' . ($target ? ' target="' . $target . '"' : '') . '>' . "\n" .
+ ' ' . $elementdata .
+ $this->_indent . '</a>' . "\n";
+ }
+
+
+ $this->_elements .= $elementdata;
+ }
+
+ /**
+ * Add a SVG "define" to the output
+ *
+ * @param string $def The define
+ *
+ * @return void
+ * @access private
+ */
+ function _addDefine($def)
+ {
+ $this->_defs .= ' ' . $def . "\n";
+ }
+
+ /**
+ * Get the color index for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int A SVG compatible color
+ * @access private
+ */
+ function _color($color = false)
+ {
+ if ($color === false) {
+ return 'transparent';
+ } else {
+ $color = Image_Canvas_Color::color2RGB($color);
+ return 'rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')';
+ }
+ }
+
+ /**
+ * Get the opacity for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int A SVG compatible opacity value
+ * @access private
+ */
+ function _opacity($color = false)
+ {
+ if ($color === false) {
+ return false;
+ } else {
+ $color = Image_Canvas_Color::color2RGB($color);
+ if ($color[3] != 255) {
+ return sprintf('%0.1f', $color[3]/255);
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Get the SVG applicable linestyle
+ *
+ * @param mixed $lineStyle The line style to return, false if the one
+ * explicitly set
+ *
+ * @return mixed A SVG compatible linestyle
+ * @access private
+ */
+ function _getLineStyle($lineStyle = false)
+ {
+ $result = '';
+ if ($lineStyle === false) {
+ $lineStyle = $this->_lineStyle;
+ }
+
+ // TODO Linestyles (i.e. fx. dotted) does not work
+
+ if (($lineStyle != 'transparent') && ($lineStyle !== false)) {
+ $result = 'stroke-width:' . $this->_thickness . ';';
+ $result .= 'stroke:' .$this->_color($lineStyle) . ';';
+ if ($opacity = $this->_opacity($lineStyle)) {
+ $result .= 'stroke-opacity:' . $opacity . ';';
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Get the SVG applicable fillstyle
+ *
+ * @param mixed $fillStyle The fillstyle to return, false if the one
+ * explicitly set
+ *
+ * @return mixed A SVG compatible fillstyle
+ * @access private
+ */
+ function _getFillStyle($fillStyle = false)
+ {
+ $result = '';
+ if ($fillStyle === false) {
+ $fillStyle = $this->_fillStyle;
+ }
+
+ if (is_array($fillStyle)) {
+ if ($fillStyle['type'] == 'gradient') {
+ $id = 'gradient_' . ($this->_id++);
+ $startColor = $this->_color($fillStyle['start']);
+ $endColor = $this->_color($fillStyle['end']);
+ $startOpacity = $this->_opacity($fillStyle['start']);
+ $endOpacity = $this->_opacity($fillStyle['end']);
+
+ switch ($fillStyle['direction']) {
+ case 'horizontal':
+ case 'horizontal_mirror':
+ $x1 = '0%';
+ $y1 = '0%';
+ $x2 = '100%';
+ $y2 = '0%';
+ break;
+
+ case 'vertical':
+ case 'vertical_mirror':
+ $x1 = '0%';
+ $y1 = '100%';
+ $x2 = '0%';
+ $y2 = '0%';
+ break;
+
+ case 'diagonal_tl_br':
+ $x1 = '0%';
+ $y1 = '0%';
+ $x2 = '100%';
+ $y2 = '100%';
+ break;
+
+ case 'diagonal_bl_tr':
+ $x1 = '0%';
+ $y1 = '100%';
+ $x2 = '100%';
+ $y2 = '0%';
+ break;
+
+ case 'radial':
+ $cx = '50%';
+ $cy = '50%';
+ $r = '100%';
+ $fx = '50%';
+ $fy = '50%';
+ break;
+
+ }
+
+ if ($fillStyle['direction'] == 'radial') {
+ $this->_addDefine(
+ '<radialGradient id="' . $id . '" cx="' .
+ $cx .'" cy="' . $cy .'" r="' . $r .'" fx="' .
+ $fx .'" fy="' . $fy .'">'
+ );
+ $this->_addDefine(
+ ' <stop offset="0%" style="stop-color:' .
+ $startColor. ';' . ($startOpacity ? 'stop-opacity:' .
+ $startOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ ' <stop offset="100%" style="stop-color:' .
+ $endColor. ';' . ($endOpacity ? 'stop-opacity:' .
+ $endOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ '</radialGradient>'
+ );
+ } elseif (($fillStyle['direction'] == 'vertical_mirror')
+ || ($fillStyle['direction'] == 'horizontal_mirror')
+ ) {
+ $this->_addDefine(
+ '<linearGradient id="' . $id . '" x1="' .
+ $x1 .'" y1="' . $y1 .'" x2="' . $x2 .'" y2="' .
+ $y2 .'">'
+ );
+ $this->_addDefine(
+ ' <stop offset="0%" style="stop-color:' .
+ $startColor. ';' . ($startOpacity ? 'stop-opacity:' .
+ $startOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ ' <stop offset="50%" style="stop-color:' .
+ $endColor. ';' . ($endOpacity ? 'stop-opacity:' .
+ $endOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ ' <stop offset="100%" style="stop-color:' .
+ $startColor. ';' . ($startOpacity ? 'stop-opacity:' .
+ $startOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ '</linearGradient>'
+ );
+ } else {
+ $this->_addDefine(
+ '<linearGradient id="' . $id . '" x1="' .
+ $x1 .'" y1="' . $y1 .'" x2="' . $x2 .'" y2="' .
+ $y2 .'">'
+ );
+ $this->_addDefine(
+ ' <stop offset="0%" style="stop-color:' .
+ $startColor. ';' . ($startOpacity ? 'stop-opacity:' .
+ $startOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ ' <stop offset="100%" style="stop-color:' .
+ $endColor. ';' . ($endOpacity ? 'stop-opacity:' .
+ $endOpacity . ';' : ''). '"/>'
+ );
+ $this->_addDefine(
+ '</linearGradient>'
+ );
+ }
+
+ return 'fill:url(#' . $id . ');';
+ }
+ } elseif (($fillStyle != 'transparent') && ($fillStyle !== false)) {
+ $result = 'fill:' . $this->_color($fillStyle) . ';';
+ if ($opacity = $this->_opacity($fillStyle)) {
+ $result .= 'fill-opacity:' . $opacity . ';';
+ }
+ return $result;
+ } else {
+ return 'fill:none;';
+ }
+ }
+
+ /**
+ * Sets an image that should be used for filling
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ }
+
+ /**
+ * Sets a gradient fill
+ *
+ * @param array $gradient Gradient fill options
+ *
+ * @return void
+ */
+ function setGradientFill($gradient)
+ {
+ $this->_fillStyle = $gradient;
+ $this->_fillStyle['type'] = 'gradient';
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ * 'type' = 'ttf' (TrueType) or omitted for default<br>
+ * If 'type' = 'ttf' then the following can be specified<br>
+ * 'size' = size in pixels<br>
+ * 'angle' = the angle with which to write the text
+ * 'file' = the .ttf file (either the basename, filename or full path)
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ parent::setFont($fontOptions);
+ if (!isset($this->_font['size'])) {
+ $this->_font['size'] = 10;
+ }
+ }
+
+ /**
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+ $color = (isset($params['color']) ? $params['color'] : false);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $style = $this->_getLineStyle($color) . $this->_getFillStyle('transparent');
+ if ($style != '') {
+ $this->_addElement(
+ '<line ' .
+ 'x1="' . round($x0) . '" ' .
+ 'y1="' . round($y0) . '" ' .
+ 'x2="' . round($x1) . '" ' .
+ 'y2="' . round($y1) . '" ' .
+ 'style="' . $style . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '/>',
+ $params
+ );
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params = array())
+ {
+ $connectEnds = (isset($params['connect']) ? $params['connect'] : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ if (!$connectEnds) {
+ $fillColor = 'transparent';
+ }
+ $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $first = true;
+ $spline = false;
+ $lastpoint = false;
+ foreach ($this->_polygon as $point) {
+ if ($first) {
+ $points = 'M';
+ } elseif (!$spline) {
+ $points .= ' L';
+ }
+
+ if (($spline) && ($lastpoint !== false)) {
+ $points .= ' ' .round($lastpoint['P1X']) . ',' . round($lastpoint['P1Y']) . ' ' .
+ round($lastpoint['P2X']) . ',' . round($lastpoint['P2Y']);
+ }
+
+ $points .= ' ' . round($point['X']) . ',' . round($point['Y']);
+
+ if ((isset($point['P1X'])) && (isset($point['P1Y']))
+ && (isset($point['P2X'])) && (isset($point['P2Y']))
+ ) {
+ if (($first) || (!$spline)) {
+ $points .= ' C';
+ }
+ $lastpoint = $point;
+ $spline = true;
+ } else {
+ $spline = false;
+ }
+ $first = false;
+ }
+ if ($connectEnds) {
+ $points .= ' Z';
+ }
+ $this->_addElement(
+ '<path ' .
+ 'd="' . $points . '" ' .
+ 'style="' . $style . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '/>',
+ $params
+ );
+
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $x0 = min($this->_getX($params['x0']), $this->_getX($params['x1']));
+ $y0 = min($this->_getY($params['y0']), $this->_getY($params['y1']));
+ $x1 = max($this->_getX($params['x0']), $this->_getX($params['x1']));
+ $y1 = max($this->_getY($params['y0']), $this->_getY($params['y1']));
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);
+ if ($style != '') {
+ $this->_addElement(
+ '<rect ' .
+ 'x="' . round($x0) . '" ' .
+ 'y="' . round($y0) . '" ' .
+ 'width="' . round(abs($x1 - $x0)) . '" ' .
+ 'height="' . round(abs($y1 - $y0)) . '" ' .
+ 'style="' . $style . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '/>',
+ $params
+ );
+ }
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);
+ if ($style != '') {
+ $this->_addElement(
+ '<ellipse ' .
+ 'cx="' . round($x) . '" ' .
+ 'cy="' . round($y) . '" ' .
+ 'rx="' . round($rx) . '" ' .
+ 'ry="' . round($ry) . '" ' .
+ 'style="' . $style . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '/>',
+ $params
+ );
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+ $v1 = $this->_getX($params['v1']);
+ $v2 = $this->_getY($params['v2']);
+ $srx = (isset($params['srx']) ? $this->_getX($params['srx']) : false);
+ $sry = (isset($params['sry']) ? $this->_getX($params['sry']) : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $dv = max($v2, $v1) - min($v2, $v1);
+ if ($dv >= 360) {
+ $this->ellipse($params);
+ } else {
+ $style = $this->_getLineStyle($lineColor) . $this->_getFillStyle($fillColor);
+ if ($style != '') {
+ $x1 = ($x + $rx * cos(deg2rad(min($v1, $v2) % 360)));
+ $y1 = ($y + $ry * sin(deg2rad(min($v1, $v2) % 360)));
+ $x2 = ($x + $rx * cos(deg2rad(max($v1, $v2) % 360)));
+ $y2 = ($y + $ry * sin(deg2rad(max($v1, $v2) % 360)));
+ $this->_addElement(
+ '<path d="' .
+ 'M' . round($x) . ',' . round($y) . ' ' .
+ 'L' . round($x1) . ',' . round($y1) . ' ' .
+ 'A' . round($rx) . ',' . round($ry) . ($dv > 180 ? ' 0 1,1 ' : ' 0 0,1 ') .
+ round($x2) . ',' . round($y2) . ' ' .
+ 'Z" ' .
+ 'style="' . $style . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '/>',
+ $params
+ );
+ }
+
+ parent::pieslice($params);
+ }
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ return $this->_font['size'] * count(explode("\n",$text));
+ } else {
+ return round($this->_font['size'] * 0.7 * strlen($text));
+ }
+ }
+
+ /**
+ * Get the height of a text,
+ *
+ * @param string $text The text to get the height of
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text)
+ {
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ return round($this->_font['size'] * 0.7 * strlen($text));
+ } else {
+ return $this->_font['size'] * count(explode("\n",$text));
+ }
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x': int X-point of text
+ * 'y': int Y-point of text
+ * 'text': string The text to add
+ * 'alignment': array [optional] Alignment
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $text = $params['text'];
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ $textHeight = $this->textHeight($text);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ $align = '';
+
+ if ((isset($this->_font['vertical'])) && ($this->_font['vertical'])) {
+ // $align .= 'writing-mode: tb-rl;';
+
+ if ($alignment['vertical'] == 'bottom') {
+ $align .= 'text-anchor:end;';
+ //$y = $y + $textHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ //$y = $y + ($textHeight / 2);
+ $align .= 'text-anchor:middle;';
+ }
+ } else {
+ if ($alignment['horizontal'] == 'right') {
+ $align .= 'text-anchor:end;';
+ } elseif ($alignment['horizontal'] == 'center') {
+ $align .= 'text-anchor:middle;';
+ }
+
+ if ($alignment['vertical'] == 'top') {
+ $y = $y + $textHeight;
+ } elseif ($alignment['vertical'] == 'center') {
+ $y = $y + ($textHeight / 2);
+ }
+ }
+
+ if (($color === false) && (isset($this->_font['color']))) {
+ $color = $this->_font['color'];
+ }
+
+ $textColor = $this->_color($color);
+ $textOpacity = $this->_opacity($color);
+
+ $this->_addElement(
+ '<g transform="translate(' . round($x) . ', ' . round($y) . ')">' . "\n" .
+ $this->_indent . ' <text ' .
+ 'x="0" ' .
+ 'y="0" ' .
+ (isset($this->_font['angle']) && ($this->_font['angle'] > 0) ?
+ 'transform="rotate(' . (((-1) * $this->_font['angle']) % 360) . ')" ' :
+ ''
+ ) .
+ 'style="' .
+ (isset($this->_font['name']) ?
+ 'font-family:' . $this->_font['name'] . ';' : '') .
+ 'font-size:' . $this->_font['size'] . 'px;fill:' .
+ $textColor . ($textOpacity ? ';fill-opacity:' .
+ $textOpacity :
+ ''
+ ) . ';' . $align . '"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '>' .
+ ('<tspan x="0" dy="0em">'. implode('</tspan><tspan x="0" dy="1em">', explode("\n",htmlspecialchars($text))).'</tspan>') .
+ '</text>' . "\n" .
+ $this->_indent . '</g>',
+ $params
+ );
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x': int X-point of overlayed image
+ * 'y': int Y-point of overlayed image
+ * 'filename': string The filename of the image to overlay
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $filename = $params['filename'];
+
+ $attrs = (isset($params['attrs']) && is_array($params['attrs'])) ? $this->_getAttributes($params['attrs']) : null;
+
+ list($width, $height, $type, $attr) = getimagesize($filename);
+ $width = (isset($params['width']) ? $params['width'] : $width);
+ $height = (isset($params['height']) ? $params['height'] : $height);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ $file = fopen($filename, 'rb');
+ $filedata = fread($file, filesize($filename));
+ fclose($file);
+
+ $data = 'data:' . image_type_to_mime_type($type) . ';base64,' . base64_encode($filedata);
+
+ $this->_addElement(
+ '<image xlink:href="' . $data . '" x="' . $x . '" y="' . $y . '"' .
+ ($width ? ' width="' . $width . '"' : '') .
+ ($height ? ' height="' . $height . '"' : '') .
+ ($attrs ? ' ' . $attrs : '') .
+ ' preserveAspectRatio="none"/>',
+ $params
+ );
+ parent::image($params);
+ }
+
+ /**
+ * Start a group.
+ *
+ * What this does, depends on the canvas/format.
+ *
+ * @param string $name The name of the group
+ *
+ * @return void
+ */
+ function startGroup($name = false)
+ {
+ $name = strtolower(str_replace(' ', '_', $name));
+ if (in_array($name, $this->_groupIDs)) {
+ $name .= $this->_id;
+ $this->_id++;
+ }
+ $this->_groupIDs[] = $name;
+ $this->_addElement('<g id="' . htmlspecialchars($name) . '">');
+ $this->_indent .= ' ';
+ }
+
+ /**
+ * End the "current" group.
+ *
+ * What this does, depends on the canvas/format.
+ *
+ * @return void
+ */
+ function endGroup()
+ {
+ $this->_indent = substr($this->_indent, 0, -4);
+ $this->_addElement('</g>');
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+
+ $attrs = (isset($param['attrs']) && is_array($param['attrs'])) ? $this->_getAttributes($param['attrs']) : null;
+
+ $output = $this->getData($param);
+
+ header('Content-Type: image/svg+xml');
+ header('Content-Disposition: inline; filename = "' . basename($_SERVER['PHP_SELF'], '.php') . '.svg"');
+ print $output;
+ }
+
+ /**
+ * Output the result of the canvas
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ */
+ function save($param = false)
+ {
+ parent::save($param);
+
+ $output = $this->getData($param);
+
+ $file = fopen($param['filename'], 'w+');
+ fwrite($file, $output);
+ fclose($file);
+ }
+
+
+ /**
+ * Get SVG data
+ *
+ * @param array $param Parameter array
+ *
+ * @return string
+ */
+ function getData($param = false)
+ {
+ $attrs = (isset($param['attrs']) && is_array($param['attrs'])) ? $this->_getAttributes($param['attrs']) : null;
+
+ return '<?xml version="1.0" encoding="'. $this->_encoding . '"?>' . "\n" .
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"' . "\n\t" .
+ ' "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">' . "\n" .
+ '<svg width="' . $this->_width . '" height="' . $this->_height .
+ '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"' .
+ ($attrs ? ' ' . $attrs : '') .
+ '>' . "\n" .
+ ($this->_defs ?
+ ' <defs>' . "\n" .
+ $this->_defs .
+ ' </defs>' . "\n" :
+ ''
+ ) .
+ $this->_elements .
+ '</svg>';
+ }
+
+ /**
+ * Set clipping to occur
+ *
+ * Parameter array:
+ *
+ * 'x0': int X point of Upper-left corner
+ * 'y0': int X point of Upper-left corner
+ * 'x1': int X point of lower-right corner
+ * 'y1': int Y point of lower-right corner
+ *
+ * @param array $params Parameter array (x0, y0, x1, y1)
+ *
+ * @return void
+ */
+ function setClipping($params = false)
+ {
+ if ($params === false) {
+ $this->_addElement('</g>');
+ } else {
+ $group = "clipping_" . $this->_id;
+ $this->_id++;
+ $this->_addElement('<g clip-path="url(#' . $group . ')">');
+
+ $this->_addDefine('<clipPath id="' . $group . '">');
+ $this->_addDefine(
+ ' <path d="' .
+ 'M' . $this->_getX($params['x0']) . ' ' . $this->_getY($params['y0']) .
+ ' H' . $this->_getX($params['x1']) .
+ ' V' . $this->_getY($params['y1']) .
+ ' H' . $this->_getX($params['x0']) .
+ ' Z"/>'
+ );
+ $this->_addDefine('</clipPath>');
+ }
+ }
+
+ /**
+ * Get a canvas specific HTML tag.
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ * 'filename': string
+ * 'filepath': string Path to the file on the file system. Remember the final slash
+ * 'urlpath': string Path to the file available through an URL. Remember the final slash
+ * 'width': int The width in pixels
+ * 'height': int The height in pixels
+ *
+ * @param array $params Parameter array
+ *
+ * @return string HTML code
+ */
+ function toHtml($params)
+ {
+ parent::toHtml($params);
+ return '<embed src="' . $params['urlpath'] . $params['filename'] . '" width=' . $params['width'] . ' height=' . $params['height'] . ' type="image/svg+xml">';
+ }
+
+ /**
+ * Converts array of attributes to string
+ *
+ * @param array $attrs Attributes array
+ *
+ * @return array
+ */
+ function _getAttributes($attrs)
+ {
+ $string = '';
+
+ foreach ($attrs as $key => $value) {
+ $string .= ' ' . $key . '="' . $value . '"';
+ }
+
+ return $string;
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for handling output in SWF flash format.\r
- *\r
- * Requires PHP extension ming\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Torsten Roehr <troehr@php.net>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: SWF.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas.php';\r
-\r
-/**\r
- * Include file Image/Canvas/Color.php\r
- */\r
-require_once 'Image/Canvas/Color.php';\r
-\r
-/**\r
- * SVG Canvas class.\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Torsten Roehr <troehr@php.net>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-class Image_Canvas_SWF extends Image_Canvas\r
-{\r
-\r
- /**\r
- * The canvas of the graph\r
- * @var object SWFMovie\r
- * @access private\r
- */\r
- var $_canvas;\r
-\r
- /**\r
- * The default Flash version\r
- *\r
- * Ming supports up to Flash version 6\r
- *\r
- * @var int\r
- * @access private\r
- */\r
- var $_version = 6;\r
-\r
- /**\r
- * Creates the SWF movie object\r
- *\r
- * Parameters available:\r
- *\r
- * 'width' The width of the graph\r
- * 'height' The height of the graph\r
- * 'version' The flash version, supports up to version 6\r
- * 'background' An array with the background color, e.g.\r
- * array('red' => 255,\r
- * 'green' => 0,\r
- * 'blue' => 0)\r
- * Either integers between 0 and 255 or hexadecimals\r
- * between 0x00 and 0xFF\r
- *\r
- * @param array $param Parameter array\r
- * @return Image_Canvas_SWF\r
- */\r
- function Image_Canvas_SWF($params)\r
- {\r
- parent::Image_Canvas($params);\r
- $this->_reset();\r
-\r
- $version = (isset($params['version']) && $params['version'] <= 6)\r
- ? $params['version'] : $this->_version;\r
-\r
- $this->_canvas = new SWFMovie($version);\r
- $this->_canvas->setDimension($this->_width, $this->_height);\r
-\r
- if (isset($params['background'])) {\r
- $this->setBackground($params['background']);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the background color\r
- *\r
- * Values can be specified either as integers between 0 and 255 or as hexadecimals between 0x00 and 0xFF\r
- *\r
- * @param mixed $color Color\r
- * @access public\r
- * @return void\r
- */\r
- function setBackground($color)\r
- {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- $this->_canvas->setBackground($color[0], $color[1], $color[2]);\r
- }\r
-\r
- /**\r
- * Add an object to the movie\r
- *\r
- * @param string $element The element\r
- * @access public\r
- */\r
- function addElement($element)\r
- {\r
- $this->_canvas->add($element);\r
- }\r
-\r
- /**\r
- * Get the color index for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int A SVG compatible color\r
- * @access private\r
- */\r
- function _color($color = false)\r
- {\r
- if ($color === false) {\r
- return array();\r
- } else {\r
- return Image_Canvas_Color::color2RGB($color);\r
- }\r
- }\r
-\r
- /**\r
- * Get the opacity for the RGB color\r
- *\r
- * @param int $color The color\r
- * @return int A SWF compatible opacity value\r
- * @access private\r
- */\r
- function _opacity($color = false)\r
- {\r
- if ($color === false) {\r
- return false;\r
- } else {\r
- $color = Image_Canvas_Color::color2RGB($color);\r
- if ($color[3] != 255) {\r
- return sprintf('%0.1f', $color[3]/255);\r
- } else {\r
- return 255;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get the applicable linestyle\r
- *\r
- * @param mixed $lineStyle The line style to return, false if the one\r
- * explicitly set\r
- * @return mixed A compatible linestyle\r
- * @access private\r
- */\r
- function _getLineStyle($lineStyle = false)\r
- {\r
- if ($lineStyle === false) {\r
- $lineStyle = $this->_lineStyle;\r
- }\r
-\r
- return $this->_color($lineStyle);\r
- }\r
-\r
- /**\r
- * Get the applicable fillstyle\r
- *\r
- * @param mixed $fillStyle The fillstyle to return, false if the one\r
- * explicitly set\r
- * @return mixed A compatible fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($fillStyle = false)\r
- {\r
- if ($fillStyle === false) {\r
- $fillStyle = $this->_fillStyle;\r
- }\r
-\r
- return $this->_color($fillStyle);\r
- }\r
-\r
- /**\r
- * Sets an image that should be used for filling\r
- *\r
- * @todo\r
- * @param string $filename The filename of the image to fill with\r
- */\r
- function setFillImage($filename)\r
- {\r
- }\r
-\r
- /**\r
- * Sets a gradient fill\r
- *\r
- * @todo\r
- * @param array $gradient Gradient fill options\r
- */\r
- function setGradientFill($gradient)\r
- {\r
- }\r
-\r
- /**\r
- * Sets the font options.\r
- *\r
- * The $font array may have the following entries:\r
- * 'type' : 'ttf' (TrueType) or omitted for default<br>\r
- * If 'type' is 'ttf' then the following can be specified<br>\r
- * 'size' : size in pixels<br>\r
- * 'angle' : the angle with which to write the text\r
- * 'file' : the .ttf file (either the basename, filename or full path)\r
- *\r
- * @param array $font The font options.\r
- */\r
- function setFont($fontOptions)\r
- {\r
- parent::setFont($fontOptions);\r
- if (!isset($this->_font['size'])) {\r
- $this->_font['size'] = 10;\r
- }\r
- }\r
-\r
- /**\r
- * Draw a line end\r
- *\r
- * Parameter array:\r
- * 'x' : int X point\r
- * 'y' : int Y point\r
- * 'end' : string The end type of the end\r
- * 'size' : int The size of the end\r
- * 'color' : string The color of the end\r
- * 'angle' : int [optional] The angle with which to draw the end\r
- * 'url' : string [optional] Target URL\r
- *\r
- * @param array $params Parameter array\r
- */\r
- function drawEnd($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $size = $params['size'];\r
- $angle = deg2rad((isset($params['angle']) ? $params['angle'] : 0));\r
- $pi2 = pi() / 2;\r
-\r
- switch ($params['end']) {\r
-\r
- case 'lollipop':\r
- case 'circle':\r
- if (($fill = $this->_getFillStyle($params['color'])) !== false) {\r
- $shapeObj = new SWFShape();\r
- $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);\r
- $shapeObj->movePenTo($x + $size / 2, $y);\r
- $shapeObj->drawCircle($size / 2);\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $this->_canvas->add($button);\r
- } else {\r
- $this->_canvas->add($shapeObj);\r
- }\r
-\r
- parent::drawEnd($params);\r
- }\r
- break;\r
-\r
- case 'diamond':\r
- $x0 = round($params['x'] + cos($angle) * $size * 0.65);\r
- $y0 = round($params['y'] - sin($angle) * $size * 0.65);\r
- $shape = array(\r
- array($x0 + round(cos($angle) * $size * 0.65),\r
- $y0 - round(sin($angle) * $size * 0.65)),\r
- array($x0 + round(cos($angle + $pi2) * $size * 0.65),\r
- $y0 - round(sin($angle + $pi2) * $size * 0.65)),\r
- array($x0 + round(cos($angle + pi()) * $size * 0.65),\r
- $y0 - round(sin($angle + pi()) * $size * 0.65)),\r
- array($x0 + round(cos($angle + 3 * $pi2) * $size * 0.65),\r
- $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65))\r
- );\r
- break;\r
-\r
- case 'line':\r
- $shape = array(\r
- array($x + round(cos($angle + $pi2) * $size / 2),\r
- $y - round(sin($angle + $pi2) * $size / 2)),\r
- array($x + round(cos($angle + 3 * $pi2) * $size / 2),\r
- $y - round(sin($angle + 3 * $pi2) * $size / 2))\r
- );\r
- break;\r
-\r
- case 'box':\r
- case 'rectangle':\r
- $x0 = round($params['x'] + cos($angle) * $size / 2);\r
- $y0 = round($params['y'] - sin($angle) * $size / 2);\r
- $pi4 = pi() / 4;\r
- $shape = array(\r
- array($x0 + round(cos($angle + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + $pi4) * $size / 2)),\r
- array($x0 + round(cos($angle + $pi2 + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2)),\r
- array($x0 + round(cos($angle + pi() + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + pi() + $pi4) * $size / 2)),\r
- array($x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2),\r
- $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2))\r
- );\r
- break;\r
-\r
- case 'arrow':\r
- $shape = array(\r
- array($x + cos($angle) * $size,\r
- $y - sin($angle) * $size),\r
- array($x + cos($angle + $pi2) * $size * 0.4,\r
- $y - sin($angle + $pi2) * $size * 0.4),\r
- array($x + cos($angle + 3 * $pi2) * $size * 0.4,\r
- $y - sin($angle + 3 * $pi2) * $size * 0.4)\r
- );\r
- break;\r
-\r
- case 'arrow2':\r
- $shape = array(\r
- array($x + round(cos($angle) * $size),\r
- $y - round(sin($angle) * $size)),\r
- array($x + round(cos($angle + $pi2 + deg2rad(45)) * $size),\r
- $y - round(sin($angle + $pi2 + deg2rad(45)) * $size)),\r
- array($x,\r
- $y),\r
- array($x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size),\r
- $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size))\r
- );\r
- break;\r
- }\r
-\r
- if (isset($shape)) {\r
- // output the shape\r
- if (($fill = $this->_getFillStyle($params['color'])) !== false) {\r
- $shapeObj = new SWFShape();\r
- $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);\r
- $shapeObj->setLine(0, $fill[0], $fill[1], $fill[2]);\r
- $shapeObj->movePenTo($shape[0][0], $shape[0][1]);\r
- for ($count = count($shape); $count--; $count > 0) {\r
- $shapeObj->drawLineTo($shape[$count][0], $shape[$count][1]);\r
- }\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $this->_canvas->add($button);\r
- } else {\r
- $this->_canvas->add($shapeObj);\r
- }\r
- }\r
- }\r
- parent::drawEnd($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'x0' : int X start point\r
- * 'y0' : int Y start point\r
- * 'x1' : int X end point\r
- * 'y1' : int Y end point\r
- * 'color' : mixed [optional] The line color\r
- * 'url' : string [optional] Target URL\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- $x0 = $this->_getX($params['x0']);\r
- $y0 = $this->_getY($params['y0']);\r
- $x1 = $this->_getX($params['x1']);\r
- $y1 = $this->_getY($params['y1']);\r
-\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $color = $this->_getLineStyle($color);\r
-\r
- $shape = new SWFShape();\r
- $shape->setLine(1, $color[0], $color[1], $color[2]);\r
-\r
- $shape->movePenTo($x0, $y0);\r
- $shape->drawLine($x1 - $x0, $y1 - $y0);\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $this->_canvas->add($button);\r
- } else {\r
- $this->_canvas->add($shape);\r
- }\r
-\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon)\r
- * or not (connected line)\r
- * 'fill' : mixed [optional] The fill color\r
- * 'line' : mixed [optional] The line color\r
- * 'url' : string [optional] Target URL\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params = array())\r
- {\r
- $connectEnds = (isset($params['connect']) ? $params['connect'] : false);\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $lineStyle = $this->_getLineStyle($lineColor);\r
- $fillStyle = $this->_getFillStyle($fillColor);\r
-\r
- $shape = new SWFShape();\r
- if ($connectEnds) {\r
- $shape->setRightFill($fillStyle[0], $fillStyle[1], $fillStyle[2]);\r
- }\r
- $shape->setLine(0, $lineStyle[0], $lineStyle[1], $lineStyle[2]);\r
- $shape->movePenTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']);\r
-\r
- foreach ($this->_polygon as $point) {\r
- $shape->drawLineTo($point['X'], $point['Y']);\r
- }\r
-\r
- if ($connectEnds) {\r
- $shape->drawLineTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']);\r
- }\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $this->_canvas->add($button);\r
- } else {\r
- $this->_canvas->add($shape);\r
- }\r
-\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0' : int X start point\r
- * 'y0' : int Y start point\r
- * 'x1' : int X end point\r
- * 'y1' : int Y end point\r
- * 'fill' : The fill style\r
- * 'line' : The line style\r
- * 'url' : string [optional] Target URL\r
- *\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- $x0 = min($this->_getX($params['x0']), $this->_getX($params['x1']));\r
- $y0 = min($this->_getY($params['y0']), $this->_getY($params['y1']));\r
- $x1 = max($this->_getX($params['x0']), $this->_getX($params['x1']));\r
- $y1 = max($this->_getY($params['y0']), $this->_getY($params['y1']));\r
-\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $fillColor = $this->_getFillStyle($fillColor);\r
- $lineColor = $this->_getLineStyle($lineColor);\r
-\r
- // use fill color if no line color is set or transparent\r
- if (count($lineColor) === 0) {\r
- $lineColor = $fillColor;\r
- }\r
-\r
- $shape = new SWFShape();\r
- $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]);\r
-\r
- if (count($fillColor)) {\r
- $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);\r
- }\r
-\r
- $shape->movePenTo($x0, $y0);\r
- $shape->drawLine($x1 - $x0, 0);\r
- $shape->drawLine(0, $y1 - $y0);\r
- $shape->drawLine($x0 - $x1, 0);\r
- $shape->drawLine(0, $y0 - $y1);\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $this->_canvas->add($button);\r
- } else {\r
- $this->_canvas->add($shape);\r
- }\r
-\r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x' : int X center point\r
- * 'y' : int Y center point\r
- * 'rx' : int X radius\r
- * 'ry' : int Y radius\r
- * 'fill' : mixed [optional] The fill color\r
- * 'line' : mixed [optional] The line color\r
- * 'url' : string [optional] Target URL\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- $x = $this->_getX($params['x']);\r
- $y = $this->_getY($params['y']);\r
- $rx = $this->_getX($params['rx']);\r
- $ry = $this->_getY($params['ry']);\r
-\r
- // calculate scale factors\r
- $scaleX = 1.0;\r
- $scaleY = 1.0;\r
- $moveX = 0;\r
- $moveY = 0;\r
-\r
- if ($rx > $ry) {\r
- $scaleY = $ry / $rx;\r
- $moveY = $ry * (1 - $scaleY);\r
- } elseif ($rx < $ry) {\r
- $scaleX = $rx / $ry;\r
- $moveX = $rx * (1 - $scaleX);\r
- }\r
-\r
- $fillColor = (isset($params['fill']) ? $params['fill'] : false);\r
- $lineColor = (isset($params['line']) ? $params['line'] : false);\r
-\r
- $fillColor = $this->_getFillStyle($fillColor);\r
- $lineColor = $this->_getLineStyle($lineColor);\r
-\r
- $shape = new SWFShape();\r
- $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);\r
- $shape->movePenTo($x, $y);\r
- $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]);\r
-\r
- if (count($fillColor)) {\r
- $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);\r
- }\r
-\r
- $shape->drawCircle(max($rx, $ry));\r
-\r
- if (isset($params['url'])) {\r
- $button = new SWFButton();\r
- $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);\r
- $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);\r
- $ellipse = $this->_canvas->add($button);\r
- } else {\r
- $ellipse = $this->_canvas->add($shape);\r
- }\r
-\r
- $ellipse->move($moveX, $moveY);\r
- $ellipse->scaleTo($scaleX, $scaleY);\r
-\r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x' : int X center point\r
- * 'y' : int Y center point\r
- * 'rx' : int X radius\r
- * 'ry' : int Y radius\r
- * 'v1' : int The starting angle (in degrees)\r
- * 'v2' : int The end angle (in degrees)\r
- * 'srx' : int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry' : int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill' : mixed [optional] The fill color\r
- * 'line' : mixed [optional] The line color\r
- * @param array $params Parameter array\r
- * @todo\r
- */\r
- function pieslice($params)\r
- {\r
- }\r
-\r
- /**\r
- * Get the width of a text,\r
- *\r
- * @param string $text The text to get the width of\r
- * @return int The width of the text\r
- */\r
- function textWidth($text)\r
- {\r
- if (isset($this->_font['vertical']) && $this->_font['vertical']) {\r
- return $this->_font['size'];\r
- } else {\r
- return round($this->_font['size'] * 0.5 * strlen($text));\r
- }\r
- }\r
-\r
- /**\r
- * Get the height of a text,\r
- *\r
- * @param string $text The text to get the height of\r
- * @return int The height of the text\r
- */\r
- function textHeight($text)\r
- {\r
- if (isset($this->_font['vertical']) && $this->_font['vertical']) {\r
- return round($this->_font['size'] * 0.7 * strlen($text));\r
- } else {\r
- return $this->_font['size'];\r
- }\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x' : int X-point of text\r
- * 'y' : int Y-point of text\r
- * 'text' : string The text to add\r
- * 'color' : mixed [optional] The color of the text\r
- *\r
- * @todo Vertical alignment\r
- */\r
- function addText($params)\r
- {\r
- $x0 = $this->_getX($params['x']);\r
- $y0 = $this->_getY($params['y']);\r
- $text = str_replace("\r", '', $params['text']);\r
- $color = (isset($params['color']) ? $params['color'] : false);\r
- $textHeight = $this->textHeight($text);\r
- $alignment = (isset($params['alignment']) ? $params['alignment'] : false);\r
-\r
- if (!is_array($alignment)) {\r
- $alignment = array('vertical' => 'top', 'horizontal' => 'left');\r
- }\r
-\r
- if (!isset($alignment['vertical'])) {\r
- $alignment['vertical'] = 'top';\r
- }\r
-\r
- if (!isset($alignment['horizontal'])) {\r
- $alignment['horizontal'] = 'left';\r
- }\r
-\r
- if (($color === false) && (isset($this->_font['color']))) {\r
- $color = $this->_font['color'];\r
- }\r
-\r
- if ($color == 'transparent') {\r
- return;\r
- }\r
-\r
- if (strpos($this->_font['file'], '.') === false) {\r
- $this->_font['file'] = IMAGE_CANVAS_SYSTEM_FONT_PATH . $this->_font['file'] . '.fdb';\r
- }\r
-\r
- $textColor = $this->_color($color);\r
- $textOpacity = $this->_opacity($color);\r
-\r
- $lines = explode("\n", $text);\r
- foreach ($lines as $line) {\r
-\r
- $x = $x0;\r
- $y = $y0;\r
-\r
- $y0 += $textHeight + 2;\r
-\r
- $width = $this->textWidth($line);\r
- $height = $this->textHeight($line);\r
-\r
- if ($alignment['horizontal'] == 'right') {\r
- $x -= $width;\r
- } else if ($alignment['horizontal'] == 'center') {\r
- $x -= $width / 2;\r
- }\r
-\r
- $font = new SWFFont($this->_font['file']);\r
- $text = new SWFText();\r
- $text->setFont($font);\r
- $text->moveTo($x, $y + $this->_font['size']);\r
- $text->setColor($textColor[0], $textColor[1], $textColor[2], $textOpacity);\r
- $text->setHeight($this->_font['size']);\r
- $text->addString($line);\r
- $this->_canvas->add($text);\r
- }\r
-\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x' : int X-point of overlayed image\r
- * 'y' : int Y-point of overlayed image\r
- * 'filename' : string The filename of the image to overlay\r
- * 'width' : int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height' : int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment' : array [optional] Alignment\r
- * 'url' : string [optional] Target URL\r
- */\r
- function image($params)\r
- {\r
- parent::image($params);\r
- }\r
-\r
- /**\r
- * Display the SWF\r
- *\r
- * @param array $param Parameter array\r
- */\r
- function show($param = false)\r
- {\r
- parent::show($param);\r
- $this->_canvas->output();\r
- }\r
-\r
- /**\r
- * Save the SWF to a file\r
- *\r
- * @param array $param Parameter array\r
- * array('filename' => 'canvas.swf',\r
- * 'compression' => 0)\r
- *\r
- * The compression level can be a value between 0 and 9,\r
- * defining the SWF compression similar to gzip compression.\r
- * This parameter is only available as of Flash MX (6).\r
- */\r
- function save($param = false)\r
- {\r
- if (!isset($param['compression'])) {\r
- $param['compression'] = 0;\r
- }\r
-\r
- parent::save($param);\r
- $this->_canvas->save($param['filename'], $param['compression']);\r
- }\r
-\r
- /**\r
- * Get SWF movie object\r
- *\r
- * @return object\r
- */\r
- function getData()\r
- {\r
- return $this->_canvas;\r
- }\r
-\r
- /**\r
- * Set clipping to occur\r
- *\r
- * Parameter array:\r
- *\r
- * 'x0' : int X point of Upper-left corner\r
- * 'y0' : int X point of Upper-left corner\r
- * 'x1' : int X point of lower-right corner\r
- * 'y1' : int Y point of lower-right corner\r
- *\r
- * @todo\r
- */\r
- function setClipping($params = false)\r
- {\r
- }\r
-\r
- /**\r
- * Get an SWF specific HTML tag\r
- *\r
- * This method implicitly saves the canvas to the filename in the\r
- * filesystem path specified and parses it as URL specified by URL path\r
- *\r
- * Parameter array:\r
- * 'filename' : string\r
- * 'filepath' : string Path to the file on the file system. Remember the final slash\r
- * 'urlpath' : string Path to the file available through an URL. Remember the final slash\r
- * 'width' : int The width in pixels\r
- * 'height' : int The height in pixels\r
- * 'quality' : Flash quality\r
- * 'scale' : Scale\r
- * 'menu' : Whether to display the Flash menu on mouse right-click\r
- */\r
- function toHtml($params)\r
- {\r
- parent::toHtml($params);\r
- return '<object data="' . $params['urlpath'] . $params['filename'] . '" type="application/x-shockwave-flash" width="' . $params['width'] . '" height="' . $params['height'] . '">\r
- <param name="movie" value="' . $params['urlpath'] . $params['filename'] . '">\r
- <param name="quality" value="' . $params['quality'] . '">\r
- <param name="scale" value="' . $params['scale'] . '">\r
- <param name="menu" value="' . $params['menu'] . '">\r
- </object>';\r
- }\r
-}\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for handling output in SWF flash format.
+ *
+ * Requires PHP extension ming
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Torsten Roehr <troehr@php.net>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: SWF.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas.php';
+
+/**
+ * Include file Image/Canvas/Color.php
+ */
+require_once 'Image/Canvas/Color.php';
+
+/**
+ * SVG Canvas class.
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Torsten Roehr <troehr@php.net>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+class Image_Canvas_SWF extends Image_Canvas
+{
+
+ /**
+ * The canvas of the graph
+ * @var object SWFMovie
+ * @access private
+ */
+ var $_canvas;
+
+ /**
+ * The default Flash version
+ *
+ * Ming supports up to Flash version 6
+ *
+ * @var int
+ * @access private
+ */
+ var $_version = 6;
+
+ /**
+ * Creates the SWF movie object
+ *
+ * Parameters available:
+ *
+ * 'width' The width of the graph
+ * 'height' The height of the graph
+ * 'version' The flash version, supports up to version 6
+ * 'background' An array with the background color, e.g.
+ * array('red' => 255,
+ * 'green' => 0,
+ * 'blue' => 0)
+ * Either integers between 0 and 255 or hexadecimals
+ * between 0x00 and 0xFF
+ *
+ * @param array $params Parameter array
+ *
+ * @return Image_Canvas_SWF
+ */
+ function Image_Canvas_SWF($params)
+ {
+ parent::Image_Canvas($params);
+ $this->_reset();
+
+ $version = (isset($params['version']) && $params['version'] <= 6)
+ ? $params['version'] : $this->_version;
+
+ $this->_canvas = new SWFMovie($version);
+ $this->_canvas->setDimension($this->_width, $this->_height);
+
+ if (isset($params['background'])) {
+ $this->setBackground($params['background']);
+ }
+ }
+
+ /**
+ * Sets the background color
+ *
+ * Values can be specified either as integers between 0 and 255 or as hexadecimals between 0x00 and 0xFF
+ *
+ * @param mixed $color Color
+ *
+ * @return void
+ * @access public
+ */
+ function setBackground($color)
+ {
+ $color = Image_Canvas_Color::color2RGB($color);
+ $this->_canvas->setBackground($color[0], $color[1], $color[2]);
+ }
+
+ /**
+ * Add an object to the movie
+ *
+ * @param string $element The element
+ *
+ * @return void
+ * @access public
+ */
+ function addElement($element)
+ {
+ $this->_canvas->add($element);
+ }
+
+ /**
+ * Get the color index for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int A SVG compatible color
+ * @access private
+ */
+ function _color($color = false)
+ {
+ if ($color === false) {
+ return array();
+ } else {
+ return Image_Canvas_Color::color2RGB($color);
+ }
+ }
+
+ /**
+ * Get the opacity for the RGB color
+ *
+ * @param int $color The color
+ *
+ * @return int A SWF compatible opacity value
+ * @access private
+ */
+ function _opacity($color = false)
+ {
+ if ($color === false) {
+ return false;
+ } else {
+ $color = Image_Canvas_Color::color2RGB($color);
+ if ($color[3] != 255) {
+ return sprintf('%0.1f', $color[3]/255);
+ } else {
+ return 255;
+ }
+ }
+ }
+
+ /**
+ * Get the applicable linestyle
+ *
+ * @param mixed $lineStyle The line style to return, false if the one
+ * explicitly set
+ *
+ * @return mixed A compatible linestyle
+ * @access private
+ */
+ function _getLineStyle($lineStyle = false)
+ {
+ if ($lineStyle === false) {
+ $lineStyle = $this->_lineStyle;
+ }
+
+ return $this->_color($lineStyle);
+ }
+
+ /**
+ * Get the applicable fillstyle
+ *
+ * @param mixed $fillStyle The fillstyle to return, false if the one
+ * explicitly set
+ *
+ * @return mixed A compatible fillstyle
+ * @access private
+ */
+ function _getFillStyle($fillStyle = false)
+ {
+ if ($fillStyle === false) {
+ $fillStyle = $this->_fillStyle;
+ }
+
+ return $this->_color($fillStyle);
+ }
+
+ /**
+ * Sets an image that should be used for filling
+ *
+ * @param string $filename The filename of the image to fill with
+ *
+ * @todo
+ * @return void
+ */
+ function setFillImage($filename)
+ {
+ }
+
+ /**
+ * Sets a gradient fill
+ *
+ * @param array $gradient Gradient fill options
+ *
+ * @todo
+ * @return void
+ */
+ function setGradientFill($gradient)
+ {
+ }
+
+ /**
+ * Sets the font options.
+ *
+ * The $font array may have the following entries:
+ * 'type' : 'ttf' (TrueType) or omitted for default<br>
+ * If 'type' is 'ttf' then the following can be specified<br>
+ * 'size' : size in pixels<br>
+ * 'angle' : the angle with which to write the text
+ * 'file' : the .ttf file (either the basename, filename or full path)
+ *
+ * @param array $fontOptions The font options.
+ *
+ * @return void
+ */
+ function setFont($fontOptions)
+ {
+ parent::setFont($fontOptions);
+ if (!isset($this->_font['size'])) {
+ $this->_font['size'] = 10;
+ }
+ }
+
+ /**
+ * Draw a line end
+ *
+ * Parameter array:
+ * 'x' : int X point
+ * 'y' : int Y point
+ * 'end' : string The end type of the end
+ * 'size' : int The size of the end
+ * 'color' : string The color of the end
+ * 'angle' : int [optional] The angle with which to draw the end
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function drawEnd($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $size = $params['size'];
+ $angle = deg2rad((isset($params['angle']) ? $params['angle'] : 0));
+ $pi2 = pi() / 2;
+
+ switch ($params['end']) {
+
+ case 'lollipop':
+ case 'circle':
+ if (($fill = $this->_getFillStyle($params['color'])) !== false) {
+ $shapeObj = new SWFShape();
+ $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);
+ $shapeObj->movePenTo($x + $size / 2, $y);
+ $shapeObj->drawCircle($size / 2);
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $this->_canvas->add($button);
+ } else {
+ $this->_canvas->add($shapeObj);
+ }
+
+ parent::drawEnd($params);
+ }
+ break;
+
+ case 'diamond':
+ $x0 = round($params['x'] + cos($angle) * $size * 0.65);
+ $y0 = round($params['y'] - sin($angle) * $size * 0.65);
+ $shape = array(
+ array($x0 + round(cos($angle) * $size * 0.65),
+ $y0 - round(sin($angle) * $size * 0.65)),
+ array($x0 + round(cos($angle + $pi2) * $size * 0.65),
+ $y0 - round(sin($angle + $pi2) * $size * 0.65)),
+ array($x0 + round(cos($angle + pi()) * $size * 0.65),
+ $y0 - round(sin($angle + pi()) * $size * 0.65)),
+ array($x0 + round(cos($angle + 3 * $pi2) * $size * 0.65),
+ $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65))
+ );
+ break;
+
+ case 'line':
+ $shape = array(
+ array($x + round(cos($angle + $pi2) * $size / 2),
+ $y - round(sin($angle + $pi2) * $size / 2)),
+ array($x + round(cos($angle + 3 * $pi2) * $size / 2),
+ $y - round(sin($angle + 3 * $pi2) * $size / 2))
+ );
+ break;
+
+ case 'box':
+ case 'rectangle':
+ $x0 = round($params['x'] + cos($angle) * $size / 2);
+ $y0 = round($params['y'] - sin($angle) * $size / 2);
+ $pi4 = pi() / 4;
+ $shape = array(
+ array($x0 + round(cos($angle + $pi4) * $size / 2),
+ $y0 - round(sin($angle + $pi4) * $size / 2)),
+ array($x0 + round(cos($angle + $pi2 + $pi4) * $size / 2),
+ $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2)),
+ array($x0 + round(cos($angle + pi() + $pi4) * $size / 2),
+ $y0 - round(sin($angle + pi() + $pi4) * $size / 2)),
+ array($x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2),
+ $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2))
+ );
+ break;
+
+ case 'arrow':
+ $shape = array(
+ array($x + cos($angle) * $size,
+ $y - sin($angle) * $size),
+ array($x + cos($angle + $pi2) * $size * 0.4,
+ $y - sin($angle + $pi2) * $size * 0.4),
+ array($x + cos($angle + 3 * $pi2) * $size * 0.4,
+ $y - sin($angle + 3 * $pi2) * $size * 0.4)
+ );
+ break;
+
+ case 'arrow2':
+ $shape = array(
+ array($x + round(cos($angle) * $size),
+ $y - round(sin($angle) * $size)),
+ array($x + round(cos($angle + $pi2 + deg2rad(45)) * $size),
+ $y - round(sin($angle + $pi2 + deg2rad(45)) * $size)),
+ array($x,
+ $y),
+ array($x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size),
+ $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size))
+ );
+ break;
+ }
+
+ if (isset($shape)) {
+ // output the shape
+ if (($fill = $this->_getFillStyle($params['color'])) !== false) {
+ $shapeObj = new SWFShape();
+ $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);
+ $shapeObj->setLine(0, $fill[0], $fill[1], $fill[2]);
+ $shapeObj->movePenTo($shape[0][0], $shape[0][1]);
+ for ($count = count($shape); $count--; $count > 0) {
+ $shapeObj->drawLineTo($shape[$count][0], $shape[$count][1]);
+ }
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $this->_canvas->add($button);
+ } else {
+ $this->_canvas->add($shapeObj);
+ }
+ }
+ }
+ parent::drawEnd($params);
+ }
+
+ /**
+ * Parameter array:
+ * 'x0' : int X start point
+ * 'y0' : int Y start point
+ * 'x1' : int X end point
+ * 'y1' : int Y end point
+ * 'color' : mixed [optional] The line color
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ $x0 = $this->_getX($params['x0']);
+ $y0 = $this->_getY($params['y0']);
+ $x1 = $this->_getX($params['x1']);
+ $y1 = $this->_getY($params['y1']);
+
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $color = $this->_getLineStyle($color);
+
+ $shape = new SWFShape();
+ $shape->setLine(1, $color[0], $color[1], $color[2]);
+
+ $shape->movePenTo($x0, $y0);
+ $shape->drawLine($x1 - $x0, $y1 - $y0);
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $this->_canvas->add($button);
+ } else {
+ $this->_canvas->add($shape);
+ }
+
+ parent::line($params);
+ }
+
+ /**
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon)
+ * or not (connected line)
+ * 'fill' : mixed [optional] The fill color
+ * 'line' : mixed [optional] The line color
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params = array())
+ {
+ $connectEnds = (isset($params['connect']) ? $params['connect'] : false);
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $lineStyle = $this->_getLineStyle($lineColor);
+ $fillStyle = $this->_getFillStyle($fillColor);
+
+ $shape = new SWFShape();
+ if ($connectEnds) {
+ $shape->setRightFill($fillStyle[0], $fillStyle[1], $fillStyle[2]);
+ }
+ $shape->setLine(0, $lineStyle[0], $lineStyle[1], $lineStyle[2]);
+ $shape->movePenTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']);
+
+ foreach ($this->_polygon as $point) {
+ $shape->drawLineTo($point['X'], $point['Y']);
+ }
+
+ if ($connectEnds) {
+ $shape->drawLineTo($this->_polygon[0]['X'], $this->_polygon[0]['Y']);
+ }
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $this->_canvas->add($button);
+ } else {
+ $this->_canvas->add($shape);
+ }
+
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0' : int X start point
+ * 'y0' : int Y start point
+ * 'x1' : int X end point
+ * 'y1' : int Y end point
+ * 'fill' : The fill style
+ * 'line' : The line style
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ $x0 = min($this->_getX($params['x0']), $this->_getX($params['x1']));
+ $y0 = min($this->_getY($params['y0']), $this->_getY($params['y1']));
+ $x1 = max($this->_getX($params['x0']), $this->_getX($params['x1']));
+ $y1 = max($this->_getY($params['y0']), $this->_getY($params['y1']));
+
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $fillColor = $this->_getFillStyle($fillColor);
+ $lineColor = $this->_getLineStyle($lineColor);
+
+ // use fill color if no line color is set or transparent
+ if (count($lineColor) === 0) {
+ $lineColor = $fillColor;
+ }
+
+ $shape = new SWFShape();
+ $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]);
+
+ if (count($fillColor)) {
+ $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);
+ }
+
+ $shape->movePenTo($x0, $y0);
+ $shape->drawLine($x1 - $x0, 0);
+ $shape->drawLine(0, $y1 - $y0);
+ $shape->drawLine($x0 - $x1, 0);
+ $shape->drawLine(0, $y0 - $y1);
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $this->_canvas->add($button);
+ } else {
+ $this->_canvas->add($shape);
+ }
+
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x' : int X center point
+ * 'y' : int Y center point
+ * 'rx' : int X radius
+ * 'ry' : int Y radius
+ * 'fill' : mixed [optional] The fill color
+ * 'line' : mixed [optional] The line color
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ $x = $this->_getX($params['x']);
+ $y = $this->_getY($params['y']);
+ $rx = $this->_getX($params['rx']);
+ $ry = $this->_getY($params['ry']);
+
+ // calculate scale factors
+ $scaleX = 1.0;
+ $scaleY = 1.0;
+ $moveX = 0;
+ $moveY = 0;
+
+ if ($rx > $ry) {
+ $scaleY = $ry / $rx;
+ $moveY = $ry * (1 - $scaleY);
+ } elseif ($rx < $ry) {
+ $scaleX = $rx / $ry;
+ $moveX = $rx * (1 - $scaleX);
+ }
+
+ $fillColor = (isset($params['fill']) ? $params['fill'] : false);
+ $lineColor = (isset($params['line']) ? $params['line'] : false);
+
+ $fillColor = $this->_getFillStyle($fillColor);
+ $lineColor = $this->_getLineStyle($lineColor);
+
+ $shape = new SWFShape();
+ $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);
+ $shape->movePenTo($x, $y);
+ $shape->setLine(1, $lineColor[0], $lineColor[1], $lineColor[2]);
+
+ if (count($fillColor)) {
+ $shape->setRightFill($fillColor[0], $fillColor[1], $fillColor[2]);
+ }
+
+ $shape->drawCircle(max($rx, $ry));
+
+ if (isset($params['url'])) {
+ $button = new SWFButton();
+ $button->addShape($shape, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+ $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
+ $ellipse = $this->_canvas->add($button);
+ } else {
+ $ellipse = $this->_canvas->add($shape);
+ }
+
+ $ellipse->move($moveX, $moveY);
+ $ellipse->scaleTo($scaleX, $scaleY);
+
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x' : int X center point
+ * 'y' : int Y center point
+ * 'rx' : int X radius
+ * 'ry' : int Y radius
+ * 'v1' : int The starting angle (in degrees)
+ * 'v2' : int The end angle (in degrees)
+ * 'srx' : int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry' : int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill' : mixed [optional] The fill color
+ * 'line' : mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @todo
+ * @return void
+ */
+ function pieslice($params)
+ {
+ }
+
+ /**
+ * Get the width of a text,
+ *
+ * @param string $text The text to get the width of
+ *
+ * @return int The width of the text
+ */
+ function textWidth($text)
+ {
+ if (isset($this->_font['vertical']) && $this->_font['vertical']) {
+ return $this->_font['size'];
+ } else {
+ return round($this->_font['size'] * 0.5 * strlen($text));
+ }
+ }
+
+ /**
+ * Get the height of a text,
+ *
+ * @param string $text The text to get the height of
+ *
+ * @return int The height of the text
+ */
+ function textHeight($text)
+ {
+ if (isset($this->_font['vertical']) && $this->_font['vertical']) {
+ return round($this->_font['size'] * 0.7 * strlen($text));
+ } else {
+ return $this->_font['size'];
+ }
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x' : int X-point of text
+ * 'y' : int Y-point of text
+ * 'text' : string The text to add
+ * 'color' : mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @todo Vertical alignment
+ * @return void
+ */
+ function addText($params)
+ {
+ $x0 = $this->_getX($params['x']);
+ $y0 = $this->_getY($params['y']);
+ $text = str_replace("\r", '', $params['text']);
+ $color = (isset($params['color']) ? $params['color'] : false);
+ $textHeight = $this->textHeight($text);
+ $alignment = (isset($params['alignment']) ? $params['alignment'] : false);
+
+ if (!is_array($alignment)) {
+ $alignment = array('vertical' => 'top', 'horizontal' => 'left');
+ }
+
+ if (!isset($alignment['vertical'])) {
+ $alignment['vertical'] = 'top';
+ }
+
+ if (!isset($alignment['horizontal'])) {
+ $alignment['horizontal'] = 'left';
+ }
+
+ if (($color === false) && (isset($this->_font['color']))) {
+ $color = $this->_font['color'];
+ }
+
+ if ($color == 'transparent') {
+ return;
+ }
+
+ if (strpos($this->_font['file'], '.') === false) {
+ $this->_font['file'] = IMAGE_CANVAS_SYSTEM_FONT_PATH . $this->_font['file'] . '.fdb';
+ }
+
+ $textColor = $this->_color($color);
+ $textOpacity = $this->_opacity($color);
+
+ $lines = explode("\n", $text);
+ foreach ($lines as $line) {
+
+ $x = $x0;
+ $y = $y0;
+
+ $y0 += $textHeight + 2;
+
+ $width = $this->textWidth($line);
+ $height = $this->textHeight($line);
+
+ if ($alignment['horizontal'] == 'right') {
+ $x -= $width;
+ } else if ($alignment['horizontal'] == 'center') {
+ $x -= $width / 2;
+ }
+
+ $font = new SWFFont($this->_font['file']);
+ $text = new SWFText();
+ $text->setFont($font);
+ $text->moveTo($x, $y + $this->_font['size']);
+ $text->setColor($textColor[0], $textColor[1], $textColor[2], $textOpacity);
+ $text->setHeight($this->_font['size']);
+ $text->addString($line);
+ $this->_canvas->add($text);
+ }
+
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x' : int X-point of overlayed image
+ * 'y' : int Y-point of overlayed image
+ * 'filename' : string The filename of the image to overlay
+ * 'width' : int [optional] The width of the overlayed image (resizing if possible)
+ * 'height' : int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment' : array [optional] Alignment
+ * 'url' : string [optional] Target URL
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ parent::image($params);
+ }
+
+ /**
+ * Display the SWF
+ *
+ * @param array $param Parameter array
+ *
+ * @return void
+ */
+ function show($param = false)
+ {
+ parent::show($param);
+ $this->_canvas->output();
+ }
+
+ /**
+ * Save the SWF to a file
+ *
+ * @param array $param Parameter array
+ * array('filename' => 'canvas.swf',
+ * 'compression' => 0)
+ *
+ * The compression level can be a value between 0 and 9,
+ * defining the SWF compression similar to gzip compression.
+ * This parameter is only available as of Flash MX (6).
+ *
+ * @return void
+ */
+ function save($param = false)
+ {
+ if (!isset($param['compression'])) {
+ $param['compression'] = 0;
+ }
+
+ parent::save($param);
+ $this->_canvas->save($param['filename'], $param['compression']);
+ }
+
+ /**
+ * Get SWF movie object
+ *
+ * @return object
+ */
+ function getData()
+ {
+ return $this->_canvas;
+ }
+
+ /**
+ * Set clipping to occur
+ *
+ * Parameter array:
+ *
+ * 'x0' : int X point of Upper-left corner
+ * 'y0' : int X point of Upper-left corner
+ * 'x1' : int X point of lower-right corner
+ * 'y1' : int Y point of lower-right corner
+ *
+ * @param array $params Parameter array (x0, y0, x1, y1)
+ *
+ * @todo
+ * @return void
+ */
+ function setClipping($params = false)
+ {
+ }
+
+ /**
+ * Get an SWF specific HTML tag
+ *
+ * This method implicitly saves the canvas to the filename in the
+ * filesystem path specified and parses it as URL specified by URL path
+ *
+ * Parameter array:
+ * 'filename' : string
+ * 'filepath' : string Path to the file on the file system. Remember the final slash
+ * 'urlpath' : string Path to the file available through an URL. Remember the final slash
+ * 'width' : int The width in pixels
+ * 'height' : int The height in pixels
+ * 'quality' : Flash quality
+ * 'scale' : Scale
+ * 'menu' : Whether to display the Flash menu on mouse right-click
+ *
+ * @param array $params Parameter array
+ *
+ * @return string HTML-output
+ */
+ function toHtml($params)
+ {
+ parent::toHtml($params);
+ return '<object data="' . $params['urlpath'] . $params['filename'] . '" type="application/x-shockwave-flash" width="' . $params['width'] . '" height="' . $params['height'] . '">
+ <param name="movie" value="' . $params['urlpath'] . $params['filename'] . '">
+ <param name="quality" value="' . $params['quality'] . '">
+ <param name="scale" value="' . $params['scale'] . '">
+ <param name="menu" value="' . $params['menu'] . '">
+ </object>';
+ }
+}
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Canvas based creation of images to facilitate different output formats\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Tool.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * This class contains a set of tool-functions.\r
- * \r
- * These functions are all to be called statically\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- * @abstract\r
- */\r
-class Image_Canvas_Tool\r
-{\r
-\r
- /**\r
- * Maps a font name to an actual font file (fx. a .ttf file)\r
- *\r
- * Used to translate names (i.e. 'Courier New' to 'cour.ttf' or\r
- * '/Windows/Fonts/Cour.ttf')\r
- *\r
- * Font names are translated using the tab-separated file\r
- * Image/Canvas/Tool/fontmap.txt.\r
- *\r
- * The translated font-name (or the original if no translation) exists is\r
- * then returned if it is an existing file, otherwise the file is searched\r
- * first in the path specified by IMAGE_CANVAS_SYSTEM_FONT_PATH defined in\r
- * Image/Canvas.php, then in the Image/Canvas/Fonts folder. If a font is\r
- * still not found and the name is not beginning with a '/' the search is\r
- * left to the library, otherwise the font is deemed non-existing.\r
- *\r
- * @param string $name The name of the font\r
- * @param string $type The needed file type of the font\r
- * @return string The filename of the font\r
- * @static\r
- */\r
- function fontMap($name, $type = '.ttf')\r
- {\r
- static $_fontMap;\r
- \r
- if (!is_array($_fontMap)) {\r
- if (file_exists($fontmap = (dirname(__FILE__) . '/Fonts/fontmap.txt'))) {\r
- $file = file($fontmap);\r
- foreach($file as $fontmapping) {\r
- list($fontname, $filenames) = explode(',', $fontmapping, 2);\r
- $fontname = trim($fontname);\r
- $filenames = trim($filenames);\r
- $filenames = explode(',', $filenames);\r
- foreach ($filenames as $filename) {\r
- $type_pos = strrpos($filename, '.');\r
- $type = substr($filename, $type_pos);\r
- $_fontMap[$fontname][$type] = $filename;\r
- }\r
- }\r
- }\r
- }\r
- \r
- $type = strtolower($type);\r
- \r
- if ((isset($_fontMap[$name])) && (isset($_fontMap[$name][$type]))) {\r
- $filename = $_fontMap[$name][$type];\r
- } else {\r
- $filename = $name;\r
- }\r
-\r
- if (substr($filename, -strlen($type)) !== $type) {\r
- $filename .= $type;\r
- }\r
-\r
- $result = false;\r
- if (file_exists($filename)) {\r
- $result = $filename;\r
- } elseif (file_exists($file = (IMAGE_CANVAS_SYSTEM_FONT_PATH . $filename))) {\r
- $result = $file;\r
- } elseif (file_exists($file = (dirname(__FILE__) . '/Fonts/' . $filename))) {\r
- $result = $file;\r
- } elseif (substr($name, 0, 1) !== '/') {\r
- // leave it to the library to find the font\r
- $result = $name;\r
- } \r
- \r
- return str_replace('\\', '/', $result); \r
- }\r
- \r
- /**\r
- * Return the average of 2 points\r
- *\r
- * @param double P1 1st point\r
- * @param double P2 2nd point\r
- * @return double The average of P1 and P2\r
- * @static\r
- */\r
- function mid($p1, $p2)\r
- {\r
- return ($p1 + $p2) / 2;\r
- }\r
-\r
- /**\r
- * Mirrors P1 in P2 by a amount of Factor\r
- *\r
- * @param double $p1 1st point, point to mirror\r
- * @param double $o2 2nd point, mirror point\r
- * @param double $factor Mirror factor, 0 returns $p2, 1 returns a pure\r
- * mirror, ie $p1 on the exact other side of $p2\r
- * @return double $p1 mirrored in $p2 by Factor\r
- * @static\r
- */\r
- function mirror($p1, $p2, $factor = 1)\r
- {\r
- return $p2 + $factor * ($p2 - $p1);\r
- }\r
-\r
- /**\r
- * Calculates a Bezier control point, this function must be called for BOTH\r
- * X and Y coordinates (will it work for 3D coordinates!?)\r
- *\r
- * @param double $p1 1st point\r
- * @param double $p2 Point to\r
- * @param double $factor Mirror factor, 0 returns P2, 1 returns a pure\r
- * mirror, i.e. P1 on the exact other side of P2\r
- * @return double P1 mirrored in P2 by Factor\r
- * @static\r
- */\r
- function controlPoint($p1, $p2, $factor, $smoothFactor = 0.75)\r
- {\r
- $sa = Image_Canvas_Tool::mirror($p1, $p2, $smoothFactor);\r
- $sb = Image_Canvas_Tool::mid($p2, $sa);\r
-\r
- $m = Image_Canvas_Tool::mid($p2, $factor);\r
-\r
- $pC = Image_Canvas_Tool::mid($sb, $m);\r
-\r
- return $pC;\r
- }\r
-\r
- /**\r
- * Calculates a Bezier point, this function must be called for BOTH X and Y\r
- * coordinates (will it work for 3D coordinates!?)\r
- *\r
- * @param double $t A position between $p2 and $p3, value between 0 and 1\r
- * @param double $p1 Point to use for calculating control points\r
- * @param double $p2 Point 1 to calculate bezier curve between\r
- * @param double $p3 Point 2 to calculate bezier curve between\r
- * @param double $p4 Point to use for calculating control points\r
- * @return double The bezier value of the point t between $p2 and $p3 using\r
- * $p1 and $p4 to calculate control points\r
- * @static\r
- */\r
- function bezier($t, $p1, $p2, $p3, $p4)\r
- {\r
- // (1-t)^3*p1 + 3*(1-t)^2*t*p2 + 3*(1-t)*t^2*p3 + t^3*p4\r
- return pow(1 - $t, 3) * $p1 +\r
- 3 * pow(1 - $t, 2) * $t * $p2 +\r
- 3 * (1 - $t) * pow($t, 2) * $p3 +\r
- pow($t, 3) * $p4;\r
- }\r
- \r
- /**\r
- * Gets the angle / slope of a line relative to horizontal (left -> right)\r
- * \r
- * @param double $x0 The starting x point\r
- * @param double $y0 The starting y point\r
- * @param double $x1 The ending x point\r
- * @param double $y1 The ending y point\r
- * @param double The angle in degrees of the line\r
- * @static\r
- */\r
- function getAngle($x0, $y0, $x1, $y1)\r
- {\r
- \r
- $dx = ($x1 - $x0);\r
- $dy = ($y1 - $y0);\r
- $l = sqrt($dx * $dx + $dy * $dy);\r
- $v = rad2deg(asin(($y0 - $y1) / $l));\r
- if ($dx < 0) {\r
- $v = 180 - $v;\r
- }\r
- return $v;\r
- \r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Canvas based creation of images to facilitate different output formats
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Tool.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * This class contains a set of tool-functions.
+ *
+ * These functions are all to be called statically
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ * @abstract
+ */
+class Image_Canvas_Tool
+{
+
+ /**
+ * Maps a font name to an actual font file (fx. a .ttf file)
+ *
+ * Used to translate names (i.e. 'Courier New' to 'cour.ttf' or
+ * '/Windows/Fonts/Cour.ttf')
+ *
+ * Font names are translated using the tab-separated file
+ * Image/Canvas/Tool/fontmap.txt.
+ *
+ * The translated font-name (or the original if no translation) exists is
+ * then returned if it is an existing file, otherwise the file is searched
+ * first in the path specified by IMAGE_CANVAS_SYSTEM_FONT_PATH defined in
+ * Image/Canvas.php, then in the Image/Canvas/Fonts folder. If a font is
+ * still not found and the name is not beginning with a '/' the search is
+ * left to the library, otherwise the font is deemed non-existing.
+ *
+ * @param string $name The name of the font
+ * @param string $type The needed file type of the font
+ *
+ * @return string The filename of the font
+ * @static
+ */
+ function fontMap($name, $type = '.ttf')
+ {
+ static $_fontMap;
+
+ if (!is_array($_fontMap)) {
+ if (file_exists($fontmap = (dirname(__FILE__) . '/Fonts/fontmap.txt'))) {
+ $file = file($fontmap);
+ foreach ($file as $fontmapping) {
+ list($fontname, $filenames) = explode(',', $fontmapping, 2);
+ $fontname = trim($fontname);
+ $filenames = trim($filenames);
+ $filenames = explode(',', $filenames);
+ foreach ($filenames as $filename) {
+ $type_pos = strrpos($filename, '.');
+ $type = substr($filename, $type_pos);
+ $_fontMap[$fontname][$type] = $filename;
+ }
+ }
+ }
+ }
+
+ $type = strtolower($type);
+
+ if ((isset($_fontMap[$name])) && (isset($_fontMap[$name][$type]))) {
+ $filename = $_fontMap[$name][$type];
+ } else {
+ $filename = $name;
+ }
+
+ if (substr($filename, -strlen($type)) !== $type) {
+ $filename .= $type;
+ }
+
+ $result = false;
+ if (file_exists($filename)) {
+ $result = $filename;
+ } elseif (file_exists($file = (IMAGE_CANVAS_SYSTEM_FONT_PATH . $filename))) {
+ $result = $file;
+ } elseif (file_exists($file = (dirname(__FILE__) . '/Fonts/' . $filename))) {
+ $result = $file;
+ } elseif (substr($name, 0, 1) !== '/') {
+ // leave it to the library to find the font
+ $result = $name;
+ }
+
+ return str_replace('\\', '/', $result);
+ }
+
+ /**
+ * Return the average of 2 points
+ *
+ * @param double $p1 1st point
+ * @param double $p2 2nd point
+ *
+ * @return double The average of P1 and P2
+ * @static
+ */
+ function mid($p1, $p2)
+ {
+ return ($p1 + $p2) / 2;
+ }
+
+ /**
+ * Mirrors P1 in P2 by a amount of Factor
+ *
+ * @param double $p1 1st point, point to mirror
+ * @param double $p2 2nd point, mirror point
+ * @param double $factor Mirror factor, 0 returns $p2, 1 returns a pure
+ * mirror, ie $p1 on the exact other side of $p2
+ *
+ * @return double $p1 mirrored in $p2 by Factor
+ * @static
+ */
+ function mirror($p1, $p2, $factor = 1)
+ {
+ return $p2 + $factor * ($p2 - $p1);
+ }
+
+ /**
+ * Calculates a Bezier control point, this function must be called for BOTH
+ * X and Y coordinates (will it work for 3D coordinates!?)
+ *
+ * @param double $p1 1st point
+ * @param double $p2 Point to
+ * @param double $factor ???
+ * @param double $smoothFactor Smooth factor (???)
+ *
+ * @return double P1 mirrored in P2 by Factor
+ * @static
+ */
+ function controlPoint($p1, $p2, $factor, $smoothFactor = 0.75)
+ {
+ $sa = Image_Canvas_Tool::mirror($p1, $p2, $smoothFactor);
+ $sb = Image_Canvas_Tool::mid($p2, $sa);
+
+ $m = Image_Canvas_Tool::mid($p2, $factor);
+
+ $pC = Image_Canvas_Tool::mid($sb, $m);
+
+ return $pC;
+ }
+
+ /**
+ * Calculates a Bezier point, this function must be called for BOTH X and Y
+ * coordinates (will it work for 3D coordinates!?)
+ *
+ * @param double $t A position between $p2 and $p3, value between 0 and 1
+ * @param double $p1 Point to use for calculating control points
+ * @param double $p2 Point 1 to calculate bezier curve between
+ * @param double $p3 Point 2 to calculate bezier curve between
+ * @param double $p4 Point to use for calculating control points
+ *
+ * @return double The bezier value of the point t between $p2 and $p3 using
+ * $p1 and $p4 to calculate control points
+ * @static
+ */
+ function bezier($t, $p1, $p2, $p3, $p4)
+ {
+ // (1-t)^3*p1 + 3*(1-t)^2*t*p2 + 3*(1-t)*t^2*p3 + t^3*p4
+ return pow(1 - $t, 3) * $p1 +
+ 3 * pow(1 - $t, 2) * $t * $p2 +
+ 3 * (1 - $t) * pow($t, 2) * $p3 +
+ pow($t, 3) * $p4;
+ }
+
+ /**
+ * Gets the angle / slope of a line relative to horizontal (left -> right)
+ *
+ * @param double $x0 The starting x point
+ * @param double $y0 The starting y point
+ * @param double $x1 The ending x point
+ * @param double $y1 The ending y point
+ *
+ * @return double The angle in degrees of the line
+ * @static
+ */
+ function getAngle($x0, $y0, $x1, $y1)
+ {
+
+ $dx = ($x1 - $x0);
+ $dy = ($y1 - $y0);
+ $l = sqrt($dx * $dx + $dy * $dy);
+ $v = rad2deg(asin(($y0 - $y1) / $l));
+ if ($dx < 0) {
+ $v = 180 - $v;
+ }
+ return $v;
+
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Canvas\r
- *\r
- * Canvas based creation of images to facilitate different output formats\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: WithMap.php 287471 2009-08-18 23:12:01Z clockwerx $\r
- * @link http://pear.php.net/package/Image_Canvas\r
- */\r
-\r
-/**\r
- * Class for handling different output formats including a HTML image map\r
- * \r
- * @category Images\r
- * @package Image_Canvas\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Image_Canvas\r
- * @since version 0.2.0\r
- * @abstract\r
- */\r
-class Image_Canvas_WithMap extends Image_Canvas\r
-{\r
-\r
- /**\r
- * The image map\r
- * @var Image_Canvas_ImageMap\r
- * @access private\r
- */\r
- var $_imageMap = null;\r
-\r
- /**\r
- * Create the canvas.\r
- *\r
- * Parameters available:\r
- *\r
- * 'width' The width of the graph on the canvas\r
- *\r
- * 'height' The height of the graph on the canvas\r
- *\r
- * 'left' The left offset of the graph on the canvas\r
- *\r
- * 'top' The top offset of the graph on the canvas\r
- * \r
- * 'usemap' Initialize an image map\r
- *\r
- * @param array $params Parameter array\r
- * @abstract\r
- */\r
- function Image_Canvas_WithMap($params)\r
- {\r
- parent::Image_Canvas($params);\r
- \r
- if ((isset($params['usemap'])) && ($params['usemap'] === true)) {\r
- $this->_imageMap =& Image_Canvas::factory(\r
- 'ImageMap',\r
- array(\r
- 'left' => $this->_left,\r
- 'top' => $this->_top,\r
- 'width' => $this->_width,\r
- 'height' => $this->_height\r
- )\r
- );\r
- }\r
- }\r
- /**\r
- * Draw a line\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'color': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function line($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->line($params);\r
- }\r
- parent::line($params);\r
- }\r
-\r
- /**\r
- * Adds vertex to a polygon\r
- *\r
- * Parameter array:\r
- * 'x': int X point\r
- * 'y': int Y point\r
- * @param array $params Parameter array\r
- */\r
- function addVertex($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->addVertex($params);\r
- }\r
- parent::addVertex($params);\r
- }\r
-\r
- /**\r
- * Adds "splined" vertex to a polygon\r
- *\r
- * Parameter array:\r
- * 'x': int X point\r
- * 'y': int Y point\r
- * 'p1x': X Control point 1\r
- * 'p1y': Y Control point 1\r
- * 'p2x': X Control point 2\r
- * 'p2y': Y Control point 2\r
- * @param array $params Parameter array\r
- */\r
- function addSpline($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->addSpline($params);\r
- }\r
- parent::addSpline($params);\r
- }\r
-\r
- /**\r
- * Draws a polygon\r
- *\r
- * Parameter array:\r
- * 'connect': bool [optional] Specifies whether the start point should be\r
- * connected to the endpoint (closed polygon) or not (connected line)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function polygon($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->polygon($params);\r
- }\r
- parent::polygon($params);\r
- }\r
-\r
- /**\r
- * Draw a rectangle\r
- *\r
- * Parameter array:\r
- * 'x0': int X start point\r
- * 'y0': int Y start point\r
- * 'x1': int X end point\r
- * 'y1': int Y end point\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function rectangle($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->rectangle($params);\r
- } \r
- parent::rectangle($params);\r
- }\r
-\r
- /**\r
- * Draw an ellipse\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function ellipse($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->ellipse($params);\r
- } \r
- parent::ellipse($params);\r
- }\r
-\r
- /**\r
- * Draw a pie slice\r
- *\r
- * Parameter array:\r
- * 'x': int X center point\r
- * 'y': int Y center point\r
- * 'rx': int X radius\r
- * 'ry': int Y radius\r
- * 'v1': int The starting angle (in degrees)\r
- * 'v2': int The end angle (in degrees)\r
- * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)\r
- * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)\r
- * 'fill': mixed [optional] The fill color\r
- * 'line': mixed [optional] The line color\r
- * @param array $params Parameter array\r
- */\r
- function pieslice($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->pieslice($params);\r
- } \r
- parent::pieslice($params);\r
- }\r
-\r
- /**\r
- * Writes text\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of text\r
- * 'y': int Y-point of text\r
- * 'text': string The text to add\r
- * 'alignment': array [optional] Alignment\r
- * 'color': mixed [optional] The color of the text\r
- */\r
- function addText($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->addText($params);\r
- }\r
- parent::addText($params);\r
- }\r
-\r
- /**\r
- * Overlay image\r
- *\r
- * Parameter array:\r
- * 'x': int X-point of overlayed image\r
- * 'y': int Y-point of overlayed image\r
- * 'filename': string The filename of the image to overlay\r
- * 'width': int [optional] The width of the overlayed image (resizing if possible)\r
- * 'height': int [optional] The height of the overlayed image (resizing if possible)\r
- * 'alignment': array [optional] Alignment\r
- */\r
- function image($params)\r
- {\r
- if (isset($this->_imageMap)) {\r
- $this->_imageMap->image($params);\r
- }\r
- parent::image($params);\r
- }\r
-\r
- /**\r
- * Get the imagemap\r
- * @return Image_Graph_ImageMap The image map (or false if none)\r
- */\r
- function &getImageMap()\r
- {\r
- $result = null;\r
- if (isset($this->_imageMap)) {\r
- $result =& $this->_imageMap;\r
- }\r
- return $result;\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Canvas
+ *
+ * Canvas based creation of images to facilitate different output formats
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: WithMap.php 291771 2009-12-06 17:38:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Canvas
+ */
+
+/**
+ * Class for handling different output formats including a HTML image map
+ *
+ * @category Images
+ * @package Image_Canvas
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Image_Canvas
+ * @since version 0.2.0
+ * @abstract
+ */
+class Image_Canvas_WithMap extends Image_Canvas
+{
+
+ /**
+ * The image map
+ * @var Image_Canvas_ImageMap
+ * @access private
+ */
+ var $_imageMap = null;
+
+ /**
+ * Create the canvas.
+ *
+ * Parameters available:
+ *
+ * 'width' The width of the graph on the canvas
+ *
+ * 'height' The height of the graph on the canvas
+ *
+ * 'left' The left offset of the graph on the canvas
+ *
+ * 'top' The top offset of the graph on the canvas
+ *
+ * 'usemap' Initialize an image map
+ *
+ * @param array $params Parameter array
+ *
+ * @abstract
+ */
+ function Image_Canvas_WithMap($params)
+ {
+ parent::Image_Canvas($params);
+
+ if ((isset($params['usemap'])) && ($params['usemap'] === true)) {
+ $this->_imageMap =& Image_Canvas::factory(
+ 'ImageMap',
+ array(
+ 'left' => $this->_left,
+ 'top' => $this->_top,
+ 'width' => $this->_width,
+ 'height' => $this->_height
+ )
+ );
+ }
+ }
+ /**
+ * Draw a line
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'color': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function line($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->line($params);
+ }
+ parent::line($params);
+ }
+
+ /**
+ * Adds vertex to a polygon
+ *
+ * Parameter array:
+ * 'x': int X point
+ * 'y': int Y point
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addVertex($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->addVertex($params);
+ }
+ parent::addVertex($params);
+ }
+
+ /**
+ * Adds "splined" vertex to a polygon
+ *
+ * Parameter array:
+ * 'x': int X point
+ * 'y': int Y point
+ * 'p1x': X Control point 1
+ * 'p1y': Y Control point 1
+ * 'p2x': X Control point 2
+ * 'p2y': Y Control point 2
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addSpline($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->addSpline($params);
+ }
+ parent::addSpline($params);
+ }
+
+ /**
+ * Draws a polygon
+ *
+ * Parameter array:
+ * 'connect': bool [optional] Specifies whether the start point should be
+ * connected to the endpoint (closed polygon) or not (connected line)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function polygon($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->polygon($params);
+ }
+ parent::polygon($params);
+ }
+
+ /**
+ * Draw a rectangle
+ *
+ * Parameter array:
+ * 'x0': int X start point
+ * 'y0': int Y start point
+ * 'x1': int X end point
+ * 'y1': int Y end point
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function rectangle($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->rectangle($params);
+ }
+ parent::rectangle($params);
+ }
+
+ /**
+ * Draw an ellipse
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function ellipse($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->ellipse($params);
+ }
+ parent::ellipse($params);
+ }
+
+ /**
+ * Draw a pie slice
+ *
+ * Parameter array:
+ * 'x': int X center point
+ * 'y': int Y center point
+ * 'rx': int X radius
+ * 'ry': int Y radius
+ * 'v1': int The starting angle (in degrees)
+ * 'v2': int The end angle (in degrees)
+ * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
+ * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
+ * 'fill': mixed [optional] The fill color
+ * 'line': mixed [optional] The line color
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function pieslice($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->pieslice($params);
+ }
+ parent::pieslice($params);
+ }
+
+ /**
+ * Writes text
+ *
+ * Parameter array:
+ * 'x': int X-point of text
+ * 'y': int Y-point of text
+ * 'text': string The text to add
+ * 'alignment': array [optional] Alignment
+ * 'color': mixed [optional] The color of the text
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function addText($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->addText($params);
+ }
+ parent::addText($params);
+ }
+
+ /**
+ * Overlay image
+ *
+ * Parameter array:
+ * 'x': int X-point of overlayed image
+ * 'y': int Y-point of overlayed image
+ * 'filename': string The filename of the image to overlay
+ * 'width': int [optional] The width of the overlayed image (resizing if possible)
+ * 'height': int [optional] The height of the overlayed image (resizing if possible)
+ * 'alignment': array [optional] Alignment
+ *
+ * @param array $params Parameter array
+ *
+ * @return void
+ */
+ function image($params)
+ {
+ if (isset($this->_imageMap)) {
+ $this->_imageMap->image($params);
+ }
+ parent::image($params);
+ }
+
+ /**
+ * Get the imagemap
+ *
+ * @return Image_Graph_ImageMap The image map (or false if none)
+ */
+ function &getImageMap()
+ {
+ $result = null;
+ if (isset($this->_imageMap)) {
+ $result =& $this->_imageMap;
+ }
+ return $result;
+ }
+
+}
+
+?>
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Color.php is the implementation of Image_Color.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category Image\r
- * @package Image_Color\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @author Andrew Morton <drewish@katherinehouse.com>\r
- * @copyright 2003-2005 The PHP Group\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: Color.php,v 1.17 2008/10/26 18:27:10 clockwerx Exp $\r
- * @link http://pear.php.net/package/Image_Color\r
- */\r
-\r
-/**\r
- * Image_Color handles color conversion and mixing.\r
- *\r
- * The class is quick, simple to use, and does its job fairly well but it's got\r
- * some code smells:\r
- * - Call setColors() for some functions but not others.\r
- * - Different functions expect different color formats. setColors() only\r
- * accepts hex while allocateColor() will accept named or hex (provided the\r
- * hex ones start with the # character).\r
- * - Some conversions go in only one direction, ie HSV->RGB but no RGB->HSV.\r
- * I'm going to try to straighten out some of this but I'll be hard to do so\r
- * without breaking backwards compatibility.\r
- *\r
- * @category Image\r
- * @package Image_Color\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @author Andrew Morton <drewish@katherinehouse.com>\r
- * @copyright 2003-2005 The PHP Group\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version Release: 0.1.2\r
- * @link http://pear.php.net/package/Image_Color\r
- */\r
-class Image_Color\r
-{\r
- /**\r
- * First color that the class handles for ranges and mixes.\r
- * @var array\r
- * @access public\r
- * @see setColors()\r
- */\r
- var $color1 = array();\r
-\r
- /**\r
- * Second color that the class handles for ranges and mixes.\r
- * @var array\r
- * @access public\r
- * @see setColors()\r
- */\r
- var $color2 = array();\r
-\r
- /**\r
- * Boolean value for determining whether colors outputted should be limited\r
- * to the web safe pallet or not.\r
- *\r
- * @var boolean\r
- * @access private\r
- * @see setWebSafe()\r
- */\r
- var $_websafeb = false;\r
-\r
- /**\r
- * Mix two colors together by finding their average. If the colors are not\r
- * passed as parameters, the class's colors will be mixed instead.\r
- *\r
- * @param string $col1 The first color you want to mix\r
- * @param string $col2 The second color you want to mix\r
- * @return string The mixed color.\r
- * @access public\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @uses _setColors() to assign the colors if any are passed to the\r
- * class.\r
- */\r
- function mixColors($col1 = false, $col2 = false)\r
- {\r
- if ($col1) {\r
- $this->_setColors($col1, $col2);\r
- }\r
-\r
- // after finding the average, it will be a float. add 0.5 and then\r
- // cast to an integer to properly round it to an integer.\r
- $color3[0] = (int) ((($this->color1[0] + $this->color2[0]) / 2) + 0.5);\r
- $color3[1] = (int) ((($this->color1[1] + $this->color2[1]) / 2) + 0.5);\r
- $color3[2] = (int) ((($this->color1[2] + $this->color2[2]) / 2) + 0.5);\r
-\r
- if ($this->_websafeb) {\r
- array_walk($color3, '_makeWebSafe');\r
- }\r
-\r
- return Image_Color::rgb2hex($color3);\r
- }\r
-\r
- /**\r
- * Determines whether colors the returned by this class will be rounded to\r
- * the nearest web safe value.\r
- *\r
- * @param boolean $bool Indicates if colors should be limited to the\r
- * websafe pallet.\r
- * @return void\r
- * @access public\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- */\r
- function setWebSafe($bool = true)\r
- {\r
- $this->_websafeb = (boolean) $bool;\r
- }\r
-\r
- /**\r
- * Set the two colors this class uses for mixing and ranges.\r
- *\r
- * @param string $col1 The first color in hex format\r
- * @param string $col2 The second color in hex format\r
- * @return void\r
- * @access public\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- */\r
- function setColors($col1, $col2)\r
- {\r
- $this->_setColors($col1, $col2);\r
- }\r
-\r
- /**\r
- * Get the range of colors between the class's two colors, given a degree.\r
- *\r
- * @param integer $degrees How large a 'step' we should take between the\r
- * colors.\r
- * @return array Returns an array of hex strings, one element for each\r
- * color.\r
- * @access public\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @todo Allow for degrees for individual parts of the colors.\r
- */\r
- function getRange($degrees = 2)\r
- {\r
- if ($degrees == 0) {\r
- $degrees = 1;\r
- }\r
-\r
- // The degrees give us how much we should advance each color at each\r
- // phase of the loop. This way, the advance is equal throughout all\r
- // the colors.\r
-\r
- $red_steps = ($this->color2[0] - $this->color1[0]) / $degrees;\r
- $green_steps = ($this->color2[1] - $this->color1[1]) / $degrees;\r
- $blue_steps = ($this->color2[2] - $this->color1[2]) / $degrees;\r
-\r
- $allcolors = array();\r
-\r
- /**\r
- * The loop stops once any color has gone beyond the end color.\r
- */\r
-\r
- // Loop through all the degrees between the colors\r
- for ($x = 0; $x < $degrees; $x++) {\r
- $col[0] = $red_steps * $x;\r
- $col[1] = $green_steps * $x;\r
- $col[2] = $blue_steps * $x;\r
-\r
- // Loop through each R, G, and B\r
- for ($i = 0; $i < 3; $i++) {\r
- $partcolor = $this->color1[$i] + $col[$i];\r
- // If the color is less than 256\r
- if ($partcolor < 256) {\r
- // Makes sure the colors is not less than 0\r
- if ($partcolor > -1) {\r
- $newcolor[$i] = $partcolor;\r
- } else {\r
- $newcolor[$i] = 0;\r
- }\r
- // Color was greater than 255\r
- } else {\r
- $newcolor[$i] = 255;\r
- }\r
- }\r
-\r
- if ($this->_websafeb) {\r
- array_walk($newcolor, '_makeWebSafe');\r
- }\r
-\r
- $allcolors[] = Image_Color::rgb2hex($newcolor);\r
- }\r
-\r
- return $allcolors;\r
- }\r
-\r
- /**\r
- * Change the lightness of the class's two colors.\r
- *\r
- * @param integer $degree The degree of the change. Positive values\r
- * lighten the color while negative values will darken it.\r
- * @return void\r
- * @access public\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @uses Image_Color::$color1 as an input and return value.\r
- * @uses Image_Color::$color2 as an input and return value.\r
- */\r
- function changeLightness($degree = 10)\r
- {\r
- $color1 =& $this->color1;\r
- $color2 =& $this->color2;\r
-\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Color.php is the implementation of Image_Color.
+ *
+ * PHP versions 4 and 5
+ *
+ * This package is released under both the LGPL and PHP licenses.
+ *
+ *
+ * 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.
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * @category Image
+ * @package Image_Color
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @author Andrew Morton <drewish@katherinehouse.com>
+ * @copyright 2003-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version CVS: $Id: Color.php 299528 2010-05-20 17:45:25Z drewish $
+ * @link http://pear.php.net/package/Image_Color
+ */
+
+/**
+ * Image_Color handles color conversion and mixing.
+ *
+ * The class is quick, simple to use, and does its job fairly well but it's got
+ * some code smells:
+ * - Call setColors() for some functions but not others.
+ * - Different functions expect different color formats. setColors() only
+ * accepts hex while allocateColor() will accept named or hex (provided the
+ * hex ones start with the # character).
+ * - Some conversions go in only one direction, ie HSV->RGB but no RGB->HSV.
+ * I'm going to try to straighten out some of this but I'll be hard to do so
+ * without breaking backwards compatibility.
+ *
+ * @category Image
+ * @package Image_Color
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @author Andrew Morton <drewish@katherinehouse.com>
+ * @copyright 2003-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: 0.1.2
+ * @link http://pear.php.net/package/Image_Color
+ */
+class Image_Color
+{
+ /**
+ * First color that the class handles for ranges and mixes.
+ * @var array
+ * @access public
+ * @see setColors()
+ */
+ var $color1 = array();
+
+ /**
+ * Second color that the class handles for ranges and mixes.
+ * @var array
+ * @access public
+ * @see setColors()
+ */
+ var $color2 = array();
+
+ /**
+ * Boolean value for determining whether colors outputted should be limited
+ * to the web safe pallet or not.
+ *
+ * @var boolean
+ * @access private
+ * @see setWebSafe()
+ */
+ var $_websafeb = false;
+
+ /**
+ * Mix two colors together by finding their average. If the colors are not
+ * passed as parameters, the class's colors will be mixed instead.
+ *
+ * @param string $col1 The first color you want to mix
+ * @param string $col2 The second color you want to mix
+ * @return string The mixed color.
+ * @access public
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @uses _setColors() to assign the colors if any are passed to the
+ * class.
+ */
+ function mixColors($col1 = false, $col2 = false)
+ {
+ if ($col1) {
+ $this->_setColors($col1, $col2);
+ }
+
+ // after finding the average, it will be a float. add 0.5 and then
+ // cast to an integer to properly round it to an integer.
+ $color3[0] = (int) ((($this->color1[0] + $this->color2[0]) / 2) + 0.5);
+ $color3[1] = (int) ((($this->color1[1] + $this->color2[1]) / 2) + 0.5);
+ $color3[2] = (int) ((($this->color1[2] + $this->color2[2]) / 2) + 0.5);
+
+ if ($this->_websafeb) {
+ array_walk($color3, '_makeWebSafe');
+ }
+
+ return Image_Color::rgb2hex($color3);
+ }
+
+ /**
+ * Determines whether colors the returned by this class will be rounded to
+ * the nearest web safe value.
+ *
+ * @param boolean $bool Indicates if colors should be limited to the
+ * websafe pallet.
+ * @return void
+ * @access public
+ * @author Jason Lotito <jason@lehighweb.com>
+ */
+ function setWebSafe($bool = true)
+ {
+ $this->_websafeb = (boolean) $bool;
+ }
+
+ /**
+ * Set the two colors this class uses for mixing and ranges.
+ *
+ * @param string $col1 The first color in hex format
+ * @param string $col2 The second color in hex format
+ * @return void
+ * @access public
+ * @author Jason Lotito <jason@lehighweb.com>
+ */
+ function setColors($col1, $col2)
+ {
+ $this->_setColors($col1, $col2);
+ }
+
+ /**
+ * Get the range of colors between the class's two colors, given a degree.
+ *
+ * @param integer $degrees How large a 'step' we should take between the
+ * colors.
+ * @return array Returns an array of hex strings, one element for each
+ * color.
+ * @access public
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @todo Allow for degrees for individual parts of the colors.
+ */
+ function getRange($degrees = 2)
+ {
+ if ($degrees == 0) {
+ $degrees = 1;
+ }
+
+ // The degrees give us how much we should advance each color at each
+ // phase of the loop. This way, the advance is equal throughout all
+ // the colors.
+
+ $red_steps = ($this->color2[0] - $this->color1[0]) / $degrees;
+ $green_steps = ($this->color2[1] - $this->color1[1]) / $degrees;
+ $blue_steps = ($this->color2[2] - $this->color1[2]) / $degrees;
+
+ $allcolors = array();
+
+ /**
+ * The loop stops once any color has gone beyond the end color.
+ */
+
+ // Loop through all the degrees between the colors
+ for ($x = 0; $x < $degrees; $x++) {
+ $col[0] = $red_steps * $x;
+ $col[1] = $green_steps * $x;
+ $col[2] = $blue_steps * $x;
+
+ // Loop through each R, G, and B
+ for ($i = 0; $i < 3; $i++) {
+ $partcolor = $this->color1[$i] + $col[$i];
+ // If the color is less than 256
+ if ($partcolor < 256) {
+ // Makes sure the colors is not less than 0
+ if ($partcolor > -1) {
+ $newcolor[$i] = $partcolor;
+ } else {
+ $newcolor[$i] = 0;
+ }
+ // Color was greater than 255
+ } else {
+ $newcolor[$i] = 255;
+ }
+ }
+
+ if ($this->_websafeb) {
+ array_walk($newcolor, '_makeWebSafe');
+ }
+
+ $allcolors[] = Image_Color::rgb2hex($newcolor);
+ }
+
+ return $allcolors;
+ }
+
+ /**
+ * Change the lightness of the class's two colors.
+ *
+ * @param integer $degree The degree of the change. Positive values
+ * lighten the color while negative values will darken it.
+ * @return void
+ * @access public
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @uses Image_Color::$color1 as an input and return value.
+ * @uses Image_Color::$color2 as an input and return value.
+ */
+ function changeLightness($degree = 10)
+ {
+ $color1 =& $this->color1;
+ $color2 =& $this->color2;
+
for ($x = 0; $x < 3; $x++) {
- if (isset($color1[$x])) {\r
- if (($color1[$x] + $degree) < 256) {\r
- if (($color1[$x] + $degree) > -1) {\r
- $color1[$x] += $degree;\r
- } else {\r
- $color1[$x] = 0;\r
- }\r
- } else {\r
- $color1[$x] = 255;\r
+ if (isset($color1[$x])) {
+ if (($color1[$x] + $degree) < 256) {
+ if (($color1[$x] + $degree) > -1) {
+ $color1[$x] += $degree;
+ } else {
+ $color1[$x] = 0;
+ }
+ } else {
+ $color1[$x] = 255;
}
- }\r
-
- if (isset($color2[$x])) {\r
- if (($color2[$x] + $degree) < 256) {\r
- if (($color2[$x] + $degree) > -1) {\r
- $color2[$x] += $degree;\r
- } else {\r
- $color2[$x] = 0;\r
- }\r
- } else {\r
- $color2[$x] = 255;\r
+ }
+
+ if (isset($color2[$x])) {
+ if (($color2[$x] + $degree) < 256) {
+ if (($color2[$x] + $degree) > -1) {
+ $color2[$x] += $degree;
+ } else {
+ $color2[$x] = 0;
+ }
+ } else {
+ $color2[$x] = 255;
}
- }\r
- }\r
- }\r
-\r
- /**\r
- * Determine if a light or dark text color would be more readable on a\r
- * background of a given color. This is determined by the G(reen) value of\r
- * RGB. You can change the dark and the light colors from their default\r
- * black and white.\r
- *\r
- * @param string $color The hex color to analyze\r
- * @param string $light The light color value to return if we should\r
- * have light text.\r
- * @param string $dark The dark color value to return if we should have\r
- * dark text.\r
- * @return string The light or dark value which would make the text most\r
- * readable.\r
- * @access public\r
- * @static\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- */\r
- function getTextColor($color, $light = '#FFFFFF', $dark = '#000000')\r
- {\r
- $color = Image_Color::_splitColor($color);\r
- if ($color[1] > hexdec('66')) {\r
- return $dark;\r
- } else {\r
- return $light;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Internal method to set the colors.\r
- *\r
- * @param string $col1 First color, either a name or hex value\r
- * @param string $col2 Second color, either a name or hex value\r
- * @return void\r
- * @access private\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- */\r
- function _setColors($col1, $col2)\r
- {\r
- if ($col1) {\r
- $this->color1 = Image_Color::_splitColor($col1);\r
- }\r
- if ($col2) {\r
- $this->color2 = Image_Color::_splitColor($col2);\r
- }\r
- }\r
-\r
- /**\r
- * Given a color, properly split it up into a 3 element RGB array.\r
- *\r
- * @param string $color The color.\r
- * @return array A three element RGB array.\r
- * @access private\r
- * @static\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- */\r
- function _splitColor($color)\r
- {\r
- $color = str_replace('#', '', $color);\r
- $c[] = hexdec(substr($color, 0, 2));\r
- $c[] = hexdec(substr($color, 2, 2));\r
- $c[] = hexdec(substr($color, 4, 2));\r
- return $c;\r
- }\r
-\r
- /**\r
- * This is deprecated. Use rgb2hex() instead.\r
- * @access private\r
- * @deprecated Function deprecated after 1.0.1\r
- * @see rgb2hex().\r
- */\r
- function _returnColor ( $color )\r
- {\r
- return Image_Color::rgb2hex($color);\r
- }\r
-\r
- /**\r
- * Convert an RGB array to a hex string.\r
- *\r
- * @param array $color 3 element RGB array.\r
- * @return string Hex color string.\r
- * @access public\r
- * @static\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @see hex2rgb()\r
- */\r
- function rgb2hex($color)\r
- {\r
- return sprintf('%02X%02X%02X',$color[0],$color[1],$color[2]);\r
- }\r
-\r
- /**\r
- * Convert a hex color string into an RGB array. An extra fourth element\r
- * will be returned with the original hex value.\r
- *\r
- * @param string $hex Hex color string.\r
- * @return array RGB color array with an extra 'hex' element containing\r
- * the original hex string.\r
- * @access public\r
- * @static\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @see rgb2hex()\r
- */\r
- function hex2rgb($hex)\r
- {\r
- $return = Image_Color::_splitColor($hex);\r
- $return['hex'] = $hex;\r
- return $return;\r
- }\r
-\r
- /**\r
- * Convert an HSV (Hue, Saturation, Brightness) value to RGB.\r
- *\r
- * @param integer $h Hue\r
- * @param integer $s Saturation\r
- * @param integer $v Brightness\r
- * @return array RGB array.\r
- * @access public\r
- * @static\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @uses hsv2hex() to convert the HSV value to Hex.\r
- * @uses hex2rgb() to convert the Hex value to RGB.\r
- */\r
- function hsv2rgb($h, $s, $v)\r
- {\r
- return Image_Color::hex2rgb(Image_Color::hsv2hex($h, $s, $v));\r
- }\r
-\r
- /**\r
- * Convert HSV (Hue, Saturation, Brightness) to a hex color string.\r
- *\r
- * Originally written by Jurgen Schwietering. Integrated into the class by\r
- * Jason Lotito.\r
- *\r
- * @param integer $h Hue\r
- * @param integer $s Saturation\r
- * @param integer $v Brightness\r
- * @return string The hex string.\r
- * @access public\r
- * @static\r
- * @author Jurgen Schwietering <jurgen@schwietering.com>\r
- * @uses rgb2hex() to convert the return value to a hex string.\r
- */\r
- function hsv2hex($h, $s, $v)\r
- {\r
- $s /= 256.0;\r
- $v /= 256.0;\r
- if ($s == 0.0) {\r
- $r = $g = $b = $v;\r
- return '';\r
- } else {\r
- $h = $h / 256.0 * 6.0;\r
- $i = floor($h);\r
- $f = $h - $i;\r
-\r
- $v *= 256.0;\r
- $p = (integer)($v * (1.0 - $s));\r
- $q = (integer)($v * (1.0 - $s * $f));\r
- $t = (integer)($v * (1.0 - $s * (1.0 - $f)));\r
- switch($i) {\r
- case 0:\r
- $r = $v;\r
- $g = $t;\r
- $b = $p;\r
- break;\r
-\r
- case 1:\r
- $r = $q;\r
- $g = $v;\r
- $b = $p;\r
- break;\r
-\r
- case 2:\r
- $r = $p;\r
- $g = $v;\r
- $b = $t;\r
- break;\r
-\r
- case 3:\r
- $r = $p;\r
- $g = $q;\r
- $b = $v;\r
- break;\r
-\r
- case 4:\r
- $r = $t;\r
- $g = $p;\r
- $b = $v;\r
- break;\r
-\r
- default:\r
- $r = $v;\r
- $g = $p;\r
- $b = $q;\r
- break;\r
- }\r
- }\r
- return Image_Color::rgb2hex(array($r, $g, $b));\r
- }\r
-\r
- /**\r
- * Allocates a color in the given image.\r
- *\r
- * User defined color specifications get translated into an array of RGB\r
- * values.\r
- *\r
- * @param resource $img Image handle\r
- * @param string|array $color Name or hex string or an RGB array.\r
- * @return resource Image color handle.\r
- * @access public\r
- * @static\r
- * @uses ImageColorAllocate() to allocate the color.\r
- * @uses color2RGB() to parse the color into RGB values.\r
- */\r
- function allocateColor(&$img, $color) {\r
- $color = Image_Color::color2RGB($color);\r
-\r
- return ImageColorAllocate($img, $color[0], $color[1], $color[2]);\r
- }\r
-\r
- /**\r
- * Convert a named or hex color string to an RGB array. If the color begins\r
- * with the # character it will be treated as a hex value. Everything else\r
- * will be treated as a named color. If the named color is not known, black\r
- * will be returned.\r
- *\r
- * @param string $color\r
- * @return array RGB color\r
- * @access public\r
- * @static\r
- * @author Laurent Laville <pear@laurent-laville.org>\r
- * @uses hex2rgb() to convert colors begining with the # character.\r
- * @uses namedColor2RGB() to convert everything not starting with a #.\r
- */\r
- function color2RGB($color)\r
- {\r
- $c = array();\r
-\r
- if ($color{0} == '#') {\r
- $c = Image_Color::hex2rgb($color);\r
- } else {\r
- $c = Image_Color::namedColor2RGB($color);\r
- }\r
-\r
- return $c;\r
- }\r
-\r
- /**\r
- * Convert a named color to an RGB array. If the color is unknown black\r
- * is returned.\r
- *\r
- * @param string $color Case insensitive color name.\r
- * @return array RGB color array. If the color was unknown, the result\r
- * will be black.\r
- * @access public\r
- * @static\r
- * @author Sebastian Bergmann <sb@sebastian-bergmann.de>\r
- */\r
- function namedColor2RGB($color)\r
- {\r
- static $colornames;\r
-\r
- if (!isset($colornames)) {\r
- $colornames = array(\r
- 'aliceblue' => array(240, 248, 255),\r
- 'antiquewhite' => array(250, 235, 215),\r
- 'aqua' => array( 0, 255, 255),\r
- 'aquamarine' => array(127, 255, 212),\r
- 'azure' => array(240, 255, 255),\r
- 'beige' => array(245, 245, 220),\r
- 'bisque' => array(255, 228, 196),\r
- 'black' => array( 0, 0, 0),\r
- 'blanchedalmond' => array(255, 235, 205),\r
- 'blue' => array( 0, 0, 255),\r
- 'blueviolet' => array(138, 43, 226),\r
- 'brown' => array(165, 42, 42),\r
- 'burlywood' => array(222, 184, 135),\r
- 'cadetblue' => array( 95, 158, 160),\r
- 'chartreuse' => array(127, 255, 0),\r
- 'chocolate' => array(210, 105, 30),\r
- 'coral' => array(255, 127, 80),\r
- 'cornflowerblue' => array(100, 149, 237),\r
- 'cornsilk' => array(255, 248, 220),\r
- 'crimson' => array(220, 20, 60),\r
- 'cyan' => array( 0, 255, 255),\r
- 'darkblue' => array( 0, 0, 13),\r
- 'darkcyan' => array( 0, 139, 139),\r
- 'darkgoldenrod' => array(184, 134, 11),\r
- 'darkgray' => array(169, 169, 169),\r
- 'darkgreen' => array( 0, 100, 0),\r
- 'darkkhaki' => array(189, 183, 107),\r
- 'darkmagenta' => array(139, 0, 139),\r
- 'darkolivegreen' => array( 85, 107, 47),\r
- 'darkorange' => array(255, 140, 0),\r
- 'darkorchid' => array(153, 50, 204),\r
- 'darkred' => array(139, 0, 0),\r
- 'darksalmon' => array(233, 150, 122),\r
- 'darkseagreen' => array(143, 188, 143),\r
- 'darkslateblue' => array( 72, 61, 139),\r
- 'darkslategray' => array( 47, 79, 79),\r
- 'darkturquoise' => array( 0, 206, 209),\r
- 'darkviolet' => array(148, 0, 211),\r
- 'deeppink' => array(255, 20, 147),\r
- 'deepskyblue' => array( 0, 191, 255),\r
- 'dimgray' => array(105, 105, 105),\r
- 'dodgerblue' => array( 30, 144, 255),\r
- 'firebrick' => array(178, 34, 34),\r
- 'floralwhite' => array(255, 250, 240),\r
- 'forestgreen' => array( 34, 139, 34),\r
- 'fuchsia' => array(255, 0, 255),\r
- 'gainsboro' => array(220, 220, 220),\r
- 'ghostwhite' => array(248, 248, 255),\r
- 'gold' => array(255, 215, 0),\r
- 'goldenrod' => array(218, 165, 32),\r
- 'gray' => array(128, 128, 128),\r
- 'green' => array( 0, 128, 0),\r
- 'greenyellow' => array(173, 255, 47),\r
- 'honeydew' => array(240, 255, 240),\r
- 'hotpink' => array(255, 105, 180),\r
- 'indianred' => array(205, 92, 92),\r
- 'indigo' => array(75, 0, 130),\r
- 'ivory' => array(255, 255, 240),\r
- 'khaki' => array(240, 230, 140),\r
- 'lavender' => array(230, 230, 250),\r
- 'lavenderblush' => array(255, 240, 245),\r
- 'lawngreen' => array(124, 252, 0),\r
- 'lemonchiffon' => array(255, 250, 205),\r
- 'lightblue' => array(173, 216, 230),\r
- 'lightcoral' => array(240, 128, 128),\r
- 'lightcyan' => array(224, 255, 255),\r
- 'lightgoldenrodyellow' => array(250, 250, 210),\r
- 'lightgreen' => array(144, 238, 144),\r
- 'lightgrey' => array(211, 211, 211),\r
- 'lightpink' => array(255, 182, 193),\r
- 'lightsalmon' => array(255, 160, 122),\r
- 'lightseagreen' => array( 32, 178, 170),\r
- 'lightskyblue' => array(135, 206, 250),\r
- 'lightslategray' => array(119, 136, 153),\r
- 'lightsteelblue' => array(176, 196, 222),\r
- 'lightyellow' => array(255, 255, 224),\r
- 'lime' => array( 0, 255, 0),\r
- 'limegreen' => array( 50, 205, 50),\r
- 'linen' => array(250, 240, 230),\r
- 'magenta' => array(255, 0, 255),\r
- 'maroon' => array(128, 0, 0),\r
- 'mediumaquamarine' => array(102, 205, 170),\r
- 'mediumblue' => array( 0, 0, 205),\r
- 'mediumorchid' => array(186, 85, 211),\r
- 'mediumpurple' => array(147, 112, 219),\r
- 'mediumseagreen' => array( 60, 179, 113),\r
- 'mediumslateblue' => array(123, 104, 238),\r
- 'mediumspringgreen' => array( 0, 250, 154),\r
- 'mediumturquoise' => array(72, 209, 204),\r
- 'mediumvioletred' => array(199, 21, 133),\r
- 'midnightblue' => array( 25, 25, 112),\r
- 'mintcream' => array(245, 255, 250),\r
- 'mistyrose' => array(255, 228, 225),\r
- 'moccasin' => array(255, 228, 181),\r
- 'navajowhite' => array(255, 222, 173),\r
- 'navy' => array( 0, 0, 128),\r
- 'oldlace' => array(253, 245, 230),\r
- 'olive' => array(128, 128, 0),\r
- 'olivedrab' => array(107, 142, 35),\r
- 'orange' => array(255, 165, 0),\r
- 'orangered' => array(255, 69, 0),\r
- 'orchid' => array(218, 112, 214),\r
- 'palegoldenrod' => array(238, 232, 170),\r
- 'palegreen' => array(152, 251, 152),\r
- 'paleturquoise' => array(175, 238, 238),\r
- 'palevioletred' => array(219, 112, 147),\r
- 'papayawhip' => array(255, 239, 213),\r
- 'peachpuff' => array(255, 218, 185),\r
- 'peru' => array(205, 133, 63),\r
- 'pink' => array(255, 192, 203),\r
- 'plum' => array(221, 160, 221),\r
- 'powderblue' => array(176, 224, 230),\r
- 'purple' => array(128, 0, 128),\r
- 'red' => array(255, 0, 0),\r
- 'rosybrown' => array(188, 143, 143),\r
- 'royalblue' => array( 65, 105, 225),\r
- 'saddlebrown' => array(139, 69, 19),\r
- 'salmon' => array(250, 128, 114),\r
- 'sandybrown' => array(244, 164, 96),\r
- 'seagreen' => array( 46, 139, 87),\r
- 'seashell' => array(255, 245, 238),\r
- 'sienna' => array(160, 82, 45),\r
- 'silver' => array(192, 192, 192),\r
- 'skyblue' => array(135, 206, 235),\r
- 'slateblue' => array(106, 90, 205),\r
- 'slategray' => array(112, 128, 144),\r
- 'snow' => array(255, 250, 250),\r
- 'springgreen' => array( 0, 255, 127),\r
- 'steelblue' => array( 70, 130, 180),\r
- 'tan' => array(210, 180, 140),\r
- 'teal' => array( 0, 128, 128),\r
- 'thistle' => array(216, 191, 216),\r
- 'tomato' => array(255, 99, 71),\r
- 'turquoise' => array( 64, 224, 208),\r
- 'violet' => array(238, 130, 238),\r
- 'wheat' => array(245, 222, 179),\r
- 'white' => array(255, 255, 255),\r
- 'whitesmoke' => array(245, 245, 245),\r
- 'yellow' => array(255, 255, 0),\r
- 'yellowgreen' => array(154, 205, 50)\r
- );\r
- }\r
-\r
- $color = strtolower($color);\r
-\r
- if (isset($colornames[$color])) {\r
- return $colornames[$color];\r
- } else {\r
- return array(0, 0, 0);\r
- }\r
- }\r
-\r
- /**\r
- * Convert an RGB percentage string into an RGB array.\r
- *\r
- * @param string $color Percentage color string like "50%,20%,100%".\r
- * @return array RGB color array.\r
- * @access public\r
- * @static\r
- */\r
- function percentageColor2RGB($color)\r
- {\r
- // remove spaces\r
- $color = str_replace(' ', '', $color);\r
- // remove the percent signs\r
- $color = str_replace('%', '', $color);\r
- // split the string by commas\r
- $color = explode(',', $color);\r
-\r
- $ret = array();\r
- foreach ($color as $k => $v) {\r
- // range checks\r
- if ($v <= 0) {\r
- $ret[$k] = 0;\r
- } else if ($v <= 100) {\r
- // add 0.5 then cast to an integer to round the value.\r
- $ret[$k] = (integer) ((2.55 * $v) + 0.5);\r
- } else {\r
- $ret[$k] = 255;\r
- }\r
- }\r
-\r
- return $ret;\r
- }\r
-}\r
-\r
-// For Array Walk\r
-// {{{\r
-/**\r
- * Function for array_walk() to round colors to the closest web safe value.\r
- *\r
- * @param integer $color One channel of an RGB color.\r
- * @return integer The websafe equivalent of the color channel.\r
- * @author Jason Lotito <jason@lehighweb.com>\r
- * @author Andrew Morton <drewish@katherinehouse.com>\r
- * @access private\r
- * @static\r
- */\r
-function _makeWebSafe(&$color)\r
-{\r
- if ($color < 0x1a) {\r
- $color = 0x00;\r
- } else if ($color < 0x4d) {\r
- $color = 0x33;\r
- } else if ($color < 0x80) {\r
- $color = 0x66;\r
- } else if ($color < 0xB3) {\r
- $color = 0x99;\r
- } else if ($color < 0xE6) {\r
- $color = 0xCC;\r
- } else {\r
- $color = 0xFF;\r
- }\r
- return $color;\r
-}\r
-// }}}\r
-\r
-?>\r
+ }
+ }
+ }
+
+ /**
+ * Determine if a light or dark text color would be more readable on a
+ * background of a given color. This is determined by the G(reen) value of
+ * RGB. You can change the dark and the light colors from their default
+ * black and white.
+ *
+ * @param string $color The hex color to analyze
+ * @param string $light The light color value to return if we should
+ * have light text.
+ * @param string $dark The dark color value to return if we should have
+ * dark text.
+ * @return string The light or dark value which would make the text most
+ * readable.
+ * @access public
+ * @static
+ * @author Jason Lotito <jason@lehighweb.com>
+ */
+ function getTextColor($color, $light = '#FFFFFF', $dark = '#000000')
+ {
+ $color = Image_Color::_splitColor($color);
+ if ($color[1] > hexdec('66')) {
+ return $dark;
+ } else {
+ return $light;
+ }
+ }
+
+
+ /**
+ * Internal method to set the colors.
+ *
+ * @param string $col1 First color, either a name or hex value
+ * @param string $col2 Second color, either a name or hex value
+ * @return void
+ * @access private
+ * @author Jason Lotito <jason@lehighweb.com>
+ */
+ function _setColors($col1, $col2)
+ {
+ if ($col1) {
+ $this->color1 = Image_Color::_splitColor($col1);
+ }
+ if ($col2) {
+ $this->color2 = Image_Color::_splitColor($col2);
+ }
+ }
+
+ /**
+ * Given a color, properly split it up into a 3 element RGB array.
+ *
+ * @param string $color The color.
+ * @return array A three element RGB array.
+ * @access private
+ * @static
+ * @author Jason Lotito <jason@lehighweb.com>
+ */
+ function _splitColor($color)
+ {
+ $color = str_replace('#', '', $color);
+ $c[] = hexdec(substr($color, 0, 2));
+ $c[] = hexdec(substr($color, 2, 2));
+ $c[] = hexdec(substr($color, 4, 2));
+ return $c;
+ }
+
+ /**
+ * This is deprecated. Use rgb2hex() instead.
+ * @access private
+ * @deprecated Function deprecated after 1.0.1
+ * @see rgb2hex().
+ */
+ function _returnColor ( $color )
+ {
+ return Image_Color::rgb2hex($color);
+ }
+
+ /**
+ * Convert an RGB array to a hex string.
+ *
+ * @param array $color 3 element RGB array.
+ * @return string Hex color string.
+ * @access public
+ * @static
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @see hex2rgb()
+ */
+ function rgb2hex($color)
+ {
+ return sprintf('%02X%02X%02X',$color[0],$color[1],$color[2]);
+ }
+
+ /**
+ * Convert a hex color string into an RGB array. An extra fourth element
+ * will be returned with the original hex value.
+ *
+ * @param string $hex Hex color string.
+ * @return array RGB color array with an extra 'hex' element containing
+ * the original hex string.
+ * @access public
+ * @static
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @see rgb2hex()
+ */
+ function hex2rgb($hex)
+ {
+ $return = Image_Color::_splitColor($hex);
+ $return['hex'] = $hex;
+ return $return;
+ }
+
+ /**
+ * Convert an HSV (Hue, Saturation, Brightness) value to RGB.
+ *
+ * @param integer $h Hue
+ * @param integer $s Saturation
+ * @param integer $v Brightness
+ * @return array RGB array.
+ * @access public
+ * @static
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @uses hsv2hex() to convert the HSV value to Hex.
+ * @uses hex2rgb() to convert the Hex value to RGB.
+ */
+ function hsv2rgb($h, $s, $v)
+ {
+ return Image_Color::hex2rgb(Image_Color::hsv2hex($h, $s, $v));
+ }
+
+ /**
+ * Convert HSV (Hue, Saturation, Brightness) to a hex color string.
+ *
+ * Originally written by Jurgen Schwietering. Integrated into the class by
+ * Jason Lotito.
+ *
+ * @param integer $h Hue
+ * @param integer $s Saturation
+ * @param integer $v Brightness
+ * @return string The hex string.
+ * @access public
+ * @static
+ * @author Jurgen Schwietering <jurgen@schwietering.com>
+ * @uses rgb2hex() to convert the return value to a hex string.
+ */
+ function hsv2hex($h, $s, $v)
+ {
+ $s /= 256.0;
+ $v /= 256.0;
+ if ($s == 0.0) {
+ $r = $g = $b = $v;
+ return '';
+ } else {
+ $h = $h / 256.0 * 6.0;
+ $i = floor($h);
+ $f = $h - $i;
+
+ $v *= 256.0;
+ $p = (integer)($v * (1.0 - $s));
+ $q = (integer)($v * (1.0 - $s * $f));
+ $t = (integer)($v * (1.0 - $s * (1.0 - $f)));
+ switch($i) {
+ case 0:
+ $r = $v;
+ $g = $t;
+ $b = $p;
+ break;
+
+ case 1:
+ $r = $q;
+ $g = $v;
+ $b = $p;
+ break;
+
+ case 2:
+ $r = $p;
+ $g = $v;
+ $b = $t;
+ break;
+
+ case 3:
+ $r = $p;
+ $g = $q;
+ $b = $v;
+ break;
+
+ case 4:
+ $r = $t;
+ $g = $p;
+ $b = $v;
+ break;
+
+ default:
+ $r = $v;
+ $g = $p;
+ $b = $q;
+ break;
+ }
+ }
+ return Image_Color::rgb2hex(array($r, $g, $b));
+ }
+
+ /**
+ * Allocates a color in the given image.
+ *
+ * User defined color specifications get translated into an array of RGB
+ * values.
+ *
+ * @param resource $img Image handle
+ * @param string|array $color Name or hex string or an RGB array.
+ * @return resource Image color handle.
+ * @access public
+ * @static
+ * @uses ImageColorAllocate() to allocate the color.
+ * @uses color2RGB() to parse the color into RGB values.
+ */
+ function allocateColor(&$img, $color) {
+ $color = Image_Color::color2RGB($color);
+
+ return ImageColorAllocate($img, $color[0], $color[1], $color[2]);
+ }
+
+ /**
+ * Convert a named or hex color string to an RGB array. If the color begins
+ * with the # character it will be treated as a hex value. Everything else
+ * will be treated as a named color. If the named color is not known, black
+ * will be returned.
+ *
+ * @param string $color
+ * @return array RGB color
+ * @access public
+ * @static
+ * @author Laurent Laville <pear@laurent-laville.org>
+ * @uses hex2rgb() to convert colors begining with the # character.
+ * @uses namedColor2RGB() to convert everything not starting with a #.
+ */
+ function color2RGB($color)
+ {
+ $c = array();
+
+ if ($color{0} == '#') {
+ $c = Image_Color::hex2rgb($color);
+ } else {
+ $c = Image_Color::namedColor2RGB($color);
+ }
+
+ return $c;
+ }
+
+ /**
+ * Convert a named color to an RGB array. If the color is unknown black
+ * is returned.
+ *
+ * @param string $color Case insensitive color name.
+ * @return array RGB color array. If the color was unknown, the result
+ * will be black.
+ * @access public
+ * @static
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ */
+ function namedColor2RGB($color)
+ {
+ static $colornames;
+
+ if (!isset($colornames)) {
+ $colornames = array(
+ 'aliceblue' => array(240, 248, 255),
+ 'antiquewhite' => array(250, 235, 215),
+ 'aqua' => array( 0, 255, 255),
+ 'aquamarine' => array(127, 255, 212),
+ 'azure' => array(240, 255, 255),
+ 'beige' => array(245, 245, 220),
+ 'bisque' => array(255, 228, 196),
+ 'black' => array( 0, 0, 0),
+ 'blanchedalmond' => array(255, 235, 205),
+ 'blue' => array( 0, 0, 255),
+ 'blueviolet' => array(138, 43, 226),
+ 'brown' => array(165, 42, 42),
+ 'burlywood' => array(222, 184, 135),
+ 'cadetblue' => array( 95, 158, 160),
+ 'chartreuse' => array(127, 255, 0),
+ 'chocolate' => array(210, 105, 30),
+ 'coral' => array(255, 127, 80),
+ 'cornflowerblue' => array(100, 149, 237),
+ 'cornsilk' => array(255, 248, 220),
+ 'crimson' => array(220, 20, 60),
+ 'cyan' => array( 0, 255, 255),
+ 'darkblue' => array( 0, 0, 13),
+ 'darkcyan' => array( 0, 139, 139),
+ 'darkgoldenrod' => array(184, 134, 11),
+ 'darkgray' => array(169, 169, 169),
+ 'darkgreen' => array( 0, 100, 0),
+ 'darkkhaki' => array(189, 183, 107),
+ 'darkmagenta' => array(139, 0, 139),
+ 'darkolivegreen' => array( 85, 107, 47),
+ 'darkorange' => array(255, 140, 0),
+ 'darkorchid' => array(153, 50, 204),
+ 'darkred' => array(139, 0, 0),
+ 'darksalmon' => array(233, 150, 122),
+ 'darkseagreen' => array(143, 188, 143),
+ 'darkslateblue' => array( 72, 61, 139),
+ 'darkslategray' => array( 47, 79, 79),
+ 'darkturquoise' => array( 0, 206, 209),
+ 'darkviolet' => array(148, 0, 211),
+ 'deeppink' => array(255, 20, 147),
+ 'deepskyblue' => array( 0, 191, 255),
+ 'dimgray' => array(105, 105, 105),
+ 'dodgerblue' => array( 30, 144, 255),
+ 'firebrick' => array(178, 34, 34),
+ 'floralwhite' => array(255, 250, 240),
+ 'forestgreen' => array( 34, 139, 34),
+ 'fuchsia' => array(255, 0, 255),
+ 'gainsboro' => array(220, 220, 220),
+ 'ghostwhite' => array(248, 248, 255),
+ 'gold' => array(255, 215, 0),
+ 'goldenrod' => array(218, 165, 32),
+ 'gray' => array(128, 128, 128),
+ 'green' => array( 0, 128, 0),
+ 'greenyellow' => array(173, 255, 47),
+ 'honeydew' => array(240, 255, 240),
+ 'hotpink' => array(255, 105, 180),
+ 'indianred' => array(205, 92, 92),
+ 'indigo' => array(75, 0, 130),
+ 'ivory' => array(255, 255, 240),
+ 'khaki' => array(240, 230, 140),
+ 'lavender' => array(230, 230, 250),
+ 'lavenderblush' => array(255, 240, 245),
+ 'lawngreen' => array(124, 252, 0),
+ 'lemonchiffon' => array(255, 250, 205),
+ 'lightblue' => array(173, 216, 230),
+ 'lightcoral' => array(240, 128, 128),
+ 'lightcyan' => array(224, 255, 255),
+ 'lightgoldenrodyellow' => array(250, 250, 210),
+ 'lightgreen' => array(144, 238, 144),
+ 'lightgrey' => array(211, 211, 211),
+ 'lightpink' => array(255, 182, 193),
+ 'lightsalmon' => array(255, 160, 122),
+ 'lightseagreen' => array( 32, 178, 170),
+ 'lightskyblue' => array(135, 206, 250),
+ 'lightslategray' => array(119, 136, 153),
+ 'lightsteelblue' => array(176, 196, 222),
+ 'lightyellow' => array(255, 255, 224),
+ 'lime' => array( 0, 255, 0),
+ 'limegreen' => array( 50, 205, 50),
+ 'linen' => array(250, 240, 230),
+ 'magenta' => array(255, 0, 255),
+ 'maroon' => array(128, 0, 0),
+ 'mediumaquamarine' => array(102, 205, 170),
+ 'mediumblue' => array( 0, 0, 205),
+ 'mediumorchid' => array(186, 85, 211),
+ 'mediumpurple' => array(147, 112, 219),
+ 'mediumseagreen' => array( 60, 179, 113),
+ 'mediumslateblue' => array(123, 104, 238),
+ 'mediumspringgreen' => array( 0, 250, 154),
+ 'mediumturquoise' => array(72, 209, 204),
+ 'mediumvioletred' => array(199, 21, 133),
+ 'midnightblue' => array( 25, 25, 112),
+ 'mintcream' => array(245, 255, 250),
+ 'mistyrose' => array(255, 228, 225),
+ 'moccasin' => array(255, 228, 181),
+ 'navajowhite' => array(255, 222, 173),
+ 'navy' => array( 0, 0, 128),
+ 'oldlace' => array(253, 245, 230),
+ 'olive' => array(128, 128, 0),
+ 'olivedrab' => array(107, 142, 35),
+ 'orange' => array(255, 165, 0),
+ 'orangered' => array(255, 69, 0),
+ 'orchid' => array(218, 112, 214),
+ 'palegoldenrod' => array(238, 232, 170),
+ 'palegreen' => array(152, 251, 152),
+ 'paleturquoise' => array(175, 238, 238),
+ 'palevioletred' => array(219, 112, 147),
+ 'papayawhip' => array(255, 239, 213),
+ 'peachpuff' => array(255, 218, 185),
+ 'peru' => array(205, 133, 63),
+ 'pink' => array(255, 192, 203),
+ 'plum' => array(221, 160, 221),
+ 'powderblue' => array(176, 224, 230),
+ 'purple' => array(128, 0, 128),
+ 'red' => array(255, 0, 0),
+ 'rosybrown' => array(188, 143, 143),
+ 'royalblue' => array( 65, 105, 225),
+ 'saddlebrown' => array(139, 69, 19),
+ 'salmon' => array(250, 128, 114),
+ 'sandybrown' => array(244, 164, 96),
+ 'seagreen' => array( 46, 139, 87),
+ 'seashell' => array(255, 245, 238),
+ 'sienna' => array(160, 82, 45),
+ 'silver' => array(192, 192, 192),
+ 'skyblue' => array(135, 206, 235),
+ 'slateblue' => array(106, 90, 205),
+ 'slategray' => array(112, 128, 144),
+ 'snow' => array(255, 250, 250),
+ 'springgreen' => array( 0, 255, 127),
+ 'steelblue' => array( 70, 130, 180),
+ 'tan' => array(210, 180, 140),
+ 'teal' => array( 0, 128, 128),
+ 'thistle' => array(216, 191, 216),
+ 'tomato' => array(255, 99, 71),
+ 'turquoise' => array( 64, 224, 208),
+ 'violet' => array(238, 130, 238),
+ 'wheat' => array(245, 222, 179),
+ 'white' => array(255, 255, 255),
+ 'whitesmoke' => array(245, 245, 245),
+ 'yellow' => array(255, 255, 0),
+ 'yellowgreen' => array(154, 205, 50)
+ );
+ }
+
+ $color = strtolower($color);
+
+ if (isset($colornames[$color])) {
+ return $colornames[$color];
+ } else {
+ return array(0, 0, 0);
+ }
+ }
+
+ /**
+ * Convert an RGB percentage string into an RGB array.
+ *
+ * @param string $color Percentage color string like "50%,20%,100%".
+ * @return array RGB color array.
+ * @access public
+ * @static
+ */
+ function percentageColor2RGB($color)
+ {
+ // remove spaces
+ $color = str_replace(' ', '', $color);
+ // remove the percent signs
+ $color = str_replace('%', '', $color);
+ // split the string by commas
+ $color = explode(',', $color);
+
+ $ret = array();
+ foreach ($color as $k => $v) {
+ // range checks
+ if ($v <= 0) {
+ $ret[$k] = 0;
+ } else if ($v <= 100) {
+ // add 0.5 then cast to an integer to round the value.
+ $ret[$k] = (integer) ((2.55 * $v) + 0.5);
+ } else {
+ $ret[$k] = 255;
+ }
+ }
+
+ return $ret;
+ }
+}
+
+// For Array Walk
+// {{{
+/**
+ * Function for array_walk() to round colors to the closest web safe value.
+ *
+ * @param integer $color One channel of an RGB color.
+ * @return integer The websafe equivalent of the color channel.
+ * @author Jason Lotito <jason@lehighweb.com>
+ * @author Andrew Morton <drewish@katherinehouse.com>
+ * @access private
+ * @static
+ */
+function _makeWebSafe(&$color)
+{
+ if ($color < 0x1a) {
+ $color = 0x00;
+ } else if ($color < 0x4d) {
+ $color = 0x33;
+ } else if ($color < 0x80) {
+ $color = 0x66;
+ } else if ($color < 0xB3) {
+ $color = 0x99;
+ } else if ($color < 0xE6) {
+ $color = 0xCC;
+ } else {
+ $color = 0xFF;
+ }
+ return $color;
+}
+// }}}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Graph.php,v 1.58 2005/11/27 18:48:05 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-\r
-/**\r
- * Include PEAR.php\r
- */\r
-require_once 'PEAR.php';\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Include file Image/Graph/Constants.php\r
- */\r
-require_once 'Image/Graph/Constants.php';\r
-\r
-/**\r
- * Main class for the graph creation.\r
- *\r
- * This is the main class, it manages the canvas and performs the final output\r
- * by sequentialy making the elements output their results. The final output is\r
- * handled using the {@link Image_Canvas} classes which makes it possible\r
- * to use different engines (fx GD, PDFlib, libswf, etc) for output to several\r
- * formats with a non-intersecting API.\r
- *\r
- * This class also handles coordinates and the correct managment of setting the\r
- * correct coordinates on child elements.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * Show generation time on graph\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showTime = false;\r
-\r
- /**\r
- * Display errors on the canvas\r
- * @var boolean\r
- * @access private\r
- */\r
- var $_displayErrors = false;\r
-\r
- /**\r
- * Image_Graph [Constructor].\r
- *\r
- * If passing the 3 parameters they are defined as follows:'\r
- * \r
- * Fx.:\r
- * \r
- * $Graph =& new Image_Graph(400, 300);\r
- * \r
- * or using the factory method:\r
- * \r
- * $Graph =& Image_Graph::factory('graph', array(400, 300));\r
- * \r
- * This causes a 'png' canvas to be created by default. \r
- * \r
- * Otherwise use a single parameter either as an associated array or passing\r
- * the canvas along to the constructor:\r
- *\r
- * 1) Create a new canvas with the following parameters:\r
- *\r
- * 'canvas' - The canvas type, can be any of 'gd', 'jpg', 'png' or 'svg'\r
- * (more to come) - if omitted the default is 'gd'\r
- *\r
- * 'width' - The width of the graph\r
- *\r
- * 'height' - The height of the graph\r
- * \r
- * An example of this usage:\r
- * \r
- * $Graph =& Image_Graph::factory('graph', array(array('width' => 400,\r
- * 'height' => 300, 'canvas' => 'jpg')));\r
- * \r
- * NB! In thïs case remember the "double" array (see {@link Image_Graph::\r
- * factory()})\r
- * \r
- * 2) Use the canvas specified, pass a valid Image_Canvas as\r
- * parameter. Remember to pass by reference, i. e. &$canvas, fx.:\r
- *\r
- * $Graph =& new Image_Graph($Canvas);\r
- *\r
- * or using the factory method:\r
- *\r
- * $Graph =& Image_Graph::factory('graph', $Canvas));\r
- *\r
- * @param mixed $params The width of the graph, an indexed array\r
- * describing a new canvas or a valid {@link Image_Canvas} object\r
- * @param int $height The height of the graph in pixels\r
- * @param bool $createTransparent Specifies whether the graph should be\r
- * created with a transparent background (fx for PNG's - note: transparent\r
- * PNG's is not supported by Internet Explorer!)\r
- */\r
- function Image_Graph($params, $height = false, $createTransparent = false)\r
- {\r
- parent::Image_Graph_Element();\r
-\r
- $this->setFont(Image_Graph::factory('Image_Graph_Font'));\r
-\r
- if (defined('IMAGE_GRAPH_DEFAULT_CANVAS_TYPE')) {\r
- $canvasType = IMAGE_GRAPH_DEFAULT_CANVAS_TYPE;\r
- } else {\r
- $canvasType = 'png'; // use GD as default, if nothing else is specified\r
- }\r
-\r
- if (is_array($params)) {\r
- if (isset($params['canvas'])) {\r
- $canvasType = $params['canvas'];\r
- }\r
-\r
- $width = 0;\r
- $height = 0;\r
-\r
- if (isset($params['width'])) {\r
- $width = $params['width'];\r
- }\r
-\r
- if (isset($params['height'])) {\r
- $height = $params['height'];\r
- }\r
- } elseif (is_a($params, 'Image_Canvas')) {\r
- $this->_canvas =& $params;\r
- $width = $this->_canvas->getWidth();\r
- $height = $this->_canvas->getHeight();\r
- } elseif (is_numeric($params)) {\r
- $width = $params;\r
- }\r
-\r
- if ($this->_canvas == null) {\r
- include_once 'Image/Canvas.php';\r
- $this->_canvas =&\r
- Image_Canvas::factory(\r
- $canvasType,\r
- array('width' => $width, 'height' => $height)\r
- );\r
- }\r
-\r
- $this->_setCoords(0, 0, $width - 1, $height - 1);\r
- }\r
-\r
- /**\r
- * Gets the canvas for this graph.\r
- *\r
- * The canvas is set by either passing it to the constructor {@link\r
- * Image_Graph::ImageGraph()} or using the {@link Image_Graph::setCanvas()}\r
- * method.\r
- *\r
- * @return Image_Canvas The canvas used by this graph\r
- * @access private\r
- * @since 0.3.0dev2\r
- */\r
- function &_getCanvas()\r
- {\r
- return $this->_canvas;\r
- }\r
-\r
- /**\r
- * Sets the canvas for this graph.\r
- *\r
- * Calling this method makes this graph use the newly specified canvas for\r
- * handling output. This method should be called whenever multiple\r
- * 'outputs' are required. Invoke this method after calls to {@link\r
- * Image_Graph:: done()} has been performed, to switch canvass.\r
- *\r
- * @param Image_Canvas $canvas The new canvas\r
- * @return Image_Canvas The new canvas\r
- * @since 0.3.0dev2\r
- */\r
- function &setCanvas(&$canvas)\r
- {\r
- if (!is_a($this->_canvas, 'Image_Canvas')) {\r
- return $this->_error('The canvas introduced is not an Image_Canvas object');\r
- }\r
- \r
- $this->_canvas =& $canvas;\r
- $this->_setCoords(\r
- 0,\r
- 0,\r
- $this->_canvas->getWidth() - 1,\r
- $this->_canvas->getHeight() - 1\r
- );\r
- return $this->_canvas;\r
- }\r
-\r
- /**\r
- * Gets a very precise timestamp\r
- *\r
- * @return The number of seconds to a lot of decimals\r
- * @access private\r
- */\r
- function _getMicroTime()\r
- {\r
- list($usec, $sec) = explode(' ', microtime()); \r
- return ((float)$usec + (float)$sec); \r
- }\r
-\r
- /**\r
- * Gets the width of this graph.\r
- *\r
- * The width is returned as 'defined' by the canvas.\r
- *\r
- * @return int the width of this graph\r
- */\r
- function width()\r
- {\r
- return $this->_canvas->getWidth();\r
- }\r
-\r
- /**\r
- * Gets the height of this graph.\r
- *\r
- * The height is returned as 'defined' by the canvas.\r
- *\r
- * @return int the height of this graph\r
- */\r
- function height()\r
- {\r
- return $this->_canvas->getHeight();\r
- }\r
-\r
- /**\r
- * Enables displaying of errors on the output.\r
- *\r
- * Use this method to enforce errors to be displayed on the output. Calling\r
- * this method makes PHP uses this graphs error handler as default {@link\r
- * Image_Graph::_default_error_handler()}.\r
- */\r
- function displayErrors()\r
- {\r
- $this->_displayErrors = true;\r
- set_error_handler(array(&$this, '_default_error_handler'));\r
- }\r
-\r
- /**\r
- * Sets the log method for this graph.\r
- *\r
- * Use this method to enable logging. This causes any errors caught\r
- * by either the error handler {@see Image_Graph::displayErrors()}\r
- * or explicitly by calling {@link Image_Graph_Common::_error()} be\r
- * logged using the specified logging method.\r
- *\r
- * If a filename is specified as log method, a Log object is created (using\r
- * the 'file' handler), with a handle of 'Image_Graph Error Log'.\r
- *\r
- * Logging requires {@link Log}.\r
- *\r
- * @param mixed $log The log method, either a Log object or filename to log\r
- * to\r
- * @since 0.3.0dev2\r
- */\r
- function setLog($log)\r
- {\r
- }\r
-\r
- /**\r
- * Factory method to create Image_Graph objects.\r
- *\r
- * Used for 'lazy including', i.e. loading only what is necessary, when it\r
- * is necessary. If only one parameter is required for the constructor of\r
- * the class simply pass this parameter as the $params parameter, unless the\r
- * parameter is an array or a reference to a value, in that case you must\r
- * 'enclose' the parameter in an array. Similar if the constructor takes\r
- * more than one parameter specify the parameters in an array, i.e\r
- *\r
- * Image_Graph::factory('MyClass', array($param1, $param2, &$param3));\r
- *\r
- * Variables that need to be passed by reference *must* have the &\r
- * before the variable, i.e:\r
- *\r
- * Image_Graph::factory('line', &$Dataset);\r
- *\r
- * or\r
- *\r
- * Image_graph::factory('bar', array(array(&$Dataset1, &$Dataset2),\r
- * 'stacked'));\r
- *\r
- * Class name can be either of the following:\r
- *\r
- * 1 The 'real' Image_Graph class name, i.e. Image_Graph_Plotarea or\r
- * Image_Graph_Plot_Line\r
- *\r
- * 2 Short class name (leave out Image_Graph) and retain case, i.e.\r
- * Plotarea, Plot_Line *not* plot_line\r
- *\r
- * 3 Class name 'alias', the following are supported:\r
- *\r
- * 'graph' = Image_Graph\r
- *\r
- * 'plotarea' = Image_Graph_Plotarea\r
- *\r
- * 'line' = Image_Graph_Plot_Line\r
- *\r
- * 'area' = Image_Graph_Plot_Area\r
- *\r
- * 'bar' = Image_Graph_Plot_Bar\r
- *\r
- * 'pie' = Image_Graph_Plot_Pie\r
- *\r
- * 'radar' = Image_Graph_Plot_Radar\r
- *\r
- * 'step' = Image_Graph_Plot_Step\r
- *\r
- * 'impulse' = Image_Graph_Plot_Impulse\r
- *\r
- * 'dot' or 'scatter' = Image_Graph_Plot_Dot\r
- *\r
- * 'smooth_line' = Image_Graph_Plot_Smoothed_Line\r
- *\r
- * 'smooth_area' = Image_Graph_Plot_Smoothed_Area\r
-\r
- * 'dataset' = Image_Graph_Dataset_Trivial\r
- *\r
- * 'random' = Image_Graph_Dataset_Random\r
- *\r
- * 'function' = Image_Graph_Dataset_Function\r
- *\r
- * 'vector' = Image_Graph_Dataset_VectorFunction\r
- *\r
- * 'category' = Image_Graph_Axis_Category\r
- *\r
- * 'axis' = Image_Graph_Axis\r
- *\r
- * 'axis_log' = Image_Graph_Axis_Logarithmic\r
- *\r
- * 'title' = Image_Graph_Title\r
- *\r
- * 'line_grid' = Image_Graph_Grid_Lines\r
- *\r
- * 'bar_grid' = Image_Graph_Grid_Bars\r
- *\r
- * 'polar_grid' = Image_Graph_Grid_Polar\r
- *\r
- * 'legend' = Image_Graph_Legend\r
- *\r
- * 'font' = Image_Graph_Font\r
- *\r
- * 'ttf_font' = Image_Graph_Font\r
- * \r
- * 'Image_Graph_Font_TTF' = Image_Graph_Font (to maintain BC with Image_Graph_Font_TTF)\r
- *\r
- * 'gradient' = Image_Graph_Fill_Gradient\r
- *\r
- * 'icon_marker' = Image_Graph_Marker_Icon\r
- *\r
- * 'value_marker' = Image_Graph_Marker_Value\r
- *\r
- * @param string $class The class for the new object\r
- * @param mixed $params The paramaters to pass to the constructor\r
- * @return object A new object for the class\r
- * @static\r
- */\r
- function &factory($class, $params = null)\r
- {\r
- static $Image_Graph_classAliases = array(\r
- 'graph' => 'Image_Graph',\r
- 'plotarea' => 'Image_Graph_Plotarea', \r
-\r
- 'line' => 'Image_Graph_Plot_Line',\r
- 'area' => 'Image_Graph_Plot_Area',\r
- 'bar' => 'Image_Graph_Plot_Bar',\r
- 'smooth_line' => 'Image_Graph_Plot_Smoothed_Line',\r
- 'smooth_area' => 'Image_Graph_Plot_Smoothed_Area',\r
- 'pie' => 'Image_Graph_Plot_Pie',\r
- 'radar' => 'Image_Graph_Plot_Radar',\r
- 'step' => 'Image_Graph_Plot_Step',\r
- 'impulse' => 'Image_Graph_Plot_Impulse',\r
- 'dot' => 'Image_Graph_Plot_Dot',\r
- 'scatter' => 'Image_Graph_Plot_Dot',\r
-\r
- 'dataset' => 'Image_Graph_Dataset_Trivial',\r
- 'random' => 'Image_Graph_Dataset_Random',\r
- 'function' => 'Image_Graph_Dataset_Function',\r
- 'vector' => 'Image_Graph_Dataset_VectorFunction',\r
-\r
- 'category' => 'Image_Graph_Axis_Category',\r
- 'axis' => 'Image_Graph_Axis',\r
- 'axis_log' => 'Image_Graph_Axis_Logarithmic',\r
-\r
- 'title' => 'Image_Graph_Title',\r
-\r
- 'line_grid' => 'Image_Graph_Grid_Lines',\r
- 'bar_grid' => 'Image_Graph_Grid_Bars',\r
- 'polar_grid' => 'Image_Graph_Grid_Polar',\r
-\r
- 'legend' => 'Image_Graph_Legend',\r
- 'font' => 'Image_Graph_Font',\r
- 'ttf_font' => 'Image_Graph_Font',\r
- 'Image_Graph_Font_TTF' => 'Image_Graph_Font', // BC with Image_Graph_Font_TTF\r
- 'gradient' => 'Image_Graph_Fill_Gradient',\r
-\r
- 'icon_marker' => 'Image_Graph_Marker_Icon',\r
- 'value_marker' => 'Image_Graph_Marker_Value'\r
- );\r
- \r
- if (substr($class, 0, 11) != 'Image_Graph') {\r
- if (isset($Image_Graph_classAliases[$class])) {\r
- $class = $Image_Graph_classAliases[$class];\r
- } else {\r
- $class = 'Image_Graph_' . $class;\r
- }\r
- }\r
-\r
- include_once str_replace('_', '/', $class) . '.php';\r
-\r
- $obj = null;\r
-\r
- if (is_array($params)) {\r
- switch (count($params)) {\r
- case 1:\r
- $obj =& new $class(\r
- $params[0]\r
- );\r
- break;\r
-\r
- case 2:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1]\r
- );\r
- break;\r
-\r
- case 3:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2]\r
- );\r
- break;\r
-\r
- case 4:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3]\r
- );\r
- break;\r
-\r
- case 5:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4]\r
- );\r
- break;\r
-\r
- case 6:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4],\r
- $params[5]\r
- );\r
- break;\r
-\r
- case 7:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4],\r
- $params[5],\r
- $params[6]\r
- );\r
- break;\r
-\r
- case 8:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4],\r
- $params[5],\r
- $params[6],\r
- $params[7]\r
- );\r
- break;\r
-\r
- case 9:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4],\r
- $params[5],\r
- $params[6],\r
- $params[7],\r
- $params[8]\r
- );\r
- break;\r
-\r
- case 10:\r
- $obj =& new $class(\r
- $params[0],\r
- $params[1],\r
- $params[2],\r
- $params[3],\r
- $params[4],\r
- $params[5],\r
- $params[6],\r
- $params[7],\r
- $params[8],\r
- $params[9]\r
- );\r
- break;\r
-\r
- default:\r
- $obj =& new $class();\r
- break;\r
-\r
- }\r
- } else {\r
- if ($params == null) {\r
- $obj =& new $class();\r
- } else {\r
- $obj =& new $class($params);\r
- }\r
- }\r
- return $obj;\r
- }\r
-\r
- /**\r
- * Factory method to create layouts.\r
- *\r
- * This method is used for easy creation, since using {@link Image_Graph::\r
- * factory()} does not work with passing newly created objects from\r
- * Image_Graph::factory() as reference, this is something that is\r
- * fortunately fixed in PHP5. Also used for 'lazy including', i.e. loading\r
- * only what is necessary, when it is necessary.\r
- *\r
- * Use {@link Image_Graph::horizontal()} or {@link Image_Graph::vertical()}\r
- * instead for easier access.\r
- *\r
- * @param mixed $layout The type of layout, can be either 'Vertical'\r
- * or 'Horizontal' (case sensitive)\r
- * @param Image_Graph_Element $part1 The 1st part of the layout\r
- * @param Image_Graph_Element $part2 The 2nd part of the layout\r
- * @param int $percentage The percentage of the layout to split at\r
- * @return Image_Graph_Layout The newly created layout object\r
- * @static\r
- */\r
- function &layoutFactory($layout, &$part1, &$part2, $percentage = 50)\r
- {\r
- if (($layout != 'Vertical') && ($layout != 'Horizontal')) {\r
- return $this->_error('Layouts must be either \'Horizontal\' or \'Vertical\'');\r
- }\r
- \r
- if (!(is_a($part1, 'Image_Graph_Element'))) {\r
- return $this->_error('Part 1 is not a valid Image_Graph element');\r
- }\r
- \r
- if (!(is_a($part2, 'Image_Graph_Element'))) {\r
- return $this->_error('Part 2 is not a valid Image_Graph element');\r
- }\r
- \r
- if ((!is_numeric($percentage)) || ($percentage < 0) || ($percentage > 100)) {\r
- return $this->_error('Percentage has to be a number between 0 and 100');\r
- }\r
- \r
- include_once "Image/Graph/Layout/$layout.php";\r
- $class = "Image_Graph_Layout_$layout";\r
- $obj =& new $class($part1, $part2, $percentage);\r
- return $obj;\r
- }\r
-\r
- /**\r
- * Factory method to create horizontal layout.\r
- *\r
- * See {@link Image_Graph::layoutFactory()}\r
- *\r
- * @param Image_Graph_Element $part1 The 1st (left) part of the layout\r
- * @param Image_Graph_Element $part2 The 2nd (right) part of the layout\r
- * @param int $percentage The percentage of the layout to split at\r
- * (percentage of total height from the left side)\r
- * @return Image_Graph_Layout The newly created layout object\r
- * @static\r
- */\r
- function &horizontal(&$part1, &$part2, $percentage = 50)\r
- {\r
- $obj =& Image_Graph::layoutFactory('Horizontal', $part1, $part2, $percentage);\r
- return $obj;\r
- }\r
-\r
- /**\r
- * Factory method to create vertical layout.\r
- *\r
- * See {@link Image_Graph::layoutFactory()}\r
- *\r
- * @param Image_Graph_Element $part1 The 1st (top) part of the layout\r
- * @param Image_Graph_Element $part2 The 2nd (bottom) part of the layout\r
- * @param int $percentage The percentage of the layout to split at\r
- * (percentage of total width from the top edge)\r
- * @return Image_Graph_Layout The newly created layout object\r
- * @static\r
- */\r
- function &vertical(&$part1, &$part2, $percentage = 50)\r
- {\r
- $obj =& Image_Graph::layoutFactory('Vertical', $part1, $part2, $percentage);\r
- return $obj;\r
- }\r
-\r
- /**\r
- * The error handling routine set by set_error_handler().\r
- *\r
- * This method is used internaly by Image_Graph and PHP as a proxy for {@link\r
- * Image_Graph::_error()}. \r
- *\r
- * @param string $error_type The type of error being handled.\r
- * @param string $error_msg The error message being handled.\r
- * @param string $error_file The file in which the error occurred.\r
- * @param integer $error_line The line in which the error occurred.\r
- * @param string $error_context The context in which the error occurred.\r
- * @access private\r
- */\r
- function _default_error_handler($error_type, $error_msg, $error_file, $error_line, $error_context)\r
- {\r
- switch( $error_type ) {\r
- case E_ERROR:\r
- $level = 'error';\r
- break;\r
-\r
- case E_USER_ERROR:\r
- $level = 'user error';\r
- break;\r
-\r
- case E_WARNING:\r
- $level = 'warning';\r
- break;\r
-\r
- case E_USER_WARNING:\r
- $level = 'user warning';\r
- break;\r
-\r
- case E_NOTICE:\r
- $level = 'notice';\r
- break;\r
-\r
- case E_USER_NOTICE:\r
- $level = 'user notice';\r
- break;\r
-\r
- default:\r
- $level = '(unknown)';\r
- break;\r
-\r
- }\r
-\r
- $this->_error("PHP $level: $error_msg",\r
- array(\r
- 'type' => $error_type,\r
- 'file' => $error_file,\r
- 'line' => $error_line,\r
- 'context' => $error_context\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * Displays the errors on the error stack.\r
- *\r
- * Invoking this method cause all errors on the error stack to be displayed\r
- * on the graph-output, by calling the {@link Image_Graph::_displayError()}\r
- * method.\r
- *\r
- * @access private\r
- */\r
- function _displayErrors()\r
- {\r
- return true;\r
- }\r
-\r
- /**\r
- * Display an error from the error stack.\r
- *\r
- * This method writes error messages caught from the {@link Image_Graph::\r
- * _default_error_handler()} if {@Image_Graph::displayErrors()} was invoked,\r
- * and the error explicitly set by the system using {@link\r
- * Image_Graph_Common::_error()}.\r
- *\r
- * @param int $x The horizontal position of the error message\r
- * @param int $y The vertical position of the error message\r
- * @param array $error The error context\r
- *\r
- * @access private\r
- */\r
- function _displayError($x, $y, $error)\r
- {\r
- }\r
-\r
- /**\r
- * Outputs this graph using the canvas.\r
- *\r
- * This causes the graph to make all elements perform their output. Their\r
- * result is 'written' to the output using the canvas, which also performs\r
- * the actual output, fx. it being to a file or directly to the browser\r
- * (in the latter case, the canvas will also make sure the correct HTTP\r
- * headers are sent, making the browser handle the output correctly, if\r
- * supported by it).\r
- * \r
- * Parameters are the ones supported by the canvas, common ones are:\r
- * \r
- * 'filename' To output to a file instead of browser\r
- * \r
- * 'tohtml' Return a HTML string that encompasses the current graph/canvas - this\r
- * implies an implicit save using the following parameters: 'filename' The "temporary"\r
- * filename of the graph, 'filepath' A path in the file system where Image_Graph can\r
- * store the output (this file must be in DOCUMENT_ROOT scope), 'urlpath' The URL that the\r
- * 'filepath' corresponds to (i.e. filepath + filename must be reachable from a browser using\r
- * urlpath + filename) \r
- *\r
- * @param mixed $param The output parameters to pass to the canvas\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- */\r
- function done($param = false)\r
- {\r
- $result = $this->_reset();\r
- if (PEAR::isError($result)) {\r
- return $result;\r
- }\r
- return $this->_done($param);\r
- }\r
-\r
- /**\r
- * Outputs this graph using the canvas.\r
- *\r
- * This causes the graph to make all elements perform their output. Their\r
- * result is 'written' to the output using the canvas, which also performs\r
- * the actual output, fx. it being to a file or directly to the browser\r
- * (in the latter case, the canvas will also make sure the correct HTTP\r
- * headers are sent, making the browser handle the output correctly, if\r
- * supported by it).\r
- *\r
- * @param mixed $param The output parameters to pass to the canvas\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done($param = false)\r
- {\r
- $timeStart = $this->_getMicroTime();\r
-\r
- if ($this->_shadow) {\r
- $this->setPadding(20);\r
- $this->_setCoords(\r
- $this->_left,\r
- $this->_top,\r
- $this->_right - 10,\r
- $this->_bottom - 10);\r
- }\r
-\r
- $result = $this->_updateCoords(); \r
- if (PEAR::isError($result)) {\r
- return $result;\r
- }\r
-\r
- if ($this->_getBackground()) {\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_bottom\r
- )\r
- );\r
- }\r
-\r
- $result = parent::_done();\r
- if (PEAR::isError($result)) {\r
- return $result;\r
- }\r
-\r
- if ($this->_displayErrors) {\r
- $this->_displayErrors();\r
- }\r
-\r
- $timeEnd = $this->_getMicroTime();\r
-\r
- if (($this->_showTime) || \r
- ((isset($param['showtime'])) && ($param['showtime'] === true))\r
- ) {\r
- $text = 'Generated in ' .\r
- sprintf('%0.3f', $timeEnd - $timeStart) . ' sec';\r
- $this->write(\r
- $this->_right,\r
- $this->_bottom,\r
- $text,\r
- IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_BOTTOM,\r
- array('color' => 'red')\r
- );\r
- }\r
- \r
- if (isset($param['filename'])) {\r
- if ((isset($param['tohtml'])) && ($param['tohtml'])) {\r
- return $this->_canvas->toHtml($param);\r
- }\r
- else {\r
- return $this->_canvas->save($param);\r
- }\r
- } else {\r
- return $this->_canvas->show($param);\r
- }\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Graph.php 291756 2009-12-06 02:55:46Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+
+/**
+ * Include PEAR.php
+ */
+require_once 'PEAR.php';
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Include file Image/Graph/Constants.php
+ */
+require_once 'Image/Graph/Constants.php';
+
+/**
+ * Main class for the graph creation.
+ *
+ * This is the main class, it manages the canvas and performs the final output
+ * by sequentialy making the elements output their results. The final output is
+ * handled using the {@link Image_Canvas} classes which makes it possible
+ * to use different engines (fx GD, PDFlib, libswf, etc) for output to several
+ * formats with a non-intersecting API.
+ *
+ * This class also handles coordinates and the correct managment of setting the
+ * correct coordinates on child elements.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph extends Image_Graph_Element
+{
+
+ /**
+ * Show generation time on graph
+ * @var bool
+ * @access private
+ */
+ var $_showTime = false;
+
+ /**
+ * Display errors on the canvas
+ * @var boolean
+ * @access private
+ */
+ var $_displayErrors = false;
+
+ /**
+ * Image_Graph [Constructor].
+ *
+ * If passing the 3 parameters they are defined as follows:'
+ *
+ * Fx.:
+ *
+ * $Graph = new Image_Graph(400, 300);
+ *
+ * or using the factory method:
+ *
+ * $Graph =& Image_Graph::factory('graph', array(400, 300));
+ *
+ * This causes a 'png' canvas to be created by default.
+ *
+ * Otherwise use a single parameter either as an associated array or passing
+ * the canvas along to the constructor:
+ *
+ * 1) Create a new canvas with the following parameters:
+ *
+ * 'canvas' - The canvas type, can be any of 'gd', 'jpg', 'png' or 'svg'
+ * (more to come) - if omitted the default is 'gd'
+ *
+ * 'width' - The width of the graph
+ *
+ * 'height' - The height of the graph
+ *
+ * An example of this usage:
+ *
+ * $Graph =& Image_Graph::factory('graph', array(array('width' => 400,
+ * 'height' => 300, 'canvas' => 'jpg')));
+ *
+ * NB! In th�s case remember the "double" array (see {@link Image_Graph::
+ * factory()})
+ *
+ * 2) Use the canvas specified, pass a valid Image_Canvas as
+ * parameter. Remember to pass by reference, i. e. &$canvas, fx.:
+ *
+ * $Graph = new Image_Graph($Canvas);
+ *
+ * or using the factory method:
+ *
+ * $Graph =& Image_Graph::factory('graph', $Canvas));
+ *
+ * @param mixed $params The width of the graph, an indexed array
+ * describing a new canvas or a valid {@link Image_Canvas} object
+ * @param int $height The height of the graph in pixels
+ * @param bool $createTransparent Specifies whether the graph should be
+ * created with a transparent background (fx for PNG's - note: transparent
+ * PNG's is not supported by Internet Explorer!)
+ */
+ function Image_Graph($params, $height = false, $createTransparent = false)
+ {
+ parent::__construct();
+
+ $this->setFont(Image_Graph::factory('Image_Graph_Font'));
+
+ if (defined('IMAGE_GRAPH_DEFAULT_CANVAS_TYPE')) {
+ $canvasType = IMAGE_GRAPH_DEFAULT_CANVAS_TYPE;
+ } else {
+ $canvasType = 'png'; // use GD as default, if nothing else is specified
+ }
+
+ if (is_array($params)) {
+ if (isset($params['canvas'])) {
+ $canvasType = $params['canvas'];
+ }
+
+ $width = 0;
+ $height = 0;
+
+ if (isset($params['width'])) {
+ $width = $params['width'];
+ }
+
+ if (isset($params['height'])) {
+ $height = $params['height'];
+ }
+ } elseif (is_a($params, 'Image_Canvas')) {
+ $this->_canvas =& $params;
+ $width = $this->_canvas->getWidth();
+ $height = $this->_canvas->getHeight();
+ } elseif (is_numeric($params)) {
+ $width = $params;
+ }
+
+ if ($this->_canvas == null) {
+ include_once 'Image/Canvas.php';
+ $this->_canvas =&
+ Image_Canvas::factory(
+ $canvasType,
+ array('width' => $width, 'height' => $height)
+ );
+ }
+
+ $this->_setCoords(0, 0, $width - 1, $height - 1);
+ }
+
+ /**
+ * Gets the canvas for this graph.
+ *
+ * The canvas is set by either passing it to the constructor {@link
+ * Image_Graph::ImageGraph()} or using the {@link Image_Graph::setCanvas()}
+ * method.
+ *
+ * @return Image_Canvas The canvas used by this graph
+ * @access private
+ * @since 0.3.0dev2
+ */
+ function &_getCanvas()
+ {
+ return $this->_canvas;
+ }
+
+ /**
+ * Sets the canvas for this graph.
+ *
+ * Calling this method makes this graph use the newly specified canvas for
+ * handling output. This method should be called whenever multiple
+ * 'outputs' are required. Invoke this method after calls to {@link
+ * Image_Graph:: done()} has been performed, to switch canvass.
+ *
+ * @param Image_Canvas &$canvas The new canvas
+ *
+ * @return Image_Canvas The new canvas
+ * @since 0.3.0dev2
+ */
+ function &setCanvas(&$canvas)
+ {
+ if (!is_a($this->_canvas, 'Image_Canvas')) {
+ return $this->_error('The canvas introduced is not an Image_Canvas object');
+ }
+
+ $this->_canvas =& $canvas;
+ $this->_setCoords(
+ 0,
+ 0,
+ $this->_canvas->getWidth() - 1,
+ $this->_canvas->getHeight() - 1
+ );
+ return $this->_canvas;
+ }
+
+ /**
+ * Gets a very precise timestamp
+ *
+ * @return The number of seconds to a lot of decimals
+ * @access private
+ */
+ function _getMicroTime()
+ {
+ list($usec, $sec) = explode(' ', microtime());
+ return ((float)$usec + (float)$sec);
+ }
+
+ /**
+ * Gets the width of this graph.
+ *
+ * The width is returned as 'defined' by the canvas.
+ *
+ * @return int the width of this graph
+ */
+ function width()
+ {
+ return $this->_canvas->getWidth();
+ }
+
+ /**
+ * Gets the height of this graph.
+ *
+ * The height is returned as 'defined' by the canvas.
+ *
+ * @return int the height of this graph
+ */
+ function height()
+ {
+ return $this->_canvas->getHeight();
+ }
+
+ /**
+ * Enables displaying of errors on the output.
+ *
+ * Use this method to enforce errors to be displayed on the output. Calling
+ * this method makes PHP uses this graphs error handler as default {@link
+ * Image_Graph::_default_error_handler()}.
+ *
+ * @return void
+ */
+ function displayErrors()
+ {
+ $this->_displayErrors = true;
+ set_error_handler(array(&$this, '_default_error_handler'));
+ }
+
+ /**
+ * Sets the log method for this graph.
+ *
+ * Use this method to enable logging. This causes any errors caught
+ * by either the error handler {@see Image_Graph::displayErrors()}
+ * or explicitly by calling {@link Image_Graph_Common::_error()} be
+ * logged using the specified logging method.
+ *
+ * If a filename is specified as log method, a Log object is created (using
+ * the 'file' handler), with a handle of 'Image_Graph Error Log'.
+ *
+ * Logging requires {@link Log}.
+ *
+ * @param mixed $log The log method, either a Log object or filename to log to
+ *
+ * @since 0.3.0dev2
+ * @return void
+ */
+ function setLog($log)
+ {
+ }
+
+ /**
+ * Factory method to create Image_Graph objects.
+ *
+ * Used for 'lazy including', i.e. loading only what is necessary, when it
+ * is necessary. If only one parameter is required for the constructor of
+ * the class simply pass this parameter as the $params parameter, unless the
+ * parameter is an array or a reference to a value, in that case you must
+ * 'enclose' the parameter in an array. Similar if the constructor takes
+ * more than one parameter specify the parameters in an array, i.e
+ *
+ * Image_Graph::factory('MyClass', array($param1, $param2, &$param3));
+ *
+ * Variables that need to be passed by reference *must* have the &
+ * before the variable, i.e:
+ *
+ * Image_Graph::factory('line', &$Dataset);
+ *
+ * or
+ *
+ * Image_graph::factory('bar', array(array(&$Dataset1, &$Dataset2),
+ * 'stacked'));
+ *
+ * Class name can be either of the following:
+ *
+ * 1 The 'real' Image_Graph class name, i.e. Image_Graph_Plotarea or
+ * Image_Graph_Plot_Line
+ *
+ * 2 Short class name (leave out Image_Graph) and retain case, i.e.
+ * Plotarea, Plot_Line *not* plot_line
+ *
+ * 3 Class name 'alias', the following are supported:
+ *
+ * 'graph' = Image_Graph
+ *
+ * 'plotarea' = Image_Graph_Plotarea
+ *
+ * 'line' = Image_Graph_Plot_Line
+ *
+ * 'area' = Image_Graph_Plot_Area
+ *
+ * 'bar' = Image_Graph_Plot_Bar
+ *
+ * 'pie' = Image_Graph_Plot_Pie
+ *
+ * 'radar' = Image_Graph_Plot_Radar
+ *
+ * 'step' = Image_Graph_Plot_Step
+ *
+ * 'impulse' = Image_Graph_Plot_Impulse
+ *
+ * 'dot' or 'scatter' = Image_Graph_Plot_Dot
+ *
+ * 'smooth_line' = Image_Graph_Plot_Smoothed_Line
+ *
+ * 'smooth_area' = Image_Graph_Plot_Smoothed_Area
+
+ * 'dataset' = Image_Graph_Dataset_Trivial
+ *
+ * 'random' = Image_Graph_Dataset_Random
+ *
+ * 'function' = Image_Graph_Dataset_Function
+ *
+ * 'vector' = Image_Graph_Dataset_VectorFunction
+ *
+ * 'category' = Image_Graph_Axis_Category
+ *
+ * 'axis' = Image_Graph_Axis
+ *
+ * 'axis_log' = Image_Graph_Axis_Logarithmic
+ *
+ * 'title' = Image_Graph_Title
+ *
+ * 'line_grid' = Image_Graph_Grid_Lines
+ *
+ * 'bar_grid' = Image_Graph_Grid_Bars
+ *
+ * 'polar_grid' = Image_Graph_Grid_Polar
+ *
+ * 'legend' = Image_Graph_Legend
+ *
+ * 'font' = Image_Graph_Font
+ *
+ * 'ttf_font' = Image_Graph_Font
+ *
+ * 'Image_Graph_Font_TTF' = Image_Graph_Font (to maintain BC with Image_Graph_Font_TTF)
+ *
+ * 'gradient' = Image_Graph_Fill_Gradient
+ *
+ * 'icon_marker' = Image_Graph_Marker_Icon
+ *
+ * 'value_marker' = Image_Graph_Marker_Value
+ *
+ * @param string $class The class for the new object
+ * @param mixed $params The paramaters to pass to the constructor
+ *
+ * @return object A new object for the class
+ * @static
+ */
+ function &factory($class, $params = null)
+ {
+ static $Image_Graph_classAliases = array(
+ 'graph' => 'Image_Graph',
+ 'plotarea' => 'Image_Graph_Plotarea',
+
+ 'line' => 'Image_Graph_Plot_Line',
+ 'area' => 'Image_Graph_Plot_Area',
+ 'bar' => 'Image_Graph_Plot_Bar',
+ 'smooth_line' => 'Image_Graph_Plot_Smoothed_Line',
+ 'smooth_area' => 'Image_Graph_Plot_Smoothed_Area',
+ 'pie' => 'Image_Graph_Plot_Pie',
+ 'radar' => 'Image_Graph_Plot_Radar',
+ 'step' => 'Image_Graph_Plot_Step',
+ 'impulse' => 'Image_Graph_Plot_Impulse',
+ 'dot' => 'Image_Graph_Plot_Dot',
+ 'scatter' => 'Image_Graph_Plot_Dot',
+
+ 'dataset' => 'Image_Graph_Dataset_Trivial',
+ 'random' => 'Image_Graph_Dataset_Random',
+ 'function' => 'Image_Graph_Dataset_Function',
+ 'vector' => 'Image_Graph_Dataset_VectorFunction',
+
+ 'category' => 'Image_Graph_Axis_Category',
+ 'axis' => 'Image_Graph_Axis',
+ 'axis_log' => 'Image_Graph_Axis_Logarithmic',
+
+ 'title' => 'Image_Graph_Title',
+
+ 'line_grid' => 'Image_Graph_Grid_Lines',
+ 'bar_grid' => 'Image_Graph_Grid_Bars',
+ 'polar_grid' => 'Image_Graph_Grid_Polar',
+
+ 'legend' => 'Image_Graph_Legend',
+ 'font' => 'Image_Graph_Font',
+ 'ttf_font' => 'Image_Graph_Font',
+ 'Image_Graph_Font_TTF' => 'Image_Graph_Font', // BC with Image_Graph_Font_TTF
+ 'gradient' => 'Image_Graph_Fill_Gradient',
+
+ 'icon_marker' => 'Image_Graph_Marker_Icon',
+ 'value_marker' => 'Image_Graph_Marker_Value'
+ );
+
+ if (substr($class, 0, 11) != 'Image_Graph') {
+ if (isset($Image_Graph_classAliases[$class])) {
+ $class = $Image_Graph_classAliases[$class];
+ } else {
+ $class = 'Image_Graph_' . $class;
+ }
+ }
+
+ include_once str_replace('_', '/', $class) . '.php';
+
+ $obj = null;
+
+ if (is_array($params)) {
+ switch (count($params)) {
+ case 1:
+ $obj = new $class(
+ $params[0]
+ );
+ break;
+
+ case 2:
+ $obj = new $class(
+ $params[0],
+ $params[1]
+ );
+ break;
+
+ case 3:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2]
+ );
+ break;
+
+ case 4:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3]
+ );
+ break;
+
+ case 5:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4]
+ );
+ break;
+
+ case 6:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4],
+ $params[5]
+ );
+ break;
+
+ case 7:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4],
+ $params[5],
+ $params[6]
+ );
+ break;
+
+ case 8:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4],
+ $params[5],
+ $params[6],
+ $params[7]
+ );
+ break;
+
+ case 9:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4],
+ $params[5],
+ $params[6],
+ $params[7],
+ $params[8]
+ );
+ break;
+
+ case 10:
+ $obj = new $class(
+ $params[0],
+ $params[1],
+ $params[2],
+ $params[3],
+ $params[4],
+ $params[5],
+ $params[6],
+ $params[7],
+ $params[8],
+ $params[9]
+ );
+ break;
+
+ default:
+ $obj = new $class();
+ break;
+
+ }
+ } else {
+ if ($params == null) {
+ $obj = new $class();
+ } else {
+ $obj = new $class($params);
+ }
+ }
+ return $obj;
+ }
+
+ /**
+ * Factory method to create layouts.
+ *
+ * This method is used for easy creation, since using {@link Image_Graph::
+ * factory()} does not work with passing newly created objects from
+ * Image_Graph::factory() as reference, this is something that is
+ * fortunately fixed in PHP5. Also used for 'lazy including', i.e. loading
+ * only what is necessary, when it is necessary.
+ *
+ * Use {@link Image_Graph::horizontal()} or {@link Image_Graph::vertical()}
+ * instead for easier access.
+ *
+ * @param mixed $layout The type of layout, can be either 'Vertical'
+ * or 'Horizontal' (case sensitive)
+ * @param Image_Graph_Element &$part1 The 1st part of the layout
+ * @param Image_Graph_Element &$part2 The 2nd part of the layout
+ * @param int $percentage The percentage of the layout to split at
+ *
+ * @return Image_Graph_Layout The newly created layout object
+ * @static
+ */
+ function &layoutFactory($layout, &$part1, &$part2, $percentage = 50)
+ {
+ if (($layout != 'Vertical') && ($layout != 'Horizontal')) {
+ return $this->_error('Layouts must be either \'Horizontal\' or \'Vertical\'');
+ }
+
+ if (!(is_a($part1, 'Image_Graph_Element'))) {
+ return $this->_error('Part 1 is not a valid Image_Graph element');
+ }
+
+ if (!(is_a($part2, 'Image_Graph_Element'))) {
+ return $this->_error('Part 2 is not a valid Image_Graph element');
+ }
+
+ if ((!is_numeric($percentage)) || ($percentage < 0) || ($percentage > 100)) {
+ return $this->_error('Percentage has to be a number between 0 and 100');
+ }
+
+ include_once "Image/Graph/Layout/$layout.php";
+ $class = "Image_Graph_Layout_$layout";
+ $obj = new $class($part1, $part2, $percentage);
+ return $obj;
+ }
+
+ /**
+ * Factory method to create horizontal layout.
+ *
+ * See {@link Image_Graph::layoutFactory()}
+ *
+ * @param Image_Graph_Element &$part1 The 1st (left) part of the layout
+ * @param Image_Graph_Element &$part2 The 2nd (right) part of the layout
+ * @param int $percentage The percentage of the layout to split at
+ * (percentage of total height from the left side)
+ *
+ * @return Image_Graph_Layout The newly created layout object
+ * @static
+ */
+ function &horizontal(&$part1, &$part2, $percentage = 50)
+ {
+ $obj =& Image_Graph::layoutFactory('Horizontal', $part1, $part2, $percentage);
+ return $obj;
+ }
+
+ /**
+ * Factory method to create vertical layout.
+ *
+ * See {@link Image_Graph::layoutFactory()}
+ *
+ * @param Image_Graph_Element &$part1 The 1st (top) part of the layout
+ * @param Image_Graph_Element &$part2 The 2nd (bottom) part of the layout
+ * @param int $percentage The percentage of the layout to split at
+ * (percentage of total width from the top edge)
+ *
+ * @return Image_Graph_Layout The newly created layout object
+ * @static
+ */
+ function &vertical(&$part1, &$part2, $percentage = 50)
+ {
+ $obj =& Image_Graph::layoutFactory('Vertical', $part1, $part2, $percentage);
+ return $obj;
+ }
+
+ /**
+ * The error handling routine set by set_error_handler().
+ *
+ * This method is used internaly by Image_Graph and PHP as a proxy for {@link
+ * Image_Graph::_error()}.
+ *
+ * @param string $error_type The type of error being handled.
+ * @param string $error_msg The error message being handled.
+ * @param string $error_file The file in which the error occurred.
+ * @param integer $error_line The line in which the error occurred.
+ * @param string $error_context The context in which the error occurred.
+ *
+ * @access private
+ * @return void
+ */
+ function _default_error_handler($error_type, $error_msg, $error_file, $error_line, $error_context)
+ {
+ switch( $error_type ) {
+ case E_ERROR:
+ $level = 'error';
+ break;
+
+ case E_USER_ERROR:
+ $level = 'user error';
+ break;
+
+ case E_WARNING:
+ $level = 'warning';
+ break;
+
+ case E_USER_WARNING:
+ $level = 'user warning';
+ break;
+
+ case E_NOTICE:
+ $level = 'notice';
+ break;
+
+ case E_USER_NOTICE:
+ $level = 'user notice';
+ break;
+
+ default:
+ $level = '(unknown)';
+ break;
+
+ }
+
+ $this->_error(
+ "PHP $level: $error_msg",
+ array(
+ 'type' => $error_type,
+ 'file' => $error_file,
+ 'line' => $error_line,
+ 'context' => $error_context
+ )
+ );
+ }
+
+ /**
+ * Displays the errors on the error stack.
+ *
+ * Invoking this method cause all errors on the error stack to be displayed
+ * on the graph-output, by calling the {@link Image_Graph::_displayError()}
+ * method.
+ *
+ * @access private
+ * @return boolean
+ */
+ function _displayErrors()
+ {
+ return true;
+ }
+
+ /**
+ * Display an error from the error stack.
+ *
+ * This method writes error messages caught from the {@link Image_Graph::
+ * _default_error_handler()} if {@Image_Graph::displayErrors()} was invoked,
+ * and the error explicitly set by the system using {@link
+ * Image_Graph_Common::_error()}.
+ *
+ * @param int $x The horizontal position of the error message
+ * @param int $y The vertical position of the error message
+ * @param array $error The error context
+ *
+ * @access private
+ * @return void
+ */
+ function _displayError($x, $y, $error)
+ {
+ }
+
+ /**
+ * Outputs this graph using the canvas.
+ *
+ * This causes the graph to make all elements perform their output. Their
+ * result is 'written' to the output using the canvas, which also performs
+ * the actual output, fx. it being to a file or directly to the browser
+ * (in the latter case, the canvas will also make sure the correct HTTP
+ * headers are sent, making the browser handle the output correctly, if
+ * supported by it).
+ *
+ * Parameters are the ones supported by the canvas, common ones are:
+ *
+ * 'filename' To output to a file instead of browser
+ *
+ * 'tohtml' Return a HTML string that encompasses the current graph/canvas - this
+ * implies an implicit save using the following parameters: 'filename' The "temporary"
+ * filename of the graph, 'filepath' A path in the file system where Image_Graph can
+ * store the output (this file must be in DOCUMENT_ROOT scope), 'urlpath' The URL that the
+ * 'filepath' corresponds to (i.e. filepath + filename must be reachable from a browser using
+ * urlpath + filename)
+ *
+ * 'output' = 'none' Forces the graph to be drawn, but no output is sent to
+ * the browser. This allows working with an existing canvas after graphs has
+ * been drawn
+ *
+ * @param mixed $param The output parameters to pass to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ */
+ function done($param = false)
+ {
+ $result = $this->_reset();
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+ return $this->_done($param);
+ }
+
+ /**
+ * Outputs this graph using the canvas.
+ *
+ * This causes the graph to make all elements perform their output. Their
+ * result is 'written' to the output using the canvas, which also performs
+ * the actual output, fx. it being to a file or directly to the browser
+ * (in the latter case, the canvas will also make sure the correct HTTP
+ * headers are sent, making the browser handle the output correctly, if
+ * supported by it).
+ *
+ * @param mixed $param The output parameters to pass to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done($param = false)
+ {
+ $timeStart = $this->_getMicroTime();
+
+ if ($this->_shadow) {
+ $this->setPadding(20);
+ $this->_setCoords(
+ $this->_left,
+ $this->_top,
+ $this->_right - 10,
+ $this->_bottom - 10
+ );
+ }
+
+ $result = $this->_updateCoords();
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+
+ if ($this->_getBackground()) {
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_bottom
+ )
+ );
+ }
+
+ $result = parent::_done();
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+
+ if ($this->_displayErrors) {
+ $this->_displayErrors();
+ }
+
+ $timeEnd = $this->_getMicroTime();
+
+ if (($this->_showTime)
+ || ((isset($param['showtime'])) && ($param['showtime'] === true))
+ ) {
+ $text = 'Generated in ' .
+ sprintf('%0.3f', $timeEnd - $timeStart) . ' sec';
+ $this->write(
+ $this->_right,
+ $this->_bottom,
+ $text,
+ IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_BOTTOM,
+ array('color' => 'red')
+ );
+ }
+
+ if ((!isset($param['output'])) || ($param['output'] !== 'none')) {
+ if (isset($param['filename'])) {
+ if ((isset($param['tohtml'])) && ($param['tohtml'])) {
+ return $this->_canvas->toHtml($param);
+ } else {
+ return $this->_canvas->save($param);
+ }
+ } else {
+ return $this->_canvas->show($param);
+ }
+ }
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for axis handling.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Axis.php,v 1.35 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Plotarea/Element.php\r
- */\r
-require_once 'Image/Graph/Plotarea/Element.php';\r
-\r
-/**\r
- * Diplays a normal linear axis (either X- or Y-axis).\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- class Image_Graph_Axis extends Image_Graph_Plotarea_Element\r
-{\r
- \r
- /**\r
- * The type of the axis, possible values are:\r
- * <ul>\r
- * <li>IMAGE_GRAPH_AXIS_X / IMAGE_GRAPH_AXIS_HORIZONTAL\r
- * <li>IMAGE_GRAPH_AXIS_Y / IMAGE_GRAPH_AXIS_VERTICAL /\r
- * IMAGE_GRAPH_AXIS_Y_SECONDARY\r
- * </ul>\r
- * @var int\r
- * @access private\r
- */\r
- var $_type;\r
-\r
- /**\r
- * The minimum value the axis displays\r
- * @var int\r
- * @access private\r
- */\r
- var $_minimum = false;\r
-\r
- /**\r
- * The minimum value the axis has been explicitly set by the user\r
- * @var bool\r
- * @access private\r
- */\r
- var $_minimumSet = false;\r
-\r
- /**\r
- * The maximum value the axis displays\r
- * @var int\r
- * @access private\r
- */\r
- var $_maximum = false;\r
-\r
- /**\r
- * The maximum value the axis has been explicitly set by the user\r
- * @var bool\r
- * @access private\r
- */\r
- var $_maximumSet = false;\r
-\r
- /**\r
- * The value span of the axis.\r
- * This is primarily included for performance reasons\r
- * @var double\r
- * @access private\r
- */\r
- var $_axisSpan = false;\r
-\r
- /**\r
- * The value span of the axis.\r
- * This is primarily included for performance reasons\r
- * @var double\r
- * @access private\r
- */\r
- var $_axisValueSpan = false;\r
- \r
- /**\r
- * The axis padding.\r
- * The index 'low' specifies the padding for the low axis values (when not\r
- * inverted), i.e. to the left on an x-axis and on the bottom of an y-axis,\r
- * vice versa for 'high'.\r
- * \r
- * Axis padding does not make sense on a normal linear y-axis with a 'y-min'\r
- * of 0 since this corresponds to displaying a small part of the y-axis\r
- * below 0!\r
- * \r
- * @var array\r
- * @access private\r
- */\r
- var $_axisPadding = array('low' => 0, 'high' => 0);\r
-\r
- /**\r
- * The number of "pixels" representing 1 unit on the axis\r
- *\r
- * This is primarily included for performance reasons\r
- * @var double\r
- * @access private\r
- */\r
- var $_delta = false;\r
- \r
- /**\r
- * Specify if the axis should label the minimum value\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showLabelMinimum = true;\r
-\r
- /**\r
- * Specify if the axis should label 0 (zero)\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showLabelZero = false;\r
-\r
- /**\r
- * Specify if the axis should label the maximum value\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showLabelMaximum = true;\r
-\r
- /**\r
- * Show arrow heads at the 'end' of the axis, default: false\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showArrow = false;\r
-\r
- /**\r
- * Intersection data of axis\r
- * @var array\r
- * @access private\r
- */\r
- var $_intersect = array('value' => 'default', 'axis' => 'default');\r
-\r
- /**\r
- * The fixed size of the axis (i.e. width for y-axis, height for x-axis)\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_fixedSize = false;\r
-\r
- /**\r
- * The label options\r
- *\r
- * Should text be shows, preferences for ticks. The indexes start at level\r
- * 1, which is chosen for readability\r
- * @var array\r
- * @access private\r
- */\r
- var $_labelOptions = array(\r
- 1 => array(\r
- 'interval' => 1,\r
- 'type' => 'auto',\r
- 'tick' => array(\r
- 'start' => -2, \r
- 'end' => 2, \r
- 'color' => false // default color\r
- ),\r
- 'showtext' => true,\r
- 'showoffset' => false,\r
- 'font' => array(),\r
- 'offset' => 0,\r
- 'position' => 'outside', \r
- )\r
- );\r
-\r
- /**\r
- * The labels that are shown.\r
- *\r
- * This is used to make values show only once...\r
- * @access private\r
- */\r
- var $_labelText = array();\r
-\r
- /**\r
- * A data preprocessor for formatting labels, fx showing dates as a standard\r
- * date instead of Unix time stamp\r
- * @var Image_Graph_DatePreProcessor\r
- * @access private\r
- * @see Image_Graph_DataPreProcessor\r
- */\r
- var $_dataPreProcessor = null;\r
-\r
- /**\r
- * Point marked in the axis\r
- * @var array\r
- * @access private\r
- */\r
- var $_marks = array();\r
-\r
- /**\r
- * Specifies whether the values should be 'pushed' by 0.5\r
- * @var bool\r
- * @access private\r
- */\r
- var $_pushValues = false;\r
-\r
- /**\r
- * The title of this axis\r
- * @var string\r
- * @access private\r
- */\r
- var $_title = '';\r
-\r
- /**\r
- * The font used for the title of this axis\r
- * @var Image_Graph_Font\r
- * @access private\r
- */\r
- var $_titleFont = false;\r
- \r
- /**\r
- * Invert the axis (i.e. if an y-axis normally displays minimum values at\r
- * the bottom, they are not displayed at the top\r
- * @var bool\r
- * @access private\r
- * @since 0.3.0dev3\r
- */\r
- var $_invert = false;\r
- \r
- /**\r
- * Transpose the axis (i.e. is a normal y-axis transposed, so thats it's not show\r
- * vertically as normally expected, but instead horizontally)\r
- * @var bool\r
- * @access private\r
- */\r
- var $_transpose = false;\r
-\r
- /**\r
- * Image_Graph_Axis [Constructor].\r
- * Normally a manual creation should not be necessary, axis are created\r
- * automatically by the {@link Image_Graph_Plotarea} constructor unless\r
- * explicitly defined otherwise\r
- *\r
- * @param int $type The type (direction) of the Axis, use IMAGE_GRAPH_AXIS_X\r
- * for an X-axis (default, may be omitted) and IMAGE_GRAPH_AXIS_Y for Y-\r
- * axis)\r
- */\r
- function Image_Graph_Axis($type = IMAGE_GRAPH_AXIS_X)\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_type = $type;\r
- $this->_fillStyle = 'black';\r
- }\r
-\r
- /**\r
- * Push the values by 0.5 (for bar and step chart)\r
- *\r
- * @access private\r
- */\r
- function _pushValues()\r
- {\r
- $this->_pushValues = true;\r
- }\r
- \r
- /**\r
- * Sets the axis padding for a given position ('low' or 'high')\r
- * @param string $where The position\r
- * @param int $value The number of pixels to "pad"\r
- * @access private\r
- */\r
- function _setAxisPadding($where, $value)\r
- {\r
- $this->_axisPadding[$where] = $value;\r
- } \r
-\r
- /**\r
- * Gets the font of the title.\r
- *\r
- * If not font has been set, the parent font is propagated through it's\r
- * children.\r
- *\r
- * @return array An associated array used for canvas\r
- * @access private\r
- */\r
- function _getTitleFont()\r
- {\r
- if ($this->_titleFont === false) {\r
- if ($this->_defaultFontOptions !== false) {\r
- return $this->_defaultFontOptions;\r
- } else {\r
- return $this->_getFont();\r
- }\r
- } else {\r
- if (is_object($this->_titleFont)) {\r
- return $this->_titleFont->_getFont();\r
- } elseif (is_array($this->_titleFont)) {\r
- return $this->_getFont($this->_titleFont);\r
- } elseif (is_int($this->_titleFont)) {\r
- return $this->_getFont(array('size' => $this->_titleFont));\r
- }\r
- }\r
- return array();\r
- }\r
-\r
- /**\r
- * Shows a label for the the specified values.\r
- *\r
- * Allowed values are combinations of:\r
- * <ul>\r
- * <li>IMAGE_GRAPH_LABEL_MINIMUM\r
- * <li>IMAGE_GRAPH_LABEL_ZERO\r
- * <li>IMAGE_GRAPH_LABEL_MAXIMUM\r
- * </ul>\r
- * By default none of these are shows on the axis\r
- *\r
- * @param int $value The values to show labels for\r
- */\r
- function showLabel($value)\r
- {\r
- $this->_showLabelMinimum = ($value & IMAGE_GRAPH_LABEL_MINIMUM);\r
- $this->_showLabelZero = ($value & IMAGE_GRAPH_LABEL_ZERO);\r
- $this->_showLabelMaximum = ($value & IMAGE_GRAPH_LABEL_MAXIMUM);\r
- }\r
-\r
- /**\r
- * Sets a data preprocessor for formatting the axis labels\r
- *\r
- * @param Image_Graph_DataPreprocessor $dataPreProcessor The data preprocessor\r
- * @see Image_Graph_DataPreprocessor\r
- */\r
- function setDataPreProcessor(& $dataPreProcessor)\r
- {\r
- $this->_dataPreProcessor =& $dataPreProcessor;\r
- }\r
-\r
- /**\r
- * Gets the minimum value the axis will show\r
- *\r
- * @return double The minumum value\r
- * @access private\r
- */\r
- function _getMinimum()\r
- {\r
- return $this->_minimum;\r
- }\r
-\r
- /**\r
- * Gets the maximum value the axis will show\r
- *\r
- * @return double The maximum value\r
- * @access private\r
- */\r
- function _getMaximum()\r
- {\r
- return $this->_maximum;\r
- }\r
-\r
- /**\r
- * Sets the minimum value the axis will show\r
- *\r
- * @param double $minimum The minumum value to use on the axis\r
- * @access private\r
- */\r
- function _setMinimum($minimum)\r
- {\r
- if ($this->_minimum === false) {\r
- $this->forceMinimum($minimum, false);\r
- } else {\r
- $this->forceMinimum(min($this->_minimum, $minimum), false);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the maximum value the axis will show\r
- *\r
- * @param double $maximum The maximum value to use on the axis\r
- * @access private\r
- */\r
- function _setMaximum($maximum)\r
- {\r
- if ($this->_maximum === false) {\r
- $this->forceMaximum($maximum, false);\r
- } else {\r
- $this->forceMaximum(max($this->_maximum, $maximum), false);\r
- }\r
- }\r
-\r
- /**\r
- * Forces the minimum value of the axis\r
- *\r
- * @param double $minimum The minumum value to use on the axis\r
- * @param bool $userEnforce This value should not be set, used internally\r
- */\r
- function forceMinimum($minimum, $userEnforce = true)\r
- { \r
- if (($userEnforce) || (!$this->_minimumSet)) {\r
- $this->_minimum = $minimum;\r
- $this->_minimumSet = $userEnforce;\r
- }\r
- $this->_calcLabelInterval();\r
- }\r
-\r
- /**\r
- * Forces the maximum value of the axis\r
- *\r
- * @param double $maximum The maximum value to use on the axis\r
- * @param bool $userEnforce This value should not be set, used internally\r
- */\r
- function forceMaximum($maximum, $userEnforce = true)\r
- {\r
- if (($userEnforce) || (!$this->_maximumSet)) {\r
- $this->_maximum = $maximum;\r
- $this->_maximumSet = $userEnforce;\r
- }\r
- $this->_calcLabelInterval();\r
- }\r
-\r
- /**\r
- * Show an arrow head on the 'end' of the axis\r
- */\r
- function showArrow()\r
- {\r
- $this->_showArrow = true;\r
- }\r
-\r
- /**\r
- * Do not show an arrow head on the 'end' of the axis (default)\r
- */\r
- function hideArrow()\r
- {\r
- $this->_showArrow = false;\r
- }\r
-\r
- /**\r
- * Return the label distance.\r
- *\r
- * @param int $level The label level to return the distance of\r
- * @return int The distance between 2 adjacent labels\r
- * @access private\r
- */\r
- function _labelDistance($level = 1)\r
- {\r
- $l1 = $this->_getNextLabel(false, $level);\r
- $l2 = $this->_getNextLabel($l1, $level);;\r
- return abs($this->_point($l2) - $this->_point($l1));\r
- }\r
-\r
- /**\r
- * Sets an interval for when labels are shown on the axis.\r
- *\r
- * By default 'auto' is used, forcing the axis to calculate a approximate\r
- * best label interval to be used. Specify an array to use user-defined\r
- * values for labels.\r
- *\r
- * @param mixed $labelInterval The interval with which labels are shown\r
- * @param int $level The label level to set the interval on\r
- */\r
- function setLabelInterval($labelInterval = 'auto', $level = 1)\r
- {\r
- if (!isset($this->_labelOptions[$level])) {\r
- $this->_labelOptions[$level] = array();\r
- }\r
-\r
- if ($labelInterval === 'auto') {\r
- $this->_labelOptions[$level]['type'] = 'auto';\r
- $this->_calcLabelInterval();\r
- } else {\r
- $this->_labelOptions[$level]['type'] = 'manual';\r
- $this->_labelOptions[$level]['interval'] = $labelInterval;\r
- }\r
- }\r
-\r
- /**\r
- * Sets options for the label at a specific level.\r
- *\r
- * Possible options are:\r
- * \r
- * 'showtext' true or false whether label text should be shown or not\r
- * \r
- * 'showoffset' should the label be shown at an offset, i.e. should the\r
- * label be shown at a position so that it does not overlap with prior\r
- * levels. Only applies to multilevel labels with text\r
- * \r
- * 'font' The font options as an associated array\r
- * \r
- * 'position' The position at which the labels are written ('inside' or\r
- * 'outside' the axis). NB! This relative position only applies to the\r
- * default location of the axis, i.e. if an x-axis is inverted then\r
- * 'outside' still refers to the "left" side of a normal y-axis (since this\r
- * is normally 'outside') but the actual output will be labels on the\r
- * "inside"!\r
- *\r
- * 'format' To format the label text according to a sprintf statement\r
- *\r
- * 'dateformat' To format the label as a date, fx. j. M Y = 29. Jun 2005\r
- *\r
- * @param string $option The label option name (see detailed description\r
- * for possible values)\r
- * @param mixed $value The value for the option\r
- * @param int $level The label level to set the interval on\r
- */\r
- function setLabelOption($option, $value, $level = 1)\r
- {\r
- if (!isset($this->_labelOptions[$level])) {\r
- $this->_labelOptions[$level] = array('type' => 'auto');\r
- }\r
-\r
- $this->_labelOptions[$level][$option] = $value;\r
- }\r
-\r
- /**\r
- * Sets options for the label at a specific level.\r
- *\r
- * The possible options are specified in {@link Image_Graph_Axis::\r
- * setLabelOption()}.\r
- *\r
- * @param array $options An assciated array with label options\r
- * @param int $level The label level to set the interval on\r
- */\r
- function setLabelOptions($options, $level = 1)\r
- {\r
- if (is_array($options)) {\r
- if (isset($this->_labelOptions[$level])) {\r
- $this->_labelOptions[$level] = array_merge($this->_labelOptions[$level], $options);\r
- } else {\r
- $this->_labelOptions[$level] = $options;\r
- }\r
- \r
- }\r
- } \r
- \r
- /**\r
- * Sets the title of this axis.\r
- *\r
- * This is used as an alternative (maybe better) method, than using layout's\r
- * for axis-title generation.\r
- * \r
- * To use the current propagated font, but just set it vertically, simply\r
- * pass 'vertical' as second parameter for vertical alignment down-to-up or\r
- * 'vertical2' for up-to-down alignment.\r
- *\r
- * @param string $title The title of this axis\r
- * @param Image_Graph_Font $font The font used for the title\r
- * @since 0.3.0dev2\r
- */\r
- function setTitle($title, $font = false)\r
- {\r
- $this->_title = $title;\r
- if ($font === 'vertical') {\r
- $this->_titleFont = array('vertical' => true, 'angle' => 90);\r
- } elseif ($font === 'vertical2') {\r
- $this->_titleFont = array('vertical' => true, 'angle' => 270);\r
- } else {\r
- $this->_titleFont =& $font;\r
- }\r
- }\r
-\r
- /**\r
- * Sets a fixed "size" for the axis.\r
- * \r
- * If the axis is any type of y-axis the size relates to the width of the\r
- * axis, if an x-axis is concerned the size is the height.\r
- *\r
- * @param int $size The fixed size of the axis\r
- * @since 0.3.0dev5\r
- */\r
- function setFixedSize($size)\r
- {\r
- $this->_fixedSize = $size;\r
- }\r
-\r
- /**\r
- * Preprocessor for values, ie for using logarithmic axis\r
- *\r
- * @param double $value The value to preprocess\r
- * @return double The preprocessed value\r
- * @access private\r
- */\r
- function _value($value)\r
- {\r
- return $value - $this->_getMinimum() + ($this->_pushValues ? 0.5 : 0);\r
- }\r
-\r
- /**\r
- * Apply the dataset to the axis\r
- *\r
- * @param Image_Graph_Dataset $dataset The dataset\r
- * @access private\r
- */\r
- function _applyDataset(&$dataset)\r
- {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- $this->_setMinimum($dataset->minimumX());\r
- $this->_setMaximum($dataset->maximumX());\r
- } else {\r
- $this->_setMinimum($dataset->minimumY());\r
- $this->_setMaximum($dataset->maximumY());\r
- }\r
- }\r
-\r
- /**\r
- * Get the pixel position represented by a value on the canvas\r
- *\r
- * @param double $value the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _point($value) \r
- { \r
- if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||\r
- (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))) \r
- {\r
- if ($this->_invert) { \r
- return max($this->_left, $this->_right - $this->_axisPadding['high'] - $this->_delta * $this->_value($value));\r
- } else {\r
- return min($this->_right, $this->_left + $this->_axisPadding['low'] + $this->_delta * $this->_value($value));\r
- } \r
- } else {\r
- if ($this->_invert) { \r
- return min($this->_bottom, $this->_top + $this->_axisPadding['high'] + $this->_delta * $this->_value($value));\r
- } else {\r
- return max($this->_top, $this->_bottom - $this->_axisPadding['low'] - $this->_delta * $this->_value($value));\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the axis intersection pixel position\r
- *\r
- * This is only to be called prior to output! I.e. between the user\r
- * invokation of Image_Graph::done() and any actual output is performed.\r
- * This is because it can change the axis range.\r
- *\r
- * @param double $value the intersection value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _intersectPoint($value)\r
- {\r
-\r
- if (($value === 'min') || ($value < $this->_getMinimum())) {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- if ($this->_invert) {\r
- return ($this->_transpose ? $this->_top : $this->_right);\r
- } else {\r
- return ($this->_transpose ? $this->_bottom : $this->_left);\r
- }\r
- } else {\r
- if ($this->_invert) {\r
- return ($this->_transpose ? $this->_right : $this->_top);\r
- } else {\r
- return ($this->_transpose ? $this->_left : $this->_bottom);\r
- }\r
- }\r
- } elseif (($value === 'max') || ($value > $this->_getMaximum())) {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- if ($this->_invert) {\r
- return ($this->_transpose ? $this->_bottom : $this->_left);\r
- } else {\r
- return ($this->_transpose ? $this->_top : $this->_right);\r
- }\r
- } else {\r
- if ($this->_invert) {\r
- return ($this->_transpose ? $this->_left : $this->_bottom);\r
- } else {\r
- return ($this->_transpose ? $this->_right : $this->_top);\r
- }\r
- }\r
- } \r
- \r
- return $this->_point($value);\r
- }\r
- \r
- /**\r
- * Calculate the delta value (the number of pixels representing one unit\r
- * on the axis)\r
- *\r
- * @return double The label interval\r
- * @access private\r
- */\r
- function _calcDelta()\r
- {\r
- if ($this->_axisValueSpan == 0) {\r
- $this->_delta = false;\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- $this->_delta = (($this->_transpose ? $this->height() : $this->width()) - ($this->_axisPadding['low'] + $this->_axisPadding['high'])) / ($this->_axisValueSpan + ($this->_pushValues ? 1 : 0));\r
- } else {\r
- $this->_delta = (($this->_transpose ? $this->width() : $this->height()) - ($this->_axisPadding['low'] + $this->_axisPadding['high'])) / ($this->_axisValueSpan + ($this->_pushValues ? 1 : 0));\r
- }\r
- } \r
- \r
- /**\r
- * Calculate the label interval\r
- *\r
- * If explicitly defined this will be calucated to an approximate best.\r
- *\r
- * @return double The label interval\r
- * @access private\r
- */\r
- function _calcLabelInterval()\r
- {\r
- $min = $this->_getMinimum();\r
- $max = $this->_getMaximum();\r
- \r
- $this->_axisValueSpan = $this->_axisSpan = abs($max - $min);\r
- \r
- if ((!empty($min)) && (!empty($max)) && ($min > $max)) {\r
- $this->_labelOptions[1]['interval'] = 1;\r
- return true;\r
- }\r
-\r
- $span = 0;\r
- foreach($this->_labelOptions as $level => $labelOptions) {\r
- if ((!isset($labelOptions['type'])) || ($labelOptions['type'] !== 'auto')) {\r
- $span = false;\r
- } elseif ($level == 1) {\r
- $span = $this->_axisValueSpan;\r
- } else {\r
- $l1 = $this->_getNextLabel(false, $level - 1);\r
- $l2 = $this->_getNextLabel($l1, $level - 1);\r
- if ((!is_numeric($l1)) || (!is_numeric($l2))) {\r
- $span == false;\r
- } else {\r
- $span = $l2 - $l1;\r
- }\r
- }\r
-\r
- if ($span !== false) {\r
- $interval = pow(10, floor(log10($span)));\r
-\r
- if ($interval == 0) {\r
- $interval = 1;\r
- }\r
-\r
- if ((($span) / $interval) < 3) {\r
- $interval = $interval / 4;\r
- } elseif ((($span) / $interval) < 5) {\r
- $interval = $interval / 2;\r
- } elseif ((($span) / $interval) > 10) {\r
- $interval = $interval * 2;\r
- }\r
-\r
- if (($interval -floor($interval) == 0.5) && ($interval != 0.5)) {\r
- $interval = floor($interval);\r
- }\r
-\r
- // just to be 100% sure that an interval of 0 is not returned some\r
- // additional checks are performed\r
- if ($interval == 0) {\r
- $interval = ($span) / 5;\r
- }\r
-\r
- if ($interval == 0) {\r
- $interval = 1;\r
- }\r
-\r
- $this->_labelOptions[$level]['interval'] = $interval;\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get next label point\r
- *\r
- * @param doubt $currentLabel The current label, if omitted or false, the\r
- * first is returned\r
- * @param int $level The label level to get the next label from\r
- * @return double The next label point\r
- * @access private\r
- */\r
- function _getNextLabel($currentLabel = false, $level = 1)\r
- {\r
- if (!isset($this->_labelOptions[$level])) {\r
- return false;\r
- }\r
-\r
- if (is_array($this->_labelOptions[$level]['interval'])) {\r
- if ($currentLabel === false) {\r
- reset($this->_labelOptions[$level]['interval']);\r
- }\r
-\r
- if (list(, $label) = each($this->_labelOptions[$level]['interval'])) {\r
- return $label;\r
- } else {\r
- return false;\r
- }\r
- } else {\r
- $li = $this->_labelInterval($level);\r
- if (($this->_axisSpan == 0) || ($this->_axisValueSpan == 0) ||\r
- ($li == 0)\r
- ) {\r
- return false;\r
- }\r
-\r
- $labelInterval = $this->_axisSpan / ($this->_axisValueSpan / $li);\r
-\r
- if ($labelInterval == 0) {\r
- return false;\r
- }\r
-\r
- if ($currentLabel === false) {\r
- $label = ((int) ($this->_getMinimum() / $labelInterval)) *\r
- $labelInterval - $labelInterval;\r
- while ($label < $this->_getMinimum()) {\r
- $label += $labelInterval;\r
- }\r
- return $label;\r
- } else {\r
- if ($currentLabel + $labelInterval > $this->_getMaximum()) {\r
- return false;\r
- } else {\r
- return $currentLabel + $labelInterval;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get the interval with which labels are shown on the axis.\r
- *\r
- * If explicitly defined this will be calucated to an approximate best.\r
- *\r
- * @param int $level The label level to get the label interval for\r
- * @return double The label interval\r
- * @access private\r
- */\r
- function _labelInterval($level = 1)\r
- {\r
- if ((!isset($this->_labelOptions[$level])) ||\r
- (!isset($this->_labelOptions[$level]['interval']))\r
- ) {\r
- return 1;\r
- }\r
-\r
- return (is_array($this->_labelOptions[$level]['interval'])\r
- ? 1\r
- : $this->_labelOptions[$level]['interval']\r
- );\r
- }\r
-\r
- /**\r
- * Get the size in pixels of the axis.\r
- *\r
- * For an x-axis this is the width of the axis including labels, and for an\r
- * y-axis it is the corrresponding height\r
- *\r
- * @return int The size of the axis\r
- * @access private\r
- */\r
- function _size()\r
- {\r
- if (!$this->_visible) {\r
- return 0;\r
- }\r
- \r
- if ($this->_fixedSize !== false) {\r
- return $this->_fixedSize;\r
- }\r
- \r
- krsort($this->_labelOptions);\r
-\r
- $totalMaxSize = 0;\r
-\r
- foreach ($this->_labelOptions as $level => $labelOptions) {\r
- if ((isset($labelOptions['showoffset'])) && ($labelOptions['showoffset'] === true)) {\r
- $this->_labelOptions[$level]['offset'] += $totalMaxSize;\r
- } elseif (!isset($this->_labelOptions[$level]['offset'])) {\r
- $this->_labelOptions[$level]['offset'] = 0;\r
- }\r
- if (\r
- (isset($labelOptions['showtext'])) && \r
- ($labelOptions['showtext'] === true) &&\r
- (\r
- (!isset($labelOptions['position'])) ||\r
- ($labelOptions['position'] == 'outside')\r
- ) \r
- ) {\r
- if (isset($labelOptions['font'])) {\r
- $font = $this->_getFont($labelOptions['font']);\r
- } else {\r
- if ($this->_defaultFontOptions !== false) {\r
- $font = $this->_defaultFontOptions;\r
- } else {\r
- $font = $this->_getFont();\r
- }\r
- }\r
- $this->_canvas->setFont($font);\r
-\r
- $value = false;\r
- $maxSize = 0;\r
- while (($value = $this->_getNextLabel($value, $level)) !== false) {\r
- if ((abs($value) > 0.0001) && ($value > $this->_getMinimum()) &&\r
- ($value < $this->_getMaximum()))\r
- {\r
- if (is_object($this->_dataPreProcessor)) {\r
- $labelText = $this->_dataPreProcessor->_process($value);\r
- } elseif (isset($labelOptions['format'])) {\r
- $labelText = sprintf($labelOptions['format'], $value);\r
- } elseif (isset($labelOptions['dateformat'])) {\r
- $labelText = date($labelOptions['dateformat'], $value);\r
- } else {\r
- $labelText = $value;\r
- }\r
-\r
- if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||\r
- (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))\r
- {\r
- $maxSize = max($maxSize, $this->_canvas->textHeight($labelText));\r
- } else {\r
- $maxSize = max($maxSize, $this->_canvas->textWidth($labelText));\r
- }\r
- }\r
- }\r
- if ((isset($labelOptions['showoffset'])) && ($labelOptions['showoffset'] === true)) {\r
- $totalMaxSize += $maxSize;\r
- } else {\r
- $totalMaxSize = max($totalMaxSize, $maxSize);\r
- }\r
- }\r
- }\r
-\r
- if ($this->_title) {\r
- $this->_canvas->setFont($this->_getTitleFont());\r
-\r
- if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||\r
- (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))\r
- {\r
- $totalMaxSize += $this->_canvas->textHeight($this->_title);\r
- } else {\r
- $totalMaxSize += $this->_canvas->textWidth($this->_title);\r
- }\r
- $totalMaxSize += 10;\r
- }\r
-\r
- return $totalMaxSize + 3;\r
- }\r
-\r
- /**\r
- * Adds a mark to the axis at the specified value\r
- *\r
- * @param double $value The value\r
- * @param double $value2 The second value (for a ranged mark)\r
- */\r
- function addMark($value, $value2 = false, $text = false)\r
- {\r
- if ($value2 === false) {\r
- $this->_marks[] = $value;\r
- } else {\r
- $this->_marks[] = array($value, $value2);\r
- }\r
- }\r
-\r
- /**\r
- * Is the axis numeric or not?\r
- *\r
- * @return bool True if numeric, false if not\r
- * @access private\r
- */\r
- function _isNumeric()\r
- {\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the major tick appearance.\r
- *\r
- * The positions are specified in pixels relative to the axis, meaning that\r
- * a value of -1 for start will draw the major tick 'line' starting at 1\r
- * pixel outside (negative) value the axis (i.e. below an x-axis and to the\r
- * left of a normal y-axis).\r
- *\r
- * @param int $start The start position relative to the axis\r
- * @param int $end The end position relative to the axis\r
- * @param int $level The label level to set the tick options for\r
- * @since 0.3.0dev2\r
- */\r
- function setTickOptions($start, $end, $level = 1)\r
- {\r
- if (!isset($this->_labelOptions[$level])) {\r
- $this->_labelOptions[$level] = array();\r
- }\r
-\r
- $this->_labelOptions[$level]['tick'] = array(\r
- 'start' => $start,\r
- 'end' => $end\r
- );\r
- }\r
- \r
- /**\r
- * Invert the axis direction\r
- * \r
- * If the minimum values are normally displayed fx. at the bottom setting\r
- * axis inversion to true, will cause the minimum values to be displayed at\r
- * the top and maximum at the bottom.\r
- *\r
- * @param bool $invert True if the axis is to be inverted, false if not\r
- * @since 0.3.0dev3\r
- */\r
- function setInverted($invert)\r
- {\r
- $this->_invert = $invert;\r
- }\r
-\r
- /**\r
- * Set axis intersection.\r
- *\r
- * Sets the value at which the axis intersects other axis, fx. at which Y-\r
- * value the x-axis intersects the y-axis (normally at 0).\r
- * \r
- * Possible values are 'default', 'min', 'max' or a number between axis min\r
- * and max (the value will automatically be limited to this range).\r
- * \r
- * For a coordinate system with 2 y-axis, the x-axis can either intersect\r
- * the primary or the secondary y-axis. To make the x-axis intersect the\r
- * secondary y-axis at a given value pass IMAGE_GRAPH_AXIS_Y_SECONDARY as\r
- * second parameter.\r
- *\r
- * @param mixed $intersection The value at which the axis intersect the\r
- * 'other' axis\r
- * @param mixed $axis The axis to intersect. Only applies to x-axis with\r
- * both a primary and secondary y-axis available.\r
- * @since 0.3.0dev2\r
- */\r
- function setAxisIntersection($intersection, $axis = 'default')\r
- {\r
- if ($axis == 'x') {\r
- $axis = IMAGE_GRAPH_AXIS_X;\r
- } elseif ($axis == 'y') {\r
- $axis = IMAGE_GRAPH_AXIS_Y;\r
- } elseif ($axis == 'ysec') {\r
- $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;\r
- }\r
- $this->_intersect = array(\r
- 'value' => $intersection,\r
- 'axis' => $axis\r
- );\r
- }\r
-\r
- /**\r
- * Get axis intersection data.\r
- * \r
- * @return array An array with the axis intersection data.\r
- * @since 0.3.0dev2\r
- * @access private\r
- */\r
- function _getAxisIntersection()\r
- {\r
- $value = $this->_intersect['value'];\r
- $axis = $this->_intersect['axis'];\r
- if (($this->_type == IMAGE_GRAPH_AXIS_Y) \r
- || ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY)\r
- ) {\r
- $axis = IMAGE_GRAPH_AXIS_X;\r
- } elseif ($axis == 'default') {\r
- $axis = IMAGE_GRAPH_AXIS_Y;\r
- }\r
- \r
- if ($value === 'default') {\r
- switch ($this->_type) {\r
- case IMAGE_GRAPH_AXIS_Y:\r
- $value = 'min';\r
- break;\r
- case IMAGE_GRAPH_AXIS_Y_SECONDARY:\r
- $value = 'max';\r
- break;\r
- case IMAGE_GRAPH_AXIS_X:\r
- $value = 0;\r
- break;\r
- }\r
- }\r
- \r
- return array('value' => $value, 'axis' => $axis);\r
- }\r
- \r
- /**\r
- * Resets the elements\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- parent::_reset();\r
- $this->_labelText = array();\r
- }\r
- \r
- /**\r
- * Output an axis tick mark.\r
- *\r
- * @param int $value The value to output\r
- * @param int $level The label level to draw the tick for\r
- * @access private\r
- */\r
- function _drawTick($value, $level = 1)\r
- {\r
- if (isset($this->_labelOptions[$level])) {\r
- $labelOptions = $this->_labelOptions[$level];\r
- $labelPosition = $this->_point($value);\r
-\r
- if (isset($labelOptions['offset'])) {\r
- $offset = $labelOptions['offset'];\r
- } else {\r
- $offset = 0;\r
- }\r
-\r
- if ((isset($labelOptions['showtext'])) && ($labelOptions['showtext'] === true)) {\r
- if (is_object($this->_dataPreProcessor)) {\r
- $labelText = $this->_dataPreProcessor->_process($value);\r
- } elseif (isset($labelOptions['format'])) {\r
- $labelText = sprintf($labelOptions['format'], $value);\r
- } elseif (isset($labelOptions['dateformat'])) {\r
- $labelText = date($labelOptions['dateformat'], $value);\r
- } else {\r
- $labelText = $value;\r
- }\r
-\r
- if (!in_array($labelText, $this->_labelText)) {\r
- $this->_labelText[] = $labelText;\r
-\r
- if (isset($labelOptions['font'])) {\r
- $font = $this->_getFont($labelOptions['font']);\r
- } else {\r
- if ($this->_defaultFontOptions !== false) {\r
- $font = $this->_defaultFontOptions;\r
- } else {\r
- $font = $this->_getFont();\r
- }\r
- }\r
- $this->_canvas->setFont($font);\r
- \r
- if (\r
- (isset($labelOptions['position'])) && \r
- ($labelOptions['position'] == 'inside')\r
- ) {\r
- $labelInside = true;\r
- } else {\r
- $labelInside = false;\r
- }\r
- \r
- if ($this->_type == IMAGE_GRAPH_AXIS_Y) {\r
- if ($this->_transpose) {\r
- if ($labelInside) {\r
- $this->write(\r
- $labelPosition,\r
- $this->_top - 3 - $offset,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,\r
- $font\r
- );\r
- } else {\r
- $this->write(\r
- $labelPosition,\r
- $this->_top + 6 + $offset + $font['size'] * (substr_count($labelText, "\n") + 1), \r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,\r
- $font\r
- );\r
- }\r
- }\r
- else { \r
- if ($labelInside) {\r
- $this->write(\r
- $this->_right + 3 + $offset,\r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,\r
- $font\r
- );\r
- } else {\r
- $this->write(\r
- $this->_right - 3 - $offset,\r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,\r
- $font\r
- );\r
- }\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {\r
- if ($this->_transpose) {\r
- if ($labelInside) {\r
- $this->write(\r
- $labelPosition,\r
- $this->_bottom + 6 + $offset + $font['size'] * (substr_count($labelText, "\n") + 1),\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,\r
- $font\r
- );\r
- } else {\r
- $this->write(\r
- $labelPosition,\r
- $this->_bottom - 3 - $offset, \r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,\r
- $font\r
- );\r
- }\r
- }\r
- else {\r
- if ($labelInside) {\r
- $this->write(\r
- $this->_left - 3 - $offset,\r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,\r
- $font\r
- );\r
- } else {\r
- $this->write(\r
- $this->_left + 3 + $offset,\r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,\r
- $font\r
- );\r
- }\r
- }\r
- } else {\r
- if ($this->_transpose) {\r
- if ($labelInside) {\r
- $this->write(\r
- $this->_right + 3 + $offset,\r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,\r
- $font\r
- );\r
- } else {\r
- $this->write(\r
- $this->_right - 3 - $offset, \r
- $labelPosition,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,\r
- $font\r
- );\r
- }\r
- }\r
- else {\r
- if ($labelInside === true) {\r
- $this->write(\r
- $labelPosition,\r
- $this->_top - 3 - $offset,\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_BOTTOM,\r
- $font\r
- );\r
- } else { \r
- $this->write(\r
- $labelPosition,\r
- $this->_top + 6 + $offset + $font['size'] * (substr_count($labelText, "\n") + 1),\r
- $labelText,\r
- IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_BOTTOM,\r
- $font\r
- );\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- $tickColor = false;\r
- if (isset($this->_labelOptions[$level]['tick'])) {\r
- if (isset($this->_labelOptions[$level]['tick']['start'])) { \r
- $tickStart = $this->_labelOptions[$level]['tick']['start'];\r
- } else {\r
- $tickStart = false;\r
- }\r
-\r
- if (isset($this->_labelOptions[$level]['tick']['end'])) { \r
- $tickEnd = $this->_labelOptions[$level]['tick']['end'];\r
- } else {\r
- $tickEnd = false;\r
- }\r
- \r
- if ((isset($this->_labelOptions[$level]['tick']['color'])) && ($this->_labelOptions[$level]['tick']['color'] !== false)) {\r
- $tickColor = $this->_labelOptions[$level]['tick']['color'];\r
- }\r
- }\r
- \r
- if ($tickStart === false) {\r
- $tickStart = -2;\r
- }\r
- \r
- if ($tickEnd === false) {\r
- $tickEnd = 2;\r
- }\r
-\r
- if ($tickColor !== false) {\r
- $this->_canvas->setLineColor($tickColor);\r
- }\r
- else {\r
- $this->_getLineStyle();\r
- }\r
- \r
- if ($this->_type == IMAGE_GRAPH_AXIS_Y) {\r
- if ($tickStart === 'auto') {\r
- $tickStart = -$offset;\r
- }\r
- if ($this->_transpose) {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $labelPosition,\r
- 'y0' => $this->_top + $tickStart,\r
- 'x1' => $labelPosition,\r
- 'y1' => $this->_top + $tickEnd\r
- )\r
- );\r
- }\r
- else {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $this->_right + $tickStart,\r
- 'y0' => $labelPosition,\r
- 'x1' => $this->_right + $tickEnd,\r
- 'y1' => $labelPosition\r
- )\r
- );\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {\r
- if ($tickStart === 'auto') {\r
- $tickStart = $offset;\r
- }\r
- if ($this->_transpose) {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $labelPosition,\r
- 'y0' => $this->_bottom - $tickStart,\r
- 'x1' => $labelPosition,\r
- 'y1' => $this->_bottom - $tickEnd\r
- )\r
- );\r
- }\r
- else {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $this->_left - $tickStart,\r
- 'y0' => $labelPosition,\r
- 'x1' => $this->_left - $tickEnd,\r
- 'y1' => $labelPosition\r
- )\r
- );\r
- }\r
- } else {\r
- if ($tickStart === 'auto') {\r
- $tickStart = $offset;\r
- }\r
- if ($this->_transpose) {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $this->_right + $tickStart,\r
- 'y0' => $labelPosition,\r
- 'x1' => $this->_right + $tickEnd,\r
- 'y1' => $labelPosition\r
- )\r
- );\r
- }\r
- else {\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $labelPosition,\r
- 'y0' => $this->_top - $tickStart,\r
- 'x1' => $labelPosition,\r
- 'y1' => $this->_top - $tickEnd\r
- )\r
- );\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Draws axis lines.\r
- *\r
- * @access private\r
- */\r
- function _drawAxisLines()\r
- {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- $this->_getLineStyle(); \r
- $this->_getFillStyle(); \r
- \r
- if ($this->_transpose) {\r
- $data = array(\r
- 'x0' => $this->_right,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_bottom\r
- );\r
- } else {\r
- $data = array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_top\r
- );\r
- }\r
- \r
- if ($this->_showArrow) {\r
- if ($this->_getMaximum() <= 0) {\r
- $data['end0'] = 'arrow2';\r
- $data['size0'] = 7;\r
- }\r
- else {\r
- $data['end1'] = 'arrow2';\r
- $data['size1'] = 7;\r
- }\r
- } \r
- \r
- $this->_canvas->line($data);\r
-\r
- if ($this->_title) {\r
- if (!$this->_transpose) {\r
- $y = $this->_bottom;\r
- $x = $this->_left + $this->width() / 2;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_BOTTOM, $this->_getTitleFont());\r
- }\r
- else {\r
- $y = $this->_top + $this->height() / 2;\r
- $x = $this->_left;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());\r
- }\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {\r
- $this->_getLineStyle();\r
- $this->_getFillStyle(); \r
- \r
- if ($this->_transpose) {\r
- $data = array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_bottom,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_bottom\r
- );\r
- } else {\r
- $data = array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_bottom,\r
- 'x1' => $this->_left,\r
- 'y1' => $this->_top\r
- );\r
- }\r
- if ($this->_showArrow) {\r
- if ($this->_getMaximum() <= 0) {\r
- $data['end0'] = 'arrow2';\r
- $data['size0'] = 7;\r
- }\r
- else {\r
- $data['end1'] = 'arrow2';\r
- $data['size1'] = 7;\r
- }\r
- } \r
- $this->_canvas->line($data);\r
-\r
- if ($this->_title) {\r
- if ($this->_transpose) {\r
- $y = $this->_top;\r
- $x = $this->_left + $this->width() / 2;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_TOP, $this->_getTitleFont());\r
- }\r
- else {\r
- $y = $this->_top + $this->height() / 2;\r
- $x = $this->_right;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());\r
- }\r
- }\r
- } else {\r
- $this->_getLineStyle();\r
- $this->_getFillStyle(); \r
- \r
- if ($this->_transpose) {\r
- $data = array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_top\r
- );\r
- } else {\r
- $data = array(\r
- 'x0' => $this->_right,\r
- 'y0' => $this->_bottom,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_top\r
- );\r
- }\r
- if ($this->_showArrow) {\r
- if ($this->_getMaximum() <= 0) {\r
- $data['end0'] = 'arrow2';\r
- $data['size0'] = 7;\r
- }\r
- else {\r
- $data['end1'] = 'arrow2';\r
- $data['size1'] = 7;\r
- }\r
- } \r
- $this->_canvas->line($data); \r
-\r
- if ($this->_title) {\r
- if ($this->_transpose) {\r
- $y = $this->_bottom;\r
- $x = $this->_left + $this->width() / 2;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_BOTTOM, $this->_getTitleFont());\r
- }\r
- else {\r
- $y = $this->_top + $this->height() / 2;\r
- $x = $this->_left;\r
- $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Causes the object to update all sub elements coordinates\r
- *\r
- * (Image_Graph_Common, does not itself have coordinates, this is basically\r
- * an abstract method)\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- parent::_updateCoords();\r
- $this->_calcDelta();\r
- }\r
- \r
- /**\r
- * Output the axis\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $this->_canvas->startGroup(get_class($this)); \r
-\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
- \r
- $this->_drawAxisLines();\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_ticks'); \r
- ksort($this->_labelOptions);\r
- foreach ($this->_labelOptions as $level => $labelOption) {\r
- $value = false;\r
- while (($value = $this->_getNextLabel($value, $level)) !== false) {\r
- if ((((abs($value) > 0.0001) || ($this->_showLabelZero)) &&\r
- (($value > $this->_getMinimum()) || ($this->_showLabelMinimum)) &&\r
- (($value < $this->_getMaximum()) || ($this->_showLabelMaximum))) &&\r
- ($value >= $this->_getMinimum()) && ($value <= $this->_getMaximum())\r
- ) {\r
- $this->_drawTick($value, $level);\r
- }\r
- }\r
- }\r
- $this->_canvas->endGroup(); \r
-\r
- $tickStart = -3;\r
- $tickEnd = 2;\r
-\r
- foreach ($this->_marks as $mark) {\r
- if (is_array($mark)) {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_right + $tickStart;\r
- $y0 = $this->_point($mark[1]);\r
- $x1 = $this->_right + $tickEnd;\r
- $y1 = $this->_point($mark[0]);\r
- }\r
- else {\r
- $x0 = $this->_point($mark[0]);\r
- $y0 = $this->_top + $tickStart;\r
- $x1 = $this->_point($mark[1]);\r
- $y1 = $this->_top + $tickEnd;\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_point($mark[0]);\r
- $y0 = $this->_top + $tickStart;\r
- $x1 = $this->_point($mark[1]);\r
- $y1 = $this->_top + $tickEnd;\r
- }\r
- else {\r
- $x0 = $this->_right + $tickStart;\r
- $y0 = $this->_point($mark[1]);\r
- $x1 = $this->_right + $tickEnd;\r
- $y1 = $this->_point($mark[0]);\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_point($mark[0]);\r
- $y0 = $this->_bottom + $tickStart;\r
- $x1 = $this->_point($mark[1]);\r
- $y1 = $this->_bottom + $tickEnd;\r
- }\r
- else {\r
- $x0 = $this->_left + $tickStart;\r
- $y0 = $this->_point($mark[1]);\r
- $x1 = $this->_left + $tickEnd;\r
- $y1 = $this->_point($mark[0]);\r
- } \r
- }\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->rectangle(array('x0' => $x0, 'y0' => $y0, 'x1' => $x1, 'y1' => $y1));\r
- } else {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_right + 5;\r
- $y0 = $this->_point($mark);\r
- $x1 = $this->_right + 15;\r
- $y1 = $y0;\r
- }\r
- else {\r
- $x0 = $this->_point($mark);\r
- $y0 = $this->_top - 5;\r
- $x1 = $x0;\r
- $y1 = $this->_top - 15;\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_point($mark);\r
- $y0 = $this->_top - 5;\r
- $x1 = $x0;\r
- $y1 = $this->_top - 15;\r
- }\r
- else {\r
- $x0 = $this->_right + 5;\r
- $y0 = $this->_point($mark);\r
- $x1 = $this->_right + 15;\r
- $y1 = $y0;\r
- }\r
- } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {\r
- if ($this->_transpose) {\r
- $x0 = $this->_point($mark);\r
- $y0 = $this->_bottom + 5;\r
- $x1 = $x0;\r
- $y1 = $this->_bottom + 15;\r
- }\r
- else {\r
- $x0 = $this->_left - 5;\r
- $y0 = $this->_point($mark);\r
- $x1 = $this->_left - 15;\r
- $y1 = $y0;\r
- } \r
- }\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x0,\r
- 'y0' => $y0, \r
- 'x1' => $x1, \r
- 'y1' => $y1, \r
- 'end0' => 'arrow2',\r
- 'size0' => 5 \r
- )\r
- );\r
- }\r
- }\r
- $this->_canvas->endGroup(); \r
-\r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for axis handling.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Axis.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea/Element.php
+ */
+require_once 'Image/Graph/Plotarea/Element.php';
+
+/**
+ * Diplays a normal linear axis (either X- or Y-axis).
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis extends Image_Graph_Plotarea_Element
+{
+
+ /**
+ * The type of the axis, possible values are:
+ * <ul>
+ * <li>IMAGE_GRAPH_AXIS_X / IMAGE_GRAPH_AXIS_HORIZONTAL
+ * <li>IMAGE_GRAPH_AXIS_Y / IMAGE_GRAPH_AXIS_VERTICAL /
+ * IMAGE_GRAPH_AXIS_Y_SECONDARY
+ * </ul>
+ * @var int
+ * @access private
+ */
+ var $_type;
+
+ /**
+ * The minimum value the axis displays
+ * @var int
+ * @access private
+ */
+ var $_minimum = false;
+
+ /**
+ * The minimum value the axis has been explicitly set by the user
+ * @var bool
+ * @access private
+ */
+ var $_minimumSet = false;
+
+ /**
+ * The maximum value the axis displays
+ * @var int
+ * @access private
+ */
+ var $_maximum = false;
+
+ /**
+ * The maximum value the axis has been explicitly set by the user
+ * @var bool
+ * @access private
+ */
+ var $_maximumSet = false;
+
+ /**
+ * The value span of the axis.
+ * This is primarily included for performance reasons
+ * @var double
+ * @access private
+ */
+ var $_axisSpan = false;
+
+ /**
+ * The value span of the axis.
+ * This is primarily included for performance reasons
+ * @var double
+ * @access private
+ */
+ var $_axisValueSpan = false;
+
+ /**
+ * The axis padding.
+ * The index 'low' specifies the padding for the low axis values (when not
+ * inverted), i.e. to the left on an x-axis and on the bottom of an y-axis,
+ * vice versa for 'high'.
+ *
+ * Axis padding does not make sense on a normal linear y-axis with a 'y-min'
+ * of 0 since this corresponds to displaying a small part of the y-axis
+ * below 0!
+ *
+ * @var array
+ * @access private
+ */
+ var $_axisPadding = array('low' => 0, 'high' => 0);
+
+ /**
+ * The number of "pixels" representing 1 unit on the axis
+ *
+ * This is primarily included for performance reasons
+ * @var double
+ * @access private
+ */
+ var $_delta = false;
+
+ /**
+ * Specify if the axis should label the minimum value
+ * @var bool
+ * @access private
+ */
+ var $_showLabelMinimum = true;
+
+ /**
+ * Specify if the axis should label 0 (zero)
+ * @var bool
+ * @access private
+ */
+ var $_showLabelZero = false;
+
+ /**
+ * Specify if the axis should label the maximum value
+ * @var bool
+ * @access private
+ */
+ var $_showLabelMaximum = true;
+
+ /**
+ * Show arrow heads at the 'end' of the axis, default: false
+ * @var bool
+ * @access private
+ */
+ var $_showArrow = false;
+
+ /**
+ * Intersection data of axis
+ * @var array
+ * @access private
+ */
+ var $_intersect = array('value' => 'default', 'axis' => 'default');
+
+ /**
+ * The fixed size of the axis (i.e. width for y-axis, height for x-axis)
+ * @var mixed
+ * @access private
+ */
+ var $_fixedSize = false;
+
+ /**
+ * The label options
+ *
+ * Should text be shows, preferences for ticks. The indexes start at level
+ * 1, which is chosen for readability
+ * @var array
+ * @access private
+ */
+ var $_labelOptions = array(
+ 1 => array(
+ 'interval' => 1,
+ 'type' => 'auto',
+ 'tick' => array(
+ 'start' => -2,
+ 'end' => 2,
+ 'color' => false // default color
+ ),
+ 'showtext' => true,
+ 'showoffset' => false,
+ 'font' => array(),
+ 'offset' => 0,
+ 'position' => 'outside',
+ )
+ );
+
+ /**
+ * The labels that are shown.
+ *
+ * This is used to make values show only once...
+ * @access private
+ */
+ var $_labelText = array();
+
+ /**
+ * A data preprocessor for formatting labels, fx showing dates as a standard
+ * date instead of Unix time stamp
+ * @var Image_Graph_DatePreProcessor
+ * @access private
+ * @see Image_Graph_DataPreProcessor
+ */
+ var $_dataPreProcessor = null;
+
+ /**
+ * Point marked in the axis
+ * @var array
+ * @access private
+ */
+ var $_marks = array();
+
+ /**
+ * Specifies whether the values should be 'pushed' by 0.5
+ * @var bool
+ * @access private
+ */
+ var $_pushValues = false;
+
+ /**
+ * The title of this axis
+ * @var string
+ * @access private
+ */
+ var $_title = '';
+
+ /**
+ * The font used for the title of this axis
+ * @var Image_Graph_Font
+ * @access private
+ */
+ var $_titleFont = false;
+
+ /**
+ * Invert the axis (i.e. if an y-axis normally displays minimum values at
+ * the bottom, they are not displayed at the top
+ * @var bool
+ * @access private
+ * @since 0.3.0dev3
+ */
+ var $_invert = false;
+
+ /**
+ * Transpose the axis (i.e. is a normal y-axis transposed, so thats it's not show
+ * vertically as normally expected, but instead horizontally)
+ * @var bool
+ * @access private
+ */
+ var $_transpose = false;
+
+ /**
+ * Image_Graph_Axis [Constructor].
+ * Normally a manual creation should not be necessary, axis are created
+ * automatically by the {@link Image_Graph_Plotarea} constructor unless
+ * explicitly defined otherwise
+ *
+ * @param int $type The type (direction) of the Axis, use IMAGE_GRAPH_AXIS_X
+ * for an X-axis (default, may be omitted) and IMAGE_GRAPH_AXIS_Y for Y-
+ * axis)
+ */
+ function Image_Graph_Axis($type = IMAGE_GRAPH_AXIS_X)
+ {
+ parent::__construct();
+ $this->_type = $type;
+ $this->_fillStyle = 'black';
+ }
+
+ /**
+ * Push the values by 0.5 (for bar and step chart)
+ *
+ * @return void
+ * @access private
+ */
+ function _pushValues()
+ {
+ $this->_pushValues = true;
+ }
+
+ /**
+ * Sets the axis padding for a given position ('low' or 'high')
+ *
+ * @param string $where The position
+ * @param int $value The number of pixels to "pad"
+ *
+ * @return void
+ * @access private
+ */
+ function _setAxisPadding($where, $value)
+ {
+ $this->_axisPadding[$where] = $value;
+ }
+
+ /**
+ * Gets the font of the title.
+ *
+ * If not font has been set, the parent font is propagated through it's
+ * children.
+ *
+ * @return array An associated array used for canvas
+ * @access private
+ */
+ function _getTitleFont()
+ {
+ if ($this->_titleFont === false) {
+ if ($this->_defaultFontOptions !== false) {
+ return $this->_defaultFontOptions;
+ } else {
+ return $this->_getFont();
+ }
+ } else {
+ if (is_object($this->_titleFont)) {
+ return $this->_titleFont->_getFont();
+ } elseif (is_array($this->_titleFont)) {
+ return $this->_getFont($this->_titleFont);
+ } elseif (is_int($this->_titleFont)) {
+ return $this->_getFont(array('size' => $this->_titleFont));
+ }
+ }
+ return array();
+ }
+
+ /**
+ * Shows a label for the the specified values.
+ *
+ * Allowed values are combinations of:
+ * <ul>
+ * <li>IMAGE_GRAPH_LABEL_MINIMUM
+ * <li>IMAGE_GRAPH_LABEL_ZERO
+ * <li>IMAGE_GRAPH_LABEL_MAXIMUM
+ * </ul>
+ * By default none of these are shows on the axis
+ *
+ * @param int $value The values to show labels for
+ *
+ * @return void
+ */
+ function showLabel($value)
+ {
+ $this->_showLabelMinimum = ($value & IMAGE_GRAPH_LABEL_MINIMUM);
+ $this->_showLabelZero = ($value & IMAGE_GRAPH_LABEL_ZERO);
+ $this->_showLabelMaximum = ($value & IMAGE_GRAPH_LABEL_MAXIMUM);
+ }
+
+ /**
+ * Sets a data preprocessor for formatting the axis labels
+ *
+ * @param Image_Graph_DataPreprocessor &$dataPreProcessor The data preprocessor
+ *
+ * @see Image_Graph_DataPreprocessor
+ * @return void
+ */
+ function setDataPreProcessor(& $dataPreProcessor)
+ {
+ $this->_dataPreProcessor =& $dataPreProcessor;
+ }
+
+ /**
+ * Gets the minimum value the axis will show
+ *
+ * @return double The minumum value
+ * @access private
+ */
+ function _getMinimum()
+ {
+ return $this->_minimum;
+ }
+
+ /**
+ * Gets the maximum value the axis will show
+ *
+ * @return double The maximum value
+ * @access private
+ */
+ function _getMaximum()
+ {
+ return $this->_maximum;
+ }
+
+ /**
+ * Sets the minimum value the axis will show
+ *
+ * @param double $minimum The minumum value to use on the axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setMinimum($minimum)
+ {
+ if ($this->_minimum === false) {
+ $this->forceMinimum($minimum, false);
+ } else {
+ $this->forceMinimum(min($this->_minimum, $minimum), false);
+ }
+ }
+
+ /**
+ * Sets the maximum value the axis will show
+ *
+ * @param double $maximum The maximum value to use on the axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setMaximum($maximum)
+ {
+ if ($this->_maximum === false) {
+ $this->forceMaximum($maximum, false);
+ } else {
+ $this->forceMaximum(max($this->_maximum, $maximum), false);
+ }
+ }
+
+ /**
+ * Forces the minimum value of the axis
+ *
+ * @param double $minimum The minumum value to use on the axis
+ * @param bool $userEnforce This value should not be set, used internally
+ *
+ * @return void
+ */
+ function forceMinimum($minimum, $userEnforce = true)
+ {
+ if (($userEnforce) || (!$this->_minimumSet)) {
+ $this->_minimum = $minimum;
+ $this->_minimumSet = $userEnforce;
+ }
+ $this->_calcLabelInterval();
+ }
+
+ /**
+ * Forces the maximum value of the axis
+ *
+ * @param double $maximum The maximum value to use on the axis
+ * @param bool $userEnforce This value should not be set, used internally
+ *
+ * @return void
+ */
+ function forceMaximum($maximum, $userEnforce = true)
+ {
+ if (($userEnforce) || (!$this->_maximumSet)) {
+ $this->_maximum = $maximum;
+ $this->_maximumSet = $userEnforce;
+ }
+ $this->_calcLabelInterval();
+ }
+
+ /**
+ * Show an arrow head on the 'end' of the axis
+ *
+ * @return void
+ */
+ function showArrow()
+ {
+ $this->_showArrow = true;
+ }
+
+ /**
+ * Do not show an arrow head on the 'end' of the axis (default)
+ *
+ * @return void
+ */
+ function hideArrow()
+ {
+ $this->_showArrow = false;
+ }
+
+ /**
+ * Return the label distance.
+ *
+ * @param int $level The label level to return the distance of
+ *
+ * @return int The distance between 2 adjacent labels
+ * @access private
+ */
+ function _labelDistance($level = 1)
+ {
+ $l1 = $this->_getNextLabel(false, $level);
+ $l2 = $this->_getNextLabel($l1, $level);;
+ return abs($this->_point($l2) - $this->_point($l1));
+ }
+
+ /**
+ * Sets an interval for when labels are shown on the axis.
+ *
+ * By default 'auto' is used, forcing the axis to calculate a approximate
+ * best label interval to be used. Specify an array to use user-defined
+ * values for labels.
+ *
+ * @param mixed $labelInterval The interval with which labels are shown
+ * @param int $level The label level to set the interval on
+ *
+ * @return void
+ */
+ function setLabelInterval($labelInterval = 'auto', $level = 1)
+ {
+ if (!isset($this->_labelOptions[$level])) {
+ $this->_labelOptions[$level] = array();
+ }
+
+ if ($labelInterval === 'auto') {
+ $this->_labelOptions[$level]['type'] = 'auto';
+ $this->_calcLabelInterval();
+ } else {
+ $this->_labelOptions[$level]['type'] = 'manual';
+ $this->_labelOptions[$level]['interval'] = $labelInterval;
+ }
+ }
+
+ /**
+ * Sets options for the label at a specific level.
+ *
+ * Possible options are:
+ *
+ * 'showtext' true or false whether label text should be shown or not
+ *
+ * 'showoffset' should the label be shown at an offset, i.e. should the
+ * label be shown at a position so that it does not overlap with prior
+ * levels. Only applies to multilevel labels with text
+ *
+ * 'font' The font options as an associated array
+ *
+ * 'position' The position at which the labels are written ('inside' or
+ * 'outside' the axis). NB! This relative position only applies to the
+ * default location of the axis, i.e. if an x-axis is inverted then
+ * 'outside' still refers to the "left" side of a normal y-axis (since this
+ * is normally 'outside') but the actual output will be labels on the
+ * "inside"!
+ *
+ * 'format' To format the label text according to a sprintf statement
+ *
+ * 'dateformat' To format the label as a date, fx. j. M Y = 29. Jun 2005
+ *
+ * @param string $option The label option name (see detailed description
+ * for possible values)
+ * @param mixed $value The value for the option
+ * @param int $level The label level to set the interval on
+ *
+ * @return void
+ */
+ function setLabelOption($option, $value, $level = 1)
+ {
+ if (!isset($this->_labelOptions[$level])) {
+ $this->_labelOptions[$level] = array('type' => 'auto');
+ }
+
+ $this->_labelOptions[$level][$option] = $value;
+ }
+
+ /**
+ * Sets options for the label at a specific level.
+ *
+ * The possible options are specified in {@link Image_Graph_Axis::
+ * setLabelOption()}.
+ *
+ * @param array $options An assciated array with label options
+ * @param int $level The label level to set the interval on
+ *
+ * @return void
+ */
+ function setLabelOptions($options, $level = 1)
+ {
+ if (is_array($options)) {
+ if (isset($this->_labelOptions[$level])) {
+ $this->_labelOptions[$level] = array_merge($this->_labelOptions[$level], $options);
+ } else {
+ $this->_labelOptions[$level] = $options;
+ }
+
+ }
+ }
+
+ /**
+ * Sets the title of this axis.
+ *
+ * This is used as an alternative (maybe better) method, than using layout's
+ * for axis-title generation.
+ *
+ * To use the current propagated font, but just set it vertically, simply
+ * pass 'vertical' as second parameter for vertical alignment down-to-up or
+ * 'vertical2' for up-to-down alignment.
+ *
+ * @param string $title The title of this axis
+ * @param Image_Graph_Font $font The font used for the title
+ *
+ * @return void
+ * @since 0.3.0dev2
+ */
+ function setTitle($title, $font = false)
+ {
+ $this->_title = $title;
+ if ($font === 'vertical') {
+ $this->_titleFont = array('vertical' => true, 'angle' => 90);
+ } elseif ($font === 'vertical2') {
+ $this->_titleFont = array('vertical' => true, 'angle' => 270);
+ } else {
+ $this->_titleFont =& $font;
+ }
+ }
+
+ /**
+ * Sets a fixed "size" for the axis.
+ *
+ * If the axis is any type of y-axis the size relates to the width of the
+ * axis, if an x-axis is concerned the size is the height.
+ *
+ * @param int $size The fixed size of the axis
+ *
+ * @return void
+ * @since 0.3.0dev5
+ */
+ function setFixedSize($size)
+ {
+ $this->_fixedSize = $size;
+ }
+
+ /**
+ * Preprocessor for values, ie for using logarithmic axis
+ *
+ * @param double $value The value to preprocess
+ *
+ * @return double The preprocessed value
+ * @access private
+ */
+ function _value($value)
+ {
+ return $value - $this->_getMinimum() + ($this->_pushValues ? 0.5 : 0);
+ }
+
+ /**
+ * Apply the dataset to the axis
+ *
+ * @param Image_Graph_Dataset &$dataset The dataset
+ *
+ * @return void
+ * @access private
+ */
+ function _applyDataset(&$dataset)
+ {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ $this->_setMinimum($dataset->minimumX());
+ $this->_setMaximum($dataset->maximumX());
+ } else {
+ $this->_setMinimum($dataset->minimumY());
+ $this->_setMaximum($dataset->maximumY());
+ }
+ }
+
+ /**
+ * Get the pixel position represented by a value on the canvas
+ *
+ * @param double $value the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _point($value)
+ {
+ if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose))
+ || (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))
+ ) {
+ if ($this->_invert) {
+ return max($this->_left, $this->_right - $this->_axisPadding['high'] - $this->_delta * $this->_value($value));
+ } else {
+ return min($this->_right, $this->_left + $this->_axisPadding['low'] + $this->_delta * $this->_value($value));
+ }
+ } else {
+ if ($this->_invert) {
+ return min($this->_bottom, $this->_top + $this->_axisPadding['high'] + $this->_delta * $this->_value($value));
+ } else {
+ return max($this->_top, $this->_bottom - $this->_axisPadding['low'] - $this->_delta * $this->_value($value));
+ }
+ }
+ }
+
+
+ /**
+ * Get the axis intersection pixel position
+ *
+ * This is only to be called prior to output! I.e. between the user
+ * invokation of Image_Graph::done() and any actual output is performed.
+ * This is because it can change the axis range.
+ *
+ * @param double $value the intersection value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _intersectPoint($value)
+ {
+
+ if (($value === 'min') || ($value < $this->_getMinimum())) {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ if ($this->_invert) {
+ return ($this->_transpose ? $this->_top : $this->_right);
+ } else {
+ return ($this->_transpose ? $this->_bottom : $this->_left);
+ }
+ } else {
+ if ($this->_invert) {
+ return ($this->_transpose ? $this->_right : $this->_top);
+ } else {
+ return ($this->_transpose ? $this->_left : $this->_bottom);
+ }
+ }
+ } elseif (($value === 'max') || ($value > $this->_getMaximum())) {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ if ($this->_invert) {
+ return ($this->_transpose ? $this->_bottom : $this->_left);
+ } else {
+ return ($this->_transpose ? $this->_top : $this->_right);
+ }
+ } else {
+ if ($this->_invert) {
+ return ($this->_transpose ? $this->_left : $this->_bottom);
+ } else {
+ return ($this->_transpose ? $this->_right : $this->_top);
+ }
+ }
+ }
+
+ return $this->_point($value);
+ }
+
+ /**
+ * Calculate the delta value (the number of pixels representing one unit
+ * on the axis)
+ *
+ * @return double The label interval
+ * @access private
+ */
+ function _calcDelta()
+ {
+ if ($this->_axisValueSpan == 0) {
+ $this->_delta = false;
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ $this->_delta = (($this->_transpose ? $this->height() : $this->width()) - ($this->_axisPadding['low'] + $this->_axisPadding['high'])) / ($this->_axisValueSpan + ($this->_pushValues ? 1 : 0));
+ } else {
+ $this->_delta = (($this->_transpose ? $this->width() : $this->height()) - ($this->_axisPadding['low'] + $this->_axisPadding['high'])) / ($this->_axisValueSpan + ($this->_pushValues ? 1 : 0));
+ }
+ }
+
+ /**
+ * Calculate the label interval
+ *
+ * If explicitly defined this will be calucated to an approximate best.
+ *
+ * @return double The label interval
+ * @access private
+ */
+ function _calcLabelInterval()
+ {
+ $min = $this->_getMinimum();
+ $max = $this->_getMaximum();
+
+ $this->_axisValueSpan = $this->_axisSpan = abs($max - $min);
+
+ if ((!empty($min)) && (!empty($max)) && ($min > $max)) {
+ $this->_labelOptions[1]['interval'] = 1;
+ return true;
+ }
+
+ $span = 0;
+ foreach ($this->_labelOptions as $level => $labelOptions) {
+ if ((!isset($labelOptions['type'])) || ($labelOptions['type'] !== 'auto')) {
+ $span = false;
+ } elseif ($level == 1) {
+ $span = $this->_axisValueSpan;
+ } else {
+ $l1 = $this->_getNextLabel(false, $level - 1);
+ $l2 = $this->_getNextLabel($l1, $level - 1);
+ if ((!is_numeric($l1)) || (!is_numeric($l2))) {
+ $span == false;
+ } else {
+ $span = $l2 - $l1;
+ }
+ }
+
+ if ($span !== false) {
+ $interval = pow(10, floor(log10($span)));
+
+ if ($interval == 0) {
+ $interval = 1;
+ }
+
+ if ((($span) / $interval) < 3) {
+ $interval = $interval / 4;
+ } elseif ((($span) / $interval) < 5) {
+ $interval = $interval / 2;
+ } elseif ((($span) / $interval) > 10) {
+ $interval = $interval * 2;
+ }
+
+ if (($interval -floor($interval) == 0.5) && ($interval != 0.5)) {
+ $interval = floor($interval);
+ }
+
+ // just to be 100% sure that an interval of 0 is not returned some
+ // additional checks are performed
+ if ($interval == 0) {
+ $interval = ($span) / 5;
+ }
+
+ if ($interval == 0) {
+ $interval = 1;
+ }
+
+ $this->_labelOptions[$level]['interval'] = $interval;
+ }
+ }
+ }
+
+ /**
+ * Get next label point
+ *
+ * @param doubt $currentLabel The current label, if omitted or false, the
+ * first is returned
+ * @param int $level The label level to get the next label from
+ *
+ * @return double The next label point
+ * @access private
+ */
+ function _getNextLabel($currentLabel = false, $level = 1)
+ {
+ if (!isset($this->_labelOptions[$level])) {
+ return false;
+ }
+
+ if (is_array($this->_labelOptions[$level]['interval'])) {
+ if ($currentLabel === false) {
+ reset($this->_labelOptions[$level]['interval']);
+ }
+
+ if (list(, $label) = each($this->_labelOptions[$level]['interval'])) {
+ return $label;
+ } else {
+ return false;
+ }
+ } else {
+ $li = $this->_labelInterval($level);
+ if (($this->_axisSpan == 0) || ($this->_axisValueSpan == 0)
+ || ($li == 0)
+ ) {
+ return false;
+ }
+
+ $labelInterval = $this->_axisSpan / ($this->_axisValueSpan / $li);
+
+ if ($labelInterval == 0) {
+ return false;
+ }
+
+ if ($currentLabel === false) {
+ $label = ((int) ($this->_getMinimum() / $labelInterval)) *
+ $labelInterval - $labelInterval;
+ while ($label < $this->_getMinimum()) {
+ $label += $labelInterval;
+ }
+ return $label;
+ } else {
+ if ($currentLabel + $labelInterval > $this->_getMaximum()) {
+ return false;
+ } else {
+ return $currentLabel + $labelInterval;
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the interval with which labels are shown on the axis.
+ *
+ * If explicitly defined this will be calucated to an approximate best.
+ *
+ * @param int $level The label level to get the label interval for
+ *
+ * @return double The label interval
+ * @access private
+ */
+ function _labelInterval($level = 1)
+ {
+ if ((!isset($this->_labelOptions[$level]))
+ || (!isset($this->_labelOptions[$level]['interval']))
+ ) {
+ return 1;
+ }
+
+ return (is_array($this->_labelOptions[$level]['interval'])
+ ? 1
+ : $this->_labelOptions[$level]['interval']
+ );
+ }
+
+ /**
+ * Get the size in pixels of the axis.
+ *
+ * For an x-axis this is the width of the axis including labels, and for an
+ * y-axis it is the corrresponding height
+ *
+ * @return int The size of the axis
+ * @access private
+ */
+ function _size()
+ {
+ if (!$this->_visible) {
+ return 0;
+ }
+
+ if ($this->_fixedSize !== false) {
+ return $this->_fixedSize;
+ }
+
+ krsort($this->_labelOptions);
+
+ $totalMaxSize = 0;
+
+ foreach ($this->_labelOptions as $level => $labelOptions) {
+ if ((isset($labelOptions['showoffset'])) && ($labelOptions['showoffset'] === true)) {
+ $this->_labelOptions[$level]['offset'] += $totalMaxSize;
+ } elseif (!isset($this->_labelOptions[$level]['offset'])) {
+ $this->_labelOptions[$level]['offset'] = 0;
+ }
+ if ((isset($labelOptions['showtext']))
+ && ($labelOptions['showtext'] === true)
+ && ((!isset($labelOptions['position']))
+ || ($labelOptions['position'] == 'outside')
+ )
+ ) {
+ if (isset($labelOptions['font'])) {
+ $font = $this->_getFont($labelOptions['font']);
+ } else {
+ if ($this->_defaultFontOptions !== false) {
+ $font = $this->_defaultFontOptions;
+ } else {
+ $font = $this->_getFont();
+ }
+ }
+ $this->_canvas->setFont($font);
+
+ $value = false;
+ $maxSize = 0;
+ while (($value = $this->_getNextLabel($value, $level)) !== false) {
+ if ((abs($value) > 0.0001) && ($value > $this->_getMinimum())
+ && ($value < $this->_getMaximum())
+ ) {
+ if (is_object($this->_dataPreProcessor)) {
+ $labelText = $this->_dataPreProcessor->_process($value);
+ } elseif (isset($labelOptions['format'])) {
+ $labelText = sprintf($labelOptions['format'], $value);
+ } elseif (isset($labelOptions['dateformat'])) {
+ $labelText = date($labelOptions['dateformat'], $value);
+ } else {
+ $labelText = $value;
+ }
+
+ if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose))
+ || (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))
+ ) {
+ $maxSize = max($maxSize, $this->_canvas->textHeight($labelText));
+ } else {
+ $maxSize = max($maxSize, $this->_canvas->textWidth($labelText));
+ }
+ }
+ }
+ if ((isset($labelOptions['showoffset'])) && ($labelOptions['showoffset'] === true)) {
+ $totalMaxSize += $maxSize;
+ } else {
+ $totalMaxSize = max($totalMaxSize, $maxSize);
+ }
+ }
+ }
+
+ if ($this->_title) {
+ $this->_canvas->setFont($this->_getTitleFont());
+
+ if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose))
+ || (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))
+ ) {
+ $totalMaxSize += $this->_canvas->textHeight($this->_title);
+ } else {
+ $totalMaxSize += $this->_canvas->textWidth($this->_title);
+ }
+ $totalMaxSize += 10;
+ }
+
+ return $totalMaxSize + 3;
+ }
+
+ /**
+ * Adds a mark to the axis at the specified value
+ *
+ * @param double $value The value
+ * @param double $value2 The second value (for a ranged mark)
+ * @param string $text Text to display at mark (optional)
+ *
+ * @return void
+ */
+ function addMark($value, $value2 = false, $text = false)
+ {
+ if ($value2 === false) {
+ $this->_marks[] = $value;
+ } else {
+ $this->_marks[] = array($value, $value2);
+ }
+ }
+
+ /**
+ * Is the axis numeric or not?
+ *
+ * @return bool True if numeric, false if not
+ * @access private
+ */
+ function _isNumeric()
+ {
+ return true;
+ }
+
+ /**
+ * Set the major tick appearance.
+ *
+ * The positions are specified in pixels relative to the axis, meaning that
+ * a value of -1 for start will draw the major tick 'line' starting at 1
+ * pixel outside (negative) value the axis (i.e. below an x-axis and to the
+ * left of a normal y-axis).
+ *
+ * @param int $start The start position relative to the axis
+ * @param int $end The end position relative to the axis
+ * @param int $level The label level to set the tick options for
+ *
+ * @return void
+ * @since 0.3.0dev2
+ */
+ function setTickOptions($start, $end, $level = 1)
+ {
+ if (!isset($this->_labelOptions[$level])) {
+ $this->_labelOptions[$level] = array();
+ }
+
+ $this->_labelOptions[$level]['tick'] = array(
+ 'start' => $start,
+ 'end' => $end
+ );
+ }
+
+ /**
+ * Invert the axis direction
+ *
+ * If the minimum values are normally displayed fx. at the bottom setting
+ * axis inversion to true, will cause the minimum values to be displayed at
+ * the top and maximum at the bottom.
+ *
+ * @param bool $invert True if the axis is to be inverted, false if not
+ *
+ * @return void
+ * @since 0.3.0dev3
+ */
+ function setInverted($invert)
+ {
+ $this->_invert = $invert;
+ }
+
+ /**
+ * Set axis intersection.
+ *
+ * Sets the value at which the axis intersects other axis, fx. at which Y-
+ * value the x-axis intersects the y-axis (normally at 0).
+ *
+ * Possible values are 'default', 'min', 'max' or a number between axis min
+ * and max (the value will automatically be limited to this range).
+ *
+ * For a coordinate system with 2 y-axis, the x-axis can either intersect
+ * the primary or the secondary y-axis. To make the x-axis intersect the
+ * secondary y-axis at a given value pass IMAGE_GRAPH_AXIS_Y_SECONDARY as
+ * second parameter.
+ *
+ * @param mixed $intersection The value at which the axis intersect the
+ * 'other' axis
+ * @param mixed $axis The axis to intersect. Only applies to x-axis
+ * with both a primary and secondary y-axis available.
+ *
+ * @return void
+ * @since 0.3.0dev2
+ */
+ function setAxisIntersection($intersection, $axis = 'default')
+ {
+ if ($axis == 'x') {
+ $axis = IMAGE_GRAPH_AXIS_X;
+ } elseif ($axis == 'y') {
+ $axis = IMAGE_GRAPH_AXIS_Y;
+ } elseif ($axis == 'ysec') {
+ $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;
+ }
+ $this->_intersect = array(
+ 'value' => $intersection,
+ 'axis' => $axis
+ );
+ }
+
+ /**
+ * Get axis intersection data.
+ *
+ * @return array An array with the axis intersection data.
+ * @since 0.3.0dev2
+ * @access private
+ */
+ function _getAxisIntersection()
+ {
+ $value = $this->_intersect['value'];
+ $axis = $this->_intersect['axis'];
+ if (($this->_type == IMAGE_GRAPH_AXIS_Y)
+ || ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ ) {
+ $axis = IMAGE_GRAPH_AXIS_X;
+ } elseif ($axis == 'default') {
+ $axis = IMAGE_GRAPH_AXIS_Y;
+ }
+
+ if ($value === 'default') {
+ switch ($this->_type) {
+ case IMAGE_GRAPH_AXIS_Y:
+ $value = 'min';
+ break;
+ case IMAGE_GRAPH_AXIS_Y_SECONDARY:
+ $value = 'max';
+ break;
+ case IMAGE_GRAPH_AXIS_X:
+ $value = 0;
+ break;
+ }
+ }
+
+ return array('value' => $value, 'axis' => $axis);
+ }
+
+ /**
+ * Resets the elements
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ parent::_reset();
+ $this->_labelText = array();
+ }
+
+ /**
+ * Output an axis tick mark.
+ *
+ * @param int $value The value to output
+ * @param int $level The label level to draw the tick for
+ *
+ * @return void
+ * @access private
+ */
+ function _drawTick($value, $level = 1)
+ {
+ if (isset($this->_labelOptions[$level])) {
+ $labelOptions = $this->_labelOptions[$level];
+ $labelPosition = $this->_point($value);
+
+ if (isset($labelOptions['offset'])) {
+ $offset = $labelOptions['offset'];
+ } else {
+ $offset = 0;
+ }
+
+ if ((isset($labelOptions['showtext'])) && ($labelOptions['showtext'] === true)) {
+ if (is_object($this->_dataPreProcessor)) {
+ $labelText = $this->_dataPreProcessor->_process($value);
+ } elseif (isset($labelOptions['format'])) {
+ $labelText = sprintf($labelOptions['format'], $value);
+ } elseif (isset($labelOptions['dateformat'])) {
+ $labelText = date($labelOptions['dateformat'], $value);
+ } else {
+ $labelText = $value;
+ }
+
+ if (!in_array($labelText, $this->_labelText)) {
+ $this->_labelText[] = $labelText;
+
+ if (isset($labelOptions['font'])) {
+ $font = $this->_getFont($labelOptions['font']);
+ } else {
+ if ($this->_defaultFontOptions !== false) {
+ $font = $this->_defaultFontOptions;
+ } else {
+ $font = $this->_getFont();
+ }
+ }
+ $this->_canvas->setFont($font);
+
+ if ((isset($labelOptions['position']))
+ && ($labelOptions['position'] == 'inside')
+ ) {
+ $labelInside = true;
+ } else {
+ $labelInside = false;
+ }
+
+ if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
+ if ($this->_transpose) {
+ if ($labelInside) {
+ $this->write(
+ $labelPosition,
+ $this->_top - 4 - $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,
+ $font
+ );
+ } else {
+ $this->write(
+ $labelPosition,
+ $this->_top + 4 + $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_TOP | IMAGE_GRAPH_ALIGN_CENTER_X,
+ $font
+ );
+ }
+ } else {
+ if ($labelInside) {
+ $this->write(
+ $this->_right + 4 + $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,
+ $font
+ );
+ } else {
+ $this->write(
+ $this->_right - 4 - $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,
+ $font
+ );
+ }
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
+ if ($this->_transpose) {
+ if ($labelInside) {
+ $this->write(
+ $labelPosition,
+ $this->_bottom + 4 + $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_TOP | IMAGE_GRAPH_ALIGN_CENTER_X,
+ $font
+ );
+ } else {
+ $this->write(
+ $labelPosition,
+ $this->_bottom - 4 - $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X,
+ $font
+ );
+ }
+ } else {
+ if ($labelInside) {
+ $this->write(
+ $this->_left - 4 - $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,
+ $font
+ );
+ } else {
+ $this->write(
+ $this->_left + 4 + $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,
+ $font
+ );
+ }
+ }
+ } else {
+ if ($this->_transpose) {
+ if ($labelInside) {
+ $this->write(
+ $this->_right + 4 + $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT,
+ $font
+ );
+ } else {
+ $this->write(
+ $this->_right - 4 - $offset,
+ $labelPosition,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT,
+ $font
+ );
+ }
+ } else {
+ if ($labelInside === true) {
+ $this->write(
+ $labelPosition,
+ $this->_top - 4 - $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_BOTTOM,
+ $font
+ );
+ } else {
+ $this->write(
+ $labelPosition,
+ $this->_top + 4 + $offset,
+ $labelText,
+ IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_TOP,
+ $font
+ );
+ }
+ }
+ }
+ }
+ }
+
+ $tickColor = false;
+ if (isset($this->_labelOptions[$level]['tick'])) {
+ if (isset($this->_labelOptions[$level]['tick']['start'])) {
+ $tickStart = $this->_labelOptions[$level]['tick']['start'];
+ } else {
+ $tickStart = false;
+ }
+
+ if (isset($this->_labelOptions[$level]['tick']['end'])) {
+ $tickEnd = $this->_labelOptions[$level]['tick']['end'];
+ } else {
+ $tickEnd = false;
+ }
+
+ if ((isset($this->_labelOptions[$level]['tick']['color'])) && ($this->_labelOptions[$level]['tick']['color'] !== false)) {
+ $tickColor = $this->_labelOptions[$level]['tick']['color'];
+ }
+ }
+
+ if ($tickStart === false) {
+ $tickStart = -2;
+ }
+
+ if ($tickEnd === false) {
+ $tickEnd = 2;
+ }
+
+ if ($tickColor !== false) {
+ $this->_canvas->setLineColor($tickColor);
+ } else {
+ $this->_getLineStyle();
+ }
+
+ if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
+ if ($tickStart === 'auto') {
+ $tickStart = -$offset;
+ }
+ if ($this->_transpose) {
+ $this->_canvas->line(
+ array(
+ 'x0' => $labelPosition,
+ 'y0' => $this->_top + $tickStart,
+ 'x1' => $labelPosition,
+ 'y1' => $this->_top + $tickEnd
+ )
+ );
+ } else {
+ $this->_canvas->line(
+ array(
+ 'x0' => $this->_right + $tickStart,
+ 'y0' => $labelPosition,
+ 'x1' => $this->_right + $tickEnd,
+ 'y1' => $labelPosition
+ )
+ );
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
+ if ($tickStart === 'auto') {
+ $tickStart = $offset;
+ }
+ if ($this->_transpose) {
+ $this->_canvas->line(
+ array(
+ 'x0' => $labelPosition,
+ 'y0' => $this->_bottom - $tickStart,
+ 'x1' => $labelPosition,
+ 'y1' => $this->_bottom - $tickEnd
+ )
+ );
+ } else {
+ $this->_canvas->line(
+ array(
+ 'x0' => $this->_left - $tickStart,
+ 'y0' => $labelPosition,
+ 'x1' => $this->_left - $tickEnd,
+ 'y1' => $labelPosition
+ )
+ );
+ }
+ } else {
+ if ($tickStart === 'auto') {
+ $tickStart = $offset;
+ }
+ if ($this->_transpose) {
+ $this->_canvas->line(
+ array(
+ 'x0' => $this->_right + $tickStart,
+ 'y0' => $labelPosition,
+ 'x1' => $this->_right + $tickEnd,
+ 'y1' => $labelPosition
+ )
+ );
+ } else {
+ $this->_canvas->line(
+ array(
+ 'x0' => $labelPosition,
+ 'y0' => $this->_top - $tickStart,
+ 'x1' => $labelPosition,
+ 'y1' => $this->_top - $tickEnd
+ )
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * Draws axis lines.
+ *
+ * @return void
+ * @access private
+ */
+ function _drawAxisLines()
+ {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+
+ if ($this->_transpose) {
+ $data = array(
+ 'x0' => $this->_right,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_bottom
+ );
+ } else {
+ $data = array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_top
+ );
+ }
+
+ if ($this->_showArrow) {
+ if ($this->_getMaximum() <= 0) {
+ $data['end0'] = 'arrow2';
+ $data['size0'] = 7;
+ } else {
+ $data['end1'] = 'arrow2';
+ $data['size1'] = 7;
+ }
+ }
+
+ $this->_canvas->line($data);
+
+ if ($this->_title) {
+ if (!$this->_transpose) {
+ $y = $this->_bottom;
+ $x = $this->_left + $this->width() / 2;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_BOTTOM, $this->_getTitleFont());
+ } else {
+ $y = $this->_top + $this->height() / 2;
+ $x = $this->_left;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());
+ }
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+
+ if ($this->_transpose) {
+ $data = array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_bottom,
+ 'x1' => $this->_right,
+ 'y1' => $this->_bottom
+ );
+ } else {
+ $data = array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_bottom,
+ 'x1' => $this->_left,
+ 'y1' => $this->_top
+ );
+ }
+ if ($this->_showArrow) {
+ if ($this->_getMaximum() <= 0) {
+ $data['end0'] = 'arrow2';
+ $data['size0'] = 7;
+ } else {
+ $data['end1'] = 'arrow2';
+ $data['size1'] = 7;
+ }
+ }
+ $this->_canvas->line($data);
+
+ if ($this->_title) {
+ if ($this->_transpose) {
+ $y = $this->_top;
+ $x = $this->_left + $this->width() / 2;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_TOP, $this->_getTitleFont());
+ } else {
+ $y = $this->_top + $this->height() / 2;
+ $x = $this->_right;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());
+ }
+ }
+ } else {
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+
+ if ($this->_transpose) {
+ $data = array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_top
+ );
+ } else {
+ $data = array(
+ 'x0' => $this->_right,
+ 'y0' => $this->_bottom,
+ 'x1' => $this->_right,
+ 'y1' => $this->_top
+ );
+ }
+ if ($this->_showArrow) {
+ if ($this->_getMaximum() <= 0) {
+ $data['end0'] = 'arrow2';
+ $data['size0'] = 7;
+ } else {
+ $data['end1'] = 'arrow2';
+ $data['size1'] = 7;
+ }
+ }
+ $this->_canvas->line($data);
+
+ if ($this->_title) {
+ if ($this->_transpose) {
+ $y = $this->_bottom;
+ $x = $this->_left + $this->width() / 2;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_BOTTOM, $this->_getTitleFont());
+ } else {
+ $y = $this->_top + $this->height() / 2;
+ $x = $this->_left;
+ $this->write($x, $y, $this->_title, IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y, $this->_getTitleFont());
+ }
+ }
+ }
+ }
+
+ /**
+ * Causes the object to update all sub elements coordinates
+ *
+ * (Image_Graph_Common, does not itself have coordinates, this is basically
+ * an abstract method)
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ parent::_updateCoords();
+ $this->_calcDelta();
+ }
+
+ /**
+ * Output the axis
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $this->_canvas->startGroup(get_class($this));
+
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_drawAxisLines();
+
+ $this->_canvas->startGroup(get_class($this) . '_ticks');
+ ksort($this->_labelOptions);
+ foreach ($this->_labelOptions as $level => $labelOption) {
+ $value = false;
+ while (($value = $this->_getNextLabel($value, $level)) !== false) {
+ if ((((abs($value) > 0.0001) || ($this->_showLabelZero))
+ && (($value > $this->_getMinimum()) || ($this->_showLabelMinimum))
+ && (($value < $this->_getMaximum()) || ($this->_showLabelMaximum)))
+ && ($value >= $this->_getMinimum()) && ($value <= $this->_getMaximum())
+ ) {
+ $this->_drawTick($value, $level);
+ }
+ }
+ }
+ $this->_canvas->endGroup();
+
+ $tickStart = -3;
+ $tickEnd = 2;
+
+ foreach ($this->_marks as $mark) {
+ if (is_array($mark)) {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ if ($this->_transpose) {
+ $x0 = $this->_right + $tickStart;
+ $y0 = $this->_point($mark[1]);
+ $x1 = $this->_right + $tickEnd;
+ $y1 = $this->_point($mark[0]);
+ } else {
+ $x0 = $this->_point($mark[0]);
+ $y0 = $this->_top + $tickStart;
+ $x1 = $this->_point($mark[1]);
+ $y1 = $this->_top + $tickEnd;
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y) {
+ if ($this->_transpose) {
+ $x0 = $this->_point($mark[0]);
+ $y0 = $this->_top + $tickStart;
+ $x1 = $this->_point($mark[1]);
+ $y1 = $this->_top + $tickEnd;
+ } else {
+ $x0 = $this->_right + $tickStart;
+ $y0 = $this->_point($mark[1]);
+ $x1 = $this->_right + $tickEnd;
+ $y1 = $this->_point($mark[0]);
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
+ if ($this->_transpose) {
+ $x0 = $this->_point($mark[0]);
+ $y0 = $this->_bottom + $tickStart;
+ $x1 = $this->_point($mark[1]);
+ $y1 = $this->_bottom + $tickEnd;
+ } else {
+ $x0 = $this->_left + $tickStart;
+ $y0 = $this->_point($mark[1]);
+ $x1 = $this->_left + $tickEnd;
+ $y1 = $this->_point($mark[0]);
+ }
+ }
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->rectangle(array('x0' => $x0, 'y0' => $y0, 'x1' => $x1, 'y1' => $y1));
+ } else {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ if ($this->_transpose) {
+ $x0 = $this->_right + 5;
+ $y0 = $this->_point($mark);
+ $x1 = $this->_right + 15;
+ $y1 = $y0;
+ } else {
+ $x0 = $this->_point($mark);
+ $y0 = $this->_top - 5;
+ $x1 = $x0;
+ $y1 = $this->_top - 15;
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y) {
+ if ($this->_transpose) {
+ $x0 = $this->_point($mark);
+ $y0 = $this->_top - 5;
+ $x1 = $x0;
+ $y1 = $this->_top - 15;
+ } else {
+ $x0 = $this->_right + 5;
+ $y0 = $this->_point($mark);
+ $x1 = $this->_right + 15;
+ $y1 = $y0;
+ }
+ } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
+ if ($this->_transpose) {
+ $x0 = $this->_point($mark);
+ $y0 = $this->_bottom + 5;
+ $x1 = $x0;
+ $y1 = $this->_bottom + 15;
+ } else {
+ $x0 = $this->_left - 5;
+ $y0 = $this->_point($mark);
+ $x1 = $this->_left - 15;
+ $y1 = $y0;
+ }
+ }
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x0,
+ 'y0' => $y0,
+ 'x1' => $x1,
+ 'y1' => $y1,
+ 'end0' => 'arrow2',
+ 'size0' => 5
+ )
+ );
+ }
+ }
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for axis handling.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Category.php,v 1.19 2006/03/02 12:15:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Axis.php\r
- */\r
-require_once 'Image/Graph/Axis.php';\r
-\r
-/**\r
- * A normal axis thats displays labels with a 'interval' of 1.\r
- * This is basically a normal axis where the range is\r
- * the number of labels defined, that is the range is explicitly defined\r
- * when constructing the axis.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Axis_Category extends Image_Graph_Axis\r
-{\r
-\r
- /**\r
- * The labels shown on the axis\r
- * @var array\r
- * @access private\r
- */\r
- var $_labels = false;\r
-\r
- /**\r
- * Image_Graph_Axis_Category [Constructor].\r
- *\r
- * @param int $type The type (direction) of the Axis\r
- */\r
- function Image_Graph_Axis_Category($type = IMAGE_GRAPH_AXIS_X)\r
- {\r
- parent::Image_Graph_Axis($type);\r
- $this->_labels = array();\r
- $this->setlabelInterval(1);\r
- }\r
-\r
- /**\r
- * Gets the minimum value the axis will show.\r
- *\r
- * This is always 0\r
- *\r
- * @return double The minumum value\r
- * @access private\r
- */\r
- function _getMinimum()\r
- {\r
- return 0;\r
- }\r
-\r
- /**\r
- * Gets the maximum value the axis will show.\r
- *\r
- * This is always the number of labels passed to the constructor.\r
- *\r
- * @return double The maximum value\r
- * @access private\r
- */\r
- function _getMaximum()\r
- {\r
- return count($this->_labels) - 1;\r
- }\r
-\r
- /**\r
- * Sets the minimum value the axis will show.\r
- *\r
- * A minimum cannot be set on a SequentialAxis, it is always 0.\r
- *\r
- * @param double Minimum The minumum value to use on the axis\r
- * @access private\r
- */\r
- function _setMinimum($minimum)\r
- {\r
- }\r
-\r
- /**\r
- * Sets the maximum value the axis will show\r
- *\r
- * A maximum cannot be set on a SequentialAxis, it is always the number\r
- * of labels passed to the constructor.\r
- *\r
- * @param double Maximum The maximum value to use on the axis\r
- * @access private\r
- */\r
- function _setMaximum($maximum)\r
- {\r
- }\r
-\r
- /**\r
- * Forces the minimum value of the axis\r
- *\r
- * <b>A minimum cannot be set on this type of axis</b>\r
- * \r
- * To modify the labels which are displayed on the axis, instead use \r
- * setLabelInterval($labels) where $labels is an array containing the \r
- * values/labels the axis should display. <b>Note!</b> Only values in\r
- * this array will then be displayed on the graph!\r
- *\r
- * @param double $minimum A minimum cannot be set on this type of axis\r
- */\r
- function forceMinimum($minimum, $userEnforce = true)\r
- {\r
- }\r
-\r
- /**\r
- * Forces the maximum value of the axis\r
- *\r
- * <b>A maximum cannot be set on this type of axis</b>\r
- * \r
- * To modify the labels which are displayed on the axis, instead use \r
- * setLabelInterval($labels) where $labels is an array containing the \r
- * values/labels the axis should display. <b>Note!</b> Only values in\r
- * this array will then be displayed on the graph!\r
- *\r
- * @param double $maximum A maximum cannot be set on this type of axis\r
- */\r
- function forceMaximum($maximum, $userEnforce = true)\r
- {\r
- }\r
-\r
- /**\r
- * Sets an interval for where labels are shown on the axis.\r
- *\r
- * The label interval is rounded to nearest integer value.\r
- *\r
- * @param double $labelInterval The interval with which labels are shown\r
- */\r
- function setLabelInterval($labelInterval = 'auto', $level = 1)\r
- {\r
- if (is_array($labelInterval)) {\r
- parent::setLabelInterval($labelInterval);\r
- } elseif ($labelInterval == 'auto') {\r
- parent::setLabelInterval(1);\r
- } else {\r
- parent::setLabelInterval(round($labelInterval));\r
- }\r
- }\r
-\r
- /**\r
- * Preprocessor for values, ie for using logarithmic axis\r
- *\r
- * @param double $value The value to preprocess\r
- * @return double The preprocessed value\r
- * @access private\r
- */\r
- function _value($value)\r
- {\r
-// $the_value = array_search($value, $this->_labels);\r
- if (isset($this->_labels[$value])) {\r
- $the_value = $this->_labels[$value];\r
- if ($the_value !== false) {\r
- return $the_value + ($this->_pushValues ? 0.5 : 0);\r
- } else {\r
- return 0;\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the minor label interval with which axis label ticks are drawn.\r
- *\r
- * For a sequential axis this is always disabled (i.e false)\r
- *\r
- * @return double The minor label interval, always false\r
- * @access private\r
- */\r
- function _minorLabelInterval()\r
- {\r
- return false;\r
- }\r
-\r
- /**\r
- * Get the size in pixels of the axis.\r
- *\r
- * For an x-axis this is the width of the axis including labels, and for an\r
- * y-axis it is the corrresponding height\r
- *\r
- * @return int The size of the axis\r
- * @access private\r
- */\r
- function _size()\r
- {\r
- if (!$this->_visible) {\r
- return 0;\r
- }\r
- \r
- $this->_canvas->setFont($this->_getFont());\r
-\r
- $maxSize = 0;\r
- foreach($this->_labels as $label => $id) {\r
- $labelPosition = $this->_point($label);\r
-\r
- if (is_object($this->_dataPreProcessor)) {\r
- $labelText = $this->_dataPreProcessor->_process($label);\r
- } else {\r
- $labelText = $label;\r
- }\r
-\r
- if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||\r
- (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))\r
- {\r
- $maxSize = max($maxSize, $this->_canvas->textHeight($labelText));\r
- } else {\r
- $maxSize = max($maxSize, $this->_canvas->textWidth($labelText));\r
- }\r
- }\r
-\r
- if ($this->_title) {\r
- $this->_canvas->setFont($this->_getTitleFont());\r
-\r
- if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||\r
- (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))\r
- {\r
- $maxSize += $this->_canvas->textHeight($this->_title);\r
- } else {\r
- $maxSize += $this->_canvas->textWidth($this->_title);\r
- }\r
- $maxSize += 10;\r
- }\r
- return $maxSize +3;\r
- }\r
-\r
- /**\r
- * Apply the dataset to the axis.\r
- *\r
- * This calculates the order of the categories, which is very important\r
- * for fx. line plots, so that the line does not "go backwards", consider\r
- * these X-sets:<p>\r
- * 1: (1, 2, 3, 4, 5, 6)<br>\r
- * 2: (0, 1, 2, 3, 4, 5, 6, 7)<p>\r
- * If they are not ordered, but simply appended, the categories on the axis\r
- * would be:<p>\r
- * X: (1, 2, 3, 4, 5, 6, 0, 7)<p>\r
- * Which would render the a line for the second plot to show incorrectly.\r
- * Instead this algorithm, uses and 'value- is- before' method to see that\r
- * the 0 is before a 1 in the second set, and that it should also be before\r
- * a 1 in the X set. Hence:<p>\r
- * X: (0, 1, 2, 3, 4, 5, 6, 7)\r
- *\r
- * @param Image_Graph_Dataset $dataset The dataset\r
- * @access private\r
- */\r
- function _applyDataset(&$dataset)\r
- {\r
- $newLabels = array();\r
- $allLabels = array();\r
-\r
- $dataset->_reset();\r
- $count = 0;\r
- $count_new = 0;\r
- while ($point = $dataset->_next()) {\r
- if ($this->_type == IMAGE_GRAPH_AXIS_X) {\r
- $data = $point['X'];\r
- } else {\r
- $data = $point['Y'];\r
- }\r
- if (!isset($this->_labels[$data])) {\r
- $newLabels[$data] = $count_new++;\r
- //$this->_labels[] = $data;\r
- }\r
- $allLabels[$data] = $count++;\r
- }\r
-\r
- if (count($this->_labels) == 0) {\r
- $this->_labels = $newLabels; \r
- } elseif ((is_array($newLabels)) && (count($newLabels) > 0)) { \r
- // get all intersecting labels\r
- $intersect = array_intersect(array_keys($allLabels), array_keys($this->_labels));\r
- // traverse all new and find their relative position withing the\r
- // intersec, fx value X0 is before X1 in the intersection, which\r
- // means that X0 should be placed before X1 in the label array\r
- foreach($newLabels as $newLabel => $id) {\r
- $key = $allLabels[$newLabel];\r
- reset($intersect);\r
- $this_value = false;\r
- // intersect indexes are the same as in allLabels!\r
- $first = true;\r
- while ((list($id, $value) = each($intersect)) &&\r
- ($this_value === false))\r
- {\r
- if (($first) && ($id > $key)) {\r
- $this_value = $value;\r
- } elseif ($id >= $key) {\r
- $this_value = $value;\r
- }\r
- $first = false;\r
- }\r
-\r
- if ($this_value === false) {\r
- // the new label was not found before anything in the\r
- // intersection -> append it\r
- $this->_labels[$newLabel] = count($this->_labels);\r
- } else {\r
- // the new label was found before $this_value in the\r
- // intersection, insert the label before this position in\r
- // the label array\r
-// $key = $this->_labels[$this_value];\r
- $keys = array_keys($this->_labels);\r
- $key = array_search($this_value, $keys);\r
- $pre = array_slice($keys, 0, $key);\r
- $pre[] = $newLabel;\r
- $post = array_slice($keys, $key);\r
- $this->_labels = array_flip(array_merge($pre, $post));\r
- }\r
- }\r
- unset($keys);\r
- }\r
-\r
- $labels = array_keys($this->_labels);\r
- $i = 0;\r
- foreach ($labels as $label) {\r
- $this->_labels[$label] = $i++;\r
- }\r
-\r
-// $this->_labels = array_values(array_unique($this->_labels));\r
- $this->_calcLabelInterval();\r
- }\r
-\r
- /**\r
- * Return the label distance.\r
- *\r
- * @return int The distance between 2 adjacent labels\r
- * @access private\r
- */\r
- function _labelDistance($level = 1)\r
- {\r
- reset($this->_labels);\r
- list($l1) = each($this->_labels);\r
- list($l2) = each($this->_labels);\r
- return abs($this->_point($l2) - $this->_point($l1));\r
- }\r
-\r
- /**\r
- * Get next label point\r
- *\r
- * @param doubt $point The current point, if omitted or false, the first is\r
- * returned\r
- * @return double The next label point\r
- * @access private\r
- */\r
- function _getNextLabel($currentLabel = false, $level = 1)\r
- {\r
- if ($currentLabel === false) {\r
- reset($this->_labels);\r
- }\r
- $result = false;\r
- $count = ($currentLabel === false ? $this->_labelInterval() - 1 : 0);\r
- while ($count < $this->_labelInterval()) {\r
- $result = (list($label) = each($this->_labels));\r
- $count++;\r
- }\r
- if ($result) {\r
- return $label;\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Is the axis numeric or not?\r
- *\r
- * @return bool True if numeric, false if not\r
- * @access private\r
- */\r
- function _isNumeric()\r
- {\r
- return false;\r
- }\r
-\r
- /**\r
- * Output the axis\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $result = true;\r
- if (Image_Graph_Element::_done() === false) {\r
- $result = false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $this->_drawAxisLines();\r
- \r
- $this->_canvas->startGroup(get_class($this) . '_ticks');\r
- $label = false;\r
- while (($label = $this->_getNextLabel($label)) !== false) {\r
- $this->_drawTick($label);\r
- }\r
- $this->_canvas->endGroup(); \r
-\r
- $this->_canvas->endGroup();\r
- \r
- return $result;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for axis handling.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Groupn
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Category.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Axis.php
+ */
+require_once 'Image/Graph/Axis.php';
+
+/**
+ * A normal axis thats displays labels with a 'interval' of 1.
+ * This is basically a normal axis where the range is
+ * the number of labels defined, that is the range is explicitly defined
+ * when constructing the axis.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis_Category extends Image_Graph_Axis
+{
+
+ /**
+ * The labels shown on the axis
+ * @var array
+ * @access private
+ */
+ var $_labels = false;
+
+ /**
+ * Image_Graph_Axis_Category [Constructor].
+ *
+ * @param int $type The type (direction) of the Axis
+ */
+ function Image_Graph_Axis_Category($type = IMAGE_GRAPH_AXIS_X)
+ {
+ parent::__construct($type);
+ $this->_labels = array();
+ $this->setlabelInterval(1);
+ }
+
+ /**
+ * Gets the minimum value the axis will show.
+ *
+ * This is always 0
+ *
+ * @return double The minumum value
+ * @access private
+ */
+ function _getMinimum()
+ {
+ return 0;
+ }
+
+ /**
+ * Gets the maximum value the axis will show.
+ *
+ * This is always the number of labels passed to the constructor.
+ *
+ * @return double The maximum value
+ * @access private
+ */
+ function _getMaximum()
+ {
+ return count($this->_labels) - 1;
+ }
+
+ /**
+ * Sets the minimum value the axis will show.
+ *
+ * A minimum cannot be set on a SequentialAxis, it is always 0.
+ *
+ * @param double $minimum The minumum value to use on the axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setMinimum($minimum)
+ {
+ }
+
+ /**
+ * Sets the maximum value the axis will show
+ *
+ * A maximum cannot be set on a SequentialAxis, it is always the number
+ * of labels passed to the constructor.
+ *
+ * @param double $maximum The maximum value to use on the axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setMaximum($maximum)
+ {
+ }
+
+ /**
+ * Forces the minimum value of the axis
+ *
+ * <b>A minimum cannot be set on this type of axis</b>
+ *
+ * To modify the labels which are displayed on the axis, instead use
+ * setLabelInterval($labels) where $labels is an array containing the
+ * values/labels the axis should display. <b>Note!</b> Only values in
+ * this array will then be displayed on the graph!
+ *
+ * @param double $minimum A minimum cannot be set on this type of axis
+ * @param bool $userEnforce ???
+ *
+ * @return void
+ */
+ function forceMinimum($minimum, $userEnforce = true)
+ {
+ }
+
+ /**
+ * Forces the maximum value of the axis
+ *
+ * <b>A maximum cannot be set on this type of axis</b>
+ *
+ * To modify the labels which are displayed on the axis, instead use
+ * setLabelInterval($labels) where $labels is an array containing the
+ * values/labels the axis should display. <b>Note!</b> Only values in
+ * this array will then be displayed on the graph!
+ *
+ * @param double $maximum A maximum cannot be set on this type of axis
+ * @param bool $userEnforce ???
+ *
+ * @return void
+ */
+ function forceMaximum($maximum, $userEnforce = true)
+ {
+ }
+
+ /**
+ * Sets an interval for where labels are shown on the axis.
+ *
+ * The label interval is rounded to nearest integer value.
+ *
+ * @param double $labelInterval The interval with which labels are shown
+ * @param int $level Label level
+ *
+ * @return void
+ */
+ function setLabelInterval($labelInterval = 'auto', $level = 1)
+ {
+ if (is_array($labelInterval)) {
+ parent::setLabelInterval($labelInterval);
+ } elseif ($labelInterval == 'auto') {
+ parent::setLabelInterval(1);
+ } else {
+ parent::setLabelInterval(round($labelInterval));
+ }
+ }
+
+ /**
+ * Preprocessor for values, ie for using logarithmic axis
+ *
+ * @param double $value The value to preprocess
+ *
+ * @return double The preprocessed value
+ * @access private
+ */
+ function _value($value)
+ {
+ // $the_value = array_search($value, $this->_labels);
+ if (isset($this->_labels[$value])) {
+ $the_value = $this->_labels[$value];
+ if ($the_value !== false) {
+ return $the_value + ($this->_pushValues ? 0.5 : 0);
+ } else {
+ return 0;
+ }
+ }
+ }
+
+
+ /**
+ * Get the minor label interval with which axis label ticks are drawn.
+ *
+ * For a sequential axis this is always disabled (i.e false)
+ *
+ * @return double The minor label interval, always false
+ * @access private
+ */
+ function _minorLabelInterval()
+ {
+ return false;
+ }
+
+ /**
+ * Get the size in pixels of the axis.
+ *
+ * For an x-axis this is the width of the axis including labels, and for an
+ * y-axis it is the corrresponding height
+ *
+ * @return int The size of the axis
+ * @access private
+ */
+ function _size()
+ {
+ if (!$this->_visible) {
+ return 0;
+ }
+
+ $this->_canvas->setFont($this->_getFont());
+
+ $maxSize = 0;
+ foreach ($this->_labels as $label => $id) {
+ $labelPosition = $this->_point($label);
+
+ if (is_object($this->_dataPreProcessor)) {
+ $labelText = $this->_dataPreProcessor->_process($label);
+ } else {
+ $labelText = $label;
+ }
+
+ if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose))
+ || (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))
+ ) {
+ $maxSize = max($maxSize, $this->_canvas->textHeight($labelText));
+ } else {
+ $maxSize = max($maxSize, $this->_canvas->textWidth($labelText));
+ }
+ }
+
+ if ($this->_title) {
+ $this->_canvas->setFont($this->_getTitleFont());
+
+ if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose))
+ || (($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose))
+ ) {
+ $maxSize += $this->_canvas->textHeight($this->_title);
+ } else {
+ $maxSize += $this->_canvas->textWidth($this->_title);
+ }
+ $maxSize += 10;
+ }
+ return $maxSize +3;
+ }
+
+ /**
+ * Apply the dataset to the axis.
+ *
+ * This calculates the order of the categories, which is very important
+ * for fx. line plots, so that the line does not "go backwards", consider
+ * these X-sets:<p>
+ * 1: (1, 2, 3, 4, 5, 6)<br>
+ * 2: (0, 1, 2, 3, 4, 5, 6, 7)<p>
+ * If they are not ordered, but simply appended, the categories on the axis
+ * would be:<p>
+ * X: (1, 2, 3, 4, 5, 6, 0, 7)<p>
+ * Which would render the a line for the second plot to show incorrectly.
+ * Instead this algorithm, uses and 'value- is- before' method to see that
+ * the 0 is before a 1 in the second set, and that it should also be before
+ * a 1 in the X set. Hence:<p>
+ * X: (0, 1, 2, 3, 4, 5, 6, 7)
+ *
+ * @param Image_Graph_Dataset &$dataset The dataset
+ *
+ * @return void
+ * @access private
+ */
+ function _applyDataset(&$dataset)
+ {
+ $newLabels = array();
+ $allLabels = array();
+
+ $dataset->_reset();
+ $count = 0;
+ $count_new = 0;
+ while ($point = $dataset->_next()) {
+ if ($this->_type == IMAGE_GRAPH_AXIS_X) {
+ $data = $point['X'];
+ } else {
+ $data = $point['Y'];
+ }
+ if (!isset($this->_labels[$data])) {
+ $newLabels[$data] = $count_new++;
+ //$this->_labels[] = $data;
+ }
+ $allLabels[$data] = $count++;
+ }
+
+ if (count($this->_labels) == 0) {
+ $this->_labels = $newLabels;
+ } elseif ((is_array($newLabels)) && (count($newLabels) > 0)) {
+ // get all intersecting labels
+ $intersect = array_intersect(array_keys($allLabels), array_keys($this->_labels));
+ // traverse all new and find their relative position withing the
+ // intersec, fx value X0 is before X1 in the intersection, which
+ // means that X0 should be placed before X1 in the label array
+ foreach ($newLabels as $newLabel => $id) {
+ $key = $allLabels[$newLabel];
+ reset($intersect);
+ $this_value = false;
+ // intersect indexes are the same as in allLabels!
+ $first = true;
+ while ((list($id, $value) = each($intersect))
+ && ($this_value === false)
+ ) {
+ if (($first) && ($id > $key)) {
+ $this_value = $value;
+ } elseif ($id >= $key) {
+ $this_value = $value;
+ }
+ $first = false;
+ }
+
+ if ($this_value === false) {
+ // the new label was not found before anything in the
+ // intersection -> append it
+ $this->_labels[$newLabel] = count($this->_labels);
+ } else {
+ // the new label was found before $this_value in the
+ // intersection, insert the label before this position in
+ // the label array
+ // $key = $this->_labels[$this_value];
+ $keys = array_keys($this->_labels);
+ $key = array_search($this_value, $keys);
+ $pre = array_slice($keys, 0, $key);
+ $pre[] = $newLabel;
+ $post = array_slice($keys, $key);
+ $this->_labels = array_flip(array_merge($pre, $post));
+ }
+ }
+ unset($keys);
+ }
+
+ $labels = array_keys($this->_labels);
+ $i = 0;
+ foreach ($labels as $label) {
+ $this->_labels[$label] = $i++;
+ }
+
+ //$this->_labels = array_values(array_unique($this->_labels));
+ $this->_calcLabelInterval();
+ }
+
+ /**
+ * Return the label distance.
+ *
+ * @param int $level Label level
+ *
+ * @return int The distance between 2 adjacent labels
+ * @access private
+ */
+ function _labelDistance($level = 1)
+ {
+ reset($this->_labels);
+ list($l1) = each($this->_labels);
+ list($l2) = each($this->_labels);
+ return abs($this->_point($l2) - $this->_point($l1));
+ }
+
+ /**
+ * Get next label point
+ *
+ * @param doubt $currentLabel The current label point. If omitted or false, the first is
+ * returned
+ * @param int $level Label level
+ *
+ * @return double The next label point
+ * @access private
+ */
+ function _getNextLabel($currentLabel = false, $level = 1)
+ {
+ if ($currentLabel === false) {
+ reset($this->_labels);
+ }
+ $result = false;
+ $count = ($currentLabel === false ? $this->_labelInterval() - 1 : 0);
+ while ($count < $this->_labelInterval()) {
+ $result = (list($label) = each($this->_labels));
+ $count++;
+ }
+ if ($result) {
+ return $label;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Is the axis numeric or not?
+ *
+ * @return bool True if numeric, false if not
+ * @access private
+ */
+ function _isNumeric()
+ {
+ return false;
+ }
+
+ /**
+ * Output the axis
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $result = true;
+ if (Image_Graph_Element::_done() === false) {
+ $result = false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $this->_drawAxisLines();
+
+ $this->_canvas->startGroup(get_class($this) . '_ticks');
+ $label = false;
+ while (($label = $this->_getNextLabel($label)) !== false) {
+ $this->_drawTick($label);
+ }
+ $this->_canvas->endGroup();
+
+ $this->_canvas->endGroup();
+
+ return $result;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for axis handling.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Logarithmic.php,v 1.15 2006/03/02 12:35:57 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Axis.php\r
- */\r
-require_once 'Image/Graph/Axis.php';\r
-\r
-/**\r
- * Diplays a logarithmic axis (either X- or Y-axis).\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Axis_Logarithmic extends Image_Graph_Axis\r
-{\r
-\r
- /**\r
- * Image_Graph_AxisLogarithmic [Constructor].\r
- *\r
- * Normally a manual creation should not be necessary, axis are\r
- * created automatically by the {@link Image_Graph_Plotarea} constructor\r
- * unless explicitly defined otherwise\r
- *\r
- * @param int $type The type (direction) of the Axis, use IMAGE_GRAPH_AXIS_X\r
- * for an X-axis (default, may be omitted) and IMAGE_GRAPH_AXIS_Y for Y-\r
- * axis)\r
- */\r
- function Image_Graph_Axis_Logarithmic($type = IMAGE_GRAPH_AXIS_X)\r
- {\r
- parent::Image_Graph_Axis($type);\r
- $this->showLabel(IMAGE_GRAPH_LABEL_MINIMUM + IMAGE_GRAPH_LABEL_MAXIMUM);\r
- $this->_minimum = 1;\r
- $this->_minimumSet = true;\r
- }\r
-\r
- /**\r
- * Calculate the label interval\r
- *\r
- * If explicitly defined this will be calucated to an approximate best.\r
- *\r
- * @return double The label interval\r
- * @access private\r
- */\r
- function _calcLabelInterval()\r
- {\r
- $result = parent::_calcLabelInterval();\r
- $this->_axisValueSpan = $this->_value($this->_axisSpan); \r
- return $result;\r
- }\r
-\r
- /**\r
- * Preprocessor for values, ie for using logarithmic axis\r
- *\r
- * @param double $value The value to preprocess\r
- * @return double The preprocessed value\r
- * @access private\r
- */\r
- function _value($value)\r
- {\r
- return log10($value) - log10($this->_minimum);\r
- }\r
-\r
- /**\r
- * Get next label point\r
- *\r
- * @param doubt $point The current point, if omitted or false, the first is\r
- * returned\r
- * @return double The next label point\r
- * @access private\r
- */\r
- function _getNextLabel($currentLabel = false, $level = 1)\r
- {\r
- if (is_array($this->_labelOptions[$level]['interval'])) {\r
- return parent::_getNextLabel($currentLabel, $level);\r
- }\r
-\r
- if ($currentLabel !== false) {\r
- $value = log10($currentLabel);\r
- $base = floor($value);\r
- $frac = $value - $base;\r
- for ($i = 2; $i < 10; $i++) {\r
- if ($frac <= (log10($i)-0.01)) { \r
- $label = pow(10, $base)*$i;\r
- if ($label > $this->_getMaximum()) {\r
- return false;\r
- } else {\r
- return $label;\r
- }\r
- }\r
- }\r
- return pow(10, $base+1);\r
- }\r
-\r
- return max(1, $this->_minimum);\r
- }\r
-\r
- /**\r
- * Get the axis intersection pixel position\r
- *\r
- * This is only to be called prior to output! I.e. between the user\r
- * invokation of Image_Graph::done() and any actual output is performed.\r
- * This is because it can change the axis range.\r
- *\r
- * @param double $value the intersection value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _intersectPoint($value)\r
- { \r
- if (($value <= 0) && ($value !== 'max') && ($value !== 'min')) {\r
- $value = 1;\r
- }\r
- return parent::_intersectPoint($value);\r
- }\r
- \r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for axis handling.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Logarithmic.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Axis.php
+ */
+require_once 'Image/Graph/Axis.php';
+
+/**
+ * Diplays a logarithmic axis (either X- or Y-axis).
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis_Logarithmic extends Image_Graph_Axis
+{
+
+ /**
+ * Image_Graph_AxisLogarithmic [Constructor].
+ *
+ * Normally a manual creation should not be necessary, axis are
+ * created automatically by the {@link Image_Graph_Plotarea} constructor
+ * unless explicitly defined otherwise
+ *
+ * @param int $type The type (direction) of the Axis, use IMAGE_GRAPH_AXIS_X
+ * for an X-axis (default, may be omitted) and IMAGE_GRAPH_AXIS_Y for Y-
+ * axis)
+ */
+ function Image_Graph_Axis_Logarithmic($type = IMAGE_GRAPH_AXIS_X)
+ {
+ parent::__construct($type);
+ $this->showLabel(IMAGE_GRAPH_LABEL_MINIMUM + IMAGE_GRAPH_LABEL_MAXIMUM);
+ $this->_minimum = 1;
+ $this->_minimumSet = true;
+ }
+
+ /**
+ * Calculate the label interval
+ *
+ * If explicitly defined this will be calucated to an approximate best.
+ *
+ * @return double The label interval
+ * @access private
+ */
+ function _calcLabelInterval()
+ {
+ $result = parent::_calcLabelInterval();
+ $this->_axisValueSpan = $this->_value($this->_axisSpan);
+ return $result;
+ }
+
+ /**
+ * Preprocessor for values, ie for using logarithmic axis
+ *
+ * @param double $value The value to preprocess
+ *
+ * @return double The preprocessed value
+ * @access private
+ */
+ function _value($value)
+ {
+ return log10($value) - log10($this->_minimum);
+ }
+
+ /**
+ * Get next label point
+ *
+ * @param doubt $currentLabel The current label point. If omitted or false, the first is
+ * returned
+ * @param int $level Label level
+ *
+ * @return double The next label point
+ * @access private
+ */
+ function _getNextLabel($currentLabel = false, $level = 1)
+ {
+ if (is_array($this->_labelOptions[$level]['interval'])) {
+ return parent::_getNextLabel($currentLabel, $level);
+ }
+
+ if ($currentLabel !== false) {
+ $value = log10($currentLabel);
+ $base = floor($value);
+ $frac = $value - $base;
+ for ($i = 2; $i < 10; $i++) {
+ if ($frac <= (log10($i)-0.01)) {
+ $label = pow(10, $base)*$i;
+ if ($label > $this->_getMaximum()) {
+ return false;
+ } else {
+ return $label;
+ }
+ }
+ }
+ return pow(10, $base+1);
+ }
+
+ return max(1, $this->_minimum);
+ }
+
+ /**
+ * Get the axis intersection pixel position
+ *
+ * This is only to be called prior to output! I.e. between the user
+ * invokation of Image_Graph::done() and any actual output is performed.
+ * This is because it can change the axis range.
+ *
+ * @param double $value the intersection value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _intersectPoint($value)
+ {
+ if (($value <= 0) && ($value !== 'max') && ($value !== 'min')) {
+ $value = 1;
+ }
+ return parent::_intersectPoint($value);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class file containing a axis marker used for explicitly highlighting a area\r
- * on the graph, based on an interval specified on an axis.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Area.php,v 1.11 2005/08/24 20:36:04 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Grid.php\r
- */\r
-require_once 'Image/Graph/Grid.php';\r
-\r
-/**\r
- * Display a grid\r
- *\r
- * {@link Image_Graph_Grid}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Axis_Marker_Area extends Image_Graph_Grid\r
-{\r
-\r
- /**\r
- * The lower bound\r
- * @var double\r
- * @access private\r
- */\r
- var $_lower = false;\r
-\r
- /**\r
- * The upper bound\r
- * @var double\r
- * @access private\r
- */\r
- var $_upper = false;\r
-\r
- /**\r
- * [Constructor]\r
- */\r
- function Image_Graph_Axis_Marker_Area()\r
- {\r
- parent::Image_Graph_Grid();\r
- $this->_lineStyle = false;\r
- }\r
-\r
- /**\r
- * Sets the lower bound of the area (value on the axis)\r
- *\r
- * @param double $lower the lower bound\r
- */\r
- function setLowerBound($lower)\r
- {\r
- $this->_lower = $lower;\r
- }\r
-\r
- /**\r
- * Sets the upper bound of the area (value on the axis)\r
- *\r
- * @param double $upper the upper bound\r
- */\r
- function setUpperBound($upper)\r
- {\r
- $this->_upper = $upper;\r
- }\r
-\r
- /**\r
- * Output the grid\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!$this->_primaryAxis) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $i = 0;\r
-\r
- $this->_lower = max($this->_primaryAxis->_getMinimum(), $this->_lower);\r
- $this->_upper = min($this->_primaryAxis->_getMaximum(), $this->_upper);\r
-\r
- $secondaryPoints = $this->_getSecondaryAxisPoints();\r
-\r
- reset($secondaryPoints);\r
- list ($id, $previousSecondaryValue) = each($secondaryPoints);\r
- while (list ($id, $secondaryValue) = each($secondaryPoints)) {\r
- if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {\r
- $p1 = array ('Y' => $secondaryValue, 'X' => $this->_lower);\r
- $p2 = array ('Y' => $previousSecondaryValue, 'X' => $this->_lower);\r
- $p3 = array ('Y' => $previousSecondaryValue, 'X' => $this->_upper);\r
- $p4 = array ('Y' => $secondaryValue, 'X' => $this->_upper);\r
- } else {\r
- $p1 = array ('X' => $secondaryValue, 'Y' => $this->_lower);\r
- $p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_lower);\r
- $p3 = array ('X' => $previousSecondaryValue, 'Y' => $this->_upper);\r
- $p4 = array ('X' => $secondaryValue, 'Y' => $this->_upper);\r
- }\r
-\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p1), 'y' => $this->_pointY($p1)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p2), 'y' => $this->_pointY($p2)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p3), 'y' => $this->_pointY($p3)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p4), 'y' => $this->_pointY($p4)));\r
-\r
- $previousSecondaryValue = $secondaryValue;\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle();\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class file containing a axis marker used for explicitly highlighting a area
+ * on the graph, based on an interval specified on an axis.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Area.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Grid.php
+ */
+require_once 'Image/Graph/Grid.php';
+
+/**
+ * Display a grid
+ *
+ * {@link Image_Graph_Grid}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis_Marker_Area extends Image_Graph_Grid
+{
+
+ /**
+ * The lower bound
+ * @var double
+ * @access private
+ */
+ var $_lower = false;
+
+ /**
+ * The upper bound
+ * @var double
+ * @access private
+ */
+ var $_upper = false;
+
+ /**
+ * [Constructor]
+ */
+ function Image_Graph_Axis_Marker_Area()
+ {
+ parent::Image_Graph_Grid();
+ $this->_lineStyle = false;
+ }
+
+ /**
+ * Sets the lower bound of the area (value on the axis)
+ *
+ * @param double $lower the lower bound
+ *
+ * @return void
+ */
+ function setLowerBound($lower)
+ {
+ $this->_lower = $lower;
+ }
+
+ /**
+ * Sets the upper bound of the area (value on the axis)
+ *
+ * @param double $upper the upper bound
+ *
+ * @return void
+ */
+ function setUpperBound($upper)
+ {
+ $this->_upper = $upper;
+ }
+
+ /**
+ * Output the grid
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!$this->_primaryAxis) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $i = 0;
+
+ $this->_lower = max($this->_primaryAxis->_getMinimum(), $this->_lower);
+ $this->_upper = min($this->_primaryAxis->_getMaximum(), $this->_upper);
+
+ $secondaryPoints = $this->_getSecondaryAxisPoints();
+
+ reset($secondaryPoints);
+ list ($id, $previousSecondaryValue) = each($secondaryPoints);
+ while (list ($id, $secondaryValue) = each($secondaryPoints)) {
+ if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {
+ $p1 = array ('Y' => $secondaryValue, 'X' => $this->_lower);
+ $p2 = array ('Y' => $previousSecondaryValue, 'X' => $this->_lower);
+ $p3 = array ('Y' => $previousSecondaryValue, 'X' => $this->_upper);
+ $p4 = array ('Y' => $secondaryValue, 'X' => $this->_upper);
+ } else {
+ $p1 = array ('X' => $secondaryValue, 'Y' => $this->_lower);
+ $p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_lower);
+ $p3 = array ('X' => $previousSecondaryValue, 'Y' => $this->_upper);
+ $p4 = array ('X' => $secondaryValue, 'Y' => $this->_upper);
+ }
+
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p1), 'y' => $this->_pointY($p1)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p2), 'y' => $this->_pointY($p2)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p3), 'y' => $this->_pointY($p3)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p4), 'y' => $this->_pointY($p4)));
+
+ $previousSecondaryValue = $secondaryValue;
+
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class file containing a axis marker used for explicitly highlighting a point\r
- * (line) on the graph, based on an value specified on an axis.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Line.php,v 1.11 2005/08/03 21:21:58 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Grid.php\r
- */\r
-require_once 'Image/Graph/Grid.php';\r
-\r
-/**\r
- * Display a grid\r
- *\r
- * {@link Image_Graph_Grid}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Axis_Marker_Line extends Image_Graph_Grid\r
-{\r
-\r
- /**\r
- * The value\r
- * @var double\r
- * @access private\r
- */\r
- var $_value = false;\r
-\r
- /**\r
- * Sets the value of the line marker (value on the axis)\r
- *\r
- * @param double $value the value\r
- */\r
- function setValue($value)\r
- {\r
- $this->_value = $value;\r
- }\r
-\r
- /**\r
- * Output the grid\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!$this->_primaryAxis) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this));\r
-\r
- $i = 0;\r
-\r
- $this->_value = min($this->_primaryAxis->_getMaximum(), max($this->_primaryAxis->_getMinimum(), $this->_value));\r
-\r
- $secondaryPoints = $this->_getSecondaryAxisPoints();\r
-\r
- reset($secondaryPoints);\r
- list ($id, $previousSecondaryValue) = each($secondaryPoints);\r
- while (list ($id, $secondaryValue) = each($secondaryPoints)) {\r
- if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {\r
- $p1 = array ('X' => $this->_value, 'Y' => $secondaryValue);\r
- $p2 = array ('X' => $this->_value, 'Y' => $previousSecondaryValue);\r
- } else {\r
- $p1 = array ('X' => $secondaryValue, 'Y' => $this->_value);\r
- $p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_value);\r
- }\r
-\r
- $x1 = $this->_pointX($p1);\r
- $y1 = $this->_pointY($p1);\r
- $x2 = $this->_pointX($p2);\r
- $y2 = $this->_pointY($p2);\r
-\r
- $previousSecondaryValue = $secondaryValue;\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x1, 'y0' => $y1, 'x1' => $x2, 'y1' => $y2));\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class file containing a axis marker used for explicitly highlighting a point
+ * (line) on the graph, based on an value specified on an axis.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Line.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Grid.php
+ */
+require_once 'Image/Graph/Grid.php';
+
+/**
+ * Display a grid
+ *
+ * {@link Image_Graph_Grid}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis_Marker_Line extends Image_Graph_Grid
+{
+
+ /**
+ * The value
+ * @var double
+ * @access private
+ */
+ var $_value = false;
+
+ /**
+ * Sets the value of the line marker (value on the axis)
+ *
+ * @param double $value the value
+ *
+ * @return void
+ */
+ function setValue($value)
+ {
+ $this->_value = $value;
+ }
+
+ /**
+ * Output the grid
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!$this->_primaryAxis) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $i = 0;
+
+ $this->_value = min($this->_primaryAxis->_getMaximum(), max($this->_primaryAxis->_getMinimum(), $this->_value));
+
+ $secondaryPoints = $this->_getSecondaryAxisPoints();
+
+ reset($secondaryPoints);
+ list ($id, $previousSecondaryValue) = each($secondaryPoints);
+ while (list ($id, $secondaryValue) = each($secondaryPoints)) {
+ if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {
+ $p1 = array ('X' => $this->_value, 'Y' => $secondaryValue);
+ $p2 = array ('X' => $this->_value, 'Y' => $previousSecondaryValue);
+ } else {
+ $p1 = array ('X' => $secondaryValue, 'Y' => $this->_value);
+ $p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_value);
+ }
+
+ $x1 = $this->_pointX($p1);
+ $y1 = $this->_pointY($p1);
+ $x2 = $this->_pointX($p2);
+ $y2 = $this->_pointY($p2);
+
+ $previousSecondaryValue = $secondaryValue;
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x1, 'y0' => $y1, 'x1' => $x2, 'y1' => $y2));
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Class for axis handling.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Radar.php,v 1.6 2005/08/03 21:22:11 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Axis/Category.php\r
- */\r
-require_once 'Image/Graph/Axis/Category.php';\r
-\r
-/**\r
- * Displays an 'X'-axis in a radar plot chart.\r
- *\r
- * This axis maps the number of elements in the dataset to a angle (from 0-\r
- * 360 degrees). Displaying the axis consist of drawing a number of lines from\r
- * center to the edge of the 'circle' than encloses the radar plot. The labels\r
- * are drawn on the 'ends' of these radial lines.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Axis\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Axis_Radar extends Image_Graph_Axis_Category\r
-{\r
-\r
- /**\r
- * Specifies the number of pixels, the labels is offsetted from the end of\r
- * the axis\r
- *\r
- * @var int\r
- * @access private\r
- */\r
- var $_distanceFromEnd = 5;\r
-\r
- /**\r
- * Gets the minimum value the axis will show.\r
- *\r
- * This is always 0\r
- *\r
- * @return double The minumum value\r
- * @access private\r
- */\r
- function _getMinimum()\r
- {\r
- return 0;\r
- }\r
-\r
- /**\r
- * Gets the maximum value the axis will show.\r
- *\r
- * This is always the number of labels passed to the constructor.\r
- *\r
- * @return double The maximum value\r
- * @access private\r
- */\r
- function _getMaximum()\r
- {\r
- return count($this->_labels);\r
- }\r
-\r
- /**\r
- * Calculate the delta value (the number of pixels representing one unit\r
- * on the axis)\r
- *\r
- * @return double The label interval\r
- * @access private\r
- */\r
- function _calcDelta()\r
- {\r
- if (abs($this->_getMaximum() - $this->_getMinimum()) == 0) {\r
- $this->_delta = false;\r
- } else {\r
- $this->_delta = 360 / ($this->_getMaximum() - $this->_getMinimum());\r
- } \r
- } \r
-\r
- /**\r
- * Get the pixel position represented by a value on the canvas\r
- *\r
- * @param double $value the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _point($value)\r
- {\r
- return (90 + (int) ($this->_value($value) * $this->_delta)) % 360;\r
- }\r
-\r
- /**\r
- * Get the size in pixels of the axis.\r
- *\r
- * For a radar plot this is always 0\r
- *\r
- * @return int The size of the axis\r
- * @access private\r
- */\r
- function _size()\r
- {\r
- return 0;\r
- }\r
-\r
- /**\r
- * Sets the distance from the end of the category lines to the label.\r
- *\r
- * @param int $distance The distance in pixels\r
- */\r
- function setDistanceFromEnd($distance = 5)\r
- {\r
- $this->_distanceFromEnd = $distance;\r
- }\r
-\r
- /**\r
- * Draws axis lines.\r
- *\r
- * @access private\r
- */\r
- function _drawAxisLines()\r
- {\r
- }\r
-\r
- /**\r
- * Output an axis tick mark.\r
- *\r
- * @param int $value The value to output\r
- * @access private\r
- */\r
- function _drawTick($value, $level = 1)\r
- {\r
- $centerX = (int) (($this->_left + $this->_right) / 2);\r
- $centerY = (int) (($this->_top + $this->_bottom) / 2);\r
-\r
- $radius = min($this->height(), $this->width()) / 2;\r
-\r
- $endPoint = array ('X' => $value, 'Y' => '#max#');\r
- $dX = $this->_pointX($endPoint);\r
- $dY = $this->_pointY($endPoint);\r
-\r
- $offX = ($dX - $centerX);\r
- $offY = ($dY - $centerY);\r
-\r
- $hyp = sqrt($offX*$offX + $offY*$offY);\r
- if ($hyp != 0) {\r
- $scale = $this->_distanceFromEnd / $hyp;\r
- } else {\r
- $scale = 1;\r
- }\r
-\r
- $adX = $dX + $offX * $scale;\r
- $adY = $dY + $offY * $scale;\r
-\r
- if (is_object($this->_dataPreProcessor)) {\r
- $labelText = $this->_dataPreProcessor->_process($value);\r
- } else {\r
- $labelText = $value;\r
- }\r
-\r
- if ((abs($dX - $centerX) < 1.5) && ($dY < $centerY)) {\r
- $align = IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_CENTER_X;\r
- } elseif ((abs($dX - $centerX) < 1.5) && ($dY > $centerY)) {\r
- $align = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_CENTER_X;\r
- } elseif ($dX < $centerX) {\r
- $align = IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y;\r
- } else {\r
- $align = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y;\r
- }\r
- $this->write($adX, $adY, $labelText, $align);\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $centerX, 'y0' => $centerY, 'x1' => $dX, 'y1' => $dY));\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Class for axis handling.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Radar.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Axis/Category.php
+ */
+require_once 'Image/Graph/Axis/Category.php';
+
+/**
+ * Displays an 'X'-axis in a radar plot chart.
+ *
+ * This axis maps the number of elements in the dataset to a angle (from 0-
+ * 360 degrees). Displaying the axis consist of drawing a number of lines from
+ * center to the edge of the 'circle' than encloses the radar plot. The labels
+ * are drawn on the 'ends' of these radial lines.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Axis
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Axis_Radar extends Image_Graph_Axis_Category
+{
+
+ /**
+ * Specifies the number of pixels, the labels is offsetted from the end of
+ * the axis
+ *
+ * @var int
+ * @access private
+ */
+ var $_distanceFromEnd = 5;
+
+ /**
+ * Gets the minimum value the axis will show.
+ *
+ * This is always 0
+ *
+ * @return double The minumum value
+ * @access private
+ */
+ function _getMinimum()
+ {
+ return 0;
+ }
+
+ /**
+ * Gets the maximum value the axis will show.
+ *
+ * This is always the number of labels passed to the constructor.
+ *
+ * @return double The maximum value
+ * @access private
+ */
+ function _getMaximum()
+ {
+ return count($this->_labels);
+ }
+
+ /**
+ * Calculate the delta value (the number of pixels representing one unit
+ * on the axis)
+ *
+ * @return double The label interval
+ * @access private
+ */
+ function _calcDelta()
+ {
+ if (abs($this->_getMaximum() - $this->_getMinimum()) == 0) {
+ $this->_delta = false;
+ } else {
+ $this->_delta = 360 / ($this->_getMaximum() - $this->_getMinimum());
+ }
+ }
+
+ /**
+ * Get the pixel position represented by a value on the canvas
+ *
+ * @param double $value the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _point($value)
+ {
+ return (90 + (int) ($this->_value($value) * $this->_delta)) % 360;
+ }
+
+ /**
+ * Get the size in pixels of the axis.
+ *
+ * For a radar plot this is always 0
+ *
+ * @return int The size of the axis
+ * @access private
+ */
+ function _size()
+ {
+ return 0;
+ }
+
+ /**
+ * Sets the distance from the end of the category lines to the label.
+ *
+ * @param int $distance The distance in pixels
+ *
+ * @return void
+ */
+ function setDistanceFromEnd($distance = 5)
+ {
+ $this->_distanceFromEnd = $distance;
+ }
+
+ /**
+ * Draws axis lines.
+ *
+ * @return void
+ * @access private
+ */
+ function _drawAxisLines()
+ {
+ }
+
+ /**
+ * Output an axis tick mark.
+ *
+ * @param int $value The value to output
+ * @param int $level Tick mark level
+ *
+ * @return void
+ * @access private
+ */
+ function _drawTick($value, $level = 1)
+ {
+ $centerX = (int) (($this->_left + $this->_right) / 2);
+ $centerY = (int) (($this->_top + $this->_bottom) / 2);
+
+ $radius = min($this->height(), $this->width()) / 2;
+
+ $endPoint = array ('X' => $value, 'Y' => '#max#');
+ $dX = $this->_pointX($endPoint);
+ $dY = $this->_pointY($endPoint);
+
+ $offX = ($dX - $centerX);
+ $offY = ($dY - $centerY);
+
+ $hyp = sqrt($offX*$offX + $offY*$offY);
+ if ($hyp != 0) {
+ $scale = $this->_distanceFromEnd / $hyp;
+ } else {
+ $scale = 1;
+ }
+
+ $adX = $dX + $offX * $scale;
+ $adY = $dY + $offY * $scale;
+
+ if (is_object($this->_dataPreProcessor)) {
+ $labelText = $this->_dataPreProcessor->_process($value);
+ } else {
+ $labelText = $value;
+ }
+
+ if ((abs($dX - $centerX) < 1.5) && ($dY < $centerY)) {
+ $align = IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_CENTER_X;
+ } elseif ((abs($dX - $centerX) < 1.5) && ($dY > $centerY)) {
+ $align = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_CENTER_X;
+ } elseif ($dX < $centerX) {
+ $align = IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y;
+ } else {
+ $align = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y;
+ }
+ $this->write($adX, $adY, $labelText, $align);
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $centerX, 'y0' => $centerY, 'x1' => $dX, 'y1' => $dY));
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Common.php,v 1.16 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-if (!function_exists('is_a')) {\r
-\r
- /**\r
- * Check if an object is of a given class, this function is available as of PHP 4.2.0, so if it exist it will not be declared\r
- *\r
- * @link http://www.php.net/manual/en/function.is-a.php PHP.net Online Manual for function is_a()\r
- * @param object $object The object to check class for\r
- * @param string $class_name The name of the class to check the object for\r
- * @return bool Returns TRUE if the object is of this class or has this class as one of its parents\r
- */\r
- function is_a($object, $class_name)\r
- {\r
- if (empty ($object)) {\r
- return false;\r
- }\r
- $object = is_object($object) ? get_class($object) : $object;\r
- if (strtolower($object) == strtolower($class_name)) {\r
- return true;\r
- }\r
- return is_a(get_parent_class($object), $class_name);\r
- }\r
-}\r
-\r
-/**\r
- * Include file Image/Canvas.php\r
- */\r
-require_once 'Image/Canvas.php';\r
-\r
-/**\r
- * The ultimate ancestor of all Image_Graph classes.\r
- *\r
- * This class contains common functionality needed by all Image_Graph classes.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Common\r
-{\r
-\r
- /**\r
- * The parent container of the current Image_Graph object\r
- *\r
- * @var Image_Graph_Common\r
- * @access private\r
- */\r
- var $_parent = null;\r
-\r
- /**\r
- * The sub-elements of the current Image_Graph container object\r
- *\r
- * @var array\r
- * @access private\r
- */\r
- var $_elements;\r
-\r
- /**\r
- * The canvas for output.\r
- *\r
- * Enables support for multiple output formats.\r
- *\r
- * @var Image_Canvas\r
- * @access private\r
- */\r
- var $_canvas = null;\r
- \r
- /**\r
- * Is the object visible?\r
- * \r
- * @var bool\r
- * @access private\r
- */\r
- var $_visible = true;\r
-\r
- /**\r
- * Constructor [Image_Graph_Common]\r
- */\r
- function Image_Graph_Common()\r
- {\r
- }\r
-\r
- /**\r
- * Resets the elements\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- if (is_object($this->_elements[$key])) {\r
- $this->_elements[$key]->_setParent($this);\r
- $result =& $this->_elements[$key]->_reset();\r
- if (PEAR::isError($result)) {\r
- return $result;\r
- }\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Sets the parent. The parent chain should ultimately be a GraPHP object\r
- *\r
- * @see Image_Graph_Common\r
- * @param Image_Graph_Common $parent The parent\r
- * @access private\r
- */\r
- function _setParent(& $parent)\r
- {\r
- $this->_parent =& $parent;\r
- $this->_canvas =& $this->_parent->_getCanvas();\r
-\r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- if (is_object($this->_elements[$key])) {\r
- $this->_elements[$key]->_setParent($this);\r
- }\r
- }\r
- unset($keys);\r
- }\r
- }\r
-\r
- /**\r
- * Hide the element\r
- */\r
- function hide()\r
- {\r
- $this->_visible = false;\r
- } \r
-\r
- /**\r
- * Get the canvas\r
- *\r
- * @return Image_Canvas The canvas\r
- * @access private\r
- */\r
- function &_getCanvas()\r
- { \r
- if (($this->_canvas !== null) || ($this->_canvas !== false)) {\r
- return $this->_canvas;\r
- } elseif (is_a($this->_parent, 'Image_Graph_Common')) {\r
- $this->_canvas =& $this->_parent->_getCanvas();\r
- return $this->_canvas;\r
- } else {\r
- $this->_error('Invalid canvas');\r
- $result = null;\r
- return $result;\r
- }\r
- }\r
-\r
- /**\r
- * Adds an element to the objects element list.\r
- *\r
- * The new Image_Graph_elements parent is automatically set.\r
- *\r
- * @param Image_Graph_Common $element The new Image_Graph_element\r
- * @return Image_Graph_Common The new Image_Graph_element\r
- */\r
- function &add(& $element)\r
- {\r
- if (!is_a($element, 'Image_Graph_Font')) {\r
- $this->_elements[] = &$element;\r
- }\r
- $element->_setParent($this);\r
- return $element;\r
- }\r
-\r
- /**\r
- * Creates an object from the class and adds it to the objects element list.\r
- *\r
- * Creates an object from the class specified and adds it to the objects\r
- * element list. If only one parameter is required for the constructor of\r
- * the class simply pass this parameter as the $params parameter, unless the\r
- * parameter is an array or a reference to a value, in that case you must\r
- * 'enclose' the parameter in an array. Similar if the constructor takes\r
- * more than one parameter specify the parameters in an array.\r
- *\r
- * @see Image_Graph::factory()\r
- * @param string $class The class for the object\r
- * @param mixed $params The paramaters to pass to the constructor\r
- * @return Image_Graph_Common The new Image_Graph_element\r
- */\r
- function &addNew($class, $params = null, $additional = false)\r
- {\r
- include_once 'Image/Graph.php';\r
- $element =& Image_Graph::factory($class, $params);\r
- if ($additional === false) {\r
- $obj =& $this->add($element);\r
- } else {\r
- $obj =& $this->add($element, $additional);\r
- }\r
- return $obj;\r
- }\r
-\r
- /**\r
- * Shows an error message box on the canvas\r
- *\r
- * @param string $text The error text\r
- * @param array $params An array containing error specific details\r
- * @param int $error_code Error code\r
- * @access private\r
- */\r
- function _error($text, $params = false, $error_code = IMAGE_GRAPH_ERROR_GENERIC)\r
- { \r
- if ((is_array($params)) && (count($params) > 0)) {\r
- foreach ($params as $name => $key) {\r
- if (isset($parameters)) {\r
- $parameters .= ' ';\r
- } \r
- else {\r
- $parameters = '';\r
- }\r
- $parameters .= $name . '=' . $key;\r
- }\r
- } \r
- $error =& PEAR::raiseError(\r
- $text .\r
- ($error_code != IMAGE_GRAPH_ERROR_GENERIC ? ' error:' . IMAGE_GRAPH_ERROR_GENERIC : '') .\r
- (isset($parameters) ? ' parameters:[' . $parameters . ']' : '') \r
- ); \r
- }\r
-\r
- /**\r
- * Causes the object to update all sub elements coordinates\r
- *\r
- * (Image_Graph_Common, does not itself have coordinates, this is basically\r
- * an abstract method)\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- if (is_object($this->_elements[$key])) {\r
- $this->_elements[$key]->_updateCoords();\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Causes output to canvas\r
- *\r
- * The last method to call. Calling Done causes output to the canvas. All\r
- * sub elements done() method will be invoked\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (($this->_canvas == null) || (!is_a($this->_canvas, 'Image_Canvas'))) {\r
- return false;\r
- }\r
-\r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- if (($this->_elements[$key]->_visible) && ($this->_elements[$key]->_done() === false)) {\r
- return false;\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Common.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Canvas.php
+ */
+require_once 'Image/Canvas.php';
+
+/**
+ * The ultimate ancestor of all Image_Graph classes.
+ *
+ * This class contains common functionality needed by all Image_Graph classes.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Common
+{
+
+ /**
+ * The parent container of the current Image_Graph object
+ *
+ * @var Image_Graph_Common
+ * @access private
+ */
+ var $_parent = null;
+
+ /**
+ * The sub-elements of the current Image_Graph container object
+ *
+ * @var array
+ * @access private
+ */
+ var $_elements;
+
+ /**
+ * The canvas for output.
+ *
+ * Enables support for multiple output formats.
+ *
+ * @var Image_Canvas
+ * @access private
+ */
+ var $_canvas = null;
+
+ /**
+ * Is the object visible?
+ *
+ * @var bool
+ * @access private
+ */
+ var $_visible = true;
+
+ /**
+ * Constructor [Image_Graph_Common]
+ */
+ function Image_Graph_Common()
+ {
+ }
+
+ /**
+ * Resets the elements
+ *
+ * @return bool
+ * @access private
+ */
+ function _reset()
+ {
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ if (is_object($this->_elements[$key])) {
+ $this_ =& $this;
+ $this->_elements[$key]->_setParent($this_);
+ $result =& $this->_elements[$key]->_reset();
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+ }
+ }
+ unset($keys);
+ }
+ return true;
+ }
+
+ /**
+ * Sets the parent. The parent chain should ultimately be a GraPHP object
+ *
+ * @param Image_Graph_Common &$parent The parent
+ *
+ * @return void
+ * @see Image_Graph_Common
+ * @access private
+ */
+ function _setParent(& $parent)
+ {
+ $this->_parent =& $parent;
+ $this->_canvas =& $this->_parent->_getCanvas();
+
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ if (is_object($this->_elements[$key])) {
+ $this->_elements[$key]->_setParent($this);
+ }
+ }
+ unset($keys);
+ }
+ }
+
+ /**
+ * Hide the element
+ *
+ * @return void
+ */
+ function hide()
+ {
+ $this->_visible = false;
+ }
+
+ /**
+ * Get the canvas
+ *
+ * @return Image_Canvas The canvas
+ * @access private
+ */
+ function &_getCanvas()
+ {
+ if (($this->_canvas !== null) || ($this->_canvas !== false)) {
+ return $this->_canvas;
+ } elseif (is_a($this->_parent, 'Image_Graph_Common')) {
+ $this->_canvas =& $this->_parent->_getCanvas();
+ return $this->_canvas;
+ } else {
+ $this->_error('Invalid canvas');
+ $result = null;
+ return $result;
+ }
+ }
+
+ /**
+ * Adds an element to the objects element list.
+ *
+ * The new Image_Graph_elements parent is automatically set.
+ *
+ * @param Image_Graph_Common &$element The new Image_Graph_element
+ *
+ * @return Image_Graph_Common The new Image_Graph_element
+ */
+ function &add(&$element)
+ {
+ if (!is_a($element, 'Image_Graph_Font')) {
+ $this->_elements[] = &$element;
+ }
+ $element->_setParent($this);
+ return $element;
+ }
+
+ /**
+ * Creates an object from the class and adds it to the objects element list.
+ *
+ * Creates an object from the class specified and adds it to the objects
+ * element list. If only one parameter is required for the constructor of
+ * the class simply pass this parameter as the $params parameter, unless the
+ * parameter is an array or a reference to a value, in that case you must
+ * 'enclose' the parameter in an array. Similar if the constructor takes
+ * more than one parameter specify the parameters in an array.
+ *
+ * @param string $class The class for the object
+ * @param mixed $params The paramaters to pass to the constructor
+ * @param mixed $additional Additional parameter to be pass (optional)
+ *
+ * @return Image_Graph_Common The new Image_Graph_element
+ * @see Image_Graph::factory()
+ */
+ function &addNew($class, $params = null, $additional = false)
+ {
+ include_once 'Image/Graph.php';
+ $element =& Image_Graph::factory($class, $params);
+ if ($additional === false) {
+ $obj =& $this->add($element);
+ } else {
+ $obj =& $this->add($element, $additional);
+ }
+ return $obj;
+ }
+
+ /**
+ * Shows an error message box on the canvas
+ *
+ * @param string $text The error text
+ * @param array $params An array containing error specific details
+ * @param int $error_code Error code
+ *
+ * @return void
+ * @access private
+ */
+ function _error($text, $params = false, $error_code = IMAGE_GRAPH_ERROR_GENERIC)
+ {
+ if ((is_array($params)) && (count($params) > 0)) {
+ foreach ($params as $name => $key) {
+ if (isset($parameters)) {
+ $parameters .= ' ';
+ } else {
+ $parameters = '';
+ }
+ $parameters .= $name . '=' . $key;
+ }
+ }
+ $error =& PEAR::raiseError(
+ $text .
+ ($error_code != IMAGE_GRAPH_ERROR_GENERIC ? ' error:' . IMAGE_GRAPH_ERROR_GENERIC : '') .
+ (isset($parameters) ? ' parameters:[' . $parameters . ']' : '')
+ );
+ }
+
+ /**
+ * Causes the object to update all sub elements coordinates
+ *
+ * (Image_Graph_Common, does not itself have coordinates, this is basically
+ * an abstract method)
+ *
+ * @return bool
+ * @access private
+ */
+ function _updateCoords()
+ {
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ if (is_object($this->_elements[$key])) {
+ $this->_elements[$key]->_updateCoords();
+ }
+ }
+ unset($keys);
+ }
+ return true;
+ }
+
+ /**
+ * Causes output to canvas
+ *
+ * The last method to call. Calling Done causes output to the canvas. All
+ * sub elements done() method will be invoked
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (($this->_canvas == null) || (!is_a($this->_canvas, 'Image_Canvas'))) {
+ return false;
+ }
+
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ if (($this->_elements[$key]->_visible) && ($this->_elements[$key]->_done() === false)) {
+ return false;
+ }
+ }
+ unset($keys);
+ }
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Config.php,v 1.7 2005/08/03 21:21:52 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Config.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Constants.php,v 1.7 2005/08/03 21:21:52 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Font.php\r
- */\r
-require_once 'Image/Graph/Font.php';\r
-\r
-// Constant declarations\r
-\r
-/**\r
- * Defines an X (horizontal) axis\r
- */\r
-define('IMAGE_GRAPH_AXIS_X', 1);\r
-\r
-/**\r
- * Defines an Y (vertical) axis\r
- */\r
-define('IMAGE_GRAPH_AXIS_Y', 2);\r
-\r
-/**\r
- * Defines an Y (vertical) axis\r
- */\r
-define('IMAGE_GRAPH_AXIS_Y_SECONDARY', 3);\r
-\r
-/**\r
- * Defines an horizontal (X) axis\r
- */\r
-define('IMAGE_GRAPH_AXIS_HORIZONTAL', 1);\r
-\r
-/**\r
- * Defines an vertical (Y) axis\r
- */\r
-define('IMAGE_GRAPH_AXIS_VERTICAL', 2);\r
-\r
-/**\r
- * Define if label should be shown for axis minimum value\r
- */\r
-define('IMAGE_GRAPH_LABEL_MINIMUM', 1);\r
-\r
-/**\r
- * Define if label should be shown for axis 0 (zero) value\r
- */\r
-define('IMAGE_GRAPH_LABEL_ZERO', 2);\r
-\r
-/**\r
- * Define if label should be shown for axis maximum value\r
- */\r
-define('IMAGE_GRAPH_LABEL_MAXIMUM', 4);\r
-\r
-/**\r
- * Defines a horizontal gradient fill\r
- */\r
-define('IMAGE_GRAPH_GRAD_HORIZONTAL', 1);\r
-\r
-/**\r
- * Defines a vertical gradient fill\r
- */\r
-define('IMAGE_GRAPH_GRAD_VERTICAL', 2);\r
-\r
-/**\r
- * Defines a horizontally mirrored gradient fill\r
- */\r
-define('IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED', 3);\r
-\r
-/**\r
- * Defines a vertically mirrored gradient fill\r
- */\r
-define('IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED', 4);\r
-\r
-/**\r
- * Defines a diagonal gradient fill from top-left to bottom-right\r
- */\r
-define('IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR', 5);\r
-\r
-/**\r
- * Defines a diagonal gradient fill from bottom-left to top-right\r
- */\r
-define('IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR', 6);\r
-\r
-/**\r
- * Defines a radial gradient fill\r
- */\r
-define('IMAGE_GRAPH_GRAD_RADIAL', 7);\r
-\r
-/**\r
- * Defines the default builtin font\r
- */\r
-define('IMAGE_GRAPH_FONT', 1);\r
-\r
-/**\r
- * Defines a X value should be used\r
- */\r
-define('IMAGE_GRAPH_VALUE_X', 0);\r
-\r
-/**\r
- * Defines a Y value should be used\r
- */\r
-define('IMAGE_GRAPH_VALUE_Y', 1);\r
-\r
-/**\r
- * Defines a min X% value should be used\r
- */\r
-define('IMAGE_GRAPH_PCT_X_MIN', 2);\r
-\r
-/**\r
- * Defines a max X% value should be used\r
- */\r
-define('IMAGE_GRAPH_PCT_X_MAX', 3);\r
-\r
-/**\r
- * Defines a min Y% value should be used\r
- */\r
-define('IMAGE_GRAPH_PCT_Y_MIN', 4);\r
-\r
-/**\r
- * Defines a max Y% value should be used\r
- */\r
-define('IMAGE_GRAPH_PCT_Y_MAX', 5);\r
-\r
-/**\r
- * Defines a total Y% value should be used\r
- */\r
-define('IMAGE_GRAPH_PCT_Y_TOTAL', 6);\r
-\r
-/**\r
- * Defines a ID value should be used\r
- */\r
-define('IMAGE_GRAPH_POINT_ID', 7);\r
-\r
-/**\r
- * Align text left\r
- */\r
-define('IMAGE_GRAPH_ALIGN_LEFT', 0x1);\r
-\r
-/**\r
- * Align text right\r
- */\r
-define('IMAGE_GRAPH_ALIGN_RIGHT', 0x2);\r
-\r
-/**\r
- * Align text center x (horizontal)\r
- */\r
-define('IMAGE_GRAPH_ALIGN_CENTER_X', 0x4);\r
-\r
-/**\r
- * Align text top\r
- */\r
-define('IMAGE_GRAPH_ALIGN_TOP', 0x8);\r
-\r
-/**\r
- * Align text bottom\r
- */\r
-define('IMAGE_GRAPH_ALIGN_BOTTOM', 0x10);\r
-\r
-/**\r
- * Align text center y (vertical)\r
- */\r
-define('IMAGE_GRAPH_ALIGN_CENTER_Y', 0x20);\r
-\r
-/**\r
- * Align text center (both x and y)\r
- */\r
-define('IMAGE_GRAPH_ALIGN_CENTER', IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_CENTER_Y);\r
-\r
-/**\r
- * Align text top left\r
- */\r
-define('IMAGE_GRAPH_ALIGN_TOP_LEFT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_LEFT);\r
-\r
-/**\r
- * Align text top right\r
- */\r
-define('IMAGE_GRAPH_ALIGN_TOP_RIGHT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_RIGHT);\r
-\r
-/**\r
- * Align text bottom left\r
- */\r
-define('IMAGE_GRAPH_ALIGN_BOTTOM_LEFT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_LEFT);\r
-\r
-/**\r
- * Align text bottom right\r
- */\r
-define('IMAGE_GRAPH_ALIGN_BOTTOM_RIGHT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_RIGHT);\r
-\r
-/**\r
- * Align vertical\r
- */\r
-define('IMAGE_GRAPH_ALIGN_VERTICAL', IMAGE_GRAPH_ALIGN_TOP);\r
-\r
-/**\r
- * Align horizontal\r
- */\r
-define('IMAGE_GRAPH_ALIGN_HORIZONTAL', IMAGE_GRAPH_ALIGN_LEFT);\r
-\r
-// Error codes\r
-define('IMAGE_GRAPH_ERROR_GENERIC', 0);\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Constants.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Font.php
+ */
+require_once 'Image/Graph/Font.php';
+
+// Constant declarations
+
+/**
+ * Defines an X (horizontal) axis
+ */
+define('IMAGE_GRAPH_AXIS_X', 1);
+
+/**
+ * Defines an Y (vertical) axis
+ */
+define('IMAGE_GRAPH_AXIS_Y', 2);
+
+/**
+ * Defines an Y (vertical) axis
+ */
+define('IMAGE_GRAPH_AXIS_Y_SECONDARY', 3);
+
+/**
+ * Defines an horizontal (X) axis
+ */
+define('IMAGE_GRAPH_AXIS_HORIZONTAL', 1);
+
+/**
+ * Defines an vertical (Y) axis
+ */
+define('IMAGE_GRAPH_AXIS_VERTICAL', 2);
+
+/**
+ * Define if label should be shown for axis minimum value
+ */
+define('IMAGE_GRAPH_LABEL_MINIMUM', 1);
+
+/**
+ * Define if label should be shown for axis 0 (zero) value
+ */
+define('IMAGE_GRAPH_LABEL_ZERO', 2);
+
+/**
+ * Define if label should be shown for axis maximum value
+ */
+define('IMAGE_GRAPH_LABEL_MAXIMUM', 4);
+
+/**
+ * Defines a horizontal gradient fill
+ */
+define('IMAGE_GRAPH_GRAD_HORIZONTAL', 1);
+
+/**
+ * Defines a vertical gradient fill
+ */
+define('IMAGE_GRAPH_GRAD_VERTICAL', 2);
+
+/**
+ * Defines a horizontally mirrored gradient fill
+ */
+define('IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED', 3);
+
+/**
+ * Defines a vertically mirrored gradient fill
+ */
+define('IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED', 4);
+
+/**
+ * Defines a diagonal gradient fill from top-left to bottom-right
+ */
+define('IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR', 5);
+
+/**
+ * Defines a diagonal gradient fill from bottom-left to top-right
+ */
+define('IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR', 6);
+
+/**
+ * Defines a radial gradient fill
+ */
+define('IMAGE_GRAPH_GRAD_RADIAL', 7);
+
+/**
+ * Defines the default builtin font
+ */
+define('IMAGE_GRAPH_FONT', 1);
+
+/**
+ * Defines a X value should be used
+ */
+define('IMAGE_GRAPH_VALUE_X', 0);
+
+/**
+ * Defines a Y value should be used
+ */
+define('IMAGE_GRAPH_VALUE_Y', 1);
+
+/**
+ * Defines a min X% value should be used
+ */
+define('IMAGE_GRAPH_PCT_X_MIN', 2);
+
+/**
+ * Defines a max X% value should be used
+ */
+define('IMAGE_GRAPH_PCT_X_MAX', 3);
+
+/**
+ * Defines a min Y% value should be used
+ */
+define('IMAGE_GRAPH_PCT_Y_MIN', 4);
+
+/**
+ * Defines a max Y% value should be used
+ */
+define('IMAGE_GRAPH_PCT_Y_MAX', 5);
+
+/**
+ * Defines a total Y% value should be used
+ */
+define('IMAGE_GRAPH_PCT_Y_TOTAL', 6);
+
+/**
+ * Defines a ID value should be used
+ */
+define('IMAGE_GRAPH_POINT_ID', 7);
+
+/**
+ * Align text left
+ */
+define('IMAGE_GRAPH_ALIGN_LEFT', 0x1);
+
+/**
+ * Align text right
+ */
+define('IMAGE_GRAPH_ALIGN_RIGHT', 0x2);
+
+/**
+ * Align text center x (horizontal)
+ */
+define('IMAGE_GRAPH_ALIGN_CENTER_X', 0x4);
+
+/**
+ * Align text top
+ */
+define('IMAGE_GRAPH_ALIGN_TOP', 0x8);
+
+/**
+ * Align text bottom
+ */
+define('IMAGE_GRAPH_ALIGN_BOTTOM', 0x10);
+
+/**
+ * Align text center y (vertical)
+ */
+define('IMAGE_GRAPH_ALIGN_CENTER_Y', 0x20);
+
+/**
+ * Align text center (both x and y)
+ */
+define('IMAGE_GRAPH_ALIGN_CENTER', IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_CENTER_Y);
+
+/**
+ * Align text top left
+ */
+define('IMAGE_GRAPH_ALIGN_TOP_LEFT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_LEFT);
+
+/**
+ * Align text top right
+ */
+define('IMAGE_GRAPH_ALIGN_TOP_RIGHT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_RIGHT);
+
+/**
+ * Align text bottom left
+ */
+define('IMAGE_GRAPH_ALIGN_BOTTOM_LEFT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_LEFT);
+
+/**
+ * Align text bottom right
+ */
+define('IMAGE_GRAPH_ALIGN_BOTTOM_RIGHT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_RIGHT);
+
+/**
+ * Align vertical
+ */
+define('IMAGE_GRAPH_ALIGN_VERTICAL', IMAGE_GRAPH_ALIGN_TOP);
+
+/**
+ * Align horizontal
+ */
+define('IMAGE_GRAPH_ALIGN_HORIZONTAL', IMAGE_GRAPH_ALIGN_LEFT);
+
+// Error codes
+define('IMAGE_GRAPH_ERROR_GENERIC', 0);
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: DataPreprocessor.php,v 1.7 2005/08/24 20:35:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Data preprocessor used for preformatting a data.\r
- *\r
- * A data preprocessor is used in cases where a value from a dataset or label must be\r
- * displayed in another format or way than entered. This could for example be the need\r
- * to display X-values as a date instead of 1, 2, 3, .. or even worse unix-timestamps.\r
- * It could also be when a {@link Image_Graph_Marker_Value} needs to display values as percentages\r
- * with 1 decimal digit instead of the default formatting (fx. 12.01271 -> 12.0%).\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * Image_Graph_DataPreprocessor [Constructor].\r
- */\r
- function Image_Graph_DataPreprocessor()\r
- {\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- return $value;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: DataPreprocessor.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Data preprocessor used for preformatting a data.
+ *
+ * A data preprocessor is used in cases where a value from a dataset or label must be
+ * displayed in another format or way than entered. This could for example be the need
+ * to display X-values as a date instead of 1, 2, 3, .. or even worse unix-timestamps.
+ * It could also be when a {@link Image_Graph_Marker_Value} needs to display values as percentages
+ * with 1 decimal digit instead of the default formatting (fx. 12.01271 -> 12.0%).
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_DataPreprocessor
+{
+
+ /**
+ * Image_Graph_DataPreprocessor [Constructor].
+ */
+ function Image_Graph_DataPreprocessor()
+ {
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ return $value;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Array.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Format data as looked up in an array.\r
- *\r
- * ArrayData is useful when a numercal value is to be translated to\r
- * something thats cannot directly be calculated from this value, this could for\r
- * example be a dataset meant to plot population of various countries. Since x-\r
- * values are numerical and they should really be country names, but there is no\r
- * linear correlation between the number and the name, we use an array to 'map'\r
- * the numbers to the name, i.e. $array[0] = 'Denmark'; $array[1] = 'Sweden';\r
- * ..., where the indexes are the numerical values from the dataset. This is NOT\r
- * usefull when the x-values are a large domain, i.e. to map unix timestamps to\r
- * date-strings for an x-axis. This is because the x-axis will selecte arbitrary\r
- * values for labels, which would in principle require the ArrayData to hold\r
- * values for every unix timestamp. However ArrayData can still be used to solve\r
- * such a situation, since one can use another value for X-data in the dataset\r
- * and then map this (smaller domain) value to a date. That is we for example\r
- * instead of using the unix-timestamp we use value 0 to represent the 1st date,\r
- * 1 to represent the next date, etc.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Array extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * The data label array\r
- * @var array\r
- * @access private\r
- */\r
- var $_dataArray;\r
-\r
- /**\r
- * Image_Graph_ArrayData [Constructor].\r
- *\r
- * @param array $array The array to use as a lookup table\r
- */\r
- function Image_Graph_DataPreprocessor_Array($array)\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- $this->_dataArray = $array;\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- if ((is_array($this->_dataArray)) && (isset ($this->_dataArray[$value]))) {\r
- return $this->_dataArray[$value];\r
- } else {\r
- return $value;\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Array.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Format data as looked up in an array.
+ *
+ * ArrayData is useful when a numercal value is to be translated to
+ * something thats cannot directly be calculated from this value, this could for
+ * example be a dataset meant to plot population of various countries. Since x-
+ * values are numerical and they should really be country names, but there is no
+ * linear correlation between the number and the name, we use an array to 'map'
+ * the numbers to the name, i.e. $array[0] = 'Denmark'; $array[1] = 'Sweden';
+ * ..., where the indexes are the numerical values from the dataset. This is NOT
+ * usefull when the x-values are a large domain, i.e. to map unix timestamps to
+ * date-strings for an x-axis. This is because the x-axis will selecte arbitrary
+ * values for labels, which would in principle require the ArrayData to hold
+ * values for every unix timestamp. However ArrayData can still be used to solve
+ * such a situation, since one can use another value for X-data in the dataset
+ * and then map this (smaller domain) value to a date. That is we for example
+ * instead of using the unix-timestamp we use value 0 to represent the 1st date,
+ * 1 to represent the next date, etc.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Array extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * The data label array
+ * @var array
+ * @access private
+ */
+ var $_dataArray;
+
+ /**
+ * Image_Graph_ArrayData [Constructor].
+ *
+ * @param array $array The array to use as a lookup table
+ */
+ function Image_Graph_DataPreprocessor_Array($array)
+ {
+ parent::__construct();
+ $this->_dataArray = $array;
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ if ((is_array($this->_dataArray)) && (isset ($this->_dataArray[$value]))) {
+ return $this->_dataArray[$value];
+ } else {
+ return $value;
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Currency.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor/Formatted.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor/Formatted.php';\r
-\r
-/**\r
- * Format data as a currency.\r
- *\r
- * Uses the {@link Image_Graph_DataPreprocessor_Formatted} to represent the\r
- * values as a currency, i.e. 10 => \80 10.00\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Currency extends Image_Graph_DataPreprocessor_Formatted\r
-{\r
-\r
- /**\r
- * Image_Graph_CurrencyData [Constructor].\r
- *\r
- * @param string $currencySymbol The symbol representing the currency\r
- */\r
- function Image_Graph_DataPreprocessor_Currency($currencySymbol)\r
- {\r
- parent::Image_Graph_DataPreprocessor_Formatted("$currencySymbol %0.2f");\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Currency.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor/Formatted.php
+ */
+require_once 'Image/Graph/DataPreprocessor/Formatted.php';
+
+/**
+ * Format data as a currency.
+ *
+ * Uses the {@link Image_Graph_DataPreprocessor_Formatted} to represent the
+ * values as a currency, i.e. 10 => � 10.00
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Currency extends Image_Graph_DataPreprocessor_Formatted
+{
+
+ /**
+ * Image_Graph_CurrencyData [Constructor].
+ *
+ * @param string $currencySymbol The symbol representing the currency
+ */
+ function Image_Graph_DataPreprocessor_Currency($currencySymbol)
+ {
+ parent::__construct($currencySymbol.' %0.2f');
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Date.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Formats Unix timestamp as a date using specified format.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Date extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * The format of the Unix time stamp.\r
- * See <a href = 'http://www.php.net/manual/en/function.date.php'>PHP\r
- * Manual</a> for a description\r
- * @var string\r
- * @access private\r
- */\r
- var $_format;\r
-\r
- /**\r
- * Create a DateData preprocessor [Constructor]\r
- *\r
- * @param string $format See {@link http://www.php.net/manual/en/function.date.php\r
- * PHP Manual} for a description\r
- */\r
- function Image_Graph_DataPreprocessor_Date($format)\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- $this->_format = $format;\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- if (!$value) {\r
- return false;\r
- } else {\r
- return date($this->_format, $value);\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Date.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Formats Unix timestamp as a date using specified format.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Date extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * The format of the Unix time stamp.
+ * See <a href = 'http://www.php.net/manual/en/function.date.php'>PHP
+ * Manual</a> for a description
+ * @var string
+ * @access private
+ */
+ var $_format;
+
+ /**
+ * Create a DateData preprocessor [Constructor]
+ *
+ * @param string $format See {@link http://www.php.net/manual/en/function.date.php
+ * PHP Manual} for a description
+ */
+ function Image_Graph_DataPreprocessor_Date($format)
+ {
+ parent::__construct();
+ $this->_format = $format;
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ if (!$value) {
+ return false;
+ } else {
+ return date($this->_format, $value);
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Formatted.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Format data using a (s)printf pattern.\r
- *\r
- * This method is useful when data must displayed using a simple (s) printf\r
- * pattern as described in the {@link http://www.php. net/manual/en/function.\r
- * sprintf.php PHP manual}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Formatted extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * A (s)printf format string.\r
- * See {@link http://www.php.net/manual/en/function.sprintf.php PHP Manual}\r
- * for a description\r
- * @var string\r
- * @access private\r
- */\r
- var $_format;\r
-\r
- /**\r
- * Create a (s)printf format data preprocessor\r
- *\r
- * @param string $format See {@link http://www.php.net/manual/en/function.sprintf.php\r
- * PHP Manual} for a description\r
- */\r
- function Image_Graph_DataPreprocessor_Formatted($format)\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- $this->_format = $format;\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- return sprintf($this->_format, $value);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Formatted.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Format data using a (s)printf pattern.
+ *
+ * This method is useful when data must displayed using a simple (s) printf
+ * pattern as described in the {@link http://www.php. net/manual/en/function.
+ * sprintf.php PHP manual}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Formatted extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * A (s)printf format string.
+ * See {@link http://www.php.net/manual/en/function.sprintf.php PHP Manual}
+ * for a description
+ * @var string
+ * @access private
+ */
+ var $_format;
+
+ /**
+ * Create a (s)printf format data preprocessor
+ *
+ * @param string $format See {@link http://www.php.net/manual/en/function.sprintf.php
+ * PHP Manual} for a description
+ */
+ function Image_Graph_DataPreprocessor_Formatted($format)
+ {
+ parent::__construct();
+ $this->_format = $format;
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ return sprintf($this->_format, $value);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Function.php,v 1.7 2005/11/11 17:53:44 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Formatting a value using a userdefined function.\r
- *\r
- * Use this method to convert/format a value to a 'displayable' lable using a (perhaps)\r
- * more complex function. An example could be (not very applicable though) if one would\r
- * need for values to be displayed on the reverse order, i.e. 1234 would be displayed as\r
- * 4321, then this method can solve this by creating the function that converts the value\r
- * and use the FunctionData datapreprocessor to make Image_Graph use this function.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Function extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * The name of the PHP function\r
- * @var string\r
- * @access private\r
- */\r
- var $_dataFunction;\r
-\r
- /**\r
- * Create a FunctionData preprocessor\r
- *\r
- * @param string $function The name of the PHP function to use as\r
- * a preprocessor, this function must take a single parameter and return a\r
- * formatted version of this parameter\r
- */\r
- function Image_Graph_DataPreprocessor_Function($function)\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- $this->_dataFunction = $function;\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- $function = $this->_dataFunction;\r
- return call_user_func($function, $value);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Function.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Formatting a value using a userdefined function.
+ *
+ * Use this method to convert/format a value to a 'displayable' lable using a (perhaps)
+ * more complex function. An example could be (not very applicable though) if one would
+ * need for values to be displayed on the reverse order, i.e. 1234 would be displayed as
+ * 4321, then this method can solve this by creating the function that converts the value
+ * and use the FunctionData datapreprocessor to make Image_Graph use this function.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Function extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * The name of the PHP function
+ * @var string
+ * @access private
+ */
+ var $_dataFunction;
+
+ /**
+ * Create a FunctionData preprocessor
+ *
+ * @param string $function The name of the PHP function to use as
+ * a preprocessor, this function must take a single parameter and return a
+ * formatted version of this parameter
+ */
+ function Image_Graph_DataPreprocessor_Function($function)
+ {
+ parent::__construct();
+ $this->_dataFunction = $function;
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ $function = $this->_dataFunction;
+ return call_user_func($function, $value);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: NumberText.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Formatting a number as its written in languages supported by Numbers_Words.\r
- *\r
- * Used to display values as text, i.e. 123 is displayed as one hundred and twenty three.\r
- * Requires Numbers_Words\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_NumberText extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * The language identifier\r
- * @var string\r
- * @access private\r
- */\r
- var $_language;\r
-\r
- /**\r
- * Image_Graph_NumberText [Constructor].\r
- *\r
- * Supported languages see {@link http://pear.php.net/package/Numbers_Words Numbers_Words}\r
- *\r
- * @param string $langugage The language identifier for the language.\r
- */\r
- function Image_Graph_DataPreprocessor_NumberText($language = 'en_US')\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- $this->_language = $language;\r
- require_once 'Numbers/Words.php';\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- return Numbers_Words::toWords($value, $this->_language);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: NumberText.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Formatting a number as its written in languages supported by Numbers_Words.
+ *
+ * Used to display values as text, i.e. 123 is displayed as one hundred and twenty three.
+ * Requires Numbers_Words
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_NumberText extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * The language identifier
+ * @var string
+ * @access private
+ */
+ var $_language;
+
+ /**
+ * Image_Graph_NumberText [Constructor].
+ *
+ * Supported languages see {@link http://pear.php.net/package/Numbers_Words Numbers_Words}
+ *
+ * @param string $language The language identifier for the language.
+ */
+ function Image_Graph_DataPreprocessor_NumberText($language = 'en_US')
+ {
+ parent::__construct();
+ $this->_language = $language;
+ include_once 'Numbers/Words.php';
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ return Numbers_Words::toWords($value, $this->_language);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: RomanNumerals.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor.php';\r
-\r
-/**\r
- * Formatting a value as a roman numerals.\r
- *\r
- * Values are formatted as roman numeral, i.e. 1 = I, 2 = II, 9 = IX, 2004 = MMIV.\r
- * Requires Numbers_Roman\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_RomanNumerals extends Image_Graph_DataPreprocessor\r
-{\r
-\r
- /**\r
- * Create a RomanNumerals preprocessor\r
- *\r
- * See {@link http://pear.php.net/package/Numbers_Roman Numbers_Roman}\r
- */\r
- function Image_Graph_DataPreprocessor_RomanNumerals()\r
- {\r
- parent::Image_Graph_DataPreprocessor();\r
- include_once 'Numbers/Roman.php';\r
- }\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- return Numbers_Roman::toNumeral($value);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: RomanNumerals.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor.php
+ */
+require_once 'Image/Graph/DataPreprocessor.php';
+
+/**
+ * Formatting a value as a roman numerals.
+ *
+ * Values are formatted as roman numeral, i.e. 1 = I, 2 = II, 9 = IX, 2004 = MMIV.
+ * Requires Numbers_Roman
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_RomanNumerals extends Image_Graph_DataPreprocessor
+{
+
+ /**
+ * Create a RomanNumerals preprocessor
+ *
+ * See {@link http://pear.php.net/package/Numbers_Roman Numbers_Roman}
+ */
+ function Image_Graph_DataPreprocessor_RomanNumerals()
+ {
+ parent::__construct();
+ include_once 'Numbers/Roman.php';
+ }
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ return Numbers_Roman::toNumeral($value);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Sequential.php,v 1.5 2005/02/21 20:49:50 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataPreprocessor/Array.php\r
- */\r
-require_once 'Image/Graph/DataPreprocessor/Array.php';\r
-\r
-/**\r
- * Formatting values using a sequential data label array, ie. returning the\r
- * 'next label' when asked for any label.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataPreprocessor\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataPreprocessor_Sequential extends Image_Graph_DataPreprocessor_Array\r
-{\r
-\r
- /**\r
- * Process the value\r
- *\r
- * @param var $value The value to process/format\r
- * @return string The processed value\r
- * @access private\r
- */\r
- function _process($value)\r
- {\r
- list ($id, $value) = each($this->_dataArray);\r
- return $value;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Sequential.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataPreprocessor/Array.php
+ */
+require_once 'Image/Graph/DataPreprocessor/Array.php';
+
+/**
+ * Formatting values using a sequential data label array, ie. returning the
+ * 'next label' when asked for any label.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataPreprocessor
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataPreprocessor_Sequential extends Image_Graph_DataPreprocessor_Array
+{
+
+ /**
+ * Process the value
+ *
+ * @param var $value The value to process/format
+ *
+ * @return string The processed value
+ * @access private
+ */
+ function _process($value)
+ {
+ list ($id, $value) = each($this->_dataArray);
+ return $value;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: DataSelector.php,v 1.7 2005/08/24 20:35:56 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Filter used for selecting which data to show as markers\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataSelector\r
-{\r
-\r
- /**\r
- * Image_Graph_DataSelector [Constructor]\r
- */\r
- function Image_Graph_DataSelector()\r
- {\r
- }\r
-\r
- /**\r
- * Check if a specified value should be 'selected', ie shown as a marker\r
- *\r
- * @param array $values The values to check\r
- * @return bool True if the Values should cause a marker to be shown, false if not\r
- * @access private\r
- */\r
- function _select($values)\r
- {\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: DataSelector.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Filter used for selecting which data to show as markers
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataSelector
+{
+
+ /**
+ * Image_Graph_DataSelector [Constructor]
+ */
+ function Image_Graph_DataSelector()
+ {
+ }
+
+ /**
+ * Check if a specified value should be 'selected', ie shown as a marker
+ *
+ * @param array $values The values to check
+ *
+ * @return bool True if the Values should cause a marker to be shown, false if not
+ * @access private
+ */
+ function _select($values)
+ {
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: EveryNthPoint.php,v 1.6 2005/08/24 20:35:59 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataSelector.php\r
- */\r
-require_once 'Image/Graph/DataSelector.php';\r
-\r
-/**\r
- * Filter out all points except every Nth point.\r
- *\r
- * Use this dataselector if you have a large number of datapoints, but only want to\r
- * show markers for a small number of them, say every 10th.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataSelector_EveryNthPoint extends Image_Graph_DataSelector\r
-{\r
-\r
- /**\r
- * The number of points checked\r
- * @var int\r
- * @access private\r
- */\r
- var $_pointNum = 0;\r
-\r
- /**\r
- * The number of points between every 'show', default: 10\r
- * @var int\r
- * @access private\r
- */\r
- var $_pointInterval = 10;\r
-\r
- /**\r
- * EvertNthPoint [Constructor]\r
- *\r
- * @param int $pointInterval The number of points between every 'show',\r
- * default: 10\r
- */\r
- function Image_Graph_DataSelector_EveryNthpoint($pointInterval = 10)\r
- {\r
- parent::Image_Graph_DataSelector();\r
- $this->_pointInterval = $pointInterval;\r
- }\r
-\r
- /**\r
- * Check if a specified value should be 'selected', ie shown as a marker\r
- *\r
- * @param array $values The values to check\r
- * @return bool True if the Values should cause a marker to be shown,\r
- * false if not\r
- * @access private\r
- */\r
- function _select($values)\r
- {\r
- $oldPointNum = $this->_pointNum;\r
- $this->_pointNum++;\r
- return (($oldPointNum % $this->_pointInterval) == 0);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: EveryNthPoint.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataSelector.php
+ */
+require_once 'Image/Graph/DataSelector.php';
+
+/**
+ * Filter out all points except every Nth point.
+ *
+ * Use this dataselector if you have a large number of datapoints, but only want to
+ * show markers for a small number of them, say every 10th.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataSelector_EveryNthPoint extends Image_Graph_DataSelector
+{
+
+ /**
+ * The number of points checked
+ * @var int
+ * @access private
+ */
+ var $_pointNum = 0;
+
+ /**
+ * The number of points between every 'show', default: 10
+ * @var int
+ * @access private
+ */
+ var $_pointInterval = 10;
+
+ /**
+ * EvertNthPoint [Constructor]
+ *
+ * @param int $pointInterval The number of points between every 'show',
+ * default: 10
+ */
+ function Image_Graph_DataSelector_EveryNthPoint($pointInterval = 10)
+ {
+ parent::__construct();
+ $this->_pointInterval = $pointInterval;
+ }
+
+ /**
+ * Check if a specified value should be 'selected', ie shown as a marker
+ *
+ * @param array $values The values to check
+ *
+ * @return bool True if the Values should cause a marker to be shown,
+ * false if not
+ * @access private
+ */
+ function _select($values)
+ {
+ $oldPointNum = $this->_pointNum;
+ $this->_pointNum++;
+ return (($oldPointNum % $this->_pointInterval) == 0);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: NoZeros.php,v 1.5 2005/02/21 20:49:58 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataSelector.php\r
- */\r
-require_once 'Image/Graph/DataSelector.php';\r
-\r
-/**\r
- * Filter out all zero's.\r
- *\r
- * Display all Y-values as markers, except those with Y = 0\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataSelector_NoZeros extends Image_Graph_DataSelector\r
-{\r
-\r
- /**\r
- * Check if a specified value should be 'selected', ie shown as a marker\r
- *\r
- * @param array $values The values to check\r
- * @return bool True if the Values should cause a marker to be shown, false\r
- * if not\r
- * @access private\r
- */\r
- function _select($values)\r
- {\r
- return ($values['Y'] != 0);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: NoZeros.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataSelector.php
+ */
+require_once 'Image/Graph/DataSelector.php';
+
+/**
+ * Filter out all zero's.
+ *
+ * Display all Y-values as markers, except those with Y = 0
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataSelector_NoZeros extends Image_Graph_DataSelector
+{
+
+ /**
+ * Check if a specified value should be 'selected', ie shown as a marker
+ *
+ * @param array $values The values to check
+ *
+ * @return bool True if the Values should cause a marker to be shown, false
+ * if not
+ * @access private
+ */
+ function _select($values)
+ {
+ return ($values['Y'] != 0);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Values.php,v 1.2 2005/10/05 20:51:21 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/DataSelector.php\r
- */\r
-require_once 'Image/Graph/DataSelector.php';\r
-\r
-/**\r
- * Filter out all but the specified values.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage DataSelector\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_DataSelector_Values extends Image_Graph_DataSelector {\r
-\r
- /**\r
- * The array with values that should be included\r
- * @var array\r
- * @access private\r
- */\r
- var $_values;\r
-\r
- /**\r
- * ValueArray [Constructor]\r
- *\r
- * @param array $valueArray The array to use as filter (default empty) \r
- */\r
- function &Image_Graph_DataSelector_Values($values)\r
- {\r
- parent::Image_Graph_DataSelector();\r
- $this->_values = $values;\r
- }\r
-\r
- /**\r
- * Sets the array to use\r
- */\r
- function setValueArray($values)\r
- {\r
- $this->_values = $values;\r
- }\r
-\r
- /**\r
- * Check if a specified value should be 'selected', ie shown as a marker\r
- *\r
- * @param array $values The values to check\r
- * @return bool True if the Values should cause a marker to be shown, false\r
- * if not\r
- * @access private\r
- */\r
- function _select($values)\r
- {\r
- return ( in_array($values['Y'], $this->_values) );\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Values.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/DataSelector.php
+ */
+require_once 'Image/Graph/DataSelector.php';
+
+/**
+ * Filter out all but the specified values.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage DataSelector
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_DataSelector_Values extends Image_Graph_DataSelector
+{
+
+ /**
+ * The array with values that should be included
+ * @var array
+ * @access private
+ */
+ var $_values;
+
+ /**
+ * ValueArray [Constructor]
+ *
+ * @param array $values The array to use as filter (default empty)
+ */
+ function &Image_Graph_DataSelector_Values($values)
+ {
+ parent::__construct();
+ $this->_values = $values;
+ }
+
+ /**
+ * Sets the array to use
+ *
+ * @param array $values Values to use
+ *
+ * @return void
+ */
+ function setValueArray($values)
+ {
+ $this->_values = $values;
+ }
+
+ /**
+ * Check if a specified value should be 'selected', ie shown as a marker
+ *
+ * @param array $values The values to check
+ *
+ * @return bool True if the Values should cause a marker to be shown,
+ * false if not
+ * @access private
+ */
+ function _select($values)
+ {
+ return ( in_array($values['Y'], $this->_values) );
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Dataset.php,v 1.10 2005/08/24 20:35:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-\r
-/**\r
- * Data set used to represent a data collection to plot in a chart\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Dataset\r
-{\r
-\r
- /**\r
- * The pointer of the data set\r
- * @var int\r
- * @access private\r
- */\r
- var $_posX = 0;\r
-\r
- /**\r
- * The minimum X value of the dataset\r
- * @var int\r
- * @access private\r
- */\r
- var $_minimumX = 0;\r
-\r
- /**\r
- * The maximum X value of the dataset\r
- * @var int\r
- * @access private\r
- */\r
- var $_maximumX = 0;\r
-\r
- /**\r
- * The minimum Y value of the dataset\r
- * @var int\r
- * @access private\r
- */\r
- var $_minimumY = 0;\r
-\r
- /**\r
- * The maximum Y value of the dataset\r
- * @var int\r
- * @access private\r
- */\r
- var $_maximumY = 0;\r
-\r
- /**\r
- * The number of points in the dataset\r
- * @var int\r
- * @access private\r
- */\r
- var $_count = 0;\r
-\r
- /**\r
- * The name of the dataset, used for legending\r
- * @var string\r
- * @access private\r
- */\r
- var $_name = '';\r
-\r
- /**\r
- * Image_Graph_Dataset [Constructor]\r
- */\r
- function Image_Graph_Dataset()\r
- {\r
- }\r
-\r
- /**\r
- * Sets the name of the data set, used for legending\r
- *\r
- * @param string $name The name of the dataset\r
- */\r
- function setName($name)\r
- {\r
- $this->_name = $name;\r
- }\r
-\r
- /**\r
- * Add a point to the dataset\r
- *\r
- * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain\r
- * values used for creation of the HTML image map. This is achieved using is an an associated array\r
- * with the following values:\r
- * \r
- * 'url' The URL to create the link to\r
- * \r
- * 'alt' [optional] The alt text on the link\r
- * \r
- * 'target' [optional] The target of the link\r
- * \r
- * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink'\r
- *\r
- * @param int $x The X value to add\r
- * @param int $y The Y value to add, can be omited\r
- * @param var $ID The ID of the point\r
- */\r
- function addPoint($x, $y = false, $ID = false)\r
- {\r
- if ($y !== null) {\r
- if (is_array($y)) {\r
- $maxY = max($y);\r
- $minY = min($y);\r
- } else {\r
- $maxY = $y;\r
- $minY = $y;\r
- }\r
- }\r
-\r
- if ($this->_count) {\r
- $this->_minimumX = min($x, $this->_minimumX);\r
- $this->_maximumX = max($x, $this->_maximumX);\r
- if ($y !== null) {\r
- $this->_minimumY = min($minY, $this->_minimumY);\r
- $this->_maximumY = max($maxY, $this->_maximumY);\r
- }\r
- } else {\r
- $this->_minimumX = $x;\r
- $this->_maximumX = $x;\r
- if ($y !== null) {\r
- $this->_minimumY = $minY;\r
- $this->_maximumY = $maxY;\r
- }\r
- }\r
-\r
- $this->_count++;\r
- }\r
-\r
- /**\r
- * The number of values in the dataset\r
- *\r
- * @return int The number of values in the dataset\r
- */\r
- function count()\r
- {\r
- return $this->_count;\r
- }\r
-\r
- /**\r
- * Gets a X point from the dataset\r
- *\r
- * @param var $x The variable to return an X value from, fx in a vector\r
- * function data set\r
- * @return var The X value of the variable\r
- * @access private\r
- */\r
- function _getPointX($x)\r
- {\r
- return $x;\r
- }\r
-\r
- /**\r
- * Gets a Y point from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a vector\r
- * function data set\r
- * @return var The Y value of the variable\r
- * @access private\r
- */\r
- function _getPointY($x)\r
- {\r
- return $x;\r
- }\r
-\r
- /**\r
- * Gets a ID from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a vector\r
- * function data set\r
- * @return var The ID value of the variable\r
- * @access private\r
- */\r
- function _getPointID($x)\r
- {\r
- return false;\r
- }\r
- \r
- /**\r
- * Gets point data from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a vector\r
- * function data set\r
- * @return array The data for the point\r
- * @access private\r
- */\r
- function _getPointData($x)\r
- {\r
- return false;\r
- }\r
-\r
- /**\r
- * The minimum X value\r
- *\r
- * @return var The minimum X value\r
- */\r
- function minimumX()\r
- {\r
- return $this->_minimumX;\r
- }\r
-\r
- /**\r
- * The maximum X value\r
- *\r
- * @return var The maximum X value\r
- */\r
- function maximumX()\r
- {\r
- return $this->_maximumX;\r
- }\r
-\r
- /**\r
- * The minimum Y value\r
- *\r
- * @return var The minimum Y value\r
- */\r
- function minimumY()\r
- {\r
- return $this->_minimumY;\r
- }\r
-\r
- /**\r
- * The maximum Y value\r
- *\r
- * @return var The maximum Y value\r
- */\r
- function maximumY()\r
- {\r
- return $this->_maximumY;\r
- }\r
-\r
- /**\r
- * The first point\r
- *\r
- * @return array The last point\r
- */\r
- function first()\r
- {\r
- return array('X' => $this->minimumX(), 'Y' => $this->minimumY());\r
- }\r
-\r
- /**\r
- * The last point\r
- *\r
- * @return array The first point\r
- */\r
- function last()\r
- {\r
- return array('X' => $this->maximumX(), 'Y' => $this->maximumY());\r
- }\r
- \r
- /**\r
- * The minimum X value\r
- *\r
- * @param var $value The minimum X value\r
- * @access private\r
- */\r
- function _setMinimumX($value)\r
- {\r
- $this->_minimumX = $value;\r
- }\r
-\r
- /**\r
- * The maximum X value\r
- *\r
- * @param var $value The maximum X value\r
- * @access private\r
- */\r
- function _setMaximumX($value)\r
- {\r
- $this->_maximumX = $value;\r
- }\r
-\r
- /**\r
- * The minimum Y value\r
- *\r
- * @param var $value The minimum X value\r
- * @access private\r
- */\r
- function _setMinimumY($value)\r
- {\r
- $this->_minimumY = $value;\r
- }\r
-\r
- /**\r
- * The maximum Y value\r
- *\r
- * @param var $value The maximum X value\r
- * @access private\r
- */\r
- function _setMaximumY($value)\r
- {\r
- $this->_maximumY = $value;\r
- }\r
-\r
- /**\r
- * The interval between 2 adjacent X values\r
- *\r
- * @return var The interval\r
- * @access private\r
- */\r
- function _stepX()\r
- {\r
- return 1;\r
- }\r
-\r
- /**\r
- * The interval between 2 adjacent Y values\r
- *\r
- * @return var The interval\r
- * @access private\r
- */\r
- function _stepY()\r
- {\r
- return 1;\r
- }\r
-\r
- /**\r
- * Reset the intertal dataset pointer\r
- *\r
- * @return var The first X value\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- $this->_posX = $this->_minimumX;\r
- return $this->_posX;\r
- }\r
-\r
- /**\r
- * Get a point close to the internal pointer\r
- *\r
- * @param int Step Number of points next to the internal pointer, negative\r
- * Step is towards lower X values, positive towards higher X values\r
- * @return array The point\r
- * @access private\r
- */\r
- function _nearby($step = 0)\r
- {\r
- $x = $this->_getPointX($this->_posX + $this->_stepX() * $step);\r
- $y = $this->_getPointY($this->_posX + $this->_stepX() * $step);\r
- $ID = $this->_getPointID($this->_posX + $this->_stepX() * $step);\r
- $data = $this->_getPointData($this->_posX + $this->_stepX() * $step);\r
- if (($x === false) || ($y === false)) {\r
- return false;\r
- } else {\r
- return array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);\r
- }\r
- }\r
-\r
- /**\r
- * Get the next point the internal pointer refers to and advance the pointer\r
- *\r
- * @return array The next point\r
- * @access private\r
- */\r
- function _next()\r
- {\r
- if ($this->_posX > $this->_maximumX) {\r
- return false;\r
- }\r
-\r
- $x = $this->_getPointX($this->_posX);\r
- $y = $this->_getPointY($this->_posX);\r
- $ID = $this->_getPointID($this->_posX);\r
- $data = $this->_getPointData($this->_posX);\r
- $this->_posX += $this->_stepX();\r
-\r
- return array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);\r
- }\r
-\r
- /**\r
- * Get the average of the dataset's Y points\r
- *\r
- * @return var The Y-average across the dataset\r
- * @access private\r
- */\r
- function _averageY()\r
- {\r
- $posX = $this->_minimumX;\r
- $count = 0;\r
- $total = 0;\r
- while ($posX < $this->_maximumX) {\r
- $count ++;\r
- $total += $this->_getPointY($posX);\r
- $posX += $this->_stepX();\r
- }\r
-\r
- if ($count != 0) {\r
- return $total / $count;\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Get the median of the array passed Y points\r
- *\r
- * @param array $data The data-array to get the median from\r
- * @param int $quartile The quartile to return the median from\r
- * @return var The Y-median across the dataset from the specified quartile\r
- * @access private\r
- */\r
- function _median($data, $quartile = 'second')\r
- {\r
- sort($data);\r
- $point = (count($data) - 1) / 2;\r
-\r
- if ($quartile == 'first') {\r
- $lowPoint = 0;\r
- $highPoint = floor($point);\r
- } elseif ($quartile == 'third') {\r
- $lowPoint = round($point);\r
- $highPoint = count($data) - 1;\r
- } else {\r
- $lowPoint = 0;\r
- $highPoint = count($data) - 1;\r
- }\r
-\r
- $point = ($lowPoint + $highPoint) / 2;\r
-\r
- if (floor($point) != $point) {\r
- $point = floor($point);\r
- return ($data[$point] + $data[($point + 1)]) / 2;\r
- } else {\r
- return $data[$point];\r
- }\r
- }\r
-\r
- /**\r
- * Get the median of the datasets Y points\r
- *\r
- * @param int $quartile The quartile to return the median from\r
- * @return var The Y-median across the dataset from the specified quartile\r
- * @access private\r
- */\r
- function _medianY($quartile = 'second')\r
- {\r
- $pointsY = array();\r
- $posX = $this->_minimumX;\r
- while ($posX <= $this->_maximumX) {\r
- $pointsY[] = $this->_getPointY($posX);\r
- $posX += $this->_stepX();\r
- }\r
- return $this->_median($pointsY, $quartile);\r
- }\r
-\r
-}\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Dataset.php 291167 2009-11-23 01:39:31Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+
+/**
+ * Data set used to represent a data collection to plot in a chart
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Dataset
+{
+
+ /**
+ * The pointer of the data set
+ * @var int
+ * @access private
+ */
+ var $_posX = 0;
+
+ /**
+ * The minimum X value of the dataset
+ * @var int
+ * @access private
+ */
+ var $_minimumX = 0;
+
+ /**
+ * The maximum X value of the dataset
+ * @var int
+ * @access private
+ */
+ var $_maximumX = 0;
+
+ /**
+ * The minimum Y value of the dataset
+ * @var int
+ * @access private
+ */
+ var $_minimumY = 0;
+
+ /**
+ * The maximum Y value of the dataset
+ * @var int
+ * @access private
+ */
+ var $_maximumY = 0;
+
+ /**
+ * The number of points in the dataset
+ * @var int
+ * @access private
+ */
+ var $_count = 0;
+
+ /**
+ * The name of the dataset, used for legending
+ * @var string
+ * @access private
+ */
+ var $_name = '';
+
+ /**
+ * Image_Graph_Dataset [Constructor]
+ */
+ function Image_Graph_Dataset()
+ {
+ }
+
+ /**
+ * Sets the name of the data set, used for legending
+ *
+ * @param string $name The name of the dataset
+ *
+ * @return void
+ */
+ function setName($name)
+ {
+ $this->_name = $name;
+ }
+
+ /**
+ * Add a point to the dataset
+ *
+ * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain
+ * values used for creation of the HTML image map. This is achieved using is an an associated array
+ * with the following values:
+ *
+ * 'url' The URL to create the link to
+ *
+ * 'alt' [optional] The alt text on the link
+ *
+ * 'target' [optional] The target of the link
+ *
+ * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink'
+ *
+ * @param int $x The X value to add
+ * @param int $y The Y value to add, can be omited
+ * @param var $ID The ID of the point
+ *
+ * @return void
+ */
+ function addPoint($x, $y = false, $ID = false)
+ {
+ if ($y !== null) {
+ if (is_array($y)) {
+ $maxY = max($y);
+ $minY = min($y);
+ } else {
+ $maxY = $y;
+ $minY = $y;
+ }
+ }
+
+ if ($this->_count) {
+ $this->_minimumX = min($x, $this->_minimumX);
+ $this->_maximumX = max($x, $this->_maximumX);
+ if ($y !== null) {
+ $this->_minimumY = min($minY, $this->_minimumY);
+ $this->_maximumY = max($maxY, $this->_maximumY);
+ }
+ } else {
+ $this->_minimumX = $x;
+ $this->_maximumX = $x;
+ if ($y !== null) {
+ $this->_minimumY = $minY;
+ $this->_maximumY = $maxY;
+ }
+ }
+
+ $this->_count++;
+ }
+
+ /**
+ * The number of values in the dataset
+ *
+ * @return int The number of values in the dataset
+ */
+ function count()
+ {
+ return $this->_count;
+ }
+
+ /**
+ * Gets a X point from the dataset
+ *
+ * @param var $x The variable to return an X value from, fx in a vector
+ * function data set
+ *
+ * @return var The X value of the variable
+ * @access private
+ */
+ function _getPointX($x)
+ {
+ return $x;
+ }
+
+ /**
+ * Gets a Y point from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a vector
+ * function data set
+ *
+ * @return var The Y value of the variable
+ * @access private
+ */
+ function _getPointY($x)
+ {
+ return $x;
+ }
+
+ /**
+ * Gets a ID from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a vector
+ * function data set
+ *
+ * @return var The ID value of the variable
+ * @access private
+ */
+ function _getPointID($x)
+ {
+ return false;
+ }
+
+ /**
+ * Gets point data from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a vector
+ * function data set
+ *
+ * @return array The data for the point
+ * @access private
+ */
+ function _getPointData($x)
+ {
+ return false;
+ }
+
+ /**
+ * The minimum X value
+ *
+ * @return var The minimum X value
+ */
+ function minimumX()
+ {
+ return $this->_minimumX;
+ }
+
+ /**
+ * The maximum X value
+ *
+ * @return var The maximum X value
+ */
+ function maximumX()
+ {
+ return $this->_maximumX;
+ }
+
+ /**
+ * The minimum Y value
+ *
+ * @return var The minimum Y value
+ */
+ function minimumY()
+ {
+ return $this->_minimumY;
+ }
+
+ /**
+ * The maximum Y value
+ *
+ * @return var The maximum Y value
+ */
+ function maximumY()
+ {
+ return $this->_maximumY;
+ }
+
+ /**
+ * The first point
+ *
+ * @return array The last point
+ */
+ function first()
+ {
+ return array('X' => $this->minimumX(), 'Y' => $this->minimumY());
+ }
+
+ /**
+ * The last point
+ *
+ * @return array The first point
+ */
+ function last()
+ {
+ return array('X' => $this->maximumX(), 'Y' => $this->maximumY());
+ }
+
+ /**
+ * The minimum X value
+ *
+ * @param var $value The minimum X value
+ *
+ * @return void
+ * @access private
+ */
+ function _setMinimumX($value)
+ {
+ $this->_minimumX = $value;
+ }
+
+ /**
+ * The maximum X value
+ *
+ * @param var $value The maximum X value
+ *
+ * @return void
+ * @access private
+ */
+ function _setMaximumX($value)
+ {
+ $this->_maximumX = $value;
+ }
+
+ /**
+ * The minimum Y value
+ *
+ * @param var $value The minimum X value
+ *
+ * @return void
+ * @access private
+ */
+ function _setMinimumY($value)
+ {
+ $this->_minimumY = $value;
+ }
+
+ /**
+ * The maximum Y value
+ *
+ * @param var $value The maximum X value
+ *
+ * @return void
+ * @access private
+ */
+ function _setMaximumY($value)
+ {
+ $this->_maximumY = $value;
+ }
+
+ /**
+ * The interval between 2 adjacent X values
+ *
+ * @return var The interval
+ * @access private
+ */
+ function _stepX()
+ {
+ return 1;
+ }
+
+ /**
+ * The interval between 2 adjacent Y values
+ *
+ * @return var The interval
+ * @access private
+ */
+ function _stepY()
+ {
+ return 1;
+ }
+
+ /**
+ * Reset the intertal dataset pointer
+ *
+ * @return var The first X value
+ * @access private
+ */
+ function _reset()
+ {
+ $this->_posX = $this->_minimumX;
+ return $this->_posX;
+ }
+
+ /**
+ * Get a point close to the internal pointer
+ *
+ * @param int $step Number of points next to the internal pointer, negative
+ * Step is towards lower X values, positive towards higher X values
+ *
+ * @return array The point
+ * @access private
+ */
+ function _nearby($step = 0)
+ {
+ $x = $this->_getPointX($this->_posX + $this->_stepX() * $step);
+ $y = $this->_getPointY($this->_posX + $this->_stepX() * $step);
+ $ID = $this->_getPointID($this->_posX + $this->_stepX() * $step);
+ $data = $this->_getPointData($this->_posX + $this->_stepX() * $step);
+ if (($x === false) || ($y === false)) {
+ return false;
+ } else {
+ return array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
+ }
+ }
+
+ /**
+ * Get the next point the internal pointer refers to and advance the pointer
+ *
+ * @return array The next point
+ * @access private
+ */
+ function _next()
+ {
+ if ($this->_posX > $this->_maximumX) {
+ return false;
+ }
+
+ $x = $this->_getPointX($this->_posX);
+ $y = $this->_getPointY($this->_posX);
+ $ID = $this->_getPointID($this->_posX);
+ $data = $this->_getPointData($this->_posX);
+ $this->_posX += $this->_stepX();
+
+ return array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
+ }
+
+ /**
+ * Get the average of the dataset's Y points
+ *
+ * @return var The Y-average across the dataset
+ * @access private
+ */
+ function _averageY()
+ {
+ $posX = $this->_minimumX;
+ $count = 0;
+ $total = 0;
+ while ($posX < $this->_maximumX) {
+ $count ++;
+ $total += $this->_getPointY($posX);
+ $posX += $this->_stepX();
+ }
+
+ if ($count != 0) {
+ return $total / $count;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Get the median of the array passed Y points
+ *
+ * @param array $data The data-array to get the median from
+ * @param int $quartile The quartile to return the median from
+ *
+ * @return var The Y-median across the dataset from the specified quartile
+ * @access private
+ */
+ function _median($data, $quartile = 'second')
+ {
+ sort($data);
+ $point = (count($data) - 1) / 2;
+
+ if ($quartile == 'first') {
+ $lowPoint = 0;
+ $highPoint = floor($point);
+ } elseif ($quartile == 'third') {
+ $lowPoint = round($point);
+ $highPoint = count($data) - 1;
+ } else {
+ $lowPoint = 0;
+ $highPoint = count($data) - 1;
+ }
+
+ $point = ($lowPoint + $highPoint) / 2;
+
+ if (floor($point) != $point) {
+ $point = floor($point);
+ return ($data[$point] + $data[($point + 1)]) / 2;
+ } else {
+ return $data[$point];
+ }
+ }
+
+ /**
+ * Get the median of the datasets Y points
+ *
+ * @param int $quartile The quartile to return the median from
+ *
+ * @return var The Y-median across the dataset from the specified quartile
+ * @access private
+ */
+ function _medianY($quartile = 'second')
+ {
+ $pointsY = array();
+ $posX = $this->_minimumX;
+ while ($posX <= $this->_maximumX) {
+ $pointsY[] = $this->_getPointY($posX);
+ $posX += $this->_stepX();
+ }
+ return $this->_median($pointsY, $quartile);
+ }
+
+}
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Function.php,v 1.7 2005/08/24 20:35:57 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Dataset.php\r
- */\r
-require_once 'Image/Graph/Dataset.php';\r
-\r
-/**\r
- * Function data set, points are generated by calling an external function.\r
- *\r
- * The function must be a single variable function and return a the result,\r
- * builtin functions that are fx sin() or cos(). User defined function can be\r
- * used if they are such, i.e: function myFunction($variable)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Dataset_Function extends Image_Graph_Dataset\r
-{\r
-\r
- /**\r
- * The name of the function\r
- * @var string\r
- * @access private\r
- */\r
- var $_dataFunction;\r
-\r
- /**\r
- * Image_Graph_FunctionDataset [Constructor]\r
- *\r
- * @param double $minimumX The minimum X value\r
- * @param double $maximumX The maximum X value\r
- * @param string $function The name of the function, if must be a single\r
- * parameter function like fx sin(x) or cos(x)\r
- * @param int $points The number of points to create\r
- */\r
- function Image_Graph_Dataset_Function($minimumX, $maximumX, $function, $points)\r
- {\r
- parent::Image_Graph_Dataset();\r
- $this->_minimumX = $minimumX;\r
- $this->_maximumX = $maximumX;\r
- $this->_dataFunction = $function;\r
- $this->_count = $points;\r
- $this->_calculateMaxima();\r
- }\r
-\r
- /**\r
- * Add a point to the dataset.\r
- *\r
- * You can't add points to a function dataset\r
- *\r
- * @param int $x The X value to add\r
- * @param int $y The Y value to add, can be omited\r
- * @param var $ID The ID of the point\r
- */\r
- function addPoint($x, $y = false, $ID = false)\r
- {\r
- }\r
-\r
- /**\r
- * Gets a Y point from the dataset\r
- *\r
- * @param var $x The variable to apply the function to\r
- * @return var The function applied to the X value\r
- * @access private\r
- */\r
- function _getPointY($x)\r
- {\r
- $function = $this->_dataFunction;\r
- return $function ($x);\r
- }\r
-\r
- /**\r
- * The number of values in the dataset\r
- *\r
- * @return int The number of values in the dataset\r
- * @access private\r
- */\r
- function _count()\r
- {\r
- return $this->_count;\r
- }\r
-\r
- /**\r
- * The interval between 2 adjacent Y values\r
- *\r
- * @return var The interval\r
- * @access private\r
- */\r
- function _stepX()\r
- {\r
- return ($this->_maximumX - $this->_minimumX) / $this->_count();\r
- }\r
-\r
- /**\r
- * Calculates the Y extrema of the function\r
- *\r
- * @access private\r
- */\r
- function _calculateMaxima()\r
- {\r
- $x = $this->_minimumX;\r
- while ($x <= $this->_maximumX) {\r
- $y = $this->_getPointY($x);\r
- $this->_minimumY = min($y, $this->_minimumY);\r
- $this->_maximumY = max($y, $this->_maximumY);\r
- $x += $this->_stepX();\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Function.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Dataset.php
+ */
+require_once 'Image/Graph/Dataset.php';
+
+/**
+ * Function data set, points are generated by calling an external function.
+ *
+ * The function must be a single variable function and return a the result,
+ * builtin functions that are fx sin() or cos(). User defined function can be
+ * used if they are such, i.e: function myFunction($variable)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Dataset_Function extends Image_Graph_Dataset
+{
+
+ /**
+ * The name of the function
+ * @var string
+ * @access private
+ */
+ var $_dataFunction;
+
+ /**
+ * Image_Graph_FunctionDataset [Constructor]
+ *
+ * @param double $minimumX The minimum X value
+ * @param double $maximumX The maximum X value
+ * @param string $function The name of the function, if must be a single
+ * parameter function like fx sin(x) or cos(x)
+ * @param int $points The number of points to create
+ */
+ function Image_Graph_Dataset_Function($minimumX, $maximumX, $function, $points)
+ {
+ parent::__construct();
+ $this->_minimumX = $minimumX;
+ $this->_maximumX = $maximumX;
+ $this->_dataFunction = $function;
+ $this->_count = $points;
+ $this->_calculateMaxima();
+ }
+
+ /**
+ * Add a point to the dataset.
+ *
+ * You can't add points to a function dataset
+ *
+ * @param int $x The X value to add
+ * @param int $y The Y value to add, can be omited
+ * @param var $ID The ID of the point
+ *
+ * @return void
+ */
+ function addPoint($x, $y = false, $ID = false)
+ {
+ }
+
+ /**
+ * Gets a Y point from the dataset
+ *
+ * @param var $x The variable to apply the function to
+ *
+ * @return var The function applied to the X value
+ * @access private
+ */
+ function _getPointY($x)
+ {
+ $function = $this->_dataFunction;
+ return $function ($x);
+ }
+
+ /**
+ * The number of values in the dataset
+ *
+ * @return int The number of values in the dataset
+ * @access private
+ */
+ function _count()
+ {
+ return $this->_count;
+ }
+
+ /**
+ * The interval between 2 adjacent Y values
+ *
+ * @return var The interval
+ * @access private
+ */
+ function _stepX()
+ {
+ return ($this->_maximumX - $this->_minimumX) / $this->_count();
+ }
+
+ /**
+ * Calculates the Y extrema of the function
+ *
+ * @return void
+ * @access private
+ */
+ function _calculateMaxima()
+ {
+ $x = $this->_minimumX;
+ while ($x <= $this->_maximumX) {
+ $y = $this->_getPointY($x);
+ $this->_minimumY = min($y, $this->_minimumY);
+ $this->_maximumY = max($y, $this->_maximumY);
+ $x += $this->_stepX();
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Random.php,v 1.6 2005/08/24 20:35:57 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Dataset/Trivial.php\r
- */\r
-require_once 'Image/Graph/Dataset/Trivial.php';\r
-\r
-/**\r
- * Random data set, points are generated by random.\r
- *\r
- * This dataset is mostly (if not solely) used for demo-purposes.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Dataset_Random extends Image_Graph_Dataset_Trivial\r
-{\r
-\r
- /**\r
- * RandomDataset [Constructor]\r
- *\r
- * @param int $count The number of points to create\r
- * @param double $minimum The minimum value the random set can be\r
- * @param double $maximum The maximum value the random set can be\r
- * @param bool $includeZero Whether 0 should be included or not as an X\r
- * value, may be omitted, default: false</false>\r
- */\r
- function Image_Graph_Dataset_Random($count, $minimum, $maximum, $includeZero = false)\r
- {\r
- parent::Image_Graph_Dataset_Trivial();\r
- $i = 0;\r
- while ($i < $count) {\r
- $this->addPoint(\r
- $ixc = ($includeZero ? $i : $i +1),\r
- rand($minimum, $maximum)\r
- );\r
- $i ++;\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Random.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Dataset/Trivial.php
+ */
+require_once 'Image/Graph/Dataset/Trivial.php';
+
+/**
+ * Random data set, points are generated by random.
+ *
+ * This dataset is mostly (if not solely) used for demo-purposes.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Groupn
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Dataset_Random extends Image_Graph_Dataset_Trivial
+{
+
+ /**
+ * RandomDataset [Constructor]
+ *
+ * @param int $count The number of points to create
+ * @param double $minimum The minimum value the random set can be
+ * @param double $maximum The maximum value the random set can be
+ * @param bool $includeZero Whether 0 should be included or not as an X
+ * value, may be omitted, default: false</false>
+ */
+ function Image_Graph_Dataset_Random($count, $minimum, $maximum, $includeZero = false)
+ {
+ parent::__construct();
+ $i = 0;
+ while ($i < $count) {
+ $this->addPoint(
+ $ixc = ($includeZero ? $i : $i +1),
+ rand($minimum, $maximum)
+ );
+ $i ++;
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Sequential.php,v 1.7 2005/08/24 20:35:58 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Dataset/Trivial.php\r
- */\r
-require_once 'Image/Graph/Dataset/Trivial.php';\r
-\r
-/**\r
- * Sequential data set, simply add points (y) 1 by 1.\r
- *\r
- * This is a single point (1D) dataset, all points are of the type (0, y1), (1,\r
- * y2), (2, y3)... Where the X-value is implicitly incremented. This is useful\r
- * for example for barcharts, where you could fx. use an {@link\r
- * Image_Graph_Dataset_Array} datapreprocessor to make sence of the x-values.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Dataset_Sequential extends Image_Graph_Dataset_Trivial\r
-{\r
-\r
- /**\r
- * Image_Graph_SequentialDataset [Constructor]\r
- */\r
- function Image_Graph_Dataset_Sequential($dataArray = false)\r
- {\r
- parent::Image_Graph_Dataset_Trivial();\r
- if (is_array($dataArray)) {\r
- reset($dataArray);\r
- foreach ($dataArray as $value) {\r
- $this->addPoint($value);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Add a point to the dataset\r
- *\r
- * @param int $y The Y value to add, can be omited\r
- * @param var $ID The ID of the point\r
- */\r
- function addPoint($y, $ID = false)\r
- {\r
- parent::addPoint($this->count(), $y);\r
- }\r
-\r
- /**\r
- * Gets a X point from the dataset\r
- *\r
- * @param var $x The variable to return an X value from, fx in a\r
- * vector function data set\r
- * @return var The X value of the variable\r
- * @access private\r
- */\r
- function _getPointX($x)\r
- {\r
- return ((int) $x);\r
- }\r
-\r
- /**\r
- * The minimum X value\r
- * @return var The minimum X value\r
- */\r
- function minimumX()\r
- {\r
- return 0;\r
- }\r
-\r
- /**\r
- * The maximum X value\r
- * @return var The maximum X value\r
- */\r
- function maximumX()\r
- {\r
- return $this->count();\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Sequential.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Dataset/Trivial.php
+ */
+require_once 'Image/Graph/Dataset/Trivial.php';
+
+/**
+ * Sequential data set, simply add points (y) 1 by 1.
+ *
+ * This is a single point (1D) dataset, all points are of the type (0, y1), (1,
+ * y2), (2, y3)... Where the X-value is implicitly incremented. This is useful
+ * for example for barcharts, where you could fx. use an {@link
+ * Image_Graph_Dataset_Array} datapreprocessor to make sence of the x-values.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Dataset_Sequential extends Image_Graph_Dataset_Trivial
+{
+
+ /**
+ * Image_Graph_SequentialDataset [Constructor]
+ *
+ * @param array $dataArray Array with data
+ */
+ function Image_Graph_Dataset_Sequential($dataArray = false)
+ {
+ parent::__construct();
+ if (is_array($dataArray)) {
+ reset($dataArray);
+ foreach ($dataArray as $value) {
+ $this->addPoint($value);
+ }
+ }
+ }
+
+ /**
+ * Add a point to the dataset
+ *
+ * @param int $y The Y value to add, can be omited
+ * @param var $ID The ID of the point
+ *
+ * @return void
+ */
+ function addPoint($y, $ID = false)
+ {
+ parent::addPoint($this->count(), $y, $ID);
+ }
+
+ /**
+ * Gets a X point from the dataset
+ *
+ * @param var $x The variable to return an X value from, fx in a
+ * vector function data set
+ *
+ * @return var The X value of the variable
+ * @access private
+ */
+ function _getPointX($x)
+ {
+ return ((int) $x);
+ }
+
+ /**
+ * The minimum X value
+ *
+ * @return var The minimum X value
+ */
+ function minimumX()
+ {
+ return 0;
+ }
+
+ /**
+ * The maximum X value
+ *
+ * @return var The maximum X value
+ */
+ function maximumX()
+ {
+ return $this->count();
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Trivial.php,v 1.10 2005/09/25 18:08:56 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Dataset.php\r
- */\r
-require_once 'Image/Graph/Dataset.php';\r
-\r
-/**\r
- * Trivial data set, simply add points (x, y) 1 by 1\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Dataset_Trivial extends Image_Graph_Dataset\r
-{\r
-\r
- /**\r
- * Data storage\r
- * @var array\r
- * @access private\r
- */\r
- var $_data;\r
-\r
- /**\r
- * Image_Graph_Dataset_Trivial [Constructor]\r
- *\r
- * Pass an associated array ($data[$x] = $y) to the constructor for easy\r
- * data addition. Alternatively (if multiple entries with same x value is\r
- * required) pass an array with (x, y) values: $data[$id] = array('x' => $x,\r
- * 'y' => $y); \r
- *\r
- * NB! If passing the 1st type array at this point, the x-values will also\r
- * be used for ID tags, i.e. when using {@link Image_Graph_Fill_Array}. In\r
- * the 2nd type the key/index of the "outermost" array will be the id tag\r
- * (i.e. $id in the example)\r
- *\r
- * @param array $dataArray An associated array with values to the dataset\r
- */\r
- function Image_Graph_Dataset_Trivial($dataArray = false)\r
- {\r
- parent::Image_Graph_Dataset();\r
- $this->_data = array ();\r
- if (is_array($dataArray)) {\r
- reset($dataArray);\r
- $keys = array_keys($dataArray);\r
- foreach ($keys as $x) {\r
- $y =& $dataArray[$x];\r
- if ((is_array($y)) && (isset($y['x'])) && (isset($y['y']))) {\r
- $this->addPoint($y['x'], $y['y'], (isset($y['id']) ? $y['id'] : $x));\r
- } else {\r
- $this->addPoint($x, $y, $x);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Add a point to the dataset\r
- *\r
- * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain\r
- * values used for creation of the HTML image map. This is achieved using is an an associated array\r
- * with the following values:\r
- * \r
- * 'url' The URL to create the link to\r
- * \r
- * 'alt' [optional] The alt text on the link\r
- * \r
- * 'target' [optional] The target of the link\r
- * \r
- * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink'\r
- *\r
- * @param int $x The X value to add\r
- * @param int $y The Y value to add, can be omited\r
- * @param var $ID The ID of the point\r
- */\r
- function addPoint($x, $y = false, $ID = false)\r
- {\r
- parent::addPoint($x, $y, $ID);\r
-\r
- if (is_array($ID)) {\r
- $data = $ID;\r
- $ID = (isset($data['id']) ? $data['id'] : false);\r
- } else {\r
- $data = false;\r
- }\r
-\r
- $this->_data[] = array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);\r
- if (!is_numeric($x)) {\r
- $this->_maximumX = count($this->_data);\r
- }\r
- }\r
-\r
- /**\r
- * The first point\r
- *\r
- * @return array The last point\r
- */\r
- function first()\r
- {\r
- reset($this->_data);\r
- return current($this->_data);\r
- }\r
-\r
- /**\r
- * The last point\r
- *\r
- * @return array The first point\r
- */\r
- function last()\r
- {\r
- return end($this->_data);\r
- }\r
-\r
- /**\r
- * Gets a X point from the dataset\r
- *\r
- * @param var $x The variable to return an X value from, fx in a\r
- * vector function data set\r
- * @return var The X value of the variable\r
- * @access private\r
- */\r
- function _getPointX($x)\r
- {\r
- if (isset($this->_data[$x])) {\r
- return $this->_data[$x]['X'];\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Gets a Y point from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a\r
- * vector function data set\r
- * @return var The Y value of the variable\r
- * @access private\r
- */\r
- function _getPointY($x)\r
- {\r
- if (isset($this->_data[$x])) {\r
- return $this->_data[$x]['Y'];\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Gets a ID from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a\r
- * vector function data set\r
- * @return var The ID value of the variable\r
- * @access private\r
- */\r
- function _getPointID($x)\r
- {\r
- if (isset($this->_data[$x])) {\r
- return $this->_data[$x]['ID'];\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * Gets point data from the dataset\r
- *\r
- * @param var $x The variable to return an Y value from, fx in a vector\r
- * function data set\r
- * @return array The data for the point\r
- * @access private\r
- */\r
- function _getPointData($x)\r
- {\r
- if (isset($this->_data[$x])) {\r
- return $this->_data[$x]['data'];\r
- } else {\r
- return false;\r
- }\r
- }\r
- \r
- /**\r
- * The number of values in the dataset\r
- *\r
- * @return int The number of values in the dataset\r
- */\r
- function count()\r
- {\r
- return count($this->_data);\r
- }\r
-\r
- /**\r
- * Reset the intertal dataset pointer\r
- *\r
- * @return var The first X value\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- $this->_posX = 0;\r
- return $this->_posX;\r
- }\r
-\r
- /**\r
- * Get the next point the internal pointer refers to and advance the pointer\r
- *\r
- * @return array The next point\r
- * @access private\r
- */\r
- function _next()\r
- {\r
- if ($this->_posX >= $this->count()) {\r
- return false;\r
- }\r
- $x = $this->_getPointX($this->_posX);\r
- $y = $this->_getPointY($this->_posX);\r
- $ID = $this->_getPointID($this->_posX);\r
- $data = $this->_getPointData($this->_posX);\r
- $this->_posX += $this->_stepX();\r
-\r
- return array('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Trivial.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Dataset.php
+ */
+require_once 'Image/Graph/Dataset.php';
+
+/**
+ * Trivial data set, simply add points (x, y) 1 by 1
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Dataset_Trivial extends Image_Graph_Dataset
+{
+
+ /**
+ * Data storage
+ * @var array
+ * @access private
+ */
+ var $_data;
+
+ /**
+ * Image_Graph_Dataset_Trivial [Constructor]
+ *
+ * Pass an associated array ($data[$x] = $y) to the constructor for easy
+ * data addition. Alternatively (if multiple entries with same x value is
+ * required) pass an array with (x, y) values: $data[$id] = array('x' => $x,
+ * 'y' => $y);
+ *
+ * NB! If passing the 1st type array at this point, the x-values will also
+ * be used for ID tags, i.e. when using {@link Image_Graph_Fill_Array}. In
+ * the 2nd type the key/index of the "outermost" array will be the id tag
+ * (i.e. $id in the example)
+ *
+ * @param array $dataArray An associated array with values to the dataset
+ */
+ function Image_Graph_Dataset_Trivial($dataArray = false)
+ {
+ parent::__construct();
+ $this->_data = array ();
+ if (is_array($dataArray)) {
+ reset($dataArray);
+ $keys = array_keys($dataArray);
+ foreach ($keys as $x) {
+ $y =& $dataArray[$x];
+ if ((is_array($y)) && (isset($y['x'])) && (isset($y['y']))) {
+ $this->addPoint($y['x'], $y['y'], (isset($y['id']) ? $y['id'] : $x));
+ } else {
+ $this->addPoint($x, $y, $x);
+ }
+ }
+ }
+ }
+
+ /**
+ * Add a point to the dataset
+ *
+ * $ID can contain either the ID of the point, i.e. 'DK', 123, 'George', etc. or it can contain
+ * values used for creation of the HTML image map. This is achieved using is an an associated array
+ * with the following values:
+ *
+ * 'url' The URL to create the link to
+ *
+ * 'alt' [optional] The alt text on the link
+ *
+ * 'target' [optional] The target of the link
+ *
+ * 'htmltags' [optional] An associated array with html tags (tag as key), fx. 'onMouseOver' => 'history.go(-1);', 'id' => 'thelink'
+ *
+ * @param int $x The X value to add
+ * @param int $y The Y value to add, can be omited
+ * @param var $ID The ID of the point
+ *
+ * @return void
+ */
+ function addPoint($x, $y = false, $ID = false)
+ {
+ parent::addPoint($x, $y, $ID);
+
+ if (is_array($ID)) {
+ $data = $ID;
+ $ID = (isset($data['id']) ? $data['id'] : false);
+ } else {
+ $data = false;
+ }
+
+ $this->_data[] = array ('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
+ if (!is_numeric($x)) {
+ $this->_maximumX = count($this->_data);
+ }
+ }
+
+ /**
+ * The first point
+ *
+ * @return array The first point
+ */
+ function first()
+ {
+ reset($this->_data);
+ return current($this->_data);
+ }
+
+ /**
+ * The last point
+ *
+ * @return array The last point
+ */
+ function last()
+ {
+ return end($this->_data);
+ }
+
+ /**
+ * Gets a X point from the dataset
+ *
+ * @param var $x The variable to return an X value from, fx in a
+ * vector function data set
+ *
+ * @return var The X value of the variable
+ * @access private
+ */
+ function _getPointX($x)
+ {
+ if (isset($this->_data[$x])) {
+ return $this->_data[$x]['X'];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Gets a Y point from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a
+ * vector function data set
+ *
+ * @return var The Y value of the variable
+ * @access private
+ */
+ function _getPointY($x)
+ {
+ if (isset($this->_data[$x])) {
+ return $this->_data[$x]['Y'];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Gets a ID from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a
+ * vector function data set
+ *
+ * @return var The ID value of the variable
+ * @access private
+ */
+ function _getPointID($x)
+ {
+ if (isset($this->_data[$x])) {
+ return $this->_data[$x]['ID'];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Gets point data from the dataset
+ *
+ * @param var $x The variable to return an Y value from, fx in a vector
+ * function data set
+ *
+ * @return array The data for the point
+ * @access private
+ */
+ function _getPointData($x)
+ {
+ if (isset($this->_data[$x])) {
+ return $this->_data[$x]['data'];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * The number of values in the dataset
+ *
+ * @return int The number of values in the dataset
+ */
+ function count()
+ {
+ return count($this->_data);
+ }
+
+ /**
+ * Reset the intertal dataset pointer
+ *
+ * @return var The first X value
+ * @access private
+ */
+ function _reset()
+ {
+ $this->_posX = 0;
+ return $this->_posX;
+ }
+
+ /**
+ * Get the next point the internal pointer refers to and advance the pointer
+ *
+ * @return array The next point
+ * @access private
+ */
+ function _next()
+ {
+ if ($this->_posX >= $this->count()) {
+ return false;
+ }
+ $x = $this->_getPointX($this->_posX);
+ $y = $this->_getPointY($this->_posX);
+ $ID = $this->_getPointID($this->_posX);
+ $data = $this->_getPointData($this->_posX);
+ $this->_posX += $this->_stepX();
+
+ return array('X' => $x, 'Y' => $y, 'ID' => $ID, 'data' => $data);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: VectorFunction.php,v 1.6 2005/08/24 20:35:57 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Dataset.php\r
- */\r
-require_once 'Image/Graph/Dataset.php';\r
-\r
-/**\r
- * Vector Function data set.\r
- *\r
- * Points are generated by calling 2 external functions, fx. x = sin(t) and y =\r
- * cos(t)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Dataset\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Dataset_VectorFunction extends Image_Graph_Dataset\r
-{\r
-\r
- /**\r
- * The name of the X function\r
- * @var string\r
- * @access private\r
- */\r
- var $_functionX;\r
-\r
- /**\r
- * The name of the Y function\r
- * @var string\r
- * @access private\r
- */\r
- var $_functionY;\r
-\r
- /**\r
- * The minimum of the vector function variable\r
- * @var double\r
- * @access private\r
- */\r
- var $_minimumT;\r
-\r
- /**\r
- * The maximum of the vector function variable\r
- * @var double\r
- * @access private\r
- */\r
- var $_maximumT;\r
-\r
- /**\r
- * Image_Graph_VectorFunctionDataset [Constructor]\r
- *\r
- * @param double $minimumT The minimum value of the vector function variable\r
- * @param double $maximumT The maximum value of the vector function variable\r
- * @param string $functionX The name of the X function, if must be a single\r
- * parameter function like fx sin(x) or cos(x)\r
- * @param string $functionY The name of the Y function, if must be a single\r
- * parameter function like fx sin(x) or cos(x)\r
- * @param int $points The number of points to create\r
- */\r
- function Image_Graph_Dataset_VectorFunction($minimumT, $maximumT, $functionX, $functionY, $points)\r
- {\r
- parent::Image_Graph_Dataset();\r
- $this->_minimumT = $minimumT;\r
- $this->_maximumT = $maximumT;\r
- $this->_functionX = $functionX;\r
- $this->_functionY = $functionY;\r
- $this->_count = $points;\r
- $this->_calculateMaxima();\r
- }\r
-\r
- /**\r
- * Add a point to the dataset\r
- *\r
- * @param int $x The X value to add\r
- * @param int $y The Y value to add, can be omited\r
- * @param var $ID The ID of the point\r
- */\r
- function addPoint($x, $y = false, $ID = false)\r
- {\r
- }\r
-\r
- /**\r
- * Gets a X point from the dataset\r
- *\r
- * @param var $x The variable to apply the X function to\r
- * @return var The X function applied to the X value\r
- * @access private\r
- */\r
- function _getPointX($x)\r
- {\r
- $functionX = $this->_functionX;\r
- return $functionX ($x);\r
- }\r
-\r
- /**\r
- * Gets a Y point from the dataset\r
- *\r
- * @param var $x The variable to apply the Y function to\r
- * @return var The Y function applied to the X value\r
- * @access private\r
- */\r
- function _getPointY($x)\r
- {\r
- $functionY = $this->_functionY;\r
- return $functionY ($x);\r
- }\r
-\r
- /**\r
- * Reset the intertal dataset pointer\r
- *\r
- * @return var The first T value\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- $this->_posX = $this->_minimumT;\r
- return $this->_posX;\r
- }\r
-\r
- /**\r
- * The interval between 2 adjacent T values\r
- *\r
- * @return var The interval\r
- * @access private\r
- */\r
- function _stepX()\r
- {\r
- return ($this->_maximumT - $this->_minimumT) / $this->count();\r
- }\r
-\r
- /**\r
- * Calculates the X and Y extrema of the functions\r
- *\r
- * @access private\r
- */\r
- function _calculateMaxima()\r
- {\r
- $t = $this->_minimumT;\r
- while ($t <= $this->_maximumT) {\r
- $x = $this->_getPointX($t);\r
- $y = $this->_getPointY($t);\r
- $this->_minimumX = min($x, $this->_minimumX);\r
- $this->_maximumX = max($x, $this->_maximumX);\r
- $this->_minimumY = min($y, $this->_minimumY);\r
- $this->_maximumY = max($y, $this->_maximumY);\r
- $t += $this->_stepX();\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: VectorFunction.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Dataset.php
+ */
+require_once 'Image/Graph/Dataset.php';
+
+/**
+ * Vector Function data set.
+ *
+ * Points are generated by calling 2 external functions, fx. x = sin(t) and y =
+ * cos(t)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Dataset
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Dataset_VectorFunction extends Image_Graph_Dataset
+{
+
+ /**
+ * The name of the X function
+ * @var string
+ * @access private
+ */
+ var $_functionX;
+
+ /**
+ * The name of the Y function
+ * @var string
+ * @access private
+ */
+ var $_functionY;
+
+ /**
+ * The minimum of the vector function variable
+ * @var double
+ * @access private
+ */
+ var $_minimumT;
+
+ /**
+ * The maximum of the vector function variable
+ * @var double
+ * @access private
+ */
+ var $_maximumT;
+
+ /**
+ * Image_Graph_VectorFunctionDataset [Constructor]
+ *
+ * @param double $minimumT The minimum value of the vector function variable
+ * @param double $maximumT The maximum value of the vector function variable
+ * @param string $functionX The name of the X function, if must be a single
+ * parameter function like fx sin(x) or cos(x)
+ * @param string $functionY The name of the Y function, if must be a single
+ * parameter function like fx sin(x) or cos(x)
+ * @param int $points The number of points to create
+ */
+ function Image_Graph_Dataset_VectorFunction($minimumT, $maximumT, $functionX, $functionY, $points)
+ {
+ parent::__construct();
+ $this->_minimumT = $minimumT;
+ $this->_maximumT = $maximumT;
+ $this->_functionX = $functionX;
+ $this->_functionY = $functionY;
+ $this->_count = $points;
+ $this->_calculateMaxima();
+ }
+
+ /**
+ * Add a point to the dataset
+ *
+ * @param int $x The X value to add
+ * @param int $y The Y value to add, can be omited
+ * @param var $ID The ID of the point
+ *
+ * @return void
+ */
+ function addPoint($x, $y = false, $ID = false)
+ {
+ }
+
+ /**
+ * Gets a X point from the dataset
+ *
+ * @param var $x The variable to apply the X function to
+ *
+ * @return var The X function applied to the X value
+ * @access private
+ */
+ function _getPointX($x)
+ {
+ $functionX = $this->_functionX;
+ return $functionX ($x);
+ }
+
+ /**
+ * Gets a Y point from the dataset
+ *
+ * @param var $x The variable to apply the Y function to
+ *
+ * @return var The Y function applied to the X value
+ * @access private
+ */
+ function _getPointY($x)
+ {
+ $functionY = $this->_functionY;
+ return $functionY ($x);
+ }
+
+ /**
+ * Reset the intertal dataset pointer
+ *
+ * @return var The first T value
+ * @access private
+ */
+ function _reset()
+ {
+ $this->_posX = $this->_minimumT;
+ return $this->_posX;
+ }
+
+ /**
+ * The interval between 2 adjacent T values
+ *
+ * @return var The interval
+ * @access private
+ */
+ function _stepX()
+ {
+ return ($this->_maximumT - $this->_minimumT) / $this->count();
+ }
+
+ /**
+ * Calculates the X and Y extrema of the functions
+ *
+ * @return void
+ * @access private
+ */
+ function _calculateMaxima()
+ {
+ $t = $this->_minimumT;
+ while ($t <= $this->_maximumT) {
+ $x = $this->_getPointX($t);
+ $y = $this->_getPointY($t);
+ $this->_minimumX = min($x, $this->_minimumX);
+ $this->_maximumX = max($x, $this->_maximumX);
+ $this->_minimumY = min($y, $this->_minimumY);
+ $this->_maximumY = max($y, $this->_maximumY);
+ $t += $this->_stepX();
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Element.php,v 1.18 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Common.php\r
- */\r
-require_once 'Image/Graph/Common.php';\r
-\r
-/**\r
- * Representation of a element.\r
- *\r
- * The Image_Graph_Element can be drawn on the canvas, ie it has coordinates,\r
- * {@link Image_Graph_Line}, {@link Image_Graph_Fill}, border and background -\r
- * although not all of these may apply to all children.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Element extends Image_Graph_Common\r
-{\r
-\r
- /**\r
- * The leftmost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_left = 0;\r
-\r
- /**\r
- * The topmost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_top = 0;\r
-\r
- /**\r
- * The rightmost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_right = 0;\r
-\r
- /**\r
- * The bottommost pixel of the element on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_bottom = 0;\r
-\r
- /**\r
- * Background of the element. Default: None\r
- * @var FillStyle\r
- * @access private\r
- */\r
- var $_background = null;\r
-\r
- /**\r
- * Borderstyle of the element. Default: None\r
- * @var LineStyle\r
- * @access private\r
- */\r
- var $_borderStyle = null;\r
-\r
- /**\r
- * Line style of the element. Default: None\r
- * @var LineStyle\r
- * @access private\r
- */\r
- var $_lineStyle = 'black';\r
-\r
- /**\r
- * Fill style of the element. Default: None\r
- * @var FillStyle\r
- * @access private\r
- */\r
- var $_fillStyle = 'white';\r
-\r
- /**\r
- * Font of the element. Default: Standard font - FONT\r
- * @var Font\r
- * @access private\r
- * @see $IMAGE_GRAPH_FONT\r
- */\r
- var $_font = null;\r
-\r
- /**\r
- * Font options\r
- * @var array\r
- * @access private\r
- */\r
- var $_fontOptions = array();\r
-\r
- /**\r
- * Default font options\r
- * \r
- * This option is included for performance reasons. The value is calculated\r
- * before output and reused in default cases to avoid unnecessary recursive\r
- * calls.\r
- * \r
- * @var array\r
- * @access private\r
- */\r
- var $_defaultFontOptions = false;\r
-\r
- /**\r
- * Shadows options of the element\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_shadow = false;\r
-\r
- /**\r
- * The padding displayed on the element\r
- * @var int\r
- * @access private\r
- */\r
- var $_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);\r
-\r
- /**\r
- * Sets the background fill style of the element\r
- *\r
- * @param Image_Graph_Fill $background The background\r
- * @see Image_Graph_Fill\r
- */\r
- function setBackground(& $background)\r
- {\r
- if (!is_a($background, 'Image_Graph_Fill')) {\r
- $this->_error(\r
- 'Could not set background for ' . get_class($this) . ': ' .\r
- get_class($background), array('background' => &$background)\r
- );\r
- } else {\r
- $this->_background =& $background;\r
- $this->add($background);\r
- }\r
- }\r
-\r
- /**\r
- * Shows shadow on the element\r
- */\r
- function showShadow($color = 'black@0.2', $size = 5)\r
- {\r
- $this->_shadow = array(\r
- 'color' => $color,\r
- 'size' => $size\r
- );\r
- }\r
-\r
- /**\r
- * Sets the background color of the element.\r
- *\r
- * See colors.txt in the docs/ folder for a list of available named colors.\r
- *\r
- * @param mixed $color The color\r
- */\r
- function setBackgroundColor($color)\r
- {\r
- $this->_background = $color;\r
- }\r
-\r
- /**\r
- * Gets the background fill style of the element\r
- *\r
- * @return int A GD fillstyle representing the background style\r
- * @see Image_Graph_Fill\r
- * @access private\r
- */\r
- function _getBackground()\r
- {\r
- if (is_object($this->_background)) {\r
- $this->_canvas->setFill($this->_background->_getFillStyle());\r
- } elseif ($this->_background != null) {\r
- $this->_canvas->setFill($this->_background);\r
- } else {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Sets the border line style of the element\r
- *\r
- * @param Image_Graph_Line $borderStyle The line style of the border\r
- * @see Image_Graph_Line\r
- */\r
- function setBorderStyle(& $borderStyle)\r
- {\r
- if (!is_a($borderStyle, 'Image_Graph_Line')) {\r
- $this->_error(\r
- 'Could not set border style for ' . get_class($this) . ': ' .\r
- get_class($borderStyle), array('borderstyle' => &$borderStyle)\r
- );\r
- } else {\r
- $this->_borderStyle =& $borderStyle;\r
- $this->add($borderStyle);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the border color of the element.\r
- *\r
- * See colors.txt in the docs/ folder for a list of available named colors.\r
- * @param mixed $color The color\r
- */\r
- function setBorderColor($color)\r
- {\r
- $this->_borderStyle = $color;\r
- }\r
-\r
- /**\r
- * Gets the border line style of the element\r
- *\r
- * @return int A GD linestyle representing the borders line style\r
- * @see Image_Graph_Line\r
- * @access private\r
- */\r
- function _getBorderStyle()\r
- {\r
- if (is_object($this->_borderStyle)) {\r
- $result = $this->_borderStyle->_getLineStyle();\r
- $this->_canvas->setLineThickness($result['thickness']);\r
- $this->_canvas->setLineColor($result['color']);\r
- } elseif ($this->_borderStyle != null) {\r
- $this->_canvas->setLineThickness(1);\r
- $this->_canvas->setLineColor($this->_borderStyle);\r
- } else {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Sets the line style of the element\r
- *\r
- * @param Image_Graph_Line $lineStyle The line style of the element\r
- * @see Image_Graph_Line\r
- */\r
- function setLineStyle(& $lineStyle)\r
- {\r
- if (!is_object($lineStyle)) {\r
- $this->_error(\r
- 'Could not set line style for ' . get_class($this) . ': ' .\r
- get_class($lineStyle), array('linestyle' => &$lineStyle)\r
- );\r
- } else {\r
- $this->_lineStyle =& $lineStyle;\r
- $this->add($lineStyle);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the line color of the element.\r
- *\r
- * See colors.txt in the docs/ folder for a list of available named colors.\r
- *\r
- * @param mixed $color The color\r
- */\r
- function setLineColor($color)\r
- {\r
- $this->_lineStyle = $color;\r
- }\r
-\r
- /**\r
- * Gets the line style of the element\r
- *\r
- * @return int A GD linestyle representing the line style\r
- * @see Image_Graph_Line\r
- * @access private\r
- */\r
- function _getLineStyle($ID = false)\r
- {\r
- if (is_object($this->_lineStyle)) {\r
- $result = $this->_lineStyle->_getLineStyle($ID);\r
- if (is_array($result)) {\r
- $this->_canvas->setLineThickness($result['thickness']);\r
- $this->_canvas->setLineColor($result['color']);\r
- } else {\r
- $this->_canvas->setLineThickness(1);\r
- $this->_canvas->setLineColor($result);\r
- }\r
- } elseif ($this->_lineStyle != null) {\r
- $this->_canvas->setLineThickness(1);\r
- $this->_canvas->setLineColor($this->_lineStyle);\r
- } else {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Sets the fill style of the element\r
- *\r
- * @param Image_Graph_Fill $fillStyle The fill style of the element\r
- * @see Image_Graph_Fill\r
- */\r
- function setFillStyle(& $fillStyle)\r
- {\r
- if (!is_a($fillStyle, 'Image_Graph_Fill')) {\r
- $this->_error(\r
- 'Could not set fill style for ' . get_class($this) . ': ' .\r
- get_class($fillStyle), array('fillstyle' => &$fillStyle)\r
- );\r
- } else {\r
- $this->_fillStyle =& $fillStyle;\r
- $this->add($fillStyle);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the fill color of the element.\r
- *\r
- * See colors.txt in the docs/ folder for a list of available named colors.\r
- *\r
- * @param mixed $color The color\r
- */\r
- function setFillColor($color)\r
- {\r
- $this->_fillStyle = $color;\r
- }\r
-\r
-\r
- /**\r
- * Gets the fill style of the element\r
- *\r
- * @return int A GD filestyle representing the fill style\r
- * @see Image_Graph_Fill\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- if (is_object($this->_fillStyle)) {\r
- $this->_canvas->setFill($this->_fillStyle->_getFillStyle($ID));\r
- } elseif ($this->_fillStyle != null) {\r
- $this->_canvas->setFill($this->_fillStyle);\r
- } else {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Gets the font of the element.\r
- *\r
- * If not font has been set, the parent font is propagated through it's\r
- * children.\r
- *\r
- * @return array An associated array used for canvas\r
- * @access private\r
- */\r
- function _getFont($options = false)\r
- {\r
- if (($options === false) && ($this->_defaultFontOptions !== false)) {\r
- return $this->_defaultFontOptions;\r
- }\r
- \r
- if ($options === false) {\r
- $saveDefault = true;\r
- } else {\r
- $saveDefault = false;\r
- }\r
- \r
- if ($options === false) {\r
- $options = $this->_fontOptions;\r
- } else {\r
- $options = array_merge($this->_fontOptions, $options);\r
- }\r
-\r
- if ($this->_font == null) {\r
- $result = $this->_parent->_getFont($options);\r
- } else {\r
- $result = $this->_font->_getFont($options);\r
- }\r
-\r
- if ((isset($result['size'])) && (isset($result['size_rel']))) {\r
- $result['size'] += $result['size_rel'];\r
- unset($result['size_rel']);\r
- }\r
- \r
- if ($saveDefault) {\r
- $this->_defaultFontOptions = $result;\r
- }\r
- \r
- return $result;\r
- }\r
-\r
- /**\r
- * Sets the font of the element\r
- *\r
- * @param Image_Graph_Font $font The font of the element\r
- * @see Image_Graph_Font\r
- */\r
- function setFont(& $font)\r
- {\r
- if (!is_a($font, 'Image_Graph_Font')) {\r
- $this->_error('Invalid font set on ' . get_class($this));\r
- } else {\r
- $this->_font =& $font;\r
- $this->add($font);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the font size\r
- *\r
- * @param int $size The size of the font\r
- */\r
- function setFontSize($size)\r
- {\r
- $this->_fontOptions['size'] = $size;\r
- }\r
-\r
- /**\r
- * Sets the font angle\r
- *\r
- * @param int $angle The angle of the font\r
- */\r
- function setFontAngle($angle)\r
- {\r
- if ($angle == 'vertical') {\r
- $this->_fontOptions['vertical'] = true;\r
- $this->_fontOptions['angle'] = 90;\r
- } else {\r
- $this->_fontOptions['angle'] = $angle;\r
- }\r
- }\r
-\r
- /**\r
- * Sets the font color\r
- *\r
- * @param mixed $color The color of the font\r
- */\r
- function setFontColor($color)\r
- {\r
- $this->_fontOptions['color'] = $color;\r
- }\r
-\r
- /**\r
- * Clip the canvas to the coordinates of the element\r
- * \r
- * @param $enable bool Whether clipping should be enabled or disabled\r
- * @access protected\r
- */\r
- function _clip($enable)\r
- {\r
- $this->_canvas->setClipping(\r
- ($enable ?\r
- array(\r
- 'x0' => min($this->_left, $this->_right),\r
- 'y0' => min($this->_top, $this->_bottom),\r
- 'x1' => max($this->_left, $this->_right),\r
- 'y1' => max($this->_top, $this->_bottom)\r
- )\r
- : false\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * Sets the coordinates of the element\r
- *\r
- * @param int $left The leftmost pixel of the element on the canvas\r
- * @param int $top The topmost pixel of the element on the canvas\r
- * @param int $right The rightmost pixel of the element on the canvas\r
- * @param int $bottom The bottommost pixel of the element on the canvas\r
- * @access private\r
- */\r
- function _setCoords($left, $top, $right, $bottom)\r
- {\r
- if ($left === false) {\r
- $left = $this->_left;\r
- }\r
- \r
- if ($top === false) {\r
- $top = $this->_top;\r
- }\r
-\r
- if ($right === false) {\r
- $right = $this->_right;\r
- }\r
- \r
- if ($bottom === false) {\r
- $bottom = $this->_bottom;\r
- }\r
- \r
- $this->_left = min($left, $right);\r
- $this->_top = min($top, $bottom);\r
- $this->_right = max($left, $right);\r
- $this->_bottom = max($top, $bottom); \r
- }\r
-\r
- /**\r
- * Moves the element\r
- *\r
- * @param int $deltaX Number of pixels to move the element to the right\r
- * (negative values move to the left)\r
- * @param int $deltaY Number of pixels to move the element downwards\r
- * (negative values move upwards)\r
- * @access private\r
- */\r
- function _move($deltaX, $deltaY)\r
- {\r
- $this->_left += $deltaX;\r
- $this->_right += $deltaX;\r
- $this->_top += $deltaY;\r
- $this->_bottom += $deltaY;\r
- }\r
-\r
- /**\r
- * Sets the width of the element relative to the left side\r
- *\r
- * @param int $width Number of pixels the element should be in width\r
- * @access private\r
- */\r
- function _setWidth($width)\r
- {\r
- $this->_right = $this->_left + $width;\r
- }\r
-\r
- /**\r
- * Sets the height of the element relative to the top\r
- *\r
- * @param int $width Number of pixels the element should be in height\r
- * @access private\r
- */\r
- function _setHeight($height)\r
- {\r
- $this->_bottom = $this->_top + $height;\r
- }\r
-\r
- /**\r
- * Sets padding of the element\r
- *\r
- * @param mixed $padding Number of pixels the element should be padded with\r
- * or an array of paddings (left, top, right and bottom as index)\r
- */\r
- function setPadding($padding)\r
- {\r
- if (is_array($padding)) {\r
- $this->_padding = array();\r
- $this->_padding['left'] = (isset($padding['left']) ? $padding['left'] : 0); \r
- $this->_padding['top'] = (isset($padding['top']) ? $padding['top'] : 0); \r
- $this->_padding['right'] = (isset($padding['right']) ? $padding['right'] : 0); \r
- $this->_padding['bottom'] = (isset($padding['bottom']) ? $padding['bottom'] : 0); \r
- }\r
- else {\r
- $this->_padding = array(\r
- 'left' => $padding,\r
- 'top' => $padding,\r
- 'right' => $padding,\r
- 'bottom' => $padding\r
- );\r
- }\r
- }\r
-\r
- /**\r
- * The width of the element on the canvas\r
- *\r
- * @return int Number of pixels representing the width of the element\r
- */\r
- function width()\r
- {\r
- return abs($this->_right - $this->_left) + 1;\r
- }\r
-\r
- /**\r
- * The height of the element on the canvas\r
- *\r
- * @return int Number of pixels representing the height of the element\r
- */\r
- function height()\r
- {\r
- return abs($this->_bottom - $this->_top) + 1;\r
- }\r
-\r
- /**\r
- * Left boundary of the background fill area\r
- *\r
- * @return int Leftmost position on the canvas\r
- * @access private\r
- */\r
- function _fillLeft()\r
- {\r
- return $this->_left + $this->_padding['left'];\r
- }\r
-\r
- /**\r
- * Top boundary of the background fill area\r
- *\r
- * @return int Topmost position on the canvas\r
- * @access private\r
- */\r
- function _fillTop()\r
- {\r
- return $this->_top + $this->_padding['top'];\r
- }\r
-\r
- /**\r
- * Right boundary of the background fill area\r
- *\r
- * @return int Rightmost position on the canvas\r
- * @access private\r
- */\r
- function _fillRight()\r
- {\r
- return $this->_right - $this->_padding['right'];\r
- }\r
-\r
- /**\r
- * Bottom boundary of the background fill area\r
- *\r
- * @return int Bottommost position on the canvas\r
- * @access private\r
- */\r
- function _fillBottom()\r
- {\r
- return $this->_bottom - $this->_padding['bottom'];\r
- }\r
-\r
- /**\r
- * Returns the filling width of the element on the canvas\r
- *\r
- * @return int Filling width\r
- * @access private\r
- */\r
- function _fillWidth()\r
- {\r
- return $this->_fillRight() - $this->_fillLeft() + 1;\r
- }\r
-\r
- /**\r
- * Returns the filling height of the element on the canvas\r
- *\r
- * @return int Filling height\r
- * @access private\r
- */\r
- function _fillHeight()\r
- {\r
- return $this->_fillBottom() - $this->_fillTop() + 1;\r
- }\r
-\r
- /**\r
- * Draws a shadow 'around' the element\r
- * \r
- * Not implemented yet.\r
- *\r
- * @access private\r
- */\r
- function _displayShadow()\r
- { \r
- if (is_array($this->_shadow)) {\r
- $this->_canvas->startGroup(get_class($this) . '_shadow');\r
- $this->_canvas->setFillColor($this->_shadow['color']); \r
- $this->_canvas->addVertex(array('x' => $this->_right + 1, 'y' => $this->_top + $this->_shadow['size']));\r
- $this->_canvas->addVertex(array('x' => $this->_right + $this->_shadow['size'], 'y' => $this->_top + $this->_shadow['size']));\r
- $this->_canvas->addVertex(array('x' => $this->_right + $this->_shadow['size'], 'y' => $this->_bottom + $this->_shadow['size']));\r
- $this->_canvas->addVertex(array('x' => $this->_left + $this->_shadow['size'], 'y' => $this->_bottom + $this->_shadow['size']));\r
- $this->_canvas->addVertex(array('x' => $this->_left + $this->_shadow['size'], 'y' => $this->_bottom + 1));\r
- $this->_canvas->addVertex(array('x' => $this->_right + 1, 'y' => $this->_bottom + 1));\r
- $this->_canvas->polygon(array('connect' => true)); \r
- $this->_canvas->endGroup();\r
- }\r
- }\r
-\r
- /**\r
- * Writes text to the canvas.\r
- *\r
- * @param int $x The x position relative to alignment\r
- * @param int $y The y position relative to alignment\r
- * @param string $text The text\r
- * @param int $alignmen The text alignment (both vertically and horizontally)\r
- */\r
- function write($x, $y, $text, $alignment = false, $font = false)\r
- {\r
- if (($font === false) && ($this->_defaultFontOptions !== false)) {\r
- $font = $this->_defaultFontOptions;\r
- } else {\r
- $font = $this->_getFont($font);\r
- }\r
-\r
- if ($alignment === false) {\r
- $alignment = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_TOP;\r
- }\r
- \r
- $align = array(); \r
- \r
- if (($alignment & IMAGE_GRAPH_ALIGN_TOP) != 0) {\r
- $align['vertical'] = 'top';\r
- } else if (($alignment & IMAGE_GRAPH_ALIGN_BOTTOM) != 0) { \r
- $align['vertical'] = 'bottom';\r
- } else {\r
- $align['vertical'] = 'center';\r
- }\r
-\r
- if (($alignment & IMAGE_GRAPH_ALIGN_LEFT) != 0) {\r
- $align['horizontal'] = 'left';\r
- } else if (($alignment & IMAGE_GRAPH_ALIGN_RIGHT) != 0) { \r
- $align['horizontal'] = 'right';\r
- } else {\r
- $align['horizontal'] = 'center';\r
- }\r
-\r
- $this->_canvas->setFont($font);\r
- $this->_canvas->addText(array('x' => $x, 'y' => $y, 'text' => $text, 'alignment' => $align));\r
- }\r
-\r
- /**\r
- * Output the element to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @see Image_Graph_Common\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $background = $this->_getBackground();\r
- $border = $this->_getBorderStyle();\r
- if (($background) || ($border)) {\r
- $this->_canvas->rectangle(array('x0' => $this->_left, 'y0' => $this->_top, 'x1' => $this->_right, 'y1' => $this->_bottom));\r
- }\r
-\r
- $result = parent::_done();\r
- \r
- if ($this->_shadow !== false) {\r
- $this->_displayShadow();\r
- }\r
-\r
- return $result;\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Element.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Common.php
+ */
+require_once 'Image/Graph/Common.php';
+
+/**
+ * Representation of a element.
+ *
+ * The Image_Graph_Element can be drawn on the canvas, ie it has coordinates,
+ * {@link Image_Graph_Line}, {@link Image_Graph_Fill}, border and background -
+ * although not all of these may apply to all children.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Element extends Image_Graph_Common
+{
+
+ /**
+ * The leftmost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_left = 0;
+
+ /**
+ * The topmost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_top = 0;
+
+ /**
+ * The rightmost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_right = 0;
+
+ /**
+ * The bottommost pixel of the element on the canvas
+ * @var int
+ * @access private
+ */
+ var $_bottom = 0;
+
+ /**
+ * Background of the element. Default: None
+ * @var FillStyle
+ * @access private
+ */
+ var $_background = null;
+
+ /**
+ * Borderstyle of the element. Default: None
+ * @var LineStyle
+ * @access private
+ */
+ var $_borderStyle = null;
+
+ /**
+ * Line style of the element. Default: None
+ * @var LineStyle
+ * @access private
+ */
+ var $_lineStyle = 'black';
+
+ /**
+ * Fill style of the element. Default: None
+ * @var FillStyle
+ * @access private
+ */
+ var $_fillStyle = 'white';
+
+ /**
+ * Font of the element. Default: Standard font - FONT
+ * @var Font
+ * @access private
+ * @see $IMAGE_GRAPH_FONT
+ */
+ var $_font = null;
+
+ /**
+ * Font options
+ * @var array
+ * @access private
+ */
+ var $_fontOptions = array();
+
+ /**
+ * Default font options
+ *
+ * This option is included for performance reasons. The value is calculated
+ * before output and reused in default cases to avoid unnecessary recursive
+ * calls.
+ *
+ * @var array
+ * @access private
+ */
+ var $_defaultFontOptions = false;
+
+ /**
+ * Shadows options of the element
+ * @var mixed
+ * @access private
+ */
+ var $_shadow = false;
+
+ /**
+ * The padding displayed on the element
+ * @var int
+ * @access private
+ */
+ var $_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
+
+ /**
+ * Sets the background fill style of the element
+ *
+ * @param Image_Graph_Fill &$background The background
+ *
+ * @return void
+ * @see Image_Graph_Fill
+ */
+ function setBackground(&$background)
+ {
+ if (!is_a($background, 'Image_Graph_Fill')) {
+ $this->_error(
+ 'Could not set background for ' . get_class($this) . ': ' .
+ get_class($background), array('background' => &$background)
+ );
+ } else {
+ $this->_background =& $background;
+ $this->add($background);
+ }
+ }
+
+ /**
+ * Shows shadow on the element
+ *
+ * @param string $color Shadow color
+ * @param int $size Shadow size
+ *
+ * @return void
+ */
+ function showShadow($color = 'black@0.2', $size = 5)
+ {
+ $this->_shadow = array(
+ 'color' => $color,
+ 'size' => $size
+ );
+ }
+
+ /**
+ * Sets the background color of the element.
+ *
+ * See colors.txt in the docs/ folder for a list of available named colors.
+ *
+ * @param mixed $color The color
+ *
+ * @return void
+ */
+ function setBackgroundColor($color)
+ {
+ $this->_background = $color;
+ }
+
+ /**
+ * Gets the background fill style of the element
+ *
+ * @return int A GD fillstyle representing the background style
+ * @see Image_Graph_Fill
+ * @access private
+ */
+ function _getBackground()
+ {
+ if (is_object($this->_background)) {
+ $this->_canvas->setFill($this->_background->_getFillStyle());
+ } elseif ($this->_background != null) {
+ $this->_canvas->setFill($this->_background);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sets the border line style of the element
+ *
+ * @param Image_Graph_Line &$borderStyle The line style of the border
+ *
+ * @return void
+ * @see Image_Graph_Line
+ */
+ function setBorderStyle(&$borderStyle)
+ {
+ if (!is_a($borderStyle, 'Image_Graph_Line')) {
+ $this->_error(
+ 'Could not set border style for ' . get_class($this) . ': ' .
+ get_class($borderStyle), array('borderstyle' => &$borderStyle)
+ );
+ } else {
+ $this->_borderStyle =& $borderStyle;
+ $this->add($borderStyle);
+ }
+ }
+
+ /**
+ * Sets the border color of the element.
+ *
+ * See colors.txt in the docs/ folder for a list of available named colors.
+ *
+ * @param mixed $color The color
+ *
+ * @return void
+ */
+ function setBorderColor($color)
+ {
+ $this->_borderStyle = $color;
+ }
+
+ /**
+ * Gets the border line style of the element
+ *
+ * @return int A GD linestyle representing the borders line style
+ * @see Image_Graph_Line
+ * @access private
+ */
+ function _getBorderStyle()
+ {
+ if (is_object($this->_borderStyle)) {
+ $result = $this->_borderStyle->_getLineStyle();
+ $this->_canvas->setLineThickness($result['thickness']);
+ $this->_canvas->setLineColor($result['color']);
+ } elseif ($this->_borderStyle != null) {
+ $this->_canvas->setLineThickness(1);
+ $this->_canvas->setLineColor($this->_borderStyle);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sets the line style of the element
+ *
+ * @param Image_Graph_Line &$lineStyle The line style of the element
+ *
+ * @return void
+ * @see Image_Graph_Line
+ */
+ function setLineStyle(& $lineStyle)
+ {
+ if (!is_object($lineStyle)) {
+ $this->_error(
+ 'Could not set line style for ' . get_class($this) . ': ' .
+ get_class($lineStyle), array('linestyle' => &$lineStyle)
+ );
+ } else {
+ $this->_lineStyle =& $lineStyle;
+ $this->add($lineStyle);
+ }
+ }
+
+ /**
+ * Sets the line color of the element.
+ *
+ * See colors.txt in the docs/ folder for a list of available named colors.
+ *
+ * @param mixed $color The color
+ *
+ * @return void
+ */
+ function setLineColor($color)
+ {
+ $this->_lineStyle = $color;
+ }
+
+ /**
+ * Gets the line style of the element
+ *
+ * @param int $ID Style ID
+ *
+ * @return int A GD linestyle representing the line style
+ * @see Image_Graph_Line
+ * @access private
+ */
+ function _getLineStyle($ID = false)
+ {
+ if (is_object($this->_lineStyle)) {
+ $result = $this->_lineStyle->_getLineStyle($ID);
+ if (is_array($result)) {
+ $this->_canvas->setLineThickness($result['thickness']);
+ $this->_canvas->setLineColor($result['color']);
+ } else {
+ $this->_canvas->setLineThickness(1);
+ $this->_canvas->setLineColor($result);
+ }
+ } elseif ($this->_lineStyle != null) {
+ $this->_canvas->setLineThickness(1);
+ $this->_canvas->setLineColor($this->_lineStyle);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Sets the fill style of the element
+ *
+ * @param Image_Graph_Fill &$fillStyle The fill style of the element
+ *
+ * @return void
+ * @see Image_Graph_Fill
+ */
+ function setFillStyle(& $fillStyle)
+ {
+ if (!is_a($fillStyle, 'Image_Graph_Fill')) {
+ $this->_error(
+ 'Could not set fill style for ' . get_class($this) . ': ' .
+ get_class($fillStyle), array('fillstyle' => &$fillStyle)
+ );
+ } else {
+ $this->_fillStyle =& $fillStyle;
+ $this->add($fillStyle);
+ }
+ }
+
+ /**
+ * Sets the fill color of the element.
+ *
+ * See colors.txt in the docs/ folder for a list of available named colors.
+ *
+ * @param mixed $color The color
+ *
+ * @return void
+ */
+ function setFillColor($color)
+ {
+ $this->_fillStyle = $color;
+ }
+
+
+ /**
+ * Gets the fill style of the element
+ *
+ * @param int $ID Fill style ID
+ *
+ * @return int A GD filestyle representing the fill style
+ * @see Image_Graph_Fill
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ if (is_object($this->_fillStyle)) {
+ $this->_canvas->setFill($this->_fillStyle->_getFillStyle($ID));
+ } elseif ($this->_fillStyle != null) {
+ $this->_canvas->setFill($this->_fillStyle);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Gets the font of the element.
+ *
+ * If not font has been set, the parent font is propagated through it's
+ * children.
+ *
+ * @param array $options Font options
+ *
+ * @return array An associated array used for canvas
+ * @access private
+ */
+ function _getFont($options = false)
+ {
+ if (($options === false) && ($this->_defaultFontOptions !== false)) {
+ return $this->_defaultFontOptions;
+ }
+
+ if ($options === false) {
+ $saveDefault = true;
+ } else {
+ $saveDefault = false;
+ }
+
+ if ($options === false) {
+ $options = $this->_fontOptions;
+ } else {
+ $options = array_merge($this->_fontOptions, $options);
+ }
+
+ if ($this->_font == null) {
+ $result = $this->_parent->_getFont($options);
+ } else {
+ $result = $this->_font->_getFont($options);
+ }
+
+ if ((isset($result['size'])) && (isset($result['size_rel']))) {
+ $result['size'] += $result['size_rel'];
+ unset($result['size_rel']);
+ }
+
+ if ($saveDefault) {
+ $this->_defaultFontOptions = $result;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Sets the font of the element
+ *
+ * @param Image_Graph_Font &$font The font of the element
+ *
+ * @return void
+ * @see Image_Graph_Font
+ */
+ function setFont(& $font)
+ {
+ if (!is_a($font, 'Image_Graph_Font')) {
+ $this->_error('Invalid font set on ' . get_class($this));
+ } else {
+ $this->_font =& $font;
+ $this->add($font);
+ }
+ }
+
+ /**
+ * Sets the font size
+ *
+ * @param int $size The size of the font
+ *
+ * @return void
+ */
+ function setFontSize($size)
+ {
+ $this->_fontOptions['size'] = $size;
+ }
+
+ /**
+ * Sets the font angle
+ *
+ * @param int $angle The angle of the font
+ *
+ * @return void
+ */
+ function setFontAngle($angle)
+ {
+ if ($angle == 'vertical') {
+ $this->_fontOptions['vertical'] = true;
+ $this->_fontOptions['angle'] = 90;
+ } else {
+ $this->_fontOptions['angle'] = $angle;
+ }
+ }
+
+ /**
+ * Sets the font color
+ *
+ * @param mixed $color The color of the font
+ *
+ * @return void
+ */
+ function setFontColor($color)
+ {
+ $this->_fontOptions['color'] = $color;
+ }
+
+ /**
+ * Clip the canvas to the coordinates of the element
+ *
+ * @param bool $enable Whether clipping should be enabled or disabled
+ *
+ * @return void
+ * @access protected
+ */
+ function _clip($enable)
+ {
+ $this->_canvas->setClipping(
+ ($enable ?
+ array(
+ 'x0' => min($this->_left, $this->_right),
+ 'y0' => min($this->_top, $this->_bottom),
+ 'x1' => max($this->_left, $this->_right),
+ 'y1' => max($this->_top, $this->_bottom)
+ )
+ : false
+ )
+ );
+ }
+
+ /**
+ * Sets the coordinates of the element
+ *
+ * @param int $left The leftmost pixel of the element on the canvas
+ * @param int $top The topmost pixel of the element on the canvas
+ * @param int $right The rightmost pixel of the element on the canvas
+ * @param int $bottom The bottommost pixel of the element on the canvas
+ *
+ * @return void
+ * @access private
+ */
+ function _setCoords($left, $top, $right, $bottom)
+ {
+ if ($left === false) {
+ $left = $this->_left;
+ }
+
+ if ($top === false) {
+ $top = $this->_top;
+ }
+
+ if ($right === false) {
+ $right = $this->_right;
+ }
+
+ if ($bottom === false) {
+ $bottom = $this->_bottom;
+ }
+
+ $this->_left = min($left, $right);
+ $this->_top = min($top, $bottom);
+ $this->_right = max($left, $right);
+ $this->_bottom = max($top, $bottom);
+ }
+
+ /**
+ * Moves the element
+ *
+ * @param int $deltaX Number of pixels to move the element to the right
+ * (negative values move to the left)
+ * @param int $deltaY Number of pixels to move the element downwards
+ * (negative values move upwards)
+ *
+ * @return void
+ * @access private
+ */
+ function _move($deltaX, $deltaY)
+ {
+ $this->_left += $deltaX;
+ $this->_right += $deltaX;
+ $this->_top += $deltaY;
+ $this->_bottom += $deltaY;
+ }
+
+ /**
+ * Sets the width of the element relative to the left side
+ *
+ * @param int $width Number of pixels the element should be in width
+ *
+ * @return void
+ * @access private
+ */
+ function _setWidth($width)
+ {
+ $this->_right = $this->_left + $width;
+ }
+
+ /**
+ * Sets the height of the element relative to the top
+ *
+ * @param int $height Number of pixels the element should be in height
+ *
+ * @return void
+ * @access private
+ */
+ function _setHeight($height)
+ {
+ $this->_bottom = $this->_top + $height;
+ }
+
+ /**
+ * Sets padding of the element
+ *
+ * @param mixed $padding Number of pixels the element should be padded with
+ * or an array of paddings (left, top, right and bottom as index)
+ *
+ * @return void
+ */
+ function setPadding($padding)
+ {
+ if (is_array($padding)) {
+ $this->_padding = array();
+ $this->_padding['left'] = (isset($padding['left']) ? $padding['left'] : 0);
+ $this->_padding['top'] = (isset($padding['top']) ? $padding['top'] : 0);
+ $this->_padding['right'] = (isset($padding['right']) ? $padding['right'] : 0);
+ $this->_padding['bottom'] = (isset($padding['bottom']) ? $padding['bottom'] : 0);
+ } else {
+ $this->_padding = array(
+ 'left' => $padding,
+ 'top' => $padding,
+ 'right' => $padding,
+ 'bottom' => $padding
+ );
+ }
+ }
+
+ /**
+ * The width of the element on the canvas
+ *
+ * @return int Number of pixels representing the width of the element
+ */
+ function width()
+ {
+ return abs($this->_right - $this->_left) + 1;
+ }
+
+ /**
+ * The height of the element on the canvas
+ *
+ * @return int Number of pixels representing the height of the element
+ */
+ function height()
+ {
+ return abs($this->_bottom - $this->_top) + 1;
+ }
+
+ /**
+ * Left boundary of the background fill area
+ *
+ * @return int Leftmost position on the canvas
+ * @access private
+ */
+ function _fillLeft()
+ {
+ return $this->_left + $this->_padding['left'];
+ }
+
+ /**
+ * Top boundary of the background fill area
+ *
+ * @return int Topmost position on the canvas
+ * @access private
+ */
+ function _fillTop()
+ {
+ return $this->_top + $this->_padding['top'];
+ }
+
+ /**
+ * Right boundary of the background fill area
+ *
+ * @return int Rightmost position on the canvas
+ * @access private
+ */
+ function _fillRight()
+ {
+ return $this->_right - $this->_padding['right'];
+ }
+
+ /**
+ * Bottom boundary of the background fill area
+ *
+ * @return int Bottommost position on the canvas
+ * @access private
+ */
+ function _fillBottom()
+ {
+ return $this->_bottom - $this->_padding['bottom'];
+ }
+
+ /**
+ * Returns the filling width of the element on the canvas
+ *
+ * @return int Filling width
+ * @access private
+ */
+ function _fillWidth()
+ {
+ return $this->_fillRight() - $this->_fillLeft() + 1;
+ }
+
+ /**
+ * Returns the filling height of the element on the canvas
+ *
+ * @return int Filling height
+ * @access private
+ */
+ function _fillHeight()
+ {
+ return $this->_fillBottom() - $this->_fillTop() + 1;
+ }
+
+ /**
+ * Draws a shadow 'around' the element
+ *
+ * Not implemented yet. (???)
+ *
+ * @return void
+ * @access private
+ */
+ function _displayShadow()
+ {
+ if (is_array($this->_shadow)) {
+ $this->_canvas->startGroup(get_class($this) . '_shadow');
+ $this->_canvas->setFillColor($this->_shadow['color']);
+ $this->_canvas->addVertex(array('x' => $this->_right + 1, 'y' => $this->_top + $this->_shadow['size']));
+ $this->_canvas->addVertex(array('x' => $this->_right + $this->_shadow['size'], 'y' => $this->_top + $this->_shadow['size']));
+ $this->_canvas->addVertex(array('x' => $this->_right + $this->_shadow['size'], 'y' => $this->_bottom + $this->_shadow['size']));
+ $this->_canvas->addVertex(array('x' => $this->_left + $this->_shadow['size'], 'y' => $this->_bottom + $this->_shadow['size']));
+ $this->_canvas->addVertex(array('x' => $this->_left + $this->_shadow['size'], 'y' => $this->_bottom + 1));
+ $this->_canvas->addVertex(array('x' => $this->_right + 1, 'y' => $this->_bottom + 1));
+ $this->_canvas->polygon(array('connect' => true));
+ $this->_canvas->endGroup();
+ }
+ }
+
+ /**
+ * Writes text to the canvas.
+ *
+ * @param int $x The x position relative to alignment
+ * @param int $y The y position relative to alignment
+ * @param string $text The text
+ * @param int $alignment The text alignment (both vertically and horizontally)
+ * @param ??? $font The font to use
+ *
+ * @return void
+ */
+ function write($x, $y, $text, $alignment = false, $font = false)
+ {
+ if (($font === false) && ($this->_defaultFontOptions !== false)) {
+ $font = $this->_defaultFontOptions;
+ } else {
+ $font = $this->_getFont($font);
+ }
+
+ if ($alignment === false) {
+ $alignment = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_TOP;
+ }
+
+ $align = array();
+
+ if (($alignment & IMAGE_GRAPH_ALIGN_TOP) != 0) {
+ $align['vertical'] = 'top';
+ } else if (($alignment & IMAGE_GRAPH_ALIGN_BOTTOM) != 0) {
+ $align['vertical'] = 'bottom';
+ } else {
+ $align['vertical'] = 'center';
+ }
+
+ if (($alignment & IMAGE_GRAPH_ALIGN_LEFT) != 0) {
+ $align['horizontal'] = 'left';
+ } else if (($alignment & IMAGE_GRAPH_ALIGN_RIGHT) != 0) {
+ $align['horizontal'] = 'right';
+ } else {
+ $align['horizontal'] = 'center';
+ }
+
+ $this->_canvas->setFont($font);
+ $this->_canvas->addText(array('x' => $x, 'y' => $y, 'text' => $text, 'alignment' => $align));
+ }
+
+ /**
+ * Output the element to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @see Image_Graph_Common
+ * @access private
+ */
+ function _done()
+ {
+ $background = $this->_getBackground();
+ $border = $this->_getBorderStyle();
+ if (($background) || ($border)) {
+ $this->_canvas->rectangle(array('x0' => $this->_left, 'y0' => $this->_top, 'x1' => $this->_right, 'y1' => $this->_bottom));
+ }
+
+ $result = parent::_done();
+
+ if ($this->_shadow !== false) {
+ $this->_displayShadow();
+ }
+
+ return $result;
+ }
+
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Circle.php,v 1.6 2005/08/24 20:36:01 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Figure/Ellipse.php\r
- */\r
-require_once 'Image/Graph/Figure/Ellipse.php';\r
-\r
-/**\r
- * Circle to draw on the canvas\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Figure_Circle extends Image_Graph_Figure_Ellipse\r
-{\r
-\r
- /**\r
- * Image_Graph_Circle [Constructor]\r
- *\r
- * @param int $x The center pixel of the circle on the canvas\r
- * @param int $y The center pixel of the circle on the canvas\r
- * @param int $radius The radius in pixels of the circle\r
- */\r
- function Image_Graph_Figure_Circle($x, $y, $radius)\r
- {\r
- parent::Image_Graph_Ellipse($x, $y, $radius, $radius);\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Circle.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Figure/Ellipse.php
+ */
+require_once 'Image/Graph/Figure/Ellipse.php';
+
+/**
+ * Circle to draw on the canvas
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Figure_Circle extends Image_Graph_Figure_Ellipse
+{
+
+ /**
+ * Image_Graph_Circle [Constructor]
+ *
+ * @param int $x The center pixel of the circle on the canvas
+ * @param int $y The center pixel of the circle on the canvas
+ * @param int $radius The radius in pixels of the circle
+ */
+ function Image_Graph_Figure_Circle($x, $y, $radius)
+ {
+ parent::__construct($x, $y, $radius, $radius);
+ }
+
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Ellipse.php,v 1.9 2005/08/24 20:36:00 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Ellipse to draw on the canvas\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Figure_Ellipse extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * Ellipse [Constructor]\r
- *\r
- * @param int $x The center pixel of the ellipse on the canvas\r
- * @param int $y The center pixel of the ellipse on the canvas\r
- * @param int $radiusX The width in pixels of the box on the canvas\r
- * @param int $radiusY The height in pixels of the box on the canvas\r
- */\r
- function Image_Graph_Figure_Ellipse($x, $y, $radiusX, $radiusY)\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_setCoords($x - $radiusX, $y - $radiusY, $x + $radiusX, $y + $radiusY);\r
- }\r
-\r
- /**\r
- * Output the ellipse\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this));\r
-\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->ellipse(\r
- array(\r
- 'x' => ($this->_left + $this->_right) / 2,\r
- 'y' => ($this->_top + $this->_bottom) / 2,\r
- 'rx' => $this->width(),\r
- 'ry' => $this->height()\r
- )\r
- );\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Ellipse.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Ellipse to draw on the canvas
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Figure_Ellipse extends Image_Graph_Element
+{
+
+ /**
+ * Ellipse [Constructor]
+ *
+ * @param int $x The center pixel of the ellipse on the canvas
+ * @param int $y The center pixel of the ellipse on the canvas
+ * @param int $radiusX The width in pixels of the box on the canvas
+ * @param int $radiusY The height in pixels of the box on the canvas
+ */
+ function Image_Graph_Figure_Ellipse($x, $y, $radiusX, $radiusY)
+ {
+ parent::__construct();
+ $this->_setCoords($x - $radiusX, $y - $radiusY, $x + $radiusX, $y + $radiusY);
+ }
+
+ /**
+ * Output the ellipse
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->ellipse(
+ array(
+ 'x' => ($this->_left + $this->_right) / 2,
+ 'y' => ($this->_top + $this->_bottom) / 2,
+ 'rx' => $this->width(),
+ 'ry' => $this->height()
+ )
+ );
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Polygon.php,v 1.8 2005/08/03 21:21:57 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Polygon to draw on the canvas\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Figure_Polygon extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * Polygon vertices\r
- *\r
- * @var array\r
- * @access private\r
- */\r
- var $_polygon = array ();\r
-\r
- /**\r
- * Add a vertex to the polygon\r
- *\r
- * @param int $x X-coordinate\r
- * @param int $y Y-coordinate\r
- */\r
- function addVertex($x, $y)\r
- {\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
-\r
- /**\r
- * Output the polygon\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->polygon(array('connect' => true));\r
- \r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Polygon.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Polygon to draw on the canvas
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Figure_Polygon extends Image_Graph_Element
+{
+
+ /**
+ * Polygon vertices
+ *
+ * @var array
+ * @access private
+ */
+ var $_polygon = array ();
+
+ /**
+ * Add a vertex to the polygon
+ *
+ * @param int $x X-coordinate
+ * @param int $y Y-coordinate
+ *
+ * @return void
+ */
+ function addVertex($x, $y)
+ {
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+
+ /**
+ * Output the polygon
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->polygon(array('connect' => true));
+
+ $this->_canvas->endGroup();
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Rectangle.php,v 1.9 2005/08/24 20:36:01 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Rectangle to draw on the canvas\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Figure\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Figure_Rectangle extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * Rectangle [Construcor]\r
- *\r
- * @param int $x The leftmost pixel of the box on the canvas\r
- * @param int $y The topmost pixel of the box on the canvas\r
- * @param int $width The width in pixels of the box on the canvas\r
- * @param int $height The height in pixels of the box on the canvas\r
- */\r
- function Image_Graph_Figure_Rectangle($x, $y, $width, $height)\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_setCoords($x, $y, $x + $width, $y + $height);\r
- }\r
-\r
- /**\r
- * Output the box\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_bottom\r
- )\r
- );\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Rectangle.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Rectangle to draw on the canvas
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Figure
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Figure_Rectangle extends Image_Graph_Element
+{
+
+ /**
+ * Rectangle [Construcor]
+ *
+ * @param int $x The leftmost pixel of the box on the canvas
+ * @param int $y The topmost pixel of the box on the canvas
+ * @param int $width The width in pixels of the box on the canvas
+ * @param int $height The height in pixels of the box on the canvas
+ */
+ function Image_Graph_Figure_Rectangle($x, $y, $width, $height)
+ {
+ parent::__construct();
+ $this->_setCoords($x, $y, $x + $width, $y + $height);
+ }
+
+ /**
+ * Output the box
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_bottom
+ )
+ );
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Fill.php,v 1.6 2005/02/21 20:49:46 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Style used for filling elements.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Fill extends Image_Graph_Common\r
-{\r
-\r
- /**\r
- * Resets the fillstyle\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Fill.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Style used for filling elements.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Fill extends Image_Graph_Common
+{
+
+ /**
+ * Resets the fillstyle
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Array.php,v 1.8 2005/08/24 20:36:03 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Fill.php\r
- */\r
-require_once 'Image/Graph/Fill.php';\r
-\r
-/**\r
- * A sequential array of fillstyles.\r
- *\r
- * This is used for filling multiple objects within the same element with\r
- * different styles. This is done by adding multiple fillstyles to a FillArrray\r
- * structure. The fillarray will then when requested return the 'next' fillstyle\r
- * in sequential order. It is possible to specify ID tags to each fillstyle,\r
- * which is used to make sure some data uses a specific fillstyle (i.e. in a\r
- * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses\r
- * this name as ID tag when adding the dataset's associated fillstyle to the\r
- * fillarray.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Fill_Array extends Image_Graph_Fill\r
-{\r
-\r
- /**\r
- * The fill array\r
- * @var array\r
- * @access private\r
- */\r
- var $_fillStyles = array ();\r
-\r
- /**\r
- * Resets the fillstyle\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- reset($this->_fillStyles);\r
- }\r
-\r
- /**\r
- * Add a fill style to the array\r
- *\r
- * @param Image_Graph_Fill $style The style to add\r
- * @param string $id The id or name of the style\r
- */\r
- function &add(& $style, $id = '')\r
- {\r
- if ($id == '') {\r
- $this->_fillStyles[] =& $style;\r
- } else {\r
- $this->_fillStyles[$id] =& $style;\r
- }\r
- reset($this->_fillStyles);\r
- return $style;\r
- }\r
-\r
- /**\r
- * Add a color to the array\r
- *\r
- * @param int $color The color\r
- * @param string $id The id or name of the color\r
- */\r
- function addColor($color, $id = false)\r
- {\r
- if ($id !== false) {\r
- $this->_fillStyles[$id] = $color;\r
- } else {\r
- $this->_fillStyles[] = $color;\r
- }\r
- reset($this->_fillStyles);\r
- }\r
-\r
- /**\r
- * Return the fillstyle\r
- *\r
- * @return int A GD fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- if (($ID === false) || (!isset($this->_fillStyles[$ID]))) {\r
- $ID = key($this->_fillStyles);\r
- if (!next($this->_fillStyles)) {\r
- reset($this->_fillStyles);\r
- }\r
- }\r
- $fillStyle =& $this->_fillStyles[$ID];\r
-\r
- if (is_object($fillStyle)) {\r
- return $fillStyle->_getFillStyle($ID);\r
- } elseif ($fillStyle !== null) {\r
- return $fillStyle;\r
- } else {\r
- return parent::_getFillStyle($ID);\r
- }\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Array.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Fill.php
+ */
+require_once 'Image/Graph/Fill.php';
+
+/**
+ * A sequential array of fillstyles.
+ *
+ * This is used for filling multiple objects within the same element with
+ * different styles. This is done by adding multiple fillstyles to a FillArrray
+ * structure. The fillarray will then when requested return the 'next' fillstyle
+ * in sequential order. It is possible to specify ID tags to each fillstyle,
+ * which is used to make sure some data uses a specific fillstyle (i.e. in a
+ * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses
+ * this name as ID tag when adding the dataset's associated fillstyle to the
+ * fillarray.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Fill_Array extends Image_Graph_Fill
+{
+
+ /**
+ * The fill array
+ * @var array
+ * @access private
+ */
+ var $_fillStyles = array ();
+
+ /**
+ * Resets the fillstyle
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ reset($this->_fillStyles);
+ }
+
+ /**
+ * Add a fill style to the array
+ *
+ * @param Image_Graph_Fill &$style The style to add
+ * @param string $id The id or name of the style
+ *
+ * @return Image_Graph_Fill
+ */
+ function &add(& $style, $id = '')
+ {
+ if ($id == '') {
+ $this->_fillStyles[] =& $style;
+ } else {
+ $this->_fillStyles[$id] =& $style;
+ }
+ reset($this->_fillStyles);
+ return $style;
+ }
+
+ /**
+ * Add a color to the array
+ *
+ * @param int $color The color
+ * @param string $id The id or name of the color
+ *
+ * @return void
+ */
+ function addColor($color, $id = false)
+ {
+ if ($id !== false) {
+ $this->_fillStyles[$id] = $color;
+ } else {
+ $this->_fillStyles[] = $color;
+ }
+ reset($this->_fillStyles);
+ }
+
+ /**
+ * Return the fillstyle
+ *
+ * @param ??? $ID ???
+ *
+ * @return int A GD fillstyle
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ if (($ID === false) || (!isset($this->_fillStyles[$ID]))) {
+ $ID = key($this->_fillStyles);
+ if (!next($this->_fillStyles)) {
+ reset($this->_fillStyles);
+ }
+ }
+ $fillStyle =& $this->_fillStyles[$ID];
+
+ if (is_object($fillStyle)) {
+ return $fillStyle->_getFillStyle($ID);
+ } elseif ($fillStyle !== null) {
+ return $fillStyle;
+ } else {
+ return parent::_getFillStyle($ID);
+ }
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Gradient.php,v 1.15 2005/08/24 20:36:03 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Fill/Image.php\r
- */\r
-require_once 'Image/Graph/Fill/Image.php';\r
-\r
-/**\r
- * Fill using a gradient color.\r
- * This creates a scaled fillstyle with colors flowing gradiently between 2\r
- * specified RGB values. Several directions are supported:\r
- *\r
- * 1 Vertically (IMAGE_GRAPH_GRAD_VERTICAL)\r
- *\r
- * 2 Horizontally (IMAGE_GRAPH_GRAD_HORIZONTAL)\r
- *\r
- * 3 Mirrored vertically (the color grades from a- b-a vertically)\r
- * (IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED)\r
- *\r
- * 4 Mirrored horizontally (the color grades from a-b-a horizontally)\r
- * IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED\r
- *\r
- * 5 Diagonally from top-left to right-bottom\r
- * (IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR)\r
- *\r
- * 6 Diagonally from bottom-left to top-right\r
- * (IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR)\r
- *\r
- * 7 Radially (concentric circles in the center) (IMAGE_GRAPH_GRAD_RADIAL)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Fill_Gradient extends Image_Graph_Fill //Image_Graph_Fill_Image\r
-{\r
-\r
- /**\r
- * The direction of the gradient\r
- * @var int\r
- * @access private\r
- */\r
- var $_direction;\r
-\r
- /**\r
- * The first color to gradient\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_startColor;\r
-\r
- /**\r
- * The last color to gradient\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_endColor;\r
-\r
- /**\r
- * Image_Graph_GradientFill [Constructor]\r
- *\r
- * @param int $direction The direction of the gradient\r
- * @param mixed $startColor The value of the starting color\r
- * @param mixed $endColor The value of the ending color\r
- */\r
- function Image_Graph_Fill_Gradient($direction, $startColor, $endColor)\r
- {\r
- parent::Image_Graph_Fill();\r
- $this->_direction = $direction;\r
- $this->_startColor = $startColor;\r
- $this->_endColor = $endColor;\r
- }\r
-\r
- /**\r
- * Return the fillstyle\r
- *\r
- * @return int A GD fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- switch ($this->_direction) {\r
- case IMAGE_GRAPH_GRAD_HORIZONTAL:\r
- $direction = 'horizontal';\r
- break;\r
- case IMAGE_GRAPH_GRAD_VERTICAL:\r
- $direction = 'vertical';\r
- break;\r
- case IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED:\r
- $direction = 'horizontal_mirror';\r
- break;\r
- case IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED:\r
- $direction = 'vertical_mirror';\r
- break;\r
- case IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR:\r
- $direction = 'diagonal_tl_br';\r
- break;\r
- case IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR:\r
- $direction = 'diagonal_bl_tr';\r
- break;\r
- case IMAGE_GRAPH_GRAD_RADIAL:\r
- $direction = 'radial';\r
- break;\r
- }\r
- \r
- return array(\r
- 'type' => 'gradient',\r
- 'start' => $this->_startColor,\r
- 'end' => $this->_endColor,\r
- 'direction' => $direction\r
- );\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Gradient.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Fill/Image.php
+ */
+require_once 'Image/Graph/Fill/Image.php';
+
+/**
+ * Fill using a gradient color.
+ * This creates a scaled fillstyle with colors flowing gradiently between 2
+ * specified RGB values. Several directions are supported:
+ *
+ * 1 Vertically (IMAGE_GRAPH_GRAD_VERTICAL)
+ *
+ * 2 Horizontally (IMAGE_GRAPH_GRAD_HORIZONTAL)
+ *
+ * 3 Mirrored vertically (the color grades from a- b-a vertically)
+ * (IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED)
+ *
+ * 4 Mirrored horizontally (the color grades from a-b-a horizontally)
+ * IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED
+ *
+ * 5 Diagonally from top-left to right-bottom
+ * (IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR)
+ *
+ * 6 Diagonally from bottom-left to top-right
+ * (IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR)
+ *
+ * 7 Radially (concentric circles in the center) (IMAGE_GRAPH_GRAD_RADIAL)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Fill_Gradient extends Image_Graph_Fill //Image_Graph_Fill_Image
+{
+
+ /**
+ * The direction of the gradient
+ * @var int
+ * @access private
+ */
+ var $_direction;
+
+ /**
+ * The first color to gradient
+ * @var mixed
+ * @access private
+ */
+ var $_startColor;
+
+ /**
+ * The last color to gradient
+ * @var mixed
+ * @access private
+ */
+ var $_endColor;
+
+ /**
+ * Image_Graph_GradientFill [Constructor]
+ *
+ * @param int $direction The direction of the gradient
+ * @param mixed $startColor The value of the starting color
+ * @param mixed $endColor The value of the ending color
+ */
+ function Image_Graph_Fill_Gradient($direction, $startColor, $endColor)
+ {
+ parent::__construct();
+ $this->_direction = $direction;
+ $this->_startColor = $startColor;
+ $this->_endColor = $endColor;
+ }
+
+ /**
+ * Return the fillstyle
+ *
+ * @param ??? $ID ???
+ *
+ * @return int A GD fillstyle
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ switch ($this->_direction) {
+ case IMAGE_GRAPH_GRAD_HORIZONTAL:
+ $direction = 'horizontal';
+ break;
+ case IMAGE_GRAPH_GRAD_VERTICAL:
+ $direction = 'vertical';
+ break;
+ case IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED:
+ $direction = 'horizontal_mirror';
+ break;
+ case IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED:
+ $direction = 'vertical_mirror';
+ break;
+ case IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR:
+ $direction = 'diagonal_tl_br';
+ break;
+ case IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR:
+ $direction = 'diagonal_bl_tr';
+ break;
+ case IMAGE_GRAPH_GRAD_RADIAL:
+ $direction = 'radial';
+ break;
+ }
+
+ return array(
+ 'type' => 'gradient',
+ 'start' => $this->_startColor,
+ 'end' => $this->_endColor,
+ 'direction' => $direction
+ );
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Image.php,v 1.7 2005/08/24 20:36:03 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Fill.php\r
- */\r
-require_once 'Image/Graph/Fill.php';\r
-\r
-/**\r
- * Fill using an image.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Fill\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Fill_Image extends Image_Graph_Fill\r
-{\r
-\r
- /**\r
- * The file name\r
- * @var stirng\r
- * @access private\r
- */\r
- var $_filename;\r
-\r
- /**\r
- * The GD Image resource\r
- * @var resource\r
- * @access private\r
- */\r
- var $_image;\r
-\r
- /**\r
- * Resize the image to the bounding box of the area to fill\r
- * @var bool\r
- * @access private\r
- */\r
- var $_resize = true;\r
-\r
- /**\r
- * Image_Graph_ImageFill [Constructor]\r
- *\r
- * @param string $filename The filename and path of the image to use for filling\r
- */\r
- function Image_Graph_Fill_Image($filename)\r
- {\r
- parent::Image_Graph_Fill();\r
- $this->_filename = $filename;\r
- }\r
-\r
- /**\r
- * Return the fillstyle\r
- *\r
- * @param (something) $ID (Add description)\r
- * @return int A GD fillstyle\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- return $this->_filename;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Image.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Fill.php
+ */
+require_once 'Image/Graph/Fill.php';
+
+/**
+ * Fill using an image.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Fill
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Fill_Image extends Image_Graph_Fill
+{
+
+ /**
+ * The file name
+ * @var stirng
+ * @access private
+ */
+ var $_filename;
+
+ /**
+ * The GD Image resource
+ * @var resource
+ * @access private
+ */
+ var $_image;
+
+ /**
+ * Resize the image to the bounding box of the area to fill
+ * @var bool
+ * @access private
+ */
+ var $_resize = true;
+
+ /**
+ * Image_Graph_ImageFill [Constructor]
+ *
+ * @param string $filename The filename and path of the image to use for filling
+ */
+ function Image_Graph_Fill_Image($filename)
+ {
+ parent::__construct();
+ $this->_filename = $filename;
+ }
+
+ /**
+ * Return the fillstyle
+ *
+ * @param (something) $ID (Add description)
+ *
+ * @return int A GD fillstyle
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ return $this->_filename;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Text\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Font.php,v 1.8 2005/08/24 20:35:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Common.php\r
- */\r
-require_once 'Image/Graph/Common.php';\r
-\r
-/**\r
- * A font.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Text\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Font extends Image_Graph_Common\r
-{\r
-\r
- /**\r
- * The name of the font\r
- * @var string\r
- * @access private\r
- */\r
- var $_name = false;\r
-\r
- /**\r
- * The angle of the output\r
- * @var int\r
- * @access private\r
- */\r
- var $_angle = false;\r
-\r
- /**\r
- * The size of the font\r
- * @var int\r
- * @access private\r
- */\r
- var $_size = 11;\r
- \r
- /**\r
- * The color of the font\r
- * @var Color\r
- * @access private\r
- */\r
- var $_color = 'black';\r
-\r
- /**\r
- * Image_Graph_Font [Constructor]\r
- */\r
- function Image_Graph_Font($name = false, $size = false)\r
- {\r
- parent::Image_Graph_Common();\r
- if ($name !== false) {\r
- $this->_name = $name;\r
- }\r
- if ($size !== false) {\r
- $this->_size = $size;\r
- }\r
- }\r
-\r
- /**\r
- * Set the color of the font\r
- *\r
- * @param mixed $color The color object of the Font\r
- */\r
- function setColor($color)\r
- {\r
- $this->_color = $color;\r
- }\r
-\r
- /**\r
- * Set the angle slope of the output font.\r
- *\r
- * 0 = normal, 90 = bottom and up, 180 = upside down, 270 = top and down\r
- *\r
- * @param int $angle The angle in degrees to slope the text\r
- */\r
- function setAngle($angle)\r
- {\r
- $this->_angle = $angle;\r
- }\r
-\r
- /**\r
- * Set the size of the font\r
- *\r
- * @param int $size The size in pixels of the font\r
- */\r
- function setSize($size)\r
- {\r
- $this->_size = $size;\r
- }\r
- \r
- /**\r
- * Get the font 'array'\r
- *\r
- * @return array The font 'summary' to pass to the canvas\r
- * @access private\r
- */\r
- function _getFont($options = false)\r
- {\r
- if ($options === false) {\r
- $options = array();\r
- }\r
- \r
- if ($this->_name !== false) {\r
- $options['name'] = $this->_name;\r
- }\r
- \r
- if (!isset($options['color'])) {\r
- $options['color'] = $this->_color;\r
- }\r
-\r
- if (!isset($options['size'])) {\r
- $options['size'] = $this->_size;\r
- }\r
-\r
- if ((!isset($options['angle'])) && ($this->_angle !== false)) {\r
- $options['angle'] = $this->_angle;\r
- }\r
- return $options;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Text
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Font.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Common.php
+ */
+require_once 'Image/Graph/Common.php';
+
+/**
+ * A font.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Text
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Font extends Image_Graph_Common
+{
+
+ /**
+ * The name of the font
+ * @var string
+ * @access private
+ */
+ var $_name = false;
+
+ /**
+ * The angle of the output
+ * @var int
+ * @access private
+ */
+ var $_angle = false;
+
+ /**
+ * The size of the font
+ * @var int
+ * @access private
+ */
+ var $_size = 11;
+
+ /**
+ * The color of the font
+ * @var Color
+ * @access private
+ */
+ var $_color = 'black';
+
+ /**
+ * Image_Graph_Font [Constructor]
+ *
+ * @param string $name Font name
+ * @param int $size Font size
+ */
+ function Image_Graph_Font($name = false, $size = false)
+ {
+ parent::__construct();
+ if ($name !== false) {
+ $this->_name = $name;
+ }
+ if ($size !== false) {
+ $this->_size = $size;
+ }
+ }
+
+ /**
+ * Set the color of the font
+ *
+ * @param mixed $color The color object of the Font
+ *
+ * @return void
+ */
+ function setColor($color)
+ {
+ $this->_color = $color;
+ }
+
+ /**
+ * Set the angle slope of the output font.
+ *
+ * 0 = normal, 90 = bottom and up, 180 = upside down, 270 = top and down
+ *
+ * @param int $angle The angle in degrees to slope the text
+ *
+ * @return void
+ */
+ function setAngle($angle)
+ {
+ $this->_angle = $angle;
+ }
+
+ /**
+ * Set the size of the font
+ *
+ * @param int $size The size in pixels of the font
+ *
+ * @return void
+ */
+ function setSize($size)
+ {
+ $this->_size = $size;
+ }
+
+ /**
+ * Get the font 'array'
+ *
+ * @param array $options Font options (optional)
+ *
+ * @return array The font 'summary' to pass to the canvas
+ * @access private
+ */
+ function _getFont($options = false)
+ {
+ if ($options === false) {
+ $options = array();
+ }
+
+ if ($this->_name !== false) {
+ $options['name'] = $this->_name;
+ }
+
+ if (!isset($options['color'])) {
+ $options['color'] = $this->_color;
+ }
+
+ if (!isset($options['size'])) {
+ $options['size'] = $this->_size;
+ }
+
+ if ((!isset($options['angle'])) && ($this->_angle !== false)) {
+ $options['angle'] = $this->_angle;
+ }
+ return $options;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Grid.php,v 1.8 2005/02/21 20:49:47 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * A grid displayed on the plotarea.\r
- *\r
- * A grid is associated with a primary and a secondary axis. The grid is\r
- * displayed in context of the primary axis' label interval - meaning that a\r
- * grid for an Y-axis displays a grid for every label on the y-axis (fx. a {@link\r
- * Image_Graph_Grid_Lines}, which displays horizontal lines for every label on\r
- * the y-axis from the x-axis minimum to the x-axis maximum). You should always\r
- * add the grid as one of the first elements to the plotarea. This is due to the\r
- * fact that elements are 'outputted' in the order they are added, i.e. if an\r
- * grid is added *after* a chart, the grid will be displayed on top of the chart\r
- * which is (probably) not desired.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Grid extends Image_Graph_Plotarea_Element\r
-{\r
-\r
- /**\r
- * The primary axis: the grid 'refers' to\r
- * @var Axis\r
- * @access private\r
- */\r
- var $_primaryAxis = null;\r
-\r
- /**\r
- * The secondary axis\r
- * @var Axis\r
- * @access private\r
- */\r
- var $_secondaryAxis = null;\r
-\r
- /**\r
- * Set the primary axis: the grid should 'refer' to\r
- *\r
- * @param Image_Graph_Axis $axis The axis\r
- * @access private\r
- */\r
- function _setPrimaryAxis(& $axis)\r
- {\r
- $this->_primaryAxis =& $axis;\r
- }\r
-\r
- /**\r
- * Set the secondary axis\r
- *\r
- * @param Image_Graph_Axis $axis The axis\r
- * @access private\r
- */\r
- function _setSecondaryAxis(& $axis)\r
- {\r
- $this->_secondaryAxis =& $axis;\r
- }\r
-\r
- /**\r
- * Get the points on the secondary axis that the grid should 'connect'\r
- *\r
- * @return array The secondary data values that should mark the grid 'end points'\r
- * @access private\r
- */\r
- function _getSecondaryAxisPoints()\r
- {\r
- if (is_a($this->_secondaryAxis, 'Image_Graph_Axis_Radar')) {\r
- $secondaryValue = false;\r
- $firstValue = $secondaryValue;\r
- while (($secondaryValue = $this->_secondaryAxis->_getNextLabel($secondaryValue)) !== false) {\r
- $secondaryAxisPoints[] = $secondaryValue;\r
- }\r
- $secondaryAxisPoints[] = $firstValue;\r
- } else {\r
- $secondaryAxisPoints = array ('#min#', '#max#');\r
- }\r
- return $secondaryAxisPoints;\r
- }\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double $point the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($point)\r
- {\r
- if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) ||\r
- ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY))\r
- {\r
- $point['AXIS_Y'] = $this->_primaryAxis->_type;\r
- } else {\r
- $point['AXIS_Y'] = $this->_secondaryAxis->_type;\r
- }\r
- return parent::_pointX($point);\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double $point the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($point)\r
- {\r
- if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) ||\r
- ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY))\r
- {\r
- $point['AXIS_Y'] = $this->_primaryAxis->_type;\r
- } else {\r
- $point['AXIS_Y'] = $this->_secondaryAxis->_type;\r
- }\r
- return parent::_pointY($point);\r
- }\r
-\r
- /**\r
- * Causes the object to update all sub elements coordinates.\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- $this->_setCoords(\r
- $this->_parent->_plotLeft,\r
- $this->_parent->_plotTop,\r
- $this->_parent->_plotRight,\r
- $this->_parent->_plotBottom\r
- );\r
- parent::_updateCoords();\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Grid.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea/Element.php
+ */
+require_once 'Image/Graph/Plotarea/Element.php';
+
+/**
+ * A grid displayed on the plotarea.
+ *
+ * A grid is associated with a primary and a secondary axis. The grid is
+ * displayed in context of the primary axis' label interval - meaning that a
+ * grid for an Y-axis displays a grid for every label on the y-axis (fx. a {@link
+ * Image_Graph_Grid_Lines}, which displays horizontal lines for every label on
+ * the y-axis from the x-axis minimum to the x-axis maximum). You should always
+ * add the grid as one of the first elements to the plotarea. This is due to the
+ * fact that elements are 'outputted' in the order they are added, i.e. if an
+ * grid is added *after* a chart, the grid will be displayed on top of the chart
+ * which is (probably) not desired.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Grid extends Image_Graph_Plotarea_Element
+{
+
+ /**
+ * The primary axis: the grid 'refers' to
+ * @var Axis
+ * @access private
+ */
+ var $_primaryAxis = null;
+
+ /**
+ * The secondary axis
+ * @var Axis
+ * @access private
+ */
+ var $_secondaryAxis = null;
+
+ /**
+ * The starting point of the grid
+ * @var mixed
+ * @access private
+ */
+ var $_gridStart = '#min#';
+
+ /**
+ * The ending point of the grid
+ * @var mixed
+ * @access private
+ */
+ var $_gridEnd = '#max#';
+
+ /**
+ * Set the primary axis: the grid should 'refer' to
+ *
+ * @param Image_Graph_Axis &$axis The axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setPrimaryAxis(& $axis)
+ {
+ $this->_primaryAxis =& $axis;
+ }
+
+ /**
+ * Set the secondary axis
+ *
+ * @param Image_Graph_Axis &$axis The axis
+ *
+ * @return void
+ * @access private
+ */
+ function _setSecondaryAxis(& $axis)
+ {
+ $this->_secondaryAxis =& $axis;
+ }
+
+ /**
+ * Get the points on the secondary axis that the grid should 'connect'
+ *
+ * @return array The secondary data values that should mark the grid 'end points'
+ * @access private
+ */
+ function _getSecondaryAxisPoints()
+ {
+ if (is_a($this->_secondaryAxis, 'Image_Graph_Axis_Radar')) {
+ $secondaryValue = false;
+ $firstValue = $secondaryValue;
+ while (($secondaryValue = $this->_secondaryAxis->_getNextLabel($secondaryValue)) !== false) {
+ $secondaryAxisPoints[] = $secondaryValue;
+ }
+ $secondaryAxisPoints[] = $firstValue;
+ } else {
+ $secondaryAxisPoints = array ($this->_gridStart, $this->_gridEnd);
+ }
+ return $secondaryAxisPoints;
+ }
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $point the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($point)
+ {
+ if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y)
+ || ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ ) {
+ $point['AXIS_Y'] = $this->_primaryAxis->_type;
+ } else {
+ $point['AXIS_Y'] = $this->_secondaryAxis->_type;
+ }
+ return parent::_pointX($point);
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $point the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($point)
+ {
+ if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y)
+ || ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ ) {
+ $point['AXIS_Y'] = $this->_primaryAxis->_type;
+ } else {
+ $point['AXIS_Y'] = $this->_secondaryAxis->_type;
+ }
+ return parent::_pointY($point);
+ }
+
+ /**
+ * Causes the object to update all sub elements coordinates.
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ $this->_setCoords(
+ $this->_parent->_plotLeft,
+ $this->_parent->_plotTop,
+ $this->_parent->_plotRight,
+ $this->_parent->_plotBottom
+ );
+ parent::_updateCoords();
+ }
+
+ /**
+ * Sets the starting and ending points of the grid,
+ * these defaults to 'min' and 'max' which signals that the grid should
+ * span the entire the perpendicular axis
+ *
+ * @param mixed $start The starting value, use 'min' to start and "beginning" of the perpendicular axis
+ * @param mixed $end The starting value, use 'min' to start and "end" of the perpendicular axis
+ *
+ * @return void
+ */
+ function setAxisPoints($start = 'min', $end = 'max')
+ {
+ // no check for 'max' since it would make no sense
+ $this->_gridStart = ($start === 'min' ? '#min#' : $start);
+ // same - no check for 'min'
+ $this->_gridEnd = ($end === 'max' ? '#max#' : $end);
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Bars.php,v 1.10 2005/09/14 20:27:25 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Grid.php\r
- */\r
-require_once 'Image/Graph/Grid.php';\r
-\r
-/**\r
- * Display alternating bars on the plotarea.\r
- *\r
- * {@link Image_Graph_Grid}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Grid_Bars extends Image_Graph_Grid\r
-{\r
-\r
- /**\r
- * Output the grid\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!$this->_primaryAxis) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this));\r
-\r
- $i = 0;\r
- $value = false;\r
-\r
- $previousValue = 0;\r
-\r
- $secondaryPoints = $this->_getSecondaryAxisPoints();\r
-\r
- while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {\r
- if ($i == 1) {\r
- reset($secondaryPoints);\r
- list ($id, $previousSecondaryValue) = each($secondaryPoints);\r
- while (list ($id, $secondaryValue) = each($secondaryPoints)) {\r
- if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {\r
- $p1 = array ('Y' => $secondaryValue, 'X' => $value);\r
- $p2 = array ('Y' => $previousSecondaryValue, 'X' => $value);\r
- $p3 = array ('Y' => $previousSecondaryValue, 'X' => $previousValue);\r
- $p4 = array ('Y' => $secondaryValue, 'X' => $previousValue);\r
- } else {\r
- $p1 = array ('X' => $secondaryValue, 'Y' => $value);\r
- $p2 = array ('X' => $previousSecondaryValue, 'Y' => $value);\r
- $p3 = array ('X' => $previousSecondaryValue, 'Y' => $previousValue);\r
- $p4 = array ('X' => $secondaryValue, 'Y' => $previousValue);\r
- }\r
-\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p1), 'y' => $this->_pointY($p1)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p2), 'y' => $this->_pointY($p2)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p3), 'y' => $this->_pointY($p3)));\r
- $this->_canvas->addVertex(array('x' => $this->_pointX($p4), 'y' => $this->_pointY($p4)));\r
-\r
- $this->_getFillStyle();\r
- $this->_canvas->polygon(array('connect' => true));\r
-\r
- $previousSecondaryValue = $secondaryValue;\r
- }\r
- }\r
- $i = 1 - $i;\r
- $previousValue = $value;\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Bars.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Grid.php
+ */
+require_once 'Image/Graph/Grid.php';
+
+/**
+ * Display alternating bars on the plotarea.
+ *
+ * {@link Image_Graph_Grid}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Grid_Bars extends Image_Graph_Grid
+{
+
+ /**
+ * Output the grid
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!$this->_primaryAxis) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $i = 0;
+ $value = false;
+
+ $previousValue = 0;
+
+ $secondaryPoints = $this->_getSecondaryAxisPoints();
+
+ while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {
+ if ($i == 1) {
+ reset($secondaryPoints);
+ list ($id, $previousSecondaryValue) = each($secondaryPoints);
+ while (list ($id, $secondaryValue) = each($secondaryPoints)) {
+ if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {
+ $p1 = array ('Y' => $secondaryValue, 'X' => $value);
+ $p2 = array ('Y' => $previousSecondaryValue, 'X' => $value);
+ $p3 = array ('Y' => $previousSecondaryValue, 'X' => $previousValue);
+ $p4 = array ('Y' => $secondaryValue, 'X' => $previousValue);
+ } else {
+ $p1 = array ('X' => $secondaryValue, 'Y' => $value);
+ $p2 = array ('X' => $previousSecondaryValue, 'Y' => $value);
+ $p3 = array ('X' => $previousSecondaryValue, 'Y' => $previousValue);
+ $p4 = array ('X' => $secondaryValue, 'Y' => $previousValue);
+ }
+
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p1), 'y' => $this->_pointY($p1)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p2), 'y' => $this->_pointY($p2)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p3), 'y' => $this->_pointY($p3)));
+ $this->_canvas->addVertex(array('x' => $this->_pointX($p4), 'y' => $this->_pointY($p4)));
+
+ $this->_getFillStyle();
+ $this->_canvas->polygon(array('connect' => true));
+
+ $previousSecondaryValue = $secondaryValue;
+ }
+ }
+ $i = 1 - $i;
+ $previousValue = $value;
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Lines.php,v 1.10 2005/08/24 20:36:04 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Grid.php\r
- */\r
-require_once 'Image/Graph/Grid.php';\r
-\r
-/**\r
- * Display a line grid on the plotarea.\r
- *\r
- * {@link Image_Graph_Grid}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Grid_Lines extends Image_Graph_Grid\r
-{\r
-\r
- /**\r
- * GridLines [Constructor]\r
- */\r
- function Image_Graph_Grid_Lines()\r
- {\r
- parent::Image_Graph_Grid();\r
- $this->_lineStyle = 'lightgrey';\r
- }\r
-\r
- /**\r
- * Output the grid\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!$this->_primaryAxis) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $value = false;\r
-\r
- $secondaryPoints = $this->_getSecondaryAxisPoints();\r
-\r
- while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {\r
- reset($secondaryPoints);\r
- list ($id, $previousSecondaryValue) = each($secondaryPoints);\r
- while (list ($id, $secondaryValue) = each($secondaryPoints)) {\r
- if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) {\r
- $p1 = array ('X' => $secondaryValue, 'Y' => $value);\r
- $p2 = array ('X' => $previousSecondaryValue, 'Y' => $value);\r
- } else {\r
- $p1 = array ('X' => $value, 'Y' => $secondaryValue);\r
- $p2 = array ('X' => $value, 'Y' => $previousSecondaryValue);\r
- }\r
-\r
- $x1 = $this->_pointX($p1);\r
- $y1 = $this->_pointY($p1);\r
- $x2 = $this->_pointX($p2);\r
- $y2 = $this->_pointY($p2);\r
-\r
- $previousSecondaryValue = $secondaryValue;\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x1, 'y0' => $y1, 'x1' => $x2, 'y1' => $y2));\r
- }\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Lines.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Grid.php
+ */
+require_once 'Image/Graph/Grid.php';
+
+/**
+ * Display a line grid on the plotarea.
+ *
+ * {@link Image_Graph_Grid}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Grid_Lines extends Image_Graph_Grid
+{
+
+ /**
+ * GridLines [Constructor]
+ */
+ function Image_Graph_Grid_Lines()
+ {
+ parent::__construct();
+ $this->_lineStyle = 'lightgrey';
+ }
+
+ /**
+ * Output the grid
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!$this->_primaryAxis) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $value = false;
+
+ $secondaryPoints = $this->_getSecondaryAxisPoints();
+
+ while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {
+ reset($secondaryPoints);
+ list ($id, $previousSecondaryValue) = each($secondaryPoints);
+ while (list ($id, $secondaryValue) = each($secondaryPoints)) {
+ if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) {
+ $p1 = array ('X' => $secondaryValue, 'Y' => $value);
+ $p2 = array ('X' => $previousSecondaryValue, 'Y' => $value);
+ } else {
+ $p1 = array ('X' => $value, 'Y' => $secondaryValue);
+ $p2 = array ('X' => $value, 'Y' => $previousSecondaryValue);
+ }
+
+ $x1 = $this->_pointX($p1);
+ $y1 = $this->_pointY($p1);
+ $x2 = $this->_pointX($p2);
+ $y2 = $this->_pointY($p2);
+
+ $previousSecondaryValue = $secondaryValue;
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x1, 'y0' => $y1, 'x1' => $x2, 'y1' => $y2));
+ }
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Polar.php,v 1.10 2005/08/24 20:36:04 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since File available since Release 0.3.0dev2\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Grid.php\r
- */\r
-require_once 'Image/Graph/Grid.php';\r
-\r
-/**\r
- * Display a line grid on the plotarea.\r
- *\r
- * {@link Image_Graph_Grid}\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Grid\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since Class available since Release 0.3.0dev2\r
- */\r
-class Image_Graph_Grid_Polar extends Image_Graph_Grid\r
-{\r
-\r
- /**\r
- * GridLines [Constructor]\r
- */\r
- function Image_Graph_Grid_Polar()\r
- {\r
- parent::Image_Graph_Grid();\r
- $this->_lineStyle = 'lightgrey';\r
- }\r
-\r
- /**\r
- * Output the grid\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!$this->_primaryAxis) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- $value = false;\r
-\r
- $p0 = array ('X' => '#min#', 'Y' => '#min#');\r
- if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) {\r
- $p1 = array ('X' => '#min#', 'Y' => '#max#');\r
- $r0 = abs($this->_pointY($p1) - $this->_pointY($p0));\r
- } else {\r
- $p1 = array ('X' => '#max#', 'Y' => '#min#');\r
- $r0 = abs($this->_pointX($p1) - $this->_pointX($p0));\r
- }\r
-\r
- $cx = $this->_pointX($p0);\r
- $cy = $this->_pointY($p0);\r
-\r
- $span = $this->_primaryAxis->_axisSpan;\r
-\r
- while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {\r
- $r = $r0 * ($value - $this->_primaryAxis->_getMinimum()) / $span;\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->ellipse(array('x' => $cx, 'y' => $cy, 'rx' => $r, 'ry' => $r));\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Polar.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ * @since File available since Release 0.3.0dev2
+ */
+
+/**
+ * Include file Image/Graph/Grid.php
+ */
+require_once 'Image/Graph/Grid.php';
+
+/**
+ * Display a line grid on the plotarea.
+ *
+ * {@link Image_Graph_Grid}
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Grid
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @since Class available since Release 0.3.0dev2
+ */
+class Image_Graph_Grid_Polar extends Image_Graph_Grid
+{
+
+ /**
+ * GridLines [Constructor]
+ */
+ function Image_Graph_Grid_Polar()
+ {
+ parent::__construct();
+ $this->_lineStyle = 'lightgrey';
+ }
+
+ /**
+ * Output the grid
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!$this->_primaryAxis) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $value = false;
+
+ $p0 = array ('X' => '#min#', 'Y' => '#min#');
+ if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) {
+ $p1 = array ('X' => '#min#', 'Y' => '#max#');
+ $r0 = abs($this->_pointY($p1) - $this->_pointY($p0));
+ } else {
+ $p1 = array ('X' => '#max#', 'Y' => '#min#');
+ $r0 = abs($this->_pointX($p1) - $this->_pointX($p0));
+ }
+
+ $cx = $this->_pointX($p0);
+ $cy = $this->_pointY($p0);
+
+ $span = $this->_primaryAxis->_axisSpan;
+
+ while (($value = $this->_primaryAxis->_getNextLabel($value)) !== false) {
+ $r = $r0 * ($value - $this->_primaryAxis->_getMinimum()) / $span;
+
+ $this->_getLineStyle();
+ $this->_canvas->ellipse(array('x' => $cx, 'y' => $cy, 'rx' => $r, 'ry' => $r));
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+?>
-In this folder the files for the Image_Graph_Plot_Map are located. They should be the\r
-following format:\r
-\r
-[map name].png\r
-[map name].txt\r
-\r
-The [map name].png (fx. europe.png) is the actual image presenting the map. The \r
-[map name].txt file is the location -> (x,y) conversion table. In this file the\r
-named locations is written on every line with the x and y coordinates after the\r
-name (with a TAB), i.e.:\r
-\r
-Denmark 10 30\r
-England 4 30\r
-\r
-Where Denmark will be 'located' on (10, 30) on the map, and England at (4, 30).\r
-\r
+In this folder the files for the Image_Graph_Plot_Map are located. They should be the
+following format:
+
+[map name].png
+[map name].txt
+
+The [map name].png (fx. europe.png) is the actual image presenting the map. The
+[map name].txt file is the location -> (x,y) conversion table. In this file the
+named locations is written on every line with the x and y coordinates after the
+name (with a TAB), i.e.:
+
+Denmark 10 30
+England 4 30
+
+Where Denmark will be 'located' on (10, 30) on the map, and England at (4, 30).
+
No maps are released by default due to we want to avoid possible copyright issues.
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Layout.php,v 1.12 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plotarea/Element.php\r
- */\r
-require_once 'Image/Graph/Plotarea/Element.php';\r
-\r
-/**\r
- * Defines an area of the graph that can be layout'ed.\r
- *\r
- * Any class that extends this abstract class can be used within a layout on the canvas.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Layout extends Image_Graph_Plotarea_Element\r
-{\r
-\r
- /**\r
- * Has the coordinates already been updated?\r
- * @var bool\r
- * @access private\r
- */\r
- var $_updated = false;\r
-\r
- /**\r
- * Alignment of the area for each vertice (left, top, right, bottom)\r
- * @var array\r
- * @access private\r
- */\r
- var $_alignSize = array ('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);\r
-\r
- /**\r
- * Image_Graph_Layout [Constructor]\r
- */\r
- function Image_Graph_Layout()\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);\r
- }\r
-\r
- /**\r
- * Resets the elements\r
- *\r
- * @access private\r
- */\r
- function _reset()\r
- {\r
- parent::_reset();\r
- $this->_updated = false;\r
- }\r
-\r
- /**\r
- * Calculate the edge offset for a specific edge\r
- * @param array $alignSize The alignment of the edge\r
- * @param int $offset The offset/posision of the at 0% edge\r
- * @param int $total The total size (width or height) of the element\r
- * @param int $multiplier +/- 1 if the edge should pushed either toward more\r
- * negative or positive values\r
- * @since 0.3.0dev2\r
- * @access private\r
- */\r
- function _calcEdgeOffset($alignSize, $offset, $total, $multiplier)\r
- {\r
- if ($alignSize['unit'] == 'percentage') {\r
- return $offset + $multiplier * ($total * $alignSize['value'] / 100);\r
- } elseif ($alignSize['unit'] == 'pixels') {\r
- if (($alignSize['value'] == 'auto_part1') || ($alignSize['value'] == 'auto_part2')) {\r
- $alignSize['value'] = $multiplier * $this->_parent->_getAbsolute($alignSize['value']);\r
- }\r
- if ($alignSize['value'] < 0) {\r
- return $offset + $multiplier * ($total + $alignSize['value']);\r
- } else {\r
- return $offset + $multiplier * $alignSize['value'];\r
- }\r
- }\r
- return $offset;\r
- }\r
-\r
- /**\r
- * Calculate the edges\r
- *\r
- * @access private\r
- */\r
- function _calcEdges()\r
- {\r
- if ((is_array($this->_alignSize)) && (!$this->_updated)) {\r
- $left = $this->_calcEdgeOffset(\r
- $this->_alignSize['left'],\r
- $this->_parent->_fillLeft(),\r
- $this->_parent->_fillWidth(),\r
- +1\r
- );\r
- $top = $this->_calcEdgeOffset(\r
- $this->_alignSize['top'],\r
- $this->_parent->_fillTop(),\r
- $this->_parent->_fillHeight(),\r
- +1\r
- );\r
- $right = $this->_calcEdgeOffset(\r
- $this->_alignSize['right'],\r
- $this->_parent->_fillRight(),\r
- $this->_parent->_fillWidth(),\r
- -1\r
- );\r
- $bottom = $this->_calcEdgeOffset(\r
- $this->_alignSize['bottom'],\r
- $this->_parent->_fillBottom(),\r
- $this->_parent->_fillHeight(),\r
- -1\r
- );\r
-\r
- $this->_setCoords(\r
- $left + $this->_padding['left'],\r
- $top + $this->_padding['top'],\r
- $right - $this->_padding['right'],\r
- $bottom - $this->_padding['bottom']\r
- );\r
- }\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- $this->_calcEdges();\r
- parent::_updateCoords();\r
- }\r
-\r
- /**\r
- * Pushes an edge of area a specific distance 'into' the canvas\r
- *\r
- * @param int $edge The edge of the canvas to align relative to\r
- * @param int $size The number of pixels or the percentage of the canvas total size to occupy relative to the selected alignment edge\r
- * @access private\r
- */\r
- function _push($edge, $size = '100%')\r
- {\r
- $result = array();\r
- if (ereg("([0-9]*)\%", $size, $result)) {\r
- $this->_alignSize[$edge] = array(\r
- 'value' => min(100, max(0, $result[1])),\r
- 'unit' => 'percentage'\r
- );\r
- } else {\r
- $this->_alignSize[$edge] = array(\r
- 'value' => $size,\r
- 'unit' => 'pixels'\r
- );\r
- }\r
- }\r
-\r
- /**\r
- * Sets the coordinates of the element\r
- *\r
- * @param int $left The leftmost pixel of the element on the canvas\r
- * @param int $top The topmost pixel of the element on the canvas\r
- * @param int $right The rightmost pixel of the element on the canvas\r
- * @param int $bottom The bottommost pixel of the element on the canvas\r
- * @access private\r
- */\r
- function _setCoords($left, $top, $right, $bottom)\r
- {\r
- parent::_setCoords($left, $top, $right, $bottom);\r
- $this->_updated = true;\r
- }\r
-\r
- /**\r
- * Returns the calculated "auto" size\r
- *\r
- * @return int The calculated auto size\r
- * @access private\r
- */\r
- function _getAutoSize()\r
- {\r
- return false;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Layout.php 291756 2009-12-06 02:55:46Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea/Element.php
+ */
+require_once 'Image/Graph/Plotarea/Element.php';
+
+/**
+ * Defines an area of the graph that can be layout'ed.
+ *
+ * Any class that extends this abstract class can be used within a layout on the canvas.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Layout extends Image_Graph_Plotarea_Element
+{
+
+ /**
+ * Has the coordinates already been updated?
+ * @var bool
+ * @access private
+ */
+ var $_updated = false;
+
+ /**
+ * Alignment of the area for each vertice (left, top, right, bottom)
+ * @var array
+ * @access private
+ */
+ var $_alignSize = array ('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
+
+ /**
+ * Image_Graph_Layout [Constructor]
+ */
+ function Image_Graph_Layout()
+ {
+ parent::__construct();
+ $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);
+ }
+
+ /**
+ * Resets the elements
+ *
+ * @return void
+ * @access private
+ */
+ function _reset()
+ {
+ parent::_reset();
+ $this->_updated = false;
+ }
+
+ /**
+ * Calculate the edge offset for a specific edge
+ *
+ * @param array $alignSize The alignment of the edge
+ * @param int $offset The offset/posision of the at 0% edge
+ * @param int $total The total size (width or height) of the element
+ * @param int $multiplier +/- 1 if the edge should pushed either toward more
+ * negative or positive values
+ *
+ * @return int Edge offset
+ * @since 0.3.0dev2
+ * @access private
+ */
+ function _calcEdgeOffset($alignSize, $offset, $total, $multiplier)
+ {
+ if ($alignSize['unit'] == 'percentage') {
+ return $offset + $multiplier * ($total * $alignSize['value'] / 100);
+ } elseif ($alignSize['unit'] == 'pixels') {
+ if (($alignSize['value'] == 'auto_part1') || ($alignSize['value'] == 'auto_part2')) {
+ $alignSize['value'] = $multiplier * $this->_parent->_getAbsolute($alignSize['value']);
+ }
+ if ($alignSize['value'] < 0) {
+ return $offset + $multiplier * ($total + $alignSize['value']);
+ } else {
+ return $offset + $multiplier * $alignSize['value'];
+ }
+ }
+ return $offset;
+ }
+
+ /**
+ * Calculate the edges
+ *
+ * @return void
+ * @access private
+ */
+ function _calcEdges()
+ {
+ if ((is_array($this->_alignSize)) && (!$this->_updated)) {
+ $left = $this->_calcEdgeOffset(
+ $this->_alignSize['left'],
+ $this->_parent->_fillLeft(),
+ $this->_parent->_fillWidth(),
+ +1
+ );
+ $top = $this->_calcEdgeOffset(
+ $this->_alignSize['top'],
+ $this->_parent->_fillTop(),
+ $this->_parent->_fillHeight(),
+ +1
+ );
+ $right = $this->_calcEdgeOffset(
+ $this->_alignSize['right'],
+ $this->_parent->_fillRight(),
+ $this->_parent->_fillWidth(),
+ -1
+ );
+ $bottom = $this->_calcEdgeOffset(
+ $this->_alignSize['bottom'],
+ $this->_parent->_fillBottom(),
+ $this->_parent->_fillHeight(),
+ -1
+ );
+
+ $this->_setCoords(
+ $left + $this->_padding['left'],
+ $top + $this->_padding['top'],
+ $right - $this->_padding['right'],
+ $bottom - $this->_padding['bottom']
+ );
+ }
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ $this->_calcEdges();
+ parent::_updateCoords();
+ }
+
+ /**
+ * Pushes an edge of area a specific distance 'into' the canvas
+ *
+ * @param int $edge The edge of the canvas to align relative to
+ * @param int $size The number of pixels or the percentage of the canvas total size to occupy relative to the selected alignment edge
+ *
+ * @return void
+ * @access private
+ */
+ function _push($edge, $size = '100%')
+ {
+ $result = array();
+ if (preg_match("/([0-9]*)\%/", $size, $result)) {
+ $this->_alignSize[$edge] = array(
+ 'value' => min(100, max(0, $result[1])),
+ 'unit' => 'percentage'
+ );
+ } else {
+ $this->_alignSize[$edge] = array(
+ 'value' => $size,
+ 'unit' => 'pixels'
+ );
+ }
+ }
+
+ /**
+ * Sets the coordinates of the element
+ *
+ * @param int $left The leftmost pixel of the element on the canvas
+ * @param int $top The topmost pixel of the element on the canvas
+ * @param int $right The rightmost pixel of the element on the canvas
+ * @param int $bottom The bottommost pixel of the element on the canvas
+ *
+ * @return void
+ * @access private
+ */
+ function _setCoords($left, $top, $right, $bottom)
+ {
+ parent::_setCoords($left, $top, $right, $bottom);
+ $this->_updated = true;
+ }
+
+ /**
+ * Returns the calculated "auto" size
+ *
+ * @return int The calculated auto size
+ * @access private
+ */
+ function _getAutoSize()
+ {
+ return false;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Horizontal.php,v 1.11 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout.php\r
- */\r
-require_once 'Image/Graph/Layout.php';\r
-\r
-/**\r
- * Layout for displaying two elements side by side.\r
- *\r
- * This splits the area contained by this element in two, side by side by\r
- * a specified percentage (relative to the left side). A layout can be nested.\r
- * Fx. a HorizontalLayout can layout two {@link Image_Graph_Layout_Vertical}s to\r
- * make a 2 by 2 matrix of 'element-areas'.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Layout_Horizontal extends Image_Graph_Layout\r
-{\r
-\r
- /**\r
- * Part1 of the layout\r
- * @var GraPHPElemnt\r
- * @access private\r
- */\r
- var $_part1 = false;\r
-\r
- /**\r
- * Part2 of the layout\r
- * @var GraPHPElemnt\r
- * @access private\r
- */\r
- var $_part2 = false;\r
-\r
- /**\r
- * The percentage of the graph where the split occurs\r
- * @var int\r
- * @access private\r
- */\r
- var $_percentage;\r
-\r
- /**\r
- * An absolute position where the split occurs\r
- * @var int\r
- * @access private\r
- */\r
- var $_absolute;\r
-\r
- /**\r
- * HorizontalLayout [Constructor]\r
- *\r
- * @param Image_Graph_Element $part1 The 1st part of the layout\r
- * @param Image_Graph_Element $part2 The 2nd part of the layout\r
- * @param int $percentage The percentage of the layout to split at\r
- */\r
- function Image_Graph_Layout_Horizontal(& $part1, & $part2, $percentage = 50)\r
- {\r
- parent::Image_Graph_Layout();\r
- if (!is_a($part1, 'Image_Graph_Layout')) {\r
- $this->_error(\r
- 'Cannot create layout on non-layouable parts: ' . get_class($part1),\r
- array('part1' => &$part1, 'part2' => &$part2)\r
- );\r
- } elseif (!is_a($part2, 'Image_Graph_Layout')) {\r
- $this->_error(\r
- 'Cannot create layout on non-layouable parts: ' . get_class($part2),\r
- array('part1' => &$part1, 'part2' => &$part2)\r
- );\r
- } else {\r
- $this->_part1 =& $part1;\r
- $this->_part2 =& $part2;\r
- $this->add($this->_part1);\r
- $this->add($this->_part2);\r
- };\r
- if ($percentage === 'auto') {\r
- $this->_percentage = false;\r
- $this->_absolute = 'runtime';\r
- } else {\r
- $this->_absolute = false;\r
- $this->_percentage = max(0, min(100, $percentage));\r
- }\r
- $this->_split();\r
- $this->_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);\r
- }\r
-\r
- /**\r
- * Gets the absolute size of one of the parts.\r
- *\r
- * @param string $part The name of the part - auto_part(1|2)\r
- * @return int The number of pixels the edge should be pushed\r
- * @since 0.3.0dev2\r
- * @access private\r
- */ \r
- function _getAbsolute(&$part)\r
- {\r
- $part1Size = $this->_part1->_getAutoSize();\r
- $part2Size = $this->_part2->_getAutoSize();\r
- $this->_percentage = false;\r
- if (($part1Size !== false) and ($part2Size !== false)) {\r
- $width = $this->_fillWidth() * $part1Size / ($part1Size + $part2Size);\r
- } elseif ($part1Size !== false) {\r
- $width = $part1Size;\r
- } elseif ($part2Size !== false) {\r
- $width = -$part2Size;\r
- } else {\r
- $width = $this->_fillWidth() / 2;\r
- }\r
- if ($part == 'auto_part2') {\r
- $width = -$width;\r
- }\r
-\r
- return $width;\r
- }\r
-\r
- /**\r
- * Splits the layout between the parts, by the specified percentage\r
- *\r
- * @access private\r
- */\r
- function _split()\r
- {\r
- if (($this->_part1) && ($this->_part2)) {\r
- if ($this->_percentage !== false) {\r
- $split1 = 100 - $this->_percentage;\r
- $split2 = $this->_percentage;\r
- $this->_part1->_push('right', "$split1%");\r
- $this->_part2->_push('left', "$split2%");\r
- } else {\r
- $this->_part1->_push('right', 'auto_part1');\r
- $this->_part2->_push('left', 'auto_part2');\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Output the layout to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (($this->_part1) && ($this->_part2)) {\r
- return (($this->_part1->_done()) && ($this->_part2->_done())); \r
- }\r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Horizontal.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout.php
+ */
+require_once 'Image/Graph/Layout.php';
+
+/**
+ * Layout for displaying two elements side by side.
+ *
+ * This splits the area contained by this element in two, side by side by
+ * a specified percentage (relative to the left side). A layout can be nested.
+ * Fx. a HorizontalLayout can layout two {@link Image_Graph_Layout_Vertical}s to
+ * make a 2 by 2 matrix of 'element-areas'.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Layout_Horizontal extends Image_Graph_Layout
+{
+
+ /**
+ * Part1 of the layout
+ * @var GraPHPElemnt
+ * @access private
+ */
+ var $_part1 = false;
+
+ /**
+ * Part2 of the layout
+ * @var GraPHPElemnt
+ * @access private
+ */
+ var $_part2 = false;
+
+ /**
+ * The percentage of the graph where the split occurs
+ * @var int
+ * @access private
+ */
+ var $_percentage;
+
+ /**
+ * An absolute position where the split occurs
+ * @var int
+ * @access private
+ */
+ var $_absolute;
+
+ /**
+ * HorizontalLayout [Constructor]
+ *
+ * @param Image_Graph_Element &$part1 The 1st part of the layout
+ * @param Image_Graph_Element &$part2 The 2nd part of the layout
+ * @param int $percentage The percentage of the layout to split at
+ */
+ function Image_Graph_Layout_Horizontal(& $part1, & $part2, $percentage = 50)
+ {
+ parent::__construct();
+ if (!is_a($part1, 'Image_Graph_Layout')) {
+ $this->_error(
+ 'Cannot create layout on non-layouable parts: ' . get_class($part1),
+ array('part1' => &$part1, 'part2' => &$part2)
+ );
+ } elseif (!is_a($part2, 'Image_Graph_Layout')) {
+ $this->_error(
+ 'Cannot create layout on non-layouable parts: ' . get_class($part2),
+ array('part1' => &$part1, 'part2' => &$part2)
+ );
+ } else {
+ $this->_part1 =& $part1;
+ $this->_part2 =& $part2;
+ $this->add($this->_part1);
+ $this->add($this->_part2);
+ };
+ if ($percentage === 'auto') {
+ $this->_percentage = false;
+ $this->_absolute = 'runtime';
+ } else {
+ $this->_absolute = false;
+ $this->_percentage = max(0, min(100, $percentage));
+ }
+ $this->_split();
+ $this->_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
+ }
+
+ /**
+ * Gets the absolute size of one of the parts.
+ *
+ * @param string &$part The name of the part - auto_part(1|2)
+ *
+ * @return int The number of pixels the edge should be pushed
+ * @since 0.3.0dev2
+ * @access private
+ */
+ function _getAbsolute(&$part)
+ {
+ $part1Size = $this->_part1->_getAutoSize();
+ $part2Size = $this->_part2->_getAutoSize();
+ $this->_percentage = false;
+ if (($part1Size !== false) and ($part2Size !== false)) {
+ $width = $this->_fillWidth() * $part1Size / ($part1Size + $part2Size);
+ } elseif ($part1Size !== false) {
+ $width = $part1Size;
+ } elseif ($part2Size !== false) {
+ $width = -$part2Size;
+ } else {
+ $width = $this->_fillWidth() / 2;
+ }
+ if ($part == 'auto_part2') {
+ $width = -$width;
+ }
+
+ return $width;
+ }
+
+ /**
+ * Splits the layout between the parts, by the specified percentage
+ *
+ * @return void
+ * @access private
+ */
+ function _split()
+ {
+ if (($this->_part1) && ($this->_part2)) {
+ if ($this->_percentage !== false) {
+ $split1 = 100 - $this->_percentage;
+ $split2 = $this->_percentage;
+ $this->_part1->_push('right', "$split1%");
+ $this->_part2->_push('left', "$split2%");
+ } else {
+ $this->_part1->_push('right', 'auto_part1');
+ $this->_part2->_push('left', 'auto_part2');
+ }
+ }
+ }
+
+ /**
+ * Output the layout to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (($this->_part1) && ($this->_part2)) {
+ return (($this->_part1->_done()) && ($this->_part2->_done()));
+ }
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Matrix.php,v 1.8 2005/08/24 20:35:58 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout.php\r
- */\r
-require_once 'Image/Graph/Layout.php';\r
-\r
-/**\r
- * Layout for displaying elements in a matix.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Layout_Matrix extends Image_Graph_Layout\r
-{\r
-\r
- /**\r
- * Layout matrix\r
- * @var array\r
- * @access private\r
- */\r
- var $_matrix = false;\r
-\r
- /**\r
- * The number of rows\r
- * @var int\r
- * @access private\r
- */\r
- var $_rows = false;\r
-\r
- /**\r
- * The number of columns\r
- * @var int\r
- * @access private\r
- */\r
- var $_cols = false;\r
-\r
- /**\r
- * Image_Graph_Layout_Matrix [Constructor]\r
- *\r
- * @param int $rows The number of rows\r
- * @param int $cols The number of cols\r
- * @param bool $autoCreate Specifies whether the matrix should automatically\r
- * be filled with newly created Image_Graph_Plotares objects, or they will\r
- * be added manually\r
- */\r
- function Image_Graph_Layout_Matrix($rows, $cols, $autoCreate = true)\r
- {\r
- parent::Image_Graph_Layout();\r
-\r
- $this->_rows = $rows;\r
- $this->_cols = $cols;\r
- if (($this->_rows > 0) && ($this->_cols > 0)) {\r
- $this->_matrix = array(array());\r
- for ($i = 0; $i < $this->_rows; $i++) {\r
- for ($j = 0; $j < $this->_cols; $j++) {\r
- if ($autoCreate) {\r
- $this->_matrix[$i][$j] =& $this->addNew('plotarea');\r
- $this->_pushEdges($i, $j);\r
- } else {\r
- $this->_matrix[$i][$j] = false;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Pushes the edges on the specified position in the matrix\r
- *\r
- * @param int $row The row\r
- * @param int $col The column\r
- * @access private\r
- */\r
- function _pushEdges($row, $col)\r
- {\r
- if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {\r
- $height = 100/$this->_rows;\r
- $width = 100/$this->_cols;\r
- if ($col > 0) {\r
- $this->_matrix[$row][$col]->_push('left', round($col*$width) . '%');\r
- }\r
- if ($col+1 < $this->_cols) {\r
- $this->_matrix[$row][$col]->_push('right', round(100-($col+1)*$width) . '%');\r
- }\r
- if ($row > 0) {\r
- $this->_matrix[$row][$col]->_push('top', round($row*$height) . '%');\r
- }\r
- if ($row+1 < $this->_rows) {\r
- $this->_matrix[$row][$col]->_push('bottom', round(100-($row+1)*$height) . '%');\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Get the area on the specified position in the matrix\r
- *\r
- * @param int $row The row\r
- * @param int $col The column\r
- * @return Image_Graph_Layout The element of position ($row, $col) in the\r
- * matrix\r
- */\r
- function &getEntry($row, $col)\r
- {\r
- if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {\r
- return $this->_matrix[$row][$col];\r
- } else {\r
- $result = null;\r
- return $result;\r
- }\r
- }\r
-\r
- /**\r
- * Get the area on the specified position in the matrix\r
- *\r
- * @param int $row The row\r
- * @param int $col The column\r
- * @param Image_Graph_Layout $element The element to set in the position\r
- * ($row, $col) in the matrix\r
- */\r
- function setEntry($row, $col, &$element)\r
- {\r
- $this->_matrix[$row][$col] =& $element;\r
- $this->_pushEdges($row, $col);\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- for ($i = 0; $i < $this->_rows; $i++) {\r
- for ($j = 0; $j < $this->_cols; $j++) {\r
- $element =& $this->getEntry($i, $j);\r
- $this->add($element);\r
- }\r
- }\r
- parent::_updateCoords();\r
- }\r
-\r
- /**\r
- * Output the layout to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $result = true;\r
- for ($i = 0; $i < $this->_rows; $i++) {\r
- for ($j = 0; $j < $this->_cols; $j++) {\r
- $element =& $this->getEntry($i, $j);\r
- if ($element) {\r
- if (!$element->_done()) {\r
- $result = false;\r
- }\r
- }\r
- }\r
- }\r
- return $result;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Matrix.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout.php
+ */
+require_once 'Image/Graph/Layout.php';
+
+/**
+ * Layout for displaying elements in a matix.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Layout_Matrix extends Image_Graph_Layout
+{
+
+ /**
+ * Layout matrix
+ * @var array
+ * @access private
+ */
+ var $_matrix = false;
+
+ /**
+ * The number of rows
+ * @var int
+ * @access private
+ */
+ var $_rows = false;
+
+ /**
+ * The number of columns
+ * @var int
+ * @access private
+ */
+ var $_cols = false;
+
+ /**
+ * Image_Graph_Layout_Matrix [Constructor]
+ *
+ * @param int $rows The number of rows
+ * @param int $cols The number of cols
+ * @param bool $autoCreate Specifies whether the matrix should automatically
+ * be filled with newly created Image_Graph_Plotares objects, or they will
+ * be added manually
+ */
+ function Image_Graph_Layout_Matrix($rows, $cols, $autoCreate = true)
+ {
+ parent::__construct();
+
+ $this->_rows = $rows;
+ $this->_cols = $cols;
+ if (($this->_rows > 0) && ($this->_cols > 0)) {
+ $this->_matrix = array(array());
+ for ($i = 0; $i < $this->_rows; $i++) {
+ for ($j = 0; $j < $this->_cols; $j++) {
+ if ($autoCreate) {
+ $this->_matrix[$i][$j] =& $this->addNew('plotarea');
+ $this->_pushEdges($i, $j);
+ } else {
+ $this->_matrix[$i][$j] = false;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Pushes the edges on the specified position in the matrix
+ *
+ * @param int $row The row
+ * @param int $col The column
+ *
+ * @return void
+ * @access private
+ */
+ function _pushEdges($row, $col)
+ {
+ if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {
+ $height = 100/$this->_rows;
+ $width = 100/$this->_cols;
+ if ($col > 0) {
+ $this->_matrix[$row][$col]->_push('left', round($col*$width) . '%');
+ }
+ if ($col+1 < $this->_cols) {
+ $this->_matrix[$row][$col]->_push('right', round(100-($col+1)*$width) . '%');
+ }
+ if ($row > 0) {
+ $this->_matrix[$row][$col]->_push('top', round($row*$height) . '%');
+ }
+ if ($row+1 < $this->_rows) {
+ $this->_matrix[$row][$col]->_push('bottom', round(100-($row+1)*$height) . '%');
+ }
+ }
+ }
+
+ /**
+ * Get the area on the specified position in the matrix
+ *
+ * @param int $row The row
+ * @param int $col The column
+ *
+ * @return Image_Graph_Layout The element of position ($row, $col) in the
+ * matrix
+ */
+ function &getEntry($row, $col)
+ {
+ if ((isset($this->_matrix[$row])) && (isset($this->_matrix[$row][$col]))) {
+ return $this->_matrix[$row][$col];
+ } else {
+ $result = null;
+ return $result;
+ }
+ }
+
+ /**
+ * Get the area on the specified position in the matrix
+ *
+ * @param int $row The row
+ * @param int $col The column
+ * @param Image_Graph_Layout &$element The element to set in the position
+ * ($row, $col) in the matrix
+ *
+ * @return void
+ */
+ function setEntry($row, $col, &$element)
+ {
+ $this->_matrix[$row][$col] =& $element;
+ $this->_pushEdges($row, $col);
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ for ($i = 0; $i < $this->_rows; $i++) {
+ for ($j = 0; $j < $this->_cols; $j++) {
+ $element =& $this->getEntry($i, $j);
+ $this->add($element);
+ }
+ }
+ parent::_updateCoords();
+ }
+
+ /**
+ * Output the layout to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $result = true;
+ for ($i = 0; $i < $this->_rows; $i++) {
+ for ($j = 0; $j < $this->_cols; $j++) {
+ $element =& $this->getEntry($i, $j);
+ if ($element) {
+ if (!$element->_done()) {
+ $result = false;
+ }
+ }
+ }
+ }
+ return $result;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Vertical.php,v 1.6 2005/02/21 20:49:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout/Horizontal.php\r
- */\r
-require_once 'Image/Graph/Layout/Horizontal.php';\r
-\r
-/**\r
- * Layout for displaying two elements on top of each other.\r
- *\r
- * This splits the area contained by this element in two on top of each other\r
- * by a specified percentage (relative to the top). A layout can be nested.\r
- * Fx. a {@link Image_Graph_Layout_Horizontal} can layout two VerticalLayout's to\r
- * make a 2 by 2 matrix of 'element-areas'.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Layout\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Layout_Vertical extends Image_Graph_Layout_Horizontal\r
-{\r
-\r
- /**\r
- * Gets the absolute size of one of the parts.\r
- *\r
- * @param string $part The name of the part - auto_part(1|2)\r
- * @return int The number of pixels the edge should be pushed\r
- * @since 0.3.0dev2\r
- * @access private\r
- */\r
- function _getAbsolute(&$part)\r
- {\r
- $part1Size = $this->_part1->_getAutoSize();\r
- $part2Size = $this->_part2->_getAutoSize();\r
- $this->_percentage = false;\r
- if (($part1Size !== false) and ($part2Size !== false)) {\r
- $height = $this->_fillHeight() * $part1Size / ($part1Size + $part2Size);\r
- } elseif ($part1Size !== false) {\r
- $height = $part1Size;\r
- } elseif ($part2Size !== false) {\r
- $height = -$part2Size;\r
- } else {\r
- $height = $this->_fillHeight() / 2;\r
- }\r
-\r
- if ($part == 'auto_part2') {\r
-// $height = $this->_fillHeight() - $height;\r
- }\r
-\r
- return $height;\r
- }\r
-\r
- /**\r
- * Splits the layout between the parts, by the specified percentage\r
- *\r
- * @access private\r
- */\r
- function _split()\r
- {\r
- if (($this->_part1) && ($this->_part2)) {\r
- if ($this->_percentage !== false) {\r
- $split1 = 100 - $this->_percentage;\r
- $split2 = $this->_percentage;\r
- $this->_part1->_push('bottom', "$split1%");\r
- $this->_part2->_push('top', "$split2%");\r
- } else {\r
- $this->_part1->_push('bottom', 'auto_part1');\r
- $this->_part2->_push('top', 'auto_part2');\r
- }\r
- }\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Vertical.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout/Horizontal.php
+ */
+require_once 'Image/Graph/Layout/Horizontal.php';
+
+/**
+ * Layout for displaying two elements on top of each other.
+ *
+ * This splits the area contained by this element in two on top of each other
+ * by a specified percentage (relative to the top). A layout can be nested.
+ * Fx. a {@link Image_Graph_Layout_Horizontal} can layout two VerticalLayout's to
+ * make a 2 by 2 matrix of 'element-areas'.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Layout
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Layout_Vertical extends Image_Graph_Layout_Horizontal
+{
+
+ /**
+ * Gets the absolute size of one of the parts.
+ *
+ * @param string &$part The name of the part - auto_part(1|2)
+ *
+ * @return int The number of pixels the edge should be pushed
+ * @since 0.3.0dev2
+ * @access private
+ */
+ function _getAbsolute(&$part)
+ {
+ $part1Size = $this->_part1->_getAutoSize();
+ $part2Size = $this->_part2->_getAutoSize();
+ $this->_percentage = false;
+ if (($part1Size !== false) and ($part2Size !== false)) {
+ $height = $this->_fillHeight() * $part1Size / ($part1Size + $part2Size);
+ } elseif ($part1Size !== false) {
+ $height = $part1Size;
+ } elseif ($part2Size !== false) {
+ $height = -$part2Size;
+ } else {
+ $height = $this->_fillHeight() / 2;
+ }
+
+ if ($part == 'auto_part2') {
+ // $height = $this->_fillHeight() - $height;
+ }
+
+ return $height;
+ }
+
+ /**
+ * Splits the layout between the parts, by the specified percentage
+ *
+ * @return void
+ * @access private
+ */
+ function _split()
+ {
+ if (($this->_part1) && ($this->_part2)) {
+ if ($this->_percentage !== false) {
+ $split1 = 100 - $this->_percentage;
+ $split2 = $this->_percentage;
+ $this->_part1->_push('bottom', "$split1%");
+ $this->_part2->_push('top', "$split2%");
+ } else {
+ $this->_part1->_push('bottom', 'auto_part1');
+ $this->_part2->_push('top', 'auto_part2');
+ }
+ }
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Legend\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Legend.php,v 1.16 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout.php\r
- */\r
-require_once 'Image/Graph/Layout.php';\r
-\r
-/**\r
- * Displays a legend for a plotarea.\r
- *\r
- * A legend can be displayed in two ways:\r
- *\r
- * 1 As an overlayed box within the plotarea\r
- *\r
- * 2 Layout'ed on the canvas smewhere next to the plotarea.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Legend\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Legend extends Image_Graph_Layout\r
-{\r
- \r
- /**\r
- * Alignment of the text\r
- * @var int\r
- * @access private\r
- */\r
- var $_alignment = false;\r
-\r
- /**\r
- * The plotarea(s) to show the legend for\r
- * @var array\r
- * @access private\r
- */\r
- var $_plotareas = array();\r
-\r
- /**\r
- * Should markers be shown or not on this legend\r
- * @var bool\r
- * @access private\r
- */\r
- var $_showMarker = false;\r
-\r
- /**\r
- * Image_Graph_Legend [Constructor]\r
- */\r
- function Image_Graph_Legend()\r
- {\r
- parent::Image_Graph_Layout();\r
- $this->_padding = array('left' => 5, 'top' => 5, 'right' => 5, 'bottom' => 5);\r
- }\r
-\r
- /**\r
- * The number of actual plots in the plot area\r
- *\r
- * @return int The number of plotes\r
- * @access private\r
- */\r
- function _plotCount()\r
- {\r
- $count = 0;\r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- if (is_a($plotarea, 'Image_Graph_Plotarea')) {\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach ($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $count ++;\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- }\r
- unset($keys);\r
- return $count;\r
- }\r
- \r
- /**\r
- * Get a default parameter array for legendSamples\r
- * @param bool $simulate Whether the array should be used for simulation or\r
- * not\r
- * @return array Default parameter array\r
- * @access private\r
- */\r
- function _parameterArray($simulate = false)\r
- {\r
- $param['left'] = $this->_left + $this->_padding['left'];\r
- $param['top'] = $this->_top + $this->_padding['top'];\r
- $param['right'] = $this->_right - $this->_padding['right'];\r
- $param['bottom'] = $this->_bottom - $this->_padding['bottom'];\r
- $param['align'] = $this->_alignment;\r
- $param['x'] = $this->_left + $this->_padding['left'];\r
- $param['y'] = $this->_top + $this->_padding['top'];\r
- $param['width'] = 16;\r
- $param['height'] = 16;\r
- $param['show_marker'] = $this->_showMarker;\r
- $param['maxwidth'] = 0;\r
- $param['font'] = $this->_getFont();\r
- if ($simulate) {\r
- $param['simulate'] = true;\r
- }\r
- \r
- return $param;\r
- }\r
-\r
- /**\r
- * The height of the element on the canvas\r
- *\r
- * @return int Number of pixels representing the height of the element\r
- * @access private\r
- */\r
- function _height()\r
- {\r
- $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);\r
-\r
- if (strtolower($parent) == 'image_graph_plotarea') {\r
- $param = $this->_parameterArray(true);\r
- $param['align'] = IMAGE_GRAPH_ALIGN_VERTICAL;\r
- $param0 = $param;\r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_legendSample($param);\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- unset($keys);\r
- return abs($param['y'] - $param0['y']) + $this->_padding['top'] + $this->_padding['bottom'];\r
- } else {\r
- return parent::height();\r
- }\r
- }\r
-\r
- /**\r
- * The width of the element on the canvas\r
- *\r
- * @return int Number of pixels representing the width of the element\r
- * @access private\r
- */\r
- function _width()\r
- {\r
- $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);\r
-\r
- if (strtolower($parent) == 'image_graph_plotarea') {\r
- $param = $this->_parameterArray(true);\r
- $param['align'] = IMAGE_GRAPH_ALIGN_VERTICAL;\r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_legendSample($param);\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- unset($keys);\r
- return $param['maxwidth'];\r
- } else {\r
- return parent::width();\r
- }\r
- }\r
-\r
- /**\r
- * Set the alignment of the legend\r
- *\r
- * @param int $alignment The alignment\r
- */\r
- function setAlignment($alignment)\r
- {\r
- $this->_alignment = $alignment;\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- parent::_updateCoords();\r
-\r
- $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);\r
-\r
- if (strtolower($parent) == 'image_graph_plotarea') {\r
- $w = $this->_width();\r
- $h = $this->_height();\r
- \r
- if ($this->_alignment === false) {\r
- $this->_alignment = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_RIGHT;\r
- }\r
-\r
- if (($this->_alignment & IMAGE_GRAPH_ALIGN_BOTTOM) != 0) {\r
- $y = $this->_parent->_fillBottom() - $h - $this->_padding['bottom'];\r
- } else {\r
- $y = $this->_parent->_fillTop() + $this->_padding['top'];\r
- }\r
-\r
- if (($this->_alignment & IMAGE_GRAPH_ALIGN_LEFT) != 0) {\r
- $x = $this->_parent->_fillLeft() + $this->_padding['left'];\r
- } else {\r
- $x = $this->_parent->_fillRight() - $w - $this->_padding['right'];\r
- }\r
-\r
- $this->_setCoords($x, $y, $x + $w, $y + $h);\r
- }\r
- }\r
-\r
- /**\r
- * Sets Plotarea\r
- *\r
- * @param Image_Graph_Plotarea $plotarea The plotarea\r
- */\r
- function setPlotarea(& $plotarea)\r
- {\r
- if (is_a($plotarea, 'Image_Graph_Plotarea')) {\r
- $this->_plotareas[] =& $plotarea;\r
- }\r
- }\r
-\r
- /**\r
- * Sets the parent. The parent chain should ultimately be a GraPHP object\r
- *\r
- * @see Image_Graph\r
- * @param Image_Graph_Common $parent The parent\r
- * @access private\r
- */\r
- function _setParent(& $parent)\r
- {\r
- parent::_setParent($parent);\r
- if (count($this->_plotareas) == 0) {\r
- $this->setPlotarea($parent);\r
- }\r
- }\r
-\r
- /**\r
- * Set if this legends should show markers\r
- *\r
- * @param bool $showMarker True if markers are to be shown, false is not\r
- */\r
- function setShowMarker($showMarker)\r
- {\r
- $this->_showMarker = $showMarker;\r
- }\r
-\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
-\r
- if (Image_Graph_Element::_done() === false) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this));\r
-\r
- $param = $this->_parameterArray();\r
-\r
- $parent = (is_object($this->_parent) ?\r
- get_class($this->_parent) :\r
- $this->_parent\r
- );\r
-\r
- if (strtolower($parent) == 'image_graph_plotarea') { \r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_top,\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_bottom\r
- )\r
- );\r
-\r
- $param = $this->_parameterArray();\r
- \r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_legendSample($param);\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- unset($keys);\r
- } else {\r
- $param0 = $param;\r
- $param0['simulate'] = true;\r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_legendSample($param0);\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- unset($keys);\r
- if (($this->_alignment & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {\r
- if ($param0['x'] == $param['x']) {\r
- $param['y'] = $param['y'] + ($this->_height() - ($param0['y'] - $param['y']))/2;\r
- }\r
- } else {\r
- if ($param0['y'] == $param['y']) {\r
- $param['x'] = $param['x'] + ($this->_width() - ($param0['x'] - $param['x']))/2;\r
- }\r
- }\r
-\r
- $keys = array_keys($this->_plotareas);\r
- foreach($keys as $key) {\r
- $plotarea =& $this->_plotareas[$key];\r
- $keys2 = array_keys($plotarea->_elements);\r
- foreach($keys2 as $key) {\r
- $element =& $plotarea->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_legendSample($param);\r
- }\r
- }\r
- unset($keys2);\r
- }\r
- unset($keys);\r
- }\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Legend
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Legend.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout.php
+ */
+require_once 'Image/Graph/Layout.php';
+
+/**
+ * Displays a legend for a plotarea.
+ *
+ * A legend can be displayed in two ways:
+ *
+ * 1 As an overlayed box within the plotarea
+ *
+ * 2 Layout'ed on the canvas smewhere next to the plotarea.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Legend
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Legend extends Image_Graph_Layout
+{
+
+ /**
+ * Alignment of the text
+ * @var int
+ * @access private
+ */
+ var $_alignment = false;
+
+ /**
+ * The plotarea(s) to show the legend for
+ * @var array
+ * @access private
+ */
+ var $_plotareas = array();
+
+ /**
+ * Should markers be shown or not on this legend
+ * @var bool
+ * @access private
+ */
+ var $_showMarker = false;
+
+ /**
+ * Image_Graph_Legend [Constructor]
+ */
+ function Image_Graph_Legend()
+ {
+ parent::__construct();
+ $this->_padding = array('left' => 5, 'top' => 5, 'right' => 5, 'bottom' => 5);
+ }
+
+ /**
+ * The number of actual plots in the plot area
+ *
+ * @return int The number of plotes
+ * @access private
+ */
+ function _plotCount()
+ {
+ $count = 0;
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ if (is_a($plotarea, 'Image_Graph_Plotarea')) {
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $count ++;
+ }
+ }
+ unset($keys2);
+ }
+ }
+ unset($keys);
+ return $count;
+ }
+
+ /**
+ * Get a default parameter array for legendSamples
+ *
+ * @param bool $simulate Whether the array should be used for simulation or not
+ *
+ * @return array Default parameter array
+ * @access private
+ */
+ function _parameterArray($simulate = false)
+ {
+ $param['left'] = $this->_left + $this->_padding['left'];
+ $param['top'] = $this->_top + $this->_padding['top'];
+ $param['right'] = $this->_right - $this->_padding['right'];
+ $param['bottom'] = $this->_bottom - $this->_padding['bottom'];
+ $param['align'] = $this->_alignment;
+ $param['x'] = $this->_left + $this->_padding['left'];
+ $param['y'] = $this->_top + $this->_padding['top'];
+ $param['width'] = 16;
+ $param['height'] = 16;
+ $param['show_marker'] = $this->_showMarker;
+ $param['maxwidth'] = 0;
+ $param['font'] = $this->_getFont();
+ if ($simulate) {
+ $param['simulate'] = true;
+ }
+
+ return $param;
+ }
+
+ /**
+ * The height of the element on the canvas
+ *
+ * @return int Number of pixels representing the height of the element
+ * @access private
+ */
+ function _height()
+ {
+ $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);
+
+ if (strtolower($parent) == 'image_graph_plotarea') {
+ $param = $this->_parameterArray(true);
+ $param['align'] = IMAGE_GRAPH_ALIGN_VERTICAL;
+ $param0 = $param;
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_legendSample($param);
+ }
+ }
+ unset($keys2);
+ }
+ unset($keys);
+ return abs($param['y'] - $param0['y']) + $this->_padding['top'] + $this->_padding['bottom'];
+ } else {
+ return parent::height();
+ }
+ }
+
+ /**
+ * The width of the element on the canvas
+ *
+ * @return int Number of pixels representing the width of the element
+ * @access private
+ */
+ function _width()
+ {
+ $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);
+
+ if (strtolower($parent) == 'image_graph_plotarea') {
+ $param = $this->_parameterArray(true);
+ $param['align'] = IMAGE_GRAPH_ALIGN_VERTICAL;
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_legendSample($param);
+ }
+ }
+ unset($keys2);
+ }
+ unset($keys);
+ return $param['maxwidth'];
+ } else {
+ return parent::width();
+ }
+ }
+
+ /**
+ * Set the alignment of the legend
+ *
+ * @param int $alignment The alignment
+ *
+ * @return void
+ */
+ function setAlignment($alignment)
+ {
+ $this->_alignment = $alignment;
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ parent::_updateCoords();
+
+ $parent = (is_object($this->_parent) ? get_class($this->_parent) : $this->_parent);
+
+ if (strtolower($parent) == 'image_graph_plotarea') {
+ $w = $this->_width();
+ $h = $this->_height();
+
+ if ($this->_alignment === false) {
+ $this->_alignment = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_RIGHT;
+ }
+
+ if (($this->_alignment & IMAGE_GRAPH_ALIGN_BOTTOM) != 0) {
+ $y = $this->_parent->_fillBottom() - $h - $this->_padding['bottom'];
+ } else {
+ $y = $this->_parent->_fillTop() + $this->_padding['top'];
+ }
+
+ if (($this->_alignment & IMAGE_GRAPH_ALIGN_LEFT) != 0) {
+ $x = $this->_parent->_fillLeft() + $this->_padding['left'];
+ } else {
+ $x = $this->_parent->_fillRight() - $w - $this->_padding['right'];
+ }
+
+ $this->_setCoords($x, $y, $x + $w, $y + $h);
+ }
+ }
+
+ /**
+ * Sets Plotarea
+ *
+ * @param Image_Graph_Plotarea &$plotarea The plotarea
+ *
+ * @return void
+ */
+ function setPlotarea(& $plotarea)
+ {
+ if (is_a($plotarea, 'Image_Graph_Plotarea')) {
+ $this->_plotareas[] =& $plotarea;
+ }
+ }
+
+ /**
+ * Sets the parent. The parent chain should ultimately be a GraPHP object
+ *
+ * @param Image_Graph_Common &$parent The parent
+ *
+ * @return void
+ * @see Image_Graph
+ * @access private
+ */
+ function _setParent(& $parent)
+ {
+ parent::_setParent($parent);
+ if (count($this->_plotareas) == 0) {
+ $this->setPlotarea($parent);
+ }
+ }
+
+ /**
+ * Set if this legends should show markers
+ *
+ * @param bool $showMarker True if markers are to be shown, false is not
+ *
+ * @return void
+ */
+ function setShowMarker($showMarker)
+ {
+ $this->_showMarker = $showMarker;
+ }
+
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+
+ if (Image_Graph_Element::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this));
+
+ $param = $this->_parameterArray();
+
+ $parent = (is_object($this->_parent) ?
+ get_class($this->_parent) :
+ $this->_parent
+ );
+
+ if (strtolower($parent) == 'image_graph_plotarea') {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_top,
+ 'x1' => $this->_right,
+ 'y1' => $this->_bottom
+ )
+ );
+
+ $param = $this->_parameterArray();
+
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_legendSample($param);
+ }
+ }
+ unset($keys2);
+ }
+ unset($keys);
+ } else {
+ $param0 = $param;
+ $param0['simulate'] = true;
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_legendSample($param0);
+ }
+ }
+ unset($keys2);
+ }
+ unset($keys);
+ if (($this->_alignment & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {
+ if ($param0['x'] == $param['x']) {
+ $param['y'] = $param['y'] + ($this->_height() - ($param0['y'] - $param['y']))/2;
+ }
+ } else {
+ if ($param0['y'] == $param['y']) {
+ $param['x'] = $param['x'] + ($this->_width() - ($param0['x'] - $param['x']))/2;
+ }
+ }
+
+ $keys = array_keys($this->_plotareas);
+ foreach ($keys as $key) {
+ $plotarea =& $this->_plotareas[$key];
+ $keys2 = array_keys($plotarea->_elements);
+ foreach ($keys2 as $key) {
+ $element =& $plotarea->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_legendSample($param);
+ }
+ }
+ unset($keys2);
+ }
+ unset($keys);
+ }
+
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Array.php,v 1.7 2005/02/21 20:49:42 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Common.php\r
- */\r
-require_once 'Image/Graph/Common.php';\r
-\r
-/**\r
- * A sequential array of linestyles.\r
- *\r
- * This is used for multiple objects within the same element with different line\r
- * styles. This is done by adding multiple line styles to a LineArrray\r
- * structure. The linearray will then when requested return the 'next' linestyle\r
- * in sequential order. It is possible to specify ID tags to each linestyle,\r
- * which is used to make sure some data uses a specific linestyle (i.e. in a\r
- * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses\r
- * this name as ID tag when adding the dataset's associated linestyle to the\r
- * linearray.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Line_Array extends Image_Graph_Common\r
-{\r
-\r
- /**\r
- * The fill array\r
- * @var array\r
- * @access private\r
- */\r
- var $_lineStyles = array ();\r
-\r
- /**\r
- * Add a line style to the array\r
- *\r
- * @param Image_Graph_Line $style The style to add\r
- */\r
- function add(& $style, $id = false)\r
- {\r
- if (is_a($style, 'Image_Graph_Element')) {\r
- parent::add($style);\r
- }\r
- if ($id === false) {\r
- $this->_lineStyles[] =& $style;\r
- } else {\r
- $this->_lineStyles[$id] =& $style;\r
- }\r
- reset($this->_lineStyles);\r
-\r
- }\r
-\r
- /**\r
- * Add a color to the array\r
- *\r
- * @param int $color The color\r
- * @param string $id The id or name of the color\r
- */\r
- function addColor($color, $id = false)\r
- {\r
- if ($id !== false) {\r
- $this->_lineStyles[$id] = $color;\r
- } else {\r
- $this->_lineStyles[] = $color;\r
- }\r
- reset($this->_lineStyles);\r
- }\r
-\r
- /**\r
- * Return the linestyle\r
- *\r
- * @return int A GD Linestyle\r
- * @access private\r
- */\r
- function _getLineStyle($ID = false)\r
- {\r
- if (($ID === false) || (!isset($this->_lineStyles[$ID]))) {\r
- $ID = key($this->_lineStyles);\r
- if (!next($this->_lineStyles)) {\r
- reset($this->_lineStyles);\r
- }\r
- }\r
- $lineStyle =& $this->_lineStyles[$ID];\r
-\r
- if (is_object($lineStyle)) {\r
- return $lineStyle->_getLineStyle($ID);\r
- } elseif ($lineStyle !== null) {\r
- return $lineStyle;\r
- } else {\r
- return parent::_getLineStyle($ID);\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Array.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Common.php
+ */
+require_once 'Image/Graph/Common.php';
+
+/**
+ * A sequential array of linestyles.
+ *
+ * This is used for multiple objects within the same element with different line
+ * styles. This is done by adding multiple line styles to a LineArrray
+ * structure. The linearray will then when requested return the 'next' linestyle
+ * in sequential order. It is possible to specify ID tags to each linestyle,
+ * which is used to make sure some data uses a specific linestyle (i.e. in a
+ * multiple-/stackedbarchart you name the {@link Image_Graph_Dataset}s and uses
+ * this name as ID tag when adding the dataset's associated linestyle to the
+ * linearray.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Line_Array extends Image_Graph_Common
+{
+
+ /**
+ * The fill array
+ * @var array
+ * @access private
+ */
+ var $_lineStyles = array ();
+
+ /**
+ * Add a line style to the array
+ *
+ * @param Image_Graph_Line &$style The style to add
+ * @param ??? $id ???
+ *
+ * @return void
+ */
+ function add(& $style, $id = false)
+ {
+ if (is_a($style, 'Image_Graph_Element')) {
+ parent::add($style);
+ }
+ if ($id === false) {
+ $this->_lineStyles[] =& $style;
+ } else {
+ $this->_lineStyles[$id] =& $style;
+ }
+ reset($this->_lineStyles);
+
+ }
+
+ /**
+ * Add a color to the array
+ *
+ * @param int $color The color
+ * @param string $id The id or name of the color
+ *
+ * @return void
+ */
+ function addColor($color, $id = false)
+ {
+ if ($id !== false) {
+ $this->_lineStyles[$id] = $color;
+ } else {
+ $this->_lineStyles[] = $color;
+ }
+ reset($this->_lineStyles);
+ }
+
+ /**
+ * Return the linestyle
+ *
+ * @param ??? $ID ???
+ *
+ * @return int A GD Linestyle
+ * @access private
+ */
+ function _getLineStyle($ID = false)
+ {
+ if (($ID === false) || (!isset($this->_lineStyles[$ID]))) {
+ $ID = key($this->_lineStyles);
+ if (!next($this->_lineStyles)) {
+ reset($this->_lineStyles);
+ }
+ }
+ $lineStyle =& $this->_lineStyles[$ID];
+
+ if (is_object($lineStyle)) {
+ return $lineStyle->_getLineStyle($ID);
+ } elseif ($lineStyle !== null) {
+ return $lineStyle;
+ } else {
+ return parent::_getLineStyle($ID);
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Dashed.php,v 1.6 2005/08/24 20:35:52 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Line/Formatted.php\r
- */\r
-require_once 'Image/Graph/Line/Formatted.php';\r
-\r
-/**\r
- * Dashed line style.\r
- *\r
- * This style displays as a short line with a shorter space afterwards, i.e\r
- * 4px color1, 2px color2, 4px color1, etc.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Line_Dashed extends Image_Graph_Line_Formatted\r
-{\r
-\r
- /**\r
- * Image_Graph_DashedLine [Constructor]\r
- *\r
- * @param mixed $color1 The color for the 'dashes'\r
- * @param mixed $color2 The color for the 'spaces'\r
- */\r
- function Image_Graph_Line_Dashed($color1, $color2)\r
- {\r
- parent::Image_Graph_Line_Formatted(\r
- array(\r
- $color1,\r
- $color1,\r
- $color1,\r
- $color1,\r
- $color2,\r
- $color2\r
- )\r
- );\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Dashed.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Line/Formatted.php
+ */
+require_once 'Image/Graph/Line/Formatted.php';
+
+/**
+ * Dashed line style.
+ *
+ * This style displays as a short line with a shorter space afterwards, i.e
+ * 4px color1, 2px color2, 4px color1, etc.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Line_Dashed extends Image_Graph_Line_Formatted
+{
+
+ /**
+ * Image_Graph_DashedLine [Constructor]
+ *
+ * @param mixed $color1 The color for the 'dashes'
+ * @param mixed $color2 The color for the 'spaces'
+ */
+ function Image_Graph_Line_Dashed($color1, $color2)
+ {
+ parent::__construct(
+ array(
+ $color1,
+ $color1,
+ $color1,
+ $color1,
+ $color2,
+ $color2
+ )
+ );
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Dotted.php,v 1.6 2005/08/24 20:35:52 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Line/Formatted.php\r
- */\r
-require_once 'Image/Graph/Line/Formatted.php';\r
-\r
-/**\r
- * Dotted line style.\r
- *\r
- * This style displays as a short line with a shorter space afterwards, i.e\r
- * 1px color1, 1px color2, 1px color1, etc.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Line_Dotted extends Image_Graph_Line_Formatted\r
-{\r
-\r
- /**\r
- * DottedLine [Constructor]\r
- *\r
- * @param mixed $color1 The color representing the dots\r
- * @param mixed $color2 The color representing the spaces\r
- */\r
- function Image_Graph_Line_Dotted($color1, $color2)\r
- {\r
- parent::Image_Graph_Line_Formatted(array ($color1, $color2));\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Dotted.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Line/Formatted.php
+ */
+require_once 'Image/Graph/Line/Formatted.php';
+
+/**
+ * Dotted line style.
+ *
+ * This style displays as a short line with a shorter space afterwards, i.e
+ * 1px color1, 1px color2, 1px color1, etc.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Line_Dotted extends Image_Graph_Line_Formatted
+{
+
+ /**
+ * DottedLine [Constructor]
+ *
+ * @param mixed $color1 The color representing the dots
+ * @param mixed $color2 The color representing the spaces
+ */
+ function Image_Graph_Line_Dotted($color1, $color2)
+ {
+ parent::__construct(array($color1, $color2));
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Formatted.php,v 1.6 2005/08/24 20:35:51 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Line/Solid.php\r
- */\r
-require_once 'Image/Graph/Line/Solid.php';\r
-\r
-/**\r
- * Formatted user defined line style.\r
- *\r
- * Use this to create a user defined line style. Specify an array of colors that are to\r
- * be used for displaying the line.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Line_Formatted extends Image_Graph_Line_Solid\r
-{\r
-\r
- /**\r
- * The style of the line\r
- *\r
- * @var array\r
- * @access private\r
- */\r
- var $_style;\r
-\r
- /**\r
- * Image_Graph_FormattedLine [Constructor]\r
- *\r
- * @param array $style The style of the line\r
- */\r
- function Image_Graph_Line_Formatted($style)\r
- {\r
- parent::Image_Graph_Line_Solid(reset($style));\r
- $this->_style = $style;\r
- }\r
-\r
- /**\r
- * Gets the line style of the element\r
- *\r
- * @return int A GD linestyle representing the line style\r
- * @see Image_Graph_Line\r
- * @access private\r
- */\r
- function _getLineStyle()\r
- {\r
- return array(\r
- 'color' => $this->_style,\r
- 'thickness' => $this->_thickness\r
- );\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Formatted.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Line/Solid.php
+ */
+require_once 'Image/Graph/Line/Solid.php';
+
+/**
+ * Formatted user defined line style.
+ *
+ * Use this to create a user defined line style. Specify an array of colors that are to
+ * be used for displaying the line.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Line_Formatted extends Image_Graph_Line_Solid
+{
+
+ /**
+ * The style of the line
+ *
+ * @var array
+ * @access private
+ */
+ var $_style;
+
+ /**
+ * Image_Graph_FormattedLine [Constructor]
+ *
+ * @param array $style The style of the line
+ */
+ function Image_Graph_Line_Formatted($style)
+ {
+ parent::__construct(reset($style));
+ $this->_style = $style;
+ }
+
+ /**
+ * Gets the line style of the element
+ *
+ * @return int A GD linestyle representing the line style
+ * @see Image_Graph_Line
+ * @access private
+ */
+ function _getLineStyle()
+ {
+ return array(
+ 'color' => $this->_style,
+ 'thickness' => $this->_thickness
+ );
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Solid.php,v 1.6 2005/08/24 20:35:51 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Common.php\r
- */\r
-require_once 'Image/Graph/Common.php';\r
-\r
-/**\r
- * Simple colored line style.\r
- *\r
- * Use a color for line style.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Line\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Line_Solid extends Image_Graph_Common\r
-{\r
-\r
- /**\r
- * The thickness of the line (requires GD 2)\r
- * @var int\r
- * @access private\r
- */\r
- var $_thickness = 1;\r
-\r
- /**\r
- * The color of the line\r
- * @var mixed\r
- * @access private\r
- */\r
- var $_color;\r
-\r
- /**\r
- * Image_Graph_SolidLine [Constructor]\r
- *\r
- * @param mixed $color The color of the line\r
- */\r
- function Image_Graph_Line_Solid($color)\r
- {\r
- parent::Image_Graph_Common();\r
- $this->_color = $color;\r
- }\r
-\r
- /**\r
- * Set the thickness of the linestyle\r
- *\r
- * @param int $thickness The line width in pixels\r
- */\r
- function setThickness($thickness)\r
- {\r
- $this->_thickness = $thickness;\r
- }\r
-\r
- /**\r
- * Gets the line style of the element\r
- *\r
- * @return int A GD linestyle representing the line style\r
- * @see Image_Graph_Line\r
- * @access private\r
- */\r
- function _getLineStyle()\r
- {\r
- return array(\r
- 'color' => $this->_color,\r
- 'thickness' => $this->_thickness\r
- );\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Solid.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Common.php
+ */
+require_once 'Image/Graph/Common.php';
+
+/**
+ * Simple colored line style.
+ *
+ * Use a color for line style.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Line
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Line_Solid extends Image_Graph_Common
+{
+
+ /**
+ * The thickness of the line (requires GD 2)
+ * @var int
+ * @access private
+ */
+ var $_thickness = 1;
+
+ /**
+ * The color of the line
+ * @var mixed
+ * @access private
+ */
+ var $_color;
+
+ /**
+ * Image_Graph_SolidLine [Constructor]
+ *
+ * @param mixed $color The color of the line
+ */
+ function Image_Graph_Line_Solid($color)
+ {
+ parent::__construct();
+ $this->_color = $color;
+ }
+
+ /**
+ * Set the thickness of the linestyle
+ *
+ * @param int $thickness The line width in pixels
+ *
+ * @return void
+ */
+ function setThickness($thickness)
+ {
+ $this->_thickness = $thickness;
+ }
+
+ /**
+ * Gets the line style of the element
+ *
+ * @return int A GD linestyle representing the line style
+ * @see Image_Graph_Line
+ * @access private
+ */
+ function _getLineStyle()
+ {
+ return array(
+ 'color' => $this->_color,
+ 'thickness' => $this->_thickness
+ );
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Logo\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Logo.php,v 1.9 2005/08/24 20:35:56 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Displays a logo on the canvas.\r
- *\r
- * By default the logo is displayed in the top-right corner of the canvas.\r
- * \r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Logo\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Logo extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * The file name\r
- * @var stirng\r
- * @access private\r
- */\r
- var $_filename;\r
-\r
- /**\r
- * The GD Image resource\r
- * @var resource\r
- * @access private\r
- */\r
- var $_image;\r
-\r
- /**\r
- * Alignment of the logo\r
- * @var int\r
- * @access private\r
- */\r
- var $_alignment;\r
-\r
- /**\r
- * Logo [Constructor]\r
- *\r
- * @param string $filename The filename and path of the image to use for logo\r
- */\r
- function Image_Graph_Logo($filename, $alignment = IMAGE_GRAPH_ALIGN_TOP_RIGHT)\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_filename = $filename;\r
- $this->_alignment = $alignment;\r
- }\r
-\r
- /**\r
- * Sets the parent. The parent chain should ultimately be a GraPHP object\r
- *\r
- * @see Image_Graph\r
- * @param Image_Graph_Common $parent The parent\r
- * @access private\r
- */\r
- function _setParent(& $parent)\r
- {\r
- parent::_setParent($parent);\r
- $this->_setCoords(\r
- $this->_parent->_left,\r
- $this->_parent->_top,\r
- $this->_parent->_right,\r
- $this->_parent->_bottom\r
- );\r
- }\r
-\r
- /**\r
- * Output the logo\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $align = array();\r
-\r
- if ($this->_alignment & IMAGE_GRAPH_ALIGN_LEFT) {\r
- $x = $this->_parent->_left + 2;\r
- $align['horizontal'] = 'left';\r
- } elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_RIGHT) {\r
- $x = $this->_parent->_right - 2;\r
- $align['horizontal'] = 'right';\r
- } else {\r
- $x = ($this->_parent->_left + $this->_parent->_right) / 2;\r
- $align['horizontal'] = 'center';\r
- }\r
-\r
- if ($this->_alignment & IMAGE_GRAPH_ALIGN_TOP) {\r
- $y = $this->_parent->_top + 2;\r
- $align['vertical'] = 'top';\r
- } elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_BOTTOM) {\r
- $y = $this->_parent->_bottom - 2;\r
- $align['vertical'] = 'bottom';\r
- } else {\r
- $y = ($this->_parent->_top + $this->_parent->_bottom) / 2;\r
- $align['vertical'] = 'center';\r
- }\r
-\r
- $this->_canvas->image(\r
- array(\r
- 'x' => $x,\r
- 'y' => $y,\r
- 'filename' => $this->_filename,\r
- 'alignment' => $align\r
- )\r
- );\r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Logo
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Groupen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Logo.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Displays a logo on the canvas.
+ *
+ * By default the logo is displayed in the top-right corner of the canvas.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Logo
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Groupen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Logo extends Image_Graph_Element
+{
+
+ /**
+ * The file name
+ * @var stirng
+ * @access private
+ */
+ var $_filename;
+
+ /**
+ * The GD Image resource
+ * @var resource
+ * @access private
+ */
+ var $_image;
+
+ /**
+ * Alignment of the logo
+ * @var int
+ * @access private
+ */
+ var $_alignment;
+
+ /**
+ * Logo [Constructor]
+ *
+ * @param string $filename The filename and path of the image to use for logo
+ * @param ??? $alignment Where to align logo (IMAGE_GRAPH_ALIGN_...)
+ *
+ * @return void
+ */
+ function Image_Graph_Logo($filename, $alignment = IMAGE_GRAPH_ALIGN_TOP_RIGHT)
+ {
+ parent::__construct();
+ $this->_filename = $filename;
+ $this->_alignment = $alignment;
+ }
+
+ /**
+ * Sets the parent. The parent chain should ultimately be a GraPHP object
+ *
+ * @param Image_Graph_Common &$parent The parent
+ *
+ * @return void
+ * @see Image_Graph
+ * @access private
+ */
+ function _setParent(& $parent)
+ {
+ parent::_setParent($parent);
+ $this->_setCoords(
+ $this->_parent->_left,
+ $this->_parent->_top,
+ $this->_parent->_right,
+ $this->_parent->_bottom
+ );
+ }
+
+ /**
+ * Output the logo
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $align = array();
+
+ if ($this->_alignment & IMAGE_GRAPH_ALIGN_LEFT) {
+ $x = $this->_parent->_left + 2;
+ $align['horizontal'] = 'left';
+ } elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_RIGHT) {
+ $x = $this->_parent->_right - 2;
+ $align['horizontal'] = 'right';
+ } else {
+ $x = ($this->_parent->_left + $this->_parent->_right) / 2;
+ $align['horizontal'] = 'center';
+ }
+
+ if ($this->_alignment & IMAGE_GRAPH_ALIGN_TOP) {
+ $y = $this->_parent->_top + 2;
+ $align['vertical'] = 'top';
+ } elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_BOTTOM) {
+ $y = $this->_parent->_bottom - 2;
+ $align['vertical'] = 'bottom';
+ } else {
+ $y = ($this->_parent->_top + $this->_parent->_bottom) / 2;
+ $align['vertical'] = 'center';
+ }
+
+ $this->_canvas->image(
+ array(
+ 'x' => $x,
+ 'y' => $y,
+ 'filename' => $this->_filename,
+ 'alignment' => $align
+ )
+ );
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Marker.php,v 1.8 2005/02/21 20:49:47 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plotarea/Element.php\r
- */\r
-require_once 'Image/Graph/Plotarea/Element.php';\r
-\r
-/**\r
- * Data point marker.\r
- *\r
- * The data point marker is used for marking the datapoints on a graph with some\r
- * visual label, fx. a cross, a text box with the value or an icon.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Marker extends Image_Graph_Plotarea_Element\r
-{\r
-\r
- /**\r
- * Secondary marker\r
- * @var Marker\r
- * @access private\r
- */\r
- var $_secondaryMarker = false;\r
-\r
- /**\r
- * The 'size' of the marker, the meaning depends on the specific Marker\r
- * implementation\r
- * @var int\r
- * @access private\r
- */\r
- var $_size = 6;\r
-\r
- /**\r
- * Set the 'size' of the marker\r
- *\r
- * @param int $size The 'size' of the marker, the meaning depends on the\r
- * specific Marker implementation\r
- */\r
- function setSize($size)\r
- {\r
- $this->_size = $size;\r
- }\r
-\r
- /**\r
- * Set the secondary marker\r
- *\r
- * @param Marker $secondaryMarker The secondary marker\r
- */\r
- function setSecondaryMarker(& $secondaryMarker)\r
- {\r
- $this->_secondaryMarker =& $secondaryMarker;\r
- $this->_secondaryMarker->_setParent($this);\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- if (is_a($this->_secondaryMarker, 'Image_Graph_Marker')) {\r
- $this->_secondaryMarker->_drawMarker($x, $y, $values);\r
- }\r
- }\r
-\r
- /**\r
- * Output to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done() \r
- {\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Marker.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea/Element.php
+ */
+require_once 'Image/Graph/Plotarea/Element.php';
+
+/**
+ * Data point marker.
+ *
+ * The data point marker is used for marking the datapoints on a graph with some
+ * visual label, fx. a cross, a text box with the value or an icon.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Marker extends Image_Graph_Plotarea_Element
+{
+
+ /**
+ * Secondary marker
+ * @var Marker
+ * @access private
+ */
+ var $_secondaryMarker = false;
+
+ /**
+ * The 'size' of the marker, the meaning depends on the specific Marker
+ * implementation
+ * @var int
+ * @access private
+ */
+ var $_size = 6;
+
+ /**
+ * Set the 'size' of the marker
+ *
+ * @param int $size The 'size' of the marker, the meaning depends on the
+ * specific Marker implementation
+ *
+ * @return void
+ */
+ function setSize($size)
+ {
+ $this->_size = $size;
+ }
+
+ /**
+ * Set the secondary marker
+ *
+ * @param Marker &$secondaryMarker The secondary marker
+ *
+ * @return void
+ */
+ function setSecondaryMarker(& $secondaryMarker)
+ {
+ $this->_secondaryMarker =& $secondaryMarker;
+ $this->_secondaryMarker->_setParent($this);
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ if (is_a($this->_secondaryMarker, 'Image_Graph_Marker')) {
+ $this->_secondaryMarker->_drawMarker($x, $y, $values);
+ }
+ }
+
+ /**
+ * Output to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Array.php,v 1.6 2005/02/21 20:49:50 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * A sequential array of markers.\r
- *\r
- * This is used for displaying different markers for datapoints on a chart.\r
- * This is done by adding multiple markers to a MarkerArrray structure.\r
- * The marker array will then when requested return the 'next' marker in\r
- * sequential order. It is possible to specify ID tags to each marker, which is\r
- * used to make sure some data uses a specific marker.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Array extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * The marker array\r
- * @var array\r
- * @access private\r
- */\r
- var $_markers = array ();\r
-\r
- /**\r
- * Add a marker style to the array\r
- *\r
- * @param Marker $marker The marker to add\r
- */\r
- function add(& $marker)\r
- {\r
- if (is_a($marker, 'Image_Graph_Element')) {\r
- parent::add($marker);\r
- }\r
- $this->_markers[] =& $marker;\r
- reset($this->_markers);\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $ID = key($this->_markers);\r
- if (!next($this->_markers)) {\r
- reset($this->_markers);\r
- }\r
- $marker =& $this->_markers[$ID];\r
-\r
- if ($marker != null) {\r
- $marker->_drawMarker($x, $y, $values);\r
- }\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Array.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * A sequential array of markers.
+ *
+ * This is used for displaying different markers for datapoints on a chart.
+ * This is done by adding multiple markers to a MarkerArrray structure.
+ * The marker array will then when requested return the 'next' marker in
+ * sequential order. It is possible to specify ID tags to each marker, which is
+ * used to make sure some data uses a specific marker.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Array extends Image_Graph_Marker
+{
+
+ /**
+ * The marker array
+ * @var array
+ * @access private
+ */
+ var $_markers = array ();
+
+ /**
+ * Add a marker style to the array
+ *
+ * @param Marker &$marker The marker to add
+ *
+ * @return void
+ */
+ function add(& $marker)
+ {
+ if (is_a($marker, 'Image_Graph_Element')) {
+ parent::add($marker);
+ }
+ $this->_markers[] =& $marker;
+ reset($this->_markers);
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $ID = key($this->_markers);
+ if (!next($this->_markers)) {
+ reset($this->_markers);
+ }
+ $marker =& $this->_markers[$ID];
+
+ if ($marker != null) {
+ $marker->_drawMarker($x, $y, $values);
+ }
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Asterisk.php,v 1.6 2005/08/03 21:21:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as an asterisk (*)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Asterisk extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x - $this->_size,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x + $this->_size,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x + $this->_size,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x - $this->_size,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x - $this->_size,\r
- 'y0' => $y,\r
- 'x1' => $x + $this->_size,\r
- 'y1' => $y\r
- )\r
- );\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
-\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Asterisk.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as an asterisk (*)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Asterisk extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x - $this->_size,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x + $this->_size,
+ 'y1' => $y + $this->_size
+ )
+ );
+
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x + $this->_size,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x - $this->_size,
+ 'y1' => $y + $this->_size
+ )
+ );
+
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x - $this->_size,
+ 'y0' => $y,
+ 'x1' => $x + $this->_size,
+ 'y1' => $y
+ )
+ );
+
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x,
+ 'y1' => $y + $this->_size
+ )
+ );
+
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Average.php,v 1.6 2005/08/03 21:21:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * A marker displaying the 'distance' to the datasets average value.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Average extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- if ((isset($values['AVERAGE_Y'])) &&\r
- (is_a($this->_parent, 'Image_Graph_Plot')))\r
- {\r
- $point = $this->_pointXY(\r
- array(\r
- 'X' => $values['APX'],\r
- 'Y' => $values['AVERAGE_Y']\r
- )\r
- );\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $point['X'], 'y1' => $point['Y']));\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $point['X'] - 2,\r
- 'y0' => $point['Y'],\r
- 'x1' => $point['X'] + 2,\r
- 'y1' => $point['Y']\r
- )\r
- );\r
- }\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Average.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * A marker displaying the 'distance' to the datasets average value.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Average extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ if (isset($values['AVERAGE_Y'])
+ && is_a($this->_parent, 'Image_Graph_Plot')
+ ) {
+ $point = $this->_pointXY(
+ array(
+ 'X' => $values['APX'],
+ 'Y' => $values['AVERAGE_Y']
+ )
+ );
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $point['X'], 'y1' => $point['Y']));
+
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $point['X'] - 2,
+ 'y0' => $point['Y'],
+ 'x1' => $point['X'] + 2,
+ 'y1' => $point['Y']
+ )
+ );
+ }
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Box.php,v 1.6 2005/08/03 21:21:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a box\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Box extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas\r
- * @param array $values The values representing the data the marker 'points' to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $x - $this->_size,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x + $this->_size,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Box.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a box
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Box extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $x - $this->_size,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x + $this->_size,
+ 'y1' => $y + $this->_size
+ )
+ );
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Bubble.php,v 1.5 2005/02/21 20:49:50 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker/Circle.php\r
- */\r
-require_once 'Image/Graph/Marker/Circle.php';\r
-\r
-/**\r
- * Display a circle with y-value percentage as radius (require GD2).\r
- *\r
- * This will display a circle centered on the datapoint with a radius calculated\r
- * as a percentage of the maximum value. I.e. the radius depends on the y-value\r
- * of the datapoint\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Bubble extends Image_Graph_Marker_Circle\r
-{\r
-\r
- /**\r
- * The radius of the marker when 100%\r
- * @var int\r
- * @access private\r
- */\r
- var $_size100Pct = 40;\r
-\r
- /**\r
- * Sets the maximum radius the marker can occupy\r
- *\r
- * @param int $radius The new Image_Graph_max radius\r
- */\r
- function setMaxRadius($radius)\r
- {\r
- $this->_size100Pct = $radius;\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_size = $this->_size100Pct*$values['PCT_MAX_Y']/100;\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Bubble.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker/Circle.php
+ */
+require_once 'Image/Graph/Marker/Circle.php';
+
+/**
+ * Display a circle with y-value percentage as radius (require GD2).
+ *
+ * This will display a circle centered on the datapoint with a radius calculated
+ * as a percentage of the maximum value. I.e. the radius depends on the y-value
+ * of the datapoint
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Bubble extends Image_Graph_Marker_Circle
+{
+
+ /**
+ * The radius of the marker when 100%
+ * @var int
+ * @access private
+ */
+ var $_size100Pct = 40;
+
+ /**
+ * Sets the maximum radius the marker can occupy
+ *
+ * @param int $radius The new Image_Graph_max radius
+ *
+ * @return void
+ */
+ function setMaxRadius($radius)
+ {
+ $this->_size100Pct = $radius;
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_size = $this->_size100Pct*$values['PCT_MAX_Y']/100;
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Circle.php,v 1.6 2005/08/03 21:21:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as circle (require GD2)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Circle extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * The 'size' of the marker, the meaning depends on the specific Marker\r
- * implementation\r
- * @var int\r
- * @access private\r
- */\r
- var $_size = 10;\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points' to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
-\r
- $dA = 2*pi()/($this->_size*2);\r
- $angle = 0;\r
- while ($angle < 2*pi()) {\r
- $this->_canvas->addVertex(array('x' => \r
- $x + $this->_size*cos($angle), 'y' => \r
- $y - $this->_size*sin($angle)\r
- ));\r
- $angle += $dA;\r
- }\r
-\r
- $this->_canvas->addVertex(array('x' => \r
- $x + $this->_size*cos(0), 'y' => \r
- $y - $this->_size*sin(0)\r
- ));\r
-\r
- $this->_canvas->polygon(array('connect' => true));\r
-\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Circle.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as circle (require GD2)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Circle extends Image_Graph_Marker
+{
+
+ /**
+ * The 'size' of the marker, the meaning depends on the specific Marker
+ * implementation
+ * @var int
+ * @access private
+ */
+ var $_size = 10;
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+
+ $dA = 2*pi()/($this->_size*2);
+ $angle = 0;
+ while ($angle < 2*pi()) {
+ $this->_canvas->addVertex(
+ array(
+ 'x' => $x + $this->_size*cos($angle),
+ 'y' => $y - $this->_size*sin($angle)
+ )
+ );
+ $angle += $dA;
+ }
+
+ $this->_canvas->addVertex(
+ array(
+ 'x' => $x + $this->_size*cos(0),
+ 'y' => $y - $this->_size*sin(0)
+ )
+ );
+
+ $this->_canvas->polygon(array('connect' => true));
+
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Cross.php,v 1.7 2005/08/03 21:21:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a cross.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Cross extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * The thickness of the plus in pixels (thickness is actually double this)\r
- * @var int\r
- * @access private\r
- */\r
- var $_thickness = 2;\r
- \r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas\r
- * @param array $values The values representing the data the marker 'points' to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- if ($this->_thickness > 0) {\r
- $this->_getLineStyle();\r
- $this->_getFillStyle();\r
- \r
- $d1 = round(0.7071067 * $this->_size); // cos/sin(45 de>)\r
- $d2 = round(0.7071067 * $this->_thickness); // cos/sin(45 deg)\r
- \r
- $this->_canvas->addVertex(array('x' => $x - $d1 - $d2, 'y' => $y - $d1 + $d2)); \r
- $this->_canvas->addVertex(array('x' => $x - $d1 + $d2, 'y' => $y - $d1 - $d2)); \r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y - 2 * $d2)); \r
- $this->_canvas->addVertex(array('x' => $x + $d1 - $d2, 'y' => $y - $d1 - $d2)); \r
- $this->_canvas->addVertex(array('x' => $x + $d1 + $d2, 'y' => $y - $d1 + $d2)); \r
- $this->_canvas->addVertex(array('x' => $x + 2 * $d2, 'y' => $y)); \r
- $this->_canvas->addVertex(array('x' => $x + $d1 + $d2, 'y' => $y + $d1 - $d2)); \r
- $this->_canvas->addVertex(array('x' => $x + $d1 - $d2, 'y' => $y + $d1 + $d2)); \r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y + 2 * $d2)); \r
- $this->_canvas->addVertex(array('x' => $x - $d1 + $d2, 'y' => $y + $d1 + $d2)); \r
- $this->_canvas->addVertex(array('x' => $x - $d1 - $d2, 'y' => $y + $d1 - $d2)); \r
- $this->_canvas->addVertex(array('x' => $x - 2 * $d2, 'y' => $y)); \r
- $this->_canvas->polygon(array('connect' => true));\r
- } else { \r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x - $this->_size,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x + $this->_size,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
- \r
- $this->_getLineStyle();\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x + $this->_size,\r
- 'y0' => $y - $this->_size,\r
- 'x1' => $x - $this->_size,\r
- 'y1' => $y + $this->_size\r
- )\r
- );\r
- }\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Cross.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a cross.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Cross extends Image_Graph_Marker
+{
+
+ /**
+ * The thickness of the plus in pixels (thickness is actually double this)
+ * @var int
+ * @access private
+ */
+ var $_thickness = 2;
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ if ($this->_thickness > 0) {
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+
+ $d1 = round(0.7071067 * $this->_size); // cos/sin(45 de>)
+ $d2 = round(0.7071067 * $this->_thickness); // cos/sin(45 deg)
+
+ $this->_canvas->addVertex(array('x' => $x - $d1 - $d2, 'y' => $y - $d1 + $d2));
+ $this->_canvas->addVertex(array('x' => $x - $d1 + $d2, 'y' => $y - $d1 - $d2));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y - 2 * $d2));
+ $this->_canvas->addVertex(array('x' => $x + $d1 - $d2, 'y' => $y - $d1 - $d2));
+ $this->_canvas->addVertex(array('x' => $x + $d1 + $d2, 'y' => $y - $d1 + $d2));
+ $this->_canvas->addVertex(array('x' => $x + 2 * $d2, 'y' => $y));
+ $this->_canvas->addVertex(array('x' => $x + $d1 + $d2, 'y' => $y + $d1 - $d2));
+ $this->_canvas->addVertex(array('x' => $x + $d1 - $d2, 'y' => $y + $d1 + $d2));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y + 2 * $d2));
+ $this->_canvas->addVertex(array('x' => $x - $d1 + $d2, 'y' => $y + $d1 + $d2));
+ $this->_canvas->addVertex(array('x' => $x - $d1 - $d2, 'y' => $y + $d1 - $d2));
+ $this->_canvas->addVertex(array('x' => $x - 2 * $d2, 'y' => $y));
+ $this->_canvas->polygon(array('connect' => true));
+ } else {
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x - $this->_size,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x + $this->_size,
+ 'y1' => $y + $this->_size
+ )
+ );
+
+ $this->_getLineStyle();
+ $this->_canvas->line(
+ array(
+ 'x0' => $x + $this->_size,
+ 'y0' => $y - $this->_size,
+ 'x1' => $x - $this->_size,
+ 'y1' => $y + $this->_size
+ )
+ );
+ }
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Diamond.php,v 1.6 2005/08/03 21:21:55 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a diamond.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Diamond extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas\r
- * @param array $values The values representing the data the marker 'points' to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y));\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y));\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y + $this->_size));\r
- $this->_canvas->polygon(array('connect' => true));\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Diamond.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a diamond.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Diamond extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));
+ $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y + $this->_size));
+ $this->_canvas->polygon(array('connect' => true));
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Icon.php,v 1.8 2005/08/24 20:35:53 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker using an image as icon.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Icon extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Filename of the image icon\r
- * @var string\r
- * @access private\r
- */\r
- var $_filename;\r
-\r
- /**\r
- * X Point of the icon to use as data 'center'\r
- * @var int\r
- * @access private\r
- */\r
- var $_pointX = 0;\r
-\r
- /**\r
- * Y Point of the icon to use as data 'center'\r
- * @var int\r
- * @access private\r
- */\r
- var $_pointY = 0;\r
-\r
- /**\r
- * Create an icon marker\r
- *\r
- * @param string $filename The filename of the icon\r
- * @param int $width The 'new' width of the icon if it is to be resized\r
- * @param int $height The 'new' height of the icon if it is to be resized\r
- */\r
- function Image_Graph_Marker_Icon($filename, $width = 0, $height = 0)\r
- {\r
- parent::Image_Graph_Marker();\r
- $this->_filename = $filename;\r
- }\r
-\r
- /**\r
- * Set the X 'center' point of the marker\r
- *\r
- * @param int $x The X 'center' point of the marker\r
- */\r
- function setPointX($x)\r
- {\r
- $this->_pointX = $x;\r
- }\r
-\r
- /**\r
- * Set the Y 'center' point of the marker\r
- *\r
- * @param int $y The Y 'center' point of the marker\r
- */\r
- function setPointY($y)\r
- {\r
- $this->_pointY = $y;\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- parent::_drawMarker($x, $y, $values);\r
- if ($this->_filename) {\r
- $this->_canvas->image(\r
- array(\r
- 'x' => $x, \r
- 'y' => $y, \r
- 'filename' => $this->_filename, \r
- 'alignment' => array('horizontal' => 'center', 'vertical' => 'center')\r
- )\r
- );\r
- }\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Icon.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker using an image as icon.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Icon extends Image_Graph_Marker
+{
+
+ /**
+ * Filename of the image icon
+ * @var string
+ * @access private
+ */
+ var $_filename;
+
+ /**
+ * X Point of the icon to use as data 'center'
+ * @var int
+ * @access private
+ */
+ var $_pointX = 0;
+
+ /**
+ * Y Point of the icon to use as data 'center'
+ * @var int
+ * @access private
+ */
+ var $_pointY = 0;
+
+ /**
+ * Create an icon marker
+ *
+ * @param string $filename The filename of the icon
+ * @param int $width The 'new' width of the icon if it is to be resized
+ * @param int $height The 'new' height of the icon if it is to be resized
+ *
+ * @return void
+ */
+ function Image_Graph_Marker_Icon($filename, $width = 0, $height = 0)
+ {
+ parent::__construct();
+ $this->_filename = $filename;
+ }
+
+ /**
+ * Set the X 'center' point of the marker
+ *
+ * @param int $x The X 'center' point of the marker
+ *
+ * @return void
+ */
+ function setPointX($x)
+ {
+ $this->_pointX = $x;
+ }
+
+ /**
+ * Set the Y 'center' point of the marker
+ *
+ * @param int $y The Y 'center' point of the marker
+ *
+ * @return void
+ */
+ function setPointY($y)
+ {
+ $this->_pointY = $y;
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ parent::_drawMarker($x, $y, $values);
+ if ($this->_filename) {
+ $this->_canvas->image(
+ array(
+ 'x' => $x,
+ 'y' => $y,
+ 'filename' => $this->_filename,
+ 'alignment' => array('horizontal' => 'center', 'vertical' => 'center')
+ )
+ );
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Pinpoint.php,v 1.5 2005/08/24 20:35:53 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker/Icon.php\r
- */\r
-require_once 'Image/Graph/Marker/Icon.php';\r
-\r
-/**\r
- * Data marker using a pinpoint as marker.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Pinpoint extends Image_Graph_Marker_Icon\r
-{\r
-\r
- /**\r
- * Create the marker as a pin point\r
- */\r
- function Image_Graph_Marker_Pinpoint()\r
- {\r
- parent::Image_Graph_Marker_Icon(\r
- dirname(__FILE__).'/../Images/Icons/pinpoint.png'\r
- );\r
- $this->setPointX(0);\r
- $this->setPointY(13);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Pinpoint.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker/Icon.php
+ */
+require_once 'Image/Graph/Marker/Icon.php';
+
+/**
+ * Data marker using a pinpoint as marker.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Pinpoint extends Image_Graph_Marker_Icon
+{
+
+ /**
+ * Create the marker as a pin point
+ */
+ function Image_Graph_Marker_Pinpoint()
+ {
+ parent::__construct(
+ dirname(__FILE__).'/../Images/Icons/pinpoint.png'
+ );
+ $this->setPointX(0);
+ $this->setPointY(13);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Plus.php,v 1.7 2005/08/03 21:21:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a plus.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Plus extends Image_Graph_Marker\r
-{\r
- \r
- /**\r
- * The thickness of the plus in pixels (thickness is actually double this)\r
- * @var int\r
- * @access private\r
- */\r
- var $_thickness = 2;\r
- \r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- if ($this->_thickness > 0) {\r
- $this->_getLineStyle();\r
- $this->_getFillStyle();\r
- $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y - $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y - $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y - $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y - $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y - $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y - $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y + $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y + $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y + $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y + $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y + $this->_thickness));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y + $this->_thickness));\r
- $this->_canvas->polygon(array('connect' => true));\r
- } else {\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x - $this->_size, 'y0' => $y, 'x1' => $x + $this->_size, 'y1' => $y));\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y - $this->_size, 'x1' => $x, 'y1' => $y + $this->_size));\r
- }\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Plus.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a plus.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Plus extends Image_Graph_Marker
+{
+
+ /**
+ * The thickness of the plus in pixels (thickness is actually double this)
+ * @var int
+ * @access private
+ */
+ var $_thickness = 2;
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ if ($this->_thickness > 0) {
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+ $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y - $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y - $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y - $this->_size));
+ $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y - $this->_size));
+ $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y - $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y - $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y + $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y + $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x + $this->_thickness, 'y' => $y + $this->_size));
+ $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y + $this->_size));
+ $this->_canvas->addVertex(array('x' => $x - $this->_thickness, 'y' => $y + $this->_thickness));
+ $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y + $this->_thickness));
+ $this->_canvas->polygon(array('connect' => true));
+ } else {
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x - $this->_size, 'y0' => $y, 'x1' => $x + $this->_size, 'y1' => $y));
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y - $this->_size, 'x1' => $x, 'y1' => $y + $this->_size));
+ }
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Pointing.php,v 1.8 2005/08/24 20:35:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
- \r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a 'pointing marker'.\r
- *\r
- * Points to the data using another marker (as start and/or end)\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Pointing extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * The starting marker\r
- * @var Marker\r
- * @access private\r
- */\r
- var $_markerStart;\r
-\r
- /**\r
- * The ending marker\r
- * @var Marker\r
- * @access private\r
- */\r
- var $_markerEnd;\r
-\r
- /**\r
- * The X offset from the 'data'\r
- * @var int\r
- * @access private\r
- */\r
- var $_deltaX = -1;\r
-\r
- /**\r
- * The Y offset from the 'data'\r
- * @var int\r
- * @access private\r
- */\r
- var $_deltaY = -1;\r
-\r
- /**\r
- * Create an pointing marker, ie a pin on a board\r
- *\r
- * @param int $deltaX The the X offset from the real 'data' point\r
- * @param int $deltaY The the Y offset from the real 'data' point\r
- * @param Marker $markerEnd The ending marker that represents 'the head of\r
- * the pin'\r
- */\r
- function Image_Graph_Marker_Pointing($deltaX, $deltaY, & $markerEnd)\r
- {\r
- parent::Image_Graph_Marker();\r
- $this->_deltaX = $deltaX;\r
- $this->_deltaY = $deltaY;\r
- $this->_markerStart = null;\r
- $this->_markerEnd =& $markerEnd;\r
- }\r
-\r
- /**\r
- * Sets the starting marker, ie the tip of the pin on a board\r
- *\r
- * @param Marker $markerStart The starting marker that represents 'the tip\r
- * of the pin'\r
- */\r
- function setMarkerStart(& $markerStart)\r
- {\r
- $this->_markerStart =& $markerStart;\r
- $this->_markerStart->_setParent($this);\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- parent::_drawMarker($x, $y, $values);\r
- if ($this->_markerStart) {\r
- $this->_markerStart->_setParent($this);\r
- $this->_markerStart->_drawMarker($x, $y, $values);\r
- }\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $this->_deltaX, 'y1' => $y + $this->_deltaY));\r
- $this->_markerEnd->_setParent($this);\r
- $this->_markerEnd->_drawMarker(\r
- $x + $this->_deltaX,\r
- $y + $this->_deltaY,\r
- $values\r
- );\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Pointing.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a 'pointing marker'.
+ *
+ * Points to the data using another marker (as start and/or end)
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Pointing extends Image_Graph_Marker
+{
+
+ /**
+ * The starting marker
+ * @var Marker
+ * @access private
+ */
+ var $_markerStart;
+
+ /**
+ * The ending marker
+ * @var Marker
+ * @access private
+ */
+ var $_markerEnd;
+
+ /**
+ * The X offset from the 'data'
+ * @var int
+ * @access private
+ */
+ var $_deltaX = -1;
+
+ /**
+ * The Y offset from the 'data'
+ * @var int
+ * @access private
+ */
+ var $_deltaY = -1;
+
+ /**
+ * Create an pointing marker, ie a pin on a board
+ *
+ * @param int $deltaX The the X offset from the real 'data' point
+ * @param int $deltaY The the Y offset from the real 'data' point
+ * @param Marker &$markerEnd The ending marker that represents 'the head of
+ * the pin'
+ */
+ function Image_Graph_Marker_Pointing($deltaX, $deltaY, & $markerEnd)
+ {
+ parent::__construct();
+ $this->_deltaX = $deltaX;
+ $this->_deltaY = $deltaY;
+ $this->_markerStart = null;
+ $this->_markerEnd =& $markerEnd;
+ }
+
+ /**
+ * Sets the starting marker, ie the tip of the pin on a board
+ *
+ * @param Marker &$markerStart The starting marker that represents 'the tip
+ * of the pin'
+ *
+ * @return void
+ */
+ function setMarkerStart(& $markerStart)
+ {
+ $this->_markerStart =& $markerStart;
+ $this->_markerStart->_setParent($this);
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ parent::_drawMarker($x, $y, $values);
+ if ($this->_markerStart) {
+ $this->_markerStart->_setParent($this);
+ $this->_markerStart->_drawMarker($x, $y, $values);
+ }
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $this->_deltaX, 'y1' => $y + $this->_deltaY));
+ $this->_markerEnd->_setParent($this);
+ $this->_markerEnd->_drawMarker(
+ $x + $this->_deltaX,
+ $y + $this->_deltaY,
+ $values
+ );
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Angular.php,v 1.5 2005/08/24 20:36:03 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker/Pointing.php\r
- */\r
-require_once 'Image/Graph/Marker/Pointing.php';\r
-\r
-/**\r
- * Marker that points 'away' from the graph.\r
- *\r
- * Use this as a marker for displaying another marker pointing to the original\r
- * point on the graph - where the 'pointer' is calculated as line orthogonal to\r
- * a line drawn between the points neighbours to both sides (an approximate\r
- * tangent). This should make an the pointer appear to point 'straight' out from\r
- * the graph. The 'head' of the pointer is then another marker of any choice.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Pointing_Angular extends Image_Graph_Marker_Pointing\r
-{\r
-\r
- /**\r
- * The length of the angular marker\r
- * @var int\r
- * @access private\r
- */\r
- var $_radius;\r
-\r
- /**\r
- * Image_Graph_AngularPointingMarker [Constructor]\r
- * @param int $radius The 'length' of the pointer\r
- * @param Marker $markerEnd The ending marker that represents 'the head of\r
- * the pin'\r
- */\r
- function Image_Graph_Marker_Pointing_Angular($radius, & $markerEnd)\r
- {\r
- parent::Image_Graph_Marker_Pointing(0, 0, $markerEnd);\r
- $this->_radius = $radius;\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- if ((isset($values['LENGTH'])) && ($values['LENGTH'] != 0)) {\r
- $this->_deltaX = - $values['AX'] * $this->_radius / $values['LENGTH'];\r
- $this->_deltaY = - $values['AY'] * $this->_radius / $values['LENGTH'];\r
- }\r
-\r
- if ((isset($values['NPY'])) && (isset($values['APY'])) &&\r
- (isset($values['PPY'])) && ($values['NPY'] > $values['APY']) &&\r
- ($values['PPY'] > $values['APY']))\r
- {\r
- $this->_deltaX = - $this->_deltaX;\r
- $this->_deltaY = - $this->_deltaY;\r
- }\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Angular.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker/Pointing.php
+ */
+require_once 'Image/Graph/Marker/Pointing.php';
+
+/**
+ * Marker that points 'away' from the graph.
+ *
+ * Use this as a marker for displaying another marker pointing to the original
+ * point on the graph - where the 'pointer' is calculated as line orthogonal to
+ * a line drawn between the points neighbours to both sides (an approximate
+ * tangent). This should make an the pointer appear to point 'straight' out from
+ * the graph. The 'head' of the pointer is then another marker of any choice.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Pointing_Angular extends Image_Graph_Marker_Pointing
+{
+
+ /**
+ * The length of the angular marker
+ * @var int
+ * @access private
+ */
+ var $_radius;
+
+ /**
+ * Image_Graph_AngularPointingMarker [Constructor]
+ * @param int $radius The 'length' of the pointer
+ * @param Marker $markerEnd The ending marker that represents 'the head of
+ * the pin'
+ */
+ function Image_Graph_Marker_Pointing_Angular($radius, & $markerEnd)
+ {
+ parent::Image_Graph_Marker_Pointing(0, 0, $markerEnd);
+ $this->_radius = $radius;
+ }
+
+ /**
+ * Draw the marker on the canvas
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ if ((isset($values['LENGTH'])) && ($values['LENGTH'] != 0)) {
+ $this->_deltaX = - $values['AX'] * $this->_radius / $values['LENGTH'];
+ $this->_deltaY = - $values['AY'] * $this->_radius / $values['LENGTH'];
+ }
+
+ if ((isset($values['NPY'])) && (isset($values['APY'])) &&
+ (isset($values['PPY'])) && ($values['NPY'] > $values['APY']) &&
+ ($values['PPY'] > $values['APY']))
+ {
+ $this->_deltaX = - $this->_deltaX;
+ $this->_deltaY = - $this->_deltaY;
+ }
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Radial.php,v 1.5 2005/08/24 20:36:03 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker/Pointing.php\r
- */\r
-require_once 'Image/Graph/Marker/Pointing.php';\r
-\r
-/**\r
- * A pointing marker in a random angle from the data\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Pointing_Radial extends Image_Graph_Marker_Pointing\r
-{\r
-\r
- /**\r
- * The radius of the radial marker\r
- * @var int\r
- * @access private\r
- */\r
- var $_radius;\r
-\r
- /**\r
- * Create an radial pointing marker, ie a marker on a defined distance from\r
- * the data\r
- * @param int $radius The 'length' of the pointer\r
- * @param Marker $markerEnd The ending marker that represents 'the head of\r
- * the pin'\r
- */\r
- function Image_Graph_Marker_Pointing_Radial($radius, & $markerEnd)\r
- {\r
- parent::Image_Graph_Marker_Pointing(0, 0, $markerEnd);\r
- $this->_radius = $radius;\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $angle = pi() * rand(0, 360) / 180;\r
- $this->_deltaX = $this->_radius * cos($angle);\r
- $this->_deltaY = $this->_radius * sin($angle);\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Radial.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker/Pointing.php
+ */
+require_once 'Image/Graph/Marker/Pointing.php';
+
+/**
+ * A pointing marker in a random angle from the data
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Pointing_Radial extends Image_Graph_Marker_Pointing
+{
+
+ /**
+ * The radius of the radial marker
+ * @var int
+ * @access private
+ */
+ var $_radius;
+
+ /**
+ * Create an radial pointing marker, ie a marker on a defined distance from
+ * the data
+ * @param int $radius The 'length' of the pointer
+ * @param Marker $markerEnd The ending marker that represents 'the head of
+ * the pin'
+ */
+ function Image_Graph_Marker_Pointing_Radial($radius, & $markerEnd)
+ {
+ parent::Image_Graph_Marker_Pointing(0, 0, $markerEnd);
+ $this->_radius = $radius;
+ }
+
+ /**
+ * Draw the marker on the canvas
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $angle = pi() * rand(0, 360) / 180;
+ $this->_deltaX = $this->_radius * cos($angle);
+ $this->_deltaY = $this->_radius * sin($angle);
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: ReversePinpoint.php,v 1.5 2005/08/24 20:35:53 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker/Icon.php\r
- */\r
-require_once 'Image/Graph/Marker/Icon.php';\r
-\r
-/**\r
- * Data marker using a (reverse) pinpoint as marker.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_ReversePinpoint extends Image_Graph_Marker_Icon\r
-{\r
-\r
- /**\r
- * Create the marker as a reverse pin point\r
- */\r
- function Image_Graph_Marker_ReversePinpoint()\r
- {\r
- parent::Image_Graph_Marker_Icon(\r
- dirname(__FILE__).'/../Images/Icons/pinpointr.png'\r
- );\r
- $this->setPointX(10);\r
- $this->setPointY(13);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: ReversePinpoint.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker/Icon.php
+ */
+require_once 'Image/Graph/Marker/Icon.php';
+
+/**
+ * Data marker using a (reverse) pinpoint as marker.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_ReversePinpoint extends Image_Graph_Marker_Icon
+{
+
+ /**
+ * Create the marker as a reverse pin point
+ */
+ function Image_Graph_Marker_ReversePinpoint()
+ {
+ parent::__construct(
+ dirname(__FILE__).'/../Images/Icons/pinpointr.png'
+ );
+ $this->setPointX(10);
+ $this->setPointY(13);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Star.php,v 1.2 2005/08/03 21:21:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a triangle.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Star extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- \r
- $d = $this->_size / 5;\r
- $x = round($x);\r
- $y = round($y);\r
- \r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x + round($d), 'y' => $y - round($d)));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y - round($d)));\r
- $this->_canvas->addVertex(array('x' => $x + round(2 * $d), 'y' => $y + round($d)));\r
- $this->_canvas->addVertex(array('x' => $x + round(3 * $d), 'y' => $y + $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y + round(3 * $d)));\r
- $this->_canvas->addVertex(array('x' => $x - round(3 * $d), 'y' => $y + $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x - round(2 * $d), 'y' => $y + round($d)));\r
- $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y - round($d)));\r
- $this->_canvas->addVertex(array('x' => $x - round($d), 'y' => $y - round($d)));\r
- $this->_canvas->polygon(array('connect' => true));\r
- \r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Star.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a triangle.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Star extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+
+ $d = $this->_size / 5;
+ $x = round($x);
+ $y = round($y);
+
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));
+ $this->_canvas->addVertex(array('x' => $x + round($d), 'y' => $y - round($d)));
+ $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y - round($d)));
+ $this->_canvas->addVertex(array('x' => $x + round(2 * $d), 'y' => $y + round($d)));
+ $this->_canvas->addVertex(array('x' => $x + round(3 * $d), 'y' => $y + $this->_size));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y + round(3 * $d)));
+ $this->_canvas->addVertex(array('x' => $x - round(3 * $d), 'y' => $y + $this->_size));
+ $this->_canvas->addVertex(array('x' => $x - round(2 * $d), 'y' => $y + round($d)));
+ $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y - round($d)));
+ $this->_canvas->addVertex(array('x' => $x - round($d), 'y' => $y - round($d)));
+ $this->_canvas->polygon(array('connect' => true));
+
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Triangle.php,v 1.6 2005/08/03 21:21:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * Data marker as a triangle.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Triangle extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- $this->_getFillStyle();\r
- $this->_getLineStyle();\r
- $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y + $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));\r
- $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y + $this->_size));\r
- $this->_canvas->polygon(array('connect' => true));\r
- parent::_drawMarker($x, $y, $values);\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Triangle.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * Data marker as a triangle.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Triangle extends Image_Graph_Marker
+{
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker
+ * on the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker
+ * on the canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ $this->_getFillStyle();
+ $this->_getLineStyle();
+ $this->_canvas->addVertex(array('x' => $x - $this->_size, 'y' => $y + $this->_size));
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y - $this->_size));
+ $this->_canvas->addVertex(array('x' => $x + $this->_size, 'y' => $y + $this->_size));
+ $this->_canvas->polygon(array('connect' => true));
+ parent::_drawMarker($x, $y, $values);
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Value.php,v 1.10 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Marker.php\r
- */\r
-require_once 'Image/Graph/Marker.php';\r
-\r
-/**\r
- * A marker showing the data value.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Marker\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Marker_Value extends Image_Graph_Marker\r
-{\r
-\r
- /**\r
- * Datapreproccesor to format the value\r
- * @var DataPreprocessor\r
- * @access private\r
- */\r
- var $_dataPreprocessor = null;\r
-\r
- /**\r
- * Which value to use from the data set, ie the X or Y value\r
- * @var int\r
- * @access private\r
- */\r
- var $_useValue;\r
-\r
- /**\r
- * Create a value marker, ie a box containing the value of the 'pointing\r
- * data'\r
- *\r
- * @param int $useValue Defines which value to use from the dataset, i.e. the\r
- * X or Y value\r
- */\r
- function Image_Graph_Marker_Value($useValue = IMAGE_GRAPH_VALUE_X)\r
- {\r
- parent::Image_Graph_Marker();\r
- $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);\r
- $this->_useValue = $useValue;\r
- $this->_fillStyle = 'white';\r
- $this->_borderStyle = 'black';\r
- }\r
-\r
- /**\r
- * Sets the background fill style of the element\r
- *\r
- * @param Image_Graph_Fill $background The background\r
- * @see Image_Graph_Fill\r
- */\r
- function setBackground(& $background)\r
- {\r
- $this->setFillStyle($background);\r
- }\r
-\r
- /**\r
- * Sets the background color of the element\r
- *\r
- * @param mixed $color The color\r
- */\r
- function setBackgroundColor($color)\r
- {\r
- $this->setFillColor($color);\r
- }\r
-\r
- /**\r
- * Sets a data preprocessor for formatting the values\r
- *\r
- * @param DataPreprocessor $dataPreprocessor The data preprocessor\r
- * @return Image_Graph_DataPreprocessor The data preprocessor\r
- */\r
- function &setDataPreprocessor(& $dataPreprocessor)\r
- {\r
- $this->_dataPreprocessor =& $dataPreprocessor;\r
- return $dataPreprocessor;\r
- }\r
-\r
- /**\r
- * Get the value to display\r
- *\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @return string The display value, this is the pre-preprocessor value, to\r
- * support for customized with multiple values. i.e show 'x = y' or '(x, y)'\r
- * @access private\r
- */\r
- function _getDisplayValue($values)\r
- {\r
- switch ($this->_useValue) {\r
- case IMAGE_GRAPH_VALUE_X:\r
- $value = $values['X'];\r
- break;\r
-\r
- case IMAGE_GRAPH_PCT_X_MIN:\r
- $value = $values['PCT_MIN_X'];\r
- break;\r
-\r
- case IMAGE_GRAPH_PCT_X_MAX:\r
- $value = $values['PCT_MAX_X'];\r
- break;\r
-\r
- case IMAGE_GRAPH_PCT_Y_MIN:\r
- $value = $values['PCT_MIN_Y'];\r
- break;\r
-\r
- case IMAGE_GRAPH_PCT_Y_MAX:\r
- $value = $values['PCT_MAX_Y'];\r
- break;\r
-\r
- case IMAGE_GRAPH_PCT_Y_TOTAL:\r
- if (isset($values['SUM_Y'])) {\r
- $value = 100 * $values['Y'] / $values['SUM_Y'];\r
- }\r
- else {\r
- $value = 0;\r
- } \r
- break;\r
-\r
- case IMAGE_GRAPH_POINT_ID:\r
- $value = $values['ID'];\r
- break;\r
-\r
- default:\r
- $value = $values['Y'];\r
- break;\r
- }\r
- return $value;\r
- }\r
-\r
- /**\r
- * Draw the marker on the canvas\r
- *\r
- * @param int $x The X (horizontal) position (in pixels) of the marker on\r
- * the canvas\r
- * @param int $y The Y (vertical) position (in pixels) of the marker on the\r
- * canvas\r
- * @param array $values The values representing the data the marker 'points'\r
- * to\r
- * @access private\r
- */\r
- function _drawMarker($x, $y, $values = false)\r
- {\r
- parent::_drawMarker($x, $y, $values);\r
-\r
- $value = $this->_getDisplayValue($values);\r
-\r
- if ($this->_dataPreprocessor) {\r
- $value = $this->_dataPreprocessor->_process($value);\r
- }\r
-\r
- if ($this->_defaultFontOptions !== false) {\r
- $this->_canvas->setFont($this->_defaultFontOptions);\r
- } else { \r
- $this->_canvas->setFont($this->_getFont());\r
- }\r
-\r
- $width = $this->_canvas->textWidth($value);\r
- $height = $this->_canvas->textHeight($value);\r
- $offsetX = $width/2 + $this->_padding['left'];\r
- $offsetY = $height/2 + $this->_padding['top'];\r
-\r
- $this->_getFillStyle();\r
- $this->_getBorderStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $x - $offsetX,\r
- 'y0' => $y - $offsetY,\r
- 'x1' => $x + $offsetX,\r
- 'y1' => $y + $offsetY\r
- )\r
- );\r
-\r
- $this->write($x, $y, $value, IMAGE_GRAPH_ALIGN_CENTER);\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Value.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Marker.php
+ */
+require_once 'Image/Graph/Marker.php';
+
+/**
+ * A marker showing the data value.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Marker
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Marker_Value extends Image_Graph_Marker
+{
+
+ /**
+ * Datapreproccesor to format the value
+ * @var DataPreprocessor
+ * @access private
+ */
+ var $_dataPreprocessor = null;
+
+ /**
+ * Which value to use from the data set, ie the X or Y value
+ * @var int
+ * @access private
+ */
+ var $_useValue;
+
+ /**
+ * Create a value marker, ie a box containing the value of the 'pointing
+ * data'
+ *
+ * @param int $useValue Defines which value to use from the dataset, i.e. the
+ * X or Y value
+ */
+ function Image_Graph_Marker_Value($useValue = IMAGE_GRAPH_VALUE_X)
+ {
+ parent::__construct();
+ $this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);
+ $this->_useValue = $useValue;
+ $this->_fillStyle = 'white';
+ $this->_borderStyle = 'black';
+ }
+
+ /**
+ * Sets the background fill style of the element
+ *
+ * @param Image_Graph_Fill &$background The background
+ *
+ * @return void
+ * @see Image_Graph_Fill
+ */
+ function setBackground(& $background)
+ {
+ $this->setFillStyle($background);
+ }
+
+ /**
+ * Sets the background color of the element
+ *
+ * @param mixed $color The color
+ *
+ * @return void
+ */
+ function setBackgroundColor($color)
+ {
+ $this->setFillColor($color);
+ }
+
+ /**
+ * Sets a data preprocessor for formatting the values
+ *
+ * @param DataPreprocessor &$dataPreprocessor The data preprocessor
+ *
+ * @return Image_Graph_DataPreprocessor The data preprocessor
+ */
+ function &setDataPreprocessor(& $dataPreprocessor)
+ {
+ $this->_dataPreprocessor =& $dataPreprocessor;
+ return $dataPreprocessor;
+ }
+
+ /**
+ * Get the value to display
+ *
+ * @param array $values The values representing the data the marker 'points' to
+ *
+ * @return string The display value, this is the pre-preprocessor value, to
+ * support for customized with multiple values. i.e show 'x = y' or '(x, y)'
+ * @access private
+ */
+ function _getDisplayValue($values)
+ {
+ switch ($this->_useValue) {
+ case IMAGE_GRAPH_VALUE_X:
+ $value = $values['X'];
+ break;
+
+ case IMAGE_GRAPH_PCT_X_MIN:
+ $value = $values['PCT_MIN_X'];
+ break;
+
+ case IMAGE_GRAPH_PCT_X_MAX:
+ $value = $values['PCT_MAX_X'];
+ break;
+
+ case IMAGE_GRAPH_PCT_Y_MIN:
+ $value = $values['PCT_MIN_Y'];
+ break;
+
+ case IMAGE_GRAPH_PCT_Y_MAX:
+ $value = $values['PCT_MAX_Y'];
+ break;
+
+ case IMAGE_GRAPH_PCT_Y_TOTAL:
+ if (isset($values['SUM_Y'])) {
+ $value = 100 * $values['Y'] / $values['SUM_Y'];
+ } else {
+ $value = 0;
+ }
+ break;
+
+ case IMAGE_GRAPH_POINT_ID:
+ $value = $values['ID'];
+ break;
+
+ default:
+ $value = $values['Y'];
+ break;
+ }
+ return $value;
+ }
+
+ /**
+ * Draw the marker on the canvas
+ *
+ * @param int $x The X (horizontal) position (in pixels) of the marker on
+ * the canvas
+ * @param int $y The Y (vertical) position (in pixels) of the marker on the
+ * canvas
+ * @param array $values The values representing the data the marker 'points'
+ * to
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker($x, $y, $values = false)
+ {
+ parent::_drawMarker($x, $y, $values);
+
+ $value = $this->_getDisplayValue($values);
+
+ if ($this->_dataPreprocessor) {
+ $value = $this->_dataPreprocessor->_process($value);
+ }
+
+ if ($this->_defaultFontOptions !== false) {
+ $this->_canvas->setFont($this->_defaultFontOptions);
+ } else {
+ $this->_canvas->setFont($this->_getFont());
+ }
+
+ $width = $this->_canvas->textWidth($value);
+ $height = $this->_canvas->textHeight($value);
+ $offsetX = $width/2 + $this->_padding['left'];
+ $offsetY = $height/2 + $this->_padding['top'];
+
+ $this->_getFillStyle();
+ $this->_getBorderStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $x - $offsetX,
+ 'y0' => $y - $offsetY,
+ 'x1' => $x + $offsetX,
+ 'y1' => $y + $offsetY
+ )
+ );
+
+ $this->write($x, $y, $value, IMAGE_GRAPH_ALIGN_CENTER);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Plot.php,v 1.20 2006/02/28 22:33:00 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plotarea/Element.php\r
- */\r
-require_once 'Image/Graph/Plotarea/Element.php';\r
-\r
-/**\r
- * Framework for a chart\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Plot extends Image_Graph_Plotarea_Element\r
-{\r
-\r
- /**\r
- * The dataset to plot\r
- * @var Dataset\r
- * @access private\r
- */\r
- var $_dataset;\r
-\r
- /**\r
- * The marker to plot the data set as\r
- * @var Marker\r
- * @access private\r
- */\r
- var $_marker = null;\r
-\r
- /**\r
- * The dataselector to use for data marking\r
- * @var DataSelector\r
- * @access private\r
- */\r
- var $_dataSelector = null;\r
-\r
- /**\r
- * The Y axis to associate the plot with\r
- * @var int\r
- * @access private\r
- */\r
- var $_axisY = IMAGE_GRAPH_AXIS_Y;\r
-\r
- /**\r
- * The type of the plot if multiple datasets are used\r
- * @var string\r
- * @access private\r
- */\r
- var $_multiType = 'normal';\r
-\r
- /**\r
- * The title of the plot, used for legending in case of simple plots\r
- * @var string\r
- * @access private\r
- */\r
- var $_title = 'plot';\r
-\r
- /**\r
- * PlotType [Constructor]\r
- *\r
- * Valid values for multiType are:\r
- *\r
- * 'normal' Plot is normal, multiple datasets are displayes next to one\r
- * another\r
- *\r
- * 'stacked' Datasets are stacked on top of each other\r
- *\r
- * 'stacked100pct' Datasets are stacked and displayed as percentages of the\r
- * total sum\r
- *\r
- * I no title is specified a default is used, which is basically the plot\r
- * type (fx. for a 'Image_Graph_Plot_Smoothed_Area' default title is\r
- * 'Smoothed Area')\r
- *\r
- * @param Image_Graph_Dataset $dataset The data set (value containter) to\r
- * plot or an array of datasets\r
- * @param string $multiType The type of the plot\r
- * @param string $title The title of the plot (used for legends,\r
- * {@link Image_Graph_Legend})\r
- */\r
- function Image_Graph_Plot(& $dataset, $multiType = 'normal', $title = '')\r
- {\r
- if (!is_a($dataset, 'Image_Graph_Dataset')) {\r
- if (is_array($dataset)) {\r
- $keys = array_keys($dataset);\r
- foreach ($keys as $key) {\r
- if (!is_a($dataset[$key], 'Image_Graph_Dataset')) {\r
- $this->_error('Invalid dataset passed to ' . get_class($this));\r
- }\r
- }\r
- unset($keys);\r
- } else {\r
- $this->_error('Invalid dataset passed to ' . get_class($this));\r
- }\r
- }\r
-\r
- parent::Image_Graph_Common();\r
- if ($dataset) {\r
- if (is_array($dataset)) {\r
- $this->_dataset =& $dataset;\r
- } else {\r
- $this->_dataset = array(&$dataset);\r
- }\r
- }\r
- if ($title) {\r
- $this->_title = $title;\r
- } else {\r
- $this->_title = str_replace('_', ' ', substr(get_class($this), 17));\r
- }\r
-\r
- $multiType = strtolower($multiType);\r
- if (($multiType == 'normal') ||\r
- ($multiType == 'stacked') ||\r
- ($multiType == 'stacked100pct'))\r
- {\r
- $this->_multiType = $multiType;\r
- } else {\r
- $this->_error(\r
- 'Invalid multitype: ' . $multiType .\r
- ' expected (normal|stacked|stacked100pct)'\r
- );\r
- $this->_multiType = 'normal';\r
- }\r
- }\r
-\r
- /**\r
- * Sets the title of the plot, used for legend\r
- *\r
- * @param string $title The title of the plot\r
- */\r
- function setTitle($title)\r
- {\r
- $this->_title = $title;\r
- }\r
- \r
- /**\r
- * Parses the URL mapping data in the point and adds it to the parameter array used by\r
- * Image_Canvas\r
- * \r
- * @param array $point The data point (from the dataset)\r
- * @param array $canvasData The The for the canvas method\r
- * @return array The union of the canvas data points and the appropriate points for the dataset\r
- * @access private \r
- */\r
- function _mergeData($point, $canvasData)\r
- { \r
- if (isset($point['data'])) {\r
- if (isset($point['data']['url'])) {\r
- $canvasData['url'] = $point['data']['url'];\r
- }\r
- if (isset($point['data']['target'])) {\r
- $canvasData['target'] = $point['data']['target']; \r
- }\r
- if (isset($point['data']['alt'])) {\r
- $canvasData['alt'] = $point['data']['alt']; \r
- }\r
- if (isset($point['data']['htmltags'])) {\r
- $canvasData['htmltags'] = $point['data']['htmltags']; \r
- }\r
- }\r
- \r
- return $canvasData; \r
- }\r
-\r
- /**\r
- * Sets the Y axis to plot the data\r
- *\r
- * @param int $axisY The Y axis (either IMAGE_GRAPH_AXIS_Y / 'y' or\r
- * IMAGE_GRAPH_AXIS_Y_SECONDARY / 'ysec' (defaults to IMAGE_GRAPH_AXIS_Y))\r
- * @access private\r
- */\r
- function _setAxisY($axisY)\r
- {\r
- if ($axisY == 'y') {\r
- $this->_axisY = IMAGE_GRAPH_AXIS_Y;\r
- } elseif ($axisY == 'ysec') {\r
- $this->_axisY = IMAGE_GRAPH_AXIS_Y_SECONDARY;\r
- } else {\r
- $this->_axisY = $axisY;\r
- }\r
- }\r
-\r
- /**\r
- * Sets the marker to 'display' data points on the graph\r
- *\r
- * @param Marker $marker The marker\r
- */\r
- function &setMarker(& $marker)\r
- {\r
- $this->add($marker);\r
- $this->_marker =& $marker;\r
- return $marker;\r
- }\r
-\r
- /**\r
- * Sets the dataselector to specify which data should be displayed on the\r
- * plot as markers and which are not\r
- *\r
- * @param DataSelector $dataSelector The dataselector\r
- */\r
- function setDataSelector(& $dataSelector)\r
- {\r
- $this->_dataSelector =& $dataSelector;\r
- }\r
-\r
- /**\r
- * Calculate marker point data\r
- *\r
- * @param array Point The point to calculate data for\r
- * @param array NextPoint The next point\r
- * @param array PrevPoint The previous point\r
- * @param array Totals The pre-calculated totals, if needed\r
- * @return array An array containing marker point data\r
- * @access private\r
- */\r
- function _getMarkerData($point, $nextPoint, $prevPoint, & $totals)\r
- {\r
- if (is_array($this->_dataset)) {\r
- if ($this->_multiType == 'stacked') {\r
- if (!isset($totals['SUM_Y'])) {\r
- $totals['SUM_Y'] = array();\r
- }\r
- $x = $point['X'];\r
- if (!isset($totals['SUM_Y'][$x])) {\r
- $totals['SUM_Y'][$x] = 0;\r
- }\r
- } elseif ($this->_multiType == 'stacked100pct') {\r
- $x = $point['X'];\r
- if ($totals['TOTAL_Y'][$x] != 0) {\r
- if (!isset($totals['SUM_Y'])) {\r
- $totals['SUM_Y'] = array();\r
- }\r
- if (!isset($totals['SUM_Y'][$x])) {\r
- $totals['SUM_Y'][$x] = 0;\r
- }\r
- }\r
- }\r
-\r
- if (isset($totals['ALL_SUM_Y'])) {\r
- $point['SUM_Y'] = $totals['ALL_SUM_Y'];\r
- }\r
-\r
- if (!$prevPoint) {\r
- $point['AX'] = -5;\r
- $point['AY'] = 5;\r
- $point['PPX'] = 0;\r
- $point['PPY'] = 0;\r
- $point['NPX'] = $nextPoint['X'];\r
- $point['NPY'] = $nextPoint['Y'];\r
- } elseif (!$nextPoint) {\r
- $point['AX'] = 5;\r
- $point['AY'] = 5;\r
- $point['PPX'] = $prevPoint['X'];\r
- $point['PPY'] = $prevPoint['Y'];\r
- $point['NPX'] = 0;\r
- $point['NPY'] = 0;\r
- } else {\r
- $point['AX'] = $this->_pointY($prevPoint) - $this->_pointY($nextPoint);\r
- $point['AY'] = $this->_pointX($nextPoint) - $this->_pointX($prevPoint);\r
- $point['PPX'] = $prevPoint['X'];\r
- $point['PPY'] = $prevPoint['Y'];\r
- $point['NPX'] = $nextPoint['X'];\r
- $point['NPY'] = $nextPoint['Y'];\r
- }\r
-\r
- $point['APX'] = $point['X'];\r
- $point['APY'] = $point['Y'];\r
-\r
- if ((isset($totals['MINIMUM_X'])) && ($totals['MINIMUM_X'] != 0)) {\r
- $point['PCT_MIN_X'] = 100 * $point['X'] / $totals['MINIMUM_X'];\r
- }\r
- if ((isset($totals['MAXIMUM_X'])) && ($totals['MAXIMUM_X'] != 0)) {\r
- $point['PCT_MAX_X'] = 100 * $point['X'] / $totals['MAXIMUM_X'];\r
- }\r
-\r
- if ((isset($totals['MINIMUM_Y'])) && ($totals['MINIMUM_Y'] != 0)) {\r
- $point['PCT_MIN_Y'] = 100 * $point['Y'] / $totals['MINIMUM_Y'];\r
- }\r
- if ((isset($totals['MAXIMUM_Y'])) && ($totals['MAXIMUM_Y'] != 0)) {\r
- $point['PCT_MAX_Y'] = 100 * $point['Y'] / $totals['MAXIMUM_Y'];\r
- }\r
-\r
- $point['LENGTH'] = sqrt($point['AX'] * $point['AX'] +\r
- $point['AY'] * $point['AY']);\r
-\r
- if ((isset($point['LENGTH'])) && ($point['LENGTH'] != 0)) {\r
- $point['ANGLE'] = asin($point['AY'] / $point['LENGTH']);\r
- }\r
-\r
- if ((isset($point['AX'])) && ($point['AX'] > 0)) {\r
- $point['ANGLE'] = pi() - $point['ANGLE'];\r
- }\r
- \r
- if ($this->_parent->_horizontal) { \r
- $point['MARKER_Y1'] = $this->_pointY($point) -\r
- (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);\r
- \r
- $point['MARKER_Y2'] = $this->_pointY($point) +\r
- (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);\r
- \r
- $point['COLUMN_WIDTH'] = abs($point['MARKER_Y2'] -\r
- $point['MARKER_Y1']) / count($this->_dataset);\r
- \r
- $point['MARKER_Y'] = $point['MARKER_Y1'] +\r
- ((isset($totals['NUMBER']) ? $totals['NUMBER'] : 0) + 0.5) *\r
- $point['COLUMN_WIDTH'];\r
- \r
- $point['MARKER_X'] = $this->_pointX($point);\r
- \r
- if ($this->_multiType == 'stacked') {\r
- $point['MARKER_Y'] =\r
- ($point['MARKER_Y1'] + $point['MARKER_Y2']) / 2;\r
- \r
- $P1 = array('Y' => $totals['SUM_Y'][$x]);\r
- $P2 = array('Y' => $totals['SUM_Y'][$x] + $point['Y']);\r
- \r
- $point['MARKER_X'] =\r
- ($this->_pointX($P1) + $this->_pointX($P2)) / 2;\r
- } elseif ($this->_multiType == 'stacked100pct') {\r
- $x = $point['X'];\r
- if ($totals['TOTAL_Y'][$x] != 0) {\r
- $point['MARKER_Y'] =\r
- ($point['MARKER_Y1'] + $point['MARKER_Y2']) / 2;\r
- \r
- $P1 = array(\r
- 'Y' => 100 * $totals['SUM_Y'][$x] / $totals['TOTAL_Y'][$x]\r
- );\r
- \r
- $P2 = array(\r
- 'Y' => 100 * ($totals['SUM_Y'][$x] + $point['Y']) / $totals['TOTAL_Y'][$x]\r
- );\r
- \r
- $point['MARKER_X'] =\r
- ($this->_pointX($P1) + $this->_pointX($P2)) / 2;\r
- } else {\r
- $point = false;\r
- }\r
- }\r
- }\r
- else {\r
- $point['MARKER_X1'] = $this->_pointX($point) -\r
- (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);\r
- \r
- $point['MARKER_X2'] = $this->_pointX($point) +\r
- (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);\r
- \r
- $point['COLUMN_WIDTH'] = abs($point['MARKER_X2'] -\r
- $point['MARKER_X1']) / count($this->_dataset);\r
- \r
- $point['MARKER_X'] = $point['MARKER_X1'] +\r
- ((isset($totals['NUMBER']) ? $totals['NUMBER'] : 0) + 0.5) *\r
- $point['COLUMN_WIDTH'];\r
- \r
- $point['MARKER_Y'] = $this->_pointY($point);\r
- \r
- if ($this->_multiType == 'stacked') {\r
- $point['MARKER_X'] =\r
- ($point['MARKER_X1'] + $point['MARKER_X2']) / 2;\r
- \r
- $P1 = array('Y' => $totals['SUM_Y'][$x]);\r
- $P2 = array('Y' => $totals['SUM_Y'][$x] + $point['Y']);\r
- \r
- $point['MARKER_Y'] =\r
- ($this->_pointY($P1) + $this->_pointY($P2)) / 2;\r
- } elseif ($this->_multiType == 'stacked100pct') {\r
- $x = $point['X'];\r
- if ($totals['TOTAL_Y'][$x] != 0) {\r
- $point['MARKER_X'] =\r
- ($point['MARKER_X1'] + $point['MARKER_X2']) / 2;\r
- \r
- $P1 = array(\r
- 'Y' => 100 * $totals['SUM_Y'][$x] / $totals['TOTAL_Y'][$x]\r
- );\r
- \r
- $P2 = array(\r
- 'Y' => 100 * ($totals['SUM_Y'][$x] + $point['Y']) / $totals['TOTAL_Y'][$x]\r
- );\r
- \r
- $point['MARKER_Y'] =\r
- ($this->_pointY($P1) + $this->_pointY($P2)) / 2;\r
- } else {\r
- $point = false;\r
- }\r
- }\r
- }\r
- return $point;\r
- }\r
- }\r
-\r
- /**\r
- * Draws markers on the canvas\r
- *\r
- * @access private\r
- */\r
- function _drawMarker()\r
- { \r
- if (($this->_marker) && (is_array($this->_dataset))) {\r
- $this->_canvas->startGroup(get_class($this) . '_marker');\r
- \r
- $totals = $this->_getTotals();\r
- $totals['WIDTH'] = $this->width() / ($this->_maximumX() + 2) / 2;\r
-\r
- $number = 0;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $totals['MINIMUM_X'] = $dataset->minimumX();\r
- $totals['MAXIMUM_X'] = $dataset->maximumX();\r
- $totals['MINIMUM_Y'] = $dataset->minimumY();\r
- $totals['MAXIMUM_Y'] = $dataset->maximumY();\r
- $totals['NUMBER'] = $number ++;\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $prevPoint = $dataset->_nearby(-2);\r
- $nextPoint = $dataset->_nearby();\r
-\r
- $x = $point['X'];\r
- $y = $point['Y'];\r
- if (((!is_object($this->_dataSelector)) ||\r
- ($this->_dataSelector->_select($point))) && ($point['Y'] !== null))\r
- {\r
-\r
- $point = $this->_getMarkerData(\r
- $point,\r
- $nextPoint,\r
- $prevPoint,\r
- $totals\r
- );\r
-\r
- if (is_array($point)) {\r
- $this->_marker->_drawMarker(\r
- $point['MARKER_X'],\r
- $point['MARKER_Y'],\r
- $point\r
- );\r
- }\r
- }\r
- if (!isset($totals['SUM_Y'])) {\r
- $totals['SUM_Y'] = array();\r
- }\r
- if (isset($totals['SUM_Y'][$x])) {\r
- $totals['SUM_Y'][$x] += $y;\r
- } else {\r
- $totals['SUM_Y'][$x] = $y;\r
- }\r
- }\r
- }\r
- unset($keys);\r
- $this->_canvas->endGroup();\r
- } \r
- }\r
-\r
- /**\r
- * Get the minimum X value from the dataset\r
- *\r
- * @return double The minimum X value\r
- * @access private\r
- */\r
- function _minimumX()\r
- {\r
- if (!is_array($this->_dataset)) {\r
- return 0;\r
- }\r
-\r
- $min = false;\r
- if (is_array($this->_dataset)) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- if ($min === false) {\r
- $min = $this->_dataset[$key]->minimumX();\r
- } else {\r
- $min = min($min, $this->_dataset[$key]->minimumX());\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return $min;\r
- }\r
-\r
- /**\r
- * Get the maximum X value from the dataset\r
- *\r
- * @return double The maximum X value\r
- * @access private\r
- */\r
- function _maximumX()\r
- {\r
- if (!is_array($this->_dataset)) {\r
- return 0;\r
- }\r
-\r
- $max = 0;\r
- if (is_array($this->_dataset)) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $max = max($max, $this->_dataset[$key]->maximumX());\r
- }\r
- unset($keys);\r
- }\r
- return $max;\r
- }\r
-\r
- /**\r
- * Get the minimum Y value from the dataset\r
- *\r
- * @return double The minimum Y value\r
- * @access private\r
- */\r
- function _minimumY()\r
- {\r
- if (!is_array($this->_dataset)) {\r
- return 0;\r
- }\r
-\r
- $min = false;\r
- if (is_array($this->_dataset)) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- if ($this->_multiType == 'normal') {\r
- if ($min === false) {\r
- $min = $this->_dataset[$key]->minimumY();\r
- } else {\r
- $min = min($min, $this->_dataset[$key]->minimumY());\r
- }\r
- } else {\r
- if ($min === false) {\r
- $min = 0;\r
- }\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- if ($point['Y'] < 0) {\r
- $x = $point['X'];\r
- if ((!isset($total)) || (!isset($total[$x]))) {\r
- $total[$x] = $point['Y'];\r
- } else {\r
- $total[$x] += $point['Y'];\r
- }\r
- if (isset($min)) {\r
- $min = min($min, $total[$x]);\r
- } else {\r
- $min = $total[$x];\r
- }\r
- }\r
- }\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return $min;\r
- }\r
-\r
- /**\r
- * Get the maximum Y value from the dataset\r
- *\r
- * @return double The maximum Y value\r
- * @access private\r
- */\r
- function _maximumY()\r
- {\r
- if ($this->_multiType == 'stacked100pct') {\r
- return 100;\r
- }\r
-\r
- $maxY = 0;\r
- if (is_array($this->_dataset)) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
-\r
- if ($this->_multiType == 'normal') {\r
- if (isset($maxY)) {\r
- $maxY = max($maxY, $dataset->maximumY());\r
- } else {\r
- $maxY = $dataset->maximumY();\r
- }\r
- } else {\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- if ($point['Y'] > 0) {\r
- $x = $point['X'];\r
- if ((!isset($total)) || (!isset($total[$x]))) {\r
- $total[$x] = $point['Y'];\r
- } else {\r
- $total[$x] += $point['Y'];\r
- }\r
- if (isset($maxY)) {\r
- $maxY = max($maxY, $total[$x]);\r
- } else {\r
- $maxY = $total[$x];\r
- }\r
- }\r
- }\r
- }\r
- }\r
- unset($keys);\r
- }\r
- return $maxY;\r
- }\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double $point The value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($point)\r
- {\r
- $point['AXIS_Y'] = $this->_axisY;\r
- return parent::_pointX($point);\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double $point the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($point)\r
- {\r
- $point['AXIS_Y'] = $this->_axisY;\r
- return parent::_pointY($point);\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- $this->_setCoords($this->_parent->_plotLeft, $this->_parent->_plotTop, $this->_parent->_plotRight, $this->_parent->_plotBottom);\r
- parent::_updateCoords();\r
- }\r
-\r
- /**\r
- * Get the dataset\r
- *\r
- * @return Image_Graph_Dataset The dataset(s)\r
- */\r
- function &dataset()\r
- {\r
- return $this->_dataset;\r
- }\r
-\r
- /**\r
- * Calulate totals\r
- *\r
- * @return array An associated array with the totals\r
- * @access private\r
- */\r
- function _getTotals()\r
- {\r
- $total = array(\r
- 'MINIMUM_X' => $this->_minimumX(),\r
- 'MAXIMUM_X' => $this->_maximumX(),\r
- 'MINIMUM_Y' => $this->_minimumY(),\r
- 'MAXIMUM_Y' => $this->_maximumY()\r
- );\r
- $total['ALL_SUM_Y'] = 0;\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
-\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $x = $point['X'];\r
- \r
- if (is_numeric($point['Y'])) {\r
- $total['ALL_SUM_Y'] += $point['Y'];\r
- if (isset($total['TOTAL_Y'][$x])) {\r
- $total['TOTAL_Y'][$x] += $point['Y'];\r
- } else {\r
- $total['TOTAL_Y'][$x] = $point['Y'];\r
- }\r
- }\r
- \r
- if (is_numeric($point['X'])) {\r
- if (isset($total['TOTAL_X'][$x])) {\r
- $total['TOTAL_X'][$x] += $point['X'];\r
- } else {\r
- $total['TOTAL_X'][$x] = $point['X'];\r
- }\r
- }\r
- }\r
- }\r
- unset($keys);\r
- return $total;\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $this->_canvas->rectangle(array('x0' => $x0, 'y0' => $y0, 'x1' => $x1, 'y1' => $y1));\r
- }\r
-\r
- /**\r
- * Draw a sample for use with legend\r
- *\r
- * @param array $param The parameters for the legend\r
- * @access private\r
- */\r
- function _legendSample(&$param)\r
- {\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
-\r
- if (is_a($this->_fillStyle, 'Image_Graph_Fill')) {\r
- $this->_fillStyle->_reset();\r
- }\r
-\r
- $count = 0;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $count++;\r
-\r
- $caption = ($dataset->_name ? $dataset->_name : $this->_title);\r
-\r
- $this->_canvas->setFont($param['font']);\r
- $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- $param['maxwidth'] = max($param['maxwidth'], $width);\r
- $x2 = $param['x'] + $width;\r
- $y2 = $param['y'] + $param['height'] + 5;\r
-\r
- if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {\r
- $param['y'] = $param['top'];\r
- $param['x'] = $x2;\r
- $y2 = $param['y'] + $param['height'];\r
- } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {\r
- $param['x'] = $param['left'];\r
- $param['y'] = $y2;\r
- $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- }\r
-\r
- $x = $x0 = $param['x'];\r
- $y = $param['y'];\r
- $y0 = $param['y'];\r
- $x1 = $param['x'] + $param['width'];\r
- $y1 = $param['y'] + $param['height'];\r
-\r
- if (!isset($param['simulate'])) {\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle();\r
- $this->_drawLegendSample($x0, $y0, $x1, $y1);\r
-\r
- if (($this->_marker) && ($dataset) && ($param['show_marker'])) {\r
- $dataset->_reset();\r
- $point = $dataset->_next();\r
- $prevPoint = $dataset->_nearby(-2);\r
- $nextPoint = $dataset->_nearby();\r
-\r
- $tmp = array();\r
- $point = $this->_getMarkerData($point, $nextPoint, $prevPoint, $tmp);\r
- if (is_array($point)) {\r
- $point['MARKER_X'] = $x+$param['width']/2;\r
- $point['MARKER_Y'] = $y;\r
- unset ($point['AVERAGE_Y']);\r
- $this->_marker->_drawMarker($point['MARKER_X'], $point['MARKER_Y'], $point);\r
- }\r
- }\r
- $this->write($x + $param['width'] + 10, $y + $param['height'] / 2, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);\r
- }\r
-\r
- if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {\r
- $param['y'] = $y2;\r
- } else {\r
- $param['x'] = $x2;\r
- }\r
- }\r
- unset($keys);\r
- }\r
- \r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Plot.php 291755 2009-12-06 02:25:02Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea/Element.php
+ */
+require_once 'Image/Graph/Plotarea/Element.php';
+
+/**
+ * Framework for a chart
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Groupn
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Plot extends Image_Graph_Plotarea_Element
+{
+
+ /**
+ * The dataset to plot
+ * @var Dataset
+ * @access private
+ */
+ var $_dataset;
+
+ /**
+ * The marker to plot the data set as
+ * @var Marker
+ * @access private
+ */
+ var $_marker = null;
+
+ /**
+ * The dataselector to use for data marking
+ * @var DataSelector
+ * @access private
+ */
+ var $_dataSelector = null;
+
+ /**
+ * The Y axis to associate the plot with
+ * @var int
+ * @access private
+ */
+ var $_axisY = IMAGE_GRAPH_AXIS_Y;
+
+ /**
+ * The type of the plot if multiple datasets are used
+ * @var string
+ * @access private
+ */
+ var $_multiType = 'normal';
+
+ /**
+ * The title of the plot, used for legending in case of simple plots
+ * @var string
+ * @access private
+ */
+ var $_title = 'plot';
+
+ /**
+ * PlotType [Constructor]
+ *
+ * Valid values for multiType are:
+ *
+ * 'normal' Plot is normal, multiple datasets are displayes next to one
+ * another
+ *
+ * 'stacked' Datasets are stacked on top of each other
+ *
+ * 'stacked100pct' Datasets are stacked and displayed as percentages of the
+ * total sum
+ *
+ * I no title is specified a default is used, which is basically the plot
+ * type (fx. for a 'Image_Graph_Plot_Smoothed_Area' default title is
+ * 'Smoothed Area')
+ *
+ * @param Image_Graph_Dataset &$dataset The data set (value containter) to
+ * plot or an array of datasets
+ * @param string $multiType The type of the plot
+ * @param string $title The title of the plot (used for legends,
+ * {@link Image_Graph_Legend})
+ */
+ function Image_Graph_Plot(& $dataset, $multiType = 'normal', $title = '')
+ {
+ if (!is_a($dataset, 'Image_Graph_Dataset')) {
+ if (is_array($dataset)) {
+ $keys = array_keys($dataset);
+ foreach ($keys as $key) {
+ if (!is_a($dataset[$key], 'Image_Graph_Dataset')) {
+ $this->_error('Invalid dataset passed to ' . get_class($this));
+ }
+ }
+ unset($keys);
+ } else {
+ $this->_error('Invalid dataset passed to ' . get_class($this));
+ }
+ }
+
+ parent::__construct();
+ if ($dataset) {
+ if (is_array($dataset)) {
+ $this->_dataset =& $dataset;
+ } else {
+ $this->_dataset = array(&$dataset);
+ }
+ }
+ if ($title) {
+ $this->_title = $title;
+ } else {
+ $this->_title = str_replace('_', ' ', substr(get_class($this), 17));
+ }
+
+ $multiType = strtolower($multiType);
+ if (($multiType == 'normal')
+ || ($multiType == 'stacked')
+ || ($multiType == 'stacked100pct')
+ ) {
+ $this->_multiType = $multiType;
+ } else {
+ $this->_error(
+ 'Invalid multitype: ' . $multiType .
+ ' expected (normal|stacked|stacked100pct)'
+ );
+ $this->_multiType = 'normal';
+ }
+ }
+
+ /**
+ * Sets the title of the plot, used for legend
+ *
+ * @param string $title The title of the plot
+ *
+ * @return void
+ */
+ function setTitle($title)
+ {
+ $this->_title = $title;
+ }
+
+ /**
+ * Parses the URL mapping data in the point and adds it to the parameter array used by
+ * Image_Canvas
+ *
+ * @param array $point The data point (from the dataset)
+ * @param array $canvasData The The for the canvas method
+ *
+ * @return array The union of the canvas data points and the appropriate points for the dataset
+ * @access private
+ */
+ function _mergeData($point, $canvasData)
+ {
+ if (isset($point['data'])) {
+ if (isset($point['data']['url'])) {
+ $canvasData['url'] = $point['data']['url'];
+ }
+ if (isset($point['data']['target'])) {
+ $canvasData['target'] = $point['data']['target'];
+ }
+ if (isset($point['data']['alt'])) {
+ $canvasData['alt'] = $point['data']['alt'];
+ }
+ if (isset($point['data']['htmltags'])) {
+ $canvasData['htmltags'] = $point['data']['htmltags'];
+ }
+ }
+
+ return $canvasData;
+ }
+
+ /**
+ * Sets the Y axis to plot the data
+ *
+ * @param int $axisY The Y axis (either IMAGE_GRAPH_AXIS_Y / 'y' or
+ * IMAGE_GRAPH_AXIS_Y_SECONDARY / 'ysec' (defaults to IMAGE_GRAPH_AXIS_Y))
+ *
+ * @return void
+ * @access private
+ */
+ function _setAxisY($axisY)
+ {
+ if ($axisY == 'y') {
+ $this->_axisY = IMAGE_GRAPH_AXIS_Y;
+ } elseif ($axisY == 'ysec') {
+ $this->_axisY = IMAGE_GRAPH_AXIS_Y_SECONDARY;
+ } else {
+ $this->_axisY = $axisY;
+ }
+ }
+
+ /**
+ * Sets the marker to 'display' data points on the graph
+ *
+ * @param Marker &$marker The marker
+ *
+ * @return Marker
+ */
+ function &setMarker(& $marker)
+ {
+ $this->add($marker);
+ $this->_marker =& $marker;
+ return $marker;
+ }
+
+ /**
+ * Sets the dataselector to specify which data should be displayed on the
+ * plot as markers and which are not
+ *
+ * @param DataSelector &$dataSelector The dataselector
+ *
+ * @return void
+ */
+ function setDataSelector(& $dataSelector)
+ {
+ $this->_dataSelector =& $dataSelector;
+ }
+
+ /**
+ * Calculate marker point data
+ *
+ * @param array $point The point to calculate data for
+ * @param array $nextPoint The next point
+ * @param array $prevPoint The previous point
+ * @param array &$totals The pre-calculated totals, if needed
+ *
+ * @return array An array containing marker point data
+ * @access private
+ */
+ function _getMarkerData($point, $nextPoint, $prevPoint, & $totals)
+ {
+ if (is_array($this->_dataset)) {
+ if ($this->_multiType == 'stacked') {
+ if (!isset($totals['SUM_Y'])) {
+ $totals['SUM_Y'] = array();
+ }
+ $x = $point['X'];
+ if (!isset($totals['SUM_Y'][$x])) {
+ $totals['SUM_Y'][$x] = 0;
+ }
+ } elseif ($this->_multiType == 'stacked100pct') {
+ $x = $point['X'];
+ if ($totals['TOTAL_Y'][$x] != 0) {
+ if (!isset($totals['SUM_Y'])) {
+ $totals['SUM_Y'] = array();
+ }
+ if (!isset($totals['SUM_Y'][$x])) {
+ $totals['SUM_Y'][$x] = 0;
+ }
+ }
+ }
+
+ if (isset($totals['ALL_SUM_Y'])) {
+ $point['SUM_Y'] = $totals['ALL_SUM_Y'];
+ }
+
+ if (!$prevPoint) {
+ $point['AX'] = -5;
+ $point['AY'] = 5;
+ $point['PPX'] = 0;
+ $point['PPY'] = 0;
+ $point['NPX'] = $nextPoint['X'];
+ $point['NPY'] = $nextPoint['Y'];
+ } elseif (!$nextPoint) {
+ $point['AX'] = 5;
+ $point['AY'] = 5;
+ $point['PPX'] = $prevPoint['X'];
+ $point['PPY'] = $prevPoint['Y'];
+ $point['NPX'] = 0;
+ $point['NPY'] = 0;
+ } else {
+ $point['AX'] = $this->_pointY($prevPoint) - $this->_pointY($nextPoint);
+ $point['AY'] = $this->_pointX($nextPoint) - $this->_pointX($prevPoint);
+ $point['PPX'] = $prevPoint['X'];
+ $point['PPY'] = $prevPoint['Y'];
+ $point['NPX'] = $nextPoint['X'];
+ $point['NPY'] = $nextPoint['Y'];
+ }
+
+ $point['APX'] = $point['X'];
+ $point['APY'] = $point['Y'];
+
+ if ((isset($totals['MINIMUM_X'])) && ($totals['MINIMUM_X'] != 0)) {
+ $point['PCT_MIN_X'] = 100 * $point['X'] / $totals['MINIMUM_X'];
+ }
+ if ((isset($totals['MAXIMUM_X'])) && ($totals['MAXIMUM_X'] != 0)) {
+ $point['PCT_MAX_X'] = 100 * $point['X'] / $totals['MAXIMUM_X'];
+ }
+
+ if ((isset($totals['MINIMUM_Y'])) && ($totals['MINIMUM_Y'] != 0)) {
+ $point['PCT_MIN_Y'] = 100 * $point['Y'] / $totals['MINIMUM_Y'];
+ }
+ if ((isset($totals['MAXIMUM_Y'])) && ($totals['MAXIMUM_Y'] != 0)) {
+ $point['PCT_MAX_Y'] = 100 * $point['Y'] / $totals['MAXIMUM_Y'];
+ }
+
+ $point['LENGTH'] = sqrt(($point['AX'] * $point['AX']) + ($point['AY'] * $point['AY']));
+
+ if ((isset($point['LENGTH'])) && ($point['LENGTH'] != 0)) {
+ $point['ANGLE'] = asin($point['AY'] / $point['LENGTH']);
+ }
+
+ if ((isset($point['AX'])) && ($point['AX'] > 0)) {
+ $point['ANGLE'] = pi() - $point['ANGLE'];
+ }
+
+ if ($this->_parent->_horizontal) {
+ $point['MARKER_Y1'] = $this->_pointY($point) -
+ (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);
+
+ $point['MARKER_Y2'] = $this->_pointY($point) +
+ (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);
+
+ $point['COLUMN_WIDTH'] = abs(($point['MARKER_Y2'] - $point['MARKER_Y1']) / count($this->_dataset));
+
+ $point['MARKER_Y'] = $point['MARKER_Y1'] +
+ ((isset($totals['NUMBER']) ? $totals['NUMBER'] : 0) + 0.5) *
+ $point['COLUMN_WIDTH'];
+
+ $point['MARKER_X'] = $this->_pointX($point);
+
+ if ($this->_multiType == 'stacked') {
+ $point['MARKER_Y'] = ($point['MARKER_Y1'] + $point['MARKER_Y2']) / 2;
+
+ $P1 = array('Y' => $totals['SUM_Y'][$x]);
+ $P2 = array('Y' => $totals['SUM_Y'][$x] + $point['Y']);
+
+ $point['MARKER_X'] = ($this->_pointX($P1) + $this->_pointX($P2)) / 2;
+ } elseif ($this->_multiType == 'stacked100pct') {
+ $x = $point['X'];
+ if ($totals['TOTAL_Y'][$x] != 0) {
+ $point['MARKER_Y'] = ($point['MARKER_Y1'] + $point['MARKER_Y2']) / 2;
+
+ $P1 = array(
+ 'Y' => 100 * $totals['SUM_Y'][$x] / $totals['TOTAL_Y'][$x]
+ );
+
+ $P2 = array(
+ 'Y' => 100 * ($totals['SUM_Y'][$x] + $point['Y']) / $totals['TOTAL_Y'][$x]
+ );
+
+ $point['MARKER_X'] = ($this->_pointX($P1) + $this->_pointX($P2)) / 2;
+ } else {
+ $point = false;
+ }
+ }
+ } else {
+ $point['MARKER_X1'] = $this->_pointX($point) - (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);
+
+ $point['MARKER_X2'] = $this->_pointX($point) + (isset($totals['WIDTH']) ? $totals['WIDTH'] : 0);
+
+ $point['COLUMN_WIDTH'] = abs(($point['MARKER_X2'] - $point['MARKER_X1']) / count($this->_dataset));
+
+ $point['MARKER_X'] = $point['MARKER_X1'] + ((isset($totals['NUMBER']) ? $totals['NUMBER'] : 0) + 0.5) * $point['COLUMN_WIDTH'];
+
+ $point['MARKER_Y'] = $this->_pointY($point);
+
+ if ($this->_multiType == 'stacked') {
+ $point['MARKER_X'] = ($point['MARKER_X1'] + $point['MARKER_X2']) / 2;
+
+ $P1 = array('Y' => $totals['SUM_Y'][$x]);
+ $P2 = array('Y' => $totals['SUM_Y'][$x] + $point['Y']);
+
+ $point['MARKER_Y'] = ($this->_pointY($P1) + $this->_pointY($P2)) / 2;
+ } elseif ($this->_multiType == 'stacked100pct') {
+ $x = $point['X'];
+ if ($totals['TOTAL_Y'][$x] != 0) {
+ $point['MARKER_X'] = ($point['MARKER_X1'] + $point['MARKER_X2']) / 2;
+
+ $P1 = array(
+ 'Y' => 100 * $totals['SUM_Y'][$x] / $totals['TOTAL_Y'][$x]
+ );
+
+ $P2 = array(
+ 'Y' => 100 * ($totals['SUM_Y'][$x] + $point['Y']) / $totals['TOTAL_Y'][$x]
+ );
+
+ $point['MARKER_Y'] = ($this->_pointY($P1) + $this->_pointY($P2)) / 2;
+ } else {
+ $point = false;
+ }
+ }
+ }
+ return $point;
+ }
+ }
+
+ /**
+ * Draws markers on the canvas
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker()
+ {
+ if (($this->_marker) && (is_array($this->_dataset))) {
+ $this->_canvas->startGroup(get_class($this) . '_marker');
+
+ $totals = $this->_getTotals();
+ $totals['WIDTH'] = $this->width() / ($this->_maximumX() + 2) / 2;
+
+ $number = 0;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $totals['MINIMUM_X'] = $dataset->minimumX();
+ $totals['MAXIMUM_X'] = $dataset->maximumX();
+ $totals['MINIMUM_Y'] = $dataset->minimumY();
+ $totals['MAXIMUM_Y'] = $dataset->maximumY();
+ $totals['NUMBER'] = $number ++;
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $prevPoint = $dataset->_nearby(-2);
+ $nextPoint = $dataset->_nearby();
+
+ $x = $point['X'];
+ $y = $point['Y'];
+ if (((!is_object($this->_dataSelector))
+ || ($this->_dataSelector->_select($point))) && ($point['Y'] !== null)
+ ) {
+
+ $point = $this->_getMarkerData(
+ $point,
+ $nextPoint,
+ $prevPoint,
+ $totals
+ );
+
+ if (is_array($point)) {
+ $this->_marker->_drawMarker(
+ $point['MARKER_X'],
+ $point['MARKER_Y'],
+ $point
+ );
+ }
+ }
+ if (!isset($totals['SUM_Y'])) {
+ $totals['SUM_Y'] = array();
+ }
+ if (isset($totals['SUM_Y'][$x])) {
+ $totals['SUM_Y'][$x] += $y;
+ } else {
+ $totals['SUM_Y'][$x] = $y;
+ }
+ }
+ }
+ unset($keys);
+ $this->_canvas->endGroup();
+ }
+ }
+
+ /**
+ * Get the minimum X value from the dataset
+ *
+ * @return double The minimum X value
+ * @access private
+ */
+ function _minimumX()
+ {
+ if (!is_array($this->_dataset)) {
+ return 0;
+ }
+
+ $min = false;
+ if (is_array($this->_dataset)) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ if ($min === false) {
+ $min = $this->_dataset[$key]->minimumX();
+ } else {
+ $min = min($min, $this->_dataset[$key]->minimumX());
+ }
+ }
+ unset($keys);
+ }
+ return $min;
+ }
+
+ /**
+ * Get the maximum X value from the dataset
+ *
+ * @return double The maximum X value
+ * @access private
+ */
+ function _maximumX()
+ {
+ if (!is_array($this->_dataset)) {
+ return 0;
+ }
+
+ $max = 0;
+ if (is_array($this->_dataset)) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $max = max($max, $this->_dataset[$key]->maximumX());
+ }
+ unset($keys);
+ }
+ return $max;
+ }
+
+ /**
+ * Get the minimum Y value from the dataset
+ *
+ * @return double The minimum Y value
+ * @access private
+ */
+ function _minimumY()
+ {
+ if (!is_array($this->_dataset)) {
+ return 0;
+ }
+
+ $min = false;
+ if (is_array($this->_dataset)) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ if ($this->_multiType == 'normal') {
+ if ($min === false) {
+ $min = $this->_dataset[$key]->minimumY();
+ } else {
+ $min = min($min, $this->_dataset[$key]->minimumY());
+ }
+ } else {
+ if ($min === false) {
+ $min = 0;
+ }
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ if ($point['Y'] < 0) {
+ $x = $point['X'];
+ if ((!isset($total)) || (!isset($total[$x]))) {
+ $total[$x] = $point['Y'];
+ } else {
+ $total[$x] += $point['Y'];
+ }
+ if (isset($min)) {
+ $min = min($min, $total[$x]);
+ } else {
+ $min = $total[$x];
+ }
+ }
+ }
+ }
+ }
+ unset($keys);
+ }
+ return $min;
+ }
+
+ /**
+ * Get the maximum Y value from the dataset
+ *
+ * @return double The maximum Y value
+ * @access private
+ */
+ function _maximumY()
+ {
+ if ($this->_multiType == 'stacked100pct') {
+ return 100;
+ }
+
+ $maxY = 0;
+ if (is_array($this->_dataset)) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+
+ if ($this->_multiType == 'normal') {
+ if (isset($maxY)) {
+ $maxY = max($maxY, $dataset->maximumY());
+ } else {
+ $maxY = $dataset->maximumY();
+ }
+ } else {
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ if ($point['Y'] > 0) {
+ $x = $point['X'];
+ if ((!isset($total)) || (!isset($total[$x]))) {
+ $total[$x] = $point['Y'];
+ } else {
+ $total[$x] += $point['Y'];
+ }
+ if (isset($maxY)) {
+ $maxY = max($maxY, $total[$x]);
+ } else {
+ $maxY = $total[$x];
+ }
+ }
+ }
+ }
+ }
+ unset($keys);
+ }
+ return $maxY;
+ }
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $point The value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($point)
+ {
+ $point['AXIS_Y'] = $this->_axisY;
+ return parent::_pointX($point);
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $point the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($point)
+ {
+ $point['AXIS_Y'] = $this->_axisY;
+ return parent::_pointY($point);
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ $this->_setCoords($this->_parent->_plotLeft, $this->_parent->_plotTop, $this->_parent->_plotRight, $this->_parent->_plotBottom);
+ parent::_updateCoords();
+ }
+
+ /**
+ * Get the dataset
+ *
+ * @return Image_Graph_Dataset The dataset(s)
+ */
+ function &dataset()
+ {
+ return $this->_dataset;
+ }
+
+ /**
+ * Calulate totals
+ *
+ * @return array An associated array with the totals
+ * @access private
+ */
+ function _getTotals()
+ {
+ $total = array(
+ 'MINIMUM_X' => $this->_minimumX(),
+ 'MAXIMUM_X' => $this->_maximumX(),
+ 'MINIMUM_Y' => $this->_minimumY(),
+ 'MAXIMUM_Y' => $this->_maximumY()
+ );
+ $total['ALL_SUM_Y'] = 0;
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $x = $point['X'];
+
+ if (is_numeric($point['Y'])) {
+ $total['ALL_SUM_Y'] += $point['Y'];
+ if (isset($total['TOTAL_Y'][$x])) {
+ $total['TOTAL_Y'][$x] += $point['Y'];
+ } else {
+ $total['TOTAL_Y'][$x] = $point['Y'];
+ }
+ }
+
+ if (is_numeric($point['X'])) {
+ if (isset($total['TOTAL_X'][$x])) {
+ $total['TOTAL_X'][$x] += $point['X'];
+ } else {
+ $total['TOTAL_X'][$x] = $point['X'];
+ }
+ }
+ }
+ }
+ unset($keys);
+ return $total;
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $this->_canvas->rectangle(array('x0' => $x0, 'y0' => $y0, 'x1' => $x1, 'y1' => $y1));
+ }
+
+ /**
+ * Draw a sample for use with legend
+ *
+ * @param array &$param The parameters for the legend
+ *
+ * @return void
+ * @access private
+ */
+ function _legendSample(&$param)
+ {
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ if (is_a($this->_fillStyle, 'Image_Graph_Fill')) {
+ $this->_fillStyle->_reset();
+ }
+
+ $count = 0;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $count++;
+
+ $caption = ($dataset->_name ? $dataset->_name : $this->_title);
+
+ $this->_canvas->setFont($param['font']);
+ $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ $param['maxwidth'] = max($param['maxwidth'], $width);
+ $x2 = $param['x'] + $width;
+ $y2 = $param['y'] + $param['height'] + 5;
+
+ if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {
+ $param['y'] = $param['top'];
+ $param['x'] = $x2;
+ $y2 = $param['y'] + $param['height'];
+ } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {
+ $param['x'] = $param['left'];
+ $param['y'] = $y2;
+ $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ }
+
+ $x = $x0 = $param['x'];
+ $y = $param['y'];
+ $y0 = $param['y'];
+ $x1 = $param['x'] + $param['width'];
+ $y1 = $param['y'] + $param['height'];
+
+ if (!isset($param['simulate'])) {
+ $this->_getFillStyle($key);
+ $this->_getLineStyle();
+ $this->_drawLegendSample($x0, $y0, $x1, $y1);
+
+ if (($this->_marker) && ($dataset) && ($param['show_marker'])) {
+ $dataset->_reset();
+ $point = $dataset->_next();
+ $prevPoint = $dataset->_nearby(-2);
+ $nextPoint = $dataset->_nearby();
+
+ $tmp = array();
+ $point = $this->_getMarkerData($point, $nextPoint, $prevPoint, $tmp);
+ if (is_array($point)) {
+ $point['MARKER_X'] = $x+$param['width']/2;
+ $point['MARKER_Y'] = $y;
+ unset ($point['AVERAGE_Y']);
+ $this->_marker->_drawMarker($point['MARKER_X'], $point['MARKER_Y'], $point);
+ }
+ }
+ $this->write($x + $param['width'] + 10, $y + $param['height'] / 2, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);
+ }
+
+ if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {
+ $param['y'] = $y2;
+ } else {
+ $param['x'] = $x2;
+ }
+ }
+ unset($keys);
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Area.php,v 1.13 2005/11/27 22:21:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Area Chart plot.\r
- *\r
- * An area chart plots all data points similar to a {@link\r
- * Image_Graph_Plot_Line}, but the area beneath the line is filled and the whole\r
- * area 'the-line', 'the right edge', 'the x-axis' and 'the left edge' is\r
- * bounded. Smoothed charts are only supported with non-stacked types\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Area extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $dx = abs($x1 - $x0) / 3;\r
- $dy = abs($y1 - $y0) / 3;\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy));\r
- $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0));\r
- $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + $dy));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
-\r
- $this->_clip(true); \r
-\r
- $base = array();\r
- if ($this->_multiType == 'stacked') {\r
- reset($this->_dataset);\r
- $key = key($this->_dataset);\r
- $dataset =& $this->_dataset[$key];\r
-\r
- $first = $dataset->first();\r
- $point = array ('X' => $first['X'], 'Y' => '#min_pos#');\r
- $base[] = array();\r
- $base[] = $this->_pointY($point);\r
- $first = $this->_pointX($point);\r
- $base[] = $first;\r
- \r
- $last = $dataset->last();\r
- $point = array ('X' => $last['X'], 'Y' => '#min_pos#');\r
- $base[] = array();\r
- $base[] = $this->_pointY($point);\r
- $base[] = $this->_pointX($point);\r
- \r
- $current = array();\r
- }\r
-\r
- $minYaxis = $this->_parent->_getMinimum($this->_axisY);\r
- $maxYaxis = $this->_parent->_getMaximum($this->_axisY);\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- if ($this->_multiType == 'stacked') {\r
- $plotarea = array_reverse($base);\r
- $base = array();\r
- while ($point = $dataset->_next()) {\r
- $x = $point['X'];\r
- $p = $point;\r
- if (isset($current[$x])) {\r
- $p['Y'] += $current[$x];\r
- } else {\r
- $current[$x] = 0;\r
- }\r
- $x1 = $this->_pointX($p);\r
- $y1 = $this->_pointY($p);\r
- $plotarea[] = $x1;\r
- $plotarea[] = $y1;\r
- $plotarea[] = $point;\r
- $base[] = array();\r
- $base[] = $y1;\r
- $base[] = $x1;\r
- $current[$x] += $point['Y'];\r
- }\r
- } else {\r
- $first = true;\r
- $plotarea = array();\r
- while ($point = $dataset->_next()) {\r
- if ($first) {\r
- $firstPoint = array ('X' => $point['X'], 'Y' => '#min_pos#');\r
- $plotarea[] = $this->_pointX($firstPoint);\r
- $plotarea[] = $this->_pointY($firstPoint);\r
- $plotarea[] = array();\r
- }\r
- $plotarea[] = $this->_pointX($point);\r
- $plotarea[] = $this->_pointY($point);\r
- $plotarea[] = $point;\r
- $lastPoint = $point;\r
- $first = false;\r
- }\r
- $endPoint['X'] = $lastPoint['X'];\r
- $endPoint['Y'] = '#min_pos#';\r
- $plotarea[] = $this->_pointX($endPoint);\r
- $plotarea[] = $this->_pointY($endPoint);\r
- $plotarea[] = array();\r
- }\r
-\r
- reset($plotarea);\r
- while (list(, $x) = each($plotarea)) {\r
- list(, $y) = each($plotarea);\r
- list(, $data) = each($plotarea);\r
- $this->_canvas->addVertex(\r
- $this->_mergeData(\r
- $data,\r
- array('x' => $x, 'y' => $y)\r
- )\r
- );\r
- }\r
-\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => true, 'map_vertices' => true));\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- \r
- $this->_canvas->endGroup();\r
-\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Area.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Area Chart plot.
+ *
+ * An area chart plots all data points similar to a {@link
+ * Image_Graph_Plot_Line}, but the area beneath the line is filled and the whole
+ * area 'the-line', 'the right edge', 'the x-axis' and 'the left edge' is
+ * bounded. Smoothed charts are only supported with non-stacked types
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Area extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $dx = abs($x1 - $x0) / 3;
+ $dy = abs($y1 - $y0) / 3;
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy));
+ $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0));
+ $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + $dy));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $this->_clip(true);
+
+ $base = array();
+ if ($this->_multiType == 'stacked') {
+ reset($this->_dataset);
+ $key = key($this->_dataset);
+ $dataset =& $this->_dataset[$key];
+
+ $first = $dataset->first();
+ $point = array ('X' => $first['X'], 'Y' => '#min_pos#');
+ $base[] = array();
+ $base[] = $this->_pointY($point);
+ $first = $this->_pointX($point);
+ $base[] = $first;
+
+ $last = $dataset->last();
+ $point = array ('X' => $last['X'], 'Y' => '#min_pos#');
+ $base[] = array();
+ $base[] = $this->_pointY($point);
+ $base[] = $this->_pointX($point);
+
+ $current = array();
+ }
+
+ $minYaxis = $this->_parent->_getMinimum($this->_axisY);
+ $maxYaxis = $this->_parent->_getMaximum($this->_axisY);
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ if ($this->_multiType == 'stacked') {
+ $plotarea = array_reverse($base);
+ $base = array();
+ while ($point = $dataset->_next()) {
+ $x = $point['X'];
+ $p = $point;
+ if (isset($current[$x])) {
+ $p['Y'] += $current[$x];
+ } else {
+ $current[$x] = 0;
+ }
+ $x1 = $this->_pointX($p);
+ $y1 = $this->_pointY($p);
+ $plotarea[] = $x1;
+ $plotarea[] = $y1;
+ $plotarea[] = $point;
+ $base[] = array();
+ $base[] = $y1;
+ $base[] = $x1;
+ $current[$x] += $point['Y'];
+ }
+ } else {
+ $first = true;
+ $plotarea = array();
+ while ($point = $dataset->_next()) {
+ if ($first) {
+ $firstPoint = array ('X' => $point['X'], 'Y' => '#min_pos#');
+ $plotarea[] = $this->_pointX($firstPoint);
+ $plotarea[] = $this->_pointY($firstPoint);
+ $plotarea[] = array();
+ }
+ $plotarea[] = $this->_pointX($point);
+ $plotarea[] = $this->_pointY($point);
+ $plotarea[] = $point;
+ $lastPoint = $point;
+ $first = false;
+ }
+ $endPoint['X'] = $lastPoint['X'];
+ $endPoint['Y'] = '#min_pos#';
+ $plotarea[] = $this->_pointX($endPoint);
+ $plotarea[] = $this->_pointY($endPoint);
+ $plotarea[] = array();
+ }
+
+ reset($plotarea);
+ while (list(, $x) = each($plotarea)) {
+ list(, $y) = each($plotarea);
+ list(, $data) = each($plotarea);
+ $this->_canvas->addVertex(
+ $this->_mergeData(
+ $data,
+ array('x' => $x, 'y' => $y)
+ )
+ );
+ }
+
+ $this->_getFillStyle($key);
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => true, 'map_vertices' => true));
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Band.php,v 1.12 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since File available since Release 0.3.0dev2\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * "Band" (area chart with min AND max) chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since Class available since Release 0.3.0dev2\r
- */\r
-class Image_Graph_Plot_Band extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $h = abs($y1 - $y0) / 6;\r
- $w = round(abs($x1 - $x0) / 5);\r
- $y = ($y0 + $y1) / 2;\r
-\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y - $h * 3));\r
- $this->_canvas->addVertex(array('x' => $x0 + $w, 'y' => $y - 4 * $h));\r
- $this->_canvas->addVertex(array('x' => $x0 + 2 * $w, 'y' => $y - $h * 2));\r
- $this->_canvas->addVertex(array('x' => $x0 + 3 * $w, 'y' => $y - $h * 4));\r
- $this->_canvas->addVertex(array('x' => $x0 + 4 * $w, 'y' => $y - $h * 3));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $h * 2));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y + $h * 3));\r
- $this->_canvas->addVertex(array('x' => $x0 + 4 * $w, 'y' => $y + $h));\r
- $this->_canvas->addVertex(array('x' => $x0 + 3 * $w, 'y' => $y + 2 * $h));\r
- $this->_canvas->addVertex(array('x' => $x0 + 2 * $w, 'y' => $y + 1 * $h));\r
- $this->_canvas->addVertex(array('x' => $x0 + 1 * $w, 'y' => $y));\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y + $h));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle();\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
-\r
- $current = array();\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
-\r
- $this->_clip(true); \r
-\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $upperBand = array();\r
- $lowerBand = array();\r
- while ($data = $dataset->_next()) {\r
- if ($this->_parent->_horizontal) {\r
- $point['X'] = $data['X'];\r
- \r
- $point['Y'] = $data['Y']['high'];\r
- $y = $this->_pointY($point);\r
- $x_high = $this->_pointX($point);\r
- \r
- $point['Y'] = $data['Y']['low'];\r
- $x_low = $this->_pointX($point);\r
- \r
- $data = array('X' => $x_high, 'Y' => $y);\r
- if (isset($point['data'])) {\r
- $data['data'] = $point['data'];\r
- } else {\r
- $data['data'] = array();\r
- } \r
- $upperBand[] = $data;\r
- \r
- $data = array('X' => $x_low, 'Y' => $y);\r
- if (isset($point['data'])) {\r
- $data['data'] = $point['data'];\r
- } else {\r
- $data['data'] = array();\r
- } \r
- $lowerBand[] = $data;\r
- }\r
- else {\r
- $point['X'] = $data['X'];\r
- $y = $data['Y'];\r
- \r
- $point['Y'] = $data['Y']['high'];\r
- $x = $this->_pointX($point);\r
- $y_high = $this->_pointY($point);\r
- \r
- $point['Y'] = $data['Y']['low'];\r
- $y_low = $this->_pointY($point);\r
- \r
- $data = array('X' => $x, 'Y' => $y_high);\r
- if (isset($point['data'])) {\r
- $data['data'] = $point['data'];\r
- } else {\r
- $data['data'] = array();\r
- } \r
- $upperBand[] = $data;\r
- \r
- $data = array('X' => $x, 'Y' => $y_low);\r
- if (isset($point['data'])) {\r
- $data['data'] = $point['data'];\r
- } else {\r
- $data['data'] = array();\r
- } \r
- $lowerBand[] = $data;\r
- }\r
- }\r
- $lowerBand = array_reverse($lowerBand);\r
- foreach ($lowerBand as $point) {\r
- $this->_canvas->addVertex(\r
- $this->_mergeData(\r
- $point['data'],\r
- array('x' => $point['X'], 'y' => $point['Y'])\r
- )\r
- );\r
- }\r
- foreach ($upperBand as $point) {\r
- $this->_canvas->addVertex( \r
- $this->_mergeData(\r
- $point['data'],\r
- array('x' => $point['X'], 'y' => $point['Y'])\r
- )\r
- );\r
- }\r
- unset($upperBand);\r
- unset($lowerBand);\r
-\r
- $this->_getLineStyle($key);\r
- $this->_getFillStyle($key);\r
- $this->_canvas->polygon(array('connect' => true, 'map_vertices' => true));\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false); \r
-\r
- $this->_canvas->endGroup();\r
-\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Band.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ * @since File available since Release 0.3.0dev2
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * "Band" (area chart with min AND max) chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @since Class available since Release 0.3.0dev2
+ */
+class Image_Graph_Plot_Band extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $h = abs($y1 - $y0) / 6;
+ $w = round(abs($x1 - $x0) / 5);
+ $y = ($y0 + $y1) / 2;
+
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y - $h * 3));
+ $this->_canvas->addVertex(array('x' => $x0 + $w, 'y' => $y - 4 * $h));
+ $this->_canvas->addVertex(array('x' => $x0 + 2 * $w, 'y' => $y - $h * 2));
+ $this->_canvas->addVertex(array('x' => $x0 + 3 * $w, 'y' => $y - $h * 4));
+ $this->_canvas->addVertex(array('x' => $x0 + 4 * $w, 'y' => $y - $h * 3));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $h * 2));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y + $h * 3));
+ $this->_canvas->addVertex(array('x' => $x0 + 4 * $w, 'y' => $y + $h));
+ $this->_canvas->addVertex(array('x' => $x0 + 3 * $w, 'y' => $y + 2 * $h));
+ $this->_canvas->addVertex(array('x' => $x0 + 2 * $w, 'y' => $y + 1 * $h));
+ $this->_canvas->addVertex(array('x' => $x0 + 1 * $w, 'y' => $y));
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y + $h));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle();
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $current = array();
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $this->_clip(true);
+
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $upperBand = array();
+ $lowerBand = array();
+ while ($data = $dataset->_next()) {
+ if ($this->_parent->_horizontal) {
+ $point['X'] = $data['X'];
+
+ $point['Y'] = $data['Y']['high'];
+ $y = $this->_pointY($point);
+ $x_high = $this->_pointX($point);
+
+ $point['Y'] = $data['Y']['low'];
+ $x_low = $this->_pointX($point);
+
+ $data = array('X' => $x_high, 'Y' => $y);
+ if (isset($point['data'])) {
+ $data['data'] = $point['data'];
+ } else {
+ $data['data'] = array();
+ }
+ $upperBand[] = $data;
+
+ $data = array('X' => $x_low, 'Y' => $y);
+ if (isset($point['data'])) {
+ $data['data'] = $point['data'];
+ } else {
+ $data['data'] = array();
+ }
+ $lowerBand[] = $data;
+ } else {
+ $point['X'] = $data['X'];
+ $y = $data['Y'];
+
+ $point['Y'] = $data['Y']['high'];
+ $x = $this->_pointX($point);
+ $y_high = $this->_pointY($point);
+
+ $point['Y'] = $data['Y']['low'];
+ $y_low = $this->_pointY($point);
+
+ $data = array('X' => $x, 'Y' => $y_high);
+ if (isset($point['data'])) {
+ $data['data'] = $point['data'];
+ } else {
+ $data['data'] = array();
+ }
+ $upperBand[] = $data;
+
+ $data = array('X' => $x, 'Y' => $y_low);
+ if (isset($point['data'])) {
+ $data['data'] = $point['data'];
+ } else {
+ $data['data'] = array();
+ }
+ $lowerBand[] = $data;
+ }
+ }
+ $lowerBand = array_reverse($lowerBand);
+ foreach ($lowerBand as $point) {
+ $this->_canvas->addVertex(
+ $this->_mergeData(
+ $point['data'],
+ array('x' => $point['X'], 'y' => $point['Y'])
+ )
+ );
+ }
+ foreach ($upperBand as $point) {
+ $this->_canvas->addVertex(
+ $this->_mergeData(
+ $point['data'],
+ array('x' => $point['X'], 'y' => $point['Y'])
+ )
+ );
+ }
+ unset($upperBand);
+ unset($lowerBand);
+
+ $this->_getLineStyle($key);
+ $this->_getFillStyle($key);
+ $this->_canvas->polygon(array('connect' => true, 'map_vertices' => true));
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Bar.php,v 1.14 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * A bar chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Bar extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * The space between 2 bars (should be a multipla of 2)\r
- * @var int\r
- * @access private\r
- */\r
- var $_space = 4;\r
-\r
- /**\r
- * The width of the bars\r
- * @var array\r
- * @access private\r
- */\r
- var $_width = 'auto';\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $dx = abs($x1 - $x0) / 7;\r
- $this->_canvas->rectangle(array('x0' => $x0 + $dx, 'y0' => $y0, 'x1' => $x1 - $dx, 'y1' => $y1));\r
- }\r
-\r
- /**\r
- * Set the spacing between 2 neighbouring bars\r
- *\r
- * @param int $space The number of pixels between 2 bars, should be a\r
- * multipla of 2 (ie an even number)\r
- */\r
- function setSpacing($space)\r
- {\r
- $this->_space = (int) ($space / 2);\r
- }\r
-\r
- /**\r
- * Set the width of a bars.\r
- *\r
- * Specify 'auto' to auto calculate the width based on the positions on the\r
- * x-axis.\r
- *\r
- * Supported units are:\r
- *\r
- * '%' The width is specified in percentage of the total plot width\r
- *\r
- * 'px' The width specified in pixels\r
- *\r
- * @param string $width The width of any bar\r
- * @param string $unit The unit of the width\r
- */\r
- function setBarWidth($width, $unit = false)\r
- {\r
- if ($width == 'auto') {\r
- $this->_width = $width;\r
- } else {\r
- $this->_width = array(\r
- 'width' => $width,\r
- 'unit' => $unit\r
- );\r
- }\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
-\r
- $this->_clip(true); \r
-\r
- if ($this->_width == 'auto') {\r
- $width = $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2; \r
- } elseif ($this->_width['unit'] == '%') {\r
- $width = $this->_width['width'] * $this->width() / 200;\r
- } elseif ($this->_width['unit'] == 'px') {\r
- $width = $this->_width['width'] / 2;\r
- }\r
- \r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
-\r
- $minYaxis = $this->_parent->_getMinimum($this->_axisY);\r
- $maxYaxis = $this->_parent->_getMaximum($this->_axisY);\r
-\r
- $number = 0;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- \r
- if ($this->_parent->_horizontal) {\r
- $y1 = $this->_pointY($point) - $width;\r
- $y2 = $this->_pointY($point) + $width;\r
- \r
- if ($y2 - $this->_space > $y1 + $this->_space) {\r
- /*\r
- * Take bar spacing into account _only_ if the space doesn't\r
- * turn the bar "inside-out", i.e. if the actual bar width\r
- * is smaller than the space between the bars\r
- */\r
- $y2 -= $this->_space;\r
- $y1 += $this->_space;\r
- }\r
- }\r
- else { \r
- $x1 = $this->_pointX($point) - $width;\r
- $x2 = $this->_pointX($point) + $width;\r
- \r
- if ($x2 - $this->_space > $x1 + $this->_space) {\r
- /*\r
- * Take bar spacing into account _only_ if the space doesn't\r
- * turn the bar "inside-out", i.e. if the actual bar width\r
- * is smaller than the space between the bars\r
- */\r
- $x2 -= $this->_space;\r
- $x1 += $this->_space;\r
- }\r
- } \r
- \r
-\r
- if (($this->_multiType == 'stacked') ||\r
- ($this->_multiType == 'stacked100pct'))\r
- {\r
- $x = $point['X'];\r
-\r
- if ($point['Y'] >= 0) {\r
- if (!isset($current[$x])) {\r
- $current[$x] = 0;\r
- }\r
-\r
- if ($this->_multiType == 'stacked') {\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $current[$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $current[$x] + $point['Y']\r
- );\r
- } else {\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => 100 * $current[$x] / $total['TOTAL_Y'][$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x]\r
- );\r
- }\r
- $current[$x] += $point['Y'];\r
- } else {\r
- if (!isset($currentNegative[$x])) {\r
- $currentNegative[$x] = 0;\r
- }\r
-\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $currentNegative[$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $currentNegative[$x] + $point['Y']\r
- );\r
- $currentNegative[$x] += $point['Y'];\r
- }\r
- } else {\r
- if (count($this->_dataset) > 1) {\r
- $w = 2 * ($width - $this->_space) / count($this->_dataset); \r
- if ($this->_parent->_horizontal) {\r
- $y2 = ($y1 = ($y1 + $y2) / 2 - ($width - $this->_space) + $number * $w) + $w;\r
- }\r
- else {\r
- $x2 = ($x1 = ($x1 + $x2) / 2 - ($width - $this->_space) + $number * $w) + $w;\r
- }\r
- }\r
- $p0 = array('X' => $point['X'], 'Y' => 0);\r
- $p1 = $point;\r
- }\r
-\r
- if ((($minY = min($p0['Y'], $p1['Y'])) < $maxYaxis) &&\r
- (($maxY = max($p0['Y'], $p1['Y'])) > $minYaxis)\r
- ) {\r
- $p0['Y'] = $minY;\r
- $p1['Y'] = $maxY;\r
-\r
- if ($p0['Y'] < $minYaxis) {\r
- $p0['Y'] = '#min_pos#';\r
- }\r
- if ($p1['Y'] > $maxYaxis) {\r
- $p1['Y'] = '#max_neg#';\r
- }\r
-\r
- if ($this->_parent->_horizontal) {\r
- $x1 = $this->_pointX($p0);\r
- $x2 = $this->_pointX($p1);\r
- }\r
- else { \r
- $y1 = $this->_pointY($p0);\r
- $y2 = $this->_pointY($p1);\r
- }\r
-\r
- $ID = $point['ID'];\r
- if (($ID === false) && (count($this->_dataset) > 1)) {\r
- $ID = $key;\r
- }\r
- $this->_getFillStyle($ID);\r
- $this->_getLineStyle($ID);\r
-\r
- if (($y1 != $y2) && ($x1 != $x2)) {\r
- $this->_canvas->rectangle(\r
- $this->_mergeData(\r
- $point,\r
- array(\r
- 'x0' => min($x1, $x2),\r
- 'y0' => min($y1, $y2),\r
- 'x1' => max($x1, $x2),\r
- 'y1' => max($y1, $y2)\r
- )\r
- )\r
- );\r
- }\r
- }\r
- }\r
- $number ++;\r
- }\r
- unset($keys);\r
-\r
- $this->_drawMarker();\r
-\r
- $this->_clip(false); \r
- \r
- $this->_canvas->endGroup(); \r
-\r
- return true;\r
- }\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Bar.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * A bar chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Bar extends Image_Graph_Plot
+{
+
+ /**
+ * The space between 2 bars (should be a multipla of 2)
+ * @var int
+ * @access private
+ */
+ var $_space = 4;
+
+ /**
+ * The width of the bars
+ * @var array
+ * @access private
+ */
+ var $_width = 'auto';
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $dx = abs($x1 - $x0) / 7;
+ $this->_canvas->rectangle(array('x0' => $x0 + $dx, 'y0' => $y0, 'x1' => $x1 - $dx, 'y1' => $y1));
+ }
+
+ /**
+ * Set the spacing between 2 neighbouring bars
+ *
+ * @param int $space The number of pixels between 2 bars, should be a
+ * multipla of 2 (ie an even number)
+ *
+ * @return void
+ */
+ function setSpacing($space)
+ {
+ $this->_space = (int) ($space / 2);
+ }
+
+ /**
+ * Set the width of a bars.
+ *
+ * Specify 'auto' to auto calculate the width based on the positions on the
+ * x-axis.
+ *
+ * Supported units are:
+ *
+ * '%' The width is specified in percentage of the total plot width
+ *
+ * 'px' The width specified in pixels
+ *
+ * @param string $width The width of any bar
+ * @param string $unit The unit of the width (optional)
+ *
+ * @return void
+ */
+ function setBarWidth($width, $unit = false)
+ {
+ if ($width == 'auto') {
+ $this->_width = $width;
+ } else {
+ $this->_width = array(
+ 'width' => $width,
+ 'unit' => $unit
+ );
+ }
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $this->_clip(true);
+
+ if ($this->_width == 'auto') {
+ $width = $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2;
+ } elseif ($this->_width['unit'] == '%') {
+ $width = $this->_width['width'] * $this->width() / 200;
+ } elseif ($this->_width['unit'] == 'px') {
+ $width = $this->_width['width'] / 2;
+ }
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+
+ $minYaxis = $this->_parent->_getMinimum($this->_axisY);
+ $maxYaxis = $this->_parent->_getMaximum($this->_axisY);
+
+ $number = 0;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ if ($this->_parent->_horizontal) {
+ $y1 = $this->_pointY($point) - $width;
+ $y2 = $this->_pointY($point) + $width;
+
+ if ($y2 - $this->_space > $y1 + $this->_space) {
+ /*
+ * Take bar spacing into account _only_ if the space doesn't
+ * turn the bar "inside-out", i.e. if the actual bar width
+ * is smaller than the space between the bars
+ */
+ $y2 -= $this->_space;
+ $y1 += $this->_space;
+ }
+ } else {
+ $x1 = $this->_pointX($point) - $width;
+ $x2 = $this->_pointX($point) + $width;
+
+ if ($x2 - $this->_space > $x1 + $this->_space) {
+ /*
+ * Take bar spacing into account _only_ if the space doesn't
+ * turn the bar "inside-out", i.e. if the actual bar width
+ * is smaller than the space between the bars
+ */
+ $x2 -= $this->_space;
+ $x1 += $this->_space;
+ }
+ }
+
+
+ if (($this->_multiType == 'stacked')
+ || ($this->_multiType == 'stacked100pct')
+ ) {
+ $x = $point['X'];
+
+ if ($point['Y'] >= 0) {
+ if (!isset($current[$x])) {
+ $current[$x] = 0;
+ }
+
+ if ($this->_multiType == 'stacked') {
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => $current[$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => $current[$x] + $point['Y']
+ );
+ } else {
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => 100 * $current[$x] / $total['TOTAL_Y'][$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x]
+ );
+ }
+ $current[$x] += $point['Y'];
+ } else {
+ if (!isset($currentNegative[$x])) {
+ $currentNegative[$x] = 0;
+ }
+
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => $currentNegative[$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => $currentNegative[$x] + $point['Y']
+ );
+ $currentNegative[$x] += $point['Y'];
+ }
+ } else {
+ if (count($this->_dataset) > 1) {
+ $w = 2 * ($width - $this->_space) / count($this->_dataset);
+ if ($this->_parent->_horizontal) {
+ $y2 = ($y1 = ($y1 + $y2) / 2 - ($width - $this->_space) + $number * $w) + $w;
+ } else {
+ $x2 = ($x1 = ($x1 + $x2) / 2 - ($width - $this->_space) + $number * $w) + $w;
+ }
+ }
+ $p0 = array('X' => $point['X'], 'Y' => 0);
+ $p1 = $point;
+ }
+
+ if ((($minY = min($p0['Y'], $p1['Y'])) < $maxYaxis)
+ && (($maxY = max($p0['Y'], $p1['Y'])) > $minYaxis)
+ ) {
+ $p0['Y'] = $minY;
+ $p1['Y'] = $maxY;
+
+ if ($p0['Y'] < $minYaxis) {
+ $p0['Y'] = '#min_pos#';
+ }
+ if ($p1['Y'] > $maxYaxis) {
+ $p1['Y'] = '#max_neg#';
+ }
+
+ if ($this->_parent->_horizontal) {
+ $x1 = $this->_pointX($p0);
+ $x2 = $this->_pointX($p1);
+ } else {
+ $y1 = $this->_pointY($p0);
+ $y2 = $this->_pointY($p1);
+ }
+
+ $ID = $point['ID'];
+ if (($ID === false) && (count($this->_dataset) > 1)) {
+ $ID = $key;
+ }
+ $this->_getFillStyle($ID);
+ $this->_getLineStyle($ID);
+
+ if (($y1 != $y2) && ($x1 != $x2)) {
+ $this->_canvas->rectangle(
+ $this->_mergeData(
+ $point,
+ array(
+ 'x0' => min($x1, $x2),
+ 'y0' => min($y1, $y2),
+ 'x1' => max($x1, $x2),
+ 'y1' => max($y1, $y2)
+ )
+ )
+ );
+ }
+ }
+ }
+ $number ++;
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: BoxWhisker.php,v 1.14 2005/11/27 22:21:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since File available since Release 0.3.0dev2\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Box & Whisker chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since Class available since Release 0.3.0dev2\r
- */\r
-class Image_Graph_Plot_BoxWhisker extends Image_Graph_Plot\r
-{\r
- /**\r
- * Whisker circle size\r
- * @var int\r
- * @access private\r
- */\r
- var $_whiskerSize = false;\r
-\r
- /**\r
- * Draws a box & whisker\r
- *\r
- * @param int $x The x position\r
- * @param int $w The width of the box\r
- * @param int $r The radius of the circle markers\r
- * @param int $y_min The Y position of the minimum value\r
- * @param int $y_q1 The Y position of the median of the first quartile\r
- * @param int $y_med The Y position of the median\r
- * @param int $y_q3 The Y position of the median of the third quartile\r
- * @param int $y_max The Y position of the maximum value\r
- * @param int $key The ID tag\r
- * @access private\r
- */\r
- function _drawBoxWhiskerV($x, $w, $r, $y_min, $y_q1, $y_med, $y_q3, $y_max, $key = false)\r
- {\r
- // draw circles\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('min');\r
- $this->_canvas->ellipse(array('x' => $x, 'y' => $y_min, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('quartile1');\r
- $this->_canvas->ellipse(array('x' => $x, 'y' => $y_q1, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('median');\r
- $this->_canvas->ellipse(array('x' => $x, 'y' => $y_med, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('quartile3');\r
- $this->_canvas->ellipse(array('x' => $x, 'y' => $y_q3, $r, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('max');\r
- $this->_canvas->ellipse(array('x' => $x, 'y' => $y_max, $r, 'rx' => $r, 'ry' => $r));\r
-\r
- // draw box and lines\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y_min, 'x1' => $x, 'y1' => $y_q1));\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y_q3, 'x1' => $x, 'y1' => $y_max));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('box');\r
- $this->_canvas->rectangle(array('x0' => $x - $w, 'y0' => $y_q1, 'x1' => $x + $w, 'y1' => $y_q3));\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x - $w, 'y0' => $y_med, 'x1' => $x + $w, 'y1' => $y_med));\r
- }\r
-\r
- /**\r
- * Draws a box & whisker\r
- *\r
- * @param int $y The x position\r
- * @param int $h The width of the box\r
- * @param int $r The radius of the circle markers\r
- * @param int $x_min The Y position of the minimum value\r
- * @param int $x_q1 The Y position of the median of the first quartile\r
- * @param int $x_med The Y position of the median\r
- * @param int $x_q3 The Y position of the median of the third quartile\r
- * @param int $x_max The Y position of the maximum value\r
- * @param int $key The ID tag\r
- * @access private\r
- */\r
- function _drawBoxWhiskerH($y, $h, $r, $x_min, $x_q1, $x_med, $x_q3, $x_max, $key = false)\r
- {\r
- // draw circles\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('min');\r
- $this->_canvas->ellipse(array('x' => $x_min, 'y' => $y, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('quartile1');\r
- $this->_canvas->ellipse(array('x' => $x_q1, 'y' => $y, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('median');\r
- $this->_canvas->ellipse(array('x' => $x_med, 'y' => $y, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('quartile3');\r
- $this->_canvas->ellipse(array('x' => $x_q3, 'y' => $y, $r, 'rx' => $r, 'ry' => $r));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('max');\r
- $this->_canvas->ellipse(array('x' => $x_max, 'y' => $y, $r, 'rx' => $r, 'ry' => $r));\r
-\r
- // draw box and lines\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x_min, 'y0' => $y, 'x1' => $x_q1, 'y1' => $y));\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x_q3, 'y0' => $y, 'x1' => $x_max, 'y1' => $y));\r
-\r
- $this->_getLineStyle();\r
- $this->_getFillStyle('box');\r
- $this->_canvas->rectangle(array('x0' => $x_q1, 'y0' => $y - $h, 'x1' => $x_q3, 'y1' => $y + $h));\r
-\r
- $this->_getLineStyle();\r
- $this->_canvas->line(array('x0' => $x_med, 'y0' => $y - $h, 'x1' => $x_med, 'y1' => $y + $h));\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $x = round(($x0 + $x1) / 2);\r
- $h = abs($y1 - $y0) / 9;\r
- $w = round(abs($x1 - $x0) / 5);\r
- $r = 2;//round(abs($x1 - $x0) / 13);\r
- $this->_drawBoxWhiskerV($x, $w, $r, $y1, $y1 - 2 * $h, $y1 - 4 * $h, $y0 + 3 * $h, $y0);\r
- }\r
- \r
- /**\r
- * Sets the whisker circle size\r
- *\r
- * @param int $size Size (radius) of the whisker circle/dot\r
- */\r
- function setWhiskerSize($size = false)\r
- {\r
- $this->_whiskerSize = $size;\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
-\r
- $this->_clip(true); \r
-\r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
- $current = array();\r
- $number = 0;\r
- $width = floor(0.5 * $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2);\r
-\r
- if ($this->_whiskerSize !== false) {\r
- $r = $this->_whiskerSize;\r
- } else { \r
- $r = min(5, $width / 10);\r
- }\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- while ($data = $dataset->_next()) {\r
- if ($this->_parent->_horizontal) {\r
- $point['X'] = $data['X'];\r
- $y = $data['Y'];\r
- \r
- $min = min($y);\r
- $max = max($y);\r
- $q1 = $dataset->_median($y, 'first');\r
- $med = $dataset->_median($y, 'second');\r
- $q3 = $dataset->_median($y, 'third');\r
- \r
- $point['Y'] = $min;\r
- $y = $this->_pointY($point);\r
- $x_min = $this->_pointX($point);\r
- \r
- $point['Y'] = $max;\r
- $x_max = $this->_pointX($point);\r
- \r
- $point['Y'] = $q1;\r
- $x_q1 = $this->_pointX($point);\r
- \r
- $point['Y'] = $med;\r
- $x_med = $this->_pointX($point);\r
- \r
- $point['Y'] = $q3;\r
- $x_q3 = $this->_pointX($point);\r
- \r
- $this->_drawBoxWhiskerH($y, $width, $r, $x_min, $x_q1, $x_med, $x_q3, $x_max, $key);\r
- }\r
- else {\r
- $point['X'] = $data['X'];\r
- $y = $data['Y'];\r
- \r
- $min = min($y);\r
- $max = max($y);\r
- $q1 = $dataset->_median($y, 'first');\r
- $med = $dataset->_median($y, 'second');\r
- $q3 = $dataset->_median($y, 'third');\r
- \r
- $point['Y'] = $min;\r
- $x = $this->_pointX($point);\r
- $y_min = $this->_pointY($point);\r
- \r
- $point['Y'] = $max;\r
- $y_max = $this->_pointY($point);\r
- \r
- $point['Y'] = $q1;\r
- $y_q1 = $this->_pointY($point);\r
- \r
- $point['Y'] = $med;\r
- $y_med = $this->_pointY($point);\r
- \r
- $point['Y'] = $q3;\r
- $y_q3 = $this->_pointY($point);\r
- \r
- $this->_drawBoxWhiskerV($x, $width, $r, $y_min, $y_q1, $y_med, $y_q3, $y_max, $key);\r
- }\r
- }\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
-\r
- $this->_clip(false); \r
-\r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: BoxWhisker.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ * @since File available since Release 0.3.0dev2
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Box & Whisker chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @since Class available since Release 0.3.0dev2
+ */
+class Image_Graph_Plot_BoxWhisker extends Image_Graph_Plot
+{
+ /**
+ * Whisker circle size
+ * @var int
+ * @access private
+ */
+ var $_whiskerSize = false;
+
+ /**
+ * Draws a box & whisker
+ *
+ * @param int $x The x position
+ * @param int $w The width of the box
+ * @param int $r The radius of the circle markers
+ * @param int $y_min The Y position of the minimum value
+ * @param int $y_q1 The Y position of the median of the first quartile
+ * @param int $y_med The Y position of the median
+ * @param int $y_q3 The Y position of the median of the third quartile
+ * @param int $y_max The Y position of the maximum value
+ * @param int $key The ID tag
+ *
+ * @return void
+ * @access private
+ */
+ function _drawBoxWhiskerV($x, $w, $r, $y_min, $y_q1, $y_med, $y_q3, $y_max, $key = false)
+ {
+ // draw circles
+ $this->_getLineStyle();
+ $this->_getFillStyle('min');
+ $this->_canvas->ellipse(array('x' => $x, 'y' => $y_min, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('quartile1');
+ $this->_canvas->ellipse(array('x' => $x, 'y' => $y_q1, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('median');
+ $this->_canvas->ellipse(array('x' => $x, 'y' => $y_med, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('quartile3');
+ $this->_canvas->ellipse(array('x' => $x, 'y' => $y_q3, $r, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('max');
+ $this->_canvas->ellipse(array('x' => $x, 'y' => $y_max, $r, 'rx' => $r, 'ry' => $r));
+
+ // draw box and lines
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y_min, 'x1' => $x, 'y1' => $y_q1));
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y_q3, 'x1' => $x, 'y1' => $y_max));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('box');
+ $this->_canvas->rectangle(array('x0' => $x - $w, 'y0' => $y_q1, 'x1' => $x + $w, 'y1' => $y_q3));
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x - $w, 'y0' => $y_med, 'x1' => $x + $w, 'y1' => $y_med));
+ }
+
+ /**
+ * Draws a box & whisker
+ *
+ * @param int $y The x position
+ * @param int $h The width of the box
+ * @param int $r The radius of the circle markers
+ * @param int $x_min The Y position of the minimum value
+ * @param int $x_q1 The Y position of the median of the first quartile
+ * @param int $x_med The Y position of the median
+ * @param int $x_q3 The Y position of the median of the third quartile
+ * @param int $x_max The Y position of the maximum value
+ * @param int $key The ID tag
+ *
+ * @return void
+ * @access private
+ */
+ function _drawBoxWhiskerH($y, $h, $r, $x_min, $x_q1, $x_med, $x_q3, $x_max, $key = false)
+ {
+ // draw circles
+ $this->_getLineStyle();
+ $this->_getFillStyle('min');
+ $this->_canvas->ellipse(array('x' => $x_min, 'y' => $y, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('quartile1');
+ $this->_canvas->ellipse(array('x' => $x_q1, 'y' => $y, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('median');
+ $this->_canvas->ellipse(array('x' => $x_med, 'y' => $y, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('quartile3');
+ $this->_canvas->ellipse(array('x' => $x_q3, 'y' => $y, $r, 'rx' => $r, 'ry' => $r));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('max');
+ $this->_canvas->ellipse(array('x' => $x_max, 'y' => $y, $r, 'rx' => $r, 'ry' => $r));
+
+ // draw box and lines
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x_min, 'y0' => $y, 'x1' => $x_q1, 'y1' => $y));
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x_q3, 'y0' => $y, 'x1' => $x_max, 'y1' => $y));
+
+ $this->_getLineStyle();
+ $this->_getFillStyle('box');
+ $this->_canvas->rectangle(array('x0' => $x_q1, 'y0' => $y - $h, 'x1' => $x_q3, 'y1' => $y + $h));
+
+ $this->_getLineStyle();
+ $this->_canvas->line(array('x0' => $x_med, 'y0' => $y - $h, 'x1' => $x_med, 'y1' => $y + $h));
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $x = round(($x0 + $x1) / 2);
+ $h = abs($y1 - $y0) / 9;
+ $w = round(abs($x1 - $x0) / 5);
+ $r = 2;//round(abs($x1 - $x0) / 13);
+ $this->_drawBoxWhiskerV($x, $w, $r, $y1, $y1 - 2 * $h, $y1 - 4 * $h, $y0 + 3 * $h, $y0);
+ }
+
+ /**
+ * Sets the whisker circle size
+ *
+ * @param int $size Size (radius) of the whisker circle/dot
+ *
+ * @return void
+ */
+ function setWhiskerSize($size = false)
+ {
+ $this->_whiskerSize = $size;
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $this->_clip(true);
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+ $current = array();
+ $number = 0;
+ $width = floor(0.5 * $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2);
+
+ if ($this->_whiskerSize !== false) {
+ $r = $this->_whiskerSize;
+ } else {
+ $r = min(5, $width / 10);
+ }
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ while ($data = $dataset->_next()) {
+ if ($this->_parent->_horizontal) {
+ $point['X'] = $data['X'];
+ $y = $data['Y'];
+
+ $min = min($y);
+ $max = max($y);
+ $q1 = $dataset->_median($y, 'first');
+ $med = $dataset->_median($y, 'second');
+ $q3 = $dataset->_median($y, 'third');
+
+ $point['Y'] = $min;
+ $y = $this->_pointY($point);
+ $x_min = $this->_pointX($point);
+
+ $point['Y'] = $max;
+ $x_max = $this->_pointX($point);
+
+ $point['Y'] = $q1;
+ $x_q1 = $this->_pointX($point);
+
+ $point['Y'] = $med;
+ $x_med = $this->_pointX($point);
+
+ $point['Y'] = $q3;
+ $x_q3 = $this->_pointX($point);
+
+ $this->_drawBoxWhiskerH($y, $width, $r, $x_min, $x_q1, $x_med, $x_q3, $x_max, $key);
+ } else {
+ $point['X'] = $data['X'];
+ $y = $data['Y'];
+
+ $min = min($y);
+ $max = max($y);
+ $q1 = $dataset->_median($y, 'first');
+ $med = $dataset->_median($y, 'second');
+ $q3 = $dataset->_median($y, 'third');
+
+ $point['Y'] = $min;
+ $x = $this->_pointX($point);
+ $y_min = $this->_pointY($point);
+
+ $point['Y'] = $max;
+ $y_max = $this->_pointY($point);
+
+ $point['Y'] = $q1;
+ $y_q1 = $this->_pointY($point);
+
+ $point['Y'] = $med;
+ $y_med = $this->_pointY($point);
+
+ $point['Y'] = $q3;
+ $y_q3 = $this->_pointY($point);
+
+ $this->_drawBoxWhiskerV($x, $width, $r, $y_min, $y_q1, $y_med, $y_q3, $y_max, $key);
+ }
+ }
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: CandleStick.php,v 1.12 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since File available since Release 0.3.0dev2\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Candlestick chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since Class available since Release 0.3.0dev2\r
- */\r
-class Image_Graph_Plot_CandleStick extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * (Add basic description here)\r
- *\r
- * @access private\r
- */\r
- function _drawCandleStickH($y, $h, $x_min, $x_open, $x_close, $x_max, $ID) \r
- {\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => min($x_open, $x_close), \r
- 'y0' => $y, \r
- 'x1' => $x_min, \r
- 'y1' => $y\r
- )\r
- );\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => max($x_open, $x_close), \r
- 'y0' => $y, \r
- 'x1' => $x_max, \r
- 'y1' => $y\r
- )\r
- );\r
- \r
- $this->_getLineStyle($ID);\r
- $this->_getFillStyle($ID);\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => min($x_open, $x_close), \r
- 'y0' => $y - $h, \r
- 'x1' => max($x_open, $x_close), \r
- 'y1' => $y + $h\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * (Add basic description here)\r
- *\r
- * @access private\r
- */\r
- function _drawCandleStickV($x, $w, $y_min, $y_open, $y_close, $y_max, $ID) \r
- {\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x, \r
- 'y0' => min($y_open, $y_close), \r
- 'x1' => $x, \r
- 'y1' => $y_max \r
- )\r
- );\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $x, \r
- 'y0' => max($y_open, $y_close), \r
- 'x1' => $x, \r
- 'y1' => $y_min\r
- )\r
- );\r
- \r
- $this->_getLineStyle($ID);\r
- $this->_getFillStyle($ID);\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $x - $w, \r
- 'y0' => min($y_open, $y_close), \r
- 'x1' => $x + $w, \r
- 'y1' => max($y_open, $y_close)\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $x = round(($x0 + $x1) / 2);\r
- $h = abs($y1 - $y0) / 4;\r
- $w = round(abs($x1 - $x0) / 5);\r
- $this->_drawCandleStickV($x, $w, $y1, $y1 - $h, $y0 + $h, $y0, 'green');\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- \r
- $this->_clip(true);\r
-\r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
- $current = array();\r
- $number = 0;\r
- $width = floor(0.8 * $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2);\r
-\r
- $lastClosed = false;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- while ($data = $dataset->_next()) {\r
- if ($this->_parent->_horizontal) {\r
- $point['X'] = $data['X'];\r
- //$y = $data['Y'];\r
-\r
- if (isset($data['Y']['open'])) { \r
- $point['Y'] = $data['Y']['open'];\r
- } else {\r
- $point['Y'] = $lastClosed;\r
- }\r
- $y = $this->_pointY($point);\r
- $x_open = $this->_pointX($point);\r
- \r
- $lastClosed = $point['Y'] = $data['Y']['close'];\r
- $x_close = $this->_pointX($point);\r
- \r
- $point['Y'] = $data['Y']['min'];\r
- $x_min = $this->_pointX($point);\r
- \r
- $point['Y'] = $data['Y']['max'];\r
- $x_max = $this->_pointX($point);\r
- \r
- if ($data['Y']['close'] < $data['Y']['open']) {\r
- $ID = 'red';\r
- } else {\r
- $ID = 'green';\r
- }\r
- \r
- $this->_drawCandleStickH($y, $width, $x_min, $x_open, $x_close, $x_max, $ID);\r
- }\r
- else {\r
- $point['X'] = $data['X'];\r
- //$y = $data['Y'];\r
- \r
- if (isset($data['Y']['open'])) { \r
- $point['Y'] = $data['Y']['open'];\r
- } else {\r
- $point['Y'] = $lastClosed;\r
- }\r
- $x = $this->_pointX($point);\r
- $y_open = $this->_pointY($point);\r
- \r
- $lastClosed = $point['Y'] = $data['Y']['close'];\r
- $y_close = $this->_pointY($point);\r
- \r
- $point['Y'] = $data['Y']['min'];\r
- $y_min = $this->_pointY($point);\r
- \r
- $point['Y'] = $data['Y']['max'];\r
- $y_max = $this->_pointY($point);\r
- \r
- if ($data['Y']['close'] < $data['Y']['open']) {\r
- $ID = 'red';\r
- } else {\r
- $ID = 'green';\r
- }\r
- \r
- $this->_drawCandleStickV($x, $width, $y_min, $y_open, $y_close, $y_max, $ID);\r
- }\r
- }\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- \r
- $this->_clip(false); \r
- \r
- $this->_canvas->endGroup($this->_title);\r
- \r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: CandleStick.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ * @since File available since Release 0.3.0dev2
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Candlestick chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @since Class available since Release 0.3.0dev2
+ */
+class Image_Graph_Plot_CandleStick extends Image_Graph_Plot
+{
+
+ /**
+ * (Add basic description here)
+ *
+ * @param ??? $y ???
+ * @param ??? $h ???
+ * @param ??? $x_min ???
+ * @param ??? $x_open ???
+ * @param ??? $x_close ???
+ * @param ??? $x_max ???
+ * @param ??? $ID ???
+ *
+ * @return void
+ * @access private
+ */
+ function _drawCandleStickH($y, $h, $x_min, $x_open, $x_close, $x_max, $ID)
+ {
+ $this->_getLineStyle($ID);
+ $this->_canvas->line(
+ array(
+ 'x0' => min($x_open, $x_close),
+ 'y0' => $y,
+ 'x1' => $x_min,
+ 'y1' => $y
+ )
+ );
+ $this->_getLineStyle($ID);
+ $this->_canvas->line(
+ array(
+ 'x0' => max($x_open, $x_close),
+ 'y0' => $y,
+ 'x1' => $x_max,
+ 'y1' => $y
+ )
+ );
+
+ $this->_getLineStyle($ID);
+ $this->_getFillStyle($ID);
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => min($x_open, $x_close),
+ 'y0' => $y - $h,
+ 'x1' => max($x_open, $x_close),
+ 'y1' => $y + $h
+ )
+ );
+ }
+
+ /**
+ * (Add basic description here)
+ *
+ * @param ??? $x ???
+ * @param ??? $w ???
+ * @param ??? $y_min ???
+ * @param ??? $y_open ???
+ * @param ??? $y_close ???
+ * @param ??? $y_max ???
+ * @param ??? $ID ???
+ *
+ * @return void
+ * @access private
+ */
+ function _drawCandleStickV($x, $w, $y_min, $y_open, $y_close, $y_max, $ID)
+ {
+ $this->_getLineStyle($ID);
+ $this->_canvas->line(
+ array(
+ 'x0' => $x,
+ 'y0' => min($y_open, $y_close),
+ 'x1' => $x,
+ 'y1' => $y_max
+ )
+ );
+ $this->_getLineStyle($ID);
+ $this->_canvas->line(
+ array(
+ 'x0' => $x,
+ 'y0' => max($y_open, $y_close),
+ 'x1' => $x,
+ 'y1' => $y_min
+ )
+ );
+
+ $this->_getLineStyle($ID);
+ $this->_getFillStyle($ID);
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $x - $w,
+ 'y0' => min($y_open, $y_close),
+ 'x1' => $x + $w,
+ 'y1' => max($y_open, $y_close)
+ )
+ );
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $x = round(($x0 + $x1) / 2);
+ $h = abs($y1 - $y0) / 4;
+ $w = round(abs($x1 - $x0) / 5);
+ $this->_drawCandleStickV($x, $w, $y1, $y1 - $h, $y0 + $h, $y0, 'green');
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $this->_clip(true);
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+ $current = array();
+ $number = 0;
+ $width = floor(0.8 * $this->_parent->_labelDistance(IMAGE_GRAPH_AXIS_X) / 2);
+
+ $lastClosed = false;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ while ($data = $dataset->_next()) {
+ if ($this->_parent->_horizontal) {
+ $point['X'] = $data['X'];
+ //$y = $data['Y'];
+
+ if (isset($data['Y']['open'])) {
+ $point['Y'] = $data['Y']['open'];
+ } else {
+ $point['Y'] = $lastClosed;
+ }
+ $y = $this->_pointY($point);
+ $x_open = $this->_pointX($point);
+
+ $lastClosed = $point['Y'] = $data['Y']['close'];
+ $x_close = $this->_pointX($point);
+
+ $point['Y'] = $data['Y']['min'];
+ $x_min = $this->_pointX($point);
+
+ $point['Y'] = $data['Y']['max'];
+ $x_max = $this->_pointX($point);
+
+ if ($data['Y']['close'] < $data['Y']['open']) {
+ $ID = 'red';
+ } else {
+ $ID = 'green';
+ }
+
+ $this->_drawCandleStickH($y, $width, $x_min, $x_open, $x_close, $x_max, $ID);
+ } else {
+ $point['X'] = $data['X'];
+ //$y = $data['Y'];
+
+ if (isset($data['Y']['open'])) {
+ $point['Y'] = $data['Y']['open'];
+ } else {
+ $point['Y'] = $lastClosed;
+ }
+ $x = $this->_pointX($point);
+ $y_open = $this->_pointY($point);
+
+ $lastClosed = $point['Y'] = $data['Y']['close'];
+ $y_close = $this->_pointY($point);
+
+ $point['Y'] = $data['Y']['min'];
+ $y_min = $this->_pointY($point);
+
+ $point['Y'] = $data['Y']['max'];
+ $y_max = $this->_pointY($point);
+
+ if ($data['Y']['close'] < $data['Y']['open']) {
+ $ID = 'red';
+ } else {
+ $ID = 'green';
+ }
+
+ $this->_drawCandleStickV($x, $width, $y_min, $y_open, $y_close, $y_max, $ID);
+ }
+ }
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup($this->_title);
+
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Dot.php,v 1.11 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Dot / scatter chart (only marker).\r
- *\r
- * This plot type only displays a {@link Image_Graph_Marker} for the datapoints.\r
- * The marker must explicitly be defined using {@link Image_Graph_Plot::\r
- * setMarker()}.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Dot extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- if (isset($this->_marker)) {\r
- $key = key($this->_dataset);\r
- $samplePoint = $this->_dataset[$key]->_nearby();\r
- $this->_marker->_drawMarker(($x0 + $x1) / 2, ($y0 + $y1) / 2, $samplePoint);\r
- }\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (Image_Graph_Plot::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
-\r
- $this->_clip(true);\r
- \r
- $this->_drawMarker();\r
- \r
- $this->_clip(false);\r
- \r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Dot.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Dot / scatter chart (only marker).
+ *
+ * This plot type only displays a {@link Image_Graph_Marker} for the datapoints.
+ * The marker must explicitly be defined using {@link Image_Graph_Plot::
+ * setMarker()}.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Dot extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ if (isset($this->_marker)) {
+ $key = key($this->_dataset);
+ $samplePoint = $this->_dataset[$key]->_nearby();
+ $this->_marker->_drawMarker(($x0 + $x1) / 2, ($y0 + $y1) / 2, $samplePoint);
+ }
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (Image_Graph_Plot::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Line.php,v 1.2 2005/11/27 22:21:18 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Include file Image/Graph/Tool.php\r
- */\r
-require_once 'Image/Graph/Tool.php';\r
-\r
-/**\r
- * Fit the graph (to a line using linear regression).\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Fit_Line extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $y = ($y0 + $y1) / 2;\r
- $dy = abs($y1 - $y0) / 6;\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y + $dy));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));\r
- $this->_canvas->polygon(array('connect' => false));\r
- }\r
- \r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (Image_Graph_Plot::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $data = array();\r
- while ($point = $dataset->_next()) {\r
- $data[] = array(\r
- 'X' => $this->_pointX($point),\r
- 'Y' => $this->_pointY($point)\r
- );\r
- }\r
-\r
- $regression = Image_Graph_Tool::calculateLinearRegression($data);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->line(\r
- array(\r
- 'x0' => $this->_left,\r
- 'y0' => $this->_left * $regression['slope'] + $regression['intersection'],\r
- 'x1' => $this->_right,\r
- 'y1' => $this->_right * $regression['slope'] + $regression['intersection']\r
- )\r
- );\r
- }\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- \r
- return true;\r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Line.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Include file Image/Graph/Tool.php
+ */
+require_once 'Image/Graph/Tool.php';
+
+/**
+ * Fit the graph (to a line using linear regression).
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Fit_Line extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $y = ($y0 + $y1) / 2;
+ $dy = abs($y1 - $y0) / 6;
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y + $dy));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));
+ $this->_canvas->polygon(array('connect' => false));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (Image_Graph_Plot::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $data = array();
+ while ($point = $dataset->_next()) {
+ $data[] = array(
+ 'X' => $this->_pointX($point),
+ 'Y' => $this->_pointY($point)
+ );
+ }
+
+ $regression = Image_Graph_Tool::calculateLinearRegression($data);
+ $this->_getLineStyle($key);
+ $this->_canvas->line(
+ array(
+ 'x0' => $this->_left,
+ 'y0' => $this->_left * $regression['slope'] + $regression['intersection'],
+ 'x1' => $this->_right,
+ 'y1' => $this->_right * $regression['slope'] + $regression['intersection']
+ )
+ );
+ }
+ $this->_clip(false);
+ $this->_canvas->endGroup();
+
+ return true;
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Impulse.php,v 1.13 2005/11/27 22:21:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Impulse chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Impulse extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $x = ($x0 + $x1) / 2;\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y0, 'x1' => $x, 'y1' => $y1));\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true); \r
-\r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
- $current = array();\r
- $number = 0;\r
-\r
- $minYaxis = $this->_parent->_getMinimum($this->_axisY);\r
- $maxYaxis = $this->_parent->_getMaximum($this->_axisY);\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $x0 = $this->_pointX($point);\r
- if (($this->_multiType == 'stacked') ||\r
- ($this->_multiType == 'stacked100pct'))\r
- {\r
- $x = $point['X'];\r
-\r
- if ($point['Y'] >= 0) {\r
- if (!isset($current[$x])) {\r
- $current[$x] = 0;\r
- }\r
-\r
- if ($this->_multiType == 'stacked') {\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $current[$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $current[$x] + $point['Y']\r
- );\r
- } else {\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => 100 * $current[$x] / $total['TOTAL_Y'][$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x]\r
- );\r
- }\r
- $current[$x] += $point['Y'];\r
- } else {\r
- if (!isset($currentNegative[$x])) {\r
- $currentNegative[$x] = 0;\r
- }\r
-\r
- $p0 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $currentNegative[$x]\r
- );\r
- $p1 = array(\r
- 'X' => $point['X'],\r
- 'Y' => $currentNegative[$x] + $point['Y']\r
- );\r
- $currentNegative[$x] += $point['Y'];\r
- }\r
- } else {\r
- $p0 = array('X' => $point['X'], 'Y' => 0);\r
- $p1 = $point;\r
- }\r
-\r
- if ((($minY = min($p0['Y'], $p1['Y'])) < $maxYaxis) &&\r
- (($maxY = max($p0['Y'], $p1['Y'])) > $minYaxis)\r
- ) {\r
- $p0['Y'] = $minY;\r
- $p1['Y'] = $maxY;\r
-\r
- if ($p0['Y'] < $minYaxis) {\r
- $p0['Y'] = '#min_pos#';\r
- }\r
- if ($p1['Y'] > $maxYaxis) {\r
- $p1['Y'] = '#max_neg#';\r
- }\r
-\r
- $x1 = $this->_pointX($p0);\r
- $y1 = $this->_pointY($p0);\r
-\r
- $x2 = $this->_pointX($p1);\r
- $y2 = $this->_pointY($p1);\r
-\r
- if ($this->_multiType == 'normal') {\r
- $offset = 5*$number;\r
- $x1 += $offset;\r
- $x2 += $offset;\r
- }\r
-\r
- $ID = $point['ID'];\r
- if (($ID === false) && (count($this->_dataset) > 1)) {\r
- $ID = $key;\r
- }\r
- $this->_getLineStyle($key);\r
- $this->_canvas->line(\r
- $this->_mergeData(\r
- $point,\r
- array(\r
- 'x0' => $x1, \r
- 'y0' => $y1, \r
- 'x1' => $x2, \r
- 'y1' => $y2\r
- )\r
- )\r
- );\r
- }\r
- }\r
- $number++;\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup(); \r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Impulse.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Impulse chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Impulse extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $x = ($x0 + $x1) / 2;
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y0, 'x1' => $x, 'y1' => $y1));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+ $current = array();
+ $number = 0;
+
+ $minYaxis = $this->_parent->_getMinimum($this->_axisY);
+ $maxYaxis = $this->_parent->_getMaximum($this->_axisY);
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $x0 = $this->_pointX($point);
+ if (($this->_multiType == 'stacked')
+ || ($this->_multiType == 'stacked100pct')
+ ) {
+ $x = $point['X'];
+
+ if ($point['Y'] >= 0) {
+ if (!isset($current[$x])) {
+ $current[$x] = 0;
+ }
+
+ if ($this->_multiType == 'stacked') {
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => $current[$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => $current[$x] + $point['Y']
+ );
+ } else {
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => 100 * $current[$x] / $total['TOTAL_Y'][$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x]
+ );
+ }
+ $current[$x] += $point['Y'];
+ } else {
+ if (!isset($currentNegative[$x])) {
+ $currentNegative[$x] = 0;
+ }
+
+ $p0 = array(
+ 'X' => $point['X'],
+ 'Y' => $currentNegative[$x]
+ );
+ $p1 = array(
+ 'X' => $point['X'],
+ 'Y' => $currentNegative[$x] + $point['Y']
+ );
+ $currentNegative[$x] += $point['Y'];
+ }
+ } else {
+ $p0 = array('X' => $point['X'], 'Y' => 0);
+ $p1 = $point;
+ }
+
+ if ((($minY = min($p0['Y'], $p1['Y'])) < $maxYaxis)
+ && (($maxY = max($p0['Y'], $p1['Y'])) > $minYaxis)
+ ) {
+ $p0['Y'] = $minY;
+ $p1['Y'] = $maxY;
+
+ if ($p0['Y'] < $minYaxis) {
+ $p0['Y'] = '#min_pos#';
+ }
+ if ($p1['Y'] > $maxYaxis) {
+ $p1['Y'] = '#max_neg#';
+ }
+
+ $x1 = $this->_pointX($p0);
+ $y1 = $this->_pointY($p0);
+
+ $x2 = $this->_pointX($p1);
+ $y2 = $this->_pointY($p1);
+
+ if ($this->_multiType == 'normal') {
+ $offset = 5*$number;
+ $x1 += $offset;
+ $x2 += $offset;
+ }
+
+ $ID = $point['ID'];
+ if (($ID === false) && (count($this->_dataset) > 1)) {
+ $ID = $key;
+ }
+ $this->_getLineStyle($key);
+ $this->_canvas->line(
+ $this->_mergeData(
+ $point,
+ array(
+ 'x0' => $x1,
+ 'y0' => $y1,
+ 'x1' => $x2,
+ 'y1' => $y2
+ )
+ )
+ );
+ }
+ }
+ $number++;
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Line.php,v 1.15 2006/03/02 12:37:37 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Linechart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Line extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Gets the fill style of the element\r
- *\r
- * @return int A GD filestyle representing the fill style\r
- * @see Image_Graph_Fill\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- return IMG_COLOR_TRANSPARENT;\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $y = ($y0 + $y1) / 2;\r
- $dx = abs($x1 - $x0) / 3;\r
- $dy = abs($y1 - $y0) / 5;\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y));\r
- $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y - $dy * 2));\r
- $this->_canvas->addVertex(array('x' => $x1 - $dx, 'y' => $y + $dy));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));\r
- $this->_canvas->polygon(array('connect' => false));\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- if (!is_array($this->_dataset)) {\r
- return false;\r
- }\r
- \r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- reset($this->_dataset);\r
-\r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
-\r
- $p1 = false;\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $numPoints = 0;\r
- while ($point = $dataset->_next()) {\r
- if (($this->_multiType == 'stacked') ||\r
- ($this->_multiType == 'stacked100pct'))\r
- {\r
- $x = $point['X'];\r
- if (!isset($current[$x])) {\r
- $current[$x] = 0;\r
- }\r
- if ($this->_multiType == 'stacked') {\r
- $py = $current[$x] + $point['Y'];\r
- } else {\r
- $py = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x];\r
- }\r
- $current[$x] += $point['Y'];\r
- $point['Y'] = $py;\r
- }\r
-\r
- if ($point['Y'] === null) {\r
- if ($numPoints > 1) {\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));\r
- }\r
- else {\r
- $this->_canvas->reset();\r
- }\r
- $numPoints = 0;\r
- } else {\r
- $p2['X'] = $this->_pointX($point);\r
- $p2['Y'] = $this->_pointY($point);\r
- \r
- $this->_canvas->addVertex(\r
- $this->_mergeData(\r
- $point,\r
- array('x' => $p2['X'], 'y' => $p2['Y'])\r
- )\r
- );\r
- $numPoints++;\r
- }\r
- }\r
- if ($numPoints > 1) {\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));\r
- }\r
- else {\r
- $this->_canvas->reset();\r
- }\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Line.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Linechart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Line extends Image_Graph_Plot
+{
+
+ /**
+ * Gets the fill style of the element
+ *
+ * @param ??? $ID ???
+ *
+ * @return int A GD filestyle representing the fill style
+ * @see Image_Graph_Fill
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ return IMG_COLOR_TRANSPARENT;
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $y = ($y0 + $y1) / 2;
+ $dx = abs($x1 - $x0) / 3;
+ $dy = abs($y1 - $y0) / 5;
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y));
+ $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y - $dy * 2));
+ $this->_canvas->addVertex(array('x' => $x1 - $dx, 'y' => $y + $dy));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y - $dy));
+ $this->_canvas->polygon(array('connect' => false));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if (!is_array($this->_dataset)) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+ reset($this->_dataset);
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+
+ $p1 = false;
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $numPoints = 0;
+ while ($point = $dataset->_next()) {
+ if (($this->_multiType == 'stacked')
+ || ($this->_multiType == 'stacked100pct')
+ ) {
+ $x = $point['X'];
+ if (!isset($current[$x])) {
+ $current[$x] = 0;
+ }
+ if ($this->_multiType == 'stacked') {
+ $py = $current[$x] + $point['Y'];
+ } else {
+ $py = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x];
+ }
+ $current[$x] += $point['Y'];
+ $point['Y'] = $py;
+ }
+
+ if ($point['Y'] === null) {
+ if ($numPoints > 1) {
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
+ } else {
+ $this->_canvas->reset();
+ }
+ $numPoints = 0;
+ } else {
+ $p2['X'] = $this->_pointX($point);
+ $p2['Y'] = $this->_pointY($point);
+
+ $this->_canvas->addVertex(
+ $this->_mergeData(
+ $point,
+ array('x' => $p2['X'], 'y' => $p2['Y'])
+ )
+ );
+ $numPoints++;
+ }
+ }
+ if ($numPoints > 1) {
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
+ } else {
+ $this->_canvas->reset();
+ }
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Odo.php,v 1.3 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Include file Image/Graph/Tool.php\r
- */\r
-require_once 'Image/Graph/Tool.php';\r
-\r
-/**\r
- * 2D Odochart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Maxime Delorme <mdelorme@tennaxia.com>\r
- * @copyright Copyright (C) 2005 Maxime Delorme\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Odo extends Image_Graph_Plot\r
-{\r
- /**\r
- * the percent of the radius of the chart that will be use as the width of the range\r
- * @access private\r
- * @var int\r
- */\r
- var $_radiusPercent = 50;\r
-\r
- /**\r
- * the minimun value of the chart or the start value\r
- * @access private\r
- * @var int\r
- */\r
- var $_value_min = 0;\r
-\r
- /**\r
- * the maximum value of the chart or the end value\r
- * @access private\r
- * @var int\r
- */\r
- var $_value_max = 100;\r
-\r
- /**\r
- * the start angle\r
- * @access private\r
- * @var int\r
- */\r
- var $_deg_offset = 135;\r
-\r
- /**\r
- * the angle of the chart , the length of the chart\r
- * 180 min a half circle\r
- * @access private\r
- * @var int\r
- */\r
- var $_deg_width = 270;\r
-\r
- /**\r
- * the length of the big ticks\r
- * the small ones will be half ot it, the values 160% of it\r
- * 180 min a half circle\r
- * @access private\r
- * @var int\r
- */\r
- var $_tickLength = 14;\r
-\r
- /**\r
- * how many small ticks a big tick appears\r
- * the small ticks appear every 6°\r
- * so with the default value of 5, every 30° there is a value and a big tick\r
- * 180 min a half circle\r
- * @access private\r
- * @var int\r
- */\r
- var $_axisTicks = 5;\r
- \r
- /**\r
- * Arrow marker\r
- * @access private\r
- * @var Image_Graph_Marker\r
- */\r
- var $_arrowMarker;\r
- \r
- /**\r
- * Range marker fill style\r
- * @access private\r
- * @var Image_Graph_Fill\r
- */\r
- var $_rangeFillStyle = null;\r
- \r
- /**\r
- * The width of the arrow\r
- * @access private\r
- * @var int\r
- */\r
- var $_arrowWidth = 5; \r
-\r
- /**\r
- * The length of the arrow\r
- * @access private\r
- * @var int\r
- */\r
- var $_arrowLength = 80;\r
- \r
- /**\r
- * The radius of the plot\r
- * @access private\r
- * @var int\r
- */\r
- var $_radius = false;\r
- \r
- /**\r
- * The total Y\r
- * @access private\r
- * @var int\r
- */\r
- var $_totalY = false;\r
-\r
- /**\r
- * Center X of odometer "circle"\r
- * @access private\r
- * @var int\r
- */\r
- var $_centerX = false;\r
-\r
- /**\r
- * Center y of odometer "circle"\r
- * @access private\r
- * @var int\r
- */\r
- var $_centerY = false;\r
-\r
- /**\r
- * Plot_Odo [Constructor]\r
- *\r
- * dataset with one data per arrow\r
- * @param Image_Graph_Dataset $dataset The data set (value containter) to\r
- * plot or an array of datasets\r
- * {@link Image_Graph_Legend}\r
- */\r
- function Image_Graph_Plot_Odo(&$dataset)\r
- {\r
- parent::Image_Graph_Plot($dataset);\r
- \r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- if (isset($min)) {\r
- $min = min($dataset->minimumY(), $min);\r
- }\r
- else {\r
- $min = $dataset->minimumY();\r
- }\r
- if (isset($max)) {\r
- $max = max($dataset->maximumY(), $max);\r
- }\r
- else {\r
- $max = $dataset->maximumY();\r
- }\r
- }\r
- $this->_value_min = $min;\r
- $this->_value_max = $max;\r
- }\r
-\r
- /**\r
- * Set the center of the odometer\r
- * \r
- * @param int $centerX The center x point\r
- * @param int $centerY The center y point\r
- */\r
- function setCenter($centerX, $centerY)\r
- {\r
- $this->_centerX = $centerX;\r
- $this->_centerY = $centerY;\r
- }\r
-\r
- /**\r
- * Convert a value to the angle position onto the odometer\r
- *\r
- * @access private\r
- * @param int $value the value to convert\r
- * @return int the angle'position onto the odometer\r
- */\r
- function _value2angle($value)\r
- {\r
- return $this->_deg_width * (($value - $this->_value_min) / $this->_totalY) + $this->_deg_offset;\r
- }\r
- \r
- /**\r
- * set some internal var\r
- *\r
- * @access private\r
- */\r
- function _initialize()\r
- {\r
- $v1 = $this->_deg_offset;\r
- $v2 = $this->_deg_offset + $this->_deg_width;\r
- \r
- $dimensions = Image_Graph_Tool::calculateArcDimensionAndCenter($v1, $v2);\r
- \r
- $radiusX = ($this->width() / 2) / $dimensions['rx'];\r
- $radiusY = ($this->height() / 2) / $dimensions['ry'];\r
- \r
- $this->_radius = min($radiusX, $radiusY);\r
- \r
- if ($this->_marker) {\r
- $this->_radius = $this->_radius * 0.85;\r
- } \r
- \r
- //the center of the plot\r
- if ($this->_centerX === false) { \r
- $this->_centerX = (int) (($this->_left + $this->_right) / 2) +\r
- $this->_radius * ($dimensions['cx'] - 0.5);\r
- }\r
- \r
- if ($this->_centerY === false) {\r
- $this->_centerY = (int) (($this->_top + $this->_bottom) / 2) +\r
- $this->_radius * ($dimensions['cy'] - 0.5);\r
- }\r
- \r
- //the max range\r
- $this->_totalY = abs($this->_value_max - $this->_value_min);\r
- }\r
-\r
- /**\r
- * set min and max value of the range\r
- *\r
- * @access public\r
- * @param integer $value_min the minimun value of the chart or the start value\r
- * @param integer $value_max the maximum value of the chart or the end value\r
- */\r
- function setRange($value_min, $value_max)\r
- {\r
- $this->_value_min = $value_min;\r
- $this->_value_max = $value_max;\r
- }\r
-\r
- /**\r
- * Set start's angle and amplitude of the chart\r
- *\r
- * @access public\r
- * @param integer $deg_offset the start angle\r
- * @param integer $deg_width the angle of the chart (the length)\r
- */\r
- function setAngles($deg_offset, $deg_width)\r
- {\r
- $this->_deg_offset = min(360, abs($deg_offset));\r
- $this->_deg_width = min(360, abs($deg_width));\r
- }\r
-\r
- /**\r
- * set the width of the chart\r
- *\r
- * @access public\r
- * @param string $radius_percent a value between 0 and 100\r
- */\r
- function setRadiusWidth($radius_percent)\r
- {\r
- $this->_radiusPercent = $radius_percent;\r
- }\r
- \r
- /**\r
- * set the width and length of the arrow (in percent of the total plot "radius")\r
- * \r
- * @param int length The length in percent\r
- * @param int width The width in percent \r
- */\r
- function setArrowSize($length, $width)\r
- {\r
- $this->_arrowWidth = max(0, min(100, $width));\r
- $this->_arrowLength = max(0, min(100, $length));\r
- }\r
-\r
- /**\r
- * Set the arrow marker\r
- * @param Image_Graph_Marker $marker The marker to set for arrow marker\r
- */\r
- function setArrowMarker(&$marker)\r
- {\r
- $this->_arrowMarker =& $marker;\r
- }\r
- \r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
- $this->_initialize();\r
- $this->_drawRange();\r
- $this->_drawAxis();\r
- $this->_drawArrow();\r
- $this->_drawMarker();\r
- return true;\r
- }\r
-\r
- /**\r
- * set the length of the ticks\r
- *\r
- * @access public\r
- * @param string $radius_percent a value between 0 and 100\r
- */\r
- function setTickLength($radius)\r
- {\r
- $this->_tickLength = $radius;\r
- }\r
-\r
- /**\r
- * set the length of the ticks\r
- *\r
- * @access public\r
- * @param string $radius_percent a value between 0 and 100\r
- */\r
- function setAxisTicks($int)\r
- {\r
- $this->_axisTicks = $int;\r
- }\r
-\r
- /**\r
- * Draw the outline and the axis\r
- *\r
- * @access private\r
- */\r
- function _drawAxis()\r
- {\r
- //draw outline\r
- $this->_getLineStyle();\r
- $this->_canvas->pieslice(\r
- array(\r
- 'x' => $this->_centerX,\r
- 'y' => $this->_centerY,\r
- 'rx' => $this->_radius,\r
- 'ry' => $this->_radius,\r
- 'v1' => $this->_deg_offset,\r
- 'v2' => $this->_deg_offset+$this->_deg_width,\r
- 'srx' => $this->_radius * (1 - $this->_radiusPercent / 100),\r
- 'sry' => $this->_radius * (1 - $this->_radiusPercent / 100)\r
- )\r
- );\r
- \r
- //step for every 6°\r
- $step = (int) ($this->_totalY / $this->_deg_width * 6);\r
- $value = $this->_value_min;\r
- $i = 0;\r
- while ($value <= $this->_value_max) {\r
- $angle = $this->_value2angle($value);\r
-\r
- $cos = cos(deg2rad($angle));\r
- $sin = sin(deg2rad($angle));\r
- $point = array('Y' => $value);\r
- $point['AX'] = $cos;\r
- $point['AY'] = $sin;\r
- $point['LENGTH'] = 1;\r
- $x = $this->_centerX + $this->_radius * $cos;\r
- $y = $this->_centerY + $this->_radius * $sin;\r
- $deltaX = - $cos * $this->_tickLength ;\r
- $deltaY = - $sin * $this->_tickLength ;\r
- $this->_getLineStyle();\r
- if(($i % $this->_axisTicks) == 0){\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $deltaX, 'y1' => $y + $deltaY));\r
- if ($this->_arrowMarker) {\r
- $this->_arrowMarker->_drawMarker($x + $deltaX * 1.6, $y + $deltaY *1.6, $point);\r
- }\r
- } else {\r
- $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $deltaX * 0.5, 'y1' => $y + $deltaY * 0.5));\r
- }\r
- $i++;\r
- $value += $step;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Set the line style of the arrows\r
- *\r
- * @param Image_Graph_Line $lineStyle The line style of the Arrow\r
- * @see Image_Graph_Line\r
- * @access public\r
- */\r
- function setArrowLineStyle($lineStyle)\r
- {\r
- $this->_arrowLineStyle = &$lineStyle;\r
- }\r
-\r
- /**\r
- * Set the fillstyle of the arrows\r
- *\r
- * @param Image_Graph_Fill $fillStyle The fill style of the arrows\r
- * @see Image_Graph_Fill\r
- * @access public\r
- */\r
- function setArrowFillStyle($fillStyle)\r
- {\r
- $this->_arrowFillStyle = &$fillStyle;\r
- }\r
-\r
- /**\r
- * Draw the arrows\r
- *\r
- * @access private\r
- */\r
- function _drawArrow()\r
- {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $this->setLineStyle($this->_arrowLineStyle);\r
- $this->setFillStyle($this->_arrowFillStyle);\r
- while ($point = $dataset->_next()) {\r
- $ID = $point['ID'];\r
- $this->_getFillStyle($ID);\r
- $this->_getLineStyle($ID);\r
- $deg = $this->_value2angle($point['Y']);\r
- list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX + $this->_arrowLength * $this->_radius / 100, $this->_centerY, $this->_centerX, $this->_centerY, $deg);\r
- $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));\r
- list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX, $this->_centerY - $this->_arrowWidth * $this->_radius/100, $this->_centerX, $this->_centerY, $deg);\r
- $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));\r
- list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX - $this->_arrowWidth * $this->_radius / 100, $this->_centerY, $this->_centerX, $this->_centerY, $deg);\r
- $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));\r
- list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX,$this->_centerY + $this->_arrowWidth * $this->_radius / 100, $this->_centerX, $this->_centerY, $deg);\r
- $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Calculate marker point data\r
- *\r
- * @param array $point The point to calculate data for\r
- * @param array $nextPoint The next point\r
- * @param array $prevPoint The previous point\r
- * @param array $totals The pre-calculated totals, if needed\r
- * @return array An array containing marker point data\r
- * @access private\r
- */\r
- function _getMarkerData($point, $nextPoint, $prevPoint, &$totals)\r
- {\r
- $point = parent::_getMarkerData($point, $nextPoint, $prevPoint, $totals);\r
- \r
- $point['ANGLE'] = $this->_value2angle($point['Y']);\r
-\r
- $point['ANG_X'] = cos(deg2rad($point['ANGLE']));\r
- $point['ANG_Y'] = sin(deg2rad($point['ANGLE']));\r
-\r
- $point['AX'] = -$point['ANG_X'];\r
- $point['AY'] = -$point['ANG_Y'];\r
-\r
- $point['LENGTH'] = 2.5; //$radius;\r
-\r
- $point['MARKER_X'] = $totals['CENTER_X'] +\r
- $totals['ODO_RADIUS'] * $point['ANG_X'];\r
- $point['MARKER_Y'] = $totals['CENTER_Y'] +\r
- $totals['ODO_RADIUS'] * $point['ANG_Y'];\r
-\r
- return $point;\r
- }\r
-\r
- /**\r
- * Draws markers of the arrows on the canvas\r
- *\r
- * @access private\r
- */\r
- function _drawMarker()\r
- {\r
-\r
- if ($this->_marker) {\r
- $this->_marker->_radius += $this->_radius / 2;\r
- $totals = $this->_getTotals();\r
-\r
- $totals['CENTER_X'] = $this->_centerX;\r
- $totals['CENTER_Y'] = $this->_centerY;\r
-\r
-\r
- /* $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) { */\r
- $dataset =& $this->_dataset[0];\r
-\r
- $totals['RADIUS0'] = false;\r
- $totals['ODO_RADIUS'] = 1.1 * $this->_radius * $this->_arrowLength / 100;\r
- $totals['ALL_SUM_Y'] = $this->_totalY;\r
-\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- if ((!is_object($this->_dataSelector)) ||\r
- ($this->_dataSelector->select($point))\r
- ) {\r
- $point = $this->_getMarkerData(\r
- $point,\r
- false,\r
- false,\r
- $totals\r
- );\r
- if (is_array($point)) {\r
- $this->_marker->_drawMarker(\r
- $point['MARKER_X'],\r
- $point['MARKER_Y'],\r
- $point\r
- );\r
- }\r
- }\r
- }\r
- /* }\r
- unset($keys); */\r
- }\r
- }\r
-\r
- /**\r
- * Set range\r
- *\r
- * dataset with two data start and end value of the range\r
- * @param Image_Graph_Dataset $dataset The data set (value containter) to\r
- * plot or an array of datasets\r
- *\r
- */\r
- function addRangeMarker($min, $max, $id = false)\r
- {\r
- $this->_range[] = \r
- array(\r
- 'min' => max($this->_value_min, min($min, $max)), \r
- 'max' => min($this->_value_max, max($min, $max)), \r
- 'id' => $id\r
- );\r
- }\r
-\r
- /**\r
- * Set the fillstyle of the ranges\r
- *\r
- * @param Image_Graph_Fill $fillStyle The fill style of the range\r
- * @see Image_Graph_Fill\r
- * @access public\r
- */\r
- function &setRangeMarkerFillStyle(&$rangeMarkerFillStyle)\r
- {\r
- $this->_rangeFillStyle = $rangeMarkerFillStyle;\r
- }\r
-\r
- /**\r
- * Draw the ranges\r
- *\r
- * @access private\r
- */\r
- function _drawRange()\r
- {\r
- if($this->_range){\r
- $radius0 = $this->_radius * (1 - $this->_radiusPercent/100);\r
- foreach ($this->_range as $range) {\r
- $angle1 = $this->_value2angle($range['min']);\r
- $angle2 = $this->_value2angle($range['max']);\r
-\r
- if (is_object($this->_rangeFillStyle)) {\r
- $this->_canvas->setFill($this->_rangeFillStyle->_getFillStyle($range['id']));\r
- } elseif ($this->_rangeFillStyle != null) {\r
- $this->_canvas->setFill($this->_rangeFillStyle);\r
- } \r
- $this->_getLineStyle();\r
- $this->_canvas->Pieslice(\r
- array(\r
- 'x' => $this->_centerX,\r
- 'y' => $this->_centerY,\r
- 'rx' => $this->_radius,\r
- 'ry' => $this->_radius,\r
- 'v1' => $angle1,\r
- 'v2' => $angle2,\r
- 'srx' => $radius0,\r
- 'sry' => $radius0\r
- )\r
- );\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $dx = abs($x1 - $x0) / 4;\r
- $this->_canvas->addVertex(array('x' => $x0 + $dx , 'y' => $y1));\r
- $this->_canvas->addVertex(array('x' => ($x0 + $x1) / 2, 'y' => $y0 ));\r
- $this->_canvas->addVertex(array('x' => $x1 - $dx , 'y' => $y1));\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * Draw a sample for use with legend\r
- *\r
- * @param array $param The parameters for the legend\r
- * @access private\r
- */\r
- function _legendSample(&$param)\r
- {\r
- if (is_array($this->_dataset)) {\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- \r
- $totals = $this->_getTotals();\r
- $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);\r
- $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);\r
- $totals['RADIUS'] = min($this->height(), $this->width()) * 0.75 * 0.5;\r
- $totals['CURRENT_Y'] = 0;\r
-\r
- if (is_a($this->_fillStyle, "Image_Graph_Fill")) {\r
- $this->_fillStyle->_reset();\r
- }\r
-\r
- $count = 0;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $count++;\r
-\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $caption = $point['X'];\r
-\r
- $this->_canvas->setFont($param['font']);\r
- $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- $param['maxwidth'] = max($param['maxwidth'], $width);\r
- $x2 = $param['x'] + $width;\r
- $y2 = $param['y'] + $param['height'] + 5;\r
-\r
- if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {\r
- $param['y'] = $param['top'];\r
- $param['x'] = $x2;\r
- $y2 = $param['y'] + $param['height'];\r
- } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {\r
- $param['x'] = $param['left'];\r
- $param['y'] = $y2;\r
- $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- }\r
-\r
- $x = $x0 = $param['x'];\r
- $y = $param['y'];\r
- $y0 = $param['y'] - $param['height'] / 2;\r
- $x1 = $param['x'] + $param['width'];\r
- $y1 = $param['y'] + $param['height'] / 2;\r
-\r
- if (!isset($param['simulate'])) {\r
- $this->_getFillStyle($point['ID']);\r
- $this->_getLineStyle($point['ID']);\r
- $this->_drawLegendSample($x0, $y0, $x1, $y1);\r
-\r
- if (($this->_marker) && ($dataset) && ($param['show_marker'])) {\r
- $prevPoint = $dataset->_nearby(-2);\r
- $nextPoint = $dataset->_nearby();\r
-\r
- $p = $this->_getMarkerData($point, $nextPoint, $prevPoint, $totals);\r
- if (is_array($point)) {\r
- $p['MARKER_X'] = $x+$param['width'] / 2;\r
- $p['MARKER_Y'] = $y;\r
- unset ($p['AVERAGE_Y']);\r
- $this->_marker->_drawMarker($p['MARKER_X'], $p['MARKER_Y'], $p);\r
- }\r
- }\r
- $this->write($x + $param['width'] + 10, $y, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);\r
- }\r
-\r
- if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {\r
- $param['y'] = $y2;\r
- } else {\r
- $param['x'] = $x2;\r
- }\r
- }\r
- }\r
- unset($keys);\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- }\r
- }\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Odo.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Include file Image/Graph/Tool.php
+ */
+require_once 'Image/Graph/Tool.php';
+
+/**
+ * 2D Odochart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Maxime Delorme <mdelorme@tennaxia.com>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Odo extends Image_Graph_Plot
+{
+ /**
+ * the percent of the radius of the chart that will be use as the width of the range
+ * @access private
+ * @var int
+ */
+ var $_radiusPercent = 50;
+
+ /**
+ * the minimun value of the chart or the start value
+ * @access private
+ * @var int
+ */
+ var $_value_min = 0;
+
+ /**
+ * the maximum value of the chart or the end value
+ * @access private
+ * @var int
+ */
+ var $_value_max = 100;
+
+ /**
+ * the start angle
+ * @access private
+ * @var int
+ */
+ var $_deg_offset = 135;
+
+ /**
+ * the angle of the chart , the length of the chart
+ * 180 min a half circle
+ * @access private
+ * @var int
+ */
+ var $_deg_width = 270;
+
+ /**
+ * the length of the big ticks
+ * the small ones will be half ot it, the values 160% of it
+ * 180 min a half circle
+ * @access private
+ * @var int
+ */
+ var $_tickLength = 14;
+
+ /**
+ * how many small ticks a big tick appears
+ * the small ticks appear every 6�
+ * so with the default value of 5, every 30� there is a value and a big tick
+ * 180 min a half circle
+ * @access private
+ * @var int
+ */
+ var $_axisTicks = 5;
+
+ /**
+ * Arrow marker
+ * @access private
+ * @var Image_Graph_Marker
+ */
+ var $_arrowMarker;
+
+ /**
+ * Range marker fill style
+ * @access private
+ * @var Image_Graph_Fill
+ */
+ var $_rangeFillStyle = null;
+
+ /**
+ * The width of the arrow
+ * @access private
+ * @var int
+ */
+ var $_arrowWidth = 5;
+
+ /**
+ * The length of the arrow
+ * @access private
+ * @var int
+ */
+ var $_arrowLength = 80;
+
+ /**
+ * The radius of the plot
+ * @access private
+ * @var int
+ */
+ var $_radius = false;
+
+ /**
+ * The total Y
+ * @access private
+ * @var int
+ */
+ var $_totalY = false;
+
+ /**
+ * Center X of odometer "circle"
+ * @access private
+ * @var int
+ */
+ var $_centerX = false;
+
+ /**
+ * Center y of odometer "circle"
+ * @access private
+ * @var int
+ */
+ var $_centerY = false;
+
+ /**
+ * Plot_Odo [Constructor]
+ *
+ * dataset with one data per arrow
+ *
+ * @param Image_Graph_Dataset &$dataset The data set (value containter) to
+ * plot or an array of datasets
+ * {@link Image_Graph_Legend}
+ *
+ * @return void
+ */
+ function Image_Graph_Plot_Odo(&$dataset)
+ {
+ parent::__construct($dataset);
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ if (isset($min)) {
+ $min = min($dataset->minimumY(), $min);
+ } else {
+ $min = $dataset->minimumY();
+ }
+ if (isset($max)) {
+ $max = max($dataset->maximumY(), $max);
+ } else {
+ $max = $dataset->maximumY();
+ }
+ }
+ $this->_value_min = $min;
+ $this->_value_max = $max;
+ }
+
+ /**
+ * Set the center of the odometer
+ *
+ * @param int $centerX The center x point
+ * @param int $centerY The center y point
+ *
+ * @return void
+ */
+ function setCenter($centerX, $centerY)
+ {
+ $this->_centerX = $centerX;
+ $this->_centerY = $centerY;
+ }
+
+ /**
+ * Convert a value to the angle position onto the odometer
+ *
+ * @param int $value the value to convert
+ *
+ * @return int the angle'position onto the odometer
+ * @access private
+ */
+ function _value2angle($value)
+ {
+ return $this->_deg_width * (($value - $this->_value_min) / $this->_totalY) + $this->_deg_offset;
+ }
+
+ /**
+ * set some internal var
+ *
+ * @return void
+ * @access private
+ */
+ function _initialize()
+ {
+ $v1 = $this->_deg_offset;
+ $v2 = $this->_deg_offset + $this->_deg_width;
+
+ $dimensions = Image_Graph_Tool::calculateArcDimensionAndCenter($v1, $v2);
+
+ $radiusX = ($this->width() / 2) / $dimensions['rx'];
+ $radiusY = ($this->height() / 2) / $dimensions['ry'];
+
+ $this->_radius = min($radiusX, $radiusY);
+
+ if ($this->_marker) {
+ $this->_radius = $this->_radius * 0.85;
+ }
+
+ //the center of the plot
+ if ($this->_centerX === false) {
+ $this->_centerX = (int) (($this->_left + $this->_right) / 2) +
+ $this->_radius * ($dimensions['cx'] - 0.5);
+ }
+
+ if ($this->_centerY === false) {
+ $this->_centerY = (int) (($this->_top + $this->_bottom) / 2) +
+ $this->_radius * ($dimensions['cy'] - 0.5);
+ }
+
+ //the max range
+ $this->_totalY = abs($this->_value_max - $this->_value_min);
+ }
+
+ /**
+ * set min and max value of the range
+ *
+ * @param integer $value_min the minimun value of the chart or the start value
+ * @param integer $value_max the maximum value of the chart or the end value
+ *
+ * @return void
+ * @access public
+ */
+ function setRange($value_min, $value_max)
+ {
+ $this->_value_min = $value_min;
+ $this->_value_max = $value_max;
+ }
+
+ /**
+ * Set start's angle and amplitude of the chart
+ *
+ * @param integer $deg_offset the start angle
+ * @param integer $deg_width the angle of the chart (the length)
+ *
+ * @return void
+ * @access public
+ */
+ function setAngles($deg_offset, $deg_width)
+ {
+ $this->_deg_offset = min(360, abs($deg_offset));
+ $this->_deg_width = min(360, abs($deg_width));
+ }
+
+ /**
+ * set the width of the chart
+ *
+ * @param string $radius_percent a value between 0 and 100
+ *
+ * @return void
+ * @access public
+ */
+ function setRadiusWidth($radius_percent)
+ {
+ $this->_radiusPercent = $radius_percent;
+ }
+
+ /**
+ * set the width and length of the arrow (in percent of the total plot "radius")
+ *
+ * @param int $length The length in percent
+ * @param int $width The width in percent
+ *
+ * @return void
+ */
+ function setArrowSize($length, $width)
+ {
+ $this->_arrowWidth = max(0, min(100, $width));
+ $this->_arrowLength = max(0, min(100, $length));
+ }
+
+ /**
+ * Set the arrow marker
+ *
+ * @param Image_Graph_Marker &$marker The marker to set for arrow marker
+ *
+ * @return void
+ */
+ function setArrowMarker(&$marker)
+ {
+ $this->_arrowMarker =& $marker;
+ }
+
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+ $this->_initialize();
+ $this->_drawRange();
+ $this->_drawAxis();
+ $this->_drawArrow();
+ $this->_drawMarker();
+ return true;
+ }
+
+ /**
+ * set the length of the ticks
+ *
+ * @param int $length Length of ticks
+ *
+ * @return void
+ * @access public
+ */
+ function setTickLength($length)
+ {
+ $this->_tickLength = $length;
+ }
+
+ /**
+ * set the axis ticks
+ *
+ * @param int $ticks Ticks on axis
+ *
+ * @return void
+ * @access public
+ */
+ function setAxisTicks($ticks)
+ {
+ $this->_axisTicks = $ticks;
+ }
+
+ /**
+ * Draw the outline and the axis
+ *
+ * @return void
+ * @access private
+ */
+ function _drawAxis()
+ {
+ //draw outline
+ $this->_getLineStyle();
+ $this->_canvas->pieslice(
+ array(
+ 'x' => $this->_centerX,
+ 'y' => $this->_centerY,
+ 'rx' => $this->_radius,
+ 'ry' => $this->_radius,
+ 'v1' => $this->_deg_offset,
+ 'v2' => $this->_deg_offset+$this->_deg_width,
+ 'srx' => $this->_radius * (1 - $this->_radiusPercent / 100),
+ 'sry' => $this->_radius * (1 - $this->_radiusPercent / 100)
+ )
+ );
+
+ //step for every 6�
+ $step = (int) ($this->_totalY / $this->_deg_width * 6);
+ $value = $this->_value_min;
+ $i = 0;
+ while ($value <= $this->_value_max) {
+ $angle = $this->_value2angle($value);
+
+ $cos = cos(deg2rad($angle));
+ $sin = sin(deg2rad($angle));
+ $point = array('Y' => $value);
+ $point['AX'] = $cos;
+ $point['AY'] = $sin;
+ $point['LENGTH'] = 1;
+ $x = $this->_centerX + $this->_radius * $cos;
+ $y = $this->_centerY + $this->_radius * $sin;
+ $deltaX = - $cos * $this->_tickLength ;
+ $deltaY = - $sin * $this->_tickLength ;
+ $this->_getLineStyle();
+ if (($i % $this->_axisTicks) == 0) {
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $deltaX, 'y1' => $y + $deltaY));
+ if ($this->_arrowMarker) {
+ $this->_arrowMarker->_drawMarker($x + $deltaX * 1.6, $y + $deltaY *1.6, $point);
+ }
+ } else {
+ $this->_canvas->line(array('x0' => $x, 'y0' => $y, 'x1' => $x + $deltaX * 0.5, 'y1' => $y + $deltaY * 0.5));
+ }
+ $i++;
+ $value += $step;
+ }
+
+ }
+
+ /**
+ * Set the line style of the arrows
+ *
+ * @param Image_Graph_Line $lineStyle The line style of the Arrow
+ *
+ * @return void
+ * @see Image_Graph_Line
+ * @access public
+ */
+ function setArrowLineStyle($lineStyle)
+ {
+ $this->_arrowLineStyle = &$lineStyle;
+ }
+
+ /**
+ * Set the fillstyle of the arrows
+ *
+ * @param Image_Graph_Fill $fillStyle The fill style of the arrows
+ *
+ * @return void
+ * @see Image_Graph_Fill
+ * @access public
+ */
+ function setArrowFillStyle($fillStyle)
+ {
+ $this->_arrowFillStyle = &$fillStyle;
+ }
+
+ /**
+ * Draw the arrows
+ *
+ * @return void
+ * @access private
+ */
+ function _drawArrow()
+ {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $this->setLineStyle($this->_arrowLineStyle);
+ $this->setFillStyle($this->_arrowFillStyle);
+ while ($point = $dataset->_next()) {
+ $ID = $point['ID'];
+ $this->_getFillStyle($ID);
+ $this->_getLineStyle($ID);
+ $deg = $this->_value2angle($point['Y']);
+ list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX + $this->_arrowLength * $this->_radius / 100, $this->_centerY, $this->_centerX, $this->_centerY, $deg);
+ $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));
+ list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX, $this->_centerY - $this->_arrowWidth * $this->_radius/100, $this->_centerX, $this->_centerY, $deg);
+ $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));
+ list($xr,$yr) = Image_Graph_Tool::rotate($this->_centerX - $this->_arrowWidth * $this->_radius / 100, $this->_centerY, $this->_centerX, $this->_centerY, $deg);
+ $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));
+ list($xr, $yr) = Image_Graph_Tool::rotate(
+ $this->_centerX,
+ $this->_centerY + $this->_arrowWidth * $this->_radius / 100,
+ $this->_centerX,
+ $this->_centerY,
+ $deg
+ );
+ $this->_canvas->addVertex(array('x' => $xr, 'y' => $yr));
+ $this->_canvas->polygon(array('connect' => true));
+ }
+ }
+ }
+
+ /**
+ * Calculate marker point data
+ *
+ * @param array $point The point to calculate data for
+ * @param array $nextPoint The next point
+ * @param array $prevPoint The previous point
+ * @param array &$totals The pre-calculated totals, if needed
+ *
+ * @return array An array containing marker point data
+ * @access private
+ */
+ function _getMarkerData($point, $nextPoint, $prevPoint, &$totals)
+ {
+ $point = parent::_getMarkerData($point, $nextPoint, $prevPoint, $totals);
+
+ $point['ANGLE'] = $this->_value2angle($point['Y']);
+
+ $point['ANG_X'] = cos(deg2rad($point['ANGLE']));
+ $point['ANG_Y'] = sin(deg2rad($point['ANGLE']));
+
+ $point['AX'] = -$point['ANG_X'];
+ $point['AY'] = -$point['ANG_Y'];
+
+ $point['LENGTH'] = 2.5; //$radius;
+
+ $point['MARKER_X'] = $totals['CENTER_X'] +
+ $totals['ODO_RADIUS'] * $point['ANG_X'];
+ $point['MARKER_Y'] = $totals['CENTER_Y'] +
+ $totals['ODO_RADIUS'] * $point['ANG_Y'];
+
+ return $point;
+ }
+
+ /**
+ * Draws markers of the arrows on the canvas
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker()
+ {
+
+ if ($this->_marker) {
+ $this->_marker->_radius += $this->_radius / 2;
+ $totals = $this->_getTotals();
+
+ $totals['CENTER_X'] = $this->_centerX;
+ $totals['CENTER_Y'] = $this->_centerY;
+
+
+ /* $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) { */
+ $dataset =& $this->_dataset[0];
+
+ $totals['RADIUS0'] = false;
+ $totals['ODO_RADIUS'] = 1.1 * $this->_radius * $this->_arrowLength / 100;
+ $totals['ALL_SUM_Y'] = $this->_totalY;
+
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ if ((!is_object($this->_dataSelector))
+ || ($this->_dataSelector->select($point))
+ ) {
+ $point = $this->_getMarkerData(
+ $point,
+ false,
+ false,
+ $totals
+ );
+ if (is_array($point)) {
+ $this->_marker->_drawMarker(
+ $point['MARKER_X'],
+ $point['MARKER_Y'],
+ $point
+ );
+ }
+ }
+ }
+ /* }
+ unset($keys); */
+ }
+ }
+
+ /**
+ * Set range
+ *
+ * add dataset with two data start and end value of the range
+ *
+ * @param float $min ???
+ * @param float $max ???
+ * @param boolean $id ??? (optional)
+ *
+ * @return void
+ */
+ function addRangeMarker($min, $max, $id = false)
+ {
+ $this->_range[] = array(
+ 'min' => max($this->_value_min, min($min, $max)),
+ 'max' => min($this->_value_max, max($min, $max)),
+ 'id' => $id
+ );
+ }
+
+ /**
+ * Set the fillstyle of the ranges
+ *
+ * @param Image_Graph_Fill &$rangeMarkerFillStyle The fill style of the range marker
+ *
+ * @return void
+ * @see Image_Graph_Fill
+ * @access public
+ */
+ function &setRangeMarkerFillStyle(&$rangeMarkerFillStyle)
+ {
+ $this->_rangeFillStyle = &$rangeMarkerFillStyle;
+ return $rangeMarkerFillStyle;
+ }
+
+ /**
+ * Draw the ranges
+ *
+ * @return void
+ * @access private
+ */
+ function _drawRange()
+ {
+ if ($this->_range) {
+ $radius0 = $this->_radius * (1 - $this->_radiusPercent/100);
+ foreach ($this->_range as $range) {
+ $angle1 = $this->_value2angle($range['min']);
+ $angle2 = $this->_value2angle($range['max']);
+
+ if (is_object($this->_rangeFillStyle)) {
+ $this->_canvas->setFill($this->_rangeFillStyle->_getFillStyle($range['id']));
+ } elseif ($this->_rangeFillStyle != null) {
+ $this->_canvas->setFill($this->_rangeFillStyle);
+ }
+ $this->_getLineStyle();
+ $this->_canvas->Pieslice(
+ array(
+ 'x' => $this->_centerX,
+ 'y' => $this->_centerY,
+ 'rx' => $this->_radius,
+ 'ry' => $this->_radius,
+ 'v1' => $angle1,
+ 'v2' => $angle2,
+ 'srx' => $radius0,
+ 'sry' => $radius0
+ )
+ );
+ }
+ }
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $dx = abs($x1 - $x0) / 4;
+ $this->_canvas->addVertex(array('x' => $x0 + $dx , 'y' => $y1));
+ $this->_canvas->addVertex(array('x' => ($x0 + $x1) / 2, 'y' => $y0 ));
+ $this->_canvas->addVertex(array('x' => $x1 - $dx , 'y' => $y1));
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * Draw a sample for use with legend
+ *
+ * @param array &$param The parameters for the legend
+ *
+ * @return void
+ * @access private
+ */
+ function _legendSample(&$param)
+ {
+ if (is_array($this->_dataset)) {
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $totals = $this->_getTotals();
+ $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);
+ $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);
+ $totals['RADIUS'] = min($this->height(), $this->width()) * 0.75 * 0.5;
+ $totals['CURRENT_Y'] = 0;
+
+ if (is_a($this->_fillStyle, "Image_Graph_Fill")) {
+ $this->_fillStyle->_reset();
+ }
+
+ $count = 0;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $count++;
+
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $caption = $point['X'];
+
+ $this->_canvas->setFont($param['font']);
+ $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ $param['maxwidth'] = max($param['maxwidth'], $width);
+ $x2 = $param['x'] + $width;
+ $y2 = $param['y'] + $param['height'] + 5;
+
+ if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {
+ $param['y'] = $param['top'];
+ $param['x'] = $x2;
+ $y2 = $param['y'] + $param['height'];
+ } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {
+ $param['x'] = $param['left'];
+ $param['y'] = $y2;
+ $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ }
+
+ $x = $x0 = $param['x'];
+ $y = $param['y'];
+ $y0 = $param['y'] - $param['height'] / 2;
+ $x1 = $param['x'] + $param['width'];
+ $y1 = $param['y'] + $param['height'] / 2;
+
+ if (!isset($param['simulate'])) {
+ $this->_getFillStyle($point['ID']);
+ $this->_getLineStyle($point['ID']);
+ $this->_drawLegendSample($x0, $y0, $x1, $y1);
+
+ if (($this->_marker) && ($dataset) && ($param['show_marker'])) {
+ $prevPoint = $dataset->_nearby(-2);
+ $nextPoint = $dataset->_nearby();
+
+ $p = $this->_getMarkerData($point, $nextPoint, $prevPoint, $totals);
+ if (is_array($point)) {
+ $p['MARKER_X'] = $x+$param['width'] / 2;
+ $p['MARKER_Y'] = $y;
+ unset ($p['AVERAGE_Y']);
+ $this->_marker->_drawMarker($p['MARKER_X'], $p['MARKER_Y'], $p);
+ }
+ }
+ $this->write($x + $param['width'] + 10, $y, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);
+ }
+
+ if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {
+ $param['y'] = $y2;
+ } else {
+ $param['x'] = $x2;
+ }
+ }
+ }
+ unset($keys);
+ $this->_canvas->endGroup();
+ }
+ }
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Pie.php,v 1.19 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * 2D Piechart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Pie extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * The radius of the 'pie' spacing\r
- * @access private\r
- * @var int\r
- */\r
- var $_radius = 3;\r
-\r
- /**\r
- * Explode pie slices.\r
- * @access private\r
- * @var mixed\r
- */\r
- var $_explode = false;\r
-\r
- /**\r
- * The starting angle of the plot\r
- * @access private\r
- * @var int\r
- */\r
- var $_startingAngle = 0;\r
-\r
- /**\r
- * The angle direction (1 = CCW, -1 = CW)\r
- * @access private\r
- * @var int\r
- */\r
- var $_angleDirection = 1;\r
-\r
- /**\r
- * The diameter of the pie plot\r
- * @access private\r
- * @var int\r
- */\r
- var $_diameter = false;\r
- \r
- /**\r
- * Group items below this limit together as "the rest"\r
- * @access private\r
- * @var double\r
- */\r
- var $_restGroupLimit = false;\r
-\r
- /**\r
- * Rest group title\r
- * @access private\r
- * @var string\r
- */\r
- var $_restGroupTitle = 'The rest';\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $y = ($y0 + $y1) / 2;\r
- $this->_canvas->pieslice(\r
- array(\r
- 'x' => $x1, \r
- 'y' => $y, \r
- 'rx' => abs($x1 - $x0) / 2, \r
- 'ry' => abs($y1 - $y0) / 2, \r
- 'v1' => 45, \r
- 'v2' => 315\r
- )\r
- );\r
- }\r
-\r
- /**\r
- * Calculate marker point data\r
- *\r
- * @param array $point The point to calculate data for\r
- * @param array $nextPoint The next point\r
- * @param array $prevPoint The previous point\r
- * @param array $totals The pre-calculated totals, if needed\r
- * @return array An array containing marker point data\r
- * @access private\r
- */\r
- function _getMarkerData($point, $nextPoint, $prevPoint, &$totals)\r
- {\r
- $point = parent::_getMarkerData($point, $nextPoint, $prevPoint, $totals);\r
-\r
- $y = $totals['CURRENT_Y'];\r
- \r
- if ($this->_angleDirection < 0) {\r
- $y = $totals['ALL_SUM_Y'] - $y;\r
- }\r
-\r
- $point['ANGLE'] = 360 * (($y + ($point['Y'] / 2)) / $totals['ALL_SUM_Y']) + $this->_startingAngle;\r
- $totals['CURRENT_Y'] += $point['Y'];\r
-\r
- $point['ANG_X'] = cos(deg2rad($point['ANGLE']));\r
- $point['ANG_Y'] = sin(deg2rad($point['ANGLE']));\r
-\r
- $point['AX'] = -10 * $point['ANG_X'];\r
- $point['AY'] = -10 * $point['ANG_Y'];\r
-\r
- if ((isset($totals['ALL_SUM_Y'])) && ($totals['ALL_SUM_Y'] != 0)) {\r
- $point['PCT_MIN_Y'] = $point['PCT_MAX_Y'] = (100 * $point['Y'] / $totals['ALL_SUM_Y']);\r
- }\r
-\r
- $point['LENGTH'] = 10; //$radius;\r
-\r
- $x = $point['X'];\r
- $explodeRadius = 0;\r
- if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {\r
- $explodeRadius = $this->_explode[$x];\r
- } elseif (is_numeric($this->_explode)) {\r
- $explodeRadius = $this->_explode;\r
- }\r
-\r
- $point['MARKER_X'] = $totals['CENTER_X'] +\r
- ($totals['RADIUS'] + $explodeRadius) * $point['ANG_X'];\r
- $point['MARKER_Y'] = $totals['CENTER_Y'] +\r
- ($totals['RADIUS'] + $explodeRadius) * $point['ANG_Y'];\r
-\r
- return $point;\r
- }\r
-\r
- /**\r
- * Draws markers on the canvas\r
- *\r
- * @access private\r
- */\r
- function _drawMarker()\r
- {\r
-\r
- if ($this->_marker) {\r
- $totals = $this->_getTotals();\r
-\r
- $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);\r
- $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);\r
-\r
- $totals['CURRENT_Y'] = 0;\r
- $number = 0;\r
- \r
- $diameter = $this->_getDiameter();\r
- \r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
-\r
- if (count($this->_dataset) == 1) {\r
- $totals['RADIUS0'] = false;\r
- $totals['RADIUS'] = $diameter / 2;\r
- } else {\r
- $dr = $diameter / (2 * count($this->_dataset));\r
-\r
- $totals['RADIUS0'] = $number * $dr + ($number > 0 ? $this->_radius : 0);\r
- $totals['RADIUS'] = ($number + 1) * $dr;\r
- }\r
-\r
- $totals['ALL_SUM_Y'] = 0;\r
- $totals['CURRENT_Y'] = 0;\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $totals['ALL_SUM_Y'] += $point['Y'];\r
- }\r
-\r
- $dataset->_reset();\r
- $currentY = 0;\r
- $the_rest = 0;\r
- while ($point = $dataset->_next()) {\r
- if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {\r
- $the_rest += $point['Y'];\r
- }\r
- else {\r
- if ((!is_object($this->_dataSelector)) ||\r
- ($this->_dataSelector->select($point))\r
- ) {\r
- $point = $this->_getMarkerData(\r
- $point,\r
- false,\r
- false,\r
- $totals\r
- );\r
- if (is_array($point)) {\r
- $this->_marker->_drawMarker(\r
- $point['MARKER_X'],\r
- $point['MARKER_Y'],\r
- $point\r
- );\r
- }\r
- }\r
- }\r
- }\r
- if ($the_rest > 0) {\r
- $point = array('X' => $this->_restGroupTitle, 'Y' => $the_rest); \r
- $point = $this->_getMarkerData(\r
- $point,\r
- false,\r
- false,\r
- $totals\r
- );\r
- if (is_array($point)) {\r
- $this->_marker->_drawMarker(\r
- $point['MARKER_X'],\r
- $point['MARKER_Y'],\r
- $point\r
- );\r
- }\r
- }\r
- $number++;\r
- }\r
- unset($keys);\r
- }\r
- }\r
-\r
- /**\r
- * Explodes a piece of this pie chart\r
- *\r
- * @param int $explode Radius to explode with (or an array)\r
- * @param string $x The 'x' value to explode or omitted\r
- */\r
- function explode($explode, $x = false)\r
- {\r
- if ($x === false) {\r
- $this->_explode = $explode;\r
- } else {\r
- $this->_explode[$x] = $explode;\r
- }\r
- }\r
- \r
- /**\r
- * Set the starting angle of the plot\r
- * \r
- * East is 0 degrees\r
- * South is 90 degrees\r
- * West is 180 degrees\r
- * North is 270 degrees\r
- * \r
- * It is also possible to specify the direction of the plot angles (i.e. clockwise 'cw' or \r
- * counterclockwise 'ccw')\r
- */\r
- function setStartingAngle($angle = 0, $direction = 'ccw') \r
- {\r
- $this->_startingAngle = ($angle % 360);\r
- $this->_angleDirection = ($direction == 'ccw' ? 1 : -1);\r
- }\r
- \r
- /**\r
- * Set the diameter of the pie plot (i.e. the number of pixels the\r
- * pie plot should be across)\r
- * \r
- * Use 'max' for the maximum possible diameter\r
- * \r
- * Use negative values for the maximum possible - minus this value (fx -2\r
- * to leave 1 pixel at each side)\r
- * \r
- * @param mixed @diameter The number of pixels\r
- */\r
- function setDiameter($diameter)\r
- {\r
- $this->_diameter = $diameter;\r
- }\r
- \r
- /**\r
- * Set the limit for the y-value, where values below are grouped together\r
- * as "the rest"\r
- * \r
- * @param double $limit The limit\r
- * @param string $title The title to display in the legends (default 'The\r
- * rest')\r
- */\r
- function setRestGroup($limit, $title = 'The rest')\r
- {\r
- $this->_restGroupLimit = $limit;\r
- $this->_restGroupTitle = $title;\r
- } \r
- \r
- /**\r
- * Get the diameter of the plot\r
- * @return int The number of pixels the diameter is\r
- * @access private\r
- */\r
- function _getDiameter()\r
- {\r
- $diameter = 0;\r
- if ($this->_diameter === false) {\r
- $diameter = min($this->height(), $this->width()) * 0.75;\r
- }\r
- else {\r
- if ($this->_diameter === 'max') {\r
- $diameter = min($this->height(), $this->width());\r
- }\r
- elseif ($this->_diameter < 0) {\r
- $diameter = min($this->height(), $this->width()) + $this->_diameter;\r
- } else {\r
- $diameter = $this->_diameter;\r
- }\r
- }\r
- return $diameter;\r
- }\r
- \r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $number = 0;\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
-\r
- $totalY = 0;\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $totalY += $point['Y'];\r
- }\r
-\r
- $centerX = (int) (($this->_left + $this->_right) / 2);\r
- $centerY = (int) (($this->_top + $this->_bottom) / 2);\r
- $diameter = $this->_getDiameter();\r
- if ($this->_angleDirection < 0) {\r
- $currentY = $totalY;\r
- } else { \r
- $currentY = 0; //rand(0, 100)*$totalY/100;\r
- } \r
- $dataset->_reset();\r
-\r
- if (count($this->_dataset) == 1) {\r
- $radius0 = false;\r
- $radius1 = $diameter / 2;\r
- } else {\r
- $dr = $diameter / (2 * count($this->_dataset));\r
-\r
- $radius0 = $number * $dr + ($number > 0 ? $this->_radius : 0);\r
- $radius1 = ($number + 1) * $dr;\r
- }\r
-\r
- $the_rest = 0;\r
- while ($point = $dataset->_next()) {\r
- if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {\r
- $the_rest += $point['Y'];\r
- }\r
- else {\r
- $angle1 = 360 * ($currentY / $totalY) + $this->_startingAngle;\r
- $currentY += $this->_angleDirection * $point['Y'];\r
- $angle2 = 360 * ($currentY / $totalY) + $this->_startingAngle;\r
- \r
- $x = $point['X'];\r
- $id = $point['ID'];\r
- \r
- $dX = 0;\r
- $dY = 0;\r
- $explodeRadius = 0;\r
- if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {\r
- $explodeRadius = $this->_explode[$x];\r
- } elseif (is_numeric($this->_explode)) {\r
- $explodeRadius = $this->_explode;\r
- }\r
- \r
- if ($explodeRadius > 0) {\r
- $dX = $explodeRadius * cos(deg2rad(($angle1 + $angle2) / 2));\r
- $dY = $explodeRadius * sin(deg2rad(($angle1 + $angle2) / 2));\r
- }\r
- \r
- $ID = $point['ID'];\r
- $this->_getFillStyle($ID);\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->pieslice(\r
- $this->_mergeData(\r
- $point,\r
- array(\r
- 'x' => $centerX + $dX, \r
- 'y' => $centerY + $dY, \r
- 'rx' => $radius1, \r
- 'ry' => $radius1, \r
- 'v1' => $angle1, \r
- 'v2' => $angle2, \r
- 'srx' => $radius0, \r
- 'sry' => $radius0\r
- )\r
- )\r
- );\r
- }\r
- }\r
- \r
- if ($the_rest > 0) {\r
- $angle1 = 360 * ($currentY / $totalY) + $this->_startingAngle;\r
- $currentY += $this->_angleDirection * $the_rest;\r
- $angle2 = 360 * ($currentY / $totalY) + $this->_startingAngle;\r
-\r
- $x = 'rest';\r
- $id = 'rest';\r
-\r
- $dX = 0;\r
- $dY = 0;\r
- $explodeRadius = 0;\r
- if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {\r
- $explodeRadius = $this->_explode[$x];\r
- } elseif (is_numeric($this->_explode)) {\r
- $explodeRadius = $this->_explode;\r
- }\r
-\r
- if ($explodeRadius > 0) {\r
- $dX = $explodeRadius * cos(deg2rad(($angle1 + $angle2) / 2));\r
- $dY = $explodeRadius * sin(deg2rad(($angle1 + $angle2) / 2));\r
- }\r
-\r
- $ID = $id;\r
- $this->_getFillStyle($ID);\r
- $this->_getLineStyle($ID);\r
- $this->_canvas->pieslice(\r
- $this->_mergeData(\r
- $point,\r
- array(\r
- 'x' => $centerX + $dX, \r
- 'y' => $centerY + $dY, \r
- 'rx' => $radius1, \r
- 'ry' => $radius1, \r
- 'v1' => $angle1, \r
- 'v2' => $angle2, \r
- 'srx' => $radius0, \r
- 'sry' => $radius0\r
- )\r
- )\r
- );\r
- }\r
- $number++;\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- return true;\r
- }\r
-\r
- /**\r
- * Draw a sample for use with legend\r
- *\r
- * @param array $param The parameters for the legend\r
- * @access private\r
- */\r
- function _legendSample(&$param)\r
- {\r
- if (is_array($this->_dataset)) {\r
- \r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- \r
- $totals = $this->_getTotals();\r
- $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);\r
- $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);\r
- $totals['RADIUS'] = min($this->height(), $this->width()) * 0.75 * 0.5;\r
- $totals['CURRENT_Y'] = 0;\r
-\r
- if (is_a($this->_fillStyle, "Image_Graph_Fill")) {\r
- $this->_fillStyle->_reset();\r
- }\r
-\r
- $count = 0;\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $count++;\r
- \r
- $dataset->_reset();\r
- $the_rest = 0;\r
- while ($point = $dataset->_next()) {\r
- $caption = $point['X'];\r
- if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {\r
- $the_rest += $point['Y'];\r
- }\r
- else { \r
- $this->_canvas->setFont($param['font']);\r
- $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- $param['maxwidth'] = max($param['maxwidth'], $width);\r
- $x2 = $param['x'] + $width;\r
- $y2 = $param['y'] + $param['height']+5;\r
- \r
- if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {\r
- $param['y'] = $param['top'];\r
- $param['x'] = $x2;\r
- $y2 = $param['y'] + $param['height'];\r
- } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {\r
- $param['x'] = $param['left'];\r
- $param['y'] = $y2;\r
- $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);\r
- }\r
- \r
- $x = $x0 = $param['x'];\r
- $y = $param['y'];\r
- $y0 = $param['y'] - $param['height']/2;\r
- $x1 = $param['x'] + $param['width'];\r
- $y1 = $param['y'] + $param['height']/2;\r
- \r
- if (!isset($param['simulate'])) {\r
- $this->_getFillStyle($point['ID']);\r
- $this->_getLineStyle($point['ID']);\r
- $this->_drawLegendSample($x0, $y0, $x1, $y1);\r
- \r
- if (($this->_marker) && ($dataset) && ($param['show_marker'])) {\r
- $prevPoint = $dataset->_nearby(-2);\r
- $nextPoint = $dataset->_nearby();\r
- \r
- $p = $this->_getMarkerData($point, $nextPoint, $prevPoint, $totals);\r
- if (is_array($point)) {\r
- $p['MARKER_X'] = $x+$param['width']/2;\r
- $p['MARKER_Y'] = $y;\r
- unset ($p['AVERAGE_Y']);\r
- $this->_marker->_drawMarker($p['MARKER_X'], $p['MARKER_Y'], $p);\r
- }\r
- }\r
- $this->write($x + $param['width'] +10, $y, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);\r
- }\r
- \r
- if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {\r
- $param['y'] = $y2;\r
- } else {\r
- $param['x'] = $x2;\r
- } \r
- }\r
- }\r
- if ($the_rest > 0) {\r
- $this->_canvas->setFont($param['font']);\r
- $width = 20 + $param['width'] + $this->_canvas->textWidth($this->_restGroupTitle);\r
- $param['maxwidth'] = max($param['maxwidth'], $width);\r
- $x2 = $param['x'] + $width;\r
- $y2 = $param['y'] + $param['height']+5;\r
- \r
- if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {\r
- $param['y'] = $param['top'];\r
- $param['x'] = $x2;\r
- $y2 = $param['y'] + $param['height'];\r
- } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {\r
- $param['x'] = $param['left'];\r
- $param['y'] = $y2;\r
- $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($this->_restGroupTitle);\r
- }\r
- \r
- $x = $x0 = $param['x'];\r
- $y = $param['y'];\r
- $y0 = $param['y'] - $param['height']/2;\r
- $x1 = $param['x'] + $param['width'];\r
- $y1 = $param['y'] + $param['height']/2;\r
- \r
- if (!isset($param['simulate'])) {\r
- $this->_getFillStyle('rest');\r
- $this->_getLineStyle('rest');\r
- $this->_drawLegendSample($x0, $y0, $x1, $y1);\r
- \r
- $this->write($x + $param['width'] + 10, $y, $this->_restGroupTitle, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);\r
- }\r
- \r
- if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {\r
- $param['y'] = $y2;\r
- } else {\r
- $param['x'] = $x2;\r
- }\r
- }\r
- }\r
- unset($keys);\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- }\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Pie.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * 2D Piechart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Pie extends Image_Graph_Plot
+{
+
+ /**
+ * The radius of the 'pie' spacing
+ * @access private
+ * @var int
+ */
+ var $_radius = 3;
+
+ /**
+ * Explode pie slices.
+ * @access private
+ * @var mixed
+ */
+ var $_explode = false;
+
+ /**
+ * The starting angle of the plot
+ * @access private
+ * @var int
+ */
+ var $_startingAngle = 0;
+
+ /**
+ * The angle direction (1 = CCW, -1 = CW)
+ * @access private
+ * @var int
+ */
+ var $_angleDirection = 1;
+
+ /**
+ * The diameter of the pie plot
+ * @access private
+ * @var int
+ */
+ var $_diameter = false;
+
+ /**
+ * Group items below this limit together as "the rest"
+ * @access private
+ * @var double
+ */
+ var $_restGroupLimit = false;
+
+ /**
+ * Rest group title
+ * @access private
+ * @var string
+ */
+ var $_restGroupTitle = 'The rest';
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $y = ($y0 + $y1) / 2;
+ $this->_canvas->pieslice(
+ array(
+ 'x' => $x1,
+ 'y' => $y,
+ 'rx' => abs($x1 - $x0) / 2,
+ 'ry' => abs($y1 - $y0) / 2,
+ 'v1' => 45,
+ 'v2' => 315
+ )
+ );
+ }
+
+ /**
+ * Calculate marker point data
+ *
+ * @param array $point The point to calculate data for
+ * @param array $nextPoint The next point
+ * @param array $prevPoint The previous point
+ * @param array &$totals The pre-calculated totals, if needed
+ *
+ * @return array An array containing marker point data
+ * @access private
+ */
+ function _getMarkerData($point, $nextPoint, $prevPoint, &$totals)
+ {
+ $point = parent::_getMarkerData($point, $nextPoint, $prevPoint, $totals);
+
+ $y = $totals['CURRENT_Y'];
+
+ if ($this->_angleDirection < 0) {
+ $y = $totals['ALL_SUM_Y'] - $y;
+ }
+
+ $point['ANGLE'] = 360 * (($y + ($point['Y'] / 2)) / $totals['ALL_SUM_Y']) + $this->_startingAngle;
+ $totals['CURRENT_Y'] += $point['Y'];
+
+ $point['ANG_X'] = cos(deg2rad($point['ANGLE']));
+ $point['ANG_Y'] = sin(deg2rad($point['ANGLE']));
+
+ $point['AX'] = -10 * $point['ANG_X'];
+ $point['AY'] = -10 * $point['ANG_Y'];
+
+ if ((isset($totals['ALL_SUM_Y'])) && ($totals['ALL_SUM_Y'] != 0)) {
+ $point['PCT_MIN_Y'] = $point['PCT_MAX_Y'] = (100 * $point['Y'] / $totals['ALL_SUM_Y']);
+ }
+
+ $point['LENGTH'] = 10; //$radius;
+
+ $x = $point['X'];
+ $explodeRadius = 0;
+ if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {
+ $explodeRadius = $this->_explode[$x];
+ } elseif (is_numeric($this->_explode)) {
+ $explodeRadius = $this->_explode;
+ }
+
+ $point['MARKER_X'] = $totals['CENTER_X'] +
+ ($totals['RADIUS'] + $explodeRadius) * $point['ANG_X'];
+ $point['MARKER_Y'] = $totals['CENTER_Y'] +
+ ($totals['RADIUS'] + $explodeRadius) * $point['ANG_Y'];
+
+ return $point;
+ }
+
+ /**
+ * Draws markers on the canvas
+ *
+ * @return void
+ * @access private
+ */
+ function _drawMarker()
+ {
+
+ if ($this->_marker) {
+ $totals = $this->_getTotals();
+
+ $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);
+ $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);
+
+ $totals['CURRENT_Y'] = 0;
+ $number = 0;
+
+ $diameter = $this->_getDiameter();
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+
+ if (count($this->_dataset) == 1) {
+ $totals['RADIUS0'] = false;
+ $totals['RADIUS'] = $diameter / 2;
+ } else {
+ $dr = $diameter / (2 * count($this->_dataset));
+
+ $totals['RADIUS0'] = $number * $dr + ($number > 0 ? $this->_radius : 0);
+ $totals['RADIUS'] = ($number + 1) * $dr;
+ }
+
+ $totals['ALL_SUM_Y'] = 0;
+ $totals['CURRENT_Y'] = 0;
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $totals['ALL_SUM_Y'] += $point['Y'];
+ }
+
+ $dataset->_reset();
+ $currentY = 0;
+ $the_rest = 0;
+ while ($point = $dataset->_next()) {
+ if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {
+ $the_rest += $point['Y'];
+ } else {
+ if ((!is_object($this->_dataSelector))
+ || ($this->_dataSelector->select($point))
+ ) {
+ $point = $this->_getMarkerData(
+ $point,
+ false,
+ false,
+ $totals
+ );
+ if (is_array($point)) {
+ $this->_marker->_drawMarker(
+ $point['MARKER_X'],
+ $point['MARKER_Y'],
+ $point
+ );
+ }
+ }
+ }
+ }
+ if ($the_rest > 0) {
+ $point = array('X' => $this->_restGroupTitle, 'Y' => $the_rest);
+ $point = $this->_getMarkerData(
+ $point,
+ false,
+ false,
+ $totals
+ );
+ if (is_array($point)) {
+ $this->_marker->_drawMarker(
+ $point['MARKER_X'],
+ $point['MARKER_Y'],
+ $point
+ );
+ }
+ }
+ $number++;
+ }
+ unset($keys);
+ }
+ }
+
+ /**
+ * Explodes a piece of this pie chart
+ *
+ * @param int $explode Radius to explode with (or an array)
+ * @param string $x The 'x' value to explode or omitted
+ *
+ * @return void
+ */
+ function explode($explode, $x = false)
+ {
+ if ($x === false) {
+ $this->_explode = $explode;
+ } else {
+ $this->_explode[$x] = $explode;
+ }
+ }
+
+ /**
+ * Set the starting angle of the plot
+ *
+ * East is 0 degrees
+ * South is 90 degrees
+ * West is 180 degrees
+ * North is 270 degrees
+ *
+ * It is also possible to specify the direction of the plot angles (i.e. clockwise 'cw' or
+ * counterclockwise 'ccw')
+ *
+ * @param int $angle Angle for plot
+ * @param string $direction Direction for plot ('cw' [clockwise] or 'ccw' [counter-clockwise])
+ *
+ * @return void
+ */
+ function setStartingAngle($angle = 0, $direction = 'ccw')
+ {
+ $this->_startingAngle = ($angle % 360);
+ $this->_angleDirection = ($direction == 'ccw' ? 1 : -1);
+ }
+
+ /**
+ * Set the diameter of the pie plot (i.e. the number of pixels the
+ * pie plot should be across)
+ *
+ * Use 'max' for the maximum possible diameter
+ *
+ * Use negative values for the maximum possible - minus this value (fx -2
+ * to leave 1 pixel at each side)
+ *
+ * @param mixed $diameter The number of pixels
+ *
+ * @return void
+ */
+ function setDiameter($diameter)
+ {
+ $this->_diameter = $diameter;
+ }
+
+ /**
+ * Set the limit for the y-value, where values below are grouped together
+ * as "the rest"
+ *
+ * @param double $limit The limit
+ * @param string $title The title to display in the legends (default 'The rest')
+ *
+ * @return void
+ */
+ function setRestGroup($limit, $title = 'The rest')
+ {
+ $this->_restGroupLimit = $limit;
+ $this->_restGroupTitle = $title;
+ }
+
+ /**
+ * Get the diameter of the plot
+ *
+ * @return int The number of pixels the diameter is
+ * @access private
+ */
+ function _getDiameter()
+ {
+ $diameter = 0;
+ if ($this->_diameter === false) {
+ $diameter = min($this->height(), $this->width()) * 0.75;
+ } else {
+ if ($this->_diameter === 'max') {
+ $diameter = min($this->height(), $this->width());
+ } elseif ($this->_diameter < 0) {
+ $diameter = min($this->height(), $this->width()) + $this->_diameter;
+ } else {
+ $diameter = $this->_diameter;
+ }
+ }
+ return $diameter;
+ }
+
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $number = 0;
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+
+ $totalY = 0;
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $totalY += $point['Y'];
+ }
+
+ $centerX = (int) (($this->_left + $this->_right) / 2);
+ $centerY = (int) (($this->_top + $this->_bottom) / 2);
+ $diameter = $this->_getDiameter();
+ if ($this->_angleDirection < 0) {
+ $currentY = $totalY;
+ } else {
+ $currentY = 0; //rand(0, 100)*$totalY/100;
+ }
+ $dataset->_reset();
+
+ if (count($this->_dataset) == 1) {
+ $radius0 = false;
+ $radius1 = $diameter / 2;
+ } else {
+ $dr = $diameter / (2 * count($this->_dataset));
+
+ $radius0 = $number * $dr + ($number > 0 ? $this->_radius : 0);
+ $radius1 = ($number + 1) * $dr;
+ }
+
+ $the_rest = 0;
+ while ($point = $dataset->_next()) {
+ if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {
+ $the_rest += $point['Y'];
+ } else {
+ $angle1 = 360 * ($currentY / $totalY) + $this->_startingAngle;
+ $currentY += $this->_angleDirection * $point['Y'];
+ $angle2 = 360 * ($currentY / $totalY) + $this->_startingAngle;
+
+ $x = $point['X'];
+ $id = $point['ID'];
+
+ $dX = 0;
+ $dY = 0;
+ $explodeRadius = 0;
+ if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {
+ $explodeRadius = $this->_explode[$x];
+ } elseif (is_numeric($this->_explode)) {
+ $explodeRadius = $this->_explode;
+ }
+
+ if ($explodeRadius > 0) {
+ $dX = $explodeRadius * cos(deg2rad(($angle1 + $angle2) / 2));
+ $dY = $explodeRadius * sin(deg2rad(($angle1 + $angle2) / 2));
+ }
+
+ $ID = $point['ID'];
+ $this->_getFillStyle($ID);
+ $this->_getLineStyle($ID);
+ $this->_canvas->pieslice(
+ $this->_mergeData(
+ $point,
+ array(
+ 'x' => $centerX + $dX,
+ 'y' => $centerY + $dY,
+ 'rx' => $radius1,
+ 'ry' => $radius1,
+ 'v1' => $angle1,
+ 'v2' => $angle2,
+ 'srx' => $radius0,
+ 'sry' => $radius0
+ )
+ )
+ );
+ }
+ }
+
+ if ($the_rest > 0) {
+ $angle1 = 360 * ($currentY / $totalY) + $this->_startingAngle;
+ $currentY += $this->_angleDirection * $the_rest;
+ $angle2 = 360 * ($currentY / $totalY) + $this->_startingAngle;
+
+ $x = 'rest';
+ $id = 'rest';
+
+ $dX = 0;
+ $dY = 0;
+ $explodeRadius = 0;
+ if ((is_array($this->_explode)) && (isset($this->_explode[$x]))) {
+ $explodeRadius = $this->_explode[$x];
+ } elseif (is_numeric($this->_explode)) {
+ $explodeRadius = $this->_explode;
+ }
+
+ if ($explodeRadius > 0) {
+ $dX = $explodeRadius * cos(deg2rad(($angle1 + $angle2) / 2));
+ $dY = $explodeRadius * sin(deg2rad(($angle1 + $angle2) / 2));
+ }
+
+ $ID = $id;
+ $this->_getFillStyle($ID);
+ $this->_getLineStyle($ID);
+ $this->_canvas->pieslice(
+ $this->_mergeData(
+ $point,
+ array(
+ 'x' => $centerX + $dX,
+ 'y' => $centerY + $dY,
+ 'rx' => $radius1,
+ 'ry' => $radius1,
+ 'v1' => $angle1,
+ 'v2' => $angle2,
+ 'srx' => $radius0,
+ 'sry' => $radius0
+ )
+ )
+ );
+ }
+ $number++;
+ }
+ unset($keys);
+ $this->_drawMarker();
+ return true;
+ }
+
+ /**
+ * Draw a sample for use with legend
+ *
+ * @param array &$param The parameters for the legend
+ *
+ * @return void
+ * @access private
+ */
+ function _legendSample(&$param)
+ {
+ if (is_array($this->_dataset)) {
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+
+ $totals = $this->_getTotals();
+ $totals['CENTER_X'] = (int) (($this->_left + $this->_right) / 2);
+ $totals['CENTER_Y'] = (int) (($this->_top + $this->_bottom) / 2);
+ $totals['RADIUS'] = min($this->height(), $this->width()) * 0.75 * 0.5;
+ $totals['CURRENT_Y'] = 0;
+
+ if (is_a($this->_fillStyle, "Image_Graph_Fill")) {
+ $this->_fillStyle->_reset();
+ }
+
+ $count = 0;
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $count++;
+
+ $dataset->_reset();
+ $the_rest = 0;
+ while ($point = $dataset->_next()) {
+ $caption = $point['X'];
+ if (($this->_restGroupLimit !== false) && ($point['Y'] <= $this->_restGroupLimit)) {
+ $the_rest += $point['Y'];
+ } else {
+ $this->_canvas->setFont($param['font']);
+ $width = 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ $param['maxwidth'] = max($param['maxwidth'], $width);
+ $x2 = $param['x'] + $width;
+ $y2 = $param['y'] + $param['height']+5;
+
+ if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {
+ $param['y'] = $param['top'];
+ $param['x'] = $x2;
+ $y2 = $param['y'] + $param['height'];
+ } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {
+ $param['x'] = $param['left'];
+ $param['y'] = $y2;
+ $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($caption);
+ }
+
+ $x = $x0 = $param['x'];
+ $y = $param['y'];
+ $y0 = $param['y'] - $param['height']/2;
+ $x1 = $param['x'] + $param['width'];
+ $y1 = $param['y'] + $param['height']/2;
+
+ if (!isset($param['simulate'])) {
+ $this->_getFillStyle($point['ID']);
+ $this->_getLineStyle($point['ID']);
+ $this->_drawLegendSample($x0, $y0, $x1, $y1);
+
+ if (($this->_marker) && ($dataset) && ($param['show_marker'])) {
+ $prevPoint = $dataset->_nearby(-2);
+ $nextPoint = $dataset->_nearby();
+
+ $p = $this->_getMarkerData($point, $nextPoint, $prevPoint, $totals);
+ if (is_array($point)) {
+ $p['MARKER_X'] = $x+$param['width']/2;
+ $p['MARKER_Y'] = $y;
+ unset ($p['AVERAGE_Y']);
+ $this->_marker->_drawMarker($p['MARKER_X'], $p['MARKER_Y'], $p);
+ }
+ }
+ $this->write($x + $param['width'] +10, $y, $caption, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);
+ }
+
+ if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {
+ $param['y'] = $y2;
+ } else {
+ $param['x'] = $x2;
+ }
+ }
+ }
+ if ($the_rest > 0) {
+ $this->_canvas->setFont($param['font']);
+ $width = 20 + $param['width'] + $this->_canvas->textWidth($this->_restGroupTitle);
+ $param['maxwidth'] = max($param['maxwidth'], $width);
+ $x2 = $param['x'] + $width;
+ $y2 = $param['y'] + $param['height']+5;
+
+ if ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) && ($y2 > $param['bottom'])) {
+ $param['y'] = $param['top'];
+ $param['x'] = $x2;
+ $y2 = $param['y'] + $param['height'];
+ } elseif ((($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) == 0) && ($x2 > $param['right'])) {
+ $param['x'] = $param['left'];
+ $param['y'] = $y2;
+ $x2 = $param['x'] + 20 + $param['width'] + $this->_canvas->textWidth($this->_restGroupTitle);
+ }
+
+ $x = $x0 = $param['x'];
+ $y = $param['y'];
+ $y0 = $param['y'] - $param['height']/2;
+ $x1 = $param['x'] + $param['width'];
+ $y1 = $param['y'] + $param['height']/2;
+
+ if (!isset($param['simulate'])) {
+ $this->_getFillStyle('rest');
+ $this->_getLineStyle('rest');
+ $this->_drawLegendSample($x0, $y0, $x1, $y1);
+
+ $this->write($x + $param['width'] + 10, $y, $this->_restGroupTitle, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $param['font']);
+ }
+
+ if (($param['align'] & IMAGE_GRAPH_ALIGN_VERTICAL) != 0) {
+ $param['y'] = $y2;
+ } else {
+ $param['x'] = $x2;
+ }
+ }
+ }
+ unset($keys);
+ $this->_canvas->endGroup();
+ }
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Radar.php,v 1.11 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Radar chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Radar extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $p = 10;\r
- $rx = abs($x1 - $x0) / 2;\r
- $ry = abs($x1 - $x0) / 2;\r
- $r = min($rx, $ry);\r
- $cx = ($x0 + $x1) / 2;\r
- $cy = ($y0 + $y1) / 2;\r
- $max = 5;\r
- for ($i = 0; $i < $p; $i++) {\r
- $v = 2 * pi() * $i / $p;\r
- $t = $r * rand(3, $max) / $max;\r
- $x = $cx + $t * cos($v);\r
- $y = $cy + $t * sin($v);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- if (is_a($this->_parent, 'Image_Graph_Plotarea_Radar')) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $maxY = $dataset->maximumY();\r
- $count = $dataset->count();\r
-\r
- $dataset->_reset();\r
- while ($point = $dataset->_next()) {\r
- $this->_canvas->addVertex(array('x' => \r
- $this->_pointX($point), 'y' => \r
- $this->_pointY($point)\r
- ));\r
- }\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- unset($keys);\r
- }\r
- $this->_drawMarker();\r
-\r
- $this->_clip(false);\r
- $this->_canvas->endGroup(); \r
- return parent::_done();\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Radar.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Radar chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Radar extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $p = 10;
+ $rx = abs($x1 - $x0) / 2;
+ $ry = abs($x1 - $x0) / 2;
+ $r = min($rx, $ry);
+ $cx = ($x0 + $x1) / 2;
+ $cy = ($y0 + $y1) / 2;
+ $max = 5;
+ for ($i = 0; $i < $p; $i++) {
+ $v = 2 * pi() * $i / $p;
+ $t = $r * rand(3, $max) / $max;
+ $x = $cx + $t * cos($v);
+ $y = $cy + $t * sin($v);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+ if (is_a($this->_parent, 'Image_Graph_Plotarea_Radar')) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $maxY = $dataset->maximumY();
+ $count = $dataset->count();
+
+ $dataset->_reset();
+ while ($point = $dataset->_next()) {
+ $this->_canvas->addVertex(
+ array(
+ 'x' => $this->_pointX($point),
+ 'y' => $this->_pointY($point)
+ )
+ );
+ }
+ $this->_getFillStyle($key);
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => true));
+ }
+ unset($keys);
+ }
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return parent::_done();
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Area.php,v 1.11 2005/11/27 22:21:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot/Smoothed/Bezier.php\r
- */\r
-require_once 'Image/Graph/Plot/Smoothed/Bezier.php';\r
-\r
-/**\r
- * Bezier smoothed area chart\r
- *\r
- * Similar to an {@link Image_Graph_Plot_Area}, but the interconnecting lines\r
- * between two datapoints are smoothed using a Bezier curve, which enables the\r
- * chart to appear as a nice curved plot instead of the sharp edges of a\r
- * conventional {@link Image_Graph_Plot_Area}. Smoothed charts are only supported\r
- * with non-stacked types\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Smoothed_Area extends Image_Graph_Plot_Smoothed_Bezier\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
-\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));\r
- $this->_addSamplePoints($x0, $y0, $x1, $y1);\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * Output the Bezier smoothed plot as an Area Chart\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- \r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $first = true;\r
- while ($p1 = $dataset->_next()) {\r
- $p0 = $dataset->_nearby(-2);\r
- $p2 = $dataset->_nearby(0);\r
- $p3 = $dataset->_nearby(1);\r
- if ($first) {\r
- $p = $p1;\r
- $p['Y'] = '#min_pos#';\r
- $x = $this->_pointX($p);\r
- $y = $this->_pointY($p);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
-\r
- if ($p2) {\r
- $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);\r
- $this->_canvas->addSpline(\r
- array(\r
- 'x' => $cp['X'],\r
- 'y' => $cp['Y'],\r
- 'p1x' => $cp['P1X'],\r
- 'p1y' => $cp['P1Y'],\r
- 'p2x' => $cp['P2X'],\r
- 'p2y' => $cp['P2Y']\r
- )\r
- );\r
- } else {\r
- $x = $this->_pointX($p1);\r
- $y = $this->_pointY($p1);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
- $lastPoint = $p1;\r
- $first = false;\r
- }\r
- $lastPoint['Y'] = '#min_pos#';\r
- $x = $this->_pointX($lastPoint);\r
- $y = $this->_pointY($lastPoint);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
-\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Area.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot/Smoothed/Bezier.php
+ */
+require_once 'Image/Graph/Plot/Smoothed/Bezier.php';
+
+/**
+ * Bezier smoothed area chart
+ *
+ * Similar to an {@link Image_Graph_Plot_Area}, but the interconnecting lines
+ * between two datapoints are smoothed using a Bezier curve, which enables the
+ * chart to appear as a nice curved plot instead of the sharp edges of a
+ * conventional {@link Image_Graph_Plot_Area}. Smoothed charts are only supported
+ * with non-stacked types
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Smoothed_Area extends Image_Graph_Plot_Smoothed_Bezier
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));
+ $this->_addSamplePoints($x0, $y0, $x1, $y1);
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * Output the Bezier smoothed plot as an Area Chart
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $first = true;
+ while ($p1 = $dataset->_next()) {
+ $p0 = $dataset->_nearby(-2);
+ $p2 = $dataset->_nearby(0);
+ $p3 = $dataset->_nearby(1);
+ if ($first) {
+ $p = $p1;
+ $p['Y'] = '#min_pos#';
+ $x = $this->_pointX($p);
+ $y = $this->_pointY($p);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+
+ if ($p2) {
+ $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);
+ $this->_canvas->addSpline(
+ array(
+ 'x' => $cp['X'],
+ 'y' => $cp['Y'],
+ 'p1x' => $cp['P1X'],
+ 'p1y' => $cp['P1Y'],
+ 'p2x' => $cp['P2X'],
+ 'p2y' => $cp['P2Y']
+ )
+ );
+ } else {
+ $x = $this->_pointX($p1);
+ $y = $this->_pointY($p1);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+ $lastPoint = $p1;
+ $first = false;
+ }
+ $lastPoint['Y'] = '#min_pos#';
+ $x = $this->_pointX($lastPoint);
+ $y = $this->_pointY($lastPoint);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+
+ $this->_getFillStyle($key);
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => true));
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return true;
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Bezier.php,v 1.8 2005/08/24 20:36:02 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot.php\r
- */\r
-require_once 'Image/Graph/Plot.php';\r
-\r
-/**\r
- * Include file Image/Graph/Tool.php\r
- */\r
-require_once 'Image/Graph/Tool.php';\r
-\r
-/**\r
- * Bezier smoothed plottype.\r
- *\r
- * The framework for calculating the Bezier smoothed curve from the dataset.\r
- * Used in {@link Image_Graph_Plot_Smoothed_Line} and {@link\r
- * Image_Graph_Plot_Smoothed_Area}. Smoothed charts are only supported with non-\r
- * stacked types\r
- * @link http://homepages.borland.com/efg2lab/Graphics/Jean-\r
- * YvesQueinecBezierCurves.htm efg computer lab - description of bezier curves\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Plot_Smoothed_Bezier extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Image_Graph_Plot_Smoothed_Bezier [Constructor]\r
- *\r
- * Only 'normal' multitype supported\r
- *\r
- * @param Dataset $dataset The data set (value containter) to plot\r
- * @param string $title The title of the plot (used for legends, {@link\r
- * Image_Graph_Legend})\r
- */\r
- function Image_Graph_Plot_Smoothed_Bezier(& $dataset, $title = '')\r
- {\r
- parent::Image_Graph_Plot($dataset, 'normal', $title);\r
- }\r
-\r
- /**\r
- * Return the minimum Y point\r
- *\r
- * @return double The minumum Y point\r
- * @access private\r
- */\r
- function _minimumY()\r
- {\r
- return 1.05 * parent::_minimumY();\r
- }\r
-\r
- /**\r
- * Return the maximum Y point\r
- *\r
- * @return double The maximum Y point\r
- * @access private\r
- */\r
- function _maximumY()\r
- {\r
- return 1.05 * parent::_maximumY();\r
- }\r
-\r
- /**\r
- * Calculates all Bezier points, for the curve\r
- *\r
- * @param array $p1 The actual point to calculate control points for\r
- * @param array $p0 The point "just before" $p1\r
- * @param array $p2 The point "just after" $p1\r
- * @param array $p3 The point "just after" $p2\r
- * @return array Array of Bezier points\r
- * @access private\r
- */\r
- function _getControlPoints($p1, $p0, $p2, $p3)\r
- {\r
- $p1 = $this->_pointXY($p1);\r
- if ($p2) {\r
- $p2 = $this->_pointXY($p2);\r
- }\r
- if (!$p0) {\r
- $p0['X'] = $p1['X'] - abs($p2['X'] - $p1['X']);\r
- $p0['Y'] = $p1['Y']; //-($p2['Y']-$p1['Y']);\r
- } else {\r
- $p0 = $this->_pointXY($p0);\r
- }\r
- if (!$p3) {\r
- $p3['X'] = $p1['X'] + 2*abs($p1['X'] - $p0['X']);\r
- $p3['Y'] = $p1['Y'];\r
- } else {\r
- $p3 = $this->_pointXY($p3);\r
- }\r
-\r
- if (!$p2) {\r
- $p2['X'] = $p1['X'] + abs($p1['X'] - $p0['X']);\r
- $p2['Y'] = $p1['Y'];\r
- }\r
-\r
- $pC1['X'] = Image_Graph_Tool::controlPoint($p0['X'], $p1['X'], $p2['X']);\r
- $pC1['Y'] = Image_Graph_Tool::controlPoint($p0['Y'], $p1['Y'], $p2['Y']);\r
- $pC2['X'] = Image_Graph_Tool::controlPoint($p3['X'], $p2['X'], $p1['X']);\r
- $pC2['Y'] = Image_Graph_Tool::controlPoint($p3['Y'], $p2['Y'], $p1['Y']);\r
-\r
- return array(\r
- 'X' => $p1['X'],\r
- 'Y' => $p1['Y'],\r
- 'P1X' => $pC1['X'],\r
- 'P1Y' => $pC1['Y'],\r
- 'P2X' => $pC2['X'],\r
- 'P2Y' => $pC2['Y']\r
- );\r
- }\r
-\r
- /**\r
- * Create legend sample data for the canvas.\r
- *\r
- * Common for all smoothed plots\r
- *\r
- * @access private\r
- */\r
- function _addSamplePoints($x0, $y0, $x1, $y1)\r
- {\r
- $p = abs($x1 - $x0);\r
- $cy = ($y0 + $y1) / 2;\r
- $h = abs($y1 - $y0);\r
- $dy = $h / 4;\r
- $dw = abs($x1 - $x0) / $p;\r
- for ($i = 0; $i < $p; $i++) {\r
- $v = 2 * pi() * $i / $p;\r
- $x = $x0 + $i * $dw;\r
- $y = $cy + 2 * $v * sin($v);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Bezier.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot.php
+ */
+require_once 'Image/Graph/Plot.php';
+
+/**
+ * Include file Image/Graph/Tool.php
+ */
+require_once 'Image/Graph/Tool.php';
+
+/**
+ * Bezier smoothed plottype.
+ *
+ * The framework for calculating the Bezier smoothed curve from the dataset.
+ * Used in {@link Image_Graph_Plot_Smoothed_Line} and {@link
+ * Image_Graph_Plot_Smoothed_Area}. Smoothed charts are only supported with non-
+ * stacked types
+ * {@link http://homepages.borland.com/efg2lab/Graphics/Jean-
+ * YvesQueinecBezierCurves.htm} efg computer lab - description of bezier curves
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Plot_Smoothed_Bezier extends Image_Graph_Plot
+{
+
+ /**
+ * Image_Graph_Plot_Smoothed_Bezier [Constructor]
+ *
+ * Only 'normal' multitype supported
+ *
+ * @param Dataset &$dataset The data set (value containter) to plot
+ * @param string $title The title of the plot (used for legends, {@link
+ * Image_Graph_Legend})
+ */
+ function Image_Graph_Plot_Smoothed_Bezier(& $dataset, $title = '')
+ {
+ parent::Image_Graph_Plot($dataset, 'normal', $title);
+ }
+
+ /**
+ * Return the minimum Y point
+ *
+ * @return double The minumum Y point
+ * @access private
+ */
+ function _minimumY()
+ {
+ return 1.05 * parent::_minimumY();
+ }
+
+ /**
+ * Return the maximum Y point
+ *
+ * @return double The maximum Y point
+ * @access private
+ */
+ function _maximumY()
+ {
+ return 1.05 * parent::_maximumY();
+ }
+
+ /**
+ * Calculates all Bezier points, for the curve
+ *
+ * @param array $p1 The actual point to calculate control points for
+ * @param array $p0 The point "just before" $p1
+ * @param array $p2 The point "just after" $p1
+ * @param array $p3 The point "just after" $p2
+ *
+ * @return array Array of Bezier points
+ * @access private
+ */
+ function _getControlPoints($p1, $p0, $p2, $p3)
+ {
+ $p1 = $this->_pointXY($p1);
+ if ($p2) {
+ $p2 = $this->_pointXY($p2);
+ }
+ if (!$p0) {
+ $p0['X'] = $p1['X'] - abs($p2['X'] - $p1['X']);
+ $p0['Y'] = $p1['Y']; //-($p2['Y']-$p1['Y']);
+ } else {
+ $p0 = $this->_pointXY($p0);
+ }
+ if (!$p3) {
+ $p3['X'] = $p1['X'] + 2*abs($p1['X'] - $p0['X']);
+ $p3['Y'] = $p1['Y'];
+ } else {
+ $p3 = $this->_pointXY($p3);
+ }
+
+ if (!$p2) {
+ $p2['X'] = $p1['X'] + abs($p1['X'] - $p0['X']);
+ $p2['Y'] = $p1['Y'];
+ }
+
+ $pC1['X'] = Image_Graph_Tool::controlPoint($p0['X'], $p1['X'], $p2['X']);
+ $pC1['Y'] = Image_Graph_Tool::controlPoint($p0['Y'], $p1['Y'], $p2['Y']);
+ $pC2['X'] = Image_Graph_Tool::controlPoint($p3['X'], $p2['X'], $p1['X']);
+ $pC2['Y'] = Image_Graph_Tool::controlPoint($p3['Y'], $p2['Y'], $p1['Y']);
+
+ return array(
+ 'X' => $p1['X'],
+ 'Y' => $p1['Y'],
+ 'P1X' => $pC1['X'],
+ 'P1Y' => $pC1['Y'],
+ 'P2X' => $pC2['X'],
+ 'P2Y' => $pC2['Y']
+ );
+ }
+
+ /**
+ * Create legend sample data for the canvas.
+ *
+ * Common for all smoothed plots
+ *
+ * @param int $x0 ???
+ * @param int $y0 ???
+ * @param int $x1 ???
+ * @param int $y1 ???
+ *
+ * @return void
+ * @access private
+ */
+ function _addSamplePoints($x0, $y0, $x1, $y1)
+ {
+ $p = abs($x1 - $x0);
+ $cy = ($y0 + $y1) / 2;
+ $h = abs($y1 - $y0);
+ $dy = $h / 4;
+ $dw = abs($x1 - $x0) / $p;
+ for ($i = 0; $i < $p; $i++) {
+ $v = 2 * pi() * $i / $p;
+ $x = $x0 + $i * $dw;
+ $y = $cy + 2 * $v * sin($v);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Line.php,v 1.14 2006/03/02 12:37:37 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot/Smoothed/Bezier.php\r
- */\r
-require_once 'Image/Graph/Plot/Smoothed/Bezier.php';\r
-\r
-/**\r
- * Bezier smoothed line chart.\r
- *\r
- * Similar to a {@link Image_Graph_Plot_Line}, but the interconnecting lines\r
- * between two datapoints are smoothed using a Bezier curve, which enables the\r
- * chart to appear as a nice curved plot instead of the sharp edges of a\r
- * conventional {@link Image_Graph_Plot_Line}. Smoothed charts are only supported\r
- * with non-stacked types\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Smoothed_Line extends Image_Graph_Plot_Smoothed_Bezier\r
-{\r
-\r
- /**\r
- * Gets the fill style of the element\r
- *\r
- * @return int A GD filestyle representing the fill style\r
- * @see Image_Graph_Fill\r
- * @access private\r
- */\r
- function _getFillStyle($ID = false)\r
- {\r
- return IMG_COLOR_TRANSPARENT;\r
- }\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $this->_addSamplePoints($x0, $y0, $x1, $y1);\r
- $this->_canvas->polygon(array('connect' => false));\r
- }\r
-\r
- /**\r
- * Output the Bezier smoothed plot as an Line Chart\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $numPoints = 0;\r
- while ($p1 = $dataset->_next()) {\r
- if ($p1['Y'] === null) {\r
- if ($numPoints > 1) {\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));\r
- }\r
- else {\r
- $this->_canvas->reset();\r
- }\r
- $numPoints = 0;\r
- } else {\r
- $p0 = $dataset->_nearby(-2);\r
- $p2 = $dataset->_nearby(0);\r
- $p3 = $dataset->_nearby(1);\r
-\r
- if (($p0) && ($p0['Y'] === null)) {\r
- $p0 = false;\r
- }\r
- if (($p2) && ($p2['Y'] === null)) {\r
- $p2 = false;\r
- }\r
- if (($p3) && ($p3['Y'] === null)) {\r
- $p3 = false;\r
- }\r
-\r
- if ($p2) {\r
- $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);\r
- $this->_canvas->addSpline(\r
- $this->_mergeData(\r
- $p1,\r
- array(\r
- 'x' => $cp['X'],\r
- 'y' => $cp['Y'],\r
- 'p1x' => $cp['P1X'],\r
- 'p1y' => $cp['P1Y'],\r
- 'p2x' => $cp['P2X'],\r
- 'p2y' => $cp['P2Y']\r
- )\r
- )\r
- );\r
- } else {\r
- $x = $this->_pointX($p1);\r
- $y = $this->_pointY($p1);\r
- $this->_canvas->addVertex(\r
- $this->_mergeData(\r
- $p1,\r
- array('x' => $x, 'y' => $y)\r
- )\r
- );\r
- }\r
- $numPoints++;\r
- }\r
- }\r
- if ($numPoints > 1) {\r
- $this->_getLineStyle();\r
- $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));\r
- }\r
- else {\r
- $this->_canvas->reset();\r
- }\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-\r
-}\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Line.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot/Smoothed/Bezier.php
+ */
+require_once 'Image/Graph/Plot/Smoothed/Bezier.php';
+
+/**
+ * Bezier smoothed line chart.
+ *
+ * Similar to a {@link Image_Graph_Plot_Line}, but the interconnecting lines
+ * between two datapoints are smoothed using a Bezier curve, which enables the
+ * chart to appear as a nice curved plot instead of the sharp edges of a
+ * conventional {@link Image_Graph_Plot_Line}. Smoothed charts are only supported
+ * with non-stacked types
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Smoothed_Line extends Image_Graph_Plot_Smoothed_Bezier
+{
+ /**
+ * Gets the fill style of the element
+ *
+ * @param boolean $ID ???
+ *
+ * @return int A GD filestyle representing the fill style
+ * @see Image_Graph_Fill
+ * @access private
+ */
+ function _getFillStyle($ID = false)
+ {
+ return IMG_COLOR_TRANSPARENT;
+ }
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $this->_addSamplePoints($x0, $y0, $x1, $y1);
+ $this->_canvas->polygon(array('connect' => false));
+ }
+
+ /**
+ * Output the Bezier smoothed plot as an Line Chart
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $numPoints = 0;
+ while ($p1 = $dataset->_next()) {
+ if ($p1['Y'] === null) {
+ if ($numPoints > 1) {
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
+ } else {
+ $this->_canvas->reset();
+ }
+ $numPoints = 0;
+ } else {
+ $p0 = $dataset->_nearby(-2);
+ $p2 = $dataset->_nearby(0);
+ $p3 = $dataset->_nearby(1);
+
+ if (($p0) && ($p0['Y'] === null)) {
+ $p0 = false;
+ }
+ if (($p2) && ($p2['Y'] === null)) {
+ $p2 = false;
+ }
+ if (($p3) && ($p3['Y'] === null)) {
+ $p3 = false;
+ }
+
+ if ($p2) {
+ $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);
+ $this->_canvas->addSpline(
+ $this->_mergeData(
+ $p1,
+ array(
+ 'x' => $cp['X'],
+ 'y' => $cp['Y'],
+ 'p1x' => $cp['P1X'],
+ 'p1y' => $cp['P1Y'],
+ 'p2x' => $cp['P2X'],
+ 'p2y' => $cp['P2Y']
+ )
+ )
+ );
+ } else {
+ $x = $this->_pointX($p1);
+ $y = $this->_pointY($p1);
+ $this->_canvas->addVertex(
+ $this->_mergeData(
+ $p1,
+ array('x' => $x, 'y' => $y)
+ )
+ );
+ }
+ $numPoints++;
+ }
+ }
+ if ($numPoints > 1) {
+ $this->_getLineStyle();
+ $this->_canvas->polygon(array('connect' => false, 'map_vertices' => true));
+ } else {
+ $this->_canvas->reset();
+ }
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return true;
+ }
+
+}
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Radar.php,v 1.10 2005/11/27 22:21:17 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since File available since Release 0.3.0dev2\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot/Smoothed/Bezier.php\r
- */\r
-require_once 'Image/Graph/Plot/Smoothed/Bezier.php';\r
-\r
-/**\r
- * Smoothed radar chart.\r
- * \r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @since Class available since Release 0.3.0dev2\r
- */\r
-class Image_Graph_Plot_Smoothed_Radar extends Image_Graph_Plot_Smoothed_Bezier\r
-{\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- if (is_a($this->_parent, 'Image_Graph_Plotarea_Radar')) {\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- if ($dataset->count() >= 3) {\r
- $dataset->_reset();\r
- $p1_ = $dataset->_next();\r
- $p2_ = $dataset->_next();\r
- $p3_ = $dataset->_next();\r
- $plast_ = false;\r
- if ($p3_) {\r
- while ($p = $dataset->_next()) {\r
- $plast_ = $p;\r
- }\r
- }\r
-\r
- if ($plast_ === false) {\r
- $plast_ = $p3_;\r
- }\r
- $dataset->_reset();\r
- while ($p1 = $dataset->_next()) {\r
- $p0 = $dataset->_nearby(-2);\r
- $p2 = $dataset->_nearby(0);\r
- $p3 = $dataset->_nearby(1);\r
-\r
- if ($p0 === false) {\r
- $p0 = $plast_;\r
- }\r
-\r
- if ($p2 === false) {\r
- $p2 = $p1_;\r
- $p3 = $p2_;\r
- } elseif ($p3 === false) {\r
- $p3 = $p1_;\r
- }\r
-\r
-\r
- $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);\r
- $this->_canvas->addSpline(\r
- array(\r
- 'x' => $cp['X'],\r
- 'y' => $cp['Y'],\r
- 'p1x' => $cp['P1X'],\r
- 'p1y' => $cp['P1Y'],\r
- 'p2x' => $cp['P2X'],\r
- 'p2y' => $cp['P2Y']\r
- )\r
- );\r
-\r
- $next2last = $p0;\r
- $last = $p1;\r
- }\r
-\r
- $cp = $this->_getControlPoints($p1_, $plast_, $p2_, $p3_);\r
- $this->_canvas->addSpline(\r
- array(\r
- 'x' => $cp['X'],\r
- 'y' => $cp['Y'],\r
- 'p1x' => $cp['P1X'],\r
- 'p1y' => $cp['P1Y'],\r
- 'p2x' => $cp['P2X'],\r
- 'p2y' => $cp['P2Y']\r
- )\r
- );\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- }\r
- unset($keys);\r
- }\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup($this->_title);\r
- return parent::_done();\r
- }\r
-\r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Radar.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ * @since File available since Release 0.3.0dev2
+ */
+
+/**
+ * Include file Image/Graph/Plot/Smoothed/Bezier.php
+ */
+require_once 'Image/Graph/Plot/Smoothed/Bezier.php';
+
+/**
+ * Smoothed radar chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @since Class available since Release 0.3.0dev2
+ */
+class Image_Graph_Plot_Smoothed_Radar extends Image_Graph_Plot_Smoothed_Bezier
+{
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+ if (is_a($this->_parent, 'Image_Graph_Plotarea_Radar')) {
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ if ($dataset->count() >= 3) {
+ $dataset->_reset();
+ $p1_ = $dataset->_next();
+ $p2_ = $dataset->_next();
+ $p3_ = $dataset->_next();
+ $plast_ = false;
+ if ($p3_) {
+ while ($p = $dataset->_next()) {
+ $plast_ = $p;
+ }
+ }
+
+ if ($plast_ === false) {
+ $plast_ = $p3_;
+ }
+ $dataset->_reset();
+ while ($p1 = $dataset->_next()) {
+ $p0 = $dataset->_nearby(-2);
+ $p2 = $dataset->_nearby(0);
+ $p3 = $dataset->_nearby(1);
+
+ if ($p0 === false) {
+ $p0 = $plast_;
+ }
+
+ if ($p2 === false) {
+ $p2 = $p1_;
+ $p3 = $p2_;
+ } elseif ($p3 === false) {
+ $p3 = $p1_;
+ }
+
+
+ $cp = $this->_getControlPoints($p1, $p0, $p2, $p3);
+ $this->_canvas->addSpline(
+ array(
+ 'x' => $cp['X'],
+ 'y' => $cp['Y'],
+ 'p1x' => $cp['P1X'],
+ 'p1y' => $cp['P1Y'],
+ 'p2x' => $cp['P2X'],
+ 'p2y' => $cp['P2Y']
+ )
+ );
+
+ $next2last = $p0;
+ $last = $p1;
+ }
+
+ $cp = $this->_getControlPoints($p1_, $plast_, $p2_, $p3_);
+ $this->_canvas->addSpline(
+ array(
+ 'x' => $cp['X'],
+ 'y' => $cp['Y'],
+ 'p1x' => $cp['P1X'],
+ 'p1y' => $cp['P1Y'],
+ 'p2x' => $cp['P2X'],
+ 'p2y' => $cp['P2Y']
+ )
+ );
+ $this->_getFillStyle($key);
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => true));
+ }
+ }
+ unset($keys);
+ }
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup($this->_title);
+ return parent::_done();
+ }
+
+}
+
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Step.php,v 1.15 2005/11/27 22:21:16 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plot/Bar.php\r
- */\r
-require_once 'Image/Graph/Plot/Bar.php';\r
-\r
-/**\r
- * Step chart.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plot\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plot_Step extends Image_Graph_Plot\r
-{\r
-\r
- /**\r
- * Perform the actual drawing on the legend.\r
- *\r
- * @param int $x0 The top-left x-coordinate\r
- * @param int $y0 The top-left y-coordinate\r
- * @param int $x1 The bottom-right x-coordinate\r
- * @param int $y1 The bottom-right y-coordinate\r
- * @access private\r
- */\r
- function _drawLegendSample($x0, $y0, $x1, $y1)\r
- {\r
- $dx = abs($x1 - $x0) / 3;\r
- $dy = abs($y1 - $y0) / 3;\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));\r
- $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy));\r
-\r
- $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0 + $dy));\r
- $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0));\r
-\r
- $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0));\r
- $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy));\r
-\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + 2*$dy));\r
- $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
-\r
- /**\r
- * PlotType [Constructor]\r
- *\r
- * A 'normal' step chart is 'stacked'\r
- *\r
- * @param Dataset $dataset The data set (value containter) to plot\r
- * @param string $multiType The type of the plot\r
- * @param string $title The title of the plot (used for legends,\r
- * {@link Image_Graph_Legend})\r
- */\r
- function Image_Graph_Plot_Step(& $dataset, $multiType = 'stacked', $title = '')\r
- {\r
- $multiType = strtolower($multiType);\r
- if (($multiType != 'stacked') && ($multiType != 'stacked100pct')) {\r
- $multiType = 'stacked';\r
- }\r
- parent::Image_Graph_Plot($dataset, $multiType, $title);\r
- }\r
-\r
- /**\r
- * Output the plot\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if (Image_Graph_Plot::_done() === false) {\r
- return false;\r
- }\r
-\r
- $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);\r
- $this->_clip(true);\r
- \r
- if ($this->_multiType == 'stacked100pct') {\r
- $total = $this->_getTotals();\r
- }\r
-\r
- if ($this->_parent->_horizontal) {\r
- $width = $this->height() / ($this->_maximumX() + 2) / 2;\r
- }\r
- else {\r
- $width = $this->width() / ($this->_maximumX() + 2) / 2;\r
- }\r
-\r
- reset($this->_dataset);\r
- $key = key($this->_dataset);\r
- $dataset =& $this->_dataset[$key];\r
-\r
- $first = $dataset->first();\r
- $last = $dataset->last();\r
-\r
- $point = array ('X' => $first['X'], 'Y' => '#min_pos#');\r
- $firstY = $this->_pointY($point) + ($this->_parent->_horizontal ? $width : 0);\r
- $base[] = $firstY; \r
- $firstX = $this->_pointX($point) - ($this->_parent->_horizontal ? 0 : $width);\r
- $base[] = $firstX;\r
- \r
- $point = array ('X' => $last['X'], 'Y' => '#min_pos#');\r
- $base[] = $this->_pointY($point) - ($this->_parent->_horizontal ? $width : 0);\r
- $base[] = $this->_pointX($point) + ($this->_parent->_horizontal ? 0 : $width);\r
-\r
- $first = ($this->_parent->_horizontal ? $firstY : $firstX);\r
-\r
- $keys = array_keys($this->_dataset);\r
- foreach ($keys as $key) {\r
- $dataset =& $this->_dataset[$key];\r
- $dataset->_reset();\r
- $polygon = array_reverse($base);\r
- unset ($base);\r
- $last = $first;\r
- while ($point = $dataset->_next()) {\r
- $x = $point['X'];\r
- $p = $point;\r
-\r
- if (!isset($current[$x])) {\r
- $current[$x] = 0;\r
- }\r
-\r
- if ($this->_multiType == 'stacked100pct') {\r
- $p['Y'] = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x];\r
- } else {\r
- $p['Y'] += $current[$x];\r
- }\r
- $current[$x] += $point['Y'];\r
- $point = $p;\r
-\r
- if ($this->_parent->_horizontal) {\r
- $x0 = $this->_pointX($point);\r
- $y0 = $last;\r
- $x1 = $this->_pointX($point);\r
- $last = $y1 = $this->_pointY($point) - $width;\r
- }\r
- else {\r
- $x0 = $last;\r
- $y0 = $this->_pointY($point);\r
- $last = $x1 = $this->_pointX($point) + $width;\r
- $y1 = $this->_pointY($point);\r
- } \r
- $polygon[] = $x0; $base[] = $y0;\r
- $polygon[] = $y0; $base[] = $x0;\r
- $polygon[] = $x1; $base[] = $y1;\r
- $polygon[] = $y1; $base[] = $x1;\r
- }\r
-\r
- while (list(, $x) = each($polygon)) {\r
- list(, $y) = each($polygon);\r
- $this->_canvas->addVertex(array('x' => $x, 'y' => $y));\r
- }\r
-\r
- $this->_getFillStyle($key);\r
- $this->_getLineStyle($key);\r
- $this->_canvas->polygon(array('connect' => true));\r
- }\r
- unset($keys);\r
- $this->_drawMarker();\r
- $this->_clip(false);\r
- $this->_canvas->endGroup();\r
- return true;\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Step.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plot/Bar.php
+ */
+require_once 'Image/Graph/Plot/Bar.php';
+
+/**
+ * Step chart.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plot
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plot_Step extends Image_Graph_Plot
+{
+
+ /**
+ * Perform the actual drawing on the legend.
+ *
+ * @param int $x0 The top-left x-coordinate
+ * @param int $y0 The top-left y-coordinate
+ * @param int $x1 The bottom-right x-coordinate
+ * @param int $y1 The bottom-right y-coordinate
+ *
+ * @return void
+ * @access private
+ */
+ function _drawLegendSample($x0, $y0, $x1, $y1)
+ {
+ $dx = abs($x1 - $x0) / 3;
+ $dy = abs($y1 - $y0) / 3;
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y1));
+ $this->_canvas->addVertex(array('x' => $x0, 'y' => $y0 + $dy));
+
+ $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0 + $dy));
+ $this->_canvas->addVertex(array('x' => $x0 + $dx, 'y' => $y0));
+
+ $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0));
+ $this->_canvas->addVertex(array('x' => $x0 + 2*$dx, 'y' => $y0 + 2*$dy));
+
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y0 + 2*$dy));
+ $this->_canvas->addVertex(array('x' => $x1, 'y' => $y1));
+ $this->_canvas->polygon(array('connect' => true));
+ }
+
+ /**
+ * PlotType [Constructor]
+ *
+ * A 'normal' step chart is 'stacked'
+ *
+ * @param Dataset &$dataset The data set (value containter) to plot
+ * @param string $multiType The type of the plot
+ * @param string $title The title of the plot (used for legends,
+ * {@link Image_Graph_Legend})
+ */
+ function Image_Graph_Plot_Step(& $dataset, $multiType = 'stacked', $title = '')
+ {
+ $multiType = strtolower($multiType);
+ if (($multiType != 'stacked') && ($multiType != 'stacked100pct')) {
+ $multiType = 'stacked';
+ }
+ parent::__construct($dataset, $multiType, $title);
+ }
+
+ /**
+ * Output the plot
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if (Image_Graph_Plot::_done() === false) {
+ return false;
+ }
+
+ $this->_canvas->startGroup(get_class($this) . '_' . $this->_title);
+ $this->_clip(true);
+
+ if ($this->_multiType == 'stacked100pct') {
+ $total = $this->_getTotals();
+ }
+
+ if ($this->_parent->_horizontal) {
+ $width = $this->height() / ($this->_maximumX() + 2) / 2;
+ } else {
+ $width = $this->width() / ($this->_maximumX() + 2) / 2;
+ }
+
+ reset($this->_dataset);
+ $key = key($this->_dataset);
+ $dataset =& $this->_dataset[$key];
+
+ $first = $dataset->first();
+ $last = $dataset->last();
+
+ $point = array ('X' => $first['X'], 'Y' => '#min_pos#');
+ $firstY = $this->_pointY($point) + ($this->_parent->_horizontal ? $width : 0);
+ $base[] = $firstY;
+ $firstX = $this->_pointX($point) - ($this->_parent->_horizontal ? 0 : $width);
+ $base[] = $firstX;
+
+ $point = array ('X' => $last['X'], 'Y' => '#min_pos#');
+ $base[] = $this->_pointY($point) - ($this->_parent->_horizontal ? $width : 0);
+ $base[] = $this->_pointX($point) + ($this->_parent->_horizontal ? 0 : $width);
+
+ $first = ($this->_parent->_horizontal ? $firstY : $firstX);
+
+ $keys = array_keys($this->_dataset);
+ foreach ($keys as $key) {
+ $dataset =& $this->_dataset[$key];
+ $dataset->_reset();
+ $polygon = array_reverse($base);
+ unset ($base);
+ $last = $first;
+ while ($point = $dataset->_next()) {
+ $x = $point['X'];
+ $p = $point;
+
+ if (!isset($current[$x])) {
+ $current[$x] = 0;
+ }
+
+ if ($this->_multiType == 'stacked100pct') {
+ $p['Y'] = 100 * ($current[$x] + $point['Y']) / $total['TOTAL_Y'][$x];
+ } else {
+ $p['Y'] += $current[$x];
+ }
+ $current[$x] += $point['Y'];
+ $point = $p;
+
+ if ($this->_parent->_horizontal) {
+ $x0 = $this->_pointX($point);
+ $y0 = $last;
+ $x1 = $this->_pointX($point);
+ $last = $y1 = $this->_pointY($point) - $width;
+ } else {
+ $x0 = $last;
+ $y0 = $this->_pointY($point);
+ $last = $x1 = $this->_pointX($point) + $width;
+ $y1 = $this->_pointY($point);
+ }
+ $polygon[] = $x0; $base[] = $y0;
+ $polygon[] = $y0; $base[] = $x0;
+ $polygon[] = $x1; $base[] = $y1;
+ $polygon[] = $y1; $base[] = $x1;
+ }
+
+ while (list(, $x) = each($polygon)) {
+ list(, $y) = each($polygon);
+ $this->_canvas->addVertex(array('x' => $x, 'y' => $y));
+ }
+
+ $this->_getFillStyle($key);
+ $this->_getLineStyle($key);
+ $this->_canvas->polygon(array('connect' => true));
+ }
+ unset($keys);
+ $this->_clip(false);
+
+ $this->_drawMarker();
+ $this->_canvas->endGroup();
+ return true;
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Plotarea.php,v 1.23 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout.php\r
- */\r
-require_once 'Image/Graph/Layout.php';\r
-\r
-/**\r
- * Plot area used for drawing plots.\r
- *\r
- * The plotarea consists of an x-axis and an y-axis, the plotarea can plot multiple\r
- * charts within one plotares, by simply adding them (the axis' will scale to the\r
- * plots automatically). A graph can consist of more plotareas\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plotarea extends Image_Graph_Layout\r
-{\r
- \r
- /**\r
- * The left most pixel of the 'real' plot area on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_plotLeft = 0;\r
-\r
- /**\r
- * The top most pixel of the 'real' plot area on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_plotTop = 0;\r
-\r
- /**\r
- * The right most pixel of the 'real' plot area on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_plotRight = 0;\r
-\r
- /**\r
- * The bottom most pixel of the 'real' plot area on the canvas\r
- * @var int\r
- * @access private\r
- */\r
- var $_plotBottom = 0;\r
-\r
- /**\r
- * The X axis\r
- * @var Axis\r
- * @access private\r
- */\r
- var $_axisX = null;\r
-\r
- /**\r
- * The Y axis\r
- * @var Axis\r
- * @access private\r
- */\r
- var $_axisY = null;\r
-\r
- /**\r
- * The secondary Y axis\r
- * @var Axis\r
- * @access private\r
- */\r
- var $_axisYSecondary = null;\r
-\r
- /**\r
- * The border style of the 'real' plot area\r
- * @var LineStyle\r
- * @access private\r
- */\r
- var $_plotBorderStyle = null;\r
-\r
- /**\r
- * Does any plot have any data?\r
- * @var bool\r
- * @access private\r
- */\r
- var $_hasData = false;\r
- \r
- /**\r
- * Is the plotarea horizontal?\r
- * @var bool\r
- * @access private\r
- */\r
- var $_horizontal = false;\r
-\r
- /**\r
- * Image_Graph_Plotarea [Constructor]\r
- *\r
- * @param string $axisX The class of the X axis (if omitted a std. axis is created)\r
- * @param string $axisY The class of the Y axis (if omitted a std. axis is created)\r
- * @param string $direction The direction of the plotarea - 'horizontal' or 'vertical' (default)\r
- */\r
- function Image_Graph_Plotarea($axisX = 'Image_Graph_Axis_Category', $axisY = 'Image_Graph_Axis', $direction = 'vertical')\r
- {\r
- parent::Image_Graph_Layout();\r
-\r
- $this->_padding = array('left' => 5, 'top' => 5, 'right' => 5, 'bottom' => 5);;\r
-\r
- include_once 'Image/Graph.php';\r
-\r
- $this->_axisX =& Image_Graph::factory($axisX, IMAGE_GRAPH_AXIS_X);\r
- $this->_axisX->_setParent($this);\r
-\r
- $this->_axisY =& Image_Graph::factory($axisY, IMAGE_GRAPH_AXIS_Y);\r
- $this->_axisY->_setParent($this);\r
- $this->_axisY->_setMinimum(0);\r
-\r
- $this->_fillStyle = false;\r
- \r
- if ($direction == 'horizontal') {\r
- $this->_horizontal = true;\r
- $this->_axisX->_transpose = true;\r
- $this->_axisY->_transpose = true;\r
- }\r
- }\r
-\r
- /**\r
- * Sets the parent. The parent chain should ultimately be a GraPHP object\r
- *\r
- * @see Image_Graph_Common\r
- * @param Image_Graph_Common $parent The parent\r
- * @access private\r
- */\r
- function _setParent(& $parent)\r
- {\r
- parent::_setParent($parent);\r
- if ($this->_axisX !== null) {\r
- $this->_axisX->_setParent($this);\r
- }\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setParent($this);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setParent($this);\r
- }\r
- }\r
-\r
- /**\r
- * Sets the plot border line style of the element.\r
- *\r
- * @param Image_Graph_Line $lineStyle The line style of the border\r
- * @deprecated 0.3.0dev2 - 2004-12-16\r
- */\r
- function setPlotBorderStyle(& $plotBorderStyle)\r
- { \r
- }\r
-\r
- /**\r
- * Adds an element to the plotarea\r
- *\r
- * @param Image_Graph_Element $element The element to add\r
- * @param int $axis The axis to associate the element with, either\r
- * IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y, IMAGE_GRAPH_AXIS_Y_SECONDARY\r
- * or the shorter string notations 'x', 'y' or 'ysec' (defaults to\r
- * IMAGE_GRAPH_AXIS_Y)\r
- * @return Image_Graph_Element The added element\r
- * @see Image_Graph_Common::add()\r
- */\r
- function &add(& $element, $axis = IMAGE_GRAPH_AXIS_Y) \r
- {\r
- if ($axis == 'x') {\r
- $axis = IMAGE_GRAPH_AXIS_X;\r
- }\r
- if ($axis == 'y') {\r
- $axis = IMAGE_GRAPH_AXIS_Y;\r
- }\r
- if ($axis == 'ysec') {\r
- $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;\r
- }\r
- if (($axis == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&\r
- ($this->_axisYSecondary == null))\r
- {\r
- $this->_axisYSecondary =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);\r
- $this->_axisYSecondary->_setMinimum(0);\r
- if ($this->_horizontal) {\r
- $this->_axisYSecondary->_transpose = true;\r
- }\r
- }\r
-\r
- parent::add($element);\r
-\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $element->_setAxisY($axis);\r
- // postpone extrema calculation until we calculate coordinates\r
- //$this->_setExtrema($element);\r
- } elseif (is_a($element, 'Image_Graph_Grid')) {\r
- switch ($axis) {\r
- case IMAGE_GRAPH_AXIS_X:\r
- if ($this->_axisX != null) {\r
- $element->_setPrimaryAxis($this->_axisX);\r
- if ($this->_axisY != null) {\r
- $element->_setSecondaryAxis($this->_axisY);\r
- }\r
- }\r
- break;\r
- case IMAGE_GRAPH_AXIS_Y:\r
- if ($this->_axisY != null) {\r
- $element->_setPrimaryAxis($this->_axisY);\r
- if ($this->_axisX != null) {\r
- $element->_setSecondaryAxis($this->_axisX);\r
- }\r
- }\r
- break;\r
- case IMAGE_GRAPH_AXIS_Y_SECONDARY:\r
- if ($this->_axisYSecondary != null) {\r
- $element->_setPrimaryAxis($this->_axisYSecondary);\r
- if ($this->_axisX != null) {\r
- $element->_setSecondaryAxis($this->_axisX);\r
- }\r
- }\r
- break;\r
- }\r
- } elseif (is_a($element, 'Image_Graph_Axis')) {\r
- switch ($element->_type) {\r
- case IMAGE_GRAPH_AXIS_X:\r
- $this->_axisX =& $element;\r
- break;\r
-\r
- case IMAGE_GRAPH_AXIS_Y:\r
- $this->_axisY =& $element;\r
- break;\r
-\r
- case IMAGE_GRAPH_AXIS_Y_SECONDARY:\r
- $this->_axisYSecondary =& $element;\r
- break;\r
-\r
- }\r
- if ($element->_getMinimum() == $element->_getMaximum()) {\r
- $element->_setMinimum(0);\r
- $element->_setMaximum(1);\r
- }\r
- }\r
- return $element;\r
- } \r
-\r
- /**\r
- * Get the width of the 'real' plotarea\r
- *\r
- * @return int The width of the 'real' plotarea, ie not including space occupied by padding and axis\r
- * @access private\r
- */\r
- function _plotWidth()\r
- {\r
- return abs($this->_plotRight - $this->_plotLeft);\r
- }\r
-\r
- /**\r
- * Get the height of the 'real' plotarea\r
- *\r
- * @return int The height of the 'real' plotarea, ie not including space\r
- * occupied by padding and axis\r
- * @access private\r
- */\r
- function _plotHeight()\r
- {\r
- return abs($this->_plotBottom - $this->_plotTop);\r
- }\r
-\r
- /**\r
- * Set the extrema of the axis\r
- *\r
- * @param Image_Graph_Plot $plot The plot that 'hold' the values\r
- * @access private\r
- */\r
- function _setExtrema(& $plot)\r
- {\r
- if (($this->_axisX != null) && ($this->_axisX->_isNumeric())) {\r
- $this->_axisX->_setMinimum($plot->_minimumX());\r
- $this->_axisX->_setMaximum($plot->_maximumX());\r
- }\r
-\r
- if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&\r
- ($this->_axisYSecondary !== null) &&\r
- ($this->_axisYSecondary->_isNumeric()))\r
- {\r
- $this->_axisYSecondary->_setMinimum($plot->_minimumY());\r
- $this->_axisYSecondary->_setMaximum($plot->_maximumY());\r
- } elseif (($this->_axisY != null) && ($this->_axisY->_isNumeric())) {\r
- $this->_axisY->_setMinimum($plot->_minimumY());\r
- $this->_axisY->_setMaximum($plot->_maximumY());\r
- }\r
-\r
- $datasets =& $plot->dataset();\r
- if (!is_array($datasets)) {\r
- $datasets = array($datasets);\r
- }\r
- \r
- $keys = array_keys($datasets);\r
- foreach ($keys as $key) {\r
- $dataset =& $datasets[$key];\r
- if ($dataset->count() > 0) {\r
- $this->_hasData = true;\r
- }\r
- \r
- if (is_a($dataset, 'Image_Graph_Dataset')) {\r
- if (($this->_axisX != null) && (!$this->_axisX->_isNumeric())) {\r
- $this->_axisX->_applyDataset($dataset);\r
- }\r
-\r
- if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&\r
- ($this->_axisYSecondary !== null) &&\r
- (!$this->_axisYSecondary->_isNumeric()))\r
- {\r
- $this->_axisYSecondary->_applyDataset($dataset);\r
- } elseif (($this->_axisY != null) && (!$this->_axisY->_isNumeric())) {\r
- $this->_axisY->_applyDataset($dataset);\r
- }\r
- }\r
- }\r
- unset($keys);\r
- }\r
-\r
- /**\r
- * Left boundary of the background fill area\r
- *\r
- * @return int Leftmost position on the canvas\r
- * @access private\r
- */\r
- function _fillLeft()\r
- {\r
- return $this->_plotLeft;\r
- }\r
-\r
- /**\r
- * Top boundary of the background fill area\r
- *\r
- * @return int Topmost position on the canvas\r
- * @access private\r
- */\r
- function _fillTop()\r
- {\r
- return $this->_plotTop;\r
- }\r
-\r
- /**\r
- * Right boundary of the background fill area\r
- *\r
- * @return int Rightmost position on the canvas\r
- * @access private\r
- */\r
- function _fillRight()\r
- {\r
- return $this->_plotRight;\r
- }\r
-\r
- /**\r
- * Bottom boundary of the background fill area\r
- *\r
- * @return int Bottommost position on the canvas\r
- * @access private\r
- */\r
- function _fillBottom()\r
- {\r
- return $this->_plotBottom;\r
- }\r
-\r
- /**\r
- * Get the point from the x-axis\r
- * @param array $value The value array\r
- * @param int $min The minimum pixel position possible\r
- * @param int $max The maximum pixel position possible\r
- * @return int The pixel position from the axis\r
- * @access private\r
- */\r
- function _axisPointX($value, $min, $max)\r
- {\r
- if (($this->_axisX == null) || (!isset($value['X']))) {\r
- return false;\r
- }\r
-\r
- if ($value['X'] === '#min#') {\r
- return $min;\r
- }\r
- if ($value['X'] === '#max#') {\r
- return $max;\r
- }\r
-\r
- return $this->_axisX->_point($value['X']);\r
- }\r
- \r
- /**\r
- * Get the point from the x-axis\r
- * @param array $value The value array\r
- * @param int $min The minimum pixel position possible\r
- * @param int $max The maximum pixel position possible\r
- * @return int The pixel position from the axis\r
- * @access private\r
- */\r
- function _axisPointY($value, $min, $max)\r
- {\r
- if (!isset($value['Y'])) {\r
- return false;\r
- }\r
- \r
- if (($value['Y'] === '#min_pos#') || ($value['Y'] === '#max_nex#')) {\r
- // return the minimum (bottom) position or if negative then zero\r
- // or the maxmum (top) position or if positive then zero\r
- if ((isset($value['AXIS_Y'])) &&\r
- ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&\r
- ($this->_axisYSecondary !== null)\r
- ) {\r
- $axisY =& $this->_axisYSecondary;\r
- } else {\r
- $axisY =& $this->_axisY;\r
- }\r
- if ($value['Y'] === '#min_pos#') {\r
- return $axisY->_point(max(0, $axisY->_getMinimum()));\r
- } else {\r
- return $axisY->_point(min(0, $axisY->_getMaximum()));\r
- }\r
- }\r
- \r
- if ($value['Y'] === '#min#') {\r
- return $min;\r
- }\r
- if ($value['Y'] === '#max#') {\r
- return $max;\r
- }\r
- \r
- if ((isset($value['AXIS_Y'])) &&\r
- ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY)\r
- ) {\r
- if ($this->_axisYSecondary !== null) {\r
- return $this->_axisYSecondary->_point($value['Y']);\r
- }\r
- } else {\r
- if ($this->_axisY !== null) {\r
- return $this->_axisY->_point($value['Y']);\r
- }\r
- }\r
- return false; \r
- }\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double Value the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($value)\r
- {\r
- if ($this->_horizontal) {\r
- return $this->_axisPointY($value, $this->_plotLeft, $this->_plotRight);\r
- }\r
- else {\r
- return $this->_axisPointX($value, $this->_plotLeft, $this->_plotRight);\r
- }\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double Value the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($value)\r
- {\r
- if ($this->_horizontal) {\r
- return $this->_axisPointX($value, $this->_plotBottom, $this->_plotTop);\r
- }\r
- else {\r
- return $this->_axisPointY($value, $this->_plotBottom, $this->_plotTop);\r
- }\r
- }\r
-\r
- /**\r
- * Return the minimum value of the specified axis\r
- *\r
- * @param int $axis The axis to return the minimum value of (see {$link\r
- * Image_Graph_Plotarea::getAxis()})\r
- * @return double The minimum value of the axis\r
- * @access private\r
- */\r
- function _getMinimum($axis = IMAGE_GRAPH_AXIS_Y)\r
- {\r
- $axis =& $this->getAxis($axis);\r
- if ($axis !== null) {\r
- return $axis->_getMinimum();\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- /**\r
- * Return the maximum value of the specified axis\r
- *\r
- * @param int $axis The axis to return the maximum value of(see {$link\r
- * Image_Graph_Plotarea::getAxis()})\r
- * @return double The maximum value of the axis\r
- * @access private\r
- */\r
- function _getMaximum($axis = IMAGE_GRAPH_AXIS_Y)\r
- {\r
- $axis =& $this->getAxis($axis);\r
- if ($axis !== null) {\r
- return $axis->_getMaximum();\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- /**\r
- * Return the label distance for the specified axis.\r
- *\r
- * @param int $axis The axis to return the label distance for\r
- * @return int The distance between 2 adjacent labels\r
- * @access private\r
- */\r
- function _labelDistance($axis)\r
- {\r
- $axis =& $this->getAxis($axis);\r
- if ($axis !== null) {\r
- return $axis->_labelDistance();\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /**\r
- * Hides the axis\r
- */\r
- function hideAxis($axis = false)\r
- {\r
- if (((!$axis) || ($axis === $this->_axisX) || ($axis === 'x')) && ($this->_axisX != null)) {\r
- $this->_axisX->hide();\r
- } \r
- if (((!$axis) || ($axis === $this->_axisY) || ($axis === 'y')) && ($this->_axisY != null)) {\r
- $this->_axisY->hide();\r
- } \r
- if (((!$axis) || ($axis === $this->_axisYSecondary) || ($axis === 'y_sec')) && ($this->_axisYSecondary != null)) {\r
- $this->_axisYSecondary->hide();\r
- } \r
- }\r
-\r
- /**\r
- * Clears/removes the axis\r
- */\r
- function clearAxis()\r
- {\r
- $this->_axisX = $this->_axisY = $this->_axisYSecondary = null;\r
- }\r
- \r
- /**\r
- * Get axis.\r
- * \r
- * Possible values are IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y,\r
- * IMAGE_GRAPH_AXIS_Y_SECONDARY or a short hand notation using\r
- * string identifiers: 'x', 'y', 'ysec'\r
- * \r
- * @param int $axis The axis to return\r
- * @return Image_Graph_Axis The axis\r
- */\r
- function &getAxis($axis = IMAGE_GRAPH_AXIS_X)\r
- {\r
- switch ($axis) {\r
- case IMAGE_GRAPH_AXIS_X:\r
- case 'x':\r
- return $this->_axisX;\r
-\r
- case IMAGE_GRAPH_AXIS_Y:\r
- case 'y':\r
- return $this->_axisY;\r
-\r
- case IMAGE_GRAPH_AXIS_Y_SECONDARY:\r
- case 'ysec':\r
- return $this->_axisYSecondary;\r
-\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- { \r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- $element =& $this->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) { \r
- if (((is_a($element, 'Image_Graph_Plot_Bar')) ||\r
- (is_a($element, 'Image_Graph_Plot_Step')) ||\r
- (is_a($element, 'Image_Graph_Plot_Dot')) ||\r
- (is_a($element, 'Image_Graph_Plot_CandleStick')) ||\r
- (is_a($element, 'Image_Graph_Plot_BoxWhisker')) ||\r
- (is_a($element, 'Image_Graph_Plot_Impulse'))) &&\r
- ($this->_axisX != null) &&\r
- (strtolower(get_class($this->_axisX)) != 'image_graph_axis') // do not push plot if x-axis is linear\r
- )\r
- {\r
- $this->_axisX->_pushValues();\r
- }\r
- $this->_setExtrema($element);\r
- }\r
- }\r
- unset($keys);\r
- }\r
-\r
- $this->_calcEdges();\r
-\r
- $pctWidth = (int) ($this->width() * 0.05);\r
- $pctHeight = (int) ($this->height() * 0.05);\r
-\r
- $left = $this->_left + $this->_padding['left'];\r
- $top = $this->_top + $this->_padding['top'];\r
- $right = $this->_right - $this->_padding['right'];\r
- $bottom = $this->_bottom - $this->_padding['bottom'];\r
- \r
- // temporary place holder for axis point calculations\r
- $axisPoints['x'] = array($left, $top, $right, $bottom);\r
- $axisPoints['y'] = $axisPoints['x'];\r
- $axisPoints['y2'] = $axisPoints['x'];\r
- \r
- if ($this->_axisX !== null) {\r
- $intersectX = $this->_axisX->_getAxisIntersection();\r
- $sizeX = $this->_axisX->_size();\r
- $this->_axisX->_setCoords($left, $top, $right, $bottom);\r
- $this->_axisX->_updateCoords(); \r
- }\r
- \r
- if ($this->_axisY !== null) {\r
- $intersectY = $this->_axisY->_getAxisIntersection();\r
- $sizeY = $this->_axisY->_size();\r
- $this->_axisY->_setCoords($left, $top, $right, $bottom);\r
- $this->_axisY->_updateCoords();\r
- }\r
-\r
- if ($this->_axisYSecondary !== null) {\r
- $intersectYsec = $this->_axisYSecondary->_getAxisIntersection();\r
- $sizeYsec = $this->_axisYSecondary->_size();\r
- $this->_axisYSecondary->_setCoords($left, $top, $right, $bottom);\r
- $this->_axisYSecondary->_updateCoords();\r
- } \r
- \r
- $axisCoordAdd = array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0);\r
- \r
- if ($this->_axisY != null) {\r
- if ($this->_axisX != null) { \r
- $pos = $this->_axisX->_intersectPoint($intersectY['value']); \r
- } else {\r
- $pos = ($this->_horizontal ? $bottom : $left);\r
- }\r
-\r
- if ($this->_horizontal) {\r
- if (($pos + $sizeY) > $bottom) {\r
- $axisCoordAdd['bottom'] = ($pos + $sizeY) - $bottom; \r
- // the y-axis position needs to be recalculated! \r
- } else { \r
- // top & bottom may need to be adjusted when the x-axis has been\r
- // calculated!\r
- $this->_axisY->_setCoords(\r
- $left,\r
- $pos,\r
- $right,\r
- $pos + $sizeY\r
- );\r
- $this->_axisY->_updateCoords();\r
- }\r
- }\r
- else {\r
- if (($pos - $sizeY) < $left) {\r
- $axisCoordAdd['left'] = $left - ($pos - $sizeY);\r
- // the y-axis position needs to be recalculated! \r
- } else { \r
- // top & bottom may need to be adjusted when the x-axis has been\r
- // calculated!\r
- $this->_axisY->_setCoords(\r
- $pos - $sizeY,\r
- $top,\r
- $pos,\r
- $bottom\r
- );\r
- $this->_axisY->_updateCoords();\r
- }\r
- } \r
- } \r
-\r
- if ($this->_axisYSecondary != null) {\r
- if ($this->_axisX != null) {\r
- $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);\r
- } else {\r
- $pos = ($this->_horizontal ? $top : $right);\r
- }\r
- \r
- if ($this->_horizontal) {\r
- if (($pos - $sizeYsec) < $top) {\r
- $axisCoordAdd['top'] = $top - ($pos - $sizeYsec);\r
- // the secondary y-axis position need to be recalculated\r
- } else {\r
- // top & bottom may need to be adjusted when the x-axis has been\r
- // calculated!\r
- $this->_axisYSecondary->_setCoords(\r
- $left,\r
- $pos - $sizeY,\r
- $right,\r
- $pos\r
- );\r
- $this->_axisYSecondary->_updateCoords();\r
- }\r
- }\r
- else {\r
- if (($pos + $sizeYsec) > $right) {\r
- $axisCoordAdd['right'] = ($pos + $sizeYsec) - $right;\r
- // the secondary y-axis position need to be recalculated\r
- } else {\r
- // top & bottom may need to be adjusted when the x-axis has been\r
- // calculated!\r
- $this->_axisYSecondary->_setCoords(\r
- $pos,\r
- $top,\r
- $pos + $sizeY,\r
- $bottom\r
- );\r
- $this->_axisYSecondary->_updateCoords();\r
- }\r
- } \r
- } \r
- \r
- if ($this->_axisX != null) {\r
- if (($intersectX['axis'] == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&\r
- ($this->_axisYSecondary !== null)\r
- ) {\r
- $axis =& $this->_axisYSecondary;\r
- } elseif ($this->_axisY !== null) {\r
- $axis =& $this->_axisY;\r
- } else {\r
- $axis = false;\r
- }\r
- \r
- if ($axis !== false) {\r
- $pos = $axis->_intersectPoint($intersectX['value']);\r
- } else {\r
- $pos = ($this->_horizontal ? $left : $bottom);\r
- }\r
- \r
- if ($this->_horizontal) {\r
- if (($pos - $sizeX) < $left) {\r
- $axisCoordAdd['left'] = $left - ($pos - $sizeX);\r
- $pos = $left + $sizeX;\r
- }\r
- \r
- $this->_axisX->_setCoords(\r
- $pos - $sizeX,\r
- $top + $axisCoordAdd['top'],\r
- $pos,\r
- $bottom - $axisCoordAdd['bottom']\r
- );\r
- $this->_axisX->_updateCoords();\r
- }\r
- else {\r
- if (($pos + $sizeX) > $bottom) {\r
- $axisCoordAdd['bottom'] = ($pos + $sizeX) - $bottom;\r
- $pos = $bottom - $sizeX;\r
- }\r
- \r
- $this->_axisX->_setCoords(\r
- $left + $axisCoordAdd['left'],\r
- $pos,\r
- $right - $axisCoordAdd['right'],\r
- $pos + $sizeX\r
- );\r
- $this->_axisX->_updateCoords();\r
- }\r
- }\r
- \r
- if ($this->_horizontal) {\r
- if (($this->_axisX !== null) && \r
- (($axisCoordAdd['top'] != 0) ||\r
- ($axisCoordAdd['bottom'] != 0))\r
- ) {\r
- // readjust y-axis for better estimate of position\r
- if ($this->_axisY !== null) {\r
- $pos = $this->_axisX->_intersectPoint($intersectY['value']);\r
- $this->_axisY->_setCoords(\r
- false,\r
- $pos,\r
- false,\r
- $pos + $sizeY\r
- );\r
- $this->_axisY->_updateCoords();\r
- }\r
- \r
- if ($this->_axisYSecondary !== null) {\r
- $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);\r
- $this->_axisYSecondary->_setCoords(\r
- false,\r
- $pos - $sizeYsec,\r
- false,\r
- $pos\r
- );\r
- $this->_axisYSecondary->_updateCoords();\r
- }\r
- } \r
- \r
- // adjust top and bottom of y-axis\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setCoords(\r
- $left + $axisCoordAdd['left'],\r
- false, \r
- $right - $axisCoordAdd['right'],\r
- false \r
- );\r
- $this->_axisY->_updateCoords();\r
- } \r
- \r
- // adjust top and bottom of y-axis\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setCoords(\r
- $left + $axisCoordAdd['left'], \r
- false, \r
- $right - $axisCoordAdd['right'],\r
- false \r
- );\r
- $this->_axisYSecondary->_updateCoords(); \r
- } \r
- \r
- if ($this->_axisX !== null) {\r
- $this->_plotTop = $this->_axisX->_top;\r
- $this->_plotBottom = $this->_axisX->_bottom;\r
- } else {\r
- $this->_plotTop = $top;\r
- $this->_plotBottom = $bottom;\r
- }\r
- \r
- if ($this->_axisY !== null) {\r
- $this->_plotLeft = $this->_axisY->_left;\r
- $this->_plotRight = $this->_axisY->_right;\r
- } elseif ($this->_axisYSecondary !== null) {\r
- $this->_plotLeft = $this->_axisYSecondary->_left;\r
- $this->_plotRight = $this->_axisYSecondary->_right;\r
- } else {\r
- $this->_plotLeft = $this->_left;\r
- $this->_plotRight = $this->_right;\r
- }\r
- }\r
- else {\r
- if (($this->_axisX !== null) && \r
- (($axisCoordAdd['left'] != 0) ||\r
- ($axisCoordAdd['right'] != 0))\r
- ) {\r
- // readjust y-axis for better estimate of position\r
- if ($this->_axisY !== null) {\r
- $pos = $this->_axisX->_intersectPoint($intersectY['value']);\r
- $this->_axisY->_setCoords(\r
- $pos - $sizeY,\r
- false,\r
- $pos,\r
- false\r
- );\r
- $this->_axisY->_updateCoords();\r
- }\r
- \r
- if ($this->_axisYSecondary !== null) {\r
- $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);\r
- $this->_axisYSecondary->_setCoords(\r
- $pos,\r
- false,\r
- $pos + $sizeYsec,\r
- false\r
- );\r
- $this->_axisYSecondary->_updateCoords();\r
- }\r
- } \r
- \r
- // adjust top and bottom of y-axis\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setCoords(\r
- false, \r
- $top + $axisCoordAdd['top'], \r
- false, \r
- $bottom - $axisCoordAdd['bottom']\r
- );\r
- $this->_axisY->_updateCoords();\r
- } \r
- \r
- // adjust top and bottom of y-axis\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setCoords(\r
- false, \r
- $top + $axisCoordAdd['top'], \r
- false, \r
- $bottom - $axisCoordAdd['bottom']\r
- );\r
- $this->_axisYSecondary->_updateCoords(); \r
- } \r
- \r
- if ($this->_axisX !== null) {\r
- $this->_plotLeft = $this->_axisX->_left;\r
- $this->_plotRight = $this->_axisX->_right;\r
- } else {\r
- $this->_plotLeft = $left;\r
- $this->_plotRight = $right;\r
- }\r
- \r
- if ($this->_axisY !== null) {\r
- $this->_plotTop = $this->_axisY->_top;\r
- $this->_plotBottom = $this->_axisY->_bottom;\r
- } elseif ($this->_axisYSecondary !== null) {\r
- $this->_plotTop = $this->_axisYSecondary->_top;\r
- $this->_plotBottom = $this->_axisYSecondary->_bottom;\r
- } else {\r
- $this->_plotTop = $this->_top;\r
- $this->_plotBottom = $this->_bottom;\r
- }\r
- }\r
- \r
- Image_Graph_Element::_updateCoords();\r
-/*\r
- if ($this->_axisX != null) {\r
- $this->_axisX->_updateCoords();\r
- }\r
- if ($this->_axisY != null) {\r
- $this->_axisY->_updateCoords();\r
- }\r
- if ($this->_axisYSecondary != null) {\r
- $this->_axisYSecondary->_updateCoords();\r
- }*/\r
- }\r
- \r
- /**\r
- * Set the axis padding for a specified position.\r
- * \r
- * The axis padding is padding "inside" the plotarea (i.e. to put some space\r
- * between the axis line and the actual plot).\r
- * \r
- * This can be specified in a number of ways:\r
- * \r
- * 1) Specify an associated array with 'left', 'top', 'right' and 'bottom'\r
- * indices with values for the paddings. Leave out 2nd parameter.\r
- * \r
- * 2) Specify an overall padding as the first parameter\r
- * \r
- * 3) Specify the padding and position with position values as mentioned\r
- * above\r
- * \r
- * Normally you'd only consider applying axis padding to a category x-axis.\r
- * \r
- * @param mixed $value The value/padding\r
- * @param mixed $position The "position" of the padding\r
- */\r
- function setAxisPadding($value, $position = false)\r
- {\r
- if ($position === false) {\r
- if (is_array($value)) {\r
- if ($this->_horizontal) {\r
- if ((isset($value['top'])) && ($this->_axisX !== null)) {\r
- $this->_axisX->_setAxisPadding('low', $value['top']);\r
- }\r
- if ((isset($value['bottom'])) && ($this->_axisX !== null)) {\r
- $this->_axisX->_setAxisPadding('high', $value['bottom']);\r
- }\r
- if ((isset($value['left'])) && ($this->_axisY !== null)) {\r
- $this->_axisY->_setAxisPadding('low', $value['left']);\r
- }\r
- if ((isset($value['right'])) && ($this->_axisY !== null)) { \r
- $this->_axisY->_setAxisPadding('high', $value['right']);\r
- }\r
- if ((isset($value['left'])) && ($this->_axisYSecondary !== null)) {\r
- $this->_axisYSecondary->_setAxisPadding('low', $value['left']);\r
- }\r
- if ((isset($value['right'])) && ($this->_axisYSecondary !== null)) { \r
- $this->_axisYSecondary->_setAxisPadding('high', $value['right']);\r
- }\r
- }\r
- else {\r
- if ((isset($value['left'])) && ($this->_axisX !== null)) {\r
- $this->_axisX->_setAxisPadding('low', $value['left']);\r
- }\r
- if ((isset($value['right'])) && ($this->_axisX !== null)) {\r
- $this->_axisX->_setAxisPadding('high', $value['right']);\r
- }\r
- if ((isset($value['bottom'])) && ($this->_axisY !== null)) {\r
- $this->_axisY->_setAxisPadding('low', $value['bottom']);\r
- }\r
- if ((isset($value['top'])) && ($this->_axisY !== null)) { \r
- $this->_axisY->_setAxisPadding('high', $value['top']);\r
- }\r
- if ((isset($value['bottom'])) && ($this->_axisYSecondary !== null)) {\r
- $this->_axisYSecondary->_setAxisPadding('low', $value['bottom']);\r
- }\r
- if ((isset($value['top'])) && ($this->_axisYSecondary !== null)) { \r
- $this->_axisYSecondary->_setAxisPadding('high', $value['top']);\r
- }\r
- }\r
- } else {\r
- if ($this->_axisX !== null) {\r
- $this->_axisX->_setAxisPadding('low', $value);\r
- $this->_axisX->_setAxisPadding('high', $value);\r
- }\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setAxisPadding('low', $value);\r
- $this->_axisY->_setAxisPadding('high', $value);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setAxisPadding('low', $value);\r
- $this->_axisYSecondary->_setAxisPadding('high', $value);\r
- }\r
- }\r
- } else {\r
- switch ($position) {\r
- case 'left': \r
- if ($this->_horizontal) {\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setAxisPadding('low', $value);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setAxisPadding('low', $value);\r
- }\r
- }\r
- else if ($this->_axisX !== null) {\r
- $this->_axisX->_setAxisPadding('low', $value);\r
- }\r
- break;\r
-\r
- case 'right': \r
- if ($this->_horizontal) {\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setAxisPadding('high', $value);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setAxisPadding('high', $value);\r
- }\r
- }\r
- else if ($this->_axisX !== null) {\r
- $this->_axisX->_setAxisPadding('high', $value);\r
- }\r
- break;\r
-\r
- case 'top': \r
- if (!$this->_horizontal) {\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setAxisPadding('high', $value);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setAxisPadding('high', $value);\r
- }\r
- }\r
- else if ($this->_axisX !== null) {\r
- $this->_axisX->_setAxisPadding('high', $value);\r
- } \r
- break;\r
-\r
- case 'bottom': \r
- if (!$this->_horizontal) {\r
- if ($this->_axisY !== null) {\r
- $this->_axisY->_setAxisPadding('low', $value);\r
- }\r
- if ($this->_axisYSecondary !== null) {\r
- $this->_axisYSecondary->_setAxisPadding('low', $value);\r
- }\r
- }\r
- else if ($this->_axisX !== null) {\r
- $this->_axisX->_setAxisPadding('low', $value);\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Output the plotarea to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if ($this->_hasData) { \r
- $this->_canvas->startGroup(get_class($this));\r
- \r
- if ($this->_axisX != null) {\r
- $this->add($this->_axisX);\r
- }\r
- if ($this->_axisY != null) {\r
- $this->add($this->_axisY);\r
- }\r
- if ($this->_axisYSecondary != null) {\r
- $this->add($this->_axisYSecondary);\r
- }\r
- \r
- $this->_getFillStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $this->_plotLeft,\r
- 'y0' => $this->_plotTop,\r
- 'x1' => $this->_plotRight,\r
- 'y1' => $this->_plotBottom\r
- )\r
- );\r
- $result = parent::_done();\r
- $this->_canvas->endGroup(); \r
- return $result;\r
- } else {\r
- // no data -> do nothing at all!\r
- return true;\r
- } \r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Plotarea.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout.php
+ */
+require_once 'Image/Graph/Layout.php';
+
+/**
+ * Plot area used for drawing plots.
+ *
+ * The plotarea consists of an x-axis and an y-axis, the plotarea can plot multiple
+ * charts within one plotares, by simply adding them (the axis' will scale to the
+ * plots automatically). A graph can consist of more plotareas
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plotarea extends Image_Graph_Layout
+{
+
+ /**
+ * The left most pixel of the 'real' plot area on the canvas
+ * @var int
+ * @access private
+ */
+ var $_plotLeft = 0;
+
+ /**
+ * The top most pixel of the 'real' plot area on the canvas
+ * @var int
+ * @access private
+ */
+ var $_plotTop = 0;
+
+ /**
+ * The right most pixel of the 'real' plot area on the canvas
+ * @var int
+ * @access private
+ */
+ var $_plotRight = 0;
+
+ /**
+ * The bottom most pixel of the 'real' plot area on the canvas
+ * @var int
+ * @access private
+ */
+ var $_plotBottom = 0;
+
+ /**
+ * The X axis
+ * @var Axis
+ * @access private
+ */
+ var $_axisX = null;
+
+ /**
+ * The Y axis
+ * @var Axis
+ * @access private
+ */
+ var $_axisY = null;
+
+ /**
+ * The secondary Y axis
+ * @var Axis
+ * @access private
+ */
+ var $_axisYSecondary = null;
+
+ /**
+ * The border style of the 'real' plot area
+ * @var LineStyle
+ * @access private
+ */
+ var $_plotBorderStyle = null;
+
+ /**
+ * Does any plot have any data?
+ * @var bool
+ * @access private
+ */
+ var $_hasData = false;
+
+ /**
+ * Is the plotarea horizontal?
+ * @var bool
+ * @access private
+ */
+ var $_horizontal = false;
+
+ /**
+ * Image_Graph_Plotarea [Constructor]
+ *
+ * @param string $axisX The class of the X axis (if omitted a std. axis is created)
+ * @param string $axisY The class of the Y axis (if omitted a std. axis is created)
+ * @param string $direction The direction of the plotarea - 'horizontal' or 'vertical' (default)
+ *
+ * @return void
+ */
+ function Image_Graph_Plotarea($axisX = 'Image_Graph_Axis_Category', $axisY = 'Image_Graph_Axis', $direction = 'vertical')
+ {
+ parent::__construct();
+
+ $this->_padding = array('left' => 5, 'top' => 5, 'right' => 5, 'bottom' => 5);;
+
+ include_once 'Image/Graph.php';
+
+ $this->_axisX =& Image_Graph::factory($axisX, IMAGE_GRAPH_AXIS_X);
+ $this->_axisX->_setParent($this);
+
+ $this->_axisY =& Image_Graph::factory($axisY, IMAGE_GRAPH_AXIS_Y);
+ $this->_axisY->_setParent($this);
+ $this->_axisY->_setMinimum(0);
+
+ $this->_fillStyle = false;
+
+ if ($direction == 'horizontal') {
+ $this->_horizontal = true;
+ $this->_axisX->_transpose = true;
+ $this->_axisY->_transpose = true;
+ }
+ }
+
+ /**
+ * Sets the parent. The parent chain should ultimately be a GraPHP object
+ *
+ * @param Image_Graph_Common &$parent The parent
+ *
+ * @return void
+ * @see Image_Graph_Common
+ * @access private
+ */
+ function _setParent(& $parent)
+ {
+ parent::_setParent($parent);
+ if ($this->_axisX !== null) {
+ $this->_axisX->_setParent($this);
+ }
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setParent($this);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setParent($this);
+ }
+ }
+
+ /**
+ * Sets the plot border line style of the element.
+ *
+ * @param Image_Graph_Line &$plotBorderStyle The plot border line style
+ *
+ * @return void
+ * @deprecated 0.3.0dev2 - 2004-12-16
+ */
+ function setPlotBorderStyle(& $plotBorderStyle)
+ {
+ }
+
+ /**
+ * Adds an element to the plotarea
+ *
+ * @param Image_Graph_Element &$element The element to add
+ * @param int $axis The axis to associate the element with,
+ * either IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y, IMAGE_GRAPH_AXIS_Y_SECONDARY
+ * or the shorter string notations 'x', 'y' or 'ysec' (defaults to
+ * IMAGE_GRAPH_AXIS_Y)
+ *
+ * @return Image_Graph_Element The added element
+ * @see Image_Graph_Common::add()
+ */
+ function &add(& $element, $axis = IMAGE_GRAPH_AXIS_Y)
+ {
+ if ($axis == 'x') {
+ $axis = IMAGE_GRAPH_AXIS_X;
+ }
+ if ($axis == 'y') {
+ $axis = IMAGE_GRAPH_AXIS_Y;
+ }
+ if ($axis == 'ysec') {
+ $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;
+ }
+ if (($axis == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ && ($this->_axisYSecondary == null)
+ ) {
+ $this->_axisYSecondary =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
+ $this->_axisYSecondary->_setMinimum(0);
+ if ($this->_horizontal) {
+ $this->_axisYSecondary->_transpose = true;
+ }
+ }
+
+ parent::add($element);
+
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $element->_setAxisY($axis);
+ // postpone extrema calculation until we calculate coordinates
+ //$this->_setExtrema($element);
+ } elseif (is_a($element, 'Image_Graph_Grid')) {
+ switch ($axis) {
+ case IMAGE_GRAPH_AXIS_X:
+ if ($this->_axisX != null) {
+ $element->_setPrimaryAxis($this->_axisX);
+ if ($this->_axisY != null) {
+ $element->_setSecondaryAxis($this->_axisY);
+ }
+ }
+ break;
+ case IMAGE_GRAPH_AXIS_Y:
+ if ($this->_axisY != null) {
+ $element->_setPrimaryAxis($this->_axisY);
+ if ($this->_axisX != null) {
+ $element->_setSecondaryAxis($this->_axisX);
+ }
+ }
+ break;
+ case IMAGE_GRAPH_AXIS_Y_SECONDARY:
+ if ($this->_axisYSecondary != null) {
+ $element->_setPrimaryAxis($this->_axisYSecondary);
+ if ($this->_axisX != null) {
+ $element->_setSecondaryAxis($this->_axisX);
+ }
+ }
+ break;
+ }
+ } elseif (is_a($element, 'Image_Graph_Axis')) {
+ switch ($element->_type) {
+ case IMAGE_GRAPH_AXIS_X:
+ $this->_axisX =& $element;
+ break;
+
+ case IMAGE_GRAPH_AXIS_Y:
+ $this->_axisY =& $element;
+ break;
+
+ case IMAGE_GRAPH_AXIS_Y_SECONDARY:
+ $this->_axisYSecondary =& $element;
+ break;
+
+ }
+ if ($element->_getMinimum() == $element->_getMaximum()) {
+ $element->_setMinimum(0);
+ $element->_setMaximum(1);
+ }
+ }
+ return $element;
+ }
+
+ /**
+ * Get the width of the 'real' plotarea
+ *
+ * @return int The width of the 'real' plotarea, ie not including space occupied by padding and axis
+ * @access private
+ */
+ function _plotWidth()
+ {
+ return abs($this->_plotRight - $this->_plotLeft);
+ }
+
+ /**
+ * Get the height of the 'real' plotarea
+ *
+ * @return int The height of the 'real' plotarea, ie not including space
+ * occupied by padding and axis
+ * @access private
+ */
+ function _plotHeight()
+ {
+ return abs($this->_plotBottom - $this->_plotTop);
+ }
+
+ /**
+ * Set the extrema of the axis
+ *
+ * @param Image_Graph_Plot &$plot The plot that 'hold' the values
+ *
+ * @return void
+ * @access private
+ */
+ function _setExtrema(& $plot)
+ {
+ if (($this->_axisX != null) && ($this->_axisX->_isNumeric())) {
+ $this->_axisX->_setMinimum($plot->_minimumX());
+ $this->_axisX->_setMaximum($plot->_maximumX());
+ }
+
+ if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ && ($this->_axisYSecondary !== null)
+ && ($this->_axisYSecondary->_isNumeric())
+ ) {
+ $this->_axisYSecondary->_setMinimum($plot->_minimumY());
+ $this->_axisYSecondary->_setMaximum($plot->_maximumY());
+ } elseif (($this->_axisY != null) && ($this->_axisY->_isNumeric())) {
+ $this->_axisY->_setMinimum($plot->_minimumY());
+ $this->_axisY->_setMaximum($plot->_maximumY());
+ }
+
+ $datasets =& $plot->dataset();
+ if (!is_array($datasets)) {
+ $datasets = array($datasets);
+ }
+
+ $keys = array_keys($datasets);
+ foreach ($keys as $key) {
+ $dataset =& $datasets[$key];
+ if ($dataset->count() > 0) {
+ $this->_hasData = true;
+ }
+
+ if (is_a($dataset, 'Image_Graph_Dataset')) {
+ if (($this->_axisX != null) && (!$this->_axisX->_isNumeric())) {
+ $this->_axisX->_applyDataset($dataset);
+ }
+
+ if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ && ($this->_axisYSecondary !== null)
+ && (!$this->_axisYSecondary->_isNumeric())
+ ) {
+ $this->_axisYSecondary->_applyDataset($dataset);
+ } elseif (($this->_axisY != null) && (!$this->_axisY->_isNumeric())) {
+ $this->_axisY->_applyDataset($dataset);
+ }
+ }
+ }
+ unset($keys);
+ }
+
+ /**
+ * Left boundary of the background fill area
+ *
+ * @return int Leftmost position on the canvas
+ * @access private
+ */
+ function _fillLeft()
+ {
+ return $this->_plotLeft;
+ }
+
+ /**
+ * Top boundary of the background fill area
+ *
+ * @return int Topmost position on the canvas
+ * @access private
+ */
+ function _fillTop()
+ {
+ return $this->_plotTop;
+ }
+
+ /**
+ * Right boundary of the background fill area
+ *
+ * @return int Rightmost position on the canvas
+ * @access private
+ */
+ function _fillRight()
+ {
+ return $this->_plotRight;
+ }
+
+ /**
+ * Bottom boundary of the background fill area
+ *
+ * @return int Bottommost position on the canvas
+ * @access private
+ */
+ function _fillBottom()
+ {
+ return $this->_plotBottom;
+ }
+
+ /**
+ * Get the point from the x-axis
+ *
+ * @param array $value The value array
+ * @param int $min The minimum pixel position possible
+ * @param int $max The maximum pixel position possible
+ *
+ * @return int The pixel position from the axis
+ * @access private
+ */
+ function _axisPointX($value, $min, $max)
+ {
+ if (($this->_axisX == null) || (!isset($value['X']))) {
+ return false;
+ }
+
+ if ($value['X'] === '#min#') {
+ return $min;
+ }
+ if ($value['X'] === '#max#') {
+ return $max;
+ }
+
+ return $this->_axisX->_point($value['X']);
+ }
+
+ /**
+ * Get the point from the x-axis
+ *
+ * @param array $value The value array
+ * @param int $min The minimum pixel position possible
+ * @param int $max The maximum pixel position possible
+ *
+ * @return int The pixel position from the axis
+ * @access private
+ */
+ function _axisPointY($value, $min, $max)
+ {
+ if (!isset($value['Y'])) {
+ return false;
+ }
+
+ if (($value['Y'] === '#min_pos#') || ($value['Y'] === '#max_nex#')) {
+ // return the minimum (bottom) position or if negative then zero
+ // or the maxmum (top) position or if positive then zero
+ if ((isset($value['AXIS_Y']))
+ && ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ && ($this->_axisYSecondary !== null)
+ ) {
+ $axisY =& $this->_axisYSecondary;
+ } else {
+ $axisY =& $this->_axisY;
+ }
+ if ($value['Y'] === '#min_pos#') {
+ return $axisY->_point(max(0, $axisY->_getMinimum()));
+ } else {
+ return $axisY->_point(min(0, $axisY->_getMaximum()));
+ }
+ }
+
+ if ($value['Y'] === '#min#') {
+ return $min;
+ }
+ if ($value['Y'] === '#max#') {
+ return $max;
+ }
+
+ if ((isset($value['AXIS_Y']))
+ && ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ ) {
+ if ($this->_axisYSecondary !== null) {
+ return $this->_axisYSecondary->_point($value['Y']);
+ }
+ } else {
+ if ($this->_axisY !== null) {
+ return $this->_axisY->_point($value['Y']);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $value the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($value)
+ {
+ if ($this->_horizontal) {
+ return $this->_axisPointY($value, $this->_plotLeft, $this->_plotRight);
+ } else {
+ return $this->_axisPointX($value, $this->_plotLeft, $this->_plotRight);
+ }
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $value the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($value)
+ {
+ if ($this->_horizontal) {
+ return $this->_axisPointX($value, $this->_plotBottom, $this->_plotTop);
+ } else {
+ return $this->_axisPointY($value, $this->_plotBottom, $this->_plotTop);
+ }
+ }
+
+ /**
+ * Return the minimum value of the specified axis
+ *
+ * @param int $axis The axis to return the minimum value of (see {$link
+ * Image_Graph_Plotarea::getAxis()})
+ *
+ * @return double The minimum value of the axis
+ * @access private
+ */
+ function _getMinimum($axis = IMAGE_GRAPH_AXIS_Y)
+ {
+ $axis =& $this->getAxis($axis);
+ if ($axis !== null) {
+ return $axis->_getMinimum();
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Return the maximum value of the specified axis
+ *
+ * @param int $axis The axis to return the maximum value of(see {$link
+ * Image_Graph_Plotarea::getAxis()})
+ *
+ * @return double The maximum value of the axis
+ * @access private
+ */
+ function _getMaximum($axis = IMAGE_GRAPH_AXIS_Y)
+ {
+ $axis =& $this->getAxis($axis);
+ if ($axis !== null) {
+ return $axis->_getMaximum();
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Return the label distance for the specified axis.
+ *
+ * @param int $axis The axis to return the label distance for
+ *
+ * @return int The distance between 2 adjacent labels
+ * @access private
+ */
+ function _labelDistance($axis)
+ {
+ $axis =& $this->getAxis($axis);
+ if ($axis !== null) {
+ return $axis->_labelDistance();
+ }
+
+ return false;
+ }
+
+ /**
+ * Hides the axis
+ *
+ * @param string $axis Which axis? (x, y, y_sec)
+ *
+ * @return void
+ */
+ function hideAxis($axis = false)
+ {
+ if (((!$axis) || ($axis === $this->_axisX) || ($axis === 'x')) && ($this->_axisX != null)) {
+ $this->_axisX->hide();
+ }
+ if (((!$axis) || ($axis === $this->_axisY) || ($axis === 'y')) && ($this->_axisY != null)) {
+ $this->_axisY->hide();
+ }
+ if (((!$axis) || ($axis === $this->_axisYSecondary) || ($axis === 'y_sec')) && ($this->_axisYSecondary != null)) {
+ $this->_axisYSecondary->hide();
+ }
+ }
+
+ /**
+ * Clears/removes the axis
+ *
+ * @return void
+ */
+ function clearAxis()
+ {
+ $this->_axisX = $this->_axisY = $this->_axisYSecondary = null;
+ }
+
+ /**
+ * Get axis.
+ *
+ * Possible values are IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y,
+ * IMAGE_GRAPH_AXIS_Y_SECONDARY or a short hand notation using
+ * string identifiers: 'x', 'y', 'ysec'
+ *
+ * @param int $axis The axis to return
+ *
+ * @return Image_Graph_Axis The axis
+ */
+ function &getAxis($axis = IMAGE_GRAPH_AXIS_X)
+ {
+ switch ($axis) {
+ case IMAGE_GRAPH_AXIS_X:
+ case 'x':
+ return $this->_axisX;
+
+ case IMAGE_GRAPH_AXIS_Y:
+ case 'y':
+ return $this->_axisY;
+
+ case IMAGE_GRAPH_AXIS_Y_SECONDARY:
+ case 'ysec':
+ return $this->_axisYSecondary;
+
+ }
+ return null;
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ $element =& $this->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ if (((is_a($element, 'Image_Graph_Plot_Bar'))
+ || (is_a($element, 'Image_Graph_Plot_Step'))
+ || (is_a($element, 'Image_Graph_Plot_Dot'))
+ || (is_a($element, 'Image_Graph_Plot_CandleStick'))
+ || (is_a($element, 'Image_Graph_Plot_BoxWhisker'))
+ || (is_a($element, 'Image_Graph_Plot_Impulse')))
+ && ($this->_axisX != null)
+ && (strtolower(get_class($this->_axisX)) != 'image_graph_axis') // do not push plot if x-axis is linear
+ ) {
+ $this->_axisX->_pushValues();
+ }
+ $this->_setExtrema($element);
+ }
+ }
+ unset($keys);
+ }
+
+ $this->_calcEdges();
+
+ $pctWidth = (int) ($this->width() * 0.05);
+ $pctHeight = (int) ($this->height() * 0.05);
+
+ $left = $this->_left + $this->_padding['left'];
+ $top = $this->_top + $this->_padding['top'];
+ $right = $this->_right - $this->_padding['right'];
+ $bottom = $this->_bottom - $this->_padding['bottom'];
+
+ // temporary place holder for axis point calculations
+ $axisPoints['x'] = array($left, $top, $right, $bottom);
+ $axisPoints['y'] = $axisPoints['x'];
+ $axisPoints['y2'] = $axisPoints['x'];
+
+ if ($this->_axisX !== null) {
+ $intersectX = $this->_axisX->_getAxisIntersection();
+ $sizeX = $this->_axisX->_size();
+ $this->_axisX->_setCoords($left, $top, $right, $bottom);
+ $this->_axisX->_updateCoords();
+ }
+
+ if ($this->_axisY !== null) {
+ $intersectY = $this->_axisY->_getAxisIntersection();
+ $sizeY = $this->_axisY->_size();
+ $this->_axisY->_setCoords($left, $top, $right, $bottom);
+ $this->_axisY->_updateCoords();
+ }
+
+ if ($this->_axisYSecondary !== null) {
+ $intersectYsec = $this->_axisYSecondary->_getAxisIntersection();
+ $sizeYsec = $this->_axisYSecondary->_size();
+ $this->_axisYSecondary->_setCoords($left, $top, $right, $bottom);
+ $this->_axisYSecondary->_updateCoords();
+ }
+
+ $axisCoordAdd = array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0);
+
+ if ($this->_axisY != null) {
+ if ($this->_axisX != null) {
+ $pos = $this->_axisX->_intersectPoint($intersectY['value']);
+ } else {
+ $pos = ($this->_horizontal ? $bottom : $left);
+ }
+
+ if ($this->_horizontal) {
+ if (($pos + $sizeY) > $bottom) {
+ $axisCoordAdd['bottom'] = ($pos + $sizeY) - $bottom;
+ // the y-axis position needs to be recalculated!
+ } else {
+ // top & bottom may need to be adjusted when the x-axis has been
+ // calculated!
+ $this->_axisY->_setCoords(
+ $left,
+ $pos,
+ $right,
+ $pos + $sizeY
+ );
+ $this->_axisY->_updateCoords();
+ }
+ } else {
+ if (($pos - $sizeY) < $left) {
+ $axisCoordAdd['left'] = $left - ($pos - $sizeY);
+ // the y-axis position needs to be recalculated!
+ } else {
+ // top & bottom may need to be adjusted when the x-axis has been
+ // calculated!
+ $this->_axisY->_setCoords(
+ $pos - $sizeY,
+ $top,
+ $pos,
+ $bottom
+ );
+ $this->_axisY->_updateCoords();
+ }
+ }
+ }
+
+ if ($this->_axisYSecondary != null) {
+ if ($this->_axisX != null) {
+ $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
+ } else {
+ $pos = ($this->_horizontal ? $top : $right);
+ }
+
+ if ($this->_horizontal) {
+ if (($pos - $sizeYsec) < $top) {
+ $axisCoordAdd['top'] = $top - ($pos - $sizeYsec);
+ // the secondary y-axis position need to be recalculated
+ } else {
+ // top & bottom may need to be adjusted when the x-axis has been
+ // calculated!
+ $this->_axisYSecondary->_setCoords(
+ $left,
+ $pos - $sizeY,
+ $right,
+ $pos
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+ } else {
+ if (($pos + $sizeYsec) > $right) {
+ $axisCoordAdd['right'] = ($pos + $sizeYsec) - $right;
+ // the secondary y-axis position need to be recalculated
+ } else {
+ // top & bottom may need to be adjusted when the x-axis has been
+ // calculated!
+ $this->_axisYSecondary->_setCoords(
+ $pos,
+ $top,
+ $pos + $sizeY,
+ $bottom
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+ }
+ }
+
+ if ($this->_axisX != null) {
+ if (($intersectX['axis'] == IMAGE_GRAPH_AXIS_Y_SECONDARY)
+ && ($this->_axisYSecondary !== null)
+ ) {
+ $axis =& $this->_axisYSecondary;
+ } elseif ($this->_axisY !== null) {
+ $axis =& $this->_axisY;
+ } else {
+ $axis = false;
+ }
+
+ if ($axis !== false) {
+ $pos = $axis->_intersectPoint($intersectX['value']);
+ } else {
+ $pos = ($this->_horizontal ? $left : $bottom);
+ }
+
+ if ($this->_horizontal) {
+ if (($pos - $sizeX) < $left) {
+ $axisCoordAdd['left'] = $left - ($pos - $sizeX);
+ $pos = $left + $sizeX;
+ }
+
+ $this->_axisX->_setCoords(
+ $pos - $sizeX,
+ $top + $axisCoordAdd['top'],
+ $pos,
+ $bottom - $axisCoordAdd['bottom']
+ );
+ $this->_axisX->_updateCoords();
+ } else {
+ if (($pos + $sizeX) > $bottom) {
+ $axisCoordAdd['bottom'] = ($pos + $sizeX) - $bottom;
+ $pos = $bottom - $sizeX;
+ }
+
+ $this->_axisX->_setCoords(
+ $left + $axisCoordAdd['left'],
+ $pos,
+ $right - $axisCoordAdd['right'],
+ $pos + $sizeX
+ );
+ $this->_axisX->_updateCoords();
+ }
+ }
+
+ if ($this->_horizontal) {
+ if (($this->_axisX !== null)
+ && (($axisCoordAdd['top'] != 0)
+ || ($axisCoordAdd['bottom'] != 0))
+ ) {
+ // readjust y-axis for better estimate of position
+ if ($this->_axisY !== null) {
+ $pos = $this->_axisX->_intersectPoint($intersectY['value']);
+ $this->_axisY->_setCoords(
+ false,
+ $pos,
+ false,
+ $pos + $sizeY
+ );
+ $this->_axisY->_updateCoords();
+ }
+
+ if ($this->_axisYSecondary !== null) {
+ $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
+ $this->_axisYSecondary->_setCoords(
+ false,
+ $pos - $sizeYsec,
+ false,
+ $pos
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+ }
+
+ // adjust top and bottom of y-axis
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setCoords(
+ $left + $axisCoordAdd['left'],
+ false,
+ $right - $axisCoordAdd['right'],
+ false
+ );
+ $this->_axisY->_updateCoords();
+ }
+
+ // adjust top and bottom of y-axis
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setCoords(
+ $left + $axisCoordAdd['left'],
+ false,
+ $right - $axisCoordAdd['right'],
+ false
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+
+ if ($this->_axisX !== null) {
+ $this->_plotTop = $this->_axisX->_top;
+ $this->_plotBottom = $this->_axisX->_bottom;
+ } else {
+ $this->_plotTop = $top;
+ $this->_plotBottom = $bottom;
+ }
+
+ if ($this->_axisY !== null) {
+ $this->_plotLeft = $this->_axisY->_left;
+ $this->_plotRight = $this->_axisY->_right;
+ } elseif ($this->_axisYSecondary !== null) {
+ $this->_plotLeft = $this->_axisYSecondary->_left;
+ $this->_plotRight = $this->_axisYSecondary->_right;
+ } else {
+ $this->_plotLeft = $this->_left;
+ $this->_plotRight = $this->_right;
+ }
+ } else {
+ if (($this->_axisX !== null)
+ && (($axisCoordAdd['left'] != 0)
+ || ($axisCoordAdd['right'] != 0))
+ ) {
+ // readjust y-axis for better estimate of position
+ if ($this->_axisY !== null) {
+ $pos = $this->_axisX->_intersectPoint($intersectY['value']);
+ $this->_axisY->_setCoords(
+ $pos - $sizeY,
+ false,
+ $pos,
+ false
+ );
+ $this->_axisY->_updateCoords();
+ }
+
+ if ($this->_axisYSecondary !== null) {
+ $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
+ $this->_axisYSecondary->_setCoords(
+ $pos,
+ false,
+ $pos + $sizeYsec,
+ false
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+ }
+
+ // adjust top and bottom of y-axis
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setCoords(
+ false,
+ $top + $axisCoordAdd['top'],
+ false,
+ $bottom - $axisCoordAdd['bottom']
+ );
+ $this->_axisY->_updateCoords();
+ }
+
+ // adjust top and bottom of y-axis
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setCoords(
+ false,
+ $top + $axisCoordAdd['top'],
+ false,
+ $bottom - $axisCoordAdd['bottom']
+ );
+ $this->_axisYSecondary->_updateCoords();
+ }
+
+ if ($this->_axisX !== null) {
+ $this->_plotLeft = $this->_axisX->_left;
+ $this->_plotRight = $this->_axisX->_right;
+ } else {
+ $this->_plotLeft = $left;
+ $this->_plotRight = $right;
+ }
+
+ if ($this->_axisY !== null) {
+ $this->_plotTop = $this->_axisY->_top;
+ $this->_plotBottom = $this->_axisY->_bottom;
+ } elseif ($this->_axisYSecondary !== null) {
+ $this->_plotTop = $this->_axisYSecondary->_top;
+ $this->_plotBottom = $this->_axisYSecondary->_bottom;
+ } else {
+ $this->_plotTop = $this->_top;
+ $this->_plotBottom = $this->_bottom;
+ }
+ }
+
+ Image_Graph_Element::_updateCoords();
+ /*
+ if ($this->_axisX != null) {
+ $this->_axisX->_updateCoords();
+ }
+ if ($this->_axisY != null) {
+ $this->_axisY->_updateCoords();
+ }
+ if ($this->_axisYSecondary != null) {
+ $this->_axisYSecondary->_updateCoords();
+ }*/
+ }
+
+ /**
+ * Set the axis padding for a specified position.
+ *
+ * The axis padding is padding "inside" the plotarea (i.e. to put some space
+ * between the axis line and the actual plot).
+ *
+ * This can be specified in a number of ways:
+ *
+ * 1) Specify an associated array with 'left', 'top', 'right' and 'bottom'
+ * indices with values for the paddings. Leave out 2nd parameter.
+ *
+ * 2) Specify an overall padding as the first parameter
+ *
+ * 3) Specify the padding and position with position values as mentioned
+ * above
+ *
+ * Normally you'd only consider applying axis padding to a category x-axis.
+ *
+ * @param mixed $value The value/padding
+ * @param mixed $position The "position" of the padding
+ *
+ * @return void
+ */
+ function setAxisPadding($value, $position = false)
+ {
+ if ($position === false) {
+ if (is_array($value)) {
+ if ($this->_horizontal) {
+ if ((isset($value['top'])) && ($this->_axisX !== null)) {
+ $this->_axisX->_setAxisPadding('low', $value['top']);
+ }
+ if ((isset($value['bottom'])) && ($this->_axisX !== null)) {
+ $this->_axisX->_setAxisPadding('high', $value['bottom']);
+ }
+ if ((isset($value['left'])) && ($this->_axisY !== null)) {
+ $this->_axisY->_setAxisPadding('low', $value['left']);
+ }
+ if ((isset($value['right'])) && ($this->_axisY !== null)) {
+ $this->_axisY->_setAxisPadding('high', $value['right']);
+ }
+ if ((isset($value['left'])) && ($this->_axisYSecondary !== null)) {
+ $this->_axisYSecondary->_setAxisPadding('low', $value['left']);
+ }
+ if ((isset($value['right'])) && ($this->_axisYSecondary !== null)) {
+ $this->_axisYSecondary->_setAxisPadding('high', $value['right']);
+ }
+ } else {
+ if ((isset($value['left'])) && ($this->_axisX !== null)) {
+ $this->_axisX->_setAxisPadding('low', $value['left']);
+ }
+ if ((isset($value['right'])) && ($this->_axisX !== null)) {
+ $this->_axisX->_setAxisPadding('high', $value['right']);
+ }
+ if ((isset($value['bottom'])) && ($this->_axisY !== null)) {
+ $this->_axisY->_setAxisPadding('low', $value['bottom']);
+ }
+ if ((isset($value['top'])) && ($this->_axisY !== null)) {
+ $this->_axisY->_setAxisPadding('high', $value['top']);
+ }
+ if ((isset($value['bottom'])) && ($this->_axisYSecondary !== null)) {
+ $this->_axisYSecondary->_setAxisPadding('low', $value['bottom']);
+ }
+ if ((isset($value['top'])) && ($this->_axisYSecondary !== null)) {
+ $this->_axisYSecondary->_setAxisPadding('high', $value['top']);
+ }
+ }
+ } else {
+ if ($this->_axisX !== null) {
+ $this->_axisX->_setAxisPadding('low', $value);
+ $this->_axisX->_setAxisPadding('high', $value);
+ }
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setAxisPadding('low', $value);
+ $this->_axisY->_setAxisPadding('high', $value);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setAxisPadding('low', $value);
+ $this->_axisYSecondary->_setAxisPadding('high', $value);
+ }
+ }
+ } else {
+ switch ($position) {
+ case 'left':
+ if ($this->_horizontal) {
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setAxisPadding('low', $value);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setAxisPadding('low', $value);
+ }
+ } else if ($this->_axisX !== null) {
+ $this->_axisX->_setAxisPadding('low', $value);
+ }
+ break;
+
+ case 'right':
+ if ($this->_horizontal) {
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setAxisPadding('high', $value);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setAxisPadding('high', $value);
+ }
+ } else if ($this->_axisX !== null) {
+ $this->_axisX->_setAxisPadding('high', $value);
+ }
+ break;
+
+ case 'top':
+ if (!$this->_horizontal) {
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setAxisPadding('high', $value);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setAxisPadding('high', $value);
+ }
+ } else if ($this->_axisX !== null) {
+ $this->_axisX->_setAxisPadding('high', $value);
+ }
+ break;
+
+ case 'bottom':
+ if (!$this->_horizontal) {
+ if ($this->_axisY !== null) {
+ $this->_axisY->_setAxisPadding('low', $value);
+ }
+ if ($this->_axisYSecondary !== null) {
+ $this->_axisYSecondary->_setAxisPadding('low', $value);
+ }
+ } else if ($this->_axisX !== null) {
+ $this->_axisX->_setAxisPadding('low', $value);
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Output the plotarea to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if ($this->_hasData) {
+ $this->_canvas->startGroup(get_class($this));
+
+ if ($this->_axisX != null) {
+ $this->add($this->_axisX);
+ }
+ if ($this->_axisY != null) {
+ $this->add($this->_axisY);
+ }
+ if ($this->_axisYSecondary != null) {
+ $this->add($this->_axisYSecondary);
+ }
+
+ $this->_getFillStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $this->_plotLeft,
+ 'y0' => $this->_plotTop,
+ 'x1' => $this->_plotRight,
+ 'y1' => $this->_plotBottom
+ )
+ );
+ $result = parent::_done();
+ $this->_canvas->endGroup();
+ return $result;
+ } else {
+ // no data -> do nothing at all!
+ return true;
+ }
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Element.php,v 1.5 2005/02/21 20:50:01 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Element.php\r
- */\r
-require_once 'Image/Graph/Element.php';\r
-\r
-/**\r
- * Representation of a element on a plotarea.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- * @abstract\r
- */\r
-class Image_Graph_Plotarea_Element extends Image_Graph_Element\r
-{\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double $point the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($point)\r
- {\r
- return $this->_parent->_pointX($point);\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double $point the value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($point)\r
- {\r
- return $this->_parent->_pointY($point);\r
- }\r
-\r
- /**\r
- * Get the X and Y pixel position represented by a value\r
- *\r
- * @param array $point the values to get the pixel-point for\r
- * @return array The (x, y) pixel position along the axis\r
- * @access private\r
- */\r
- function _pointXY($point)\r
- {\r
- return array ('X' => $this->_pointX($point), 'Y' => $this->_pointY($point));\r
- }\r
-\r
-}\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Element.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Element.php
+ */
+require_once 'Image/Graph/Element.php';
+
+/**
+ * Representation of a element on a plotarea.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ * @abstract
+ */
+class Image_Graph_Plotarea_Element extends Image_Graph_Element
+{
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $point the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($point)
+ {
+ return $this->_parent->_pointX($point);
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $point the value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($point)
+ {
+ return $this->_parent->_pointY($point);
+ }
+
+ /**
+ * Get the X and Y pixel position represented by a value
+ *
+ * @param array $point the values to get the pixel-point for
+ *
+ * @return array The (x, y) pixel position along the axis
+ * @access private
+ */
+ function _pointXY($point)
+ {
+ return array ('X' => $this->_pointX($point), 'Y' => $this->_pointY($point));
+ }
+
+}
?>
\ No newline at end of file
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Map.php,v 1.10 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plotarea.php\r
- */\r
-require_once 'Image/Graph/Plotarea.php';\r
-\r
-/**\r
- * Plot area used for map plots.\r
- *\r
- * A map plot is a chart that displays a map (fx. a world map) in the form of .\r
- * png file. The maps must be located in the /Images/Maps folder and a\r
- * corresponding .txt files mush also exist in this location where named\r
- * locations are mapped to an (x, y) coordinate of the map picture (this text\r
- * file is tab separated with 'Name' 'X' 'Y' values, fx 'Denmark 378 223'). The\r
- * x-values in the dataset are then the named locations (fx 'Denmark') and the\r
- * y-values are then the data to plot. Currently the best (if not only) use is\r
- * to combine a map plot area with a {@link Image_Graph_Plot_Dot} using {@link\r
- * Image_Graph_Marker_PercentageCircle} as marker.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plotarea_Map extends Image_Graph_Plotarea\r
-{\r
-\r
- /**\r
- * The GD image for the map\r
- * @var string\r
- * @access private\r
- */\r
- var $_imageMap;\r
-\r
- /**\r
- * The value for scaling the width and height to fit into the layout boundaries\r
- * @var int\r
- * @access private\r
- */\r
- var $_scale;\r
-\r
- /**\r
- * The (x,y)-points for the named point\r
- * @var array\r
- * @access private\r
- */\r
- var $_mapPoints;\r
-\r
- /**\r
- * The original size of the image map\r
- * @var array\r
- * @access private\r
- */\r
- var $_mapSize;\r
-\r
- /**\r
- * PlotareaMap [Constructor]\r
- *\r
- * @param string $map The name of the map, i.e. the [name].png and [name].\r
- * txt files located in the Images/maps folder\r
- */\r
- function Image_Graph_Plotarea_Map($map)\r
- {\r
- parent::Image_Graph_Plotarea();\r
-\r
- $this->_imageMap = dirname(__FILE__)."/../Images/Maps/$map.png";\r
- $points = file(dirname(__FILE__)."/../Images/Maps/$map.txt");\r
- list($width, $height) = getimagesize($this->_imageMap);\r
- $this->_mapSize['X'] = $width;\r
- $this->_mapSize['Y'] = $height;\r
-\r
- if (is_array($points)) {\r
- unset($this->_mapPoints);\r
- foreach ($points as $line) {\r
- list($country, $x, $y) = explode("\t", $line);\r
- $this->_mapPoints[$country] = array('X' => $x, 'Y' => $y);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Left boundary of the background fill area\r
- *\r
- * @return int Leftmost position on the canvas\r
- * @access private\r
- */\r
- function _fillLeft()\r
- {\r
- return $this->_left + $this->_padding['left'];\r
- }\r
-\r
- /**\r
- * Top boundary of the background fill area\r
- *\r
- * @return int Topmost position on the canvas\r
- * @access private\r
- */\r
- function _fillTop()\r
- {\r
- return $this->_top + $this->_padding['top'];\r
- }\r
-\r
- /**\r
- * Right boundary of the background fill area\r
- *\r
- * @return int Rightmost position on the canvas\r
- * @access private\r
- */\r
- function _fillRight()\r
- {\r
- return $this->_right - $this->_padding['right'];\r
- }\r
-\r
- /**\r
- * Bottom boundary of the background fill area\r
- *\r
- * @return int Bottommost position on the canvas\r
- * @access private\r
- */\r
- function _fillBottom()\r
- {\r
- return $this->_bottom - $this->_padding['bottom'];\r
- }\r
-\r
- /**\r
- * Set the extrema of the axis\r
- *\r
- * @param Image_Graph_Plot $plot The plot that 'hold' the values\r
- * @access private\r
- */\r
- function _setExtrema(& $plot)\r
- {\r
- }\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double $value The value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($value)\r
- {\r
- $country = $value['X'];\r
- return $this->_plotLeft+$this->_mapPoints[$country]['X']*$this->_scale;\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double $value The value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($value)\r
- {\r
- $country = $value['X'];\r
- return $this->_plotTop+$this->_mapPoints[$country]['Y']*$this->_scale;\r
- }\r
-\r
- /**\r
- * Hides the axis\r
- */\r
- function hideAxis()\r
- {\r
- }\r
-\r
- /**\r
- * Add a point to the maps\r
- *\r
- * @param int $latitude The latitude of the point\r
- * @param int $longiude The longitude of the point\r
- * @param string $name The name of the plot\r
- */\r
- function addMappoint($latitude, $longitude, $name)\r
- {\r
- $x = (($longitude + 180) * ($this->_mapSize['X'] / 360));\r
- $y = ((($latitude * -1) + 90) * ($this->_mapSize['Y'] / 180));\r
- $this->_mapPoints[$name] = array('X' => $x, 'Y' => $y);\r
- }\r
-\r
- /**\r
- * Add a point to the maps\r
- *\r
- * @param int $x The latitude of the point\r
- * @param int $y The longitude of the point\r
- * @param string $name The name of the plot\r
- */\r
- function addPoint($x, $y, $name)\r
- {\r
- $this->_mapPoints[$name] = array('X' => $x, 'Y' => $y);\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- parent::_updateCoords();\r
-\r
- $mapAspectRatio = $this->_mapSize['X']/$this->_mapSize['Y'];\r
- $plotAspectRatio = ($width = $this->_fillWidth())/($height = $this->_fillHeight());\r
-\r
- $scaleFactorX = ($mapAspectRatio > $plotAspectRatio);\r
-\r
- if ((($this->_mapSize['X'] <= $width) && ($this->_mapSize['Y'] <= $height)) ||\r
- (($this->_mapSize['X'] >= $width) && ($this->_mapSize['Y'] >= $height)))\r
- {\r
- if ($scaleFactorX) {\r
- $this->_scale = $width / $this->_mapSize['X'];\r
- } else {\r
- $this->_scale = $height / $this->_mapSize['Y'];\r
- }\r
- } elseif ($this->_mapSize['X'] < $width) {\r
- $this->_scale = $height / $this->_mapSize['Y'];\r
- } elseif ($this->_mapSize['Y'] < $height) {\r
- $this->_scale = $width / $this->_mapSize['X'];\r
- }\r
-\r
- $this->_plotLeft = ($this->_fillLeft() + $this->_fillRight() -\r
- $this->_mapSize['X']*$this->_scale)/2;\r
-\r
- $this->_plotTop = ($this->_fillTop() + $this->_fillBottom() -\r
- $this->_mapSize['Y']*$this->_scale)/2;\r
-\r
- $this->_plotRight = ($this->_fillLeft() + $this->_fillRight() +\r
- $this->_mapSize['X']*$this->_scale)/2;\r
-\r
- $this->_plotBottom = ($this->_fillTop() + $this->_fillBottom() +\r
- $this->_mapSize['Y']*$this->_scale)/2;\r
- }\r
-\r
- /**\r
- * Output the plotarea to the canvas\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- $this->_getFillStyle();\r
- $this->_canvas->rectangle(\r
- array(\r
- 'x0' => $this->_fillLeft(),\r
- 'y0' => $this->_fillTop(),\r
- 'x1' => $this->_fillRight(),\r
- 'y1' => $this->_fillBottom()\r
- )\r
- );\r
-\r
- $scaledWidth = $this->_mapSize['X']*$this->_scale;\r
- $scaledHeight = $this->_mapSize['Y']*$this->_scale;\r
-\r
- $this->_canvas->image(\r
- array(\r
- 'x' => $this->_plotLeft,\r
- 'y' => $this->_plotTop,\r
- 'filename' => $this->_imageMap,\r
- 'width' => $scaledWidth,\r
- 'height' => $scaledHeight\r
- )\r
- );\r
-\r
- return Image_Graph_Layout::_done();\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Map.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea.php
+ */
+require_once 'Image/Graph/Plotarea.php';
+
+/**
+ * Plot area used for map plots.
+ *
+ * A map plot is a chart that displays a map (fx. a world map) in the form of .
+ * png file. The maps must be located in the /Images/Maps folder and a
+ * corresponding .txt files mush also exist in this location where named
+ * locations are mapped to an (x, y) coordinate of the map picture (this text
+ * file is tab separated with 'Name' 'X' 'Y' values, fx 'Denmark 378 223'). The
+ * x-values in the dataset are then the named locations (fx 'Denmark') and the
+ * y-values are then the data to plot. Currently the best (if not only) use is
+ * to combine a map plot area with a {@link Image_Graph_Plot_Dot} using {@link
+ * Image_Graph_Marker_PercentageCircle} as marker.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plotarea_Map extends Image_Graph_Plotarea
+{
+
+ /**
+ * The GD image for the map
+ * @var string
+ * @access private
+ */
+ var $_imageMap;
+
+ /**
+ * The value for scaling the width and height to fit into the layout boundaries
+ * @var int
+ * @access private
+ */
+ var $_scale;
+
+ /**
+ * The (x,y)-points for the named point
+ * @var array
+ * @access private
+ */
+ var $_mapPoints;
+
+ /**
+ * The original size of the image map
+ * @var array
+ * @access private
+ */
+ var $_mapSize;
+
+ /**
+ * PlotareaMap [Constructor]
+ *
+ * @param string $map The name of the map, i.e. the [name].png and [name].
+ * txt files located in the Images/maps folder
+ */
+ function Image_Graph_Plotarea_Map($map)
+ {
+ parent::__construct();
+
+ $this->_imageMap = dirname(__FILE__)."/../Images/Maps/$map.png";
+ $points = file(dirname(__FILE__)."/../Images/Maps/$map.txt");
+ list($width, $height) = getimagesize($this->_imageMap);
+ $this->_mapSize['X'] = $width;
+ $this->_mapSize['Y'] = $height;
+
+ if (is_array($points)) {
+ unset($this->_mapPoints);
+ foreach ($points as $line) {
+ list($country, $x, $y) = explode("\t", $line);
+ $this->_mapPoints[$country] = array('X' => $x, 'Y' => $y);
+ }
+ }
+ }
+
+ /**
+ * Left boundary of the background fill area
+ *
+ * @return int Leftmost position on the canvas
+ * @access private
+ */
+ function _fillLeft()
+ {
+ return $this->_left + $this->_padding['left'];
+ }
+
+ /**
+ * Top boundary of the background fill area
+ *
+ * @return int Topmost position on the canvas
+ * @access private
+ */
+ function _fillTop()
+ {
+ return $this->_top + $this->_padding['top'];
+ }
+
+ /**
+ * Right boundary of the background fill area
+ *
+ * @return int Rightmost position on the canvas
+ * @access private
+ */
+ function _fillRight()
+ {
+ return $this->_right - $this->_padding['right'];
+ }
+
+ /**
+ * Bottom boundary of the background fill area
+ *
+ * @return int Bottommost position on the canvas
+ * @access private
+ */
+ function _fillBottom()
+ {
+ return $this->_bottom - $this->_padding['bottom'];
+ }
+
+ /**
+ * Set the extrema of the axis
+ *
+ * @param Image_Graph_Plot &$plot The plot that 'hold' the values
+ *
+ * @return void
+ * @access private
+ */
+ function _setExtrema(& $plot)
+ {
+ }
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $value The value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($value)
+ {
+ $country = $value['X'];
+ return $this->_plotLeft+$this->_mapPoints[$country]['X']*$this->_scale;
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $value The value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($value)
+ {
+ $country = $value['X'];
+ return $this->_plotTop+$this->_mapPoints[$country]['Y']*$this->_scale;
+ }
+
+ /**
+ * Hides the axis
+ *
+ * @return void
+ */
+ function hideAxis()
+ {
+ }
+
+ /**
+ * Add a point to the maps
+ *
+ * @param int $latitude The latitude of the point
+ * @param int $longitude The longitude of the point
+ * @param string $name The name of the plot
+ *
+ * @return void
+ */
+ function addMappoint($latitude, $longitude, $name)
+ {
+ $x = (($longitude + 180) * ($this->_mapSize['X'] / 360));
+ $y = ((($latitude * -1) + 90) * ($this->_mapSize['Y'] / 180));
+ $this->_mapPoints[$name] = array('X' => $x, 'Y' => $y);
+ }
+
+ /**
+ * Add a point to the maps
+ *
+ * @param int $x The latitude of the point
+ * @param int $y The longitude of the point
+ * @param string $name The name of the plot
+ *
+ * @return void
+ */
+ function addPoint($x, $y, $name)
+ {
+ $this->_mapPoints[$name] = array('X' => $x, 'Y' => $y);
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ parent::_updateCoords();
+
+ $mapAspectRatio = $this->_mapSize['X']/$this->_mapSize['Y'];
+ $plotAspectRatio = ($width = $this->_fillWidth())/($height = $this->_fillHeight());
+
+ $scaleFactorX = ($mapAspectRatio > $plotAspectRatio);
+
+ if ((($this->_mapSize['X'] <= $width) && ($this->_mapSize['Y'] <= $height))
+ || (($this->_mapSize['X'] >= $width) && ($this->_mapSize['Y'] >= $height))
+ ) {
+ if ($scaleFactorX) {
+ $this->_scale = $width / $this->_mapSize['X'];
+ } else {
+ $this->_scale = $height / $this->_mapSize['Y'];
+ }
+ } elseif ($this->_mapSize['X'] < $width) {
+ $this->_scale = $height / $this->_mapSize['Y'];
+ } elseif ($this->_mapSize['Y'] < $height) {
+ $this->_scale = $width / $this->_mapSize['X'];
+ }
+
+ $this->_plotLeft = ($this->_fillLeft() + $this->_fillRight() -
+ $this->_mapSize['X']*$this->_scale)/2;
+
+ $this->_plotTop = ($this->_fillTop() + $this->_fillBottom() -
+ $this->_mapSize['Y']*$this->_scale)/2;
+
+ $this->_plotRight = ($this->_fillLeft() + $this->_fillRight() +
+ $this->_mapSize['X']*$this->_scale)/2;
+
+ $this->_plotBottom = ($this->_fillTop() + $this->_fillBottom() +
+ $this->_mapSize['Y']*$this->_scale)/2;
+ }
+
+ /**
+ * Output the plotarea to the canvas
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ $this->_getFillStyle();
+ $this->_canvas->rectangle(
+ array(
+ 'x0' => $this->_fillLeft(),
+ 'y0' => $this->_fillTop(),
+ 'x1' => $this->_fillRight(),
+ 'y1' => $this->_fillBottom()
+ )
+ );
+
+ $scaledWidth = $this->_mapSize['X']*$this->_scale;
+ $scaledHeight = $this->_mapSize['Y']*$this->_scale;
+
+ $this->_canvas->image(
+ array(
+ 'x' => $this->_plotLeft,
+ 'y' => $this->_plotTop,
+ 'filename' => $this->_imageMap,
+ 'width' => $scaledWidth,
+ 'height' => $scaledHeight
+ )
+ );
+
+ return Image_Graph_Layout::_done();
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - PEAR PHP OO Graph Rendering Utility.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Radar.php,v 1.8 2006/02/28 22:48:07 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Plotarea.php\r
- */\r
-require_once 'Image/Graph/Plotarea.php';\r
-\r
-/**\r
- * Plot area used for radar plots.\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Plotarea\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Plotarea_Radar extends Image_Graph_Plotarea\r
-{\r
-\r
- /**\r
- * Create the plotarea, implicitely creates 2 normal axis\r
- */\r
- function Image_Graph_Plotarea_Radar()\r
- {\r
- parent::Image_Graph_Element();\r
- $this->_padding = array('left' => 10, 'top' => 10, 'right' => 10, 'bottom' => 10);\r
- $this->_axisX =& Image_Graph::factory('Image_Graph_Axis_Radar');\r
- $this->_axisX->_setParent($this);\r
- $this->_axisY =& Image_Graph::factory('Image_Graph_Axis', IMAGE_GRAPH_AXIS_Y);\r
- $this->_axisY->_setParent($this);\r
- $this->_axisY->_setMinimum(0);\r
- }\r
-\r
- /**\r
- * Get the width of the 'real' plotarea\r
- *\r
- * @return int The width of the 'real' plotarea, ie not including space occupied by padding and axis\r
- * @access private\r
- */\r
- function _plotWidth()\r
- {\r
- return (min($this->height(), $this->width())) * 0.80;\r
- }\r
-\r
- /**\r
- * Get the height of the 'real' plotarea\r
- *\r
- * @return int The height of the 'real' plotarea, ie not including space occupied by padding and axis\r
- * @access private\r
- */\r
- function _plotHeight()\r
- {\r
- return (min($this->height(), $this->width())) * 0.80;\r
- }\r
-\r
- /**\r
- * Left boundary of the background fill area\r
- *\r
- * @return int Leftmost position on the canvas\r
- * @access private\r
- */\r
- function _fillLeft()\r
- {\r
- return (int) (($this->_left + $this->_right - $this->_plotWidth()) / 2);\r
- }\r
-\r
- /**\r
- * Top boundary of the background fill area\r
- *\r
- * @return int Topmost position on the canvas\r
- * @access private\r
- */\r
- function _fillTop()\r
- {\r
- return (int) (($this->_top + $this->_bottom - $this->_plotHeight()) / 2);\r
- }\r
-\r
- /**\r
- * Right boundary of the background fill area\r
- *\r
- * @return int Rightmost position on the canvas\r
- * @access private\r
- */\r
- function _fillRight()\r
- {\r
- return (int) (($this->_left + $this->_right + $this->_plotWidth()) / 2);\r
- }\r
-\r
- /**\r
- * Bottom boundary of the background fill area\r
- *\r
- * @return int Bottommost position on the canvas\r
- * @access private\r
- */\r
- function _fillBottom()\r
- {\r
- return (int) (($this->_top + $this->_bottom + $this->_plotHeight()) / 2);\r
- }\r
-\r
- /**\r
- * Get the X pixel position represented by a value\r
- *\r
- * @param double $value The value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointX($value)\r
- {\r
- if (is_array($value)) {\r
- if ($value['Y'] == '#min#') {\r
- $radius = 0;\r
- } elseif (($value['Y'] == '#max#') || ($value['Y'] === false)) {\r
- $radius = 1;\r
- } else {\r
- $radius = ($value['Y'] - $this->_axisY->_getMinimum()) /\r
- ($this->_axisY->_getMaximum() - $this->_axisY->_getMinimum());\r
- }\r
- $x = ($this->_left + $this->_right) / 2 -\r
- $radius * ($this->_plotWidth() / 2) *\r
- cos(deg2rad($this->_axisX->_point($value['X'])));\r
- }\r
- return max($this->_plotLeft, min($this->_plotRight, $x));\r
- }\r
-\r
- /**\r
- * Get the Y pixel position represented by a value\r
- *\r
- * @param double $value The value to get the pixel-point for\r
- * @return double The pixel position along the axis\r
- * @access private\r
- */\r
- function _pointY($value)\r
- {\r
- if (is_array($value)) {\r
- if ($value['Y'] == '#min#') {\r
- $radius = 0;\r
- } elseif (($value['Y'] == '#max#') || ($value['Y'] === false)) {\r
- $radius = 1;\r
- } else {\r
- $radius = ($value['Y'] - $this->_axisY->_getMinimum()) /\r
- ($this->_axisY->_getMaximum() - $this->_axisY->_getMinimum());\r
- }\r
-\r
- $y = ($this->_top + $this->_bottom) / 2 -\r
- $radius * ($this->_plotHeight() / 2) *\r
- sin(deg2rad($this->_axisX->_point($value['X'])));\r
- }\r
- return max($this->_plotTop, min($this->_plotBottom, $y));\r
- }\r
-\r
- /**\r
- * Update coordinates\r
- *\r
- * @access private\r
- */\r
- function _updateCoords()\r
- {\r
- if (is_array($this->_elements)) {\r
- $keys = array_keys($this->_elements);\r
- foreach ($keys as $key) {\r
- $element =& $this->_elements[$key];\r
- if (is_a($element, 'Image_Graph_Plot')) {\r
- $this->_setExtrema($element);\r
- }\r
- }\r
- unset($keys);\r
- }\r
-\r
- $this->_calcEdges();\r
-\r
- $centerX = (int) (($this->_left + $this->_right) / 2);\r
- $centerY = (int) (($this->_top + $this->_bottom) / 2);\r
- $radius = min($this->_plotHeight(), $this->_plotWidth()) / 2;\r
-\r
- if (is_object($this->_axisX)) {\r
- $this->_axisX->_setCoords(\r
- $centerX - $radius,\r
- $centerY - $radius,\r
- $centerX + $radius,\r
- $centerY + $radius\r
- );\r
- }\r
-\r
- if (is_object($this->_axisY)) {\r
- $this->_axisY->_setCoords(\r
- $centerX,\r
- $centerY,\r
- $centerX - $radius,\r
- $centerY - $radius\r
- );\r
- }\r
-\r
- $this->_plotLeft = $this->_fillLeft();\r
- $this->_plotTop = $this->_fillTop();\r
- $this->_plotRight = $this->_fillRight();\r
- $this->_plotBottom = $this->_fillBottom();\r
-\r
- Image_Graph_Element::_updateCoords();\r
- \r
- if (is_object($this->_axisX)) {\r
- $this->_axisX->_updateCoords();\r
- }\r
-\r
- if (is_object($this->_axisY)) {\r
- $this->_axisY->_updateCoords();\r
- }\r
- \r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - PEAR PHP OO Graph Rendering Utility.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Radar.php 291406 2009-11-29 00:54:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Plotarea.php
+ */
+require_once 'Image/Graph/Plotarea.php';
+
+/**
+ * Plot area used for radar plots.
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Plotarea
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Plotarea_Radar extends Image_Graph_Plotarea
+{
+
+ /**
+ * Create the plotarea, implicitely creates 2 normal axis
+ */
+ function Image_Graph_Plotarea_Radar()
+ {
+ parent::__construct();
+ $this->_padding = array('left' => 10, 'top' => 10, 'right' => 10, 'bottom' => 10);
+ $this->_axisX =& Image_Graph::factory('Image_Graph_Axis_Radar');
+ $this->_axisX->_setParent($this);
+ $this->_axisY =& Image_Graph::factory('Image_Graph_Axis', IMAGE_GRAPH_AXIS_Y);
+ $this->_axisY->_setParent($this);
+ $this->_axisY->_setMinimum(0);
+ }
+
+ /**
+ * Get the width of the 'real' plotarea
+ *
+ * @return int The width of the 'real' plotarea, ie not including space occupied by padding and axis
+ * @access private
+ */
+ function _plotWidth()
+ {
+ return (min($this->height(), $this->width())) * 0.80;
+ }
+
+ /**
+ * Get the height of the 'real' plotarea
+ *
+ * @return int The height of the 'real' plotarea, ie not including space occupied by padding and axis
+ * @access private
+ */
+ function _plotHeight()
+ {
+ return (min($this->height(), $this->width())) * 0.80;
+ }
+
+ /**
+ * Left boundary of the background fill area
+ *
+ * @return int Leftmost position on the canvas
+ * @access private
+ */
+ function _fillLeft()
+ {
+ return (int) (($this->_left + $this->_right - $this->_plotWidth()) / 2);
+ }
+
+ /**
+ * Top boundary of the background fill area
+ *
+ * @return int Topmost position on the canvas
+ * @access private
+ */
+ function _fillTop()
+ {
+ return (int) (($this->_top + $this->_bottom - $this->_plotHeight()) / 2);
+ }
+
+ /**
+ * Right boundary of the background fill area
+ *
+ * @return int Rightmost position on the canvas
+ * @access private
+ */
+ function _fillRight()
+ {
+ return (int) (($this->_left + $this->_right + $this->_plotWidth()) / 2);
+ }
+
+ /**
+ * Bottom boundary of the background fill area
+ *
+ * @return int Bottommost position on the canvas
+ * @access private
+ */
+ function _fillBottom()
+ {
+ return (int) (($this->_top + $this->_bottom + $this->_plotHeight()) / 2);
+ }
+
+ /**
+ * Get the X pixel position represented by a value
+ *
+ * @param double $value The value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointX($value)
+ {
+ if (is_array($value)) {
+ if ($value['Y'] == '#min#') {
+ $radius = 0;
+ } elseif (($value['Y'] == '#max#') || ($value['Y'] === false)) {
+ $radius = 1;
+ } else {
+ $radius = ($value['Y'] - $this->_axisY->_getMinimum()) /
+ ($this->_axisY->_getMaximum() - $this->_axisY->_getMinimum());
+ }
+ $x = ($this->_left + $this->_right) / 2 -
+ $radius * ($this->_plotWidth() / 2) *
+ cos(deg2rad($this->_axisX->_point($value['X'])));
+ }
+ return max($this->_plotLeft, min($this->_plotRight, $x));
+ }
+
+ /**
+ * Get the Y pixel position represented by a value
+ *
+ * @param double $value The value to get the pixel-point for
+ *
+ * @return double The pixel position along the axis
+ * @access private
+ */
+ function _pointY($value)
+ {
+ if (is_array($value)) {
+ if ($value['Y'] == '#min#') {
+ $radius = 0;
+ } elseif (($value['Y'] == '#max#') || ($value['Y'] === false)) {
+ $radius = 1;
+ } else {
+ $radius = ($value['Y'] - $this->_axisY->_getMinimum()) /
+ ($this->_axisY->_getMaximum() - $this->_axisY->_getMinimum());
+ }
+
+ $y = ($this->_top + $this->_bottom) / 2 -
+ $radius * ($this->_plotHeight() / 2) *
+ sin(deg2rad($this->_axisX->_point($value['X'])));
+ }
+ return max($this->_plotTop, min($this->_plotBottom, $y));
+ }
+
+ /**
+ * Update coordinates
+ *
+ * @return void
+ * @access private
+ */
+ function _updateCoords()
+ {
+ if (is_array($this->_elements)) {
+ $keys = array_keys($this->_elements);
+ foreach ($keys as $key) {
+ $element =& $this->_elements[$key];
+ if (is_a($element, 'Image_Graph_Plot')) {
+ $this->_setExtrema($element);
+ }
+ }
+ unset($keys);
+ }
+
+ $this->_calcEdges();
+
+ $centerX = (int) (($this->_left + $this->_right) / 2);
+ $centerY = (int) (($this->_top + $this->_bottom) / 2);
+ $radius = min($this->_plotHeight(), $this->_plotWidth()) / 2;
+
+ if (is_object($this->_axisX)) {
+ $this->_axisX->_setCoords(
+ $centerX - $radius,
+ $centerY - $radius,
+ $centerX + $radius,
+ $centerY + $radius
+ );
+ }
+
+ if (is_object($this->_axisY)) {
+ $this->_axisY->_setCoords(
+ $centerX,
+ $centerY,
+ $centerX - $radius,
+ $centerY - $radius
+ );
+ }
+
+ $this->_plotLeft = $this->_fillLeft();
+ $this->_plotTop = $this->_fillTop();
+ $this->_plotRight = $this->_fillRight();
+ $this->_plotBottom = $this->_fillBottom();
+
+ Image_Graph_Element::_updateCoords();
+
+ if (is_object($this->_axisX)) {
+ $this->_axisX->_updateCoords();
+ }
+
+ if (is_object($this->_axisY)) {
+ $this->_axisY->_updateCoords();
+ }
+
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Simple.php,v 1.8 2005/08/24 20:35:54 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph.php\r
- */\r
-require_once 'Image/Graph.php';\r
-\r
-/**\r
- * Class for simple creation of graphs\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Simple extends Image_Graph\r
-{\r
-\r
- /**\r
- * Image_Graph_Simple [Constructor]\r
- *\r
- * @param int $width The width of the graph in pixels\r
- * @param int $height The height of the graph in pixels\r
- */\r
- function Image_Graph_Simple($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)\r
- {\r
- parent::Image_Graph($width, $height);\r
-\r
- $plotarea =& Image_Graph::factory('plotarea');\r
-\r
- $dataset =& Image_Graph::factory('dataset', array($data));\r
-\r
- if ($font === false) {\r
- $font =& Image_Graph::factory('Image_Graph_Font');\r
- } elseif (is_string($font)) {\r
- $font =& Image_Graph::factory('ttf_font', $font);\r
- $font->setSize(8);\r
- }\r
-\r
- $this->setFont($font);\r
-\r
- $this->add(\r
- Image_Graph::vertical(\r
- Image_Graph::factory('title',\r
- array(\r
- $title,\r
- array('size_rel' => 2)\r
- )\r
- ),\r
- $plotarea,\r
- 10\r
- )\r
- );\r
-\r
- $plotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);\r
-\r
- $plot =& $plotarea->addNew($plotType, array(&$dataset));\r
- $plot->setLineColor($lineColor);\r
- $plot->setFillColor($fillColor);\r
-\r
- $axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);\r
- $axisX->showLabel(\r
- IMAGE_GRAPH_LABEL_MINIMUM +\r
- IMAGE_GRAPH_LABEL_ZERO +\r
- IMAGE_GRAPH_LABEL_MAXIMUM\r
- );\r
-\r
- }\r
-\r
- /**\r
- * Factory method to create the Image_Simple_Graph object.\r
- */\r
- function &factory($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)\r
- {\r
- $obj =& Image_Graph::factory('Image_Graph_Simple',\r
- array(\r
- $width,\r
- $height,\r
- $plotType,\r
- $data,\r
- $title,\r
- $lineColor,\r
- $fillColor,\r
- $font\r
- )\r
- );\r
- return $obj;\r
- }\r
-\r
-}\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Simple.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph.php
+ */
+require_once 'Image/Graph.php';
+
+/**
+ * Class for simple creation of graphs
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Simple extends Image_Graph
+{
+
+ /**
+ * Image_Graph_Simple [Constructor]
+ *
+ * @param int $width The width of the graph in pixels
+ * @param int $height The height of the graph in pixels
+ * @param ??? $plotType ???
+ * @param ??? $data ???
+ * @param string $title The title
+ * @param string $lineColor Color for lines
+ * @param string $fillColor Color for fills
+ * @param ??? $font ???
+ */
+ function Image_Graph_Simple($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)
+ {
+ parent::__construct($width, $height);
+
+ $plotarea =& Image_Graph::factory('plotarea');
+
+ $dataset =& Image_Graph::factory('dataset', array($data));
+
+ if ($font === false) {
+ $font =& Image_Graph::factory('Image_Graph_Font');
+ } elseif (is_string($font)) {
+ $font =& Image_Graph::factory('ttf_font', $font);
+ $font->setSize(8);
+ }
+
+ $this->setFont($font);
+
+ $this->add(
+ Image_Graph::vertical(
+ Image_Graph::factory(
+ 'title',
+ array(
+ $title,
+ array('size_rel' => 2)
+ )
+ ),
+ $plotarea,
+ 10
+ )
+ );
+
+ $plotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
+
+ $plot =& $plotarea->addNew($plotType, array(&$dataset));
+ $plot->setLineColor($lineColor);
+ $plot->setFillColor($fillColor);
+
+ $axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
+ $axisX->showLabel(
+ IMAGE_GRAPH_LABEL_MINIMUM +
+ IMAGE_GRAPH_LABEL_ZERO +
+ IMAGE_GRAPH_LABEL_MAXIMUM
+ );
+
+ }
+
+ /**
+ * Factory method to create the Image_Simple_Graph object.
+ *
+ * @param int $width ???
+ * @param int $height ???
+ * @param ??? $plotType ???
+ * @param ??? $data ???
+ * @param string $title ???
+ * @param string $lineColor ???
+ * @param string $fillColor ???
+ * @param ??? $font ???
+ *
+ * @return Image_Simple_Graph
+ */
+ function &factory($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)
+ {
+ $obj =& Image_Graph::factory(
+ 'Image_Graph_Simple',
+ array(
+ $width,
+ $height,
+ $plotType,
+ $data,
+ $title,
+ $lineColor,
+ $fillColor,
+ $font
+ )
+ );
+ return $obj;
+ }
+
+}
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Text\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Title.php,v 1.12 2005/08/24 20:35:56 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * Include file Image/Graph/Layout.php\r
- */\r
-require_once 'Image/Graph/Layout.php';\r
-\r
-/**\r
- * Title\r
- * \r
- * @category Images\r
- * @package Image_Graph\r
- * @subpackage Text\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Title extends Image_Graph_Layout\r
-{\r
-\r
- /**\r
- * The text to print\r
- * @var string\r
- * @access private\r
- */\r
- var $_text;\r
-\r
- /**\r
- * The font to use\r
- * @var Font\r
- * @access private\r
- */\r
- var $_font;\r
-\r
- /**\r
- * The alignment of the title\r
- * @var int\r
- * @access private\r
- */\r
- var $_alignment = IMAGE_GRAPH_ALIGN_CENTER_X;\r
-\r
- /**\r
- * Create the title.\r
- *\r
- * Pass a Image_Graph_Font object - preferably by-ref (&) as second\r
- * parameter, the font size in pixels or an associated array with some or\r
- * all of the followin keys:\r
- *\r
- * 'size' The size of the title\r
- *\r
- * 'angle' The angle at which to write the title (in degrees or 'vertical')\r
- *\r
- * 'color' The font-face color\r
- *\r
- * @param sting $text The text to represent the title\r
- * @param mixed $fontOptions The font to use in the title\r
- */\r
- function Image_Graph_Title($text, $fontOptions = false)\r
- {\r
- parent::Image_Graph_Layout();\r
- if (is_object($fontOptions)) {\r
- $this->_font =& $fontOptions;\r
- } else {\r
- if (is_array($fontOptions)) {\r
- $this->_fontOptions = $fontOptions;\r
- } else {\r
- $this->_fontOptions['size'] = $fontOptions;\r
- }\r
- }\r
- $this->setText($text);\r
- }\r
-\r
- /**\r
- * Set the text\r
- *\r
- * @param string $text The text to display\r
- */\r
- function setText($text)\r
- {\r
- $this->_text = $text;\r
- }\r
-\r
- /**\r
- * Returns the calculated "auto" size\r
- *\r
- * @return int The calculated auto size\r
- * @access private\r
- */\r
- function _getAutoSize()\r
- {\r
- if ($this->_defaultFontOptions !== false) {\r
- $this->_canvas->setFont($this->_defaultFontOptions);\r
- } else { \r
- $this->_canvas->setFont($this->_getFont());\r
- }\r
-\r
- return $this->_canvas->textHeight($this->_text);\r
- }\r
-\r
- /**\r
- * Set the alignment of the legend\r
- *\r
- * @param int $alignment The alignment\r
- */\r
- function setAlignment($alignment)\r
- {\r
- $this->_alignment = $alignment & 0x7;\r
- }\r
- \r
- /**\r
- * Output the text\r
- *\r
- * @return bool Was the output 'good' (true) or 'bad' (false).\r
- * @access private\r
- */\r
- function _done()\r
- {\r
- if ($this->_defaultFontOptions !== false) {\r
- $this->_canvas->setFont($this->_defaultFontOptions);\r
- } else { \r
- $this->_canvas->setFont($this->_getFont());\r
- }\r
-\r
- if (is_a($this->_parent, 'Image_Graph_Plotarea')) { \r
- $this->_setCoords(\r
- $this->_parent->_left,\r
- $this->_parent->_top,\r
- $this->_parent->_right,\r
- $this->_parent->_top + $this->_canvas->textHeight($this->_text)\r
- );\r
- } elseif (!is_a($this->_parent, 'Image_Graph_Layout')) {\r
- $this->_setCoords(\r
- $this->_parent->_fillLeft(),\r
- $this->_parent->_fillTop(),\r
- $this->_parent->_fillRight(),\r
- $this->_parent->_fillTop() + $this->_canvas->textHeight($this->_text)\r
- );\r
- }\r
-\r
- if (parent::_done() === false) {\r
- return false;\r
- }\r
- \r
- if ($this->_alignment == IMAGE_GRAPH_ALIGN_CENTER_X) {\r
- $x = ($this->_left + $this->_right) / 2;\r
- } elseif ($this->_alignment == IMAGE_GRAPH_ALIGN_LEFT) {\r
- $x = $this->_left;\r
- } else {\r
- $x = $this->_right;\r
- }\r
- $y = ($this->_top + $this->_bottom) / 2;\r
-\r
- $this->write(\r
- $x,\r
- $y,\r
- $this->_text,\r
- $this->_alignment + IMAGE_GRAPH_ALIGN_CENTER_Y\r
- );\r
- return true;\r
- }\r
-\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Text
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Title.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * Include file Image/Graph/Layout.php
+ */
+require_once 'Image/Graph/Layout.php';
+
+/**
+ * Title
+ *
+ * @category Images
+ * @package Image_Graph
+ * @subpackage Text
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Title extends Image_Graph_Layout
+{
+
+ /**
+ * The text to print
+ * @var string
+ * @access private
+ */
+ var $_text;
+
+ /**
+ * The font to use
+ * @var Font
+ * @access private
+ */
+ var $_font;
+
+ /**
+ * The alignment of the title
+ * @var int
+ * @access private
+ */
+ var $_alignment = IMAGE_GRAPH_ALIGN_CENTER_X;
+
+ /**
+ * Create the title.
+ *
+ * Pass a Image_Graph_Font object - preferably by-ref (&) as second
+ * parameter, the font size in pixels or an associated array with some or
+ * all of the followin keys:
+ *
+ * 'size' The size of the title
+ *
+ * 'angle' The angle at which to write the title (in degrees or 'vertical')
+ *
+ * 'color' The font-face color
+ *
+ * @param sting $text The text to represent the title
+ * @param mixed $fontOptions The font to use in the title
+ */
+ function Image_Graph_Title($text, $fontOptions = false)
+ {
+ parent::__construct();
+ if (is_object($fontOptions)) {
+ $this->_font =& $fontOptions;
+ } else {
+ if (is_array($fontOptions)) {
+ $this->_fontOptions = $fontOptions;
+ } else {
+ $this->_fontOptions['size'] = $fontOptions;
+ }
+ }
+ $this->setText($text);
+ }
+
+ /**
+ * Set the text
+ *
+ * @param string $text The text to display
+ *
+ * @return void
+ */
+ function setText($text)
+ {
+ $this->_text = $text;
+ }
+
+ /**
+ * Returns the calculated "auto" size
+ *
+ * @return int The calculated auto size
+ * @access private
+ */
+ function _getAutoSize()
+ {
+ if ($this->_defaultFontOptions !== false) {
+ $this->_canvas->setFont($this->_defaultFontOptions);
+ } else {
+ $this->_canvas->setFont($this->_getFont());
+ }
+
+ return $this->_canvas->textHeight($this->_text);
+ }
+
+ /**
+ * Set the alignment of the legend
+ *
+ * @param int $alignment The alignment
+ *
+ * @return void
+ */
+ function setAlignment($alignment)
+ {
+ $this->_alignment = $alignment & 0x7;
+ }
+
+ /**
+ * Output the text
+ *
+ * @return bool Was the output 'good' (true) or 'bad' (false).
+ * @access private
+ */
+ function _done()
+ {
+ if ($this->_defaultFontOptions !== false) {
+ $this->_canvas->setFont($this->_defaultFontOptions);
+ } else {
+ $this->_canvas->setFont($this->_getFont());
+ }
+
+ if (is_a($this->_parent, 'Image_Graph_Plotarea')) {
+ $this->_setCoords(
+ $this->_parent->_left,
+ $this->_parent->_top,
+ $this->_parent->_right,
+ $this->_parent->_top + $this->_canvas->textHeight($this->_text)
+ );
+ } elseif (!is_a($this->_parent, 'Image_Graph_Layout')) {
+ $this->_setCoords(
+ $this->_parent->_fillLeft(),
+ $this->_parent->_fillTop(),
+ $this->_parent->_fillRight(),
+ $this->_parent->_fillTop() + $this->_canvas->textHeight($this->_text)
+ );
+ }
+
+ if (parent::_done() === false) {
+ return false;
+ }
+
+ if ($this->_alignment == IMAGE_GRAPH_ALIGN_CENTER_X) {
+ $x = ($this->_left + $this->_right) / 2;
+ } elseif ($this->_alignment == IMAGE_GRAPH_ALIGN_LEFT) {
+ $x = $this->_left;
+ } else {
+ $x = $this->_right;
+ }
+ $y = ($this->_top + $this->_bottom) / 2;
+
+ $this->write(
+ $x,
+ $y,
+ $this->_text,
+ $this->_alignment + IMAGE_GRAPH_ALIGN_CENTER_Y
+ );
+ return true;
+ }
+
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Graph - Main class for the graph creation.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This library is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or (at your\r
- * option) any later version. This library is distributed in the hope that it\r
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty\r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser\r
- * General Public License for more details. You should have received a copy of\r
- * the GNU Lesser General Public License along with this library; if not, write\r
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- * 02111-1307 USA\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version CVS: $Id: Tool.php,v 1.4 2005/09/14 20:27:24 nosey Exp $\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-\r
-/**\r
- * This class contains a set of tool-functions.\r
- * \r
- * These functions are all to be called statically\r
- *\r
- * @category Images\r
- * @package Image_Graph\r
- * @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
- * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen\r
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1\r
- * @version Release: 0.7.2\r
- * @link http://pear.php.net/package/Image_Graph\r
- */\r
-class Image_Graph_Tool\r
-{\r
-\r
- /**\r
- * Return the average of 2 points\r
- *\r
- * @param double P1 1st point\r
- * @param double P2 2nd point\r
- * @return double The average of P1 and P2\r
- * @static\r
- */\r
- function mid($p1, $p2)\r
- {\r
- return ($p1 + $p2) / 2;\r
- }\r
-\r
- /**\r
- * Mirrors P1 in P2 by a amount of Factor\r
- *\r
- * @param double $p1 1st point, point to mirror\r
- * @param double $o2 2nd point, mirror point\r
- * @param double $factor Mirror factor, 0 returns $p2, 1 returns a pure\r
- * mirror, ie $p1 on the exact other side of $p2\r
- * @return double $p1 mirrored in $p2 by Factor\r
- * @static\r
- */\r
- function mirror($p1, $p2, $factor = 1)\r
- {\r
- return $p2 + $factor * ($p2 - $p1);\r
- }\r
-\r
- /**\r
- * Calculates a Bezier control point, this function must be called for BOTH\r
- * X and Y coordinates (will it work for 3D coordinates!?)\r
- *\r
- * @param double $p1 1st point\r
- * @param double $p2 Point to\r
- * @param double $factor Mirror factor, 0 returns P2, 1 returns a pure\r
- * mirror, i.e. P1 on the exact other side of P2\r
- * @return double P1 mirrored in P2 by Factor\r
- * @static\r
- */\r
- function controlPoint($p1, $p2, $factor, $smoothFactor = 0.75)\r
- {\r
- $sa = Image_Graph_Tool::mirror($p1, $p2, $smoothFactor);\r
- $sb = Image_Graph_Tool::mid($p2, $sa);\r
-\r
- $m = Image_Graph_Tool::mid($p2, $factor);\r
-\r
- $pC = Image_Graph_Tool::mid($sb, $m);\r
-\r
- return $pC;\r
- }\r
-\r
- /**\r
- * Calculates a Bezier point, this function must be called for BOTH X and Y\r
- * coordinates (will it work for 3D coordinates!?)\r
- *\r
- * @param double $t A position between $p2 and $p3, value between 0 and 1\r
- * @param double $p1 Point to use for calculating control points\r
- * @param double $p2 Point 1 to calculate bezier curve between\r
- * @param double $p3 Point 2 to calculate bezier curve between\r
- * @param double $p4 Point to use for calculating control points\r
- * @return double The bezier value of the point t between $p2 and $p3 using\r
- * $p1 and $p4 to calculate control points\r
- * @static\r
- */\r
- function bezier($t, $p1, $p2, $p3, $p4)\r
- {\r
- // (1-t)^3*p1 + 3*(1-t)^2*t*p2 + 3*(1-t)*t^2*p3 + t^3*p4\r
- return pow(1 - $t, 3) * $p1 +\r
- 3 * pow(1 - $t, 2) * $t * $p2 +\r
- 3 * (1 - $t) * pow($t, 2) * $p3 +\r
- pow($t, 3) * $p4;\r
- }\r
- \r
- /**\r
- * For a given point (x,y) return a point rotated by a given angle aroung the center (xy,yc)\r
- *\r
- * @param int $x x coordinate of the point to rotate\r
- * @param int $y y coordinate of the point to rotate\r
- * @param int $xc x coordinate of the center of the rotation\r
- * @param int $yc y coordinate of the center of the rotation\r
- * @param int $angle angle of the rotation\r
- * @return array the coordinate of the new point\r
- * @static\r
- */\r
- function rotate($x, $y, $xc, $yc, $angle)\r
- {\r
- $cos = cos(deg2rad($angle));\r
- $sin = sin(deg2rad($angle));\r
- $xr= $x - $xc;\r
- $yr= $y - $yc;\r
- $x1= $xc + $cos * $xr - $sin * $yr;\r
- $y1= $yc + $sin * $xr + $cos * $yr;\r
- return array((int) $x1,(int) $y1);\r
- }\r
-\r
- /**\r
- * If a number is close 0 zero (i.e. 0 within $decimal decimals) it is rounded down to zero\r
- * \r
- * @param double $value The value to round\r
- * @param int $decimal The number of decimals\r
- * @return double The value or zero if "close enough" to zero\r
- * @static\r
- */\r
- function close2zero($value, $decimal)\r
- {\r
- if (abs($value) < pow(10, -$decimal)) {\r
- return 0;\r
- }\r
- else {\r
- return $value;\r
- }\r
- }\r
- \r
- /**\r
- * Calculate the dimensions and center point (of gravity) for an arc\r
- * \r
- * @param int $v1 The angle at which the arc starts\r
- * @param int $v2 The angle at which the arc ends\r
- * @return array An array with the dimensions in a fraction of a circle width radius 1 'rx', 'ry' and the\r
- * center point of gravity ('cx', 'cy')\r
- * @static\r
- */\r
- function calculateArcDimensionAndCenter($v1, $v2)\r
- { \r
- // $v2 always larger than $v1\r
- $r1x = Image_Graph_Tool::close2zero(cos(deg2rad($v1)), 3); \r
- $r2x = Image_Graph_Tool::close2zero(cos(deg2rad($v2)), 3);\r
- \r
- $r1y = Image_Graph_Tool::close2zero(sin(deg2rad($v1)), 3);\r
- $r2y = Image_Graph_Tool::close2zero(sin(deg2rad($v2)), 3);\r
- \r
- // $rx = how many percent of the x-diameter of the entire ellipse does the arc x-diameter occupy: 1 entire width, 0 no width\r
- // $cx = at what percentage of the diameter does the center lie\r
- \r
- // if the arc passes through 0/360 degrees the "highest" of r1x and r2x is replaced by 1!\r
- if ((($v1 <= 0) && ($v2 >= 0)) || (($v1 <= 360) && ($v2 >= 360))) {\r
- $r1x = min($r1x, $r2x);\r
- $r2x = 1;\r
- } \r
- \r
- // if the arc passes through 180 degrees the "lowest" of r1x and r2x is replaced by -1!\r
- if ((($v1 <= 180) && ($v2 >= 180)) || (($v1 <= 540) && ($v2 >= 540))) {\r
- $r1x = max($r1x, $r2x);\r
- $r2x = -1;\r
- }\r
- \r
- if ($r1x >= 0) { // start between [270; 360] or [0; 90] \r
- if ($r2x >= 0) {\r
- $rx = max($r1x, $r2x) / 2;\r
- $cx = 0; // center lies 0 percent along this "vector"\r
- }\r
- else {\r
- $rx = abs($r1x - $r2x) / 2;\r
- $cx = abs($r2x / 2) / $rx;\r
- }\r
- }\r
- else { // start between ]90; 270[\r
- if ($r2x < 0) {\r
- $rx = max(abs($r1x), abs($r2x)) / 2;\r
- $cx = $rx;\r
- }\r
- else {\r
- $rx = abs($r1x - $r2x) / 2;\r
- $cx = abs($r1x / 2) / $rx;\r
- }\r
- }\r
- \r
- // $ry = how many percent of the y-diameter of the entire ellipse does the arc y-diameter occupy: 1 entire, 0 none\r
- // $cy = at what percentage of the y-diameter does the center lie\r
- \r
- // if the arc passes through 90 degrees the "lowest" of r1x and r2x is replaced by -1!\r
- if ((($v1 <= 90) && ($v2 >= 90)) || (($v1 <= 450) && ($v2 >= 450))) {\r
- $r1y = min($r1y, $r2y);\r
- $r2y = 1;\r
- }\r
- \r
- // if the arc passes through 270 degrees the "highest" of r1y and r2y is replaced by -1!\r
- if ((($v1 <= 270) && ($v2 >= 270)) || (($v1 <= 630) && ($v2 >= 630))) {\r
- $r1y = max($r1y, $r2y);\r
- $r2y = -1;\r
- } \r
- \r
- if ($r1y >= 0) { // start between [0; 180] \r
- if ($r2y >= 0) {\r
- $ry = max($r1y, $r2y) / 2;\r
- $cy = 0; // center lies 0 percent along this "vector"\r
- }\r
- else {\r
- $ry = abs($r1y - $r2y) / 2;\r
- $cy = abs($r2y / 2) / $ry;\r
- }\r
- }\r
- else { // start between ]180; 360[\r
- if ($r2y < 0) {\r
- $ry = max(abs($r1y), abs($r2y)) / 2;\r
- $cy = $ry;\r
- }\r
- else {\r
- $ry = abs($r1y - $r2y) / 2;\r
- $cy = abs($r1y / 2) / $ry;\r
- }\r
- }\r
- \r
- return array(\r
- 'rx' => $rx,\r
- 'cx' => $cx,\r
- 'ry' => $ry,\r
- 'cy' => $cy\r
- );\r
- }\r
- \r
- /**\r
- * Calculate linear regression on a dataset\r
- * @param array $data The data to calculate regression upon\r
- * @return array The slope and intersection of the "best-fit" line\r
- * @static\r
- */ \r
- function calculateLinearRegression(&$data)\r
- {\r
- $sumX = 0; \r
- $sumY = 0;\r
- foreach ($data as $point) {\r
- $sumX += $point['X'];\r
- $sumY += $point['Y'];\r
- } \r
- $meanX = $sumX / count($data);\r
- $meanY = $sumY / count($data);\r
-\r
- $sumXX = 0;\r
- $sumYY = 0;\r
- $sumXY = 0;\r
- foreach ($data as $point) {\r
- $sumXX += ($point['X'] - $meanX) * ($point['X'] - $meanX);\r
- $sumYY += ($point['Y'] - $meanY) * ($point['Y'] - $meanY);\r
- $sumXY += ($point['X'] - $meanX) * ($point['Y'] - $meanY);\r
- } \r
-\r
- $result = array();\r
- $result['slope'] = ($sumXY / $sumXX);\r
- $result['intersection'] = $meanY - ($result['slope'] * $meanX);\r
- return $result;\r
- }\r
- \r
-}\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Graph - Main class for the graph creation.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version SVN: $Id: Tool.php 291170 2009-11-23 03:50:22Z neufeind $
+ * @link http://pear.php.net/package/Image_Graph
+ */
+
+/**
+ * This class contains a set of tool-functions.
+ *
+ * These functions are all to be called statically
+ *
+ * @category Images
+ * @package Image_Graph
+ * @author Jesper Veggerby <pear.nosey@veggerby.dk>
+ * @author Stefan Neufeind <pear.neufeind@speedpartner.de>
+ * @copyright 2003-2009 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
+ * @version Release: 0.8.0
+ * @link http://pear.php.net/package/Image_Graph
+ */
+class Image_Graph_Tool
+{
+
+ /**
+ * Return the average of 2 points
+ *
+ * @param double $p1 1st point
+ * @param double $p2 2nd point
+ *
+ * @return double The average of P1 and P2
+ * @static
+ */
+ function mid($p1, $p2)
+ {
+ return ($p1 + $p2) / 2;
+ }
+
+ /**
+ * Mirrors P1 in P2 by a amount of Factor
+ *
+ * @param double $p1 1st point, point to mirror
+ * @param double $p2 2nd point, mirror point
+ * @param double $factor Mirror factor, 0 returns $p2, 1 returns a pure
+ * mirror, ie $p1 on the exact other side of $p2
+ *
+ * @return double $p1 mirrored in $p2 by Factor
+ * @static
+ */
+ function mirror($p1, $p2, $factor = 1)
+ {
+ return $p2 + $factor * ($p2 - $p1);
+ }
+
+ /**
+ * Calculates a Bezier control point, this function must be called for BOTH
+ * X and Y coordinates (will it work for 3D coordinates!?)
+ *
+ * @param double $p1 1st point
+ * @param double $p2 2nd point
+ * @param double $factor Mirror factor, 0 returns P2, 1 returns a pure
+ * mirror, i.e. P1 on the exact other side of P2
+ * @param double $smoothFactor How much to smooth the curve (0..1)
+ *
+ * @return double P1 mirrored in P2 by Factor
+ * @static
+ */
+ function controlPoint($p1, $p2, $factor, $smoothFactor = 0.75)
+ {
+ $sa = Image_Graph_Tool::mirror($p1, $p2, $smoothFactor);
+ $sb = Image_Graph_Tool::mid($p2, $sa);
+
+ $m = Image_Graph_Tool::mid($p2, $factor);
+
+ $pC = Image_Graph_Tool::mid($sb, $m);
+
+ return $pC;
+ }
+
+ /**
+ * Calculates a Bezier point, this function must be called for BOTH X and Y
+ * coordinates (will it work for 3D coordinates!?)
+ *
+ * @param double $t A position between $p2 and $p3, value between 0 and 1
+ * @param double $p1 Point to use for calculating control points
+ * @param double $p2 Point 1 to calculate bezier curve between
+ * @param double $p3 Point 2 to calculate bezier curve between
+ * @param double $p4 Point to use for calculating control points
+ *
+ * @return double The bezier value of the point t between $p2 and $p3 using
+ * $p1 and $p4 to calculate control points
+ * @static
+ */
+ function bezier($t, $p1, $p2, $p3, $p4)
+ {
+ // (1-t)^3*p1 + 3*(1-t)^2*t*p2 + 3*(1-t)*t^2*p3 + t^3*p4
+ return pow(1 - $t, 3) * $p1 +
+ 3 * pow(1 - $t, 2) * $t * $p2 +
+ 3 * (1 - $t) * pow($t, 2) * $p3 +
+ pow($t, 3) * $p4;
+ }
+
+ /**
+ * For a given point (x,y) return a point rotated by a given angle aroung the center (xy,yc)
+ *
+ * @param int $x x coordinate of the point to rotate
+ * @param int $y y coordinate of the point to rotate
+ * @param int $xc x coordinate of the center of the rotation
+ * @param int $yc y coordinate of the center of the rotation
+ * @param int $angle angle of the rotation
+ *
+ * @return array the coordinate of the new point
+ * @static
+ */
+ function rotate($x, $y, $xc, $yc, $angle)
+ {
+ $cos = cos(deg2rad($angle));
+ $sin = sin(deg2rad($angle));
+ $xr= $x - $xc;
+ $yr= $y - $yc;
+ $x1= $xc + $cos * $xr - $sin * $yr;
+ $y1= $yc + $sin * $xr + $cos * $yr;
+ return array((int) $x1,(int) $y1);
+ }
+
+ /**
+ * If a number is close 0 zero (i.e. 0 within $decimal decimals) it is rounded down to zero
+ *
+ * @param double $value The value to round
+ * @param int $decimal The number of decimals
+ *
+ * @return double The value or zero if "close enough" to zero
+ * @static
+ */
+ function close2zero($value, $decimal)
+ {
+ if (abs($value) < pow(10, -$decimal)) {
+ return 0;
+ } else {
+ return $value;
+ }
+ }
+
+ /**
+ * Calculate the dimensions and center point (of gravity) for an arc
+ *
+ * @param int $v1 The angle at which the arc starts
+ * @param int $v2 The angle at which the arc ends
+ *
+ * @return array An array with the dimensions in a fraction of a circle width radius 1 'rx', 'ry' and the
+ * center point of gravity ('cx', 'cy')
+ * @static
+ */
+ function calculateArcDimensionAndCenter($v1, $v2)
+ {
+ // $v2 always larger than $v1
+ $r1x = Image_Graph_Tool::close2zero(cos(deg2rad($v1)), 3);
+ $r2x = Image_Graph_Tool::close2zero(cos(deg2rad($v2)), 3);
+
+ $r1y = Image_Graph_Tool::close2zero(sin(deg2rad($v1)), 3);
+ $r2y = Image_Graph_Tool::close2zero(sin(deg2rad($v2)), 3);
+
+ // $rx = how many percent of the x-diameter of the entire ellipse does the arc x-diameter occupy: 1 entire width, 0 no width
+ // $cx = at what percentage of the diameter does the center lie
+
+ // if the arc passes through 0/360 degrees the "highest" of r1x and r2x is replaced by 1!
+ if ((($v1 <= 0) && ($v2 >= 0)) || (($v1 <= 360) && ($v2 >= 360))) {
+ $r1x = min($r1x, $r2x);
+ $r2x = 1;
+ }
+
+ // if the arc passes through 180 degrees the "lowest" of r1x and r2x is replaced by -1!
+ if ((($v1 <= 180) && ($v2 >= 180)) || (($v1 <= 540) && ($v2 >= 540))) {
+ $r1x = max($r1x, $r2x);
+ $r2x = -1;
+ }
+
+ if ($r1x >= 0) { // start between [270; 360] or [0; 90]
+ if ($r2x >= 0) {
+ $rx = max($r1x, $r2x) / 2;
+ $cx = 0; // center lies 0 percent along this "vector"
+ } else {
+ $rx = abs($r1x - $r2x) / 2;
+ $cx = abs($r2x / 2) / $rx;
+ }
+ } else { // start between ]90; 270[
+ if ($r2x < 0) {
+ $rx = max(abs($r1x), abs($r2x)) / 2;
+ $cx = $rx;
+ } else {
+ $rx = abs($r1x - $r2x) / 2;
+ $cx = abs($r1x / 2) / $rx;
+ }
+ }
+
+ // $ry = how many percent of the y-diameter of the entire ellipse does the arc y-diameter occupy: 1 entire, 0 none
+ // $cy = at what percentage of the y-diameter does the center lie
+
+ // if the arc passes through 90 degrees the "lowest" of r1x and r2x is replaced by -1!
+ if ((($v1 <= 90) && ($v2 >= 90)) || (($v1 <= 450) && ($v2 >= 450))) {
+ $r1y = min($r1y, $r2y);
+ $r2y = 1;
+ }
+
+ // if the arc passes through 270 degrees the "highest" of r1y and r2y is replaced by -1!
+ if ((($v1 <= 270) && ($v2 >= 270)) || (($v1 <= 630) && ($v2 >= 630))) {
+ $r1y = max($r1y, $r2y);
+ $r2y = -1;
+ }
+
+ if ($r1y >= 0) { // start between [0; 180]
+ if ($r2y >= 0) {
+ $ry = max($r1y, $r2y) / 2;
+ $cy = 0; // center lies 0 percent along this "vector"
+ } else {
+ $ry = abs($r1y - $r2y) / 2;
+ $cy = abs($r2y / 2) / $ry;
+ }
+ } else { // start between ]180; 360[
+ if ($r2y < 0) {
+ $ry = max(abs($r1y), abs($r2y)) / 2;
+ $cy = $ry;
+ } else {
+ $ry = abs($r1y - $r2y) / 2;
+ $cy = abs($r1y / 2) / $ry;
+ }
+ }
+
+ return array(
+ 'rx' => $rx,
+ 'cx' => $cx,
+ 'ry' => $ry,
+ 'cy' => $cy
+ );
+ }
+
+ /**
+ * Calculate linear regression on a dataset
+ *
+ * @param array &$data The data to calculate regression upon
+ *
+ * @return array The slope and intersection of the "best-fit" line
+ * @static
+ */
+ function calculateLinearRegression(&$data)
+ {
+ $sumX = 0;
+ $sumY = 0;
+ foreach ($data as $point) {
+ $sumX += $point['X'];
+ $sumY += $point['Y'];
+ }
+ $meanX = $sumX / count($data);
+ $meanY = $sumY / count($data);
+
+ $sumXX = 0;
+ $sumYY = 0;
+ $sumXY = 0;
+ foreach ($data as $point) {
+ $sumXX += ($point['X'] - $meanX) * ($point['X'] - $meanX);
+ $sumYY += ($point['Y'] - $meanY) * ($point['Y'] - $meanY);
+ $sumXY += ($point['X'] - $meanX) * ($point['Y'] - $meanY);
+ }
+
+ $result = array();
+ $result['slope'] = ($sumXY / $sumXX);
+ $result['intersection'] = $meanY - ($result['slope'] * $meanX);
+ return $result;
+ }
+
+}
+
?>
\ No newline at end of file
define('PHPUnit_MAIN_METHOD', 'AllTests::main');
}
-require_once 'PHPUnit/Framework/TestSuite.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'ColorTest.php';
-<?php\r
-\r
-/**\r
- * Image_Color Tests\r
- *\r
- * @version $Id: ColorTest.php,v 1.2 2008/10/26 18:21:22 clockwerx Exp $\r
- * @copyright 2005\r
- */\r
-\r
-require_once 'PHPUnit/Framework/TestCase.php';\r
-require_once 'Color.php';\r
-\r
-class ColorTest extends PHPUnit_Framework_TestCase {\r
- var $color;\r
-\r
-\r
- function setUp() {\r
- $this->color = new Image_Color();\r
- }\r
- function tearDown() {\r
- unset($this->color);\r
- }\r
-\r
- function testDefaultValues() {\r
- $this->assertFalse($this->color->_websafeb, 'WebSafe should be false by default.');\r
- $this->assertEquals(array(), $this->color->color1, 'Color1 should be an empty array by default.');\r
- $this->assertEquals(array(), $this->color->color2, 'Color2 should be an empty array by default.');\r
- }\r
-\r
- function testSetWebsafe() {\r
- $this->color->setWebSafe(true);\r
- $this->assertTrue($this->color->_websafeb, 'setting true failed.');\r
- $this->color->setWebSafe(false);\r
- $this->assertFalse($this->color->_websafeb, 'setting false failed.');\r
- }\r
-\r
- function testGetGetRange_DefaultParam() {\r
- $this->color->setColors('#ffffff', '#000000');\r
- $result = $this->color->getRange();\r
- $this->assertType('array', $result);\r
- $this->assertEquals(2, count($result));\r
- }\r
- function testGetGetRange_Param5() {\r
- $this->color->setColors('#ffffff', '#000000');\r
- $result = $this->color->getRange(5);\r
- $this->assertType('array', $result);\r
- $this->assertEquals(5, count($result));\r
- }\r
-\r
- function testChangeLightness_DefaultParam_SingleColor() {\r
- $color = array(128,128,128);\r
- $this->color->setColors(Image_Color::rgb2hex($color), null);\r
- $this->color->changeLightness();\r
- $this->assertEquals(array(138,138,138), $this->color->color1);\r
- }\r
- function testChangeLightness_NegativeParam_SingleColor() {\r
- $color = array(128,128,128);\r
- $this->color->setColors(Image_Color::rgb2hex($color), null);\r
- $this->color->changeLightness(-5);\r
- $this->assertEquals(array(123,123,123), $this->color->color1);\r
- }\r
- function testChangeLightness_NegativeParam_TwoColors() {\r
- $color1 = array(128,128,128);\r
- $color2 = array(64,64,64);\r
- $this->color->setColors(\r
- Image_Color::rgb2hex($color1),\r
- Image_Color::rgb2hex($color2)\r
- );\r
- $this->color->changeLightness(-32);\r
- $this->assertEquals(array(96,96,96), $this->color->color1);\r
- $this->assertEquals(array(32,32,32), $this->color->color2);\r
- }\r
-\r
-\r
- function testMixColors_FromParam_Orange_Websafe() {\r
- $red = '#ff0000';\r
- $yellow = '#ffff00';\r
- $this->color->setWebSafe(true);\r
- $ret = $this->color->mixColors($red, $yellow);\r
- $this->assertEquals('FF9900', $ret);\r
- }\r
- function testMixColors_FromParam_Orange_NotWebsafe() {\r
- $red = '#ff0000';\r
- $yellow = '#ffff00';\r
- $ret = $this->color->mixColors($red, $yellow);\r
- $this->assertEquals('FF8000', $ret);\r
- }\r
- function testMixColors_FromParam_Gray_Websafe() {\r
- $black = '#000000';\r
- $white = '#ffffff';\r
- $this->color->setWebSafe(true);\r
- $ret = $this->color->mixColors($black, $white);\r
- $this->assertEquals('999999', $ret);\r
- }\r
- function testMixColors_FromParam_Gray_NotWebsafe() {\r
- $black = '#000000';\r
- $white = '#ffffff';\r
- $ret = $this->color->mixColors($black, $white);\r
- $this->assertEquals('808080', $ret);\r
- }\r
- function testMixColors_FromClass_Orange() {\r
- $red = '#ff0000';\r
- $yellow = '#ffff00';\r
- $this->color->setColors($red, $yellow);\r
- $ret = $this->color->mixColors();\r
- $this->assertEquals('FF8000', $ret);\r
- }\r
- function testMixColors_FromClass_Purple() {\r
- $red = '#ff0000';\r
- $blue = '#0000ff';\r
- $this->color->setColors($red, $blue);\r
- $ret = $this->color->mixColors();\r
- $this->assertEquals('800080', $ret);\r
- }\r
-\r
-\r
- function testSetColors_Neither() {\r
- $this->color->setColors(null, null);\r
- $this->assertEquals(array(), $this->color->color1);\r
- $this->assertEquals(array(), $this->color->color2);\r
- }\r
- function testSetColors_OnlyOne_Hex() {\r
- $this->color->setColors('ABCDEF', null);\r
- $this->assertEquals(array(171, 205, 239), $this->color->color1);\r
- $this->assertEquals(array(), $this->color->color2);\r
- }\r
- function testSetColors_Both_Hex() {\r
- $this->color->setColors('ABCDEF', '012345');\r
- $this->assertEquals(array(171, 205, 239), $this->color->color1);\r
- $this->assertEquals(array( 1, 35, 69), $this->color->color2);\r
- }\r
-\r
-\r
- function testHex2rgb_WithPound() {\r
- $result = Image_Color::hex2rgb('#abcdef');\r
- $this->assertEquals(array(171,205,239,'hex'=>'#abcdef'), $result);\r
- }\r
- function testHex2rgb_WithoutPound() {\r
- $result = Image_Color::hex2rgb('abcdef');\r
- $this->assertEquals(array(171,205,239,'hex'=>'abcdef'), $result);\r
- }\r
-\r
-\r
- function testRgb2hex() {\r
- $result = Image_Color::rgb2hex(array(171,205,239));\r
- $this->assertEquals('ABCDEF', $result);\r
- }\r
-\r
-\r
- function testGetTextColor_WithParams_OnBlack() {\r
- $result = Image_Color::getTextColor('#000000', 'light', 'dark');\r
- $this->assertEquals('light', $result);\r
- }\r
- function testGetTextColor_WithParams_OnWhite() {\r
- $result = Image_Color::getTextColor('#ffffff', 'light', 'dark');\r
- $this->assertEquals('dark', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnWhite() {\r
- $result = Image_Color::getTextColor('#ffffff');\r
- $this->assertEquals('#000000', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnBlack() {\r
- $result = Image_Color::getTextColor('#000000');\r
- $this->assertEquals('#FFFFFF', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnRed() {\r
- $result = Image_Color::getTextColor('#FF0000');\r
- $this->assertEquals('#FFFFFF', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnBlue() {\r
- $result = Image_Color::getTextColor('#0000ff');\r
- $this->assertEquals('#FFFFFF', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnDarkGreen() {\r
- $result = Image_Color::getTextColor('#006400');\r
- $this->assertEquals('#FFFFFF', $result);\r
- }\r
- function testGetTextColor_DefaultParams_OnLightGreen() {\r
- $result = Image_Color::getTextColor('90ee90');\r
- $this->assertEquals('#000000', $result);\r
- }\r
-\r
-\r
- function testColor2RGB_Hex() {\r
- $result = Image_Color::color2RGB('#00ff00');\r
- $this->assertEquals(array(0,255,0,'hex'=>'#00ff00'), $result);\r
- }\r
- function testColor2RGB_Named() {\r
- $result = Image_Color::color2RGB('red');\r
- $this->assertEquals(array(255,0,0), $result);\r
- }\r
-\r
-\r
- function testNamedColor2RGB_Valid() {\r
- $result = Image_Color::namedColor2RGB('orange');\r
- $this->assertEquals(array(255,165,0), $result);\r
- }\r
- function testNamedColor2RGB_InvalidReturnsBlack() {\r
- $result = Image_Color::namedColor2RGB('NOT A REAL COLOR');\r
- $this->assertEquals(array(0,0,0), $result);\r
- }\r
-\r
-\r
- function testPercentageColor2RGB_100s() {\r
- $result = Image_Color::percentageColor2RGB("100%,100%,100%");\r
- $this->assertEquals(array(255,255,255), $result);\r
- }\r
- function testPercentageColor2RGB_0s() {\r
- $result = Image_Color::percentageColor2RGB("0%,0%,0%");\r
- $this->assertEquals(array(0,0,0), $result);\r
- }\r
- function testPercentageColor2RGB_2digits() {\r
- $result = Image_Color::percentageColor2RGB("10%,50%,90%");\r
- $this->assertEquals(array(26,127,229), $result);\r
- }\r
-\r
-\r
- function testMakeWebSafe_00() {\r
- $expected = 0x00;\r
- $param = -1;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 0;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 25;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
- function testMakeWebSafe_33() {\r
- $expected = 0x33;\r
- $param = 26;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 76;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
- function testMakeWebSafe_66() {\r
- $expected = 0x66;\r
- $param = 77;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 127;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
- function testMakeWebSafe_99() {\r
- $expected = 0x99;\r
- $param = 128;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 178;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
- function testMakeWebSafe_cc() {\r
- $expected = 0xcc;\r
- $param = 179;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 229;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
- function testMakeWebSafe_ff() {\r
- $expected = 0xff;\r
- $param = 230;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 255;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- $param = 257;\r
- $actual = _makeWebSafe($param);\r
- $this->assertEquals($expected, $actual, "test return");\r
- $this->assertEquals($expected, $param, 'test param passed by ref');\r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+/**
+ * Image_Color Tests
+ *
+ * @version $Id: ColorTest.php 267819 2008-10-26 18:21:22Z clockwerx $
+ * @copyright 2005
+ */
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once 'Color.php';
+
+class ColorTest extends PHPUnit_Framework_TestCase {
+ var $color;
+
+
+ function setUp() {
+ $this->color = new Image_Color();
+ }
+ function tearDown() {
+ unset($this->color);
+ }
+
+ function testDefaultValues() {
+ $this->assertFalse($this->color->_websafeb, 'WebSafe should be false by default.');
+ $this->assertEquals(array(), $this->color->color1, 'Color1 should be an empty array by default.');
+ $this->assertEquals(array(), $this->color->color2, 'Color2 should be an empty array by default.');
+ }
+
+ function testSetWebsafe() {
+ $this->color->setWebSafe(true);
+ $this->assertTrue($this->color->_websafeb, 'setting true failed.');
+ $this->color->setWebSafe(false);
+ $this->assertFalse($this->color->_websafeb, 'setting false failed.');
+ }
+
+ function testGetGetRange_DefaultParam() {
+ $this->color->setColors('#ffffff', '#000000');
+ $result = $this->color->getRange();
+ $this->assertType('array', $result);
+ $this->assertEquals(2, count($result));
+ }
+ function testGetGetRange_Param5() {
+ $this->color->setColors('#ffffff', '#000000');
+ $result = $this->color->getRange(5);
+ $this->assertType('array', $result);
+ $this->assertEquals(5, count($result));
+ }
+
+ function testChangeLightness_DefaultParam_SingleColor() {
+ $color = array(128,128,128);
+ $this->color->setColors(Image_Color::rgb2hex($color), null);
+ $this->color->changeLightness();
+ $this->assertEquals(array(138,138,138), $this->color->color1);
+ }
+ function testChangeLightness_NegativeParam_SingleColor() {
+ $color = array(128,128,128);
+ $this->color->setColors(Image_Color::rgb2hex($color), null);
+ $this->color->changeLightness(-5);
+ $this->assertEquals(array(123,123,123), $this->color->color1);
+ }
+ function testChangeLightness_NegativeParam_TwoColors() {
+ $color1 = array(128,128,128);
+ $color2 = array(64,64,64);
+ $this->color->setColors(
+ Image_Color::rgb2hex($color1),
+ Image_Color::rgb2hex($color2)
+ );
+ $this->color->changeLightness(-32);
+ $this->assertEquals(array(96,96,96), $this->color->color1);
+ $this->assertEquals(array(32,32,32), $this->color->color2);
+ }
+
+
+ function testMixColors_FromParam_Orange_Websafe() {
+ $red = '#ff0000';
+ $yellow = '#ffff00';
+ $this->color->setWebSafe(true);
+ $ret = $this->color->mixColors($red, $yellow);
+ $this->assertEquals('FF9900', $ret);
+ }
+ function testMixColors_FromParam_Orange_NotWebsafe() {
+ $red = '#ff0000';
+ $yellow = '#ffff00';
+ $ret = $this->color->mixColors($red, $yellow);
+ $this->assertEquals('FF8000', $ret);
+ }
+ function testMixColors_FromParam_Gray_Websafe() {
+ $black = '#000000';
+ $white = '#ffffff';
+ $this->color->setWebSafe(true);
+ $ret = $this->color->mixColors($black, $white);
+ $this->assertEquals('999999', $ret);
+ }
+ function testMixColors_FromParam_Gray_NotWebsafe() {
+ $black = '#000000';
+ $white = '#ffffff';
+ $ret = $this->color->mixColors($black, $white);
+ $this->assertEquals('808080', $ret);
+ }
+ function testMixColors_FromClass_Orange() {
+ $red = '#ff0000';
+ $yellow = '#ffff00';
+ $this->color->setColors($red, $yellow);
+ $ret = $this->color->mixColors();
+ $this->assertEquals('FF8000', $ret);
+ }
+ function testMixColors_FromClass_Purple() {
+ $red = '#ff0000';
+ $blue = '#0000ff';
+ $this->color->setColors($red, $blue);
+ $ret = $this->color->mixColors();
+ $this->assertEquals('800080', $ret);
+ }
+
+
+ function testSetColors_Neither() {
+ $this->color->setColors(null, null);
+ $this->assertEquals(array(), $this->color->color1);
+ $this->assertEquals(array(), $this->color->color2);
+ }
+ function testSetColors_OnlyOne_Hex() {
+ $this->color->setColors('ABCDEF', null);
+ $this->assertEquals(array(171, 205, 239), $this->color->color1);
+ $this->assertEquals(array(), $this->color->color2);
+ }
+ function testSetColors_Both_Hex() {
+ $this->color->setColors('ABCDEF', '012345');
+ $this->assertEquals(array(171, 205, 239), $this->color->color1);
+ $this->assertEquals(array( 1, 35, 69), $this->color->color2);
+ }
+
+
+ function testHex2rgb_WithPound() {
+ $result = Image_Color::hex2rgb('#abcdef');
+ $this->assertEquals(array(171,205,239,'hex'=>'#abcdef'), $result);
+ }
+ function testHex2rgb_WithoutPound() {
+ $result = Image_Color::hex2rgb('abcdef');
+ $this->assertEquals(array(171,205,239,'hex'=>'abcdef'), $result);
+ }
+
+
+ function testRgb2hex() {
+ $result = Image_Color::rgb2hex(array(171,205,239));
+ $this->assertEquals('ABCDEF', $result);
+ }
+
+
+ function testGetTextColor_WithParams_OnBlack() {
+ $result = Image_Color::getTextColor('#000000', 'light', 'dark');
+ $this->assertEquals('light', $result);
+ }
+ function testGetTextColor_WithParams_OnWhite() {
+ $result = Image_Color::getTextColor('#ffffff', 'light', 'dark');
+ $this->assertEquals('dark', $result);
+ }
+ function testGetTextColor_DefaultParams_OnWhite() {
+ $result = Image_Color::getTextColor('#ffffff');
+ $this->assertEquals('#000000', $result);
+ }
+ function testGetTextColor_DefaultParams_OnBlack() {
+ $result = Image_Color::getTextColor('#000000');
+ $this->assertEquals('#FFFFFF', $result);
+ }
+ function testGetTextColor_DefaultParams_OnRed() {
+ $result = Image_Color::getTextColor('#FF0000');
+ $this->assertEquals('#FFFFFF', $result);
+ }
+ function testGetTextColor_DefaultParams_OnBlue() {
+ $result = Image_Color::getTextColor('#0000ff');
+ $this->assertEquals('#FFFFFF', $result);
+ }
+ function testGetTextColor_DefaultParams_OnDarkGreen() {
+ $result = Image_Color::getTextColor('#006400');
+ $this->assertEquals('#FFFFFF', $result);
+ }
+ function testGetTextColor_DefaultParams_OnLightGreen() {
+ $result = Image_Color::getTextColor('90ee90');
+ $this->assertEquals('#000000', $result);
+ }
+
+
+ function testColor2RGB_Hex() {
+ $result = Image_Color::color2RGB('#00ff00');
+ $this->assertEquals(array(0,255,0,'hex'=>'#00ff00'), $result);
+ }
+ function testColor2RGB_Named() {
+ $result = Image_Color::color2RGB('red');
+ $this->assertEquals(array(255,0,0), $result);
+ }
+
+
+ function testNamedColor2RGB_Valid() {
+ $result = Image_Color::namedColor2RGB('orange');
+ $this->assertEquals(array(255,165,0), $result);
+ }
+ function testNamedColor2RGB_InvalidReturnsBlack() {
+ $result = Image_Color::namedColor2RGB('NOT A REAL COLOR');
+ $this->assertEquals(array(0,0,0), $result);
+ }
+
+
+ function testPercentageColor2RGB_100s() {
+ $result = Image_Color::percentageColor2RGB("100%,100%,100%");
+ $this->assertEquals(array(255,255,255), $result);
+ }
+ function testPercentageColor2RGB_0s() {
+ $result = Image_Color::percentageColor2RGB("0%,0%,0%");
+ $this->assertEquals(array(0,0,0), $result);
+ }
+ function testPercentageColor2RGB_2digits() {
+ $result = Image_Color::percentageColor2RGB("10%,50%,90%");
+ $this->assertEquals(array(26,127,229), $result);
+ }
+
+
+ function testMakeWebSafe_00() {
+ $expected = 0x00;
+ $param = -1;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 0;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 25;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+ function testMakeWebSafe_33() {
+ $expected = 0x33;
+ $param = 26;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 76;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+ function testMakeWebSafe_66() {
+ $expected = 0x66;
+ $param = 77;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 127;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+ function testMakeWebSafe_99() {
+ $expected = 0x99;
+ $param = 128;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 178;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+ function testMakeWebSafe_cc() {
+ $expected = 0xcc;
+ $param = 179;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 229;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+ function testMakeWebSafe_ff() {
+ $expected = 0xff;
+ $param = 230;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 255;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ $param = 257;
+ $actual = _makeWebSafe($param);
+ $this->assertEquals($expected, $actual, "test return");
+ $this->assertEquals($expected, $param, 'test param passed by ref');
+ }
+}
+
+?>
-<?php\r
-\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Image_Text.\r
- *\r
- * This is the main file of the Image_Text package. This file has to be\r
- * included for usage of Image_Text.\r
- *\r
- * This is a simple example script, showing Image_Text's facilities.\r
- *\r
- * -------- Start example --------\r
- *\r
- * require_once 'Image/Text.php';\r
- *\r
- * $colors = array(\r
- * 0 => '#0d54e2',\r
- * 1 => '#e8ce7a',\r
- * 2 => '#7ae8ad'\r
- * );\r
- *\r
- * $text = "EXTERIOR: DAGOBAH -- DAY\nWith Yoda\nstrapped to\n\nhis back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in PHP.\nYODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will.\nLUKE: Is Perl better than PHP?\nYODA: No... no... no. Orderless, dirtier, more seductive.\nLUKE: But how will I know why PHP is better than Perl?\nYODA: You will know. When your code you try to read six months from now...";\r
- *\r
- * $options = array(\r
- * 'canvas' => array('width'=> 600,'height'=> 600), // Generate a new image 600x600 pixel\r
- * 'cx' => 300, // Set center to the middle of the canvas\r
- * 'cy' => 300,\r
- * 'width' => 300, // Set text box size\r
- * 'height' => 300,\r
- * 'line_spacing' => 1, // Normal linespacing\r
- * 'angle' => 45, // Text rotated by 45\r
- * 'color' => $colors, // Predefined colors\r
- * 'background_color' => '#FF0000', //red background\r
- * 'max_lines' => 100, // Maximum lines to render\r
- * 'min_font_size' => 2, // Minimal/Maximal font size (for automeasurize)\r
- * 'max_font_size' => 50,\r
- * 'font_path' => './', // Settings for the font file\r
- * 'font_file' => 'Vera.ttf',\r
- * 'antialias' => true, // Antialiase font rendering\r
- * 'halign' => IMAGE_TEXT_ALIGN_RIGHT, // Alignment to the right and middle\r
- * 'valign' => IMAGE_TEXT_ALIGN_MIDDLE\r
- * );\r
- *\r
- * // Generate a new Image_Text object\r
- * $itext = new Image_Text($text, $options);\r
- *\r
- * // Initialize and check the settings\r
- * $itext->init();\r
-\r
- * // Automatically determine optimal font size\r
- * $itext->autoMeasurize();\r
- *\r
- * // Render the image\r
- * $itext->render();\r
- *\r
- * // Display it\r
- * $itext->display();\r
- *\r
- * -------- End example --------\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category Image\r
- * @package Text\r
- * @author Tobias Schlitt <toby@php.net>\r
- * @copyright 1997-2005 The PHP Group\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: Text.php,v 1.32 2007/04/16 09:52:34 cweiske Exp $\r
- * @link http://pear.php.net/package/Net_FTP2\r
- * @since File available since Release 0.0.1\r
- */\r
-\r
-/**\r
- * Require PEAR file for error handling.\r
- */\r
-require_once 'PEAR.php';\r
-\r
-/**\r
- * Regex to match HTML style hex triples.\r
- */\r
-define("IMAGE_TEXT_REGEX_HTMLCOLOR", "/^[#|]([a-f0-9]{2})?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i", true);\r
-\r
-/**\r
- * Defines horizontal alignment to the left of the text box. (This is standard.)\r
- */\r
-define("IMAGE_TEXT_ALIGN_LEFT", "left", true);\r
-\r
-/**\r
- * Defines horizontal alignment to the center of the text box.\r
- */\r
-define("IMAGE_TEXT_ALIGN_RIGHT", "right", true);\r
-\r
-/**\r
- * Defines horizontal alignment to the center of the text box.\r
- */\r
-define("IMAGE_TEXT_ALIGN_CENTER", "center", true);\r
-\r
-/**\r
- * Defines vertical alignment to the to the top of the text box. (This is standard.)\r
- */\r
-define("IMAGE_TEXT_ALIGN_TOP", "top", true);\r
-\r
-/**\r
- * Defines vertical alignment to the to the middle of the text box.\r
- */\r
-define("IMAGE_TEXT_ALIGN_MIDDLE", "middle", true);\r
-\r
-/**\r
- * Defines vertical alignment to the to the bottom of the text box.\r
- */\r
-define("IMAGE_TEXT_ALIGN_BOTTOM", "bottom", true);\r
-\r
-/**\r
- * TODO: This constant is useless until now, since justified alignment does not work yet\r
- */\r
-define("IMAGE_TEXT_ALIGN_JUSTIFY", "justify", true);\r
-\r
-/**\r
- * Image_Text - Advanced text maipulations in images\r
- *\r
- * Image_Text provides advanced text manipulation facilities for GD2\r
- * image generation with PHP. Simply add text clippings to your images,\r
- * let the class automatically determine lines, rotate text boxes around\r
- * their center or top left corner. These are only a couple of features\r
- * Image_Text provides.\r
- *\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @category Image\r
- * @package Text\r
- * @author Tobias Schlitt <toby@php.net>\r
- * @copyright 1997-2005 The PHP Group\r
- * @version Release: @package_version@\r
- * @link http://pear.php.net/package/Net_FTP\r
- * @since 0.0.1\r
- * @access public\r
- */\r
-class Image_Text {\r
-\r
- /**\r
- * Options array. these options can be set through the constructor or the set() method.\r
- *\r
- * Possible options to set are:\r
- * <pre>\r
- *\r
- * 'x' | This sets the top left coordinates (using x/y) or the center point\r
- * 'y' | coordinates (using cx/cy) for your text box. The values from\r
- * 'cx' | cx/cy will overwrite x/y.\r
- * 'cy' |\r
- *\r
- * 'canvas' | You can set different values as a canvas:\r
- * | - A gd image resource.\r
- * | - An array with 'width' and 'height'.\r
- * | - Nothing (the canvas will be measured after the real text size).\r
- *\r
- * 'antialias' | This is usually true. Set it to false to switch antialiasing off.\r
- *\r
- * 'width' | The width and height for your text box.\r
- * 'height' |\r
- *\r
- * 'halign' | Alignment of your text inside the textbox. Use alignmnet constants to define\r
- * 'valign' | vertical and horizontal alignment.\r
- *\r
- * 'angle' | The angle to rotate your text box.\r
- *\r
- * 'color' | An array of color values. Colors will be rotated in the mode you choose (linewise\r
- * | or paragraphwise). Can be in the following formats:\r
- * | - String representing HTML style hex couples (+ unusual alpha couple in the first place, optional).\r
- * | - Array of int values using 'r', 'g', 'b' and optionally 'a' as keys.\r
- *\r
- * 'color_mode' | The color rotation mode for your color sets. Does only apply if you\r
- * | defined multiple colors. Use 'line' or 'paragraph'.\r
- *\r
- * 'background_color' | defines the background color. NULL sets it transparent\r
- * 'enable_alpha' | if alpha channel should be enabled. Automatically\r
- * | enabled when background_color is set to NULL\r
- *\r
- * 'font_path' | Location of the font to use. The path only gives the directory path (ending with a /).\r
- * 'font_file' | The fontfile is given in the 'font_file' option.\r
- *\r
- * 'font_size' | The font size to render text in (will be overwriten, if you use automeasurize).\r
- *\r
- * 'line_spacing' | Measure for the line spacing to use. Default is 0.5.\r
- *\r
- * 'min_font_size' | Automeasurize settings. Try to keep this area as small as possible to get better\r
- * 'max_font_size' | performance.\r
- *\r
- * 'image_type' | The type of image (use image type constants). Is default set to PNG.\r
- *\r
- * 'dest_file' | The destination to (optionally) save your file.\r
- * </pre>\r
- *\r
- * @access public\r
- * @var array\r
- * @see Image_Text::Image_Text(), Image_Text::set()\r
- */\r
-\r
- var $options = array(\r
- // orientation\r
- 'x' => 0,\r
- 'y' => 0,\r
-\r
- // surface\r
- 'canvas' => null,\r
- 'antialias' => true,\r
-\r
- // text clipping\r
- 'width' => 0,\r
- 'height' => 0,\r
-\r
- // text alignment inside the clipping\r
- 'halign' => IMAGE_TEXT_ALIGN_LEFT,\r
- 'valign' => IMAGE_TEXT_ALIGN_TOP,\r
-\r
- // angle to rotate the text clipping\r
- 'angle' => 0,\r
-\r
- // color settings\r
- 'color' => array( '#000000' ),\r
-\r
- 'color_mode' => 'line',\r
-\r
- 'background_color' => '#000000',\r
- 'enable_alpha' => false,\r
-\r
- // font settings\r
- 'font_path' => "./",\r
- 'font_file' => null,\r
- 'font_size' => 2,\r
- 'line_spacing' => 0.5,\r
-\r
- // automasurizing settings\r
- 'min_font_size' => 1,\r
- 'max_font_size' => 100,\r
-\r
- //max. lines to render\r
- 'max_lines' => 100,\r
-\r
- // misc settings\r
- 'image_type' => IMAGETYPE_PNG,\r
- 'dest_file' => ''\r
- );\r
-\r
- /**\r
- * Contains option names, which can cause re-initialization force.\r
- *\r
- * @var array\r
- * @access private\r
- */\r
-\r
- var $_reInits = array('width', 'height', 'canvas', 'angle', 'font_file', 'font_path', 'font_size');\r
-\r
- /**\r
- * The text you want to render.\r
- *\r
- * @access private\r
- * @var string\r
- */\r
-\r
- var $_text;\r
-\r
- /**\r
- * Resource ID of the image canvas.\r
- *\r
- * @access private\r
- * @var ressource\r
- */\r
-\r
- var $_img;\r
-\r
- /**\r
- * Tokens (each word).\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $_tokens = array();\r
-\r
- /**\r
- * Fullpath to the font.\r
- *\r
- * @access private\r
- * @var string\r
- */\r
-\r
- var $_font;\r
-\r
- /**\r
- * Contains the bbox of each rendered lines.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $bbox = array();\r
-\r
- /**\r
- * Defines in which mode the canvas has be set.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $_mode = '';\r
-\r
- /**\r
- * Color indeces returned by imagecolorallocatealpha.\r
- *\r
- * @access public\r
- * @var array\r
- */\r
-\r
- var $colors = array();\r
-\r
- /**\r
- * Width and height of the (rendered) text.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $_realTextSize = array('width' => false, 'height' => false);\r
-\r
- /**\r
- * Measurized lines.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $_lines = false;\r
-\r
- /**\r
- * Fontsize for which the last measuring process was done.\r
- *\r
- * @access private\r
- * @var array\r
- */\r
-\r
- var $_measurizedSize = false;\r
-\r
- /**\r
- * Is the text object initialized?\r
- *\r
- * @access private\r
- * @var bool\r
- */\r
-\r
- var $_init = false;\r
-\r
- /**\r
- * Constructor\r
- *\r
- * Set the text and options. This initializes a new Image_Text object. You must set your text\r
- * here. Optinally you can set all options here using the $options parameter. If you finished switching\r
- * all options you have to call the init() method first befor doing anything further! See Image_Text::set()\r
- * for further information.\r
- *\r
- * @param string $text Text to print.\r
- * @param array $options Options.\r
- * @access public\r
- * @see Image_Text::set(), Image_Text::construct(), Image_Text::init()\r
- */\r
-\r
- function Image_Text($text, $options = null)\r
- {\r
- $this->set('text', $text);\r
- if (!empty($options)) {\r
- $this->options = array_merge($this->options, $options);\r
- }\r
- }\r
-\r
- /**\r
- * Construct and initialize an Image_Text in one step.\r
- * This method is called statically and creates plus initializes an Image_Text object.\r
- * Beware: You will have to recall init() if you set an option afterwards manually.\r
- *\r
- * @param string $text Text to print.\r
- * @param array $options Options.\r
- * @access public\r
- * @static\r
- * @see Image_Text::set(), Image_Text::Image_Text(), Image_Text::init()\r
- */\r
-\r
- function &construct ( $text, $options ) {\r
- $itext = new Image_Text($text, $options);\r
- $res = $itext->init();\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- return $itext;\r
- }\r
-\r
- /**\r
- * Set options\r
- *\r
- * Set a single or multiple options. It may happen that you have to reinitialize the Image_Text\r
- * object after changing options. For possible options, please take a look at the class options\r
- * array!\r
- *\r
- *\r
- * @param mixed $option A single option name or the options array.\r
- * @param mixed $value Option value if $option is string.\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @access public\r
- * @see Image_Text::Image_Text()\r
- */\r
-\r
- function set($option, $value=null)\r
- {\r
- $reInits = array_flip($this->_reInits);\r
- if (!is_array($option)) {\r
- if (!isset($value)) {\r
- return PEAR::raiseError('No value given.');\r
- }\r
- $option = array($option => $value);\r
- }\r
- foreach ($option as $opt => $val) {\r
- switch ($opt) {\r
- case 'color':\r
- $this->setColors($val);\r
- break;\r
- case 'text':\r
- if (is_array($val)) {\r
- $this->_text = implode('\n', $val);\r
- } else {\r
- $this->_text = $val;\r
- }\r
- break;\r
- default:\r
- $this->options[$opt] = $val;\r
- break;\r
- }\r
- if (isset($reInits[$opt])) {\r
- $this->_init = false;\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Set the color-set\r
- *\r
- * Using this method you can set multiple colors for your text.\r
- * Use a simple numeric array to determine their order and give\r
- * it to this function. Multiple colors will be\r
- * cycled by the options specified 'color_mode' option. The given array\r
- * will overwrite the existing color settings!\r
- *\r
- * The following colors syntaxes are understood by this method:\r
- * - "#ffff00" hexadecimal format (HTML style), with and without #.\r
- * - "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.\r
- * - array with 'r','g','b' and (optionally) 'a' keys, using int values.\r
- * - a GD color special color (tiled,...).\r
- *\r
- * A single color or an array of colors are allowed here.\r
- *\r
- * @param mixed $colors Single color or array of colors.\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @access public\r
- * @see Image_Text::setColor(), Image_Text::set()\r
- */\r
-\r
- function setColors($colors)\r
- {\r
- $i = 0;\r
- if (is_array($colors) &&\r
- (is_string($colors[0]) || is_array($colors[0]))\r
- ) {\r
- foreach ($colors as $color) {\r
- $res = $this->setColor($color,$i++);\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- }\r
- } else {\r
- return $this->setColor($colors, $i);\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Set a color\r
- *\r
- * This method is used to set a color at a specific color ID inside the\r
- * color cycle.\r
- *\r
- * The following colors syntaxes are understood by this method:\r
- * - "#ffff00" hexadecimal format (HTML style), with and without #.\r
- * - "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.\r
- * - array with 'r','g','b' and (optionally) 'a' keys, using int values.\r
- *\r
- * @param mixed $color Color value.\r
- * @param mixed $id ID (in the color array) to set color to.\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @access public\r
- * @see Image_Text::setColors(), Image_Text::set()\r
- */\r
-\r
- function setColor($color, $id=0)\r
- {\r
- if(is_array($color)) {\r
- if (isset($color['r']) && isset($color['g']) && isset($color['b'])) {\r
- $color['a'] = isset($color['a']) ? $color['a'] : 0;\r
- $this->options['colors'][$id] = $color;\r
- } else if (isset($color[0]) && isset($color[1]) && isset($color[2])) {\r
- $color['r'] = $color[0];\r
- $color['g'] = $color[1];\r
- $color['b'] = $color[2];\r
- $color['a'] = isset($color[3]) ? $color[3] : 0;\r
- $this->options['colors'][$id] = $color;\r
- } else {\r
- return PEAR::raiseError('Use keys 1,2,3 (optionally) 4 or r,g,b and (optionally) a.');\r
- }\r
- } elseif (is_string($color)) {\r
- $color = $this->_convertString2RGB($color);\r
- if ($color) {\r
- $this->options['color'][$id] = $color;\r
- } else {\r
- return PEAR::raiseError('Invalid color.');\r
- }\r
- }\r
- if ($this->_img) {\r
- $aaFactor = ($this->options['antialias']) ? 1 : -1;\r
- if (function_exists('imagecolorallocatealpha') && isset($color['a'])) {\r
- $this->colors[$id] = $aaFactor * imagecolorallocatealpha($this->_img,\r
- $color['r'],$color['g'],$color['b'],$color['a']);\r
- } else {\r
- $this->colors[$id] = $aaFactor * imagecolorallocate($this->_img,\r
- $color['r'],$color['g'],$color['b']);\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Initialiaze the Image_Text object.\r
- *\r
- * This method has to be called after setting the options for your Image_Text object.\r
- * It initializes the canvas, normalizes some data and checks important options.\r
- * Be shure to check the initialization after you switched some options. The\r
- * set() method may force you to reinitialize the object.\r
- *\r
- * @access public\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @see Image_Text::set()\r
- */\r
-\r
- function init()\r
- {\r
- // Does the fontfile exist and is readable?\r
- // todo: with some versions of the GD-library it's also possible to leave font_path empty, add strip ".ttf" from\r
- // the fontname; the fontfile will then be automatically searched for in library-defined directories\r
- // however this does not yet work if at this point we check for the existance of the fontfile\r
- $font_file = rtrim($this->options['font_path'], '/\\');\r
- $font_file.= (OS_WINDOWS) ? '\\' : '/';\r
- $font_file.= $this->options['font_file'];\r
- $font_file = realpath($font_file);\r
- if (empty($font_file) || !is_file($font_file) || !is_readable($font_file)) {\r
- return PEAR::raiseError('Fontfile not found or not readable.');\r
- } else {\r
- $this->_font = $font_file;\r
- }\r
-\r
- // Is the font size to small?\r
- if ($this->options['width'] < 1) {\r
- return PEAR::raiseError('Width too small. Has to be > 1.');\r
- }\r
-\r
- // Check and create canvas\r
-\r
- switch (true) {\r
- case (empty($this->options['canvas'])):\r
-\r
- // Create new image from width && height of the clipping\r
- $this->_img = imagecreatetruecolor(\r
- $this->options['width'], $this->options['height']);\r
- if (!$this->_img) {\r
- return PEAR::raiseError('Could not create image canvas.');\r
- }\r
- break;\r
-\r
- case (is_resource($this->options['canvas']) &&\r
- get_resource_type($this->options['canvas'])=='gd'):\r
- // The canvas is an image resource\r
- $this->_img = $this->options['canvas'];\r
- break;\r
-\r
- case (is_array($this->options['canvas']) &&\r
- isset($this->options['canvas']['width']) &&\r
- isset($this->options['canvas']['height'])):\r
-\r
- // Canvas must be a width and height measure\r
- $this->_img = imagecreatetruecolor(\r
- $this->options['canvas']['width'],\r
- $this->options['canvas']['height']\r
- );\r
- break;\r
-\r
-\r
- case (is_array($this->options['canvas']) &&\r
- isset($this->options['canvas']['size']) &&\r
- ($this->options['canvas']['size'] = 'auto')):\r
-\r
- case (is_string($this->options['canvas']) &&\r
- ($this->options['canvas'] = 'auto')):\r
- $this->_mode = 'auto';\r
- break;\r
-\r
- default:\r
- return PEAR::raiseError('Could not create image canvas.');\r
-\r
- }\r
-\r
-\r
-\r
- if ($this->_img) {\r
- $this->options['canvas'] = array();\r
- $this->options['canvas']['width'] = imagesx($this->_img);\r
- $this->options['canvas']['height'] = imagesy($this->_img);\r
- }\r
-\r
- if ($this->options['enable_alpha']) {\r
- imagesavealpha($this->_img, true);\r
- imagealphablending($this->_img, false);\r
- }\r
-\r
- if ($this->options['background_color'] === null) {\r
- $this->options['enable_alpha'] = true;\r
- imagesavealpha($this->_img, true);\r
- imagealphablending($this->_img, false);\r
- $colBg = imagecolorallocatealpha($this->_img, 255, 255, 255, 127);\r
- } else {\r
- $arBg = $this->_convertString2RGB($this->options['background_color']);\r
- if ($arBg === false) {\r
- return PEAR::raiseError('Background color is invalid.');\r
- }\r
- $colBg = imagecolorallocatealpha($this->_img, $arBg['r'], $arBg['g'], $arBg['b'], $arBg['a']);\r
- }\r
- imagefilledrectangle(\r
- $this->_img,\r
- 0, 0,\r
- $this->options['canvas']['width'] - 1, $this->options['canvas']['height'] - 1,\r
- $colBg\r
- );\r
-\r
-\r
- // Save and repair angle\r
- $angle = $this->options['angle'];\r
- while ($angle < 0) {\r
- $angle += 360;\r
- }\r
- if ($angle > 359) {\r
- $angle = $angle % 360;\r
- }\r
- $this->options['angle'] = $angle;\r
-\r
- // Set the color values\r
- $res = $this->setColors($this->options['color']);\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
-\r
- $this->_lines = null;\r
-\r
- // Initialization is complete\r
- $this->_init = true;\r
- return true;\r
- }\r
-\r
- /**\r
- * Auto measurize text\r
- *\r
- * Automatically determines the greatest possible font size to\r
- * fit the text into the text box. This method may be very resource\r
- * intensive on your webserver. A good tweaking point are the $start\r
- * and $end parameters, which specify the range of font sizes to search\r
- * through. Anyway, the results should be cached if possible. You can\r
- * optionally set $start and $end here as a parameter or the settings of\r
- * the options array are used.\r
- *\r
- * @access public\r
- * @param int $start Fontsize to start testing with.\r
- * @param int $end Fontsize to end testing with.\r
- * @return int Fontsize measured or PEAR::Error.\r
- * @see Image_Text::measurize()\r
- */\r
-\r
- function autoMeasurize($start=false, $end=false)\r
- {\r
- if (!$this->_init) {\r
- return PEAR::raiseError('Not initialized. Call ->init() first!');\r
- }\r
-\r
- $start = (empty($start)) ? $this->options['min_font_size'] : $start;\r
- $end = (empty($end)) ? $this->options['max_font_size'] : $end;\r
-\r
- $res = false;\r
- // Run through all possible font sizes until a measurize fails\r
- // Not the optimal way. This can be tweaked!\r
- for ($i = $start; $i <= $end; $i++) {\r
- $this->options['font_size'] = $i;\r
- $res = $this->measurize();\r
-\r
- if ($res === false) {\r
- if ($start == $i) {\r
- $this->options['font_size'] = -1;\r
- return PEAR::raiseError("No possible font size found");\r
- }\r
- $this->options['font_size'] -= 1;\r
- $this->_measurizedSize = $this->options['font_size'];\r
- break;\r
- }\r
- // Always the last couple of lines is stored here.\r
- $this->_lines = $res;\r
- }\r
- return $this->options['font_size'];\r
- }\r
-\r
- /**\r
- * Measurize text into the text box\r
- *\r
- * This method makes your text fit into the defined textbox by measurizing the\r
- * lines for your given font-size. You can do this manually before rendering (or use\r
- * even Image_Text::autoMeasurize()) or the renderer will do measurizing\r
- * automatically.\r
- *\r
- * @access public\r
- * @param bool $force Optionally, default is false, set true to force measurizing.\r
- * @return array Array of measured lines or PEAR::Error.\r
- * @see Image_Text::autoMeasurize()\r
- */\r
-\r
- function measurize($force=false)\r
- {\r
- if (!$this->_init) {\r
- return PEAR::raiseError('Not initialized. Call ->init() first!');\r
- }\r
- $this->_processText();\r
-\r
- // Precaching options\r
- $font = $this->_font;\r
- $size = $this->options['font_size'];\r
-\r
- $line_spacing = $this->options['line_spacing'];\r
- $space = (1 + $this->options['line_spacing']) * $this->options['font_size'];\r
-\r
- $max_lines = (int)$this->options['max_lines'];\r
-\r
- if (($max_lines<1) && !$force) {\r
- return false;\r
- }\r
-\r
- $block_width = $this->options['width'];\r
- $block_height = $this->options['height'];\r
-\r
- $colors_cnt = sizeof($this->colors);\r
- $c = $this->colors[0];\r
-\r
- $text_line = '';\r
-\r
- $lines_cnt = 0;\r
- $tokens_cnt = sizeof($this->_tokens);\r
-\r
- $lines = array();\r
-\r
- $text_height = 0;\r
- $text_width = 0;\r
-\r
- $i = 0;\r
- $para_cnt = 0;\r
-\r
- $beginning_of_line = true;\r
-\r
- // Run through tokens and order them in lines\r
- foreach($this->_tokens as $token) {\r
- // Handle new paragraphs\r
- if ($token=="\n") {\r
- $bounds = imagettfbbox($size, 0, $font, $text_line);\r
- if ((++$lines_cnt>=$max_lines) && !$force) {\r
- return false;\r
- }\r
- if ($this->options['color_mode']=='paragraph') {\r
- $c = $this->colors[$para_cnt%$colors_cnt];\r
- $i++;\r
- } else {\r
- $c = $this->colors[$i++%$colors_cnt];\r
- }\r
- $lines[] = array(\r
- 'string' => $text_line,\r
- 'width' => $bounds[2]-$bounds[0],\r
- 'height' => $bounds[1]-$bounds[7],\r
- 'bottom_margin' => $bounds[1],\r
- 'left_margin' => $bounds[0],\r
- 'color' => $c\r
- );\r
- $text_width = max($text_width, ($bounds[2]-$bounds[0]));\r
- $text_height += (int)$space;\r
- if (($text_height > $block_height) && !$force) {\r
- return false;\r
- }\r
- $para_cnt++;\r
- $text_line = '';\r
- $beginning_of_line = true;\r
- continue;\r
- }\r
-\r
- // Usual lining up\r
-\r
- if ($beginning_of_line) {\r
- $text_line = '';\r
- $text_line_next = $token;\r
- $beginning_of_line = false;\r
- } else {\r
- $text_line_next = $text_line.' '.$token;\r
- }\r
- $bounds = imagettfbbox($size, 0, $font, $text_line_next);\r
- $prev_width = isset($prev_width)?$width:0;\r
- $width = $bounds[2]-$bounds[0];\r
-\r
- // Handling of automatic new lines\r
- if ($width>$block_width) {\r
- if ((++$lines_cnt>=$max_lines) && !$force) {\r
- return false;\r
- }\r
- if ($this->options['color_mode']=='line') {\r
- $c = $this->colors[$i++%$colors_cnt];\r
- } else {\r
- $c = $this->colors[$para_cnt%$colors_cnt];\r
- $i++;\r
- }\r
-\r
- $lines[] = array(\r
- 'string' => $text_line,\r
- 'width' => $prev_width,\r
- 'height' => $bounds[1]-$bounds[7],\r
- 'bottom_margin' => $bounds[1],\r
- 'left_margin' => $bounds[0],\r
- 'color' => $c\r
- );\r
- $text_width = max($text_width, ($bounds[2]-$bounds[0]));\r
- $text_height += (int)$space;\r
- if (($text_height > $block_height) && !$force) {\r
- return false;\r
- }\r
-\r
- $text_line = $token;\r
- $bounds = imagettfbbox($size, 0, $font, $text_line);\r
- $width = $bounds[2]-$bounds[0];\r
- $beginning_of_line = false;\r
- } else {\r
- $text_line = $text_line_next;\r
- }\r
- }\r
- // Store remaining line\r
- $bounds = imagettfbbox($size, 0, $font,$text_line);\r
- if ($this->options['color_mode']=='line') {\r
- $c = $this->colors[$i++%$colors_cnt];\r
- } else {\r
- $c = $this->colors[$para_cnt%$colors_cnt];\r
- $i++;\r
- }\r
- $lines[] = array(\r
- 'string'=> $text_line,\r
- 'width' => $bounds[2]-$bounds[0],\r
- 'height'=> $bounds[1]-$bounds[7],\r
- 'bottom_margin' => $bounds[1],\r
- 'left_margin' => $bounds[0],\r
- 'color' => $c\r
- );\r
-\r
- // add last line height, but without the line-spacing\r
- $text_height += $this->options['font_size'];\r
-\r
- $text_width = max($text_width, ($bounds[2]-$bounds[0]));\r
-\r
- if (($text_height > $block_height) && !$force) {\r
- return false;\r
- }\r
-\r
- $this->_realTextSize = array('width' => $text_width, 'height' => $text_height);\r
- $this->_measurizedSize = $this->options['font_size'];\r
-\r
- return $lines;\r
- }\r
-\r
- /**\r
- * Render the text in the canvas using the given options.\r
- *\r
- * This renders the measurized text or automatically measures it first. The $force parameter\r
- * can be used to switch of measurizing problems (this may cause your text being rendered\r
- * outside a given text box or destroy your image completely).\r
- *\r
- * @access public\r
- * @param bool $force Optional, initially false, set true to silence measurize errors.\r
- * @return bool True on success, otherwise PEAR::Error.\r
- */\r
-\r
- function render($force=false)\r
- {\r
- if (!$this->_init) {\r
- return PEAR::raiseError('Not initialized. Call ->init() first!');\r
- }\r
-\r
- if (!$this->_tokens) {\r
- $this->_processText();\r
- }\r
-\r
- if (empty($this->_lines) || ($this->_measurizedSize != $this->options['font_size'])) {\r
- $this->_lines = $this->measurize( $force );\r
- }\r
- $lines = $this->_lines;\r
-\r
- if (PEAR::isError($this->_lines)) {\r
- return $this->_lines;\r
- }\r
-\r
- if ($this->_mode === 'auto') {\r
- $this->_img = imagecreatetruecolor(\r
- $this->_realTextSize['width'],\r
- $this->_realTextSize['height']\r
- );\r
- if (!$this->_img) {\r
- return PEAR::raiseError('Could not create image cabvas.');\r
- }\r
- $this->_mode = '';\r
- $this->setColors($this->_options['color']);\r
- }\r
-\r
- $block_width = $this->options['width'];\r
- $block_height = $this->options['height'];\r
-\r
- $max_lines = $this->options['max_lines'];\r
-\r
- $angle = $this->options['angle'];\r
- $radians = round(deg2rad($angle), 3);\r
-\r
- $font = $this->_font;\r
- $size = $this->options['font_size'];\r
-\r
- $line_spacing = $this->options['line_spacing'];\r
-\r
- $align = $this->options['halign'];\r
-\r
- $im = $this->_img;\r
-\r
- $offset = $this->_getOffset();\r
-\r
- $start_x = $offset['x'];\r
- $start_y = $offset['y'];\r
-\r
- $end_x = $start_x + $block_width;\r
- $end_y = $start_y + $block_height;\r
-\r
- $sinR = sin($radians);\r
- $cosR = cos($radians);\r
-\r
- switch ($this->options['valign']) {\r
- case IMAGE_TEXT_ALIGN_TOP:\r
- $valign_space = 0;\r
- break;\r
- case IMAGE_TEXT_ALIGN_MIDDLE:\r
- $valign_space = ($this->options['height'] - $this->_realTextSize['height']) / 2;\r
- break;\r
- case IMAGE_TEXT_ALIGN_BOTTOM:\r
- $valign_space = $this->options['height'] - $this->_realTextSize['height'];\r
- break;\r
- default:\r
- $valign_space = 0;\r
- }\r
-\r
- $space = (1 + $line_spacing) * $size;\r
-\r
- // Adjustment of align + translation of top-left-corner to bottom-left-corner of first line\r
- $new_posx = $start_x + ($sinR * ($valign_space + $size));\r
- $new_posy = $start_y + ($cosR * ($valign_space + $size));\r
-\r
- $lines_cnt = min($max_lines,sizeof($lines));\r
-\r
- // Go thorugh lines for rendering\r
- for($i=0; $i<$lines_cnt; $i++){\r
-\r
- // Calc the new start X and Y (only for line>0)\r
- // the distance between the line above is used\r
- if($i > 0){\r
- $new_posx += $sinR * $space;\r
- $new_posy += $cosR * $space;\r
- }\r
-\r
- // Calc the position of the 1st letter. We can then get the left and bottom margins\r
- // 'i' is really not the same than 'j' or 'g'.\r
- $bottom_margin = $lines[$i]['bottom_margin'];\r
- $left_margin = $lines[$i]['left_margin'];\r
- $line_width = $lines[$i]['width'];\r
-\r
- // Calc the position using the block width, the current line width and obviously\r
- // the angle. That gives us the offset to slide the line.\r
- switch($align) {\r
- case IMAGE_TEXT_ALIGN_LEFT:\r
- $hyp = 0;\r
- break;\r
- case IMAGE_TEXT_ALIGN_RIGHT:\r
- $hyp = $block_width - $line_width - $left_margin;\r
- break;\r
- case IMAGE_TEXT_ALIGN_CENTER:\r
- $hyp = ($block_width-$line_width)/2 - $left_margin;\r
- break;\r
- default:\r
- $hyp = 0;\r
- break;\r
- }\r
-\r
- $posx = $new_posx + $cosR * $hyp;\r
- $posy = $new_posy - $sinR * $hyp;\r
-\r
- $c = $lines[$i]['color'];\r
-\r
- // Render textline\r
- $bboxes[] = imagettftext ($im, $size, $angle, $posx, $posy, $c, $font, $lines[$i]['string']);\r
- }\r
- $this->bbox = $bboxes;\r
- return true;\r
- }\r
-\r
- /**\r
- * Return the image ressource.\r
- *\r
- * Get the image canvas.\r
- *\r
- * @access public\r
- * @return resource Used image resource\r
- */\r
-\r
- function &getImg()\r
- {\r
- return $this->_img;\r
- }\r
-\r
- /**\r
- * Display the image (send it to the browser).\r
- *\r
- * This will output the image to the users browser. You can use the standard IMAGETYPE_*\r
- * constants to determine which image type will be generated. Optionally you can save your\r
- * image to a destination you set in the options.\r
- *\r
- * @param bool $save Save or not the image on printout.\r
- * @param bool $free Free the image on exit.\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @access public\r
- * @see Image_Text::save()\r
- */\r
-\r
- function display($save=false, $free=false)\r
- {\r
- if (!headers_sent()) {\r
- header("Content-type: " .image_type_to_mime_type($this->options['image_type']));\r
- } else {\r
- PEAR::raiseError('Header already sent.');\r
- }\r
- switch ($this->options['image_type']) {\r
- case IMAGETYPE_PNG:\r
- $imgout = 'imagepng';\r
- break;\r
- case IMAGETYPE_JPEG:\r
- $imgout = 'imagejpeg';\r
- break;\r
- case IMAGETYPE_BMP:\r
- $imgout = 'imagebmp';\r
- break;\r
- default:\r
- return PEAR::raiseError('Unsupported image type.');\r
- break;\r
- }\r
- if ($save) {\r
- $imgout($this->_img);\r
- $res = $this->save();\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- } else {\r
- $imgout($this->_img);\r
- }\r
-\r
- if ($free) {\r
- $res = imagedestroy($this->image);\r
- if (!$res) {\r
- PEAR::raiseError('Destroying image failed.');\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Save image canvas.\r
- *\r
- * Saves the image to a given destination. You can leave out the destination file path,\r
- * if you have the option for that set correctly. Saving is possible with the save()\r
- * method, too.\r
- *\r
- * @param string $destFile The destination to save to (optional, uses options value else).\r
- * @return bool True on success, otherwise PEAR::Error.\r
- * @see Image_Text::display()\r
- */\r
-\r
- function save($dest_file=false)\r
- {\r
- if (!$dest_file) {\r
- $dest_file = $this->options['dest_file'];\r
- }\r
- if (!$dest_file) {\r
- return PEAR::raiseError("Invalid desitination file.");\r
- }\r
-\r
- switch ($this->options['image_type']) {\r
- case IMAGETYPE_PNG:\r
- $imgout = 'imagepng';\r
- break;\r
- case IMAGETYPE_JPEG:\r
- $imgout = 'imagejpeg';\r
- break;\r
- case IMAGETYPE_BMP:\r
- $imgout = 'imagebmp';\r
- break;\r
- default:\r
- return PEAR::raiseError('Unsupported image type.');\r
- break;\r
- }\r
-\r
- $res = $imgout($this->_img, $dest_file);\r
- if (!$res) {\r
- PEAR::raiseError('Saving file failed.');\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Get completely translated offset for text rendering.\r
- *\r
- * Get completely translated offset for text rendering. Important\r
- * for usage of center coords and angles\r
- *\r
- * @access private\r
- * @return array Array of x/y coordinates.\r
- */\r
-\r
- function _getOffset()\r
- {\r
- // Presaving data\r
- $width = $this->options['width'];\r
- $height = $this->options['height'];\r
- $angle = $this->options['angle'];\r
- $x = $this->options['x'];\r
- $y = $this->options['y'];\r
- // Using center coordinates\r
- if (!empty($this->options['cx']) && !empty($this->options['cy'])) {\r
- $cx = $this->options['cx'];\r
- $cy = $this->options['cy'];\r
- // Calculation top left corner\r
- $x = $cx - ($width / 2);\r
- $y = $cy - ($height / 2);\r
- // Calculating movement to keep the center point on himslf after rotation\r
- if ($angle) {\r
- $ang = deg2rad($angle);\r
- // Vector from the top left cornern ponting to the middle point\r
- $vA = array( ($cx - $x), ($cy - $y) );\r
- // Matrix to rotate vector\r
- // sinus and cosinus\r
- $sin = round(sin($ang), 14);\r
- $cos = round(cos($ang), 14);\r
- // matrix\r
- $mRot = array(\r
- $cos, (-$sin),\r
- $sin, $cos\r
- );\r
- // Multiply vector with matrix to get the rotated vector\r
- // This results in the location of the center point after rotation\r
- $vB = array (\r
- ($mRot[0] * $vA[0] + $mRot[2] * $vA[0]),\r
- ($mRot[1] * $vA[1] + $mRot[3] * $vA[1])\r
- );\r
- // To get the movement vector, we subtract the original middle\r
- $vC = array (\r
- ($vA[0] - $vB[0]),\r
- ($vA[1] - $vB[1])\r
- );\r
- // Finally we move the top left corner coords there\r
- $x += $vC[0];\r
- $y += $vC[1];\r
- }\r
- }\r
- return array ('x' => (int)round($x, 0), 'y' => (int)round($y, 0));\r
- }\r
-\r
- /**\r
- * Convert a color to an array.\r
- *\r
- * The following colors syntax must be used:\r
- * "#08ffff00" hexadecimal format with alpha channel (08)\r
- * array with 'r','g','b','a'(optionnal) keys\r
- * A GD color special color (tiled,...)\r
- * Only one color is allowed\r
- * If $id is given, the color index $id is used\r
- *\r
- * @param mixed $colors Array of colors.\r
- * @param mixed $id Array of colors.\r
- * @access private\r
- */\r
- function _convertString2RGB($scolor)\r
- {\r
- if (preg_match(IMAGE_TEXT_REGEX_HTMLCOLOR, $scolor, $matches)) {\r
- return array(\r
- 'r' => hexdec($matches[2]),\r
- 'g' => hexdec($matches[3]),\r
- 'b' => hexdec($matches[4]),\r
- 'a' => hexdec(!empty($matches[1])?$matches[1]:0),\r
- );\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Extract the tokens from the text.\r
- *\r
- * @access private\r
- */\r
- function _processText()\r
- {\r
- if (!isset($this->_text)) {\r
- return false;\r
- }\r
- $this->_tokens = array();\r
-\r
- // Normalize linebreak to "\n"\r
- $this->_text = preg_replace("[\r\n]", "\n", $this->_text);\r
-\r
- // Get each paragraph\r
- $paras = explode("\n",$this->_text);\r
-\r
- // loop though the paragraphs\r
- // and get each word (token)\r
- foreach($paras as $para) {\r
- $words = explode(' ',$para);\r
- foreach($words as $word) {\r
- $this->_tokens[] = $word;\r
- }\r
- // add a "\n" to mark the end of a paragraph\r
- $this->_tokens[] = "\n";\r
- }\r
- // we do not need an end paragraph as the last token\r
- array_pop($this->_tokens);\r
- }\r
-}\r
-\r
-\r
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Image_Text.
+ *
+ * This is the main file of the Image_Text package. This file has to be
+ * included for usage of Image_Text.
+ *
+ * This is a simple example script, showing Image_Text's facilities.
+ *
+ * -------- Start example --------
+ *
+ * require_once 'Image/Text.php';
+ *
+ * $colors = array(
+ * 0 => '#0d54e2',
+ * 1 => '#e8ce7a',
+ * 2 => '#7ae8ad'
+ * );
+ *
+ * $text = "EXTERIOR: DAGOBAH -- DAY\nWith Yoda\nstrapped to\n\nhis back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in PHP.\nYODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will.\nLUKE: Is Perl better than PHP?\nYODA: No... no... no. Orderless, dirtier, more seductive.\nLUKE: But how will I know why PHP is better than Perl?\nYODA: You will know. When your code you try to read six months from now...";
+ *
+ * $options = array(
+ * 'canvas' => array('width'=> 600,'height'=> 600), // Generate a new image 600x600 pixel
+ * 'cx' => 300, // Set center to the middle of the canvas
+ * 'cy' => 300,
+ * 'width' => 300, // Set text box size
+ * 'height' => 300,
+ * 'line_spacing' => 1, // Normal linespacing
+ * 'angle' => 45, // Text rotated by 45
+ * 'color' => $colors, // Predefined colors
+ * 'background_color' => '#FF0000', //red background
+ * 'max_lines' => 100, // Maximum lines to render
+ * 'min_font_size' => 2, // Minimal/Maximal font size (for automeasurize)
+ * 'max_font_size' => 50,
+ * 'font_path' => './', // Settings for the font file
+ * 'font_file' => 'Vera.ttf',
+ * 'antialias' => true, // Antialiase font rendering
+ * 'halign' => IMAGE_TEXT_ALIGN_RIGHT, // Alignment to the right and middle
+ * 'valign' => IMAGE_TEXT_ALIGN_MIDDLE
+ * );
+ *
+ * // Generate a new Image_Text object
+ * $itext = new Image_Text($text, $options);
+ *
+ * // Initialize and check the settings
+ * $itext->init();
+
+ * // Automatically determine optimal font size
+ * $itext->autoMeasurize();
+ *
+ * // Render the image
+ * $itext->render();
+ *
+ * // Display it
+ * $itext->display();
+ *
+ * -------- End example --------
+ *
+ * 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 Image
+ * @package Text
+ * @author Tobias Schlitt <toby@php.net>
+ * @copyright 1997-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version CVS: $Id: Text.php 235913 2007-05-19 02:54:19Z ssttoo $
+ * @link http://pear.php.net/package/Net_FTP2
+ * @since File available since Release 0.0.1
+ */
+
+/**
+ * Require PEAR file for error handling.
+ */
+require_once 'PEAR.php';
+
+/**
+ * Regex to match HTML style hex triples.
+ */
+define("IMAGE_TEXT_REGEX_HTMLCOLOR", "/^[#|]([a-f0-9]{2})?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i", true);
+
+/**
+ * Defines horizontal alignment to the left of the text box. (This is standard.)
+ */
+define("IMAGE_TEXT_ALIGN_LEFT", "left", true);
+
+/**
+ * Defines horizontal alignment to the center of the text box.
+ */
+define("IMAGE_TEXT_ALIGN_RIGHT", "right", true);
+
+/**
+ * Defines horizontal alignment to the center of the text box.
+ */
+define("IMAGE_TEXT_ALIGN_CENTER", "center", true);
+
+/**
+ * Defines vertical alignment to the to the top of the text box. (This is standard.)
+ */
+define("IMAGE_TEXT_ALIGN_TOP", "top", true);
+
+/**
+ * Defines vertical alignment to the to the middle of the text box.
+ */
+define("IMAGE_TEXT_ALIGN_MIDDLE", "middle", true);
+
+/**
+ * Defines vertical alignment to the to the bottom of the text box.
+ */
+define("IMAGE_TEXT_ALIGN_BOTTOM", "bottom", true);
+
+/**
+ * TODO: This constant is useless until now, since justified alignment does not work yet
+ */
+define("IMAGE_TEXT_ALIGN_JUSTIFY", "justify", true);
+
+/**
+ * Image_Text - Advanced text maipulations in images
+ *
+ * Image_Text provides advanced text manipulation facilities for GD2
+ * image generation with PHP. Simply add text clippings to your images,
+ * let the class automatically determine lines, rotate text boxes around
+ * their center or top left corner. These are only a couple of features
+ * Image_Text provides.
+ *
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @category Image
+ * @package Text
+ * @author Tobias Schlitt <toby@php.net>
+ * @copyright 1997-2005 The PHP Group
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/Net_FTP
+ * @since 0.0.1
+ * @access public
+ */
+class Image_Text {
+
+ /**
+ * Options array. these options can be set through the constructor or the set() method.
+ *
+ * Possible options to set are:
+ * <pre>
+ *
+ * 'x' | This sets the top left coordinates (using x/y) or the center point
+ * 'y' | coordinates (using cx/cy) for your text box. The values from
+ * 'cx' | cx/cy will overwrite x/y.
+ * 'cy' |
+ *
+ * 'canvas' | You can set different values as a canvas:
+ * | - A gd image resource.
+ * | - An array with 'width' and 'height'.
+ * | - Nothing (the canvas will be measured after the real text size).
+ *
+ * 'antialias' | This is usually true. Set it to false to switch antialiasing off.
+ *
+ * 'width' | The width and height for your text box.
+ * 'height' |
+ *
+ * 'halign' | Alignment of your text inside the textbox. Use alignmnet constants to define
+ * 'valign' | vertical and horizontal alignment.
+ *
+ * 'angle' | The angle to rotate your text box.
+ *
+ * 'color' | An array of color values. Colors will be rotated in the mode you choose (linewise
+ * | or paragraphwise). Can be in the following formats:
+ * | - String representing HTML style hex couples (+ unusual alpha couple in the first place, optional).
+ * | - Array of int values using 'r', 'g', 'b' and optionally 'a' as keys.
+ *
+ * 'color_mode' | The color rotation mode for your color sets. Does only apply if you
+ * | defined multiple colors. Use 'line' or 'paragraph'.
+ *
+ * 'background_color' | defines the background color. NULL sets it transparent
+ * 'enable_alpha' | if alpha channel should be enabled. Automatically
+ * | enabled when background_color is set to NULL
+ *
+ * 'font_path' | Location of the font to use. The path only gives the directory path (ending with a /).
+ * 'font_file' | The fontfile is given in the 'font_file' option.
+ *
+ * 'font_size' | The font size to render text in (will be overwriten, if you use automeasurize).
+ *
+ * 'line_spacing' | Measure for the line spacing to use. Default is 0.5.
+ *
+ * 'min_font_size' | Automeasurize settings. Try to keep this area as small as possible to get better
+ * 'max_font_size' | performance.
+ *
+ * 'image_type' | The type of image (use image type constants). Is default set to PNG.
+ *
+ * 'dest_file' | The destination to (optionally) save your file.
+ * </pre>
+ *
+ * @access public
+ * @var array
+ * @see Image_Text::Image_Text(), Image_Text::set()
+ */
+
+ var $options = array(
+ // orientation
+ 'x' => 0,
+ 'y' => 0,
+
+ // surface
+ 'canvas' => null,
+ 'antialias' => true,
+
+ // text clipping
+ 'width' => 0,
+ 'height' => 0,
+
+ // text alignment inside the clipping
+ 'halign' => IMAGE_TEXT_ALIGN_LEFT,
+ 'valign' => IMAGE_TEXT_ALIGN_TOP,
+
+ // angle to rotate the text clipping
+ 'angle' => 0,
+
+ // color settings
+ 'color' => array( '#000000' ),
+
+ 'color_mode' => 'line',
+
+ 'background_color' => '#000000',
+ 'enable_alpha' => false,
+
+ // font settings
+ 'font_path' => "./",
+ 'font_file' => null,
+ 'font_size' => 2,
+ 'line_spacing' => 0.5,
+
+ // automasurizing settings
+ 'min_font_size' => 1,
+ 'max_font_size' => 100,
+
+ //max. lines to render
+ 'max_lines' => 100,
+
+ // misc settings
+ 'image_type' => IMAGETYPE_PNG,
+ 'dest_file' => ''
+ );
+
+ /**
+ * Contains option names, which can cause re-initialization force.
+ *
+ * @var array
+ * @access private
+ */
+
+ var $_reInits = array('width', 'height', 'canvas', 'angle', 'font_file', 'font_path', 'font_size');
+
+ /**
+ * The text you want to render.
+ *
+ * @access private
+ * @var string
+ */
+
+ var $_text;
+
+ /**
+ * Resource ID of the image canvas.
+ *
+ * @access private
+ * @var ressource
+ */
+
+ var $_img;
+
+ /**
+ * Tokens (each word).
+ *
+ * @access private
+ * @var array
+ */
+
+ var $_tokens = array();
+
+ /**
+ * Fullpath to the font.
+ *
+ * @access private
+ * @var string
+ */
+
+ var $_font;
+
+ /**
+ * Contains the bbox of each rendered lines.
+ *
+ * @access private
+ * @var array
+ */
+
+ var $bbox = array();
+
+ /**
+ * Defines in which mode the canvas has be set.
+ *
+ * @access private
+ * @var array
+ */
+
+ var $_mode = '';
+
+ /**
+ * Color indeces returned by imagecolorallocatealpha.
+ *
+ * @access public
+ * @var array
+ */
+
+ var $colors = array();
+
+ /**
+ * Width and height of the (rendered) text.
+ *
+ * @access private
+ * @var array
+ */
+
+ var $_realTextSize = array('width' => false, 'height' => false);
+
+ /**
+ * Measurized lines.
+ *
+ * @access private
+ * @var array
+ */
+
+ var $_lines = false;
+
+ /**
+ * Fontsize for which the last measuring process was done.
+ *
+ * @access private
+ * @var array
+ */
+
+ var $_measurizedSize = false;
+
+ /**
+ * Is the text object initialized?
+ *
+ * @access private
+ * @var bool
+ */
+
+ var $_init = false;
+
+ /**
+ * Constructor
+ *
+ * Set the text and options. This initializes a new Image_Text object. You must set your text
+ * here. Optinally you can set all options here using the $options parameter. If you finished switching
+ * all options you have to call the init() method first befor doing anything further! See Image_Text::set()
+ * for further information.
+ *
+ * @param string $text Text to print.
+ * @param array $options Options.
+ * @access public
+ * @see Image_Text::set(), Image_Text::construct(), Image_Text::init()
+ */
+
+ function Image_Text($text, $options = null)
+ {
+ $this->set('text', $text);
+ if (!empty($options)) {
+ $this->options = array_merge($this->options, $options);
+ }
+ }
+
+ /**
+ * Construct and initialize an Image_Text in one step.
+ * This method is called statically and creates plus initializes an Image_Text object.
+ * Beware: You will have to recall init() if you set an option afterwards manually.
+ *
+ * @param string $text Text to print.
+ * @param array $options Options.
+ * @access public
+ * @static
+ * @see Image_Text::set(), Image_Text::Image_Text(), Image_Text::init()
+ */
+
+ function &construct ( $text, $options ) {
+ $itext = new Image_Text($text, $options);
+ $res = $itext->init();
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ return $itext;
+ }
+
+ /**
+ * Set options
+ *
+ * Set a single or multiple options. It may happen that you have to reinitialize the Image_Text
+ * object after changing options. For possible options, please take a look at the class options
+ * array!
+ *
+ *
+ * @param mixed $option A single option name or the options array.
+ * @param mixed $value Option value if $option is string.
+ * @return bool True on success, otherwise PEAR::Error.
+ * @access public
+ * @see Image_Text::Image_Text()
+ */
+
+ function set($option, $value=null)
+ {
+ $reInits = array_flip($this->_reInits);
+ if (!is_array($option)) {
+ if (!isset($value)) {
+ return PEAR::raiseError('No value given.');
+ }
+ $option = array($option => $value);
+ }
+ foreach ($option as $opt => $val) {
+ switch ($opt) {
+ case 'color':
+ $this->setColors($val);
+ break;
+ case 'text':
+ if (is_array($val)) {
+ $this->_text = implode('\n', $val);
+ } else {
+ $this->_text = $val;
+ }
+ break;
+ default:
+ $this->options[$opt] = $val;
+ break;
+ }
+ if (isset($reInits[$opt])) {
+ $this->_init = false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Set the color-set
+ *
+ * Using this method you can set multiple colors for your text.
+ * Use a simple numeric array to determine their order and give
+ * it to this function. Multiple colors will be
+ * cycled by the options specified 'color_mode' option. The given array
+ * will overwrite the existing color settings!
+ *
+ * The following colors syntaxes are understood by this method:
+ * - "#ffff00" hexadecimal format (HTML style), with and without #.
+ * - "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.
+ * - array with 'r','g','b' and (optionally) 'a' keys, using int values.
+ * - a GD color special color (tiled,...).
+ *
+ * A single color or an array of colors are allowed here.
+ *
+ * @param mixed $colors Single color or array of colors.
+ * @return bool True on success, otherwise PEAR::Error.
+ * @access public
+ * @see Image_Text::setColor(), Image_Text::set()
+ */
+
+ function setColors($colors)
+ {
+ $i = 0;
+ if (is_array($colors) &&
+ (is_string($colors[0]) || is_array($colors[0]))
+ ) {
+ foreach ($colors as $color) {
+ $res = $this->setColor($color,$i++);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+ } else {
+ return $this->setColor($colors, $i);
+ }
+ return true;
+ }
+
+ /**
+ * Set a color
+ *
+ * This method is used to set a color at a specific color ID inside the
+ * color cycle.
+ *
+ * The following colors syntaxes are understood by this method:
+ * - "#ffff00" hexadecimal format (HTML style), with and without #.
+ * - "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.
+ * - array with 'r','g','b' and (optionally) 'a' keys, using int values.
+ *
+ * @param mixed $color Color value.
+ * @param mixed $id ID (in the color array) to set color to.
+ * @return bool True on success, otherwise PEAR::Error.
+ * @access public
+ * @see Image_Text::setColors(), Image_Text::set()
+ */
+
+ function setColor($color, $id=0)
+ {
+ if(is_array($color)) {
+ if (isset($color['r']) && isset($color['g']) && isset($color['b'])) {
+ $color['a'] = isset($color['a']) ? $color['a'] : 0;
+ $this->options['colors'][$id] = $color;
+ } else if (isset($color[0]) && isset($color[1]) && isset($color[2])) {
+ $color['r'] = $color[0];
+ $color['g'] = $color[1];
+ $color['b'] = $color[2];
+ $color['a'] = isset($color[3]) ? $color[3] : 0;
+ $this->options['colors'][$id] = $color;
+ } else {
+ return PEAR::raiseError('Use keys 1,2,3 (optionally) 4 or r,g,b and (optionally) a.');
+ }
+ } elseif (is_string($color)) {
+ $color = $this->_convertString2RGB($color);
+ if ($color) {
+ $this->options['color'][$id] = $color;
+ } else {
+ return PEAR::raiseError('Invalid color.');
+ }
+ }
+ if ($this->_img) {
+ $aaFactor = ($this->options['antialias']) ? 1 : -1;
+ if (function_exists('imagecolorallocatealpha') && isset($color['a'])) {
+ $this->colors[$id] = $aaFactor * imagecolorallocatealpha($this->_img,
+ $color['r'],$color['g'],$color['b'],$color['a']);
+ } else {
+ $this->colors[$id] = $aaFactor * imagecolorallocate($this->_img,
+ $color['r'],$color['g'],$color['b']);
+ }
+ if ($this->colors[$id] == 0 && $aaFactor == -1) {
+ // correction for black with antialiasing OFF
+ // since color cannot be negative zero
+ $this->colors[$id] = -256;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Initialiaze the Image_Text object.
+ *
+ * This method has to be called after setting the options for your Image_Text object.
+ * It initializes the canvas, normalizes some data and checks important options.
+ * Be shure to check the initialization after you switched some options. The
+ * set() method may force you to reinitialize the object.
+ *
+ * @access public
+ * @return bool True on success, otherwise PEAR::Error.
+ * @see Image_Text::set()
+ */
+
+ function init()
+ {
+ // Does the fontfile exist and is readable?
+ // todo: with some versions of the GD-library it's also possible to leave font_path empty, add strip ".ttf" from
+ // the fontname; the fontfile will then be automatically searched for in library-defined directories
+ // however this does not yet work if at this point we check for the existance of the fontfile
+ $font_file = rtrim($this->options['font_path'], '/\\');
+ $font_file.= (OS_WINDOWS) ? '\\' : '/';
+ $font_file.= $this->options['font_file'];
+ $font_file = realpath($font_file);
+ if (empty($font_file) || !is_file($font_file) || !is_readable($font_file)) {
+ return PEAR::raiseError('Fontfile not found or not readable.');
+ } else {
+ $this->_font = $font_file;
+ }
+
+ // Is the font size to small?
+ if ($this->options['width'] < 1) {
+ return PEAR::raiseError('Width too small. Has to be > 1.');
+ }
+
+ // Check and create canvas
+ $image_canvas = false;
+ switch (true) {
+ case (empty($this->options['canvas'])):
+
+ // Create new image from width && height of the clipping
+ $this->_img = imagecreatetruecolor(
+ $this->options['width'], $this->options['height']);
+ if (!$this->_img) {
+ return PEAR::raiseError('Could not create image canvas.');
+ }
+ break;
+
+ case (is_resource($this->options['canvas']) &&
+ get_resource_type($this->options['canvas'])=='gd'):
+ // The canvas is an image resource
+ $image_canvas = true;
+ $this->_img = $this->options['canvas'];
+ break;
+
+ case (is_array($this->options['canvas']) &&
+ isset($this->options['canvas']['width']) &&
+ isset($this->options['canvas']['height'])):
+
+ // Canvas must be a width and height measure
+ $this->_img = imagecreatetruecolor(
+ $this->options['canvas']['width'],
+ $this->options['canvas']['height']
+ );
+ break;
+
+
+ case (is_array($this->options['canvas']) &&
+ isset($this->options['canvas']['size']) &&
+ ($this->options['canvas']['size'] = 'auto')):
+
+ case (is_string($this->options['canvas']) &&
+ ($this->options['canvas'] = 'auto')):
+ $this->_mode = 'auto';
+ break;
+
+ default:
+ return PEAR::raiseError('Could not create image canvas.');
+
+ }
+
+
+
+ if ($this->_img) {
+ $this->options['canvas'] = array();
+ $this->options['canvas']['width'] = imagesx($this->_img);
+ $this->options['canvas']['height'] = imagesy($this->_img);
+ }
+
+ if ($this->options['enable_alpha']) {
+ imagesavealpha($this->_img, true);
+ imagealphablending($this->_img, false);
+ }
+
+ if ($this->options['background_color'] === null) {
+ $this->options['enable_alpha'] = true;
+ imagesavealpha($this->_img, true);
+ imagealphablending($this->_img, false);
+ $colBg = imagecolorallocatealpha($this->_img, 255, 255, 255, 127);
+ } else {
+ $arBg = $this->_convertString2RGB($this->options['background_color']);
+ if ($arBg === false) {
+ return PEAR::raiseError('Background color is invalid.');
+ }
+ $colBg = imagecolorallocatealpha($this->_img, $arBg['r'], $arBg['g'], $arBg['b'], $arBg['a']);
+ }
+ if ($image_canvas === false) {
+ imagefilledrectangle(
+ $this->_img,
+ 0, 0,
+ $this->options['canvas']['width'] - 1, $this->options['canvas']['height'] - 1,
+ $colBg
+ );
+ }
+
+
+ // Save and repair angle
+ $angle = $this->options['angle'];
+ while ($angle < 0) {
+ $angle += 360;
+ }
+ if ($angle > 359) {
+ $angle = $angle % 360;
+ }
+ $this->options['angle'] = $angle;
+
+ // Set the color values
+ $res = $this->setColors($this->options['color']);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+
+ $this->_lines = null;
+
+ // Initialization is complete
+ $this->_init = true;
+ return true;
+ }
+
+ /**
+ * Auto measurize text
+ *
+ * Automatically determines the greatest possible font size to
+ * fit the text into the text box. This method may be very resource
+ * intensive on your webserver. A good tweaking point are the $start
+ * and $end parameters, which specify the range of font sizes to search
+ * through. Anyway, the results should be cached if possible. You can
+ * optionally set $start and $end here as a parameter or the settings of
+ * the options array are used.
+ *
+ * @access public
+ * @param int $start Fontsize to start testing with.
+ * @param int $end Fontsize to end testing with.
+ * @return int Fontsize measured or PEAR::Error.
+ * @see Image_Text::measurize()
+ */
+
+ function autoMeasurize($start=false, $end=false)
+ {
+ if (!$this->_init) {
+ return PEAR::raiseError('Not initialized. Call ->init() first!');
+ }
+
+ $start = (empty($start)) ? $this->options['min_font_size'] : $start;
+ $end = (empty($end)) ? $this->options['max_font_size'] : $end;
+
+ $res = false;
+ // Run through all possible font sizes until a measurize fails
+ // Not the optimal way. This can be tweaked!
+ for ($i = $start; $i <= $end; $i++) {
+ $this->options['font_size'] = $i;
+ $res = $this->measurize();
+
+ if ($res === false) {
+ if ($start == $i) {
+ $this->options['font_size'] = -1;
+ return PEAR::raiseError("No possible font size found");
+ }
+ $this->options['font_size'] -= 1;
+ $this->_measurizedSize = $this->options['font_size'];
+ break;
+ }
+ // Always the last couple of lines is stored here.
+ $this->_lines = $res;
+ }
+ return $this->options['font_size'];
+ }
+
+ /**
+ * Measurize text into the text box
+ *
+ * This method makes your text fit into the defined textbox by measurizing the
+ * lines for your given font-size. You can do this manually before rendering (or use
+ * even Image_Text::autoMeasurize()) or the renderer will do measurizing
+ * automatically.
+ *
+ * @access public
+ * @param bool $force Optionally, default is false, set true to force measurizing.
+ * @return array Array of measured lines or PEAR::Error.
+ * @see Image_Text::autoMeasurize()
+ */
+
+ function measurize($force=false)
+ {
+ if (!$this->_init) {
+ return PEAR::raiseError('Not initialized. Call ->init() first!');
+ }
+ $this->_processText();
+
+ // Precaching options
+ $font = $this->_font;
+ $size = $this->options['font_size'];
+
+ $line_spacing = $this->options['line_spacing'];
+ $space = (1 + $this->options['line_spacing']) * $this->options['font_size'];
+
+ $max_lines = (int)$this->options['max_lines'];
+
+ if (($max_lines<1) && !$force) {
+ return false;
+ }
+
+ $block_width = $this->options['width'];
+ $block_height = $this->options['height'];
+
+ $colors_cnt = sizeof($this->colors);
+ $c = $this->colors[0];
+
+ $text_line = '';
+
+ $lines_cnt = 0;
+ $tokens_cnt = sizeof($this->_tokens);
+
+ $lines = array();
+
+ $text_height = 0;
+ $text_width = 0;
+
+ $i = 0;
+ $para_cnt = 0;
+
+ $beginning_of_line = true;
+
+ // Run through tokens and order them in lines
+ foreach($this->_tokens as $token) {
+ // Handle new paragraphs
+ if ($token=="\n") {
+ $bounds = imagettfbbox($size, 0, $font, $text_line);
+ if ((++$lines_cnt>=$max_lines) && !$force) {
+ return false;
+ }
+ if ($this->options['color_mode']=='paragraph') {
+ $c = $this->colors[$para_cnt%$colors_cnt];
+ $i++;
+ } else {
+ $c = $this->colors[$i++%$colors_cnt];
+ }
+ $lines[] = array(
+ 'string' => $text_line,
+ 'width' => $bounds[2]-$bounds[0],
+ 'height' => $bounds[1]-$bounds[7],
+ 'bottom_margin' => $bounds[1],
+ 'left_margin' => $bounds[0],
+ 'color' => $c
+ );
+ $text_width = max($text_width, ($bounds[2]-$bounds[0]));
+ $text_height += (int)$space;
+ if (($text_height > $block_height) && !$force) {
+ return false;
+ }
+ $para_cnt++;
+ $text_line = '';
+ $beginning_of_line = true;
+ continue;
+ }
+
+ // Usual lining up
+
+ if ($beginning_of_line) {
+ $text_line = '';
+ $text_line_next = $token;
+ $beginning_of_line = false;
+ } else {
+ $text_line_next = $text_line.' '.$token;
+ }
+ $bounds = imagettfbbox($size, 0, $font, $text_line_next);
+ $prev_width = isset($prev_width)?$width:0;
+ $width = $bounds[2]-$bounds[0];
+
+ // Handling of automatic new lines
+ if ($width>$block_width) {
+ if ((++$lines_cnt>=$max_lines) && !$force) {
+ return false;
+ }
+ if ($this->options['color_mode']=='line') {
+ $c = $this->colors[$i++%$colors_cnt];
+ } else {
+ $c = $this->colors[$para_cnt%$colors_cnt];
+ $i++;
+ }
+
+ $lines[] = array(
+ 'string' => $text_line,
+ 'width' => $prev_width,
+ 'height' => $bounds[1]-$bounds[7],
+ 'bottom_margin' => $bounds[1],
+ 'left_margin' => $bounds[0],
+ 'color' => $c
+ );
+ $text_width = max($text_width, ($bounds[2]-$bounds[0]));
+ $text_height += (int)$space;
+ if (($text_height > $block_height) && !$force) {
+ return false;
+ }
+
+ $text_line = $token;
+ $bounds = imagettfbbox($size, 0, $font, $text_line);
+ $width = $bounds[2]-$bounds[0];
+ $beginning_of_line = false;
+ } else {
+ $text_line = $text_line_next;
+ }
+ }
+ // Store remaining line
+ $bounds = imagettfbbox($size, 0, $font,$text_line);
+ if ($this->options['color_mode']=='line') {
+ $c = $this->colors[$i++%$colors_cnt];
+ } else {
+ $c = $this->colors[$para_cnt%$colors_cnt];
+ $i++;
+ }
+ $lines[] = array(
+ 'string'=> $text_line,
+ 'width' => $bounds[2]-$bounds[0],
+ 'height'=> $bounds[1]-$bounds[7],
+ 'bottom_margin' => $bounds[1],
+ 'left_margin' => $bounds[0],
+ 'color' => $c
+ );
+
+ // add last line height, but without the line-spacing
+ $text_height += $this->options['font_size'];
+
+ $text_width = max($text_width, ($bounds[2]-$bounds[0]));
+
+ if (($text_height > $block_height) && !$force) {
+ return false;
+ }
+
+ $this->_realTextSize = array('width' => $text_width, 'height' => $text_height);
+ $this->_measurizedSize = $this->options['font_size'];
+
+ return $lines;
+ }
+
+ /**
+ * Render the text in the canvas using the given options.
+ *
+ * This renders the measurized text or automatically measures it first. The $force parameter
+ * can be used to switch of measurizing problems (this may cause your text being rendered
+ * outside a given text box or destroy your image completely).
+ *
+ * @access public
+ * @param bool $force Optional, initially false, set true to silence measurize errors.
+ * @return bool True on success, otherwise PEAR::Error.
+ */
+
+ function render($force=false)
+ {
+ if (!$this->_init) {
+ return PEAR::raiseError('Not initialized. Call ->init() first!');
+ }
+
+ if (!$this->_tokens) {
+ $this->_processText();
+ }
+
+ if (empty($this->_lines) || ($this->_measurizedSize != $this->options['font_size'])) {
+ $this->_lines = $this->measurize( $force );
+ }
+ $lines = $this->_lines;
+
+ if (PEAR::isError($this->_lines)) {
+ return $this->_lines;
+ }
+
+ if ($this->_mode === 'auto') {
+ $this->_img = imagecreatetruecolor(
+ $this->_realTextSize['width'],
+ $this->_realTextSize['height']
+ );
+ if (!$this->_img) {
+ return PEAR::raiseError('Could not create image cabvas.');
+ }
+ $this->_mode = '';
+ $this->setColors($this->_options['color']);
+ }
+
+ $block_width = $this->options['width'];
+ $block_height = $this->options['height'];
+
+ $max_lines = $this->options['max_lines'];
+
+ $angle = $this->options['angle'];
+ $radians = round(deg2rad($angle), 3);
+
+ $font = $this->_font;
+ $size = $this->options['font_size'];
+
+ $line_spacing = $this->options['line_spacing'];
+
+ $align = $this->options['halign'];
+
+ $im = $this->_img;
+
+ $offset = $this->_getOffset();
+
+ $start_x = $offset['x'];
+ $start_y = $offset['y'];
+
+ $end_x = $start_x + $block_width;
+ $end_y = $start_y + $block_height;
+
+ $sinR = sin($radians);
+ $cosR = cos($radians);
+
+ switch ($this->options['valign']) {
+ case IMAGE_TEXT_ALIGN_TOP:
+ $valign_space = 0;
+ break;
+ case IMAGE_TEXT_ALIGN_MIDDLE:
+ $valign_space = ($this->options['height'] - $this->_realTextSize['height']) / 2;
+ break;
+ case IMAGE_TEXT_ALIGN_BOTTOM:
+ $valign_space = $this->options['height'] - $this->_realTextSize['height'];
+ break;
+ default:
+ $valign_space = 0;
+ }
+
+ $space = (1 + $line_spacing) * $size;
+
+ // Adjustment of align + translation of top-left-corner to bottom-left-corner of first line
+ $new_posx = $start_x + ($sinR * ($valign_space + $size));
+ $new_posy = $start_y + ($cosR * ($valign_space + $size));
+
+ $lines_cnt = min($max_lines,sizeof($lines));
+
+ // Go thorugh lines for rendering
+ for($i=0; $i<$lines_cnt; $i++){
+
+ // Calc the new start X and Y (only for line>0)
+ // the distance between the line above is used
+ if($i > 0){
+ $new_posx += $sinR * $space;
+ $new_posy += $cosR * $space;
+ }
+
+ // Calc the position of the 1st letter. We can then get the left and bottom margins
+ // 'i' is really not the same than 'j' or 'g'.
+ $bottom_margin = $lines[$i]['bottom_margin'];
+ $left_margin = $lines[$i]['left_margin'];
+ $line_width = $lines[$i]['width'];
+
+ // Calc the position using the block width, the current line width and obviously
+ // the angle. That gives us the offset to slide the line.
+ switch($align) {
+ case IMAGE_TEXT_ALIGN_LEFT:
+ $hyp = 0;
+ break;
+ case IMAGE_TEXT_ALIGN_RIGHT:
+ $hyp = $block_width - $line_width - $left_margin;
+ break;
+ case IMAGE_TEXT_ALIGN_CENTER:
+ $hyp = ($block_width-$line_width)/2 - $left_margin;
+ break;
+ default:
+ $hyp = 0;
+ break;
+ }
+
+ $posx = $new_posx + $cosR * $hyp;
+ $posy = $new_posy - $sinR * $hyp;
+
+ $c = $lines[$i]['color'];
+
+ // Render textline
+ $bboxes[] = imagettftext ($im, $size, $angle, $posx, $posy, $c, $font, $lines[$i]['string']);
+ }
+ $this->bbox = $bboxes;
+ return true;
+ }
+
+ /**
+ * Return the image ressource.
+ *
+ * Get the image canvas.
+ *
+ * @access public
+ * @return resource Used image resource
+ */
+
+ function &getImg()
+ {
+ return $this->_img;
+ }
+
+ /**
+ * Display the image (send it to the browser).
+ *
+ * This will output the image to the users browser. You can use the standard IMAGETYPE_*
+ * constants to determine which image type will be generated. Optionally you can save your
+ * image to a destination you set in the options.
+ *
+ * @param bool $save Save or not the image on printout.
+ * @param bool $free Free the image on exit.
+ * @return bool True on success, otherwise PEAR::Error.
+ * @access public
+ * @see Image_Text::save()
+ */
+
+ function display($save=false, $free=false)
+ {
+ if (!headers_sent()) {
+ header("Content-type: " .image_type_to_mime_type($this->options['image_type']));
+ } else {
+ PEAR::raiseError('Header already sent.');
+ }
+ switch ($this->options['image_type']) {
+ case IMAGETYPE_PNG:
+ $imgout = 'imagepng';
+ break;
+ case IMAGETYPE_JPEG:
+ $imgout = 'imagejpeg';
+ break;
+ case IMAGETYPE_BMP:
+ $imgout = 'imagebmp';
+ break;
+ default:
+ return PEAR::raiseError('Unsupported image type.');
+ break;
+ }
+ if ($save) {
+ $imgout($this->_img);
+ $res = $this->save();
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ } else {
+ $imgout($this->_img);
+ }
+
+ if ($free) {
+ $res = imagedestroy($this->image);
+ if (!$res) {
+ PEAR::raiseError('Destroying image failed.');
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Save image canvas.
+ *
+ * Saves the image to a given destination. You can leave out the destination file path,
+ * if you have the option for that set correctly. Saving is possible with the display()
+ * method, too.
+ *
+ * @param string $destFile The destination to save to (optional, uses options value else).
+ * @return bool True on success, otherwise PEAR::Error.
+ * @see Image_Text::display()
+ */
+
+ function save($dest_file=false)
+ {
+ if (!$dest_file) {
+ $dest_file = $this->options['dest_file'];
+ }
+ if (!$dest_file) {
+ return PEAR::raiseError("Invalid desitination file.");
+ }
+
+ switch ($this->options['image_type']) {
+ case IMAGETYPE_PNG:
+ $imgout = 'imagepng';
+ break;
+ case IMAGETYPE_JPEG:
+ $imgout = 'imagejpeg';
+ break;
+ case IMAGETYPE_BMP:
+ $imgout = 'imagebmp';
+ break;
+ default:
+ return PEAR::raiseError('Unsupported image type.');
+ break;
+ }
+
+ $res = $imgout($this->_img, $dest_file);
+ if (!$res) {
+ PEAR::raiseError('Saving file failed.');
+ }
+ return true;
+ }
+
+ /**
+ * Get completely translated offset for text rendering.
+ *
+ * Get completely translated offset for text rendering. Important
+ * for usage of center coords and angles
+ *
+ * @access private
+ * @return array Array of x/y coordinates.
+ */
+
+ function _getOffset()
+ {
+ // Presaving data
+ $width = $this->options['width'];
+ $height = $this->options['height'];
+ $angle = $this->options['angle'];
+ $x = $this->options['x'];
+ $y = $this->options['y'];
+ // Using center coordinates
+ if (!empty($this->options['cx']) && !empty($this->options['cy'])) {
+ $cx = $this->options['cx'];
+ $cy = $this->options['cy'];
+ // Calculation top left corner
+ $x = $cx - ($width / 2);
+ $y = $cy - ($height / 2);
+ // Calculating movement to keep the center point on himslf after rotation
+ if ($angle) {
+ $ang = deg2rad($angle);
+ // Vector from the top left cornern ponting to the middle point
+ $vA = array( ($cx - $x), ($cy - $y) );
+ // Matrix to rotate vector
+ // sinus and cosinus
+ $sin = round(sin($ang), 14);
+ $cos = round(cos($ang), 14);
+ // matrix
+ $mRot = array(
+ $cos, (-$sin),
+ $sin, $cos
+ );
+ // Multiply vector with matrix to get the rotated vector
+ // This results in the location of the center point after rotation
+ $vB = array (
+ ($mRot[0] * $vA[0] + $mRot[2] * $vA[0]),
+ ($mRot[1] * $vA[1] + $mRot[3] * $vA[1])
+ );
+ // To get the movement vector, we subtract the original middle
+ $vC = array (
+ ($vA[0] - $vB[0]),
+ ($vA[1] - $vB[1])
+ );
+ // Finally we move the top left corner coords there
+ $x += $vC[0];
+ $y += $vC[1];
+ }
+ }
+ return array ('x' => (int)round($x, 0), 'y' => (int)round($y, 0));
+ }
+
+ /**
+ * Convert a color to an array.
+ *
+ * The following colors syntax must be used:
+ * "#08ffff00" hexadecimal format with alpha channel (08)
+ * array with 'r','g','b','a'(optionnal) keys
+ * A GD color special color (tiled,...)
+ * Only one color is allowed
+ * If $id is given, the color index $id is used
+ *
+ * @param mixed $colors Array of colors.
+ * @param mixed $id Array of colors.
+ * @access private
+ */
+ function _convertString2RGB($scolor)
+ {
+ if (preg_match(IMAGE_TEXT_REGEX_HTMLCOLOR, $scolor, $matches)) {
+ return array(
+ 'r' => hexdec($matches[2]),
+ 'g' => hexdec($matches[3]),
+ 'b' => hexdec($matches[4]),
+ 'a' => hexdec(!empty($matches[1])?$matches[1]:0),
+ );
+ }
+ return false;
+ }
+
+ /**
+ * Extract the tokens from the text.
+ *
+ * @access private
+ */
+ function _processText()
+ {
+ if (!isset($this->_text)) {
+ return false;
+ }
+ $this->_tokens = array();
+
+ // Normalize linebreak to "\n"
+ $this->_text = preg_replace("[\r\n]", "\n", $this->_text);
+
+ // Get each paragraph
+ $paras = explode("\n",$this->_text);
+
+ // loop though the paragraphs
+ // and get each word (token)
+ foreach($paras as $para) {
+ $words = explode(' ',$para);
+ foreach($words as $word) {
+ $this->_tokens[] = $word;
+ }
+ // add a "\n" to mark the end of a paragraph
+ $this->_tokens[] = "\n";
+ }
+ // we do not need an end paragraph as the last token
+ array_pop($this->_tokens);
+ }
+}
+
+
{
if ($driver == '') {
$extensions = array(
- 'imagick' => 'Imagick2',
+ 'imagick' => 'Imagick3',
'gd' => 'GD',
'imlib' => 'Imlib'
);
+ if (version_compare(PHP_VERSION, '5.0.0', '<')) {
+ //Imagick2 driver for php < 5
+ $extensions['imagick'] = 'Imagick2';
+ }
foreach ($extensions as $ext => $ext_driver) {
if (PEAR::loadExtension($ext)) {
$driver = 'GD';
break;
case 'imagick':
- $driver = 'Imagick2';
+ $driver = 'Imagick3';
+ if (version_compare(PHP_VERSION, '5.0.0', '<')) {
+ $driver = 'Imagick2';
+ }
break;
case 'imlib':
$driver = 'Imlib';
*
* 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 Image
* @package Image_Transform
- * @subpackage Image_Transform_Driver_GD
+ * @subpackage Image_Transform_Driver_Cairowrapper
* @author Christian Weiske <cweiske@php.net>
* @copyright 2008 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: Cairowrapper.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @version CVS: $Id: Cairowrapper.php 288112 2009-09-06 21:02:37Z cweiske $
* @link http://pear.php.net/package/Image_Transform
*/
require_once 'Image/Transform.php';
* Cairo implementation for Image_Transform package using pecl's cairo_wrapper
* extension.
*
+ * Supports png files only.
+ *
* @category Image
* @package Image_Transform
* @subpackage Image_Transform_Driver_Cairowrapper
* @author Christian Weiske <cweiske@php.net>
* @copyright 2008 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Transform
*/
/**
* Supported image types
- * @var array
+ *
+ * @var array
* @access protected
*/
var $_supported_image_types = array(
/**
- * Check settings
- *
- * @since PHP 5
+ * Create object and check if cairo_wrapper is loaded
*/
function __construct()
{
if (!PEAR::loadExtension('cairo_wrapper')) {
$this->isError(
PEAR::raiseError(
- "cairo_wrapper extension is not available.",
+ 'cairo_wrapper extension is not available.',
IMAGE_TRANSFORM_ERROR_UNSUPPORTED
)
);
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: GD.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version CVS: $Id: GD.php 258673 2008-04-28 21:56:06Z cweiske $
* @link http://pear.php.net/package/Image_Transform
*/
* @package
* @author NAWAL ASWAN
* @copyright Copyright (c) 2003
- * @version $Id: GD1.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version $Id: GD1.php 234123 2007-04-19 16:36:09Z dufuz $
* @access public
**/
Class Image_Transform_Driver_GD1 extends Image_Transform_Driver_GD
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: IM.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version CVS: $Id: IM.php 266859 2008-09-30 22:28:47Z dufuz $
* @link http://pear.php.net/package/Image_Transform
*/
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: Imagick2.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version CVS: $Id: Imagick2.php 266907 2008-10-01 21:10:50Z dufuz $
* @link http://pear.php.net/package/Image_Transform
*/
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: Imagick3.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version CVS: $Id: Imagick3.php 266908 2008-10-01 21:11:07Z dufuz $
* @link http://pear.php.net/package/Image_Transform
*/
// +----------------------------------------------------------------------+
// | Authors: Jason Rust <jrust@rustyparts.com> |
// +----------------------------------------------------------------------+
-// $Id: Imlib.php 287351 2009-08-16 03:28:48Z clockwerx $
+// $Id: Imlib.php 258825 2008-04-30 23:00:13Z cweiske $
// {{{ requires
require_once 'Image/Transform.php';
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: NetPBM.php 287351 2009-08-16 03:28:48Z clockwerx $
+ * @version CVS: $Id: NetPBM.php 236527 2007-05-28 16:36:09Z dufuz $
* @link http://pear.php.net/package/Image_Transform
*/
* $Header$
* $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $
*
- * @version $Revision: 284340 $
+ * @version $Revision: 310238 $
* @package Log
*/
define('PEAR_LOG_TYPE_MAIL', 1); /* Use PHP's mail() function */
define('PEAR_LOG_TYPE_DEBUG', 2); /* Use PHP's debugging connection */
define('PEAR_LOG_TYPE_FILE', 3); /* Append to a file */
+define('PEAR_LOG_TYPE_SAPI', 4); /* Use the SAPI logging handler */
/**
* The Log:: class implements both an abstraction for various logging
*/
var $_listeners = array();
+ /**
+ * Starting depth to use when walking a backtrace in search of the
+ * function that invoked the log system.
+ *
+ * @var integer
+ * @access protected
+ */
+ var $_backtrace_depth = 0;
+
/**
* Maps canonical format keys to position arguments for use in building
* "line format" strings.
'%{class}' => '%8$s',
'%\{' => '%%{');
- /**
- * Utility function which wraps PHP's class_exists() function to ensure
- * consistent behavior between PHP versions 4 and 5. Autoloading behavior
- * is always disabled.
- *
- * @param string $class The name of the class whose existence should
- * be tested.
- *
- * @return bool True if the class exists.
- *
- * @access private
- * @since Log 1.9.13
- */
- function _classExists($class)
- {
- if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
- return class_exists($class, false);
- }
-
- return class_exists($class);
- }
-
/**
* Attempts to return a concrete Log instance of type $handler.
*
* @access public
* @since Log 1.0
*/
- function &factory($handler, $name = '', $ident = '', $conf = array(),
- $level = PEAR_LOG_DEBUG)
+ public static function factory($handler, $name = '', $ident = '',
+ $conf = array(), $level = PEAR_LOG_DEBUG)
{
$handler = strtolower($handler);
$class = 'Log_' . $handler;
* a failure as fatal. The caller may have already included their own
* version of the named class.
*/
- if (!Log::_classExists($class)) {
+ if (!class_exists($class, false)) {
include_once $classfile;
}
/* If the class exists, return a new instance of it. */
- if (Log::_classExists($class)) {
- $obj = &new $class($name, $ident, $conf, $level);
+ if (class_exists($class, false)) {
+ $obj = new $class($name, $ident, $conf, $level);
return $obj;
}
* @access public
* @since Log 1.0
*/
- function &singleton($handler, $name = '', $ident = '', $conf = array(),
- $level = PEAR_LOG_DEBUG)
+ public static function singleton($handler, $name = '', $ident = '',
+ $conf = array(), $level = PEAR_LOG_DEBUG)
{
static $instances;
if (!isset($instances)) $instances = array();
$signature = serialize(array($handler, $name, $ident, $conf, $level));
if (!isset($instances[$signature])) {
- $instances[$signature] = &Log::factory($handler, $name, $ident,
- $conf, $level);
+ $instances[$signature] = Log::factory($handler, $name, $ident,
+ $conf, $level);
}
return $instances[$signature];
} else if (method_exists($message, 'tostring')) {
$message = $message->toString();
} else if (method_exists($message, '__tostring')) {
- if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
- $message = (string)$message;
- } else {
- $message = $message->__toString();
- }
+ $message = (string)$message;
} else {
$message = var_export($message, true);
}
/* Start by generating a backtrace from the current call (here). */
$bt = debug_backtrace();
+ /* Store some handy shortcuts to our previous frames. */
+ $bt0 = isset($bt[$depth]) ? $bt[$depth] : null;
+ $bt1 = isset($bt[$depth + 1]) ? $bt[$depth + 1] : null;
+
/*
* If we were ultimately invoked by the composite handler, we need to
* increase our depth one additional level to compensate.
*/
- $class = isset($bt[$depth+1]['class']) ? $bt[$depth+1]['class'] : null;
+ $class = isset($bt1['class']) ? $bt1['class'] : null;
if ($class !== null && strcasecmp($class, 'Log_composite') == 0) {
$depth++;
- $class = isset($bt[$depth + 1]) ? $bt[$depth + 1]['class'] : null;
+ $bt0 = isset($bt[$depth]) ? $bt[$depth] : null;
+ $bt1 = isset($bt[$depth + 1]) ? $bt[$depth + 1] : null;
+ $class = isset($bt1['class']) ? $bt1['class'] : null;
}
/*
* further back to find the name of the encapsulating function from
* which log() was called.
*/
- $file = isset($bt[$depth]) ? $bt[$depth]['file'] : null;
- $line = isset($bt[$depth]) ? $bt[$depth]['line'] : 0;
- $func = isset($bt[$depth + 1]) ? $bt[$depth + 1]['function'] : null;
+ $file = isset($bt0) ? $bt0['file'] : null;
+ $line = isset($bt0) ? $bt0['line'] : 0;
+ $func = isset($bt1) ? $bt1['function'] : null;
/*
* However, if log() was called from one of our "shortcut" functions,
*/
if (in_array($func, array('emerg', 'alert', 'crit', 'err', 'warning',
'notice', 'info', 'debug'))) {
- $file = isset($bt[$depth + 1]) ? $bt[$depth + 1]['file'] : null;
- $line = isset($bt[$depth + 1]) ? $bt[$depth + 1]['line'] : 0;
- $func = isset($bt[$depth + 2]) ? $bt[$depth + 2]['function'] : null;
- $class = isset($bt[$depth + 2]) ? $bt[$depth + 2]['class'] : null;
+ $bt2 = isset($bt[$depth + 2]) ? $bt[$depth + 2] : null;
+
+ $file = is_array($bt1) ? $bt1['file'] : null;
+ $line = is_array($bt1) ? $bt1['line'] : 0;
+ $func = is_array($bt2) ? $bt2['function'] : null;
+ $class = isset($bt2['class']) ? $bt2['class'] : null;
}
/*
* If we couldn't extract a function name (perhaps because we were
* executed from the "main" context), provide a default value.
*/
- if (is_null($func)) {
+ if ($func === null) {
$func = '(none)';
}
return array($file, $line, $func, $class);
}
+ /**
+ * Sets the starting depth to use when walking a backtrace in search of
+ * the function that invoked the log system. This is used on conjunction
+ * with the 'file', 'line', 'function', and 'class' formatters.
+ *
+ * @param int $depth The new backtrace depth.
+ *
+ * @access public
+ * @since Log 1.12.7
+ */
+ public function setBacktraceDepth($depth)
+ {
+ $this->_backtrace_depth = $depth;
+ }
+
/**
* Produces a formatted log line based on a format string and a set of
* variables representing the current log record and state.
* variables (%5 %6,%7,%8), generate the backtrace and fetch them.
*/
if (preg_match('/%[5678]/', $format)) {
- list($file, $line, $func, $class) = $this->_getBacktraceVars(2);
+ /* Plus 2 to account for our internal function calls. */
+ $d = $this->_backtrace_depth + 2;
+ list($file, $line, $func, $class) = $this->_getBacktraceVars($d);
}
/*
* @access public
* @since Log 1.7.0
*/
- function MASK($priority)
+ public static function MASK($priority)
{
return (1 << $priority);
}
*
* @deprecated deprecated since Log 1.9.4; use Log::MAX() instead
*/
- function UPTO($priority)
+ public static function UPTO($priority)
{
return Log::MAX($priority);
}
* @access public
* @since Log 1.9.4
*/
- function MIN($priority)
+ public static function MIN($priority)
{
return PEAR_LOG_ALL ^ ((1 << $priority) - 1);
}
* @access public
* @since Log 1.9.4
*/
- function MAX($priority)
+ public static function MAX($priority)
{
return ((1 << ($priority + 1)) - 1);
}
* $Header$
* $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $
*
- * @version $Revision: 215528 $
+ * @version $Revision: 305990 $
* @package Log
*/
{
/* Attempt to open each of our children. */
$this->_opened = true;
- foreach ($this->_children as $id => $child) {
- $this->_opened &= $this->_children[$id]->open();
+ foreach ($this->_children as $child) {
+ $this->_opened &= $child->open();
}
/* If all children were opened, return success. */
}
/**
- * Closes all of the child instances.
+ * Closes all open child instances.
*
- * @return True if all of the child instances were successfully closed.
+ * @return True if all of the opened child instances were successfully
+ * closed.
*
* @access public
*/
function close()
{
+ /* If we haven't been opened, there's nothing more to do. */
+ if (!$this->_opened) {
+ return true;
+ }
+
/* Attempt to close each of our children. */
$closed = true;
- foreach ($this->_children as $id => $child) {
- $closed &= $this->_children[$id]->close();
+ foreach ($this->_children as $child) {
+ if ($child->_opened) {
+ $closed &= $child->close();
+ }
}
- /* Track the _opened state for consistency. */
+ /* Clear the opened state for consistency. */
$this->_opened = false;
/* If all children were closed, return success. */
{
/* Attempt to flush each of our children. */
$flushed = true;
- foreach ($this->_children as $id => $child) {
- $flushed &= $this->_children[$id]->flush();
+ foreach ($this->_children as $child) {
+ $flushed &= $child->flush();
}
/* If all children were flushed, return success. */
/**
* Sends $message and $priority to each child of this composite. If the
- * children aren't already open, they will be opened here.
+ * appropriate children aren't already open, they will be opened here.
*
* @param mixed $message String or object containing the message
* to log.
}
/*
- * If the handlers haven't been opened, attempt to open them now.
- * However, we don't treat failure to open all of the handlers as a
- * fatal error. We defer that consideration to the success of calling
- * each handler's log() method below.
+ * Abort early if the priority is above the composite handler's
+ * maximum logging level.
+ *
+ * XXX: Consider whether or not introducing this change would break
+ * backwards compatibility. Some users may be expecting composite
+ * handlers to pass on all events to their children regardless of
+ * their own priority.
*/
- if (!$this->_opened) {
- $this->open();
- }
+ #if (!$this->_isMasked($priority)) {
+ # return false;
+ #}
- /* Attempt to log the event using each of the children. */
+ /*
+ * Iterate over all of our children. If a unopened child will respond
+ * to this log event, we attempt to open it immediately. The composite
+ * handler's opened state will be enabled as soon as the first child
+ * handler is successfully opened.
+ *
+ * We track an overall success state that indicates whether or not all
+ * of the relevant child handlers were opened and successfully logged
+ * the event. If one handler fails, we still attempt any remaining
+ * children, but we consider the overall result a failure.
+ */
$success = true;
- foreach ($this->_children as $id => $child) {
- $success &= $this->_children[$id]->log($message, $priority);
+ foreach ($this->_children as $child) {
+ /* If this child won't respond to this event, skip it. */
+ if (!$child->_isMasked($priority)) {
+ continue;
+ }
+
+ /* If this child has yet to be opened, attempt to do so now. */
+ if (!$child->_opened) {
+ $success &= $child->open();
+
+ /*
+ * If we've successfully opened our first handler, the
+ * composite handler itself is considered to be opened.
+ */
+ if (!$this->_opened && $success) {
+ $this->_opened = true;
+ }
+ }
+
+ /* Finally, attempt to log the message to the child handler. */
+ if ($child->_opened) {
+ $success &= $child->log($message, $priority);
+ }
}
+ /* Notify the observers. */
$this->_announce(array('priority' => $priority, 'message' => $message));
- /* Return success if all of the children logged the event. */
+ /* Return success if all of the open children logged the event. */
return $success;
}
parent::setIdent($ident);
/* ... and then call setIdent() on all of our children. */
- foreach ($this->_children as $id => $child) {
- $this->_children[$id]->setIdent($ident);
+ foreach ($this->_children as $child) {
+ $child->setIdent($ident);
}
}
return false;
}
- $this->_children[$child->_id] = &$child;
+ $this->_children[$child->_id] = $child;
return true;
}
/**
* $Header$
*
- * @version $Revision: 224513 $
+ * @version $Revision: 306594 $
* @package Log
*/
* @var resource
* @access private
*/
- var $_stream = STDOUT;
+ var $_stream = null;
+
+ /**
+ * Is this object responsible for closing the stream resource?
+ * @var bool
+ * @access private
+ */
+ var $_closeResource = false;
/**
* Should the output be buffered or displayed immediately?
if (!empty($conf['stream'])) {
$this->_stream = $conf['stream'];
+ } elseif (defined('STDOUT')) {
+ $this->_stream = STDOUT;
+ } else {
+ $this->_stream = fopen('php://output', 'a');
+ $this->_closeResource = true;
}
if (isset($conf['buffering'])) {
{
$this->flush();
$this->_opened = false;
+ if ($this->_closeResource === true && is_resource($this->_stream)) {
+ fclose($this->_stream);
+ }
return true;
}
fwrite($this->_stream, $this->_buffer);
$this->_buffer = '';
}
-
+
if (is_resource($this->_stream)) {
return fflush($this->_stream);
}
return true;
}
-
}
/**
* $Header$
*
- * @version $Revision: 255603 $
+ * @version $Revision: 305290 $
* @package Log
*/
*/
var $_timeFormat = '%b %d %H:%M:%S';
+ /**
+ * Flag indicating whether raw message text should be passed directly to
+ * the log system. Otherwise, the text will be converted to an HTML-safe
+ * representation.
+ * @var boolean
+ * @access private
+ */
+ var $_rawText = false;
+
/**
* Constructs a new Log_display object.
*
if (!empty($conf['timeFormat'])) {
$this->_timeFormat = $conf['timeFormat'];
}
+
+ /* Message text conversion can be disabled. */
+ if (isset($conf['rawText'])) {
+ $this->_rawText = $conf['rawText'];
+ }
}
/**
/* Extract the string representation of the message. */
$message = $this->_extractMessage($message);
+ /* Convert the message to an HTML-friendly represention unless raw
+ * text has been requested. */
+ if ($this->_rawText === false) {
+ $message = nl2br(htmlspecialchars($message));
+ }
+
/* Build and output the complete log line. */
echo $this->_format($this->_lineFormat,
strftime($this->_timeFormat),
$priority,
- nl2br(htmlspecialchars($message)));
+ $message);
/* Notify observers about this log message. */
$this->_announce(array('priority' => $priority, 'message' => $message));
/**
* $Header$
*
- * @version $Revision: 266582 $
+ * @version $Revision: 293927 $
* @package Log
*/
/**
* Constructs a new Log_error_log object.
*
- * @param string $name Ignored.
+ * @param string $name One of the PEAR_LOG_TYPE_* constants.
* @param string $ident The identity string.
* @param array $conf The configuration array.
* @param int $level Log messages up to and including this level.
/**
* $Header$
*
- * @version $Revision: 250923 $
+ * @version $Revision: 306582 $
* @package Log
*/
/* Extract the string representation of the message. */
$message = $this->_extractMessage($message);
$method = $this->_methods[$priority];
-
- /* normalize line breaks */
- $message = str_replace("\r\n", "\n", $message);
-
- /* escape line breaks */
- $message = str_replace("\n", "\\n\\\n", $message);
-
- /* escape quotes */
- $message = str_replace('"', '\\"', $message);
+
+ /* normalize line breaks and escape quotes*/
+ $message = preg_replace("/\r?\n/", "\\n", addslashes($message));
/* Build the string containing the complete log line. */
$line = $this->_format($this->_lineFormat,
return true;
}
-
}
* $Header$
* $Horde: horde/lib/Log/syslog.php,v 1.6 2000/06/28 21:36:13 jon Exp $
*
- * @version $Revision: 291780 $
+ * @version $Revision: 308379 $
* @package Log
*/
*/
var $_inherit = false;
+ /**
+ * Should we re-open the syslog connection for each log event?
+ * @var boolean
+ * @access private
+ */
+ var $_reopen = false;
+
/**
* Maximum message length that will be sent to syslog(). If the handler
* receives a message longer than this length limit, it will be split into
*/
var $_maxLength = 500;
+ /**
+ * String containing the format of a message.
+ * @var string
+ * @access private
+ */
+ var $_lineFormat = '%4$s';
+
+ /**
+ * String containing the timestamp format. It will be passed directly to
+ * strftime(). Note that the timestamp string will generated using the
+ * current locale.
+ * @var string
+ * @access private
+ */
+ var $_timeFormat = '%b %d %H:%M:%S';
+
/**
* Constructs a new syslog object.
*
$this->_inherit = $conf['inherit'];
$this->_opened = $this->_inherit;
}
+ if (isset($conf['reopen'])) {
+ $this->_reopen = $conf['reopen'];
+ }
if (isset($conf['maxLength'])) {
$this->_maxLength = $conf['maxLength'];
}
+ if (!empty($conf['lineFormat'])) {
+ $this->_lineFormat = str_replace(array_keys($this->_formatMap),
+ array_values($this->_formatMap),
+ $conf['lineFormat']);
+ }
+ if (!empty($conf['timeFormat'])) {
+ $this->_timeFormat = $conf['timeFormat'];
+ }
$this->_id = md5(microtime());
$this->_name = $name;
*/
function open()
{
- if (!$this->_opened) {
+ if (!$this->_opened || $this->_reopen) {
$this->_opened = openlog($this->_ident, LOG_PID, $this->_name);
}
return false;
}
- /* If the connection isn't open and can't be opened, return failure. */
- if (!$this->_opened && !$this->open()) {
+ /* If we need to (re)open the connection and open() fails, abort. */
+ if ((!$this->_opened || $this->_reopen) && !$this->open()) {
return false;
}
$priority |= $this->_name;
}
+ /* Apply the configured line format to the message string. */
+ $message = $this->_format($this->_lineFormat,
+ strftime($this->_timeFormat),
+ $priority, $message);
+
/* Split the string into parts based on our maximum length setting. */
$parts = str_split($message, $this->_maxLength);
if ($parts === false) {
return $err;
}
- $db = new $class_name();
+ $db =& new $class_name();
$db->setDSN($dsninfo);
$err = MDB2::setOptions($db, $options);
if (PEAR::isError($err)) {
"unable to load module '$module' into property '$property'", __FUNCTION__);
return $err;
}
- $this->{$property} = new $class_name($this->db_index);
- $this->modules[$module] = $this->{$property};
+ $this->{$property} =& new $class_name($this->db_index);
+ $this->modules[$module] =& $this->{$property};
if ($version) {
// this will be used in the connect method to determine if the module
// needs to be loaded with a different version if the server
$module = $this->options['modules'][$match[1]];
$method = strtolower($match[2]).$match[3];
if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
- $result = $this->loadModule($module);
+ $result =& $this->loadModule($module);
if (PEAR::isError($result)) {
return $result;
}
return $connection;
}
- $result = $this->_doQuery($query, $is_manip, $connection, false);
+ $result =& $this->_doQuery($query, $is_manip, $connection, false);
if (PEAR::isError($result)) {
return $result;
}
$affected_rows = $this->_affectedRows($connection, $result);
return $affected_rows;
}
- $result = $this->_wrapResult($result, $types, true, false, $limit, $offset);
+ $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
return $result;
}
}
$query = $result;
}
- $err = $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $err;
}
return $connection;
}
- $result = $this->_doQuery($query, true, $connection, $this->database_name);
+ $result =& $this->_doQuery($query, true, $connection, $this->database_name);
if (PEAR::isError($result)) {
return $result;
}
return $connection;
}
- $result = $this->_doQuery($query, false, $connection, $this->database_name);
+ $result =& $this->_doQuery($query, false, $connection, $this->database_name);
if (PEAR::isError($result)) {
return $result;
}
- $result = $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
+ $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
return $result;
}
if ($result_class) {
$class_name = sprintf($result_class, $this->phptype);
if (!MDB2::classExists($class_name)) {
- $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result class does not exist '.$class_name, __FUNCTION__);
return $err;
}
- $result = new $class_name($this, $result, $limit, $offset);
+ $result =& new $class_name($this, $result, $limit, $offset);
if (!MDB2::isResultCommon($result)) {
- $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result class is not extended from MDB2_Result_Common', __FUNCTION__);
return $err;
}
}
if ($result_wrap_class) {
if (!MDB2::classExists($result_wrap_class)) {
- $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
return $err;
}
- $result = new $result_wrap_class($result, $this->fetchmode);
+ $result =& new $result_wrap_class($result, $this->fetchmode);
}
return $result;
}
$condition = ' WHERE '.implode(' AND ', $condition);
$query = "DELETE FROM $table$condition";
- $result = $this->_doQuery($query, true, $connection);
+ $result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) {
$affected_rows = $this->_affectedRows($connection, $result);
$insert = implode(', ', array_keys($values));
$values = implode(', ', $values);
$query = "INSERT INTO $table ($insert) VALUES ($values)";
- $result = $this->_doQuery($query, true, $connection);
+ $result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) {
$affected_rows += $this->_affectedRows($connection, $result);;
}
if ($placeholder_type == ':') {
$parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
if ($parameter === '') {
- $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'named parameter with an empty name', __FUNCTION__);
return $err;
}
}
$class_name = 'MDB2_Statement_'.$this->phptype;
$statement = null;
- $obj = new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
+ $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
$this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
return $obj;
}
if ($ignore['end'] === "\n") {
$end_quote = strlen($query) - 1;
} else {
- $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+ $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
'query with an unterminated text string specified', __FUNCTION__);
return $err;
}
*/
function __construct(&$db, &$result, $limit = 0, $offset = 0)
{
- $this->db = $db;
- $this->result = $result;
+ $this->db =& $db;
+ $this->result =& $result;
$this->offset = $offset;
$this->limit = max(0, $limit - 1);
}
*/
function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
{
- $err = $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+ $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $err;
}
}
$column = $column_names[$column];
}
- $this->values[$column] = $value;
+ $this->values[$column] =& $value;
if (!is_null($type)) {
$this->types[$column] = $type;
}
*/
function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
{
- $this->db = $db;
- $this->statement = $statement;
+ $this->db =& $db;
+ $this->statement =& $statement;
$this->positions = $positions;
$this->query = $query;
$this->types = (array)$types;
return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
}
- $this->values[$parameter] = $value;
+ $this->values[$parameter] =& $value;
if (!is_null($type)) {
$this->types[$parameter] = $type;
}
'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
}
}
- $result = $this->_execute($result_class, $result_wrap_class);
+ $result =& $this->_execute($result_class, $result_wrap_class);
return $result;
}
if ($this->is_manip) {
$result = $this->db->exec($query);
} else {
- $result = $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
+ $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
}
return $result;
}
function &getDBInstance()
{
if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
- $result = $GLOBALS['_MDB2_databases'][$this->db_index];
+ $result =& $GLOBALS['_MDB2_databases'][$this->db_index];
} else {
- $result = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+ $result =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'could not find MDB2 instance');
}
return $result;
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Chuck Hagenbuch <chuck@horde.org> |\r
-// +----------------------------------------------------------------------+\r
-//\r
-// $Id: Mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $\r
-\r
-require_once 'PEAR.php';\r
-\r
-/**\r
- * PEAR's Mail:: interface. Defines the interface for implementing\r
- * mailers under the PEAR hierarchy, and provides supporting functions\r
- * useful in multiple mailer backends.\r
- *\r
- * @access public\r
- * @version $Revision: 1.20 $\r
- * @package Mail\r
- */\r
-class Mail\r
-{\r
- /**\r
- * Line terminator used for separating header lines.\r
- * @var string\r
- */\r
- var $sep = "\r\n";\r
-\r
- /**\r
- * Provides an interface for generating Mail:: objects of various\r
- * types\r
- *\r
- * @param string $driver The kind of Mail:: object to instantiate.\r
- * @param array $params The parameters to pass to the Mail:: object.\r
- * @return object Mail a instance of the driver class or if fails a PEAR Error\r
- * @access public\r
- */\r
- function &factory($driver, $params = array())\r
- {\r
- $driver = strtolower($driver);\r
- @include_once 'Mail/' . $driver . '.php';\r
- $class = 'Mail_' . $driver;\r
- if (class_exists($class)) {\r
- $mailer = new $class($params);\r
- return $mailer;\r
- } else {\r
- return PEAR::raiseError('Unable to find class for driver ' . $driver);\r
- }\r
- }\r
-\r
- /**\r
- * Implements Mail::send() function using php's built-in mail()\r
- * command.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (ie, 'Subject'), and the array value\r
- * is the header value (ie, 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * Mime parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- *\r
- * @access public\r
- * @deprecated use Mail_mail::send instead\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- if (!is_array($headers)) {\r
- return PEAR::raiseError('$headers must be an array');\r
- }\r
-\r
- $result = $this->_sanitizeHeaders($headers);\r
- if (is_a($result, 'PEAR_Error')) {\r
- return $result;\r
- }\r
-\r
- // if we're passed an array of recipients, implode it.\r
- if (is_array($recipients)) {\r
- $recipients = implode(', ', $recipients);\r
- }\r
-\r
- // get the Subject out of the headers array so that we can\r
- // pass it as a seperate argument to mail().\r
- $subject = '';\r
- if (isset($headers['Subject'])) {\r
- $subject = $headers['Subject'];\r
- unset($headers['Subject']);\r
- }\r
-\r
- // flatten the headers out.\r
- list(, $text_headers) = Mail::prepareHeaders($headers);\r
-\r
- return mail($recipients, $subject, $body, $text_headers);\r
- }\r
-\r
- /**\r
- * Sanitize an array of mail headers by removing any additional header\r
- * strings present in a legitimate header's value. The goal of this\r
- * filter is to prevent mail injection attacks.\r
- *\r
- * @param array $headers The associative array of headers to sanitize.\r
- *\r
- * @access private\r
- */\r
- function _sanitizeHeaders(&$headers)\r
- {\r
- foreach ($headers as $key => $value) {\r
- $headers[$key] =\r
- preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',\r
- null, $value);\r
- }\r
- }\r
-\r
- /**\r
- * Take an array of mail headers and return a string containing\r
- * text usable in sending a message.\r
- *\r
- * @param array $headers The array of headers to prepare, in an associative\r
- * array, where the array key is the header name (ie,\r
- * 'Subject'), and the array value is the header\r
- * value (ie, 'test'). The header produced from those\r
- * values would be 'Subject: test'.\r
- *\r
- * @return mixed Returns false if it encounters a bad address,\r
- * otherwise returns an array containing two\r
- * elements: Any From: address found in the headers,\r
- * and the plain text version of the headers.\r
- * @access private\r
- */\r
- function prepareHeaders($headers)\r
- {\r
- $lines = array();\r
- $from = null;\r
-\r
- foreach ($headers as $key => $value) {\r
- if (strcasecmp($key, 'From') === 0) {\r
- include_once 'Mail/RFC822.php';\r
- $parser = new Mail_RFC822();\r
- $addresses = $parser->parseAddressList($value, 'localhost', false);\r
- if (is_a($addresses, 'PEAR_Error')) {\r
- return $addresses;\r
- }\r
-\r
- $from = $addresses[0]->mailbox . '@' . $addresses[0]->host;\r
-\r
- // Reject envelope From: addresses with spaces.\r
- if (strstr($from, ' ')) {\r
- return false;\r
- }\r
-\r
- $lines[] = $key . ': ' . $value;\r
- } elseif (strcasecmp($key, 'Received') === 0) {\r
- $received = array();\r
- if (is_array($value)) {\r
- foreach ($value as $line) {\r
- $received[] = $key . ': ' . $line;\r
- }\r
- }\r
- else {\r
- $received[] = $key . ': ' . $value;\r
- }\r
- // Put Received: headers at the top. Spam detectors often\r
- // flag messages with Received: headers after the Subject:\r
- // as spam.\r
- $lines = array_merge($received, $lines);\r
- } else {\r
- // If $value is an array (i.e., a list of addresses), convert\r
- // it to a comma-delimited string of its elements (addresses).\r
- if (is_array($value)) {\r
- $value = implode(', ', $value);\r
- }\r
- $lines[] = $key . ': ' . $value;\r
- }\r
- }\r
-\r
- return array($from, join($this->sep, $lines));\r
- }\r
-\r
- /**\r
- * Take a set of recipients and parse them, returning an array of\r
- * bare addresses (forward paths) that can be passed to sendmail\r
- * or an smtp server with the rcpt to: command.\r
- *\r
- * @param mixed Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid.\r
- *\r
- * @return mixed An array of forward paths (bare addresses) or a PEAR_Error\r
- * object if the address list could not be parsed.\r
- * @access private\r
- */\r
- function parseRecipients($recipients)\r
- {\r
- include_once 'Mail/RFC822.php';\r
-\r
- // if we're passed an array, assume addresses are valid and\r
- // implode them before parsing.\r
- if (is_array($recipients)) {\r
- $recipients = implode(', ', $recipients);\r
- }\r
-\r
- // Parse recipients, leaving out all personal info. This is\r
- // for smtp recipients, etc. All relevant personal information\r
- // should already be in the headers.\r
- $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);\r
-\r
- // If parseAddressList() returned a PEAR_Error object, just return it.\r
- if (is_a($addresses, 'PEAR_Error')) {\r
- return $addresses;\r
- }\r
-\r
- $recipients = array();\r
- if (is_array($addresses)) {\r
- foreach ($addresses as $ob) {\r
- $recipients[] = $ob->mailbox . '@' . $ob->host;\r
- }\r
- }\r
-\r
- return $recipients;\r
- }\r
-\r
-}\r
+<?php
+/**
+ * PEAR's Mail:: interface.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2002-2007, 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.
+ *
+ * @category Mail
+ * @package Mail
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 1997-2010 Chuck Hagenbuch
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Mail.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+require_once 'PEAR.php';
+
+/**
+ * PEAR's Mail:: interface. Defines the interface for implementing
+ * mailers under the PEAR hierarchy, and provides supporting functions
+ * useful in multiple mailer backends.
+ *
+ * @access public
+ * @version $Revision: 294747 $
+ * @package Mail
+ */
+class Mail
+{
+ /**
+ * Line terminator used for separating header lines.
+ * @var string
+ */
+ var $sep = "\r\n";
+
+ /**
+ * Provides an interface for generating Mail:: objects of various
+ * types
+ *
+ * @param string $driver The kind of Mail:: object to instantiate.
+ * @param array $params The parameters to pass to the Mail:: object.
+ * @return object Mail a instance of the driver class or if fails a PEAR Error
+ * @access public
+ */
+ function &factory($driver, $params = array())
+ {
+ $driver = strtolower($driver);
+ @include_once 'Mail/' . $driver . '.php';
+ $class = 'Mail_' . $driver;
+ if (class_exists($class)) {
+ $mailer = new $class($params);
+ return $mailer;
+ } else {
+ return PEAR::raiseError('Unable to find class for driver ' . $driver);
+ }
+ }
+
+ /**
+ * Implements Mail::send() function using php's built-in mail()
+ * command.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (ie, 'Subject'), and the array value
+ * is the header value (ie, 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * Mime parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ *
+ * @access public
+ * @deprecated use Mail_mail::send instead
+ */
+ function send($recipients, $headers, $body)
+ {
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ $result = $this->_sanitizeHeaders($headers);
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ // if we're passed an array of recipients, implode it.
+ if (is_array($recipients)) {
+ $recipients = implode(', ', $recipients);
+ }
+
+ // get the Subject out of the headers array so that we can
+ // pass it as a seperate argument to mail().
+ $subject = '';
+ if (isset($headers['Subject'])) {
+ $subject = $headers['Subject'];
+ unset($headers['Subject']);
+ }
+
+ // flatten the headers out.
+ list(, $text_headers) = Mail::prepareHeaders($headers);
+
+ return mail($recipients, $subject, $body, $text_headers);
+ }
+
+ /**
+ * Sanitize an array of mail headers by removing any additional header
+ * strings present in a legitimate header's value. The goal of this
+ * filter is to prevent mail injection attacks.
+ *
+ * @param array $headers The associative array of headers to sanitize.
+ *
+ * @access private
+ */
+ function _sanitizeHeaders(&$headers)
+ {
+ foreach ($headers as $key => $value) {
+ $headers[$key] =
+ preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',
+ null, $value);
+ }
+ }
+
+ /**
+ * Take an array of mail headers and return a string containing
+ * text usable in sending a message.
+ *
+ * @param array $headers The array of headers to prepare, in an associative
+ * array, where the array key is the header name (ie,
+ * 'Subject'), and the array value is the header
+ * value (ie, 'test'). The header produced from those
+ * values would be 'Subject: test'.
+ *
+ * @return mixed Returns false if it encounters a bad address,
+ * otherwise returns an array containing two
+ * elements: Any From: address found in the headers,
+ * and the plain text version of the headers.
+ * @access private
+ */
+ function prepareHeaders($headers)
+ {
+ $lines = array();
+ $from = null;
+
+ foreach ($headers as $key => $value) {
+ if (strcasecmp($key, 'From') === 0) {
+ include_once 'Mail/RFC822.php';
+ $parser = new Mail_RFC822();
+ $addresses = $parser->parseAddressList($value, 'localhost', false);
+ if (is_a($addresses, 'PEAR_Error')) {
+ return $addresses;
+ }
+
+ $from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
+
+ // Reject envelope From: addresses with spaces.
+ if (strstr($from, ' ')) {
+ return false;
+ }
+
+ $lines[] = $key . ': ' . $value;
+ } elseif (strcasecmp($key, 'Received') === 0) {
+ $received = array();
+ if (is_array($value)) {
+ foreach ($value as $line) {
+ $received[] = $key . ': ' . $line;
+ }
+ }
+ else {
+ $received[] = $key . ': ' . $value;
+ }
+ // Put Received: headers at the top. Spam detectors often
+ // flag messages with Received: headers after the Subject:
+ // as spam.
+ $lines = array_merge($received, $lines);
+ } else {
+ // If $value is an array (i.e., a list of addresses), convert
+ // it to a comma-delimited string of its elements (addresses).
+ if (is_array($value)) {
+ $value = implode(', ', $value);
+ }
+ $lines[] = $key . ': ' . $value;
+ }
+ }
+
+ return array($from, join($this->sep, $lines));
+ }
+
+ /**
+ * Take a set of recipients and parse them, returning an array of
+ * bare addresses (forward paths) that can be passed to sendmail
+ * or an smtp server with the rcpt to: command.
+ *
+ * @param mixed Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid.
+ *
+ * @return mixed An array of forward paths (bare addresses) or a PEAR_Error
+ * object if the address list could not be parsed.
+ * @access private
+ */
+ function parseRecipients($recipients)
+ {
+ include_once 'Mail/RFC822.php';
+
+ // if we're passed an array, assume addresses are valid and
+ // implode them before parsing.
+ if (is_array($recipients)) {
+ $recipients = implode(', ', $recipients);
+ }
+
+ // Parse recipients, leaving out all personal info. This is
+ // for smtp recipients, etc. All relevant personal information
+ // should already be in the headers.
+ $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
+
+ // If parseAddressList() returned a PEAR_Error object, just return it.
+ if (is_a($addresses, 'PEAR_Error')) {
+ return $addresses;
+ }
+
+ $recipients = array();
+ if (is_array($addresses)) {
+ foreach ($addresses as $ob) {
+ $recipients[] = $ob->mailbox . '@' . $ob->host;
+ }
+ }
+
+ return $recipients;
+ }
+
+}
-<?php\r
-// +-----------------------------------------------------------------------+\r
-// | Copyright (c) 2001-2002, Richard Heyes |\r
-// | All rights reserved. |\r
-// | |\r
-// | Redistribution and use in source and binary forms, with or without |\r
-// | modification, are permitted provided that the following conditions |\r
-// | are met: |\r
-// | |\r
-// | o Redistributions of source code must retain the above copyright |\r
-// | notice, this list of conditions and the following disclaimer. |\r
-// | o Redistributions in binary form must reproduce the above copyright |\r
-// | notice, this list of conditions and the following disclaimer in the |\r
-// | documentation and/or other materials provided with the distribution.|\r
-// | o The names of the authors may not be used to endorse or promote |\r
-// | products derived from this software without specific prior written |\r
-// | permission. |\r
-// | |\r
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |\r
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |\r
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |\r
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |\r
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |\r
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |\r
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |\r
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |\r
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |\r
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |\r
-// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |\r
-// | |\r
-// +-----------------------------------------------------------------------+\r
-// | Authors: Richard Heyes <richard@phpguru.org> |\r
-// | Chuck Hagenbuch <chuck@horde.org> |\r
-// +-----------------------------------------------------------------------+\r
-\r
-/**\r
- * RFC 822 Email address list validation Utility\r
- *\r
- * What is it?\r
- *\r
- * This class will take an address string, and parse it into it's consituent\r
- * parts, be that either addresses, groups, or combinations. Nested groups\r
- * are not supported. The structure it returns is pretty straight forward,\r
- * and is similar to that provided by the imap_rfc822_parse_adrlist(). Use\r
- * print_r() to view the structure.\r
- *\r
- * How do I use it?\r
- *\r
- * $address_string = 'My Group: "Richard" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;';\r
- * $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', true)\r
- * print_r($structure);\r
- *\r
- * @author Richard Heyes <richard@phpguru.org>\r
- * @author Chuck Hagenbuch <chuck@horde.org>\r
- * @version $Revision: 1.24 $\r
- * @license BSD\r
- * @package Mail\r
- */\r
-class Mail_RFC822 {\r
-\r
- /**\r
- * The address being parsed by the RFC822 object.\r
- * @var string $address\r
- */\r
- var $address = '';\r
-\r
- /**\r
- * The default domain to use for unqualified addresses.\r
- * @var string $default_domain\r
- */\r
- var $default_domain = 'localhost';\r
-\r
- /**\r
- * Should we return a nested array showing groups, or flatten everything?\r
- * @var boolean $nestGroups\r
- */\r
- var $nestGroups = true;\r
-\r
- /**\r
- * Whether or not to validate atoms for non-ascii characters.\r
- * @var boolean $validate\r
- */\r
- var $validate = true;\r
-\r
- /**\r
- * The array of raw addresses built up as we parse.\r
- * @var array $addresses\r
- */\r
- var $addresses = array();\r
-\r
- /**\r
- * The final array of parsed address information that we build up.\r
- * @var array $structure\r
- */\r
- var $structure = array();\r
-\r
- /**\r
- * The current error message, if any.\r
- * @var string $error\r
- */\r
- var $error = null;\r
-\r
- /**\r
- * An internal counter/pointer.\r
- * @var integer $index\r
- */\r
- var $index = null;\r
-\r
- /**\r
- * The number of groups that have been found in the address list.\r
- * @var integer $num_groups\r
- * @access public\r
- */\r
- var $num_groups = 0;\r
-\r
- /**\r
- * A variable so that we can tell whether or not we're inside a\r
- * Mail_RFC822 object.\r
- * @var boolean $mailRFC822\r
- */\r
- var $mailRFC822 = true;\r
-\r
- /**\r
- * A limit after which processing stops\r
- * @var int $limit\r
- */\r
- var $limit = null;\r
-\r
- /**\r
- * Sets up the object. The address must either be set here or when\r
- * calling parseAddressList(). One or the other.\r
- *\r
- * @access public\r
- * @param string $address The address(es) to validate.\r
- * @param string $default_domain Default domain/host etc. If not supplied, will be set to localhost.\r
- * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.\r
- * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.\r
- *\r
- * @return object Mail_RFC822 A new Mail_RFC822 object.\r
- */\r
- function Mail_RFC822($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)\r
- {\r
- if (isset($address)) $this->address = $address;\r
- if (isset($default_domain)) $this->default_domain = $default_domain;\r
- if (isset($nest_groups)) $this->nestGroups = $nest_groups;\r
- if (isset($validate)) $this->validate = $validate;\r
- if (isset($limit)) $this->limit = $limit;\r
- }\r
-\r
- /**\r
- * Starts the whole process. The address must either be set here\r
- * or when creating the object. One or the other.\r
- *\r
- * @access public\r
- * @param string $address The address(es) to validate.\r
- * @param string $default_domain Default domain/host etc.\r
- * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.\r
- * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.\r
- *\r
- * @return array A structured array of addresses.\r
- */\r
- function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)\r
- {\r
- if (!isset($this) || !isset($this->mailRFC822)) {\r
- $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);\r
- return $obj->parseAddressList();\r
- }\r
-\r
- if (isset($address)) $this->address = $address;\r
- if (isset($default_domain)) $this->default_domain = $default_domain;\r
- if (isset($nest_groups)) $this->nestGroups = $nest_groups;\r
- if (isset($validate)) $this->validate = $validate;\r
- if (isset($limit)) $this->limit = $limit;\r
-\r
- $this->structure = array();\r
- $this->addresses = array();\r
- $this->error = null;\r
- $this->index = null;\r
-\r
- // Unfold any long lines in $this->address.\r
- $this->address = preg_replace('/\r?\n/', "\r\n", $this->address);\r
- $this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);\r
-\r
- while ($this->address = $this->_splitAddresses($this->address));\r
-\r
- if ($this->address === false || isset($this->error)) {\r
- require_once 'PEAR.php';\r
- return PEAR::raiseError($this->error);\r
- }\r
-\r
- // Validate each address individually. If we encounter an invalid\r
- // address, stop iterating and return an error immediately.\r
- foreach ($this->addresses as $address) {\r
- $valid = $this->_validateAddress($address);\r
-\r
- if ($valid === false || isset($this->error)) {\r
- require_once 'PEAR.php';\r
- return PEAR::raiseError($this->error);\r
- }\r
-\r
- if (!$this->nestGroups) {\r
- $this->structure = array_merge($this->structure, $valid);\r
- } else {\r
- $this->structure[] = $valid;\r
- }\r
- }\r
-\r
- return $this->structure;\r
- }\r
-\r
- /**\r
- * Splits an address into separate addresses.\r
- *\r
- * @access private\r
- * @param string $address The addresses to split.\r
- * @return boolean Success or failure.\r
- */\r
- function _splitAddresses($address)\r
- {\r
- if (!empty($this->limit) && count($this->addresses) == $this->limit) {\r
- return '';\r
- }\r
-\r
- if ($this->_isGroup($address) && !isset($this->error)) {\r
- $split_char = ';';\r
- $is_group = true;\r
- } elseif (!isset($this->error)) {\r
- $split_char = ',';\r
- $is_group = false;\r
- } elseif (isset($this->error)) {\r
- return false;\r
- }\r
-\r
- // Split the string based on the above ten or so lines.\r
- $parts = explode($split_char, $address);\r
- $string = $this->_splitCheck($parts, $split_char);\r
-\r
- // If a group...\r
- if ($is_group) {\r
- // If $string does not contain a colon outside of\r
- // brackets/quotes etc then something's fubar.\r
-\r
- // First check there's a colon at all:\r
- if (strpos($string, ':') === false) {\r
- $this->error = 'Invalid address: ' . $string;\r
- return false;\r
- }\r
-\r
- // Now check it's outside of brackets/quotes:\r
- if (!$this->_splitCheck(explode(':', $string), ':')) {\r
- return false;\r
- }\r
-\r
- // We must have a group at this point, so increase the counter:\r
- $this->num_groups++;\r
- }\r
-\r
- // $string now contains the first full address/group.\r
- // Add to the addresses array.\r
- $this->addresses[] = array(\r
- 'address' => trim($string),\r
- 'group' => $is_group\r
- );\r
-\r
- // Remove the now stored address from the initial line, the +1\r
- // is to account for the explode character.\r
- $address = trim(substr($address, strlen($string) + 1));\r
-\r
- // If the next char is a comma and this was a group, then\r
- // there are more addresses, otherwise, if there are any more\r
- // chars, then there is another address.\r
- if ($is_group && substr($address, 0, 1) == ','){\r
- $address = trim(substr($address, 1));\r
- return $address;\r
-\r
- } elseif (strlen($address) > 0) {\r
- return $address;\r
-\r
- } else {\r
- return '';\r
- }\r
-\r
- // If you got here then something's off\r
- return false;\r
- }\r
-\r
- /**\r
- * Checks for a group at the start of the string.\r
- *\r
- * @access private\r
- * @param string $address The address to check.\r
- * @return boolean Whether or not there is a group at the start of the string.\r
- */\r
- function _isGroup($address)\r
- {\r
- // First comma not in quotes, angles or escaped:\r
- $parts = explode(',', $address);\r
- $string = $this->_splitCheck($parts, ',');\r
-\r
- // Now we have the first address, we can reliably check for a\r
- // group by searching for a colon that's not escaped or in\r
- // quotes or angle brackets.\r
- if (count($parts = explode(':', $string)) > 1) {\r
- $string2 = $this->_splitCheck($parts, ':');\r
- return ($string2 !== $string);\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * A common function that will check an exploded string.\r
- *\r
- * @access private\r
- * @param array $parts The exloded string.\r
- * @param string $char The char that was exploded on.\r
- * @return mixed False if the string contains unclosed quotes/brackets, or the string on success.\r
- */\r
- function _splitCheck($parts, $char)\r
- {\r
- $string = $parts[0];\r
-\r
- for ($i = 0; $i < count($parts); $i++) {\r
- if ($this->_hasUnclosedQuotes($string)\r
- || $this->_hasUnclosedBrackets($string, '<>')\r
- || $this->_hasUnclosedBrackets($string, '[]')\r
- || $this->_hasUnclosedBrackets($string, '()')\r
- || substr($string, -1) == '\\') {\r
- if (isset($parts[$i + 1])) {\r
- $string = $string . $char . $parts[$i + 1];\r
- } else {\r
- $this->error = 'Invalid address spec. Unclosed bracket or quotes';\r
- return false;\r
- }\r
- } else {\r
- $this->index = $i;\r
- break;\r
- }\r
- }\r
-\r
- return $string;\r
- }\r
-\r
- /**\r
- * Checks if a string has unclosed quotes or not.\r
- *\r
- * @access private\r
- * @param string $string The string to check.\r
- * @return boolean True if there are unclosed quotes inside the string,\r
- * false otherwise.\r
- */\r
- function _hasUnclosedQuotes($string)\r
- {\r
- $string = trim($string);\r
- $iMax = strlen($string);\r
- $in_quote = false;\r
- $i = $slashes = 0;\r
-\r
- for (; $i < $iMax; ++$i) {\r
- switch ($string[$i]) {\r
- case '\\':\r
- ++$slashes;\r
- break;\r
-\r
- case '"':\r
- if ($slashes % 2 == 0) {\r
- $in_quote = !$in_quote;\r
- }\r
- // Fall through to default action below.\r
-\r
- default:\r
- $slashes = 0;\r
- break;\r
- }\r
- }\r
-\r
- return $in_quote;\r
- }\r
-\r
- /**\r
- * Checks if a string has an unclosed brackets or not. IMPORTANT:\r
- * This function handles both angle brackets and square brackets;\r
- *\r
- * @access private\r
- * @param string $string The string to check.\r
- * @param string $chars The characters to check for.\r
- * @return boolean True if there are unclosed brackets inside the string, false otherwise.\r
- */\r
- function _hasUnclosedBrackets($string, $chars)\r
- {\r
- $num_angle_start = substr_count($string, $chars[0]);\r
- $num_angle_end = substr_count($string, $chars[1]);\r
-\r
- $this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);\r
- $this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);\r
-\r
- if ($num_angle_start < $num_angle_end) {\r
- $this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';\r
- return false;\r
- } else {\r
- return ($num_angle_start > $num_angle_end);\r
- }\r
- }\r
-\r
- /**\r
- * Sub function that is used only by hasUnclosedBrackets().\r
- *\r
- * @access private\r
- * @param string $string The string to check.\r
- * @param integer &$num The number of occurences.\r
- * @param string $char The character to count.\r
- * @return integer The number of occurences of $char in $string, adjusted for backslashes.\r
- */\r
- function _hasUnclosedBracketsSub($string, &$num, $char)\r
- {\r
- $parts = explode($char, $string);\r
- for ($i = 0; $i < count($parts); $i++){\r
- if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))\r
- $num--;\r
- if (isset($parts[$i + 1]))\r
- $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];\r
- }\r
-\r
- return $num;\r
- }\r
-\r
- /**\r
- * Function to begin checking the address.\r
- *\r
- * @access private\r
- * @param string $address The address to validate.\r
- * @return mixed False on failure, or a structured array of address information on success.\r
- */\r
- function _validateAddress($address)\r
- {\r
- $is_group = false;\r
- $addresses = array();\r
-\r
- if ($address['group']) {\r
- $is_group = true;\r
-\r
- // Get the group part of the name\r
- $parts = explode(':', $address['address']);\r
- $groupname = $this->_splitCheck($parts, ':');\r
- $structure = array();\r
-\r
- // And validate the group part of the name.\r
- if (!$this->_validatePhrase($groupname)){\r
- $this->error = 'Group name did not validate.';\r
- return false;\r
- } else {\r
- // Don't include groups if we are not nesting\r
- // them. This avoids returning invalid addresses.\r
- if ($this->nestGroups) {\r
- $structure = new stdClass;\r
- $structure->groupname = $groupname;\r
- }\r
- }\r
-\r
- $address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));\r
- }\r
-\r
- // If a group then split on comma and put into an array.\r
- // Otherwise, Just put the whole address in an array.\r
- if ($is_group) {\r
- while (strlen($address['address']) > 0) {\r
- $parts = explode(',', $address['address']);\r
- $addresses[] = $this->_splitCheck($parts, ',');\r
- $address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));\r
- }\r
- } else {\r
- $addresses[] = $address['address'];\r
- }\r
-\r
- // Check that $addresses is set, if address like this:\r
- // Groupname:;\r
- // Then errors were appearing.\r
- if (!count($addresses)){\r
- $this->error = 'Empty group.';\r
- return false;\r
- }\r
-\r
- // Trim the whitespace from all of the address strings.\r
- array_map('trim', $addresses);\r
-\r
- // Validate each mailbox.\r
- // Format could be one of: name <geezer@domain.com>\r
- // geezer@domain.com\r
- // geezer\r
- // ... or any other format valid by RFC 822.\r
- for ($i = 0; $i < count($addresses); $i++) {\r
- if (!$this->validateMailbox($addresses[$i])) {\r
- if (empty($this->error)) {\r
- $this->error = 'Validation failed for: ' . $addresses[$i];\r
- }\r
- return false;\r
- }\r
- }\r
-\r
- // Nested format\r
- if ($this->nestGroups) {\r
- if ($is_group) {\r
- $structure->addresses = $addresses;\r
- } else {\r
- $structure = $addresses[0];\r
- }\r
-\r
- // Flat format\r
- } else {\r
- if ($is_group) {\r
- $structure = array_merge($structure, $addresses);\r
- } else {\r
- $structure = $addresses;\r
- }\r
- }\r
-\r
- return $structure;\r
- }\r
-\r
- /**\r
- * Function to validate a phrase.\r
- *\r
- * @access private\r
- * @param string $phrase The phrase to check.\r
- * @return boolean Success or failure.\r
- */\r
- function _validatePhrase($phrase)\r
- {\r
- // Splits on one or more Tab or space.\r
- $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);\r
-\r
- $phrase_parts = array();\r
- while (count($parts) > 0){\r
- $phrase_parts[] = $this->_splitCheck($parts, ' ');\r
- for ($i = 0; $i < $this->index + 1; $i++)\r
- array_shift($parts);\r
- }\r
-\r
- foreach ($phrase_parts as $part) {\r
- // If quoted string:\r
- if (substr($part, 0, 1) == '"') {\r
- if (!$this->_validateQuotedString($part)) {\r
- return false;\r
- }\r
- continue;\r
- }\r
-\r
- // Otherwise it's an atom:\r
- if (!$this->_validateAtom($part)) return false;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Function to validate an atom which from rfc822 is:\r
- * atom = 1*<any CHAR except specials, SPACE and CTLs>\r
- *\r
- * If validation ($this->validate) has been turned off, then\r
- * validateAtom() doesn't actually check anything. This is so that you\r
- * can split a list of addresses up before encoding personal names\r
- * (umlauts, etc.), for example.\r
- *\r
- * @access private\r
- * @param string $atom The string to check.\r
- * @return boolean Success or failure.\r
- */\r
- function _validateAtom($atom)\r
- {\r
- if (!$this->validate) {\r
- // Validation has been turned off; assume the atom is okay.\r
- return true;\r
- }\r
-\r
- // Check for any char from ASCII 0 - ASCII 127\r
- if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {\r
- return false;\r
- }\r
-\r
- // Check for specials:\r
- if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {\r
- return false;\r
- }\r
-\r
- // Check for control characters (ASCII 0-31):\r
- if (preg_match('/[\\x00-\\x1F]+/', $atom)) {\r
- return false;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Function to validate quoted string, which is:\r
- * quoted-string = <"> *(qtext/quoted-pair) <">\r
- *\r
- * @access private\r
- * @param string $qstring The string to check\r
- * @return boolean Success or failure.\r
- */\r
- function _validateQuotedString($qstring)\r
- {\r
- // Leading and trailing "\r
- $qstring = substr($qstring, 1, -1);\r
-\r
- // Perform check, removing quoted characters first.\r
- return !preg_match('/[\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));\r
- }\r
-\r
- /**\r
- * Function to validate a mailbox, which is:\r
- * mailbox = addr-spec ; simple address\r
- * / phrase route-addr ; name and route-addr\r
- *\r
- * @access public\r
- * @param string &$mailbox The string to check.\r
- * @return boolean Success or failure.\r
- */\r
- function validateMailbox(&$mailbox)\r
- {\r
- // A couple of defaults.\r
- $phrase = '';\r
- $comment = '';\r
- $comments = array();\r
-\r
- // Catch any RFC822 comments and store them separately.\r
- $_mailbox = $mailbox;\r
- while (strlen(trim($_mailbox)) > 0) {\r
- $parts = explode('(', $_mailbox);\r
- $before_comment = $this->_splitCheck($parts, '(');\r
- if ($before_comment != $_mailbox) {\r
- // First char should be a (.\r
- $comment = substr(str_replace($before_comment, '', $_mailbox), 1);\r
- $parts = explode(')', $comment);\r
- $comment = $this->_splitCheck($parts, ')');\r
- $comments[] = $comment;\r
-\r
- // +1 is for the trailing )\r
- $_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1);\r
- } else {\r
- break;\r
- }\r
- }\r
-\r
- foreach ($comments as $comment) {\r
- $mailbox = str_replace("($comment)", '', $mailbox);\r
- }\r
-\r
- $mailbox = trim($mailbox);\r
-\r
- // Check for name + route-addr\r
- if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {\r
- $parts = explode('<', $mailbox);\r
- $name = $this->_splitCheck($parts, '<');\r
-\r
- $phrase = trim($name);\r
- $route_addr = trim(substr($mailbox, strlen($name.'<'), -1));\r
-\r
- if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {\r
- return false;\r
- }\r
-\r
- // Only got addr-spec\r
- } else {\r
- // First snip angle brackets if present.\r
- if (substr($mailbox, 0, 1) == '<' && substr($mailbox, -1) == '>') {\r
- $addr_spec = substr($mailbox, 1, -1);\r
- } else {\r
- $addr_spec = $mailbox;\r
- }\r
-\r
- if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {\r
- return false;\r
- }\r
- }\r
-\r
- // Construct the object that will be returned.\r
- $mbox = new stdClass();\r
-\r
- // Add the phrase (even if empty) and comments\r
- $mbox->personal = $phrase;\r
- $mbox->comment = isset($comments) ? $comments : array();\r
-\r
- if (isset($route_addr)) {\r
- $mbox->mailbox = $route_addr['local_part'];\r
- $mbox->host = $route_addr['domain'];\r
- $route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';\r
- } else {\r
- $mbox->mailbox = $addr_spec['local_part'];\r
- $mbox->host = $addr_spec['domain'];\r
- }\r
-\r
- $mailbox = $mbox;\r
- return true;\r
- }\r
-\r
- /**\r
- * This function validates a route-addr which is:\r
- * route-addr = "<" [route] addr-spec ">"\r
- *\r
- * Angle brackets have already been removed at the point of\r
- * getting to this function.\r
- *\r
- * @access private\r
- * @param string $route_addr The string to check.\r
- * @return mixed False on failure, or an array containing validated address/route information on success.\r
- */\r
- function _validateRouteAddr($route_addr)\r
- {\r
- // Check for colon.\r
- if (strpos($route_addr, ':') !== false) {\r
- $parts = explode(':', $route_addr);\r
- $route = $this->_splitCheck($parts, ':');\r
- } else {\r
- $route = $route_addr;\r
- }\r
-\r
- // If $route is same as $route_addr then the colon was in\r
- // quotes or brackets or, of course, non existent.\r
- if ($route === $route_addr){\r
- unset($route);\r
- $addr_spec = $route_addr;\r
- if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {\r
- return false;\r
- }\r
- } else {\r
- // Validate route part.\r
- if (($route = $this->_validateRoute($route)) === false) {\r
- return false;\r
- }\r
-\r
- $addr_spec = substr($route_addr, strlen($route . ':'));\r
-\r
- // Validate addr-spec part.\r
- if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {\r
- return false;\r
- }\r
- }\r
-\r
- if (isset($route)) {\r
- $return['adl'] = $route;\r
- } else {\r
- $return['adl'] = '';\r
- }\r
-\r
- $return = array_merge($return, $addr_spec);\r
- return $return;\r
- }\r
-\r
- /**\r
- * Function to validate a route, which is:\r
- * route = 1#("@" domain) ":"\r
- *\r
- * @access private\r
- * @param string $route The string to check.\r
- * @return mixed False on failure, or the validated $route on success.\r
- */\r
- function _validateRoute($route)\r
- {\r
- // Split on comma.\r
- $domains = explode(',', trim($route));\r
-\r
- foreach ($domains as $domain) {\r
- $domain = str_replace('@', '', trim($domain));\r
- if (!$this->_validateDomain($domain)) return false;\r
- }\r
-\r
- return $route;\r
- }\r
-\r
- /**\r
- * Function to validate a domain, though this is not quite what\r
- * you expect of a strict internet domain.\r
- *\r
- * domain = sub-domain *("." sub-domain)\r
- *\r
- * @access private\r
- * @param string $domain The string to check.\r
- * @return mixed False on failure, or the validated domain on success.\r
- */\r
- function _validateDomain($domain)\r
- {\r
- // Note the different use of $subdomains and $sub_domains\r
- $subdomains = explode('.', $domain);\r
-\r
- while (count($subdomains) > 0) {\r
- $sub_domains[] = $this->_splitCheck($subdomains, '.');\r
- for ($i = 0; $i < $this->index + 1; $i++)\r
- array_shift($subdomains);\r
- }\r
-\r
- foreach ($sub_domains as $sub_domain) {\r
- if (!$this->_validateSubdomain(trim($sub_domain)))\r
- return false;\r
- }\r
-\r
- // Managed to get here, so return input.\r
- return $domain;\r
- }\r
-\r
- /**\r
- * Function to validate a subdomain:\r
- * subdomain = domain-ref / domain-literal\r
- *\r
- * @access private\r
- * @param string $subdomain The string to check.\r
- * @return boolean Success or failure.\r
- */\r
- function _validateSubdomain($subdomain)\r
- {\r
- if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){\r
- if (!$this->_validateDliteral($arr[1])) return false;\r
- } else {\r
- if (!$this->_validateAtom($subdomain)) return false;\r
- }\r
-\r
- // Got here, so return successful.\r
- return true;\r
- }\r
-\r
- /**\r
- * Function to validate a domain literal:\r
- * domain-literal = "[" *(dtext / quoted-pair) "]"\r
- *\r
- * @access private\r
- * @param string $dliteral The string to check.\r
- * @return boolean Success or failure.\r
- */\r
- function _validateDliteral($dliteral)\r
- {\r
- return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';\r
- }\r
-\r
- /**\r
- * Function to validate an addr-spec.\r
- *\r
- * addr-spec = local-part "@" domain\r
- *\r
- * @access private\r
- * @param string $addr_spec The string to check.\r
- * @return mixed False on failure, or the validated addr-spec on success.\r
- */\r
- function _validateAddrSpec($addr_spec)\r
- {\r
- $addr_spec = trim($addr_spec);\r
-\r
- // Split on @ sign if there is one.\r
- if (strpos($addr_spec, '@') !== false) {\r
- $parts = explode('@', $addr_spec);\r
- $local_part = $this->_splitCheck($parts, '@');\r
- $domain = substr($addr_spec, strlen($local_part . '@'));\r
-\r
- // No @ sign so assume the default domain.\r
- } else {\r
- $local_part = $addr_spec;\r
- $domain = $this->default_domain;\r
- }\r
-\r
- if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;\r
- if (($domain = $this->_validateDomain($domain)) === false) return false;\r
-\r
- // Got here so return successful.\r
- return array('local_part' => $local_part, 'domain' => $domain);\r
- }\r
-\r
- /**\r
- * Function to validate the local part of an address:\r
- * local-part = word *("." word)\r
- *\r
- * @access private\r
- * @param string $local_part\r
- * @return mixed False on failure, or the validated local part on success.\r
- */\r
- function _validateLocalPart($local_part)\r
- {\r
- $parts = explode('.', $local_part);\r
- $words = array();\r
-\r
- // Split the local_part into words.\r
- while (count($parts) > 0){\r
- $words[] = $this->_splitCheck($parts, '.');\r
- for ($i = 0; $i < $this->index + 1; $i++) {\r
- array_shift($parts);\r
- }\r
- }\r
-\r
- // Validate each word.\r
- foreach ($words as $word) {\r
- // If this word contains an unquoted space, it is invalid. (6.2.4)\r
- if (strpos($word, ' ') && $word[0] !== '"')\r
- {\r
- return false;\r
- }\r
-\r
- if ($this->_validatePhrase(trim($word)) === false) return false;\r
- }\r
-\r
- // Managed to get here, so return the input.\r
- return $local_part;\r
- }\r
-\r
- /**\r
- * Returns an approximate count of how many addresses are in the\r
- * given string. This is APPROXIMATE as it only splits based on a\r
- * comma which has no preceding backslash. Could be useful as\r
- * large amounts of addresses will end up producing *large*\r
- * structures when used with parseAddressList().\r
- *\r
- * @param string $data Addresses to count\r
- * @return int Approximate count\r
- */\r
- function approximateCount($data)\r
- {\r
- return count(preg_split('/(?<!\\\\),/', $data));\r
- }\r
-\r
- /**\r
- * This is a email validating function separate to the rest of the\r
- * class. It simply validates whether an email is of the common\r
- * internet form: <user>@<domain>. This can be sufficient for most\r
- * people. Optional stricter mode can be utilised which restricts\r
- * mailbox characters allowed to alphanumeric, full stop, hyphen\r
- * and underscore.\r
- *\r
- * @param string $data Address to check\r
- * @param boolean $strict Optional stricter mode\r
- * @return mixed False if it fails, an indexed array\r
- * username/domain if it matches\r
- */\r
- function isValidInetAddress($data, $strict = false)\r
- {\r
- $regex = $strict ? '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';\r
- if (preg_match($regex, trim($data), $matches)) {\r
- return array($matches[1], $matches[2]);\r
- } else {\r
- return false;\r
- }\r
- }\r
-\r
-}\r
+<?php
+/**
+ * RFC 822 Email address list validation Utility
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2001-2010, 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.
+ *
+ * @category Mail
+ * @package Mail
+ * @author Richard Heyes <richard@phpguru.org>
+ * @author Chuck Hagenbuch <chuck@horde.org
+ * @copyright 2001-2010 Richard Heyes
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: RFC822.php 294749 2010-02-08 08:22:25Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+/**
+ * RFC 822 Email address list validation Utility
+ *
+ * What is it?
+ *
+ * This class will take an address string, and parse it into it's consituent
+ * parts, be that either addresses, groups, or combinations. Nested groups
+ * are not supported. The structure it returns is pretty straight forward,
+ * and is similar to that provided by the imap_rfc822_parse_adrlist(). Use
+ * print_r() to view the structure.
+ *
+ * How do I use it?
+ *
+ * $address_string = 'My Group: "Richard" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;';
+ * $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', true)
+ * print_r($structure);
+ *
+ * @author Richard Heyes <richard@phpguru.org>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @version $Revision: 294749 $
+ * @license BSD
+ * @package Mail
+ */
+class Mail_RFC822 {
+
+ /**
+ * The address being parsed by the RFC822 object.
+ * @var string $address
+ */
+ var $address = '';
+
+ /**
+ * The default domain to use for unqualified addresses.
+ * @var string $default_domain
+ */
+ var $default_domain = 'localhost';
+
+ /**
+ * Should we return a nested array showing groups, or flatten everything?
+ * @var boolean $nestGroups
+ */
+ var $nestGroups = true;
+
+ /**
+ * Whether or not to validate atoms for non-ascii characters.
+ * @var boolean $validate
+ */
+ var $validate = true;
+
+ /**
+ * The array of raw addresses built up as we parse.
+ * @var array $addresses
+ */
+ var $addresses = array();
+
+ /**
+ * The final array of parsed address information that we build up.
+ * @var array $structure
+ */
+ var $structure = array();
+
+ /**
+ * The current error message, if any.
+ * @var string $error
+ */
+ var $error = null;
+
+ /**
+ * An internal counter/pointer.
+ * @var integer $index
+ */
+ var $index = null;
+
+ /**
+ * The number of groups that have been found in the address list.
+ * @var integer $num_groups
+ * @access public
+ */
+ var $num_groups = 0;
+
+ /**
+ * A variable so that we can tell whether or not we're inside a
+ * Mail_RFC822 object.
+ * @var boolean $mailRFC822
+ */
+ var $mailRFC822 = true;
+
+ /**
+ * A limit after which processing stops
+ * @var int $limit
+ */
+ var $limit = null;
+
+ /**
+ * Sets up the object. The address must either be set here or when
+ * calling parseAddressList(). One or the other.
+ *
+ * @access public
+ * @param string $address The address(es) to validate.
+ * @param string $default_domain Default domain/host etc. If not supplied, will be set to localhost.
+ * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
+ * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
+ *
+ * @return object Mail_RFC822 A new Mail_RFC822 object.
+ */
+ function Mail_RFC822($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
+ {
+ if (isset($address)) $this->address = $address;
+ if (isset($default_domain)) $this->default_domain = $default_domain;
+ if (isset($nest_groups)) $this->nestGroups = $nest_groups;
+ if (isset($validate)) $this->validate = $validate;
+ if (isset($limit)) $this->limit = $limit;
+ }
+
+ /**
+ * Starts the whole process. The address must either be set here
+ * or when creating the object. One or the other.
+ *
+ * @access public
+ * @param string $address The address(es) to validate.
+ * @param string $default_domain Default domain/host etc.
+ * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
+ * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
+ *
+ * @return array A structured array of addresses.
+ */
+ function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
+ {
+ if (!isset($this) || !isset($this->mailRFC822)) {
+ $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
+ return $obj->parseAddressList();
+ }
+
+ if (isset($address)) $this->address = $address;
+ if (isset($default_domain)) $this->default_domain = $default_domain;
+ if (isset($nest_groups)) $this->nestGroups = $nest_groups;
+ if (isset($validate)) $this->validate = $validate;
+ if (isset($limit)) $this->limit = $limit;
+
+ $this->structure = array();
+ $this->addresses = array();
+ $this->error = null;
+ $this->index = null;
+
+ // Unfold any long lines in $this->address.
+ $this->address = preg_replace('/\r?\n/', "\r\n", $this->address);
+ $this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);
+
+ while ($this->address = $this->_splitAddresses($this->address));
+
+ if ($this->address === false || isset($this->error)) {
+ require_once 'PEAR.php';
+ return PEAR::raiseError($this->error);
+ }
+
+ // Validate each address individually. If we encounter an invalid
+ // address, stop iterating and return an error immediately.
+ foreach ($this->addresses as $address) {
+ $valid = $this->_validateAddress($address);
+
+ if ($valid === false || isset($this->error)) {
+ require_once 'PEAR.php';
+ return PEAR::raiseError($this->error);
+ }
+
+ if (!$this->nestGroups) {
+ $this->structure = array_merge($this->structure, $valid);
+ } else {
+ $this->structure[] = $valid;
+ }
+ }
+
+ return $this->structure;
+ }
+
+ /**
+ * Splits an address into separate addresses.
+ *
+ * @access private
+ * @param string $address The addresses to split.
+ * @return boolean Success or failure.
+ */
+ function _splitAddresses($address)
+ {
+ if (!empty($this->limit) && count($this->addresses) == $this->limit) {
+ return '';
+ }
+
+ if ($this->_isGroup($address) && !isset($this->error)) {
+ $split_char = ';';
+ $is_group = true;
+ } elseif (!isset($this->error)) {
+ $split_char = ',';
+ $is_group = false;
+ } elseif (isset($this->error)) {
+ return false;
+ }
+
+ // Split the string based on the above ten or so lines.
+ $parts = explode($split_char, $address);
+ $string = $this->_splitCheck($parts, $split_char);
+
+ // If a group...
+ if ($is_group) {
+ // If $string does not contain a colon outside of
+ // brackets/quotes etc then something's fubar.
+
+ // First check there's a colon at all:
+ if (strpos($string, ':') === false) {
+ $this->error = 'Invalid address: ' . $string;
+ return false;
+ }
+
+ // Now check it's outside of brackets/quotes:
+ if (!$this->_splitCheck(explode(':', $string), ':')) {
+ return false;
+ }
+
+ // We must have a group at this point, so increase the counter:
+ $this->num_groups++;
+ }
+
+ // $string now contains the first full address/group.
+ // Add to the addresses array.
+ $this->addresses[] = array(
+ 'address' => trim($string),
+ 'group' => $is_group
+ );
+
+ // Remove the now stored address from the initial line, the +1
+ // is to account for the explode character.
+ $address = trim(substr($address, strlen($string) + 1));
+
+ // If the next char is a comma and this was a group, then
+ // there are more addresses, otherwise, if there are any more
+ // chars, then there is another address.
+ if ($is_group && substr($address, 0, 1) == ','){
+ $address = trim(substr($address, 1));
+ return $address;
+
+ } elseif (strlen($address) > 0) {
+ return $address;
+
+ } else {
+ return '';
+ }
+
+ // If you got here then something's off
+ return false;
+ }
+
+ /**
+ * Checks for a group at the start of the string.
+ *
+ * @access private
+ * @param string $address The address to check.
+ * @return boolean Whether or not there is a group at the start of the string.
+ */
+ function _isGroup($address)
+ {
+ // First comma not in quotes, angles or escaped:
+ $parts = explode(',', $address);
+ $string = $this->_splitCheck($parts, ',');
+
+ // Now we have the first address, we can reliably check for a
+ // group by searching for a colon that's not escaped or in
+ // quotes or angle brackets.
+ if (count($parts = explode(':', $string)) > 1) {
+ $string2 = $this->_splitCheck($parts, ':');
+ return ($string2 !== $string);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * A common function that will check an exploded string.
+ *
+ * @access private
+ * @param array $parts The exloded string.
+ * @param string $char The char that was exploded on.
+ * @return mixed False if the string contains unclosed quotes/brackets, or the string on success.
+ */
+ function _splitCheck($parts, $char)
+ {
+ $string = $parts[0];
+
+ for ($i = 0; $i < count($parts); $i++) {
+ if ($this->_hasUnclosedQuotes($string)
+ || $this->_hasUnclosedBrackets($string, '<>')
+ || $this->_hasUnclosedBrackets($string, '[]')
+ || $this->_hasUnclosedBrackets($string, '()')
+ || substr($string, -1) == '\\') {
+ if (isset($parts[$i + 1])) {
+ $string = $string . $char . $parts[$i + 1];
+ } else {
+ $this->error = 'Invalid address spec. Unclosed bracket or quotes';
+ return false;
+ }
+ } else {
+ $this->index = $i;
+ break;
+ }
+ }
+
+ return $string;
+ }
+
+ /**
+ * Checks if a string has unclosed quotes or not.
+ *
+ * @access private
+ * @param string $string The string to check.
+ * @return boolean True if there are unclosed quotes inside the string,
+ * false otherwise.
+ */
+ function _hasUnclosedQuotes($string)
+ {
+ $string = trim($string);
+ $iMax = strlen($string);
+ $in_quote = false;
+ $i = $slashes = 0;
+
+ for (; $i < $iMax; ++$i) {
+ switch ($string[$i]) {
+ case '\\':
+ ++$slashes;
+ break;
+
+ case '"':
+ if ($slashes % 2 == 0) {
+ $in_quote = !$in_quote;
+ }
+ // Fall through to default action below.
+
+ default:
+ $slashes = 0;
+ break;
+ }
+ }
+
+ return $in_quote;
+ }
+
+ /**
+ * Checks if a string has an unclosed brackets or not. IMPORTANT:
+ * This function handles both angle brackets and square brackets;
+ *
+ * @access private
+ * @param string $string The string to check.
+ * @param string $chars The characters to check for.
+ * @return boolean True if there are unclosed brackets inside the string, false otherwise.
+ */
+ function _hasUnclosedBrackets($string, $chars)
+ {
+ $num_angle_start = substr_count($string, $chars[0]);
+ $num_angle_end = substr_count($string, $chars[1]);
+
+ $this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);
+ $this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);
+
+ if ($num_angle_start < $num_angle_end) {
+ $this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';
+ return false;
+ } else {
+ return ($num_angle_start > $num_angle_end);
+ }
+ }
+
+ /**
+ * Sub function that is used only by hasUnclosedBrackets().
+ *
+ * @access private
+ * @param string $string The string to check.
+ * @param integer &$num The number of occurences.
+ * @param string $char The character to count.
+ * @return integer The number of occurences of $char in $string, adjusted for backslashes.
+ */
+ function _hasUnclosedBracketsSub($string, &$num, $char)
+ {
+ $parts = explode($char, $string);
+ for ($i = 0; $i < count($parts); $i++){
+ if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))
+ $num--;
+ if (isset($parts[$i + 1]))
+ $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
+ }
+
+ return $num;
+ }
+
+ /**
+ * Function to begin checking the address.
+ *
+ * @access private
+ * @param string $address The address to validate.
+ * @return mixed False on failure, or a structured array of address information on success.
+ */
+ function _validateAddress($address)
+ {
+ $is_group = false;
+ $addresses = array();
+
+ if ($address['group']) {
+ $is_group = true;
+
+ // Get the group part of the name
+ $parts = explode(':', $address['address']);
+ $groupname = $this->_splitCheck($parts, ':');
+ $structure = array();
+
+ // And validate the group part of the name.
+ if (!$this->_validatePhrase($groupname)){
+ $this->error = 'Group name did not validate.';
+ return false;
+ } else {
+ // Don't include groups if we are not nesting
+ // them. This avoids returning invalid addresses.
+ if ($this->nestGroups) {
+ $structure = new stdClass;
+ $structure->groupname = $groupname;
+ }
+ }
+
+ $address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));
+ }
+
+ // If a group then split on comma and put into an array.
+ // Otherwise, Just put the whole address in an array.
+ if ($is_group) {
+ while (strlen($address['address']) > 0) {
+ $parts = explode(',', $address['address']);
+ $addresses[] = $this->_splitCheck($parts, ',');
+ $address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));
+ }
+ } else {
+ $addresses[] = $address['address'];
+ }
+
+ // Check that $addresses is set, if address like this:
+ // Groupname:;
+ // Then errors were appearing.
+ if (!count($addresses)){
+ $this->error = 'Empty group.';
+ return false;
+ }
+
+ // Trim the whitespace from all of the address strings.
+ array_map('trim', $addresses);
+
+ // Validate each mailbox.
+ // Format could be one of: name <geezer@domain.com>
+ // geezer@domain.com
+ // geezer
+ // ... or any other format valid by RFC 822.
+ for ($i = 0; $i < count($addresses); $i++) {
+ if (!$this->validateMailbox($addresses[$i])) {
+ if (empty($this->error)) {
+ $this->error = 'Validation failed for: ' . $addresses[$i];
+ }
+ return false;
+ }
+ }
+
+ // Nested format
+ if ($this->nestGroups) {
+ if ($is_group) {
+ $structure->addresses = $addresses;
+ } else {
+ $structure = $addresses[0];
+ }
+
+ // Flat format
+ } else {
+ if ($is_group) {
+ $structure = array_merge($structure, $addresses);
+ } else {
+ $structure = $addresses;
+ }
+ }
+
+ return $structure;
+ }
+
+ /**
+ * Function to validate a phrase.
+ *
+ * @access private
+ * @param string $phrase The phrase to check.
+ * @return boolean Success or failure.
+ */
+ function _validatePhrase($phrase)
+ {
+ // Splits on one or more Tab or space.
+ $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
+
+ $phrase_parts = array();
+ while (count($parts) > 0){
+ $phrase_parts[] = $this->_splitCheck($parts, ' ');
+ for ($i = 0; $i < $this->index + 1; $i++)
+ array_shift($parts);
+ }
+
+ foreach ($phrase_parts as $part) {
+ // If quoted string:
+ if (substr($part, 0, 1) == '"') {
+ if (!$this->_validateQuotedString($part)) {
+ return false;
+ }
+ continue;
+ }
+
+ // Otherwise it's an atom:
+ if (!$this->_validateAtom($part)) return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Function to validate an atom which from rfc822 is:
+ * atom = 1*<any CHAR except specials, SPACE and CTLs>
+ *
+ * If validation ($this->validate) has been turned off, then
+ * validateAtom() doesn't actually check anything. This is so that you
+ * can split a list of addresses up before encoding personal names
+ * (umlauts, etc.), for example.
+ *
+ * @access private
+ * @param string $atom The string to check.
+ * @return boolean Success or failure.
+ */
+ function _validateAtom($atom)
+ {
+ if (!$this->validate) {
+ // Validation has been turned off; assume the atom is okay.
+ return true;
+ }
+
+ // Check for any char from ASCII 0 - ASCII 127
+ if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
+ return false;
+ }
+
+ // Check for specials:
+ if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
+ return false;
+ }
+
+ // Check for control characters (ASCII 0-31):
+ if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Function to validate quoted string, which is:
+ * quoted-string = <"> *(qtext/quoted-pair) <">
+ *
+ * @access private
+ * @param string $qstring The string to check
+ * @return boolean Success or failure.
+ */
+ function _validateQuotedString($qstring)
+ {
+ // Leading and trailing "
+ $qstring = substr($qstring, 1, -1);
+
+ // Perform check, removing quoted characters first.
+ return !preg_match('/[\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));
+ }
+
+ /**
+ * Function to validate a mailbox, which is:
+ * mailbox = addr-spec ; simple address
+ * / phrase route-addr ; name and route-addr
+ *
+ * @access public
+ * @param string &$mailbox The string to check.
+ * @return boolean Success or failure.
+ */
+ function validateMailbox(&$mailbox)
+ {
+ // A couple of defaults.
+ $phrase = '';
+ $comment = '';
+ $comments = array();
+
+ // Catch any RFC822 comments and store them separately.
+ $_mailbox = $mailbox;
+ while (strlen(trim($_mailbox)) > 0) {
+ $parts = explode('(', $_mailbox);
+ $before_comment = $this->_splitCheck($parts, '(');
+ if ($before_comment != $_mailbox) {
+ // First char should be a (.
+ $comment = substr(str_replace($before_comment, '', $_mailbox), 1);
+ $parts = explode(')', $comment);
+ $comment = $this->_splitCheck($parts, ')');
+ $comments[] = $comment;
+
+ // +2 is for the brackets
+ $_mailbox = substr($_mailbox, strpos($_mailbox, '('.$comment)+strlen($comment)+2);
+ } else {
+ break;
+ }
+ }
+
+ foreach ($comments as $comment) {
+ $mailbox = str_replace("($comment)", '', $mailbox);
+ }
+
+ $mailbox = trim($mailbox);
+
+ // Check for name + route-addr
+ if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {
+ $parts = explode('<', $mailbox);
+ $name = $this->_splitCheck($parts, '<');
+
+ $phrase = trim($name);
+ $route_addr = trim(substr($mailbox, strlen($name.'<'), -1));
+
+ if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {
+ return false;
+ }
+
+ // Only got addr-spec
+ } else {
+ // First snip angle brackets if present.
+ if (substr($mailbox, 0, 1) == '<' && substr($mailbox, -1) == '>') {
+ $addr_spec = substr($mailbox, 1, -1);
+ } else {
+ $addr_spec = $mailbox;
+ }
+
+ if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
+ return false;
+ }
+ }
+
+ // Construct the object that will be returned.
+ $mbox = new stdClass();
+
+ // Add the phrase (even if empty) and comments
+ $mbox->personal = $phrase;
+ $mbox->comment = isset($comments) ? $comments : array();
+
+ if (isset($route_addr)) {
+ $mbox->mailbox = $route_addr['local_part'];
+ $mbox->host = $route_addr['domain'];
+ $route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';
+ } else {
+ $mbox->mailbox = $addr_spec['local_part'];
+ $mbox->host = $addr_spec['domain'];
+ }
+
+ $mailbox = $mbox;
+ return true;
+ }
+
+ /**
+ * This function validates a route-addr which is:
+ * route-addr = "<" [route] addr-spec ">"
+ *
+ * Angle brackets have already been removed at the point of
+ * getting to this function.
+ *
+ * @access private
+ * @param string $route_addr The string to check.
+ * @return mixed False on failure, or an array containing validated address/route information on success.
+ */
+ function _validateRouteAddr($route_addr)
+ {
+ // Check for colon.
+ if (strpos($route_addr, ':') !== false) {
+ $parts = explode(':', $route_addr);
+ $route = $this->_splitCheck($parts, ':');
+ } else {
+ $route = $route_addr;
+ }
+
+ // If $route is same as $route_addr then the colon was in
+ // quotes or brackets or, of course, non existent.
+ if ($route === $route_addr){
+ unset($route);
+ $addr_spec = $route_addr;
+ if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
+ return false;
+ }
+ } else {
+ // Validate route part.
+ if (($route = $this->_validateRoute($route)) === false) {
+ return false;
+ }
+
+ $addr_spec = substr($route_addr, strlen($route . ':'));
+
+ // Validate addr-spec part.
+ if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
+ return false;
+ }
+ }
+
+ if (isset($route)) {
+ $return['adl'] = $route;
+ } else {
+ $return['adl'] = '';
+ }
+
+ $return = array_merge($return, $addr_spec);
+ return $return;
+ }
+
+ /**
+ * Function to validate a route, which is:
+ * route = 1#("@" domain) ":"
+ *
+ * @access private
+ * @param string $route The string to check.
+ * @return mixed False on failure, or the validated $route on success.
+ */
+ function _validateRoute($route)
+ {
+ // Split on comma.
+ $domains = explode(',', trim($route));
+
+ foreach ($domains as $domain) {
+ $domain = str_replace('@', '', trim($domain));
+ if (!$this->_validateDomain($domain)) return false;
+ }
+
+ return $route;
+ }
+
+ /**
+ * Function to validate a domain, though this is not quite what
+ * you expect of a strict internet domain.
+ *
+ * domain = sub-domain *("." sub-domain)
+ *
+ * @access private
+ * @param string $domain The string to check.
+ * @return mixed False on failure, or the validated domain on success.
+ */
+ function _validateDomain($domain)
+ {
+ // Note the different use of $subdomains and $sub_domains
+ $subdomains = explode('.', $domain);
+
+ while (count($subdomains) > 0) {
+ $sub_domains[] = $this->_splitCheck($subdomains, '.');
+ for ($i = 0; $i < $this->index + 1; $i++)
+ array_shift($subdomains);
+ }
+
+ foreach ($sub_domains as $sub_domain) {
+ if (!$this->_validateSubdomain(trim($sub_domain)))
+ return false;
+ }
+
+ // Managed to get here, so return input.
+ return $domain;
+ }
+
+ /**
+ * Function to validate a subdomain:
+ * subdomain = domain-ref / domain-literal
+ *
+ * @access private
+ * @param string $subdomain The string to check.
+ * @return boolean Success or failure.
+ */
+ function _validateSubdomain($subdomain)
+ {
+ if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
+ if (!$this->_validateDliteral($arr[1])) return false;
+ } else {
+ if (!$this->_validateAtom($subdomain)) return false;
+ }
+
+ // Got here, so return successful.
+ return true;
+ }
+
+ /**
+ * Function to validate a domain literal:
+ * domain-literal = "[" *(dtext / quoted-pair) "]"
+ *
+ * @access private
+ * @param string $dliteral The string to check.
+ * @return boolean Success or failure.
+ */
+ function _validateDliteral($dliteral)
+ {
+ return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
+ }
+
+ /**
+ * Function to validate an addr-spec.
+ *
+ * addr-spec = local-part "@" domain
+ *
+ * @access private
+ * @param string $addr_spec The string to check.
+ * @return mixed False on failure, or the validated addr-spec on success.
+ */
+ function _validateAddrSpec($addr_spec)
+ {
+ $addr_spec = trim($addr_spec);
+
+ // Split on @ sign if there is one.
+ if (strpos($addr_spec, '@') !== false) {
+ $parts = explode('@', $addr_spec);
+ $local_part = $this->_splitCheck($parts, '@');
+ $domain = substr($addr_spec, strlen($local_part . '@'));
+
+ // No @ sign so assume the default domain.
+ } else {
+ $local_part = $addr_spec;
+ $domain = $this->default_domain;
+ }
+
+ if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;
+ if (($domain = $this->_validateDomain($domain)) === false) return false;
+
+ // Got here so return successful.
+ return array('local_part' => $local_part, 'domain' => $domain);
+ }
+
+ /**
+ * Function to validate the local part of an address:
+ * local-part = word *("." word)
+ *
+ * @access private
+ * @param string $local_part
+ * @return mixed False on failure, or the validated local part on success.
+ */
+ function _validateLocalPart($local_part)
+ {
+ $parts = explode('.', $local_part);
+ $words = array();
+
+ // Split the local_part into words.
+ while (count($parts) > 0){
+ $words[] = $this->_splitCheck($parts, '.');
+ for ($i = 0; $i < $this->index + 1; $i++) {
+ array_shift($parts);
+ }
+ }
+
+ // Validate each word.
+ foreach ($words as $word) {
+ // If this word contains an unquoted space, it is invalid. (6.2.4)
+ if (strpos($word, ' ') && $word[0] !== '"')
+ {
+ return false;
+ }
+
+ if ($this->_validatePhrase(trim($word)) === false) return false;
+ }
+
+ // Managed to get here, so return the input.
+ return $local_part;
+ }
+
+ /**
+ * Returns an approximate count of how many addresses are in the
+ * given string. This is APPROXIMATE as it only splits based on a
+ * comma which has no preceding backslash. Could be useful as
+ * large amounts of addresses will end up producing *large*
+ * structures when used with parseAddressList().
+ *
+ * @param string $data Addresses to count
+ * @return int Approximate count
+ */
+ function approximateCount($data)
+ {
+ return count(preg_split('/(?<!\\\\),/', $data));
+ }
+
+ /**
+ * This is a email validating function separate to the rest of the
+ * class. It simply validates whether an email is of the common
+ * internet form: <user>@<domain>. This can be sufficient for most
+ * people. Optional stricter mode can be utilised which restricts
+ * mailbox characters allowed to alphanumeric, full stop, hyphen
+ * and underscore.
+ *
+ * @param string $data Address to check
+ * @param boolean $strict Optional stricter mode
+ * @return mixed False if it fails, an indexed array
+ * username/domain if it matches
+ */
+ function isValidInetAddress($data, $strict = false)
+ {
+ $regex = $strict ? '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
+ if (preg_match($regex, trim($data), $matches)) {
+ return array($matches[1], $matches[2]);
+ } else {
+ return false;
+ }
+ }
+
+}
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Chuck Hagenbuch <chuck@horde.org> |\r
-// +----------------------------------------------------------------------+\r
-//\r
-// $Id: mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $\r
-\r
-/**\r
- * internal PHP-mail() implementation of the PEAR Mail:: interface.\r
- * @package Mail\r
- * @version $Revision: 1.20 $\r
- */\r
-class Mail_mail extends Mail {\r
-\r
- /**\r
- * Any arguments to pass to the mail() function.\r
- * @var string\r
- */\r
- var $_params = '';\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * Instantiates a new Mail_mail:: object based on the parameters\r
- * passed in.\r
- *\r
- * @param array $params Extra arguments for the mail() function.\r
- */\r
- function Mail_mail($params = null)\r
- {\r
- // The other mail implementations accept parameters as arrays.\r
- // In the interest of being consistent, explode an array into\r
- // a string of parameter arguments.\r
- if (is_array($params)) {\r
- $this->_params = join(' ', $params);\r
- } else {\r
- $this->_params = $params;\r
- }\r
-\r
- /* Because the mail() function may pass headers as command\r
- * line arguments, we can't guarantee the use of the standard\r
- * "\r\n" separator. Instead, we use the system's native line\r
- * separator. */\r
- if (defined('PHP_EOL')) {\r
- $this->sep = PHP_EOL;\r
- } else {\r
- $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";\r
- }\r
- }\r
-\r
- /**\r
- * Implements Mail_mail::send() function using php's built-in mail()\r
- * command.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (ie, 'Subject'), and the array value\r
- * is the header value (ie, 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * Mime parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- *\r
- * @access public\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- if (!is_array($headers)) {\r
- return PEAR::raiseError('$headers must be an array');\r
- }\r
-\r
- $result = $this->_sanitizeHeaders($headers);\r
- if (is_a($result, 'PEAR_Error')) {\r
- return $result;\r
- }\r
-\r
- // If we're passed an array of recipients, implode it.\r
- if (is_array($recipients)) {\r
- $recipients = implode(', ', $recipients);\r
- }\r
-\r
- // Get the Subject out of the headers array so that we can\r
- // pass it as a seperate argument to mail().\r
- $subject = '';\r
- if (isset($headers['Subject'])) {\r
- $subject = $headers['Subject'];\r
- unset($headers['Subject']);\r
- }\r
-\r
- // Also remove the To: header. The mail() function will add its own\r
- // To: header based on the contents of $recipients.\r
- unset($headers['To']);\r
-\r
- // Flatten the headers out.\r
- $headerElements = $this->prepareHeaders($headers);\r
- if (is_a($headerElements, 'PEAR_Error')) {\r
- return $headerElements;\r
- }\r
- list(, $text_headers) = $headerElements;\r
-\r
- // We only use mail()'s optional fifth parameter if the additional\r
- // parameters have been provided and we're not running in safe mode.\r
- if (empty($this->_params) || ini_get('safe_mode')) {\r
- $result = mail($recipients, $subject, $body, $text_headers);\r
- } else {\r
- $result = mail($recipients, $subject, $body, $text_headers,\r
- $this->_params);\r
- }\r
-\r
- // If the mail() function returned failure, we need to create a\r
- // PEAR_Error object and return it instead of the boolean result.\r
- if ($result === false) {\r
- $result = PEAR::raiseError('mail() returned failure');\r
- }\r
-\r
- return $result;\r
- }\r
-\r
-}\r
+<?php
+/**
+ * internal PHP-mail() implementation of the PEAR Mail:: interface.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2010 Chuck Hagenbuch
+ * 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.
+ *
+ * @category Mail
+ * @package Mail
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 2010 Chuck Hagenbuch
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: mail.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+/**
+ * internal PHP-mail() implementation of the PEAR Mail:: interface.
+ * @package Mail
+ * @version $Revision: 294747 $
+ */
+class Mail_mail extends Mail {
+
+ /**
+ * Any arguments to pass to the mail() function.
+ * @var string
+ */
+ var $_params = '';
+
+ /**
+ * Constructor.
+ *
+ * Instantiates a new Mail_mail:: object based on the parameters
+ * passed in.
+ *
+ * @param array $params Extra arguments for the mail() function.
+ */
+ function Mail_mail($params = null)
+ {
+ // The other mail implementations accept parameters as arrays.
+ // In the interest of being consistent, explode an array into
+ // a string of parameter arguments.
+ if (is_array($params)) {
+ $this->_params = join(' ', $params);
+ } else {
+ $this->_params = $params;
+ }
+
+ /* Because the mail() function may pass headers as command
+ * line arguments, we can't guarantee the use of the standard
+ * "\r\n" separator. Instead, we use the system's native line
+ * separator. */
+ if (defined('PHP_EOL')) {
+ $this->sep = PHP_EOL;
+ } else {
+ $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
+ }
+ }
+
+ /**
+ * Implements Mail_mail::send() function using php's built-in mail()
+ * command.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (ie, 'Subject'), and the array value
+ * is the header value (ie, 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * Mime parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ *
+ * @access public
+ */
+ function send($recipients, $headers, $body)
+ {
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ $result = $this->_sanitizeHeaders($headers);
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ // If we're passed an array of recipients, implode it.
+ if (is_array($recipients)) {
+ $recipients = implode(', ', $recipients);
+ }
+
+ // Get the Subject out of the headers array so that we can
+ // pass it as a seperate argument to mail().
+ $subject = '';
+ if (isset($headers['Subject'])) {
+ $subject = $headers['Subject'];
+ unset($headers['Subject']);
+ }
+
+ // Also remove the To: header. The mail() function will add its own
+ // To: header based on the contents of $recipients.
+ unset($headers['To']);
+
+ // Flatten the headers out.
+ $headerElements = $this->prepareHeaders($headers);
+ if (is_a($headerElements, 'PEAR_Error')) {
+ return $headerElements;
+ }
+ list(, $text_headers) = $headerElements;
+
+ // We only use mail()'s optional fifth parameter if the additional
+ // parameters have been provided and we're not running in safe mode.
+ if (empty($this->_params) || ini_get('safe_mode')) {
+ $result = mail($recipients, $subject, $body, $text_headers);
+ } else {
+ $result = mail($recipients, $subject, $body, $text_headers,
+ $this->_params);
+ }
+
+ // If the mail() function returned failure, we need to create a
+ // PEAR_Error object and return it instead of the boolean result.
+ if ($result === false) {
+ $result = PEAR::raiseError('mail() returned failure');
+ }
+
+ return $result;
+ }
+
+}
* @author Aleksander Machniak <alec@php.net>
* @copyright 2003-2006 PEAR <pear-group@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version CVS: $Id$
+ * @version CVS: $Id: mime.php 305690 2010-11-23 12:41:00Z alec $
* @link http://pear.php.net/package/Mail_mime
*
* This class is based on HTML Mime Mail class from
}
}
-} // End of class
\ No newline at end of file
+} // End of class
* @author Sean Coates <sean@php.net>
* @copyright 2003-2006 PEAR <pear-group@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version CVS: $Id: mimeDecode.php 313905 2011-07-29 03:13:19Z alan_k $
+ * @version CVS: $Id: mimeDecode.php 305875 2010-12-01 07:17:10Z alan_k $
* @link http://pear.php.net/package/Mail_mime
*/
break;
case 'message/rfc822':
- case 'message/delivery-status': // #bug #18693
if ($this->_rfc822_bodies) {
$encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
$return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body);
* robust as it could be. Eg. header comments
* in the wrong place will probably break it.
*
- * Extra things this can handle
- * filename*0=......
- * filename*1=......
- *
- * This is where lines are broken in, and need merging.
- *
- * filename*0*=ENC''urlencoded data.
- * filename*1*=ENC''urlencoded data.
- *
- *
- *
* @param string Header value to parse
* @return array Contains parsed result
* @access private
*/
function _parseHeaderValue($input)
{
- if (($pos = strpos($input, ';')) === false) {
+
+ if (($pos = strpos($input, ';')) === false) {
$input = $this->_decode_headers ? $this->_decodeHeader($input) : $input;
$return['value'] = trim($input);
return $return;
if ($key) { // a key without a value..
$key= trim($key);
$return['other'][$key] = '';
+ $return['other'][strtolower($key)] = '';
}
$key = '';
}
$i++;
continue; // skip leading spaces after '=' or after '"'
}
-
- // do not de-quote 'xxx*= itesm..
- $key_is_trans = $key[strlen($key)-1] == '*';
-
- if (!$key_is_trans && !$escaped && ($c == '"' || $c == "'")) {
+ if (!$escaped && ($c == '"' || $c == "'")) {
// start quoted area..
$q = $c;
// in theory should not happen raw text in value part..
}
// got end....
if (!$escaped && $c == ';') {
-
- $return['other'][$key] = trim($val);
+
+ $val = trim($val);
+ $added = false;
+ if (preg_match('/\*[0-9]+$/', $key)) {
+ // this is the extended aaa*0=...;aaa*1=.... code
+ // it assumes the pieces arrive in order, and are valid...
+ $key = preg_replace('/\*[0-9]+$/', '', $key);
+ if (isset($return['other'][$key])) {
+ $return['other'][$key] .= $val;
+ if (strtolower($key) != $key) {
+ $return['other'][strtolower($key)] .= $val;
+ }
+ $added = true;
+ }
+ // continue and use standard setters..
+ }
+ if (!$added) {
+ $return['other'][$key] = $val;
+ $return['other'][strtolower($key)] = $val;
+ }
$val = false;
$key = '';
$lq = false;
// state - in quote..
if (!$escaped && $c == $q) { // potential exit state..
-
+
// end of quoted string..
$lq = $q;
$q = false;
if (strlen(trim($key)) || $val !== false) {
$val = trim($val);
-
- $return['other'][$key] = $val;
- }
-
-
- $clean_others = array();
- // merge added values. eg. *1[*]
- foreach($return['other'] as $key =>$val) {
- if (preg_match('/\*[0-9]+\**$/', $key)) {
- $key = preg_replace('/(.*)\*[0-9]+(\**)$/', '\1\2', $key);
- if (isset($clean_others[$key])) {
- $clean_others[$key] .= $val;
- continue;
+ $added = false;
+ if ($val !== false && preg_match('/\*[0-9]+$/', $key)) {
+ // no dupes due to our crazy regexp.
+ $key = preg_replace('/\*[0-9]+$/', '', $key);
+ if (isset($return['other'][$key])) {
+ $return['other'][$key] .= $val;
+ if (strtolower($key) != $key) {
+ $return['other'][strtolower($key)] .= $val;
+ }
+ $added = true;
}
-
+ // continue and use standard setters..
}
- $clean_others[$key] = $val;
-
- }
-
- // handle language translation of '*' ending others.
- foreach( $clean_others as $key =>$val) {
- if ( $key[strlen($key)-1] != '*') {
- $clean_others[strtolower($key)] = $val;
- continue;
+ if (!$added) {
+ $return['other'][$key] = $val;
+ $return['other'][strtolower($key)] = $val;
}
- unset($clean_others[$key]);
- $key = substr($key,0,-1);
- //extended-initial-value := [charset] "'" [language] "'"
- // extended-other-values
- $match = array();
- $info = preg_match("/^([^']+)'([^']*)'(.*)$/", $val, $match);
-
- $clean_others[$key] = urldecode($match[3]);
- $clean_others[strtolower($key)] = $clean_others[$key];
- $clean_others[strtolower($key).'-charset'] = $match[1];
- $clean_others[strtolower($key).'-language'] = $match[2];
-
-
}
-
-
- $return['other'] = $clean_others;
-
-
-
-
// decode values.
foreach($return['other'] as $key =>$val) {
$return['other'][$key] = $this->_decode_headers ? $this->_decodeHeader($val) : $val;
}
-
+ //print_r($return);
return $return;
}
* @author Aleksander Machniak <alec@php.net>
* @copyright 2003-2006 PEAR <pear-group@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version CVS: $Id$
+ * @version CVS: $Id: mimePart.php 314695 2011-08-10 07:18:07Z alec $
* @link http://pear.php.net/package/Mail_mime
*/
*/
var $_eol = "\r\n";
+
/**
* Constructor.
*
// Structured header (make sure addr-spec inside is not encoded)
if (!empty($separator)) {
+ // Simple e-mail address regexp
+ $email_regexp = '(\S+|("[^\r\n"]+"))@\S+';
+
$parts = Mail_mimePart::_explodeQuotedString($separator, $value);
$value = '';
}
// let's find phrase (name) and/or addr-spec
- if (preg_match('/^<\S+@\S+>$/', $part)) {
+ if (preg_match('/^<' . $email_regexp . '>$/', $part)) {
$value .= $part;
- } else if (preg_match('/^\S+@\S+$/', $part)) {
+ } else if (preg_match('/^' . $email_regexp . '$/', $part)) {
// address without brackets and without name
$value .= $part;
- } else if (preg_match('/<*\S+@\S+>*$/', $part, $matches)) {
+ } else if (preg_match('/<*' . $email_regexp . '>*$/', $part, $matches)) {
// address with name (handle name)
$address = $matches[0];
$word = str_replace($address, '', $part);
return sprintf('%%%02X', ord($matches[1]));
}
-} // End of class
\ No newline at end of file
+} // End of class
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Chuck Hagenbuch <chuck@horde.org> |\r
-// +----------------------------------------------------------------------+\r
-//\r
-// $Id: mock.php,v 1.1 2007/12/08 17:57:54 chagenbu Exp $\r
-//\r
-\r
-/**\r
- * Mock implementation of the PEAR Mail:: interface for testing.\r
- * @access public\r
- * @package Mail\r
- * @version $Revision: 1.1 $\r
- */\r
-class Mail_mock extends Mail {\r
-\r
- /**\r
- * Array of messages that have been sent with the mock.\r
- *\r
- * @var array\r
- * @access public\r
- */\r
- var $sentMessages = array();\r
-\r
- /**\r
- * Callback before sending mail.\r
- *\r
- * @var callback\r
- */\r
- var $_preSendCallback;\r
-\r
- /**\r
- * Callback after sending mai.\r
- *\r
- * @var callback\r
- */\r
- var $_postSendCallback;\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * Instantiates a new Mail_mock:: object based on the parameters\r
- * passed in. It looks for the following parameters, both optional:\r
- * preSendCallback Called before an email would be sent.\r
- * postSendCallback Called after an email would have been sent.\r
- *\r
- * @param array Hash containing any parameters.\r
- * @access public\r
- */\r
- function Mail_mock($params)\r
- {\r
- if (isset($params['preSendCallback']) &&\r
- is_callable($params['preSendCallback'])) {\r
- $this->_preSendCallback = $params['preSendCallback'];\r
- }\r
-\r
- if (isset($params['postSendCallback']) &&\r
- is_callable($params['postSendCallback'])) {\r
- $this->_postSendCallback = $params['postSendCallback'];\r
- }\r
- }\r
-\r
- /**\r
- * Implements Mail_mock::send() function. Silently discards all\r
- * mail.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (ie, 'Subject'), and the array value\r
- * is the header value (ie, 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * Mime parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- * @access public\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- if ($this->_preSendCallback) {\r
- call_user_func_array($this->_preSendCallback,\r
- array(&$this, $recipients, $headers, $body));\r
- }\r
-\r
- $entry = array('recipients' => $recipients, 'headers' => $headers, 'body' => $body);\r
- $this->sentMessages[] = $entry;\r
-\r
- if ($this->_postSendCallback) {\r
- call_user_func_array($this->_postSendCallback,\r
- array(&$this, $recipients, $headers, $body));\r
- }\r
-\r
- return true;\r
- }\r
-\r
-}\r
+<?php
+/**
+ * Mock implementation
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2010 Chuck Hagenbuch
+ * 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.
+ *
+ * @category Mail
+ * @package Mail
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 2010 Chuck Hagenbuch
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: mock.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+/**
+ * Mock implementation of the PEAR Mail:: interface for testing.
+ * @access public
+ * @package Mail
+ * @version $Revision: 294747 $
+ */
+class Mail_mock extends Mail {
+
+ /**
+ * Array of messages that have been sent with the mock.
+ *
+ * @var array
+ * @access public
+ */
+ var $sentMessages = array();
+
+ /**
+ * Callback before sending mail.
+ *
+ * @var callback
+ */
+ var $_preSendCallback;
+
+ /**
+ * Callback after sending mai.
+ *
+ * @var callback
+ */
+ var $_postSendCallback;
+
+ /**
+ * Constructor.
+ *
+ * Instantiates a new Mail_mock:: object based on the parameters
+ * passed in. It looks for the following parameters, both optional:
+ * preSendCallback Called before an email would be sent.
+ * postSendCallback Called after an email would have been sent.
+ *
+ * @param array Hash containing any parameters.
+ * @access public
+ */
+ function Mail_mock($params)
+ {
+ if (isset($params['preSendCallback']) &&
+ is_callable($params['preSendCallback'])) {
+ $this->_preSendCallback = $params['preSendCallback'];
+ }
+
+ if (isset($params['postSendCallback']) &&
+ is_callable($params['postSendCallback'])) {
+ $this->_postSendCallback = $params['postSendCallback'];
+ }
+ }
+
+ /**
+ * Implements Mail_mock::send() function. Silently discards all
+ * mail.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (ie, 'Subject'), and the array value
+ * is the header value (ie, 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * Mime parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ * @access public
+ */
+ function send($recipients, $headers, $body)
+ {
+ if ($this->_preSendCallback) {
+ call_user_func_array($this->_preSendCallback,
+ array(&$this, $recipients, $headers, $body));
+ }
+
+ $entry = array('recipients' => $recipients, 'headers' => $headers, 'body' => $body);
+ $this->sentMessages[] = $entry;
+
+ if ($this->_postSendCallback) {
+ call_user_func_array($this->_postSendCallback,
+ array(&$this, $recipients, $headers, $body));
+ }
+
+ return true;
+ }
+
+}
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Phil Kernick <philk@rotfl.com.au> |\r
-// +----------------------------------------------------------------------+\r
-//\r
-// $Id: null.php,v 1.2 2004/04/06 05:19:03 jon Exp $\r
-//\r
-\r
-/**\r
- * Null implementation of the PEAR Mail:: interface.\r
- * @access public\r
- * @package Mail\r
- * @version $Revision: 1.2 $\r
- */\r
-class Mail_null extends Mail {\r
-\r
- /**\r
- * Implements Mail_null::send() function. Silently discards all\r
- * mail.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (ie, 'Subject'), and the array value\r
- * is the header value (ie, 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * Mime parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- * @access public\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- return true;\r
- }\r
-\r
-}\r
+<?php
+/**
+ * Null implementation of the PEAR Mail interface
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2010 Phil Kernick
+ * 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.
+ *
+ * @category Mail
+ * @package Mail
+ * @author Phil Kernick <philk@rotfl.com.au>
+ * @copyright 2010 Phil Kernick
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: null.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+/**
+ * Null implementation of the PEAR Mail:: interface.
+ * @access public
+ * @package Mail
+ * @version $Revision: 294747 $
+ */
+class Mail_null extends Mail {
+
+ /**
+ * Implements Mail_null::send() function. Silently discards all
+ * mail.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (ie, 'Subject'), and the array value
+ * is the header value (ie, 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * Mime parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ * @access public
+ */
+ function send($recipients, $headers, $body)
+ {
+ return true;
+ }
+
+}
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Author: Chuck Hagenbuch <chuck@horde.org> |\r
-// +----------------------------------------------------------------------+\r
-\r
-/**\r
- * Sendmail implementation of the PEAR Mail:: interface.\r
- * @access public\r
- * @package Mail\r
- * @version $Revision: 1.20 $\r
- */\r
-class Mail_sendmail extends Mail {\r
-\r
- /**\r
- * The location of the sendmail or sendmail wrapper binary on the\r
- * filesystem.\r
- * @var string\r
- */\r
- var $sendmail_path = '/usr/sbin/sendmail';\r
-\r
- /**\r
- * Any extra command-line parameters to pass to the sendmail or\r
- * sendmail wrapper binary.\r
- * @var string\r
- */\r
- var $sendmail_args = '-i';\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * Instantiates a new Mail_sendmail:: object based on the parameters\r
- * passed in. It looks for the following parameters:\r
- * sendmail_path The location of the sendmail binary on the\r
- * filesystem. Defaults to '/usr/sbin/sendmail'.\r
- *\r
- * sendmail_args Any extra parameters to pass to the sendmail\r
- * or sendmail wrapper binary.\r
- *\r
- * If a parameter is present in the $params array, it replaces the\r
- * default.\r
- *\r
- * @param array $params Hash containing any parameters different from the\r
- * defaults.\r
- * @access public\r
- */\r
- function Mail_sendmail($params)\r
- {\r
- if (isset($params['sendmail_path'])) {\r
- $this->sendmail_path = $params['sendmail_path'];\r
- }\r
- if (isset($params['sendmail_args'])) {\r
- $this->sendmail_args = $params['sendmail_args'];\r
- }\r
-\r
- /*\r
- * Because we need to pass message headers to the sendmail program on\r
- * the commandline, we can't guarantee the use of the standard "\r\n"\r
- * separator. Instead, we use the system's native line separator.\r
- */\r
- if (defined('PHP_EOL')) {\r
- $this->sep = PHP_EOL;\r
- } else {\r
- $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";\r
- }\r
- }\r
-\r
- /**\r
- * Implements Mail::send() function using the sendmail\r
- * command-line binary.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (ie, 'Subject'), and the array value\r
- * is the header value (ie, 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * Mime parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- * @access public\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- if (!is_array($headers)) {\r
- return PEAR::raiseError('$headers must be an array');\r
- }\r
-\r
- $result = $this->_sanitizeHeaders($headers);\r
- if (is_a($result, 'PEAR_Error')) {\r
- return $result;\r
- }\r
-\r
- $recipients = $this->parseRecipients($recipients);\r
- if (is_a($recipients, 'PEAR_Error')) {\r
- return $recipients;\r
- }\r
- $recipients = escapeShellCmd(implode(' ', $recipients));\r
-\r
- $headerElements = $this->prepareHeaders($headers);\r
- if (is_a($headerElements, 'PEAR_Error')) {\r
- return $headerElements;\r
- }\r
- list($from, $text_headers) = $headerElements;\r
-\r
- /* Since few MTAs are going to allow this header to be forged\r
- * unless it's in the MAIL FROM: exchange, we'll use\r
- * Return-Path instead of From: if it's set. */\r
- if (!empty($headers['Return-Path'])) {\r
- $from = $headers['Return-Path'];\r
- }\r
-\r
- if (!isset($from)) {\r
- return PEAR::raiseError('No from address given.');\r
- } elseif (strpos($from, ' ') !== false ||\r
- strpos($from, ';') !== false ||\r
- strpos($from, '&') !== false ||\r
- strpos($from, '`') !== false) {\r
- return PEAR::raiseError('From address specified with dangerous characters.');\r
- }\r
-\r
- $from = escapeshellarg($from); // Security bug #16200\r
- \r
- $mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');\r
- if (!$mail) {\r
- return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.');\r
- }\r
-\r
- // Write the headers following by two newlines: one to end the headers\r
- // section and a second to separate the headers block from the body.\r
- fputs($mail, $text_headers . $this->sep . $this->sep);\r
-\r
- fputs($mail, $body);\r
- $result = pclose($mail);\r
- if (version_compare(phpversion(), '4.2.3') == -1) {\r
- // With older php versions, we need to shift the pclose\r
- // result to get the exit code.\r
- $result = $result >> 8 & 0xFF;\r
- }\r
-\r
- if ($result != 0) {\r
- return PEAR::raiseError('sendmail returned error code ' . $result,\r
- $result);\r
- }\r
-\r
- return true;\r
- }\r
-\r
-}\r
+<?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: Chuck Hagenbuch <chuck@horde.org> |
+// +----------------------------------------------------------------------+
+
+/**
+ * Sendmail implementation of the PEAR Mail:: interface.
+ * @access public
+ * @package Mail
+ * @version $Revision: 294744 $
+ */
+class Mail_sendmail extends Mail {
+
+ /**
+ * The location of the sendmail or sendmail wrapper binary on the
+ * filesystem.
+ * @var string
+ */
+ var $sendmail_path = '/usr/sbin/sendmail';
+
+ /**
+ * Any extra command-line parameters to pass to the sendmail or
+ * sendmail wrapper binary.
+ * @var string
+ */
+ var $sendmail_args = '-i';
+
+ /**
+ * Constructor.
+ *
+ * Instantiates a new Mail_sendmail:: object based on the parameters
+ * passed in. It looks for the following parameters:
+ * sendmail_path The location of the sendmail binary on the
+ * filesystem. Defaults to '/usr/sbin/sendmail'.
+ *
+ * sendmail_args Any extra parameters to pass to the sendmail
+ * or sendmail wrapper binary.
+ *
+ * If a parameter is present in the $params array, it replaces the
+ * default.
+ *
+ * @param array $params Hash containing any parameters different from the
+ * defaults.
+ * @access public
+ */
+ function Mail_sendmail($params)
+ {
+ if (isset($params['sendmail_path'])) {
+ $this->sendmail_path = $params['sendmail_path'];
+ }
+ if (isset($params['sendmail_args'])) {
+ $this->sendmail_args = $params['sendmail_args'];
+ }
+
+ /*
+ * Because we need to pass message headers to the sendmail program on
+ * the commandline, we can't guarantee the use of the standard "\r\n"
+ * separator. Instead, we use the system's native line separator.
+ */
+ if (defined('PHP_EOL')) {
+ $this->sep = PHP_EOL;
+ } else {
+ $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
+ }
+ }
+
+ /**
+ * Implements Mail::send() function using the sendmail
+ * command-line binary.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (ie, 'Subject'), and the array value
+ * is the header value (ie, 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * Mime parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ * @access public
+ */
+ function send($recipients, $headers, $body)
+ {
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ $result = $this->_sanitizeHeaders($headers);
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ $recipients = $this->parseRecipients($recipients);
+ if (is_a($recipients, 'PEAR_Error')) {
+ return $recipients;
+ }
+ $recipients = implode(' ', array_map('escapeshellarg', $recipients));
+
+ $headerElements = $this->prepareHeaders($headers);
+ if (is_a($headerElements, 'PEAR_Error')) {
+ return $headerElements;
+ }
+ list($from, $text_headers) = $headerElements;
+
+ /* Since few MTAs are going to allow this header to be forged
+ * unless it's in the MAIL FROM: exchange, we'll use
+ * Return-Path instead of From: if it's set. */
+ if (!empty($headers['Return-Path'])) {
+ $from = $headers['Return-Path'];
+ }
+
+ if (!isset($from)) {
+ return PEAR::raiseError('No from address given.');
+ } elseif (strpos($from, ' ') !== false ||
+ strpos($from, ';') !== false ||
+ strpos($from, '&') !== false ||
+ strpos($from, '`') !== false) {
+ return PEAR::raiseError('From address specified with dangerous characters.');
+ }
+
+ $from = escapeshellarg($from); // Security bug #16200
+
+ $mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
+ if (!$mail) {
+ return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.');
+ }
+
+ // Write the headers following by two newlines: one to end the headers
+ // section and a second to separate the headers block from the body.
+ fputs($mail, $text_headers . $this->sep . $this->sep);
+
+ fputs($mail, $body);
+ $result = pclose($mail);
+ if (version_compare(phpversion(), '4.2.3') == -1) {
+ // With older php versions, we need to shift the pclose
+ // result to get the exit code.
+ $result = $result >> 8 & 0xFF;
+ }
+
+ if ($result != 0) {
+ return PEAR::raiseError('sendmail returned error code ' . $result,
+ $result);
+ }
+
+ return true;
+ }
+
+}
-<?php\r
-//\r
-// +----------------------------------------------------------------------+\r
-// | PHP Version 4 |\r
-// +----------------------------------------------------------------------+\r
-// | Copyright (c) 1997-2003 The PHP Group |\r
-// +----------------------------------------------------------------------+\r
-// | This source file is subject to version 2.02 of the PHP license, |\r
-// | that is bundled with this package in the file LICENSE, and is |\r
-// | available at through the world-wide-web at |\r
-// | http://www.php.net/license/2_02.txt. |\r
-// | If you did not receive a copy of the PHP license and are unable to |\r
-// | obtain it through the world-wide-web, please send a note to |\r
-// | license@php.net so we can mail you a copy immediately. |\r
-// +----------------------------------------------------------------------+\r
-// | Authors: Chuck Hagenbuch <chuck@horde.org> |\r
-// | Jon Parise <jon@php.net> |\r
-// +----------------------------------------------------------------------+\r
-\r
-/** Error: Failed to create a Net_SMTP object */\r
-define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000);\r
-\r
-/** Error: Failed to connect to SMTP server */\r
-define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001);\r
-\r
-/** Error: SMTP authentication failure */\r
-define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002);\r
-\r
-/** Error: No From: address has been provided */\r
-define('PEAR_MAIL_SMTP_ERROR_FROM', 10003);\r
-\r
-/** Error: Failed to set sender */\r
-define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004);\r
-\r
-/** Error: Failed to add recipient */\r
-define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005);\r
-\r
-/** Error: Failed to send data */\r
-define('PEAR_MAIL_SMTP_ERROR_DATA', 10006);\r
-\r
-/**\r
- * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class.\r
- * @access public\r
- * @package Mail\r
- * @version $Revision: 1.33 $\r
- */\r
-class Mail_smtp extends Mail {\r
-\r
- /**\r
- * SMTP connection object.\r
- *\r
- * @var object\r
- * @access private\r
- */\r
- var $_smtp = null;\r
-\r
- /**\r
- * The list of service extension parameters to pass to the Net_SMTP\r
- * mailFrom() command.\r
- * @var array\r
- */\r
- var $_extparams = array();\r
-\r
- /**\r
- * The SMTP host to connect to.\r
- * @var string\r
- */\r
- var $host = 'localhost';\r
-\r
- /**\r
- * The port the SMTP server is on.\r
- * @var integer\r
- */\r
- var $port = 25;\r
-\r
- /**\r
- * Should SMTP authentication be used?\r
- *\r
- * This value may be set to true, false or the name of a specific\r
- * authentication method.\r
- *\r
- * If the value is set to true, the Net_SMTP package will attempt to use\r
- * the best authentication method advertised by the remote SMTP server.\r
- *\r
- * @var mixed\r
- */\r
- var $auth = false;\r
-\r
- /**\r
- * The username to use if the SMTP server requires authentication.\r
- * @var string\r
- */\r
- var $username = '';\r
-\r
- /**\r
- * The password to use if the SMTP server requires authentication.\r
- * @var string\r
- */\r
- var $password = '';\r
-\r
- /**\r
- * Hostname or domain that will be sent to the remote SMTP server in the\r
- * HELO / EHLO message.\r
- *\r
- * @var string\r
- */\r
- var $localhost = 'localhost';\r
-\r
- /**\r
- * SMTP connection timeout value. NULL indicates no timeout.\r
- *\r
- * @var integer\r
- */\r
- var $timeout = null;\r
-\r
- /**\r
- * Turn on Net_SMTP debugging?\r
- *\r
- * @var boolean $debug\r
- */\r
- var $debug = false;\r
-\r
- /**\r
- * Indicates whether or not the SMTP connection should persist over\r
- * multiple calls to the send() method.\r
- *\r
- * @var boolean\r
- */\r
- var $persist = false;\r
-\r
- /**\r
- * Use SMTP command pipelining (specified in RFC 2920) if the SMTP server\r
- * supports it. This speeds up delivery over high-latency connections. By\r
- * default, use the default value supplied by Net_SMTP.\r
- * @var bool\r
- */\r
- var $pipelining;\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * Instantiates a new Mail_smtp:: object based on the parameters\r
- * passed in. It looks for the following parameters:\r
- * host The server to connect to. Defaults to localhost.\r
- * port The port to connect to. Defaults to 25.\r
- * auth SMTP authentication. Defaults to none.\r
- * username The username to use for SMTP auth. No default.\r
- * password The password to use for SMTP auth. No default.\r
- * localhost The local hostname / domain. Defaults to localhost.\r
- * timeout The SMTP connection timeout. Defaults to none.\r
- * verp Whether to use VERP or not. Defaults to false.\r
- * DEPRECATED as of 1.2.0 (use setMailParams()).\r
- * debug Activate SMTP debug mode? Defaults to false.\r
- * persist Should the SMTP connection persist?\r
- * pipelining Use SMTP command pipelining\r
- *\r
- * If a parameter is present in the $params array, it replaces the\r
- * default.\r
- *\r
- * @param array Hash containing any parameters different from the\r
- * defaults.\r
- * @access public\r
- */\r
- function Mail_smtp($params)\r
- {\r
- if (isset($params['host'])) $this->host = $params['host'];\r
- if (isset($params['port'])) $this->port = $params['port'];\r
- if (isset($params['auth'])) $this->auth = $params['auth'];\r
- if (isset($params['username'])) $this->username = $params['username'];\r
- if (isset($params['password'])) $this->password = $params['password'];\r
- if (isset($params['localhost'])) $this->localhost = $params['localhost'];\r
- if (isset($params['timeout'])) $this->timeout = $params['timeout'];\r
- if (isset($params['debug'])) $this->debug = (bool)$params['debug'];\r
- if (isset($params['persist'])) $this->persist = (bool)$params['persist'];\r
- if (isset($params['pipelining'])) $this->pipelining = (bool)$params['pipelining'];\r
-\r
- // Deprecated options\r
- if (isset($params['verp'])) {\r
- $this->addServiceExtensionParameter('XVERP', is_bool($params['verp']) ? null : $params['verp']);\r
- }\r
-\r
- register_shutdown_function(array(&$this, '_Mail_smtp'));\r
- }\r
-\r
- /**\r
- * Destructor implementation to ensure that we disconnect from any\r
- * potentially-alive persistent SMTP connections.\r
- */\r
- function _Mail_smtp()\r
- {\r
- $this->disconnect();\r
- }\r
-\r
- /**\r
- * Implements Mail::send() function using SMTP.\r
- *\r
- * @param mixed $recipients Either a comma-seperated list of recipients\r
- * (RFC822 compliant), or an array of recipients,\r
- * each RFC822 valid. This may contain recipients not\r
- * specified in the headers, for Bcc:, resending\r
- * messages, etc.\r
- *\r
- * @param array $headers The array of headers to send with the mail, in an\r
- * associative array, where the array key is the\r
- * header name (e.g., 'Subject'), and the array value\r
- * is the header value (e.g., 'test'). The header\r
- * produced from those values would be 'Subject:\r
- * test'.\r
- *\r
- * @param string $body The full text of the message body, including any\r
- * MIME parts, etc.\r
- *\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- * containing a descriptive error message on\r
- * failure.\r
- * @access public\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- /* If we don't already have an SMTP object, create one. */\r
- $result = &$this->getSMTPObject();\r
- if (PEAR::isError($result)) {\r
- return $result;\r
- }\r
-\r
- if (!is_array($headers)) {\r
- return PEAR::raiseError('$headers must be an array');\r
- }\r
-\r
- $this->_sanitizeHeaders($headers);\r
-\r
- $headerElements = $this->prepareHeaders($headers);\r
- if (is_a($headerElements, 'PEAR_Error')) {\r
- $this->_smtp->rset();\r
- return $headerElements;\r
- }\r
- list($from, $textHeaders) = $headerElements;\r
-\r
- /* Since few MTAs are going to allow this header to be forged\r
- * unless it's in the MAIL FROM: exchange, we'll use\r
- * Return-Path instead of From: if it's set. */\r
- if (!empty($headers['Return-Path'])) {\r
- $from = $headers['Return-Path'];\r
- }\r
-\r
- if (!isset($from)) {\r
- $this->_smtp->rset();\r
- return PEAR::raiseError('No From: address has been provided',\r
- PEAR_MAIL_SMTP_ERROR_FROM);\r
- }\r
-\r
- $params = null;\r
- if (!empty($this->_extparams)) {\r
- foreach ($this->_extparams as $key => $val) {\r
- $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val);\r
- }\r
- }\r
- if (PEAR::isError($res = $this->_smtp->mailFrom($from, ltrim($params)))) {\r
- $error = $this->_error("Failed to set sender: $from", $res);\r
- $ret = PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER);\r
- $ret->smtpcode = $res->code;\r
- $this->_smtp->rset();\r
- return $ret;\r
- }\r
-\r
- $recipients = $this->parseRecipients($recipients);\r
- if (is_a($recipients, 'PEAR_Error')) {\r
- // smtpcode will not be set..\r
- $this->_smtp->rset();\r
- return $recipients;\r
- }\r
-\r
- foreach ($recipients as $recipient) {\r
- $res = $this->_smtp->rcptTo($recipient);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $error = $this->_error("Failed to add recipient: $recipient", $res);\r
- $ret = PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT);\r
- \r
- $ret->smtpcode = $error->code;\r
- $this->_smtp->rset();\r
- return $ret;\r
- }\r
- }\r
-\r
- /* Send the message's headers and the body as SMTP data. */\r
- $res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $error = $this->_error('Failed to send data', $res);\r
- $ret = PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA);\r
- $ret->smtpcode = $res->code;\r
- $this->_smtp->rset();\r
- return $ret;\r
- }\r
-\r
- /* If persistent connections are disabled, destroy our SMTP object. */\r
- if ($this->persist === false) {\r
- $this->disconnect();\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Connect to the SMTP server by instantiating a Net_SMTP object.\r
- *\r
- * @return mixed Returns a reference to the Net_SMTP object on success, or\r
- * a PEAR_Error containing a descriptive error message on\r
- * failure.\r
- *\r
- * @since 1.2.0\r
- * @access public\r
- */\r
- function &getSMTPObject()\r
- {\r
- if (is_object($this->_smtp) !== false) {\r
- return $this->_smtp;\r
- }\r
-\r
- include_once 'Net/SMTP.php';\r
- $this->_smtp = &new Net_SMTP($this->host,\r
- $this->port,\r
- $this->localhost);\r
-\r
- /* If we still don't have an SMTP object at this point, fail. */\r
- if (is_object($this->_smtp) === false) {\r
- return PEAR::raiseError('Failed to create a Net_SMTP object',\r
- PEAR_MAIL_SMTP_ERROR_CREATE);\r
- }\r
-\r
- /* Configure the SMTP connection. */\r
- if ($this->debug) {\r
- $this->_smtp->setDebug(true);\r
- }\r
-\r
- /* Attempt to connect to the configured SMTP server. */\r
- if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {\r
- $error = $this->_error('Failed to connect to ' .\r
- $this->host . ':' . $this->port,\r
- $res);\r
- $ret = PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT);\r
- $ret->smtpcode = $res->code;\r
- return $ret;\r
- }\r
-\r
- /* Attempt to authenticate if authentication has been enabled. */\r
- if ($this->auth) {\r
- $method = is_string($this->auth) ? $this->auth : '';\r
-\r
- if (PEAR::isError($res = $this->_smtp->auth($this->username,\r
- $this->password,\r
- $method))) {\r
- $error = $this->_error("$method authentication failure",\r
- $res);\r
- $this->_smtp->rset();\r
- return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH);\r
- }\r
- }\r
-\r
- return $this->_smtp;\r
- }\r
-\r
- /**\r
- * Add parameter associated with a SMTP service extension.\r
- *\r
- * @param string Extension keyword.\r
- * @param string Any value the keyword needs.\r
- *\r
- * @since 1.2.0\r
- * @access public\r
- */\r
- function addServiceExtensionParameter($keyword, $value = null)\r
- {\r
- $this->_extparams[$keyword] = $value;\r
- }\r
-\r
- /**\r
- * Disconnect and destroy the current SMTP connection.\r
- *\r
- * @return boolean True if the SMTP connection no longer exists.\r
- *\r
- * @since 1.1.9\r
- * @access public\r
- */\r
- function disconnect()\r
- {\r
- /* If we have an SMTP object, disconnect and destroy it. */\r
- if (is_object($this->_smtp) && $this->_smtp->disconnect()) {\r
- $this->_smtp = null;\r
- }\r
-\r
- /* We are disconnected if we no longer have an SMTP object. */\r
- return ($this->_smtp === null);\r
- }\r
-\r
- /**\r
- * Build a standardized string describing the current SMTP error.\r
- *\r
- * @param string $text Custom string describing the error context.\r
- * @param object $error Reference to the current PEAR_Error object.\r
- *\r
- * @return string A string describing the current SMTP error.\r
- *\r
- * @since 1.1.7\r
- * @access private\r
- */\r
- function _error($text, &$error)\r
- {\r
- /* Split the SMTP response into a code and a response string. */\r
- list($code, $response) = $this->_smtp->getResponse();\r
-\r
- /* Build our standardized error string. */\r
- return $text\r
- . ' [SMTP: ' . $error->getMessage()\r
- . " (code: $code, response: $response)]";\r
- }\r
-\r
-}\r
+<?php
+/**
+ * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2010, Chuck Hagenbuch
+ * 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.
+ *
+ * @category HTTP
+ * @package HTTP_Request
+ * @author Jon Parise <jon@php.net>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 2010 Chuck Hagenbuch
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: smtp.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+/** Error: Failed to create a Net_SMTP object */
+define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000);
+
+/** Error: Failed to connect to SMTP server */
+define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001);
+
+/** Error: SMTP authentication failure */
+define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002);
+
+/** Error: No From: address has been provided */
+define('PEAR_MAIL_SMTP_ERROR_FROM', 10003);
+
+/** Error: Failed to set sender */
+define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004);
+
+/** Error: Failed to add recipient */
+define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005);
+
+/** Error: Failed to send data */
+define('PEAR_MAIL_SMTP_ERROR_DATA', 10006);
+
+/**
+ * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class.
+ * @access public
+ * @package Mail
+ * @version $Revision: 294747 $
+ */
+class Mail_smtp extends Mail {
+
+ /**
+ * SMTP connection object.
+ *
+ * @var object
+ * @access private
+ */
+ var $_smtp = null;
+
+ /**
+ * The list of service extension parameters to pass to the Net_SMTP
+ * mailFrom() command.
+ * @var array
+ */
+ var $_extparams = array();
+
+ /**
+ * The SMTP host to connect to.
+ * @var string
+ */
+ var $host = 'localhost';
+
+ /**
+ * The port the SMTP server is on.
+ * @var integer
+ */
+ var $port = 25;
+
+ /**
+ * Should SMTP authentication be used?
+ *
+ * This value may be set to true, false or the name of a specific
+ * authentication method.
+ *
+ * If the value is set to true, the Net_SMTP package will attempt to use
+ * the best authentication method advertised by the remote SMTP server.
+ *
+ * @var mixed
+ */
+ var $auth = false;
+
+ /**
+ * The username to use if the SMTP server requires authentication.
+ * @var string
+ */
+ var $username = '';
+
+ /**
+ * The password to use if the SMTP server requires authentication.
+ * @var string
+ */
+ var $password = '';
+
+ /**
+ * Hostname or domain that will be sent to the remote SMTP server in the
+ * HELO / EHLO message.
+ *
+ * @var string
+ */
+ var $localhost = 'localhost';
+
+ /**
+ * SMTP connection timeout value. NULL indicates no timeout.
+ *
+ * @var integer
+ */
+ var $timeout = null;
+
+ /**
+ * Turn on Net_SMTP debugging?
+ *
+ * @var boolean $debug
+ */
+ var $debug = false;
+
+ /**
+ * Indicates whether or not the SMTP connection should persist over
+ * multiple calls to the send() method.
+ *
+ * @var boolean
+ */
+ var $persist = false;
+
+ /**
+ * Use SMTP command pipelining (specified in RFC 2920) if the SMTP server
+ * supports it. This speeds up delivery over high-latency connections. By
+ * default, use the default value supplied by Net_SMTP.
+ * @var bool
+ */
+ var $pipelining;
+
+ /**
+ * Constructor.
+ *
+ * Instantiates a new Mail_smtp:: object based on the parameters
+ * passed in. It looks for the following parameters:
+ * host The server to connect to. Defaults to localhost.
+ * port The port to connect to. Defaults to 25.
+ * auth SMTP authentication. Defaults to none.
+ * username The username to use for SMTP auth. No default.
+ * password The password to use for SMTP auth. No default.
+ * localhost The local hostname / domain. Defaults to localhost.
+ * timeout The SMTP connection timeout. Defaults to none.
+ * verp Whether to use VERP or not. Defaults to false.
+ * DEPRECATED as of 1.2.0 (use setMailParams()).
+ * debug Activate SMTP debug mode? Defaults to false.
+ * persist Should the SMTP connection persist?
+ * pipelining Use SMTP command pipelining
+ *
+ * If a parameter is present in the $params array, it replaces the
+ * default.
+ *
+ * @param array Hash containing any parameters different from the
+ * defaults.
+ * @access public
+ */
+ function Mail_smtp($params)
+ {
+ if (isset($params['host'])) $this->host = $params['host'];
+ if (isset($params['port'])) $this->port = $params['port'];
+ if (isset($params['auth'])) $this->auth = $params['auth'];
+ if (isset($params['username'])) $this->username = $params['username'];
+ if (isset($params['password'])) $this->password = $params['password'];
+ if (isset($params['localhost'])) $this->localhost = $params['localhost'];
+ if (isset($params['timeout'])) $this->timeout = $params['timeout'];
+ if (isset($params['debug'])) $this->debug = (bool)$params['debug'];
+ if (isset($params['persist'])) $this->persist = (bool)$params['persist'];
+ if (isset($params['pipelining'])) $this->pipelining = (bool)$params['pipelining'];
+
+ // Deprecated options
+ if (isset($params['verp'])) {
+ $this->addServiceExtensionParameter('XVERP', is_bool($params['verp']) ? null : $params['verp']);
+ }
+
+ register_shutdown_function(array(&$this, '_Mail_smtp'));
+ }
+
+ /**
+ * Destructor implementation to ensure that we disconnect from any
+ * potentially-alive persistent SMTP connections.
+ */
+ function _Mail_smtp()
+ {
+ $this->disconnect();
+ }
+
+ /**
+ * Implements Mail::send() function using SMTP.
+ *
+ * @param mixed $recipients Either a comma-seperated list of recipients
+ * (RFC822 compliant), or an array of recipients,
+ * each RFC822 valid. This may contain recipients not
+ * specified in the headers, for Bcc:, resending
+ * messages, etc.
+ *
+ * @param array $headers The array of headers to send with the mail, in an
+ * associative array, where the array key is the
+ * header name (e.g., 'Subject'), and the array value
+ * is the header value (e.g., 'test'). The header
+ * produced from those values would be 'Subject:
+ * test'.
+ *
+ * @param string $body The full text of the message body, including any
+ * MIME parts, etc.
+ *
+ * @return mixed Returns true on success, or a PEAR_Error
+ * containing a descriptive error message on
+ * failure.
+ * @access public
+ */
+ function send($recipients, $headers, $body)
+ {
+ /* If we don't already have an SMTP object, create one. */
+ $result = &$this->getSMTPObject();
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ $this->_sanitizeHeaders($headers);
+
+ $headerElements = $this->prepareHeaders($headers);
+ if (is_a($headerElements, 'PEAR_Error')) {
+ $this->_smtp->rset();
+ return $headerElements;
+ }
+ list($from, $textHeaders) = $headerElements;
+
+ /* Since few MTAs are going to allow this header to be forged
+ * unless it's in the MAIL FROM: exchange, we'll use
+ * Return-Path instead of From: if it's set. */
+ if (!empty($headers['Return-Path'])) {
+ $from = $headers['Return-Path'];
+ }
+
+ if (!isset($from)) {
+ $this->_smtp->rset();
+ return PEAR::raiseError('No From: address has been provided',
+ PEAR_MAIL_SMTP_ERROR_FROM);
+ }
+
+ $params = null;
+ if (!empty($this->_extparams)) {
+ foreach ($this->_extparams as $key => $val) {
+ $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val);
+ }
+ }
+ if (PEAR::isError($res = $this->_smtp->mailFrom($from, ltrim($params)))) {
+ list($code, $error) = $this->_error(
+ "Failed to set sender: $from", $res, PEAR_MAIL_SMTP_ERROR_SENDER);
+ $this->_smtp->rset();
+ return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER,
+ null,null,array('smtpcode' => $code)
+ );
+ }
+
+ $recipients = $this->parseRecipients($recipients);
+ if (is_a($recipients, 'PEAR_Error')) {
+ $this->_smtp->rset();
+ return $recipients;
+ }
+
+ foreach ($recipients as $recipient) {
+ $res = $this->_smtp->rcptTo($recipient);
+ if (is_a($res, 'PEAR_Error')) {
+ list($code, $error) = $this->_error("Failed to add recipient: $recipient", $res);
+ $this->_smtp->rset();
+ return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT,
+ null,null,array('smtpcode' => $code)
+ );
+ }
+ }
+
+ /* Send the message's headers and the body as SMTP data. */
+ $res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body);
+ list(,$args) = $this->_smtp->getResponse();
+
+ if (preg_match("/Ok: queued as (.*)/", $args, $queued)) {
+ $this->queued_as = $queued[1];
+ }
+
+ /* we need the greeting; from it we can extract the authorative name of the mail server we've really connected to.
+ * ideal if we're connecting to a round-robin of relay servers and need to track which exact one took the email */
+ $this->greeting = $this->_smtp->getGreeting();
+
+ if (is_a($res, 'PEAR_Error')) {
+ list($code,$error) = $this->_error('Failed to send data', $res);
+ $this->_smtp->rset();
+ return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA,
+ null,null,array('smtpcode' => $code)
+ );
+ }
+
+ /* If persistent connections are disabled, destroy our SMTP object. */
+ if ($this->persist === false) {
+ $this->disconnect();
+ }
+
+ return true;
+ }
+
+ /**
+ * Connect to the SMTP server by instantiating a Net_SMTP object.
+ *
+ * @return mixed Returns a reference to the Net_SMTP object on success, or
+ * a PEAR_Error containing a descriptive error message on
+ * failure.
+ *
+ * @since 1.2.0
+ * @access public
+ */
+ function &getSMTPObject()
+ {
+ if (is_object($this->_smtp) !== false) {
+ return $this->_smtp;
+ }
+
+ include_once 'Net/SMTP.php';
+ $this->_smtp = &new Net_SMTP($this->host,
+ $this->port,
+ $this->localhost);
+
+ /* If we still don't have an SMTP object at this point, fail. */
+ if (is_object($this->_smtp) === false) {
+ return PEAR::raiseError('Failed to create a Net_SMTP object',
+ PEAR_MAIL_SMTP_ERROR_CREATE);
+ }
+
+ /* Configure the SMTP connection. */
+ if ($this->debug) {
+ $this->_smtp->setDebug(true);
+ }
+
+ /* Attempt to connect to the configured SMTP server. */
+ if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {
+ list($code, $error) = $this->_error('Failed to connect to ' .
+ $this->host . ':' . $this->port,
+ $res);
+ return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT,
+ null,null,array('smtpcode' => $code));
+ }
+
+ /* Attempt to authenticate if authentication has been enabled. */
+ if ($this->auth) {
+ $method = is_string($this->auth) ? $this->auth : '';
+
+ if (PEAR::isError($res = $this->_smtp->auth($this->username,
+ $this->password,
+ $method))) {
+
+ list($code, $error) =$this->_error("$method authentication failure",
+ $res);
+ $this->_smtp->rset();
+ return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH,
+ null,null,array('smtpcode' => $code)
+ );
+ }
+ }
+
+ return $this->_smtp;
+ }
+
+ /**
+ * Add parameter associated with a SMTP service extension.
+ *
+ * @param string Extension keyword.
+ * @param string Any value the keyword needs.
+ *
+ * @since 1.2.0
+ * @access public
+ */
+ function addServiceExtensionParameter($keyword, $value = null)
+ {
+ $this->_extparams[$keyword] = $value;
+ }
+
+ /**
+ * Disconnect and destroy the current SMTP connection.
+ *
+ * @return boolean True if the SMTP connection no longer exists.
+ *
+ * @since 1.1.9
+ * @access public
+ */
+ function disconnect()
+ {
+ /* If we have an SMTP object, disconnect and destroy it. */
+ if (is_object($this->_smtp) && $this->_smtp->disconnect()) {
+ $this->_smtp = null;
+ }
+
+ /* We are disconnected if we no longer have an SMTP object. */
+ return ($this->_smtp === null);
+ }
+
+ /**
+ * Build a standardized string describing the current SMTP error.
+ *
+ * @param string $text Custom string describing the error context.
+ * @param object $error Reference to the current PEAR_Error object.
+ *
+ * @return string A string describing the current SMTP error.
+ *
+ * @since 1.1.7
+ * @access private
+ */
+ function _error($text, &$error, $eid=false)
+ {
+ /* Split the SMTP response into a code and a response string. */
+ list($code, $response) = $this->_smtp->getResponse();
+
+ /* Build our standardized error string. */
+ return array($code, $text
+ . ' [SMTP: ' . $error->getMessage()
+ . " (code: $code, response: $response)]"
+ );
+
+ }
+
+
+}
-<?PHP\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * SMTP MX\r
- *\r
- * SMTP MX implementation of the PEAR Mail interface. Requires the Net_SMTP class.\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: This source file is subject to version 3.0 of the PHP license\r
- * that is available through the world-wide-web at the following URI:\r
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of\r
- * the PHP License and are unable to obtain it through the web, please\r
- * send a note to license@php.net so we can mail you a copy immediately.\r
- *\r
- * @category Mail\r
- * @package Mail_smtpmx\r
- * @author gERD Schaufelberger <gerd@php-tools.net>\r
- * @copyright 1997-2005 The PHP Group\r
- * @license http://www.php.net/license/3_0.txt PHP License 3.0\r
- * @version CVS: $Id: smtpmx.php,v 1.2 2007/10/06 17:00:00 chagenbu Exp $\r
- * @see Mail\r
- */\r
-\r
-require_once 'Net/SMTP.php';\r
-\r
-/**\r
- * SMTP MX implementation of the PEAR Mail interface. Requires the Net_SMTP class.\r
- *\r
- *\r
- * @access public\r
- * @author gERD Schaufelberger <gerd@php-tools.net>\r
- * @package Mail\r
- * @version $Revision: 1.2 $\r
- */\r
-class Mail_smtpmx extends Mail {\r
-\r
- /**\r
- * SMTP connection object.\r
- *\r
- * @var object\r
- * @access private\r
- */\r
- var $_smtp = null;\r
-\r
- /**\r
- * The port the SMTP server is on.\r
- * @var integer\r
- * @see getservicebyname()\r
- */\r
- var $port = 25;\r
-\r
- /**\r
- * Hostname or domain that will be sent to the remote SMTP server in the\r
- * HELO / EHLO message.\r
- *\r
- * @var string\r
- * @see posix_uname()\r
- */\r
- var $mailname = 'localhost';\r
-\r
- /**\r
- * SMTP connection timeout value. NULL indicates no timeout.\r
- *\r
- * @var integer\r
- */\r
- var $timeout = 10;\r
-\r
- /**\r
- * use either PEAR:Net_DNS or getmxrr\r
- *\r
- * @var boolean\r
- */\r
- var $withNetDns = true;\r
-\r
- /**\r
- * PEAR:Net_DNS_Resolver\r
- *\r
- * @var object\r
- */\r
- var $resolver;\r
-\r
- /**\r
- * Whether to use VERP or not. If not a boolean, the string value\r
- * will be used as the VERP separators.\r
- *\r
- * @var mixed boolean or string\r
- */\r
- var $verp = false;\r
-\r
- /**\r
- * Whether to use VRFY or not.\r
- *\r
- * @var boolean $vrfy\r
- */\r
- var $vrfy = false;\r
-\r
- /**\r
- * Switch to test mode - don't send emails for real\r
- *\r
- * @var boolean $debug\r
- */\r
- var $test = false;\r
-\r
- /**\r
- * Turn on Net_SMTP debugging?\r
- *\r
- * @var boolean $peardebug\r
- */\r
- var $debug = false;\r
-\r
- /**\r
- * internal error codes\r
- *\r
- * translate internal error identifier to PEAR-Error codes and human\r
- * readable messages.\r
- *\r
- * @var boolean $debug\r
- * @todo as I need unique error-codes to identify what exactly went wrond\r
- * I did not use intergers as it should be. Instead I added a "namespace"\r
- * for each code. This avoids conflicts with error codes from different\r
- * classes. How can I use unique error codes and stay conform with PEAR?\r
- */\r
- var $errorCode = array(\r
- 'not_connected' => array(\r
- 'code' => 1,\r
- 'msg' => 'Could not connect to any mail server ({HOST}) at port {PORT} to send mail to {RCPT}.'\r
- ),\r
- 'failed_vrfy_rcpt' => array(\r
- 'code' => 2,\r
- 'msg' => 'Recipient "{RCPT}" could not be veryfied.'\r
- ),\r
- 'failed_set_from' => array(\r
- 'code' => 3,\r
- 'msg' => 'Failed to set sender: {FROM}.'\r
- ),\r
- 'failed_set_rcpt' => array(\r
- 'code' => 4,\r
- 'msg' => 'Failed to set recipient: {RCPT}.'\r
- ),\r
- 'failed_send_data' => array(\r
- 'code' => 5,\r
- 'msg' => 'Failed to send mail to: {RCPT}.'\r
- ),\r
- 'no_from' => array(\r
- 'code' => 5,\r
- 'msg' => 'No from address has be provided.'\r
- ),\r
- 'send_data' => array(\r
- 'code' => 7,\r
- 'msg' => 'Failed to create Net_SMTP object.'\r
- ),\r
- 'no_mx' => array(\r
- 'code' => 8,\r
- 'msg' => 'No MX-record for {RCPT} found.'\r
- ),\r
- 'no_resolver' => array(\r
- 'code' => 9,\r
- 'msg' => 'Could not start resolver! Install PEAR:Net_DNS or switch off "netdns"'\r
- ),\r
- 'failed_rset' => array(\r
- 'code' => 10,\r
- 'msg' => 'RSET command failed, SMTP-connection corrupt.'\r
- ),\r
- );\r
-\r
- /**\r
- * Constructor.\r
- *\r
- * Instantiates a new Mail_smtp:: object based on the parameters\r
- * passed in. It looks for the following parameters:\r
- * mailname The name of the local mail system (a valid hostname which matches the reverse lookup)\r
- * port smtp-port - the default comes from getservicebyname() and should work fine\r
- * timeout The SMTP connection timeout. Defaults to 30 seconds.\r
- * vrfy Whether to use VRFY or not. Defaults to false.\r
- * verp Whether to use VERP or not. Defaults to false.\r
- * test Activate test mode? Defaults to false.\r
- * debug Activate SMTP and Net_DNS debug mode? Defaults to false.\r
- * netdns whether to use PEAR:Net_DNS or the PHP build in function getmxrr, default is true\r
- *\r
- * If a parameter is present in the $params array, it replaces the\r
- * default.\r
- *\r
- * @access public\r
- * @param array Hash containing any parameters different from the\r
- * defaults.\r
- * @see _Mail_smtpmx()\r
- */\r
- function __construct($params)\r
- {\r
- if (isset($params['mailname'])) {\r
- $this->mailname = $params['mailname'];\r
- } else {\r
- // try to find a valid mailname\r
- if (function_exists('posix_uname')) {\r
- $uname = posix_uname();\r
- $this->mailname = $uname['nodename'];\r
- }\r
- }\r
-\r
- // port number\r
- if (isset($params['port'])) {\r
- $this->_port = $params['port'];\r
- } else {\r
- $this->_port = getservbyname('smtp', 'tcp');\r
- }\r
-\r
- if (isset($params['timeout'])) $this->timeout = $params['timeout'];\r
- if (isset($params['verp'])) $this->verp = $params['verp'];\r
- if (isset($params['test'])) $this->test = $params['test'];\r
- if (isset($params['peardebug'])) $this->test = $params['peardebug'];\r
- if (isset($params['netdns'])) $this->withNetDns = $params['netdns'];\r
- }\r
-\r
- /**\r
- * Constructor wrapper for PHP4\r
- *\r
- * @access public\r
- * @param array Hash containing any parameters different from the defaults\r
- * @see __construct()\r
- */\r
- function Mail_smtpmx($params)\r
- {\r
- $this->__construct($params);\r
- register_shutdown_function(array(&$this, '__destruct'));\r
- }\r
-\r
- /**\r
- * Destructor implementation to ensure that we disconnect from any\r
- * potentially-alive persistent SMTP connections.\r
- */\r
- function __destruct()\r
- {\r
- if (is_object($this->_smtp)) {\r
- $this->_smtp->disconnect();\r
- $this->_smtp = null;\r
- }\r
- }\r
-\r
- /**\r
- * Implements Mail::send() function using SMTP direct delivery\r
- *\r
- * @access public\r
- * @param mixed $recipients in RFC822 style or array\r
- * @param array $headers The array of headers to send with the mail.\r
- * @param string $body The full text of the message body,\r
- * @return mixed Returns true on success, or a PEAR_Error\r
- */\r
- function send($recipients, $headers, $body)\r
- {\r
- if (!is_array($headers)) {\r
- return PEAR::raiseError('$headers must be an array');\r
- }\r
-\r
- $result = $this->_sanitizeHeaders($headers);\r
- if (is_a($result, 'PEAR_Error')) {\r
- return $result;\r
- }\r
-\r
- // Prepare headers\r
- $headerElements = $this->prepareHeaders($headers);\r
- if (is_a($headerElements, 'PEAR_Error')) {\r
- return $headerElements;\r
- }\r
- list($from, $textHeaders) = $headerElements;\r
-\r
- // use 'Return-Path' if possible\r
- if (!empty($headers['Return-Path'])) {\r
- $from = $headers['Return-Path'];\r
- }\r
- if (!isset($from)) {\r
- return $this->_raiseError('no_from');\r
- }\r
-\r
- // Prepare recipients\r
- $recipients = $this->parseRecipients($recipients);\r
- if (is_a($recipients, 'PEAR_Error')) {\r
- return $recipients;\r
- }\r
-\r
- foreach ($recipients as $rcpt) {\r
- list($user, $host) = explode('@', $rcpt);\r
-\r
- $mx = $this->_getMx($host);\r
- if (is_a($mx, 'PEAR_Error')) {\r
- return $mx;\r
- }\r
-\r
- if (empty($mx)) {\r
- $info = array('rcpt' => $rcpt);\r
- return $this->_raiseError('no_mx', $info);\r
- }\r
-\r
- $connected = false;\r
- foreach ($mx as $mserver => $mpriority) {\r
- $this->_smtp = new Net_SMTP($mserver, $this->port, $this->mailname);\r
-\r
- // configure the SMTP connection.\r
- if ($this->debug) {\r
- $this->_smtp->setDebug(true);\r
- }\r
-\r
- // attempt to connect to the configured SMTP server.\r
- $res = $this->_smtp->connect($this->timeout);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $this->_smtp = null;\r
- continue;\r
- }\r
-\r
- // connection established\r
- if ($res) {\r
- $connected = true;\r
- break;\r
- }\r
- }\r
-\r
- if (!$connected) {\r
- $info = array(\r
- 'host' => implode(', ', array_keys($mx)),\r
- 'port' => $this->port,\r
- 'rcpt' => $rcpt,\r
- );\r
- return $this->_raiseError('not_connected', $info);\r
- }\r
-\r
- // Verify recipient\r
- if ($this->vrfy) {\r
- $res = $this->_smtp->vrfy($rcpt);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $info = array('rcpt' => $rcpt);\r
- return $this->_raiseError('failed_vrfy_rcpt', $info);\r
- }\r
- }\r
-\r
- // mail from:\r
- $args['verp'] = $this->verp;\r
- $res = $this->_smtp->mailFrom($from, $args);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $info = array('from' => $from);\r
- return $this->_raiseError('failed_set_from', $info);\r
- }\r
-\r
- // rcpt to:\r
- $res = $this->_smtp->rcptTo($rcpt);\r
- if (is_a($res, 'PEAR_Error')) {\r
- $info = array('rcpt' => $rcpt);\r
- return $this->_raiseError('failed_set_rcpt', $info);\r
- }\r
-\r
- // Don't send anything in test mode\r
- if ($this->test) {\r
- $result = $this->_smtp->rset();\r
- $res = $this->_smtp->rset();\r
- if (is_a($res, 'PEAR_Error')) {\r
- return $this->_raiseError('failed_rset');\r
- }\r
-\r
- $this->_smtp->disconnect();\r
- $this->_smtp = null;\r
- return true;\r
- }\r
-\r
- // Send data\r
- $res = $this->_smtp->data("$textHeaders\r\n$body");\r
- if (is_a($res, 'PEAR_Error')) {\r
- $info = array('rcpt' => $rcpt);\r
- return $this->_raiseError('failed_send_data', $info);\r
- }\r
-\r
- $this->_smtp->disconnect();\r
- $this->_smtp = null;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * Recieve mx rexords for a spciefied host\r
- *\r
- * The MX records\r
- *\r
- * @access private\r
- * @param string $host mail host\r
- * @return mixed sorted\r
- */\r
- function _getMx($host)\r
- {\r
- $mx = array();\r
-\r
- if ($this->withNetDns) {\r
- $res = $this->_loadNetDns();\r
- if (is_a($res, 'PEAR_Error')) {\r
- return $res;\r
- }\r
-\r
- $response = $this->resolver->query($host, 'MX');\r
- if (!$response) {\r
- return false;\r
- }\r
-\r
- foreach ($response->answer as $rr) {\r
- if ($rr->type == 'MX') {\r
- $mx[$rr->exchange] = $rr->preference;\r
- }\r
- }\r
- } else {\r
- $mxHost = array();\r
- $mxWeight = array();\r
-\r
- if (!getmxrr($host, $mxHost, $mxWeight)) {\r
- return false;\r
- }\r
- for ($i = 0; $i < count($mxHost); ++$i) {\r
- $mx[$mxHost[$i]] = $mxWeight[$i];\r
- }\r
- }\r
-\r
- asort($mx);\r
- return $mx;\r
- }\r
-\r
- /**\r
- * initialize PEAR:Net_DNS_Resolver\r
- *\r
- * @access private\r
- * @return boolean true on success\r
- */\r
- function _loadNetDns()\r
- {\r
- if (is_object($this->resolver)) {\r
- return true;\r
- }\r
-\r
- if (!include_once 'Net/DNS.php') {\r
- return $this->_raiseError('no_resolver');\r
- }\r
-\r
- $this->resolver = new Net_DNS_Resolver();\r
- if ($this->debug) {\r
- $this->resolver->test = 1;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * raise standardized error\r
- *\r
- * include additional information in error message\r
- *\r
- * @access private\r
- * @param string $id maps error ids to codes and message\r
- * @param array $info optional information in associative array\r
- * @see _errorCode\r
- */\r
- function _raiseError($id, $info = array())\r
- {\r
- $code = $this->errorCode[$id]['code'];\r
- $msg = $this->errorCode[$id]['msg'];\r
-\r
- // include info to messages\r
- if (!empty($info)) {\r
- $search = array();\r
- $replace = array();\r
-\r
- foreach ($info as $key => $value) {\r
- array_push($search, '{' . strtoupper($key) . '}');\r
- array_push($replace, $value);\r
- }\r
-\r
- $msg = str_replace($search, $replace, $msg);\r
- }\r
-\r
- return PEAR::raiseError($msg, $code);\r
- }\r
-\r
-}\r
+<?PHP
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * SMTP MX
+ *
+ * SMTP MX implementation of the PEAR Mail interface. Requires the Net_SMTP class.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2010, gERD Schaufelberger
+ * 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.
+ *
+ * @category Mail
+ * @package Mail_smtpmx
+ * @author gERD Schaufelberger <gerd@php-tools.net>
+ * @copyright 2010 gERD Schaufelberger
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: smtpmx.php 294747 2010-02-08 08:18:33Z clockwerx $
+ * @link http://pear.php.net/package/Mail/
+ */
+
+require_once 'Net/SMTP.php';
+
+/**
+ * SMTP MX implementation of the PEAR Mail interface. Requires the Net_SMTP class.
+ *
+ *
+ * @access public
+ * @author gERD Schaufelberger <gerd@php-tools.net>
+ * @package Mail
+ * @version $Revision: 294747 $
+ */
+class Mail_smtpmx extends Mail {
+
+ /**
+ * SMTP connection object.
+ *
+ * @var object
+ * @access private
+ */
+ var $_smtp = null;
+
+ /**
+ * The port the SMTP server is on.
+ * @var integer
+ * @see getservicebyname()
+ */
+ var $port = 25;
+
+ /**
+ * Hostname or domain that will be sent to the remote SMTP server in the
+ * HELO / EHLO message.
+ *
+ * @var string
+ * @see posix_uname()
+ */
+ var $mailname = 'localhost';
+
+ /**
+ * SMTP connection timeout value. NULL indicates no timeout.
+ *
+ * @var integer
+ */
+ var $timeout = 10;
+
+ /**
+ * use either PEAR:Net_DNS or getmxrr
+ *
+ * @var boolean
+ */
+ var $withNetDns = true;
+
+ /**
+ * PEAR:Net_DNS_Resolver
+ *
+ * @var object
+ */
+ var $resolver;
+
+ /**
+ * Whether to use VERP or not. If not a boolean, the string value
+ * will be used as the VERP separators.
+ *
+ * @var mixed boolean or string
+ */
+ var $verp = false;
+
+ /**
+ * Whether to use VRFY or not.
+ *
+ * @var boolean $vrfy
+ */
+ var $vrfy = false;
+
+ /**
+ * Switch to test mode - don't send emails for real
+ *
+ * @var boolean $debug
+ */
+ var $test = false;
+
+ /**
+ * Turn on Net_SMTP debugging?
+ *
+ * @var boolean $peardebug
+ */
+ var $debug = false;
+
+ /**
+ * internal error codes
+ *
+ * translate internal error identifier to PEAR-Error codes and human
+ * readable messages.
+ *
+ * @var boolean $debug
+ * @todo as I need unique error-codes to identify what exactly went wrond
+ * I did not use intergers as it should be. Instead I added a "namespace"
+ * for each code. This avoids conflicts with error codes from different
+ * classes. How can I use unique error codes and stay conform with PEAR?
+ */
+ var $errorCode = array(
+ 'not_connected' => array(
+ 'code' => 1,
+ 'msg' => 'Could not connect to any mail server ({HOST}) at port {PORT} to send mail to {RCPT}.'
+ ),
+ 'failed_vrfy_rcpt' => array(
+ 'code' => 2,
+ 'msg' => 'Recipient "{RCPT}" could not be veryfied.'
+ ),
+ 'failed_set_from' => array(
+ 'code' => 3,
+ 'msg' => 'Failed to set sender: {FROM}.'
+ ),
+ 'failed_set_rcpt' => array(
+ 'code' => 4,
+ 'msg' => 'Failed to set recipient: {RCPT}.'
+ ),
+ 'failed_send_data' => array(
+ 'code' => 5,
+ 'msg' => 'Failed to send mail to: {RCPT}.'
+ ),
+ 'no_from' => array(
+ 'code' => 5,
+ 'msg' => 'No from address has be provided.'
+ ),
+ 'send_data' => array(
+ 'code' => 7,
+ 'msg' => 'Failed to create Net_SMTP object.'
+ ),
+ 'no_mx' => array(
+ 'code' => 8,
+ 'msg' => 'No MX-record for {RCPT} found.'
+ ),
+ 'no_resolver' => array(
+ 'code' => 9,
+ 'msg' => 'Could not start resolver! Install PEAR:Net_DNS or switch off "netdns"'
+ ),
+ 'failed_rset' => array(
+ 'code' => 10,
+ 'msg' => 'RSET command failed, SMTP-connection corrupt.'
+ ),
+ );
+
+ /**
+ * Constructor.
+ *
+ * Instantiates a new Mail_smtp:: object based on the parameters
+ * passed in. It looks for the following parameters:
+ * mailname The name of the local mail system (a valid hostname which matches the reverse lookup)
+ * port smtp-port - the default comes from getservicebyname() and should work fine
+ * timeout The SMTP connection timeout. Defaults to 30 seconds.
+ * vrfy Whether to use VRFY or not. Defaults to false.
+ * verp Whether to use VERP or not. Defaults to false.
+ * test Activate test mode? Defaults to false.
+ * debug Activate SMTP and Net_DNS debug mode? Defaults to false.
+ * netdns whether to use PEAR:Net_DNS or the PHP build in function getmxrr, default is true
+ *
+ * If a parameter is present in the $params array, it replaces the
+ * default.
+ *
+ * @access public
+ * @param array Hash containing any parameters different from the
+ * defaults.
+ * @see _Mail_smtpmx()
+ */
+ function __construct($params)
+ {
+ if (isset($params['mailname'])) {
+ $this->mailname = $params['mailname'];
+ } else {
+ // try to find a valid mailname
+ if (function_exists('posix_uname')) {
+ $uname = posix_uname();
+ $this->mailname = $uname['nodename'];
+ }
+ }
+
+ // port number
+ if (isset($params['port'])) {
+ $this->_port = $params['port'];
+ } else {
+ $this->_port = getservbyname('smtp', 'tcp');
+ }
+
+ if (isset($params['timeout'])) $this->timeout = $params['timeout'];
+ if (isset($params['verp'])) $this->verp = $params['verp'];
+ if (isset($params['test'])) $this->test = $params['test'];
+ if (isset($params['peardebug'])) $this->test = $params['peardebug'];
+ if (isset($params['netdns'])) $this->withNetDns = $params['netdns'];
+ }
+
+ /**
+ * Constructor wrapper for PHP4
+ *
+ * @access public
+ * @param array Hash containing any parameters different from the defaults
+ * @see __construct()
+ */
+ function Mail_smtpmx($params)
+ {
+ $this->__construct($params);
+ register_shutdown_function(array(&$this, '__destruct'));
+ }
+
+ /**
+ * Destructor implementation to ensure that we disconnect from any
+ * potentially-alive persistent SMTP connections.
+ */
+ function __destruct()
+ {
+ if (is_object($this->_smtp)) {
+ $this->_smtp->disconnect();
+ $this->_smtp = null;
+ }
+ }
+
+ /**
+ * Implements Mail::send() function using SMTP direct delivery
+ *
+ * @access public
+ * @param mixed $recipients in RFC822 style or array
+ * @param array $headers The array of headers to send with the mail.
+ * @param string $body The full text of the message body,
+ * @return mixed Returns true on success, or a PEAR_Error
+ */
+ function send($recipients, $headers, $body)
+ {
+ if (!is_array($headers)) {
+ return PEAR::raiseError('$headers must be an array');
+ }
+
+ $result = $this->_sanitizeHeaders($headers);
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ // Prepare headers
+ $headerElements = $this->prepareHeaders($headers);
+ if (is_a($headerElements, 'PEAR_Error')) {
+ return $headerElements;
+ }
+ list($from, $textHeaders) = $headerElements;
+
+ // use 'Return-Path' if possible
+ if (!empty($headers['Return-Path'])) {
+ $from = $headers['Return-Path'];
+ }
+ if (!isset($from)) {
+ return $this->_raiseError('no_from');
+ }
+
+ // Prepare recipients
+ $recipients = $this->parseRecipients($recipients);
+ if (is_a($recipients, 'PEAR_Error')) {
+ return $recipients;
+ }
+
+ foreach ($recipients as $rcpt) {
+ list($user, $host) = explode('@', $rcpt);
+
+ $mx = $this->_getMx($host);
+ if (is_a($mx, 'PEAR_Error')) {
+ return $mx;
+ }
+
+ if (empty($mx)) {
+ $info = array('rcpt' => $rcpt);
+ return $this->_raiseError('no_mx', $info);
+ }
+
+ $connected = false;
+ foreach ($mx as $mserver => $mpriority) {
+ $this->_smtp = new Net_SMTP($mserver, $this->port, $this->mailname);
+
+ // configure the SMTP connection.
+ if ($this->debug) {
+ $this->_smtp->setDebug(true);
+ }
+
+ // attempt to connect to the configured SMTP server.
+ $res = $this->_smtp->connect($this->timeout);
+ if (is_a($res, 'PEAR_Error')) {
+ $this->_smtp = null;
+ continue;
+ }
+
+ // connection established
+ if ($res) {
+ $connected = true;
+ break;
+ }
+ }
+
+ if (!$connected) {
+ $info = array(
+ 'host' => implode(', ', array_keys($mx)),
+ 'port' => $this->port,
+ 'rcpt' => $rcpt,
+ );
+ return $this->_raiseError('not_connected', $info);
+ }
+
+ // Verify recipient
+ if ($this->vrfy) {
+ $res = $this->_smtp->vrfy($rcpt);
+ if (is_a($res, 'PEAR_Error')) {
+ $info = array('rcpt' => $rcpt);
+ return $this->_raiseError('failed_vrfy_rcpt', $info);
+ }
+ }
+
+ // mail from:
+ $args['verp'] = $this->verp;
+ $res = $this->_smtp->mailFrom($from, $args);
+ if (is_a($res, 'PEAR_Error')) {
+ $info = array('from' => $from);
+ return $this->_raiseError('failed_set_from', $info);
+ }
+
+ // rcpt to:
+ $res = $this->_smtp->rcptTo($rcpt);
+ if (is_a($res, 'PEAR_Error')) {
+ $info = array('rcpt' => $rcpt);
+ return $this->_raiseError('failed_set_rcpt', $info);
+ }
+
+ // Don't send anything in test mode
+ if ($this->test) {
+ $result = $this->_smtp->rset();
+ $res = $this->_smtp->rset();
+ if (is_a($res, 'PEAR_Error')) {
+ return $this->_raiseError('failed_rset');
+ }
+
+ $this->_smtp->disconnect();
+ $this->_smtp = null;
+ return true;
+ }
+
+ // Send data
+ $res = $this->_smtp->data("$textHeaders\r\n$body");
+ if (is_a($res, 'PEAR_Error')) {
+ $info = array('rcpt' => $rcpt);
+ return $this->_raiseError('failed_send_data', $info);
+ }
+
+ $this->_smtp->disconnect();
+ $this->_smtp = null;
+ }
+
+ return true;
+ }
+
+ /**
+ * Recieve mx rexords for a spciefied host
+ *
+ * The MX records
+ *
+ * @access private
+ * @param string $host mail host
+ * @return mixed sorted
+ */
+ function _getMx($host)
+ {
+ $mx = array();
+
+ if ($this->withNetDns) {
+ $res = $this->_loadNetDns();
+ if (is_a($res, 'PEAR_Error')) {
+ return $res;
+ }
+
+ $response = $this->resolver->query($host, 'MX');
+ if (!$response) {
+ return false;
+ }
+
+ foreach ($response->answer as $rr) {
+ if ($rr->type == 'MX') {
+ $mx[$rr->exchange] = $rr->preference;
+ }
+ }
+ } else {
+ $mxHost = array();
+ $mxWeight = array();
+
+ if (!getmxrr($host, $mxHost, $mxWeight)) {
+ return false;
+ }
+ for ($i = 0; $i < count($mxHost); ++$i) {
+ $mx[$mxHost[$i]] = $mxWeight[$i];
+ }
+ }
+
+ asort($mx);
+ return $mx;
+ }
+
+ /**
+ * initialize PEAR:Net_DNS_Resolver
+ *
+ * @access private
+ * @return boolean true on success
+ */
+ function _loadNetDns()
+ {
+ if (is_object($this->resolver)) {
+ return true;
+ }
+
+ if (!include_once 'Net/DNS.php') {
+ return $this->_raiseError('no_resolver');
+ }
+
+ $this->resolver = new Net_DNS_Resolver();
+ if ($this->debug) {
+ $this->resolver->test = 1;
+ }
+
+ return true;
+ }
+
+ /**
+ * raise standardized error
+ *
+ * include additional information in error message
+ *
+ * @access private
+ * @param string $id maps error ids to codes and message
+ * @param array $info optional information in associative array
+ * @see _errorCode
+ */
+ function _raiseError($id, $info = array())
+ {
+ $code = $this->errorCode[$id]['code'];
+ $msg = $this->errorCode[$id]['msg'];
+
+ // include info to messages
+ if (!empty($info)) {
+ $search = array();
+ $replace = array();
+
+ foreach ($info as $key => $value) {
+ array_push($search, '{' . strtoupper($key) . '}');
+ array_push($replace, $value);
+ }
+
+ $msg = str_replace($search, $replace, $msg);
+ }
+
+ return PEAR::raiseError($msg, $code);
+ }
+
+}
// | Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar> |
// +----------------------------------------------------------------------+
//
-// $Id: SMTP.php 284052 2009-07-14 05:34:26Z jon $
+// $Id: SMTP.php 314875 2011-08-13 17:03:30Z jon $
require_once 'PEAR.php';
require_once 'Net/Socket.php';
* @var array
* @access public
*/
- var $auth_methods = array('DIGEST-MD5', 'CRAM-MD5', 'LOGIN', 'PLAIN');
+ var $auth_methods = array();
/**
* Use SMTP command pipelining (specified in RFC 2920) if the SMTP
*/
var $_socket = null;
+ /**
+ * Array of socket options that will be passed to Net_Socket::connect().
+ * @see stream_context_create()
+ * @var array
+ * @access private
+ */
+ var $_socket_options = null;
+
+ /**
+ * The socket I/O timeout value in seconds.
+ * @var int
+ * @access private
+ */
+ var $_timeout = 0;
+
/**
* The most recent server response code.
* @var int
* @param integer $port The port to connect to.
* @param string $localhost The value to give when sending EHLO or HELO.
* @param boolean $pipeling Use SMTP command pipelining
+ * @param integer $timeout Socket I/O timeout in seconds.
+ * @param array $socket_options Socket stream_context_create() options.
*
* @access public
* @since 1.0
*/
- function Net_SMTP($host = null, $port = null, $localhost = null, $pipelining = false)
+ function Net_SMTP($host = null, $port = null, $localhost = null,
+ $pipelining = false, $timeout = 0, $socket_options = null)
{
if (isset($host)) {
$this->host = $host;
$this->pipelining = $pipelining;
$this->_socket = new Net_Socket();
+ $this->_socket_options = $socket_options;
+ $this->_timeout = $timeout;
- /* Include the Auth_SASL package. If the package is not
- * available, we disable the authentication methods that
- * depend upon it. */
- if ((@include_once 'Auth/SASL.php') === false) {
- $pos = array_search('DIGEST-MD5', $this->auth_methods);
- unset($this->auth_methods[$pos]);
- $pos = array_search('CRAM-MD5', $this->auth_methods);
- unset($this->auth_methods[$pos]);
+ /* Include the Auth_SASL package. If the package is available, we
+ * enable the authentication methods that depend upon it. */
+ if (@include_once 'Auth/SASL.php') {
+ $this->setAuthMethod('CRAM-MD5', array($this, '_authCram_MD5'));
+ $this->setAuthMethod('DIGEST-MD5', array($this, '_authDigest_MD5'));
}
+
+ /* These standard authentication methods are always available. */
+ $this->setAuthMethod('LOGIN', array($this, '_authLogin'), false);
+ $this->setAuthMethod('PLAIN', array($this, '_authPlain'), false);
+ }
+
+ /**
+ * Set the socket I/O timeout value in seconds plus microseconds.
+ *
+ * @param integer $seconds Timeout value in seconds.
+ * @param integer $microseconds Additional value in microseconds.
+ *
+ * @access public
+ * @since 1.5.0
+ */
+ function setTimeout($seconds, $microseconds = 0) {
+ return $this->_socket->setTimeout($seconds, $microseconds);
}
/**
call_user_func_array($this->_debug_handler,
array(&$this, $message));
} else {
- echo "DEBUG: '$message'\n";
+ echo "DEBUG: $message\n";
}
}
}
*
* @param string $data The string of data to send.
*
- * @return mixed True on success or a PEAR_Error object on failure.
+ * @return mixed The number of bytes that were actually written,
+ * or a PEAR_Error object on failure.
*
* @access private
* @since 1.1.0
{
$this->_debug("Send: $data");
- $error = $this->_socket->write($data);
- if ($error === false || PEAR::isError($error)) {
- $msg = ($error) ? $error->getMessage() : "unknown error";
- return PEAR::raiseError("Failed to write to socket: $msg");
+ $result = $this->_socket->write($data);
+ if (!$result || PEAR::isError($result)) {
+ $msg = ($result) ? $result->getMessage() : "unknown error";
+ return PEAR::raiseError("Failed to write to socket: $msg",
+ null, PEAR_ERROR_RETURN);
}
- return true;
+ return $result;
}
/**
}
if (strcspn($command, "\r\n") !== strlen($command)) {
- return PEAR::raiseError('Commands cannot contain newlines');
+ return PEAR::raiseError('Commands cannot contain newlines',
+ null, PEAR_ERROR_RETURN);
}
- //return $this->_send($command . "\r\n");
- return $this->_send($command . "\n");
+ return $this->_send($command . "\r\n");
}
/**
while ($line = $this->_socket->readLine()) {
$this->_debug("Recv: $line");
- /* If we receive an empty line, the connection has been closed. */
+ /* If we receive an empty line, the connection was closed. */
if (empty($line)) {
$this->disconnect();
- return PEAR::raiseError('Connection was unexpectedly closed');
+ return PEAR::raiseError('Connection was closed',
+ null, PEAR_ERROR_RETURN);
}
/* Read the code and store the rest in the arguments array. */
}
return PEAR::raiseError('Invalid response code received from server',
- $this->_code);
+ $this->_code, PEAR_ERROR_RETURN);
+ }
+
+ /**
+ * Issue an SMTP command and verify its response.
+ *
+ * @param string $command The SMTP command string or data.
+ * @param mixed $valid The set of valid response codes. These
+ * may be specified as an array of integer
+ * values or as a single integer value.
+ *
+ * @return mixed True on success or a PEAR_Error object on failure.
+ *
+ * @access public
+ * @since 1.6.0
+ */
+ function command($command, $valid)
+ {
+ if (PEAR::isError($error = $this->_put($command))) {
+ return $error;
+ }
+ if (PEAR::isError($error = $this->_parseResponse($valid))) {
+ return $error;
+ }
+
+ return true;
}
/**
* Attempt to connect to the SMTP server.
*
* @param int $timeout The timeout value (in seconds) for the
- * socket connection.
+ * socket connection attempt.
* @param bool $persistent Should a persistent socket connection
* be used?
*
{
$this->_greeting = null;
$result = $this->_socket->connect($this->host, $this->port,
- $persistent, $timeout);
+ $persistent, $timeout,
+ $this->_socket_options);
if (PEAR::isError($result)) {
return PEAR::raiseError('Failed to connect socket: ' .
$result->getMessage());
}
+ /*
+ * Now that we're connected, reset the socket's timeout value for
+ * future I/O operations. This allows us to have different socket
+ * timeout values for the initial connection (our $timeout parameter)
+ * and all other socket operations.
+ */
+ if ($this->_timeout > 0) {
+ if (PEAR::isError($error = $this->setTimeout($this->_timeout))) {
+ return $error;
+ }
+ }
+
if (PEAR::isError($error = $this->_parseResponse(220))) {
return $error;
}
return $error;
}
if (PEAR::isError($this->_parseResponse(250))) {
- return PEAR::raiseError('HELO was not accepted: ', $this->_code);
+ return PEAR::raiseError('HELO was not accepted: ', $this->_code,
+ PEAR_ERROR_RETURN);
}
return true;
{
$available_methods = explode(' ', $this->_esmtp['AUTH']);
- foreach ($this->auth_methods as $method) {
+ foreach ($this->auth_methods as $method => $callback) {
if (in_array($method, $available_methods)) {
return $method;
}
}
- return PEAR::raiseError('No supported authentication methods');
+ return PEAR::raiseError('No supported authentication methods',
+ null, PEAR_ERROR_RETURN);
}
/**
* @param string The password to authenticate with.
* @param string The requested authentication method. If none is
* specified, the best supported method will be used.
+ * @param bool Flag indicating whether or not TLS should be attempted.
+ * @param string An optional authorization identifier. If specified, this
+ * identifier will be used as the authorization proxy.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
*/
- function auth($uid, $pwd , $method = '')
+ function auth($uid, $pwd , $method = '', $tls = true, $authz = '')
{
- /* We can only attempt a TLS connection if we're running PHP 5.1.0 or
- * later, have access to the OpenSSL extension, are connected to an
- * SMTP server which supports the STARTTLS extension, and aren't
- * already connected over a secure (SSL) socket connection. */
- $tls = version_compare(PHP_VERSION, '5.1.0', '>=') && extension_loaded('openssl') &&
- isset($this->_esmtp['STARTTLS']) && strncasecmp($this->host, 'ssl://', 6) != 0;
-
- if ($tls) {
+ /* We can only attempt a TLS connection if one has been requested,
+ * we're running PHP 5.1.0 or later, have access to the OpenSSL
+ * extension, are connected to an SMTP server which supports the
+ * STARTTLS extension, and aren't already connected over a secure
+ * (SSL) socket connection. */
+ if ($tls && version_compare(PHP_VERSION, '5.1.0', '>=') &&
+ extension_loaded('openssl') && isset($this->_esmtp['STARTTLS']) &&
+ strncasecmp($this->host, 'ssl://', 6) !== 0) {
+ /* Start the TLS connection attempt. */
if (PEAR::isError($result = $this->_put('STARTTLS'))) {
return $result;
}
}
} else {
$method = strtoupper($method);
- if (!in_array($method, $this->auth_methods)) {
+ if (!array_key_exists($method, $this->auth_methods)) {
return PEAR::raiseError("$method is not a supported authentication method");
}
}
- switch ($method) {
- case 'DIGEST-MD5':
- $result = $this->_authDigest_MD5($uid, $pwd);
- break;
-
- case 'CRAM-MD5':
- $result = $this->_authCRAM_MD5($uid, $pwd);
- break;
-
- case 'LOGIN':
- $result = $this->_authLogin($uid, $pwd);
- break;
-
- case 'PLAIN':
- $result = $this->_authPlain($uid, $pwd);
- break;
+ if (!isset($this->auth_methods[$method])) {
+ return PEAR::raiseError("$method is not a supported authentication method");
+ }
- default:
- $result = PEAR::raiseError("$method is not a supported authentication method");
- break;
+ if (!is_callable($this->auth_methods[$method], false)) {
+ return PEAR::raiseError("$method authentication method cannot be called");
}
+ if (is_array($this->auth_methods[$method])) {
+ list($object, $method) = $this->auth_methods[$method];
+ $result = $object->{$method}($uid, $pwd, $authz, $this);
+ } else {
+ $func = $this->auth_methods[$method];
+ $result = $func($uid, $pwd, $authz, $this);
+ }
+
/* If an error was encountered, return the PEAR_Error object. */
if (PEAR::isError($result)) {
return $result;
return true;
}
+ /**
+ * Add a new authentication method.
+ *
+ * @param string The authentication method name (e.g. 'PLAIN')
+ * @param mixed The authentication callback (given as the name of a
+ * function or as an (object, method name) array).
+ * @param bool Should the new method be prepended to the list of
+ * available methods? This is the default behavior,
+ * giving the new method the highest priority.
+ *
+ * @return mixed True on success or a PEAR_Error object on failure.
+ *
+ * @access public
+ * @since 1.6.0
+ */
+ function setAuthMethod($name, $callback, $prepend = true)
+ {
+ if (!is_string($name)) {
+ return PEAR::raiseError('Method name is not a string');
+ }
+
+ if (!is_string($callback) && !is_array($callback)) {
+ return PEAR::raiseError('Method callback must be string or array');
+ }
+
+ if (is_array($callback)) {
+ if (!is_object($callback[0]) || !is_string($callback[1]))
+ return PEAR::raiseError('Bad mMethod callback array');
+ }
+
+ if ($prepend) {
+ $this->auth_methods = array_merge(array($name => $callback),
+ $this->auth_methods);
+ } else {
+ $this->auth_methods[$name] = $callback;
+ }
+
+ return true;
+ }
+
/**
* Authenticates the user using the DIGEST-MD5 method.
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
+ * @param string The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
*/
- function _authDigest_MD5($uid, $pwd)
+ function _authDigest_MD5($uid, $pwd, $authz = '')
{
if (PEAR::isError($error = $this->_put('AUTH', 'DIGEST-MD5'))) {
return $error;
$challenge = base64_decode($this->_arguments[0]);
$digest = &Auth_SASL::factory('digestmd5');
$auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge,
- $this->host, "smtp"));
+ $this->host, "smtp",
+ $authz));
if (PEAR::isError($error = $this->_put($auth_str))) {
return $error;
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
+ * @param string The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
*/
- function _authCRAM_MD5($uid, $pwd)
+ function _authCRAM_MD5($uid, $pwd, $authz = '')
{
if (PEAR::isError($error = $this->_put('AUTH', 'CRAM-MD5'))) {
return $error;
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
+ * @param string The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
*/
- function _authLogin($uid, $pwd)
+ function _authLogin($uid, $pwd, $authz = '')
{
if (PEAR::isError($error = $this->_put('AUTH', 'LOGIN'))) {
return $error;
*
* @param string The userid to authenticate as.
* @param string The password to authenticate with.
+ * @param string The optional authorization proxy identifier.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access private
* @since 1.1.0
*/
- function _authPlain($uid, $pwd)
+ function _authPlain($uid, $pwd, $authz = '')
{
if (PEAR::isError($error = $this->_put('AUTH', 'PLAIN'))) {
return $error;
return $error;
}
- $auth_str = base64_encode(chr(0) . $uid . chr(0) . $pwd);
+ $auth_str = base64_encode($authz . chr(0) . $uid . chr(0) . $pwd);
if (PEAR::isError($error = $this->_put($auth_str))) {
return $error;
*/
function mailFrom($sender, $params = null)
{
- $args = "FROM: <$sender>";
+ $args = "FROM:<$sender>";
/* Support the deprecated array form of $params. */
if (is_array($params) && isset($params['verp'])) {
} elseif (trim($params['verp'])) {
$args .= ' XVERP=' . $params['verp'];
}
- } elseif (is_string($params) && !empty($parms)) {
+ } elseif (is_string($params) && !empty($params)) {
$args .= ' ' . $params;
}
/**
* Send the DATA command.
*
- * @param string $data The message body to send.
+ * @param mixed $data The message data, either as a string or an open
+ * file resource.
+ * @param string $headers The message headers. If $headers is provided,
+ * $data is assumed to contain only body data.
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
*/
- function data($data)
+ function data($data, $headers = null)
{
- /* RFC 1870, section 3, subsection 3 states "a value of zero
- * indicates that no fixed maximum message size is in force".
- * Furthermore, it says that if "the parameter is omitted no
- * information is conveyed about the server's fixed maximum
- * message size". */
- if (isset($this->_esmtp['SIZE']) && ($this->_esmtp['SIZE'] > 0)) {
- if (strlen($data) >= $this->_esmtp['SIZE']) {
- $this->disconnect();
- return PEAR::raiseError('Message size excedes the server limit');
+ /* Verify that $data is a supported type. */
+ if (!is_string($data) && !is_resource($data)) {
+ return PEAR::raiseError('Expected a string or file resource');
+ }
+
+ /* Start by considering the size of the optional headers string. We
+ * also account for the addition 4 character "\r\n\r\n" separator
+ * sequence. */
+ $size = (is_null($headers)) ? 0 : strlen($headers) + 4;
+
+ if (is_resource($data)) {
+ $stat = fstat($data);
+ if ($stat === false) {
+ return PEAR::raiseError('Failed to get file size');
}
+ $size += $stat['size'];
+ } else {
+ $size += strlen($data);
}
- /* Quote the data based on the SMTP standards. */
- $this->quotedata($data);
+ /* RFC 1870, section 3, subsection 3 states "a value of zero indicates
+ * that no fixed maximum message size is in force". Furthermore, it
+ * says that if "the parameter is omitted no information is conveyed
+ * about the server's fixed maximum message size". */
+ $limit = (isset($this->_esmtp['SIZE'])) ? $this->_esmtp['SIZE'] : 0;
+ if ($limit > 0 && $size >= $limit) {
+ $this->disconnect();
+ return PEAR::raiseError('Message size exceeds server limit');
+ }
+ /* Initiate the DATA command. */
if (PEAR::isError($error = $this->_put('DATA'))) {
return $error;
}
return $error;
}
- if (PEAR::isError($result = $this->_send($data . "\r\n.\r\n"))) {
+ /* If we have a separate headers string, send it first. */
+ if (!is_null($headers)) {
+ $this->quotedata($headers);
+ if (PEAR::isError($result = $this->_send($headers . "\r\n\r\n"))) {
+ return $result;
+ }
+ }
+
+ /* Now we can send the message body data. */
+ if (is_resource($data)) {
+ /* Stream the contents of the file resource out over our socket
+ * connection, line by line. Each line must be run through the
+ * quoting routine. */
+ while (strlen($line = fread($data, 8192)) > 0) {
+ /* If the last character is an newline, we need to grab the
+ * next character to check to see if it is a period. */
+ while (!feof($data)) {
+ $char = fread($data, 1);
+ $line .= $char;
+ if ($char != "\n") {
+ break;
+ }
+ }
+ $this->quotedata($line);
+ if (PEAR::isError($result = $this->_send($line))) {
+ return $result;
+ }
+ }
+ } else {
+ /*
+ * Break up the data by sending one chunk (up to 512k) at a time.
+ * This approach reduces our peak memory usage.
+ */
+ for ($offset = 0; $offset < $size;) {
+ $end = $offset + 512000;
+
+ /*
+ * Ensure we don't read beyond our data size or span multiple
+ * lines. quotedata() can't properly handle character data
+ * that's split across two line break boundaries.
+ */
+ if ($end >= $size) {
+ $end = $size;
+ } else {
+ for (; $end < $size; $end++) {
+ if ($data[$end] != "\n") {
+ break;
+ }
+ }
+ }
+
+ /* Extract our chunk and run it through the quoting routine. */
+ $chunk = substr($data, $offset, $end - $offset);
+ $this->quotedata($chunk);
+
+ /* If we run into a problem along the way, abort. */
+ if (PEAR::isError($result = $this->_send($chunk))) {
+ return $result;
+ }
+
+ /* Advance the offset to the end of this chunk. */
+ $offset = $end;
+ }
+ }
+
+ /* Finally, send the DATA terminator sequence. */
+ if (PEAR::isError($result = $this->_send("\r\n.\r\n"))) {
return $result;
}
+
+ /* Verify that the data was successfully received by the server. */
if (PEAR::isError($error = $this->_parseResponse(250, $this->pipelining))) {
return $error;
}
<?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.38 2008/02/15 18:24:17 chagenbu Exp $
+/**
+ * Net_Socket
+ *
+ * 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>
+ *
+ * @category Net
+ * @package Net_Socket
+ * @author Stig Bakken <ssb@php.net>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 1997-2003 The PHP Group
+ * @license http://www.php.net/license/2_02.txt PHP 2.02
+ * @version CVS: $Id: Socket.php 304428 2010-10-15 13:51:46Z clockwerx $
+ * @link http://pear.php.net/packages/Net_Socket
+ */
require_once 'PEAR.php';
-define('NET_SOCKET_READ', 1);
+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>
+ * @category Net
+ * @package Net_Socket
+ * @author Stig Bakken <ssb@php.net>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @copyright 1997-2003 The PHP Group
+ * @license http://www.php.net/license/2_02.txt PHP 2.02
+ * @link http://pear.php.net/packages/Net_Socket
*/
-class Net_Socket extends PEAR {
-
+class Net_Socket extends PEAR
+{
/**
* Socket file pointer.
* @var resource $fp
*/
var $lineLength = 2048;
+ /**
+ * The string to use as a newline terminator. Usually "\r\n" or "\n".
+ * @var string $newline
+ */
+ var $newline = "\r\n";
+
/**
* 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.
+ * @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)
+ function connect($addr, $port = 0, $persistent = null,
+ $timeout = null, $options = null)
{
if (is_resource($this->fp)) {
@fclose($this->fp);
}
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
- $errno = 0;
- $errstr = '';
+ $errno = 0;
+ $errstr = '';
+
$old_track_errors = @ini_set('track_errors', 1);
+
if ($options && function_exists('stream_context_create')) {
if ($this->timeout) {
$timeout = $this->timeout;
// Since PHP 5 fsockopen doesn't allow context specification
if (function_exists('stream_socket_client')) {
- $flags = $this->persistent ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT;
+ $flags = STREAM_CLIENT_CONNECT;
+
+ if ($this->persistent) {
+ $flags = STREAM_CLIENT_PERSISTENT;
+ }
+
$addr = $this->addr . ':' . $this->port;
- $fp = stream_socket_client($addr, $errno, $errstr, $timeout, $flags, $context);
+ $fp = stream_socket_client($addr, $errno, $errstr,
+ $timeout, $flags, $context);
} else {
- $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
+ $fp = @$openfunc($this->addr, $this->port, $errno,
+ $errstr, $timeout, $context);
}
} else {
if ($this->timeout) {
- $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
+ $fp = @$openfunc($this->addr, $this->port, $errno,
+ $errstr, $this->timeout);
} else {
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr);
}
}
if (!$fp) {
- if ($errno == 0 && isset($php_errormsg)) {
+ if ($errno == 0 && !strlen($errstr) && isset($php_errormsg)) {
$errstr = $php_errormsg;
}
@ini_set('track_errors', $old_track_errors);
return true;
}
+ /**
+ * Set the newline character/sequence to use.
+ *
+ * @param string $newline Newline character(s)
+ * @return boolean True
+ */
+ function setNewline($newline)
+ {
+ $this->newline = $newline;
+ return true;
+ }
+
/**
* Find out if the socket is in blocking mode.
*
* 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.
+ * @param boolean $mode True for blocking sockets, false for nonblocking.
+ *
* @access public
* @return mixed true on success or a PEAR_Error instance otherwise
*/
}
$this->blocking = $mode;
- socket_set_blocking($this->fp, $this->blocking);
+ stream_set_blocking($this->fp, (int)$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.
+ * @param integer $seconds Seconds.
+ * @param integer $microseconds Microseconds.
+ *
* @access public
* @return mixed true on success or a PEAR_Error instance otherwise
*/
* Sets the file buffering size on the stream.
* See php's stream_set_write_buffer for more information.
*
- * @param integer $size Write buffer size.
+ * @param integer $size Write buffer size.
+ *
* @access public
* @return mixed on success or an PEAR_Error object otherwise
*/
* </p>
*
* @access public
- * @return mixed Array containing information about existing socket resource or a PEAR_Error instance otherwise
+ * @return mixed Array containing information about existing socket
+ * resource or a PEAR_Error instance otherwise
*/
function getStatus()
{
/**
* Get a specified line of data
*
+ * @param int $size ??
+ *
* @access public
* @return $size bytes of data from the socket, or a PEAR_Error if
* not connected.
*/
- function gets($size)
+ function gets($size = null)
{
if (!is_resource($this->fp)) {
return $this->raiseError('not connected');
}
- return @fgets($this->fp, $size);
+ if (is_null($size)) {
+ return @fgets($this->fp);
+ } else {
+ return @fgets($this->fp, $size);
+ }
}
/**
* 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.
+ * @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.
/**
* 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.
+ * @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 If the socket is not connected, returns an instance of PEAR_Error
+ * @return mixed If the socket is not connected, returns an instance of
+ * PEAR_Error
* If the write succeeds, returns the number of bytes written
* If the write fails, returns false.
*/
$blocksize = 1024;
}
- $pos = 0;
+ $pos = 0;
$size = strlen($data);
while ($pos < $size) {
$written = @fwrite($this->fp, substr($data, $pos, $blocksize));
- if ($written === false) {
- return false;
+ if (!$written) {
+ return $written;
}
$pos += $written;
}
}
/**
- * Write a line of data to the socket, followed by a trailing "\r\n".
+ * Write a line of data to the socket, followed by a trailing newline.
+ *
+ * @param string $data Data to write
*
* @access public
* @return mixed fputs result, or an error
return $this->raiseError('not connected');
}
- return fwrite($this->fp, $data . "\r\n");
+ return fwrite($this->fp, $data . $this->newline);
}
/**
}
$string = '';
- while (($char = @fread($this->fp, 1)) != "\x00") {
+ while (($char = @fread($this->fp, 1)) != "\x00") {
$string .= $char;
}
return $string;
}
$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 rtrim($line, $this->newline);
}
}
return $line;
* 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.
+ * @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
return $this->raiseError('not connected');
}
- $read = null;
- $write = null;
+ $read = null;
+ $write = null;
$except = null;
if ($state & NET_SOCKET_READ) {
$read[] = $this->fp;
if ($state & NET_SOCKET_ERROR) {
$except[] = $this->fp;
}
- if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) {
+ if (false === ($sr = stream_select($read, $write, $except,
+ $tv_sec, $tv_usec))) {
return false;
}
/**
* 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.
+ * @param bool $enabled Set this parameter to true to enable encryption
+ * and false to disable encryption.
+ * @param integer $type Type of encryption. See stream_socket_enable_crypto()
+ * for values.
*
+ * @see http://se.php.net/manual/en/function.stream-socket-enable-crypto.php
* @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
+ * @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)
{
}
return @stream_socket_enable_crypto($this->fp, $enabled, $type);
} else {
- return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0');
+ $msg = 'Net_Socket::enableCrypto() requires php version >= 5.1.0';
+ return $this->raiseError($msg);
}
}
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: Words.php,v 1.11 2009/03/14 19:24:34 kouber Exp $\r
+ * @version CVS: $Id: Words.php 295090 2010-02-15 06:38:34Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
\r
@$obj = new $classname;\r
\r
+ // round if a float is passed, use Math_BigInteger otherwise\r
+ if (is_float($num)) {\r
+ $num = round($num, 2);\r
+ }\r
+\r
if (strpos($num, '.') === false) {\r
return trim($obj->toCurrencyWords($int_curr, $num));\r
}\r
\r
$currency = explode('.', $num, 2);\r
- /* add leading zero */\r
- if (strlen($currency[1]) == 1) {\r
+\r
+ $len = strlen($currency[1]);\r
+\r
+ if ($len == 1) {\r
+ // add leading zero\r
$currency[1] .= '0';\r
+ } elseif ($len > 2) {\r
+ // get the 3rd digit after the comma\r
+ $round_digit = substr($currency[1], 2, 1);\r
+ \r
+ // cut everything after the 2nd digit\r
+ $currency[1] = substr($currency[1], 0, 2);\r
+ \r
+ if ($round_digit >= 5) {\r
+ // round up without losing precision\r
+ include_once "Math/BigInteger.php";\r
+\r
+ $int = new Math_BigInteger(join($currency));\r
+ $int = $int->add(new Math_BigInteger(1));\r
+ $int_str = $int->toString();\r
+\r
+ $currency[0] = substr($int_str, 0, -2);\r
+ $currency[1] = substr($int_str, -2);\r
+\r
+ // check if the rounded decimal part became zero\r
+ if ($currency[1] == '00') {\r
+ $currency[1] = false;\r
+ }\r
+ }\r
}\r
\r
return trim($obj->toCurrencyWords($int_curr, $currency[0], $currency[1]));\r
* @package Numbers_Words\r
* @author Kouber Saparev <kouber@php.net>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.bg.php,v 1.5 2008/11/24 14:41:17 clockwerx Exp $\r
+ * @version CVS: $Id: lang.bg.php 269608 2008-11-24 14:41:17Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Petr 'PePa' Pavel <petr.pavel@pepa.info>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.cs.php,v 1.3 2008/11/25 02:45:52 clockwerx Exp $\r
+ * @version CVS: $Id: lang.cs.php 269648 2008-11-25 02:45:52Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.de.php,v 1.4 2008/11/25 03:14:15 clockwerx Exp $\r
+ * @version CVS: $Id: lang.de.php 269649 2008-11-25 03:14:15Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Jesper Veggerby <pear.nosey@veggerby.dk>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.dk.php,v 1.3 2008/11/25 03:14:15 clockwerx Exp $\r
+ * @version CVS: $Id: lang.dk.php 269649 2008-11-25 03:14:15Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.en_100.php,v 1.3 2008/11/25 02:45:52 clockwerx Exp $\r
+ * @version CVS: $Id: lang.en_100.php 269648 2008-11-25 02:45:52Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.en_GB.php,v 1.6 2008/11/25 02:45:52 clockwerx Exp $\r
+ * @version CVS: $Id: lang.en_GB.php 269648 2008-11-25 02:45:52Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.en_US.php,v 1.6 2008/11/25 02:45:52 clockwerx Exp $\r
+ * @version CVS: $Id: lang.en_US.php 269648 2008-11-25 02:45:52Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Xavier Noguer\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.es.php,v 1.2 2008/11/25 03:37:50 clockwerx Exp $\r
+ * @version CVS: $Id: lang.es.php 269650 2008-11-25 03:37:50Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Xavier Noguer <xnoguer.php@gmail.com>\r
* @author Martin Marrese <mmare@mecon.gov.ar>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.es_AR.php,v 1.5 2008/11/25 13:47:38 clockwerx Exp $\r
+ * @version CVS: $Id: lang.es_AR.php 269823 2008-11-25 13:47:38Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Erkki Saarniit <erkki@center.ee>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.et.php,v 1.3 2008/11/25 03:53:39 clockwerx Exp $\r
+ * @version CVS: $Id: lang.et.php 269655 2008-11-25 03:53:39Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
require_once "Numbers/Words.php";\r
* @package Numbers_Words\r
* @author Kouber Saparev <kouber@php.net>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.fr.php,v 1.5 2008/11/24 14:53:41 clockwerx Exp $\r
+ * @version CVS: $Id: lang.fr.php 269609 2008-11-24 14:53:41Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Kouber Saparev <kouber@php.net>\r
* @author Philippe Bajoit <phil@lebutch.org\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.fr_BE.php,v 1.3 2009/02/27 11:17:20 kouber Exp $\r
+ * @version CVS: $Id: lang.fr_BE.php 276562 2009-02-27 11:17:20Z kouber $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Hadar Porat <hpman28@gmail.com>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.he.php,v 1.6 2008/11/25 13:53:42 clockwerx Exp $\r
+ * @version CVS: $Id: lang.he.php 269824 2008-11-25 13:53:42Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Nils Homp\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.hu_HU.php,v 1.6 2008/11/24 22:19:38 clockwerx Exp $\r
+ * @version CVS: $Id: lang.hu_HU.php 295960 2010-03-08 13:04:59Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
switch ($t) {\r
case 9:\r
case 5:\r
- case 4:\r
$ret .= $this->_sep . $this->_digits[$t] . 'ven';\r
break;\r
case 8:\r
case 3:\r
$ret .= $this->_sep . 'harminc';\r
break;\r
+ case 4:\r
+ $ret .= $this->_sep . 'negyven';\r
+ break;\r
case 2:\r
switch ($d) {\r
case 0:\r
* @author Ernas M. Jamil <ernasm@samba.co.id>\r
* @author Arif Rifai Dwiyanto\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.id.php,v 1.2 2008/11/25 03:37:50 clockwerx Exp $\r
+ * @version CVS: $Id: lang.id.php 269650 2008-11-25 03:37:50Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Filippo Beltramini <phil@esight.it>\r
* @author Davide Caironi <cairo@esight.it>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.it_IT.php,v 1.3 2009/03/13 10:23:23 quipo Exp $\r
+ * @version CVS: $Id: lang.it_IT.php 277094 2009-03-13 10:23:23Z quipo $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Laurynas Butkus <lauris@night.lt>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.lt.php,v 1.2 2008/11/25 03:48:32 clockwerx Exp $\r
+ * @version CVS: $Id: lang.lt.php 269651 2008-11-25 03:48:32Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.nl.php,v 1.2 2008/11/25 03:48:32 clockwerx Exp $\r
+ * @version CVS: $Id: lang.nl.php 269651 2008-11-25 03:48:32Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @package Numbers_Words\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.pl.php,v 1.5 2008/11/25 03:14:15 clockwerx Exp $\r
+ * @version CVS: $Id: lang.pl.php 293456 2010-01-12 16:44:28Z kouber $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
*/\r
function _get_numlevel($num)\r
{\r
- $num = (int)substr($num, -3);\r
+ if (strlen($num) > 3) {\r
+ $num = substr($num, -3);\r
+ }\r
+ $num = (int) $num;\r
\r
$h = $t = $d = $lev = 0;\r
\r
* @author Igor Feghali <ifeghali@php.net>\r
* @copyright 1997-2008 The PHP Group\r
* @license http://www.php.net/license/3_01.txt PHP License 3.01\r
- * @version CVS: $Id: lang.pt_BR.php,v 1.18 2008/12/20 22:23:24 ifeghali Exp $\r
+ * @version CVS: $Id: lang.pt_BR.php 271694 2008-12-20 22:23:24Z ifeghali $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @author Andrey Demenev <demenev@gmail.com>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.ru.php,v 1.4 2008/11/24 15:11:52 clockwerx Exp $\r
+ * @version CVS: $Id: lang.ru.php 269612 2008-11-24 15:11:52Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Piotr Klaban <makler@man.torun.pl>\r
* @author Robin Ericsson <robin.ericsson@profecta.se>\r
* @license PHP 3.0 http://www.php.net/license/3_0.txt\r
- * @version CVS: $Id: lang.sv.php,v 1.2 2008/11/24 15:01:07 clockwerx Exp $\r
+ * @version CVS: $Id: lang.sv.php 269610 2008-11-24 15:01:07Z clockwerx $\r
* @link http://pear.php.net/package/Numbers_Words\r
*/\r
\r
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Guess.php 278521 2009-04-09 22:24:12Z dufuz $
+ * @version CVS: $Id: Guess.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since PEAR 0.1
*/
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Greg Beaver <cellog@php.net>
- * @copyright 1997-2009 The Authors
+ * @copyright 1997-2010 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: PEAR.php 286670 2009-08-02 14:16:06Z dufuz $
+ * @version CVS: $Id: PEAR.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @see PEAR_Error
* @since Class available since PHP 4.0.2
*/
class PEAR
{
- // {{{ properties
-
/**
* Whether to enable internal debug messages.
*
*/
var $_expected_errors = array();
- // }}}
-
- // {{{ constructor
-
/**
* Constructor. Registers this object in
* $_PEAR_destructor_object_list for destructor emulation if a
if ($this->_debug) {
print "PEAR constructor called, class=$classname\n";
}
+
if ($error_class !== null) {
$this->_error_class = $error_class;
}
+
while ($classname && strcasecmp($classname, "pear")) {
$destructor = "_$classname";
if (method_exists($this, $destructor)) {
}
}
- // }}}
- // {{{ destructor
-
/**
* Destructor (the emulated type of...). Does nothing right now,
* but is included for forward compatibility, so subclass
}
}
- // }}}
- // {{{ getStaticProperty()
-
/**
* If you have a class that's mostly/entirely static, and you need static
* properties, you can use this method to simulate them. Eg. in your method(s)
return $properties[$class][$var];
}
- // }}}
- // {{{ registerShutdownFunc()
-
/**
* Use this function to register a shutdown method for static
* classes.
$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
}
- // }}}
- // {{{ isError()
-
/**
* Tell whether a value is a PEAR error.
*
return $data->getCode() == $code;
}
- // }}}
- // {{{ setErrorHandling()
-
/**
* Sets how errors generated by this object should be handled.
* Can be invoked both in objects and statically. If called
*
* @since PHP 4.0.5
*/
-
function setErrorHandling($mode = null, $options = null)
{
if (isset($this) && is_a($this, 'PEAR')) {
}
}
- // }}}
- // {{{ expectError()
-
/**
* This method is used to tell which errors you expect to get.
* Expected errors are always returned with error mode
} else {
array_push($this->_expected_errors, array($code));
}
- return sizeof($this->_expected_errors);
+ return count($this->_expected_errors);
}
- // }}}
- // {{{ popExpect()
-
/**
* This method pops one element off the expected error codes
* stack.
return array_pop($this->_expected_errors);
}
- // }}}
- // {{{ _checkDelExpect()
-
/**
* This method checks unsets an error code if available
*
function _checkDelExpect($error_code)
{
$deleted = false;
-
- foreach ($this->_expected_errors AS $key => $error_array) {
+ foreach ($this->_expected_errors as $key => $error_array) {
if (in_array($error_code, $error_array)) {
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
$deleted = true;
unset($this->_expected_errors[$key]);
}
}
+
return $deleted;
}
- // }}}
- // {{{ delExpect()
-
/**
* This method deletes all occurences of the specified element from
* the expected error codes stack.
{
$deleted = false;
if ((is_array($error_code) && (0 != count($error_code)))) {
- // $error_code is a non-empty array here;
- // we walk through it trying to unset all
- // values
- foreach($error_code as $key => $error) {
- if ($this->_checkDelExpect($error)) {
- $deleted = true;
- } else {
- $deleted = false;
- }
+ // $error_code is a non-empty array here; we walk through it trying
+ // to unset all values
+ foreach ($error_code as $key => $error) {
+ $deleted = $this->_checkDelExpect($error) ? true : false;
}
+
return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
} elseif (!empty($error_code)) {
// $error_code comes alone, trying to unset it
if ($this->_checkDelExpect($error_code)) {
return true;
- } else {
- return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
}
+
+ return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
}
// $error_code is empty
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
}
- // }}}
- // {{{ raiseError()
-
/**
* This method is a wrapper that returns an instance of the
* configured error class with this object's default error
$message = $message->getMessage();
}
- if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
+ if (
+ isset($this) &&
+ isset($this->_expected_errors) &&
+ count($this->_expected_errors) > 0 &&
+ count($exp = end($this->_expected_errors))
+ ) {
if ($exp[0] == "*" ||
(is_int(reset($exp)) && in_array($code, $exp)) ||
- (is_string(reset($exp)) && in_array($message, $exp))) {
+ (is_string(reset($exp)) && in_array($message, $exp))
+ ) {
$mode = PEAR_ERROR_RETURN;
}
}
return $a;
}
- // }}}
- // {{{ throwError()
-
/**
* Simpler form of raiseError with fewer options. In most cases
* message, code and userinfo are enough.
*
- * @param string $message
+ * @param mixed $message a text error message or a PEAR error object
*
+ * @param int $code a numeric error code (it is up to your class
+ * to define these if you want to use codes)
+ *
+ * @param string $userinfo If you need to pass along for example debug
+ * information, this parameter is meant for that.
+ *
+ * @access public
+ * @return object a PEAR error object
+ * @see PEAR::raiseError
*/
- function &throwError($message = null,
- $code = null,
- $userinfo = null)
+ function &throwError($message = null, $code = null, $userinfo = null)
{
if (isset($this) && is_a($this, 'PEAR')) {
$a = &$this->raiseError($message, $code, null, null, $userinfo);
return $a;
}
- // }}}
function staticPushErrorHandling($mode, $options = null)
{
- $stack = &$GLOBALS['_PEAR_error_handler_stack'];
+ $stack = &$GLOBALS['_PEAR_error_handler_stack'];
$def_mode = &$GLOBALS['_PEAR_default_error_mode'];
$def_options = &$GLOBALS['_PEAR_default_error_options'];
$stack[] = array($def_mode, $def_options);
return true;
}
- // {{{ pushErrorHandling()
-
/**
* Push a new error handler on top of the error handler options stack. With this
* you can easily override the actual error handler for some code and restore
return true;
}
- // }}}
- // {{{ popErrorHandling()
-
/**
* Pop the last error handler used
*
return true;
}
- // }}}
- // {{{ loadExtension()
-
/**
* OS independant PHP extension load. Remember to take care
* on the correct extension name for case sensitive OSes.
*/
function loadExtension($ext)
{
- if (!extension_loaded($ext)) {
- // if either returns true dl() will produce a FATAL error, stop that
- if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
- return false;
- }
+ if (extension_loaded($ext)) {
+ return true;
+ }
- if (OS_WINDOWS) {
- $suffix = '.dll';
- } elseif (PHP_OS == 'HP-UX') {
- $suffix = '.sl';
- } elseif (PHP_OS == 'AIX') {
- $suffix = '.a';
- } elseif (PHP_OS == 'OSX') {
- $suffix = '.bundle';
- } else {
- $suffix = '.so';
- }
+ // if either returns true dl() will produce a FATAL error, stop that
+ if (
+ function_exists('dl') === false ||
+ ini_get('enable_dl') != 1 ||
+ ini_get('safe_mode') == 1
+ ) {
+ return false;
+ }
- return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
+ if (OS_WINDOWS) {
+ $suffix = '.dll';
+ } elseif (PHP_OS == 'HP-UX') {
+ $suffix = '.sl';
+ } elseif (PHP_OS == 'AIX') {
+ $suffix = '.a';
+ } elseif (PHP_OS == 'OSX') {
+ $suffix = '.bundle';
+ } else {
+ $suffix = '.so';
}
- return true;
+ return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
}
-
- // }}}
}
if (PEAR_ZE2) {
include_once 'PEAR5.php';
}
-// {{{ _PEAR_call_destructors()
-
function _PEAR_call_destructors()
{
global $_PEAR_destructor_object_list;
}
// Now call the shutdown functions
- if (isset($GLOBALS['_PEAR_shutdown_funcs']) AND is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
+ if (
+ isset($GLOBALS['_PEAR_shutdown_funcs']) &&
+ is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
+ !empty($GLOBALS['_PEAR_shutdown_funcs'])
+ ) {
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
call_user_func_array($value[0], $value[1]);
}
}
}
-// }}}
/**
* Standard PEAR error class for PHP 4
*
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/manual/en/core.pear.pear-error.php
* @see PEAR::raiseError(), PEAR::throwError()
* @since Class available since PHP 4.0.2
*/
class PEAR_Error
{
- // {{{ properties
-
var $error_message_prefix = '';
var $mode = PEAR_ERROR_RETURN;
var $level = E_USER_NOTICE;
var $userinfo = '';
var $backtrace = null;
- // }}}
- // {{{ constructor
-
/**
* PEAR_Error constructor
*
die(sprintf($format, $msg));
}
- if ($this->mode & PEAR_ERROR_CALLBACK) {
- if (is_callable($this->callback)) {
- call_user_func($this->callback, $this);
- }
+ if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
+ call_user_func($this->callback, $this);
}
if ($this->mode & PEAR_ERROR_EXCEPTION) {
}
}
- // }}}
- // {{{ getMode()
-
/**
* Get the error mode from an error object.
*
* @return int error mode
* @access public
*/
- function getMode() {
+ function getMode()
+ {
return $this->mode;
}
- // }}}
- // {{{ getCallback()
-
/**
* Get the callback function/method from an error object.
*
* @return mixed callback function or object/method array
* @access public
*/
- function getCallback() {
+ function getCallback()
+ {
return $this->callback;
}
- // }}}
- // {{{ getMessage()
-
-
/**
* Get the error message from an error object.
*
return ($this->error_message_prefix . $this->message);
}
-
- // }}}
- // {{{ getCode()
-
/**
* Get error code from an error object
*
return $this->code;
}
- // }}}
- // {{{ getType()
-
/**
* Get the name of this error/exception.
*
return get_class($this);
}
- // }}}
- // {{{ getUserInfo()
-
/**
* Get additional user-supplied information.
*
return $this->userinfo;
}
- // }}}
- // {{{ getDebugInfo()
-
/**
* Get additional debug information supplied by the application.
*
return $this->getUserInfo();
}
- // }}}
- // {{{ getBacktrace()
-
/**
* Get the call backtrace from where the error was generated.
* Supported with PHP 4.3.0 or newer.
return $this->backtrace[$frame];
}
- // }}}
- // {{{ addUserInfo()
-
function addUserInfo($info)
{
if (empty($this->userinfo)) {
}
}
- // }}}
- // {{{ toString()
function __toString()
{
return $this->getMessage();
}
- // }}}
- // {{{ toString()
/**
* Make a string representation of this object.
* @return string a string with an object summary
* @access public
*/
- function toString() {
+ function toString()
+ {
$modes = array();
$levels = array(E_USER_NOTICE => 'notice',
E_USER_WARNING => 'warning',
$this->error_message_prefix,
$this->userinfo);
}
-
- // }}}
}
/*
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Autoloader.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Autoloader.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
* @since File available since Release 0.1
* @deprecated File deprecated in Release 1.4.0a1
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
* @since File available since Release 0.1
* @deprecated File deprecated in Release 1.4.0a1
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Builder.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Builder.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since PHP 4.0.2
* @see http://pear.php.net/manual/en/core.ppm.pear-builder.php
/**
* Build an extension from source. Runs "phpize" in the source
* directory, but compiles in a temporary directory
- * (/var/tmp/pear-build-USER/PACKAGE-VERSION).
+ * (TMPDIR/pear-build-USER/PACKAGE-VERSION).
*
* @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
* a PEAR_PackageFile object
' appears to have a prefix ' . $matches[2] . ', but' .
' config variable php_prefix does not match');
}
+
if (isset($matches[3]) && strlen($matches[3]) &&
trim($matches[3]) != trim($this->config->get('php_suffix'))) {
$this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
}
}
-
$this->current_callback = $callback;
if (PEAR_OS == "Windows") {
return $this->_build_win32($descfile, $callback);
}
+
if (PEAR_OS != 'Unix') {
return $this->raiseError("building extensions not supported on this platform");
}
+
if (is_object($descfile)) {
$pkg = $descfile;
$descfile = $pkg->getPackageFile();
}
$dir = dirname($descfile);
}
+
+ // Find config. outside of normal path - e.g. config.m4
+ foreach (array_keys($pkg->getInstallationFileList()) as $item) {
+ if (stristr(basename($item), 'config.m4') && dirname($item) != '.') {
+ $dir .= DIRECTORY_SEPARATOR . dirname($item);
+ break;
+ }
+ }
+
$old_cwd = getcwd();
if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
return $this->raiseError("could not chdir to $dir");
}
+
$vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
if (is_dir($vdir)) {
chdir($vdir);
}
+
$dir = getcwd();
$this->log(2, "building in $dir");
putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
if (PEAR::isError($err)) {
return $err;
}
+
if (!$err) {
return $this->raiseError("`phpize' failed");
}
// }}} end of interactive part
// FIXME make configurable
- if(!$user=getenv('USER')){
+ if (!$user=getenv('USER')) {
$user='defaultuser';
}
- $build_basedir = "/var/tmp/pear-build-$user";
+
+ $tmpdir = $this->config->get('temp_dir');
+ $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"');
$build_dir = "$build_basedir/$vdir";
$inst_dir = "$build_basedir/install-$vdir";
$this->log(1, "building in $build_dir");
if (is_dir($build_dir)) {
System::rm(array('-rf', $build_dir));
}
+
if (!System::mkDir(array('-p', $build_dir))) {
return $this->raiseError("could not create build dir: $build_dir");
}
+
$this->addTempFile($build_dir);
if (!System::mkDir(array('-p', $inst_dir))) {
return $this->raiseError("could not create temporary install dir: $inst_dir");
}
$this->addTempFile($inst_dir);
- if (getenv('MAKE')) {
- $make_command = getenv('MAKE');
- } else {
- $make_command = 'make';
- }
+ $make_command = getenv('MAKE') ? getenv('MAKE') : 'make';
+
$to_run = array(
$configure_command,
$make_command,
if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
return $this->raiseError("could not chdir to $build_dir");
}
- putenv('PHP_PEAR_VERSION=1.9.0');
+ putenv('PHP_PEAR_VERSION=1.9.4');
foreach ($to_run as $cmd) {
$err = $this->_runCommand($cmd, $callback);
if (PEAR::isError($err)) {
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: ChannelFile.php 286951 2009-08-09 14:41:22Z dufuz $
+ * @version CVS: $Id: ChannelFile.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Parser.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Parser.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Command.php 286494 2009-07-29 06:57:11Z dufuz $
+ * @version CVS: $Id: Command.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Auth.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Auth.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
* @deprecated since 1.8.0alpha1
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @deprecated since 1.8.0alpha1
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Build.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Build.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Channels.php 287561 2009-08-21 22:42:58Z dufuz $
+ * @version CVS: $Id: Channels.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Common.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Config.php 287554 2009-08-21 21:16:25Z dufuz $
+ * @version CVS: $Id: Config.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
return $this->raiseError("config-get expects 1 or 2 parameters");
}
- $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
$reg = &$this->config->getRegistry();
+ $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
+ $channel = $reg->channelName($channel);
$this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
return true;
}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Install.php 287477 2009-08-19 14:19:43Z dufuz $
+ * @version CVS: $Id: Install.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
- $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
+ $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$enable = 'zend_extension' . $debug . $ts;
}
foreach ($ini[$search] as $line => $extension) {
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
- $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
+ $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$enable = 'zend_extension' . $debug . $ts;
}
$found = false;
if ($param->getPackageType() == 'extsrc' ||
$param->getPackageType() == 'extbin' ||
$param->getPackageType() == 'zendextsrc' ||
- $param->getPackageType() == 'zendextbin') {
+ $param->getPackageType() == 'zendextbin'
+ ) {
$pkg = &$param->getPackageFile();
if ($instbin = $pkg->getInstalledBinary()) {
$instpkg = &$instreg->getPackage($instbin, $pkg->getChannel());
foreach ($instpkg->getFilelist() as $name => $atts) {
$pinfo = pathinfo($atts['installed_as']);
if (!isset($pinfo['extension']) ||
- in_array($pinfo['extension'], array('c', 'h'))) {
+ in_array($pinfo['extension'], array('c', 'h'))
+ ) {
continue; // make sure we don't match php_blah.h
}
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
- $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
+ $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$exttype = 'zend_extension' . $debug . $ts;
}
$extrainfo[] = 'You should add "' . $exttype . '=' .
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
- $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
+ $ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$exttype = 'zend_extension' . $debug . $ts;
}
$this->ui->outputData('Unable to remove "' . $exttype . '=' .
* @author Alexander Merz <alexmerz@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Mirror.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Mirror.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.2.0
*/
* @author Alexander Merz <alexmerz@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.2.0
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Package.php 287559 2009-08-21 22:33:10Z dufuz $
+ * @version CVS: $Id: Package.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
Sets a SVN tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
- after running cvstag once, but before the tarball is released to the public,
+ after running svntag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
to include files (such as a second package.xml, or tests not included in the
return $a;
}
- function &getPackageFile($config, $debug = false, $tmpdir = null)
+ function &getPackageFile($config, $debug = false)
{
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
- $a = &new PEAR_PackageFile($config, $debug, $tmpdir);
+ $a = &new PEAR_PackageFile($config, $debug);
$common = new PEAR_Common;
$common->ui = $this->ui;
$a->setLogger($common);
$packageFile = realpath($params[0]);
$dir = dirname($packageFile);
- $dir = substr($dir, strrpos($dir, '/') + 1);
+ $dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
}
// Check if tag already exists
- $releaseTag = $path['local']['base'] . 'tags/' . $svntag;
+ $releaseTag = $path['local']['base'] . 'tags' . DIRECTORY_SEPARATOR . $svntag;
$existsCommand = 'svn ls ' . $path['base'] . 'tags/';
$fp = popen($existsCommand, "r");
}
pclose($fp);
- if (in_array($svntag . '/', explode("\n", $out))) {
+ if (in_array($svntag . DIRECTORY_SEPARATOR, explode("\n", $out))) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('SVN tag ' . $svntag . ' for ' . $package . ' already exists.');
+ } elseif (file_exists($path['local']['base'] . 'tags') === false) {
+ return $this->raiseError('Can not locate the tags directory at ' . $path['local']['base'] . 'tags');
+ } elseif (is_writeable($path['local']['base'] . 'tags') === false) {
+ return $this->raiseError('Can not write to the tag directory at ' . $path['local']['base'] . 'tags');
} else {
$makeCommand = 'svn mkdir ' . $releaseTag;
$this->output .= "+ $makeCommand\n";
$command .= ' copy --parents ';
$dir = dirname($packageFile);
- $dir = substr($dir, strrpos($dir, '/') + 1);
+ $dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$files = array_keys($info->getFilelist());
+ if (!in_array(basename($packageFile), $files)) {
+ $files[] = basename($packageFile);
+ }
+
+ array_shift($params);
+ if (count($params)) {
+ // add in additional files to be tagged (package files and such)
+ $files = array_merge($files, $params);
+ }
+
$commands = array();
foreach ($files as $file) {
if (!file_exists($file)) {
$path['from'] = substr($url, 0, strrpos($url, '/'));
$path['base'] = substr($path['from'], 0, strrpos($path['from'], '/') + 1);
- // Figure out the local paths
- $pos = strpos($file, '/trunk/');
+ // Figure out the local paths - see http://pear.php.net/bugs/17463
+ $pos = strpos($file, DIRECTORY_SEPARATOR . 'trunk' . DIRECTORY_SEPARATOR);
if ($pos === false) {
- $pos = strpos($file, '/branches/');
+ $pos = strpos($file, DIRECTORY_SEPARATOR . 'branches' . DIRECTORY_SEPARATOR);
}
$path['local']['base'] = substr($file, 0, $pos + 1);
}
$tar = new Archive_Tar($params[0]);
- $tmpdir = System::mktemp('-d pearsign');
+
+ $tmpdir = $this->config->get('temp_dir');
+ $tmpdir = System::mktemp(' -t "' . $tmpdir . '" -d pearsign');
if (!$tar->extractList('package2.xml package.xml package.sig', $tmpdir)) {
return $this->raiseError("failed to extract tar file");
}
Sets a SVN tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
- after running cvstag once, but before the tarball is released to the public,
+ after running svntag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
to include files (such as a second package.xml, or tests not included in the
* @author Greg Beaver <cellog@php.net>
* @copyright 2005-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Pickle.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Pickle.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 2005-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.1
*/
* @param string|null $tmpdir
* @return PEAR_PackageFile
*/
- function &getPackageFile($config, $debug = false, $tmpdir = null)
+ function &getPackageFile($config, $debug = false)
{
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
require_once 'PEAR/PackageFile.php';
}
- $a = &new PEAR_PackageFile($config, $debug, $tmpdir);
+ $a = &new PEAR_PackageFile($config, $debug);
$common = new PEAR_Common;
$common->ui = $this->ui;
$a->setLogger($common);
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Registry.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Registry.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
$info = $fp = false;
$reg = &$this->config->getRegistry();
- if ((file_exists($params[0]) && is_file($params[0]) && !is_dir($params[0])) || $fp = @fopen($params[0], 'r')) {
+ if (is_file($params[0]) && !is_dir($params[0]) &&
+ (file_exists($params[0]) || $fp = @fopen($params[0], 'r'))
+ ) {
if ($fp) {
fclose($fp);
}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Remote.php 287477 2009-08-19 14:19:43Z dufuz $
+ * @version CVS: $Id: Remote.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
'shortcut' => 'cc',
'options' => array(),
'doc' => '
-Clear the XML-RPC/REST cache. See also the cache_ttl configuration
+Clear the REST cache. See also the cache_ttl configuration
parameter.
',
),
if ($verbose >= 1) {
$output .= "reading directory $cache_dir\n";
}
+
$num = 0;
while ($ent = readdir($dp)) {
if (preg_match('/rest.cache(file|id)\\z/', $ent)) {
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Test.php 279072 2009-04-20 19:57:41Z cellog $
+ * @version CVS: $Id: Test.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Common.php 282969 2009-06-28 23:09:27Z dufuz $
+ * @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1.0
* @deprecated File deprecated since Release 1.4.0a1
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @deprecated This class will disappear, and its components will be spread
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Config.php 286480 2009-07-29 02:50:02Z dufuz $
+ * @version CVS: $Id: Config.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Dependency2.php 286494 2009-07-29 06:57:11Z dufuz $
+ * @version CVS: $Id: Dependency2.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
*/
function getPEARVersion()
{
- return '1.9.0';
+ return '1.9.4';
}
function validatePearinstallerDependency($dep)
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: DependencyDB.php 286686 2009-08-02 17:38:57Z dufuz $
+ * @version CVS: $Id: DependencyDB.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Tomas V.V.Cox <cox@idec.net.com>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Martin Jansen <mj@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Downloader.php 287109 2009-08-11 18:50:30Z dufuz $
+ * @version CVS: $Id: Downloader.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.0
*/
* @author Martin Jansen <mj@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.0
*/
require_once 'System.php';
}
- $tmp = System::mktemp(array('-d'));
+ $tmpdir = $this->config->get('temp_dir');
+ $tmp = System::mktemp('-d -t "' . $tmpdir . '"');
$a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
PEAR::popErrorHandling();
if (PEAR::isError($a)) {
*/
function analyzeDependencies(&$params, $force = false)
{
- $hasfailed = $failed = false;
if (isset($this->_options['downloadonly'])) {
return;
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$redo = true;
- $reset = false;
+ $reset = $hasfailed = $failed = false;
while ($redo) {
$redo = false;
foreach ($params as $i => $param) {
}
$failed = false;
- if (isset($deps['required'])) {
+ if (isset($deps['required']) && is_array($deps['required'])) {
foreach ($deps['required'] as $type => $dep) {
// note: Dependency2 will never return a PEAR_Error if ignore-errors
// is specified, so soft is needed to turn off logging
}
}
- if (isset($deps['optional'])) {
+ if (isset($deps['optional']) && is_array($deps['optional'])) {
foreach ($deps['optional'] as $type => $dep) {
if (!isset($dep[0])) {
if (PEAR::isError($e =
}
}
}
+
PEAR::staticPopErrorHandling();
if ($hasfailed && (isset($this->_options['ignore-errors']) ||
isset($this->_options['nodeps']))) {
if (isset($this->_downloadDir)) {
return $this->_downloadDir;
}
+
$downloaddir = $this->config->get('download_dir');
if (empty($downloaddir) || (is_dir($downloaddir) && !is_writable($downloaddir))) {
if (is_dir($downloaddir) && !is_writable($downloaddir)) {
'" is not writeable. Change download_dir config variable to ' .
'a writeable dir to avoid this warning');
}
+
if (!class_exists('System')) {
require_once 'System.php';
}
+
if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
return $downloaddir;
}
$this->log(3, '+ tmp dir created at ' . $downloaddir);
}
+
if (!is_writable($downloaddir)) {
if (PEAR::isError(System::mkdir(array('-p', $downloaddir))) ||
!is_writable($downloaddir)) {
'a writeable dir');
}
}
+
return $this->_downloadDir = $downloaddir;
}
$this->_options = $options;
}
- // }}}
- // {{{ setOptions()
function getOptions()
{
return $this->_options;
}
- /**
- * For simpler unit-testing
- * @param PEAR_Config
- * @param int
- * @param string
- */
- function &getPackagefileObject(&$c, $d, $t = false)
- {
- if (!class_exists('PEAR_PackageFile')) {
- require_once 'PEAR/PackageFile.php';
- }
- $a = &new PEAR_PackageFile($c, $d, $t);
- return $a;
- }
/**
* @param array output of {@link parsePackageName()}
}
return $info;
} elseif ($chan->supportsREST($this->config->get('preferred_mirror'))
- && $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))
+ &&
+ (
+ ($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror')))
+ ||
+ ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror')))
+ )
) {
- $rest = &$this->config->getREST('1.0', $this->_options);
+ if ($base2) {
+ $base = $base2;
+ $rest = &$this->config->getREST('1.3', $this->_options);
+ } else {
+ $rest = &$this->config->getREST('1.0', $this->_options);
+ }
+
$url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr,
$state, $version, $chan->getName());
if (PEAR::isError($url)) {
if ($lastmodified === false || $lastmodified) {
$request = "GET $url HTTP/1.1\r\n";
- $request .= "Host: $host:$port\r\n";
+ $request .= "Host: $host\r\n";
} else {
$request = "GET $url HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
if ($lastmodified === false || $lastmodified) {
$request = "GET $path HTTP/1.1\r\n";
- $request .= "Host: $host:$port\r\n";
+ $request .= "Host: $host\r\n";
} else {
$request = "GET $path HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
}
$request .= $ifmodifiedsince .
- "User-Agent: PEAR/1.9.0/PHP/" . PHP_VERSION . "\r\n";
+ "User-Agent: PEAR/1.9.4/PHP/" . PHP_VERSION . "\r\n";
if (isset($this)) { // only pass in authentication for non-static calls
$username = $config->get('username', null, $channel);
}
$dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
+ if (is_link($dest_file)) {
+ return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $dest_file . ' as it is symlinked to ' . readlink($dest_file) . ' - Possible symlink attack');
+ }
+
if (!$wp = @fopen($dest_file, 'wb')) {
fclose($fp);
if ($callback) {
}
return $dest_file;
}
-}
-// }}}
\ No newline at end of file
+}
\ No newline at end of file
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Package.php 287560 2009-08-21 22:36:18Z dufuz $
+ * @version CVS: $Id: Package.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
continue;
}
+ // FIXME do symlink check
+
fwrite($fp, $filecontents, strlen($filecontents));
fclose($fp);
if ($s = $params[$i]->explicitState()) {
* @param int
* @param string
*/
- function &getPackagefileObject(&$c, $d, $t = false)
+ function &getPackagefileObject(&$c, $d)
{
- $a = &new PEAR_PackageFile($c, $d, $t);
+ $a = &new PEAR_PackageFile($c, $d);
return $a;
}
-
/**
* This will retrieve from a local file if possible, and parse out
* a group name as well. The original parameter will be modified to reflect this.
if (@is_file($param)) {
$this->_type = 'local';
$options = $this->_downloader->getOptions();
- if (isset($options['downloadonly'])) {
- $pkg = &$this->getPackagefileObject($this->_config,
- $this->_downloader->_debug);
- } else {
- if (PEAR::isError($dir = $this->_downloader->getDownloadDir())) {
- return $dir;
- }
- $pkg = &$this->getPackagefileObject($this->_config,
- $this->_downloader->_debug, $dir);
- }
+ $pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->_debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($param, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
}
// whew, download worked!
- if (isset($options['downloadonly'])) {
- $pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug);
- } else {
- $dir = $this->_downloader->getDownloadDir();
- if (PEAR::isError($dir)) {
- return $dir;
- }
- $pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug, $dir);
- }
+ $pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($file, PEAR_VALIDATE_INSTALLING);
* @author Greg Beaver <cellog@php.net>
* @copyright 2004-2008 Greg Beaver
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: ErrorStack.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: ErrorStack.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR_ErrorStack
*/
* $local_stack = new PEAR_ErrorStack('MyPackage');
* </code>
* @author Greg Beaver <cellog@php.net>
- * @version 1.9.0
+ * @version 1.9.4
* @package PEAR_ErrorStack
* @category Debugging
* @copyright 2004-2008 Greg Beaver
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: ErrorStack.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: ErrorStack.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR_ErrorStack
*/
class PEAR_ErrorStack {
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Exception.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Exception.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.3
*
}
public function getTraceSafe()
- {
+ {
if (!isset($this->_trace)) {
$this->_trace = $this->getTrace();
if (empty($this->_trace)) {
$trace = $this->getTraceSafe();
$causes = array();
$this->getCauseMessage($causes);
- $html = '<table border="1" cellspacing="0">' . "\n";
+ $html = '<table style="border: 1px" cellspacing="0">' . "\n";
foreach ($causes as $i => $cause) {
- $html .= '<tr><td colspan="3" bgcolor="#ff9999">'
+ $html .= '<tr><td colspan="3" style="background: #ff9999">'
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
. 'on line <b>' . $cause['line'] . '</b>'
. "</td></tr>\n";
}
- $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
- . '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
- . '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
- . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
+ $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
+ . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
+ . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
+ . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
foreach ($trace as $k => $v) {
- $html .= '<tr><td align="center">' . $k . '</td>'
+ $html .= '<tr><td style="text-align: center;">' . $k . '</td>'
. '<td>';
if (!empty($v['class'])) {
$html .= $v['class'] . $v['type'];
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
. '</td></tr>' . "\n";
}
- $html .= '<tr><td align="center">' . ($k+1) . '</td>'
+ $html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
. '<td>{main}</td>'
. '<td> </td></tr>' . "\n"
. '</table>';
}
return $causeMsg . $this->getTraceAsString();
}
-}
-
-?>
\ No newline at end of file
+}
\ No newline at end of file
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Frontend.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Frontend.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: CLI.php 278236 2009-04-04 00:09:14Z dufuz $
+ * @version CVS: $Id: CLI.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
case 'install':
case 'upgrade':
case 'upgrade-all':
- if (isset($data['release_warnings'])) {
+ if (is_array($data) && isset($data['release_warnings'])) {
$this->_displayLine('');
$this->_startTable(array(
'border' => false,
$this->_displayLine('');
}
- $this->_displayLine($data['data']);
+ $this->_displayLine(is_array($data) ? $data['data'] : $data);
break;
case 'search':
$this->_startTable($data);
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
+ $packages = array();
foreach($data['data'] as $category) {
- foreach($category as $pkg) {
- $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
+ foreach($category as $name => $pkg) {
+ $packages[$pkg[0]] = $pkg;
}
}
+ $p = array_keys($packages);
+ natcasesort($p);
+ foreach ($p as $name) {
+ $this->_tableRow($packages[$name], null, array(1 => array('wrap' => 55)));
+ }
+
$this->_endTable();
break;
case 'list-all':
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
+ $packages = array();
foreach($data['data'] as $category) {
- foreach($category as $pkg) {
- unset($pkg[4], $pkg[5]);
- $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
+ foreach($category as $name => $pkg) {
+ $packages[$pkg[0]] = $pkg;
}
}
+ $p = array_keys($packages);
+ natcasesort($p);
+ foreach ($p as $name) {
+ $pkg = $packages[$name];
+ unset($pkg[4], $pkg[5]);
+ $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
+ }
+
$this->_endTable();
break;
case 'config-show':
$opts);
}
- foreach($data['data'] as $row) {
- $this->_tableRow($row, null, $opts);
- }
+ if (is_array($data['data'])) {
+ foreach($data['data'] as $row) {
+ $this->_tableRow($row, null, $opts);
+ }
+ } else {
+ $this->_tableRow(array($data['data']), null, $opts);
+ }
$this->_endTable();
} else {
$this->_displayLine($data);
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Installer.php 287446 2009-08-18 11:45:05Z dufuz $
+ * @version CVS: $Id: Installer.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
function commitFileTransaction()
{
- $n = count($this->file_operations);
- $this->log(2, "about to commit $n file operations");
// {{{ first, check permissions and such manually
$errors = array();
- foreach ($this->file_operations as $tr) {
+ foreach ($this->file_operations as $key => $tr) {
list($type, $data) = $tr;
switch ($type) {
case 'rename':
fclose($fp);
}
}
+
+ /* Verify we are not deleting a file owned by another package
+ * This can happen when a file moves from package A to B in
+ * an upgrade ala http://pear.php.net/17986
+ */
+ $info = array(
+ 'package' => strtolower($this->pkginfo->getName()),
+ 'channel' => strtolower($this->pkginfo->getChannel()),
+ );
+ $result = $this->_registry->checkFileMap($data[0], $info, '1.1');
+ if (is_array($result)) {
+ $res = array_diff($result, $info);
+ if (!empty($res)) {
+ $new = $this->_registry->getPackage($result[1], $result[0]);
+ $this->file_operations[$key] = false;
+ $this->log(3, "file $data[0] was scheduled for removal from {$this->pkginfo->getName()} but is owned by {$new->getChannel()}/{$new->getName()}, removal has been cancelled.");
+ }
+ }
}
break;
}
}
// }}}
+
+ $n = count($this->file_operations);
+ $this->log(2, "about to commit $n file operations for " . $this->pkginfo->getName());
+
$m = count($errors);
if ($m > 0) {
foreach ($errors as $error) {
// }}}
// {{{ _parsePackageXml()
- function _parsePackageXml(&$descfile, &$tmpdir)
+ function _parsePackageXml(&$descfile)
{
- if (substr($descfile, -4) == '.xml') {
- $tmpdir = false;
- } else {
- // {{{ Decompress pack in tmp dir -------------------------------------
-
- // To allow relative package file names
- $descfile = realpath($descfile);
-
- if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
- return $tmpdir;
- }
- $this->log(3, '+ tmp dir created at ' . $tmpdir);
- // }}}
- }
-
// Parse xml file -----------------------------------------------
- $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir);
+ $pkg = new PEAR_PackageFile($this->config, $this->debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$p = &$pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING);
PEAR::staticPopErrorHandling();
$pkg = $pkgfile->getPackageFile();
$pkgfile = $pkg->getArchiveFile();
$descfile = $pkg->getPackageFile();
- $tmpdir = dirname($descfile);
} else {
$descfile = $pkgfile;
- $tmpdir = '';
- $pkg = $this->_parsePackageXml($descfile, $tmpdir);
+ $pkg = $this->_parsePackageXml($descfile);
if (PEAR::isError($pkg)) {
return $pkg;
}
}
+ $tmpdir = dirname($descfile);
if (realpath($descfile) != realpath($pkgfile)) {
+ // Use the temp_dir since $descfile can contain the download dir path
+ $tmpdir = $this->config->get('temp_dir', null, 'pear.php.net');
+ $tmpdir = System::mktemp('-d -t "' . $tmpdir . '"');
+
$tar = new Archive_Tar($pkgfile);
if (!$tar->extract($tmpdir)) {
return $this->raiseError("unable to unpack $pkgfile");
$this->startFileTransaction();
- if (empty($options['upgrade']) && empty($options['soft'])) {
- // checks to do only when installing new packages
- if ($channel == 'pecl.php.net') {
- $test = $installregistry->packageExists($pkgname, $channel);
- if (!$test) {
- $test = $installregistry->packageExists($pkgname, 'pear.php.net');
- }
- } else {
- $test = $installregistry->packageExists($pkgname, $channel);
+ $usechannel = $channel;
+ if ($channel == 'pecl.php.net') {
+ $test = $installregistry->packageExists($pkgname, $channel);
+ if (!$test) {
+ $test = $installregistry->packageExists($pkgname, 'pear.php.net');
+ $usechannel = 'pear.php.net';
}
+ } else {
+ $test = $installregistry->packageExists($pkgname, $channel);
+ }
+ if (empty($options['upgrade']) && empty($options['soft'])) {
+ // checks to do only when installing new packages
if (empty($options['force']) && $test) {
return $this->raiseError("$channel/$pkgname is already installed");
}
} else {
- $usechannel = $channel;
- if ($channel == 'pecl.php.net') {
- $test = $installregistry->packageExists($pkgname, $channel);
- if (!$test) {
- $test = $installregistry->packageExists($pkgname, 'pear.php.net');
- $usechannel = 'pear.php.net';
- }
- } else {
- $test = $installregistry->packageExists($pkgname, $channel);
- }
-
+ // Upgrade
if ($test) {
$v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel);
$v2 = $pkg->getVersion();
if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
}
+ }
+ }
- if (empty($options['register-only'])) {
- // when upgrading, remove old release's files first:
- if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel,
- true))) {
- if (!isset($options['ignore-errors'])) {
- return $this->raiseError($err);
- }
+ // Do cleanups for upgrade and install, remove old release's files first
+ if ($test && empty($options['register-only'])) {
+ // when upgrading, remove old release's files first:
+ if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel,
+ true))) {
+ if (!isset($options['ignore-errors'])) {
+ return $this->raiseError($err);
+ }
- if (!isset($options['soft'])) {
- $this->log(0, 'WARNING: ' . $err->getMessage());
- }
- } else {
- $backedup = $err;
- }
+ if (!isset($options['soft'])) {
+ $this->log(0, 'WARNING: ' . $err->getMessage());
}
+ } else {
+ $backedup = $err;
}
}
}
}
- $tmp_path = dirname($descfile);
if (substr($pkgfile, -4) != '.xml') {
- $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();
+ $tmpdir .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();
}
$this->configSet('default_channel', $channel);
foreach ($filelist as $file => $atts) {
$this->expectError(PEAR_INSTALLER_FAILED);
if ($pkg->getPackagexmlVersion() == '1.0') {
- $res = $this->_installFile($file, $atts, $tmp_path, $options);
+ $res = $this->_installFile($file, $atts, $tmpdir, $options);
} else {
- $res = $this->_installFile2($pkg, $file, $atts, $tmp_path, $options);
+ $res = $this->_installFile2($pkg, $file, $atts, $tmpdir, $options);
}
$this->popExpect();
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Role.php 278552 2009-04-10 19:42:49Z dufuz $
+ * @version CVS: $Id: Role.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Cfg.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Cfg.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.7.0
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.7.0
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Common.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Data.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Data.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Doc.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Doc.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Ext.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Ext.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Php.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Php.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Script.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Script.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Src.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Src.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Test.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Test.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Www.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Www.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.7.0
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.7.0
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: PackageFile.php 286670 2009-08-02 14:16:06Z dufuz $
+ * @version CVS: $Id: PackageFile.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
*/
var $_config;
var $_debug;
- /**
- * Temp directory for uncompressing tgz files.
- * @var string|false
- */
- var $_tmpdir;
+
var $_logger = false;
/**
* @var boolean
*/
var $_rawReturn = false;
+ /**
+ * helper for extracting Archive_Tar errors
+ * @var array
+ * @access private
+ */
+ var $_extractErrors = array();
+
/**
*
* @param PEAR_Config $config
* @param string @tmpdir Optional temporary directory for uncompressing
* files
*/
- function PEAR_PackageFile(&$config, $debug = false, $tmpdir = false)
+ function PEAR_PackageFile(&$config, $debug = false)
{
$this->_config = $config;
$this->_debug = $debug;
- $this->_tmpdir = $tmpdir;
}
/**
*/
function &fromXmlString($data, $state, $file, $archive = false)
{
- if (preg_match('/<package[^>]+version="([0-9]+\.[0-9]+)"/', $data, $packageversion)) {
+ if (preg_match('/<package[^>]+version=[\'"]([0-9]+\.[0-9]+)[\'"]/', $data, $packageversion)) {
if (!in_array($packageversion[1], array('1.0', '2.0', '2.1'))) {
return PEAR::raiseError('package.xml version "' . $packageversion[1] .
'" is not supported, only 1.0, 2.0, and 2.1 are supported.');
}
return $pf;
- } elseif (preg_match('/<package[^>]+version="([^"]+)"/', $data, $packageversion)) {
+ } elseif (preg_match('/<package[^>]+version=[\'"]([^"\']+)[\'"]/', $data, $packageversion)) {
$a = PEAR::raiseError('package.xml file "' . $file .
'" has unsupported package.xml <package> version "' . $packageversion[1] . '"');
return $a;
}
}
- if ($this->_tmpdir) {
- $tmpdir = $this->_tmpdir;
- } else {
- $tmpdir = System::mkTemp(array('-t', $this->_config->get('temp_dir'), '-d', 'pear'));
- if ($tmpdir === false) {
- $ret = PEAR::raiseError("there was a problem with getting the configured temp directory");
- return $ret;
- }
-
- PEAR_PackageFile::addTempFile($tmpdir);
+ $tmpdir = System::mktemp('-t "' . $this->_config->get('temp_dir') . '" -d pear');
+ if ($tmpdir === false) {
+ $ret = PEAR::raiseError("there was a problem with getting the configured temp directory");
+ return $ret;
}
+ PEAR_PackageFile::addTempFile($tmpdir);
+
$this->_extractErrors();
PEAR::staticPushErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_extractErrors'));
+
if (!$xml || !$tar->extractList(array($xml), $tmpdir)) {
$extra = implode("\n", $this->_extractErrors());
if ($extra) {
return $ret;
}
- /**
- * helper for extracting Archive_Tar errors
- * @var array
- * @access private
- */
- var $_extractErrors = array();
-
/**
* helper callback for extracting Archive_Tar errors
*
return $ret;
}
-
/**
* Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file.
*
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v1.php 286494 2009-07-29 06:57:11Z dufuz $
+ * @version CVS: $Id: v1.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
function getPackagerVersion()
{
- return '1.9.0';
+ return '1.9.4';
}
/**
);
$ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
- $ret .= "<package version=\"1.0\" packagerversion=\"1.9.0\">\n" .
+ $ret .= "<package version=\"1.0\" packagerversion=\"1.9.4\">\n" .
" <name>$pkginfo[package]</name>";
if (isset($pkginfo['extends'])) {
$ret .= "\n<extends>$pkginfo[extends]</extends>";
* @author Stephan Schmidt (original XML_Serializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v2.php 278907 2009-04-17 21:10:04Z dufuz $
+ * @version CVS: $Id: v2.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Stephan Schmidt (original XML_Serializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
*/
function getPackagerVersion()
{
- return '1.9.0';
+ return '1.9.4';
}
/**
$this->options['beautifyFilelist'] = true;
}
- $arr['attribs']['packagerversion'] = '1.9.0';
+ $arr['attribs']['packagerversion'] = '1.9.4';
if ($this->serialize($arr, $options)) {
return $this->_serializedData . "\n";
}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v1.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: v1.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v2.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: v2.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v1.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: v1.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: v2.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: v2.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
{
unset($pinfo['old']);
unset($pinfo['xsdversion']);
+ // If the changelog isn't an array then it was passed in as an empty tag
+ if (isset($pinfo['changelog']) && !is_array($pinfo['changelog'])) {
+ unset($pinfo['changelog']);
+ }
$this->_incomplete = false;
$this->_packageInfo = $pinfo;
}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Validator.php 277885 2009-03-27 19:29:31Z dufuz $
+ * @version CVS: $Id: Validator.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a8
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a8
* @access private
isset($test['dependencies']['required']) &&
isset($test['dependencies']['required']['pearinstaller']) &&
isset($test['dependencies']['required']['pearinstaller']['min']) &&
- version_compare('1.9.0',
+ version_compare('1.9.4',
$test['dependencies']['required']['pearinstaller']['min'], '<')
) {
$this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);
$validator = $chan->getValidationObject($this->_pf->getPackage());
if (!$validator) {
$this->_stack->push(__FUNCTION__, 'error',
- array_merge(
- array('channel' => $chan->getName(),
- 'package' => $this->_pf->getPackage()),
- $valpack
- ),
+ array('channel' => $chan->getName(),
+ 'package' => $this->_pf->getPackage(),
+ 'name' => $valpack['_content'],
+ 'version' => $valpack['attribs']['version']),
'package "%channel%/%package%" cannot be properly validated without ' .
'validation package "%channel%/%name%-%version%"');
return $this->_isValid = 0;
$this->_stack->push(__FUNCTION__, 'error',
array('version' => $version),
'This package.xml requires PEAR version %version% to parse properly, we are ' .
- 'version 1.9.0');
+ 'version 1.9.4');
}
function _invalidTagOrder($oktags, $actual, $root)
}
continue 2;
case T_DOUBLE_COLON:
- if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
+ $token = $tokens[$i - 1][0];
+ if (!($token == T_WHITESPACE || $token == T_STRING || $token == T_STATIC)) {
if (isset($this->_stack)) {
$this->_stack->push(__FUNCTION__, 'warning', array('file' => $file),
'Parser error: invalid PHP found in file "%file%"');
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: rw.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a8
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a8
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Packager.php 286809 2009-08-04 15:10:26Z dufuz $
+ * @version CVS: $Id: Packager.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: REST.php 286489 2009-07-29 05:59:08Z dufuz $
+ * @version CVS: $Id: REST.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
$ret = $this->getCache($url);
if (!PEAR::isError($ret) && $trieddownload) {
// reset the age of the cache if the server says it was unmodified
- $this->saveCache($url, $ret, null, true, $cacheId);
+ $result = $this->saveCache($url, $ret, null, true, $cacheId);
+ if (PEAR::isError($result)) {
+ return PEAR::raiseError($result->getMessage());
+ }
}
return $ret;
}
if ($forcestring) {
- $this->saveCache($url, $content, $lastmodified, false, $cacheId);
+ $result = $this->saveCache($url, $content, $lastmodified, false, $cacheId);
+ if (PEAR::isError($result)) {
+ return PEAR::raiseError($result->getMessage());
+ }
+
return $content;
}
$content = $parser->getData();
}
- $this->saveCache($url, $content, $lastmodified, false, $cacheId);
+ $result = $this->saveCache($url, $content, $lastmodified, false, $cacheId);
+ if (PEAR::isError($result)) {
+ return PEAR::raiseError($result->getMessage());
+ }
+
return $content;
}
*/
function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null)
{
- $cachedir = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR . md5($url);
- $cacheidfile = $cachedir . 'rest.cacheid';
- $cachefile = $cachedir . 'rest.cachefile';
+ $cache_dir = $this->config->get('cache_dir');
+ $d = $cache_dir . DIRECTORY_SEPARATOR . md5($url);
+ $cacheidfile = $d . 'rest.cacheid';
+ $cachefile = $d . 'rest.cachefile';
+
+ if (!is_dir($cache_dir)) {
+ if (System::mkdir(array('-p', $cache_dir)) === false) {
+ return PEAR::raiseError("The value of config option cache_dir ($cache_dir) is not a directory and attempts to create the directory failed.");
+ }
+ }
if ($cacheid === null && $nochange) {
$cacheid = unserialize(implode('', file($cacheidfile)));
}
- $fp = @fopen($cacheidfile, 'wb');
- if (!$fp) {
- $cache_dir = $this->config->get('cache_dir');
- if (is_dir($cache_dir)) {
- return false;
- }
+ $idData = serialize(array(
+ 'age' => time(),
+ 'lastChange' => ($nochange ? $cacheid['lastChange'] : $lastmodified),
+ ));
- System::mkdir(array('-p', $cache_dir));
- $fp = @fopen($cacheidfile, 'wb');
- if (!$fp) {
- return false;
- }
+ $result = $this->saveCacheFile($cacheidfile, $idData);
+ if (PEAR::isError($result)) {
+ return $result;
+ } elseif ($nochange) {
+ return true;
}
- if ($nochange) {
- fwrite($fp, serialize(array(
- 'age' => time(),
- 'lastChange' => $cacheid['lastChange'],
- ))
- );
+ $result = $this->saveCacheFile($cachefile, serialize($contents));
+ if (PEAR::isError($result)) {
+ if (file_exists($cacheidfile)) {
+ @unlink($cacheidfile);
+ }
- fclose($fp);
- return true;
+ return $result;
}
- fwrite($fp, serialize(array(
- 'age' => time(),
- 'lastChange' => $lastmodified,
- ))
- );
+ return true;
+ }
- fclose($fp);
- $fp = @fopen($cachefile, 'wb');
- if (!$fp) {
- if (file_exists($cacheidfile)) {
- @unlink($cacheidfile);
+ function saveCacheFile($file, $contents)
+ {
+ $len = strlen($contents);
+
+ $cachefile_fp = @fopen($file, 'xb'); // x is the O_CREAT|O_EXCL mode
+ if ($cachefile_fp !== false) { // create file
+ if (fwrite($cachefile_fp, $contents, $len) < $len) {
+ fclose($cachefile_fp);
+ return PEAR::raiseError("Could not write $file.");
+ }
+ } else { // update file
+ $cachefile_lstat = lstat($file);
+ $cachefile_fp = @fopen($file, 'wb');
+ if (!$cachefile_fp) {
+ return PEAR::raiseError("Could not open $file for writing.");
}
- return false;
+ $cachefile_fstat = fstat($cachefile_fp);
+ if (
+ $cachefile_lstat['mode'] == $cachefile_fstat['mode'] &&
+ $cachefile_lstat['ino'] == $cachefile_fstat['ino'] &&
+ $cachefile_lstat['dev'] == $cachefile_fstat['dev'] &&
+ $cachefile_fstat['nlink'] === 1
+ ) {
+ if (fwrite($cachefile_fp, $contents, $len) < $len) {
+ fclose($cachefile_fp);
+ return PEAR::raiseError("Could not write $file.");
+ }
+ } else {
+ fclose($cachefile_fp);
+ $link = function_exists('readlink') ? readlink($file) : $file;
+ return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $file . ' as it is symlinked to ' . $link . ' - Possible symlink attack');
+ }
}
- fwrite($fp, serialize($contents));
- fclose($fp);
+ fclose($cachefile_fp);
return true;
}
$request = "GET $path HTTP/1.1\r\n";
}
- $request .= "Host: $host:$port\r\n";
+ $request .= "Host: $host\r\n";
$ifmodifiedsince = '';
if (is_array($lastmodified)) {
if (isset($lastmodified['Last-Modified'])) {
}
$request .= $ifmodifiedsince .
- "User-Agent: PEAR/1.9.0/PHP/" . PHP_VERSION . "\r\n";
+ "User-Agent: PEAR/1.9.4/PHP/" . PHP_VERSION . "\r\n";
$username = $this->config->get('username', null, $channel);
$password = $this->config->get('password', null, $channel);
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: 10.php 287558 2009-08-21 22:21:28Z dufuz $
+ * @version CVS: $Id: 10.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a12
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a12
*/
$allinfo = $this->_rest->retrieveData($base . 'r/' . $packageLower .
'/allreleases.xml', false, false, $channel);
+ if (PEAR::isError($allinfo)) {
+ return $allinfo;
+ }
+
if (!is_array($allinfo['r']) || !isset($allinfo['r'][0])) {
$allinfo['r'] = array($allinfo['r']);
}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: 11.php 286670 2009-08-02 14:16:06Z dufuz $
+ * @version CVS: $Id: 11.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.3
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.3
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: 13.php 287110 2009-08-11 18:51:15Z dufuz $
+ * @version CVS: $Id: 13.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a12
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a12
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Registry.php 287555 2009-08-21 21:27:27Z dufuz $
+ * @version CVS: $Id: Registry.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: RunTest.php 287447 2009-08-18 11:46:19Z dufuz $
+ * @version CVS: $Id: RunTest.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.3
*/
if (empty($this->_options['cgi'])) {
// try to see if php-cgi is in the path
$res = $this->system_with_timeout('php-cgi -v');
- if (false !== $res && !(is_array($res) && $res === array(127, ''))) {
+ if (false !== $res && !(is_array($res) && in_array($res[0], array(-1, 127)))) {
$this->_options['cgi'] = 'php-cgi';
}
}
// We've satisfied the preconditions - run the test!
if (isset($this->_options['coverage']) && $this->xdebug_loaded) {
$xdebug_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'xdebug';
- $text = '<?php';
- $text .= "\n" . 'function coverage_shutdown() {' .
- "\n" . ' $xdebug = var_export(xdebug_get_code_coverage(), true);';
+ $text = "\n" . 'function coverage_shutdown() {' .
+ "\n" . ' $xdebug = var_export(xdebug_get_code_coverage(), true);';
if (!function_exists('file_put_contents')) {
$text .= "\n" . ' $fh = fopen(\'' . $xdebug_file . '\', "wb");' .
"\n" . ' if ($fh !== false) {' .
$text .= "\n" . ' file_put_contents(\'' . $xdebug_file . '\', $xdebug);';
}
- $text .= "\n" . 'xdebug_stop_code_coverage();' .
- "\n" . '} // end coverage_shutdown()' .
- "\n" . 'register_shutdown_function("coverage_shutdown");';
- $text .= "\n" . 'xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);' . "\n?>";
+ // Workaround for http://pear.php.net/bugs/bug.php?id=17292
+ $lines = explode("\n", $section_text['FILE']);
+ $numLines = count($lines);
+ $namespace = '';
+ $coverage_shutdown = 'coverage_shutdown';
+
+ if (
+ substr($lines[0], 0, 2) == '<?' ||
+ substr($lines[0], 0, 5) == '<?php'
+ ) {
+ unset($lines[0]);
+ }
+
+
+ for ($i = 0; $i < $numLines; $i++) {
+ if (isset($lines[$i]) && substr($lines[$i], 0, 9) == 'namespace') {
+ $namespace = substr($lines[$i], 10, -1);
+ $coverage_shutdown = $namespace . '\\coverage_shutdown';
+ $namespace = "namespace " . $namespace . ";\n";
- $len_f = 5;
- if (substr($section_text['FILE'], 0, 5) != '<?php'
- && substr($section_text['FILE'], 0, 2) == '<?') {
- $len_f = 2;
+ unset($lines[$i]);
+ break;
+ }
}
- $text .= $section_text['FILE'];
- $this->save_text($temp_file, $text);
+ $text .= "\n xdebug_stop_code_coverage();" .
+ "\n" . '} // end coverage_shutdown()' .
+ "\n\n" . 'register_shutdown_function("' . $coverage_shutdown . '");';
+ $text .= "\n" . 'xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);' . "\n";
+
+ $this->save_text($temp_file, "<?php\n" . $namespace . $text . "\n" . implode("\n", $lines));
} else {
$this->save_text($temp_file, $section_text['FILE']);
}
}
}
}
-}
\ No newline at end of file
+}
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Common.php 276394 2009-02-25 00:15:49Z dufuz $
+ * @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @abstract
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Postinstallscript.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: Postinstallscript.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: rw.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Replace.php 276394 2009-02-25 00:15:49Z dufuz $
+ * @version CVS: $Id: Replace.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: rw.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Unixeol.php 276394 2009-02-25 00:15:49Z dufuz $
+ * @version CVS: $Id: Unixeol.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: rw.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Windowseol.php 276394 2009-02-25 00:15:49Z dufuz $
+ * @version CVS: $Id: Windowseol.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: rw.php 276385 2009-02-24 23:46:03Z dufuz $
+ * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a10
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Validate.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: Validate.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: PECL.php 276383 2009-02-24 23:39:37Z dufuz $
+ * @version CVS: $Id: PECL.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a5
*/
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a5
*/
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version CVS: $Id: XMLParser.php 282970 2009-06-28 23:10:07Z dufuz $
+ * @version CVS: $Id: XMLParser.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version Release: 1.9.0
+ * @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
* @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 307804 2011-01-28 00:16:42Z alan_k $
+ * @version CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
* @license http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
*/
var $_mb_substr = false;
var $_mb_convert_encoding = false;
- // tab and crlf are used by stringfy to produce pretty JSON.
- var $_tab = '';
- var $_crlf = '';
- var $_indent = 0;
/**
* convert a string from one UTF-16 char to one UTF-8 char
*
return '';
}
-
/**
- * stringfy an arbitrary variable into JSON format (and sends JSON Header)
- * UNSAFE - does not send HTTP headers (to be compatible with Javsacript Spec)
- *
- * @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!
- * @param mixed $replacer NOT SUPPORTED YET.
- * @param number|string $space
- * an optional parameter that specifies the indentation
- * of nested structures. If it is omitted, the text will
- * be packed without extra whitespace. If it is a number,
- * it will specify the number of spaces to indent at each
- * level. If it is a string (such as '\t' or ' '),
- * it contains the characters used to indent at each level.
- *
- * @return mixed JSON string representation of input var or an error if a problem occurs
- * @access public
- */
- static function stringify($var, $replacer=false, $space=false)
- {
- //header('Content-type: application/json');
- $s = new Services_JSON(SERVICES_JSON_USE_TO_JSON);
-
- $s->_tab = is_numeric($space) ? str_repeat(' ', $space) : $space;
- $s->_crlf = "\n";
- $s->_indent = 0;
- return $s->encodeUnsafe($var);
-
- }
- /**
* encodes an arbitrary variable into JSON format (and sends JSON Header)
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
*/
function _encode($var)
{
- $ind = str_repeat($this->_tab, $this->_indent);
- $indx = $ind . $this->_tab;
-
+
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
// treat as a JSON object
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
- $this->_indent++;
$properties = array_map(array($this, 'name_value'),
array_keys($var),
array_values($var));
- $this->_indent--;
+
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
-
- return "{" . $this->_crlf . $indx .
- join(",". $this->_crlf . $indx, $properties) . $this->_crlf .
- $ind."}";
-
+
+ return '{' . join(',', $properties) . '}';
}
// treat it like a regular array
- $this->_indent++;
$elements = array_map(array($this, '_encode'), $var);
- $this->_indent--;
-
+
foreach($elements as $element) {
if(Services_JSON::isError($element)) {
return $element;
}
}
-
- $pad = $this->_tab === '' ? '' : ' ';
-
- // short array, just show it on one line.
- if (strlen(join(',' . $pad, $elements)) < 30) {
- return '[' . join(',' . $pad, $elements) . ']';
- }
-
- return "[" . $this->_crlf .
- $indx . join(",". $this->_crlf . $indx, $elements) . $this->_crlf .
- $ind . "]";
+
+ return '[' . join(',', $elements) . ']';
case 'object':
$vars = get_object_vars($var);
- $this->_indent++;
$properties = array_map(array($this, 'name_value'),
array_keys($vars),
array_values($vars));
- $this->_indent--;
-
+
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
-
- return "{" . $this->_crlf .
- $indx . join(",". $this->_crlf . $indx, $properties) . $this->_crlf .
- $ind . "}";
-
+
+ return '{' . join(',', $properties) . '}';
+
default:
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
? 'null'
function name_value($name, $value)
{
$encoded_value = $this->_encode($value);
-
+
if(Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
-
- $pad = $this->_tab === '' ? '' : ' ';
-
- return $this->_encode(strval($name)) . $pad . ':' . $pad . $encoded_value;
+
+ return $this->_encode(strval($name)) . ':' . $encoded_value;
}
/**
// TODO: possible class value 0,1,2 check Formula.pm\r
// Split the range into 2 cell refs\r
if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {\r
- list($cell1, $cell2) = explode(':', $range);\r
+ list($cell1, $cell2) = split(':', $range);\r
} elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {\r
- list($cell1, $cell2) = explode('\.\.', $range);\r
+ list($cell1, $cell2) = split('\.\.', $range);\r
\r
} else {\r
// TODO: use real error codes\r
*/
var $_country_code;
- /**
- * The temporary dir for storing the OLE file
- * @var string
- */
- var $_tmp_dir;
-
/**
* number of bytes for sizeinfo of strings
* @var integer
$this->Spreadsheet_Excel_Writer_BIFFwriter();
$this->_filename = $filename;
- $this->_parser = new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version);
+ $this->_parser =& new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version);
$this->_1904 = 0;
$this->_activesheet = 0;
$this->_firstsheet = 0;
$this->_fileclosed = 0;
$this->_biffsize = 0;
$this->_sheetname = 'Sheet';
- $this->_tmp_format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version);
+ $this->_tmp_format =& new Spreadsheet_Excel_Writer_Format($this->_BIFF_version);
$this->_worksheets = array();
$this->_sheetnames = array();
$this->_formats = array();
$this->_string_sizeinfo = 3;
// Add the default format for hyperlinks
- $this->_url_format = $this->addFormat(array('color' => 'blue', 'underline' => 1));
+ $this->_url_format =& $this->addFormat(array('color' => 'blue', 'underline' => 1));
$this->_str_total = 0;
$this->_str_unique = 0;
$this->_str_table = array();
$this->_setPaletteXl97();
- $this->_tmp_dir = '';
}
/**
$this->_tmp_format->_BIFF_version = $version;
$this->_url_format->_BIFF_version = $version;
$this->_parser->_BIFF_version = $version;
+ $this->_codepage = 0x04B0;
$total_worksheets = count($this->_worksheets);
// change version for all worksheets too
$this->_str_total, $this->_str_unique,
$this->_str_table, $this->_url_format,
$this->_parser, $this->_tmp_dir);
-
+
$this->_worksheets[$index] = &$worksheet; // Store ref for iterator
$this->_sheetnames[$index] = $name; // Store EXTERNSHEET names
$this->_parser->setExtSheet($name, $index); // Register worksheet name with parser
*/
function _storeWorkbook()
{
+ if (count($this->_worksheets) == 0) {
+ return true;
+ }
+
// Ensure that at least one worksheet has been selected.
if ($this->_activesheet == 0) {
$this->_worksheets[0]->selected = 1;
return true;
}
- /**
- * 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;
- }
-
/**
* Store the workbook in an OLE container
*
*/
function _storeOLEFile()
{
- $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
+ if($this->_BIFF_version == 0x0600) {
+ $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
+ } else {
+ $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
+ }
if ($this->_tmp_dir != '') {
$OLE->setTempDir($this->_tmp_dir);
}
$header = pack("vvv", $record, $length, $ccv);
$this->_append($header . $data);
}
- /**
+
+ /**
* Calculate
* Handling of the SST continue blocks is complicated by the need to include an
* additional continuation byte depending on whether the string is split between
8228 : Maximum Excel97 block size
-4 : Length of block header
-8 : Length of additional SST header information
- -8 : Arbitrary number to keep within _add_continue() limit
- = 8208
+ -8 : Arbitrary number to keep within _add_continue() limit = 8208
*/
$continue_limit = 8208;
$block_length = 0;
foreach (array_keys($this->_str_table) as $string) {
$string_length = strlen($string);
- $headerinfo = unpack("vlength/Cencoding", $string);
- $encoding = $headerinfo["encoding"];
- $split_string = 0;
+ $headerinfo = unpack("vlength/Cencoding", $string);
+ $encoding = $headerinfo["encoding"];
+ $split_string = 0;
// Block length is the total length of the strings that will be
// written out in a single SST or CONTINUE block.
boundaries. Therefore, in some cases we need to reduce the
amount of available
*/
- $align = 0;
-
- # Only applies to Unicode strings
- if ($encoding == 1) {
- # Min string + header size -1
- $header_length = 4;
-
- if ($space_remaining > $header_length) {
- # String contains 3 byte header => split on odd boundary
- if (!$split_string && $space_remaining % 2 != 1) {
- $space_remaining--;
- $align = 1;
- }
- # Split section without header => split on even boundary
- else if ($split_string && $space_remaining % 2 == 1) {
- $space_remaining--;
- $align = 1;
- }
-
- $split_string = 1;
- }
- }
+ $align = 0;
+
+ // Only applies to Unicode strings
+ if ($encoding == 1) {
+ // Min string + header size -1
+ $header_length = 4;
+
+ if ($space_remaining > $header_length) {
+ // String contains 3 byte header => split on odd boundary
+ if (!$split_string && $space_remaining % 2 != 1) {
+ $space_remaining--;
+ $align = 1;
+ }
+ // Split section without header => split on even boundary
+ else if ($split_string && $space_remaining % 2 == 1) {
+ $space_remaining--;
+ $align = 1;
+ }
+
+ $split_string = 1;
+ }
+ }
if ($space_remaining > $header_length) {
they must be written before the SST records
*/
- $tmp_block_sizes = array();
- $tmp_block_sizes = $this->_block_sizes;
+ $tmp_block_sizes = array();
+ $tmp_block_sizes = $this->_block_sizes;
- $length = 12;
- if (!empty($tmp_block_sizes)) {
- $length += array_shift($tmp_block_sizes); # SST
- }
- while (!empty($tmp_block_sizes)) {
- $length += 4 + array_shift($tmp_block_sizes); # CONTINUEs
- }
+ $length = 12;
+ if (!empty($tmp_block_sizes)) {
+ $length += array_shift($tmp_block_sizes); // SST
+ }
+ while (!empty($tmp_block_sizes)) {
+ $length += 4 + array_shift($tmp_block_sizes); // CONTINUEs
+ }
- return $length;
+ return $length;
}
/**
function _storeSharedStringsTable()
{
$record = 0x00fc; // Record identifier
- $length = 0x0008; // Number of bytes to follow
- $total = 0x0000;
+ $length = 0x0008; // Number of bytes to follow
+ $total = 0x0000;
// Iterate through the strings to calculate the CONTINUE block sizes
$continue_limit = 8208;
$continue = 0;
// sizes are upside down
- $tmp_block_sizes = $this->_block_sizes;
-// $tmp_block_sizes = array_reverse($this->_block_sizes);
+ $tmp_block_sizes = $this->_block_sizes;
+ // $tmp_block_sizes = array_reverse($this->_block_sizes);
- # The SST record is required even if it contains no strings. Thus we will
- # always have a length
- #
- if (!empty($tmp_block_sizes)) {
- $length = 8 + array_shift($tmp_block_sizes);
- }
- else {
- # No strings
- $length = 8;
- }
+ // The SST record is required even if it contains no strings. Thus we will
+ // always have a length
+ //
+ if (!empty($tmp_block_sizes)) {
+ $length = 8 + array_shift($tmp_block_sizes);
+ }
+ else {
+ // No strings
+ $length = 8;
+ }
foreach (array_keys($this->_str_table) as $string) {
$string_length = strlen($string);
- $headerinfo = unpack("vlength/Cencoding", $string);
- $encoding = $headerinfo["encoding"];
+ $headerinfo = unpack("vlength/Cencoding", $string);
+ $encoding = $headerinfo["encoding"];
$split_string = 0;
// Block length is the total length of the strings that will be
// Unicode data should only be split on char (2 byte) boundaries.
// Therefore, in some cases we need to reduce the amount of available
- // space by 1 byte to ensure the correct alignment.
- $align = 0;
-
- // Only applies to Unicode strings
- if ($encoding == 1) {
- // Min string + header size -1
- $header_length = 4;
-
- if ($space_remaining > $header_length) {
- // String contains 3 byte header => split on odd boundary
- if (!$split_string && $space_remaining % 2 != 1) {
- $space_remaining--;
- $align = 1;
- }
- // Split section without header => split on even boundary
- else if ($split_string && $space_remaining % 2 == 1) {
- $space_remaining--;
- $align = 1;
- }
-
- $split_string = 1;
- }
- }
+ // space by 1 byte to ensure the correct alignment.
+ $align = 0;
+
+ // Only applies to Unicode strings
+ if ($encoding == 1) {
+ // Min string + header size -1
+ $header_length = 4;
+
+ if ($space_remaining > $header_length) {
+ // String contains 3 byte header => split on odd boundary
+ if (!$split_string && $space_remaining % 2 != 1) {
+ $space_remaining--;
+ $align = 1;
+ }
+ // Split section without header => split on even boundary
+ else if ($split_string && $space_remaining % 2 == 1) {
+ $space_remaining--;
+ $align = 1;
+ }
+
+ $split_string = 1;
+ }
+ }
if ($space_remaining > $header_length) {
}
}
}
-
-
+
+
}
+
}\r
elseif ($this->_input_encoding != '')\r
{\r
- $str = mb_convert_encoding($str,'UTF-16LE', $this->_input_encoding );\r
+ $str = iconv($this->_input_encoding, 'UTF-16LE', $str);\r
$strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);\r
$encoding = 0x1;\r
}\r
* @access public
*/
function connectsTo(&$target) {
+ if (version_compare(PHP_VERSION, '5.0.0') >= 0) {
+ return in_array($target, $this->getNeighbours(), true);
+ }
+
$copy = $target;
$arcKeys = array_keys($this->_arcs);
foreach($arcKeys as $key) {
* @author Tomas V.V.Cox <cox@idecnet.com>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: System.php 276386 2009-02-24 23:52:56Z dufuz $
+ * @version CVS: $Id: System.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
* @author Tomas V.V. Cox <cox@idecnet.com>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
-* @version Release: 1.9.0
+* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @static
function _parseArgs($argv, $short_options, $long_options = null)
{
if (!is_array($argv) && $argv !== null) {
- $argv = preg_split('/\s+/', $argv, -1, PREG_SPLIT_NO_EMPTY);
+ // Find all items, quoted or otherwise
+ preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\s]+)/", $argv, $av);
+ $argv = $av[1];
+ foreach ($av[2] as $k => $a) {
+ if (empty($a)) {
+ continue;
+ }
+ $argv[$k] = trim($a) ;
+ }
}
- return Console_Getopt::getopt2($argv, $short_options);
+ return Console_Getopt::getopt2($argv, $short_options, $long_options);
}
/**
* Class to create a Turing test for websites by
* creating an image, ASCII art or something else
* with some (obfuscated) characters
- *
*
- * @package Text_CAPTCHA
- * @license BSD License
- * @author Christian Wenz <wenz@php.net>
* @category Text
+ * @package Text_CAPTCHA
+ * @author Christian Wenz <wenz@php.net>
+ * @license BSD License
*/
'font_file' => 'COUR.TTF',
'text_color' => '#DDFF99',
'lines_color' => '#CCEEDD',
- 'background_color' => '#555555'
+ 'background_color' => '#555555',
+ 'antialias' => true
);
// Set CAPTCHA options
?>
*/
-class Text_CAPTCHA {
+class Text_CAPTCHA
+{
/**
* Version number
* @access private
* @var string
*/
- var $_version = '0.4.0';
+ var $_version = '0.4.2';
/**
* Phrase
include_once "Text/CAPTCHA/Driver/$driver.php";
$classname = "Text_CAPTCHA_Driver_$driver";
- $obj =& new $classname;
+ $obj = new $classname;
return $obj;
}
*
* This method creates a random phrase, 8 characters long
*
- * @access private
+ * @param array $options optionally supply advanced options for the phrase creation
+ *
+ * @access private
+ * @return void
*/
function _createPhrase($options = array())
{
*
* This method returns the CAPTCHA phrase
*
- * @access public
- * @return phrase secret phrase
+ * @access public
+ * @return phrase secret phrase
*/
function getPhrase()
{
* This method sets the CAPTCHA phrase
* (use null for a random phrase)
*
+ * @param string $phrase the (new) phrase
+ *
* @access public
- * @param string $phrase the (new) phrase
- * @void
+ * @return void
*/
function setPhrase($phrase = null)
{
* @access private
* @return PEAR_Error
*/
- function init() {
+ function init()
+ {
return PEAR::raiseError('CAPTCHA type not selected', true);
}
* @access private
* @return PEAR_Error
*/
- function _createCAPTCHA() {
+ function _createCAPTCHA()
+ {
return PEAR::raiseError('CAPTCHA type not selected', true);
}
* @access private
* @return PEAR_Error
*/
- function getCAPTCHA() {
+ function getCAPTCHA()
+ {
return PEAR::raiseError('CAPTCHA type not selected', true);
}
-
}
-?>
* Equation driver for Text_CAPTCHA.
* Returns simple equations as string, e.g. "9 - 2"
*
+ * @author Christian Weiske <cweiske@php.net>
+ * @author Christian Wenz <wenz@php.net>
* @license BSD License
- * @author Christian Weiske <cweiske@php.net>
- * @author Christian Wenz <wenz@php.net>
*/
require_once 'Text/CAPTCHA.php';
/**
* Initialize the driver.
*
+ * @param array $options Optionally supply options for the initialization phase
+ *
* @access public
* @return true on success, PEAR_Error on error.
*/
- function init($options = array()) {
+ function init($options = array())
+ {
if (isset($options['min'])) {
$this->_min = (int)$options['min'];
} else {
*
* Also converts the numbers to words if required.
*
+ * @param int $one First number
+ * @param int $two Second number
+ * @param string $operator Operator
+ *
* @access protected
* @return array Array with equation and solution
*/
* @access protected
* @return PEAR_Error
*/
- function _createCAPTCHA() {
+ function _createCAPTCHA()
+ {
//is already done in _createPhrase();
}
* @access public
* @return string
*/
- function getCAPTCHA() {
+ function getCAPTCHA()
+ {
return $this->_equation;
}
}//class Text_CAPTCHA_Driver_TextEquation extends Text_CAPTCHA
-?>
\ No newline at end of file
<?php
/**
- *
* Require Figlet class for rendering the text.
- *
*/
require_once 'Text/CAPTCHA.php';
require_once 'Text/Figlet.php';
-
/**
* Text_CAPTCHA_Driver_Figlet - Text_CAPTCHA driver Figlet based CAPTCHAs
*
+ * @author Aaron Wormus <wormus@php.net>
+ * @author Christian Wenz <wenz@php.net>
* @license BSD License
- * @author Aaron Wormus <wormus@php.net>
- * @author Christian Wenz <wenz@php.net>
* @todo define an obfuscation algorithm
*/
*
* Initializes the new Text_CAPTCHA_Driver_Figlet object and creates a GD image
*
- * @param array $options CAPTCHA options
+ * @param array $options CAPTCHA options
* @access public
- * @return mixed true upon success, PEAR error otherwise
+ * @return mixed true upon success, PEAR error otherwise
*/
function init($options = array())
{
if (is_array($options)) {
- if (!empty($options['output'])){
- $this->_output = $options['output'];
+ if (!empty($options['output'])) {
+ $this->_output = $options['output'];
} else {
- $this->_output = 'html';
+ $this->_output = 'html';
}
if (isset($options['width']) && is_int($options['width'])) {
- $this->_width = $options['width'];
+ $this->_width = $options['width'];
} else {
- $this->_width = 200;
+ $this->_width = 200;
}
- if (!empty($options['length'])){
+ if (!empty($options['length'])) {
$this->_length = $options['length'];
} else {
$this->_length = 6;
if (!isset($options['phrase']) || empty($options['phrase'])) {
$phraseoptions = (isset($options['phraseOptions']) && is_array($options['phraseOptions'])) ? $options['phraseOptions'] : array();
- $this->_createPhrase($options);
+ $this->_createPhrase($phraseoptions);
} else {
$this->_phrase = $options['phrase'];
}
}
- if (empty($options['options']) || !is_array($options['options'])){
+ if (!isset($options['options']) || empty($options['options']) || !is_array($options['options'])) {
die;
} else {
- if (!empty($options['options']['style']) && is_array($options['options']['style'])){
+ if (isset($options['options']['style']) && !empty($options['options']['style']) && is_array($options['options']['style'])) {
$this->_style = $options['options']['style'];
}
- if (empty($this->style['padding'])){
+ if (!isset($this->_style['padding']) || empty($this->_style['padding'])) {
$this->_style['padding'] = '5px';
}
- if (!empty($options['options']['font_file'])){
- if (is_array($options['options']['font_file'])){
+ if (isset($options['options']['font_file']) && !empty($options['options']['font_file'])) {
+ if (is_array($options['options']['font_file'])) {
$this->_font = $options['options']['font_file'][array_rand($options['options']['font_file'])];
} else {
$this->_font = $options['options']['font_file'];
* Create random CAPTCHA phrase
* This method creates a random phrase
*
- * @access private
+ * @param array $options Optionally supply advanced options for the phase creation;
+ * used for the initialization of Text_Password
+ *
+ * @access private
+ * @return void
*/
- function _createPhrase($options)
+ function _createPhrase($options = array())
{
if (!is_array($options) || count($options) === 0) {
$this->_phrase = Text_Password::create($this->_length);
*
* This method creates a CAPTCHA image
*
- * @access private
- * @return void PEAR_Error on error
+ * @access private
+ * @return void PEAR_Error on error
*/
function _createCAPTCHA()
-
{
$this->_fig = new Text_Figlet();
- if (PEAR::isError($this->_fig->LoadFont($this->_font))){
+ if (PEAR::isError($this->_fig->LoadFont($this->_font))) {
$this->_error = PEAR::raiseError('Error loading Text_Figlet font');
return $this->_error;
}
- $this->_output_string = $this->_fig->LineEcho($this->_phrase);
+ $this->_output_string = $this->_fig->LineEcho($this->_phrase);
}
/**
*
* This method returns the CAPTCHA depending on the output format
*
- * @access public
- * @return mixed Formatted captcha or PEAR error
+ * @access public
+ * @return mixed Formatted captcha or PEAR error
*/
function getCAPTCHA()
{
*
* This method returns the CAPTCHA as HTML
*
- * @access public
- * @return mixed HTML Figlet image or PEAR error
+ * @access public
+ * @return mixed HTML Figlet image or PEAR error
*/
function getCAPTCHAAsHTML()
{
$textsize = ($this->_width / $charwidth) * 1.4;
$css_output = "";
- foreach ($this->_style as $key => $value){
+ foreach ($this->_style as $key => $value) {
$css_output .= "$key: $value;";
}
}
/**
- * Return CAPTCHA as Javascript version of HTML
+ * Return CAPTCHA as JavaScript version of HTML
*
- * This method returns the CAPTCHA as a Javascript string
+ * This method returns the CAPTCHA as a JavaScript string
* I'm not exactly sure what the point of doing this would be.
*
- * @access public
- * @return mixed javascript string or PEAR error
+ * @access public
+ * @return mixed JavaScript string or PEAR error
*/
function getCAPTCHAAsJavascript()
{
$obfus_data = rawurlencode($data);
- $javascript = "<script language=\"javascript\">
- document.write(unescape(\"$obfus_data.\" ) );
+ $javascript = "<script type=\"text/javascript\">
+ document.write(unescape(\"${obfus_data}\"));
</script>";
return $javascript;
<?php
/**
- *
* Require Image_Text class for generating the text.
- *
*/
require_once 'Text/CAPTCHA.php';
require_once 'Image/Text.php';
* Text_CAPTCHA_Driver_Image - Text_CAPTCHA driver graphical CAPTCHAs
*
* Class to create a graphical Turing test
- *
*
+ * @author Christian Wenz <wenz@php.net>
* @license BSD License
- * @author Christian Wenz <wenz@php.net>
* @todo refine the obfuscation algorithm :-)
* @todo consider removing Image_Text dependency
*/
'font_file' => 'COUR.TTF',
'text_color' => '#000000',
'lines_color' => '#CACACA',
- 'background_color' => '#555555');
+ 'background_color' => '#555555',
+ 'antialias' => false);
/**
* Whether the immage resource has been created
*
* Initializes the new Text_CAPTCHA_Driver_Image object and creates a GD image
*
- * @param array $options CAPTCHA options
+ * @param array $options CAPTCHA options
+ *
* @access public
- * @return mixed true upon success, PEAR error otherwise
+ * @return mixed true upon success, PEAR error otherwise
*/
function init($options = array())
{
}
if (is_array($options)) {
if (isset($options['width']) && is_int($options['width'])) {
- $this->_width = $options['width'];
+ $this->_width = $options['width'];
} else {
- $this->_width = 200;
+ $this->_width = 200;
}
if (isset($options['height']) && is_int($options['height'])) {
- $this->_height = $options['height'];
+ $this->_height = $options['height'];
} else {
- $this->_height = 80;
+ $this->_height = 80;
}
if (!isset($options['phrase']) || empty($options['phrase'])) {
$phraseoptions = (isset($options['phraseOptions']) && is_array($options['phraseOptions'])) ? $options['phraseOptions'] : array();
*
* This method creates a random phrase, maximum 8 characters or width / 25, whatever is smaller
*
- * @access private
+ * @param array $options Optionally supply advanced options for the phrase creation
+ *
+ * @access private
+ * @return void
*/
function _createPhrase($options = array())
{
);
if (PEAR::isError($e = $this->_imt->init())) {
$this->_error = PEAR::raiseError(
- sprintf('Error initializing Image_Text (%s)',
- $e->getMessage()));
+ sprintf('Error initializing Image_Text (%s)', $e->getMessage()));
return $this->_error;
} else {
$this->_created = true;
$this->_error = PEAR::raiseError('The text provided does not fit in the image dimensions');
return $this->_error;
}
- $this->_imt->render();
+ $this->_imt->render();
$this->_im =& $this->_imt->getImg();
+
+ if (isset($this->_imageOptions['antialias']) && $this->_imageOptions['antialias'] === true && function_exists('imageantialias')) {
+ imageantialias($this->_im, true);
+ }
+
$colors = $this->_imt->_convertString2RGB($this->_imageOptions['lines_color']);
$lines_color = imagecolorallocate($this->_im, $colors['r'], $colors['g'], $colors['b']);
//some obfuscation
/**
* __wakeup method (PHP 5 only)
+ *
+ * @return void
*/
function __wakeup()
{
* Example:
* Give me the answer to "54 + 2" to prove that you are human.
*
+ * @category Text
+ * @package Text_CAPTCHA
* @author David Coallier <davidc@agoraproduction.com>
* @author Christian Wenz <wenz@php.net>
- * @package Text_CAPTCHA
- * @category Text
*/
class Text_CAPTCHA_Driver_Numeral extends Text_CAPTCHA
{
// }}}
// {{{ private function _createCAPTCHA
/**
- * Create the CAPTCHA (the numeral expressio)
+ * Create the CAPTCHA (the numeral expression)
*
* This function determines a random numeral expression
* and set the associated class properties
*
* @access private
+ * @return void
*/
function _createCAPTCHA()
{
* to set the range minimum value so the operations
* can be bigger, smaller, etc.
*
- * @access private
* @param integer $minValue The minimum value
+ *
+ * @access private
+ * @return void
*/
function _setRangeMinimum($minValue = 1)
{
* function that generates a random number.
*
* @access private
+ * @return void
* @see $this->_firstNumber, $this->_generateNumber
*/
function _generateFirstNumber()
* operation by calling _generateNumber()
*
* @access private
+ * @return void
* @see $this->_secondNumber, $this->_generateNumber()
*/
function _generateSecondNumber()
* the $this->_operators() array.
*
* @access private
+ * @return void
* @see $this->_operators, $this->_operator
*/
function _generateOperator()
* basically the result of the function we have done
* and it will set $this->answer with it.
*
- * @access private
* @param integer $phraseValue The answer value
+ *
+ * @access private
+ * @return void
* @see $this->_phrase
*/
function _setPhrase($phraseValue)
* This function sets the first number
* to the value passed to the function
*
- * @access private
* @param integer $value The first number value.
+ *
+ * @access private
+ * @return void
*/
function _setFirstNumber($value)
{
* This function sets the second number
* with the value passed to it.
*
- * @access private
* @param integer $value The second number new value.
+ *
+ * @access private
+ * @return void
*/
function _setSecondNumber($value)
{
* by taking the firstNumber, secondNumber and operator
*
* @access private
+ * @return void
* @see $this->_operation
*/
function _setOperation()
* set the answer value.
*
* @access private
+ * @return void
* @see $this->_firstNumber, $this->_secondNumber, $this->_setAnswer()
*/
function _doAdd()
* then we regenerate the first number and regenerate the operation.
*
* @access private
+ * @return void
* @see $this->_firstNumber, $this->_secondNumber, $this->_setAnswer()
*/
function _doSubstract()
/**
* Check if firstNumber is smaller than secondNumber
*/
- if ($first < $second) {
- $this->_setFirstNumber($second);
- $this->_setSecondNumber($first);
- $this->_setOperation();
- }
+ if ($first < $second) {
+ $this->_setFirstNumber($second);
+ $this->_setSecondNumber($first);
+ $this->_setOperation();
+ }
$phrase = $this->_getFirstNumber() - $this->_getSecondNumber();
$this->_setPhrase($phrase);
* depending on which operation is set by this->operator.
*
* @access private
+ * @return void
* @see $this->_setOperation(), $this->_operator
*/
function _generateOperation()
}
}
// }}}
-?>
*
* Class to create a textual Turing test
*
- *
+ * @author Tobias Schlitt <schlitt@php.net>
+ * @author Christian Wenz <wenz@php.net>
* @license BSD License
- * @author Tobias Schlitt <schlitt@php.net>
- * @author Christian Wenz <wenz@php.net>
*/
/**
*
* Initializes the new Text_CAPTCHA_Driver_Word object
*
- * @param array $options CAPTCHA options with these keys:
- * phrase The "secret word" of the CAPTCHA
- * length The number of characters in the phrase
- * locale The locale for Numbers_Words
- * mode The mode for Numbers_Words
+ * @param array $options CAPTCHA options with these keys:
+ * phrase The "secret word" of the CAPTCHA
+ * length The number of characters in the phrase
+ * locale The locale for Numbers_Words
+ * mode The mode for Numbers_Words
+ *
* @access public
*/
function init($options = array())
return $res;
}
}
-?>
* @author Olivier Vanhoucke <olivier@php.net>
* @copyright 2004-2005 Martin Jansen, Olivier Vanhoucke
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: Password.php,v 1.16 2005/08/21 19:47:53 mj Exp $
+ * @version CVS: $Id: Password.php,v 1.18 2008/11/30 13:38:56 mj Exp $
* @link http://pear.php.net/package/Text_Password
*/
/**
* Number of possible characters in the password
*/
-$_Text_Password_NumberOfPossibleCharacters = 0;
+$GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 0;
/**
* Main class for the Text_Password package
* @param integer Length of the password.
* @param string Type of password (pronounceable, unpronounceable)
* @param string Character which could be use in the
- * unpronounceable password ex : 'A,B,C,D,E,F,G'
+ * unpronounceable password ex : 'ABCDEFG'
* or numeric, alphabetical or alphanumeric.
* @return string Returns the generated password.
*/
function _createPronounceable($length)
{
- global $_Text_Password_NumberOfPossibleCharacters;
$retVal = '';
/**
$v_count = 12;
$c_count = 29;
- $_Text_Password_NumberOfPossibleCharacters = $v_count + $c_count;
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = $v_count + $c_count;
for ($i = 0; $i < $length; $i++) {
$retVal .= $c[mt_rand(0, $c_count-1)] . $v[mt_rand(0, $v_count-1)];
*/
function _createUnpronounceable($length, $chars)
{
- global $_Text_Password_NumberOfPossibleCharacters;
-
$password = '';
/**
case 'alphanumeric':
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- $_Text_Password_NumberOfPossibleCharacters = 62;
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 62;
break;
case 'alphabetical':
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- $_Text_Password_NumberOfPossibleCharacters = 52;
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 52;
break;
case 'numeric':
$chars = '0123456789';
- $_Text_Password_NumberOfPossibleCharacters = 10;
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 10;
break;
case '':
$chars = '_#@%&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- $_Text_Password_NumberOfPossibleCharacters = 67;
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 67;
break;
default:
$chars = trim($chars);
$chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars);
- $_Text_Password_NumberOfPossibleCharacters = strlen($chars);
+ $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = strlen($chars);
}
/**
* Generate password
*/
for ($i = 0; $i < $length; $i++) {
- $num = mt_rand(0, $_Text_Password_NumberOfPossibleCharacters - 1);
+ $num = mt_rand(0, $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] - 1);
$password .= $chars{$num};
}
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Contains the Translation2 base class\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2008 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: Translation2.php,v 1.42 2008/11/14 16:18:50 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-\r
-/**\r
- * require PEAR base class\r
- */\r
-require_once 'PEAR.php';\r
-\r
-/**\r
- * Allows redefinition of the default pageID.\r
- * This constant is needed to allow both NULL and EMPTY pageID values\r
- * and to have them match\r
- */\r
-if (!defined('TRANSLATION2_DEFAULT_PAGEID')) {\r
- define('TRANSLATION2_DEFAULT_PAGEID', 'translation2_default_pageID');\r
-}\r
-/**\r
- * Class Error codes\r
- */\r
-define('TRANSLATION2_ERROR', -1);\r
-define('TRANSLATION2_ERROR_METHOD_NOT_SUPPORTED', -2);\r
-define('TRANSLATION2_ERROR_CANNOT_CONNECT', -3);\r
-define('TRANSLATION2_ERROR_CANNOT_FIND_FILE', -4);\r
-define('TRANSLATION2_ERROR_DOMAIN_NOT_SET', -5);\r
-define('TRANSLATION2_ERROR_INVALID_PATH', -6);\r
-define('TRANSLATION2_ERROR_CANNOT_CREATE_DIR', -7);\r
-define('TRANSLATION2_ERROR_CANNOT_WRITE_FILE', -8);\r
-define('TRANSLATION2_ERROR_UNKNOWN_LANG', -9);\r
-define('TRANSLATION2_ERROR_ENCODING_CONVERSION', -10);\r
-define('TRANSLATION2_ERROR_UNSUPPORTED', -11);\r
-\r
-/**\r
- * Translation2 base class\r
- *\r
- * This class provides an easy way to retrieve all the strings\r
- * for a multilingual site or application from a data source\r
- * (i.e. a db, an xml file or a gettext file).\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2008 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-class Translation2\r
-{\r
- // {{{ class vars\r
-\r
- /**\r
- * Storage object\r
- * @var object\r
- * @access protected\r
- */\r
- var $storage = '';\r
-\r
- /**\r
- * Class options\r
- * @var array\r
- */\r
- var $options = array();\r
-\r
- /**\r
- * Default lang\r
- * @var array\r
- * @access protected\r
- */\r
- var $lang = array();\r
-\r
- /**\r
- * Current pageID\r
- * @var string\r
- * @access protected\r
- */\r
- var $currentPageID = null;\r
-\r
- /**\r
- * Array of parameters for the adapter class\r
- * @var array\r
- * @access protected\r
- */\r
- var $params = array();\r
-\r
- // }}}\r
- // {{{ Constructor\r
-\r
- /**\r
- * Constructor\r
- */\r
- function Translation2()\r
- {\r
- if (func_num_args()) {\r
- $msg = '<b>Translation2 error:</b>'\r
- .' Don\'t use the constructor - use factory()';\r
- trigger_error($msg, E_USER_ERROR);\r
- }\r
- }\r
-\r
- // }}}\r
- // {{{ factory()\r
-\r
- /**\r
- * Return a Translation2 instance already initialized\r
- *\r
- * @param string $driver Type of the storage driver\r
- * @param mixed $options Additional options for the storage driver\r
- * (example: if you are using DB as the storage\r
- * driver, you have to pass the dsn string here)\r
- * @param array $params Array of parameters for the adapter class\r
- * (i.e. you can set here the mappings between your\r
- * table/field names and the ones used by this class)\r
- *\r
- * @return object Translation2 instance or PEAR_Error on failure\r
- * @static\r
- */\r
- function & factory($driver, $options = '', $params = array())\r
- {\r
- $tr = new Translation2;\r
- $tr->storage = Translation2::_storageFactory($driver, $options);\r
- if (PEAR::isError($tr->storage)) {\r
- return $tr->storage;\r
- }\r
- $tr->_setDefaultOptions();\r
- $tr->_parseOptions($params);\r
- $tr->storage->_parseOptions($params);\r
- return $tr;\r
- }\r
-\r
- // }}}\r
- // {{{ _storageFactory()\r
-\r
- /**\r
- * Return a storage driver based on $driver and $options\r
- *\r
- * @param string $driver Type of storage class to return\r
- * @param string $options Optional parameters for the storage class\r
- *\r
- * @return object Object Storage object\r
- * @static\r
- * @access private\r
- */\r
- function & _storageFactory($driver, $options = '')\r
- {\r
- $storage_path = 'Translation2/Container/'.strtolower($driver).'.php';\r
- $storage_class = 'Translation2_Container_'.strtolower($driver);\r
- include_once $storage_path;\r
- $storage = new $storage_class;\r
- $err = $storage->init($options);\r
- if (PEAR::isError($err)) {\r
- return $err;\r
- }\r
- return $storage;\r
- }\r
-\r
- // }}}\r
- // {{{ setContainerOptions()\r
-\r
- /**\r
- * Set some storage driver options\r
- *\r
- * @param array $options array of options\r
- *\r
- * @return void\r
- * @access protected\r
- */\r
- function setContainerOptions($options)\r
- {\r
- $this->storage->_parseOptions($options);\r
- }\r
-\r
- // }}}\r
- // {{{ _setDefaultOptions()\r
-\r
- /**\r
- * Set some default options\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function _setDefaultOptions()\r
- {\r
- $this->options['ParameterPrefix'] = '&&';\r
- $this->options['ParameterPostfix'] = '&&';\r
- $this->options['ParameterAutoFree'] = true;\r
- $this->options['prefetch'] = true;\r
- }\r
-\r
- // }}}\r
- // {{{ _parseOptions()\r
-\r
- /**\r
- * Parse options passed to the base class\r
- *\r
- * @param array $array options\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function _parseOptions($array)\r
- {\r
- foreach ($array as $key => $value) {\r
- if (isset($this->options[$key])) {\r
- $this->options[$key] = $value;\r
- }\r
- }\r
- }\r
-\r
- // }}}\r
- // {{{ getDecorator()\r
-\r
- /**\r
- * Return an instance of a decorator\r
- *\r
- * This method is used to get a decorator instance.\r
- * A decorator can be seen as a filter, i.e. something that can change\r
- * or handle the values of the objects/vars that pass through.\r
- *\r
- * @param string $decorator Name of the decorator\r
- *\r
- * @return object Decorator object reference\r
- */\r
- function & getDecorator($decorator)\r
- {\r
- $decorator_path = 'Translation2/Decorator/'.$decorator.'.php';\r
- $decorator_class = 'Translation2_Decorator_'.$decorator;\r
- include_once $decorator_path;\r
- if (func_num_args() > 1) {\r
- $obj = func_get_arg(1);\r
- $new_decorator = new $decorator_class($obj);\r
- } else {\r
- $new_decorator = new $decorator_class($this);\r
- }\r
- return $new_decorator;\r
- }\r
-\r
- // }}}\r
- // {{{ setCharset()\r
-\r
- /**\r
- * Set charset used to read/store the translations\r
- *\r
- * @param string $charset character set (encoding)\r
- *\r
- * @return void|PEAR_Error\r
- */\r
- function setCharset($charset)\r
- {\r
- $res = $this->storage->setCharset($charset);\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- }\r
-\r
- // }}}\r
- // {{{ setLang()\r
-\r
- /**\r
- * Set default lang\r
- *\r
- * Set the language that shall be used when retrieving strings.\r
- *\r
- * @param string $langID language code (for instance, 'en' or 'it')\r
- *\r
- * @return true|PEAR_Error\r
- */\r
- function setLang($langID)\r
- {\r
- $res = $this->storage->setLang($langID);\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- $this->lang = $res;\r
- return true;\r
- }\r
-\r
- // }}}\r
- // {{{ setPageID($pageID)\r
-\r
- /**\r
- * Set default page\r
- *\r
- * Set the page (aka "group of strings") that shall be used when retrieving strings.\r
- * If you set it, you don't have to state it in each get() call.\r
- *\r
- * @param string $pageID ID of the default page\r
- *\r
- * @return self\r
- */\r
- function setPageID($pageID = null)\r
- {\r
- $this->currentPageID = $pageID;\r
- return $this;\r
- }\r
-\r
- // }}}\r
- // {{{ getLang()\r
-\r
- /**\r
- * get lang info\r
- *\r
- * Get some extra information about the language (its full name,\r
- * the localized error text, ...)\r
- *\r
- * @param string $langID language ID\r
- * @param string $format ['name', 'meta', 'error_text', 'array']\r
- *\r
- * @return mixed [string | array], depending on $format\r
- */\r
- function getLang($langID = null, $format = 'name')\r
- {\r
- if (is_null($langID)) {\r
- if (!isset($this->lang['id'])) {\r
- $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'\r
- .' Use Translation2::setLang() to set a default language.';\r
- return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);\r
- }\r
- $langID = $this->lang['id'];\r
- }\r
- $lang = $this->storage->getLangData($langID);\r
- if ($format == 'array') {\r
- return $lang;\r
- } elseif (isset($lang[$format])) {\r
- return $lang[$format];\r
- } elseif (isset($lang['name'])) {\r
- return $lang['name'];\r
- }\r
- $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'\r
- .' Use Translation2::setLang() to set a default language.';\r
- return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);\r
- }\r
-\r
- // }}}\r
- // {{{ getLangs()\r
-\r
- /**\r
- * get langs\r
- *\r
- * Get some extra information about the languages (their full names,\r
- * the localized error text, their codes, ...)\r
- *\r
- * @param string $format ['ids', 'names', 'array']\r
- *\r
- * @return array|PEAR_Error\r
- */\r
- function getLangs($format = 'name')\r
- {\r
- return $this->storage->getLangs($format);\r
- }\r
-\r
- // }}}\r
- // {{{ setParams()\r
-\r
- /**\r
- * Set parameters for next string\r
- *\r
- * Set the replacement for the parameters in the string(s).\r
- * Parameter delimiters are customizable.\r
- *\r
- * @param array $params array of replacement parameters\r
- *\r
- * @return self\r
- */\r
- function setParams($params = null)\r
- {\r
- if (empty($params)) {\r
- $this->params = array();\r
- } elseif (is_array($params)) {\r
- $this->params = $params;\r
- } else {\r
- $this->params = array($params);\r
- }\r
- return $this;\r
- }\r
-\r
- // }}}\r
- // {{{ _replaceParams()\r
-\r
- /**\r
- * Replace parameters in strings\r
- *\r
- * @param mixed $strings strings where the replacements must occur\r
- *\r
- * @return mixed\r
- * @access protected\r
- */\r
- function _replaceParams($strings)\r
- {\r
- if (empty($strings) || is_object($strings) || !count($this->params)) {\r
- return $strings;\r
- }\r
- if (is_array($strings)) {\r
- foreach ($strings as $key => $string) {\r
- $strings[$key] = $this->_replaceParams($string);\r
- }\r
- } else {\r
- if (strpos($strings, $this->options['ParameterPrefix']) !== false) {\r
- foreach ($this->params as $name => $value) {\r
- $strings = str_replace($this->options['ParameterPrefix']\r
- . $name . $this->options['ParameterPostfix'],\r
- $value,\r
- $strings);\r
- }\r
- if ($this->options['ParameterAutoFree']) {\r
- $this->params = array();\r
- }\r
- }\r
- }\r
- return $strings;\r
- }\r
-\r
- // }}}\r
- // {{{ replaceEmptyStringsWithKeys()\r
-\r
- /**\r
- * Replace empty strings with their stringID\r
- *\r
- * @param array $strings array of strings to be replaced if empty\r
- *\r
- * @return array\r
- * @static\r
- */\r
- function replaceEmptyStringsWithKeys($strings)\r
- {\r
- if (!is_array($strings)) {\r
- return $strings;\r
- }\r
- foreach ($strings as $key => $string) {\r
- if (empty($string)) {\r
- $strings[$key] = $key;\r
- }\r
- }\r
- return $strings;\r
- }\r
-\r
- // }}}\r
- // {{{ getRaw()\r
-\r
- /**\r
- * Get translated string (as-is)\r
- *\r
- * @param string $stringID ID of the string to be translated\r
- * @param string $pageID ID of the page/group containing the string\r
- * @param string $langID ID of the language\r
- * @param string $defaultText Text to display when the string is empty\r
- *\r
- * @return string|PEAR_Error\r
- */\r
- function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);\r
- $str = $this->storage->getOne($stringID, $pageID, $langID);\r
- if (empty($str)) {\r
- $str = $defaultText;\r
- }\r
- return $str;\r
- }\r
-\r
- // }}}\r
- // {{{ get()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * First check if the string is cached, if not => fetch the page\r
- * from the container and cache it for later use.\r
- * If the string is empty, check the fallback language; if\r
- * the latter is empty too, then return the $defaultText.\r
- *\r
- * @param string $stringID ID of the string\r
- * @param string $pageID ID of the page/group containing the string\r
- * @param string $langID ID of the language\r
- * @param string $defaultText Text to display when the string is empty\r
- * NB: This parameter is only used in the DefaultText decorator\r
- *\r
- * @return string\r
- */\r
- function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- $str = $this->getRaw($stringID, $pageID, $langID);\r
- if (PEAR::isError($str)) {\r
- return $str;\r
- }\r
- return $this->_replaceParams($str);\r
- }\r
-\r
- // }}}\r
- // {{{ getRawPage()\r
-\r
- /**\r
- * Get the array of strings in a page\r
- *\r
- * Fetch the page (aka "group of strings) from the container,\r
- * without applying any formatting and without replacing the parameters\r
- *\r
- * @param string $pageID ID of the page/group containing the string\r
- * @param string $langID ID of the language\r
- *\r
- * @return array\r
- */\r
- function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);\r
- return $this->storage->getPage($pageID, $langID);\r
- }\r
-\r
- // }}}\r
- // {{{ getPage()\r
-\r
- /**\r
- * Get an entire group of strings\r
- *\r
- * Same as getRawPage, but resort to fallback language and\r
- * replace parameters when needed\r
- *\r
- * @param string $pageID ID of the page/group containing the string\r
- * @param string $langID ID of the language\r
- *\r
- * @return array\r
- */\r
- function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- $pageData = $this->getRawPage($pageID, $langID);\r
- return $this->_replaceParams($pageData);\r
- }\r
-\r
- // }}}\r
- // {{{ getStringID()\r
-\r
- /**\r
- * Get the stringID for the given string. This method is the reverse of get().\r
- *\r
- * @param string $string This is NOT the stringID, this is a real string.\r
- * The method will search for its matching stringID, and then\r
- * it will return the associate string in the selected language.\r
- * @param string $pageID ID of the page/group containing the string\r
- *\r
- * @return string\r
- */\r
- function getStringID($string, $pageID = TRANSLATION2_DEFAULT_PAGEID)\r
- {\r
- $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);\r
- return $this->storage->getStringID($string, $pageID);\r
- }\r
-\r
- // }}}\r
- // {{{ __clone()\r
-\r
- /**\r
- * Clone internal object references\r
- *\r
- * This method is called automatically by PHP5\r
- *\r
- * @return void\r
- * @access protected\r
- */\r
- function __clone()\r
- {\r
- $this->storage = clone($this->storage);\r
- }\r
-\r
- // }}}\r
-}\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contains the Translation2 base class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2008 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: Translation2.php 268999 2008-11-14 16:18:50Z quipo $
+ * @link http://pear.php.net/package/Translation2
+ */
+
+/**
+ * require PEAR base class
+ */
+require_once 'PEAR.php';
+
+/**
+ * Allows redefinition of the default pageID.
+ * This constant is needed to allow both NULL and EMPTY pageID values
+ * and to have them match
+ */
+if (!defined('TRANSLATION2_DEFAULT_PAGEID')) {
+ define('TRANSLATION2_DEFAULT_PAGEID', 'translation2_default_pageID');
+}
+/**
+ * Class Error codes
+ */
+define('TRANSLATION2_ERROR', -1);
+define('TRANSLATION2_ERROR_METHOD_NOT_SUPPORTED', -2);
+define('TRANSLATION2_ERROR_CANNOT_CONNECT', -3);
+define('TRANSLATION2_ERROR_CANNOT_FIND_FILE', -4);
+define('TRANSLATION2_ERROR_DOMAIN_NOT_SET', -5);
+define('TRANSLATION2_ERROR_INVALID_PATH', -6);
+define('TRANSLATION2_ERROR_CANNOT_CREATE_DIR', -7);
+define('TRANSLATION2_ERROR_CANNOT_WRITE_FILE', -8);
+define('TRANSLATION2_ERROR_UNKNOWN_LANG', -9);
+define('TRANSLATION2_ERROR_ENCODING_CONVERSION', -10);
+define('TRANSLATION2_ERROR_UNSUPPORTED', -11);
+
+/**
+ * Translation2 base class
+ *
+ * This class provides an easy way to retrieve all the strings
+ * for a multilingual site or application from a data source
+ * (i.e. a db, an xml file or a gettext file).
+ *
+ * @category Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2008 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @link http://pear.php.net/package/Translation2
+ */
+class Translation2
+{
+ // {{{ class vars
+
+ /**
+ * Storage object
+ * @var object
+ * @access protected
+ */
+ var $storage = '';
+
+ /**
+ * Class options
+ * @var array
+ */
+ var $options = array();
+
+ /**
+ * Default lang
+ * @var array
+ * @access protected
+ */
+ var $lang = array();
+
+ /**
+ * Current pageID
+ * @var string
+ * @access protected
+ */
+ var $currentPageID = null;
+
+ /**
+ * Array of parameters for the adapter class
+ * @var array
+ * @access protected
+ */
+ var $params = array();
+
+ // }}}
+ // {{{ Constructor
+
+ /**
+ * Constructor
+ */
+ function Translation2()
+ {
+ if (func_num_args()) {
+ $msg = '<b>Translation2 error:</b>'
+ .' Don\'t use the constructor - use factory()';
+ trigger_error($msg, E_USER_ERROR);
+ }
+ }
+
+ // }}}
+ // {{{ factory()
+
+ /**
+ * Return a Translation2 instance already initialized
+ *
+ * @param string $driver Type of the storage driver
+ * @param mixed $options Additional options for the storage driver
+ * (example: if you are using DB as the storage
+ * driver, you have to pass the dsn string here)
+ * @param array $params Array of parameters for the adapter class
+ * (i.e. you can set here the mappings between your
+ * table/field names and the ones used by this class)
+ *
+ * @return object Translation2 instance or PEAR_Error on failure
+ * @static
+ */
+ function & factory($driver, $options = '', $params = array())
+ {
+ $tr = new Translation2;
+ $tr->storage = Translation2::_storageFactory($driver, $options);
+ if (PEAR::isError($tr->storage)) {
+ return $tr->storage;
+ }
+ $tr->_setDefaultOptions();
+ $tr->_parseOptions($params);
+ $tr->storage->_parseOptions($params);
+ return $tr;
+ }
+
+ // }}}
+ // {{{ _storageFactory()
+
+ /**
+ * Return a storage driver based on $driver and $options
+ *
+ * @param string $driver Type of storage class to return
+ * @param string $options Optional parameters for the storage class
+ *
+ * @return object Object Storage object
+ * @static
+ * @access private
+ */
+ function & _storageFactory($driver, $options = '')
+ {
+ $storage_path = 'Translation2/Container/'.strtolower($driver).'.php';
+ $storage_class = 'Translation2_Container_'.strtolower($driver);
+ include_once $storage_path;
+ $storage = new $storage_class;
+ $err = $storage->init($options);
+ if (PEAR::isError($err)) {
+ return $err;
+ }
+ return $storage;
+ }
+
+ // }}}
+ // {{{ setContainerOptions()
+
+ /**
+ * Set some storage driver options
+ *
+ * @param array $options array of options
+ *
+ * @return void
+ * @access protected
+ */
+ function setContainerOptions($options)
+ {
+ $this->storage->_parseOptions($options);
+ }
+
+ // }}}
+ // {{{ _setDefaultOptions()
+
+ /**
+ * Set some default options
+ *
+ * @return void
+ * @access private
+ */
+ function _setDefaultOptions()
+ {
+ $this->options['ParameterPrefix'] = '&&';
+ $this->options['ParameterPostfix'] = '&&';
+ $this->options['ParameterAutoFree'] = true;
+ $this->options['prefetch'] = true;
+ }
+
+ // }}}
+ // {{{ _parseOptions()
+
+ /**
+ * Parse options passed to the base class
+ *
+ * @param array $array options
+ *
+ * @return void
+ * @access private
+ */
+ function _parseOptions($array)
+ {
+ foreach ($array as $key => $value) {
+ if (isset($this->options[$key])) {
+ $this->options[$key] = $value;
+ }
+ }
+ }
+
+ // }}}
+ // {{{ getDecorator()
+
+ /**
+ * Return an instance of a decorator
+ *
+ * This method is used to get a decorator instance.
+ * A decorator can be seen as a filter, i.e. something that can change
+ * or handle the values of the objects/vars that pass through.
+ *
+ * @param string $decorator Name of the decorator
+ *
+ * @return object Decorator object reference
+ */
+ function & getDecorator($decorator)
+ {
+ $decorator_path = 'Translation2/Decorator/'.$decorator.'.php';
+ $decorator_class = 'Translation2_Decorator_'.$decorator;
+ include_once $decorator_path;
+ if (func_num_args() > 1) {
+ $obj = func_get_arg(1);
+ $new_decorator = new $decorator_class($obj);
+ } else {
+ $new_decorator = new $decorator_class($this);
+ }
+ return $new_decorator;
+ }
+
+ // }}}
+ // {{{ setCharset()
+
+ /**
+ * Set charset used to read/store the translations
+ *
+ * @param string $charset character set (encoding)
+ *
+ * @return void|PEAR_Error
+ */
+ function setCharset($charset)
+ {
+ $res = $this->storage->setCharset($charset);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+
+ // }}}
+ // {{{ setLang()
+
+ /**
+ * Set default lang
+ *
+ * Set the language that shall be used when retrieving strings.
+ *
+ * @param string $langID language code (for instance, 'en' or 'it')
+ *
+ * @return true|PEAR_Error
+ */
+ function setLang($langID)
+ {
+ $res = $this->storage->setLang($langID);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ $this->lang = $res;
+ return true;
+ }
+
+ // }}}
+ // {{{ setPageID($pageID)
+
+ /**
+ * Set default page
+ *
+ * Set the page (aka "group of strings") that shall be used when retrieving strings.
+ * If you set it, you don't have to state it in each get() call.
+ *
+ * @param string $pageID ID of the default page
+ *
+ * @return self
+ */
+ function setPageID($pageID = null)
+ {
+ $this->currentPageID = $pageID;
+ return $this;
+ }
+
+ // }}}
+ // {{{ getLang()
+
+ /**
+ * get lang info
+ *
+ * Get some extra information about the language (its full name,
+ * the localized error text, ...)
+ *
+ * @param string $langID language ID
+ * @param string $format ['name', 'meta', 'error_text', 'array']
+ *
+ * @return mixed [string | array], depending on $format
+ */
+ function getLang($langID = null, $format = 'name')
+ {
+ if (is_null($langID)) {
+ if (!isset($this->lang['id'])) {
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+ $langID = $this->lang['id'];
+ }
+ $lang = $this->storage->getLangData($langID);
+ if ($format == 'array') {
+ return $lang;
+ } elseif (isset($lang[$format])) {
+ return $lang[$format];
+ } elseif (isset($lang['name'])) {
+ return $lang['name'];
+ }
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+
+ // }}}
+ // {{{ getLangs()
+
+ /**
+ * get langs
+ *
+ * Get some extra information about the languages (their full names,
+ * the localized error text, their codes, ...)
+ *
+ * @param string $format ['ids', 'names', 'array']
+ *
+ * @return array|PEAR_Error
+ */
+ function getLangs($format = 'name')
+ {
+ return $this->storage->getLangs($format);
+ }
+
+ // }}}
+ // {{{ setParams()
+
+ /**
+ * Set parameters for next string
+ *
+ * Set the replacement for the parameters in the string(s).
+ * Parameter delimiters are customizable.
+ *
+ * @param array $params array of replacement parameters
+ *
+ * @return self
+ */
+ function setParams($params = null)
+ {
+ if (empty($params)) {
+ $this->params = array();
+ } elseif (is_array($params)) {
+ $this->params = $params;
+ } else {
+ $this->params = array($params);
+ }
+ return $this;
+ }
+
+ // }}}
+ // {{{ _replaceParams()
+
+ /**
+ * Replace parameters in strings
+ *
+ * @param mixed $strings strings where the replacements must occur
+ *
+ * @return mixed
+ * @access protected
+ */
+ function _replaceParams($strings)
+ {
+ if (empty($strings) || is_object($strings) || !count($this->params)) {
+ return $strings;
+ }
+ if (is_array($strings)) {
+ foreach ($strings as $key => $string) {
+ $strings[$key] = $this->_replaceParams($string);
+ }
+ } else {
+ if (strpos($strings, $this->options['ParameterPrefix']) !== false) {
+ foreach ($this->params as $name => $value) {
+ $strings = str_replace($this->options['ParameterPrefix']
+ . $name . $this->options['ParameterPostfix'],
+ $value,
+ $strings);
+ }
+ if ($this->options['ParameterAutoFree']) {
+ $this->params = array();
+ }
+ }
+ }
+ return $strings;
+ }
+
+ // }}}
+ // {{{ replaceEmptyStringsWithKeys()
+
+ /**
+ * Replace empty strings with their stringID
+ *
+ * @param array $strings array of strings to be replaced if empty
+ *
+ * @return array
+ * @static
+ */
+ function replaceEmptyStringsWithKeys($strings)
+ {
+ if (!is_array($strings)) {
+ return $strings;
+ }
+ foreach ($strings as $key => $string) {
+ if (empty($string)) {
+ $strings[$key] = $key;
+ }
+ }
+ return $strings;
+ }
+
+ // }}}
+ // {{{ getRaw()
+
+ /**
+ * Get translated string (as-is)
+ *
+ * @param string $stringID ID of the string to be translated
+ * @param string $pageID ID of the page/group containing the string
+ * @param string $langID ID of the language
+ * @param string $defaultText Text to display when the string is empty
+ *
+ * @return string|PEAR_Error
+ */
+ function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);
+ $str = $this->storage->getOne($stringID, $pageID, $langID);
+ if (empty($str)) {
+ $str = $defaultText;
+ }
+ return $str;
+ }
+
+ // }}}
+ // {{{ get()
+
+ /**
+ * Get translated string
+ *
+ * First check if the string is cached, if not => fetch the page
+ * from the container and cache it for later use.
+ * If the string is empty, check the fallback language; if
+ * the latter is empty too, then return the $defaultText.
+ *
+ * @param string $stringID ID of the string
+ * @param string $pageID ID of the page/group containing the string
+ * @param string $langID ID of the language
+ * @param string $defaultText Text to display when the string is empty
+ * NB: This parameter is only used in the DefaultText decorator
+ *
+ * @return string
+ */
+ function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ $str = $this->getRaw($stringID, $pageID, $langID);
+ if (PEAR::isError($str)) {
+ return $str;
+ }
+ return $this->_replaceParams($str);
+ }
+
+ // }}}
+ // {{{ getRawPage()
+
+ /**
+ * Get the array of strings in a page
+ *
+ * Fetch the page (aka "group of strings) from the container,
+ * without applying any formatting and without replacing the parameters
+ *
+ * @param string $pageID ID of the page/group containing the string
+ * @param string $langID ID of the language
+ *
+ * @return array
+ */
+ function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);
+ return $this->storage->getPage($pageID, $langID);
+ }
+
+ // }}}
+ // {{{ getPage()
+
+ /**
+ * Get an entire group of strings
+ *
+ * Same as getRawPage, but resort to fallback language and
+ * replace parameters when needed
+ *
+ * @param string $pageID ID of the page/group containing the string
+ * @param string $langID ID of the language
+ *
+ * @return array
+ */
+ function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ $pageData = $this->getRawPage($pageID, $langID);
+ return $this->_replaceParams($pageData);
+ }
+
+ // }}}
+ // {{{ getStringID()
+
+ /**
+ * Get the stringID for the given string. This method is the reverse of get().
+ *
+ * @param string $string This is NOT the stringID, this is a real string.
+ * The method will search for its matching stringID, and then
+ * it will return the associate string in the selected language.
+ * @param string $pageID ID of the page/group containing the string
+ *
+ * @return string
+ */
+ function getStringID($string, $pageID = TRANSLATION2_DEFAULT_PAGEID)
+ {
+ $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->currentPageID : $pageID);
+ return $this->storage->getStringID($string, $pageID);
+ }
+
+ // }}}
+ // {{{ __clone()
+
+ /**
+ * Clone internal object references
+ *
+ * This method is called automatically by PHP5
+ *
+ * @return void
+ * @access protected
+ */
+ function __clone()
+ {
+ $this->storage = clone($this->storage);
+ }
+
+ // }}}
+}
?>
\ No newline at end of file
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2005 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: Admin.php,v 1.25 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: Admin.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 2004-2007 Alan Knowles
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: dataobjectsimple.php,v 1.11 2007/11/10 00:02:50 quipo Exp $
+ * @version CVS: $Id: dataobjectsimple.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Ian Eure <ieure@php.net>
* @copyright 2004-2007 Lorenzo Alberton, Ian Eure
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: db.php,v 1.40 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: db.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Michael Wallner <mike@php.net>
* @copyright 2004-2007 Lorenzo Alberton, Michael Wallner
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: gettext.php,v 1.30 2007/11/10 00:02:50 quipo Exp $
+ * @version CVS: $Id: gettext.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Michael Wallner <mike@php.net>
* @copyright 2004-2007 Lorenzo Alberton, Michael Wallner
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: gettext.php,v 1.30 2007/11/10 00:02:50 quipo Exp $
+ * @version CVS: $Id: gettext.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Admin_Container_gettext extends Translation2_Container_gettext
*/
function _add(&$bulk)
{
- include_once 'File/Gettext.php';
+ include_once 'File/Gettext.php';
$gtFile = &File_Gettext::factory($this->options['file_type']);
$langs = $this->getLangs('array');
- foreach ((array) $bulk as $pageID => $languages) {
+
+ foreach ((array) $bulk as $pageID => $languages) {
//create the new domain on demand
if (!isset($this->_domains[$pageID])) {
if (PEAR::isError($e = $this->_addDomain($pageID))) {
* @author Ian Eure <ieure@php.net>
* @copyright 2004-2007 Lorenzo Alberton, Ian Eure
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb.php,v 1.38 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb2.php,v 1.41 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb2.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
),
);
++$this->_queries;
- $res = $this->db->manager->createTable($langData['table_name'], $table_definition);
+ $table_options = array(
+ 'charset' => $charset,
+ 'collate' => $collation,
+ );
+ $res = $this->db->manager->createTable($langData['table_name'], $table_definition, $table_options);
if (PEAR::isError($res)) {
return $res;
}
* @author Olivier Guilyardi <olivier@samalyse.com>
* @copyright 2004-2007 Lorenzo Alberton, Olivier Guilyardi
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: xml.php,v 1.18 2007/11/10 00:02:50 quipo Exp $
+ * @version CVS: $Id: xml.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: Decorator.php,v 1.12 2007/11/10 00:02:50 quipo Exp $
+ * @version CVS: $Id: Decorator.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Ian Eure <ieure@php.net>
* @copyright 2004-2007 Lorenzo Alberton, Ian Eure
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: Autoadd.php,v 1.11 2007/10/28 23:14:49 quipo Exp $
+ * @version CVS: $Id: Autoadd.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Contains the Translation2_Container base class\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2005 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: Container.php,v 1.26 2008/08/31 13:58:30 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-\r
-/**\r
- * Base class for Translation2 drivers/containers\r
- *\r
- * Extend this class to provide custom containers.\r
- * Some containers are already bundled with the package.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2005 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-class Translation2_Container\r
-{\r
- // {{{ Class vars\r
-\r
- /**\r
- * Additional options for the storage container\r
- * @var array\r
- */\r
- var $options = array();\r
-\r
- /**\r
- * @var array\r
- * @access private\r
- */\r
- var $currentLang = array();\r
-\r
- /**\r
- * @var array\r
- * @access private\r
- */\r
- var $langs = array();\r
-\r
- // }}}\r
- // {{{ Constructor\r
-\r
- /**\r
- * Constructor\r
- * Has to be overwritten by each storage class\r
- *\r
- * @access public\r
- */\r
- function Translation2_Container()\r
- {\r
- }\r
-\r
- // }}}\r
- // {{{ _parseOptions()\r
-\r
- /**\r
- * Parse options passed to the container class\r
- *\r
- * @param array $array options\r
- *\r
- * @return void\r
- * @access protected\r
- */\r
- function _parseOptions($array)\r
- {\r
- if (!is_array($array)) {\r
- return;\r
- }\r
- foreach ($array as $key => $value) {\r
- if (isset($this->options[$key])) {\r
- $this->options[$key] = $value;\r
- }\r
- }\r
- }\r
-\r
- // }}}\r
- // {{{ _getLangID()\r
-\r
- /**\r
- * Get a valid langID or raise an error when no valid language is set\r
- *\r
- * @param string $langID language ID\r
- *\r
- * @return string language ID or PEAR_Error on error\r
- * @access private\r
- */\r
- function _getLangID($langID)\r
- {\r
- if (!empty($langID) || (0 === $langID)) {\r
- return $langID;\r
- }\r
- if (!empty($this->currentLang['id']) || (isset($this->currentLang['id']) && 0 === $this->currentLang['id'])) {\r
- return $this->currentLang['id'];\r
- }\r
- $msg = 'No valid language set. Use Translation2::setLang().';\r
- return $this->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);\r
- }\r
-\r
- // }}}\r
- // {{{ setCharset()\r
-\r
- /**\r
- * Set charset used to read/store the translations\r
- *\r
- * @param string $charset character set (encoding)\r
- *\r
- * @return PEAR_Error on error\r
- */\r
- function setCharset($charset)\r
- {\r
- if (method_exists($this->storage, 'setCharset')) {\r
- return $this->storage->setCharset($charset);\r
- }\r
- return $this->raiseError(TRANSLATION2_ERROR_UNSUPPORTED, null, null,\r
- 'method not implemented', __FUNCTION__);\r
- }\r
-\r
- // }}}\r
- // {{{ setLang()\r
-\r
- /**\r
- * Sets the current language\r
- *\r
- * @param string $langID language ID\r
- *\r
- * @return array|PEAR_Error language information\r
- */\r
- function setLang($langID)\r
- {\r
- $res = $this->getLangs(); //load available languages, if not loaded yet\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- if (!array_key_exists($langID, $this->langs)) {\r
- return $this->raiseError('unknown language: "'.$langID.'"',\r
- TRANSLATION2_ERROR_UNKNOWN_LANG,\r
- PEAR_ERROR_RETURN,\r
- E_USER_WARNING);\r
- }\r
- $this->currentLang = $this->langs[$langID];\r
- return $this->langs[$langID];\r
- }\r
-\r
- // }}}\r
- // {{{ getLang()\r
-\r
- /**\r
- * Gets the current lang\r
- *\r
- * @param string $format what must be returned\r
- *\r
- * @return mixed array with current lang data or null if not set yet\r
- */\r
- function getLang($format = 'id')\r
- {\r
- return isset($this->currentLang['id']) ? $this->currentLang : null;\r
- }\r
-\r
- // }}}\r
- // {{{ getLangData()\r
-\r
- /**\r
- * Gets the array data for the lang\r
- *\r
- * @param string $langID language ID\r
- * @param string $format what must be returned\r
- *\r
- * @return mixed array with lang data or null if not available\r
- */\r
- function getLangData($langID, $format = 'id')\r
- {\r
- $langs = $this->getLangs('array');\r
- return isset($langs[$langID]) ? $langs[$langID] : null;\r
- }\r
-\r
- // }}}\r
- // {{{ getLangs()\r
-\r
- /**\r
- * Gets the available languages\r
- *\r
- * @param string $format ['array' | 'ids' | 'names' | 'encodings']\r
- *\r
- * @return array|PEAR_Error\r
- */\r
- function getLangs($format = 'array')\r
- {\r
- //if not cached yet, fetch langs data from the container\r
- if (empty($this->langs) || !count($this->langs)) {\r
- $res = $this->fetchLangs(); //container-specific method\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- }\r
-\r
- $tmp = array();\r
- switch ($format) {\r
- case 'array':\r
- foreach ($this->langs as $aLang) {\r
- $aLang['lang_id'] = $aLang['id'];\r
- $tmp[$aLang['id']] = $aLang;\r
- }\r
- break;\r
- case 'id':\r
- case 'ids':\r
- foreach ($this->langs as $aLang) {\r
- $tmp[] = $aLang['id'];\r
- }\r
- break;\r
- case 'encoding':\r
- case 'encodings':\r
- foreach ($this->langs as $aLang) {\r
- $tmp[] = $aLang['encoding'];\r
- }\r
- break;\r
- case 'name':\r
- case 'names':\r
- default:\r
- foreach ($this->langs as $aLang) {\r
- $tmp[$aLang['id']] = $aLang['name'];\r
- }\r
- }\r
- return $tmp;\r
- }\r
-\r
- // }}}\r
- // {{{ fetchLangs()\r
-\r
- /**\r
- * Fetch the available langs if they're not cached yet.\r
- * Containers should implement this method.\r
- *\r
- * @return PEAR_Error on error\r
- */\r
- function fetchLangs()\r
- {\r
- return $this->raiseError('method "fetchLangs" not supported',\r
- TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);\r
- }\r
-\r
- // }}}\r
- // {{{ getPage()\r
-\r
- /**\r
- * Returns an array of the strings in the selected page\r
- * Containers should implement this method.\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getPage($pageID = null, $langID = null)\r
- {\r
- return $this->raiseError('method "getPage" not supported',\r
- TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);\r
- }\r
-\r
- // }}}\r
- // {{{ getOne()\r
-\r
- /**\r
- * Get a single item from the container, without caching the whole page\r
- * Containers should implement this method.\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return string\r
- */\r
- function getOne($stringID, $pageID = null, $langID = null)\r
- {\r
- return $this->raiseError('method "getOne" not supported',\r
- TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);\r
- }\r
-\r
- // }}}\r
- // {{{ getStringID()\r
-\r
- /**\r
- * Get the stringID for the given string\r
- *\r
- * @param string $string string\r
- * @param string $pageID page/group ID\r
- *\r
- * @return string\r
- */\r
- function getStringID($string, $pageID = null)\r
- {\r
- return $this->raiseError('method "getStringID" not supported',\r
- TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);\r
- }\r
-\r
- // }}}\r
- // {{{ raiseError()\r
-\r
- /**\r
- * Trigger a PEAR error\r
- *\r
- * @param string $msg error message\r
- * @param int $code error code\r
- * @param int $mode PEAR error mode\r
- * @param int $option error severity\r
- *\r
- * @return void|PEAR_Error\r
- * @access public\r
- */\r
- function raiseError($msg, $code, $mode = PEAR_ERROR_TRIGGER, $option = E_USER_WARNING)\r
- {\r
- if (isset($GLOBALS['_PEAR_default_error_mode'])) {\r
- $mode = $GLOBALS['_PEAR_default_error_mode'];\r
- }\r
- if (isset($GLOBALS['_PEAR_default_error_options'])) {\r
- $option = $GLOBALS['_PEAR_default_error_options'];\r
- }\r
- if ($mode == PEAR_ERROR_RETURN) {\r
- return PEAR::raiseError($msg, $code, $mode, $option);\r
- } else {\r
- PEAR::raiseError($msg, $code, $mode, $option);\r
- }\r
- }\r
-\r
- // }}}\r
-}\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contains the Translation2_Container base class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2005 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: Container.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+
+/**
+ * Base class for Translation2 drivers/containers
+ *
+ * Extend this class to provide custom containers.
+ * Some containers are already bundled with the package.
+ *
+ * @category Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2005 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @link http://pear.php.net/package/Translation2
+ */
+class Translation2_Container
+{
+ // {{{ Class vars
+
+ /**
+ * Additional options for the storage container
+ * @var array
+ */
+ var $options = array();
+
+ /**
+ * @var array
+ * @access private
+ */
+ var $currentLang = array();
+
+ /**
+ * @var array
+ * @access private
+ */
+ var $langs = array();
+
+ // }}}
+ // {{{ Constructor
+
+ /**
+ * Constructor
+ * Has to be overwritten by each storage class
+ *
+ * @access public
+ */
+ function Translation2_Container()
+ {
+ }
+
+ // }}}
+ // {{{ _parseOptions()
+
+ /**
+ * Parse options passed to the container class
+ *
+ * @param array $array options
+ *
+ * @return void
+ * @access protected
+ */
+ function _parseOptions($array)
+ {
+ if (!is_array($array)) {
+ return;
+ }
+ foreach ($array as $key => $value) {
+ if (isset($this->options[$key])) {
+ $this->options[$key] = $value;
+ }
+ }
+ }
+
+ // }}}
+ // {{{ _getLangID()
+
+ /**
+ * Get a valid langID or raise an error when no valid language is set
+ *
+ * @param string $langID language ID
+ *
+ * @return string language ID or PEAR_Error on error
+ * @access private
+ */
+ function _getLangID($langID)
+ {
+ if (!empty($langID) || (0 === $langID)) {
+ return $langID;
+ }
+ if (!empty($this->currentLang['id']) || (0 === $this->currentLang['id'])) {
+ return $this->currentLang['id'];
+ }
+ $msg = 'No valid language set. Use Translation2::setLang().';
+ return $this->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+
+ // }}}
+ // {{{ setCharset()
+
+ /**
+ * Set charset used to read/store the translations
+ *
+ * @param string $charset character set (encoding)
+ *
+ * @return PEAR_Error on error
+ */
+ function setCharset($charset)
+ {
+ if (method_exists($this->storage, 'setCharset')) {
+ return $this->storage->setCharset($charset);
+ }
+ return $this->raiseError(TRANSLATION2_ERROR_UNSUPPORTED, null, null,
+ 'method not implemented', __FUNCTION__);
+ }
+
+ // }}}
+ // {{{ setLang()
+
+ /**
+ * Sets the current language
+ *
+ * @param string $langID language ID
+ *
+ * @return array|PEAR_Error language information
+ */
+ function setLang($langID)
+ {
+ $res = $this->getLangs(); //load available languages, if not loaded yet
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ if (!array_key_exists($langID, $this->langs)) {
+ return $this->raiseError('unknown language: "'.$langID.'"',
+ TRANSLATION2_ERROR_UNKNOWN_LANG,
+ PEAR_ERROR_RETURN,
+ E_USER_WARNING);
+ }
+ $this->currentLang = $this->langs[$langID];
+ return $this->langs[$langID];
+ }
+
+ // }}}
+ // {{{ getLang()
+
+ /**
+ * Gets the current lang
+ *
+ * @param string $format what must be returned
+ *
+ * @return mixed array with current lang data or null if not set yet
+ */
+ function getLang($format = 'id')
+ {
+ return isset($this->currentLang['id']) ? $this->currentLang : null;
+ }
+
+ // }}}
+ // {{{ getLangData()
+
+ /**
+ * Gets the array data for the lang
+ *
+ * @param string $langID language ID
+ * @param string $format what must be returned
+ *
+ * @return mixed array with lang data or null if not available
+ */
+ function getLangData($langID, $format = 'id')
+ {
+ $langs = $this->getLangs('array');
+ return isset($langs[$langID]) ? $langs[$langID] : null;
+ }
+
+ // }}}
+ // {{{ getLangs()
+
+ /**
+ * Gets the available languages
+ *
+ * @param string $format ['array' | 'ids' | 'names' | 'encodings']
+ *
+ * @return array|PEAR_Error
+ */
+ function getLangs($format = 'array')
+ {
+ //if not cached yet, fetch langs data from the container
+ if (empty($this->langs) || !count($this->langs)) {
+ $res = $this->fetchLangs(); //container-specific method
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
+
+ $tmp = array();
+ switch ($format) {
+ case 'array':
+ foreach ($this->langs as $aLang) {
+ $aLang['lang_id'] = $aLang['id'];
+ $tmp[$aLang['id']] = $aLang;
+ }
+ break;
+ case 'id':
+ case 'ids':
+ foreach ($this->langs as $aLang) {
+ $tmp[] = $aLang['id'];
+ }
+ break;
+ case 'encoding':
+ case 'encodings':
+ foreach ($this->langs as $aLang) {
+ $tmp[] = $aLang['encoding'];
+ }
+ break;
+ case 'name':
+ case 'names':
+ default:
+ foreach ($this->langs as $aLang) {
+ $tmp[$aLang['id']] = $aLang['name'];
+ }
+ }
+ return $tmp;
+ }
+
+ // }}}
+ // {{{ fetchLangs()
+
+ /**
+ * Fetch the available langs if they're not cached yet.
+ * Containers should implement this method.
+ *
+ * @return PEAR_Error on error
+ */
+ function fetchLangs()
+ {
+ return $this->raiseError('method "fetchLangs" not supported',
+ TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);
+ }
+
+ // }}}
+ // {{{ getPage()
+
+ /**
+ * Returns an array of the strings in the selected page
+ * Containers should implement this method.
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getPage($pageID = null, $langID = null)
+ {
+ return $this->raiseError('method "getPage" not supported',
+ TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);
+ }
+
+ // }}}
+ // {{{ getOne()
+
+ /**
+ * Get a single item from the container, without caching the whole page
+ * Containers should implement this method.
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return string
+ */
+ function getOne($stringID, $pageID = null, $langID = null)
+ {
+ return $this->raiseError('method "getOne" not supported',
+ TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);
+ }
+
+ // }}}
+ // {{{ getStringID()
+
+ /**
+ * Get the stringID for the given string
+ *
+ * @param string $string string
+ * @param string $pageID page/group ID
+ *
+ * @return string
+ */
+ function getStringID($string, $pageID = null)
+ {
+ return $this->raiseError('method "getStringID" not supported',
+ TRANSLATION_ERROR_METHOD_NOT_SUPPORTED);
+ }
+
+ // }}}
+ // {{{ raiseError()
+
+ /**
+ * Trigger a PEAR error
+ *
+ * @param string $msg error message
+ * @param int $code error code
+ * @param int $mode PEAR error mode
+ * @param int $option error severity
+ *
+ * @return void|PEAR_Error
+ * @access public
+ */
+ function raiseError($msg, $code, $mode = PEAR_ERROR_TRIGGER, $option = E_USER_WARNING)
+ {
+ if (isset($GLOBALS['_PEAR_default_error_mode'])) {
+ $mode = $GLOBALS['_PEAR_default_error_mode'];
+ }
+ if (isset($GLOBALS['_PEAR_default_error_options'])) {
+ $option = $GLOBALS['_PEAR_default_error_options'];
+ }
+ if ($mode == PEAR_ERROR_RETURN) {
+ return PEAR::raiseError($msg, $code, $mode, $option);
+ } else {
+ PEAR::raiseError($msg, $code, $mode, $option);
+ }
+ }
+
+ // }}}
+}
?>
\ No newline at end of file
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 2004-2008 Alan Knowles
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: dataobjectsimple.php,v 1.18 2008/05/18 17:56:54 quipo Exp $
+ * @version CVS: $Id: dataobjectsimple.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 2004-2008 Alan Knowles
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: dataobjectsimple.php,v 1.18 2008/05/18 17:56:54 quipo Exp $
+ * @version CVS: $Id: dataobjectsimple.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Container_dataobjectsimple extends Translation2_Container
* @author Ian Eure <ieure@php.net>
* @copyright 2004-2008 Lorenzo Alberton, Ian Eure
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: db.php,v 1.39 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: db.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Ian Eure <ieure@php.net>
* @copyright 2004-2008 Lorenzo Alberton, Ian Eure
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: db.php,v 1.39 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: db.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Container_db extends Translation2_Container
* @author Michael Wallner <mike@php.net>
* @copyright 2004-2008 Lorenzo Alberton, Michael Wallner
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: gettext.php,v 1.32 2008/02/02 18:05:06 quipo Exp $
+ * @version CVS: $Id: gettext.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Michael Wallner <mike@php.net>
* @copyright 2004-2008 Lorenzo Alberton, Michael Wallner
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: gettext.php,v 1.32 2008/02/02 18:05:06 quipo Exp $
+ * @version CVS: $Id: gettext.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
* @see /docs/gettext_readme.txt for an usage example
*/
function _switchLang($langID)
{
$langID = $this->_getLangID($langID);
- $oldLang = isset($this->currentLang['id']) ? $this->currentLang['id'] : 'en';
+ $oldLang = $this->currentLang['id'];
$this->setLang($langID);
return $oldLang;
}
*/
function fetchLangs()
{
- $this->langs = parse_ini_file($this->options['langs_avail_file'], true);
-
+ $this->langs = @parse_ini_file($this->options['langs_avail_file'], true);
foreach ((array) $this->langs as $id => $lang) {
$this->langs[$id]['id'] = $id;
}
-
}
// }}}
function getPage($pageID = null, $langID = null)
{
$oldLang = $this->_switchLang($langID);
- $curLang = isset($this->currentLang['id']) ? $this->currentLang['id'] : 'en';
+ $curLang = $this->currentLang['id'];
if (empty($pageID) || $pageID == TRANSLATION2_DEFAULT_PAGEID) {
$pageID = $this->options['default_domain'];
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2008 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb.php,v 1.30 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2008 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb.php,v 1.30 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Container_mdb extends Translation2_Container
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2008 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb2.php,v 1.30 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb2.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2008 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: mdb2.php,v 1.30 2008/05/03 09:17:59 quipo Exp $
+ * @version CVS: $Id: mdb2.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Container_mdb2 extends Translation2_Container
* @author Olivier Guilyardi <olivier@samalyse.com>
* @copyright 2004-2008 Lorenzo Alberton, Olivier Guilyardi
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: xml.php,v 1.17 2008/02/02 18:05:06 quipo Exp $
+ * @version CVS: $Id: xml.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Contains the Translation2_Decorator base class\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2005 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: Decorator.php,v 1.25 2008/11/14 16:18:50 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-\r
-/**\r
- * Translation2_Decorator. Base Decorator class for Translation2\r
- *\r
- * Extend this class to provide custom decorators.\r
- * Some decorators are already bundled with the package.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2005 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @link http://pear.php.net/package/Translation2\r
- * @abstract\r
- */\r
-class Translation2_Decorator extends Translation2\r
-{\r
- // {{{ class vars\r
-\r
- /**\r
- * Translation2 object being decorated\r
- * @var object\r
- * @access protected\r
- */\r
- var $translation2;\r
-\r
- /**\r
- * @var object\r
- * @access protected\r
- */\r
- var $storage;\r
-\r
- /**\r
- * @var array\r
- * @access protected\r
- */\r
- var $lang;\r
-\r
- /**\r
- * @var string\r
- * @access protected\r
- */\r
- var $currentPageID;\r
-\r
- // }}}\r
- // {{{ Constructor\r
-\r
- /**\r
- * Constructor\r
- * Constructs the Translation2_Decorator\r
- *\r
- * @param object &$translation2 Translation2 object to decorate\r
- */\r
- function Translation2_Decorator(& $translation2)\r
- {\r
- $this->translation2 = & $translation2;\r
- //used for debug only\r
- $this->storage = & $translation2->storage;\r
- $this->currentPageID = & $translation2->currentPageID;\r
- $this->lang = & $translation2->lang;\r
- }\r
-\r
- // }}}\r
- // {{{ setOptions()\r
-\r
- /**\r
- * set Decorator options\r
- *\r
- * @param array $options decorator options\r
- *\r
- * @return self\r
- */\r
- function setOptions($options=array())\r
- {\r
- if (is_array($options)) {\r
- foreach ($options as $option => $value) {\r
- $this->setOption($option, $value);\r
- }\r
- }\r
- return $this;\r
- }\r
-\r
- // }}}\r
- // {{{ setOption()\r
-\r
- /**\r
- * set Decorator option\r
- *\r
- * @param string $option option name\r
- * @param mixed $value option value\r
- *\r
- * @return self\r
- */\r
- function setOption($option, $value=null)\r
- {\r
- if (isset($this->$option)) {\r
- $this->$option = $value;\r
- } elseif (is_a($this->translation2, 'Translation2_Decorator')) {\r
- $this->translation2->setOption($option, $value);\r
- }\r
- return $this;\r
- }\r
-\r
- // }}}\r
- // {{{ setContainerOptions()\r
-\r
- /**\r
- * Set some storage driver options\r
- *\r
- * @param array $options storage driver options\r
- *\r
- * @return void\r
- * @access protected\r
- */\r
- function setContainerOptions($options)\r
- {\r
- $this->storage->_parseOptions($options);\r
- }\r
-\r
- // }}}\r
- // {{{ getDecorator()\r
-\r
- /**\r
- * Return an instance of a decorator\r
- *\r
- * @param string $decorator Name of the decorator\r
- * @param object $object instance [optional]\r
- *\r
- * @return object Decorator object reference\r
- * @access public\r
- */\r
- function & getDecorator($decorator)\r
- {\r
- if (func_num_args() > 1) {\r
- $obj = func_get_arg(1);\r
- $new_decorator =& $this->translation2->getDecorator($decorator, $obj);\r
- } else {\r
- $new_decorator =& $this->translation2->getDecorator($decorator, $this);\r
- }\r
- return $new_decorator;\r
- }\r
-\r
- // }}}\r
- // {{{ setCharset()\r
-\r
- /**\r
- * Set charset used to read/store the translations\r
- *\r
- * @param string $charset character set (encoding)\r
- *\r
- * @return PEAR_Error on failure\r
- */\r
- function setCharset($charset)\r
- {\r
- return $this->translation2->setCharset($charset);\r
- }\r
-\r
- // }}}\r
- // {{{ setLang()\r
-\r
- /**\r
- * Set default language\r
- *\r
- * @param string $langID language ID\r
- *\r
- * @return true|PEAR_Error\r
- */\r
- function setLang($langID)\r
- {\r
- return $this->translation2->setLang($langID);\r
- }\r
-\r
- // }}}\r
- // {{{ setPageID($pageID)\r
-\r
- /**\r
- * Set default page\r
- *\r
- * @param string $pageID page/group ID\r
- *\r
- * @return void\r
- */\r
- function setPageID($pageID = null)\r
- {\r
- $this->translation2->setPageID($pageID);\r
- }\r
-\r
- // }}}\r
- // {{{ getLang()\r
-\r
- /**\r
- * Get language info\r
- *\r
- * @param string $langID language ID\r
- * @param string $format ['name', 'meta', 'error_text', 'array']\r
- *\r
- * @return mixed [string | array], depending on $format\r
- */\r
- function getLang($langID=null, $format='name')\r
- {\r
- return $this->translation2->getLang($langID, $format);\r
- }\r
-\r
- // }}}\r
- // {{{ getLangs()\r
-\r
- /**\r
- * Get languages\r
- *\r
- * @param string $format ['ids', 'names', 'array']\r
- *\r
- * @return array\r
- */\r
- function getLangs($format='name')\r
- {\r
- return $this->translation2->getLangs($format);\r
- }\r
-\r
- // }}}\r
- // {{{ setParams()\r
-\r
- /**\r
- * Set parameters for next string\r
- *\r
- * @param array $params array of replacement parameters\r
- *\r
- * @return void\r
- */\r
- function setParams($params = null)\r
- {\r
- $this->translation2->setParams($params);\r
- }\r
-\r
- // }}}\r
- // {{{ getRaw()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * No filter is applied.\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- * @param string $defaultText Text to display when the strings in both\r
- * the default and the fallback lang are empty\r
- *\r
- * @return string\r
- */\r
- function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- return $this->translation2->getRaw($stringID, $pageID, $langID, $defaultText);\r
- }\r
-\r
- // }}}\r
- // {{{ get()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * All the filters are applied.\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- * @param string $defaultText Text to display when the string is empty\r
- * NB: This parameter is only used in the DefaultText decorator\r
- *\r
- * @return string\r
- */\r
- function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- return $this->translation2->get($stringID, $pageID, $langID, $defaultText);\r
- }\r
-\r
- // }}}\r
- // {{{ getRawPage()\r
-\r
- /**\r
- * Get the array of strings in a page\r
- *\r
- * Fetch the strings from the container, without any replacing\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- return $this->translation2->getRawPage($pageID, $langID);\r
- }\r
-\r
- // }}}\r
- // {{{ getPage()\r
-\r
- /**\r
- * Same as getRawPage, but resort to fallback language and\r
- * replace parameters when needed\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- $this->translation2->getPage($pageID, $langID);\r
- }\r
-\r
- // }}}\r
- // {{{ _replaceParams()\r
-\r
- /**\r
- * Replace parameters in strings\r
- *\r
- * @param mixed $strings strings where the replacements must occur\r
- *\r
- * @return mixed\r
- * @access protected\r
- */\r
- function _replaceParams($strings)\r
- {\r
- return $this->translation2->_replaceParams($strings);\r
- }\r
-\r
- // }}}\r
- // {{{ replaceEmptyStringsWithKeys()\r
-\r
- /**\r
- * Replace empty strings with their stringID\r
- *\r
- * @param array $strings array of strings to be replaced if empty\r
- *\r
- * @return array\r
- * @access public\r
- */\r
- function replaceEmptyStringsWithKeys($strings)\r
- {\r
- return $this->translation2->replaceEmptyStringsWithKeys($strings);\r
- }\r
-\r
- // }}}\r
- // {{{ getStringID()\r
-\r
- /**\r
- * Get the stringID for the given string. This method is the reverse of get().\r
- *\r
- * @param string $string This is NOT the stringID, this is a real string.\r
- * The method will search for its matching stringID, and then\r
- * it will return the associate string in the selected language.\r
- * @param string $pageID page/group ID\r
- *\r
- * @return string\r
- */\r
- function getStringID($string, $pageID = TRANSLATION2_DEFAULT_PAGEID)\r
- {\r
- return $this->translation2->getStringID($string, $pageID);\r
- }\r
-\r
- // }}}\r
- // {{{ __clone()\r
-\r
- /**\r
- * Clone internal object references\r
- *\r
- * This method is called automatically by PHP5\r
- *\r
- * @return void\r
- * @access protected\r
- */\r
- function __clone()\r
- {\r
- $this->translation2 = clone($this->translation2);\r
- }\r
-\r
- // }}}\r
-}\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contains the Translation2_Decorator base class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2005 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: Decorator.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+
+/**
+ * Translation2_Decorator. Base Decorator class for Translation2
+ *
+ * Extend this class to provide custom decorators.
+ * Some decorators are already bundled with the package.
+ *
+ * @category Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2005 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @link http://pear.php.net/package/Translation2
+ * @abstract
+ */
+class Translation2_Decorator extends Translation2
+{
+ // {{{ class vars
+
+ /**
+ * Translation2 object being decorated
+ * @var object
+ * @access protected
+ */
+ var $translation2;
+
+ /**
+ * @var object
+ * @access protected
+ */
+ var $storage;
+
+ /**
+ * @var array
+ * @access protected
+ */
+ var $lang;
+
+ /**
+ * @var string
+ * @access protected
+ */
+ var $currentPageID;
+
+ // }}}
+ // {{{ Constructor
+
+ /**
+ * Constructor
+ * Constructs the Translation2_Decorator
+ *
+ * @param object &$translation2 Translation2 object to decorate
+ */
+ function Translation2_Decorator(& $translation2)
+ {
+ $this->translation2 = & $translation2;
+ //used for debug only
+ $this->storage = & $translation2->storage;
+ $this->currentPageID = & $translation2->currentPageID;
+ $this->lang = & $translation2->lang;
+ }
+
+ // }}}
+ // {{{ setOptions()
+
+ /**
+ * set Decorator options
+ *
+ * @param array $options decorator options
+ *
+ * @return self
+ */
+ function setOptions($options=array())
+ {
+ if (is_array($options)) {
+ foreach ($options as $option => $value) {
+ $this->setOption($option, $value);
+ }
+ }
+ return $this;
+ }
+
+ // }}}
+ // {{{ setOption()
+
+ /**
+ * set Decorator option
+ *
+ * @param string $option option name
+ * @param mixed $value option value
+ *
+ * @return self
+ */
+ function setOption($option, $value=null)
+ {
+ if (isset($this->$option)) {
+ $this->$option = $value;
+ } elseif (is_a($this->translation2, 'Translation2_Decorator')) {
+ $this->translation2->setOption($option, $value);
+ }
+ return $this;
+ }
+
+ // }}}
+ // {{{ setContainerOptions()
+
+ /**
+ * Set some storage driver options
+ *
+ * @param array $options storage driver options
+ *
+ * @return void
+ * @access protected
+ */
+ function setContainerOptions($options)
+ {
+ $this->storage->_parseOptions($options);
+ }
+
+ // }}}
+ // {{{ getDecorator()
+
+ /**
+ * Return an instance of a decorator
+ *
+ * @param string $decorator Name of the decorator
+ * @param object $object instance [optional]
+ *
+ * @return object Decorator object reference
+ * @access public
+ */
+ function & getDecorator($decorator)
+ {
+ if (func_num_args() > 1) {
+ $obj = func_get_arg(1);
+ $new_decorator =& $this->translation2->getDecorator($decorator, $obj);
+ } else {
+ $new_decorator =& $this->translation2->getDecorator($decorator, $this);
+ }
+ return $new_decorator;
+ }
+
+ // }}}
+ // {{{ setCharset()
+
+ /**
+ * Set charset used to read/store the translations
+ *
+ * @param string $charset character set (encoding)
+ *
+ * @return PEAR_Error on failure
+ */
+ function setCharset($charset)
+ {
+ return $this->translation2->setCharset($charset);
+ }
+
+ // }}}
+ // {{{ setLang()
+
+ /**
+ * Set default language
+ *
+ * @param string $langID language ID
+ *
+ * @return true|PEAR_Error
+ */
+ function setLang($langID)
+ {
+ return $this->translation2->setLang($langID);
+ }
+
+ // }}}
+ // {{{ setPageID($pageID)
+
+ /**
+ * Set default page
+ *
+ * @param string $pageID page/group ID
+ *
+ * @return void
+ */
+ function setPageID($pageID = null)
+ {
+ $this->translation2->setPageID($pageID);
+ }
+
+ // }}}
+ // {{{ getLang()
+
+ /**
+ * Get language info
+ *
+ * @param string $langID language ID
+ * @param string $format ['name', 'meta', 'error_text', 'array']
+ *
+ * @return mixed [string | array], depending on $format
+ */
+ function getLang($langID=null, $format='name')
+ {
+ return $this->translation2->getLang($langID, $format);
+ }
+
+ // }}}
+ // {{{ getLangs()
+
+ /**
+ * Get languages
+ *
+ * @param string $format ['ids', 'names', 'array']
+ *
+ * @return array
+ */
+ function getLangs($format='name')
+ {
+ return $this->translation2->getLangs($format);
+ }
+
+ // }}}
+ // {{{ setParams()
+
+ /**
+ * Set parameters for next string
+ *
+ * @param array $params array of replacement parameters
+ *
+ * @return void
+ */
+ function setParams($params = null)
+ {
+ $this->translation2->setParams($params);
+ }
+
+ // }}}
+ // {{{ getRaw()
+
+ /**
+ * Get translated string
+ *
+ * No filter is applied.
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ * @param string $defaultText Text to display when the strings in both
+ * the default and the fallback lang are empty
+ *
+ * @return string
+ */
+ function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ return $this->translation2->getRaw($stringID, $pageID, $langID, $defaultText);
+ }
+
+ // }}}
+ // {{{ get()
+
+ /**
+ * Get translated string
+ *
+ * All the filters are applied.
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ * @param string $defaultText Text to display when the string is empty
+ * NB: This parameter is only used in the DefaultText decorator
+ *
+ * @return string
+ */
+ function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ return $this->translation2->get($stringID, $pageID, $langID, $defaultText);
+ }
+
+ // }}}
+ // {{{ getRawPage()
+
+ /**
+ * Get the array of strings in a page
+ *
+ * Fetch the strings from the container, without any replacing
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ return $this->translation2->getRawPage($pageID, $langID);
+ }
+
+ // }}}
+ // {{{ getPage()
+
+ /**
+ * Same as getRawPage, but resort to fallback language and
+ * replace parameters when needed
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ $this->translation2->getPage($pageID, $langID);
+ }
+
+ // }}}
+ // {{{ _replaceParams()
+
+ /**
+ * Replace parameters in strings
+ *
+ * @param mixed $strings strings where the replacements must occur
+ *
+ * @return mixed
+ * @access protected
+ */
+ function _replaceParams($strings)
+ {
+ return $this->translation2->_replaceParams($strings);
+ }
+
+ // }}}
+ // {{{ replaceEmptyStringsWithKeys()
+
+ /**
+ * Replace empty strings with their stringID
+ *
+ * @param array $strings array of strings to be replaced if empty
+ *
+ * @return array
+ * @access public
+ */
+ function replaceEmptyStringsWithKeys($strings)
+ {
+ return $this->translation2->replaceEmptyStringsWithKeys($strings);
+ }
+
+ // }}}
+ // {{{ getStringID()
+
+ /**
+ * Get the stringID for the given string. This method is the reverse of get().
+ *
+ * @param string $string This is NOT the stringID, this is a real string.
+ * The method will search for its matching stringID, and then
+ * it will return the associate string in the selected language.
+ * @param string $pageID page/group ID
+ *
+ * @return string
+ */
+ function getStringID($string, $pageID = TRANSLATION2_DEFAULT_PAGEID)
+ {
+ return $this->translation2->getStringID($string, $pageID);
+ }
+
+ // }}}
+ // {{{ __clone()
+
+ /**
+ * Clone internal object references
+ *
+ * This method is called automatically by PHP5
+ *
+ * @return void
+ * @access protected
+ */
+ function __clone()
+ {
+ $this->translation2 = clone($this->translation2);
+ }
+
+ // }}}
+}
?>
\ No newline at end of file
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Contains the Translation2_Decorator_CacheLiteFunction class\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2007 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: CacheLiteFunction.php,v 1.23 2008/11/14 16:18:50 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-\r
-/**\r
- * Load Translation2 decorator base class\r
- * and Cache_Lite_Function class\r
- */\r
-require_once 'Translation2/Decorator.php';\r
-require_once 'Cache/Lite/Function.php';\r
-\r
-/**\r
- * Decorator to cache fetched data using the Cache_Lite_Function class.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2007 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: CacheLiteFunction.php,v 1.23 2008/11/14 16:18:50 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-class Translation2_Decorator_CacheLiteFunction extends Translation2_Decorator\r
-{\r
- // {{{ class vars\r
-\r
- /**\r
- * Cache_Lite_Function object\r
- * @var object\r
- */\r
- var $cacheLiteFunction = null;\r
-\r
- /**\r
- * @var int (default 1)\r
- * @access private\r
- */\r
- var $tempVarNameGenerator = 1;\r
-\r
- /**\r
- * @var string\r
- * @access private\r
- */\r
- var $tempVarName = null;\r
-\r
- /**\r
- * Cache lifetime (in seconds)\r
- * @var int $lifeTime\r
- * @access private\r
- */\r
- var $lifeTime = 3600;\r
-\r
- /**\r
- * Directory where to put the cache files\r
- * (make sure to add a trailing slash)\r
- * @var string $cacheDir\r
- * @access private\r
- */\r
- var $cacheDir = '/tmp/';\r
-\r
- /**\r
- * Enable / disable fileLocking. Can avoid cache corruption under bad\r
- * circumstances.\r
- * @var string $cacheDir\r
- * @access private\r
- */\r
- var $fileLocking = true;\r
-\r
- /**\r
- * Enable / disable caching\r
- * (can be very useful to debug cached scripts)\r
- * @var boolean $caching\r
- */\r
- var $caching = true;\r
-\r
- /**\r
- * Frequency of cache cleaning.\r
- * Higher values mean lower cleaning probability.\r
- * Set 0 to disable. Set 1 to clean at every request.\r
- * @var boolean $caching\r
- */\r
- var $cleaningFrequency = 0;\r
-\r
- /**\r
- * Name of default cache group.\r
- * @var string $defaultGroup\r
- */\r
- var $defaultGroup = 'Translation2';\r
-\r
- // }}}\r
- // {{{ _prepare()\r
-\r
- /**\r
- * Istanciate a new Cache_Lite_Function object\r
- * and get the name for an unused global variable,\r
- * needed by Cache_Lite_Function\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function _prepare()\r
- {\r
- if (is_null($this->cacheLiteFunction)) {\r
- $cache_options = array(\r
- 'caching' => $this->caching,\r
- 'cacheDir' => $this->cacheDir,\r
- 'lifeTime' => $this->lifeTime,\r
- 'fileLocking' => $this->fileLocking,\r
- 'defaultGroup' => $this->defaultGroup,\r
-\r
- );\r
- $this->cacheLiteFunction = new Cache_Lite_Function($cache_options);\r
- }\r
-\r
- $this->_cleanCache();\r
- }\r
-\r
- // }}}\r
- // {{{ setLang()\r
-\r
- /**\r
- * Set default lang\r
- *\r
- * Set the language that shall be used when retrieving strings.\r
- *\r
- * @param string $langID language code (for instance, 'en' or 'it')\r
- *\r
- * @return void\r
- */\r
- function setLang($langID)\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_storage_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_storage_cachelitefunction_temp = $this->translation2->storage;\r
-\r
- $this->_prepare();\r
- $res = $this->cacheLiteFunction->call(\r
- 'translation2_storage_cachelitefunction_temp->setLang', $langID);\r
- if (PEAR::isError($res)) {\r
- return $res;\r
- }\r
- $this->translation2->lang = $res;\r
-\r
- }\r
-\r
- // }}}\r
- // {{{ setCacheOption()\r
-\r
- /**\r
- * Set a Cache_Lite option\r
- *\r
- * Passes a Cache_Lite option forward to the Cache_Lite object\r
- * See Cache_Lite constructor for available options\r
- *\r
- * @param string $name name of the option\r
- * @param string $value new value of the option\r
- *\r
- * @return self\r
- * @access public\r
- * @see Cache_Lite::setOption()\r
- */\r
- function setCacheOption($name, $value)\r
- {\r
- $this->_prepare();\r
- $this->cacheLiteFunction->setOption($name, $value);\r
- return $this;\r
- }\r
-\r
- // }}}\r
- // {{{ getLang()\r
-\r
- /**\r
- * get lang info\r
- *\r
- * Get some extra information about the language (its full name,\r
- * the localized error text, ...)\r
- *\r
- * @param string $langID language ID\r
- * @param string $format ['name', 'meta', 'error_text', 'array']\r
- *\r
- * @return mixed [string | array], depending on $format\r
- */\r
- function getLang($langID = null, $format = 'name')\r
- {\r
- $langs = $this->getLangs('array');\r
-\r
- if (is_null($langID)) {\r
- if (!isset($this->lang['id']) || !array_key_exists($this->lang['id'], $langs)) {\r
- $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'\r
- .' Use Translation2::setLang() to set a default language.';\r
- return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);\r
- }\r
- $langID = $this->lang['id'];\r
- }\r
-\r
- if ($format == 'array') {\r
- return $langs[$langID];\r
- } elseif (isset($langs[$langID][$format])) {\r
- return $langs[$langID][$format];\r
- } elseif (isset($langs[$langID]['name'])) {\r
- return $langs[$langID]['name'];\r
- }\r
- $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'\r
- .' Use Translation2::setLang() to set a default language.';\r
- return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);\r
- }\r
-\r
- // }}}\r
- // {{{ getLangs()\r
-\r
- /**\r
- * get langs\r
- *\r
- * Get some extra information about the languages (their full names,\r
- * the localized error text, their codes, ...)\r
- *\r
- * @param string $format ['ids', 'names', 'array']\r
- *\r
- * @return array\r
- */\r
- function getLangs($format = 'name')\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2;\r
-\r
- $this->_prepare();\r
- return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getLangs',\r
- $format);\r
- }\r
-\r
- // }}}\r
- // {{{ getRaw()\r
-\r
- /**\r
- * Get translated string (as-is)\r
- *\r
- * First check if the string is cached, if not => fetch the page\r
- * from the container and cache it for later use.\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- * @param string $defaultText Text to display when the strings in both\r
- * the default and the fallback lang are empty\r
- *\r
- * @return string\r
- */\r
- function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2;\r
-\r
- if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {\r
- $pageID = $this->translation2->currentPageID;\r
- }\r
- $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;\r
-\r
- $this->_prepare();\r
-\r
- return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getRaw',\r
- $stringID, $pageID, $langID, $defaultText);\r
- }\r
-\r
- // }}}\r
- // {{{ get()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * First check if the string is cached, if not => fetch the page\r
- * from the container and cache it for later use.\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- * @param string $defaultText Text to display when the strings in both\r
- * the default and the fallback lang are empty\r
- *\r
- * @return string\r
- */\r
- function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2->storage;\r
-\r
- if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {\r
- $pageID = $this->translation2->currentPageID;\r
- }\r
- $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;\r
-\r
- $this->_prepare();\r
-\r
- $string = $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getOne',\r
- $stringID, $pageID, $langID);\r
- if (empty($string)) {\r
- return $defaultText;\r
- }\r
- return $this->translation2->_replaceParams($string);\r
- }\r
-\r
- // }}}\r
- // {{{ getRawPage()\r
-\r
- /**\r
- * Get the array of strings in a page\r
- *\r
- * First check if the strings are cached, if not => fetch the page\r
- * from the container and cache it for later use.\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2;\r
-\r
- if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {\r
- $pageID = $this->translation2->currentPageID;\r
- }\r
- $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;\r
-\r
- $this->_prepare();\r
-\r
- return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getRawPage',\r
- $pageID, $langID);\r
- }\r
-\r
- // }}}\r
- // {{{ getPage()\r
-\r
- /**\r
- * Same as getRawPage, but resort to fallback language and\r
- * replace parameters when needed\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2;\r
-\r
- if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {\r
- $pageID = $this->translation2->currentPageID;\r
- }\r
- $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;\r
-\r
- $this->_prepare();\r
-\r
- return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getPage',\r
- $pageID, $langID);\r
- }\r
-\r
- // }}}\r
- // {{{ getStringID()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * @param string $string This is NOT the stringID, this is a real string.\r
- * The method will search for its matching stringID, \r
- * and then it will return the associate string in the \r
- * selected language.\r
- * @param string $pageID page/group ID\r
- *\r
- * @return string\r
- */\r
- function getStringID($string, $pageID=TRANSLATION2_DEFAULT_PAGEID)\r
- {\r
- // WITHOUT THIS, IT DOESN'T WORK\r
- global $translation2_cachelitefunction_temp;\r
- //generate temp variable\r
- $translation2_cachelitefunction_temp = $this->translation2;\r
-\r
- if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {\r
- $pageID = $this->translation2->currentPageID;\r
- }\r
- $this->_prepare();\r
-\r
- return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getStringID',\r
- $string, $pageID);\r
- }\r
-\r
- // }}}\r
- // {{{ _cleanCache()\r
-\r
- /**\r
- * Statistically purge the cache\r
- *\r
- * @return void\r
- */\r
- function _cleanCache()\r
- {\r
- if ($this->cleaningFrequency > 0) {\r
- if (mt_rand(1, $this->cleaningFrequency) == 1) {\r
- $this->cacheLiteFunction->clean($this->defaultGroup);\r
- }\r
- }\r
- }\r
-\r
- // }}}\r
-}\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contains the Translation2_Decorator_CacheLiteFunction class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2007 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: CacheLiteFunction.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+
+/**
+ * Load Translation2 decorator base class
+ * and Cache_Lite_Function class
+ */
+require_once 'Translation2/Decorator.php';
+require_once 'Cache/Lite/Function.php';
+
+/**
+ * Decorator to cache fetched data using the Cache_Lite_Function class.
+ *
+ * @category Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2007 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: CacheLiteFunction.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+class Translation2_Decorator_CacheLiteFunction extends Translation2_Decorator
+{
+ // {{{ class vars
+
+ /**
+ * Cache_Lite_Function object
+ * @var object
+ */
+ var $cacheLiteFunction = null;
+
+ /**
+ * @var int (default 1)
+ * @access private
+ */
+ var $tempVarNameGenerator = 1;
+
+ /**
+ * @var string
+ * @access private
+ */
+ var $tempVarName = null;
+
+ /**
+ * Cache lifetime (in seconds)
+ * @var int $lifeTime
+ * @access private
+ */
+ var $lifeTime = 3600;
+
+ /**
+ * Directory where to put the cache files
+ * (make sure to add a trailing slash)
+ * @var string $cacheDir
+ * @access private
+ */
+ var $cacheDir = '/tmp/';
+
+ /**
+ * Enable / disable fileLocking. Can avoid cache corruption under bad
+ * circumstances.
+ * @var string $cacheDir
+ * @access private
+ */
+ var $fileLocking = true;
+
+ /**
+ * Enable / disable caching
+ * (can be very useful to debug cached scripts)
+ * @var boolean $caching
+ */
+ var $caching = true;
+
+ /**
+ * Frequency of cache cleaning.
+ * Higher values mean lower cleaning probability.
+ * Set 0 to disable. Set 1 to clean at every request.
+ * @var boolean $caching
+ */
+ var $cleaningFrequency = 0;
+
+ /**
+ * Name of default cache group.
+ * @var string $defaultGroup
+ */
+ var $defaultGroup = 'Translation2';
+
+ // }}}
+ // {{{ _prepare()
+
+ /**
+ * Istanciate a new Cache_Lite_Function object
+ * and get the name for an unused global variable,
+ * needed by Cache_Lite_Function
+ *
+ * @return void
+ * @access private
+ */
+ function _prepare()
+ {
+ if (is_null($this->cacheLiteFunction)) {
+ $cache_options = array(
+ 'caching' => $this->caching,
+ 'cacheDir' => $this->cacheDir,
+ 'lifeTime' => $this->lifeTime,
+ 'fileLocking' => $this->fileLocking,
+ 'defaultGroup' => $this->defaultGroup,
+
+ );
+ $this->cacheLiteFunction = new Cache_Lite_Function($cache_options);
+ }
+
+ $this->_cleanCache();
+ }
+
+ // }}}
+ // {{{ setLang()
+
+ /**
+ * Set default lang
+ *
+ * Set the language that shall be used when retrieving strings.
+ *
+ * @param string $langID language code (for instance, 'en' or 'it')
+ *
+ * @return void
+ */
+ function setLang($langID)
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_storage_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_storage_cachelitefunction_temp = $this->translation2->storage;
+
+ $this->_prepare();
+ $res = $this->cacheLiteFunction->call(
+ 'translation2_storage_cachelitefunction_temp->setLang', $langID);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ $this->translation2->lang = $res;
+
+ }
+
+ // }}}
+ // {{{ setCacheOption()
+
+ /**
+ * Set a Cache_Lite option
+ *
+ * Passes a Cache_Lite option forward to the Cache_Lite object
+ * See Cache_Lite constructor for available options
+ *
+ * @param string $name name of the option
+ * @param string $value new value of the option
+ *
+ * @return self
+ * @access public
+ * @see Cache_Lite::setOption()
+ */
+ function setCacheOption($name, $value)
+ {
+ $this->_prepare();
+ $this->cacheLiteFunction->setOption($name, $value);
+ return $this;
+ }
+
+ // }}}
+ // {{{ getLang()
+
+ /**
+ * get lang info
+ *
+ * Get some extra information about the language (its full name,
+ * the localized error text, ...)
+ *
+ * @param string $langID language ID
+ * @param string $format ['name', 'meta', 'error_text', 'array']
+ *
+ * @return mixed [string | array], depending on $format
+ */
+ function getLang($langID = null, $format = 'name')
+ {
+ $langs = $this->getLangs('array');
+
+ if (is_null($langID)) {
+ if (!isset($this->lang['id']) || !array_key_exists($this->lang['id'], $langs)) {
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+ $langID = $this->lang['id'];
+ }
+
+ if ($format == 'array') {
+ return $langs[$langID];
+ } elseif (isset($langs[$langID][$format])) {
+ return $langs[$langID][$format];
+ } elseif (isset($langs[$langID]['name'])) {
+ return $langs[$langID]['name'];
+ }
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+
+ // }}}
+ // {{{ getLangs()
+
+ /**
+ * get langs
+ *
+ * Get some extra information about the languages (their full names,
+ * the localized error text, their codes, ...)
+ *
+ * @param string $format ['ids', 'names', 'array']
+ *
+ * @return array
+ */
+ function getLangs($format = 'name')
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2;
+
+ $this->_prepare();
+ return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getLangs',
+ $format);
+ }
+
+ // }}}
+ // {{{ getRaw()
+
+ /**
+ * Get translated string (as-is)
+ *
+ * First check if the string is cached, if not => fetch the page
+ * from the container and cache it for later use.
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ * @param string $defaultText Text to display when the strings in both
+ * the default and the fallback lang are empty
+ *
+ * @return string
+ */
+ function getRaw($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2;
+
+ if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {
+ $pageID = $this->translation2->currentPageID;
+ }
+ $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;
+
+ $this->_prepare();
+
+ return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getRaw',
+ $stringID, $pageID, $langID, $defaultText);
+ }
+
+ // }}}
+ // {{{ get()
+
+ /**
+ * Get translated string
+ *
+ * First check if the string is cached, if not => fetch the page
+ * from the container and cache it for later use.
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ * @param string $defaultText Text to display when the strings in both
+ * the default and the fallback lang are empty
+ *
+ * @return string
+ */
+ function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2->storage;
+
+ if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {
+ $pageID = $this->translation2->currentPageID;
+ }
+ $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;
+
+ $this->_prepare();
+
+ $string = $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getOne',
+ $stringID, $pageID, $langID);
+ if (empty($string)) {
+ return $defaultText;
+ }
+ return $this->translation2->_replaceParams($string);
+ }
+
+ // }}}
+ // {{{ getRawPage()
+
+ /**
+ * Get the array of strings in a page
+ *
+ * First check if the strings are cached, if not => fetch the page
+ * from the container and cache it for later use.
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getRawPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2;
+
+ if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {
+ $pageID = $this->translation2->currentPageID;
+ }
+ $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;
+
+ $this->_prepare();
+
+ return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getRawPage',
+ $pageID, $langID);
+ }
+
+ // }}}
+ // {{{ getPage()
+
+ /**
+ * Same as getRawPage, but resort to fallback language and
+ * replace parameters when needed
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2;
+
+ if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {
+ $pageID = $this->translation2->currentPageID;
+ }
+ $langID = empty($langID) ? $this->translation2->lang['id'] : $langID;
+
+ $this->_prepare();
+
+ return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getPage',
+ $pageID, $langID);
+ }
+
+ // }}}
+ // {{{ getStringID()
+
+ /**
+ * Get translated string
+ *
+ * @param string $string This is NOT the stringID, this is a real string.
+ * The method will search for its matching stringID,
+ * and then it will return the associate string in the
+ * selected language.
+ * @param string $pageID page/group ID
+ *
+ * @return string
+ */
+ function getStringID($string, $pageID=TRANSLATION2_DEFAULT_PAGEID)
+ {
+ // WITHOUT THIS, IT DOESN'T WORK
+ global $translation2_cachelitefunction_temp;
+ //generate temp variable
+ $translation2_cachelitefunction_temp = $this->translation2;
+
+ if ($pageID == TRANSLATION2_DEFAULT_PAGEID) {
+ $pageID = $this->translation2->currentPageID;
+ }
+ $this->_prepare();
+
+ return $this->cacheLiteFunction->call('translation2_cachelitefunction_temp->getStringID',
+ $string, $pageID);
+ }
+
+ // }}}
+ // {{{ _cleanCache()
+
+ /**
+ * Statistically purge the cache
+ *
+ * @return void
+ */
+ function _cleanCache()
+ {
+ if ($this->cleaningFrequency > 0) {
+ if (mt_rand(1, $this->cleaningFrequency) == 1) {
+ $this->cacheLiteFunction->clean($this->defaultGroup);
+ }
+ }
+ }
+
+ // }}}
+}
?>
\ No newline at end of file
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: CacheMemory.php,v 1.13 2007/12/03 07:35:50 quipo Exp $
+ * @version CVS: $Id: CacheMemory.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: CacheMemory.php,v 1.13 2007/12/03 07:35:50 quipo Exp $
+ * @version CVS: $Id: CacheMemory.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Decorator_CacheMemory extends Translation2_Decorator
* @author Rolf 'Red' Ochsenbein <red@raven.ch>
* @copyright 2004-2007 Lorenzo Alberton, Rolf 'Red' Ochsenbein
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: DefaultText.php,v 1.13 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: DefaultText.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Rolf 'Red' Ochsenbein <red@raven.ch>
* @copyright 2004-2007 Lorenzo Alberton, Rolf 'Red' Ochsenbein
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: DefaultText.php,v 1.13 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: DefaultText.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Decorator_DefaultText extends Translation2_Decorator
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: ErrorText.php,v 1.7 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: ErrorText.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: ErrorText.php,v 1.7 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: ErrorText.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Decorator_ErrorText extends Translation2_Decorator
* @author Sergey Korotkov <sergey@pushok.com>
* @copyright 2004-2007 Lorenzo Alberton, Sergey Korotkov
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: Iconv.php,v 1.12 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: Iconv.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Sergey Korotkov <sergey@pushok.com>
* @copyright 2004-2007 Lorenzo Alberton, Sergey Korotkov
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: Iconv.php,v 1.12 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: Iconv.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
* @see http://www.php.net/htmlentities for a list of available encodings.
*/
-<?php\r
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\r
-\r
-/**\r
- * Contains the Translation2_Decorator_Lang class\r
- *\r
- * PHP versions 4 and 5\r
- *\r
- * LICENSE: Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED\r
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2007 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: Lang.php,v 1.15 2008/11/09 19:56:04 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-\r
-/**\r
- * Load Translation2 decorator base class\r
- */\r
-require_once 'Translation2/Decorator.php';\r
-\r
-/**\r
- * Decorator to provide a fallback language for empty strings.\r
- *\r
- * @category Internationalization\r
- * @package Translation2\r
- * @author Lorenzo Alberton <l.alberton@quipo.it>\r
- * @copyright 2004-2007 Lorenzo Alberton\r
- * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)\r
- * @version CVS: $Id: Lang.php,v 1.15 2008/11/09 19:56:04 quipo Exp $\r
- * @link http://pear.php.net/package/Translation2\r
- */\r
-class Translation2_Decorator_Lang extends Translation2_Decorator\r
-{\r
- // {{{ class vars\r
-\r
- /**\r
- * fallback lang\r
- * @var string\r
- * @access protected\r
- */\r
- var $fallbackLang;\r
-\r
- // }}}\r
- // {{{ setOption()\r
-\r
- /**\r
- * set Decorator option (intercept 'fallbackLang' option).\r
- * I don't know why it's needed, but it doesn't work without.\r
- *\r
- * @param string $option option name\r
- * @param mixed $value option value\r
- *\r
- * @return self\r
- */\r
- function setOption($option, $value=null)\r
- {\r
- if ($option == 'fallbackLang') {\r
- $this->fallbackLang = $value;\r
- return $this;\r
- }\r
- return parent::setOption($option, $value);\r
- }\r
-\r
- // }}}\r
- // {{{ get()\r
-\r
- /**\r
- * Get translated string\r
- *\r
- * If the string is empty, check the fallback language\r
- *\r
- * @param string $stringID string ID\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- * @param string $defaultText Text to display when the strings in both\r
- * the default and the fallback lang are empty\r
- *\r
- * @return string\r
- */\r
- function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')\r
- {\r
- $str = $this->translation2->get($stringID, $pageID, $langID, $defaultText);\r
- if (empty($str)) {\r
- $str = $this->translation2->get($stringID, $pageID, $this->fallbackLang);\r
- }\r
- return $str;\r
- }\r
-\r
- // }}}\r
- // {{{ getPage()\r
-\r
- /**\r
- * Same as getRawPage, but resort to fallback language and\r
- * replace parameters when needed\r
- *\r
- * @param string $pageID page/group ID\r
- * @param string $langID language ID\r
- *\r
- * @return array\r
- */\r
- function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)\r
- {\r
- $data1 = $this->translation2->getPage($pageID, $langID);\r
- if (PEAR::isError($data1)) {\r
- return $data1;\r
- }\r
- $data2 = $this->translation2->getPage($pageID, $this->fallbackLang);\r
- if (PEAR::isError($data2)) {\r
- return $data2;\r
- }\r
- foreach ($data1 as $key => $val) {\r
- if (empty($val)) {\r
- $data1[$key] = $data2[$key];\r
- }\r
- }\r
- // append keys when fallback lang contains more than current\r
- $diff = array_diff(array_keys($data2), array_keys($data1));\r
- foreach ($diff as $key) {\r
- $data1[$key] = $data2[$key];\r
- }\r
- return $data1;\r
- }\r
-\r
- // }}}\r
-}\r
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contains the Translation2_Decorator_Lang class
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 FREEBSD PROJECT 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 Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2007 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: Lang.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+
+/**
+ * Load Translation2 decorator base class
+ */
+require_once 'Translation2/Decorator.php';
+
+/**
+ * Decorator to provide a fallback language for empty strings.
+ *
+ * @category Internationalization
+ * @package Translation2
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
+ * @copyright 2004-2007 Lorenzo Alberton
+ * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
+ * @version CVS: $Id: Lang.php 305985 2010-12-05 22:55:33Z clockwerx $
+ * @link http://pear.php.net/package/Translation2
+ */
+class Translation2_Decorator_Lang extends Translation2_Decorator
+{
+ // {{{ class vars
+
+ /**
+ * fallback lang
+ * @var string
+ * @access protected
+ */
+ var $fallbackLang;
+
+ // }}}
+ // {{{ setOption()
+
+ /**
+ * set Decorator option (intercept 'fallbackLang' option).
+ * I don't know why it's needed, but it doesn't work without.
+ *
+ * @param string $option option name
+ * @param mixed $value option value
+ *
+ * @return self
+ */
+ function setOption($option, $value=null)
+ {
+ if ($option == 'fallbackLang') {
+ $this->fallbackLang = $value;
+ return $this;
+ }
+ return parent::setOption($option, $value);
+ }
+
+ // }}}
+ // {{{ get()
+
+ /**
+ * Get translated string
+ *
+ * If the string is empty, check the fallback language
+ *
+ * @param string $stringID string ID
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ * @param string $defaultText Text to display when the strings in both
+ * the default and the fallback lang are empty
+ *
+ * @return string
+ */
+ function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null, $defaultText = '')
+ {
+ $str = $this->translation2->get($stringID, $pageID, $langID, $defaultText);
+ if (empty($str)) {
+ $str = $this->translation2->get($stringID, $pageID, $this->fallbackLang);
+ }
+ return $str;
+ }
+
+ // }}}
+ // {{{ getPage()
+
+ /**
+ * Same as getRawPage, but resort to fallback language and
+ * replace parameters when needed
+ *
+ * @param string $pageID page/group ID
+ * @param string $langID language ID
+ *
+ * @return array
+ */
+ function getPage($pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null)
+ {
+ $data1 = $this->translation2->getPage($pageID, $langID);
+ if (PEAR::isError($data1)) {
+ return $data1;
+ }
+ $data2 = $this->translation2->getPage($pageID, $this->fallbackLang);
+ if (PEAR::isError($data2)) {
+ return $data2;
+ }
+ foreach ($data1 as $key => $val) {
+ if (empty($val)) {
+ $data1[$key] = $data2[$key];
+ }
+ }
+ // append keys when fallback lang contains more than current
+ $diff = array_diff(array_keys($data2), array_keys($data1));
+ foreach ($diff as $key) {
+ $data1[$key] = $data2[$key];
+ }
+ return $data1;
+ }
+
+ // }}}
+}
?>
\ No newline at end of file
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: SpecialChars.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: SpecialChars.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: SpecialChars.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: SpecialChars.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
* @see http://www.php.net/htmlentities for a list of available charsets.
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: UTF8.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: UTF8.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
- * @version CVS: $Id: UTF8.php,v 1.9 2007/10/28 23:42:35 quipo Exp $
+ * @version CVS: $Id: UTF8.php 305985 2010-12-05 22:55:33Z clockwerx $
* @link http://pear.php.net/package/Translation2
*/
class Translation2_Decorator_UTF8 extends Translation2_Decorator
* @author Amir Mohammad Saied <amir@php.net>
* @copyright 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox,Amir Mohammad Saied
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Validate.php 291251 2009-11-24 02:42:17Z amir $
+ * @version CVS: $Id: Validate.php 302518 2010-08-20 01:58:15Z clockwerx $
* @link http://pear.php.net/package/Validate
*/
define('VALIDATE_ALPHA_LOWER', 'a-z');
define('VALIDATE_ALPHA_UPPER', 'A-Z');
define('VALIDATE_ALPHA', VALIDATE_ALPHA_LOWER . VALIDATE_ALPHA_UPPER);
-define('VALIDATE_EALPHA_LOWER', VALIDATE_ALPHA_LOWER . 'áéíóúýàèìòùäëïöüÿâêîôûãñõ¨åæç½ðøþß');
-define('VALIDATE_EALPHA_UPPER', VALIDATE_ALPHA_UPPER . 'ÁÉÍÓÚÝÀÈÌÒÙÄËÏÖܾÂÊÎÔÛÃÑÕ¦ÅÆǼÐØÞ');
+define('VALIDATE_EALPHA_LOWER', VALIDATE_ALPHA_LOWER . 'áéíóúýàèìòùäëïöüÿâêîôûãñõ¨åæç½ðøþß');
+define('VALIDATE_EALPHA_UPPER', VALIDATE_ALPHA_UPPER . 'ÁÉÍÓÚÝÀÈÌÒÙÄËÏÖܾÂÊÎÔÛÃÑÕ¦ÅÆǼÐØÞ');
define('VALIDATE_EALPHA', VALIDATE_EALPHA_LOWER . VALIDATE_EALPHA_UPPER);
define('VALIDATE_PUNCTUATION', VALIDATE_SPACE . '\.,;\:&"\'\?\!\(\)');
define('VALIDATE_NAME', VALIDATE_EALPHA . VALIDATE_SPACE . "'" . '\-');
-define('VALIDATE_STREET', VALIDATE_NUM . VALIDATE_NAME . "/\\ºª\.");
+define('VALIDATE_STREET', VALIDATE_NUM . VALIDATE_NAME . "/\\ºª\.");
define('VALIDATE_ITLD_EMAILS', 1);
define('VALIDATE_GTLD_EMAILS', 2);
*
* @return XML_Parser_Error reference to the error object
**/
- function raiseError($msg = null, $ecode = 0)
+ function &raiseError($msg = null, $ecode = 0)
{
$msg = !is_null($msg) ? $msg : $this->parser;
- $err = new XML_Parser_Error($msg, $ecode);
+ $err = &new XML_Parser_Error($msg, $ecode);
return parent::raiseError($err);
}
* @author Stephan Schmidt <schst@php.net>
* @copyright 2004-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version CVS: $Id: Simple.php,v 1.7 2008/08/24 21:48:21 ashnazg Exp $
+ * @version CVS: $Id: Simple.php 265444 2008-08-24 21:48:21Z ashnazg $
* @link http://pear.php.net/package/XML_Parser
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version SVN: $Id: RPC.php 293238 2010-01-08 03:21:06Z danielc $
+ * @version SVN: $Id: RPC.php 315594 2011-08-27 01:03:57Z danielc $
* @link http://pear.php.net/package/XML_RPC
*/
$GLOBALS['XML_RPC_backslash'] = chr(92) . chr(92);
-/**#@+
- * Which functions to use, depending on whether mbstring is enabled or not.
- */
-if (function_exists('mb_ereg')) {
- /** @global string $GLOBALS['XML_RPC_func_ereg'] */
- $GLOBALS['XML_RPC_func_ereg'] = 'mb_eregi';
- /** @global string $GLOBALS['XML_RPC_func_ereg_replace'] */
- $GLOBALS['XML_RPC_func_ereg_replace'] = 'mb_eregi_replace';
- /** @global string $GLOBALS['XML_RPC_func_split'] */
- $GLOBALS['XML_RPC_func_split'] = 'mb_split';
-} else {
- /** @ignore */
- $GLOBALS['XML_RPC_func_ereg'] = 'eregi';
- /** @ignore */
- $GLOBALS['XML_RPC_func_ereg_replace'] = 'eregi_replace';
- /** @ignore */
- $GLOBALS['XML_RPC_func_split'] = 'split';
-}
-/**#@-*/
-
-
/**
* Should we automatically base64 encode strings that contain characters
* which can cause PHP's SAX-based XML parser to break?
} else {
// not top level element: see if parent is OK
if (!in_array($XML_RPC_xh[$parser]['stack'][0], $XML_RPC_valid_parents[$name])) {
- $name = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name);
+ $name = preg_replace('@[^a-zA-Z0-9._-]@', '', $name);
$XML_RPC_xh[$parser]['isf'] = 2;
$XML_RPC_xh[$parser]['isf_reason'] = "xmlrpc element $name cannot be child of {$XML_RPC_xh[$parser]['stack'][0]}";
return;
} else {
// we have an I4, INT or a DOUBLE
// we must check that only 0123456789-.<space> are characters here
- if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
+ if (!preg_match("@^[+-]?[0123456789 \t\.]+$@", $XML_RPC_xh[$parser]['ac'])) {
XML_RPC_Base::raiseError('Non-numeric value received in INT or DOUBLE',
XML_RPC_ERROR_NON_NUMERIC_FOUND);
$XML_RPC_xh[$parser]['value'] = XML_RPC_ERROR_NON_NUMERIC_FOUND;
case 'METHODNAME':
case 'RPCMETHODNAME':
- $XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '',
+ $XML_RPC_xh[$parser]['method'] = preg_replace("@^[\n\r\t ]+@", '',
$XML_RPC_xh[$parser]['ac']);
break;
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Base {
*/
function isError($value)
{
- return is_a($value, 'PEAR_Error');
+ return is_object($value) && is_a($value, 'PEAR_Error');
}
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Client extends XML_RPC_Base {
$this->proxy_user = $proxy_user;
$this->proxy_pass = $proxy_pass;
- $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $server, $match);
+ preg_match('@^(http://|https://|ssl://)?(.*)$@', $server, $match);
if ($match[1] == '') {
if ($port == 443) {
$this->server = $match[2];
}
if ($proxy) {
- $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match);
+ preg_match('@^(http://|https://|ssl://)?(.*)$@', $proxy, $match);
if ($match[1] == '') {
if ($proxy_port == 443) {
$this->proxy = $match[2];
*/
function send($msg, $timeout = 0)
{
- if (!is_a($msg, 'XML_RPC_Message')) {
+ if (!is_object($msg) || !is_a($msg, 'XML_RPC_Message')) {
$this->errstr = 'send()\'s $msg parameter must be an'
. ' XML_RPC_Message object.';
$this->raiseError($this->errstr, XML_RPC_ERROR_PROGRAMMING);
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Response extends XML_RPC_Base
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Message extends XML_RPC_Base
$this->payload .= "</params>\n";
$this->payload .= $this->xml_footer();
if ($this->remove_extra_lines) {
- $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload);
+ $this->payload = preg_replace("@[\r\n]+@", "\r\n", $this->payload);
} else {
- $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("\r\n|\n|\r|\n\r", "\r\n", $this->payload);
+ $this->payload = preg_replace("@\r\n|\n|\r|\n\r@", "\r\n", $this->payload);
}
if ($this->convert_payload_encoding) {
$this->payload = mb_convert_encoding($this->payload, $this->send_encoding);
{
global $XML_RPC_defencoding;
- if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]',
+ if (preg_match('@<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]@',
$data, $match))
{
$match[1] = trim(strtoupper($match[1]));
// See if response is a 200 or a 100 then a 200, else raise error.
// But only do this if we're using the HTTP protocol.
- if ($GLOBALS['XML_RPC_func_ereg']('^HTTP', $data) &&
- !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 200 ', $data) &&
- !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200', $data))
+ if (preg_match('@^HTTP@', $data) &&
+ !preg_match('@^HTTP/[0-9\.]+ 200 @', $data) &&
+ !preg_match('@^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200@', $data))
{
$errstr = substr($data, 0, strpos($data, "\n") - 1);
error_log('HTTP error, got response: ' . $errstr);
$r = new XML_RPC_Response($v);
}
}
- $r->hdrs = split("\r?\n", $XML_RPC_xh[$parser]['ha'][1]);
+ $r->hdrs = preg_split("@\r?\n@", $XML_RPC_xh[$parser]['ha']);
return $r;
}
}
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Value extends XML_RPC_Base
$rs .= "<struct>\n";
reset($val);
foreach ($val as $key2 => $val2) {
- $rs .= "<member><name>${key2}</name>\n";
+ $rs .= "<member><name>" . htmlspecialchars($key2) . "</name>\n";
$rs .= $this->serializeval($val2);
$rs .= "</member>\n";
}
function XML_RPC_iso8601_decode($idate, $utc = 0)
{
$t = 0;
- if ($GLOBALS['XML_RPC_func_ereg']('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) {
+ if (preg_match('@([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})@', $idate, $regs)) {
if ($utc) {
$t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
} else {
case 'string':
case 'NULL':
- if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {
+ if (preg_match('@^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$@', $php_val)) {
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']);
} elseif ($GLOBALS['XML_RPC_auto_base64']
- && $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val))
+ && preg_match("@[^ -~\t\r\n]@", $php_val))
{
// Characters other than alpha-numeric, punctuation, SP, TAB,
// LF and CR break the XML parser, encode value via Base 64.
* @package XML_RPC
* @author Christian Weiske <cweiske@php.net>
* @license http://www.php.net/license/3_01.txt PHP License
- * @version SVN: $Id: Dump.php 293224 2010-01-07 15:36:40Z danielc $
+ * @version SVN: $Id: Dump.php 300962 2010-07-03 02:24:24Z danielc $
* @link http://pear.php.net/package/XML_RPC
*/
* @package XML_RPC
* @author Christian Weiske <cweiske@php.net>
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Dump
*/
function generateDump($value, $nLevel = 0)
{
- if (!is_object($value) && get_class($value) != 'xml_rpc_value') {
+ if (!is_object($value) || strtolower(get_class($value)) != 'xml_rpc_value') {
require_once 'PEAR.php';
PEAR::raiseError('Tried to dump non-XML_RPC_Value variable' . "\r\n",
0, PEAR_ERROR_PRINT);
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version SVN: $Id: Server.php 293224 2010-01-07 15:36:40Z danielc $
+ * @version SVN: $Id: Server.php 315558 2011-08-26 14:42:51Z danielc $
* @link http://pear.php.net/package/XML_RPC
*/
* @author Daniel Convissor <danielc@php.net>
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License
- * @version Release: 1.5.3
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_RPC
*/
class XML_RPC_Server
if ($XML_RPC_Server_debuginfo != '') {
return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"
- . $GLOBALS['XML_RPC_func_ereg_replace']('--', '- - ', $XML_RPC_Server_debuginfo)
+ . str_replace('--', '- - ', $XML_RPC_Server_debuginfo)
. "-->\n";
} else {
return '';
* that someone composed a single header with multiple lines, which
* the RFCs allow.
*/
- $this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+[ \t]+",
+ $this->server_headers = preg_replace("@[\r\n]+[ \t]+@",
' ', trim($this->server_headers));
- $headers = $GLOBALS['XML_RPC_func_split']("[\r\n]+", $this->server_headers);
+ $headers = preg_split("@[\r\n]+@", $this->server_headers);
foreach ($headers as $header)
{
header($header);
} else {
$r = call_user_func($dmap[$methName]['function'], $m);
}
- if (!is_a($r, 'XML_RPC_Response')) {
+ if (!is_object($r) || !is_a($r, 'XML_RPC_Response')) {
$r = new XML_RPC_Response(0, $XML_RPC_err['not_response_object'],
$XML_RPC_str['not_response_object']);
}
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version CVS: $Id: Serializer.php,v 1.61 2009/06/12 02:11:44 ashnazg Exp $
+ * @version CVS: $Id: Serializer.php 294967 2010-02-12 03:10:19Z clockwerx $
* @link http://pear.php.net/package/XML_Serializer
* @see XML_Unserializer
*/
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version Release: 0.20.0
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_Serializer
* @see XML_Unserializer
* @todo replace extending PEAR class with instead using a PEAR_Error object
*/
function apiVersion()
{
- return '0.20.0';
+ return '@package_version@';
}
/**
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version CVS: $Id: Unserializer.php,v 1.42 2009/02/09 14:49:52 ashnazg Exp $
+ * @version CVS: $Id: Unserializer.php 303099 2010-09-06 16:23:06Z clockwerx $
* @link http://pear.php.net/package/XML_Serializer
* @see XML_Unserializer
*/
* $unserializer->unserialize($xml);
*
* $data = $unserializer->getUnserializedData();
- * <code>
+ * </code>
*
* @category XML
* @package XML_Serializer
* @author Stephan Schmidt <schst@php.net>
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
* @license http://opensource.org/licenses/bsd-license New BSD License
- * @version Release: 0.20.0
+ * @version Release: @package_version@
* @link http://pear.php.net/package/XML_Serializer
* @see XML_Serializer
*/
*/
function apiVersion()
{
- return '0.20.0';
+ return '@package_version@';
}
/**
if ($this->options[XML_UNSERIALIZER_OPTION_TAG_AS_CLASSNAME] === true
&& class_exists($classname)
) {
- $value['value'] = &new $classname;
+ $value['value'] = new $classname;
} else {
$value['value'] =
- &new $this->options[XML_UNSERIALIZER_OPTION_DEFAULT_CLASS];
+ new $this->options[XML_UNSERIALIZER_OPTION_DEFAULT_CLASS];
}
if (trim($data) !== '') {
if ($value['guessType'] === true) {
$this->_parser->free();
unset($this->_parser);
}
- $this->_parser = &new XML_Parser($this->
+ $this->_parser = new XML_Parser($this->
options[XML_UNSERIALIZER_OPTION_ENCODING_SOURCE],
'event', $this->options[XML_UNSERIALIZER_OPTION_ENCODING_TARGET]);