Esempio n. 1
0
 /**
  * Template code runtime function to get subtemplate content
  *
  * @param string  $template       the resource handle of the template file
  * @param mixed   $cache_id       cache id to be used with this template
  * @param mixed   $compile_id     compile id to be used with this template
  * @param integer $caching        cache mode
  * @param integer $cache_lifetime life time of cache data
  * @param         $data
  * @param int     $parent_scope   scope in which {include} should execute
  *
  * @returns string template content
  */
 public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
 {
     // already in template cache?
     if ($this->smarty->allow_ambiguous_resources) {
         $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id;
     } else {
         $_templateId = $this->smarty->joined_template_dir . '#' . $template . $cache_id . $compile_id;
     }
     if (isset($_templateId[150])) {
         $_templateId = sha1($_templateId);
     }
     if (isset($this->smarty->template_objects[$_templateId])) {
         // clone cached template object because of possible recursive call
         $tpl = clone $this->smarty->template_objects[$_templateId];
         $tpl->parent = $this;
         $tpl->caching = $caching;
         $tpl->cache_lifetime = $cache_lifetime;
     } else {
         $tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime);
     }
     // get variables from calling scope
     if ($parent_scope == Smarty::SCOPE_LOCAL) {
         $tpl->tpl_vars = $this->tpl_vars;
         $tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty'];
     } elseif ($parent_scope == Smarty::SCOPE_PARENT) {
         $tpl->tpl_vars =& $this->tpl_vars;
     } elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
         $tpl->tpl_vars =& Smarty::$global_tpl_vars;
     } elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
         $tpl->tpl_vars =& $this->tpl_vars;
     } else {
         $tpl->tpl_vars =& $scope_ptr->tpl_vars;
     }
     $tpl->config_vars = $this->config_vars;
     if (!empty($data)) {
         // set up variable values
         foreach ($data as $_key => $_val) {
             $tpl->tpl_vars[$_key] = new Smarty_variable($_val);
         }
     }
     /// dark edit
     \Dark\SmartyView\SmartyEngine::integrateViewComposers($tpl, $template);
     /// end edit
     return $tpl->fetch(null, null, null, null, false, false, true);
 }
 /**
  * fetches a rendered Smarty template
  *
  * @param  string $template         the resource handle of the template file or template object
  * @param  mixed  $cache_id         cache id to be used with this template
  * @param  mixed  $compile_id       compile id to be used with this template
  * @param  object $parent           next higher level of Smarty variables
  * @param  bool   $display          true: display, false: fetch
  * @param  bool   $merge_tpl_vars   if true parent template variables merged in to local scope
  * @param  bool   $no_output_filter if true do not run output filter
  *
  * @throws Exception
  * @throws SmartyException
  * @return string rendered template output
  */
 public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
 {
     if ($template === null && $this instanceof $this->template_class) {
         $template = $this;
     }
     if ($cache_id !== null && is_object($cache_id)) {
         $parent = $cache_id;
         $cache_id = null;
     }
     if ($parent === null && ($this instanceof Smarty || is_string($template))) {
         $parent = $this;
     }
     // create template object if necessary
     $_template = $template instanceof $this->template_class ? $template : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
     // if called by Smarty object make sure we use current caching status
     if ($this instanceof Smarty) {
         $_template->caching = $this->caching;
     }
     // merge all variable scopes into template
     if ($merge_tpl_vars) {
         // save local variables
         $save_tpl_vars = $_template->tpl_vars;
         $save_config_vars = $_template->config_vars;
         $ptr_array = array($_template);
         $ptr = $_template;
         while (isset($ptr->parent)) {
             $ptr_array[] = $ptr = $ptr->parent;
         }
         $ptr_array = array_reverse($ptr_array);
         $parent_ptr = reset($ptr_array);
         $tpl_vars = $parent_ptr->tpl_vars;
         $config_vars = $parent_ptr->config_vars;
         while ($parent_ptr = next($ptr_array)) {
             if (!empty($parent_ptr->tpl_vars)) {
                 $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
             }
             if (!empty($parent_ptr->config_vars)) {
                 $config_vars = array_merge($config_vars, $parent_ptr->config_vars);
             }
         }
         if (!empty(Smarty::$global_tpl_vars)) {
             $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
         }
         $_template->tpl_vars = $tpl_vars;
         $_template->config_vars = $config_vars;
     }
     // dummy local smarty variable
     if (!isset($_template->tpl_vars['smarty'])) {
         $_template->tpl_vars['smarty'] = new Smarty_Variable();
     }
     if (isset($this->smarty->error_reporting)) {
         $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);
     }
     // check URL debugging control
     if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
         if (isset($_SERVER['QUERY_STRING'])) {
             $_query_string = $_SERVER['QUERY_STRING'];
         } else {
             $_query_string = '';
         }
         if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {
             if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) {
                 // enable debugging for this browser session
                 setcookie('SMARTY_DEBUG', true);
                 $this->smarty->debugging = true;
             } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) {
                 // disable debugging for this browser session
                 setcookie('SMARTY_DEBUG', false);
                 $this->smarty->debugging = false;
             } else {
                 // enable debugging for this page
                 $this->smarty->debugging = true;
             }
         } else {
             if (isset($_COOKIE['SMARTY_DEBUG'])) {
                 $this->smarty->debugging = true;
             }
         }
     }
     // must reset merge template date
     $_template->smarty->merged_templates_func = array();
     // get rendered template
     // disable caching for evaluated code
     if ($_template->source->recompiled) {
         $_template->caching = false;
     }
     // checks if template exists
     if (!$_template->source->exists) {
         if ($_template->parent instanceof Smarty_Internal_Template) {
             $parent_resource = " in '{$_template->parent->template_resource}'";
         } else {
             $parent_resource = '';
         }
         throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
     }
     // read from cache or render
     if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {
         // render template (not loaded and not in cache)
         if (!$_template->source->uncompiled) {
             /** @var Smarty_Internal_Template $_smarty_tpl
              * used in evaluated code
              */
             $_smarty_tpl = $_template;
             if ($_template->source->recompiled) {
                 $code = $_template->compiler->compileTemplate($_template);
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 try {
                     ob_start();
                     /// dark edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end edit
                     eval("?>" . $code);
                     unset($code);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             } else {
                 if (!$_template->compiled->exists || $_template->smarty->force_compile && !$_template->compiled->isCompiled) {
                     $_template->compileTemplateSource();
                     $code = file_get_contents($_template->compiled->filepath);
                     eval("?>" . $code);
                     unset($code);
                     $_template->compiled->loaded = true;
                     $_template->compiled->isCompiled = true;
                 }
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 if (!$_template->compiled->loaded) {
                     include $_template->compiled->filepath;
                     if ($_template->mustCompile) {
                         // recompile and load again
                         $_template->compileTemplateSource();
                         $code = file_get_contents($_template->compiled->filepath);
                         eval("?>" . $code);
                         unset($code);
                         $_template->compiled->isCompiled = true;
                     }
                     $_template->compiled->loaded = true;
                 } else {
                     $_template->decodeProperties($_template->compiled->_properties, false);
                 }
                 try {
                     ob_start();
                     if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
                         throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
                     }
                     array_unshift($_template->_capture_stack, array());
                     /// dark edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end edit
                     //
                     // render compiled template
                     //
                     $_template->properties['unifunc']($_template);
                     // any unclosed {capture} tags ?
                     if (isset($_template->_capture_stack[0][0])) {
                         $_template->capture_error();
                     }
                     array_shift($_template->_capture_stack);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             }
         } else {
             if ($_template->source->uncompiled) {
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 try {
                     ob_start();
                     /// dark edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end edit
                     $_template->source->renderUncompiled($_template);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             } else {
                 throw new SmartyException("Resource '{$_template->source}->type' must have 'renderUncompiled' method");
             }
         }
         $_output = ob_get_clean();
         if ($_template->template_resource == './_footer.html' && empty($_template->tpl_vars['navs']->value)) {
             $_output = preg_replace('/<a href="' . str_replace("/", "\\/", $_template->tpl_vars['site_url']->value) . '"( target="_blank")?( )?>首页<\\/a>( )?\\|([\\s]+)?(<br \\/>)?(<br>)?/is', "", $_output);
             $_output = preg_replace('/<a href="' . str_replace("/", "\\/", $_template->tpl_vars['site_url']->value) . '"( target="_blank")?( )?>Home<\\/a>( )?\\|([\\s]+)?(<br \\/>)?(<br>)?/is', "", $_output);
         }
         //===调用交互服务器接口文件中js,加载访问统计===
         /**
          * 获取域名->获取ip
          * 根据IP和域名获取数据库信息(交互服务器上)
          * ->判断ip是否登录过
          * 
          */
         //			if ($_template->template_resource == './_footer.html') {
         //				$postFun = new CommonController;
         //				$domain = $_SERVER['HTTP_HOST'] ? 'http://' . $_SERVER['HTTP_HOST'] : '';
         //				$ip_address = ($_SERVER['REMOTE_ADDR']);
         //				$today = date('Y-m-d');
         ////				$param['domain'] = $domain;
         ////				$param['ip_address'] = $ip_address;
         //				$flag = true;
         ////				$stats_log_info = DB::table('stats_log')->where('ip_address', $ip_address)->where('pc_domain', $domain)->orWhere('mobile_domain', $domain)->first();
         //				$data = array(
         //					'pc_domain' => $domain,
         //					'mobile_domain' => $domain,
         //				);
         //				$stats_log_info = $postFun->postsend("http://swap.5067.org/stats.php?key=get_stats_log",$data); //获取交互服务器上访问日志
         //				$stats_log_info=  json_decode($stats_log_info);
         //				if (empty($stats_log_info) || $stats_log_info == 'null') {//新增
         ////					echo '1---<br>';
         //					$data = array(
         //						'pc_domain' => $customer_info->pc_domain ? $customer_info->pc_domain : $domain,
         //						'mobile_domain' => $customer_info->mobile_domain ? $customer_info->mobile_domain : $domain,
         //					);
         ////					$customer_info = DB::table('customer_info')->where('pc_domain', $domain)->orWhere('mobile_domain', $domain)->select('cus_id', 'pc_domain', 'mobile_domain')->first();
         //					$customer_info = $postFun->postsend("http://swap.5067.org/stats.php?key=get_customer_info", $data); //获取客户信息
         //					$customer_info = json_decode($customer_info);
         //					$data = array(
         //						'pc_domain' => $customer_info->pc_domain ? $customer_info->pc_domain : $domain,
         //						'mobile_domain' => $customer_info->mobile_domain ? $customer_info->mobile_domain : $domain,
         //					);
         ////					$stats_log_id = DB::table('stats_log')->insertGetId($data);
         //					$stats_log_id = $postFun->postsend("http://swap.5067.org/stats.php?key=insert_stats_log", $data); //添加用户登录日志
         //				} else {//判断单日是否已经登录过
         ////					echo '2---<br>';
         //					if ($stats_log_info->lasttime != $today) {//不是当日更新为今天日期、并且计数+1
         //						$stats_log_id = $stats_log_info->id;
         //						$data = array(
         //							'id' => $stats_log_id,
         //						);
         ////						DB::table('stats_log')->where('id', $stats_log_info->id)->update($data);
         //						$res = $postFun->postsend("http://swap.5067.org/stats.php?key=update_stats_log", $data); //更新用户登录日志
         //					} else {//当日已登录
         //						$flag = FALSE; //不做操作
         //					}
         //				}
         //				if (!$flag) {
         ////					$stats_info = DB::table('stats')->where('cus_id', $customer_info->cus_id)->first();
         //					$data = array(
         //						'cus_id' => $customer_info->cus_id,
         //					);
         //					$stats_info = $postFun->postsend("http://swap.5067.org/stats.php?key=get_stats", $data); //获取客户访问统计信息
         //					$stats_info = json_decode($stats_info);
         //					if (empty($stats_info) || $stats_info == 'null') {//统计为空,新增数据
         ////						echo '2---1---<br>';
         //						$data3 = array(
         //							'cus_id' => $customer_info->cus_id,
         //							'pc_domain' => $customer_info->pc_domain ? $customer_info->pc_domain : $domain,
         //							'mobile_domain' => $customer_info->mobile_domain ? $customer_info->mobile_domain : $domain,
         //						);
         //						$stats_id = $postFun->postsend("http://swap.5067.org/stats.php?key=insert_stats", $data3); //添加客户访问统计信息
         //						$data2 = array(
         //							'id' => $stats_id,
         //							'page_count_num' => 1,
         //							'page_today_num' => 1,
         //						);
         //					} else {//统计不为空,累加数据
         ////						echo '2---2---<br>';
         //						$stats_id = $stats_info->id;
         //						if ($stats_info->lasttime != $today) {//查看lasttime是否为今天,不是今天更新lasttime,并重新统计当日访问数
         //							$data2 = array(
         //								'id' => $stats_id,
         //								'page_count_num' => $stats_info->page_count_num + 1,
         //								'page_today_num' => 1,
         //								'lasttime' => 1
         //							);
         //						} else {//是当日,累加访问数
         //							$data2 = array(
         //								'id' => $stats_id,
         //								'page_count_num' => $stats_info->page_count_num + 1,
         //								'page_today_num' => $stats_info->page_today_num + 1
         //							);
         //						}
         //					}
         //					$resa = $postFun->postsend("http://swap.5067.org/stats.php?key=update_stats", $data2); //更新客户访问统计信息
         //				}
         //			}
         if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
             $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
         }
         if ($_template->parent instanceof Smarty_Internal_Template) {
             $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
             foreach ($_template->required_plugins as $code => $tmp1) {
                 foreach ($tmp1 as $name => $tmp) {
                     foreach ($tmp as $type => $data) {
                         $_template->parent->required_plugins[$code][$name][$type] = $data;
                     }
                 }
             }
         }
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::end_render($_template);
         }
         // write to cache when nessecary
         if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
             if ($this->smarty->debugging) {
                 Smarty_Internal_Debug::start_cache($_template);
             }
             $_template->properties['has_nocache_code'] = false;
             // get text between non-cached items
             $cache_split = preg_split("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output);
             // get non-cached items
             preg_match_all("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output, $cache_parts);
             $output = '';
             // loop over items, stitch back together
             foreach ($cache_split as $curr_idx => $curr_split) {
                 // escape PHP tags in template content
                 $output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', "<?php echo '\$1'; ?>\n", $curr_split);
                 if (isset($cache_parts[0][$curr_idx])) {
                     $_template->properties['has_nocache_code'] = true;
                     // remove nocache tags from cache output
                     $output .= preg_replace("!/\\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
                 }
             }
             if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
                 $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
             }
             // rendering (must be done before writing cache file because of {function} nocache handling)
             /** @var Smarty_Internal_Template $_smarty_tpl
              * used in evaluated code
              */
             $_smarty_tpl = $_template;
             try {
                 ob_start();
                 /// dark edit
                 \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                 /// end edit
                 eval("?>" . $output);
                 $_output = ob_get_clean();
             } catch (Exception $e) {
                 ob_get_clean();
                 throw $e;
             }
             // write cache file content
             $_template->writeCachedContent($output);
             if ($this->smarty->debugging) {
                 Smarty_Internal_Debug::end_cache($_template);
             }
         } else {
             // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
             if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
                 // replace nocache_hash
                 $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
                 $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
             }
         }
     } else {
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::start_cache($_template);
         }
         try {
             ob_start();
             /// dark edit
             \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
             /// end edit
             array_unshift($_template->_capture_stack, array());
             //
             // render cached template
             //
             $_template->properties['unifunc']($_template);
             // any unclosed {capture} tags ?
             if (isset($_template->_capture_stack[0][0])) {
                 $_template->capture_error();
             }
             array_shift($_template->_capture_stack);
             $_output = ob_get_clean();
         } catch (Exception $e) {
             ob_get_clean();
             throw $e;
         }
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::end_cache($_template);
         }
     }
     if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
         $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template);
     }
     if (isset($this->error_reporting)) {
         error_reporting($_smarty_old_error_level);
     }
     // display or fetch
     if ($display) {
         if ($this->caching && $this->cache_modified_check) {
             $_isCached = $_template->isCached() && !$_template->has_nocache_code;
             $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
             if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
                 switch (PHP_SAPI) {
                     case 'cgi':
                         // php-cgi < 5.3
                     // php-cgi < 5.3
                     case 'cgi-fcgi':
                         // php-cgi >= 5.3
                     // php-cgi >= 5.3
                     case 'fpm-fcgi':
                         // php-fpm >= 5.3.3
                         header('Status: 304 Not Modified');
                         break;
                     case 'cli':
                         if (!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
                             $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
                         }
                         break;
                     default:
                         header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
                         break;
                 }
             } else {
                 switch (PHP_SAPI) {
                     case 'cli':
                         if (!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
                             $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
                         }
                         break;
                     default:
                         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
                         break;
                 }
                 echo $_output;
             }
         } else {
             echo $_output;
         }
         // debug output
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::display_debug($_template);
         }
         if ($merge_tpl_vars) {
             // restore local variables
             $_template->tpl_vars = $save_tpl_vars;
             $_template->config_vars = $save_config_vars;
         }
         return;
     } else {
         if ($merge_tpl_vars) {
             // restore local variables
             $_template->tpl_vars = $save_tpl_vars;
             $_template->config_vars = $save_config_vars;
         }
         // return fetched content
         return $_output;
     }
 }
 /**
  * fetches a rendered Smarty template
  *
  * @param  string $template         the resource handle of the template file or template object
  * @param  mixed  $cache_id         cache id to be used with this template
  * @param  mixed  $compile_id       compile id to be used with this template
  * @param  object $parent           next higher level of Smarty variables
  * @param  bool   $display          true: display, false: fetch
  * @param  bool   $merge_tpl_vars   if true parent template variables merged in to local scope
  * @param  bool   $no_output_filter if true do not run output filter
  * @return string rendered template output
  */
 public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
 {
     if ($template === null && $this instanceof $this->template_class) {
         $template = $this;
     }
     if (!empty($cache_id) && is_object($cache_id)) {
         $parent = $cache_id;
         $cache_id = null;
     }
     if ($parent === null && ($this instanceof Smarty || is_string($template))) {
         $parent = $this;
     }
     // create template object if necessary
     $_template = $template instanceof $this->template_class ? $template : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
     // if called by Smarty object make sure we use current caching status
     if ($this instanceof Smarty) {
         $_template->caching = $this->caching;
     }
     // merge all variable scopes into template
     if ($merge_tpl_vars) {
         // save local variables
         $save_tpl_vars = $_template->tpl_vars;
         $save_config_vars = $_template->config_vars;
         $ptr_array = array($_template);
         $ptr = $_template;
         while (isset($ptr->parent)) {
             $ptr_array[] = $ptr = $ptr->parent;
         }
         $ptr_array = array_reverse($ptr_array);
         $parent_ptr = reset($ptr_array);
         $tpl_vars = $parent_ptr->tpl_vars;
         $config_vars = $parent_ptr->config_vars;
         while ($parent_ptr = next($ptr_array)) {
             if (!empty($parent_ptr->tpl_vars)) {
                 $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
             }
             if (!empty($parent_ptr->config_vars)) {
                 $config_vars = array_merge($config_vars, $parent_ptr->config_vars);
             }
         }
         if (!empty(Smarty::$global_tpl_vars)) {
             $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
         }
         $_template->tpl_vars = $tpl_vars;
         $_template->config_vars = $config_vars;
     }
     // dummy local smarty variable
     if (!isset($_template->tpl_vars['smarty'])) {
         $_template->tpl_vars['smarty'] = new Smarty_Variable();
     }
     if (isset($this->smarty->error_reporting)) {
         $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);
     }
     // check URL debugging control
     if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
         if (isset($_SERVER['QUERY_STRING'])) {
             $_query_string = $_SERVER['QUERY_STRING'];
         } else {
             $_query_string = '';
         }
         if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {
             if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) {
                 // enable debugging for this browser session
                 setcookie('SMARTY_DEBUG', true);
                 $this->smarty->debugging = true;
             } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) {
                 // disable debugging for this browser session
                 setcookie('SMARTY_DEBUG', false);
                 $this->smarty->debugging = false;
             } else {
                 // enable debugging for this page
                 $this->smarty->debugging = true;
             }
         } else {
             if (isset($_COOKIE['SMARTY_DEBUG'])) {
                 $this->smarty->debugging = true;
             }
         }
     }
     // must reset merge template date
     $_template->smarty->merged_templates_func = array();
     // get rendered template
     // disable caching for evaluated code
     if ($_template->source->recompiled) {
         $_template->caching = false;
     }
     // checks if template exists
     if (!$_template->source->exists) {
         if ($_template->parent instanceof Smarty_Internal_Template) {
             $parent_resource = " in '{$_template->parent->template_resource}'";
         } else {
             $parent_resource = '';
         }
         throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
     }
     // read from cache or render
     if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {
         // render template (not loaded and not in cache)
         if (!$_template->source->uncompiled) {
             $_smarty_tpl = $_template;
             if ($_template->source->recompiled) {
                 $code = $_template->compiler->compileTemplate($_template);
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 try {
                     ob_start();
                     /// dark mad edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end mad edit
                     eval("?>" . $code);
                     unset($code);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             } else {
                 if (!$_template->compiled->exists || $_template->smarty->force_compile && !$_template->compiled->isCompiled) {
                     $_template->compileTemplateSource();
                     $code = file_get_contents($_template->compiled->filepath);
                     eval("?>" . $code);
                     unset($code);
                     $_template->compiled->loaded = true;
                     $_template->compiled->isCompiled = true;
                 }
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 if (!$_template->compiled->loaded) {
                     include $_template->compiled->filepath;
                     if ($_template->mustCompile) {
                         // recompile and load again
                         $_template->compileTemplateSource();
                         $code = file_get_contents($_template->compiled->filepath);
                         eval("?>" . $code);
                         unset($code);
                         $_template->compiled->isCompiled = true;
                     }
                     $_template->compiled->loaded = true;
                 } else {
                     $_template->decodeProperties($_template->compiled->_properties, false);
                 }
                 try {
                     ob_start();
                     if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
                         throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
                     }
                     array_unshift($_template->_capture_stack, array());
                     /// dark mad edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end mad edit
                     //
                     // render compiled template
                     //
                     $_template->properties['unifunc']($_template);
                     // any unclosed {capture} tags ?
                     if (isset($_template->_capture_stack[0][0])) {
                         $_template->capture_error();
                     }
                     array_shift($_template->_capture_stack);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             }
         } else {
             if ($_template->source->uncompiled) {
                 if ($this->smarty->debugging) {
                     Smarty_Internal_Debug::start_render($_template);
                 }
                 try {
                     ob_start();
                     /// dark mad edit
                     \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                     /// end mad edit
                     $_template->source->renderUncompiled($_template);
                 } catch (Exception $e) {
                     ob_get_clean();
                     throw $e;
                 }
             } else {
                 throw new SmartyException("Resource '{$_template->source}->type' must have 'renderUncompiled' method");
             }
         }
         $_output = ob_get_clean();
         if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
             $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
         }
         if ($_template->parent instanceof Smarty_Internal_Template) {
             $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
             foreach ($_template->required_plugins as $code => $tmp1) {
                 foreach ($tmp1 as $name => $tmp) {
                     foreach ($tmp as $type => $data) {
                         $_template->parent->required_plugins[$code][$name][$type] = $data;
                     }
                 }
             }
         }
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::end_render($_template);
         }
         // write to cache when nessecary
         if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
             if ($this->smarty->debugging) {
                 Smarty_Internal_Debug::start_cache($_template);
             }
             $_template->properties['has_nocache_code'] = false;
             // get text between non-cached items
             $cache_split = preg_split("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output);
             // get non-cached items
             preg_match_all("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output, $cache_parts);
             $output = '';
             // loop over items, stitch back together
             foreach ($cache_split as $curr_idx => $curr_split) {
                 // escape PHP tags in template content
                 $output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', "<?php echo '\$1'; ?>\n", $curr_split);
                 if (isset($cache_parts[0][$curr_idx])) {
                     $_template->properties['has_nocache_code'] = true;
                     // remove nocache tags from cache output
                     $output .= preg_replace("!/\\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
                 }
             }
             if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
                 $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
             }
             // rendering (must be done before writing cache file because of {function} nocache handling)
             $_smarty_tpl = $_template;
             try {
                 ob_start();
                 /// dark mad edit
                 \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
                 /// end mad edit
                 eval("?>" . $output);
                 $_output = ob_get_clean();
             } catch (Exception $e) {
                 ob_get_clean();
                 throw $e;
             }
             // write cache file content
             $_template->writeCachedContent($output);
             if ($this->smarty->debugging) {
                 Smarty_Internal_Debug::end_cache($_template);
             }
         } else {
             // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
             if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
                 // replace nocache_hash
                 $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
                 $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
             }
         }
     } else {
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::start_cache($_template);
         }
         try {
             ob_start();
             /// dark mad edit
             \Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
             /// end mad edit
             array_unshift($_template->_capture_stack, array());
             //
             // render cached template
             //
             $_template->properties['unifunc']($_template);
             // any unclosed {capture} tags ?
             if (isset($_template->_capture_stack[0][0])) {
                 $_template->capture_error();
             }
             array_shift($_template->_capture_stack);
             $_output = ob_get_clean();
         } catch (Exception $e) {
             ob_get_clean();
             throw $e;
         }
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::end_cache($_template);
         }
     }
     if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
         $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template);
     }
     if (isset($this->error_reporting)) {
         error_reporting($_smarty_old_error_level);
     }
     // display or fetch
     if ($display) {
         if ($this->caching && $this->cache_modified_check) {
             $_isCached = $_template->isCached() && !$_template->has_nocache_code;
             $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
             if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
                 switch (PHP_SAPI) {
                     case 'cgi':
                         // php-cgi < 5.3
                     // php-cgi < 5.3
                     case 'cgi-fcgi':
                         // php-cgi >= 5.3
                     // php-cgi >= 5.3
                     case 'fpm-fcgi':
                         // php-fpm >= 5.3.3
                         header('Status: 304 Not Modified');
                         break;
                     case 'cli':
                         if (!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
                             $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
                         }
                         break;
                     default:
                         header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
                         break;
                 }
             } else {
                 switch (PHP_SAPI) {
                     case 'cli':
                         if (!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
                             $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
                         }
                         break;
                     default:
                         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
                         break;
                 }
                 echo $_output;
             }
         } else {
             echo $_output;
         }
         // debug output
         if ($this->smarty->debugging) {
             Smarty_Internal_Debug::display_debug($this);
         }
         if ($merge_tpl_vars) {
             // restore local variables
             $_template->tpl_vars = $save_tpl_vars;
             $_template->config_vars = $save_config_vars;
         }
         return;
     } else {
         if ($merge_tpl_vars) {
             // restore local variables
             $_template->tpl_vars = $save_tpl_vars;
             $_template->config_vars = $save_config_vars;
         }
         // return fetched content
         return $_output;
     }
 }