Update v1.0.6
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class AngleField extends IntField
|
||||
{
|
||||
function __construct($name, $default, $hint = 'In degrees clockwise, negative values accepted')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->value)
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
|
||||
echo '<input type="hidden" name="' . $name . '" id="' . $id . '_val" value="' . ($this->value ? '1' : '') . '" />';
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '_cb" id="' . $id . '" value="1" onclick="document.getElementById(\'' . $id . '_val\').value = Number(this.checked);" />';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxSetField extends Field
|
||||
{
|
||||
public $options;
|
||||
public $request;
|
||||
|
||||
function __construct($name, $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = array();
|
||||
if (is_array($request->get($this->name)))
|
||||
foreach ($request->get($this->name) as $val)
|
||||
if (in_array($val, $this->options))
|
||||
$this->value[] = $val;
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$request = $this->request;
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if (is_array($request->get($this->name)) && in_array($option, $request->get($this->name)))
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
|
||||
$name = $this->name . '[]';
|
||||
$id = $this->name . '_' . $option;
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '" id="' . $id . '" value="' . $option . '" />';
|
||||
echo '<label for="' . $id . '">' . $option . '</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
$v = '';
|
||||
foreach ($this->value as $value)
|
||||
$v .= $this->name . '[]=' . $value . '&';
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class ColorField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'RRGGBB hex, leave blank for transparent background')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$c = $request->getColor($this->name, $this->default);
|
||||
if ($c === '')
|
||||
$this->value = null;
|
||||
else
|
||||
$this->value = str_pad(dechex(hexdec($c)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CoordinateField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Smart coordinate')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getCoordinate($this->name, $this->default);
|
||||
if ($this->value > 1000)
|
||||
$this->value = 1000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
public $name;
|
||||
public $format = null;
|
||||
public $fields = array();
|
||||
public $order = 1000;
|
||||
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
}
|
||||
|
||||
static function create($name)
|
||||
{
|
||||
$file = DEMO_PATH . '/demos/' . $name . '.php';
|
||||
if (!file_exists($file))
|
||||
throw new Exception("Invalid demo: {$name}");
|
||||
include $file;
|
||||
$className = 'Demo_' . $name;
|
||||
$demo = new $className($name);
|
||||
$demo->request = Request::getInstance();
|
||||
$demo->init();
|
||||
foreach ($demo->fields as $field)
|
||||
{
|
||||
$field->request = Request::getInstance();
|
||||
$field->init(Request::getInstance());
|
||||
}
|
||||
return $demo;
|
||||
}
|
||||
|
||||
function getFormat()
|
||||
{
|
||||
return 'as input';
|
||||
}
|
||||
|
||||
function addField($field)
|
||||
{
|
||||
$this->fields[$field->name] = $field;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
}
|
||||
|
||||
function fval($name)
|
||||
{
|
||||
return $this->fields[$name]->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
public $name;
|
||||
public $default;
|
||||
public $value;
|
||||
public $request;
|
||||
public $hint;
|
||||
|
||||
function __construct($name, $default = null, $hint = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($hint == '')
|
||||
$hint = $name;
|
||||
|
||||
$this->hint = $hint;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default);
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$id = htmlentities($this->name);
|
||||
echo '<label style="background-color: #c0c0c0; padding: 5px; margin: 2px;" for="imgparam_' . $id . '" title="' . htmlentities($this->hint) . '">';
|
||||
echo $this->name . ': ';
|
||||
$this->renderBody($id, 'imgparam_' . $id);
|
||||
echo '</label> ';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<input id="' . $id . '" type="text" size="15" name="' . $name . '" value="' . $this->getRenderValue() . '" />';
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getUrlValue()
|
||||
{
|
||||
return urlencode($this->name) . '=' . urlencode($this->value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FileSelectField extends Field
|
||||
{
|
||||
public $request;
|
||||
public $files = array();
|
||||
public $options;
|
||||
|
||||
function __construct($name, $path, $options = array())
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->path = $path;
|
||||
$this->options = $options;
|
||||
|
||||
if (!isset($options['show']))
|
||||
$this->options['show'] = true;
|
||||
|
||||
if (!isset($options['pattern']))
|
||||
$this->options['pattern'] = '/(.*)/';
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = null;
|
||||
$di = new DirectoryIterator(DEMO_PATH . $this->path);
|
||||
foreach ($di as $file)
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename()))
|
||||
{
|
||||
$this->files[] = $file->getFilename();
|
||||
if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename())
|
||||
$this->value = $this->options['default'];
|
||||
|
||||
if ($this->request->get($this->name) == $file->getFilename())
|
||||
$this->value = $file->getFilename();
|
||||
}
|
||||
|
||||
sort($this->files);
|
||||
|
||||
if (!$this->value && count($this->files) > 0)
|
||||
$this->value = $this->files[0];
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->options['show'])
|
||||
{
|
||||
$onch = "document.getElementById('sel_{$id}').src = '{$this->path}/' + this.options[this.selectedIndex].value;";
|
||||
}
|
||||
else
|
||||
$onch = '';
|
||||
|
||||
echo '<select id="' . $id . '" name="' . $name . '" onchange="' . $onch . '">';
|
||||
$selected_file = null;
|
||||
foreach ($this->files as $file)
|
||||
{
|
||||
if ($this->value == $file)
|
||||
{
|
||||
$sel = 'selected="selected"';
|
||||
$selected_file = $file;
|
||||
}
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $file . '">' . $file . '</option>' . PHP_EOL;
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
if ($this->options['show'] && $selected_file)
|
||||
{
|
||||
echo '<div style="display: inline; min-width: 50px; min-height: 50px">';
|
||||
echo '<img style="position: absolute" id="sel_' . $id . '" width="50" src="' . $this->path . '/' . $selected_file . '" /> ';
|
||||
echo " ";
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
return $this->name . '=' . $this->value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FloatField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Float')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getFloat($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FormatSelectField extends SelectField
|
||||
{
|
||||
function __construct($name)
|
||||
{
|
||||
parent::__construct($name, array('preset for demo', 'as input', 'png8', 'png24', 'jpeg', 'gif', 'bmp'), null, 'Image format');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class IntField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Integer')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getInt($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage 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.
|
||||
|
||||
WideImage 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 WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $vars = array();
|
||||
|
||||
protected static $instance;
|
||||
static function getInstance()
|
||||
{
|
||||
if (self::$instance === null)
|
||||
self::$instance = new Request;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->vars = $_GET;
|
||||
|
||||
/*
|
||||
// have to rely on parsing QUERY_STRING, thanks to PHP
|
||||
// http://bugs.php.net/bug.php?id=39078
|
||||
// http://bugs.php.net/bug.php?id=45149
|
||||
$all_vars = explode('&', $_SERVER['QUERY_STRING']);
|
||||
foreach ($all_vars as $keyval)
|
||||
{
|
||||
if (strlen($keyval) == 0)
|
||||
continue;
|
||||
|
||||
if (strpos($keyval, '=') === false)
|
||||
{
|
||||
$key = $keyval;
|
||||
$value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($key, $value) = explode('=', $keyval);
|
||||
#$value = str_replace('%2B', '[[PLUS]]', $value);
|
||||
$value = urldecode($value);
|
||||
#$value = str_replace('[[PLUS]]', '+', $value);
|
||||
}
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->vars[$key]))
|
||||
return $this->vars[$key];
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
|
||||
function getInt($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return intval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getFloat($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return floatval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getCoordinate($key, $default = 0)
|
||||
{
|
||||
$v = self::get($key);
|
||||
if (strlen($v) > 0 && WideImage_Coordinate::parse($v) !== null)
|
||||
return self::get($key);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getOption($key, $valid = array(), $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && in_array($value, $valid))
|
||||
return strval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getColor($key, $default = '000000')
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (substr($value, 0, 1) == '#')
|
||||
$value = substr($value, 1);
|
||||
|
||||
if ($value === '' || preg_match('~^[0-9a-f]{1,6}$~i', $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getRegex($key, $regex, $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && preg_match($regex, $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class SelectField extends Field
|
||||
{
|
||||
public $options;
|
||||
|
||||
function __construct($name, $options, $default = null, $hint = null)
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
if ($default === null)
|
||||
$this->default = $options[0];
|
||||
else
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $this->default;
|
||||
$v = str_replace('+', ' ', $request->get($this->name));
|
||||
if (in_array($v, $this->options))
|
||||
$this->value = $v;
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<select id="' . $id . '" name="' . $name . '">';
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if ($this->value == $option)
|
||||
$sel = 'selected="selected"';
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $option . '">' . $option . '</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
define('DEMO_PATH', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
require_once DEMO_PATH . 'helpers/Request.php';
|
||||
require_once DEMO_PATH . 'helpers/Demo.php';
|
||||
require_once DEMO_PATH . 'helpers/Field.php';
|
||||
require_once DEMO_PATH . 'helpers/CheckboxField.php';
|
||||
require_once DEMO_PATH . 'helpers/FileSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/CoordinateField.php';
|
||||
require_once DEMO_PATH . 'helpers/IntField.php';
|
||||
require_once DEMO_PATH . 'helpers/FloatField.php';
|
||||
require_once DEMO_PATH . 'helpers/AngleField.php';
|
||||
require_once DEMO_PATH . 'helpers/SelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/FormatSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/ColorField.php';
|
||||
|
||||
Reference in New Issue
Block a user