/** * Smarty {html_select_date} plugin * * Type: function<br> * Name: html_select_date<br> * Purpose: Prints the dropdowns for date selection. * * ChangeLog: * <pre> * - 1.0 initial release * - 1.1 added support for +/- N syntax for begin * and end year values. (Monte) * - 1.2 added support for yyyy-mm-dd syntax for * time value. (Jan Rosier) * - 1.3 added support for choosing format for * month values (Gary Loescher) * - 1.3.1 added support for choosing format for * day values (Marcus Bointon) * - 1.3.2 support negative timestamps, force year * dropdown to include given date unless explicitly set (Monte) * - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that * of 0000-00-00 dates (cybot, boots) * - 2.0 complete rewrite for performance, * added attributes month_names, *_id * </pre> * * @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} * (Smarty online manual) * @version 2.0 * @author Andrei Zmievski * @author Monte Ohrt <monte at ohrt dot com> * @author Rodney Rehm * @param array $params parameters * @param Template $template template object * @return string */ function smarty_function_html_select_date($params, $template) { $template->assertIsNotStrict('`{html_select_date}` is a deprecated plugin and is not allowed in strict mode'); // generate timestamps used for month names only static $_month_timestamps = null; static $_current_year = null; if ($_month_timestamps === null) { $_current_year = date('Y'); $_month_timestamps = array(); for ($i = 1; $i <= 12; $i++) { $_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000); } } /* Default values. */ $options = array('prefix' => "Date_", 'start_year' => null, 'end_year' => null, 'display_days' => true, 'display_months' => true, 'display_years' => true, 'month_format' => "%B", 'month_value_format' => "%m", 'day_format' => "%02d", 'day_value_format' => "%d", 'year_as_text' => false, 'reverse_years' => false, 'field_array' => null, 'day_size' => null, 'month_size' => null, 'year_size' => null, 'all_extra' => null, 'day_extra' => null, 'month_extra' => null, 'year_extra' => null, 'field_order' => 'MDY', 'field_separator' => "\n", 'option_separator' => "\n", 'time' => null, 'rel_time' => null, 'extra_attrs' => '', 'all_id' => null, 'day_id' => null, 'month_id' => null, 'year_id' => null, 'all_empty' => null, 'day_empty' => null, 'month_empty' => null, 'year_empty' => null); foreach ($params as $_key => $_value) { switch ($_key) { case 'rel_time': case 'time': if (!is_array($_value) && $_value !== null) { $options[$_key] = smarty_make_timestamp($_value); } break; case 'month_names': if (is_array($_value) && count($_value) == 12) { $options[$_key] = $_value; } else { trigger_error("html_select_date: month_names must be an array of 12 strings", E_USER_NOTICE); } break; case 'prefix': case 'field_array': case 'start_year': case 'end_year': case 'day_format': case 'day_value_format': case 'month_format': case 'month_value_format': case 'day_size': case 'month_size': case 'year_size': case 'all_extra': case 'day_extra': case 'month_extra': case 'year_extra': case 'all_empty': case 'day_empty': case 'month_empty': case 'year_empty': case 'field_order': case 'field_separator': case 'option_separator': case 'all_id': case 'month_id': case 'day_id': case 'year_id': $options[$_key] = (string) $_value; break; case 'display_days': case 'display_months': case 'display_years': case 'year_as_text': case 'reverse_years': $options[$_key] = (bool) $_value; break; default: if (!is_array($_value)) { $options['extra_attrs'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; } else { trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } if (!empty($params['rel_time'])) { $_current_year = date('Y', $params['rel_time']); } $timeData = array('_day' => null, '_month' => null, '_year' => null); // Note: date() is faster than strftime() // Note: explode(date()) is faster than date() date() date() if (isset($params['time']) && is_array($params['time'])) { if (isset($params['time'][$options['prefix'] . 'Year'])) { // $_REQUEST[$options['field_array']] given foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $timeData[$_variableName] = isset($params['time'][$options['prefix'] . $_elementName]) ? $params['time'][$options['prefix'] . $_elementName] : date($_elementKey); } $options['time'] = mktime(0, 0, 0, $timeData['_month'], $timeData['_day'], $timeData['_year']); } elseif (isset($params['time'][$options['field_array']][$options['prefix'] . 'Year'])) { // $_REQUEST given foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $timeData[$_variableName] = isset($params['time'][$options['field_array']][$options['prefix'] . $_elementName]) ? $params['time'][$options['field_array']][$options['prefix'] . $_elementName] : date($_elementKey); } $options['time'] = mktime(0, 0, 0, $timeData['_month'], $timeData['_day'], $timeData['_year']); } else { // no date found, use NOW list($timeData['_year'], $timeData['_month'], $timeData['_day']) = $options['time'] = explode('-', date('Y-m-d')); } } elseif ($options['time'] === null) { if (array_key_exists('time', $params)) { $timeData['_year'] = $timeData['_month'] = $timeData['_day'] = $options['time'] = null; } else { list($timeData['_year'], $timeData['_month'], $timeData['_day']) = $options['time'] = explode('-', date('Y-m-d')); } } else { list($timeData['_year'], $timeData['_month'], $timeData['_day']) = $options['time'] = explode('-', date('Y-m-d', $options['time'])); } // make syntax "+N" or "-N" work with $options['start_year'] and $options['end_year'] // Note preg_match('!^(\+|\-)\s*(\d+)$!', $options['end_year'], $match) is slower than trim+substr foreach (array('start', 'end') as $key) { $key .= '_year'; $t = $options[$key]; if ($t === null) { $options[$key] = (int) $_current_year; } elseif ($t[0] == '+') { $options[$key] = (int) ($_current_year + trim(substr($t, 1))); } elseif ($t[0] == '-') { $options[$key] = (int) ($_current_year - trim(substr($t, 1))); } else { $options[$key] = (int) $options[$key]; } } // flip for ascending or descending if ($options['start_year'] > $options['end_year'] && !$options['reverse_years'] || $options['start_year'] < $options['end_year'] && $options['reverse_years']) { $t = $options['end_year']; $options['end_year'] = $options['start_year']; $options['start_year'] = $t; } // generate year <select> or <input> if ($options['display_years']) { $_html_years = ''; $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Year]' : $options['prefix'] . 'Year'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['year_extra']) { $_extra .= ' ' . $options['year_extra']; } if ($options['year_as_text']) { $_html_years = '<input type="text" name="' . $_name . '" value="' . $timeData['_year'] . '" size="4" maxlength="4"' . $_extra . $options['extra_attrs'] . ' />'; } else { $_html_years = '<select name="' . $_name . '"'; if ($options['year_id'] !== null || $options['all_id'] !== null) { $_html_years .= ' id="' . smarty_function_escape_special_chars($options['year_id'] !== null ? $options['year_id'] ? $options['year_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['year_size']) { $_html_years .= ' size="' . $options['year_size'] . '"'; } $_html_years .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['year_empty']) || isset($options['all_empty'])) { $_html_years .= '<option value="">' . (isset($options['year_empty']) ? $options['year_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } $op = $options['start_year'] > $options['end_year'] ? -1 : 1; for ($i = $options['start_year']; $op > 0 ? $i <= $options['end_year'] : $i >= $options['end_year']; $i += $op) { $_html_years .= '<option value="' . $i . '"' . ($timeData['_year'] == $i ? ' selected="selected"' : '') . '>' . $i . '</option>' . $options['option_separator']; } $_html_years .= '</select>'; } } // generate month <select> or <input> if ($options['display_months']) { $_html_month = ''; $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Month]' : $options['prefix'] . 'Month'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['month_extra']) { $_extra .= ' ' . $options['month_extra']; } $_html_months = '<select name="' . $_name . '"'; if ($options['month_id'] !== null || $options['all_id'] !== null) { $_html_months .= ' id="' . smarty_function_escape_special_chars($options['month_id'] !== null ? $options['month_id'] ? $options['month_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['month_size']) { $_html_months .= ' size="' . $options['month_size'] . '"'; } $_html_months .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['month_empty']) || isset($options['all_empty'])) { $_html_months .= '<option value="">' . (isset($options['month_empty']) ? $options['month_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } for ($i = 1; $i <= 12; $i++) { $_val = sprintf('%02d', $i); $_text = isset($options['month_names']) ? smarty_function_escape_special_chars($options['month_names'][$i]) : ($options['month_format'] == "%m" ? $_val : strftime($options['month_format'], $_month_timestamps[$i])); $_value = $options['month_value_format'] == "%m" ? $_val : strftime($options['month_value_format'], $_month_timestamps[$i]); $_html_months .= '<option value="' . $_value . '"' . ($_val == $timeData['_month'] ? ' selected="selected"' : '') . '>' . $_text . '</option>' . $options['option_separator']; } $_html_months .= '</select>'; } // generate day <select> or <input> if ($options['display_days']) { $_html_day = ''; $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Day]' : $options['prefix'] . 'Day'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['day_extra']) { $_extra .= ' ' . $options['day_extra']; } $_html_days = '<select name="' . $_name . '"'; if ($options['day_id'] !== null || $options['all_id'] !== null) { $_html_days .= ' id="' . smarty_function_escape_special_chars($options['day_id'] !== null ? $options['day_id'] ? $options['day_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['day_size']) { $_html_days .= ' size="' . $options['day_size'] . '"'; } $_html_days .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['day_empty']) || isset($options['all_empty'])) { $_html_days .= '<option value="">' . (isset($options['day_empty']) ? $options['day_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } for ($i = 1; $i <= 31; $i++) { $_val = sprintf('%02d', $i); $_text = $options['day_format'] == '%02d' ? $_val : sprintf($options['day_format'], $i); $_value = $options['day_value_format'] == '%02d' ? $_val : sprintf($options['day_value_format'], $i); $_html_days .= '<option value="' . $_value . '"' . ($_val == $timeData['_day'] ? ' selected="selected"' : '') . '>' . $_text . '</option>' . $options['option_separator']; } $_html_days .= '</select>'; } // order the fields for output $_html = ''; for ($i = 0; $i <= 2; $i++) { switch ($options['field_order'][$i]) { case 'Y': case 'y': if (isset($_html_years)) { if ($_html) { $_html .= $options['field_separator']; } $_html .= $_html_years; } break; case 'm': case 'M': if (isset($_html_months)) { if ($_html) { $_html .= $options['field_separator']; } $_html .= $_html_months; } break; case 'd': case 'D': if (isset($_html_days)) { if ($_html) { $_html .= $options['field_separator']; } $_html .= $_html_days; } break; } } return $_html; }
/** * 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> * Params: * <pre> * - loop - array to loop through * - cols - number of columns, comma separated list of column names * or array of column names * - rows - number of rows * - table_attr - table attributes * - th_attr - table heading attributes (arrays are cycled) * - tr_attr - table row attributes (arrays are cycled) * - td_attr - table cell attributes (arrays are cycled) * - trailpad - value to pad trailing cells with * - caption - text for caption element * - vdir - vertical direction (default: "down", means top-to-bottom) * - hdir - horizontal direction (default: "right", means left-to-right) * - inner - inner loop (default "cols": print $options['loop'] line by line, * $options['loop'] will be printed column by column otherwise) * </pre> * Examples: * <pre> * {table loop=$data} * {table loop=$data cols=4 tr_attr='"bgcolor=red"'} * {table loop=$data cols="first,second,third" tr_attr=$colors} * </pre> * * @author Monte Ohrt <monte at ohrt dot com> * @author credit to Messju Mohr <messju at lammfellpuschen dot de> * @author credit to boots <boots dot smarty at yahoo dot com> * @version 1.1 * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} * (Smarty online manual) * @param array $params parameters * @param Template $template template object * @return string */ function smarty_function_html_table($params, $template) { $template->assertIsNotStrict('`{html_table}` is a deprecated plugin and is not allowed in strict mode'); $options = array('table_attr' => 'border="1"', 'tr_attr' => '', 'th_attr' => '', 'td_attr' => '', 'cols' => 3, 'cols_count' => 3, 'rows' => 3, 'trailpad' => ' ', 'vdir' => 'down', 'hdir' => 'right', 'inner' => 'cols', 'caption' => '', 'loop' => null); if (!isset($params['loop'])) { trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING); return; } foreach ($params as $_key => $_value) { switch ($_key) { case 'loop': $options[$_key] = (array) $_value; break; case 'cols': if (is_array($_value) && !empty($_value)) { $options['cols'] = $_value; $cols_count = count($_value); } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) { $options['cols'] = explode(',', $_value); $cols_count = count($options['cols']); } elseif (!empty($_value)) { $cols_count = (int) $_value; } else { $cols_count = $options['cols']; } break; case 'rows': $options[$_key] = (int) $_value; break; case 'table_attr': case 'trailpad': case 'hdir': case 'vdir': case 'inner': case 'caption': $options[$_key] = (string) $_value; break; case 'tr_attr': case 'td_attr': case 'th_attr': $options[$_key] = $_value; break; } } $loop_count = count($options['loop']); if (empty($params['rows'])) { /* no rows specified */ $options['rows'] = ceil($loop_count / $cols_count); } elseif (empty($params['cols'])) { if (!empty($params['rows'])) { /* no cols specified, but rows */ $cols_count = ceil($loop_count / $options['rows']); } } $output = "<table {$options['table_attr']}>\n"; if (!empty($options['caption'])) { $output .= '<caption>' . $options['caption'] . "</caption>\n"; } if (is_array($options['cols'])) { $options['cols'] = $options['hdir'] == 'right' ? $options['cols'] : array_reverse($options['cols']); $output .= "<thead><tr>\n"; for ($r = 0; $r < $cols_count; $r++) { $output .= '<th' . smarty_function_html_table_cycle('th', $options['th_attr'], $r) . '>'; $output .= $options['cols'][$r]; $output .= "</th>\n"; } $output .= "</tr></thead>\n"; } $output .= "<tbody>\n"; for ($r = 0; $r < $options['rows']; $r++) { $output .= "<tr" . smarty_function_html_table_cycle('tr', $options['tr_attr'], $r) . ">\n"; $rx = $options['vdir'] == 'down' ? $r * $cols_count : ($options['rows'] - 1 - $r) * $cols_count; for ($c = 0; $c < $cols_count; $c++) { $x = $options['hdir'] == 'right' ? $rx + $c : $rx + $cols_count - 1 - $c; if ($options['inner'] != 'cols') { /* shuffle x to loop over rows*/ $x = floor($x / $cols_count) + $x % $cols_count * $options['rows']; } if ($x < $loop_count) { $output .= "<td" . smarty_function_html_table_cycle('td', $options['td_attr'], $c) . ">" . $options['loop'][$x] . "</td>\n"; } else { $output .= "<td" . smarty_function_html_table_cycle('td', $options['td_attr'], $c) . ">{$options['trailpad']}</td>\n"; } } $output .= "</tr>\n"; } $output .= "</tbody>\n"; $output .= "</table>\n"; return $output; }
/** * Smarty {html_options} function plugin * * Type: function<br> * Name: html_options<br> * Purpose: Prints the list of <option> tags generated from * the passed parameters<br> * Params: * <pre> * - 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 * - id (optional) - string default not set * - class (optional) - string default not set * </pre> * * @link http://www.smarty.net/manual/en/language.function.html.options.php {html_image} * (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> * @param array $params parameters * @param Template $template template object * @return string * @uses smarty_function_escape_special_chars() */ function smarty_function_html_options($params, $template) { $template->assertIsNotStrict('`{html_options}` is a deprecated plugin and is not allowed in strict mode'); include_once BRAINY_PLUGINS_DIR . 'shared.escape_special_chars.php'; $options = array('name' => null, 'values' => null, 'options' => null, 'selected' => null, 'output' => null, 'id' => null, 'class' => null, 'extra' => ''); foreach ($params as $_key => $_val) { switch ($_key) { case 'name': case 'class': case 'id': $options[$_key] = (string) $_val; break; case 'options': $options['options'] = (array) $_val; break; case 'values': case 'output': $options[$_key] = array_values((array) $_val); break; case 'selected': if (is_array($_val)) { $options['selected'] = array(); foreach ($_val as $_sel) { if (is_object($_sel)) { if (method_exists($_sel, "__toString")) { $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); } else { trigger_error("html_options: selected attribute contains an object of class '" . get_class($_sel) . "' without __toString() method", E_USER_NOTICE); continue; } } else { $_sel = smarty_function_escape_special_chars((string) $_sel); } $options['selected'][$_sel] = true; } } elseif (is_object($_val)) { if (method_exists($_val, "__toString")) { $options['selected'] = smarty_function_escape_special_chars((string) $_val->__toString()); } else { trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE); } } else { $options['selected'] = smarty_function_escape_special_chars((string) $_val); } break; case 'strict': break; case 'disabled': case 'readonly': if (!empty($params['strict'])) { if (!is_scalar($_val)) { trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", E_USER_NOTICE); } if ($_val === true || $_val === $_key) { $options['extra'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; } break; } // omit break; to fall through! // omit break; to fall through! default: if (!is_array($_val)) { $options['extra'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } if (empty($options['options']) && empty($options['values'])) { /* raise error here? */ return ''; } $_html_result = ''; $_idx = 0; if (isset($options['options'])) { foreach ($options['options'] as $_key => $_val) { $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $options['selected'], $options['id'], $options['class'], $_idx); } } else { foreach ($options['values'] as $_i => $_key) { $_val = isset($options['output'][$_i]) ? $options['output'][$_i] : ''; $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $options['selected'], $options['id'], $options['class'], $_idx); } } if (!empty($options['name'])) { $_html_class = !empty($options['class']) ? ' class="' . $options['class'] . '"' : ''; $_html_id = !empty($options['id']) ? ' id="' . $options['id'] . '"' : ''; $_html_result = '<select name="' . $options['name'] . '"' . $_html_class . $_html_id . $options['extra'] . '>' . "\n" . $_html_result . '</select>' . "\n"; } return $_html_result; }
/** * Smarty {html_select_time} function plugin * * Type: function<br> * Name: html_select_time<br> * Purpose: Prints the dropdowns for time selection * * @link http://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time} * (Smarty online manual) * @author Roberto Berto <*****@*****.**> * @author Monte Ohrt <monte AT ohrt DOT com> * @param array $params parameters * @param Template $template template object * @return string * @uses smarty_make_timestamp() */ function smarty_function_html_select_time($params, $template) { $template->assertIsNotStrict('`{html_select_time}` is a deprecated plugin and is not allowed in strict mode'); $options = array('prefix' => "Time_", 'field_array' => null, 'field_separator' => "\n", 'option_separator' => "\n", 'time' => null, 'display_hours' => true, 'display_minutes' => true, 'display_seconds' => true, 'display_meridian' => true, 'hour_format' => '%02d', 'hour_value_format' => '%02d', 'minute_format' => '%02d', 'minute_value_format' => '%02d', 'second_format' => '%02d', 'second_value_format' => '%02d', 'hour_size' => null, 'minute_size' => null, 'second_size' => null, 'meridian_size' => null, 'all_empty' => null, 'hour_empty' => null, 'minute_empty' => null, 'second_empty' => null, 'meridian_empty' => null, 'all_id' => null, 'hour_id' => null, 'minute_id' => null, 'second_id' => null, 'meridian_id' => null, 'use_24_hours' => true, 'minute_interval' => 1, 'second_interval' => 1, 'extra_attrs' => '', 'all_extra' => null, 'hour_extra' => null, 'minute_extra' => null, 'second_extra' => null, 'meridian_extra' => null); foreach ($params as $_key => $_value) { switch ($_key) { case 'time': if (!is_array($_value) && $_value !== null) { $options['time'] = smarty_make_timestamp($_value); } break; case 'prefix': case 'field_array': case 'field_separator': case 'option_separator': case 'all_extra': case 'hour_extra': case 'minute_extra': case 'second_extra': case 'meridian_extra': case 'all_empty': case 'hour_empty': case 'minute_empty': case 'second_empty': case 'meridian_empty': case 'all_id': case 'hour_id': case 'minute_id': case 'second_id': case 'meridian_id': case 'hour_format': case 'hour_value_format': case 'minute_format': case 'minute_value_format': case 'second_format': case 'second_value_format': $options[$_key] = (string) $_value; break; case 'display_hours': case 'display_minutes': case 'display_seconds': case 'display_meridian': case 'use_24_hours': $options[$_key] = (bool) $_value; break; case 'minute_interval': case 'second_interval': case 'hour_size': case 'minute_size': case 'second_size': case 'meridian_size': $options[$_key] = (int) $_value; break; default: if (!is_array($_value)) { $options['extra_attrs'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; } else { trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } $timeData = array('_hour' => null, '_minute' => null, '_second' => null); if (isset($params['time']) && is_array($params['time'])) { if (isset($params['time'][$options['prefix'] . 'Hour'])) { // $_REQUEST[$options['field_array']] given foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $timeData[$_variableName] = isset($params['time'][$options['prefix'] . $_elementName]) ? $params['time'][$options['prefix'] . $_elementName] : date($_elementKey); } $_meridian = isset($params['time'][$options['prefix'] . 'Meridian']) ? ' ' . $params['time'][$options['prefix'] . 'Meridian'] : ''; $options['time'] = strtotime($timeData['_hour'] . ':' . $timeData['_minute'] . ':' . $timeData['_second'] . $_meridian); list($timeData['_hour'], $timeData['_minute'], $timeData['_second']) = $options['time'] = explode('-', date('H-i-s', $options['time'])); } elseif (isset($params['time'][$options['field_array']][$options['prefix'] . 'Hour'])) { // $_REQUEST given foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); $timeData[$_variableName] = isset($params['time'][$options['field_array']][$options['prefix'] . $_elementName]) ? $params['time'][$options['field_array']][$options['prefix'] . $_elementName] : date($_elementKey); } $_meridian = isset($params['time'][$options['field_array']][$options['prefix'] . 'Meridian']) ? ' ' . $params['time'][$options['field_array']][$options['prefix'] . 'Meridian'] : ''; $options['time'] = strtotime($timeData['_hour'] . ':' . $timeData['_minute'] . ':' . $timeData['_second'] . $_meridian); list($timeData['_hour'], $timeData['_minute'], $timeData['_second']) = $options['time'] = explode('-', date('H-i-s', $options['time'])); } else { // no date found, use NOW list($_year, $_month, $_day) = $options['time'] = explode('-', date('Y-m-d')); } } elseif ($options['time'] === null) { if (array_key_exists('time', $params)) { $timeData['_hour'] = $timeData['_minute'] = $timeData['_second'] = $options['time'] = null; } else { list($timeData['_hour'], $timeData['_minute'], $timeData['_second']) = $options['time'] = explode('-', date('H-i-s')); } } else { list($timeData['_hour'], $timeData['_minute'], $timeData['_second']) = $options['time'] = explode('-', date('H-i-s', $options['time'])); } // generate hour <select> $_html_hours = null; if ($options['display_hours']) { $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Hour]' : $options['prefix'] . 'Hour'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['hour_extra']) { $_extra .= ' ' . $options['hour_extra']; } $_html_hours = '<select name="' . $_name . '"'; if ($options['hour_id'] !== null || $options['all_id'] !== null) { $_html_hours .= ' id="' . smarty_function_escape_special_chars($options['hour_id'] !== null ? $options['hour_id'] ? $options['hour_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['hour_size']) { $_html_hours .= ' size="' . $options['hour_size'] . '"'; } $_html_hours .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['hour_empty']) || isset($options['all_empty'])) { $_html_hours .= '<option value="">' . (isset($options['hour_empty']) ? $options['hour_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } $start = $options['use_24_hours'] ? 0 : 1; $end = $options['use_24_hours'] ? 23 : 12; for ($i = $start; $i <= $end; $i++) { $_val = sprintf('%02d', $i); $_text = $options['hour_format'] == '%02d' ? $_val : sprintf($options['hour_format'], $i); $_value = $options['hour_value_format'] == '%02d' ? $_val : sprintf($options['hour_value_format'], $i); if (!$options['use_24_hours']) { $_hour12 = $timeData['_hour'] == 0 ? 12 : ($timeData['_hour'] <= 12 ? $timeData['_hour'] : $timeData['_hour'] - 12); } $selected = $timeData['_hour'] !== null ? $options['use_24_hours'] ? $timeData['_hour'] == $_val : $_hour12 == $_val : null; $_html_hours .= '<option value="' . $_value . '"' . ($selected ? ' selected="selected"' : '') . '>' . $_text . '</option>' . $options['option_separator']; } $_html_hours .= '</select>'; } // generate minute <select> $_html_minutes = null; if ($options['display_minutes']) { $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Minute]' : $options['prefix'] . 'Minute'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['minute_extra']) { $_extra .= ' ' . $options['minute_extra']; } $_html_minutes = '<select name="' . $_name . '"'; if ($options['minute_id'] !== null || $options['all_id'] !== null) { $_html_minutes .= ' id="' . smarty_function_escape_special_chars($options['minute_id'] !== null ? $options['minute_id'] ? $options['minute_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['minute_size']) { $_html_minutes .= ' size="' . $options['minute_size'] . '"'; } $_html_minutes .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['minute_empty']) || isset($options['all_empty'])) { $_html_minutes .= '<option value="">' . (isset($options['minute_empty']) ? $options['minute_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } $selected = $timeData['_minute'] !== null ? $timeData['_minute'] - $timeData['_minute'] % $options['minute_interval'] : null; for ($i = 0; $i <= 59; $i += $options['minute_interval']) { $_val = sprintf('%02d', $i); $_text = $options['minute_format'] == '%02d' ? $_val : sprintf($options['minute_format'], $i); $_value = $options['minute_value_format'] == '%02d' ? $_val : sprintf($options['minute_value_format'], $i); $_html_minutes .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') . '>' . $_text . '</option>' . $options['option_separator']; } $_html_minutes .= '</select>'; } // generate second <select> $_html_seconds = null; if ($options['display_seconds']) { $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Second]' : $options['prefix'] . 'Second'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['second_extra']) { $_extra .= ' ' . $options['second_extra']; } $_html_seconds = '<select name="' . $_name . '"'; if ($options['second_id'] !== null || $options['all_id'] !== null) { $_html_seconds .= ' id="' . smarty_function_escape_special_chars($options['second_id'] !== null ? $options['second_id'] ? $options['second_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['second_size']) { $_html_seconds .= ' size="' . $options['second_size'] . '"'; } $_html_seconds .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['second_empty']) || isset($options['all_empty'])) { $_html_seconds .= '<option value="">' . (isset($options['second_empty']) ? $options['second_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } $selected = $timeData['_second'] !== null ? $timeData['_second'] - $timeData['_second'] % $options['second_interval'] : null; for ($i = 0; $i <= 59; $i += $options['second_interval']) { $_val = sprintf('%02d', $i); $_text = $options['second_format'] == '%02d' ? $_val : sprintf($options['second_format'], $i); $_value = $options['second_value_format'] == '%02d' ? $_val : sprintf($options['second_value_format'], $i); $_html_seconds .= '<option value="' . $_value . '"' . ($selected === $i ? ' selected="selected"' : '') . '>' . $_text . '</option>' . $options['option_separator']; } $_html_seconds .= '</select>'; } // generate meridian <select> $_html_meridian = null; if ($options['display_meridian'] && !$options['use_24_hours']) { $_extra = ''; $_name = $options['field_array'] ? $options['field_array'] . '[' . $options['prefix'] . 'Meridian]' : $options['prefix'] . 'Meridian'; if ($options['all_extra']) { $_extra .= ' ' . $options['all_extra']; } if ($options['meridian_extra']) { $_extra .= ' ' . $options['meridian_extra']; } $_html_meridian = '<select name="' . $_name . '"'; if ($options['meridian_id'] !== null || $options['all_id'] !== null) { $_html_meridian .= ' id="' . smarty_function_escape_special_chars($options['meridian_id'] !== null ? $options['meridian_id'] ? $options['meridian_id'] : $_name : ($options['all_id'] ? $options['all_id'] . $_name : $_name)) . '"'; } if ($options['meridian_size']) { $_html_meridian .= ' size="' . $options['meridian_size'] . '"'; } $_html_meridian .= $_extra . $options['extra_attrs'] . '>' . $options['option_separator']; if (isset($options['meridian_empty']) || isset($options['all_empty'])) { $_html_meridian .= '<option value="">' . (isset($options['meridian_empty']) ? $options['meridian_empty'] : $options['all_empty']) . '</option>' . $options['option_separator']; } $_html_meridian .= '<option value="am"' . ($timeData['_hour'] < 12 ? ' selected="selected"' : '') . '>AM</option>' . $options['option_separator'] . '<option value="pm"' . ($timeData['_hour'] < 12 ? '' : ' selected="selected"') . '>PM</option>' . $options['option_separator'] . '</select>'; } $_html = ''; foreach (array($_html_hours, $_html_minutes, $_html_seconds, $_html_meridian) as $k) { if (!empty($k)) { if ($_html) { $_html .= $options['field_separator']; } $_html .= $k; } } return $_html; }
/** * 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> * Params: * <pre> * - name (optional) - string default "radio" * - values (required) - array * - options (required) - associative array * - checked (optional) - array default not set * - separator (optional) - ie <br> or * - output (optional) - the output next to each radio button * - assign (optional) - assign the output as an array to this variable * - escape (optional) - escape the content (not value), defaults to true * </pre> * 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 <*****@*****.**> * @author credits to Monte Ohrt <monte at ohrt dot com> * @version 1.0 * @param array $params parameters * @param Template $template template object * @return string * @uses smarty_function_escape_special_chars() */ function smarty_function_html_radios($params, $template) { $template->assertIsNotStrict('`{html_radios}` is a deprecated plugin and is not allowed in strict mode'); include_once SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'; $options = array('name' => 'radio', 'values' => null, 'options' => null, 'selected' => null, 'separator' => '', 'escape' => true, 'labels' => true, 'label_ids' => false, 'output' => null, 'extra' => ''); foreach ($params as $_key => $_val) { switch ($_key) { case 'name': case 'separator': $options[$_key] = (string) $_val; break; case 'checked': case 'selected': if (is_array($_val)) { trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); } elseif (is_object($_val)) { if (method_exists($_val, "__toString")) { $options['selected'] = smarty_function_escape_special_chars((string) $_val->__toString()); } else { trigger_error("html_radios: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE); } } else { $options['selected'] = (string) $_val; } break; case 'escape': case 'labels': case 'label_ids': $options[$_key] = (bool) $_val; break; case 'options': $options[$_key] = (array) $_val; break; case 'values': case 'output': $options[$_key] = array_values((array) $_val); break; case 'radios': trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING); $options = (array) $_val; break; case 'assign': break; case 'strict': break; case 'disabled': case 'readonly': if (!empty($params['strict'])) { if (!is_scalar($_val)) { trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", E_USER_NOTICE); } if ($_val === true || $_val === $_key) { $options['extra'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; } break; } // omit break; to fall through! // omit break; to fall through! default: if (!is_array($_val)) { $options['extra'] .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; } else { trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } if (!isset($options) && !isset($values)) { /* raise error here? */ return ''; } $_html_result = array(); if (isset($options['options'])) { foreach ($options['options'] as $_key => $_val) { $_html_result[] = smarty_function_html_radios_output($options, $_key, $_val); } } else { foreach ($options['values'] as $_i => $_key) { $_val = isset($options['output'][$_i]) ? $options['output'][$_i] : ''; $_html_result[] = smarty_function_html_radios_output($options, $_key, $_val); } } if (!empty($params['assign'])) { $template->assign($params['assign'], $_html_result); } else { return implode("\n", $_html_result); } }