本文整理汇总了PHP中unknown::trigger_error方法的典型用法代码示例。如果您正苦于以下问题:PHP unknown::trigger_error方法的具体用法?PHP unknown::trigger_error怎么用?PHP unknown::trigger_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unknown
的用法示例。
在下文中一共展示了unknown::trigger_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_assign
/**
* Smarty {assign} function plugin
*
* Type: 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)
* @param array Format: array('var' => variable name, 'value' => value to assign)
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
*/
function smarty_function_assign($params, &$smarty)
{
extract($params);
if (empty($var)) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (!in_array('value', array_keys($params))) {
$smarty->trigger_error("assign: missing 'value' parameter");
return;
}
$smarty->assign($var, $value);
}
示例2: smarty_function_math
/**
* Smarty {math} function plugin
*
* Type: function<br>
* Name: math<br>
* Purpose: handle math computations in template<br>
*
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @param array
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_math($params, &$smarty)
{
// be sure equation parameter is present
if (empty($params['equation'])) {
$smarty->trigger_error("math: missing equation parameter");
return;
}
$equation = $params['equation'];
// make sure parenthesis are balanced
if (substr_count($equation, "(") != substr_count($equation, ")")) {
$smarty->trigger_error("math: unbalanced parenthesis");
return;
}
// match all vars in equation, make sure all are passed
preg_match_all("!\\!(0x)([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
$allowed_funcs = array('int', 'abs', 'ceil', 'cos', 'exp', 'floor', 'log', 'log10', 'max', 'min', 'pi', 'pow', 'rand', 'round', 'sin', 'sqrt', 'srand', 'tan');
foreach ($match[2] as $curr_var) {
if (!in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
$smarty->trigger_error("math: parameter {$curr_var} not passed as argument");
return;
}
}
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
$smarty->trigger_error("math: parameter {$key} is empty");
return;
}
if (!is_numeric($val)) {
$smarty->trigger_error("math: parameter {$key}: is not numeric");
return;
}
$equation = preg_replace("/\\b{$key}\\b/", $val, $equation);
}
}
eval("\$smarty_math_result = " . $equation . ";");
if (empty($params['format'])) {
if (empty($params['assign'])) {
return $smarty_math_result;
} else {
$smarty->assign($params['assign'], $smarty_math_result);
}
} else {
if (empty($params['assign'])) {
printf($params['format'], $smarty_math_result);
} else {
$smarty->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
}
}
}
示例3: smarty_core_write_compiled_resource
/**
* write the compiled resource
*
* @param unknown $params
* @param unknown $smarty (reference)
* @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_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
smarty_core_write_file($_params, $smarty);
touch($params['compile_path'], $params['resource_timestamp']);
return true;
}
示例4: smarty_function_cycle
/**
* 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@ispi.net>
* @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
* @param unknown $params
* @param unknown $smarty (reference)
* @return string|null
*/
function smarty_function_cycle($params, &$smarty)
{
static $cycle_vars;
extract($params);
if (empty($name)) {
$name = 'default';
}
if (!isset($print)) {
$print = true;
}
if (!isset($advance)) {
$advance = true;
}
if (!isset($reset)) {
$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'] != $values) {
$cycle_vars[$name]['index'] = 0;
}
$cycle_vars[$name]['values'] = $values;
}
if (isset($delimiter)) {
$cycle_vars[$name]['delimiter'] = $delimiter;
} elseif (!isset($cycle_vars[$name]['delimiter'])) {
$cycle_vars[$name]['delimiter'] = ',';
}
if (!is_array($cycle_vars[$name]['values'])) {
$cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']);
} else {
$cycle_array = $cycle_vars[$name]['values'];
}
if (!isset($cycle_vars[$name]['index']) || $reset) {
$cycle_vars[$name]['index'] = 0;
}
if (isset($assign)) {
$print = false;
$smarty->assign($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;
}
示例5: smarty_function_popup_init
/**
* Smarty {popup_init} function plugin
*
* Type: function<br>
* Name: popup_init<br>
* Purpose: initialize overlib
*
* @link http://smarty.php.net/manual/en/language.function.popup.init.php {popup_init}
* (Smarty online manual)
* @param array
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_popup_init($params, &$smarty)
{
$zindex = 1000;
if (!empty($params['zindex'])) {
$zindex = $params['zindex'];
}
if (!empty($params['src'])) {
return '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:' . $zindex . ';"></div>' . "\n" . '<script type="text/javascript" language="JavaScript" src="' . $params['src'] . '"></script>' . "\n";
} else {
$smarty->trigger_error("popup_init: missing src parameter");
}
}
示例6: smarty_core_create_dir_structure
/**
*
*
* @param unknown $params
* @param unknown $smarty (reference)
* @return unknown
*/
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 = $_dir[0] == '/' ? '/' : 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 .= '/';
}
}
}
示例7: smarty_function_html_options
/**
* Smarty {html_options} function plugin
*
* Type: function<br>
* Name: html_options<br>
* Input:<br>
* - name (optional) - string default "select"
* - values (required if no options supplied) - array
* - options (required if no values supplied) - associative array
* - selected (optional) - string default not set
* - output (required if not options supplied) - array
* Purpose: Prints the list of <option> tags generated from
* the passed parameters
*
* @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @param array
* @param Smarty
* @uses smarty_function_escape_special_chars()
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_html_options($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
$name = null;
$values = null;
$options = null;
$selected = array();
$output = null;
$extra = '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
${$_key} = (string) $_val;
break;
case 'options':
${$_key} = (array) $_val;
break;
case 'selected':
case 'values':
case 'output':
${$_key} = array_values((array) $_val);
break;
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
$smarty->trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values)) {
return '';
}
/* raise error here? */
$_html_result = '';
if (is_array($options)) {
foreach ($options as $_key => $_val) {
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
}
} else {
foreach ((array) $values as $_i => $_key) {
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
}
}
if (!empty($name)) {
$_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
}
return $_html_result;
}
示例8: smarty_core_write_cache_file
/**
*
*
* @param unknown $params
* @param unknown $smarty (reference)
* @return unknown
*/
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...}-tags
$params['results'] = preg_replace('!((\\{nocache\\:([0-9a-f]{32})#(\\d+)\\})' . '.*' . '{/nocache\\:\\3#\\4\\})!Us', '\\2', $params['results']);
$smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
// prepend the cache header info into cache file
$params['results'] = serialize($smarty->_cache_info) . "\n" . $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'], null));
} 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_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
smarty_core_write_file($_params, $smarty);
return true;
}
}
示例9: smarty_function_html_table
/**
* Smarty {html_table} function plugin
*
* Type: function<br>
* Name: html_table<br>
* Date: Feb 17, 2003<br>
* Purpose: make an html table from an array of data<br>
* Input:<br>
* - loop = array to loop through
* - cols = number of columns
* - rows = number of rows
* - table_attr = table attributes
* - tr_attr = table row attributes (arrays are cycled)
* - td_attr = table cell attributes (arrays are cycled)
* - trailpad = value to pad trailing cells with
* - vdir = vertical direction (default: "down", means top-to-bottom)
* - hdir = horizontal direction (default: "right", means left-to-right)
* - inner = inner loop (default "cols": print $loop line by line,
* $loop will be printed column by column otherwise)
*
*
* Examples:
* <pre>
* {table loop=$data}
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols=4 tr_attr=$colors}
* </pre>
*
* @author Monte Ohrt <monte@ispi.net>
* @version 1.0
* @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
* @param array
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_html_table($params, &$smarty)
{
$table_attr = 'border="1"';
$tr_attr = '';
$td_attr = '';
$cols = 3;
$rows = 3;
$trailpad = ' ';
$vdir = 'down';
$hdir = 'right';
$inner = 'cols';
extract($params);
if (!isset($loop)) {
$smarty->trigger_error("html_table: missing 'loop' parameter");
return;
}
$loop_count = count($loop);
if (empty($params['rows'])) {
/* no rows specified */
$rows = ceil($loop_count / $cols);
} elseif (empty($params['cols'])) {
if (!empty($params['rows'])) {
/* no cols specified, but rows */
$cols = ceil($loop_count / $rows);
}
}
$output = "<table {$table_attr}>\n";
for ($r = 0; $r < $rows; $r++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = $vdir == 'down' ? $r * $cols : ($rows - 1 - $r) * $cols;
for ($c = 0; $c < $cols; $c++) {
$x = $hdir == 'right' ? $rx + $c : $rx + $cols - 1 - $c;
if ($inner != 'cols') {
/* shuffle x to loop over rows*/
$x = floor($x / $cols) + $x % $cols * $rows;
}
if ($x < $loop_count) {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
} else {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">{$trailpad}</td>\n";
}
}
$output .= "</tr>\n";
}
$output .= "</table>\n";
return $output;
}
示例10: smarty_function_eval
/**
* Smarty {eval} function plugin
*
* Type: function<br>
* Name: eval<br>
* Purpose: evaluate a template variable as a template<br>
*
* @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
* (Smarty online manual)
* @param array
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
* @return unknown
*/
function smarty_function_eval($params, &$smarty)
{
if (!isset($params['var'])) {
$smarty->trigger_error("eval: missing 'var' parameter");
return;
}
if ($params['var'] == '') {
return;
}
$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
ob_start();
$smarty->_eval('?>' . $_var_compiled);
$_contents = ob_get_contents();
ob_end_clean();
if (!empty($params['assign'])) {
$smarty->assign($params['assign'], $_contents);
} else {
return $_contents;
}
}
示例11: smarty_function_getpost
/**
*
*
* @param unknown $params
* @param unknown $bBlog (reference)
* @return unknown
*/
function smarty_function_getpost($params, &$bBlog)
{
$ar = array();
// If "assign" is not set... we'll establish a default.
if ($params['assign'] == '') {
$params['assign'] = 'post';
}
if ($params['postid'] == '') {
$bBlog->trigger_error('postid is a required parameter');
return '';
}
$q = $bBlog->make_post_query(array("postid" => $params['postid']));
$ar['posts'] = $bBlog->get_posts($q);
// No posts.
if (!is_array($ar['posts'])) {
return false;
}
$ar['posts'][0]['newday'] = 'yes';
$ar['posts'][0]['newmonth'] = 'yes';
$bBlog->assign($params['assign'], $ar['posts'][0]);
return '';
}
示例12: smarty_function_mailto
/**
* Smarty {mailto} function plugin
*
* Type: function<br>
* Name: mailto<br>
* Date: May 21, 2002
* Purpose: automate mailto address link creation, and optionally
* encode them.<br>
* Input:<br>
* - address = e-mail address
* - text = (optional) text to display, default is address
* - encode = (optional) can be one of:
* * none : no encoding (default)
* * javascript : encode with javascript
* * hex : encode with hexidecimal (no javascript)
* - cc = (optional) address(es) to carbon copy
* - bcc = (optional) address(es) to blind carbon copy
* - subject = (optional) e-mail subject
* - newsgroups = (optional) newsgroup(s) to post to
* - followupto = (optional) address(es) to follow up to
* - extra = (optional) extra tags for the href link
*
* Examples:
* <pre>
* {mailto address="me@domain.com"}
* {mailto address="me@domain.com" encode="javascript"}
* {mailto address="me@domain.com" encode="hex"}
* {mailto address="me@domain.com" subject="Hello to you!"}
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'}
* </pre>
*
* @link http://smarty.php.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
* @version 1.2
* @author Monte Ohrt <monte@ispi.net>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
* @param array
* @param Smarty
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_mailto($params, &$smarty)
{
$extra = '';
extract($params);
if (empty($address)) {
$smarty->trigger_error("mailto: missing 'address' parameter");
return;
}
if (empty($text)) {
$text = $address;
}
// netscape and mozilla do not decode %40 (@) in BCC field (bug?)
// so, don't encode it.
$mail_parms = array();
if (!empty($cc)) {
$mail_parms[] = 'cc=' . str_replace('%40', '@', rawurlencode($cc));
}
if (!empty($bcc)) {
$mail_parms[] = 'bcc=' . str_replace('%40', '@', rawurlencode($bcc));
}
if (!empty($subject)) {
$mail_parms[] = 'subject=' . rawurlencode($subject);
}
if (!empty($newsgroups)) {
$mail_parms[] = 'newsgroups=' . rawurlencode($newsgroups);
}
if (!empty($followupto)) {
$mail_parms[] = 'followupto=' . str_replace('%40', '@', rawurlencode($followupto));
}
$mail_parm_vals = '';
for ($i = 0; $i < count($mail_parms); $i++) {
$mail_parm_vals .= 0 == $i ? '?' : '&';
$mail_parm_vals .= $mail_parms[$i];
}
$address .= $mail_parm_vals;
if (empty($encode)) {
$encode = 'none';
} elseif (!in_array($encode, array('javascript', 'hex', 'none'))) {
$smarty->trigger_error("mailto: 'encode' parameter must be none, javascript or hex");
return;
}
if ($encode == 'javascript') {
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
for ($x = 0; $x < strlen($string); $x++) {
$js_encode .= '%' . bin2hex($string[$x]);
}
return '<script type="text/javascript" language="javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
} elseif ($encode == 'hex') {
preg_match('!^(.*)(\\?.*)$!', $address, $match);
if (!empty($match[2])) {
$smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.");
return;
}
for ($x = 0; $x < strlen($address); $x++) {
if (preg_match('!\\w!', $address[$x])) {
$address_encode .= '%' . bin2hex($address[$x]);
} else {
//.........这里部分代码省略.........
示例13: smarty_function_html_radios
/**
* Smarty {html_radios} function plugin
*
* File: function.html_radios.php<br>
* Type: function<br>
* Name: html_radios<br>
* Date: 24.Feb.2003<br>
* Purpose: Prints out a list of radio input types<br>
* Input:<br>
* - name (optional) - string default "radio"
* - values (required) - array
* - options (optional) - associative array
* - checked (optional) - array default not set
* - separator (optional) - ie <br> or
* - output (optional) - without this one the buttons don't have names
* Examples:
* <pre>
* {html_radios values=$ids output=$names}
* {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* </pre>
*
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte@ispi.net>
* @version 1.0
* @param array
* @param Smarty
* @uses smarty_function_escape_special_chars()
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_html_radios($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
$name = 'radio';
$values = null;
$options = null;
$selected = null;
$separator = '';
$labels = true;
$output = null;
$extra = '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'name':
case 'separator':
${$_key} = (string) $_val;
break;
case 'checked':
case 'selected':
if (is_array($_val)) {
$smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} else {
$selected = (string) $_val;
}
break;
case 'labels':
${$_key} = (bool) $_val;
break;
case 'options':
${$_key} = (array) $_val;
break;
case 'values':
case 'output':
${$_key} = array_values((array) $_val);
break;
case 'radios':
$smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
$options = (array) $_val;
break;
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
$smarty->trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values)) {
return '';
}
/* raise error here? */
$_html_result = '';
if (isset($options) && is_array($options)) {
foreach ((array) $options as $_key => $_val) {
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
}
} else {
foreach ((array) $values as $_i => $_key) {
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
}
}
return $_html_result;
}
示例14: smarty_function_html_image
/**
* Smarty {html_image} function plugin
*
* Type: function<br>
* Name: html_image<br>
* Date: Feb 24, 2003<br>
* Purpose: format HTML tags for the image<br>
* Input:<br>
* - file = file (and path) of image (required)
* - border = border width (optional, default 0)
* - height = image height (optional, default actual height)
* - image =image width (optional, default actual width)
* - basedir = base directory for absolute paths, default
* is environment variable DOCUMENT_ROOT
*
* Examples: {html_image file="images/masthead.gif"}
* Output: <img src="images/masthead.gif" border=0 width=400 height=23>
*
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte@ispi.net>
* @author credits to Duda <duda@big.hu> - wrote first image function
* in repository, helped with lots of functionality
* @version 1.0
* @param array
* @param Smarty
* @uses smarty_function_escape_special_chars()
* @param unknown $params
* @param unknown $smarty (reference)
* @return string
*/
function smarty_function_html_image($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
$alt = '';
$file = '';
$border = 0;
$height = '';
$width = '';
$extra = '';
$prefix = '';
$suffix = '';
$basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']) ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '';
if (strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) {
$dpi_default = 72;
} else {
$dpi_default = 96;
}
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'file':
case 'border':
case 'height':
case 'width':
case 'dpi':
case 'basedir':
${$_key} = $_val;
break;
case 'alt':
if (!is_array($_val)) {
${$_key} = smarty_function_escape_special_chars($_val);
} else {
$smarty->trigger_error("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
case 'link':
case 'href':
$prefix = '<a href="' . $_val . '">';
$suffix = '</a>';
break;
default:
if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else {
$smarty->trigger_error("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (empty($file)) {
$smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
return;
}
if (substr($file, 0, 1) == '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
}
if (!isset($params['width']) || !isset($params['height'])) {
if (!($_image_data = @getimagesize($_image_path))) {
if (!file_exists($_image_path)) {
$smarty->trigger_error("html_image: unable to find '{$_image_path}'", E_USER_NOTICE);
return;
} else {
if (!is_readable($_image_path)) {
$smarty->trigger_error("html_image: unable to read '{$_image_path}'", E_USER_NOTICE);
return;
} else {
$smarty->trigger_error("html_image: '{$_image_path}' is not a valid image file", E_USER_NOTICE);
return;
//.........这里部分代码省略.........
示例15: smarty_function_getposts
/**
*
*
* @param unknown $params
* @param unknown $bBlog (reference)
* @return unknown
*/
function smarty_function_getposts($params, &$bBlog)
{
$ar = array();
$opt = array();
if (is_numeric($params['postid']) && $params['postid'] > 0) {
$postid = $params['postid'];
} else {
$postid = FALSE;
}
// If "assign" is not set... we'll establish a default.
if ($params['assign'] == '') {
if ($postid) {
$params['assign'] = 'post';
} else {
$params['assign'] = 'posts';
}
}
if ($postid) {
//we've been given a post id so we'll just get it and get outta here.
$q = $bBlog->make_post_query(array("postid" => $params['postid']));
$ar['posts'] = $bBlog->get_posts($q);
// No post.
if (!is_array($ar['posts'])) {
return false;
}
$ar['posts'][0]['newday'] = 'yes';
$ar['posts'][0]['newmonth'] = 'yes';
$bBlog->assign($params['assign'], $ar['posts'][0]);
return '';
// so if postid is given this is the last line processed
}
// If "archive" is set, order them ASCENDING by posttime.
if ($params['archive']) {
$opt['order'] = " ORDER BY posttime ";
}
// If num is set, we'll only get that many results in return
if (is_numeric($params['num'])) {
$opt['num'] = $params['num'];
}
// If skip is set, we'll skip that many results
if (is_numeric($params['skip'])) {
$opt['skip'] = $params['skip'];
}
if ($params['section'] != '') {
$opt['sectionid'] = $bBlog->sect_by_name[$params['section']];
}
if ($bBlog->show_section) {
$opt['sectionid'] = $bBlog->show_section;
}
if (is_numeric($params['year'])) {
if (strlen($params['year']) != 4) {
$bBlog->trigger_error('getposts: year parameter requires a 4 digit month');
return '';
}
$opt['year'] = $params['year'];
}
if (is_numeric($params['month'])) {
if (strlen($params['month']) != 2) {
$bBlog->trigger_error('getposts: month parameter requires a 2 digit month');
return '';
}
$opt['month'] = $params['month'];
}
if (is_numeric($params['day'])) {
if (strlen($params['day']) != 2) {
$bBlog->trigger_error('getposts: day parameter requires a 2 digit day');
return '';
}
$opt['day'] = $params['day'];
}
if (is_numeric($params['hour'])) {
if (strlen($params['hour']) != 2) {
$bBlog->trigger_error('getposts: hour parameter requires a 2 digit hour');
return '';
}
$opt['hour'] = $params['hour'];
}
if (is_numeric($params['minute'])) {
if (strlen($params['minute']) != 2) {
$bBlog->trigger_error('getposts: minute parameter requires a 2 digit minute');
return '';
}
$opt['minute'] = $params['minute'];
}
if (is_numeric($params['second'])) {
if (strlen($params['second']) != 2) {
$bBlog->trigger_error('getposts: second parameter requires a 2 digit second');
return '';
}
$opt['second'] = $params['second'];
}
$opt['home'] = $params['home'];
$q = $bBlog->make_post_query($opt);
//.........这里部分代码省略.........