Beispiel #1
0
/**
 * template_lite {html_input} function plugin
 *
 * Type:     function
 * Name:     html_input
 * Purpose:  Creates an input text or password box
 * Input:
 *           - name = the name of the textbox
 *           - password = boolean - if set, this box will be a password box
 *           - value = optional default value for the input box
 *           - size = optional size for the input box
 *           - length = optional maxlength for the input box
 * Author:   Paul Lockaby <*****@*****.**>
 */
function tpl_function_html_input($params, &$tpl)
{
    require_once "shared.escape_chars.php";
    $name = null;
    $value = '';
    $password = false;
    $extra = '';
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'name':
            case 'value':
                ${$_key} = $_value;
                break;
            case 'password':
                ${$_key} = true;
                break;
            default:
                if (!is_array($_key)) {
                    $extra .= ' ' . $_key . '="' . $_value . '"';
                } else {
                    $tpl->trigger_error("html_input: attribute '{$_key}' cannot be an array");
                }
        }
    }
    if (!isset($name) || empty($name)) {
        $tpl->trigger_error("html_input: missing 'name' parameter");
        return;
    }
    $toReturn = '<input type="';
    $toReturn .= $password ? 'password' : 'text';
    $toReturn .= '" name="' . tpl_escape_chars($name) . '" value="' . tpl_escape_chars($value) . '" ' . $extra . ' />';
    return $toReturn;
}
/**
 * Template_Lite {html_textbox} function plugin
 *
 * Type:     function
 * Name:     html_textbox
 * Purpose:  Creates a textbox
 * Input:
 *           - name = the name of the textbox
 *           - rows = optional number of rows in the textbox
 *           - cols = optional number of columns in the textbox
 *           - value = optional preset value to put in the textbox
 * Author:   Paul Lockaby <*****@*****.**>
 */
function tpl_function_html_textbox($params, &$tpl)
{
    require_once "shared.escape_chars.php";
    $name = null;
    $value = '';
    $extra = '';
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'name':
            case 'value':
                ${$_key} = $_value;
                break;
            default:
                if (!is_array($_key)) {
                    $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"';
                } else {
                    $tpl->trigger_error("html_textbox: attribute '{$_key}' cannot be an array");
                }
        }
    }
    if (!isset($name) || empty($name)) {
        $tpl->trigger_error("html_textbox: missing 'name' parameter");
        return;
    }
    $toReturn = '<textarea name="' . tpl_escape_chars($name) . '" ' . $extra . '>' . tpl_escape_chars($value) . '</textarea>';
    return $toReturn;
}
function tpl_function_html_options_optgroup(&$tpl, $key, $values, $selected)
{
    $optgroup_html = '<optgroup label="' . tpl_escape_chars($key) . '">' . "\n";
    foreach ($values as $key => $value) {
        $optgroup_html .= tpl_function_html_options_optoutput($tpl, $key, $value, $selected);
    }
    $optgroup_html .= "</optgroup>\n";
    return $optgroup_html;
}
/**
 * Template_Lite {html_checkbox} function plugin
 *
 * Type:     function
 * Name:     textbox
 * Purpose:  Creates a checkbox
 * Input:
 *           - name = the name of the checkbox
 *           - value = optional value for the checkbox
 *           - checked = boolean - whether the box is checked or not
 * Author:   Paul Lockaby <*****@*****.**>
 */
function tpl_function_html_checkboxes($params, &$tpl)
{
    require_once "shared.escape_chars.php";
    $name = null;
    $value = null;
    $checked = null;
    $extra = '';
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'name':
            case 'value':
                ${$_key} = $_value;
                break;
            case 'checked':
                if ($_key == 'true' || $_key == 'yes' || $_key == 'on') {
                    ${$_key} = true;
                } else {
                    ${$_key} = false;
                }
                break;
            default:
                if (!is_array($_key)) {
                    $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"';
                } else {
                    $tpl->trigger_error("html_checkbox: attribute '{$_key}' cannot be an array");
                }
        }
    }
    if (!isset($name) || empty($name)) {
        $tpl->trigger_error("html_checkbox: missing 'name' parameter");
        return;
    }
    $toReturn = '<input type="checkbox" name="' . tpl_escape_chars($name) . '"';
    if (isset($checked)) {
        $toReturn .= ' checked';
    }
    if (isset($value)) {
        $toReturn .= ' value="' . tpl_escape_chars($value) . '"';
    }
    $toReturn .= ' ' . $extra . ' />';
    return $toReturn;
}
Beispiel #5
0
function tpl_input_checkbox($params, $tpl)
{
    if (!defined('CORE_INCLUDE_DIR')) {
        define('CORE_INCLUDE_DIR', CORE_DIR . ((!defined('SHOP_DEVELOPER') || !constant('SHOP_DEVELOPER')) && version_compare(PHP_VERSION, '5.0', '>=') ? '/include_v5' : '/include'));
    }
    require_once CORE_INCLUDE_DIR . '/smartyplugins/shared.escape_chars.php';
    $name = null;
    $value = null;
    $checked = null;
    $extra = '';
    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'name':
            case 'value':
                ${$_key} = $_value;
                break;
            case 'checked':
                if ($_key == 'true' || $_key == 'yes' || $_key == 'on') {
                    ${$_key} = true;
                } else {
                    ${$_key} = false;
                }
                break;
            default:
                if (!is_array($_key)) {
                    $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"';
                } else {
                    $tpl->trigger_error("html_checkbox: attribute '{$_key}' cannot be an array");
                }
        }
    }
    $toReturn = '<input type="checkbox" name="' . tpl_escape_chars($name) . '"';
    if (isset($checked)) {
        $toReturn .= ' checked';
    }
    if (isset($value)) {
        $toReturn .= ' value="' . tpl_escape_chars($value) . '"';
    }
    $toReturn .= ' ' . $extra . ' />';
    return $toReturn;
}
function tpl_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels)
{
    $_output = '';
    if ($labels) {
        $_output .= '<label>';
    }
    $_output .= '<input type="checkbox" name="' . tpl_escape_chars($name) . '[]" value="' . tpl_escape_chars($value) . '"';
    if (in_array((string) $value, $selected)) {
        $_output .= ' checked="checked"';
    }
    $_output .= $extra . ' />' . $output;
    if ($labels) {
        $_output .= '</label>';
    }
    $_output .= $separator;
    return $_output;
}
Beispiel #7
0
/**
 * template_lite {html_image} function plugin
 *
 * Type:     function
 * Name:     html_image
 * Purpose:  Outputs an image tag along with resized height/width
 * Input:
 *           - url = the url of the picture
 *           - width = optional width
 *           - height = optional height
 *           - limit = boolean - will resize image to the above height
 *                     and width if the above height and width are
 *                     smaller than the real height and width
 *           - border = optional size of the border, default is "0"
 *           - alt = optional alternate text to display
 * Examples:<br>
 * <pre>
 * {html_image url="http://www.yoursite.com/image.jpg"}
 * {html_image url="images/me.gif" alt="A picture of me!"}
 * </pre>
 * Author:   Paul Lockaby <*****@*****.**>
 */
function tpl_function_html_image($params, &$tpl)
{
    require_once "shared.escape_chars.php";
    $alt = '';
    $url = '';
    $height = '';
    $width = '';
    $extra = '';
    $prefix = '';
    $suffix = '';
    $basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '';
    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'url':
            case 'height':
            case 'width':
                ${$_key} = $_val;
                break;
            case 'limit':
                ${$_key} = true;
                break;
            case 'alt':
                if (!is_array($_val)) {
                    ${$_key} = tpl_escape_chars($_val);
                } else {
                    $tpl->trigger_error("html_image: attribute '{$_key}' cannot be an array");
                }
                break;
            case 'link':
            case 'href':
                $prefix = '<a href="' . $_val . '">';
                $suffix = '</a>';
                break;
            default:
                if (!is_array($_val)) {
                    $extra .= ' ' . $_key . '="' . template_function_escape_special_chars($_val) . '"';
                } else {
                    $template_object->trigger_error("html_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
                }
                break;
        }
    }
    if (empty($url)) {
        $template_object->trigger_error("html_image: missing 'url' parameter", E_USER_NOTICE);
        return;
    }
    if (substr($file, 0, 1) == '/') {
        $_image_path = $basedir . $file;
    } else {
        $_image_path = $file;
    }
    // 0 = width, 1 = height
    if ($size = @getimagesize($url)) {
        if (empty($limit) || $limit == false) {
            // only a height was specified; we will fill in the width
            if (!empty($height)) {
                $width = $size[0];
            }
            // only a width was specified; we will fill in the height
            if (!empty($width)) {
                $height = $size[1];
            }
            // neither a height nor a width was specified; we will fill in both
            if (empty($width) && empty($height)) {
                $width = $size[0];
                $height = $size[1];
            }
        } else {
            if (!empty($width) && $size[0] > $width || !empty($height) && $size[1] > $height) {
                if (!empty($height) && !empty($width)) {
                    // compare the ratios to determine how much each dimension needs to be changed
                    // this will return the width if the height is set to specified
                    $bth_width = round($size[0] * ($height / $size[1]));
                    // this will return the height if the width is set to specified
                    $bth_height = round($size[1] * ($width / $size[0]));
                    // first we set the width to the max and see how big the height will be
                    if (!($bth_height > $height)) {
                        // returned height is acceptable (i.e. less than specified)
                        $fin1_height = $bth_height;
                        $fin1_width = $width;
                    }
                    // now we set the height to the max and see how big the width will be
                    if (!($bth_width > $width)) {
                        // returned width is acceptable (i.e. less than specified)
                        $fin2_height = $height;
                        $fin2_width = $bth_width;
                    }
                    // check to see if both of them went through
                    if (isset($fin1_height) && isset($fin1_width) && isset($fin2_height) && isset($fin2_width)) {
                        // now check the difference between abs($fin1_height-$fin1_width) and abs($fin2_height-$fin2_width)
                        // since we obviously want the larger image, take whichever one has the smaller difference
                        if (abs($fin1_height - $fin1_width) < abs($fin2_height - $fin2_width)) {
                            $new_height = $fin1_height;
                            $new_width = $fin1_width;
                        } else {
                            $new_height = $fin2_height;
                            $new_width = $fin2_width;
                        }
                    } else {
                        // since $new_height and $new_width weren't set above, we have to set them here
                        if (isset($fin1_height) && isset($fin1_width)) {
                            $new_height = $fin1_height;
                            $new_width = $fin1_width;
                        } else {
                            $new_height = $fin2_height;
                            $new_width = $fin2_width;
                        }
                    }
                } else {
                    // only a height or only a width was specified
                    // much easier
                    if (!empty($height)) {
                        // working with only a height now
                        $new_height = $height;
                        $new_width = round($size[0] * ($height / $size[1]));
                    }
                    if (!empty($width)) {
                        // working with only a width now
                        $new_height = round($size[1] * ($width / $size[0]));
                        $new_width = $width;
                    }
                }
                $width = $new_width;
                $height = $new_height;
            } else {
                $width = $size[0];
                $height = $size[1];
            }
        }
    }
    return $prefix . '<img src="' . $url . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix;
}