Exemple #1
0
function nel_parse_template($template, $subdirectory, $render, $regen)
{
    if (!empty($subdirectory)) {
        $subdirectory .= '/';
    }
    $template_short = utf8_str_replace('.tpl', '', $template);
    $info = nel_template_info($template, NULL, NULL, TRUE);
    if (is_null($info) || $info['loaded'] === FALSE || $info['loaded'] === NULL) {
        clearstatcache();
        $modify_time = filemtime(TEMPLATE_PATH . $subdirectory . $template);
        if (!isset($info['modify_time']) || $modify_time !== $info['modify_time'] || !file_exists(CACHE_PATH . $template_short . '.nelcache')) {
            $info['modify-time'] = $modify_time;
            $lol = file_get_contents(TEMPLATE_PATH . $subdirectory . $template);
            $lol = trim($lol);
            $begin = '<?php function nel_template_render_' . $template_short . '($render) { $temp = \'';
            // Start of the cached template
            $lol = preg_replace_callback('#({{.*?}})|({(.*?)})|(\')#', 'nel_escape_single_quotes', $lol);
            // Do escaping and variable parse
            $lol = preg_replace('#(})\\s*?({)#', '$1$2', $lol);
            // Clear white space between control statements
            $lol = preg_replace('#{{\\s*?(if|elseif|foreach|for|while)\\s*?(.*?)}}#', '\'; $1($2): $temp .= \'', $lol);
            // Parse opening control statements
            $lol = preg_replace('#{{\\s*?else\\s*?}}#', '\'; else: $temp .= \'', $lol);
            // Parse else statements
            $lol = preg_replace('#{{\\s*?(endif|endforeach|endfor|endwhile|endswitch)\\s*?}}#', '\'; $1; $temp .= \'', $lol);
            // Parse closing control statements
            $lol = preg_replace('#{{{\\s*?(.*?)\\s*?}}}#', '\'; $1; $temp .= \'', $lol);
            // Parse other PHP code
            $end = '\'; return $temp; } ?>';
            // End of the caches template
            $lol_out = $begin . $lol . $end;
            nel_write_file(CACHE_PATH . $template_short . '.nelcache', $lol_out, 0644);
        }
        include CACHE_PATH . $template_short . '.nelcache';
        $info['loaded'] = TRUE;
        nel_template_info($template, NULL, $info, FALSE);
    }
    if (!$regen) {
        $dat_temp = call_user_func('nel_template_render_' . $template_short, $render);
        return $dat_temp;
    }
}
function nel_write_multi_cache($dataforce)
{
    $template_info = nel_template_info(NULL, NULL, NULL, TRUE);
    $template_info = nel_reset_template_status($template_info);
    $cache = '<?php
$dataforce[\'post_links\'] = \'' . $dataforce['post_links'] . '\';
$dataforce[\'rules_list\'] = \'' . $dataforce['rules_list'] . '\';
$template_info = ' . var_export($template_info, TRUE) . ';
nel_template_info(NULL, NULL, $template_info, FALSE);
?>';
    nel_write_file(CACHE_PATH . 'multi-cache.nelcache', $cache, 0644);
}