Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * determines if a resource is secure or not.
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * @param string $resource_type
Chris PeBenito 696b41
 * @param string $resource_name
Chris PeBenito 696b41
 * @return boolean
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
//  $resource_type, $resource_name
Chris PeBenito 696b41
Chris PeBenito 696b41
function smarty_core_is_secure($params, &$smarty)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
    if (!$smarty->security || $smarty->security_settings['INCLUDE_ANY']) {
Chris PeBenito 696b41
        return true;
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    if ($params['resource_type'] == 'file') {
Chris PeBenito 696b41
        $_rp = realpath($params['resource_name']);
Chris PeBenito 696b41
        if (isset($params['resource_base_path'])) {
Chris PeBenito 696b41
            foreach ((array)$params['resource_base_path'] as $curr_dir) {
Chris PeBenito 696b41
                if ( ($_cd = realpath($curr_dir)) !== false &&
Chris PeBenito 696b41
                     strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
Chris PeBenito 696b41
                     $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) {
Chris PeBenito 696b41
                    return true;
Chris PeBenito 696b41
                }
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
        if (!empty($smarty->secure_dir)) {
Chris PeBenito 696b41
            foreach ((array)$smarty->secure_dir as $curr_dir) {
Chris PeBenito 696b41
                if ( ($_cd = realpath($curr_dir)) !== false &&
Chris PeBenito 696b41
                     strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
Chris PeBenito 696b41
                     $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) {
Chris PeBenito 696b41
                    return true;
Chris PeBenito 696b41
                }            
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
    } else {
Chris PeBenito 696b41
        // resource is not on local file system
Chris PeBenito 696b41
        return call_user_func_array(
Chris PeBenito 696b41
            $smarty->_plugins['resource'][$params['resource_type']][0][2],
Chris PeBenito 696b41
            array($params['resource_name'], &$smarty));
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    return false;
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>