Move artichow and smarty libs into includes directory with other libraries.

This commit is contained in:
Laurent Destailleur
2009-10-07 17:51:15 +00:00
parent 98b83f5554
commit 28993e7dcd
150 changed files with 19 additions and 23 deletions

View File

@@ -0,0 +1,79 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/*
* Path to Artichow
*/
define('ARTICHOW', dirname(__FILE__).DIRECTORY_SEPARATOR.'php'.substr(phpversion(), 0, 1));
/*
* Path to TrueType fonts
*/
if(defined('ARTICHOW_FONT') === FALSE) {
define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'font');
}
/*
* Patterns directory
*/
if(defined('ARTICHOW_PATTERN') === FALSE) {
define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patterns');
}
/*
* Images directory
*/
if(defined('ARTICHOW_IMAGE') === FALSE) {
define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images');
}
/*
* Enable/disable cache support
*/
define('ARTICHOW_CACHE', TRUE);
/*
* Cache directory
*/
if(defined('ARTICHOW_CACHE') === FALSE) {
define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache');
}
/*
* Prefix for class names
* No prefix by default
*/
define('ARTICHOW_PREFIX', '');
/*
* Trigger errors when use of a deprecated feature
*/
define('ARTICHOW_DEPRECATED', TRUE);
/*
* Fonts to use
*/
$fonts = array(
'Tuffy',
'TuffyBold',
'TuffyBoldItalic',
'TuffyItalic'
);
?>

View File

@@ -0,0 +1,4 @@
<?php
require_once dirname(__FILE__).'/Artichow.cfg.php';
require_once ARTICHOW.'/BarPlot.class.php';
?>

View File

@@ -0,0 +1,4 @@
<?php
require_once dirname(__FILE__).'/Artichow.cfg.php';
require_once ARTICHOW.'/Graph.class.php';
?>

View File

@@ -0,0 +1,4 @@
<?php
require_once dirname(__FILE__).'/Artichow.cfg.php';
require_once ARTICHOW.'/Image.class.php';
?>

View File

@@ -0,0 +1,4 @@
<?php
require_once dirname(__FILE__).'/Artichow.cfg.php';
require_once ARTICHOW.'/LinePlot.class.php';
?>

View File

@@ -0,0 +1,4 @@
<?php
require_once dirname(__FILE__).'/Artichow.cfg.php';
require_once ARTICHOW.'/Pie.class.php';
?>

View File

@@ -0,0 +1,9 @@
$Id$
$Revision$
Source
http://www.artichow.org/data/Artichow-1.0.7-php4+5.tar.gz
Ne pas utiliser la version 1.0.9 qui est buggee

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,217 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* AntiSpam
* String printed on the images are case insensitive.
*
* @package Artichow
*/
class awAntiSpam extends awImage {
/**
* Anti-spam string
*
* @var string
*/
var $string;
/**
* Noise intensity
*
* @var int
*/
var $noise = 0;
/**
* Construct a new awAntiSpam image
*
* @param string $string A string to display
*/
function awAntiSpam($string = '') {
parent::awImage();
$this->string = (string)$string;
}
/**
* Create a random string
*
* @param int $length String length
* @return string String created
*/
function setRand($length) {
$length = (int)$length;
$this->string = '';
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
$number = strlen($letters);
for($i = 0; $i < $length; $i++) {
$this->string .= $letters{mt_rand(0, $number - 1)};
}
return $this->string;
}
/**
* Set noise on image
*
* @param int $nois Noise intensity (from 0 to 10)
*/
function setNoise($noise) {
if($noise < 0) {
$noise = 0;
}
if($noise > 10) {
$noise = 10;
}
$this->noise = (int)$noise;
}
/**
* Save string value in session
* You can use check() to verify the value later
*
* @param string $qName A name that identify the anti-spam image
*/
function save($qName) {
$this->session();
$session = 'artichow_'.(string)$qName;
$_SESSION[$session] = $this->string;
}
/**
* Verify user entry
*
* @param string $qName A name that identify the anti-spam image
* @param string $value User-defined value
* @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
* @return bool TRUE if the value is correct, FALSE otherwise
*/
function check($qName, $value, $case = TRUE) {
$this->session();
$session = 'artichow_'.(string)$qName;
return (
array_key_exists($session, $_SESSION) === TRUE and
$case ?
(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
($_SESSION[$session] === (string)$value)
);
}
/**
* Draw image
*/
function draw() {
$fonts = array(
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'Tuffy.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBold.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyItalic.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBoldItalic.ttf'
);
$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);
$widths = array();
$heights = array();
$texts = array();
for($i = 0; $i < strlen($this->string); $i++) {
$fontKey = array_rand($fonts);
$sizeKey = array_rand($sizes);
$font = new awTTFFont(
$fonts[$fontKey], $sizes[$sizeKey]
);
$text = new awText(
$this->string{$i},
$font,
NULL,
mt_rand(-15, 15)
);
$widths[] = $font->getTextWidth($text);
$heights[] = $font->getTextHeight($text);
$texts[] = $text;
}
$width = array_sum($widths);
$height = array_max($heights);
$totalWidth = $width + 10 + count($texts) * 10;
$totalHeight = $height + 20;
$this->setSize($totalWidth, $totalHeight);
$this->create();
for($i = 0; $i < strlen($this->string); $i++) {
$this->drawer->string(
$texts[$i],
new awPoint(
5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
10 + ($height - $heights[$i]) / 2
)
);
}
$this->drawNoise($totalWidth, $totalHeight);
$this->send();
}
function drawNoise($width, $height) {
$points = $this->noise * 30;
$color = new awColor(0, 0, 0);
for($i = 0; $i < $points; $i++) {
$this->drawer->point(
$color,
new awPoint(
mt_rand(0, $width),
mt_rand(0, $height)
)
);
}
}
function session() {
// Start session if needed
if(!session_id()) {
session_start();
}
}
}
registerClass('AntiSpam');
?>

View File

@@ -0,0 +1,364 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/**
* BarPlot
*
* @package Artichow
*/
class awBarPlot extends awPlot {
/**
* Labels on your bar plot
*
* @var Label
*/
var $label;
/**
* Bar plot identifier
*
* @var int
*/
var $identifier;
/**
* Bar plot number
*
* @var int
*/
var $number;
/**
* Bar plot depth
*
* @var int
*/
var $depth;
/**
* For moving bars
*
* @var int
*/
var $move;
/**
* Bars shadow
*
* @var Shadow
*/
var $barShadow;
/**
* Bars border
*
* @var Border
*/
var $barBorder;
/**
* Bars padding
*
* @var Side
*/
var $barPadding;
/**
* Bars space
*
* @var int
*/
var $barSpace = 0;
/**
* Bars background
*
* @var Color, Gradient
*/
var $barBackground;
/**
* Construct a new awBarPlot
*
* @param array $values Some numeric values for Y axis
* @param int $identifier Plot identifier
* @param int $number Bar plot number
* @param int $depth Bar plot depth in pixels
*/
function awBarPlot($values, $identifier = 1, $number = 1, $depth = 0) {
parent::awPlot();
$this->label = new awLabel;
$this->barPadding = new awSide(0.08, 0.08, 0, 0);
$this->barShadow = new awShadow(SHADOW_RIGHT_TOP);
$this->barBorder = new awBorder;
$this->setValues($values);
$this->identifier = (int)$identifier;
$this->number = (int)$number;
$this->depth = (int)$depth;
$this->move = new awSide;
// Hide vertical grid
$this->grid->hideVertical(TRUE);
}
/**
* Change bars padding
* This method is not compatible with awBarPlot::setBarPadding()
*
* @param float $left Left padding (between 0 and 1)
* @param float $right Right padding (between 0 and 1)
*/
function setBarPadding($left = NULL, $right = NULL) {
$this->barPadding->set($left, $right);
}
/**
* Change bars size
* This method is not compatible with awBarPlot::setBarPadding()
*
* @param int $width Bars size (between 0 and 1)
*/
function setBarSize($size) {
$padding = (1 - $size) / 2;
$this->barPadding->set($padding, $padding);
}
/**
* Move bars
*
* @param int $x
* @param int $y
*/
function move($x, $y) {
$this->move->set($x, NULL, $y, NULL);
}
/**
* Change bars space
*
* @param int $space Space in pixels
*/
function setBarSpace($space) {
$this->barSpace = (int)$space;
}
/**
* Change line background color
*
* @param $color
*/
function setBarColor($color) {
$this->barBackground = $color;
}
/**
* Change line background gradient
*
* @param $gradient
*/
function setBarGradient($gradient) {
$this->barBackground = $gradient;
}
/**
* Get the line thickness
*
* @return int
*/
function getLegendLineThickness() {
}
/**
* Get the line type
*
* @return int
*/
function getLegendLineStyle() {
}
/**
* Get the color of line
*
* @return Color
*/
function getLegendLineColor() {
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
function getLegendBackground() {
return $this->barBackground;
}
/**
* Get a mark object
*
* @return Mark
*/
function getLegendMark() {
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->datay);
$max = $this->getRealYMax(NULL);
$min = $this->getRealYMin(NULL);
// Find zero for bars
if($this->xAxisZero and $min <= 0 and $max >= 0) {
$zero = 0;
} else if($max < 0) {
$zero = $max;
} else {
$zero = $min;
}
// Get base position
$zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
// Distance between two values on the graph
$distance = $this->xAxis->getDistance(0, 1);
// Compute paddings
$leftPadding = $this->barPadding->left * $distance;
$rightPadding = $this->barPadding->right * $distance;
$padding = $leftPadding + $rightPadding;
$space = $this->barSpace * ($this->number - 1);
$barSize = ($distance - $padding - $space) / $this->number;
$barPosition = $leftPadding + $barSize * ($this->identifier - 1);
for($key = 0; $key < $count; $key++) {
$value = $this->datay[$key];
if($value !== NULL) {
$position = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, $value)
);
$barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
$barStop = $barStart + $barSize;
$t1 = min($zero->y, $position->y);
$t2 = max($zero->y, $position->y);
if(round($t2 - $t1) == 0) {
continue;
}
$p1 = new awPoint(
round($barStart) + $this->depth + $this->move->left,
round($t1) - $this->depth + $this->move->top
);
$p2 = new awPoint(
round($barStop) + $this->depth + $this->move->left,
round($t2) - $this->depth + $this->move->top
);
$this->drawBar($drawer, $p1, $p2);
}
}
// Draw labels
foreach($this->datay as $key => $value) {
if($value !== NULL) {
$position = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, $value)
);
$point = new awPoint(
$barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth,
$position->y - $this->depth
);
$this->label->draw($drawer, $point, $key);
}
}
}
function getXAxisNumber() {
return count($this->datay) + 1;
}
// ça bidouille à fond ici !
function getXMax() {
return array_max($this->datax) + 1;
}
function getXCenter() {
return TRUE;
}
function drawBar($drawer, $p1, $p2) {
// Draw shadow
$this->barShadow->draw(
$drawer,
$p1,
$p2,
SHADOW_OUT
);
if(abs($p2->y - $p1->y) > 1) {
$this->barBorder->rectangle(
$drawer,
$p1,
$p2
);
if($this->barBackground !== NULL) {
$size = $this->barBorder->visible() ? 1 : 0;
$b1 = $p1->move($size, $size);
$b2 = $p2->move(-1 * $size, -1 * $size);
// Draw background
$drawer->filledRectangle(
$this->barBackground,
new awLine($b1, $b2)
);
}
}
}
}
registerClass('BarPlot');
?>

View File

@@ -0,0 +1,415 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* A graph can contain some groups of components
*
* @package Artichow
*/
class awComponentGroup extends awComponent {
/**
* Components of this group
*
* @var array
*/
var $components;
/**
* Build the component group
*/
function awComponentGroup() {
parent::awComponent();
$this->components = array();
}
/**
* Add a component to the group
*
* @param &$component A component
*/
function add(&$component) {
$this->components[] = $component;
}
}
registerClass('ComponentGroup', TRUE);
class awComponent {
/**
* Component drawer
*
* @var Drawer
*/
var $drawer;
/**
* Component width
*
* @var float
*/
var $width = 1.0;
/**
* Component height
*
* @var float
*/
var $height = 1.0;
/**
* Position X of the center the graph (from 0 to 1)
*
* @var float
*/
var $x = 0.5;
/**
* Position Y of the center the graph (from 0 to 1)
*
* @var float
*/
var $y = 0.5;
/**
* Component absolute width (in pixels)
*
*
* @var int
*/
var $w;
/**
* Component absolute height (in pixels)
*
*
* @var int
*/
var $h;
/**
* Left-top corner Y position
*
* @var float
*/
var $top;
/**
* Left-top corner X position
*
* @var float
*/
var $left;
/**
* Component background color
*
* @var Color
*/
var $background;
/**
* Component padding
*
* @var Side
*/
var $padding;
/**
* Component space
*
* @var Side
*/
var $space;
/**
* Component title
*
* @var Label
*/
var $title;
/**
* Adjust automatically the component ?
*
* @var bool
*/
var $auto = TRUE;
/**
* Legend
*
* @var Legend
*/
var $legend;
/**
* Build the component
*/
function awComponent() {
// Component legend
$this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0);
// Component title
$this->title = new awLabel(
NULL,
new awTuffy(10),
NULL,
0
);
$this->title->setAlign(LABEL_CENTER, LABEL_TOP);
}
/**
* Adjust automatically the component ?
*
* @param bool $auto
*/
function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Change the size of the component
*
* @param int $width Component width (from 0 to 1)
* @param int $height Component height (from 0 to 1)
*/
function setSize($width, $height) {
$this->width = (float)$width;
$this->height = (float)$height;
}
/**
* Change the absolute size of the component
*
* @param int $w Component width (in pixels)
* @param int $h Component height (in pixels)
*/
function setAbsSize($w, $h) {
$this->w = (int)$w;
$this->h = (int)$h;
}
/**
* Change component background color
*
* @param $color (can be null)
*/
function setBackgroundColor($color) {
if($color === NULL or is_a($color, 'awColor')) {
$this->background = $color;
}
}
/**
* Change component background gradient
*
* @param $gradient (can be null)
*/
function setBackgroundGradient($gradient) {
if($gradient === NULL or is_a($gradient, 'awGradient')) {
$this->background = $gradient;
}
}
/**
* Change component background image
*
* @param &$image (can be null)
*/
function setBackgroundImage($image) {
if($image === NULL or is_a($image, 'awImage')) {
$this->background = $image;
}
}
/**
* Return the component background
*
* @return Color, Gradient
*/
function getBackground() {
return $this->background;
}
/**
* Change component padding
*
* @param int $left Padding in pixels (NULL to keep old value)
* @param int $right Padding in pixels (NULL to keep old value)
* @param int $top Padding in pixels (NULL to keep old value)
* @param int $bottom Padding in pixels (NULL to keep old value)
*/
function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom);
}
/**
* Change component space
*
* @param float $left Space in % (NULL to keep old value)
* @param float $right Space in % (NULL to keep old value)
* @param float $bottom Space in % (NULL to keep old value)
* @param float $top Space in % (NULL to keep old value)
*/
function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top);
}
/**
* Change the absolute position of the component on the graph
*
* @var int $x Left-top corner X position
* @var int $y Left-top corner Y position
*/
function setAbsPosition($left, $top) {
$this->left = (int)$left;
$this->top = (int)$top;
}
/**
* Set the center of the component
*
* @param int $x Position on X axis of the center of the component
* @param int $y Position on Y axis of the center of the component
*/
function setCenter($x, $y) {
$this->x = (float)$x;
$this->y = (float)$y;
}
/**
* Get component coords with its padding
*
* @return array Coords of the component
*/
function getPosition() {
// Get component coords
$x1 = $this->padding->left;
$y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2);
}
/**
* Init the drawing of the component
*/
function init($drawer) {
// Set component background
$background = $this->getBackground();
if($background !== NULL) {
$p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1);
if(is_a($background, 'awImage')) {
$drawer->copyImage(
$background,
$p1,
$p2
);
} else {
$drawer->filledRectangle(
$background,
new awLine($p1, $p2)
);
}
}
}
/**
* Finalize the drawing of the component
*/
function finalize($drawer) {
// Draw component title
$point = new awPoint(
$this->w / 2,
$this->padding->top - 8
);
$this->title->draw($drawer, $point);
// Draw legend
$this->legend->draw($drawer);
}
/**
* Draw the grid around your component
*
* @param Drawer A drawer
* @return array Coords for the component
*/
/**
* Draw the component on the graph
* Component should be drawed into specified coords
*
* @param Drawer A drawer
* @param int $x1
* @param int $y1
* @param int $x2
* @param int $y2
* @param bool $aliasing Use anti-aliasing to draw the component ?
*/
/**
* Get space width in pixels
*
* @param int $width Component width
* @param int $height Component height
* @return array
*/
function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom);
}
}
registerClass('Component', TRUE);
?>

View File

@@ -0,0 +1,389 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
// Artichow configuration
// Some useful files
require_once ARTICHOW."/common.php";
require_once ARTICHOW."/Component.class.php";
require_once ARTICHOW."/Image.class.php";
require_once ARTICHOW."/inc/Grid.class.php";
require_once ARTICHOW."/inc/Tools.class.php";
require_once ARTICHOW."/inc/Drawer.class.php";
require_once ARTICHOW."/inc/Math.class.php";
require_once ARTICHOW."/inc/Tick.class.php";
require_once ARTICHOW."/inc/Axis.class.php";
require_once ARTICHOW."/inc/Legend.class.php";
require_once ARTICHOW."/inc/Mark.class.php";
require_once ARTICHOW."/inc/Label.class.php";
require_once ARTICHOW."/inc/Text.class.php";
require_once ARTICHOW."/inc/Color.class.php";
require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php";
/**
* A graph
*
* @package Artichow
*/
class awGraph extends awImage {
/**
* Graph name
*
* @var string
*/
var $name;
/**
* Cache timeout
*
* @var int
*/
var $timeout = 0;
/**
* Graph timing ?
*
* @var bool
*/
var $timing;
/**
* Components
*
* @var array
*/
var $components = array();
/**
* Some labels to add to the component
*
* @var array
*/
var $labels = array();
/**
* Graph title
*
* @var Label
*/
var $title;
/**
* Construct a new graph
*
* @param int $width Graph width
* @param int $height Graph height
* @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.
* @param int $timeout Cache timeout (unix timestamp)
*/
function awGraph($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
parent::awImage();
$this->setSize($width, $height);
if(ARTICHOW_CACHE) {
$this->name = $name;
$this->timeout = $timeout;
// Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache();
}
if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
awGraph::deleteFromCache($this->name);
} else {
header("Content-Type: image/".$type);
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit;
}
}
}
}
$this->title = new awLabel(
NULL,
new awTuffy(16),
NULL,
0
);
$this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM);
}
/**
* Delete a graph from the cache
*
* @param string $name Graph name
* @return bool TRUE on success, FALSE on failure
*/
function deleteFromCache($name) {
if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
}
}
}
/**
* Delete all graphs from the cache
*/
function deleteAllCache() {
if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) {
if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
}
}
}
}
/**
* Clean cache
*/
function cleanCache() {
if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
$name = ereg_replace(".*/(.*)\-time", "\\1", $file);
awGraph::deleteFromCache($name);
}
}
}
}
/**
* Enable/Disable Graph timing
*
* @param bool $timing
*/
function setTiming($timing) {
$this->timing = (bool)$timing;
}
/**
* Add a component to the graph
*
* @param &$component
*/
function add(&$component) {
$this->components[] = $component;
}
/**
* Add a label to the component
*
* @param &$label
* @param int $x Position on X axis of the center of the text
* @param int $y Position on Y axis of the center of the text
*/
function addLabel(&$label, $x, $y) {
$this->labels[] = array(
$label, $x, $y
);
}
/**
* Add a label to the component with aboslute position
*
* @param &$label
* @param $point Text position
*/
function addAbsLabel(&$label, $point) {
$this->labels[] = array(
$label, $point
);
}
/**
* Build the graph and draw component on it
* Image is sent to the user browser
*
* @param string $file Save the image in the specified file. Let it null to print image to screen.
*/
function draw($file = NULL) {
if($this->timing) {
$time = microtimeFloat();
}
$this->create();
foreach($this->components as $component) {
$this->drawComponent($component);
}
$this->drawTitle();
$this->drawShadow();
$this->drawLabels();
if($this->timing) {
$this->drawTiming(microtimeFloat() - $time);
}
if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start();
}
$this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable");
}
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data);
$file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean();
echo $data;
}
}
function drawLabels() {
$drawer = $this->getDrawer();
foreach($this->labels as $array) {
if(count($array) === 3) {
// Text in relative position
list($label, $x, $y) = $array;
$point = new awPoint(
$x * $this->width,
$y * $this->height
);
} else {
// Text in absolute position
list($label, $point) = $array;
}
$label->draw($drawer, $point);
}
}
function drawTitle() {
$drawer = $this->getDrawer();
$point = new awPoint(
$this->width / 2,
10
);
$this->title->draw($drawer, $point);
}
function drawTiming($time) {
$drawer = $this->getDrawer();
$label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(LABEL_LEFT, LABEL_TOP);
$label->border->show();
$label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
}
function cleanGraphCache($file) {
list(
$time,
$type
) = explode("\n", file_get_contents($file));
$time = (int)$time;
if($time !== 0 and $time < time()) {
return NULL;
} else {
return $type;
}
}
}
registerClass('Graph');
/*
* To preserve PHP 4 compatibility
*/
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
}
?>

View File

@@ -0,0 +1,421 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("IMAGE_JPEG", 1);
define("IMAGE_PNG", 2);
define("IMAGE_GIF", 3);
/* </php4> */
/*
* Check for GD2
*/
if(function_exists('imagecreatetruecolor') === FALSE) {
trigger_error("You must compile PHP with GD2 support to use Artichow", E_USER_ERROR);
}
require_once ARTICHOW."/inc/Shadow.class.php";
require_once ARTICHOW."/inc/Border.class.php";
/**
* An image for a graph
*
* @package Artichow
*/
class awImage {
/**
* Graph width
*
* @var int
*/
var $width;
/**
* Graph height
*
* @var int
*/
var $height;
/**
* Use anti-aliasing ?
*
* @var bool
*/
var $antiAliasing = FALSE;
/**
* Image format
*
* @var int
*/
var $format = IMAGE_PNG;
/**
* Image background color
*
* @var Color
*/
var $background;
/**
* GD resource
*
* @var resource
*/
var $resource;
/**
* Image drawer
*
* @var Drawer
*/
var $drawer;
/**
* Shadow
*
* @var Shadow
*/
var $shadow;
/**
* Image border
*
* @var Border
*/
var $border;
/**
* Use JPEG for image
*
* @var int
*/
/**
* Use PNG for image
*
* @var int
*/
/**
* Use GIF for image
*
* @var int
*/
/**
* Build the image
*/
function awImage() {
$this->background = new awColor(255, 255, 255);
$this->shadow = new awShadow(SHADOW_RIGHT_BOTTOM);
$this->border = new awBorder;
}
/**
* Get drawer of the image
*
* @param int $w Drawer width (from 0 to 1) (default to 1)
* @param int $h Drawer height (from 0 to 1) (default to 1)
* @param float $x Position on X axis of the center of the drawer (default to 0.5)
* @param float $y Position on Y axis of the center of the drawer (default to 0.5)
* @return Drawer
*/
function getDrawer($w = 1, $h = 1, $x = 0.5, $y = 0.5) {
$this->create();
$this->drawer->setSize($w, $h);
$this->drawer->setPosition($x, $y);
return $this->drawer;
}
/**
* Change the image size
*
* @var int $width Image width
* @var int $height Image height
*/
function setSize($width, $height) {
if($width !== NULL) {
$this->width = (int)$width;
}
if($height !== NULL) {
$this->height = (int)$height;
}
}
/**
* Change image background color
*
* @param $color
*/
function setBackgroundColor($color) {
$this->background = $color;
}
/**
* Change image background gradient
*
* @param $gradient
*/
function setBackgroundGradient($gradient) {
$this->background = $gradient;
}
/**
* Can we use anti-aliasing ?
*
* @var bool $bool
*/
function setAntiAliasing($bool) {
$this->antiAliasing = (bool)$bool;
}
/**
* Change image format
*
* @var int $format New image format
*/
function setFormat($format) {
if($format === IMAGE_JPEG or $format === IMAGE_PNG or $format === IMAGE_GIF) {
$this->format = $format;
}
}
/**
* Create a new awimage
*/
function create() {
if($this->resource === NULL) {
// Create image
$this->resource = imagecreatetruecolor($this->width, $this->height);
if(!$this->resource) {
trigger_error("Unable to create a graph", E_USER_ERROR);
}
imagealphablending($this->resource, TRUE);
if($this->antiAliasing and function_exists('imageantialias')) {
imageantialias($this->resource, TRUE);
}
$this->drawer = new awDrawer($this->resource);
$this->drawer->setImageSize($this->width, $this->height);
// Original color
$this->drawer->filledRectangle(
new awWhite,
new awLine(
new awPoint(0, 0),
new awPoint($this->width, $this->height)
)
);
$shadow = $this->shadow->getSpace();
$p1 = new awPoint($shadow->left, $shadow->top);
$p2 = new awPoint($this->width - $shadow->right - 1, $this->height - $shadow->bottom - 1);
// Draw image background
$this->drawer->filledRectangle($this->background, new awLine($p1, $p2));
$this->background->free();
// Draw image border
$this->border->rectangle($this->drawer, $p1, $p2);
}
}
/**
* Draw a component on the image
*
* @var &$component A component
*/
function drawComponent(&$component) {
$shadow = $this->shadow->getSpace(); // Image shadow
$border = $this->border->visible() ? 1 : 0; // Image border size
$drawer = $this->drawer;
$drawer->setImageSize(
$this->width - $shadow->left - $shadow->right - $border * 2,
$this->height - $shadow->top - $shadow->bottom - $border * 2
);
// No absolute size specified
if($component->w === NULL and $component->h === NULL) {
list($width, $height) = $drawer->setSize($component->width, $component->height);
// Set component size in pixels
$component->setAbsSize($width, $height);
} else {
$drawer->setAbsSize($component->w, $component->h);
}
if($component->top !== NULL and $component->left !== NULL) {
$drawer->setAbsPosition(
$border + $shadow->left + $component->left,
$border + $shadow->top + $component->top
);
} else {
$drawer->setPosition($component->x, $component->y);
}
$drawer->movePosition($border + $shadow->left, $border + $shadow->top);
list($x1, $y1, $x2, $y2) = $component->getPosition();
$component->init($drawer);
$component->drawComponent($drawer, $x1, $y1, $x2, $y2, $this->antiAliasing);
$component->drawEnvelope($drawer, $x1, $y1, $x2, $y2);
$component->finalize($drawer);
}
function drawShadow() {
$drawer = $this->getDrawer();
$this->shadow->draw(
$drawer,
new awPoint(0, 0),
new awPoint($this->width, $this->height),
SHADOW_IN
);
}
/**
* Send the image into a file or to the user browser
*
* @var string $file Save image into a file if you provide a file name
*/
function send($file = NULL) {
// Test if format is available
if((imagetypes() & $this->format) === FALSE) {
trigger_error("Format '".$this->format."' is not available on your system. Check that your PHP has been compiled with the good libraries.");
}
// Get some infos about this image
switch($this->format) {
case IMAGE_JPEG :
$function = 'imagejpeg';
break;
case IMAGE_PNG :
$function = 'imagepng';
break;
case IMAGE_GIF :
$function = 'imagegif';
break;
}
// Create image
if($file !== NULL) {
$function($this->resource, $file);
} else {
// Send headers to the browser
if(headers_sent() === FALSE) {
header("Content-type: image/".$this->getFormat());
}
$function($this->resource);
}
}
function getFormat() {
switch($this->format) {
case IMAGE_JPEG :
return 'jpeg';
case IMAGE_PNG :
return 'png';
case IMAGE_GIF :
return 'gif';
}
}
}
registerClass('Image');
/**
* Load an image from a file
*
* @package Artichow
*/
class awFileImage extends awImage {
/**
* Build a new awimage
*
* @param string $file Image file name
*/
function awFileImage($file) {
$image = @getimagesize($file);
if($image and in_array($image[2], array(2, 3))) {
$this->setSize($image[0], $image[1]);
switch($image[2]) {
case 2 :
$this->resource = imagecreatefromjpeg($file);
break;
case 3 :
$this->resource = imagecreatefrompng($file);
break;
}
$this->drawer = new awDrawer($this->resource);
$this->drawer->setImageSize($this->width, $this->height);
} else {
trigger_error("Artichow does not support this image (must be in PNG or JPEG)", E_USER_ERROR);
}
}
}
registerClass('FileImage');
?>

View File

@@ -0,0 +1,596 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/* <php4> */
define("LINEPLOT_LINE", 0);
define("LINEPLOT_MIDDLE", 1);
/* </php4> */
/**
* LinePlot
*
* @package Artichow
*/
class awLinePlot extends awPlot {
/**
* Add marks to your line plot
*
* @var Mark
*/
var $mark;
/**
* Labels on your line plot
*
* @var Label
*/
var $label;
/**
* Filled areas
*
* @var bool
*/
var $areas = array();
/**
* Is the line hidden
*
* @var bool
*/
var $lineHide = FALSE;
/**
* Line color
*
* @var Color
*/
var $lineColor;
/**
* Line mode
*
* @var int
*/
var $lineMode = LINEPLOT_LINE;
/**
* Line type
*
* @var int
*/
var $lineStyle = LINE_SOLID;
/**
* Line thickness
*
* @var int
*/
var $lineThickness = 1;
/**
* Line background
*
* @var Color, Gradient
*/
var $lineBackground;
/**
* Line mode
*
* @var int
*/
/**
* Line in the middle
*
* @var int
*/
/**
* Construct a new awLinePlot
*
* @param array $values Some numeric values for Y axis
* @param int $mode
*/
function awLinePlot($values, $mode = LINEPLOT_LINE) {
parent::awPlot();
$this->mark = new awMark;
$this->label = new awLabel;
$this->lineMode = (int)$mode;
$this->setValues($values);
}
/**
* Hide line
*
* @param bool $hide
*/
function hideLine($hide) {
$this->lineHide = (bool)$hide;
}
/**
* Add a filled area
*
* @param int $start Begining of the area
* @param int $end End of the area
* @param mixed $background Background color or gradient of the area
*/
function setFilledArea($start, $stop, $background) {
if($stop <= $start) {
trigger_error("End position can not be greater than begin position in awLinePlot::setFilledArea()", E_USER_ERROR);
}
$this->areas[] = array((int)$start, (int)$stop, $background);
}
/**
* Change line color
*
* @param $color
*/
function setColor($color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Change line background color
*
* @param $color
*/
function setFillColor($color) {
$this->lineBackground = $color;
}
/**
* Change line background gradient
*
* @param $gradient
*/
function setFillGradient($gradient) {
$this->lineBackground = $gradient;
}
/**
* Get the line thickness
*
* @return int
*/
function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
function getLegendLineColor() {
return $this->lineColor;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
function getLegendBackground() {
return $this->lineBackground;
}
/**
* Get a mark object
*
* @return Mark
*/
function getLegendMark() {
return $this->mark;
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
$max = $this->getRealYMax();
$min = $this->getRealYMin();
// Get start and stop values
list($start, $stop) = $this->getLimit();
if($this->lineMode === LINEPLOT_MIDDLE) {
$inc = $this->xAxis->getDistance(0, 1) / 2;
} else {
$inc = 0;
}
// Build the polygon
$polygon = new awPolygon;
for($key = $start; $key <= $stop; $key++) {
$value = $this->datay[$key];
if($value !== NULL) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
$p = $p->move($inc, 0);
$polygon->set($key, $p);
}
}
// Draw backgrounds
if(is_a($this->lineBackground, 'awColor') or is_a($this->lineBackground, 'awGradient')) {
$backgroundPolygon = new awPolygon;
$p = $this->xAxisPoint($start);
$p = $p->move($inc, 0);
$backgroundPolygon->append($p);
// Add others points
foreach($polygon->all() as $point) {
$backgroundPolygon->append($point);
}
$p = $this->xAxisPoint($stop);
$p = $p->move($inc, 0);
$backgroundPolygon->append($p);
// Draw polygon background
$drawer->filledPolygon($this->lineBackground, $backgroundPolygon);
}
$this->drawArea($drawer, $polygon);
// Draw line
$prev = NULL;
// Line color
if($this->lineHide === FALSE) {
if($this->lineColor === NULL) {
$this->lineColor = new awColor(0, 0, 0);
}
foreach($polygon->all() as $point) {
if($prev !== NULL) {
$drawer->line(
$this->lineColor,
new awLine(
$prev,
$point,
$this->lineStyle,
$this->lineThickness
)
);
}
$prev = $point;
}
$this->lineColor->free();
}
// Draw marks and labels
foreach($polygon->all() as $key => $point) {
$this->mark->draw($drawer, $point);
$this->label->draw($drawer, $point, $key);
}
}
function drawArea($drawer, &$polygon) {
$starts = array();
foreach($this->areas as $area) {
list($start) = $area;
$starts[$start] = TRUE;
}
// Draw filled areas
foreach($this->areas as $area) {
list($start, $stop, $background) = $area;
$polygonArea = new awPolygon;
$p = $this->xAxisPoint($start);
$polygonArea->append($p);
for($i = $start; $i <= $stop; $i++) {
$p = $polygon->get($i);
if($i === $stop and array_key_exists($stop, $starts)) {
$p = $p->move(-1, 0);
}
$polygonArea->append($p);
}
$p = $this->xAxisPoint($stop);
if(array_key_exists($stop, $starts)) {
$p = $p->move(-1, 0);
}
$polygonArea->append($p);
// Draw area
$drawer->filledPolygon($background, $polygonArea);
}
}
function getXAxisNumber() {
if($this->lineMode === LINEPLOT_MIDDLE) {
return count($this->datay) + 1;
} else {
return count($this->datay);
}
}
function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
function getXCenter() {
return ($this->lineMode === LINEPLOT_MIDDLE);
}
}
registerClass('LinePlot');
/**
* Simple LinePlot
* Useful to draw simple horizontal lines
*
* @package Artichow
*/
class awSimpleLinePlot extends awPlot {
/**
* Line color
*
* @var Color
*/
var $lineColor;
/**
* Line start
*
* @var int
*/
var $lineStart;
/**
* Line stop
*
* @var int
*/
var $lineStop;
/**
* Line value
*
* @var flaot
*/
var $lineValue;
/**
* Line mode
*
* @var int
*/
var $lineMode = LINEPLOT_LINE;
/**
* Line type
*
* @var int
*/
var $lineStyle = LINE_SOLID;
/**
* Line thickness
*
* @var int
*/
var $lineThickness = 1;
/**
* Line mode
*
* @var int
*/
/**
* Line in the middle
*
* @var int
*/
/**
* Construct a new awLinePlot
*
* @param float $value A Y value
* @param int $start Line start index
* @param int $stop Line stop index
* @param int $mode Line mode
*/
function awSimpleLinePlot($value, $start, $stop, $mode = LINEPLOT_LINE) {
parent::awPlot();
$this->lineMode = (int)$mode;
$this->lineStart = (int)$start;
$this->lineStop = (int)$stop;
$this->lineValue = (float)$value;
$this->lineColor = new awColor(0, 0, 0);
}
/**
* Change line color
*
* @param $color
*/
function setColor($color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Get the line thickness
*
* @return int
*/
function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
function getLegendLineColor() {
return $this->lineColor;
}
function getLegendBackground() {
return NULL;
}
function getLegendMark() {
return NULL;
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
if($this->lineMode === LINEPLOT_MIDDLE) {
$inc = $this->xAxis->getDistance(0, 1) / 2;
} else {
$inc = 0;
}
$p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
$p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
$drawer->line(
$this->lineColor,
new awLine(
$p1->move($inc, 0),
$p2->move($inc, 0),
$this->lineStyle,
$this->lineThickness
)
);
$this->lineColor->free();
}
function getXAxisNumber() {
if($this->lineMode === LINEPLOT_MIDDLE) {
return count($this->datay) + 1;
} else {
return count($this->datay);
}
}
function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
function getXCenter() {
return ($this->lineMode === LINEPLOT_MIDDLE);
}
}
registerClass('SimpleLinePlot');
?>

View File

@@ -0,0 +1,439 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Component.class.php";
/**
* A mathematic function
*
* @package Artichow
*/
class awMathFunction {
/**
* Function line
*
* @var Line
*/
var $line;
/**
* Marks for your plot
*
* @var Mark
*/
var $mark;
/**
* Callback function
*
* @var string
*/
var $f;
/**
* Start the drawing from this value
*
* @var float
*/
var $fromX;
/**
* Stop the drawing at this value
*
* @var float
*/
var $toX;
/**
* Line color
*
* @var Color
*/
var $color;
/**
* Construct the function
*
* @param string $f Callback function
* @param float $fromX
* @param float $toX
*/
function awMathFunction($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine;
$this->mark = new awMark;
$this->color = new awBlack;
}
/**
* Change line color
*
* @param $color A new awcolor
*/
function setColor($color) {
$this->color = $color;
}
/**
* Get line color
*
* @return Color
*/
function getColor() {
return $this->color;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
function getLegendBackground() {
}
/**
* Get the line thickness
*
* @return NULL
*/
function getLegendLineThickness() {
return $this->line->getThickness();
}
/**
* Get the line type
*
* @return NULL
*/
function getLegendLineStyle() {
return $this->line->getStyle();
}
/**
* Get the color of line
*
* @return NULL
*/
function getLegendLineColor() {
return $this->color;
}
/**
* Get a mark object
*
* @return NULL
*/
function getLegendMark() {
return $this->mark;
}
}
registerClass('MathFunction');
/**
* For mathematics functions
*
* @package Artichow
*/
class awMathPlot extends awComponent {
/**
* Functions
*
* @var array
*/
var $functions = array();
/**
* Grid properties
*
* @var Grid
*/
var $grid;
/**
* X axis
*
* @var Axis
*/
var $xAxis;
/**
* Y axis
*
* @var Axis
*/
var $yAxis;
/**
* Extremum
*
* @var Side
*/
var $extremum = NULL;
/**
* Interval
*
* @var float
*/
var $interval = 1;
/**
* Build the plot
*
* @param int $xMin Minimum X value
* @param int $xMax Maximum X value
* @param int $yMax Maximum Y value
* @param int $yMin Minimum Y value
*/
function awMathPlot($xMin, $xMax, $yMax, $yMin) {
parent::awComponent();
$this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid;
// Hide grid by default
$this->grid->hide(TRUE);
// Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis
$this->xAxis = new awAxis;
$this->xAxis->setTickStyle(TICK_IN);
$this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis);
$this->yAxis = new awAxis;
$this->yAxis->setTickStyle(TICK_IN);
$this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis);
}
function initAxis(&$axis) {
$axis->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7));
}
/**
* Interval to calculate values
*
* @param float $interval
*/
function setInterval($interval) {
$this->interval = (float)$interval;
}
/**
* Add a formula f(x)
*
* @param &$function
* @param string $name Name for the legend (can be NULL if you don't want to set a legend)
* @param int $type Type for the legend
*/
function add(&$function, $name = NULL, $type = LEGEND_LINE) {
$this->functions[] = $function;
if($name !== NULL) {
$this->legend->add($function, $name, $type);
}
}
function init($drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, LABEL_BOTTOM);
$this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(LABEL_RIGHT);
$this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number);
}
if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number);
}
// Set ticks
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
// Set axis labels
$labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->xAxis->label->set($labels);
$labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->yAxis->label->set($labels);
parent::init($drawer);
// Create the grid
$this->createGrid();
// Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
}
function drawEnvelope($drawer) {
// Draw axis
$this->xAxis->draw($drawer);
$this->yAxis->draw($drawer);
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) {
$f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
if($old !== NULL) {
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
) {
$drawer->line(
$function->getColor(),
$line
);
}
}
$old = $p;
}
// Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
) {
$drawer->line(
$function->getColor(),
$line
);
}
}
}
}
function createGrid() {
// Horizontal lines of the grid
$major = $this->yAxis->tick('major');
$interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1;
$h = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number;
}
}
// Vertical lines
$major = $this->xAxis->tick('major');
$interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1;
$w = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
if($i%$interval === 0) {
$w[] = $i / $number;
}
}
}
$this->grid->setGrid($w, $h);
}
}
registerClass('MathPlot');
?>

View File

@@ -0,0 +1,97 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* All patterns must derivate from this class
*
* @package Artichow
*/
class awPattern {
/**
* Pattern arguments
*
* @var array
*/
var $args = array();
/**
* Load a pattern
*
* @param string $pattern Pattern name
* @return Component
*/
function get($pattern) {
$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
if(is_file($file)) {
require_once $file;
$class = $pattern.'Pattern';
if(class_exists($class)) {
return new $class;
} else {
trigger_error("Class '".$class."' does not exist", E_USER_ERROR);
}
} else {
trigger_error("Pattern '".$pattern."' does not exist", E_USER_ERROR);
}
}
/**
* Change pattern argument
*
* @param string $name Argument name
* @param mixed $value Argument value
*/
function setArg($name, $value) {
if(is_string($name)) {
$this->args[$name] = $value;
}
}
/**
* Get an argument
*
* @param string $name
* @param mixed $default Default value if the argument does not exist (default to NULL)
* @return mixed Argument value
*/
function getArg($name, $default = NULL) {
if(array_key_exists($name, $this->args)) {
return $this->args[$name];
} else {
return $default;
}
}
/**
* Change several arguments
*
* @param array $args New arguments
*/
function setArgs($args) {
if(is_array($args)) {
foreach($args as $name => $value) {
$this->setArg($name, $value);
}
}
}
}
registerClass('Pattern', TRUE);
?>

View File

@@ -0,0 +1,680 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Component.class.php";
/* <php4> */
define("PIE_DARK", 1);
define("PIE_COLORED", 2);
define("PIE_AQUA", 3);
define("PIE_EARTH", 4);
/* </php4> */
/**
* Pie
*
* @package Artichow
*/
class awPie extends awComponent {
/**
* A dark theme for pies
*
*
* @var int
*/
/**
* A colored theme for pies
*
* @var int
*/
/**
* A water theme for pies
*
* @var int
*/
/**
* A earth theme for pies
*
* @var int
*/
/**
* Pie values
*
* @var array
*/
var $values;
/**
* Pie colors
*
* @var array
*/
var $colors;
/**
* Pie legend
*
* @var array
*/
var $legendValues = array();
/**
* Intensity of the 3D effect
*
* @var int
*/
var $size;
/**
* Border color
*
* @var Color
*/
var $border;
/**
* Pie explode
*
* @var array
*/
var $explode = array();
/**
* Initial angle
*
* @var int
*/
var $angle = 0;
/**
* Labels precision
*
* @var int
*/
var $precision;
/**
* Labels number
*
* @var int
*/
var $number;
/**
* Labels minimum
*
* @var int
*/
var $minimum;
/**
* Labels position
*
* @var int
*/
var $position = 15;
/**
* Labels of your pie
*
* @var Label
*/
var $label;
/**
* Build the plot
*
* @param array $values Pie values
*/
function awPie($values, $colors = PIE_COLORED) {
$this->setValues($values);
if(is_array($colors)) {
$this->colors = $colors;
} else {
switch($colors) {
case PIE_AQUA :
$this->colors = array(
new awColor(131, 220, 215),
new awColor(131, 190, 215),
new awColor(131, 160, 215),
new awColor(160, 140, 215),
new awColor(190, 131, 215),
new awColor(220, 131, 215)
);
break;
case PIE_EARTH :
$this->colors = array(
new awColor(97, 179, 110),
new awColor(130, 179, 97),
new awColor(168, 179, 97),
new awColor(179, 147, 97),
new awColor(179, 108, 97),
new awColor(99, 107, 189),
new awColor(99, 165, 189)
);
break;
case PIE_DARK :
$this->colors = array(
new awColor(140, 100, 170),
new awColor(130, 170, 100),
new awColor(160, 160, 120),
new awColor(150, 110, 140),
new awColor(130, 150, 160),
new awColor(90, 170, 140)
);
break;
default :
$this->colors = array(
new awColor(187, 213, 151),
new awColor(223, 177, 151),
new awColor(111, 186, 132),
new awColor(197, 160, 230),
new awColor(165, 169, 63),
new awColor(218, 177, 89),
new awColor(116, 205, 121),
new awColor(200, 201, 78),
new awColor(127, 205, 177),
new awColor(205, 160, 160),
new awColor(190, 190, 190)
);
break;
}
}
parent::awComponent();
$this->label = new awLabel;
$this->label->setCallbackFunction('callbackPerCent');
}
/**
* Change legend values
*
* @param array $legend An array of values for each part of the pie
*/
function setLegend($legend) {
$this->legendValues = (array)$legend;
}
/**
* Set a border all around the pie
*
* @param $color A color for the border
*/
function setBorder($color) {
$this->border = $color;
}
/**
* Change 3D effect intensity
*
* @param int $size Effect size
*/
function set3D($size) {
$this->size = (int)$size;
}
/**
* Change initial angle
*
* @param int $angle New angle in degrees
*/
function setStartAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Change label precision
*
* @param int $precision New precision
*/
function setLabelPrecision($precision) {
$this->precision = (int)$precision;
}
/**
* Change label position
*
* @param int $position New position in pixels
*/
function setLabelPosition($position) {
$this->position = (int)$position;
}
/**
* Change label number
*
* @param int $number New number
*/
function setLabelNumber($number) {
$this->number = is_null($number) ? $number : (int)$number;
}
/**
* Change label minimum
*
* @param int $minimum New minimum
*/
function setLabelMinimum($minimum) {
$this->minimum = is_null($minimum) ? $minimum : (int)$minimum;
}
/**
* Change Pie explode
*
* @param array $explode
*/
function explode($explode) {
$this->explode = (array)$explode;
}
function drawEnvelope($drawer) {
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->values);
$sum = array_sum($this->values);
$width = $x2 - $x1;
$height = $y2 - $y1;
if($aliasing) {
$x = $width / 2;
$y = $height / 2;
} else {
$x = $width / 2 + $x1;
$y = $height / 2 + $y1;
}
$position = $this->angle;
$values = array();
$parts = array();
$angles = 0;
if($aliasing) {
$side = new awSide(0, 0, 0, 0);
}
foreach($this->values as $key => $value) {
$angle = ($value / $sum * 360);
if($key === $count - 1) {
$angle = 360 - $angles;
}
$angles += $angle;
if(array_key_exists($key, $this->explode)) {
$middle = 360 - ($position + $angle / 2);
$posX = $this->explode[$key] * cos($middle * M_PI / 180);
$posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
if($aliasing) {
$explode = new awPoint(
$posX * 2,
$posY * 2
);
$side->set(
max($side->left, $posX * -2),
max($side->right, $posX * 2),
max($side->top, $posY * -2),
max($side->bottom, $posY * 2)
);
} else {
$explode = new awPoint(
$posX,
$posY
);
}
} else {
$explode = new awPoint(0, 0);
}
$values[$key] = array(
$position, ($position + $angle), $explode
);
$color = $this->colors[$key % count($this->colors)];
$parts[$key] = new awPiePart($color);
// Add part to the legend
$legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
$this->legend->add($parts[$key], $legend, LEGEND_BACKGROUND);
$position += $angle;
}
if($aliasing) {
$mainDrawer = $drawer;
$x *= 2;
$y *= 2;
$width *= 2;
$height *= 2;
$this->size *= 2;
$image = new awImage;
$image->border->hide();
$image->setSize(
$width + $side->left + $side->right,
$height + $side->top + $side->bottom + $this->size + 1 /* bugs.php.net ! */
);
$drawer = $image->getDrawer(
$width / $image->width,
$height / $image->height,
($width / 2 + $side->left) / $image->width,
($height / 2 + $side->top) / $image->height
);
}
// Draw 3D effect
for($i = $this->size; $i > 0; $i--) {
foreach($values as $key => $value) {
$color = $this->colors[$key % count($this->colors)];
$color->brightness(-50);
list($from, $to, $explode) = $value;
$drawer->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
$color->free();
unset($color);
if(is_a($this->border, 'awColor')) {
$point = $explode->move($x, $y);
if($i === $this->size) {
$drawer->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
}
}
}
}
foreach($values as $key => $value) {
$color = $this->colors[$key % count($this->colors)];
list($from, $to, $explode) = $value;
$drawer->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
if(is_a($this->border, 'awColor')) {
$point = $explode->move($x, $y);
$drawer->arc($this->border, $point, $width, $height, $from, $to);
}
}
if($aliasing) {
$x = $x / 2 + $x1;
$y = $y / 2 + $y1;
$width /= 2;
$height /= 2;
$this->size /= 2;
foreach($values as $key => $value) {
$old = $values[$key][2];
$values[$key][2] = new awPoint(
$old->x / 2, $old->y / 2
);
}
$mainDrawer->copyResizeImage(
$image,
new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2),
new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height/ 2),
new awPoint(0, 0),
new awPoint($image->width, $image->height),
TRUE
);
$drawer = $mainDrawer;
}
// Get labels values
$pc = array();
foreach($this->values as $key => $value) {
$pc[$key] = round($value / $sum * 100, $this->precision);
}
if($this->label->count() === 0) { // Check that there is no user defined values
$this->label->set($pc);
}
$position = 0;
foreach($pc as $key => $value) {
// Limit number of labels to display
if($position === $this->number) {
break;
}
if(is_null($this->minimum) === FALSE and $value < $this->minimum) {
continue;
}
$position++;
list($from, $to, $explode) = $values[$key];
$angle = $from + ($to - $from) / 2;
$angleRad = (360 - $angle) * M_PI / 180;
$point = new awPoint(
$x + $explode->x + cos($angleRad) * ($width / 2 + $this->position),
$y + $explode->y - sin($angleRad) * ($height / 2 + $this->position)
);
$angle %= 360;
// We don't display labels on the 3D effect
if($angle > 0 and $angle < 180) {
$point = $point->move(0, -1 * sin($angleRad) * $this->size);
}
if($angle >= 45 and $angle < 135) {
$this->label->setAlign(LABEL_CENTER, LABEL_BOTTOM);
} else if($angle >= 135 and $angle < 225) {
$this->label->setAlign(LABEL_RIGHT, LABEL_MIDDLE);
} else if($angle >= 225 and $angle < 315) {
$this->label->setAlign(LABEL_CENTER, LABEL_TOP);
} else {
$this->label->setAlign(LABEL_LEFT, LABEL_MIDDLE);
}
$this->label->draw(
$drawer,
$point,
$key
);
}
}
/**
* Return margins around the component
*
* @return array Left, right, top and bottom margins
*/
function getMargin() {
// Get axis informations
$leftAxis = $this->padding->left;
$rightAxis = $this->padding->right;
$topAxis = $this->padding->top;
$bottomAxis = $this->padding->bottom;
return array($leftAxis, $rightAxis, $topAxis, $bottomAxis);
}
/**
* Change values of Y axis
* This method ignores not numeric values
*
* @param array $values
*/
function setValues($values) {
$this->checkArray($values);
$this->values = $values;
}
/**
* Return values of Y axis
*
* @return array
*/
function getValues() {
return $this->values;
}
function checkArray(&$array) {
if(is_array($array) === FALSE) {
trigger_error("You tried to set values that are not an array");
}
foreach($array as $key => $value) {
if(is_numeric($value) === FALSE) {
unset($array[$key]);
}
}
if(count($array) < 1) {
trigger_error("Your graph must have at least 1 value");
}
}
}
registerClass('Pie');
/**
* Pie
*
* @package Artichow
*/
class awPiePart {
/**
* Pie part color
*
* @var Color
*/
var $color;
/**
* Build a new awPiePart
*
* @param $color Pie part color
*/
function awPiePart($color) {
$this->color = $color;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
function getLegendBackground() {
return $this->color;
}
/**
* Get the line thickness
*
* @return NULL
*/
function getLegendLineThickness() {
}
/**
* Get the line type
*
* @return NULL
*/
function getLegendLineStyle() {
}
/**
* Get the color of line
*
* @return NULL
*/
function getLegendLineColor() {
}
/**
* Get a mark object
*
* @return NULL
*/
function getLegendMark() {
}
}
registerClass('PiePart');
function callbackPerCent($value) {
return $value.'%';
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,303 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/**
* ScatterPlot
*
* @package Artichow
*/
class awScatterPlot extends awPlot {
/**
* Add marks to the scatter plot
*
* @var Mark
*/
var $mark;
/**
* Labels on the plot
*
* @var Label
*/
var $label;
/**
* Link points ?
*
* @var bool
*/
var $link = FALSE;
/**
* Display impulses
*
* @var bool
*/
var $impulse = NULL;
/**
* Link NULL points ?
*
* @var bool
*/
var $linkNull = FALSE;
/**
* Line color
*
* @var Color
*/
var $lineColor;
/**
* Line type
*
* @var int
*/
var $lineStyle = LINE_SOLID;
/**
* Line thickness
*
* @var int
*/
var $lineThickness = 1;
/**
* Construct a new awScatterPlot
*
* @param array $datay Numeric values for Y axis
* @param array $datax Numeric values for X axis
* @param int $mode
*/
function awScatterPlot($datay, $datax = NULL) {
parent::awPlot();
// Defaults marks
$this->mark = new awMark;
$this->mark->setType(MARK_CIRCLE);
$this->mark->setSize(7);
$this->mark->border->show();
$this->label = new awLabel;
$this->setValues($datay, $datax);
$this->setColor(new awBlack);
}
/**
* Display plot as impulses
*
* @param $impulse Impulses color (or NULL to disable impulses)
*/
function setImpulse($color) {
$this->impulse = $color;
}
/**
* Link scatter plot points
*
* @param bool $link
* @param $color Line color (default to black)
*/
function link($link, $color = NULL) {
$this->link = (bool)$link;
if(is_a($color, 'awColor')) {
$this->setColor($color);
}
}
/**
* Ignore null values for Y data and continue linking
*
* @param bool $link
*/
function linkNull($link) {
$this->linkNull = (bool)$link;
}
/**
* Change line color
*
* @param $color
*/
function setColor($color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Get the line thickness
*
* @return int
*/
function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
function getLegendLineColor() {
return $this->lineColor;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
function getLegendBackground() {
return NULL;
}
/**
* Get a mark object
*
* @return Mark
*/
function getLegendMark() {
return $this->mark;
}
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->datay);
// Get start and stop values
list($start, $stop) = $this->getLimit();
// Build the polygon
$polygon = new awPolygon;
for($key = 0; $key < $count; $key++) {
$x = $this->datax[$key];
$y = $this->datay[$key];
if($y !== NULL) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
$polygon->set($key, $p);
} else if($this->linkNull === FALSE) {
$polygon->set($key, NULL);
}
}
// Link points if needed
if($this->link) {
$prev = NULL;
foreach($polygon->all() as $point) {
if($prev !== NULL and $point !== NULL) {
$drawer->line(
$this->lineColor,
new awLine(
$prev,
$point,
$this->lineStyle,
$this->lineThickness
)
);
}
$prev = $point;
}
$this->lineColor->free();
}
// Draw impulses
if(is_a($this->impulse, 'awColor')) {
foreach($polygon->all() as $key => $point) {
if($point !== NULL) {
$zero = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, 0)
);
$drawer->line(
$this->impulse,
new awLine(
$zero,
$point,
LINE_SOLID,
1
)
);
}
}
}
// Draw marks and labels
foreach($polygon->all() as $key => $point) {
$this->mark->draw($drawer, $point);
$this->label->draw($drawer, $point, $key);
}
}
function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
function getXCenter() {
return FALSE;
}
}
registerClass('ScatterPlot');
?>

View File

@@ -0,0 +1,102 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/*
* Get the minimum of an array and ignore non numeric values
*/
function array_min($array) {
if(is_array($array) and count($array) > 0) {
do {
$min = array_pop($array);
if(is_numeric($min === FALSE)) {
$min = NULL;
}
} while(count($array) > 0 and $min === NULL);
if($min !== NULL) {
$min = (float)$min;
}
foreach($array as $value) {
if(is_numeric($value) and (float)$value < $min) {
$min = (float)$value;
}
}
return $min;
}
return NULL;
}
/*
* Get the maximum of an array and ignore non numeric values
*/
function array_max($array) {
if(is_array($array) and count($array) > 0) {
do {
$max = array_pop($array);
if(is_numeric($max === FALSE)) {
$max = NULL;
}
} while(count($array) > 0 and $max === NULL);
if($max !== NULL) {
$max = (float)$max;
}
foreach($array as $value) {
if(is_numeric($value) and (float)$value > $max) {
$max = (float)$value;
}
}
return $max;
}
return NULL;
}
/*
* Register a class with the prefix in configuration file
*/
function registerClass($class, $abstract = FALSE) {
if(ARTICHOW_PREFIX === 'aw') {
return;
}
$abstract = '';
eval($abstract." class ".ARTICHOW_PREFIX.$class." extends aw".$class." { }");
}
/*
* Register an interface with the prefix in configuration file
*/
function registerInterface($interface) {
if(ARTICHOW_PREFIX === 'aw') {
return;
}
}
?>

View File

@@ -0,0 +1,769 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Handle axis
*
* @package Artichow
*/
class awAxis {
/**
* Axis line
*
* @var Line
*/
var $line;
/**
* Axis labels
*
* @var Label
*/
var $label;
/**
* Axis title
*
* @var Label
*/
var $title;
/**
* Title position
*
* @var float
*/
var $titlePosition = 0.5;
/**
* Labels number
*
* @var int
*/
var $labelNumber;
/**
* Axis ticks
*
* @var array
*/
var $ticks = array();
/**
* Axis and ticks color
*
* @var Color
*/
var $color;
/**
* Axis left and right padding
*
* @var Side
*/
var $padding;
/**
* Axis range
*
* @var array
*/
var $range;
/**
* Hide axis
*
* @var bool
*/
var $hide = FALSE;
/**
* Auto-scaling mode
*
* @var bool
*/
var $auto = TRUE;
/**
* Axis range callback function
*
* @var array
*/
var $rangeCallback = array(
'toValue' => 'toProportionalValue',
'toPosition' => 'toProportionalPosition'
);
/**
* Build the axis
*
* @param float $min Begin of the range of the axis
* @param float $max End of the range of the axis
*/
function awAxis($min = NULL, $max = NULL) {
$this->line = new awVector(
new awPoint(0, 0),
new awPoint(0, 0)
);
$this->label = new awLabel;
$this->padding = new awSide;
$this->title = new awLabel(
NULL,
NULL,
NULL,
0
);
$this->setColor(new awBlack);
if($min !== NULL and $max !== NULL) {
$this->setRange($min, $max);
}
}
/**
* Enable/disable auto-scaling mode
*
* @param bool $auto
*/
function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Get auto-scaling mode status
*
* @return bool
*/
function isAuto() {
return $this->auto;
}
/**
* Hide axis
*
* @param bool $hide
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show axis
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = !(bool)$show;
}
/**
* Return a tick object from its name
*
* @param string $name Tick object name
* @return Tick
*/
function tick($name) {
if(array_key_exists($name, $this->ticks)) {
return $tick = &$this->ticks[$name];
} else {
return NULL;
}
}
/**
* Add a tick object
*
* @param string $name Tick object name
* @param &$tick Tick object
*/
function addTick($name, &$tick) {
$this->ticks[$name] = &$tick;
}
/**
* Delete a tick object
*
* @param string $name Tick object name
*/
function deleteTick($name) {
if(array_key_exists($name, $this->ticks)) {
unset($this->ticks[$name]);
}
}
/**
* Hide all ticks
*
* @param bool $hide Hide or not ?
*/
function hideTicks($hide = TRUE) {
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->hide($hide);
}
}
/**
* Change ticks style
*
* @param int $style Ticks style
*/
function setTickStyle($style) {
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->setStyle($style);
}
}
/**
* Change ticks interval
*
* @param int $interval Ticks interval
*/
function setTickInterval($interval) {
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->setInterval($interval);
}
}
/**
* Change number of ticks relative to others ticks
*
* @param &$to Change number of theses ticks
* @param &$from Ticks reference
* @param float $number Number of ticks by the reference
*/
function setNumberByTick($to, $from, $number) {
$this->ticks[$to]->setNumberByTick($this->ticks[$from], $number);
}
/**
* Reverse ticks style
*/
function reverseTickStyle() {
foreach($this->ticks as $key => $tick) {
if($this->ticks[$key]->getStyle() === TICK_IN) {
$this->ticks[$key]->setStyle(TICK_OUT);
} else if($this->ticks[$key]->getStyle() === TICK_OUT) {
$this->ticks[$key]->setStyle(TICK_IN);
}
}
}
/**
* Change interval of labels
*
* @param int $interval Interval
*/
function setLabelInterval($interval) {
$this->auto(FALSE);
$this->setTickInterval($interval);
$this->label->setInterval($interval);
}
/**
* Change number of labels
*
* @param int $number Number of labels to display (can be NULL)
*/
function setLabelNumber($number) {
$this->auto(FALSE);
$this->labelNumber = is_null($number) ? NULL : (int)$number;
}
/**
* Get number of labels
*
* @return int
*/
function getLabelNumber() {
return $this->labelNumber;
}
/**
* Change precision of labels
*
* @param int $precision Precision
*/
function setLabelPrecision($precision) {
$this->auto(FALSE);
$function = 'axis'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
return sprintf("%.'.(int)$precision.'f", $value);
}');
$this->label->setCallbackFunction($function);
}
/**
* Change text of labels
*
* @param array $texts Some texts
*/
function setLabelText($texts) {
if(is_array($texts)) {
$this->auto(FALSE);
$function = 'axis'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
$texts = '.var_export($texts, TRUE).';
return isset($texts[$value]) ? $texts[$value] : \'?\';
}');
$this->label->setCallbackFunction($function);
}
}
/**
* Get the position of a point
*
* @param &$xAxis X axis
* @param &$yAxis Y axis
* @param $p Position of the point
* @return Point Position on the axis
*/
function toPosition(&$xAxis, &$yAxis, $p) {
$p1 = $xAxis->getPointFromValue($p->x);
$p2 = $yAxis->getPointFromValue($p->y);
return new awPoint(
round($p1->x),
round($p2->y)
);
}
/**
* Change title alignment
*
* @param int $alignment New Alignment
*/
function setTitleAlignment($alignment) {
switch($alignment) {
case LABEL_TOP :
$this->setTitlePosition(1);
$this->title->setAlign(NULL, LABEL_BOTTOM);
break;
case LABEL_BOTTOM :
$this->setTitlePosition(0);
$this->title->setAlign(NULL, LABEL_TOP);
break;
case LABEL_LEFT :
$this->setTitlePosition(0);
$this->title->setAlign(LABEL_LEFT);
break;
case LABEL_RIGHT :
$this->setTitlePosition(1);
$this->title->setAlign(LABEL_RIGHT);
break;
}
}
/**
* Change title position on the axis
*
* @param float $position A new awposition between 0 and 1
*/
function setTitlePosition($position) {
$this->titlePosition = (float)$position;
}
/**
* Change axis and axis title color
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
$this->title->setColor($color);
}
/**
* Change axis padding
*
* @param int $left Left padding in pixels
* @param int $right Right padding in pixels
*/
function setPadding($left, $right) {
$this->padding->set($left, $right);
}
/**
* Get axis padding
*
* @return Side
*/
function getPadding() {
return $this->padding;
}
/**
* Change axis range
*
* @param float $min
* @param float $max
*/
function setRange($min, $max) {
if($min !== NULL) {
$this->range[0] = (float)$min;
}
if($max !== NULL) {
$this->range[1] = (float)$max;
}
}
/**
* Get axis range
*
* @return array
*/
function getRange() {
return $this->range;
}
/**
* Change axis range callback function
*
* @param string $toValue Transform a position between 0 and 1 to a value
* @param string $toPosition Transform a value to a position between 0 and 1 on the axis
*/
function setRangeCallback($toValue, $toPosition) {
$this->rangeCallback = array(
'toValue' => (string)$toValue,
'toPosition' => (string)$toPosition
);
}
/**
* Center X values of the axis
*
* @param &$axis An axis
* @param float $value The reference value on the axis
*/
function setXCenter(&$axis, $value) {
// Check vector angle
if($this->line->isVertical() === FALSE) {
trigger_error("setXCenter() can only be used on vertical axes", E_USER_ERROR);
}
$p = $axis->getPointFromValue($value);
$this->line->setX(
$p->x,
$p->x
);
}
/**
* Center Y values of the axis
*
* @param &$axis An axis
* @param float $value The reference value on the axis
*/
function setYCenter(&$axis, $value) {
// Check vector angle
if($this->line->isHorizontal() === FALSE) {
trigger_error("setYCenter() can only be used on horizontal axes", E_USER_ERROR);
}
$p = $axis->getPointFromValue($value);
$this->line->setY(
$p->y,
$p->y
);
}
/**
* Get the distance between to values on the axis
*
* @param float $from The first value
* @param float $to The last value
* @return Point
*/
function getDistance($from, $to) {
$p1 = $this->getPointFromValue($from);
$p2 = $this->getPointFromValue($to);
return $p1->getDistance($p2);
}
/**
* Get a point on the axis from a value
*
* @param float $value
* @return Point
*/
function getPointFromValue($value) {
$callback = $this->rangeCallback['toPosition'];
list($min, $max) = $this->range;
$position = $callback($value, $min, $max);
return $this->getPointFromPosition($position);
}
/**
* Get a point on the axis from a position
*
* @param float $position A position between 0 and 1
* @return Point
*/
function getPointFromPosition($position) {
$vector = $this->getVector();
$angle = $vector->getAngle();
$size = $vector->getSize();
return $vector->p1->move(
cos($angle) * $size * $position,
-1 * sin($angle) * $size * $position
);
}
/**
* Draw axis
*
* @param $drawer A drawer
*/
function draw($drawer) {
if($this->hide) {
return;
}
$vector = $this->getVector();
// Draw axis ticks
$this->drawTicks($drawer, $vector);
// Draw axis line
$this->line($drawer);
// Draw labels
$this->drawLabels($drawer);
// Draw axis title
$p = $this->getPointFromPosition($this->titlePosition);
$this->title->draw($drawer, $p);
}
function autoScale() {
if($this->isAuto() === FALSE) {
return;
}
list($min, $max) = $this->getRange();
$interval = $max - $min;
if($interval > 0) {
$partMax = $max / $interval;
$partMin = $min / $interval;
} else {
$partMax = 0;
$partMin = 0;
}
$difference = log($interval) / log(10);
$difference = floor($difference);
$pow = pow(10, $difference);
if($pow > 0) {
$intervalNormalize = $interval / $pow;
} else {
$intervalNormalize = 0;
}
if($difference <= 0) {
$precision = $difference * -1 + 1;
if($intervalNormalize > 2) {
$precision--;
}
} else {
$precision = 0;
}
if($min != 0 and $max != 0) {
$precision++;
}
$this->setLabelPrecision($precision);
if($intervalNormalize <= 1.5) {
$intervalReal = 1.5;
$labelNumber = 4;
} else if($intervalNormalize <= 2) {
$intervalReal = 2;
$labelNumber = 5;
} else if($intervalNormalize <= 3) {
$intervalReal = 3;
$labelNumber = 4;
} else if($intervalNormalize <= 4) {
$intervalReal = 4;
$labelNumber = 5;
} else if($intervalNormalize <= 5) {
$intervalReal = 5;
$labelNumber = 6;
} else if($intervalNormalize <= 8) {
$intervalReal = 8;
$labelNumber = 5;
} else if($intervalNormalize <= 10) {
$intervalReal = 10;
$labelNumber = 6;
}
if($min == 0) {
$this->setRange(
$min,
$intervalReal * $pow
);
} else if($max == 0) {
$this->setRange(
$intervalReal * $pow * -1,
0
);
}
$this->setLabelNumber($labelNumber);
}
function line($drawer) {
$drawer->line(
$this->color,
$this->line
);
}
function drawTicks($drawer, &$vector) {
foreach($this->ticks as $tick) {
$tick->setColor($this->color);
$tick->draw($drawer, $vector);
}
}
function drawLabels($drawer) {
if($this->labelNumber !== NULL) {
list($min, $max) = $this->range;
$number = $this->labelNumber - 1;
if($number < 1) {
return;
}
$function = $this->rangeCallback['toValue'];
$labels = array();
for($i = 0; $i <= $number; $i++) {
$labels[] = $function($i / $number, $min, $max);
}
$this->label->set($labels);
}
$labels = $this->label->count();
for($i = 0; $i < $labels; $i++) {
$p = $this->getPointFromValue($this->label->get($i));
$this->label->draw($drawer, $p, $i);
}
}
function getVector() {
$angle = $this->line->getAngle();
// Compute paddings
$vector = new awVector(
$this->line->p1->move(
cos($angle) * $this->padding->left,
-1 * sin($angle) * $this->padding->left
),
$this->line->p2->move(
-1 * cos($angle) * $this->padding->right,
-1 * -1 * sin($angle) * $this->padding->right
)
);
return $vector;
}
function __clone() {
$this->label = $this->label;
$this->line = $this->line;
$this->title = $this->title;
foreach($this->ticks as $name => $tick) {
$this->ticks[$name] = $tick;
}
}
}
registerClass('Axis');
function toProportionalValue($position, $min, $max) {
return $min + ($max - $min) * $position;
}
function toProportionalPosition($value, $min, $max) {
if($max - $min == 0) {
return 0;
}
return ($value - $min) / ($max - $min);
}
?>

View File

@@ -0,0 +1,158 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Draw border
*
* @package Artichow
*/
class awBorder {
/**
* Border color
*
* @var Color
*/
var $color;
/**
* Hide border ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Border line style
*
* @var int
*/
var $style;
/**
* Build the border
*
* @param $color Border color
* @param int $style Border style
*/
function awBorder($color = NULL, $style = LINE_SOLID) {
$this->setStyle($style);
if(is_a($color, 'awColor')) {
$this->setColor($color);
} else {
$this->setColor(new awBlack);
}
}
/**
* Change border color
* This method automatically shows the border if it is hidden
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
$this->show();
}
/**
* Change border style
*
* @param int $style
*/
function setStyle($style) {
$this->style = (int)$style;
}
/**
* Hide border ?
*
* @param bool $hide
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show border ?
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Is the border visible ?
*
* @return bool
*/
function visible() {
return !$this->hide;
}
/**
* Draw border as a rectangle
*
* @param $drawer
* @param $p1 Top-left corner
* @param $p2 Bottom-right corner
*/
function rectangle($drawer, $p1, $p2) {
// Border is hidden
if($this->hide) {
return;
}
$line = new awLine;
$line->setStyle($this->style);
$line->setLocation($p1, $p2);
$drawer->rectangle($this->color, $line);
}
/**
* Draw border as an ellipse
*
* @param $drawer
* @param $center Ellipse center
* @param int $width Ellipse width
* @param int $height Ellipse height
*/
function ellipse($drawer, $center, $width, $height) {
// Border is hidden
if($this->hide) {
return;
}
switch($this->style) {
case LINE_SOLID :
$drawer->ellipse($this->color, $center, $width, $height);
break;
default :
trigger_error("Dashed and dotted borders and not yet implemented on ellipses", E_USER_ERROR);
break;
}
}
}
registerClass('Border');
?>

View File

@@ -0,0 +1,201 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Create your colors
*
* @package Artichow
*/
class awColor {
var $red;
var $green;
var $blue;
var $alpha;
var $resource;
var $color;
/**
* Build your color
*
* @var int $red Red intensity (from 0 to 255)
* @var int $green Green intensity (from 0 to 255)
* @var int $blue Blue intensity (from 0 to 255)
* @var int $alpha Alpha channel (from 0 to 100)
*/
function awColor($red, $green, $blue, $alpha = 0) {
$this->red = (int)$red;
$this->green = (int)$green;
$this->blue = (int)$blue;
$this->alpha = (int)round($alpha * 127 / 100);
}
/**
* Return a GDised color
*
* @param resource $resource A GD resource
* @return int
*/
function getColor($resource) {
$this->resource = $resource;
if($this->color === NULL) {
if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
$this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
} else {
$this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
}
}
return $this->color;
}
/**
* Change color brightness
*
* @param int $brightness Add this intensity to the color (betweeen -255 and +255)
*/
function brightness($brightness) {
$brightness = (int)$brightness;
$this->red = min(255, max(0, $this->red + $brightness));
$this->green = min(255, max(0, $this->green + $brightness));
$this->blue = min(255, max(0, $this->blue + $brightness));
}
/**
* Get RGB and alpha values of your color
*
* @return array
*/
function rgba() {
return array($this->red, $this->green, $this->blue, $this->alpha);
}
/**
* Free resources used for this color
*/
function free() {
if($this->resource !== NULL) {
@imagecolordeallocate($this->resource, $this->color);
$this->resource = NULL;
}
}
function php5Destructor() {
$this->free();
}
}
registerClass('Color');
$colors = array(
'Black' => array(0, 0, 0),
'AlmostBlack' => array(48, 48, 48),
'VeryDarkGray' => array(88, 88, 88),
'DarkGray' => array(128, 128, 128),
'MidGray' => array(160, 160, 160),
'LightGray' => array(195, 195, 195),
'VeryLightGray' => array(220, 220, 220),
'White' => array(255, 255, 255),
'VeryDarkRed' => array(64, 0, 0),
'DarkRed' => array(128, 0, 0),
'MidRed' => array(192, 0, 0),
'Red' => array(255, 0, 0),
'LightRed' => array(255, 192, 192),
'VeryDarkGreen' => array(0, 64, 0),
'DarkGreen' => array(0, 128, 0),
'MidGreen' => array(0, 192, 0),
'Green' => array(0, 255, 0),
'LightGreen' => array(192, 255, 192),
'VeryDarkBlue' => array(0, 0, 64),
'DarkBlue' => array(0, 0, 128),
'MidBlue' => array(0, 0, 192),
'Blue' => array(0, 0, 255),
'LightBlue' => array(192, 192, 255),
'VeryDarkYellow' => array(64, 64, 0),
'DarkYellow' => array(128, 128, 0),
'MidYellow' => array(192, 192, 0),
'Yellow' => array(255, 255, 2),
'LightYellow' => array(255, 255, 192),
'VeryDarkCyan' => array(0, 64, 64),
'DarkCyan' => array(0, 128, 128),
'MidCyan' => array(0, 192, 192),
'Cyan' => array(0, 255, 255),
'LightCyan' => array(192, 255, 255),
'VeryDarkMagenta' => array(64, 0, 64),
'DarkMagenta' => array(128, 0, 128),
'MidMagenta' => array(192, 0, 192),
'Magenta' => array(255, 0, 255),
'LightMagenta' => array(255, 192, 255),
'DarkOrange' => array(192, 88, 0),
'Orange' => array(255, 128, 0),
'LightOrange' => array(255, 168, 88),
'VeryLightOrange' => array(255, 220, 168),
'DarkPink' => array(192, 0, 88),
'Pink' => array(255, 0, 128),
'LightPink' => array(255, 88, 168),
'VeryLightPink' => array(255, 168, 220),
'DarkPurple' => array(88, 0, 192),
'Purple' => array(128, 0, 255),
'LightPurple' => array(168, 88, 255),
'VeryLightPurple' => array(220, 168, 255),
);
$php = '';
foreach($colors as $name => $color) {
list($red, $green, $blue) = $color;
$php .= '
class aw'.$name.' extends awColor {
function aw'.$name.'($alpha = 0) {
parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
}
';
}
}
eval($php);
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,295 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Built-in PHP fonts
*
* @package Artichow
*/
class awFont {
/**
* Used font
*
* @param int $font
*/
var $font;
/**
* Build the font
*
* @param int $font Font identifier
*/
function awFont($font) {
$this->font = $font;
}
/**
* Draw a text
*
* @param $drawer
* @param $p Draw text at this point
* @param &$text The text
*/
function draw($drawer, $p, &$text) {
$angle = $text->getAngle();
if($angle !== 90 and $angle !== 0) {
trigger_error("You can only use 0° and 90°", E_USER_ERROR);
}
if($angle === 90) {
$function = 'imagestringup';
} else {
$function = 'imagestring';
}
if($angle === 90) {
$add = $this->getTextHeight($text);
} else {
$add = 0;
}
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$function(
$drawer->resource,
$this->font,
$drawer->x + $p->x,
$drawer->y + $p->y + $add,
$text->getText(),
$rgb
);
}
/**
* Get the width of a string
*
* @param &$text A string
*/
function getTextWidth(&$text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextHeight($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontWidth = imagefontwidth($font->font);
if($fontWidth === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontWidth * strlen($text->getText());
}
/**
* Get the height of a string
*
* @param &$text A string
*/
function getTextHeight(&$text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextWidth($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontHeight = imagefontheight($font->font);
if($fontHeight === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontHeight;
}
}
registerClass('Font');
/**
* TTF fonts
*
* @package Artichow
*/
class awTTFFont extends awFont {
/**
* Font size
*
* @var int
*/
var $size;
/**
* Font file
*
* @param string $font Font file
* @param int $size Font size
*/
function awTTFFont($font, $size) {
parent::awFont($font);
$this->size = (int)$size;
}
/**
* Draw a text
*
* @param $drawer
* @param $p Draw text at this point
* @param &$text The text
*/
function draw($drawer, $p, &$text) {
// Make easier font positionment
$text->setText($text->getText()." ");
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
$height = - $box[5];
$box = imagettfbbox($this->size, 90, $this->font, $text->getText());
$width = abs($box[6] - $box[2]);
// Restore old text
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
imagettftext(
$drawer->resource,
$this->size,
$text->getAngle(),
$drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI),
$drawer->y + $p->y + $height,
$rgb,
$this->font,
$text->getText()
);
}
/**
* Get the width of a string
*
* @param &$text A string
*/
function getTextWidth(&$text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($x2 - $x1);
}
/**
* Get the height of a string
*
* @param &$text A string
*/
function getTextHeight(&$text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($y2 - $y1);
}
}
registerClass('TTFFont');
$php = '';
for($i = 1; $i <= 5; $i++) {
$php .= '
class awFont'.$i.' extends awFont {
function awFont'.$i.'() {
parent::awFont('.$i.');
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
}
';
}
}
eval($php);
$php = '';
foreach($fonts as $font) {
$php .= '
class aw'.$font.' extends awTTFFont {
function aw'.$font.'($size) {
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
}
';
}
}
eval($php);
?>

View File

@@ -0,0 +1,149 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Create your gradients
*
* @package Artichow
*/
class awGradient {
/**
* From color
*
* @var Color
*/
var $from;
/**
* To color
*
* @var Color
*/
var $to;
/**
* Build the gradient
*
* @param $from From color
* @param $to To color
*/
function awGradient($from, $to) {
$this->from = $from;
$this->to = $to;
}
/**
* Free memory used by the colors of the gradient
*/
function free() {
$this->from->free();
$this->to->free();
}
function php5Destructor( ){
$this->free();
}
}
registerClass('Gradient', TRUE);
/**
* Create a linear gradient
*
* @package Artichow
*/
class awLinearGradient extends awGradient {
/**
* Gradient angle
*
* @var int
*/
var $angle;
/**
* Build the linear gradient
*
* @param $from From color
* @param $to To color
* @param int $angle Gradient angle
*/
function awLinearGradient($from, $to, $angle) {
parent::awGradient(
$from, $to
);
$this->angle = $angle;
}
}
registerClass('LinearGradient');
/**
* Create a bilinear gradient
*
* @package Artichow
*/
class awBilinearGradient extends awLinearGradient {
/**
* Gradient center
*
* @var int Center between 0 and 1
*/
var $center;
/**
* Build the bilinear gradient
*
* @param $from From color
* @param $to To color
* @param int $angle Gradient angle
* @param int $center Gradient center
*/
function awBilinearGradient($from, $to, $angle, $center = 0.5) {
parent::awLinearGradient(
$from, $to, $angle
);
$this->center = $center;
}
}
registerClass('BilinearGradient');
/**
* Create a radial gradient
*
* @package Artichow
*/
class awRadialGradient extends awGradient {
}
registerClass('RadialGradient');
?>

View File

@@ -0,0 +1,289 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Grid
*
* @package Artichow
*/
class awGrid {
/**
* Vertical lines of the grid
*
* @var array
*/
var $xgrid = array();
/**
* Horizontal lines of the grid
*
* @var array
*/
var $ygrid = array();
/**
* Is the component grid hidden ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Are horizontal lines hidden ?
*
* @var bool
*/
var $hideHorizontal = FALSE;
/**
* Are vertical lines hidden ?
*
* @var bool
*/
var $hideVertical = FALSE;
/**
* Grid color
*
* @var Color
*/
var $color;
/**
* Grid space
*
* @var int
*/
var $space;
/**
* Line type
*
* @var int
*/
var $type = LINE_SOLID;
/**
* Grid interval
*
* @var int
*/
var $interval = array(1, 1);
/**
* Grid background color
*
* @var Color
*/
var $background;
/**
* Build the factory
*/
function awGrid() {
// Set a grid default color
$this->color = new awColor(210, 210, 210);
$this->background = new awColor(255, 255, 255, 100);
}
/**
* Hide grid ?
*
* @param bool $hide
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Hide horizontal lines ?
*
* @param bool $hideHorizontal
*/
function hideHorizontal($hide = TRUE) {
$this->hideHorizontal = (bool)$hide;
}
/**
* Hide vertical lines ?
*
* @param bool $hideVertical
*/
function hideVertical($hide = TRUE) {
$this->hideVertical = (bool)$hide;
}
/**
* Change grid color
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
}
/**
* Remove grid background
*/
function setNoBackground() {
$this->background = NULL;
}
/**
* Change grid background color
*
* @param $color
*/
function setBackgroundColor($color) {
$this->background = $color;
}
/**
* Change line type
*
* @param int $type
*/
function setType($type) {
$this->type = (int)$type;
}
/**
* Change grid interval
*
* @param int $hInterval
* @param int $vInterval
*/
function setInterval($hInterval, $vInterval) {
$this->interval = array((int)$hInterval, (int)$vInterval);
}
/**
* Set grid space
*
* @param int $left Left space in pixels
* @param int $right Right space in pixels
* @param int $top Top space in pixels
* @param int $bottom Bottom space in pixels
*/
function setSpace($left, $right, $top, $bottom) {
$this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Change the current grid
*
* @param array $xgrid Vertical lines
* @param array $ygrid Horizontal lines
*/
function setGrid($xgrid, $ygrid) {
$this->xgrid = $xgrid;
$this->ygrid = $ygrid;
}
/**
* Draw grids
*
* @param $drawer A drawer object
* @param int $x1
* @param int $y1
* @param int $x2
* @param int $y2
*/
function draw($drawer, $x1, $y1, $x2, $y2) {
if(is_a($this->background, 'awColor')) {
// Draw background color
$drawer->filledRectangle(
$this->background,
awLine::build($x1, $y1, $x2, $y2)
);
$this->background->free();
}
if($this->hide === FALSE) {
$this->drawGrid(
$drawer,
$this->color,
$this->hideVertical ? array() : $this->xgrid,
$this->hideHorizontal ? array() : $this->ygrid,
$x1, $y1, $x2, $y2,
$this->type,
$this->space,
$this->interval[0],
$this->interval[1]
);
}
$this->color->free();
}
function drawGrid(
$drawer, $color,
$nx, $ny, $x1, $y1, $x2, $y2,
$type, $space, $hInterval, $vInterval
) {
list($left, $right, $top, $bottom) = $space;
$width = $x2 - $x1 - $left - $right;
$height = $y2 - $y1 - $top - $bottom;
foreach($nx as $key => $n) {
if(($key % $vInterval) === 0) {
$pos = (int)round($x1 + $left + $n * $width);
$drawer->line(
$color,
new awLine(
new awPoint($pos, $y1),
new awPoint($pos, $y2),
$type
)
);
}
}
foreach($ny as $key => $n) {
if(($key % $hInterval) === 0) {
$pos = (int)round($y1 + $top + $n * $height);
$drawer->line(
$color,
new awLine(
new awPoint($x1, $pos),
new awPoint($x2, $pos),
$type
)
);
}
}
}
}
registerClass('Grid');
?>

View File

@@ -0,0 +1,596 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("LABEL_LEFT", 1);
define("LABEL_RIGHT", 2);
define("LABEL_CENTER", 3);
define("LABEL_TOP", 4);
define("LABEL_BOTTOM", 5);
define("LABEL_MIDDLE", 6);
/* </php4> */
/**
* Draw labels
*
* @package Artichow
*/
class awLabel {
/**
* Label border
*
* @var int
*/
var $border;
/**
* Label texts
*
* @var array
*/
var $texts;
/**
* Text font
*
* @var int
*/
var $font;
/**
* Text angle
*
* @var int
*/
var $angle = 0;
/**
* Text color
*
* @var Color
*/
var $color;
/**
* Text background
*
* @var Color, Gradient
*/
var $background;
/**
* Callback function
*
* @var string
*/
var $function;
/**
* Padding
*
* @var int
*/
var $padding;
/**
* Move position from this vector
*
* @var Point
*/
var $move;
/**
* Label interval
*
* @var int
*/
var $interval = 1;
/**
* Horizontal align
*
* @var int
*/
var $hAlign = LABEL_CENTER;
/**
* Vertical align
*
* @var int
*/
var $vAlign = LABEL_MIDDLE;
/**
* Hide all labels ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Keys to hide
*
* @var array
*/
var $hideKey = array();
/**
* Values to hide
*
* @var array
*/
var $hideValue = array();
/**
* Hide first label
*
* @var bool
*/
var $hideFirst = FALSE;
/**
* Hide last label
*
* @var bool
*/
var $hideLast = FALSE;
/**
* Build the label
*
* @param string $label First label
*/
function awLabel($label = NULL, $font = NULL, $color = NULL, $angle = 0) {
if(is_array($label)) {
$this->set($label);
} else if(is_string($label)) {
$this->set(array($label));
}
if($font === NULL) {
$font = new awFont2;
}
$this->setFont($font);
$this->setAngle($angle);
if(is_a($color, 'awColor')) {
$this->setColor($color);
} else {
$this->setColor(new awColor(0, 0, 0));
}
$this->move = new awPoint(0, 0);
$this->border = new awBorder;
$this->border->hide();
}
/**
* Get an element of the label from its key
*
* @param int $key Element key
* @return string A value
*/
function get($key) {
return array_key_exists($key, $this->texts) ? $this->texts[$key] : NULL;
}
/**
* Get all labels
*
* @return array
*/
function all() {
return $this->texts;
}
/**
* Set one or several labels
*
* @param array $labels Array of string or a string
*/
function set($labels) {
if(is_string($labels)) {
$this->texts = array($labels);
} else if(is_array($labels)) {
$this->texts = $labels;
}
}
/**
* Count number of texts in the label
*
* @return int
*/
function count() {
return is_array($this->texts) ? count($this->texts) : 0;
}
/**
* Set a callback function for labels
*
* @param string $function
*/
function setCallbackFunction($function) {
$this->function = is_null($function) ? $function : (string)$function;
}
/**
* Return the callback function for labels
*
* @return string
*/
function getCallbackFunction() {
return $this->function;
}
/**
* Change labels format
*
* @param string $format New format (printf style: %.2f for example)
*/
function setFormat($format) {
$function = 'label'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
return sprintf("'.addcslashes($format, '"').'", $value);
}');
$this->setCallbackFunction($function);
}
/**
* Change font for label
*
* @param &$font New font
* @param $color Font color (can be NULL)
*/
function setFont(&$font, $color = NULL) {
$this->font = $font;
if(is_a($color, 'awColor')) {
$this->setColor($color);
}
}
/**
* Change font angle
*
* @param int $angle New angle
*/
function setAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Change font color
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
}
/**
* Change text background
*
* @param mixed $background
*/
function setBackground($background) {
$this->background = $background;
}
/**
* Change text background color
*
* @param Color
*/
function setBackgroundColor($color) {
$this->background = $color;
}
/**
* Change text background gradient
*
* @param Gradient
*/
function setBackgroundGradient($gradient) {
$this->background = $gradient;
}
/**
* Change padding
*
* @param int $left Left padding
* @param int $right Right padding
* @param int $top Top padding
* @param int $bottom Bottom padding
*/
function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Hide all labels ?
*
* @param bool $hide
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show all labels ?
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Hide a key
*
* @param int $key The key to hide
*/
function hideKey($key) {
$this->hideKey[$key] = TRUE;
}
/**
* Hide a value
*
* @param int $value The value to hide
*/
function hideValue($value) {
$this->hideValue[] = $value;
}
/**
* Hide first label
*
* @param bool $hide
*/
function hideFirst($hide) {
$this->hideFirst = (bool)$hide;
}
/**
* Hide last label
*
* @param bool $hide
*/
function hideLast($hide) {
$this->hideLast = (bool)$hide;
}
/**
* Set label interval
*
* @param int
*/
function setInterval($interval) {
$this->interval = (int)$interval;
}
/**
* Change label position
*
* @param int $x Add this interval to X coord
* @param int $y Add this interval to Y coord
*/
function move($x, $y) {
$this->move = $this->move->move($x, $y);
}
/**
* Change alignment
*
* @param int $h Horizontal alignment
* @param int $v Vertical alignment
*/
function setAlign($h = NULL, $v = NULL) {
if($h !== NULL) {
$this->hAlign = (int)$h;
}
if($v !== NULL) {
$this->vAlign = (int)$v;
}
}
/**
* Get a text from the labele
*
* @param mixed $key Key in the array text
* @return Text
*/
function getText($key) {
if(is_array($this->texts) and array_key_exists($key, $this->texts)) {
$value = $this->texts[$key];
if(is_string($this->function)) {
$value = call_user_func($this->function, $value);
}
$text = new awText($value);
$text->setFont($this->font);
$text->setAngle($this->angle);
$text->setColor($this->color);
if(is_a($this->background, 'awColor')) {
$text->setBackgroundColor($this->background);
} else if(is_a($this->background, 'awGradient')) {
$text->setBackgroundGradient($this->background);
}
$text->border = $this->border;
if($this->padding !== NULL) {
call_user_func_array(array($text, 'setPadding'), $this->padding);
}
return $text;
} else {
return NULL;
}
}
/**
* Get max width of all texts
*
* @param $drawer A drawer
* @return int
*/
function getMaxWidth($drawer) {
return $this->getMax($drawer, 'getTextWidth');
}
/**
* Get max height of all texts
*
* @param $drawer A drawer
* @return int
*/
function getMaxHeight($drawer) {
return $this->getMax($drawer, 'getTextHeight');
}
/**
* Draw the label
*
* @param $drawer
* @param $p Label center
* @param int $key Text position in the array of texts (default to zero)
*/
function draw($drawer, $p, $key = 0) {
if(($key % $this->interval) !== 0) {
return;
}
// Hide all labels
if($this->hide) {
return;
}
// Key is hidden
if(array_key_exists($key, $this->hideKey)) {
return;
}
// Hide first label
if($key === 0 and $this->hideFirst) {
return;
}
// Hide last label
if($key === count($this->texts) - 1 and $this->hideLast) {
return;
}
$text = $this->getText($key);
if($text !== NULL) {
// Value must be hidden
if(in_array($text->getText(), $this->hideValue)) {
return;
}
$x = $p->x;
$y = $p->y;
// Get padding
list($left, $right, $top, $bottom) = $text->getPadding();
$font = $text->getFont();
$width = $font->getTextWidth($text);
$height = $font->getTextHeight($text);
switch($this->hAlign) {
case LABEL_RIGHT :
$x -= ($width + $right);
break;
case LABEL_CENTER :
$x -= ($width - $left + $right) / 2;
break;
case LABEL_LEFT :
$x += $left;
break;
}
switch($this->vAlign) {
case LABEL_TOP :
$y -= ($height + $bottom);
break;
case LABEL_MIDDLE :
$y -= ($height - $top + $bottom) / 2;
break;
case LABEL_BOTTOM :
$y += $top;
break;
}
$drawer->string($text, $this->move->move($x, $y));
}
}
function getMax($drawer, $function) {
$max = NULL;
foreach($this->texts as $key => $text) {
$text = $this->getText($key);
$font = $text->getFont();
if(is_null($max)) {
$max = $font->{$function}($text);
} else {
$max = max($max, $font->{$function}($text));
}
}
return $max;
}
}
registerClass('Label');
?>

View File

@@ -0,0 +1,691 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("LEGEND_LINE", 1);
define("LEGEND_BACKGROUND", 2);
define("LEGEND_MARK", 3);
define("LEGEND_MARKONLY", 4);
define("LEGEND_MODEL_RIGHT", 1);
define("LEGEND_MODEL_BOTTOM", 2);
define("LEGEND_LEFT", 1);
define("LEGEND_RIGHT", 2);
define("LEGEND_CENTER", 3);
define("LEGEND_TOP", 4);
define("LEGEND_BOTTOM", 5);
define("LEGEND_MIDDLE", 6);
/* </php4> */
/**
* Some legends
*
* @package Artichow
*/
class awLegend {
/**
* Legends added
*
* @var array
*/
var $legends = array();
/**
* The current component
*
* @var Component
*/
var $component;
/**
* Background color or gradient
*
* @var Color, Gradient
*/
var $background;
/**
* Text color
*
* @var Color
*/
var $textColor;
/**
* Text font
*
* @var Font
*/
var $textFont;
/**
* Text margin
*
* @var Side
*/
var $textMargin;
/**
* Number of columns
*
* @var int
*/
var $columns = NULL;
/**
* Number of rows
*
* @var int
*/
var $rows = NULL;
/**
* Legend position
*
* @var Point
*/
var $position;
/**
* Hide legend ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Space between each legend
*
* @var int
*/
var $space = 4;
/**
* Horizontal alignment
*
* @var int
*/
var $hAlign;
/**
* Vertical alignment
*
* @var int
*/
var $vAlign;
/**
* Margin
*
* @var array Array for left, right, top and bottom margins
*/
var $margin;
/**
* Legend shadow
*
* @var Shadow
*/
var $shadow;
/**
* Legend border
*
* @var Border
*/
var $border;
/**
* Line legend
*
* @var int
*/
/**
* Color/Gradient background legend
*
* @var int
*/
/**
* Use marks and line as legend
*
* @var int
*/
/**
* Use marks as legend
*
* @var int
*/
/**
* Right side model
*
* @var int
*/
/**
* Bottom side model
*
* @var int
*/
/**
* Build the legend
*
* @param int $model Legend model
*/
function awLegend($model = LEGEND_MODEL_RIGHT) {
$this->shadow = new awShadow(SHADOW_LEFT_BOTTOM);
$this->border = new awBorder;
$this->textMargin = new awSide(4);
$this->setModel($model);
}
/**
* Set a predefined model for the legend
*
* @param int $model
*/
function setModel($model) {
$this->setBackgroundColor(new awColor(255, 255, 255, 15));
$this->setPadding(8, 8, 8, 8);
$this->setTextFont(new awFont2);
$this->shadow->setSize(3);
switch($model) {
case LEGEND_MODEL_RIGHT :
$this->setColumns(1);
$this->setAlign(LEGEND_RIGHT, LEGEND_MIDDLE);
$this->setPosition(0.96, 0.50);
break;
case LEGEND_MODEL_BOTTOM :
$this->setRows(1);
$this->setAlign(LEGEND_CENTER, LEGEND_TOP);
$this->setPosition(0.50, 0.92);
break;
default :
$this->setPosition(0.5, 0.5);
break;
}
}
/**
* Hide legend ?
*
* @param bool $hide TRUE to hide legend, FALSE otherwise
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show legend ?
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Add a Legendable object to the legend
*
* @param &$legendable
* @param string $title Legend title
* @param int $type Legend type (default to LEGEND_LINE)
*/
function add(&$legendable, $title, $type = LEGEND_LINE) {
$legend = array($legendable, $title, $type);
$this->legends[] = $legend;
}
/**
* Change legend padding
*
* @param int $left
* @param int $right
* @param int $top
* @param int $bottom
*/
function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Change space between each legend
*
* @param int $space
*/
function setSpace($space) {
$this->space = (int)$space;
}
/**
* Change alignment
*
* @param int $h Horizontal alignment
* @param int $v Vertical alignment
*/
function setAlign($h = NULL, $v = NULL) {
if($h !== NULL) {
$this->hAlign = (int)$h;
}
if($v !== NULL) {
$this->vAlign = (int)$v;
}
}
/**
* Change number of columns
*
* @param int $columns
*/
function setColumns($columns) {
$this->rows = NULL;
$this->columns = (int)$columns;
}
/**
* Change number of rows
*
* @param int $rows
*/
function setRows($rows) {
$this->columns = NULL;
$this->rows = (int)$rows;
}
/**
* Change legend position
* X and Y positions must be between 0 and 1.
*
* @param float $x
* @param float $y
*/
function setPosition($x = NULL, $y = NULL) {
$x = (is_null($x) and !is_null($this->position)) ? $this->position->x : $x;
$y = (is_null($y) and !is_null($this->position)) ? $this->position->y : $y;
$this->position = new awPoint($x, $y);
}
/**
* Get legend position
*
* @return Point
*/
function getPosition() {
return $this->position;
}
/**
* Change text font
*
* @param &$font
*/
function setTextFont(&$font) {
$this->textFont = $font;
}
/**
* Change text margin
*
* @param int $left
* @param int $right
*/
function setTextMargin($left, $right) {
$this->textMargin->set($left, $right);
}
/**
* Change text color
*
* @param $color
*/
function setTextColor($color) {
$this->textColor = $color;
}
/**
* Change background
*
* @param mixed $background
*/
function setBackground($background) {
$this->background = $background;
}
/**
* Change background color
*
* @param $color
*/
function setBackgroundColor($color) {
$this->background = $color;
}
/**
* Change background gradient
*
* @param $gradient
*/
function setBackgroundGradient($gradient) {
$this->background = $gradient;
}
/**
* Count the number of Legendable objects in the legend
*
* @return int
*/
function count() {
return count($this->legends);
}
function draw($drawer) {
if($this->hide) {
return;
}
$count = $this->count();
// No legend to print
if($count === 0) {
return;
}
// Get text widths and heights of each element of the legend
$widths = array();
$heights = array();
$texts = array();
for($i = 0; $i < $count; $i++) {
list(, $title, ) = $this->legends[$i];
$text = new awText(
$title,
$this->textFont,
$this->textColor,
0
);
$font = $text->getFont();
$widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
$heights[$i] = $font->getTextHeight($text);
$texts[$i] = $text;
}
// Maximum height of the font used
$heightMax = array_max($heights);
// Get number of columns
if($this->columns !== NULL) {
$columns = $this->columns;
} else if($this->rows !== NULL) {
$columns = ceil($count / $this->rows);
} else {
$columns = $count;
}
// Number of rows
$rows = (int)ceil($count / $columns);
// Get maximum with of each column
$widthMax = array();
for($i = 0; $i < $count; $i++) {
// Get column width
$column = $i % $columns;
if(array_key_exists($column, $widthMax) === FALSE) {
$widthMax[$column] = $widths[$i];
} else {
$widthMax[$column] = max($widthMax[$column], $widths[$i]);
}
}
$width = $this->padding[0] + $this->padding[1] - $this->space;
for($i = 0; $i < $columns; $i++) {
$width += $this->space + 5 + 10 + $widthMax[$i];
}
$height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
// Look for legends position
list($x, $y) = $drawer->getSize();
$p = new awPoint(
$this->position->x * $x,
$this->position->y * $y
);
switch($this->hAlign) {
case LEGEND_CENTER :
$p->x -= $width / 2;
break;
case LEGEND_RIGHT :
$p->x -= $width;
break;
}
switch($this->vAlign) {
case LEGEND_MIDDLE :
$p->y -= $height / 2;
break;
case LEGEND_BOTTOM :
$p->y -= $height;
break;
}
// Draw legend shadow
$this->shadow->draw(
$drawer,
$p,
$p->move($width, $height),
SHADOW_OUT
);
// Draw legends base
$this->drawBase($drawer, $p, $width, $height);
// Draw each legend
for($i = 0; $i < $count; $i++) {
list($component, $title, $type) = $this->legends[$i];
$column = $i % $columns;
$row = (int)floor($i / $columns);
// Get width of all previous columns
$previousColumns = 0;
for($j = 0; $j < $column; $j++) {
$previousColumns += $this->space + 10 + 5 + $widthMax[$j];
}
// Draw legend text
$drawer->string(
$texts[$i],
$p->move(
$this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left,
$this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2
)
);
// Draw legend icon
switch($type) {
case LEGEND_LINE :
case LEGEND_MARK :
case LEGEND_MARKONLY :
// Get vertical position
$x = $this->padding[0] + $previousColumns;
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
// Draw two lines
if($component->getLegendLineColor() !== NULL) {
$color = $component->getLegendLineColor();
if(is_a($color, 'awColor') and $type !== LEGEND_MARKONLY) {
$drawer->line(
$color,
new awLine(
$p->move(
$x, // YaPB ??
$y + $component->getLegendLineThickness() / 2
),
$p->move(
$x + 10,
$y + $component->getLegendLineThickness() / 2
),
$component->getLegendLineStyle(),
$component->getLegendLineThickness()
)
);
$color->free();
unset($color);
}
}
if($type === LEGEND_MARK or $type === LEGEND_MARKONLY) {
$mark = $component->getLegendMark();
if($mark !== NULL) {
$mark->draw(
$drawer,
$p->move(
$x + 5.5,
$y + $component->getLegendLineThickness() / 2
)
);
}
unset($mark);
}
break;
case LEGEND_BACKGROUND :
// Get vertical position
$x = $this->padding[0] + $previousColumns;
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
$from = $p->move(
$x,
$y
);
$to = $p->move(
$x + 10,
$y + 10
);
$background = $component->getLegendBackground();
if($background !== NULL) {
$drawer->filledRectangle(
$component->getLegendBackground(),
new awLine($from, $to)
);
// Draw rectangle border
$this->border->rectangle(
$drawer,
$from->move(0, 0),
$to->move(0, 0)
);
}
unset($background, $from, $to);
break;
}
}
}
function drawBase($drawer, $p, $width, $height) {
$this->border->rectangle(
$drawer,
$p,
$p->move($width, $height)
);
$size = $this->border->visible() ? 1 : 0;
$drawer->filledRectangle(
$this->background,
new awLine(
$p->move($size, $size),
$p->move($width - $size, $height - $size)
)
);
}
}
registerClass('Legend');
/**
* You can add a legend to components which implements this interface
*
* @package Artichow
*/
registerInterface('Legendable');
?>

View File

@@ -0,0 +1,335 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("MARK_CIRCLE", 1);
define("MARK_SQUARE", 2);
define("MARK_IMAGE", 3);
define("MARK_STAR", 4);
define("MARK_PAPERCLIP", 5);
define("MARK_BOOK", 6);
/* </php4> */
/**
* Draw marks
*
* @package Artichow
*/
class awMark {
/**
* Circle mark
*
* @var int
*/
/**
* Quare mark
*
* @var int
*/
/**
* Image mark
*
* @var int
*/
/**
* Star mark
*
* @var int
*/
/**
* Paperclip mark
*
* @var int
*/
/**
* Book mark
*
* @var int
*/
/**
* Must marks be hidden ?
*
* @var bool
*/
var $hide;
/**
* Mark type
*
* @var int
*/
var $type;
/**
* Mark size
*
* @var int
*/
var $size = 8;
/**
* Fill mark
*
* @var Color, Gradient
*/
var $fill;
/**
* Mark image
*
* @var Image
*/
var $image;
/**
* To draw marks
*
* @var Drawer
*/
var $drawer;
/**
* Move position from this vector
*
* @var Point
*/
var $move;
/**
* Marks border
*
* @var Border
*/
var $border;
/**
* Build the mark
*/
function awMark() {
$this->fill = new awColor(255, 0, 0, 0);
$this->border = new awBorder;
$this->border->hide();
$this->move = new awPoint(0, 0);
}
/**
* Change mark position
*
* @param int $x Add this interval to X coord
* @param int $y Add this interval to Y coord
*/
function move($x, $y) {
$this->move = $this->move->move($x, $y);
}
/**
* Hide marks ?
*
* @param bool $hide TRUE to hide marks, FALSE otherwise
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show marks ?
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Change mark type
*
* @param int $size Size in pixels
*/
function setSize($size) {
$this->size = (int)$size;
}
/**
* Change mark type
*
* @param int $type New mark type
* @param int $size Mark size (can be NULL)
*/
function setType($type, $size = NULL) {
$this->type = (int)$type;
if($size !== NULL) {
$this->setSize($size);
}
}
/**
* Fill the mark with a color or a gradient
*
* @param mixed $fill A color or a gradient
*/
function setFill($fill) {
if(is_a($fill, 'awColor') or is_a($fill, 'awGradient')) {
$this->fill = $fill;
}
}
/**
* Set an image
* Only for MARK_IMAGE type.
*
* @param Image An image
*/
function setImage(&$image) {
$this->image = $image;
}
/**
* Draw the mark
*
* @param $drawer
* @param $point Mark center
*/
function draw($drawer, $point) {
// Hide marks ?
if($this->hide) {
return;
}
// Check if we can print marks
if($this->type !== NULL) {
$this->drawer = $drawer;
$realPoint = $this->move->move($point->x, $point->y);
switch($this->type) {
case MARK_CIRCLE :
$this->drawCircle($realPoint);
break;
case MARK_SQUARE :
$this->drawSquare($realPoint);
break;
case MARK_IMAGE :
$this->drawImage($realPoint);
break;
case MARK_STAR :
$this->changeType('star');
$this->draw($drawer, $point);
break;
case MARK_PAPERCLIP :
$this->changeType('paperclip');
$this->draw($drawer, $point);
break;
case MARK_BOOK :
$this->changeType('book');
$this->draw($drawer, $point);
break;
}
}
}
function changeType($image) {
$this->setType(MARK_IMAGE);
$this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
}
function drawCircle($point) {
$this->drawer->filledEllipse(
$this->fill,
$point,
$this->size, $this->size
);
$this->border->ellipse(
$this->drawer,
$point,
$this->size, $this->size
);
}
function drawSquare($point) {
list($x, $y) = $point->getLocation();
$x1 = (int)($x - $this->size / 2);
$x2 = $x1 + $this->size;
$y1 = (int)($y - $this->size / 2);
$y2 = $y1 + $this->size;
$this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
$size = $this->border->visible() ? 1 : 0;
$this->drawer->filledRectangle(
$this->fill,
new awLine(
new awPoint($x1 + $size, $y1 + $size),
new awPoint($x2 - $size, $y2 - $size)
)
);
}
function drawImage($point) {
if(is_a($this->image, 'awImage')) {
$width = $this->image->width;
$height = $this->image->height;
list($x, $y) = $point->getLocation();
$x1 = (int)($x - $width / 2);
$x2 = $x1 + $width;
$y1 = (int)($y - $width / 2);
$y2 = $y1 + $height;
$this->border->rectangle($this->drawer, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
$this->drawer->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
}
}
}
registerClass('Mark');
?>

View File

@@ -0,0 +1,492 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
class awShape {
/**
* Is the shape hidden ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Shape style
*
* @var int
*/
var $style;
/**
* Shape thickness
*
* @var int
*/
var $thickness;
/**
* Solid shape
*
* @var int
*/
/**
* Dotted shape
*
* @var int
*/
/**
* Dashed shape
*
* @var int
*/
/**
* Change shape style
*
* @param int $style Line style
*/
function setStyle($style) {
$this->style = (int)$style;
}
/**
* Return shape style
*
* @return int
*/
function getStyle() {
return $this->style;
}
/**
* Change shape thickness
*
* @param int $thickness Shape thickness in pixels
*/
function setThickness($thickness) {
$this->thickness = (int)$thickness;
}
/**
* Return shape thickness
*
* @return int
*/
function getThickness() {
return $this->thickness;
}
/**
* Hide the shape
*
* @param bool $hide
*/
function hide($hide) {
$this->hide = (bool)$hide;
}
/**
* Show the shape
*
* @param bool $shape
*/
function show($shape) {
$this->hide = (bool)!$shape;
}
/**
* Is the line hidden ?
*
* @return bool
*/
function isHidden() {
return $this->hide;
}
}
registerClass('Shape', TRUE);
/**
* Describe a point
*
* @package Artichow
*/
class awPoint extends awShape {
/**
* X coord
*
* @var float
*/
var $x;
/**
* Y coord
*
* @var float
*/
var $y;
/**
* Build a new awpoint
*
* @param float $x
* @param float $y
*/
function awPoint($x, $y) {
$this->setLocation($x, $y);
}
/**
* Change X value
*
* @param float $x
*/
function setX($x) {
$this->x = (float)$x;
}
/**
* Change Y value
*
* @param float $y
*/
function setY($y) {
$this->y = (float)$y;
}
/**
* Change point location
*
* @param float $x
* @param float $y
*/
function setLocation($x, $y) {
$this->setX($x);
$this->setY($y);
}
/**
* Get point location
*
* @param array Point location
*/
function getLocation() {
return array($this->x, $this->y);
}
/**
* Get distance to another point
*
* @param $p A point
* @return float
*/
function getDistance($p) {
return sqrt(pow($p->x - $this->x, 2) + pow($p->y - $this->y, 2));
}
/**
* Move the point to another location
*
* @param Point A Point with the new awlocation
*/
function move($x, $y) {
return new awPoint(
$this->x + $x,
$this->y + $y
);
}
}
registerClass('Point');
/* <php4> */
define("LINE_SOLID", 1);
define("LINE_DOTTED", 2);
define("LINE_DASHED", 3);
/* </php4> */
/**
* Describe a line
*
* @package Artichow
*/
class awLine extends awShape {
/**
* Line first point
*
* @param Point
*/
var $p1;
/**
* Line second point
*
* @param Point
*/
var $p2;
/**
* Build a new awline
*
* @param $p1 First point
* @param $p2 Second point
* @param int $type Style of line (default to solid)
* @param int $thickness Line thickness (default to 1)
*/
function awLine($p1 = NULL, $p2 = NULL, $type = LINE_SOLID, $thickness = 1) {
$this->setLocation($p1, $p2);
$this->setStyle($type);
$this->setThickness($thickness);
}
/**
* Build a line from 4 coords
*
* @param int $x1 Left position
* @param int $y1 Top position
* @param int $x2 Right position
* @param int $y2 Bottom position
*/
function build($x1, $y1, $x2, $y2) {
return new awLine(
new awPoint($x1, $y1),
new awPoint($x2, $y2)
);
}
/**
* Change X values of the line
*
* @param int $x1 Begin value
* @param int $x2 End value
*/
function setX($x1, $x2) {
$this->p1->setX($x1);
$this->p2->setX($x2);
}
/**
* Change Y values of the line
*
* @param int $y1 Begin value
* @param int $y2 End value
*/
function setY($y1, $y2) {
$this->p1->setY($y1);
$this->p2->setY($y2);
}
/**
* Change line location
*
* @param $p1 First point
* @param $p2 Second point
*/
function setLocation($p1, $p2) {
if(is_null($p1) or is_a($p1, 'awPoint')) {
$this->p1 = $p1;
}
if(is_null($p2) or is_a($p2, 'awPoint')) {
$this->p2 = $p2;
}
}
/**
* Get line location
*
* @param array Line location
*/
function getLocation() {
return array($this->p1, $this->p2);
}
/**
* Get the line size
*
* @return float
*/
function getSize() {
$square = pow($this->p2->x - $this->p1->x, 2) + pow($this->p2->y - $this->p1->y, 2);
return sqrt($square);
}
/**
* Test if the line can be considered as a point
*
* @return bool
*/
function isPoint() {
return ($this->p1->x === $this->p2->x and $this->p1->y === $this->p2->y);
}
/**
* Test if the line is a vertical line
*
* @return bool
*/
function isVertical() {
return ($this->p1->x === $this->p2->x);
}
/**
* Test if the line is an horizontal line
*
* @return bool
*/
function isHorizontal() {
return ($this->p1->y === $this->p2->y);
}
}
registerClass('Line');
/**
* A vector is a type of line
* The sense of the vector goes from $p1 to $p2.
*
* @package Artichow
*/
class awVector extends awLine {
/**
* Get vector angle in radians
*
* @return float
*/
function getAngle() {
if($this->isPoint()) {
return 0.0;
}
$size = $this->getSize();
$width = ($this->p2->x - $this->p1->x);
$height = ($this->p2->y - $this->p1->y) * -1;
if($width >= 0 and $height >= 0) {
return acos($width / $size);
} else if($width <= 0 and $height >= 0) {
return acos($width / $size);
} else {
$height *= -1;
if($width >= 0 and $height >= 0) {
return 2 * M_PI - acos($width / $size);
} else if($width <= 0 and $height >= 0) {
return 2 * M_PI - acos($width / $size);
}
}
}
}
registerClass('Vector');
/* <php4> */
define("POLYGON_SOLID", 1);
define("POLYGON_DOTTED", 2);
define("POLYGON_DASHED", 3);
/* </php4> */
/**
* Describe a polygon
*
* @package Artichow
*/
class awPolygon extends awShape {
/**
* Polygon points
*
* @var array
*/
var $points = array();
/**
* Set a point in the polygon
*
* @param int $pos Point position
* @param $point
*/
function set($pos, $point) {
if(is_null($point) or is_a($point, 'awPoint')) {
$this->points[$pos] = $point;
}
}
/**
* Add a point at the end of the polygon
*
* @param $point
*/
function append($point) {
if(is_null($point) or is_a($point, 'awPoint')) {
$this->points[] = $point;
}
}
/**
* Get a point at a position in the polygon
*
* @param int $pos Point position
* @return Point
*/
function get($pos) {
return $this->points[$pos];
}
/**
* Count number of points in the polygon
*
* @return int
*/
function count() {
return count($this->points);
}
/**
* Returns all points in the polygon
*
* @return array
*/
function all() {
return $this->points;
}
}
registerClass('Polygon');
?>

View File

@@ -0,0 +1,415 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("SHADOW_LEFT_TOP", 1);
define("SHADOW_LEFT_BOTTOM", 2);
define("SHADOW_RIGHT_TOP", 3);
define("SHADOW_RIGHT_BOTTOM", 4);
define("SHADOW_IN", 1);
define("SHADOW_OUT", 2);
/* </php4> */
/**
* Draw shadows
*
*/
class awShadow {
/**
* Shadow on left and top sides
*
* @var int
*/
/**
* Shadow on left and bottom sides
*
* @var int
*/
/**
* Shadow on right and top sides
*
* @var int
*/
/**
* Shadow on right and bottom sides
*
* @var int
*/
/**
* In mode
*
* @var int
*/
/**
* Out mode
*
* @var int
*/
/**
* Shadow size
*
* @var int
*/
var $size = 0;
/**
* Hide shadow ?
*
* @var bool
*/
var $hide = FALSE;
/**
* Shadow color
*
* @var Color
*/
var $color;
/**
* Shadow position
*
* @var int
*/
var $position;
/**
* Smooth shadow ?
*
* @var bool
*/
var $smooth = FALSE;
/**
* Shadow constructor
*
* @param int $position Shadow position
*/
function awShadow($position) {
$this->setPosition($position);
}
/**
* Hide shadow ?
*
* @param bool $hide
*/
function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show shadow ?
*
* @param bool $show
*/
function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Change shadow size
*
* @param int $size
* @param bool $smooth Smooth the shadow (facultative argument)
*/
function setSize($size, $smooth = NULL) {
$this->size = (int)$size;
if($smooth !== NULL) {
$this->smooth($smooth);
}
}
/**
* Change shadow color
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
}
/**
* Change shadow position
*
* @param int $position
*/
function setPosition($position) {
$this->position = (int)$position;
}
/**
* Smooth shadow ?
*
* @param bool $smooth
*/
function smooth($smooth) {
$this->smooth = (bool)$smooth;
}
/**
* Get the space taken by the shadow
*
* @return Side
*/
function getSpace() {
return new awSide(
($this->position === SHADOW_LEFT_TOP or $this->position === SHADOW_LEFT_BOTTOM) ? $this->size : 0,
($this->position === SHADOW_RIGHT_TOP or $this->position === SHADOW_RIGHT_BOTTOM) ? $this->size : 0,
($this->position === SHADOW_LEFT_TOP or $this->position === SHADOW_RIGHT_TOP) ? $this->size : 0,
($this->position === SHADOW_LEFT_BOTTOM or $this->position === SHADOW_RIGHT_BOTTOM) ? $this->size : 0
);
}
/**
* Draw shadow
*
* @param $drawer
* @param $p1 Top-left point
* @param $p2 Right-bottom point
* @param int Drawing mode
*/
function draw($drawer, $p1, $p2, $mode) {
if($this->hide) {
return;
}
if($this->size <= 0) {
return;
}
$color = (is_a($this->color, 'awColor')) ? $this->color : new awColor(125, 125, 125);
switch($this->position) {
case SHADOW_RIGHT_BOTTOM :
if($mode === SHADOW_OUT) {
$t1 = $p1->move(0, 0);
$t2 = $p2->move($this->size + 1, $this->size + 1);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($width - $this->size, $this->size),
new awPoint($width - 1, $height - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, $height - $this->size),
new awPoint($width - $this->size - 1, $height - 1)
)
);
$this->smoothPast($drawer, $color, $width, $height);
break;
case SHADOW_LEFT_TOP :
if($mode === SHADOW_OUT) {
$t1 = $p1->move(- $this->size, - $this->size);
$t2 = $p2->move(0, 0);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$height = max($height + 1, $this->size);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint(0, 0),
new awPoint($this->size - 1, $height - $this->size - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, 0),
new awPoint($width - $this->size - 1, $this->size - 1)
)
);
$this->smoothPast($drawer, $color, $width, $height);
break;
case SHADOW_RIGHT_TOP :
if($mode === SHADOW_OUT) {
$t1 = $p1->move(0, - $this->size);
$t2 = $p2->move($this->size + 1, 0);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$height = max($height + 1, $this->size);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($width - $this->size, 0),
new awPoint($width - 1, $height - $this->size - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, 0),
new awPoint($width - $this->size - 1, $this->size - 1)
)
);
$this->smoothFuture($drawer, $color, $width, $height);
break;
case SHADOW_LEFT_BOTTOM :
if($mode === SHADOW_OUT) {
$t1 = $p1->move(- $this->size, 0);
$t2 = $p2->move(0, $this->size + 1);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint(0, $this->size),
new awPoint($this->size - 1, $height - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, $height - $this->size),
new awPoint($width - $this->size - 1, $height - 1)
)
);
$this->smoothFuture($drawer, $color, $width, $height);
break;
}
}
function smoothPast($drawer, $color, $width, $height) {
if($this->smooth) {
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($i, $j + $height - $this->size)
);
}
}
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($width - $this->size + $j, $i)
);
}
}
}
}
function smoothFuture($drawer, $color, $width, $height) {
if($this->smooth) {
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($i, $this->size - $j - 1)
);
}
}
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($width - $this->size + $j, $height - $i - 1)
);
}
}
}
}
}
registerClass('Shadow');
?>

View File

@@ -0,0 +1,217 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* To handle text
*
* @package Artichow
*/
class awText {
/**
* Your text
*
* @var string
*/
var $text;
/**
* Text font
*
* @var Font
*/
var $font;
/**
* Text angle
* Can be 0 or 90
*
* @var int
*/
var $angle;
/**
* Text color
*
* @var Color
*/
var $color;
/**
* Text background
*
* @var Color, Gradient
*/
var $background;
/**
* Padding
*
* @var array Array for left, right, top and bottom paddings
*/
var $padding;
/**
* Text border
*
* @var Border
*/
var $border;
/**
* Build a new awtext
*
* @param string $text Your text
*/
function awText($text, $font = NULL, $color = NULL, $angle = 0) {
if(is_null($font)) {
$font = new awFont2;
}
$this->setText($text);
$this->setFont($font);
// Set default color to black
if($color === NULL) {
$color = new awColor(0, 0, 0);
}
$this->setColor($color);
$this->setAngle($angle);
$this->border = new awBorder;
$this->border->hide();
}
/**
* Get text
*
* @return string
*/
function getText() {
return $this->text;
}
/**
* Change text
*
* @param string $text New text
*/
function setText($text) {
$this->text = (string)$text;
}
/**
* Change text font
*
* @param Font
*/
function setFont(&$font) {
$this->font = $font;
}
/**
* Get text font
*
* @return int
*/
function getFont() {
return $this->font;
}
/**
* Change text angle
*
* @param int
*/
function setAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Get text angle
*
* @return int
*/
function getAngle() {
return $this->angle;
}
/**
* Change text color
*
* @param Color
*/
function setColor($color) {
$this->color = $color;
}
/**
* Get text color
*
* @return Color
*/
function getColor() {
return $this->color;
}
/**
* Change text background color
*
* @param $color
*/
function setBackgroundColor($color) {
$this->background = $color;
}
/**
* Change text background gradient
*
* @param $gradient
*/
function setBackgroundGradient($gradient) {
$this->background = $gradient;
}
/**
* Get text background
*
* @return Color, Gradient
*/
function getBackground() {
return $this->background;
}
/**
* Change padding
*
* @param int $left Left padding
* @param int $right Right padding
* @param int $top Top padding
* @param int $bottom Bottom padding
*/
function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Get current padding
*
* @return array
*/
function getPadding() {
return $this->padding;
}
}
registerClass('Text');
?>

View File

@@ -0,0 +1,349 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("TICK_IN", 0);
define("TICK_OUT", 1);
define("TICK_IN_OUT", 2);
/* </php4> */
/**
* Handle ticks
*
* @package Artichow
*/
class awTick {
/**
* Ticks style
*
* @var int
*/
var $style = TICK_IN;
/**
* Ticks size
*
* @var int
*/
var $size;
/**
* Ticks color
*
* @var Color
*/
var $color;
/**
* Ticks number
*
* @var int
*/
var $number;
/**
* Ticks number by other tick
*
* @var array
*/
var $numberByTick;
/**
* Ticks interval
*
* @var int
*/
var $interval = 1;
/**
* Hide ticks
*
* @var bool
*/
var $hide = FALSE;
/**
* Hide first tick
*
* @var bool
*/
var $hideFirst = FALSE;
/**
* Hide last tick
*
* @var bool
*/
var $hideLast = FALSE;
/**
* In mode
*
* @param int
*/
/**
* Out mode
*
* @param int
*/
/**
* In and out mode
*
* @param int
*/
/**
* Build the ticks
*
* @param int $number Number of ticks
* @param int $size Ticks size
*/
function awTick($number, $size) {
$this->setSize($size);
$this->setNumber($number);
$this->setColor(new awBlack);
$this->style = TICK_IN;
}
/**
* Change ticks style
*
* @param int $style
*/
function setStyle($style) {
$this->style = (int)$style;
}
/**
* Get ticks style
*
* @return int
*/
function getStyle() {
return $this->style;
}
/**
* Change ticks color
*
* @param $color
*/
function setColor($color) {
$this->color = $color;
}
/**
* Change ticks size
*
* @param int $size
*/
function setSize($size) {
$this->size = (int)$size;
}
/**
* Change interval of ticks
*
* @param int $interval
*/
function setInterval($interval) {
$this->interval = (int)$interval;
}
/**
* Get interval between each tick
*
* @return int
*/
function getInterval() {
return $this->interval;
}
/**
* Change number of ticks
*
* @param int $number
*/
function setNumber($number) {
$this->number = (int)$number;
}
/**
* Get number of ticks
*
* @return int
*/
function getNumber() {
return $this->number;
}
/**
* Change number of ticks relative to others ticks
*
* @param &$tick Ticks reference
* @param int $number Number of ticks
*/
function setNumberByTick(&$tick, $number) {
$this->numberByTick = array(&$tick, (int)$number);
}
/**
* Hide ticks
*
* @param bool $hide
*/
function hide($hide) {
$this->hide = (bool)$hide;
}
/**
* Hide first tick
*
* @param bool $hide
*/
function hideFirst($hide) {
$this->hideFirst = (bool)$hide;
}
/**
* Hide last tick
*
* @param bool $hide
*/
function hideLast($hide) {
$this->hideLast = (bool)$hide;
}
/**
* Draw ticks on a vector
*
* @param $drawer A drawer
* @param &$vector A vector
*/
function draw($drawer, &$vector) {
if($this->numberByTick !== NULL) {
list($tick, $number) = $this->numberByTick;
$this->number = 1 + ($tick->getNumber() - 1) * ($number + 1);
$this->interval = $tick->getInterval();
}
if($this->number < 2 or $this->hide) {
return;
}
$angle = $vector->getAngle();
// echo "INIT:".$angle."<br>";
switch($this->style) {
case TICK_IN :
$this->drawTicks($drawer, $vector, NULL, $angle + M_PI / 2);
break;
case TICK_OUT :
$this->drawTicks($drawer, $vector, $angle + 3 * M_PI / 2, NULL);
break;
default :
$this->drawTicks($drawer, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2);
break;
}
}
function drawTicks($drawer, &$vector, $from, $to) {
// Draw last tick
if($this->hideLast === FALSE) {
//echo '<b>';
if(($this->number - 1) % $this->interval === 0) {
$this->drawTick($drawer, $vector->p2, $from, $to);
}
//echo '</b>';
}
$number = $this->number - 1;
$size = $vector->getSize();
// Get tick increment in pixels
$inc = $size / $number;
// Check if we must hide the first tick
$start = $this->hideFirst ? $inc : 0;
$stop = $inc * $number;
$position = 0;
for($i = $start; round($i, 6) < $stop; $i += $inc) {
if($position % $this->interval === 0) {
$p = $vector->p1->move(
round($i * cos($vector->getAngle()), 6),
round($i * sin($vector->getAngle() * -1), 6)
);
$this->drawTick($drawer, $p, $from, $to);
}
$position++;
}
//echo '<br><br>';
}
function drawTick($drawer, $p, $from, $to) {
// echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
// The round avoid some errors in the calcul
// For example, 12.00000008575245 becomes 12
$p1 = $p;
$p2 = $p;
if($from !== NULL) {
$p1 = $p1->move(
round($this->size * cos($from), 6),
round($this->size * sin($from) * -1, 6)
);
}
if($to !== NULL) {
$p2 = $p2->move(
round($this->size * cos($to), 6),
round($this->size * sin($to) * -1, 6)
);
}
//echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
$vector = new awVector(
$p1, $p2
);
$drawer->line(
$this->color,
$vector
);
}
}
registerClass('Tick');
?>

View File

@@ -0,0 +1,121 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Objects capable of being positioned
*
* @package Artichow
*/
registerInterface('Positionable');
/**
* Manage left, right, top and bottom sides
*
* @package Artichow
*/
class awSide {
/**
* Left side
*
* @var int
*/
var $left = 0;
/**
* Right side
*
* @var int
*/
var $right = 0;
/**
* Top side
*
* @var int
*/
var $top = 0;
/**
* Bottom side
*
* @var int
*/
var $bottom = 0;
/**
* Build the side
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
function awSide($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->set($left, $right, $top, $bottom);
}
/**
* Change side values
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
function set($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
if($left !== NULL) {
$this->left = (float)$left;
}
if($right !== NULL) {
$this->right = (float)$right;
}
if($top !== NULL) {
$this->top = (float)$top;
}
if($bottom !== NULL) {
$this->bottom = (float)$bottom;
}
}
/**
* Add values to each side
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
if($left !== NULL) {
$this->left += (float)$left;
}
if($right !== NULL) {
$this->right += (float)$right;
}
if($top !== NULL) {
$this->top += (float)$top;
}
if($bottom !== NULL) {
$this->bottom += (float)$bottom;
}
}
}
registerClass('Side');
?>

View File

@@ -0,0 +1,217 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* AntiSpam
* String printed on the images are case insensitive.
*
* @package Artichow
*/
class awAntiSpam extends awImage {
/**
* Anti-spam string
*
* @var string
*/
protected $string;
/**
* Noise intensity
*
* @var int
*/
protected $noise = 0;
/**
* Construct a new awAntiSpam image
*
* @param string $string A string to display
*/
public function __construct($string = '') {
parent::__construct();
$this->string = (string)$string;
}
/**
* Create a random string
*
* @param int $length String length
* @return string String created
*/
public function setRand($length) {
$length = (int)$length;
$this->string = '';
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
$number = strlen($letters);
for($i = 0; $i < $length; $i++) {
$this->string .= $letters{mt_rand(0, $number - 1)};
}
return $this->string;
}
/**
* Set noise on image
*
* @param int $nois Noise intensity (from 0 to 10)
*/
public function setNoise($noise) {
if($noise < 0) {
$noise = 0;
}
if($noise > 10) {
$noise = 10;
}
$this->noise = (int)$noise;
}
/**
* Save string value in session
* You can use check() to verify the value later
*
* @param string $qName A name that identify the anti-spam image
*/
public function save($qName) {
$this->session();
$session = 'artichow_'.(string)$qName;
$_SESSION[$session] = $this->string;
}
/**
* Verify user entry
*
* @param string $qName A name that identify the anti-spam image
* @param string $value User-defined value
* @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
* @return bool TRUE if the value is correct, FALSE otherwise
*/
public function check($qName, $value, $case = TRUE) {
$this->session();
$session = 'artichow_'.(string)$qName;
return (
array_key_exists($session, $_SESSION) === TRUE and
$case ?
(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
($_SESSION[$session] === (string)$value)
);
}
/**
* Draw image
*/
public function draw() {
$fonts = array(
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'Tuffy.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBold.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyItalic.ttf',
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBoldItalic.ttf'
);
$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);
$widths = array();
$heights = array();
$texts = array();
for($i = 0; $i < strlen($this->string); $i++) {
$fontKey = array_rand($fonts);
$sizeKey = array_rand($sizes);
$font = new awTTFFont(
$fonts[$fontKey], $sizes[$sizeKey]
);
$text = new awText(
$this->string{$i},
$font,
NULL,
mt_rand(-15, 15)
);
$widths[] = $font->getTextWidth($text);
$heights[] = $font->getTextHeight($text);
$texts[] = $text;
}
$width = array_sum($widths);
$height = array_max($heights);
$totalWidth = $width + 10 + count($texts) * 10;
$totalHeight = $height + 20;
$this->setSize($totalWidth, $totalHeight);
$this->create();
for($i = 0; $i < strlen($this->string); $i++) {
$this->drawer->string(
$texts[$i],
new awPoint(
5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
10 + ($height - $heights[$i]) / 2
)
);
}
$this->drawNoise($totalWidth, $totalHeight);
$this->send();
}
protected function drawNoise($width, $height) {
$points = $this->noise * 30;
$color = new awColor(0, 0, 0);
for($i = 0; $i < $points; $i++) {
$this->drawer->point(
$color,
new awPoint(
mt_rand(0, $width),
mt_rand(0, $height)
)
);
}
}
protected function session() {
// Start session if needed
if(!session_id()) {
session_start();
}
}
}
registerClass('AntiSpam');
?>

View File

@@ -0,0 +1,364 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/**
* BarPlot
*
* @package Artichow
*/
class awBarPlot extends awPlot implements awLegendable {
/**
* Labels on your bar plot
*
* @var Label
*/
public $label;
/**
* Bar plot identifier
*
* @var int
*/
protected $identifier;
/**
* Bar plot number
*
* @var int
*/
protected $number;
/**
* Bar plot depth
*
* @var int
*/
protected $depth;
/**
* For moving bars
*
* @var int
*/
protected $move;
/**
* Bars shadow
*
* @var Shadow
*/
public $barShadow;
/**
* Bars border
*
* @var Border
*/
public $barBorder;
/**
* Bars padding
*
* @var Side
*/
protected $barPadding;
/**
* Bars space
*
* @var int
*/
protected $barSpace = 0;
/**
* Bars background
*
* @var Color, Gradient
*/
protected $barBackground;
/**
* Construct a new awBarPlot
*
* @param array $values Some numeric values for Y axis
* @param int $identifier Plot identifier
* @param int $number Bar plot number
* @param int $depth Bar plot depth in pixels
*/
public function __construct($values, $identifier = 1, $number = 1, $depth = 0) {
parent::__construct();
$this->label = new awLabel;
$this->barPadding = new awSide(0.08, 0.08, 0, 0);
$this->barShadow = new awShadow(awShadow::RIGHT_TOP);
$this->barBorder = new awBorder;
$this->setValues($values);
$this->identifier = (int)$identifier;
$this->number = (int)$number;
$this->depth = (int)$depth;
$this->move = new awSide;
// Hide vertical grid
$this->grid->hideVertical(TRUE);
}
/**
* Change bars padding
* This method is not compatible with awBarPlot::setBarPadding()
*
* @param float $left Left padding (between 0 and 1)
* @param float $right Right padding (between 0 and 1)
*/
public function setBarPadding($left = NULL, $right = NULL) {
$this->barPadding->set($left, $right);
}
/**
* Change bars size
* This method is not compatible with awBarPlot::setBarPadding()
*
* @param int $width Bars size (between 0 and 1)
*/
public function setBarSize($size) {
$padding = (1 - $size) / 2;
$this->barPadding->set($padding, $padding);
}
/**
* Move bars
*
* @param int $x
* @param int $y
*/
public function move($x, $y) {
$this->move->set($x, NULL, $y, NULL);
}
/**
* Change bars space
*
* @param int $space Space in pixels
*/
public function setBarSpace($space) {
$this->barSpace = (int)$space;
}
/**
* Change line background color
*
* @param awColor $color
*/
public function setBarColor(awColor $color) {
$this->barBackground = $color;
}
/**
* Change line background gradient
*
* @param awGradient $gradient
*/
public function setBarGradient(awGradient $gradient) {
$this->barBackground = $gradient;
}
/**
* Get the line thickness
*
* @return int
*/
public function getLegendLineThickness() {
}
/**
* Get the line type
*
* @return int
*/
public function getLegendLineStyle() {
}
/**
* Get the color of line
*
* @return Color
*/
public function getLegendLineColor() {
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground() {
return $this->barBackground;
}
/**
* Get a mark object
*
* @return Mark
*/
public function getLegendMark() {
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->datay);
$max = $this->getRealYMax(NULL);
$min = $this->getRealYMin(NULL);
// Find zero for bars
if($this->xAxisZero and $min <= 0 and $max >= 0) {
$zero = 0;
} else if($max < 0) {
$zero = $max;
} else {
$zero = $min;
}
// Get base position
$zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
// Distance between two values on the graph
$distance = $this->xAxis->getDistance(0, 1);
// Compute paddings
$leftPadding = $this->barPadding->left * $distance;
$rightPadding = $this->barPadding->right * $distance;
$padding = $leftPadding + $rightPadding;
$space = $this->barSpace * ($this->number - 1);
$barSize = ($distance - $padding - $space) / $this->number;
$barPosition = $leftPadding + $barSize * ($this->identifier - 1);
for($key = 0; $key < $count; $key++) {
$value = $this->datay[$key];
if($value !== NULL) {
$position = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, $value)
);
$barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
$barStop = $barStart + $barSize;
$t1 = min($zero->y, $position->y);
$t2 = max($zero->y, $position->y);
if(round($t2 - $t1) == 0) {
continue;
}
$p1 = new awPoint(
round($barStart) + $this->depth + $this->move->left,
round($t1) - $this->depth + $this->move->top
);
$p2 = new awPoint(
round($barStop) + $this->depth + $this->move->left,
round($t2) - $this->depth + $this->move->top
);
$this->drawBar($drawer, $p1, $p2);
}
}
// Draw labels
foreach($this->datay as $key => $value) {
if($value !== NULL) {
$position = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, $value)
);
$point = new awPoint(
$barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth,
$position->y - $this->depth
);
$this->label->draw($drawer, $point, $key);
}
}
}
public function getXAxisNumber() {
return count($this->datay) + 1;
}
// ça bidouille à fond ici !
public function getXMax() {
return array_max($this->datax) + 1;
}
public function getXCenter() {
return TRUE;
}
protected function drawBar(awDrawer $drawer, awPoint $p1, awPoint $p2) {
// Draw shadow
$this->barShadow->draw(
$drawer,
$p1,
$p2,
awShadow::OUT
);
if(abs($p2->y - $p1->y) > 1) {
$this->barBorder->rectangle(
$drawer,
$p1,
$p2
);
if($this->barBackground !== NULL) {
$size = $this->barBorder->visible() ? 1 : 0;
$b1 = $p1->move($size, $size);
$b2 = $p2->move(-1 * $size, -1 * $size);
// Draw background
$drawer->filledRectangle(
$this->barBackground,
new awLine($b1, $b2)
);
}
}
}
}
registerClass('BarPlot');
?>

View File

@@ -0,0 +1,415 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* A graph can contain some groups of components
*
* @package Artichow
*/
abstract class awComponentGroup extends awComponent {
/**
* Components of this group
*
* @var array
*/
protected $components;
/**
* Build the component group
*/
public function __construct() {
parent::__construct();
$this->components = array();
}
/**
* Add a component to the group
*
* @param awComponent $component A component
*/
public function add(awComponent $component) {
$this->components[] = $component;
}
}
registerClass('ComponentGroup', TRUE);
abstract class awComponent {
/**
* Component drawer
*
* @var Drawer
*/
protected $drawer;
/**
* Component width
*
* @var float
*/
public $width = 1.0;
/**
* Component height
*
* @var float
*/
public $height = 1.0;
/**
* Position X of the center the graph (from 0 to 1)
*
* @var float
*/
public $x = 0.5;
/**
* Position Y of the center the graph (from 0 to 1)
*
* @var float
*/
public $y = 0.5;
/**
* Component absolute width (in pixels)
*
*
* @var int
*/
public $w;
/**
* Component absolute height (in pixels)
*
*
* @var int
*/
public $h;
/**
* Left-top corner Y position
*
* @var float
*/
public $top;
/**
* Left-top corner X position
*
* @var float
*/
public $left;
/**
* Component background color
*
* @var Color
*/
protected $background;
/**
* Component padding
*
* @var Side
*/
protected $padding;
/**
* Component space
*
* @var Side
*/
protected $space;
/**
* Component title
*
* @var Label
*/
public $title;
/**
* Adjust automatically the component ?
*
* @var bool
*/
protected $auto = TRUE;
/**
* Legend
*
* @var Legend
*/
public $legend;
/**
* Build the component
*/
public function __construct() {
// Component legend
$this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0);
// Component title
$this->title = new awLabel(
NULL,
new awTuffy(10),
NULL,
0
);
$this->title->setAlign(awLabel::CENTER, awLabel::TOP);
}
/**
* Adjust automatically the component ?
*
* @param bool $auto
*/
public function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Change the size of the component
*
* @param int $width Component width (from 0 to 1)
* @param int $height Component height (from 0 to 1)
*/
public function setSize($width, $height) {
$this->width = (float)$width;
$this->height = (float)$height;
}
/**
* Change the absolute size of the component
*
* @param int $w Component width (in pixels)
* @param int $h Component height (in pixels)
*/
public function setAbsSize($w, $h) {
$this->w = (int)$w;
$this->h = (int)$h;
}
/**
* Change component background color
*
* @param awColor $color (can be null)
*/
public function setBackgroundColor($color) {
if($color === NULL or $color instanceof awColor) {
$this->background = $color;
}
}
/**
* Change component background gradient
*
* @param awGradient $gradient (can be null)
*/
public function setBackgroundGradient($gradient) {
if($gradient === NULL or $gradient instanceof awGradient) {
$this->background = $gradient;
}
}
/**
* Change component background image
*
* @param awImage $image (can be null)
*/
public function setBackgroundImage($image) {
if($image === NULL or $image instanceof awImage) {
$this->background = $image;
}
}
/**
* Return the component background
*
* @return Color, Gradient
*/
public function getBackground() {
return $this->background;
}
/**
* Change component padding
*
* @param int $left Padding in pixels (NULL to keep old value)
* @param int $right Padding in pixels (NULL to keep old value)
* @param int $top Padding in pixels (NULL to keep old value)
* @param int $bottom Padding in pixels (NULL to keep old value)
*/
public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom);
}
/**
* Change component space
*
* @param float $left Space in % (NULL to keep old value)
* @param float $right Space in % (NULL to keep old value)
* @param float $bottom Space in % (NULL to keep old value)
* @param float $top Space in % (NULL to keep old value)
*/
public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top);
}
/**
* Change the absolute position of the component on the graph
*
* @var int $x Left-top corner X position
* @var int $y Left-top corner Y position
*/
public function setAbsPosition($left, $top) {
$this->left = (int)$left;
$this->top = (int)$top;
}
/**
* Set the center of the component
*
* @param int $x Position on X axis of the center of the component
* @param int $y Position on Y axis of the center of the component
*/
public function setCenter($x, $y) {
$this->x = (float)$x;
$this->y = (float)$y;
}
/**
* Get component coords with its padding
*
* @return array Coords of the component
*/
public function getPosition() {
// Get component coords
$x1 = $this->padding->left;
$y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2);
}
/**
* Init the drawing of the component
*/
public function init(awDrawer $drawer) {
// Set component background
$background = $this->getBackground();
if($background !== NULL) {
$p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1);
if($background instanceof awImage) {
$drawer->copyImage(
$background,
$p1,
$p2
);
} else {
$drawer->filledRectangle(
$background,
new awLine($p1, $p2)
);
}
}
}
/**
* Finalize the drawing of the component
*/
public function finalize(awDrawer $drawer) {
// Draw component title
$point = new awPoint(
$this->w / 2,
$this->padding->top - 8
);
$this->title->draw($drawer, $point);
// Draw legend
$this->legend->draw($drawer);
}
/**
* Draw the grid around your component
*
* @param Drawer A drawer
* @return array Coords for the component
*/
abstract public function drawEnvelope(awDrawer $drawer);
/**
* Draw the component on the graph
* Component should be drawed into specified coords
*
* @param Drawer A drawer
* @param int $x1
* @param int $y1
* @param int $x2
* @param int $y2
* @param bool $aliasing Use anti-aliasing to draw the component ?
*/
abstract public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing);
/**
* Get space width in pixels
*
* @param int $width Component width
* @param int $height Component height
* @return array
*/
protected function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom);
}
}
registerClass('Component', TRUE);
?>

View File

@@ -0,0 +1,394 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
// Artichow configuration
/* <php5> */
if(is_file(dirname(__FILE__)."/Artichow.cfg.php")) { // For PHP 4+5 version
require_once dirname(__FILE__)."/Artichow.cfg.php";
}
/* </php5> */
// Some useful files
require_once ARTICHOW."/common.php";
require_once ARTICHOW."/Component.class.php";
require_once ARTICHOW."/Image.class.php";
require_once ARTICHOW."/inc/Grid.class.php";
require_once ARTICHOW."/inc/Tools.class.php";
require_once ARTICHOW."/inc/Drawer.class.php";
require_once ARTICHOW."/inc/Math.class.php";
require_once ARTICHOW."/inc/Tick.class.php";
require_once ARTICHOW."/inc/Axis.class.php";
require_once ARTICHOW."/inc/Legend.class.php";
require_once ARTICHOW."/inc/Mark.class.php";
require_once ARTICHOW."/inc/Label.class.php";
require_once ARTICHOW."/inc/Text.class.php";
require_once ARTICHOW."/inc/Color.class.php";
require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php";
/**
* A graph
*
* @package Artichow
*/
class awGraph extends awImage {
/**
* Graph name
*
* @var string
*/
protected $name;
/**
* Cache timeout
*
* @var int
*/
protected $timeout = 0;
/**
* Graph timing ?
*
* @var bool
*/
protected $timing;
/**
* Components
*
* @var array
*/
private $components = array();
/**
* Some labels to add to the component
*
* @var array
*/
protected $labels = array();
/**
* Graph title
*
* @var Label
*/
public $title;
/**
* Construct a new graph
*
* @param int $width Graph width
* @param int $height Graph height
* @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.
* @param int $timeout Cache timeout (unix timestamp)
*/
public function __construct($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
parent::__construct();
$this->setSize($width, $height);
if(ARTICHOW_CACHE) {
$this->name = $name;
$this->timeout = $timeout;
// Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache();
}
if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
awGraph::deleteFromCache($this->name);
} else {
header("Content-Type: image/".$type);
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit;
}
}
}
}
$this->title = new awLabel(
NULL,
new awTuffy(16),
NULL,
0
);
$this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
}
/**
* Delete a graph from the cache
*
* @param string $name Graph name
* @return bool TRUE on success, FALSE on failure
*/
public static function deleteFromCache($name) {
if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
}
}
}
/**
* Delete all graphs from the cache
*/
public static function deleteAllCache() {
if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) {
if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
}
}
}
}
/**
* Clean cache
*/
public static function cleanCache() {
if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file);
if($type === NULL) {
$name = ereg_replace(".*/(.*)\-time", "\\1", $file);
awGraph::deleteFromCache($name);
}
}
}
}
/**
* Enable/Disable Graph timing
*
* @param bool $timing
*/
public function setTiming($timing) {
$this->timing = (bool)$timing;
}
/**
* Add a component to the graph
*
* @param awComponent $component
*/
public function add(awComponent $component) {
$this->components[] = $component;
}
/**
* Add a label to the component
*
* @param awLabel $label
* @param int $x Position on X axis of the center of the text
* @param int $y Position on Y axis of the center of the text
*/
public function addLabel(awLabel $label, $x, $y) {
$this->labels[] = array(
$label, $x, $y
);
}
/**
* Add a label to the component with aboslute position
*
* @param awLabel $label
* @param awPoint $point Text position
*/
public function addAbsLabel(awLabel $label, awPoint $point) {
$this->labels[] = array(
$label, $point
);
}
/**
* Build the graph and draw component on it
* Image is sent to the user browser
*
* @param string $file Save the image in the specified file. Let it null to print image to screen.
*/
public function draw($file = NULL) {
if($this->timing) {
$time = microtimeFloat();
}
$this->create();
foreach($this->components as $component) {
$this->drawComponent($component);
}
$this->drawTitle();
$this->drawShadow();
$this->drawLabels();
if($this->timing) {
$this->drawTiming(microtimeFloat() - $time);
}
if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start();
}
$this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable");
}
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data);
$file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean();
echo $data;
}
}
private function drawLabels() {
$drawer = $this->getDrawer();
foreach($this->labels as $array) {
if(count($array) === 3) {
// Text in relative position
list($label, $x, $y) = $array;
$point = new awPoint(
$x * $this->width,
$y * $this->height
);
} else {
// Text in absolute position
list($label, $point) = $array;
}
$label->draw($drawer, $point);
}
}
private function drawTitle() {
$drawer = $this->getDrawer();
$point = new awPoint(
$this->width / 2,
10
);
$this->title->draw($drawer, $point);
}
private function drawTiming($time) {
$drawer = $this->getDrawer();
$label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(awLabel::LEFT, awLabel::TOP);
$label->border->show();
$label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
}
private static function cleanGraphCache($file) {
list(
$time,
$type
) = explode("\n", file_get_contents($file));
$time = (int)$time;
if($time !== 0 and $time < time()) {
return NULL;
} else {
return $type;
}
}
}
registerClass('Graph');
/*
* To preserve PHP 4 compatibility
*/
function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
}
?>

View File

@@ -0,0 +1,421 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("IMAGE_JPEG", 1);
define("IMAGE_PNG", 2);
define("IMAGE_GIF", 3);
/* </php4> */
/*
* Check for GD2
*/
if(function_exists('imagecreatetruecolor') === FALSE) {
trigger_error("You must compile PHP with GD2 support to use Artichow", E_USER_ERROR);
}
require_once ARTICHOW."/inc/Shadow.class.php";
require_once ARTICHOW."/inc/Border.class.php";
/**
* An image for a graph
*
* @package Artichow
*/
class awImage {
/**
* Graph width
*
* @var int
*/
public $width;
/**
* Graph height
*
* @var int
*/
public $height;
/**
* Use anti-aliasing ?
*
* @var bool
*/
protected $antiAliasing = FALSE;
/**
* Image format
*
* @var int
*/
protected $format = awImage::PNG;
/**
* Image background color
*
* @var Color
*/
protected $background;
/**
* GD resource
*
* @var resource
*/
protected $resource;
/**
* Image drawer
*
* @var Drawer
*/
protected $drawer;
/**
* Shadow
*
* @var Shadow
*/
public $shadow;
/**
* Image border
*
* @var Border
*/
public $border;
/**
* Use JPEG for image
*
* @var int
*/
const JPEG = IMG_JPG;
/**
* Use PNG for image
*
* @var int
*/
const PNG = IMG_PNG;
/**
* Use GIF for image
*
* @var int
*/
const GIF = IMG_GIF;
/**
* Build the image
*/
public function __construct() {
$this->background = new awColor(255, 255, 255);
$this->shadow = new awShadow(awShadow::RIGHT_BOTTOM);
$this->border = new awBorder;
}
/**
* Get drawer of the image
*
* @param int $w Drawer width (from 0 to 1) (default to 1)
* @param int $h Drawer height (from 0 to 1) (default to 1)
* @param float $x Position on X axis of the center of the drawer (default to 0.5)
* @param float $y Position on Y axis of the center of the drawer (default to 0.5)
* @return Drawer
*/
public function getDrawer($w = 1, $h = 1, $x = 0.5, $y = 0.5) {
$this->create();
$this->drawer->setSize($w, $h);
$this->drawer->setPosition($x, $y);
return $this->drawer;
}
/**
* Change the image size
*
* @var int $width Image width
* @var int $height Image height
*/
public function setSize($width, $height) {
if($width !== NULL) {
$this->width = (int)$width;
}
if($height !== NULL) {
$this->height = (int)$height;
}
}
/**
* Change image background color
*
* @param awColor $color
*/
public function setBackgroundColor(awColor $color) {
$this->background = $color;
}
/**
* Change image background gradient
*
* @param awGradient $gradient
*/
public function setBackgroundGradient(awGradient $gradient) {
$this->background = $gradient;
}
/**
* Can we use anti-aliasing ?
*
* @var bool $bool
*/
public function setAntiAliasing($bool) {
$this->antiAliasing = (bool)$bool;
}
/**
* Change image format
*
* @var int $format New image format
*/
public function setFormat($format) {
if($format === awImage::JPEG or $format === awImage::PNG or $format === awImage::GIF) {
$this->format = $format;
}
}
/**
* Create a new awimage
*/
public function create() {
if($this->resource === NULL) {
// Create image
$this->resource = imagecreatetruecolor($this->width, $this->height);
if(!$this->resource) {
trigger_error("Unable to create a graph", E_USER_ERROR);
}
imagealphablending($this->resource, TRUE);
if($this->antiAliasing and function_exists('imageantialias')) {
imageantialias($this->resource, TRUE);
}
$this->drawer = new awDrawer($this->resource);
$this->drawer->setImageSize($this->width, $this->height);
// Original color
$this->drawer->filledRectangle(
new awWhite,
new awLine(
new awPoint(0, 0),
new awPoint($this->width, $this->height)
)
);
$shadow = $this->shadow->getSpace();
$p1 = new awPoint($shadow->left, $shadow->top);
$p2 = new awPoint($this->width - $shadow->right - 1, $this->height - $shadow->bottom - 1);
// Draw image background
$this->drawer->filledRectangle($this->background, new awLine($p1, $p2));
$this->background->free();
// Draw image border
$this->border->rectangle($this->drawer, $p1, $p2);
}
}
/**
* Draw a component on the image
*
* @var awComponent $component A component
*/
public function drawComponent(awComponent $component) {
$shadow = $this->shadow->getSpace(); // Image shadow
$border = $this->border->visible() ? 1 : 0; // Image border size
$drawer = clone $this->drawer;
$drawer->setImageSize(
$this->width - $shadow->left - $shadow->right - $border * 2,
$this->height - $shadow->top - $shadow->bottom - $border * 2
);
// No absolute size specified
if($component->w === NULL and $component->h === NULL) {
list($width, $height) = $drawer->setSize($component->width, $component->height);
// Set component size in pixels
$component->setAbsSize($width, $height);
} else {
$drawer->setAbsSize($component->w, $component->h);
}
if($component->top !== NULL and $component->left !== NULL) {
$drawer->setAbsPosition(
$border + $shadow->left + $component->left,
$border + $shadow->top + $component->top
);
} else {
$drawer->setPosition($component->x, $component->y);
}
$drawer->movePosition($border + $shadow->left, $border + $shadow->top);
list($x1, $y1, $x2, $y2) = $component->getPosition();
$component->init($drawer);
$component->drawComponent($drawer, $x1, $y1, $x2, $y2, $this->antiAliasing);
$component->drawEnvelope($drawer, $x1, $y1, $x2, $y2);
$component->finalize($drawer);
}
protected function drawShadow() {
$drawer = $this->getDrawer();
$this->shadow->draw(
$drawer,
new awPoint(0, 0),
new awPoint($this->width, $this->height),
awShadow::IN
);
}
/**
* Send the image into a file or to the user browser
*
* @var string $file Save image into a file if you provide a file name
*/
public function send($file = NULL) {
// Test if format is available
if((imagetypes() & $this->format) === FALSE) {
trigger_error("Format '".$this->format."' is not available on your system. Check that your PHP has been compiled with the good libraries.");
}
// Get some infos about this image
switch($this->format) {
case awImage::JPEG :
$function = 'imagejpeg';
break;
case awImage::PNG :
$function = 'imagepng';
break;
case awImage::GIF :
$function = 'imagegif';
break;
}
// Create image
if($file !== NULL) {
$function($this->resource, $file);
} else {
// Send headers to the browser
if(headers_sent() === FALSE) {
header("Content-type: image/".$this->getFormat());
}
$function($this->resource);
}
}
protected function getFormat() {
switch($this->format) {
case awImage::JPEG :
return 'jpeg';
case awImage::PNG :
return 'png';
case awImage::GIF :
return 'gif';
}
}
}
registerClass('Image');
/**
* Load an image from a file
*
* @package Artichow
*/
class awFileImage extends awImage {
/**
* Build a new awimage
*
* @param string $file Image file name
*/
public function __construct($file) {
$image = @getimagesize($file);
if($image and in_array($image[2], array(2, 3))) {
$this->setSize($image[0], $image[1]);
switch($image[2]) {
case 2 :
$this->resource = imagecreatefromjpeg($file);
break;
case 3 :
$this->resource = imagecreatefrompng($file);
break;
}
$this->drawer = new awDrawer($this->resource);
$this->drawer->setImageSize($this->width, $this->height);
} else {
trigger_error("Artichow does not support this image (must be in PNG or JPEG)", E_USER_ERROR);
}
}
}
registerClass('FileImage');
?>

View File

@@ -0,0 +1,596 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/* <php4> */
define("LINEPLOT_LINE", 0);
define("LINEPLOT_MIDDLE", 1);
/* </php4> */
/**
* LinePlot
*
* @package Artichow
*/
class awLinePlot extends awPlot implements awLegendable {
/**
* Add marks to your line plot
*
* @var Mark
*/
public $mark;
/**
* Labels on your line plot
*
* @var Label
*/
public $label;
/**
* Filled areas
*
* @var bool
*/
protected $areas = array();
/**
* Is the line hidden
*
* @var bool
*/
protected $lineHide = FALSE;
/**
* Line color
*
* @var Color
*/
protected $lineColor;
/**
* Line mode
*
* @var int
*/
protected $lineMode = awLinePlot::LINE;
/**
* Line type
*
* @var int
*/
protected $lineStyle = awLine::SOLID;
/**
* Line thickness
*
* @var int
*/
protected $lineThickness = 1;
/**
* Line background
*
* @var Color, Gradient
*/
protected $lineBackground;
/**
* Line mode
*
* @var int
*/
const LINE = 0;
/**
* Line in the middle
*
* @var int
*/
const MIDDLE = 1;
/**
* Construct a new awLinePlot
*
* @param array $values Some numeric values for Y axis
* @param int $mode
*/
public function __construct($values, $mode = awLinePlot::LINE) {
parent::__construct();
$this->mark = new awMark;
$this->label = new awLabel;
$this->lineMode = (int)$mode;
$this->setValues($values);
}
/**
* Hide line
*
* @param bool $hide
*/
public function hideLine($hide) {
$this->lineHide = (bool)$hide;
}
/**
* Add a filled area
*
* @param int $start Begining of the area
* @param int $end End of the area
* @param mixed $background Background color or gradient of the area
*/
public function setFilledArea($start, $stop, $background) {
if($stop <= $start) {
trigger_error("End position can not be greater than begin position in awLinePlot::setFilledArea()", E_USER_ERROR);
}
$this->areas[] = array((int)$start, (int)$stop, $background);
}
/**
* Change line color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
public function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
public function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Change line background color
*
* @param awColor $color
*/
public function setFillColor(awColor $color) {
$this->lineBackground = $color;
}
/**
* Change line background gradient
*
* @param awGradient $gradient
*/
public function setFillGradient(awGradient $gradient) {
$this->lineBackground = $gradient;
}
/**
* Get the line thickness
*
* @return int
*/
public function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
public function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
public function getLegendLineColor() {
return $this->lineColor;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground() {
return $this->lineBackground;
}
/**
* Get a mark object
*
* @return Mark
*/
public function getLegendMark() {
return $this->mark;
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
$max = $this->getRealYMax();
$min = $this->getRealYMin();
// Get start and stop values
list($start, $stop) = $this->getLimit();
if($this->lineMode === awLinePlot::MIDDLE) {
$inc = $this->xAxis->getDistance(0, 1) / 2;
} else {
$inc = 0;
}
// Build the polygon
$polygon = new awPolygon;
for($key = $start; $key <= $stop; $key++) {
$value = $this->datay[$key];
if($value !== NULL) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
$p = $p->move($inc, 0);
$polygon->set($key, $p);
}
}
// Draw backgrounds
if($this->lineBackground instanceof awColor or $this->lineBackground instanceof awGradient) {
$backgroundPolygon = new awPolygon;
$p = $this->xAxisPoint($start);
$p = $p->move($inc, 0);
$backgroundPolygon->append($p);
// Add others points
foreach($polygon->all() as $point) {
$backgroundPolygon->append(clone $point);
}
$p = $this->xAxisPoint($stop);
$p = $p->move($inc, 0);
$backgroundPolygon->append($p);
// Draw polygon background
$drawer->filledPolygon($this->lineBackground, $backgroundPolygon);
}
$this->drawArea($drawer, $polygon);
// Draw line
$prev = NULL;
// Line color
if($this->lineHide === FALSE) {
if($this->lineColor === NULL) {
$this->lineColor = new awColor(0, 0, 0);
}
foreach($polygon->all() as $point) {
if($prev !== NULL) {
$drawer->line(
$this->lineColor,
new awLine(
$prev,
$point,
$this->lineStyle,
$this->lineThickness
)
);
}
$prev = $point;
}
$this->lineColor->free();
}
// Draw marks and labels
foreach($polygon->all() as $key => $point) {
$this->mark->draw($drawer, $point);
$this->label->draw($drawer, $point, $key);
}
}
protected function drawArea(awDrawer $drawer, awPolygon $polygon) {
$starts = array();
foreach($this->areas as $area) {
list($start) = $area;
$starts[$start] = TRUE;
}
// Draw filled areas
foreach($this->areas as $area) {
list($start, $stop, $background) = $area;
$polygonArea = new awPolygon;
$p = $this->xAxisPoint($start);
$polygonArea->append($p);
for($i = $start; $i <= $stop; $i++) {
$p = clone $polygon->get($i);
if($i === $stop and array_key_exists($stop, $starts)) {
$p = $p->move(-1, 0);
}
$polygonArea->append($p);
}
$p = $this->xAxisPoint($stop);
if(array_key_exists($stop, $starts)) {
$p = $p->move(-1, 0);
}
$polygonArea->append($p);
// Draw area
$drawer->filledPolygon($background, $polygonArea);
}
}
public function getXAxisNumber() {
if($this->lineMode === awLinePlot::MIDDLE) {
return count($this->datay) + 1;
} else {
return count($this->datay);
}
}
protected function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
public function getXCenter() {
return ($this->lineMode === awLinePlot::MIDDLE);
}
}
registerClass('LinePlot');
/**
* Simple LinePlot
* Useful to draw simple horizontal lines
*
* @package Artichow
*/
class awSimpleLinePlot extends awPlot implements awLegendable {
/**
* Line color
*
* @var Color
*/
protected $lineColor;
/**
* Line start
*
* @var int
*/
protected $lineStart;
/**
* Line stop
*
* @var int
*/
protected $lineStop;
/**
* Line value
*
* @var flaot
*/
protected $lineValue;
/**
* Line mode
*
* @var int
*/
protected $lineMode = awLinePlot::LINE;
/**
* Line type
*
* @var int
*/
protected $lineStyle = awLine::SOLID;
/**
* Line thickness
*
* @var int
*/
protected $lineThickness = 1;
/**
* Line mode
*
* @var int
*/
const LINE = 0;
/**
* Line in the middle
*
* @var int
*/
const MIDDLE = 1;
/**
* Construct a new awLinePlot
*
* @param float $value A Y value
* @param int $start Line start index
* @param int $stop Line stop index
* @param int $mode Line mode
*/
public function __construct($value, $start, $stop, $mode = awLinePlot::LINE) {
parent::__construct();
$this->lineMode = (int)$mode;
$this->lineStart = (int)$start;
$this->lineStop = (int)$stop;
$this->lineValue = (float)$value;
$this->lineColor = new awColor(0, 0, 0);
}
/**
* Change line color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
public function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
public function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Get the line thickness
*
* @return int
*/
public function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
public function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
public function getLegendLineColor() {
return $this->lineColor;
}
public function getLegendBackground() {
return NULL;
}
public function getLegendMark() {
return NULL;
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
if($this->lineMode === awLinePlot::MIDDLE) {
$inc = $this->xAxis->getDistance(0, 1) / 2;
} else {
$inc = 0;
}
$p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
$p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
$drawer->line(
$this->lineColor,
new awLine(
$p1->move($inc, 0),
$p2->move($inc, 0),
$this->lineStyle,
$this->lineThickness
)
);
$this->lineColor->free();
}
public function getXAxisNumber() {
if($this->lineMode === awLinePlot::MIDDLE) {
return count($this->datay) + 1;
} else {
return count($this->datay);
}
}
protected function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
public function getXCenter() {
return ($this->lineMode === awLinePlot::MIDDLE);
}
}
registerClass('SimpleLinePlot');
?>

View File

@@ -0,0 +1,443 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Component.class.php";
/**
* A mathematic function
*
* @package Artichow
*/
class awMathFunction implements awLegendable {
/**
* Function line
*
* @var Line
*/
public $line;
/**
* Marks for your plot
*
* @var Mark
*/
public $mark;
/**
* Callback function
*
* @var string
*/
public $f;
/**
* Start the drawing from this value
*
* @var float
*/
public $fromX;
/**
* Stop the drawing at this value
*
* @var float
*/
public $toX;
/**
* Line color
*
* @var Color
*/
protected $color;
/**
* Construct the function
*
* @param string $f Callback function
* @param float $fromX
* @param float $toX
*/
public function __construct($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine;
$this->mark = new awMark;
$this->color = new awBlack;
}
/**
* Change line color
*
* @param awColor $color A new awcolor
*/
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Get line color
*
* @return Color
*/
public function getColor() {
return $this->color;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground() {
}
/**
* Get the line thickness
*
* @return NULL
*/
public function getLegendLineThickness() {
return $this->line->getThickness();
}
/**
* Get the line type
*
* @return NULL
*/
public function getLegendLineStyle() {
return $this->line->getStyle();
}
/**
* Get the color of line
*
* @return NULL
*/
public function getLegendLineColor() {
return $this->color;
}
/**
* Get a mark object
*
* @return NULL
*/
public function getLegendMark() {
return $this->mark;
}
}
registerClass('MathFunction');
/**
* For mathematics functions
*
* @package Artichow
*/
class awMathPlot extends awComponent {
/**
* Functions
*
* @var array
*/
protected $functions = array();
/**
* Grid properties
*
* @var Grid
*/
public $grid;
/**
* X axis
*
* @var Axis
*/
public $xAxis;
/**
* Y axis
*
* @var Axis
*/
public $yAxis;
/**
* Extremum
*
* @var Side
*/
private $extremum = NULL;
/**
* Interval
*
* @var float
*/
private $interval = 1;
/**
* Build the plot
*
* @param int $xMin Minimum X value
* @param int $xMax Maximum X value
* @param int $yMax Maximum Y value
* @param int $yMin Minimum Y value
*/
public function __construct($xMin, $xMax, $yMax, $yMin) {
parent::__construct();
$this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid;
// Hide grid by default
$this->grid->hide(TRUE);
// Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis
$this->xAxis = new awAxis;
$this->xAxis->setTickStyle(awTick::IN);
$this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis);
$this->yAxis = new awAxis;
$this->yAxis->setTickStyle(awTick::IN);
$this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis);
}
protected function initAxis(awAxis $axis) {
$axis->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7));
}
/**
* Interval to calculate values
*
* @param float $interval
*/
public function setInterval($interval) {
$this->interval = (float)$interval;
}
/**
* Add a formula f(x)
*
* @param awMathFunction $function
* @param string $name Name for the legend (can be NULL if you don't want to set a legend)
* @param int $type Type for the legend
*/
public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) {
$this->functions[] = $function;
if($name !== NULL) {
$this->legend->add($function, $name, $type);
}
}
public function init(awDrawer $drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, awLabel::BOTTOM);
$this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(awLabel::RIGHT);
$this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number);
}
if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number);
}
// Set ticks
/* <php5> */
$this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->tick('major')->setNumber($this->yAxis->getLabelNumber());
/* </php5> */
/* <php4> --
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
-- </php4> */
// Set axis labels
$labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->xAxis->label->set($labels);
$labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i;
}
$this->yAxis->label->set($labels);
parent::init($drawer);
// Create the grid
$this->createGrid();
// Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
}
public function drawEnvelope(awDrawer $drawer) {
// Draw axis
$this->xAxis->draw($drawer);
$this->yAxis->draw($drawer);
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) {
$f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
if($old !== NULL) {
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
) {
$drawer->line(
$function->getColor(),
$line
);
}
}
$old = $p;
}
// Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p);
}
$line = $function->line;
$line->setLocation($old, $p);
if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2)
) {
$drawer->line(
$function->getColor(),
$line
);
}
}
}
}
protected function createGrid() {
// Horizontal lines of the grid
$major = $this->yAxis->tick('major');
$interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1;
$h = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number;
}
}
// Vertical lines
$major = $this->xAxis->tick('major');
$interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1;
$w = array();
if($number > 0) {
for($i = 0; $i <= $number; $i++) {
if($i%$interval === 0) {
$w[] = $i / $number;
}
}
}
$this->grid->setGrid($w, $h);
}
}
registerClass('MathPlot');
?>

View File

@@ -0,0 +1,97 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Graph.class.php";
/**
* All patterns must derivate from this class
*
* @package Artichow
*/
abstract class awPattern {
/**
* Pattern arguments
*
* @var array
*/
protected $args = array();
/**
* Load a pattern
*
* @param string $pattern Pattern name
* @return Component
*/
public static function get($pattern) {
$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
if(is_file($file)) {
require_once $file;
$class = $pattern.'Pattern';
if(class_exists($class)) {
return new $class;
} else {
trigger_error("Class '".$class."' does not exist", E_USER_ERROR);
}
} else {
trigger_error("Pattern '".$pattern."' does not exist", E_USER_ERROR);
}
}
/**
* Change pattern argument
*
* @param string $name Argument name
* @param mixed $value Argument value
*/
public function setArg($name, $value) {
if(is_string($name)) {
$this->args[$name] = $value;
}
}
/**
* Get an argument
*
* @param string $name
* @param mixed $default Default value if the argument does not exist (default to NULL)
* @return mixed Argument value
*/
protected function getArg($name, $default = NULL) {
if(array_key_exists($name, $this->args)) {
return $this->args[$name];
} else {
return $default;
}
}
/**
* Change several arguments
*
* @param array $args New arguments
*/
public function setArgs($args) {
if(is_array($args)) {
foreach($args as $name => $value) {
$this->setArg($name, $value);
}
}
}
}
registerClass('Pattern', TRUE);
?>

View File

@@ -0,0 +1,680 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Component.class.php";
/* <php4> */
define("PIE_DARK", 1);
define("PIE_COLORED", 2);
define("PIE_AQUA", 3);
define("PIE_EARTH", 4);
/* </php4> */
/**
* Pie
*
* @package Artichow
*/
class awPie extends awComponent {
/**
* A dark theme for pies
*
*
* @var int
*/
const DARK = 1;
/**
* A colored theme for pies
*
* @var int
*/
const COLORED = 2;
/**
* A water theme for pies
*
* @var int
*/
const AQUA = 3;
/**
* A earth theme for pies
*
* @var int
*/
const EARTH = 4;
/**
* Pie values
*
* @var array
*/
protected $values;
/**
* Pie colors
*
* @var array
*/
protected $colors;
/**
* Pie legend
*
* @var array
*/
protected $legendValues = array();
/**
* Intensity of the 3D effect
*
* @var int
*/
protected $size;
/**
* Border color
*
* @var Color
*/
protected $border;
/**
* Pie explode
*
* @var array
*/
protected $explode = array();
/**
* Initial angle
*
* @var int
*/
protected $angle = 0;
/**
* Labels precision
*
* @var int
*/
protected $precision;
/**
* Labels number
*
* @var int
*/
protected $number;
/**
* Labels minimum
*
* @var int
*/
protected $minimum;
/**
* Labels position
*
* @var int
*/
protected $position = 15;
/**
* Labels of your pie
*
* @var Label
*/
public $label;
/**
* Build the plot
*
* @param array $values Pie values
*/
public function __construct($values, $colors = awPie::COLORED) {
$this->setValues($values);
if(is_array($colors)) {
$this->colors = $colors;
} else {
switch($colors) {
case awPie::AQUA :
$this->colors = array(
new awColor(131, 220, 215),
new awColor(131, 190, 215),
new awColor(131, 160, 215),
new awColor(160, 140, 215),
new awColor(190, 131, 215),
new awColor(220, 131, 215)
);
break;
case awPie::EARTH :
$this->colors = array(
new awColor(97, 179, 110),
new awColor(130, 179, 97),
new awColor(168, 179, 97),
new awColor(179, 147, 97),
new awColor(179, 108, 97),
new awColor(99, 107, 189),
new awColor(99, 165, 189)
);
break;
case awPie::DARK :
$this->colors = array(
new awColor(140, 100, 170),
new awColor(130, 170, 100),
new awColor(160, 160, 120),
new awColor(150, 110, 140),
new awColor(130, 150, 160),
new awColor(90, 170, 140)
);
break;
default :
$this->colors = array(
new awColor(187, 213, 151),
new awColor(223, 177, 151),
new awColor(111, 186, 132),
new awColor(197, 160, 230),
new awColor(165, 169, 63),
new awColor(218, 177, 89),
new awColor(116, 205, 121),
new awColor(200, 201, 78),
new awColor(127, 205, 177),
new awColor(205, 160, 160),
new awColor(190, 190, 190)
);
break;
}
}
parent::__construct();
$this->label = new awLabel;
$this->label->setCallbackFunction('callbackPerCent');
}
/**
* Change legend values
*
* @param array $legend An array of values for each part of the pie
*/
public function setLegend($legend) {
$this->legendValues = (array)$legend;
}
/**
* Set a border all around the pie
*
* @param awColor $color A color for the border
*/
public function setBorder(awColor $color) {
$this->border = $color;
}
/**
* Change 3D effect intensity
*
* @param int $size Effect size
*/
public function set3D($size) {
$this->size = (int)$size;
}
/**
* Change initial angle
*
* @param int $angle New angle in degrees
*/
public function setStartAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Change label precision
*
* @param int $precision New precision
*/
public function setLabelPrecision($precision) {
$this->precision = (int)$precision;
}
/**
* Change label position
*
* @param int $position New position in pixels
*/
public function setLabelPosition($position) {
$this->position = (int)$position;
}
/**
* Change label number
*
* @param int $number New number
*/
public function setLabelNumber($number) {
$this->number = is_null($number) ? $number : (int)$number;
}
/**
* Change label minimum
*
* @param int $minimum New minimum
*/
public function setLabelMinimum($minimum) {
$this->minimum = is_null($minimum) ? $minimum : (int)$minimum;
}
/**
* Change Pie explode
*
* @param array $explode
*/
public function explode($explode) {
$this->explode = (array)$explode;
}
public function drawEnvelope(awDrawer $drawer) {
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->values);
$sum = array_sum($this->values);
$width = $x2 - $x1;
$height = $y2 - $y1;
if($aliasing) {
$x = $width / 2;
$y = $height / 2;
} else {
$x = $width / 2 + $x1;
$y = $height / 2 + $y1;
}
$position = $this->angle;
$values = array();
$parts = array();
$angles = 0;
if($aliasing) {
$side = new awSide(0, 0, 0, 0);
}
foreach($this->values as $key => $value) {
$angle = ($value / $sum * 360);
if($key === $count - 1) {
$angle = 360 - $angles;
}
$angles += $angle;
if(array_key_exists($key, $this->explode)) {
$middle = 360 - ($position + $angle / 2);
$posX = $this->explode[$key] * cos($middle * M_PI / 180);
$posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
if($aliasing) {
$explode = new awPoint(
$posX * 2,
$posY * 2
);
$side->set(
max($side->left, $posX * -2),
max($side->right, $posX * 2),
max($side->top, $posY * -2),
max($side->bottom, $posY * 2)
);
} else {
$explode = new awPoint(
$posX,
$posY
);
}
} else {
$explode = new awPoint(0, 0);
}
$values[$key] = array(
$position, ($position + $angle), $explode
);
$color = $this->colors[$key % count($this->colors)];
$parts[$key] = new awPiePart($color);
// Add part to the legend
$legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
$this->legend->add($parts[$key], $legend, awLegend::BACKGROUND);
$position += $angle;
}
if($aliasing) {
$mainDrawer = $drawer;
$x *= 2;
$y *= 2;
$width *= 2;
$height *= 2;
$this->size *= 2;
$image = new awImage;
$image->border->hide();
$image->setSize(
$width + $side->left + $side->right,
$height + $side->top + $side->bottom + $this->size + 1 /* bugs.php.net ! */
);
$drawer = $image->getDrawer(
$width / $image->width,
$height / $image->height,
($width / 2 + $side->left) / $image->width,
($height / 2 + $side->top) / $image->height
);
}
// Draw 3D effect
for($i = $this->size; $i > 0; $i--) {
foreach($values as $key => $value) {
$color = clone $this->colors[$key % count($this->colors)];
$color->brightness(-50);
list($from, $to, $explode) = $value;
$drawer->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
$color->free();
unset($color);
if($this->border instanceof awColor) {
$point = $explode->move($x, $y);
if($i === $this->size) {
$drawer->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
}
}
}
}
foreach($values as $key => $value) {
$color = $this->colors[$key % count($this->colors)];
list($from, $to, $explode) = $value;
$drawer->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
if($this->border instanceof awColor) {
$point = $explode->move($x, $y);
$drawer->arc($this->border, $point, $width, $height, $from, $to);
}
}
if($aliasing) {
$x = $x / 2 + $x1;
$y = $y / 2 + $y1;
$width /= 2;
$height /= 2;
$this->size /= 2;
foreach($values as $key => $value) {
$old = $values[$key][2];
$values[$key][2] = new awPoint(
$old->x / 2, $old->y / 2
);
}
$mainDrawer->copyResizeImage(
$image,
new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2),
new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height/ 2),
new awPoint(0, 0),
new awPoint($image->width, $image->height),
TRUE
);
$drawer = $mainDrawer;
}
// Get labels values
$pc = array();
foreach($this->values as $key => $value) {
$pc[$key] = round($value / $sum * 100, $this->precision);
}
if($this->label->count() === 0) { // Check that there is no user defined values
$this->label->set($pc);
}
$position = 0;
foreach($pc as $key => $value) {
// Limit number of labels to display
if($position === $this->number) {
break;
}
if(is_null($this->minimum) === FALSE and $value < $this->minimum) {
continue;
}
$position++;
list($from, $to, $explode) = $values[$key];
$angle = $from + ($to - $from) / 2;
$angleRad = (360 - $angle) * M_PI / 180;
$point = new awPoint(
$x + $explode->x + cos($angleRad) * ($width / 2 + $this->position),
$y + $explode->y - sin($angleRad) * ($height / 2 + $this->position)
);
$angle %= 360;
// We don't display labels on the 3D effect
if($angle > 0 and $angle < 180) {
$point = $point->move(0, -1 * sin($angleRad) * $this->size);
}
if($angle >= 45 and $angle < 135) {
$this->label->setAlign(awLabel::CENTER, awLabel::BOTTOM);
} else if($angle >= 135 and $angle < 225) {
$this->label->setAlign(awLabel::RIGHT, awLabel::MIDDLE);
} else if($angle >= 225 and $angle < 315) {
$this->label->setAlign(awLabel::CENTER, awLabel::TOP);
} else {
$this->label->setAlign(awLabel::LEFT, awLabel::MIDDLE);
}
$this->label->draw(
$drawer,
$point,
$key
);
}
}
/**
* Return margins around the component
*
* @return array Left, right, top and bottom margins
*/
public function getMargin() {
// Get axis informations
$leftAxis = $this->padding->left;
$rightAxis = $this->padding->right;
$topAxis = $this->padding->top;
$bottomAxis = $this->padding->bottom;
return array($leftAxis, $rightAxis, $topAxis, $bottomAxis);
}
/**
* Change values of Y axis
* This method ignores not numeric values
*
* @param array $values
*/
public function setValues($values) {
$this->checkArray($values);
$this->values = $values;
}
/**
* Return values of Y axis
*
* @return array
*/
public function getValues() {
return $this->values;
}
private function checkArray(&$array) {
if(is_array($array) === FALSE) {
trigger_error("You tried to set values that are not an array");
}
foreach($array as $key => $value) {
if(is_numeric($value) === FALSE) {
unset($array[$key]);
}
}
if(count($array) < 1) {
trigger_error("Your graph must have at least 1 value");
}
}
}
registerClass('Pie');
/**
* Pie
*
* @package Artichow
*/
class awPiePart implements awLegendable {
/**
* Pie part color
*
* @var Color
*/
protected $color;
/**
* Build a new awPiePart
*
* @param awColor $color Pie part color
*/
public function __construct(awColor $color) {
$this->color = $color;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground() {
return $this->color;
}
/**
* Get the line thickness
*
* @return NULL
*/
public function getLegendLineThickness() {
}
/**
* Get the line type
*
* @return NULL
*/
public function getLegendLineStyle() {
}
/**
* Get the color of line
*
* @return NULL
*/
public function getLegendLineColor() {
}
/**
* Get a mark object
*
* @return NULL
*/
public function getLegendMark() {
}
}
registerClass('PiePart');
function callbackPerCent($value) {
return $value.'%';
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,303 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
require_once dirname(__FILE__)."/Plot.class.php";
/**
* ScatterPlot
*
* @package Artichow
*/
class awScatterPlot extends awPlot implements awLegendable {
/**
* Add marks to the scatter plot
*
* @var Mark
*/
public $mark;
/**
* Labels on the plot
*
* @var Label
*/
public $label;
/**
* Link points ?
*
* @var bool
*/
protected $link = FALSE;
/**
* Display impulses
*
* @var bool
*/
protected $impulse = NULL;
/**
* Link NULL points ?
*
* @var bool
*/
protected $linkNull = FALSE;
/**
* Line color
*
* @var Color
*/
protected $lineColor;
/**
* Line type
*
* @var int
*/
protected $lineStyle = awLine::SOLID;
/**
* Line thickness
*
* @var int
*/
protected $lineThickness = 1;
/**
* Construct a new awScatterPlot
*
* @param array $datay Numeric values for Y axis
* @param array $datax Numeric values for X axis
* @param int $mode
*/
public function __construct($datay, $datax = NULL) {
parent::__construct();
// Defaults marks
$this->mark = new awMark;
$this->mark->setType(awMark::CIRCLE);
$this->mark->setSize(7);
$this->mark->border->show();
$this->label = new awLabel;
$this->setValues($datay, $datax);
$this->setColor(new awBlack);
}
/**
* Display plot as impulses
*
* @param awColor $impulse Impulses color (or NULL to disable impulses)
*/
public function setImpulse($color) {
$this->impulse = $color;
}
/**
* Link scatter plot points
*
* @param bool $link
* @param awColor $color Line color (default to black)
*/
public function link($link, $color = NULL) {
$this->link = (bool)$link;
if($color instanceof awColor) {
$this->setColor($color);
}
}
/**
* Ignore null values for Y data and continue linking
*
* @param bool $link
*/
public function linkNull($link) {
$this->linkNull = (bool)$link;
}
/**
* Change line color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->lineColor = $color;
}
/**
* Change line style
*
* @param int $style
*/
public function setStyle($style) {
$this->lineStyle = (int)$style;
}
/**
* Change line tickness
*
* @param int $tickness
*/
public function setThickness($tickness) {
$this->lineThickness = (int)$tickness;
}
/**
* Get the line thickness
*
* @return int
*/
public function getLegendLineThickness() {
return $this->lineThickness;
}
/**
* Get the line type
*
* @return int
*/
public function getLegendLineStyle() {
return $this->lineStyle;
}
/**
* Get the color of line
*
* @return Color
*/
public function getLegendLineColor() {
return $this->lineColor;
}
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground() {
return NULL;
}
/**
* Get a mark object
*
* @return Mark
*/
public function getLegendMark() {
return $this->mark;
}
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
$count = count($this->datay);
// Get start and stop values
list($start, $stop) = $this->getLimit();
// Build the polygon
$polygon = new awPolygon;
for($key = 0; $key < $count; $key++) {
$x = $this->datax[$key];
$y = $this->datay[$key];
if($y !== NULL) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
$polygon->set($key, $p);
} else if($this->linkNull === FALSE) {
$polygon->set($key, NULL);
}
}
// Link points if needed
if($this->link) {
$prev = NULL;
foreach($polygon->all() as $point) {
if($prev !== NULL and $point !== NULL) {
$drawer->line(
$this->lineColor,
new awLine(
$prev,
$point,
$this->lineStyle,
$this->lineThickness
)
);
}
$prev = $point;
}
$this->lineColor->free();
}
// Draw impulses
if($this->impulse instanceof awColor) {
foreach($polygon->all() as $key => $point) {
if($point !== NULL) {
$zero = awAxis::toPosition(
$this->xAxis,
$this->yAxis,
new awPoint($key, 0)
);
$drawer->line(
$this->impulse,
new awLine(
$zero,
$point,
awLine::SOLID,
1
)
);
}
}
}
// Draw marks and labels
foreach($polygon->all() as $key => $point) {
$this->mark->draw($drawer, $point);
$this->label->draw($drawer, $point, $key);
}
}
protected function xAxisPoint($position) {
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
}
public function getXCenter() {
return FALSE;
}
}
registerClass('ScatterPlot');
?>

View File

@@ -0,0 +1,112 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/*
* Get the minimum of an array and ignore non numeric values
*/
function array_min($array) {
if(is_array($array) and count($array) > 0) {
do {
$min = array_pop($array);
if(is_numeric($min === FALSE)) {
$min = NULL;
}
} while(count($array) > 0 and $min === NULL);
if($min !== NULL) {
$min = (float)$min;
}
foreach($array as $value) {
if(is_numeric($value) and (float)$value < $min) {
$min = (float)$value;
}
}
return $min;
}
return NULL;
}
/*
* Get the maximum of an array and ignore non numeric values
*/
function array_max($array) {
if(is_array($array) and count($array) > 0) {
do {
$max = array_pop($array);
if(is_numeric($max === FALSE)) {
$max = NULL;
}
} while(count($array) > 0 and $max === NULL);
if($max !== NULL) {
$max = (float)$max;
}
foreach($array as $value) {
if(is_numeric($value) and (float)$value > $max) {
$max = (float)$value;
}
}
return $max;
}
return NULL;
}
/*
* Register a class with the prefix in configuration file
*/
function registerClass($class, $abstract = FALSE) {
if(ARTICHOW_PREFIX === 'aw') {
return;
}
/* <php5> */
if($abstract) {
$abstract = 'abstract';
} else {
$abstract = '';
}
/* </php5> */
/* <php4> --
$abstract = '';
-- </php4> */
eval($abstract." class ".ARTICHOW_PREFIX.$class." extends aw".$class." { }");
}
/*
* Register an interface with the prefix in configuration file
*/
function registerInterface($interface) {
if(ARTICHOW_PREFIX === 'aw') {
return;
}
/* <php5> */
eval("interface ".ARTICHOW_PREFIX.$interface." extends aw".$interface." { }");
/* </php5> */
}
?>

View File

@@ -0,0 +1,799 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Handle axis
*
* @package Artichow
*/
class awAxis {
/**
* Axis line
*
* @var Line
*/
public $line;
/**
* Axis labels
*
* @var Label
*/
public $label;
/**
* Axis title
*
* @var Label
*/
public $title;
/**
* Title position
*
* @var float
*/
protected $titlePosition = 0.5;
/**
* Labels number
*
* @var int
*/
protected $labelNumber;
/**
* Axis ticks
*
* @var array
*/
protected $ticks = array();
/**
* Axis and ticks color
*
* @var Color
*/
protected $color;
/**
* Axis left and right padding
*
* @var Side
*/
protected $padding;
/**
* Axis range
*
* @var array
*/
protected $range;
/**
* Hide axis
*
* @var bool
*/
protected $hide = FALSE;
/**
* Auto-scaling mode
*
* @var bool
*/
protected $auto = TRUE;
/**
* Axis range callback function
*
* @var array
*/
protected $rangeCallback = array(
'toValue' => 'toProportionalValue',
'toPosition' => 'toProportionalPosition'
);
/**
* Build the axis
*
* @param float $min Begin of the range of the axis
* @param float $max End of the range of the axis
*/
public function __construct($min = NULL, $max = NULL) {
$this->line = new awVector(
new awPoint(0, 0),
new awPoint(0, 0)
);
$this->label = new awLabel;
$this->padding = new awSide;
$this->title = new awLabel(
NULL,
NULL,
NULL,
0
);
$this->setColor(new awBlack);
if($min !== NULL and $max !== NULL) {
$this->setRange($min, $max);
}
}
/**
* Enable/disable auto-scaling mode
*
* @param bool $auto
*/
public function auto($auto) {
$this->auto = (bool)$auto;
}
/**
* Get auto-scaling mode status
*
* @return bool
*/
public function isAuto() {
return $this->auto;
}
/**
* Hide axis
*
* @param bool $hide
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show axis
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = !(bool)$show;
}
/**
* Return a tick object from its name
*
* @param string $name Tick object name
* @return Tick
*/
public function tick($name) {
/* <php5> */
return array_key_exists($name, $this->ticks) ? $this->ticks[$name] : NULL;
/* </php5> */
/* <php4> --
if(array_key_exists($name, $this->ticks)) {
return $tick = &$this->ticks[$name];
} else {
return NULL;
}
-- </php4> */
}
/**
* Add a tick object
*
* @param string $name Tick object name
* @param awTick $tick Tick object
*/
public function addTick($name, awTick $tick) {
/* <php5> */
$this->ticks[$name] = $tick;
/* </php5> */
/* <php4> --
$this->ticks[$name] = &$tick;
-- </php4> */
}
/**
* Delete a tick object
*
* @param string $name Tick object name
*/
public function deleteTick($name) {
if(array_key_exists($name, $this->ticks)) {
unset($this->ticks[$name]);
}
}
/**
* Hide all ticks
*
* @param bool $hide Hide or not ?
*/
public function hideTicks($hide = TRUE) {
/* <php5> */
foreach($this->ticks as $tick) {
$tick->hide($hide);
}
/* </php5> */
/* <php4> --
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->hide($hide);
}
-- </php4> */
}
/**
* Change ticks style
*
* @param int $style Ticks style
*/
public function setTickStyle($style) {
/* <php5> */
foreach($this->ticks as $tick) {
$tick->setStyle($style);
}
/* </php5> */
/* <php4> --
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->setStyle($style);
}
-- </php4> */
}
/**
* Change ticks interval
*
* @param int $interval Ticks interval
*/
public function setTickInterval($interval) {
/* <php5> */
foreach($this->ticks as $tick) {
$tick->setInterval($interval);
}
/* </php5> */
/* <php4> --
foreach($this->ticks as $key => $tick) {
$this->ticks[$key]->setInterval($interval);
}
-- </php4> */
}
/**
* Change number of ticks relative to others ticks
*
* @param awTick $to Change number of theses ticks
* @param awTick $from Ticks reference
* @param float $number Number of ticks by the reference
*/
public function setNumberByTick($to, $from, $number) {
$this->ticks[$to]->setNumberByTick($this->ticks[$from], $number);
}
/**
* Reverse ticks style
*/
public function reverseTickStyle() {
/* <php5> */
foreach($this->ticks as $tick) {
if($tick->getStyle() === awTick::IN) {
$tick->setStyle(awTick::OUT);
} else if($tick->getStyle() === awTick::OUT) {
$tick->setStyle(awTick::IN);
}
}
/* </php5> */
/* <php4> --
foreach($this->ticks as $key => $tick) {
if($this->ticks[$key]->getStyle() === awTick::IN) {
$this->ticks[$key]->setStyle(awTick::OUT);
} else if($this->ticks[$key]->getStyle() === awTick::OUT) {
$this->ticks[$key]->setStyle(awTick::IN);
}
}
-- </php4> */
}
/**
* Change interval of labels
*
* @param int $interval Interval
*/
public function setLabelInterval($interval) {
$this->auto(FALSE);
$this->setTickInterval($interval);
$this->label->setInterval($interval);
}
/**
* Change number of labels
*
* @param int $number Number of labels to display (can be NULL)
*/
public function setLabelNumber($number) {
$this->auto(FALSE);
$this->labelNumber = is_null($number) ? NULL : (int)$number;
}
/**
* Get number of labels
*
* @return int
*/
public function getLabelNumber() {
return $this->labelNumber;
}
/**
* Change precision of labels
*
* @param int $precision Precision
*/
public function setLabelPrecision($precision) {
$this->auto(FALSE);
$function = 'axis'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
return sprintf("%.'.(int)$precision.'f", $value);
}');
$this->label->setCallbackFunction($function);
}
/**
* Change text of labels
*
* @param array $texts Some texts
*/
public function setLabelText($texts) {
if(is_array($texts)) {
$this->auto(FALSE);
$function = 'axis'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
$texts = '.var_export($texts, TRUE).';
return isset($texts[$value]) ? $texts[$value] : \'?\';
}');
$this->label->setCallbackFunction($function);
}
}
/**
* Get the position of a point
*
* @param awAxis $xAxis X axis
* @param awAxis $yAxis Y axis
* @param awPoint $p Position of the point
* @return Point Position on the axis
*/
public static function toPosition(awAxis $xAxis, awAxis $yAxis, awPoint $p) {
$p1 = $xAxis->getPointFromValue($p->x);
$p2 = $yAxis->getPointFromValue($p->y);
return new awPoint(
round($p1->x),
round($p2->y)
);
}
/**
* Change title alignment
*
* @param int $alignment New Alignment
*/
public function setTitleAlignment($alignment) {
switch($alignment) {
case awLabel::TOP :
$this->setTitlePosition(1);
$this->title->setAlign(NULL, awLabel::BOTTOM);
break;
case awLabel::BOTTOM :
$this->setTitlePosition(0);
$this->title->setAlign(NULL, awLabel::TOP);
break;
case awLabel::LEFT :
$this->setTitlePosition(0);
$this->title->setAlign(awLabel::LEFT);
break;
case awLabel::RIGHT :
$this->setTitlePosition(1);
$this->title->setAlign(awLabel::RIGHT);
break;
}
}
/**
* Change title position on the axis
*
* @param float $position A new awposition between 0 and 1
*/
public function setTitlePosition($position) {
$this->titlePosition = (float)$position;
}
/**
* Change axis and axis title color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->color = $color;
$this->title->setColor($color);
}
/**
* Change axis padding
*
* @param int $left Left padding in pixels
* @param int $right Right padding in pixels
*/
public function setPadding($left, $right) {
$this->padding->set($left, $right);
}
/**
* Get axis padding
*
* @return Side
*/
public function getPadding() {
return $this->padding;
}
/**
* Change axis range
*
* @param float $min
* @param float $max
*/
public function setRange($min, $max) {
if($min !== NULL) {
$this->range[0] = (float)$min;
}
if($max !== NULL) {
$this->range[1] = (float)$max;
}
}
/**
* Get axis range
*
* @return array
*/
public function getRange() {
return $this->range;
}
/**
* Change axis range callback function
*
* @param string $toValue Transform a position between 0 and 1 to a value
* @param string $toPosition Transform a value to a position between 0 and 1 on the axis
*/
public function setRangeCallback($toValue, $toPosition) {
$this->rangeCallback = array(
'toValue' => (string)$toValue,
'toPosition' => (string)$toPosition
);
}
/**
* Center X values of the axis
*
* @param awAxis $axis An axis
* @param float $value The reference value on the axis
*/
public function setXCenter(awAxis $axis, $value) {
// Check vector angle
if($this->line->isVertical() === FALSE) {
trigger_error("setXCenter() can only be used on vertical axes", E_USER_ERROR);
}
$p = $axis->getPointFromValue($value);
$this->line->setX(
$p->x,
$p->x
);
}
/**
* Center Y values of the axis
*
* @param awAxis $axis An axis
* @param float $value The reference value on the axis
*/
public function setYCenter(awAxis $axis, $value) {
// Check vector angle
if($this->line->isHorizontal() === FALSE) {
trigger_error("setYCenter() can only be used on horizontal axes", E_USER_ERROR);
}
$p = $axis->getPointFromValue($value);
$this->line->setY(
$p->y,
$p->y
);
}
/**
* Get the distance between to values on the axis
*
* @param float $from The first value
* @param float $to The last value
* @return Point
*/
public function getDistance($from, $to) {
$p1 = $this->getPointFromValue($from);
$p2 = $this->getPointFromValue($to);
return $p1->getDistance($p2);
}
/**
* Get a point on the axis from a value
*
* @param float $value
* @return Point
*/
protected function getPointFromValue($value) {
$callback = $this->rangeCallback['toPosition'];
list($min, $max) = $this->range;
$position = $callback($value, $min, $max);
return $this->getPointFromPosition($position);
}
/**
* Get a point on the axis from a position
*
* @param float $position A position between 0 and 1
* @return Point
*/
protected function getPointFromPosition($position) {
$vector = $this->getVector();
$angle = $vector->getAngle();
$size = $vector->getSize();
return $vector->p1->move(
cos($angle) * $size * $position,
-1 * sin($angle) * $size * $position
);
}
/**
* Draw axis
*
* @param awDrawer $drawer A drawer
*/
public function draw(awDrawer $drawer) {
if($this->hide) {
return;
}
$vector = $this->getVector();
// Draw axis ticks
$this->drawTicks($drawer, $vector);
// Draw axis line
$this->line($drawer);
// Draw labels
$this->drawLabels($drawer);
// Draw axis title
$p = $this->getPointFromPosition($this->titlePosition);
$this->title->draw($drawer, $p);
}
public function autoScale() {
if($this->isAuto() === FALSE) {
return;
}
list($min, $max) = $this->getRange();
$interval = $max - $min;
if($interval > 0) {
$partMax = $max / $interval;
$partMin = $min / $interval;
} else {
$partMax = 0;
$partMin = 0;
}
$difference = log($interval) / log(10);
$difference = floor($difference);
$pow = pow(10, $difference);
if($pow > 0) {
$intervalNormalize = $interval / $pow;
} else {
$intervalNormalize = 0;
}
if($difference <= 0) {
$precision = $difference * -1 + 1;
if($intervalNormalize > 2) {
$precision--;
}
} else {
$precision = 0;
}
if($min != 0 and $max != 0) {
$precision++;
}
$this->setLabelPrecision($precision);
if($intervalNormalize <= 1.5) {
$intervalReal = 1.5;
$labelNumber = 4;
} else if($intervalNormalize <= 2) {
$intervalReal = 2;
$labelNumber = 5;
} else if($intervalNormalize <= 3) {
$intervalReal = 3;
$labelNumber = 4;
} else if($intervalNormalize <= 4) {
$intervalReal = 4;
$labelNumber = 5;
} else if($intervalNormalize <= 5) {
$intervalReal = 5;
$labelNumber = 6;
} else if($intervalNormalize <= 8) {
$intervalReal = 8;
$labelNumber = 5;
} else if($intervalNormalize <= 10) {
$intervalReal = 10;
$labelNumber = 6;
}
if($min == 0) {
$this->setRange(
$min,
$intervalReal * $pow
);
} else if($max == 0) {
$this->setRange(
$intervalReal * $pow * -1,
0
);
}
$this->setLabelNumber($labelNumber);
}
protected function line(awDrawer $drawer) {
$drawer->line(
$this->color,
$this->line
);
}
protected function drawTicks(awDrawer $drawer, awVector $vector) {
foreach($this->ticks as $tick) {
$tick->setColor($this->color);
$tick->draw($drawer, $vector);
}
}
protected function drawLabels($drawer) {
if($this->labelNumber !== NULL) {
list($min, $max) = $this->range;
$number = $this->labelNumber - 1;
if($number < 1) {
return;
}
$function = $this->rangeCallback['toValue'];
$labels = array();
for($i = 0; $i <= $number; $i++) {
$labels[] = $function($i / $number, $min, $max);
}
$this->label->set($labels);
}
$labels = $this->label->count();
for($i = 0; $i < $labels; $i++) {
$p = $this->getPointFromValue($this->label->get($i));
$this->label->draw($drawer, $p, $i);
}
}
protected function getVector() {
$angle = $this->line->getAngle();
// Compute paddings
$vector = new awVector(
$this->line->p1->move(
cos($angle) * $this->padding->left,
-1 * sin($angle) * $this->padding->left
),
$this->line->p2->move(
-1 * cos($angle) * $this->padding->right,
-1 * -1 * sin($angle) * $this->padding->right
)
);
return $vector;
}
public function __clone() {
$this->label = clone $this->label;
$this->line = clone $this->line;
$this->title = clone $this->title;
foreach($this->ticks as $name => $tick) {
$this->ticks[$name] = clone $tick;
}
}
}
registerClass('Axis');
function toProportionalValue($position, $min, $max) {
return $min + ($max - $min) * $position;
}
function toProportionalPosition($value, $min, $max) {
if($max - $min == 0) {
return 0;
}
return ($value - $min) / ($max - $min);
}
?>

View File

@@ -0,0 +1,158 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Draw border
*
* @package Artichow
*/
class awBorder {
/**
* Border color
*
* @var Color
*/
protected $color;
/**
* Hide border ?
*
* @var bool
*/
protected $hide = FALSE;
/**
* Border line style
*
* @var int
*/
protected $style;
/**
* Build the border
*
* @param awColor $color Border color
* @param int $style Border style
*/
public function __construct($color = NULL, $style = awLine::SOLID) {
$this->setStyle($style);
if($color instanceof awColor) {
$this->setColor($color);
} else {
$this->setColor(new awBlack);
}
}
/**
* Change border color
* This method automatically shows the border if it is hidden
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->color = $color;
$this->show();
}
/**
* Change border style
*
* @param int $style
*/
public function setStyle($style) {
$this->style = (int)$style;
}
/**
* Hide border ?
*
* @param bool $hide
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show border ?
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Is the border visible ?
*
* @return bool
*/
public function visible() {
return !$this->hide;
}
/**
* Draw border as a rectangle
*
* @param awDrawer $drawer
* @param awPoint $p1 Top-left corner
* @param awPoint $p2 Bottom-right corner
*/
public function rectangle(awDrawer $drawer, awPoint $p1, awPoint $p2) {
// Border is hidden
if($this->hide) {
return;
}
$line = new awLine;
$line->setStyle($this->style);
$line->setLocation($p1, $p2);
$drawer->rectangle($this->color, $line);
}
/**
* Draw border as an ellipse
*
* @param awDrawer $drawer
* @param awPoint $center Ellipse center
* @param int $width Ellipse width
* @param int $height Ellipse height
*/
public function ellipse(awDrawer $drawer, awPoint $center, $width, $height) {
// Border is hidden
if($this->hide) {
return;
}
switch($this->style) {
case awLine::SOLID :
$drawer->ellipse($this->color, $center, $width, $height);
break;
default :
trigger_error("Dashed and dotted borders and not yet implemented on ellipses", E_USER_ERROR);
break;
}
}
}
registerClass('Border');
?>

View File

@@ -0,0 +1,232 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Create your colors
*
* @package Artichow
*/
class awColor {
public $red;
public $green;
public $blue;
public $alpha;
private $resource;
private $color;
/**
* Build your color
*
* @var int $red Red intensity (from 0 to 255)
* @var int $green Green intensity (from 0 to 255)
* @var int $blue Blue intensity (from 0 to 255)
* @var int $alpha Alpha channel (from 0 to 100)
*/
public function __construct($red, $green, $blue, $alpha = 0) {
$this->red = (int)$red;
$this->green = (int)$green;
$this->blue = (int)$blue;
$this->alpha = (int)round($alpha * 127 / 100);
}
/**
* Return a GDised color
*
* @param resource $resource A GD resource
* @return int
*/
public function getColor($resource) {
$this->resource = $resource;
if($this->color === NULL) {
if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
$this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
} else {
$this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
}
}
return $this->color;
}
/**
* Change color brightness
*
* @param int $brightness Add this intensity to the color (betweeen -255 and +255)
*/
public function brightness($brightness) {
$brightness = (int)$brightness;
$this->red = min(255, max(0, $this->red + $brightness));
$this->green = min(255, max(0, $this->green + $brightness));
$this->blue = min(255, max(0, $this->blue + $brightness));
}
/**
* Get RGB and alpha values of your color
*
* @return array
*/
public function rgba() {
return array($this->red, $this->green, $this->blue, $this->alpha);
}
/**
* Free resources used for this color
*/
public function free() {
if($this->resource !== NULL) {
@imagecolordeallocate($this->resource, $this->color);
$this->resource = NULL;
}
}
public function __destruct() {
$this->free();
}
}
registerClass('Color');
$colors = array(
'Black' => array(0, 0, 0),
'AlmostBlack' => array(48, 48, 48),
'VeryDarkGray' => array(88, 88, 88),
'DarkGray' => array(128, 128, 128),
'MidGray' => array(160, 160, 160),
'LightGray' => array(195, 195, 195),
'VeryLightGray' => array(220, 220, 220),
'White' => array(255, 255, 255),
'VeryDarkRed' => array(64, 0, 0),
'DarkRed' => array(128, 0, 0),
'MidRed' => array(192, 0, 0),
'Red' => array(255, 0, 0),
'LightRed' => array(255, 192, 192),
'VeryDarkGreen' => array(0, 64, 0),
'DarkGreen' => array(0, 128, 0),
'MidGreen' => array(0, 192, 0),
'Green' => array(0, 255, 0),
'LightGreen' => array(192, 255, 192),
'VeryDarkBlue' => array(0, 0, 64),
'DarkBlue' => array(0, 0, 128),
'MidBlue' => array(0, 0, 192),
'Blue' => array(0, 0, 255),
'LightBlue' => array(192, 192, 255),
'VeryDarkYellow' => array(64, 64, 0),
'DarkYellow' => array(128, 128, 0),
'MidYellow' => array(192, 192, 0),
'Yellow' => array(255, 255, 2),
'LightYellow' => array(255, 255, 192),
'VeryDarkCyan' => array(0, 64, 64),
'DarkCyan' => array(0, 128, 128),
'MidCyan' => array(0, 192, 192),
'Cyan' => array(0, 255, 255),
'LightCyan' => array(192, 255, 255),
'VeryDarkMagenta' => array(64, 0, 64),
'DarkMagenta' => array(128, 0, 128),
'MidMagenta' => array(192, 0, 192),
'Magenta' => array(255, 0, 255),
'LightMagenta' => array(255, 192, 255),
'DarkOrange' => array(192, 88, 0),
'Orange' => array(255, 128, 0),
'LightOrange' => array(255, 168, 88),
'VeryLightOrange' => array(255, 220, 168),
'DarkPink' => array(192, 0, 88),
'Pink' => array(255, 0, 128),
'LightPink' => array(255, 88, 168),
'VeryLightPink' => array(255, 168, 220),
'DarkPurple' => array(88, 0, 192),
'Purple' => array(128, 0, 255),
'LightPurple' => array(168, 88, 255),
'VeryLightPurple' => array(220, 168, 255),
);
/* <php5> */
$php = '';
foreach($colors as $name => $color) {
list($red, $green, $blue) = $color;
$php .= '
class aw'.$name.' extends awColor {
public function __construct($alpha = 0) {
parent::__construct('.$red.', '.$green.', '.$blue.', $alpha);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
}
';
}
}
eval($php);
/* </php5> */
/* <php4> --
$php = '';
foreach($colors as $name => $color) {
list($red, $green, $blue) = $color;
$php .= '
class aw'.$name.' extends awColor {
function aw'.$name.'($alpha = 0) {
parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
}
';
}
}
eval($php);
-- </php4> */
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,348 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Built-in PHP fonts
*
* @package Artichow
*/
class awFont {
/**
* Used font
*
* @param int $font
*/
public $font;
/**
* Build the font
*
* @param int $font Font identifier
*/
public function __construct($font) {
$this->font = $font;
}
/**
* Draw a text
*
* @param awDrawer $drawer
* @param awPoint $p Draw text at this point
* @param awText $text The text
*/
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
$angle = $text->getAngle();
if($angle !== 90 and $angle !== 0) {
trigger_error("You can only use 0° and 90°", E_USER_ERROR);
}
if($angle === 90) {
$function = 'imagestringup';
} else {
$function = 'imagestring';
}
if($angle === 90) {
$add = $this->getTextHeight($text);
} else {
$add = 0;
}
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$function(
$drawer->resource,
$this->font,
$drawer->x + $p->x,
$drawer->y + $p->y + $add,
$text->getText(),
$rgb
);
}
/**
* Get the width of a string
*
* @param awText $text A string
*/
public function getTextWidth(awText $text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextHeight($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontWidth = imagefontwidth($font->font);
if($fontWidth === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontWidth * strlen($text->getText());
}
/**
* Get the height of a string
*
* @param awText $text A string
*/
public function getTextHeight(awText $text) {
if($text->getAngle() === 90) {
$text->setAngle(45);
return $this->getTextWidth($text);
} else if($text->getAngle() === 45) {
$text->setAngle(90);
}
$font = $text->getFont();
$fontHeight = imagefontheight($font->font);
if($fontHeight === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
}
return (int)$fontHeight;
}
}
registerClass('Font');
/**
* TTF fonts
*
* @package Artichow
*/
class awTTFFont extends awFont {
/**
* Font size
*
* @var int
*/
public $size;
/**
* Font file
*
* @param string $font Font file
* @param int $size Font size
*/
public function __construct($font, $size) {
parent::__construct($font);
$this->size = (int)$size;
}
/**
* Draw a text
*
* @param awDrawer $drawer
* @param awPoint $p Draw text at this point
* @param awText $text The text
*/
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
// Make easier font positionment
$text->setText($text->getText()." ");
$color = $text->getColor();
$rgb = $color->getColor($drawer->resource);
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
$height = - $box[5];
$box = imagettfbbox($this->size, 90, $this->font, $text->getText());
$width = abs($box[6] - $box[2]);
// Restore old text
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
imagettftext(
$drawer->resource,
$this->size,
$text->getAngle(),
$drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI),
$drawer->y + $p->y + $height,
$rgb,
$this->font,
$text->getText()
);
}
/**
* Get the width of a string
*
* @param awText $text A string
*/
public function getTextWidth(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($x2 - $x1);
}
/**
* Get the height of a string
*
* @param awText $text A string
*/
public function getTextHeight(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR);
return;
}
list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($y2 - $y1);
}
}
registerClass('TTFFont');
/* <php5> */
$php = '';
for($i = 1; $i <= 5; $i++) {
$php .= '
class awFont'.$i.' extends awFont {
public function __construct() {
parent::__construct('.$i.');
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
}
';
}
}
eval($php);
$php = '';
foreach($fonts as $font) {
$php .= '
class aw'.$font.' extends awTTFFont {
public function __construct($size) {
parent::__construct(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
}
';
}
}
eval($php);
/* </php5> */
/* <php4> --
$php = '';
for($i = 1; $i <= 5; $i++) {
$php .= '
class awFont'.$i.' extends awFont {
function awFont'.$i.'() {
parent::awFont('.$i.');
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
}
';
}
}
eval($php);
$php = '';
foreach($fonts as $font) {
$php .= '
class aw'.$font.' extends awTTFFont {
function aw'.$font.'($size) {
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
}
}
';
if(ARTICHOW_PREFIX !== 'aw') {
$php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
}
';
}
}
eval($php);
-- </php4> */
?>

View File

@@ -0,0 +1,149 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Create your gradients
*
* @package Artichow
*/
abstract class awGradient {
/**
* From color
*
* @var Color
*/
public $from;
/**
* To color
*
* @var Color
*/
public $to;
/**
* Build the gradient
*
* @param awColor $from From color
* @param awColor $to To color
*/
public function __construct($from, $to) {
$this->from = $from;
$this->to = $to;
}
/**
* Free memory used by the colors of the gradient
*/
public function free() {
$this->from->free();
$this->to->free();
}
public function __destruct( ){
$this->free();
}
}
registerClass('Gradient', TRUE);
/**
* Create a linear gradient
*
* @package Artichow
*/
class awLinearGradient extends awGradient {
/**
* Gradient angle
*
* @var int
*/
public $angle;
/**
* Build the linear gradient
*
* @param awColor $from From color
* @param awColor $to To color
* @param int $angle Gradient angle
*/
public function __construct($from, $to, $angle) {
parent::__construct(
$from, $to
);
$this->angle = $angle;
}
}
registerClass('LinearGradient');
/**
* Create a bilinear gradient
*
* @package Artichow
*/
class awBilinearGradient extends awLinearGradient {
/**
* Gradient center
*
* @var int Center between 0 and 1
*/
public $center;
/**
* Build the bilinear gradient
*
* @param awColor $from From color
* @param awColor $to To color
* @param int $angle Gradient angle
* @param int $center Gradient center
*/
public function __construct($from, $to, $angle, $center = 0.5) {
parent::__construct(
$from, $to, $angle
);
$this->center = $center;
}
}
registerClass('BilinearGradient');
/**
* Create a radial gradient
*
* @package Artichow
*/
class awRadialGradient extends awGradient {
}
registerClass('RadialGradient');
?>

View File

@@ -0,0 +1,289 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Grid
*
* @package Artichow
*/
class awGrid {
/**
* Vertical lines of the grid
*
* @var array
*/
private $xgrid = array();
/**
* Horizontal lines of the grid
*
* @var array
*/
private $ygrid = array();
/**
* Is the component grid hidden ?
*
* @var bool
*/
private $hide = FALSE;
/**
* Are horizontal lines hidden ?
*
* @var bool
*/
private $hideHorizontal = FALSE;
/**
* Are vertical lines hidden ?
*
* @var bool
*/
private $hideVertical = FALSE;
/**
* Grid color
*
* @var Color
*/
private $color;
/**
* Grid space
*
* @var int
*/
private $space;
/**
* Line type
*
* @var int
*/
private $type = awLine::SOLID;
/**
* Grid interval
*
* @var int
*/
private $interval = array(1, 1);
/**
* Grid background color
*
* @var Color
*/
private $background;
/**
* Build the factory
*/
public function __construct() {
// Set a grid default color
$this->color = new awColor(210, 210, 210);
$this->background = new awColor(255, 255, 255, 100);
}
/**
* Hide grid ?
*
* @param bool $hide
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Hide horizontal lines ?
*
* @param bool $hideHorizontal
*/
public function hideHorizontal($hide = TRUE) {
$this->hideHorizontal = (bool)$hide;
}
/**
* Hide vertical lines ?
*
* @param bool $hideVertical
*/
public function hideVertical($hide = TRUE) {
$this->hideVertical = (bool)$hide;
}
/**
* Change grid color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Remove grid background
*/
public function setNoBackground() {
$this->background = NULL;
}
/**
* Change grid background color
*
* @param awColor $color
*/
public function setBackgroundColor(awColor $color) {
$this->background = $color;
}
/**
* Change line type
*
* @param int $type
*/
public function setType($type) {
$this->type = (int)$type;
}
/**
* Change grid interval
*
* @param int $hInterval
* @param int $vInterval
*/
public function setInterval($hInterval, $vInterval) {
$this->interval = array((int)$hInterval, (int)$vInterval);
}
/**
* Set grid space
*
* @param int $left Left space in pixels
* @param int $right Right space in pixels
* @param int $top Top space in pixels
* @param int $bottom Bottom space in pixels
*/
public function setSpace($left, $right, $top, $bottom) {
$this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Change the current grid
*
* @param array $xgrid Vertical lines
* @param array $ygrid Horizontal lines
*/
public function setGrid($xgrid, $ygrid) {
$this->xgrid = $xgrid;
$this->ygrid = $ygrid;
}
/**
* Draw grids
*
* @param awDrawer $drawer A drawer object
* @param int $x1
* @param int $y1
* @param int $x2
* @param int $y2
*/
public function draw(awDrawer $drawer, $x1, $y1, $x2, $y2) {
if($this->background instanceof awColor) {
// Draw background color
$drawer->filledRectangle(
$this->background,
awLine::build($x1, $y1, $x2, $y2)
);
$this->background->free();
}
if($this->hide === FALSE) {
$this->drawGrid(
$drawer,
$this->color,
$this->hideVertical ? array() : $this->xgrid,
$this->hideHorizontal ? array() : $this->ygrid,
$x1, $y1, $x2, $y2,
$this->type,
$this->space,
$this->interval[0],
$this->interval[1]
);
}
$this->color->free();
}
private function drawGrid(
awDrawer $drawer, awColor $color,
$nx, $ny, $x1, $y1, $x2, $y2,
$type, $space, $hInterval, $vInterval
) {
list($left, $right, $top, $bottom) = $space;
$width = $x2 - $x1 - $left - $right;
$height = $y2 - $y1 - $top - $bottom;
foreach($nx as $key => $n) {
if(($key % $vInterval) === 0) {
$pos = (int)round($x1 + $left + $n * $width);
$drawer->line(
$color,
new awLine(
new awPoint($pos, $y1),
new awPoint($pos, $y2),
$type
)
);
}
}
foreach($ny as $key => $n) {
if(($key % $hInterval) === 0) {
$pos = (int)round($y1 + $top + $n * $height);
$drawer->line(
$color,
new awLine(
new awPoint($x1, $pos),
new awPoint($x2, $pos),
$type
)
);
}
}
}
}
registerClass('Grid');
?>

View File

@@ -0,0 +1,596 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("LABEL_LEFT", 1);
define("LABEL_RIGHT", 2);
define("LABEL_CENTER", 3);
define("LABEL_TOP", 4);
define("LABEL_BOTTOM", 5);
define("LABEL_MIDDLE", 6);
/* </php4> */
/**
* Draw labels
*
* @package Artichow
*/
class awLabel implements awPositionable {
/**
* Label border
*
* @var int
*/
public $border;
/**
* Label texts
*
* @var array
*/
protected $texts;
/**
* Text font
*
* @var int
*/
protected $font;
/**
* Text angle
*
* @var int
*/
protected $angle = 0;
/**
* Text color
*
* @var Color
*/
protected $color;
/**
* Text background
*
* @var Color, Gradient
*/
private $background;
/**
* Callback function
*
* @var string
*/
private $function;
/**
* Padding
*
* @var int
*/
private $padding;
/**
* Move position from this vector
*
* @var Point
*/
protected $move;
/**
* Label interval
*
* @var int
*/
protected $interval = 1;
/**
* Horizontal align
*
* @var int
*/
protected $hAlign = awLabel::CENTER;
/**
* Vertical align
*
* @var int
*/
protected $vAlign = awLabel::MIDDLE;
/**
* Hide all labels ?
*
* @var bool
*/
protected $hide = FALSE;
/**
* Keys to hide
*
* @var array
*/
protected $hideKey = array();
/**
* Values to hide
*
* @var array
*/
protected $hideValue = array();
/**
* Hide first label
*
* @var bool
*/
protected $hideFirst = FALSE;
/**
* Hide last label
*
* @var bool
*/
protected $hideLast = FALSE;
/**
* Build the label
*
* @param string $label First label
*/
public function __construct($label = NULL, $font = NULL, $color = NULL, $angle = 0) {
if(is_array($label)) {
$this->set($label);
} else if(is_string($label)) {
$this->set(array($label));
}
if($font === NULL) {
$font = new awFont2;
}
$this->setFont($font);
$this->setAngle($angle);
if($color instanceof awColor) {
$this->setColor($color);
} else {
$this->setColor(new awColor(0, 0, 0));
}
$this->move = new awPoint(0, 0);
$this->border = new awBorder;
$this->border->hide();
}
/**
* Get an element of the label from its key
*
* @param int $key Element key
* @return string A value
*/
public function get($key) {
return array_key_exists($key, $this->texts) ? $this->texts[$key] : NULL;
}
/**
* Get all labels
*
* @return array
*/
public function all() {
return $this->texts;
}
/**
* Set one or several labels
*
* @param array $labels Array of string or a string
*/
public function set($labels) {
if(is_string($labels)) {
$this->texts = array($labels);
} else if(is_array($labels)) {
$this->texts = $labels;
}
}
/**
* Count number of texts in the label
*
* @return int
*/
public function count() {
return is_array($this->texts) ? count($this->texts) : 0;
}
/**
* Set a callback function for labels
*
* @param string $function
*/
public function setCallbackFunction($function) {
$this->function = is_null($function) ? $function : (string)$function;
}
/**
* Return the callback function for labels
*
* @return string
*/
public function getCallbackFunction() {
return $this->function;
}
/**
* Change labels format
*
* @param string $format New format (printf style: %.2f for example)
*/
public function setFormat($format) {
$function = 'label'.time().'_'.(microtime() * 1000000);
eval('function '.$function.'($value) {
return sprintf("'.addcslashes($format, '"').'", $value);
}');
$this->setCallbackFunction($function);
}
/**
* Change font for label
*
* @param awFont $font New font
* @param awColor $color Font color (can be NULL)
*/
public function setFont(awFont $font, $color = NULL) {
$this->font = $font;
if($color instanceof awColor) {
$this->setColor($color);
}
}
/**
* Change font angle
*
* @param int $angle New angle
*/
public function setAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Change font color
*
* @param awColor $color
*/
public function setColor($color) {
$this->color = $color;
}
/**
* Change text background
*
* @param mixed $background
*/
public function setBackground($background) {
$this->background = $background;
}
/**
* Change text background color
*
* @param Color
*/
public function setBackgroundColor(awColor $color) {
$this->background = $color;
}
/**
* Change text background gradient
*
* @param Gradient
*/
public function setBackgroundGradient(awGradient $gradient) {
$this->background = $gradient;
}
/**
* Change padding
*
* @param int $left Left padding
* @param int $right Right padding
* @param int $top Top padding
* @param int $bottom Bottom padding
*/
public function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Hide all labels ?
*
* @param bool $hide
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show all labels ?
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Hide a key
*
* @param int $key The key to hide
*/
public function hideKey($key) {
$this->hideKey[$key] = TRUE;
}
/**
* Hide a value
*
* @param int $value The value to hide
*/
public function hideValue($value) {
$this->hideValue[] = $value;
}
/**
* Hide first label
*
* @param bool $hide
*/
public function hideFirst($hide) {
$this->hideFirst = (bool)$hide;
}
/**
* Hide last label
*
* @param bool $hide
*/
public function hideLast($hide) {
$this->hideLast = (bool)$hide;
}
/**
* Set label interval
*
* @param int
*/
public function setInterval($interval) {
$this->interval = (int)$interval;
}
/**
* Change label position
*
* @param int $x Add this interval to X coord
* @param int $y Add this interval to Y coord
*/
public function move($x, $y) {
$this->move = $this->move->move($x, $y);
}
/**
* Change alignment
*
* @param int $h Horizontal alignment
* @param int $v Vertical alignment
*/
public function setAlign($h = NULL, $v = NULL) {
if($h !== NULL) {
$this->hAlign = (int)$h;
}
if($v !== NULL) {
$this->vAlign = (int)$v;
}
}
/**
* Get a text from the labele
*
* @param mixed $key Key in the array text
* @return Text
*/
public function getText($key) {
if(is_array($this->texts) and array_key_exists($key, $this->texts)) {
$value = $this->texts[$key];
if(is_string($this->function)) {
$value = call_user_func($this->function, $value);
}
$text = new awText($value);
$text->setFont($this->font);
$text->setAngle($this->angle);
$text->setColor($this->color);
if($this->background instanceof awColor) {
$text->setBackgroundColor($this->background);
} else if($this->background instanceof awGradient) {
$text->setBackgroundGradient($this->background);
}
$text->border = $this->border;
if($this->padding !== NULL) {
call_user_func_array(array($text, 'setPadding'), $this->padding);
}
return $text;
} else {
return NULL;
}
}
/**
* Get max width of all texts
*
* @param awDrawer $drawer A drawer
* @return int
*/
public function getMaxWidth(awDrawer $drawer) {
return $this->getMax($drawer, 'getTextWidth');
}
/**
* Get max height of all texts
*
* @param awDrawer $drawer A drawer
* @return int
*/
public function getMaxHeight(awDrawer $drawer) {
return $this->getMax($drawer, 'getTextHeight');
}
/**
* Draw the label
*
* @param awDrawer $drawer
* @param awPoint $p Label center
* @param int $key Text position in the array of texts (default to zero)
*/
public function draw(awDrawer $drawer, awPoint $p, $key = 0) {
if(($key % $this->interval) !== 0) {
return;
}
// Hide all labels
if($this->hide) {
return;
}
// Key is hidden
if(array_key_exists($key, $this->hideKey)) {
return;
}
// Hide first label
if($key === 0 and $this->hideFirst) {
return;
}
// Hide last label
if($key === count($this->texts) - 1 and $this->hideLast) {
return;
}
$text = $this->getText($key);
if($text !== NULL) {
// Value must be hidden
if(in_array($text->getText(), $this->hideValue)) {
return;
}
$x = $p->x;
$y = $p->y;
// Get padding
list($left, $right, $top, $bottom) = $text->getPadding();
$font = $text->getFont();
$width = $font->getTextWidth($text);
$height = $font->getTextHeight($text);
switch($this->hAlign) {
case awLabel::RIGHT :
$x -= ($width + $right);
break;
case awLabel::CENTER :
$x -= ($width - $left + $right) / 2;
break;
case awLabel::LEFT :
$x += $left;
break;
}
switch($this->vAlign) {
case awLabel::TOP :
$y -= ($height + $bottom);
break;
case awLabel::MIDDLE :
$y -= ($height - $top + $bottom) / 2;
break;
case awLabel::BOTTOM :
$y += $top;
break;
}
$drawer->string($text, $this->move->move($x, $y));
}
}
protected function getMax(awDrawer $drawer, $function) {
$max = NULL;
foreach($this->texts as $key => $text) {
$text = $this->getText($key);
$font = $text->getFont();
if(is_null($max)) {
$max = $font->{$function}($text);
} else {
$max = max($max, $font->{$function}($text));
}
}
return $max;
}
}
registerClass('Label');
?>

View File

@@ -0,0 +1,728 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("LEGEND_LINE", 1);
define("LEGEND_BACKGROUND", 2);
define("LEGEND_MARK", 3);
define("LEGEND_MARKONLY", 4);
define("LEGEND_MODEL_RIGHT", 1);
define("LEGEND_MODEL_BOTTOM", 2);
define("LEGEND_LEFT", 1);
define("LEGEND_RIGHT", 2);
define("LEGEND_CENTER", 3);
define("LEGEND_TOP", 4);
define("LEGEND_BOTTOM", 5);
define("LEGEND_MIDDLE", 6);
/* </php4> */
/**
* Some legends
*
* @package Artichow
*/
class awLegend implements awPositionable {
/**
* Legends added
*
* @var array
*/
protected $legends = array();
/**
* The current component
*
* @var Component
*/
protected $component;
/**
* Background color or gradient
*
* @var Color, Gradient
*/
protected $background;
/**
* Text color
*
* @var Color
*/
protected $textColor;
/**
* Text font
*
* @var Font
*/
protected $textFont;
/**
* Text margin
*
* @var Side
*/
protected $textMargin;
/**
* Number of columns
*
* @var int
*/
protected $columns = NULL;
/**
* Number of rows
*
* @var int
*/
protected $rows = NULL;
/**
* Legend position
*
* @var Point
*/
protected $position;
/**
* Hide legend ?
*
* @var bool
*/
protected $hide = FALSE;
/**
* Space between each legend
*
* @var int
*/
protected $space = 4;
/**
* Horizontal alignment
*
* @var int
*/
protected $hAlign;
/**
* Vertical alignment
*
* @var int
*/
protected $vAlign;
/**
* Margin
*
* @var array Array for left, right, top and bottom margins
*/
private $margin;
/**
* Legend shadow
*
* @var Shadow
*/
public $shadow;
/**
* Legend border
*
* @var Border
*/
public $border;
/**
* Line legend
*
* @var int
*/
const LINE = 1;
/**
* Color/Gradient background legend
*
* @var int
*/
const BACKGROUND = 2;
/**
* Use marks and line as legend
*
* @var int
*/
const MARK = 3;
/**
* Use marks as legend
*
* @var int
*/
const MARKONLY = 4;
/**
* Right side model
*
* @var int
*/
const MODEL_RIGHT = 1;
/**
* Bottom side model
*
* @var int
*/
const MODEL_BOTTOM = 2;
/**
* Build the legend
*
* @param int $model Legend model
*/
public function __construct($model = awLegend::MODEL_RIGHT) {
$this->shadow = new awShadow(awShadow::LEFT_BOTTOM);
$this->border = new awBorder;
$this->textMargin = new awSide(4);
$this->setModel($model);
}
/**
* Set a predefined model for the legend
*
* @param int $model
*/
public function setModel($model) {
$this->setBackgroundColor(new awColor(255, 255, 255, 15));
$this->setPadding(8, 8, 8, 8);
$this->setTextFont(new awFont2);
$this->shadow->setSize(3);
switch($model) {
case awLegend::MODEL_RIGHT :
$this->setColumns(1);
$this->setAlign(awLegend::RIGHT, awLegend::MIDDLE);
$this->setPosition(0.96, 0.50);
break;
case awLegend::MODEL_BOTTOM :
$this->setRows(1);
$this->setAlign(awLegend::CENTER, awLegend::TOP);
$this->setPosition(0.50, 0.92);
break;
default :
$this->setPosition(0.5, 0.5);
break;
}
}
/**
* Hide legend ?
*
* @param bool $hide TRUE to hide legend, FALSE otherwise
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show legend ?
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Add a Legendable object to the legend
*
* @param awLegendable $legendable
* @param string $title Legend title
* @param int $type Legend type (default to awLegend::LINE)
*/
public function add(awLegendable $legendable, $title, $type = awLegend::LINE) {
$legend = array($legendable, $title, $type);
$this->legends[] = $legend;
}
/**
* Change legend padding
*
* @param int $left
* @param int $right
* @param int $top
* @param int $bottom
*/
public function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Change space between each legend
*
* @param int $space
*/
public function setSpace($space) {
$this->space = (int)$space;
}
/**
* Change alignment
*
* @param int $h Horizontal alignment
* @param int $v Vertical alignment
*/
public function setAlign($h = NULL, $v = NULL) {
if($h !== NULL) {
$this->hAlign = (int)$h;
}
if($v !== NULL) {
$this->vAlign = (int)$v;
}
}
/**
* Change number of columns
*
* @param int $columns
*/
public function setColumns($columns) {
$this->rows = NULL;
$this->columns = (int)$columns;
}
/**
* Change number of rows
*
* @param int $rows
*/
public function setRows($rows) {
$this->columns = NULL;
$this->rows = (int)$rows;
}
/**
* Change legend position
* X and Y positions must be between 0 and 1.
*
* @param float $x
* @param float $y
*/
public function setPosition($x = NULL, $y = NULL) {
$x = (is_null($x) and !is_null($this->position)) ? $this->position->x : $x;
$y = (is_null($y) and !is_null($this->position)) ? $this->position->y : $y;
$this->position = new awPoint($x, $y);
}
/**
* Get legend position
*
* @return Point
*/
public function getPosition() {
return $this->position;
}
/**
* Change text font
*
* @param awFont $font
*/
public function setTextFont(awFont $font) {
$this->textFont = $font;
}
/**
* Change text margin
*
* @param int $left
* @param int $right
*/
public function setTextMargin($left, $right) {
$this->textMargin->set($left, $right);
}
/**
* Change text color
*
* @param awColor $color
*/
public function setTextColor(awColor $color) {
$this->textColor = $color;
}
/**
* Change background
*
* @param mixed $background
*/
public function setBackground($background) {
$this->background = $background;
}
/**
* Change background color
*
* @param awColor $color
*/
public function setBackgroundColor(awColor $color) {
$this->background = $color;
}
/**
* Change background gradient
*
* @param awGradient $gradient
*/
public function setBackgroundGradient(awGradient $gradient) {
$this->background = $gradient;
}
/**
* Count the number of Legendable objects in the legend
*
* @return int
*/
public function count() {
return count($this->legends);
}
public function draw(awDrawer $drawer) {
if($this->hide) {
return;
}
$count = $this->count();
// No legend to print
if($count === 0) {
return;
}
// Get text widths and heights of each element of the legend
$widths = array();
$heights = array();
$texts = array();
for($i = 0; $i < $count; $i++) {
list(, $title, ) = $this->legends[$i];
$text = new awText(
$title,
$this->textFont,
$this->textColor,
0
);
$font = $text->getFont();
$widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
$heights[$i] = $font->getTextHeight($text);
$texts[$i] = $text;
}
// Maximum height of the font used
$heightMax = array_max($heights);
// Get number of columns
if($this->columns !== NULL) {
$columns = $this->columns;
} else if($this->rows !== NULL) {
$columns = ceil($count / $this->rows);
} else {
$columns = $count;
}
// Number of rows
$rows = (int)ceil($count / $columns);
// Get maximum with of each column
$widthMax = array();
for($i = 0; $i < $count; $i++) {
// Get column width
$column = $i % $columns;
if(array_key_exists($column, $widthMax) === FALSE) {
$widthMax[$column] = $widths[$i];
} else {
$widthMax[$column] = max($widthMax[$column], $widths[$i]);
}
}
$width = $this->padding[0] + $this->padding[1] - $this->space;
for($i = 0; $i < $columns; $i++) {
$width += $this->space + 5 + 10 + $widthMax[$i];
}
$height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
// Look for legends position
list($x, $y) = $drawer->getSize();
$p = new awPoint(
$this->position->x * $x,
$this->position->y * $y
);
switch($this->hAlign) {
case awLegend::CENTER :
$p->x -= $width / 2;
break;
case awLegend::RIGHT :
$p->x -= $width;
break;
}
switch($this->vAlign) {
case awLegend::MIDDLE :
$p->y -= $height / 2;
break;
case awLegend::BOTTOM :
$p->y -= $height;
break;
}
// Draw legend shadow
$this->shadow->draw(
$drawer,
$p,
$p->move($width, $height),
awShadow::OUT
);
// Draw legends base
$this->drawBase($drawer, $p, $width, $height);
// Draw each legend
for($i = 0; $i < $count; $i++) {
list($component, $title, $type) = $this->legends[$i];
$column = $i % $columns;
$row = (int)floor($i / $columns);
// Get width of all previous columns
$previousColumns = 0;
for($j = 0; $j < $column; $j++) {
$previousColumns += $this->space + 10 + 5 + $widthMax[$j];
}
// Draw legend text
$drawer->string(
$texts[$i],
$p->move(
$this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left,
$this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2
)
);
// Draw legend icon
switch($type) {
case awLegend::LINE :
case awLegend::MARK :
case awLegend::MARKONLY :
// Get vertical position
$x = $this->padding[0] + $previousColumns;
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
// Draw two lines
if($component->getLegendLineColor() !== NULL) {
$color = $component->getLegendLineColor();
if($color instanceof awColor and $type !== awLegend::MARKONLY) {
$drawer->line(
$color,
new awLine(
$p->move(
$x, // YaPB ??
$y + $component->getLegendLineThickness() / 2
),
$p->move(
$x + 10,
$y + $component->getLegendLineThickness() / 2
),
$component->getLegendLineStyle(),
$component->getLegendLineThickness()
)
);
$color->free();
unset($color);
}
}
if($type === awLegend::MARK or $type === awLegend::MARKONLY) {
$mark = $component->getLegendMark();
if($mark !== NULL) {
$mark->draw(
$drawer,
$p->move(
$x + 5.5,
$y + $component->getLegendLineThickness() / 2
)
);
}
unset($mark);
}
break;
case awLegend::BACKGROUND :
// Get vertical position
$x = $this->padding[0] + $previousColumns;
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
$from = $p->move(
$x,
$y
);
$to = $p->move(
$x + 10,
$y + 10
);
$background = $component->getLegendBackground();
if($background !== NULL) {
$drawer->filledRectangle(
$component->getLegendBackground(),
new awLine($from, $to)
);
// Draw rectangle border
$this->border->rectangle(
$drawer,
$from->move(0, 0),
$to->move(0, 0)
);
}
unset($background, $from, $to);
break;
}
}
}
private function drawBase(awDrawer $drawer, awPoint $p, $width, $height) {
$this->border->rectangle(
$drawer,
$p,
$p->move($width, $height)
);
$size = $this->border->visible() ? 1 : 0;
$drawer->filledRectangle(
$this->background,
new awLine(
$p->move($size, $size),
$p->move($width - $size, $height - $size)
)
);
}
}
registerClass('Legend');
/**
* You can add a legend to components which implements this interface
*
* @package Artichow
*/
interface awLegendable {
/**
* Get the line type
*
* @return int
*/
public function getLegendLineStyle();
/**
* Get the line thickness
*
* @return int
*/
public function getLegendLineThickness();
/**
* Get the color of line
*
* @return Color
*/
public function getLegendLineColor();
/**
* Get the background color or gradient of an element of the component
*
* @return Color, Gradient
*/
public function getLegendBackground();
/**
* Get a Mark object
*
* @return Mark
*/
public function getLegendMark();
}
registerInterface('Legendable');
?>

View File

@@ -0,0 +1,335 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("MARK_CIRCLE", 1);
define("MARK_SQUARE", 2);
define("MARK_IMAGE", 3);
define("MARK_STAR", 4);
define("MARK_PAPERCLIP", 5);
define("MARK_BOOK", 6);
/* </php4> */
/**
* Draw marks
*
* @package Artichow
*/
class awMark {
/**
* Circle mark
*
* @var int
*/
const CIRCLE = 1;
/**
* Quare mark
*
* @var int
*/
const SQUARE = 2;
/**
* Image mark
*
* @var int
*/
const IMAGE = 3;
/**
* Star mark
*
* @var int
*/
const STAR = 4;
/**
* Paperclip mark
*
* @var int
*/
const PAPERCLIP = 5;
/**
* Book mark
*
* @var int
*/
const BOOK = 6;
/**
* Must marks be hidden ?
*
* @var bool
*/
protected $hide;
/**
* Mark type
*
* @var int
*/
protected $type;
/**
* Mark size
*
* @var int
*/
protected $size = 8;
/**
* Fill mark
*
* @var Color, Gradient
*/
protected $fill;
/**
* Mark image
*
* @var Image
*/
protected $image;
/**
* To draw marks
*
* @var Drawer
*/
protected $drawer;
/**
* Move position from this vector
*
* @var Point
*/
protected $move;
/**
* Marks border
*
* @var Border
*/
public $border;
/**
* Build the mark
*/
public function __construct() {
$this->fill = new awColor(255, 0, 0, 0);
$this->border = new awBorder;
$this->border->hide();
$this->move = new awPoint(0, 0);
}
/**
* Change mark position
*
* @param int $x Add this interval to X coord
* @param int $y Add this interval to Y coord
*/
public function move($x, $y) {
$this->move = $this->move->move($x, $y);
}
/**
* Hide marks ?
*
* @param bool $hide TRUE to hide marks, FALSE otherwise
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show marks ?
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Change mark type
*
* @param int $size Size in pixels
*/
public function setSize($size) {
$this->size = (int)$size;
}
/**
* Change mark type
*
* @param int $type New mark type
* @param int $size Mark size (can be NULL)
*/
public function setType($type, $size = NULL) {
$this->type = (int)$type;
if($size !== NULL) {
$this->setSize($size);
}
}
/**
* Fill the mark with a color or a gradient
*
* @param mixed $fill A color or a gradient
*/
public function setFill($fill) {
if($fill instanceof awColor or $fill instanceof awGradient) {
$this->fill = $fill;
}
}
/**
* Set an image
* Only for awMark::IMAGE type.
*
* @param Image An image
*/
public function setImage(awImage $image) {
$this->image = $image;
}
/**
* Draw the mark
*
* @param awDrawer $drawer
* @param awPoint $point Mark center
*/
public function draw(awDrawer $drawer, awPoint $point) {
// Hide marks ?
if($this->hide) {
return;
}
// Check if we can print marks
if($this->type !== NULL) {
$this->drawer = $drawer;
$realPoint = $this->move->move($point->x, $point->y);
switch($this->type) {
case awMark::CIRCLE :
$this->drawCircle($realPoint);
break;
case awMark::SQUARE :
$this->drawSquare($realPoint);
break;
case awMark::IMAGE :
$this->drawImage($realPoint);
break;
case awMark::STAR :
$this->changeType('star');
$this->draw($drawer, $point);
break;
case awMark::PAPERCLIP :
$this->changeType('paperclip');
$this->draw($drawer, $point);
break;
case awMark::BOOK :
$this->changeType('book');
$this->draw($drawer, $point);
break;
}
}
}
protected function changeType($image) {
$this->setType(awMARK::IMAGE);
$this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
}
protected function drawCircle(awPoint $point) {
$this->drawer->filledEllipse(
$this->fill,
$point,
$this->size, $this->size
);
$this->border->ellipse(
$this->drawer,
$point,
$this->size, $this->size
);
}
protected function drawSquare(awPoint $point) {
list($x, $y) = $point->getLocation();
$x1 = (int)($x - $this->size / 2);
$x2 = $x1 + $this->size;
$y1 = (int)($y - $this->size / 2);
$y2 = $y1 + $this->size;
$this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
$size = $this->border->visible() ? 1 : 0;
$this->drawer->filledRectangle(
$this->fill,
new awLine(
new awPoint($x1 + $size, $y1 + $size),
new awPoint($x2 - $size, $y2 - $size)
)
);
}
protected function drawImage(awPoint $point) {
if($this->image instanceof awImage) {
$width = $this->image->width;
$height = $this->image->height;
list($x, $y) = $point->getLocation();
$x1 = (int)($x - $width / 2);
$x2 = $x1 + $width;
$y1 = (int)($y - $width / 2);
$y2 = $y1 + $height;
$this->border->rectangle($this->drawer, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
$this->drawer->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
}
}
}
registerClass('Mark');
?>

View File

@@ -0,0 +1,492 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
abstract class awShape {
/**
* Is the shape hidden ?
*
* @var bool
*/
protected $hide = FALSE;
/**
* Shape style
*
* @var int
*/
public $style;
/**
* Shape thickness
*
* @var int
*/
public $thickness;
/**
* Solid shape
*
* @var int
*/
const SOLID = 1;
/**
* Dotted shape
*
* @var int
*/
const DOTTED = 2;
/**
* Dashed shape
*
* @var int
*/
const DASHED = 3;
/**
* Change shape style
*
* @param int $style Line style
*/
public function setStyle($style) {
$this->style = (int)$style;
}
/**
* Return shape style
*
* @return int
*/
public function getStyle() {
return $this->style;
}
/**
* Change shape thickness
*
* @param int $thickness Shape thickness in pixels
*/
public function setThickness($thickness) {
$this->thickness = (int)$thickness;
}
/**
* Return shape thickness
*
* @return int
*/
public function getThickness() {
return $this->thickness;
}
/**
* Hide the shape
*
* @param bool $hide
*/
public function hide($hide) {
$this->hide = (bool)$hide;
}
/**
* Show the shape
*
* @param bool $shape
*/
public function show($shape) {
$this->hide = (bool)!$shape;
}
/**
* Is the line hidden ?
*
* @return bool
*/
public function isHidden() {
return $this->hide;
}
}
registerClass('Shape', TRUE);
/**
* Describe a point
*
* @package Artichow
*/
class awPoint extends awShape {
/**
* X coord
*
* @var float
*/
public $x;
/**
* Y coord
*
* @var float
*/
public $y;
/**
* Build a new awpoint
*
* @param float $x
* @param float $y
*/
public function __construct($x, $y) {
$this->setLocation($x, $y);
}
/**
* Change X value
*
* @param float $x
*/
public function setX($x) {
$this->x = (float)$x;
}
/**
* Change Y value
*
* @param float $y
*/
public function setY($y) {
$this->y = (float)$y;
}
/**
* Change point location
*
* @param float $x
* @param float $y
*/
public function setLocation($x, $y) {
$this->setX($x);
$this->setY($y);
}
/**
* Get point location
*
* @param array Point location
*/
public function getLocation() {
return array($this->x, $this->y);
}
/**
* Get distance to another point
*
* @param awPoint $p A point
* @return float
*/
public function getDistance(awPoint $p) {
return sqrt(pow($p->x - $this->x, 2) + pow($p->y - $this->y, 2));
}
/**
* Move the point to another location
*
* @param Point A Point with the new awlocation
*/
public function move($x, $y) {
return new awPoint(
$this->x + $x,
$this->y + $y
);
}
}
registerClass('Point');
/* <php4> */
define("LINE_SOLID", 1);
define("LINE_DOTTED", 2);
define("LINE_DASHED", 3);
/* </php4> */
/**
* Describe a line
*
* @package Artichow
*/
class awLine extends awShape {
/**
* Line first point
*
* @param Point
*/
public $p1;
/**
* Line second point
*
* @param Point
*/
public $p2;
/**
* Build a new awline
*
* @param awPoint $p1 First point
* @param awPoint $p2 Second point
* @param int $type Style of line (default to solid)
* @param int $thickness Line thickness (default to 1)
*/
public function __construct($p1 = NULL, $p2 = NULL, $type = awLine::SOLID, $thickness = 1) {
$this->setLocation($p1, $p2);
$this->setStyle($type);
$this->setThickness($thickness);
}
/**
* Build a line from 4 coords
*
* @param int $x1 Left position
* @param int $y1 Top position
* @param int $x2 Right position
* @param int $y2 Bottom position
*/
public static function build($x1, $y1, $x2, $y2) {
return new awLine(
new awPoint($x1, $y1),
new awPoint($x2, $y2)
);
}
/**
* Change X values of the line
*
* @param int $x1 Begin value
* @param int $x2 End value
*/
public function setX($x1, $x2) {
$this->p1->setX($x1);
$this->p2->setX($x2);
}
/**
* Change Y values of the line
*
* @param int $y1 Begin value
* @param int $y2 End value
*/
public function setY($y1, $y2) {
$this->p1->setY($y1);
$this->p2->setY($y2);
}
/**
* Change line location
*
* @param awPoint $p1 First point
* @param awPoint $p2 Second point
*/
public function setLocation($p1, $p2) {
if(is_null($p1) or $p1 instanceof awPoint) {
$this->p1 = $p1;
}
if(is_null($p2) or $p2 instanceof awPoint) {
$this->p2 = $p2;
}
}
/**
* Get line location
*
* @param array Line location
*/
public function getLocation() {
return array($this->p1, $this->p2);
}
/**
* Get the line size
*
* @return float
*/
public function getSize() {
$square = pow($this->p2->x - $this->p1->x, 2) + pow($this->p2->y - $this->p1->y, 2);
return sqrt($square);
}
/**
* Test if the line can be considered as a point
*
* @return bool
*/
public function isPoint() {
return ($this->p1->x === $this->p2->x and $this->p1->y === $this->p2->y);
}
/**
* Test if the line is a vertical line
*
* @return bool
*/
public function isVertical() {
return ($this->p1->x === $this->p2->x);
}
/**
* Test if the line is an horizontal line
*
* @return bool
*/
public function isHorizontal() {
return ($this->p1->y === $this->p2->y);
}
}
registerClass('Line');
/**
* A vector is a type of line
* The sense of the vector goes from $p1 to $p2.
*
* @package Artichow
*/
class awVector extends awLine {
/**
* Get vector angle in radians
*
* @return float
*/
public function getAngle() {
if($this->isPoint()) {
return 0.0;
}
$size = $this->getSize();
$width = ($this->p2->x - $this->p1->x);
$height = ($this->p2->y - $this->p1->y) * -1;
if($width >= 0 and $height >= 0) {
return acos($width / $size);
} else if($width <= 0 and $height >= 0) {
return acos($width / $size);
} else {
$height *= -1;
if($width >= 0 and $height >= 0) {
return 2 * M_PI - acos($width / $size);
} else if($width <= 0 and $height >= 0) {
return 2 * M_PI - acos($width / $size);
}
}
}
}
registerClass('Vector');
/* <php4> */
define("POLYGON_SOLID", 1);
define("POLYGON_DOTTED", 2);
define("POLYGON_DASHED", 3);
/* </php4> */
/**
* Describe a polygon
*
* @package Artichow
*/
class awPolygon extends awShape {
/**
* Polygon points
*
* @var array
*/
protected $points = array();
/**
* Set a point in the polygon
*
* @param int $pos Point position
* @param awPoint $point
*/
public function set($pos, $point) {
if(is_null($point) or $point instanceof awPoint) {
$this->points[$pos] = $point;
}
}
/**
* Add a point at the end of the polygon
*
* @param awPoint $point
*/
public function append($point) {
if(is_null($point) or $point instanceof awPoint) {
$this->points[] = $point;
}
}
/**
* Get a point at a position in the polygon
*
* @param int $pos Point position
* @return Point
*/
public function get($pos) {
return $this->points[$pos];
}
/**
* Count number of points in the polygon
*
* @return int
*/
public function count() {
return count($this->points);
}
/**
* Returns all points in the polygon
*
* @return array
*/
public function all() {
return $this->points;
}
}
registerClass('Polygon');
?>

View File

@@ -0,0 +1,415 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("SHADOW_LEFT_TOP", 1);
define("SHADOW_LEFT_BOTTOM", 2);
define("SHADOW_RIGHT_TOP", 3);
define("SHADOW_RIGHT_BOTTOM", 4);
define("SHADOW_IN", 1);
define("SHADOW_OUT", 2);
/* </php4> */
/**
* Draw shadows
*
*/
class awShadow {
/**
* Shadow on left and top sides
*
* @var int
*/
const LEFT_TOP = 1;
/**
* Shadow on left and bottom sides
*
* @var int
*/
const LEFT_BOTTOM = 2;
/**
* Shadow on right and top sides
*
* @var int
*/
const RIGHT_TOP = 3;
/**
* Shadow on right and bottom sides
*
* @var int
*/
const RIGHT_BOTTOM = 4;
/**
* In mode
*
* @var int
*/
const IN = 1;
/**
* Out mode
*
* @var int
*/
const OUT = 2;
/**
* Shadow size
*
* @var int
*/
private $size = 0;
/**
* Hide shadow ?
*
* @var bool
*/
protected $hide = FALSE;
/**
* Shadow color
*
* @var Color
*/
private $color;
/**
* Shadow position
*
* @var int
*/
private $position;
/**
* Smooth shadow ?
*
* @var bool
*/
private $smooth = FALSE;
/**
* Shadow constructor
*
* @param int $position Shadow position
*/
public function __construct($position) {
$this->setPosition($position);
}
/**
* Hide shadow ?
*
* @param bool $hide
*/
public function hide($hide = TRUE) {
$this->hide = (bool)$hide;
}
/**
* Show shadow ?
*
* @param bool $show
*/
public function show($show = TRUE) {
$this->hide = (bool)!$show;
}
/**
* Change shadow size
*
* @param int $size
* @param bool $smooth Smooth the shadow (facultative argument)
*/
public function setSize($size, $smooth = NULL) {
$this->size = (int)$size;
if($smooth !== NULL) {
$this->smooth($smooth);
}
}
/**
* Change shadow color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Change shadow position
*
* @param int $position
*/
public function setPosition($position) {
$this->position = (int)$position;
}
/**
* Smooth shadow ?
*
* @param bool $smooth
*/
public function smooth($smooth) {
$this->smooth = (bool)$smooth;
}
/**
* Get the space taken by the shadow
*
* @return Side
*/
public function getSpace() {
return new awSide(
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::LEFT_BOTTOM) ? $this->size : 0,
($this->position === awShadow::RIGHT_TOP or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0,
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::RIGHT_TOP) ? $this->size : 0,
($this->position === awShadow::LEFT_BOTTOM or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0
);
}
/**
* Draw shadow
*
* @param awDrawer $drawer
* @param awPoint $p1 Top-left point
* @param awPoint $p2 Right-bottom point
* @param int Drawing mode
*/
public function draw(awDrawer $drawer, awPoint $p1, awPoint $p2, $mode) {
if($this->hide) {
return;
}
if($this->size <= 0) {
return;
}
$drawer = clone $drawer;
$color = ($this->color instanceof awColor) ? $this->color : new awColor(125, 125, 125);
switch($this->position) {
case awShadow::RIGHT_BOTTOM :
if($mode === awShadow::OUT) {
$t1 = $p1->move(0, 0);
$t2 = $p2->move($this->size + 1, $this->size + 1);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($width - $this->size, $this->size),
new awPoint($width - 1, $height - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, $height - $this->size),
new awPoint($width - $this->size - 1, $height - 1)
)
);
$this->smoothPast($drawer, $color, $width, $height);
break;
case awShadow::LEFT_TOP :
if($mode === awShadow::OUT) {
$t1 = $p1->move(- $this->size, - $this->size);
$t2 = $p2->move(0, 0);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$height = max($height + 1, $this->size);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint(0, 0),
new awPoint($this->size - 1, $height - $this->size - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, 0),
new awPoint($width - $this->size - 1, $this->size - 1)
)
);
$this->smoothPast($drawer, $color, $width, $height);
break;
case awShadow::RIGHT_TOP :
if($mode === awShadow::OUT) {
$t1 = $p1->move(0, - $this->size);
$t2 = $p2->move($this->size + 1, 0);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$height = max($height + 1, $this->size);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($width - $this->size, 0),
new awPoint($width - 1, $height - $this->size - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, 0),
new awPoint($width - $this->size - 1, $this->size - 1)
)
);
$this->smoothFuture($drawer, $color, $width, $height);
break;
case awShadow::LEFT_BOTTOM :
if($mode === awShadow::OUT) {
$t1 = $p1->move(- $this->size, 0);
$t2 = $p2->move(0, $this->size + 1);
} else { // PHP 4 compatibility
$t1 = $p1->move(0, 0);
$t2 = $p2->move(0, 0);
}
$width = $t2->x - $t1->x;
$height = $t2->y - $t1->y;
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint(0, $this->size),
new awPoint($this->size - 1, $height - 1)
)
);
$drawer->filledRectangle(
$color,
new awLine(
new awPoint($this->size, $height - $this->size),
new awPoint($width - $this->size - 1, $height - 1)
)
);
$this->smoothFuture($drawer, $color, $width, $height);
break;
}
}
private function smoothPast(awDrawer $drawer, awColor $color, $width, $height) {
if($this->smooth) {
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($i, $j + $height - $this->size)
);
}
}
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($width - $this->size + $j, $i)
);
}
}
}
}
private function smoothFuture(awDrawer $drawer, awColor $color, $width, $height) {
if($this->smooth) {
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($i, $this->size - $j - 1)
);
}
}
for($i = 0; $i < $this->size; $i++) {
for($j = 0; $j <= $i; $j++) {
$drawer->point(
$color,
new awPoint($width - $this->size + $j, $height - $i - 1)
);
}
}
}
}
}
registerClass('Shadow');
?>

View File

@@ -0,0 +1,217 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* To handle text
*
* @package Artichow
*/
class awText {
/**
* Your text
*
* @var string
*/
private $text;
/**
* Text font
*
* @var Font
*/
private $font;
/**
* Text angle
* Can be 0 or 90
*
* @var int
*/
private $angle;
/**
* Text color
*
* @var Color
*/
private $color;
/**
* Text background
*
* @var Color, Gradient
*/
private $background;
/**
* Padding
*
* @var array Array for left, right, top and bottom paddings
*/
private $padding;
/**
* Text border
*
* @var Border
*/
public $border;
/**
* Build a new awtext
*
* @param string $text Your text
*/
public function __construct($text, $font = NULL, $color = NULL, $angle = 0) {
if(is_null($font)) {
$font = new awFont2;
}
$this->setText($text);
$this->setFont($font);
// Set default color to black
if($color === NULL) {
$color = new awColor(0, 0, 0);
}
$this->setColor($color);
$this->setAngle($angle);
$this->border = new awBorder;
$this->border->hide();
}
/**
* Get text
*
* @return string
*/
public function getText() {
return $this->text;
}
/**
* Change text
*
* @param string $text New text
*/
public function setText($text) {
$this->text = (string)$text;
}
/**
* Change text font
*
* @param Font
*/
public function setFont(awFont $font) {
$this->font = $font;
}
/**
* Get text font
*
* @return int
*/
public function getFont() {
return $this->font;
}
/**
* Change text angle
*
* @param int
*/
public function setAngle($angle) {
$this->angle = (int)$angle;
}
/**
* Get text angle
*
* @return int
*/
public function getAngle() {
return $this->angle;
}
/**
* Change text color
*
* @param Color
*/
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Get text color
*
* @return Color
*/
public function getColor() {
return $this->color;
}
/**
* Change text background color
*
* @param awColor $color
*/
public function setBackgroundColor(awColor $color) {
$this->background = $color;
}
/**
* Change text background gradient
*
* @param awGradient $gradient
*/
public function setBackgroundGradient(awGradient $gradient) {
$this->background = $gradient;
}
/**
* Get text background
*
* @return Color, Gradient
*/
public function getBackground() {
return $this->background;
}
/**
* Change padding
*
* @param int $left Left padding
* @param int $right Right padding
* @param int $top Top padding
* @param int $bottom Bottom padding
*/
public function setPadding($left, $right, $top, $bottom) {
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
}
/**
* Get current padding
*
* @return array
*/
public function getPadding() {
return $this->padding;
}
}
registerClass('Text');
?>

View File

@@ -0,0 +1,352 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/* <php4> */
define("TICK_IN", 0);
define("TICK_OUT", 1);
define("TICK_IN_OUT", 2);
/* </php4> */
/**
* Handle ticks
*
* @package Artichow
*/
class awTick {
/**
* Ticks style
*
* @var int
*/
protected $style = awTick::IN;
/**
* Ticks size
*
* @var int
*/
protected $size;
/**
* Ticks color
*
* @var Color
*/
protected $color;
/**
* Ticks number
*
* @var int
*/
protected $number;
/**
* Ticks number by other tick
*
* @var array
*/
protected $numberByTick;
/**
* Ticks interval
*
* @var int
*/
protected $interval = 1;
/**
* Hide ticks
*
* @var bool
*/
protected $hide = FALSE;
/**
* Hide first tick
*
* @var bool
*/
protected $hideFirst = FALSE;
/**
* Hide last tick
*
* @var bool
*/
protected $hideLast = FALSE;
/**
* In mode
*
* @param int
*/
const IN = 0;
/**
* Out mode
*
* @param int
*/
const OUT = 1;
/**
* In and out mode
*
* @param int
*/
const IN_OUT = 2;
/**
* Build the ticks
*
* @param int $number Number of ticks
* @param int $size Ticks size
*/
public function __construct($number, $size) {
$this->setSize($size);
$this->setNumber($number);
$this->setColor(new awBlack);
$this->style = awTick::IN;
}
/**
* Change ticks style
*
* @param int $style
*/
public function setStyle($style) {
$this->style = (int)$style;
}
/**
* Get ticks style
*
* @return int
*/
public function getStyle() {
return $this->style;
}
/**
* Change ticks color
*
* @param awColor $color
*/
public function setColor(awColor $color) {
$this->color = $color;
}
/**
* Change ticks size
*
* @param int $size
*/
public function setSize($size) {
$this->size = (int)$size;
}
/**
* Change interval of ticks
*
* @param int $interval
*/
public function setInterval($interval) {
$this->interval = (int)$interval;
}
/**
* Get interval between each tick
*
* @return int
*/
public function getInterval() {
return $this->interval;
}
/**
* Change number of ticks
*
* @param int $number
*/
public function setNumber($number) {
$this->number = (int)$number;
}
/**
* Get number of ticks
*
* @return int
*/
public function getNumber() {
return $this->number;
}
/**
* Change number of ticks relative to others ticks
*
* @param awTick $tick Ticks reference
* @param int $number Number of ticks
*/
public function setNumberByTick(awTick $tick, $number) {
/* <php5> */
$this->numberByTick = array($tick, (int)$number);
/* </php5> */
/* <php4> --
$this->numberByTick = array(&$tick, (int)$number);
-- </php4> */
}
/**
* Hide ticks
*
* @param bool $hide
*/
public function hide($hide) {
$this->hide = (bool)$hide;
}
/**
* Hide first tick
*
* @param bool $hide
*/
public function hideFirst($hide) {
$this->hideFirst = (bool)$hide;
}
/**
* Hide last tick
*
* @param bool $hide
*/
public function hideLast($hide) {
$this->hideLast = (bool)$hide;
}
/**
* Draw ticks on a vector
*
* @param awDrawer $drawer A drawer
* @param awVector $vector A vector
*/
public function draw(awDrawer $drawer, awVector $vector) {
if($this->numberByTick !== NULL) {
list($tick, $number) = $this->numberByTick;
$this->number = 1 + ($tick->getNumber() - 1) * ($number + 1);
$this->interval = $tick->getInterval();
}
if($this->number < 2 or $this->hide) {
return;
}
$angle = $vector->getAngle();
// echo "INIT:".$angle."<br>";
switch($this->style) {
case awTick::IN :
$this->drawTicks($drawer, $vector, NULL, $angle + M_PI / 2);
break;
case awTick::OUT :
$this->drawTicks($drawer, $vector, $angle + 3 * M_PI / 2, NULL);
break;
default :
$this->drawTicks($drawer, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2);
break;
}
}
protected function drawTicks(awDrawer $drawer, awVector $vector, $from, $to) {
// Draw last tick
if($this->hideLast === FALSE) {
//echo '<b>';
if(($this->number - 1) % $this->interval === 0) {
$this->drawTick($drawer, $vector->p2, $from, $to);
}
//echo '</b>';
}
$number = $this->number - 1;
$size = $vector->getSize();
// Get tick increment in pixels
$inc = $size / $number;
// Check if we must hide the first tick
$start = $this->hideFirst ? $inc : 0;
$stop = $inc * $number;
$position = 0;
for($i = $start; round($i, 6) < $stop; $i += $inc) {
if($position % $this->interval === 0) {
$p = $vector->p1->move(
round($i * cos($vector->getAngle()), 6),
round($i * sin($vector->getAngle() * -1), 6)
);
$this->drawTick($drawer, $p, $from, $to);
}
$position++;
}
//echo '<br><br>';
}
protected function drawTick(awDrawer $drawer, awPoint $p, $from, $to) {
// echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
// The round avoid some errors in the calcul
// For example, 12.00000008575245 becomes 12
$p1 = $p;
$p2 = $p;
if($from !== NULL) {
$p1 = $p1->move(
round($this->size * cos($from), 6),
round($this->size * sin($from) * -1, 6)
);
}
if($to !== NULL) {
$p2 = $p2->move(
round($this->size * cos($to), 6),
round($this->size * sin($to) * -1, 6)
);
}
//echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
$vector = new awVector(
$p1, $p2
);
$drawer->line(
$this->color,
$vector
);
}
}
registerClass('Tick');
?>

View File

@@ -0,0 +1,173 @@
<?php
/*
* This work is hereby released into the Public Domain.
* To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
*/
/**
* Objects capable of being positioned
*
* @package Artichow
*/
interface awPositionable {
/**
* Left align
*
* @var int
*/
const LEFT = 1;
/**
* Right align
*
* @var int
*/
const RIGHT = 2;
/**
* Center align
*
* @var int
*/
const CENTER = 3;
/**
* Top align
*
* @var int
*/
const TOP = 4;
/**
* Bottom align
*
* @var int
*/
const BOTTOM = 5;
/**
* Middle align
*
* @var int
*/
const MIDDLE = 6;
/**
* Change alignment
*
* @param int $h Horizontal alignment
* @param int $v Vertical alignment
*/
public function setAlign($h = NULL, $v = NULL);
}
registerInterface('Positionable');
/**
* Manage left, right, top and bottom sides
*
* @package Artichow
*/
class awSide {
/**
* Left side
*
* @var int
*/
public $left = 0;
/**
* Right side
*
* @var int
*/
public $right = 0;
/**
* Top side
*
* @var int
*/
public $top = 0;
/**
* Bottom side
*
* @var int
*/
public $bottom = 0;
/**
* Build the side
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
public function __construct($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->set($left, $right, $top, $bottom);
}
/**
* Change side values
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
public function set($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
if($left !== NULL) {
$this->left = (float)$left;
}
if($right !== NULL) {
$this->right = (float)$right;
}
if($top !== NULL) {
$this->top = (float)$top;
}
if($bottom !== NULL) {
$this->bottom = (float)$bottom;
}
}
/**
* Add values to each side
*
* @param mixed $left
* @param mixed $right
* @param mixed $top
* @param mixed $bottom
*/
public function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
if($left !== NULL) {
$this->left += (float)$left;
}
if($right !== NULL) {
$this->right += (float)$right;
}
if($top !== NULL) {
$this->top += (float)$top;
}
if($bottom !== NULL) {
$this->bottom += (float)$bottom;
}
}
}
registerClass('Side');
?>

View File

@@ -0,0 +1,7 @@
Smarty is supported only in PHP 4.0.6 or later.
Smarty versions previous to 2.0 require the PEAR libraries. Be sure to include
the path to the PEAR libraries in your php include_path. Config_file.class.php
uses the PEAR library for its error handling routines. PEAR comes with the PHP
distribution. Unix users check /usr/local/lib/php, windows users check
C:/php/pear.

View File

@@ -0,0 +1,458 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS

View File

@@ -0,0 +1,86 @@
NAME:
Smarty - the PHP compiling template engine
VERSION: 2.6.26
AUTHORS:
Monte Ohrt <monte at ohrt dot com>
Andrei Zmievski <andrei@php.net>
MAILING LISTS:
We have a few mailing lists. "discussion" for you to share your ideas or ask
questions, "developers" for those interested in the development efforts of Smarty,
and "svn" for those that would like to track the updates made in the svn
repository.
send a blank e-mail message to:
smarty-discussion-subscribe@googlecode.com(subscribe to the general discussion list)
smarty-discussion-unsubscribe@googlecode.com (unsubscribe from the general discussion list)
smarty-discussion-digest-subscribe@googlecode.com (subscribe to digest)
smarty-discussion-digest-unsubscribe@googlecode.com (unsubscribe from digest)
smarty-developers-subscribe@googlecode.com (subscribe to the dev list)
smarty-developers-unsubscribe@googlecode.com (unsubscribe from the dev list)
smarty-svn-subscribe@googlecode.com (subscribe to the svn list)
smarty-svn-unsubscribe@googlecode.com (unsubscribe from the svn list)
You can also browse the mailing list archives at
http://groups.google.com/group/smarty-discussion
http://groups.google.com/group/smarty-developers
and the OLD list archives at
http://marc.theaimsgroup.com/?l=smarty&r=1&w=2
SYNOPSIS:
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->assign("Title","My Homepage");
$smarty->assign("Names",array("John","Gary","Gregg","James"));
$smarty->display("index.tpl");
DESCRIPTION:
What is Smarty?
Smarty is a template engine for PHP. Many other template engines for PHP
provide basic variable substitution and dynamic block functionality.
Smarty takes a step further to be a "smart" template engine, adding
features such as configuration files, template functions, and variable
modifiers, and making all of this functionality as easy as possible to
use for both programmers and template designers. Smarty also converts
the templates into PHP scripts, eliminating the need to parse the
templates on every invocation. This makes Smarty extremely scalable and
manageable for large application needs.
Some of Smarty's features:
* it is extremely fast
* no template parsing overhead, only compiles once.
* it is smart about recompiling only the template files that have
changed.
* the template language is remarkably extensible via the plugin
architecture.
* configurable template delimiter tag syntax, so you can use
{}, {{}}, <!--{}-->, or whatever you like.
* built-in caching of template output.
* arbitrary template sources (filesystem, databases, etc.)
* template if/elseif/else/endif constructs are passed to the PHP parser,
so the if syntax can be as simple or as complex as you like.
* unlimited nesting of sections, conditionals, etc. allowed
* it is possible to embed PHP code right in your template files,
although not recommended and doubtfully needed since the engine
is so customizable.
* and many more.
COPYRIGHT:
Copyright (c) 2001-2005 New Digital Group, Inc. All rights reserved.
This software is released under the GNU Lesser General Public License.
Please read the disclaimer at the top of the Smarty.class.php file.

View File

@@ -0,0 +1,393 @@
<?php
/**
* Config_File class.
*
* 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
*
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @version 2.6.26
* @copyright Copyright: 2001-2005 New Digital Group, Inc.
* @author Andrei Zmievski <andrei@php.net>
* @access public
* @package Smarty
*/
/* $Id$ */
/**
* Config file reading class
* @package Smarty
*/
class Config_File {
/**#@+
* Options
* @var boolean
*/
/**
* Controls whether variables with the same name overwrite each other.
*/
var $overwrite = true;
/**
* Controls whether config values of on/true/yes and off/false/no get
* converted to boolean values automatically.
*/
var $booleanize = true;
/**
* Controls whether hidden config sections/vars are read from the file.
*/
var $read_hidden = true;
/**
* Controls whether or not to fix mac or dos formatted newlines.
* If set to true, \r or \r\n will be changed to \n.
*/
var $fix_newlines = true;
/**#@-*/
/** @access private */
var $_config_path = "";
var $_config_data = array();
/**#@-*/
/**
* Constructs a new config file class.
*
* @param string $config_path (optional) path to the config files
*/
function Config_File($config_path = NULL)
{
if (isset($config_path))
$this->set_path($config_path);
}
/**
* Set the path where configuration files can be found.
*
* @param string $config_path path to the config files
*/
function set_path($config_path)
{
if (!empty($config_path)) {
if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) {
$this->_trigger_error_msg("Bad config file path '$config_path'");
return;
}
if(substr($config_path, -1) != DIRECTORY_SEPARATOR) {
$config_path .= DIRECTORY_SEPARATOR;
}
$this->_config_path = $config_path;
}
}
/**
* Retrieves config info based on the file, section, and variable name.
*
* @param string $file_name config file to get info for
* @param string $section_name (optional) section to get info for
* @param string $var_name (optional) variable to get info for
* @return string|array a value or array of values
*/
function get($file_name, $section_name = NULL, $var_name = NULL)
{
if (empty($file_name)) {
$this->_trigger_error_msg('Empty config file name');
return;
} else {
$file_name = $this->_config_path . $file_name;
if (!isset($this->_config_data[$file_name]))
$this->load_file($file_name, false);
}
if (!empty($var_name)) {
if (empty($section_name)) {
return $this->_config_data[$file_name]["vars"][$var_name];
} else {
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]))
return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name];
else
return array();
}
} else {
if (empty($section_name)) {
return (array)$this->_config_data[$file_name]["vars"];
} else {
if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"]))
return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"];
else
return array();
}
}
}
/**
* Retrieves config info based on the key.
*
* @param $file_name string config key (filename/section/var)
* @return string|array same as get()
* @uses get() retrieves information from config file and returns it
*/
function &get_key($config_key)
{
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
$result = &$this->get($file_name, $section_name, $var_name);
return $result;
}
/**
* Get all loaded config file names.
*
* @return array an array of loaded config file names
*/
function get_file_names()
{
return array_keys($this->_config_data);
}
/**
* Get all section names from a loaded file.
*
* @param string $file_name config file to get section names from
* @return array an array of section names from the specified file
*/
function get_section_names($file_name)
{
$file_name = $this->_config_path . $file_name;
if (!isset($this->_config_data[$file_name])) {
$this->_trigger_error_msg("Unknown config file '$file_name'");
return;
}
return array_keys($this->_config_data[$file_name]["sections"]);
}
/**
* Get all global or section variable names.
*
* @param string $file_name config file to get info for
* @param string $section_name (optional) section to get info for
* @return array an array of variables names from the specified file/section
*/
function get_var_names($file_name, $section = NULL)
{
if (empty($file_name)) {
$this->_trigger_error_msg('Empty config file name');
return;
} else if (!isset($this->_config_data[$file_name])) {
$this->_trigger_error_msg("Unknown config file '$file_name'");
return;
}
if (empty($section))
return array_keys($this->_config_data[$file_name]["vars"]);
else
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
}
/**
* Clear loaded config data for a certain file or all files.
*
* @param string $file_name file to clear config data for
*/
function clear($file_name = NULL)
{
if ($file_name === NULL)
$this->_config_data = array();
else if (isset($this->_config_data[$file_name]))
$this->_config_data[$file_name] = array();
}
/**
* Load a configuration file manually.
*
* @param string $file_name file name to load
* @param boolean $prepend_path whether current config path should be
* prepended to the filename
*/
function load_file($file_name, $prepend_path = true)
{
if ($prepend_path && $this->_config_path != "")
$config_file = $this->_config_path . $file_name;
else
$config_file = $file_name;
ini_set('track_errors', true);
$fp = @fopen($config_file, "r");
if (!is_resource($fp)) {
$this->_trigger_error_msg("Could not open config file '$config_file'");
return false;
}
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
fclose($fp);
$this->_config_data[$config_file] = $this->parse_contents($contents);
return true;
}
/**
* Store the contents of a file manually.
*
* @param string $config_file file name of the related contents
* @param string $contents the file-contents to parse
*/
function set_file_contents($config_file, $contents)
{
$this->_config_data[$config_file] = $this->parse_contents($contents);
return true;
}
/**
* parse the source of a configuration file manually.
*
* @param string $contents the file-contents to parse
*/
function parse_contents($contents)
{
if($this->fix_newlines) {
// fix mac/dos formatted newlines
$contents = preg_replace('!\r\n?!', "\n", $contents);
}
$config_data = array();
$config_data['sections'] = array();
$config_data['vars'] = array();
/* reference to fill with data */
$vars =& $config_data['vars'];
/* parse file line by line */
preg_match_all('!^.*\r?\n?!m', $contents, $match);
$lines = $match[0];
for ($i=0, $count=count($lines); $i<$count; $i++) {
$line = $lines[$i];
if (empty($line)) continue;
if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
/* section found */
if (substr($match[1], 0, 1) == '.') {
/* hidden section */
if ($this->read_hidden) {
$section_name = substr($match[1], 1);
} else {
/* break reference to $vars to ignore hidden section */
unset($vars);
$vars = array();
continue;
}
} else {
$section_name = $match[1];
}
if (!isset($config_data['sections'][$section_name]))
$config_data['sections'][$section_name] = array('vars' => array());
$vars =& $config_data['sections'][$section_name]['vars'];
continue;
}
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
/* variable found */
$var_name = rtrim($match[1]);
if (strpos($match[2], '"""') === 0) {
/* handle multiline-value */
$lines[$i] = substr($match[2], 3);
$var_value = '';
while ($i<$count) {
if (($pos = strpos($lines[$i], '"""')) === false) {
$var_value .= $lines[$i++];
} else {
/* end of multiline-value */
$var_value .= substr($lines[$i], 0, $pos);
break;
}
}
$booleanize = false;
} else {
/* handle simple value */
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
$booleanize = $this->booleanize;
}
$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
}
/* else unparsable line / means it is a comment / means ignore it */
}
return $config_data;
}
/**#@+ @access private */
/**
* @param array &$container
* @param string $var_name
* @param mixed $var_value
* @param boolean $booleanize determines whether $var_value is converted to
* to true/false
*/
function _set_config_var(&$container, $var_name, $var_value, $booleanize)
{
if (substr($var_name, 0, 1) == '.') {
if (!$this->read_hidden)
return;
else
$var_name = substr($var_name, 1);
}
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
$this->_trigger_error_msg("Bad variable name '$var_name'");
return;
}
if ($booleanize) {
if (preg_match("/^(on|true|yes)$/i", $var_value))
$var_value = true;
else if (preg_match("/^(off|false|no)$/i", $var_value))
$var_value = false;
}
if (!isset($container[$var_name]) || $this->overwrite)
$container[$var_name] = $var_value;
else {
settype($container[$var_name], 'array');
$container[$var_name][] = $var_value;
}
}
/**
* @uses trigger_error() creates a PHP warning/error
* @param string $error_msg
* @param integer $error_type one of
*/
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
{
trigger_error("Config_File error: $error_msg", $error_type);
}
/**#@-*/
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
{* Smarty *}
{* debug.tpl, last updated version 2.1.0 *}
{assign_debug_info}
{capture assign=debug_output}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Smarty Debug Console</title>
{literal}
<style type="text/css">
/* <![CDATA[ */
body, h1, h2, td, th, p {
font-family: sans-serif;
font-weight: normal;
font-size: 0.9em;
margin: 1px;
padding: 0;
}
h1 {
margin: 0;
text-align: left;
padding: 2px;
background-color: #f0c040;
color: black;
font-weight: bold;
font-size: 1.2em;
}
h2 {
background-color: #9B410E;
color: white;
text-align: left;
font-weight: bold;
padding: 2px;
border-top: 1px solid black;
}
body {
background: black;
}
p, table, div {
background: #f0ead8;
}
p {
margin: 0;
font-style: italic;
text-align: center;
}
table {
width: 100%;
}
th, td {
font-family: monospace;
vertical-align: top;
text-align: left;
width: 50%;
}
td {
color: green;
}
.odd {
background-color: #eeeeee;
}
.even {
background-color: #fafafa;
}
.exectime {
font-size: 0.8em;
font-style: italic;
}
#table_assigned_vars th {
color: blue;
}
#table_config_vars th {
color: maroon;
}
/* ]]> */
</style>
{/literal}
</head>
<body>
<h1>Smarty Debug Console</h1>
<h2>included templates &amp; config files (load time in seconds)</h2>
<div>
{section name=templates loop=$_debug_tpls}
{section name=indent loop=$_debug_tpls[templates].depth}&nbsp;&nbsp;&nbsp;{/section}
<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>
{$_debug_tpls[templates].filename|escape:html}</font>
{if isset($_debug_tpls[templates].exec_time)}
<span class="exectime">
({$_debug_tpls[templates].exec_time|string_format:"%.5f"})
{if %templates.index% eq 0}(total){/if}
</span>
{/if}
<br />
{sectionelse}
<p>no templates included</p>
{/section}
</div>
<h2>assigned template variables</h2>
<table id="table_assigned_vars">
{section name=vars loop=$_debug_keys}
<tr class="{cycle values="odd,even"}">
<th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th>
<td>{$_debug_vals[vars]|@debug_print_var}</td></tr>
{sectionelse}
<tr><td><p>no template variables assigned</p></td></tr>
{/section}
</table>
<h2>assigned config file variables (outer template scope)</h2>
<table id="table_config_vars">
{section name=config_vars loop=$_debug_config_keys}
<tr class="{cycle values="odd,even"}">
<th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th>
<td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr>
{sectionelse}
<tr><td><p>no config vars assigned</p></td></tr>
{/section}
</table>
</body>
</html>
{/capture}
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
{$debug_output}
{else}
<script type="text/javascript">
// <![CDATA[
if ( self.name == '' ) {ldelim}
var title = 'Console';
{rdelim}
else {ldelim}
var title = 'Console_' + self.name;
{rdelim}
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
_smarty_console.document.write('{$debug_output|escape:'javascript'}');
_smarty_console.document.close();
// ]]>
</script>
{/if}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* assemble filepath of requested plugin
*
* @param string $type
* @param string $name
* @return string|false
*/
function smarty_core_assemble_plugin_filepath($params, &$smarty)
{
static $_filepaths_cache = array();
$_plugin_filename = $params['type'] . '.' . $params['name'] . '.php';
if (isset($_filepaths_cache[$_plugin_filename])) {
return $_filepaths_cache[$_plugin_filename];
}
$_return = false;
foreach ((array)$smarty->plugins_dir as $_plugin_dir) {
$_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
// see if path is relative
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
$_relative_paths[] = $_plugin_dir;
// relative path, see if it is in the SMARTY_DIR
if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
$_return = SMARTY_DIR . $_plugin_filepath;
break;
}
}
// try relative to cwd (or absolute)
if (@is_readable($_plugin_filepath)) {
$_return = $_plugin_filepath;
break;
}
}
if($_return === false) {
// still not found, try PHP include_path
if(isset($_relative_paths)) {
foreach ((array)$_relative_paths as $_plugin_dir) {
$_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename;
$_params = array('file_path' => $_plugin_filepath);
require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $smarty)) {
$_return = $_params['new_file_path'];
break;
}
}
}
}
$_filepaths_cache[$_plugin_filename] = $_return;
return $_return;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,43 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty assign_smarty_interface core plugin
*
* Type: core<br>
* Name: assign_smarty_interface<br>
* Purpose: assign the $smarty interface variable
* @param array Format: null
* @param Smarty
*/
function smarty_core_assign_smarty_interface($params, &$smarty)
{
if (isset($smarty->_smarty_vars) && isset($smarty->_smarty_vars['request'])) {
return;
}
$_globals_map = array('g' => 'HTTP_GET_VARS',
'p' => 'HTTP_POST_VARS',
'c' => 'HTTP_COOKIE_VARS',
's' => 'HTTP_SERVER_VARS',
'e' => 'HTTP_ENV_VARS');
$_smarty_vars_request = array();
foreach (preg_split('!!', strtolower($smarty->request_vars_order)) as $_c) {
if (isset($_globals_map[$_c])) {
$_smarty_vars_request = array_merge($_smarty_vars_request, $GLOBALS[$_globals_map[$_c]]);
}
}
$_smarty_vars_request = @array_merge($_smarty_vars_request, $GLOBALS['HTTP_SESSION_VARS']);
$smarty->_smarty_vars['request'] = $_smarty_vars_request;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,79 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* create full directory structure
*
* @param string $dir
*/
// $dir
function smarty_core_create_dir_structure($params, &$smarty)
{
if (!file_exists($params['dir'])) {
$_open_basedir_ini = ini_get('open_basedir');
if (DIRECTORY_SEPARATOR=='/') {
/* unix-style paths */
$_dir = $params['dir'];
$_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY);
$_new_dir = (substr($_dir, 0, 1)=='/') ? '/' : getcwd().'/';
if($_use_open_basedir = !empty($_open_basedir_ini)) {
$_open_basedirs = explode(':', $_open_basedir_ini);
}
} else {
/* other-style paths */
$_dir = str_replace('\\','/', $params['dir']);
$_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY);
if (preg_match('!^((//)|([a-zA-Z]:/))!', $_dir, $_root_dir)) {
/* leading "//" for network volume, or "[letter]:/" for full path */
$_new_dir = $_root_dir[1];
/* remove drive-letter from _dir_parts */
if (isset($_root_dir[3])) array_shift($_dir_parts);
} else {
$_new_dir = str_replace('\\', '/', getcwd()).'/';
}
if($_use_open_basedir = !empty($_open_basedir_ini)) {
$_open_basedirs = explode(';', str_replace('\\', '/', $_open_basedir_ini));
}
}
/* all paths use "/" only from here */
foreach ($_dir_parts as $_dir_part) {
$_new_dir .= $_dir_part;
if ($_use_open_basedir) {
// do not attempt to test or make directories outside of open_basedir
$_make_new_dir = false;
foreach ($_open_basedirs as $_open_basedir) {
if (substr($_new_dir, 0, strlen($_open_basedir)) == $_open_basedir) {
$_make_new_dir = true;
break;
}
}
} else {
$_make_new_dir = true;
}
if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, $smarty->_dir_perms) && !is_dir($_new_dir)) {
$smarty->trigger_error("problem creating directory '" . $_new_dir . "'");
return false;
}
$_new_dir .= '/';
}
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,61 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty debug_console function plugin
*
* Type: core<br>
* Name: display_debug_console<br>
* Purpose: display the javascript debug console window
* @param array Format: null
* @param Smarty
*/
function smarty_core_display_debug_console($params, &$smarty)
{
// we must force compile the debug template in case the environment
// changed between separate applications.
if(empty($smarty->debug_tpl)) {
// set path to debug template from SMARTY_DIR
$smarty->debug_tpl = SMARTY_DIR . 'debug.tpl';
if($smarty->security && is_file($smarty->debug_tpl)) {
$smarty->secure_dir[] = realpath($smarty->debug_tpl);
}
$smarty->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl';
}
$_ldelim_orig = $smarty->left_delimiter;
$_rdelim_orig = $smarty->right_delimiter;
$smarty->left_delimiter = '{';
$smarty->right_delimiter = '}';
$_compile_id_orig = $smarty->_compile_id;
$smarty->_compile_id = null;
$_compile_path = $smarty->_get_compile_path($smarty->debug_tpl);
if ($smarty->_compile_resource($smarty->debug_tpl, $_compile_path))
{
ob_start();
$smarty->_include($_compile_path);
$_results = ob_get_contents();
ob_end_clean();
} else {
$_results = '';
}
$smarty->_compile_id = $_compile_id_orig;
$smarty->left_delimiter = $_ldelim_orig;
$smarty->right_delimiter = $_rdelim_orig;
return $_results;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Get path to file from include_path
*
* @param string $file_path
* @param string $new_file_path
* @return boolean
* @staticvar array|null
*/
// $file_path, &$new_file_path
function smarty_core_get_include_path(&$params, &$smarty)
{
static $_path_array = null;
if(!isset($_path_array)) {
$_ini_include_path = ini_get('include_path');
if(strstr($_ini_include_path,';')) {
// windows pathnames
$_path_array = explode(';',$_ini_include_path);
} else {
$_path_array = explode(':',$_ini_include_path);
}
}
foreach ($_path_array as $_include_path) {
if (@is_readable($_include_path . DIRECTORY_SEPARATOR . $params['file_path'])) {
$params['new_file_path'] = $_include_path . DIRECTORY_SEPARATOR . $params['file_path'];
return true;
}
}
return false;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,23 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Get seconds and microseconds
* @return double
*/
function smarty_core_get_microtime($params, &$smarty)
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Retrieves PHP script resource
*
* sets $php_resource to the returned resource
* @param string $resource
* @param string $resource_type
* @param $php_resource
* @return boolean
*/
function smarty_core_get_php_resource(&$params, &$smarty)
{
$params['resource_base_path'] = $smarty->trusted_dir;
$smarty->_parse_resource_name($params, $smarty);
/*
* Find out if the resource exists.
*/
if ($params['resource_type'] == 'file') {
$_readable = false;
if(file_exists($params['resource_name']) && is_readable($params['resource_name'])) {
$_readable = true;
} else {
// test for file in include_path
$_params = array('file_path' => $params['resource_name']);
require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $smarty)) {
$_include_path = $_params['new_file_path'];
$_readable = true;
}
}
} else if ($params['resource_type'] != 'file') {
$_template_source = null;
$_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0])
&& call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
array($params['resource_name'], &$_template_source, &$smarty));
}
/*
* Set the error function, depending on which class calls us.
*/
if (method_exists($smarty, '_syntax_error')) {
$_error_funcc = '_syntax_error';
} else {
$_error_funcc = 'trigger_error';
}
if ($_readable) {
if ($smarty->security) {
require_once(SMARTY_CORE_DIR . 'core.is_trusted.php');
if (!smarty_core_is_trusted($params, $smarty)) {
$smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted');
return false;
}
}
} else {
$smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable');
return false;
}
if ($params['resource_type'] == 'file') {
$params['php_resource'] = $params['resource_name'];
} else {
$params['php_resource'] = $_template_source;
}
return true;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,59 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* determines if a resource is secure or not.
*
* @param string $resource_type
* @param string $resource_name
* @return boolean
*/
// $resource_type, $resource_name
function smarty_core_is_secure($params, &$smarty)
{
if (!$smarty->security || $smarty->security_settings['INCLUDE_ANY']) {
return true;
}
if ($params['resource_type'] == 'file') {
$_rp = realpath($params['resource_name']);
if (isset($params['resource_base_path'])) {
foreach ((array)$params['resource_base_path'] as $curr_dir) {
if ( ($_cd = realpath($curr_dir)) !== false &&
strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
return true;
}
}
}
if (!empty($smarty->secure_dir)) {
foreach ((array)$smarty->secure_dir as $curr_dir) {
if ( ($_cd = realpath($curr_dir)) !== false) {
if($_cd == $_rp) {
return true;
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) {
return true;
}
}
}
}
} else {
// resource is not on local file system
return call_user_func_array(
$smarty->_plugins['resource'][$params['resource_type']][0][2],
array($params['resource_name'], &$smarty));
}
return false;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,47 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* determines if a resource is trusted or not
*
* @param string $resource_type
* @param string $resource_name
* @return boolean
*/
// $resource_type, $resource_name
function smarty_core_is_trusted($params, &$smarty)
{
$_smarty_trusted = false;
if ($params['resource_type'] == 'file') {
if (!empty($smarty->trusted_dir)) {
$_rp = realpath($params['resource_name']);
foreach ((array)$smarty->trusted_dir as $curr_dir) {
if (!empty($curr_dir) && is_readable ($curr_dir)) {
$_cd = realpath($curr_dir);
if (strncmp($_rp, $_cd, strlen($_cd)) == 0
&& substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
$_smarty_trusted = true;
break;
}
}
}
}
} else {
// resource is not on local file system
$_smarty_trusted = call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][3],
array($params['resource_name'], $smarty));
}
return $_smarty_trusted;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,125 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Load requested plugins
*
* @param array $plugins
*/
// $plugins
function smarty_core_load_plugins($params, &$smarty)
{
foreach ($params['plugins'] as $_plugin_info) {
list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info;
$_plugin = &$smarty->_plugins[$_type][$_name];
/*
* We do not load plugin more than once for each instance of Smarty.
* The following code checks for that. The plugin can also be
* registered dynamically at runtime, in which case template file
* and line number will be unknown, so we fill them in.
*
* The final element of the info array is a flag that indicates
* whether the dynamically registered plugin function has been
* checked for existence yet or not.
*/
if (isset($_plugin)) {
if (empty($_plugin[3])) {
if (!is_callable($_plugin[0])) {
$smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
} else {
$_plugin[1] = $_tpl_file;
$_plugin[2] = $_tpl_line;
$_plugin[3] = true;
if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */
}
}
continue;
} else if ($_type == 'insert') {
/*
* For backwards compatibility, we check for insert functions in
* the symbol table before trying to load them as a plugin.
*/
$_plugin_func = 'insert_' . $_name;
if (function_exists($_plugin_func)) {
$_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false);
continue;
}
}
$_plugin_file = $smarty->_get_plugin_filepath($_type, $_name);
if (! $_found = ($_plugin_file != false)) {
$_message = "could not load plugin file '$_type.$_name.php'\n";
}
/*
* If plugin file is found, it -must- provide the properly named
* plugin function. In case it doesn't, simply output the error and
* do not fall back on any other method.
*/
if ($_found) {
include_once $_plugin_file;
$_plugin_func = 'smarty_' . $_type . '_' . $_name;
if (!function_exists($_plugin_func)) {
$smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
continue;
}
}
/*
* In case of insert plugins, their code may be loaded later via
* 'script' attribute.
*/
else if ($_type == 'insert' && $_delayed_loading) {
$_plugin_func = 'smarty_' . $_type . '_' . $_name;
$_found = true;
}
/*
* Plugin specific processing and error checking.
*/
if (!$_found) {
if ($_type == 'modifier') {
/*
* In case modifier falls back on using PHP functions
* directly, we only allow those specified in the security
* context.
*/
if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) {
$_message = "(secure mode) modifier '$_name' is not allowed";
} else {
if (!function_exists($_name)) {
$_message = "modifier '$_name' is not implemented";
} else {
$_plugin_func = $_name;
$_found = true;
}
}
} else if ($_type == 'function') {
/*
* This is a catch-all situation.
*/
$_message = "unknown tag - '$_name'";
}
}
if ($_found) {
$smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true);
} else {
// output error
$smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__);
}
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,74 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* load a resource plugin
*
* @param string $type
*/
// $type
function smarty_core_load_resource_plugin($params, &$smarty)
{
/*
* Resource plugins are not quite like the other ones, so they are
* handled differently. The first element of plugin info is the array of
* functions provided by the plugin, the second one indicates whether
* all of them exist or not.
*/
$_plugin = &$smarty->_plugins['resource'][$params['type']];
if (isset($_plugin)) {
if (!$_plugin[1] && count($_plugin[0])) {
$_plugin[1] = true;
foreach ($_plugin[0] as $_plugin_func) {
if (!is_callable($_plugin_func)) {
$_plugin[1] = false;
break;
}
}
}
if (!$_plugin[1]) {
$smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__);
}
return;
}
$_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']);
$_found = ($_plugin_file != false);
if ($_found) { /*
* If the plugin file is found, it -must- provide the properly named
* plugin functions.
*/
include_once($_plugin_file);
/*
* Locate functions that we require the plugin to provide.
*/
$_resource_ops = array('source', 'timestamp', 'secure', 'trusted');
$_resource_funcs = array();
foreach ($_resource_ops as $_op) {
$_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op;
if (!function_exists($_plugin_func)) {
$smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__);
return;
} else {
$_resource_funcs[] = $_plugin_func;
}
}
$smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true);
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Replace cached inserts with the actual results
*
* @param string $results
* @return string
*/
function smarty_core_process_cached_inserts($params, &$smarty)
{
preg_match_all('!'.$smarty->_smarty_md5.'{insert_cache (.*)}'.$smarty->_smarty_md5.'!Uis',
$params['results'], $match);
list($cached_inserts, $insert_args) = $match;
for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) {
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$debug_start_time = smarty_core_get_microtime($_params, $smarty);
}
$args = unserialize($insert_args[$i]);
$name = $args['name'];
if (isset($args['script'])) {
$_params = array('resource_name' => $smarty->_dequote($args['script']));
require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php');
if(!smarty_core_get_php_resource($_params, $smarty)) {
return false;
}
$resource_type = $_params['resource_type'];
$php_resource = $_params['php_resource'];
if ($resource_type == 'file') {
$smarty->_include($php_resource, true);
} else {
$smarty->_eval($php_resource);
}
}
$function_name = $smarty->_plugins['insert'][$name][0];
if (empty($args['assign'])) {
$replace = $function_name($args, $smarty);
} else {
$smarty->assign($args['assign'], $function_name($args, $smarty));
$replace = '';
}
$params['results'] = substr_replace($params['results'], $replace, strpos($params['results'], $cached_inserts[$i]), strlen($cached_inserts[$i]));
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$smarty->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name,
'depth' => $smarty->_inclusion_depth,
'exec_time' => smarty_core_get_microtime($_params, $smarty) - $debug_start_time);
}
}
return $params['results'];
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,37 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Replace nocache-tags by results of the corresponding non-cacheable
* functions and return it
*
* @param string $compiled_tpl
* @param string $cached_source
* @return string
*/
function smarty_core_process_compiled_include($params, &$smarty)
{
$_cache_including = $smarty->_cache_including;
$smarty->_cache_including = true;
$_return = $params['results'];
foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
$smarty->_include($_include_file_path, true);
}
foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
$_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s',
array(&$smarty, '_process_compiled_include_callback'),
$_return);
}
$smarty->_cache_including = $_cache_including;
return $_return;
}
?>

View File

@@ -0,0 +1,101 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* read a cache file, determine if it needs to be
* regenerated or not
*
* @param string $tpl_file
* @param string $cache_id
* @param string $compile_id
* @param string $results
* @return boolean
*/
// $tpl_file, $cache_id, $compile_id, &$results
function smarty_core_read_cache_file(&$params, &$smarty)
{
static $content_cache = array();
if ($smarty->force_compile) {
// force compile enabled, always regenerate
return false;
}
if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
return true;
}
if (!empty($smarty->cache_handler_func)) {
// use cache_handler function
call_user_func_array($smarty->cache_handler_func,
array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
} else {
// use local cache file
$_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
$params['results'] = $smarty->_read_file($_cache_file);
}
if (empty($params['results'])) {
// nothing to parse (error?), regenerate cache
return false;
}
$_contents = $params['results'];
$_info_start = strpos($_contents, "\n") + 1;
$_info_len = (int)substr($_contents, 0, $_info_start - 1);
$_cache_info = unserialize(substr($_contents, $_info_start, $_info_len));
$params['results'] = substr($_contents, $_info_start + $_info_len);
if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
// caching by expiration time
if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
// cache expired, regenerate
return false;
}
} else {
// caching by lifetime
if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
// cache expired, regenerate
return false;
}
}
if ($smarty->compile_check) {
$_params = array('get_source' => false, 'quiet'=>true);
foreach (array_keys($_cache_info['template']) as $_template_dep) {
$_params['resource_name'] = $_template_dep;
if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
// template file has changed, regenerate cache
return false;
}
}
if (isset($_cache_info['config'])) {
$_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
foreach (array_keys($_cache_info['config']) as $_config_dep) {
$_params['resource_name'] = $_config_dep;
if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
// config file has changed, regenerate cache
return false;
}
}
}
}
$content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
$smarty->_cache_info = $_cache_info;
return true;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* delete an automagically created file by name and id
*
* @param string $auto_base
* @param string $auto_source
* @param string $auto_id
* @param integer $exp_time
* @return boolean
*/
// $auto_base, $auto_source = null, $auto_id = null, $exp_time = null
function smarty_core_rm_auto($params, &$smarty)
{
if (!@is_dir($params['auto_base']))
return false;
if(!isset($params['auto_id']) && !isset($params['auto_source'])) {
$_params = array(
'dirname' => $params['auto_base'],
'level' => 0,
'exp_time' => $params['exp_time']
);
require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
$_res = smarty_core_rmdir($_params, $smarty);
} else {
$_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']);
if(isset($params['auto_source'])) {
if (isset($params['extensions'])) {
$_res = false;
foreach ((array)$params['extensions'] as $_extension)
$_res |= $smarty->_unlink($_tname.$_extension, $params['exp_time']);
} else {
$_res = $smarty->_unlink($_tname, $params['exp_time']);
}
} elseif ($smarty->use_sub_dirs) {
$_params = array(
'dirname' => $_tname,
'level' => 1,
'exp_time' => $params['exp_time']
);
require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
$_res = smarty_core_rmdir($_params, $smarty);
} else {
// remove matching file names
$_handle = opendir($params['auto_base']);
$_res = true;
while (false !== ($_filename = readdir($_handle))) {
if($_filename == '.' || $_filename == '..') {
continue;
} elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) {
$_res &= (bool)$smarty->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']);
}
}
}
}
return $_res;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,54 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* delete a dir recursively (level=0 -> keep root)
* WARNING: no tests, it will try to remove what you tell it!
*
* @param string $dirname
* @param integer $level
* @param integer $exp_time
* @return boolean
*/
// $dirname, $level = 1, $exp_time = null
function smarty_core_rmdir($params, &$smarty)
{
if(!isset($params['level'])) { $params['level'] = 1; }
if(!isset($params['exp_time'])) { $params['exp_time'] = null; }
if($_handle = @opendir($params['dirname'])) {
while (false !== ($_entry = readdir($_handle))) {
if ($_entry != '.' && $_entry != '..') {
if (@is_dir($params['dirname'] . DIRECTORY_SEPARATOR . $_entry)) {
$_params = array(
'dirname' => $params['dirname'] . DIRECTORY_SEPARATOR . $_entry,
'level' => $params['level'] + 1,
'exp_time' => $params['exp_time']
);
smarty_core_rmdir($_params, $smarty);
}
else {
$smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']);
}
}
}
closedir($_handle);
}
if ($params['level']) {
return @rmdir($params['dirname']);
}
return (bool)$_handle;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Handle insert tags
*
* @param array $args
* @return string
*/
function smarty_core_run_insert_handler($params, &$smarty)
{
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
if ($smarty->debugging) {
$_params = array();
$_debug_start_time = smarty_core_get_microtime($_params, $smarty);
}
if ($smarty->caching) {
$_arg_string = serialize($params['args']);
$_name = $params['args']['name'];
if (!isset($smarty->_cache_info['insert_tags'][$_name])) {
$smarty->_cache_info['insert_tags'][$_name] = array('insert',
$_name,
$smarty->_plugins['insert'][$_name][1],
$smarty->_plugins['insert'][$_name][2],
!empty($params['args']['script']) ? true : false);
}
return $smarty->_smarty_md5."{insert_cache $_arg_string}".$smarty->_smarty_md5;
} else {
if (isset($params['args']['script'])) {
$_params = array('resource_name' => $smarty->_dequote($params['args']['script']));
require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php');
if(!smarty_core_get_php_resource($_params, $smarty)) {
return false;
}
if ($_params['resource_type'] == 'file') {
$smarty->_include($_params['php_resource'], true);
} else {
$smarty->_eval($_params['php_resource']);
}
unset($params['args']['script']);
}
$_funcname = $smarty->_plugins['insert'][$params['args']['name']][0];
$_content = $_funcname($params['args'], $smarty);
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$smarty->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$params['args']['name'],
'depth' => $smarty->_inclusion_depth,
'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
}
if (!empty($params['args']["assign"])) {
$smarty->assign($params['args']["assign"], $_content);
} else {
return $_content;
}
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,50 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* called for included php files within templates
*
* @param string $smarty_file
* @param string $smarty_assign variable to assign the included template's
* output into
* @param boolean $smarty_once uses include_once if this is true
* @param array $smarty_include_vars associative array of vars from
* {include file="blah" var=$var}
*/
// $file, $assign, $once, $_smarty_include_vars
function smarty_core_smarty_include_php($params, &$smarty)
{
$_params = array('resource_name' => $params['smarty_file']);
require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php');
smarty_core_get_php_resource($_params, $smarty);
$_smarty_resource_type = $_params['resource_type'];
$_smarty_php_resource = $_params['php_resource'];
if (!empty($params['smarty_assign'])) {
ob_start();
if ($_smarty_resource_type == 'file') {
$smarty->_include($_smarty_php_resource, $params['smarty_once'], $params['smarty_include_vars']);
} else {
$smarty->_eval($_smarty_php_resource, $params['smarty_include_vars']);
}
$smarty->assign($params['smarty_assign'], ob_get_contents());
ob_end_clean();
} else {
if ($_smarty_resource_type == 'file') {
$smarty->_include($_smarty_php_resource, $params['smarty_once'], $params['smarty_include_vars']);
} else {
$smarty->_eval($_smarty_php_resource, $params['smarty_include_vars']);
}
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,96 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Prepend the cache information to the cache file
* and write it
*
* @param string $tpl_file
* @param string $cache_id
* @param string $compile_id
* @param string $results
* @return true|null
*/
// $tpl_file, $cache_id, $compile_id, $results
function smarty_core_write_cache_file($params, &$smarty)
{
// put timestamp in cache header
$smarty->_cache_info['timestamp'] = time();
if ($smarty->cache_lifetime > -1){
// expiration set
$smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
} else {
// cache will never expire
$smarty->_cache_info['expires'] = -1;
}
// collapse nocache.../nocache-tags
if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
// remove everything between every pair of outermost noache.../nocache-tags
// and replace it by a single nocache-tag
// this new nocache-tag will be replaced by dynamic contents in
// smarty_core_process_compiled_includes() on a cache-read
$match_count = count($match[0]);
$results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);
$level = 0;
$j = 0;
for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
if ($results[$i] == $match[0][$j]) {
// nocache tag
if ($match[1][$j]) { // closing tag
$level--;
unset($results[$i]);
} else { // opening tag
if ($level++ > 0) unset($results[$i]);
}
$j++;
} elseif ($level > 0) {
unset($results[$i]);
}
}
$params['results'] = implode('', $results);
}
$smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
// prepend the cache header info into cache file
$_cache_info = serialize($smarty->_cache_info);
$params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $params['results'];
if (!empty($smarty->cache_handler_func)) {
// use cache_handler function
call_user_func_array($smarty->cache_handler_func,
array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], $smarty->_cache_info['expires']));
} else {
// use local cache file
if(!@is_writable($smarty->cache_dir)) {
// cache_dir not writable, see if it exists
if(!@is_dir($smarty->cache_dir)) {
$smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
return false;
}
$smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR);
return false;
}
$_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
$_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
require_once(SMARTY_CORE_DIR . 'core.write_file.php');
smarty_core_write_file($_params, $smarty);
return true;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,91 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Extract non-cacheable parts out of compiled template and write it
*
* @param string $compile_path
* @param string $template_compiled
* @return boolean
*/
function smarty_core_write_compiled_include($params, &$smarty)
{
$_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
$_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
$params['compiled_content'], $_match_source, PREG_SET_ORDER);
// no nocache-parts found: done
if (count($_match_source)==0) return;
// convert the matched php-code to functions
$_include_compiled = "<?php /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
$_include_compiled .= " compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n";
$_compile_path = $params['include_file_path'];
$smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
$_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>";
$_include_compiled .= $params['plugins_code'];
$_include_compiled .= "<?php";
$this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';
for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
$_match =& $_match_source[$_i];
$source = $_match[4];
if ($this_varname == '_smarty') {
/* rename $this to $_smarty in the sourcecode */
$tokens = token_get_all('<?php ' . $_match[4]);
/* remove trailing <?php */
$open_tag = '';
while ($tokens) {
$token = array_shift($tokens);
if (is_array($token)) {
$open_tag .= $token[1];
} else {
$open_tag .= $token;
}
if ($open_tag == '<?php ') break;
}
for ($i=0, $count = count($tokens); $i < $count; $i++) {
if (is_array($tokens[$i])) {
if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
$tokens[$i] = '$' . $this_varname;
} else {
$tokens[$i] = $tokens[$i][1];
}
}
}
$source = implode('', $tokens);
}
/* add function to compiled include */
$_include_compiled .= "
function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname)
{
$source
}
";
}
$_include_compiled .= "\n\n?>\n";
$_params = array('filename' => $_compile_path,
'contents' => $_include_compiled, 'create_dirs' => true);
require_once(SMARTY_CORE_DIR . 'core.write_file.php');
smarty_core_write_file($_params, $smarty);
return true;
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* write the compiled resource
*
* @param string $compile_path
* @param string $compiled_content
* @return true
*/
function smarty_core_write_compiled_resource($params, &$smarty)
{
if(!@is_writable($smarty->compile_dir)) {
// compile_dir not writable, see if it exists
if(!@is_dir($smarty->compile_dir)) {
$smarty->trigger_error('the $compile_dir \'' . $smarty->compile_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
return false;
}
$smarty->trigger_error('unable to write to $compile_dir \'' . realpath($smarty->compile_dir) . '\'. Be sure $compile_dir is writable by the web server user.', E_USER_ERROR);
return false;
}
$_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
require_once(SMARTY_CORE_DIR . 'core.write_file.php');
smarty_core_write_file($_params, $smarty);
return true;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,54 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* write out a file to disk
*
* @param string $filename
* @param string $contents
* @param boolean $create_dirs
* @return boolean
*/
function smarty_core_write_file($params, &$smarty)
{
$_dirname = dirname($params['filename']);
if ($params['create_dirs']) {
$_params = array('dir' => $_dirname);
require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
smarty_core_create_dir_structure($_params, $smarty);
}
// write to tmp file, then rename it to avoid file locking race condition
$_tmp_file = tempnam($_dirname, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$smarty->trigger_error("problem writing temporary file '$_tmp_file'");
return false;
}
}
fwrite($fd, $params['contents']);
fclose($fd);
if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
// On platforms and filesystems that cannot overwrite with rename()
// delete the file before renaming it -- because windows always suffers
// this, it is short-circuited to avoid the initial rename() attempt
@unlink($params['filename']);
@rename($_tmp_file, $params['filename']);
}
@chmod($params['filename'], $smarty->_file_perms);
return true;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,103 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {textformat}{/textformat} block plugin
*
* Type: block function<br>
* Name: textformat<br>
* Purpose: format text a certain way with preset styles
* or custom wrap/indent settings<br>
* @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
* @param array
* <pre>
* Params: style: string (email)
* indent: integer (0)
* wrap: integer (80)
* wrap_char string ("\n")
* indent_char: string (" ")
* wrap_boundary: boolean (true)
* </pre>
* @author Monte Ohrt <monte at ohrt dot com>
* @param string contents of the block
* @param Smarty clever simulation of a method
* @return string string $content re-formatted
*/
function smarty_block_textformat($params, $content, &$smarty)
{
if (is_null($content)) {
return;
}
$style = null;
$indent = 0;
$indent_first = 0;
$indent_char = ' ';
$wrap = 80;
$wrap_char = "\n";
$wrap_cut = false;
$assign = null;
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'style':
case 'indent_char':
case 'wrap_char':
case 'assign':
$$_key = (string)$_val;
break;
case 'indent':
case 'indent_first':
case 'wrap':
$$_key = (int)$_val;
break;
case 'wrap_cut':
$$_key = (bool)$_val;
break;
default:
$smarty->trigger_error("textformat: unknown attribute '$_key'");
}
}
if ($style == 'email') {
$wrap = 72;
}
// split into paragraphs
$_paragraphs = preg_split('![\r\n][\r\n]!',$content);
$_output = '';
for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
if ($_paragraphs[$_x] == '') {
continue;
}
// convert mult. spaces & special chars to single space
$_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
// indent first line
if($indent_first > 0) {
$_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
}
// wordwrap sentences
$_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines
if($indent > 0) {
$_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
}
}
$_output = implode($wrap_char . $wrap_char, $_paragraphs);
return $assign ? $smarty->assign($assign, $_output) : $_output;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {assign} compiler function plugin
*
* Type: compiler function<br>
* Name: assign<br>
* Purpose: assign a value to a template variable
* @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> (initial author)
* @author messju mohr <messju at lammfellpuschen dot de> (conversion to compiler function)
* @param string containing var-attribute and value-attribute
* @param Smarty_Compiler
*/
function smarty_compiler_assign($tag_attrs, &$compiler)
{
$_params = $compiler->_parse_attrs($tag_attrs);
if (!isset($_params['var'])) {
$compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING);
return;
}
if (!isset($_params['value'])) {
$compiler->_syntax_error("assign: missing 'value' parameter", E_USER_WARNING);
return;
}
return "\$this->assign({$_params['var']}, {$_params['value']});";
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {assign_debug_info} function plugin
*
* Type: function<br>
* Name: assign_debug_info<br>
* Purpose: assign debug info to the template<br>
* @author Monte Ohrt <monte at ohrt dot com>
* @param array unused in this plugin, this plugin uses {@link Smarty::$_config},
* {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info}
* @param Smarty
*/
function smarty_function_assign_debug_info($params, &$smarty)
{
$assigned_vars = $smarty->_tpl_vars;
ksort($assigned_vars);
if (@is_array($smarty->_config[0])) {
$config_vars = $smarty->_config[0];
ksort($config_vars);
$smarty->assign("_debug_config_keys", array_keys($config_vars));
$smarty->assign("_debug_config_vals", array_values($config_vars));
}
$included_templates = $smarty->_smarty_debug_info;
$smarty->assign("_debug_keys", array_keys($assigned_vars));
$smarty->assign("_debug_vals", array_values($assigned_vars));
$smarty->assign("_debug_tpls", $included_templates);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,142 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {config_load} function plugin
*
* Type: function<br>
* Name: config_load<br>
* Purpose: load config file vars
* @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author messju mohr <messju at lammfellpuschen dot de> (added use of resources)
* @param array Format:
* <pre>
* array('file' => required config file name,
* 'section' => optional config file section to load
* 'scope' => local/parent/global
* 'global' => overrides scope, setting to parent if true)
* </pre>
* @param Smarty
*/
function smarty_function_config_load($params, &$smarty)
{
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$_debug_start_time = smarty_core_get_microtime($_params, $smarty);
}
$_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
$_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
$_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
$_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
if (!isset($_file) || strlen($_file) == 0) {
$smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
}
if (isset($_scope)) {
if ($_scope != 'local' &&
$_scope != 'parent' &&
$_scope != 'global') {
$smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
}
} else {
if ($_global) {
$_scope = 'parent';
} else {
$_scope = 'local';
}
}
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
'get_source' => false);
$smarty->_parse_resource_name($_params);
$_file_path = $_params['resource_type'] . ':' . $_params['resource_name'];
if (isset($_section))
$_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
else
$_compile_file = $smarty->_get_compile_path($_file_path);
if($smarty->force_compile || !file_exists($_compile_file)) {
$_compile = true;
} elseif ($smarty->compile_check) {
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
'get_source' => false);
$_compile = $smarty->_fetch_resource_info($_params) &&
$_params['resource_timestamp'] > filemtime($_compile_file);
} else {
$_compile = false;
}
if($_compile) {
// compile config file
if(!is_object($smarty->_conf_obj)) {
require_once SMARTY_DIR . $smarty->config_class . '.class.php';
$smarty->_conf_obj = new $smarty->config_class();
$smarty->_conf_obj->overwrite = $smarty->config_overwrite;
$smarty->_conf_obj->booleanize = $smarty->config_booleanize;
$smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
$smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
}
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
$_params['get_source'] = true);
if (!$smarty->_fetch_resource_info($_params)) {
return;
}
$smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
$_config_vars = array_merge($smarty->_conf_obj->get($_file),
$smarty->_conf_obj->get($_file, $_section));
if(function_exists('var_export')) {
$_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
} else {
$_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
}
$_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp']));
require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
smarty_core_write_compiled_resource($_params, $smarty);
} else {
include($_compile_file);
}
if ($smarty->caching) {
$smarty->_cache_info['config'][$_file] = true;
}
$smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);
$smarty->_config[0]['files'][$_file] = true;
if ($_scope == 'parent') {
$smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);
$smarty->_config[1]['files'][$_file] = true;
} else if ($_scope == 'global') {
for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {
$smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);
$smarty->_config[$i]['files'][$_file] = true;
}
}
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$smarty->_smarty_debug_info[] = array('type' => 'config',
'filename' => $_file.' ['.$_section.'] '.$_scope,
'depth' => $smarty->_inclusion_depth,
'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {counter} function plugin
*
* Type: function<br>
* Name: counter<br>
* Purpose: print out a counter value
* @author Monte Ohrt <monte at ohrt dot com>
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
* @param array parameters
* @param Smarty
* @return string|null
*/
function smarty_function_counter($params, &$smarty)
{
static $counters = array();
$name = (isset($params['name'])) ? $params['name'] : 'default';
if (!isset($counters[$name])) {
$counters[$name] = array(
'start'=>1,
'skip'=>1,
'direction'=>'up',
'count'=>1
);
}
$counter =& $counters[$name];
if (isset($params['start'])) {
$counter['start'] = $counter['count'] = (int)$params['start'];
}
if (!empty($params['assign'])) {
$counter['assign'] = $params['assign'];
}
if (isset($counter['assign'])) {
$smarty->assign($counter['assign'], $counter['count']);
}
if (isset($params['print'])) {
$print = (bool)$params['print'];
} else {
$print = empty($counter['assign']);
}
if ($print) {
$retval = $counter['count'];
} else {
$retval = null;
}
if (isset($params['skip'])) {
$counter['skip'] = $params['skip'];
}
if (isset($params['direction'])) {
$counter['direction'] = $params['direction'];
}
if ($counter['direction'] == "down")
$counter['count'] -= $counter['skip'];
else
$counter['count'] += $counter['skip'];
return $retval;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {cycle} function plugin
*
* Type: function<br>
* Name: cycle<br>
* Date: May 3, 2002<br>
* Purpose: cycle through given values<br>
* Input:
* - name = name of cycle (optional)
* - values = comma separated list of values to cycle,
* or an array of values to cycle
* (this can be left out for subsequent calls)
* - reset = boolean - resets given var to true
* - print = boolean - print var or not. default is true
* - advance = boolean - whether or not to advance the cycle
* - delimiter = the value delimiter, default is ","
* - assign = boolean, assigns to template var instead of
* printed.
*
* Examples:<br>
* <pre>
* {cycle values="#eeeeee,#d0d0d0d"}
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
* </pre>
* @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
* @param array
* @param Smarty
* @return string|null
*/
function smarty_function_cycle($params, &$smarty)
{
static $cycle_vars;
$name = (empty($params['name'])) ? 'default' : $params['name'];
$print = (isset($params['print'])) ? (bool)$params['print'] : true;
$advance = (isset($params['advance'])) ? (bool)$params['advance'] : true;
$reset = (isset($params['reset'])) ? (bool)$params['reset'] : false;
if (!in_array('values', array_keys($params))) {
if(!isset($cycle_vars[$name]['values'])) {
$smarty->trigger_error("cycle: missing 'values' parameter");
return;
}
} else {
if(isset($cycle_vars[$name]['values'])
&& $cycle_vars[$name]['values'] != $params['values'] ) {
$cycle_vars[$name]['index'] = 0;
}
$cycle_vars[$name]['values'] = $params['values'];
}
$cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ',';
if(is_array($cycle_vars[$name]['values'])) {
$cycle_array = $cycle_vars[$name]['values'];
} else {
$cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
}
if(!isset($cycle_vars[$name]['index']) || $reset ) {
$cycle_vars[$name]['index'] = 0;
}
if (isset($params['assign'])) {
$print = false;
$smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
}
if($print) {
$retval = $cycle_array[$cycle_vars[$name]['index']];
} else {
$retval = null;
}
if($advance) {
if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) {
$cycle_vars[$name]['index'] = 0;
} else {
$cycle_vars[$name]['index']++;
}
}
return $retval;
}
/* vim: set expandtab: */
?>

Some files were not shown because too many files have changed in this diff Show More