📄 savant.php
字号:
<?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> * * @package Savant * * * @access public * * @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> * opening tag. * * @return string */ function ahref($href, $text, $extra = null) { $output = '<a href="' . $href . '"'; if (! is_null($extra)) { $output .= ' ' . $extra; } $output .= '>' . $text . '</a>'; return $output; } /** * * Output a single checkbox <input> element. * @author Paul M. Jones <pmjones@ciaweb.net> * * @package Savant * * @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $ * * @access public * * @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 * of the checked value. * * @param string $extra Any "extra" HTML code to place within the * checkbox element. * * @return string * */ function checkbox( $name, $value, $selected = null, $set_unchecked = null, $extra = null) { $html = ''; if (! is_null($set_unchecked)) { // 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\""; } $html .= " $extra />"; return $html; } /** * * Output a set of checkbox <input>s. * * * @author Paul M. Jones <pmjones@ciaweb.net> * * @package Savant * * @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $ * * @access public * * @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 * of the checked value. * * @param string $sep The HTML text to place between every checkbox * in the set. * * @param string $extra Any "extra" HTML code to place within the * checkbox element. * * @return string * */ function checkboxes( $name, $options, $selected = array(), $set_unchecked = null, $sep = "<br />\n", $extra = null) { // force $selected to be an array. this allows multi-checks to // have multiple checked boxes. settype($selected, 'array'); // the text to be returned $html = ''; if (is_array($options)) { // an iteration counter. we use this to track which array // elements are checked and which are unchecked. $i = 0; foreach ($options as $value => $label) { if (! is_null($set_unchecked)) { // 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\""; if (in_array($value, $selected)) { $html .= " checked=\"checked\""; } if (! is_null($extra)) { $html .= " $extra"; } $html .= " />$label$sep"; $i++; } } return $html; } /** * * 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: * * 0 => a * 1 => b * 2 => c * 3 => a * 4 => b * 5 => c * * If you repeat each cycle value (a,b,c) 2 times on the iterations, * the returns look like this: * * 0 => a * 1 => a * 2 => b * 3 => b * 4 => c * 5 => c * * * @author Paul M. Jones <pmjones@ciaweb.net> * * @package Savant * * @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $ * * @access public * * @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. * * @return string * */ function cycle($iteration, $values = null, $repeat = 1) { settype($values, 'array'); // prevent divide-by-zero errors if ($repeat == 0) { $repeat = 1; } return $values[($iteration / $repeat) % count($values)]; } /** * * Output a formatted date using strftime() conventions. * * * @author Paul M. Jones <pmjones@ciaweb.net> * * @package Savant * * @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $ * * @access public * * @param string $datestring Any date-time string suitable for * strtotime(). * * @param string $format The strftime() formatting string. * * @return string * */ function dateformat($datestring, $format = false) { if ($format === false) { $format = isset($this->flexy->options['plugin.dateformat']) ? $this->flexy->options['plugin.dateformat'] : '%d %b %Y'; } if (trim($datestring) == '') { return ''; } $date = strtotime($datestring); if ($date > 1) { return strftime($format, $date); } require_once 'Date.php'; $date = new Date($date); return $date->format($format); } /** * * Output a formatted number using number_format * * * * @param string $datestring Any date-time string suitable for * strtotime(). * * @param string $format The strftime() formatting string. * * @return string * */ function numberformat($number, $dec=false,$point=false,$thousands=false) { if (!strlen(trim($number))) { return; } // 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'] : ','); return number_format($number,$dec,$point,$thousands); } /** * * Output an <image ... /> tag. * * * @author Paul M. Jones <pmjones@ciaweb.net> * * @package Savant * * @version $Id: Savant.php,v 1.7 2005/05/14 03:39:11 alan_k Exp $ * * @access public * * @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. * */ function image( $src, $alt = null, $border = 0, $width = null, $height = null) { $size = ''; // build the alt tag if (is_null($alt)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -