/** * Outputs the content by finding the correct template * and view file, if needed. */ public function getContent() { $tplDir = $this->isView ? $this->view->tpl : Config::$template; $config = array('base_url' => null, 'tpl_dir' => array(APP . 'template/' . $tplDir . '/'), 'cache_dir' => APP . 'tmp/', 'debug' => true, 'php_enabled' => true, 'tpl_ext' => 'php'); Tpl::configure($config); $tpl = new Tpl(); $tpl->assign('isView', $this->isView); $tpl->assign('title', Config::$data->title); if ($this->isView) { $vars = $this->view->getVars(); if (!empty($vars)) { foreach ($vars as $key => $value) { $tpl->assign($key, $value); } } $sep = DIRECTORY_SEPARATOR; $view = '..' . $sep . '..' . $sep . APP . 'view/' . $this->view->path; } else { $view = $this->view; if ($this->isJson === true) { echo $view; exit; } } try { File::get(APP . 'template/' . $tplDir . '/template.php'); if (class_exists('Template\\Model\\Template')) { $tpl_class = new Template\Model\Template(); $tpl->assign('template', $tpl_class); } } catch (Exception $e) { } $tpl->assign('view', $view); $tpl->draw('index'); }
<?php namespace Rain; require_once "Tpl.php"; function fixPath(&$path) { $path = preg_replace(array("#(/{2,})#", "#(/\\./+)#"), array("/", "/"), $path); $path = str_replace("/", "\\", $path); } $tpl = new Tpl(); $tpl->configure(array("tpl_dir" => "../templates/")); $fs = $tpl->countTemplates(); $grid = (new Db())->countTemplates(); echo "Count templates filesystem: " . $fs['count'] . "<br />"; echo "Count templates in cache: " . $grid['count'] . "<br /><br />"; array_walk($fs['names'], 'Rain\\fixPath'); array_walk($grid['names'], 'Rain\\fixPath'); if ($fs['count'] != $grid['count']) { echo "Not ready for production yet!<br />"; echo "Missing templates in cache:<br />"; foreach ($fs['names'] as $f) { if (!in_array($f, $grid['names'])) { echo $f . "<br />"; } } } else { echo "Ready for production!"; } #echo "<br />"; #print_r($fs['names']);