当前位置: 首页>>代码示例>>PHP>>正文


PHP smarty_core_is_secure函数代码示例

本文整理汇总了PHP中smarty_core_is_secure函数的典型用法代码示例。如果您正苦于以下问题:PHP smarty_core_is_secure函数的具体用法?PHP smarty_core_is_secure怎么用?PHP smarty_core_is_secure使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了smarty_core_is_secure函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: smarty_function_fetch

/**
 * Smarty {fetch} plugin
 *
 * Type:     function<br>
 * Name:     fetch<br>
 * Purpose:  fetch file, web or ftp data and display results
 * @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch}
 *       (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com>
 * @param array
 * @param Smarty
 * @return string|null if the assign parameter is passed, Smarty assigns the
 *                     result to a template variable
 */
function smarty_function_fetch($params, &$smarty)
{
    if (empty($params['file'])) {
        $smarty->_trigger_fatal_error("[plugin] parameter 'file' cannot be empty");
        return;
    }
    $content = '';
    if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
        $_params = array('resource_type' => 'file', 'resource_name' => $params['file']);
        require_once SMARTY_CORE_DIR . 'core.is_secure.php';
        if (!smarty_core_is_secure($_params, $smarty)) {
            $smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed');
            return;
        }
        // fetch the file
        if ($fp = @fopen($params['file'], 'r')) {
            while (!feof($fp)) {
                $content .= fgets($fp, 4096);
            }
            fclose($fp);
        } else {
            $smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
            return;
        }
    } else {
        // not a local file
        if (preg_match('!^http://!i', $params['file'])) {
            // http fetch
            if ($uri_parts = parse_url($params['file'])) {
                // set defaults
                $host = $server_name = $uri_parts['host'];
                $timeout = 30;
                $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
                $agent = "Smarty Template Engine " . $smarty->_version;
                $referer = "";
                $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/';
                $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : '';
                $_is_proxy = false;
                if (empty($uri_parts['port'])) {
                    $port = 80;
                } else {
                    $port = $uri_parts['port'];
                }
                if (!empty($uri_parts['user'])) {
                    $user = $uri_parts['user'];
                }
                if (!empty($uri_parts['pass'])) {
                    $pass = $uri_parts['pass'];
                }
                // loop through parameters, setup headers
                foreach ($params as $param_key => $param_value) {
                    switch ($param_key) {
                        case "file":
                        case "assign":
                        case "assign_headers":
                            break;
                        case "user":
                            if (!empty($param_value)) {
                                $user = $param_value;
                            }
                            break;
                        case "pass":
                            if (!empty($param_value)) {
                                $pass = $param_value;
                            }
                            break;
                        case "accept":
                            if (!empty($param_value)) {
                                $accept = $param_value;
                            }
                            break;
                        case "header":
                            if (!empty($param_value)) {
                                if (!preg_match('![\\w-]+: .+!', $param_value)) {
                                    $smarty->_trigger_fatal_error("[plugin] invalid header format '" . $param_value . "'");
                                    return;
                                } else {
                                    $extra_headers[] = $param_value;
                                }
                            }
                            break;
                        case "proxy_host":
                            if (!empty($param_value)) {
                                $proxy_host = $param_value;
                            }
                            break;
//.........这里部分代码省略.........
开发者ID:caidongyun,项目名称:vanilla,代码行数:101,代码来源:function.fetch.php

示例2: _fetch_resource_info

 /**
  * fetch the template info. Gets timestamp, and source
  * if get_source is true
  *
  * sets $source_content to the source of the template, and
  * $resource_timestamp to its time stamp
  * @param string $resource_name
  * @param string $source_content
  * @param integer $resource_timestamp
  * @param boolean $get_source
  * @param boolean $quiet
  * @return boolean
  */
 function _fetch_resource_info(&$params)
 {
     if (!isset($params['get_source'])) {
         $params['get_source'] = true;
     }
     if (!isset($params['quiet'])) {
         $params['quiet'] = false;
     }
     $_return = false;
     $_params = array('resource_name' => $params['resource_name']);
     if (isset($params['resource_base_path'])) {
         $_params['resource_base_path'] = $params['resource_base_path'];
     } else {
         $_params['resource_base_path'] = $this->template_dir;
     }
     if ($this->_parse_resource_name($_params)) {
         $_resource_type = $_params['resource_type'];
         $_resource_name = $_params['resource_name'];
         switch ($_resource_type) {
             case 'file':
                 if ($params['get_source']) {
                     $params['source_content'] = $this->_read_file($_resource_name);
                 }
                 $params['resource_timestamp'] = filemtime($_resource_name);
                 $_return = is_file($_resource_name);
                 break;
             default:
                 // call resource functions to fetch the template source and timestamp
                 if ($params['get_source']) {
                     $_source_return = isset($this->_plugins['resource'][$_resource_type]) && call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], array($_resource_name, &$params['source_content'], &$this));
                 } else {
                     $_source_return = true;
                 }
                 $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], array($_resource_name, &$params['resource_timestamp'], &$this));
                 $_return = $_source_return && $_timestamp_return;
                 break;
         }
     }
     if (!$_return) {
         // see if we can get a template with the default template handler
         if (!empty($this->default_template_handler_func)) {
             if (!is_callable($this->default_template_handler_func)) {
                 $this->trigger_error("default template handler function \"{$this->default_template_handler_func}\" doesn't exist.");
             } else {
                 $_return = call_user_func_array($this->default_template_handler_func, array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));
             }
         }
     }
     if (!$_return) {
         if (!$params['quiet']) {
             $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
         }
     } else {
         if ($_return && $this->security) {
             require_once SMARTY_CORE_DIR . 'core.is_secure.php';
             if (!smarty_core_is_secure($_params, $this)) {
                 if (!$params['quiet']) {
                     $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
                 }
                 $params['source_content'] = null;
                 $params['resource_timestamp'] = null;
                 return false;
             }
         }
     }
     return $_return;
 }
开发者ID:kingwang317,项目名称:it4fun-guam,代码行数:80,代码来源:Smarty.class.php

示例3: smarty_function_html_js_icon

/**
 * Smarty {html_js_icon} function plugin
 *
 * Type:     function<br>
 * Name:     html_js_icon<br>
 * Date:     October 06, 2005
 * Input:<br>
 *         - button = button (and path) of image (required)
 *         - border = border width (optional, default 0)
 *         - height = image height (optional, default actual height)
 *         - basedir = base directory
 *
 * Examples: {html_js_icon image="email.gif"}
 * Output:   <img src="images/masthead.gif" border=0 width=400 height=23>
 * @author r23 <info@r23.de>
 * @author credits to 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
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_html_js_icon($params, &$smarty)
{
    MyOOS_CoreApi::requireOnce('lib/smarty/libs/plugins/shared.escape_special_chars.php');
    $image = '';
    $alt = '';
    $align = 'middle';
    $border = 0;
    $height = '';
    $width = '';
    $extra = '';
    $sTheme = oos_var_prep_for_os($_SESSION['theme']);
    $basedir = 'themes/' . $sTheme . '/images/icons/';
    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'image':
            case 'basedir':
            case 'align':
                ${$_key} = $_val;
                break;
            case 'alt':
                if (!is_array($_val)) {
                    ${$_key} = smarty_function_escape_special_chars($_val);
                } else {
                    $smarty->trigger_error("html_js_icon: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
                }
                break;
            default:
                if (!is_array($_val)) {
                    $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
                } else {
                    $smarty->trigger_error("html_js_icon: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
                }
                break;
        }
    }
    if (empty($image)) {
        $smarty->trigger_error("html_js_icon: missing 'button' parameter", E_USER_NOTICE);
        return;
    }
    $_image_path = $basedir . $image;
    if (!isset($params['width']) || !isset($params['height'])) {
        if ($smarty->security && ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && (require_once SMARTY_CORE_DIR . 'core.is_secure.php') && !smarty_core_is_secure($_params, $smarty)) {
            $smarty->trigger_error("html_js_icon:: (secure) '{$_image_path}' not in secure directory", E_USER_NOTICE);
        } elseif (!($_image_data = @getimagesize($_image_path))) {
            if (!file_exists($_image_path)) {
                $smarty->trigger_error("html_js_icon: unable to find '{$_image_path}'", E_USER_NOTICE);
                return;
            } elseif (!is_readable($_image_path)) {
                $smarty->trigger_error("html_js_icon: unable to read '{$_image_path}'", E_USER_NOTICE);
                return;
            } else {
                $smarty->trigger_error("html_js_icon: '{$_image_path}' is not a valid image button", E_USER_NOTICE);
                return;
            }
        }
        if (!isset($params['width'])) {
            $width = $_image_data[0];
        }
        if (!isset($params['height'])) {
            $height = $_image_data[1];
        }
    }
    return '<img src="' . $basedir . $image . '" alt="' . $alt . '" align="' . $align . '" border="' . $border . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />';
}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:88,代码来源:function.html_js_icon.php

示例4: 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)
 *         - height = image height (optional, default actual height)
 *         - width = image width (optional, default actual width)
 *         - basedir = base directory for absolute paths, default
 *                     is environment variable DOCUMENT_ROOT
 *         - path_prefix = prefix for path output (optional, default empty)
 *
 * Examples: {html_image file="/images/masthead.gif"}
 * Output:   <img src="/images/masthead.gif" 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 at ohrt dot com>
 * @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
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_html_image($params, &$smarty)
{
    require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
    $alt = '';
    $file = '';
    $height = '';
    $width = '';
    $extra = '';
    $prefix = '';
    $suffix = '';
    $path_prefix = '';
    $server_vars = $smarty->request_use_auto_globals ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
    $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
    foreach ($params as $_key => $_val) {
        switch ($_key) {
            case 'file':
            case 'height':
            case 'width':
            case 'dpi':
            case 'path_prefix':
            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;
                }
            }
        }
        if ($smarty->security && ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && (require_once SMARTY_CORE_DIR . 'core.is_secure.php') && !smarty_core_is_secure($_params, $smarty)) {
            $smarty->trigger_error("html_image: (secure) '{$_image_path}' not in secure directory", E_USER_NOTICE);
        }
        if (!isset($params['width'])) {
//.........这里部分代码省略.........
开发者ID:quangbt2005,项目名称:belamdep,代码行数:101,代码来源:function.html_image.php

示例5: test_core_is_secure_function_is_secure_false

 function test_core_is_secure_function_is_secure_false()
 {
     $security = $this->smarty->security;
     $this->smarty->security = true;
     /* check if test_cases.php is secure (should be false) */
     $params = array('resource_type' => 'file', 'resource_base_path' => dirname(__FILE__) . '/templates', 'resource_name' => __FILE__);
     $this->assertFalse(smarty_core_is_secure($params, $this->smarty));
     $this->smarty->security = $security;
 }
开发者ID:laiello,项目名称:coopcrucial,代码行数:9,代码来源:test_cases.php

示例6: inside


//.........这里部分代码省略.........
                if (!is_array($_val)) {
                    $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
                } else {
                    $smarty->trigger_error("resized_image: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE);
                }
                break;
        }
    }
    // Checking the existence of required parameters
    if (empty($file)) {
        $smarty->trigger_error("resized_image: missing 'file' parameter", E_USER_ERROR);
        return;
    }
    if (!isset($params['width']) && !isset($params['height'])) {
        $smarty->trigger_error("resized_image: New size was not specified", E_USER_ERROR);
        return;
    }
    // If image resized is 'fit', both height and width are required
    if ($fit == 'fill' && (empty($width) || empty($height))) {
        $smarty->trigger_error("resized_image:  When you choose 'fill' fit, you have to specify both width and height", E_USER_ERROR);
    }
    // Transliteration - prepare a clean name for file
    $clean_file = str_replace(' ', '_', $file);
    // remove spaces
    $from = explode(' ', 'Á á É é è ê È Ê Í í Ó ó Ú ú Ñ ñ Ç ç');
    $to = explode(' ', 'A a E e e e E E I i O o U u N n C c');
    $clean_file = str_replace($from, $to, strtolower($clean_file));
    // removing special characters, convert to lowercase, encoding in URL the remaining for safe
    $clean_file = str_replace('%2F', '/', urlencode($clean_file));
    // URLencode the remaining, but taking into consideration the / char.
    // Preparing paths
    if (substr($file, 0, 1) == '/') {
        $original['path'] = $basedir . $file;
        $resized['path'] = ICMS_ROOT_PATH . '/cache' . $clean_file;
        $resized['url'] = ICMS_URL . '/cache' . $clean_file;
    } elseif (strpos($file, ICMS_URL) === 0) {
        // In case of full URL
        $original['path'] = ICMS_ROOT_PATH . str_replace(ICMS_URL, '', $file);
        $clean_file = str_replace(ICMS_URL, '', urldecode($clean_file));
        // Clean file shouuld not have Full URL
        $resized['path'] = ICMS_ROOT_PATH . '/cache' . $clean_file;
        $resized['url'] = ICMS_URL . '/cache' . $clean_file;
    } else {
        $original['path'] = $file;
        $resized['path'] = ICMS_ROOT_PATH . '/cache/' . $clean_file;
        $resized['url'] = ICMS_URL . '/cache/' . $clean_file;
    }
    // Check if original image exists
    if (!($_image_data = @getimagesize($original['path']))) {
        if (!file_exists($original['path'])) {
            $smarty->trigger_error("resized_image: unable to find '" . $original['path'] . "'", E_USER_NOTICE);
            return;
        } else {
            if (!is_readable($original['path'])) {
                $smarty->trigger_error("resized_image: unable to read '" . $original['path'] . "'", E_USER_NOTICE);
                return;
            } else {
                $smarty->trigger_error("resized_image: '" . $original['path'] . "' is not a valid image file", E_USER_NOTICE);
                return;
            }
        }
    }
    // Smarty Security check (comes from Smarty html_image tag, being honest, I don't understand what it does).
    if ($smarty->security && ($_params = array('resource_type' => 'file', 'resource_name' => $original['path'])) && (require_once SMARTY_CORE_DIR . 'core.is_secure.php') && !smarty_core_is_secure($_params, $smarty)) {
        $smarty->trigger_error("resized_image: (secure) '" . $original['path'] . "' not in secure directory", E_USER_NOTICE);
    }
    // Original and resized dimensions
    if (!isset($params['width'])) {
        $original['width'] = $_image_data[0];
    }
    if (!isset($params['height'])) {
        $original['height'] = $_image_data[1];
    }
    $resized['width'] = $width;
    $resized['height'] = $height;
    // build resized file name
    $resized['dir'] = substr($resized['path'], 0, strrpos($resized['path'], "/"));
    // extract path
    $resized['path'] = substr($resized['path'], 0, strrpos($resized['path'], ".")) . "-" . $resized['width'] . "x" . $resized['height'] . substr($resized['path'], strrpos($resized['path'], "."));
    // build path + file name
    $resized['url'] = substr($resized['url'], 0, strrpos($resized['url'], ".")) . "-" . $resized['width'] . "x" . $resized['height'] . substr($resized['url'], strrpos($resized['url'], "."));
    // build file URL
    // If file does not exist
    // or it's outdated, create:
    if (!file_exists($resized['path']) or filemtime($original['path']) > filemtime($resized['path'])) {
        if (!is_dir($resized['dir'])) {
            // If dir does not exist, create
            mkdir($resized['dir'], 0755, true);
        }
        // Resize image using WideImage library
        include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php';
        $resized_img = WideImage::load($original['path'], 'jpg');
        $resized_img->resize($resized['width'], $resized['height'], $fit)->saveToFile($resized['path']);
    }
    if ($return == 'url') {
        return $resized['url'];
    } else {
        return $prefix . '<img src="' . $resized['url'] . '" alt="' . $alt . '" ' . $extra . ' />' . $suffix;
    }
}
开发者ID:LeeGlendenning,项目名称:formulize,代码行数:101,代码来源:function.resized_image.php

示例7: _fetch_resource_info

    /**
     * fetch the template info. Gets timestamp, and source
     * if get_source is true
     *
     * sets $source_content to the source of the template, and
     * $resource_timestamp to its time stamp
     * @param string $resource_name
     * @param string $source_content
     * @param integer $resource_timestamp
     * @param boolean $get_source
     * @param boolean $quiet
     * @return boolean
     */
    function _fetch_resource_info(&$params)
    {
        if (!isset($params['get_source'])) {
            $params['get_source'] = true;
        }
        if (!isset($params['quiet'])) {
            $params['quiet'] = false;
        }
        $_return = false;
        $_params = array('resource_name' => $params['resource_name']);
        if (isset($params['resource_base_path'])) {
            $_params['resource_base_path'] = $params['resource_base_path'];
        } else {
            $_params['resource_base_path'] = $this->template_dir;
        }
        if ($this->_parse_resource_name($_params)) {
            $_resource_type = $_params['resource_type'];
            $_resource_name = $_params['resource_name'];
            switch ($_resource_type) {
                case 'file':
                    if ($params['get_source']) {
                        $params['source_content'] = $this->_read_file($_resource_name);
                    }
                    $params['resource_timestamp'] = filemtime($_resource_name);
                    $_return = is_file($_resource_name) && is_readable($_resource_name);
                    break;
                default:
                    // call resource functions to fetch the template source and timestamp
                    if ($params['get_source']) {
                        $_source_return = isset($this->_plugins['resource'][$_resource_type]) && call_user_func_array($this->_plugins['resource'][$_resource_type][0][0], array($_resource_name, &$params['source_content'], &$this));
                    } else {
                        $_source_return = true;
                    }
                    $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) && call_user_func_array($this->_plugins['resource'][$_resource_type][0][1], array($_resource_name, &$params['resource_timestamp'], &$this));
                    $_return = $_source_return && $_timestamp_return;
                    break;
            }
        }
        if (!$_return) {
            // see if we can get a template with the default template handler
            if (!empty($this->default_template_handler_func)) {
                if (!is_callable($this->default_template_handler_func)) {
                    $this->trigger_error("default template handler function \"{$this->default_template_handler_func}\" doesn't exist.");
                } else {
                    $_return = call_user_func_array($this->default_template_handler_func, array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));
                }
            }
        }
        if (!$_return) {
            if (!$params['quiet']) {
                $file_Name = explode('/', $params['resource_name']);
                $file_Name = end($file_Name);
                $this->html_trigger_error('Невозможно загрузить шаблон

                    <span style="font-weight:bold;color:green;">' . (!empty($file_Name) ? $file_Name : $params['resource_name']) . '</span>' . (!empty($file_Name) ? ' из папки: <span style="color:blue;">' . $this->template_dir . '/' . str_replace($file_Name, '', $params['resource_name']) . '</span>' : ''));
            }
        } else {
            if ($_return && $this->security) {
                require_once SMARTY_CORE_DIR . 'core.is_secure.php';
                if (!smarty_core_is_secure($_params, $this)) {
                    if (!$params['quiet']) {
                        $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
                    }
                    $params['source_content'] = null;
                    $params['resource_timestamp'] = null;
                    return false;
                }
            }
        }
        return $_return;
    }
开发者ID:olegfox,项目名称:muzlo,代码行数:84,代码来源:Smarty.class.php

示例8: 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)
 *         - height = image height (optional, default actual height)
 *         - width = 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" 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 at ohrt dot com>
 * @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
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_html_image($params, &$smarty)
{
    MyOOS_CoreApi::requireOnce('lib/smarty/libs/plugins/shared.escape_special_chars.php');

    $alt = '';
    $file = '';
    $height = '';
    $width = '';
    $extra = '';
    $prefix = '';
    $suffix = '';

    $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
    $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';

    foreach($params as $_key => $_val) {
        switch($_key) {
            case 'file':
            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 ($smarty->security &&
            ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
            (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
            (!smarty_core_is_secure($_params, $smarty)) ) {
            $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);

        } elseif (!$_image_data = @getimagesize($_image_path)) {
            if(!file_exists($_image_path)) {
                $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
                return;
            } elseif(!is_readable($_image_path)) {
                $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:101,代码来源:function.html_image.php


注:本文中的smarty_core_is_secure函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。