コード例 #1
0
/**
 * Extract non-cacheable parts out of compiled template and write it
 *
 * @param string $compile_path
 * @param string $template_compiled
 * @param integer $template_timestamp
 * @return boolean
 */
function smarty_core_write_compiled_include($params, &$smarty)
{
    $_tag_start = 'if \\(\\$this->caching\\) \\{ echo \'\\{nocache\\:(' . $params['cache_serial'] . ')#(\\d+)\\}\';\\}';
    $_tag_end = 'if \\(\\$this->caching\\) \\{ echo \'\\{/nocache\\:(\\2)#(\\3)\\}\';\\}';
    preg_match_all('!(' . $_tag_start . '(.*)' . $_tag_end . ')!Us', $params['compiled_content'], $_match_source, PREG_SET_ORDER);
    // no nocache-parts found: done
    if (count($_match_source) == 0) {
        return;
    }
    // convert the matched php-code to functions
    $_include_compiled = "<?php /* funky header here */\n\n";
    $_compile_path = $params['include_file_path'];
    $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
    $_include_compiled .= "\$this->_cache_serials['" . $_compile_path . "'] = '" . $params['cache_serial'] . "';\n\n?>";
    $_include_compiled .= $params['plugins_code'];
    $_include_compiled .= "<?php";
    for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
        $_match =& $_match_source[$_i];
        $_include_compiled .= "\r\nfunction _smarty_tplfunc_{$_match['2']}_{$_match['3']}(&\$this)\r\n{\r\n{$_match['4']}\r\n}\r\n\r\n";
    }
    $_include_compiled .= "\n\n?>\n";
    $_params = array('filename' => $_compile_path, 'contents' => $_include_compiled, 'create_dirs' => true);
    require_once SMARTY_DIR . 's_core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #2
0
function smarty_core_write_compiled_resource($params, &$smarty)
{
    if (!@is_writable($smarty->compile_dir)) {
        if (strpos($smarty->compile_dir, "template_c") > 0) {
            $mymsg = "";
            $ftpdir = substr($smarty->compile_dir, 23);
            if (!myftpchmod($ftpdir, 0777)) {
                $mymsg = " (cat'n do ftpchmod) ";
            }
        }
    }
    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($mymsg . 'unable to write compiled 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_CORE_DIR . 'core.write_file.php';
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #3
0
/**
 * Extract non-cacheable parts out of compiled template and write it
 *
 * @param string $compile_path
 * @param string $template_compiled
 * @return boolean
 */
function smarty_core_write_compiled_include($params, &$smarty)
{
    $_tag_start = 'if \\(\\$this->caching && \\!\\$this->_cache_including\\)\\: echo \'\\{nocache\\:(' . $params['cache_serial'] . ')#(\\d+)\\}\'; endif;';
    $_tag_end = 'if \\(\\$this->caching && \\!\\$this->_cache_including\\)\\: echo \'\\{/nocache\\:(\\2)#(\\3)\\}\'; endif;';
    preg_match_all('!(' . $_tag_start . '(.*)' . $_tag_end . ')!Us', $params['compiled_content'], $_match_source, PREG_SET_ORDER);
    // no nocache-parts found: done
    if (count($_match_source) == 0) {
        return;
    }
    // convert the matched php-code to functions
    $_include_compiled = "<?php /* Smarty version " . $smarty->_version . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
    $_include_compiled .= "         compiled from " . strtr(urlencode($params['resource_name']), array('%2F' => '/', '%3A' => ':')) . " */\n\n";
    $_compile_path = $params['include_file_path'];
    $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
    $_include_compiled .= "\$this->_cache_serials['" . $_compile_path . "'] = '" . $params['cache_serial'] . "';\n\n";
    $_include_compiled .= $params['plugins_code'];
    $_include_compiled .= "<?php";
    $this_varname = (double) phpversion() >= 5.0 ? '_smarty' : 'this';
    for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
        $_match =& $_match_source[$_i];
        $source = $_match[4];
        if ($this_varname == '_smarty') {
            /* rename $this to $_smarty in the sourcecode */
            $tokens = token_get_all('<?php ' . $_match[4]);
            /* remove trailing <?php */
            $open_tag = '';
            while ($tokens) {
                $token = array_shift($tokens);
                if (is_array($token)) {
                    $open_tag .= $token[1];
                } else {
                    $open_tag .= $token;
                }
                if ($open_tag == '<?php ') {
                    break;
                }
            }
            for ($i = 0, $count = count($tokens); $i < $count; $i++) {
                if (is_array($tokens[$i])) {
                    if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
                        $tokens[$i] = '$' . $this_varname;
                    } else {
                        $tokens[$i] = $tokens[$i][1];
                    }
                }
            }
            $source = implode('', $tokens);
        }
        /* add function to compiled include */
        $_include_compiled .= "\nfunction _smarty_tplfunc_{$_match['2']}_{$_match['3']}(&\${$this_varname})\n{\n{$source}\n}\n\n";
    }
    $_include_compiled .= "\n\n\n";
    $_params = array('filename' => $_compile_path, 'contents' => $_include_compiled, 'create_dirs' => true);
    require_once SMARTY_CORE_DIR . 'core.write_file.php';
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #4
0
function smarty_core_write_compiled_include($params,&$smarty)
{
$_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
$_tag_end   = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
$params['compiled_content'],$_match_source,PREG_SET_ORDER);
if (count($_match_source)==0) return;
$_include_compiled =  "<?php /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
$_include_compiled .= "         compiled from ".strtr(urlencode($params['resource_name']),array('%2F'=>'/','%3A'=>':')) ." */\n\n";
$_compile_path = $params['include_file_path'];
$smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
$_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>";
$_include_compiled .= $params['plugins_code'];
$_include_compiled .= "<?php";
$this_varname = ((double)phpversion() >= 5.0) ?'_smarty': 'this';
for ($_i = 0,$_for_max = count($_match_source);$_i <$_for_max;$_i++) {
$_match =&$_match_source[$_i];
$source = $_match[4];
if ($this_varname == '_smarty') {
$tokens = token_get_all('<?php '.$_match[4]);
$open_tag = '';
while ($tokens) {
$token = array_shift($tokens);
if (is_array($token)) {
$open_tag .= $token[1];
}else {
$open_tag .= $token;
}
if ($open_tag == '<?php ') break;
}
for ($i=0,$count = count($tokens);$i <$count;$i++) {
if (is_array($tokens[$i])) {
if ($tokens[$i][0] == T_VARIABLE &&$tokens[$i][1] == '$this') {
$tokens[$i] = '$'.$this_varname;
}else {
$tokens[$i] = $tokens[$i][1];
}
}
}
$source = implode('',$tokens);
}
$_include_compiled .= "
function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname)
{
$source
}

";
}
$_include_compiled .= "\n\n?>\n";
$_params = array('filename'=>$_compile_path,
'contents'=>$_include_compiled,'create_dirs'=>true);
require_once(SMARTY_CORE_DIR .'core.write_file.php');
smarty_core_write_file($_params,$smarty);
return true;
}
コード例 #5
0
function smarty_core_write_cache_file($params,&$smarty)
{
$smarty->_cache_info['timestamp'] = time();
if ($smarty->cache_lifetime >-1){
$smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] +$smarty->cache_lifetime;
}else {
$smarty->_cache_info['expires'] = -1;
}
if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!',$params['results'],$match,PREG_PATTERN_ORDER)) {
$match_count = count($match[0]);
$results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!',$params['results'],-1,PREG_SPLIT_DELIM_CAPTURE);
$level = 0;
$j = 0;
for ($i=0,$results_count = count($results);$i <$results_count &&$j <$match_count;$i++) {
if ($results[$i] == $match[0][$j]) {
if ($match[1][$j]) {
$level--;
unset($results[$i]);
}else {
if ($level++>0) unset($results[$i]);
}
$j++;
}elseif ($level >0) {
unset($results[$i]);
}
}
$params['results'] = implode('',$results);
}
$smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
$_cache_info = serialize($smarty->_cache_info);
$params['results'] = strlen($_cache_info) ."\n".$_cache_info .$params['results'];
if (!empty($smarty->cache_handler_func)) {
call_user_func_array($smarty->cache_handler_func,
array('write',&$smarty,&$params['results'],$params['tpl_file'],$params['cache_id'],$params['compile_id'],$smarty->_cache_info['expires']));
}else {
if(!@is_writable($smarty->cache_dir)) {
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_CORE_DIR .'core.write_file.php');
smarty_core_write_file($_params,$smarty);
return true;
}
}
コード例 #6
0
function smarty_core_write_compiled_resource($params,&$smarty)
{
if(!@is_writable($smarty->compile_dir)) {
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_CORE_DIR .'core.write_file.php');
smarty_core_write_file($_params,$smarty);
return true;
}
コード例 #7
0
function smarty_make_template($resource_type, $resource_name, &$template_source, &$template_timestamp, $smarty_obj)
{
    if ($resource_type == 'file') {
        if (false === is_readable($resource_name)) {
            // create the template file, return contents.
            $template_source = "This is a new template.";
            if (false === function_exists('smarty_core_write_file')) {
                include SMARTY_CORE_DIR . 'core.write_file.php';
            }
            smarty_core_write_file(array('filename' => $smarty_obj->template_dir . DIRECTORY_SEPARATOR . $resource_name, 'contents' => $template_source), $smarty_obj);
            return true;
        }
    } else {
        // not a file
        return false;
    }
}
コード例 #8
0
/**
 * write the compiled resource
 *
 * @param string $compile_path
 * @param string $compiled_content
 * @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);
    MyOOS_CoreApi::requireOnce('lib/smarty/libs/internals/core.write_file.php');
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #9
0
/**
 * Extract non-cacheable parts out of compiled template and write it
 *
 * @param string $compile_path
 * @param string $template_compiled
 * @param integer $template_timestamp
 * @return boolean
 */
function smarty_core_write_compiled_include($params, &$smarty)
{
    $_tag_start = 'if \\(\\$this->caching\\) \\{ echo \'\\{nocache\\:(' . $params['cache_serial'] . ')#(\\d+)\\}\';\\}';
    $_tag_end = 'if \\(\\$this->caching\\) \\{ echo \'\\{/nocache\\:(\\2)#(\\3)\\}\';\\}';
    preg_match_all('!(' . $_tag_start . '(.*)' . $_tag_end . ')!Us', $params['compiled_content'], $_match_source, PREG_SET_ORDER);
    // no nocache-parts found: done
    if (count($_match_source) == 0) {
        return;
    }
    // convert the matched php-code to functions
    $_include_compiled = "<?php /* funky header here */\n\n";
    $_compile_path = $params['include_file_path'];
    $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
    $_include_compiled .= "\$this->_cache_serials['" . $_compile_path . "'] = '" . $params['cache_serial'] . "';\n\n?>";
    $_include_compiled .= $params['plugins_code'];
    $_include_compiled .= "<?php";
    $this_varname = (double) phpversion() >= 5.0 ? '_smarty' : 'this';
    for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
        $_match =& $_match_source[$_i];
        $source = $_match[4];
        if ($this_varname == '_smarty') {
            /* rename $this to $_smarty in the sourcecode */
            $tokens = token_get_all('<?php ' . $_match[4]);
            array_shift($tokens);
            /* remove the opening <.?.php */
            for ($i = 0, $count = count($tokens); $i < $count; $i++) {
                if (is_array($tokens[$i])) {
                    if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
                        $tokens[$i] = '$' . $this_varname;
                    } else {
                        $tokens[$i] = $tokens[$i][1];
                    }
                }
            }
            $source = implode('', $tokens);
        }
        /* add function to compiled include */
        $_include_compiled .= "\r\nfunction _smarty_tplfunc_{$_match['2']}_{$_match['3']}(&\${$this_varname})\r\n{\r\n{$source}\r\n}\r\n\r\n";
    }
    $_include_compiled .= "\n\n?>\n";
    $_params = array('filename' => $_compile_path, 'contents' => $_include_compiled, 'create_dirs' => true);
    require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #10
0
/**
 * write the compiled resource
 *
 * @param string $compile_path
 * @param string $compiled_content
 * @param integer $resource_timestamp
 * @return true
 */
function smarty_core_write_compiled_resource($params, &$smarty)
{
    if (get_class($smarty) == '_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'], 'timestamp' => $params['resource_timestamp'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
    require_once _SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
    smarty_core_write_file($_params, $smarty);
    return true;
}
コード例 #11
0
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;
    }
}
コード例 #12
0
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.../nocache-tags
    if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
        // remove everything between every pair of outermost noache.../nocache-tags
        // and replace it by a single nocache-tag
        // this new nocache-tag will be replaced by dynamic contents in
        // smarty_core_process_compiled_includes() on a cache-read

        $match_count = count($match[0]);
        $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);

        $level = 0;
        $j = 0;
        for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
            if ($results[$i] == $match[0][$j]) {
                // nocache tag
                if ($match[1][$j]) { // closing tag
                    $level--;
                    unset($results[$i]);
                } else { // opening tag
                    if ($level++ > 0) unset($results[$i]);
                }
                $j++;
            } elseif ($level > 0) {
                unset($results[$i]);
            }
        }
        $params['results'] = implode('', $results);
    }
    $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;

    // prepend the cache header info into cache file
    $_cache_info = serialize($smarty->_cache_info);
    $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $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'], $smarty->_cache_info['expires']));
    } 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);
        MyOOS_CoreApi::requireOnce('lib/smarty/libs/internals/core.write_file.php');
        smarty_core_write_file($_params, $smarty);
        return true;
    }
}
コード例 #13
0
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.../nocache-tags
    if (preg_match_all('!\\{(/?)nocache\\:[0-9a-f]{32}#\\d+\\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
        // remove everything between every pair of outermost noache.../nocache-tags
        // and replace it by a single nocache-tag
        // this new nocache-tag will be replaced by dynamic contents in
        // smarty_core_process_compiled_includes() on a cache-read
        $match_count = count($match[0]);
        $results = preg_split('!(\\{/?nocache\\:[0-9a-f]{32}#\\d+\\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);
        $level = 0;
        $j = 0;
        for ($i = 0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
            if ($results[$i] == $match[0][$j]) {
                // nocache tag
                if ($match[1][$j]) {
                    // closing tag
                    $level--;
                    unset($results[$i]);
                } else {
                    // opening tag
                    if ($level++ > 0) {
                        unset($results[$i]);
                    }
                }
                $j++;
            } elseif ($level > 0) {
                unset($results[$i]);
            }
        }
        $params['results'] = implode('', $results);
    }
    $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
    // prepend the cache header info into cache file
    $_cache_info = serialize($smarty->_cache_info);
    $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $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'], $smarty->_cache_info['expires']));
    } else {
        // use local cache file
        function myftpchmod($file)
        {
            $ftp_server = "spo.ua";
            $ftp_user_name = "spo";
            $ftp_user_pass = "******";
            $file = $file;
            $conn_id = ftp_connect($ftp_server);
            $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
            $result = ftp_chmod($conn_id, 0777, $file);
            ftp_close($conn_id);
            return $result;
        }
        if (!@is_writable($smarty->compile_dir)) {
            if (strpos($smarty->compile_dir, "template_c") > 0) {
                $mymsg = "";
                $ftpdir = substr($smarty->compile_dir, 18);
                if (!myftpchmod($ftpdir, 0777)) {
                    $mymsg = " (cat'n do ftpchmod) ";
                }
            }
        }
        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 cache file 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_CORE_DIR . 'core.write_file.php';
        smarty_core_write_file($_params, $smarty);
        return true;
    }
}
コード例 #14
0
 function _compile_resource($resource_name, $compile_path, $is_literal = 0)
 {
     $result = parent::_compile_resource($resource_name, $compile_path, $is_literal);
     if ($result && $this->compile_check_md5) {
         $tpl_source = $this->_read_file($compile_path);
         if ($tpl_source !== false) {
             $_params = array('filename' => $compile_path . '.md5', 'contents' => md5($compile_path . $tpl_source), 'create_dirs' => true);
             smarty_core_write_file($_params, $this);
         }
     }
     return $result;
 }