Start logging of compile time

@param \Smarty_Internal_Template $template
773178
public function start_compile(Smarty_Internal_Template $template)
    {
        static $_is_stringy = array('string' => true, 'eval' => true);
        if (!empty($template->compiler->trace_uid)) {
            $key = $template->compiler->trace_uid;
            if (!isset($this->template_data[$this->index][$key])) {
                if (isset($_is_stringy[$template->source->type])) {
                    $this->template_data[$this->index][$key]['name'] =
                        '\'' . substr($template->source->name, 0, 25) . '...\'';
                } else {
                    $this->template_data[$this->index][$key]['name'] = $template->source->filepath;
                }
                $this->template_data[$this->index][$key]['compile_time'] = 0;
                $this->template_data[$this->index][$key]['render_time'] = 0;
                $this->template_data[$this->index][$key]['cache_time'] = 0;
            }
        } else {
            if (isset($this->ignore_uid[$template->source->uid])) {
                return;
            }
            $key = $this->get_key($template);
        }
        $this->template_data[$this->index][$key]['start_time'] = microtime(true);
    }
599843
public static function start_render($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['start_time'] = microtime(true);
    }
1175952
public function setTemplate(Template $template = null)
	{
		if ($this->writeOnce($this->template, $template)) {
			$this->template->addTemplateLayout($this);
		}
	}
125449
public function write(Smarty_Internal_Template $_template, $content)
    {
        if (!$_template->source->recompiled) {
            if ($this->handler->writeCachedContent($_template, $content)) {
                $this->content = null;
                $this->timestamp = time();
                $this->exists = true;
                $this->valid = true;
                if ($_template->smarty->cache_locking) {
                    $this->handler->releaseLock($_template->smarty, $this);
                }

                return true;
            }
        }

        return false;
    }
746146
protected function compiled($template)
    {
        $template = ltrim($template, '/');
        if (strrchr($template, '.') == $this->extension)
            $template = substr($template, 0, -strlen($this->extension));
        $file = $this->dir . DIRECTORY_SEPARATOR . $template . $this->extension;
        if (!is_file($file))
            throw new \RuntimeException("template not found:$file!");

        $modified = filemtime($file);
        $compiled = $this->temp . DIRECTORY_SEPARATOR . $template . ".{$modified}.php";
        if (!$this->debug && is_file($compiled) && filemtime($compiled) >= $modified)
            return $compiled;

        $content = self::compile(file_get_contents($file), $this->left, $this->right);
        self::writeFile($compiled, $content, $this->temp);

        return $compiled;
    }
1171771
public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
    {
        if ($this->isCached($_template)) {
            if ($_template->smarty->debugging) {
                $_template->smarty->_debug->start_cache($_template);
            }
            if (!$this->processed) {
                $this->process($_template);
            }
            $this->getRenderedTemplateCode($_template);
            if ($_template->smarty->debugging) {
                $_template->smarty->_debug->end_cache($_template);
            }
            return;
        } else {
            $_template->smarty->ext->_updateCache->updateCache($this, $_template, $no_output_filter);
        }
    }
976012
function SmartTemplate ( $template_filename = '' )
		{
			global $_CONFIG;

			if (!empty($_CONFIG['smarttemplate_compiled']))
			{
				$this->temp_dir  =  $_CONFIG['smarttemplate_compiled'];
			}
			if (!empty($_CONFIG['smarttemplate_cache']))
			{
				$this->cache_dir  =  $_CONFIG['smarttemplate_cache'];
			}
			if (is_numeric($_CONFIG['cache_lifetime']))
			{
				$this->cache_lifetime  =  $_CONFIG['cache_lifetime'];
			}
			if (!empty($_CONFIG['template_dir'])  &&  is_file($_CONFIG['template_dir'] . '/' . $template_filename))
			{
				$this->template_dir  =  $_CONFIG['template_dir'];
			}
			$this->tpl_file  =  $template_filename;
		}
561319
private function validateTwigTemplate($template)
    {
        $loader = $this->twig->getLoader();
        if (!$loader->exists($template)) {
            throw new \Exception(sprintf(
                'Unable to find template "%s".',
                $template
            ));
        }
    }
1287884
public function compileTemplateSource()
    {
        if (!$this->source->recompiled) {
            $this->properties['file_dependency'] = array();
            if ($this->source->components) {
                // for the extends resource the compiler will fill it
                // uses real resource for file dependency
                // $source = end($this->source->components);
                // $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
            } else {
                $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
            }
        }
        // compile locking
        if ($this->smarty->compile_locking && !$this->source->recompiled) {
            if ($saved_timestamp = $this->compiled->timestamp) {
                touch($this->compiled->filepath);
            }
        }
        // call compiler
        try {
            $code = $this->compiler->compileTemplate($this);
        }
        catch (Exception $e) {
            // restore old timestamp in case of error
            if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
                touch($this->compiled->filepath, $saved_timestamp);
            }
            throw $e;
        }
        // compiling succeded
        if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
            // write compiled template
            $_filepath = $this->compiled->filepath;
            if ($_filepath === false) {
                throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
            }
            Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
            $this->compiled->exists = true;
            $this->compiled->isCompiled = true;
        }
        // release compiler object to free memory
        unset($this->compiler);
    }
58328
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
    {
        if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
            $_template->cached->timestamp = filemtime($_template->cached->filepath);
            $_template->cached->exists = !!$_template->cached->timestamp;
            return true;
        }
        return false;
    }
30370
public static function start_cache($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['start_time'] = microtime(true);
    }
370889
public static function compileTemplate(&$context, $template) {
        array_unshift($context['parsed'], array());
        Validator::verify($context, $template);
        static::$lastParsed = $context['parsed'];

        if (count($context['error'])) {
            return;
        }

        Parser::setDelimiter($context);

        $context['compile'] = true;

        // Handle dynamic partials
        Partial::handleDynamic($context);

        // Do PHP code generation.
        $code = '';
        foreach ($context['parsed'][0] as $info) {
            if (is_array($info)) {
                $context['tokens']['current']++;
                $code .= "'" . static::compileToken($context, $info) . "'";
            } else {
                $code .= $info;
            }
        }

        array_shift($context['parsed']);

        return $code;
    }
43389
public function compile(Core $core, ITemplate $template)
    {
        // init vars
        //		$compiled = '';
        $tpl                  = $template->getSource();
        $ptr                  = 0;
        $this->core           = $core;
        $this->template       = $template;
        $this->templateSource = &$tpl;
        $this->pointer        = &$ptr;

        while (true) {
            // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed
            if ($ptr === 0) {
                // resets variables
                $this->usedPlugins     = array();
                $this->data            = array();
                $this->scope           = &$this->data;
                $this->scopeTree       = array();
                $this->stack           = array();
                $this->line            = 1;
                $this->templatePlugins = array();
                // add top level block
                $compiled                 = $this->addBlock('TopLevelBlock', array(), 0);
                $this->stack[0]['buffer'] = '';

                if ($this->debug) {
                    echo "\n";
                    echo 'COMPILER INIT' . "\n";
                }

                if ($this->debug) {
                    echo 'PROCESSING PREPROCESSORS (' . count($this->processors['pre']) . ')' . "\n";
                }

                // runs preprocessors
                foreach ($this->processors['pre'] as $preProc) {
                    if (is_array($preProc) && isset($preProc['autoload'])) {
                        $preProc = $this->loadProcessor($preProc['class'], $preProc['name']);
                    }
                    if (is_array($preProc) && $preProc[0] instanceof Processor) {
                        $tpl = call_user_func($preProc, $tpl);
                    } else {
                        $tpl = call_user_func($preProc, $this, $tpl);
                    }
                }
                unset($preProc);

                // show template source if debug
                if ($this->debug) {
                    echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>'."\n";
                }

                // strips php tags if required by the security policy
                if ($this->securityPolicy !== null) {
                    $search = array('{<\?php.*?\?>}');
                    if (ini_get('short_open_tags')) {
                        $search = array('{<\?.*?\?>}', '{<%.*?%>}');
                    }
                    switch ($this->securityPolicy->getPhpHandling()) {
                        case SecurityPolicy::PHP_ALLOW:
                            break;
                        case SecurityPolicy::PHP_ENCODE:
                            $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
                            break;
                        case SecurityPolicy::PHP_REMOVE:
                            $tpl = preg_replace($search, '', $tpl);
                    }
                }
            }

            $pos = strpos($tpl, $this->ld, $ptr);

            if ($pos === false) {
                $this->push(substr($tpl, $ptr), 0);
                break;
            } elseif (substr($tpl, $pos - 1, 1) === '\\' && substr($tpl, $pos - 2, 1) !== '\\') {
                $this->push(substr($tpl, $ptr, $pos - $ptr - 1) . $this->ld);
                $ptr = $pos + strlen($this->ld);
            } elseif (preg_match('/^' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', substr($tpl, $pos), $litOpen)) {
                if (!preg_match('/' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
                    throw new CompilationException($this, 'The {literal} blocks must be closed explicitly with {/literal}');
                }
                $endpos = $litClose[0][1];
                $this->push(substr($tpl, $ptr, $pos - $ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos - $pos - strlen($litOpen[0])));
                $ptr = $endpos + strlen($litClose[0][0]);
            } else {
                if (substr($tpl, $pos - 2, 1) === '\\' && substr($tpl, $pos - 1, 1) === '\\') {
                    $this->push(substr($tpl, $ptr, $pos - $ptr - 1));
                    $ptr = $pos;
                }

                $this->push(substr($tpl, $ptr, $pos - $ptr));
                $ptr = $pos;

                $pos += strlen($this->ld);
                if ($this->allowLooseOpenings) {
                    while (substr($tpl, $pos, 1) === ' ') {
                        $pos += 1;
                    }
                } else {
                    if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") {
                        $ptr = $pos;
                        $this->push($this->ld);
                        continue;
                    }
                }

                // check that there is an end tag present
                if (strpos($tpl, $this->rd, $pos) === false) {
                    throw new CompilationException($this, 'A template tag was not closed, started with "' . substr($tpl, $ptr, 30) . '"');
                }

                $ptr += strlen($this->ld);
                $subptr = $ptr;

                while (true) {
                    $parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr);

                    // reload loop if the compiler was reset
                    if ($ptr === 0) {
                        continue 2;
                    }

                    $len = $subptr - $ptr;
                    $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n"));
                    $ptr += $len;

                    if ($parsed === false) {
                        break;
                    }
                }
            }
        }

        $compiled .= $this->removeBlock('TopLevelBlock');

        if ($this->debug) {
            echo 'PROCESSING POSTPROCESSORS' . "\n";
        }

        foreach ($this->processors['post'] as $postProc) {
            if (is_array($postProc) && isset($postProc['autoload'])) {
                $postProc = $this->loadProcessor($postProc['class'], $postProc['name']);
            }
            if (is_array($postProc) && $postProc[0] instanceof Processor) {
                $compiled = call_user_func($postProc, $compiled);
            } else {
                $compiled = call_user_func($postProc, $this, $compiled);
            }
        }
        unset($postProc);

        if ($this->debug) {
            echo 'COMPILATION COMPLETE : MEM USAGE : ' . memory_get_usage() . "\n";
        }

        $output = "<?php\n/* template head */\n";

        // build plugin preloader
        foreach ($this->getUsedPlugins() as $plugin => $type) {
            if ($type & Core::CUSTOM_PLUGIN) {
                continue;
            }

            switch ($type) {
                case Core::CLASS_PLUGIN:
                case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
                    if (class_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
                    if (class_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::FUNC_PLUGIN:
                    if (function_exists('Plugin' . $plugin) !== false) {
                        $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    } else {
                        $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
                    }
                    break;
                case Core::SMARTY_MODIFIER:
                    $output .= "if (function_exists('smarty_modifier_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::SMARTY_FUNCTION:
                    $output .= "if (function_exists('smarty_function_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::SMARTY_BLOCK:
                    $output .= "if (function_exists('smarty_block_$plugin')===false)".
                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
                    break;
                case Core::PROXY_PLUGIN:
                    $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
                    break;
                default:
                    throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
            }
        }

        foreach ($this->templatePlugins as $function => $attr) {
            if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) {
                $this->resolveSubTemplateDependencies($function);
            }
        }
        foreach ($this->templatePlugins as $function) {
            if (isset($function['called']) && $function['called'] === true) {
                $output .= $function['body'] . PHP_EOL;
            }
        }

        $output .= $compiled . "\n?>";

        $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*' . preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/') . ')/', ";\n", $output);
        $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);

        // handle <?xml tag at the beginning
        $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output);

        // add another line break after PHP closing tags that have a line break following,
        // as we do not know whether it's intended, and PHP will strip it otherwise
        $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output);

        if ($this->debug) {
            echo '=============================================================================================' . "\n";
            $lines = preg_split('{\r\n|\n|<br />}', $output);
            array_shift($lines);
            foreach ($lines as $i => $line) {
                echo ($i + 1) . '. ' . $line . "\r\n";
            }
            echo '=============================================================================================' . "\n";
        }

        $this->template = $this->dwoo = null;
        $tpl            = null;

        return $output;
    }
570943
public function onParseTemplate(Template $template): void
    {
        if (!$this->environment->isEnabled()) {
            return;
        }

        $this->initialize();
        if ($this->isAutoMappingDisabled($template->getName())) {
            return;
        }

        $templateName = $this->getMappedTemplateName($template->getName());
        if ($templateName) {
            $template->setName($templateName);
        }
    }
40965
public static function end_cache($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
    }
749890
public function initiate($template = null, $data = null, $templateRootFolder = ERDIKO_APP)
    {
        $template = ($template === null) ? $this->getDefaultTemplate() : $template;
        $this->setTemplate($template);
        $this->setData($data);
        $this->setTemplateRootFolder($templateRootFolder);
    }
879907
public function write(Smarty_Internal_Template $_template, $code)
    {
        if (!$_template->source->handler->recompiled) {
            if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) {
                $this->timestamp = $this->exists = is_file($this->filepath);
                if ($this->exists) {
                    $this->timestamp = filemtime($this->filepath);
                    return true;
                }
            }
            return false;
        } else {
            $this->content = $code;
        }
        $this->timestamp = time();
        $this->exists = true;
        return true;
    }