Source for file Savant.php
Documentation is available at Savant.php
* 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 program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
class HTML_Template_Flexy_Plugin_Savant {
* Output an HTML <a href="">...</a> tag.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @param string $href The URL for the resulting <a href="">...</a> tag.
* @param string $text The text surrounded by the <a>...</a> tag set.
* @param string $extra Any "extra" HTML code to place within the <a>
function ahref ($href, $text, $extra = null )
$output = '<a href="' . $href . '"';
$output .= '>' . $text . '</a>';
* Output a single checkbox <input> element.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $name The HTML "name=" value for the checkbox.
* @param mixed $value The value of the checkbox if checked.
* @param mixed $selected Check $value against this; if they match,
* mark the checkbox as checked.
* @param string $set_unchecked If null, this will add no HTML to the
* output. However, if set to any non-null value, the value will be
* added as a hidden element before the checkbox so that if the
* checkbox is unchecked, the hidden value will be returned instead
* @param string $extra Any "extra" HTML code to place within the
// this sets the unchecked value of the checkbox.
$html .= "<input type=\"hidden\" ";
$html .= " name=\"$name\" ";
$html .= " value=\"$set_unchecked\" />\n";
$html .= "<input type=\"checkbox\" ";
$html .= " name=\"$name\" ";
$html .= " value=\"$value\"";
if ($value == $selected) {
$html .= " checked=\"checked\"";
* Output a set of checkbox <input>s.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $name The HTML "name=" value of all the checkbox
* <input>s. The name will get [] appended to it to make it an array
* when returned to the server.
* @param array $options An array of key-value pairs where the key is
* the checkbox value and the value is the checkbox label.
* @param string $set_unchecked If null, this will add no HTML to the
* output. However, if set to any non-null value, the value will be
* added as a hidden element before every checkbox so that if the
* checkbox is unchecked, the hidden value will be returned instead
* @param string $sep The HTML text to place between every checkbox
* @param string $extra Any "extra" HTML code to place within the
// force $selected to be an array. this allows multi-checks to
// have multiple checked boxes.
// the text to be returned
// an iteration counter. we use this to track which array
// elements are checked and which are unchecked.
foreach ($options as $value => $label) {
// this sets the unchecked value of the checkbox.
$html .= "<input type=\"hidden\" ";
$html .= " name=\"{$name}[$i]\" ";
$html .= " value=\"$set_unchecked\" />\n";
$html .= "<input type=\"checkbox\" ";
$html .= " name=\"{$name}[$i]\" ";
$html .= " value=\"$value\"";
$html .= " checked=\"checked\"";
$html .= " />$label$sep";
* Cycle through a series of values based on an iteration number,
* with optional group repetition.
* For example, if you have three values in a cycle (a, b, c) the iteration
* returns look like this:
* If you repeat each cycle value (a,b,c) 2 times on the iterations,
* the returns look like this:
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param int $iteration The iteration number for the cycle.
* @param array $values The values to cycle through.
* @param int $repeat The number of times to repeat a cycle value.
function cycle ($iteration, $values = null , $repeat = 1 )
// prevent divide-by-zero errors
return $values[($iteration / $repeat) % count($values)];
* Output a formatted date using strftime() conventions.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $datestring Any date-time string suitable for
* @param string $format The strftime() formatting string.
function dateformat ($datestring, $format = false )
$format = isset ($this->flexy->options ['plugin.dateformat']) ?
$this->flexy->options ['plugin.dateformat'] : '%d %b %Y';
if (trim($datestring) == '') {
return $date->format ($format);
* Output a formatted number using number_format
* @param string $datestring Any date-time string suitable for
* @param string $format The strftime() formatting string.
function numberformat ($number, $dec=false ,$point=false ,$thousands=false )
// numberformat int decimals, string dec_point, string thousands_sep
$dec = ($dec !== false ) ? $dec : (
isset ($this->flexy->options ['plugin.numberformat.decimals']) ?
$this->flexy->options ['plugin.numberformat.decimals'] : 2
$point = ($point !== false ) ? $point : (
isset ($this->flexy->options ['plugin.numberformat.point']) ?
$this->flexy->options ['plugin.numberformat.point'] : '.');
$thousands = ($thousands !== false ) ? $thousands : (
isset ($this->flexy->options ['plugin.numberformat.thousands']) ?
$this->flexy->options ['plugin.numberformat.thousands'] : ',');
* Output an <image ... /> tag.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $src The image source as a relative or absolute HREF.
* @param string $link Providing a link will make the image clickable,
* leading to the URL indicated by $link; defaults to null.
* @param string $alt Alternative descriptive text for the image;
* defaults to the filename of the image.
* @param int $border The border width for the image; defaults to zero.
* @param int $width The displayed image width in pixels; defaults to
* the width of the image.
* @param int $height The displayed image height in pixels; defaults to
* the height of the image.
// get the width and height of the image
// the image is not on the local filesystem
// we need to set a base root path so we can find images on the
$root = isset ($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'])
? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] . '/'
$width = (is_null($width)) ? $info[0 ] : $width;
$height = (is_null($height)) ? $info[1 ] : $height;
return '<img src="' . $src . '"' .
* Output a single <input> element.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $type The HTML "type=" value (e.g., 'text',
* @param string $name The HTML "name=" value.
* @param mixed $value The initial value of the input element.
* @param string $extra Any "extra" HTML code to place within the
function input ($type, $name, $value = '', $extra = '')
$output = " <input type=\"$type\" name=\"$name\" ";
$output .= " value=\"$value\" $extra />";
* Output a <script></script> link to a JavaScript file.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $href The HREF leading to the JavaScript source
function javascript ($href)
return '<script language="javascript" type="text/javascript" src="' .
* Output a value using echo after processing with optional modifier
* Allows you to pass a space-separated list of value-manipulation
* functions so that the value is "massaged" before output. For
* example, if you want to strip slashes, force to lower case, and
* convert to HTML entities (as for an input text box), you might do
* $this->modify($value, 'stripslashes strtolower htmlentities');
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $value The value to be printed.
* @param string $functions A space-separated list of
* single-parameter functions to be applied to the $value before
function modify ($value, $functions = null )
// is there a space-delimited function list?
// yes. split into an array of the
// functions to be called.
// loop through the function list and
// apply to the output in sequence.
foreach ($list as $func) {
if (!in_array($func, array ('htmlspecialchars','nl2br','urlencode'))) {
* Output a series of HTML <option>s based on an associative array
* where the key is the option value and the value is the option
* label. You can pass a "selected" value as well to tell the
* function which option value(s) should be marked as seleted.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param array $options An associative array of key-value pairs; the
* key is the option value, the value is the option lable.
* @param mixed $selected A string or array that matches one or more
* option values, to tell the function what options should be marked
* as selected. Defaults to an empty array.
function options ( $options, $selected = array (), $extra = null )
// force $selected to be an array. this allows multi-selects to
// have multiple selected options.
// loop through the options array
foreach ($options as $value => $label) {
$html .= '<option value="' . $value . '"';
$html .= ' label="' . $label . '"';
$html .= ' selected="selected"';
$html .= " >$label</option>\n";
* Output a set of radio <input>s with the same name.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $name The HTML "name=" value of all the radio <input>s.
* @param array $options An array of key-value pairs where the key is the
* radio button value and the value is the radio button label.
* @param string $checked A comparison string; if any of the $option
* element values and $checked are the same, that radio button will
* be marked as "checked" (otherwise not).
* @param string $extra Any "extra" HTML code to place within the
* @param string $sep The HTML text to place between every radio
// this sets the unchecked value of the
$html .= "<input type=\"hidden\" ";
$html .= " name=\"$name\" ";
$html .= " value=\"$set_unchecked\" />\n";
foreach ($options as $value => $label) {
$html .= "<input type=\"radio\" ";
$html .= " name=\"$name\" ";
$html .= " value=\"$value\"";
if ($value == $checked) {
$html .= " checked=\"checked\"";
$html .= " $extra />$label$sep";
* Output a <link ... /> to a CSS stylesheet.
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $href The HREF leading to the stylesheet file.
function stylesheet ($href)
return '<link rel="stylesheet" type="text/css" href="' .
* Output a single <textarea> element.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @author Paul M. Jones <pmjones@ciaweb.net>
* @version $Id: Savant.php 186366 2005-05-14 03:40:14Z alan_k $
* @param string $name The HTML "name=" value.
* @param string $text The initial value of the textarea element.
* @param int $tall How many rows tall should the area be?
* @param mixed $wide The many columns wide should the area be?
* @param string $extra Any "extra" HTML code to place within the
function textarea ($name, $text, $tall = 24 , $wide = 80 , $extra = '')
$output = " <textarea name=\"$name\" rows=\"$tall\" ";
$output .= " cols=\"$wide\" $extra>$text</textarea>";
Documentation generated on Mon, 11 Mar 2019 15:59:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|