/** * render * Finds and chooses the correct template, then renders the page * * @param string $template Template (or array of templates, in order of preference) to render the page with * @return string */ public function render($template) { $html = '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">No template found.</p>'; $list = $template ? $list = array($template) : self::$_templates; $template_type = 'html'; // Allow setting where to get the template from if (!self::$_template_location) { self::$_template_location = Path::assemble(BASE_PATH, Config::getTemplatesPath(), 'templates'); } foreach ($list as $template) { $template_path = Path::assemble(self::$_template_location, $template); $override_path = Path::assemble(BASE_PATH, Config::getThemesPath(), Config::getTheme(), 'admin', $template); if (File::exists($template_path . '.html') || file_exists($template_path . '.php')) { // set debug information Debug::setValue('template', $template); Debug::setvalue('layout', str_replace('layouts/', '', self::$_layout)); Debug::setValue('statamic_version', STATAMIC_VERSION); Debug::setValue('php_version', phpversion()); Debug::setValue('theme', array_get($this->data, '_theme', null)); Debug::setValue('environment', array_get($this->data, 'environment', '(none)')); $this->data['_debug'] = array('template' => Debug::getValue('template'), 'layout' => Debug::getValue('layout'), 'version' => Debug::getValue('statamic_version'), 'statamic_version' => Debug::getValue('statamic_version'), 'php_version' => Debug::getValue('php_version'), 'theme' => Debug::getValue('theme'), 'environment' => Debug::getValue('environment')); # standard lex-parsed template if (File::exists($template_path . '.html')) { $template_type = 'html'; $this->appendNewData($this->data); // Fetch template and parse any front matter $template = Parse::frontMatter(File::get($template_path . '.html')); self::$_extra_data = $template['data'] + self::$_extra_data; $this->prependNewData(self::$_extra_data); $html = Parse::template($template['content'], Statamic_View::$_dataStore, array($this, 'callback')); break; # lets forge into raw data } elseif (File::exists($override_path . '.php') || File::exists($template_path . '.php')) { $template_type = 'php'; extract($this->data); ob_start(); if (File::exists($override_path . '.php')) { $template_path = $override_path; } require $template_path . ".php"; $html = ob_get_clean(); break; } else { Log::error("Template does not exist: '{$template_path}'", 'core'); } } } // mark milestone for debug panel Debug::markMilestone('template rendered'); // get rendered HTML $rendered = $this->_render_layout($html, $template_type); // mark milestone for debug panel Debug::markMilestone('layout rendered'); // store it into the HTML cache if needed if (Addon::getAPI('html_caching')->isEnabled()) { Addon::getAPI('html_caching')->putCachedPage($rendered); } // return rendered HTML return $rendered; }
public function __construct() { parent::__construct(); $this->theme_assets_path = Config::getThemeAssetsPath(); $this->theme_path = Config::getCurrentthemePath(); $this->theme_root = Config::getTemplatesPath(); $this->site_root = Config::getSiteRoot(); }
$admin_app->get('/system', function () use($admin_app) { $redirect_to = Config::get('_admin_start_page', 'pages'); $admin_app->redirect($admin_app->urlFor('security')); })->name('system'); // Security // -------------------------------------------------------- $admin_app->get('/system/security', function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $template_list = array("security"); Statamic_View::set_templates(array_reverse($template_list)); $data = array(); if (isCurlEnabled()) { $user = Auth::getCurrentMember(); $username = $user->get('username'); $tests = array('_app' => Localization::fetch('security_app_folder'), '_config' => Localization::fetch('security_config_folder'), '_config/settings.yaml' => Localization::fetch('security_settings_files'), '_config/users/' . $username . '.yaml' => Localization::fetch('security_user_files'), Config::getContentRoot() => Localization::fetch('security_content_folder'), Config::getTemplatesPath() . 'layouts/default.php' => Localization::fetch('security_template_files'), '_logs' => Localization::fetch('security_logs_folder')); $site_url = 'http://' . $_SERVER['HTTP_HOST'] . '/'; foreach ($tests as $url => $message) { $test_url = $site_url . $url; $http = curl_init($test_url); curl_setopt($http, CURLOPT_RETURNTRANSFER, 1); curl_setopt($http, CURLOPT_TIMEOUT, 3); $result = curl_exec($http); $http_status = curl_getinfo($http, CURLINFO_HTTP_CODE); curl_close($http); $data['system_checks'][$url]['status_code'] = $http_status; $data['system_checks'][$url]['status'] = $http_status !== 200 ? 'good' : 'warning'; $data['system_checks'][$url]['message'] = $message; } } $data['users'] = Member::getList();
public static function get_templates_path() { Log::warn("Use of Statamic::get_templates_path() is deprecated. Use Config::getTemplatesPath() instead.", "core", "Statamic"); return Config::getTemplatesPath(); }
/** * Returns a given $template parsed with given $data * * @param string $template Template to parse * @param array $data Associative array of data to fill into template * @return string */ public static function getParsedTemplate($template, array $data = array()) { $parser = new Lex\Parser(); $template_path = Config::getTemplatesPath() . '/templates/' . ltrim($template, '/') . '.html'; return $parser->parse(File::get($template_path, ""), $data, FALSE); }
/** * Returns a given $template parsed with given $data * * @param string $template Template to parse * @param array $data Associative array of data to fill into template * @return string */ public static function getParsedTemplate($template, array $data = array()) { $parser = new Lex\Parser(); $template_path = Config::getTemplatesPath() . '/templates/' . ltrim($template, '/') . '.html'; return $parser->parse(File::get($template_path, ""), $data, array('statamic_view', 'callback'), Config::get('_allow_php', false)); }
/** * _render_layout * Renders the page * * @param string $_html HTML of the template to use * @param string $template_type Content type of the template * @return string */ public function _render_layout($_html, $template_type = 'html') { if (self::$_layout != '') { $this->data['layout_content'] = $_html; $layout_path = Path::assemble(BASE_PATH, Config::getTemplatesPath(), self::$_layout); if ($template_type != 'html' or self::$_control_panel) { extract($this->data); ob_start(); require $layout_path . ".php"; $html = ob_get_clean(); } else { if (!File::exists($layout_path . ".html")) { Log::fatal("Can't find the specified theme.", 'core', 'template'); return '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">We can\'t find your theme files. Please check your settings.'; } $this->mergeNewData($this->data); $html = Parse::template(File::get($layout_path . ".html"), Statamic_View::$_dataStore, array($this, 'callback')); $html = Lex\Parser::injectNoparse($html); } } else { $html = $_html; } // post-render hook $html = \Hook::run('_render', 'after', 'replace', $html, $html); return $html; }