/* |-------------------------------------------------------------------------- | The Template Parser |-------------------------------------------------------------------------- | | Statamic uses a *highly* modified fork of the Lex parser, created by | Dan Horrigan. Kudos Dan! | */ require_once __DIR__ . '/vendor/Lex/Parser.php'; /* |-------------------------------------------------------------------------- | Internal API & Class Autoloader |-------------------------------------------------------------------------- | | An autoloader for our internal API and other core classes | */ // helper functions require_once __DIR__ . '/core/exceptions.php'; require_once __DIR__ . '/core/functions.php'; // register the Statamic autoloader spl_autoload_register("autoload_statamic"); // attempt HTML caching // although this doesn't really have anything to do with autoloading, putting this // here allows us to not force people to update their index.php files if (Addon::getAPI('html_caching')->isEnabled() && Addon::getAPI('html_caching')->isPageCached()) { die(Addon::getAPI('html_caching')->getCachedPage()); } // mark milestone for debug panel Debug::markMilestone('autoloaders ready');
$template_list[] = "taxonomies"; $template_list[] = $type; $content_found = true; } // content was found if ($content_found) { // mark milestone for debug panel Debug::markMilestone('content found'); // protect if (is_array($data) && $data) { try { Addon::getAPI('protect')->hasAccess(URL::getCurrent()); } catch (Slim\Exception\Stop $e) { throw $e; } catch (Exception $e) { // something went wrong with protect, 404 this Log::error('The following error occurred while trying to protect `' . htmlspecialchars($data['current_url']) . '`: ' . $e->getMessage() . ' — for extra precaution, we sent this use the 404 page.', 'core', 'protect'); $content_found = false; $response_code = 404; } } // alter the response code if you want $response_code = (int) array_get($data, '_response', $response_code); // if the response_code was set to 404, show a 404 if ($response_code === 404) {
/** * 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; }
/** * Use a given $addon's API * * @param string $addon Name of the addon to use * @return boolean * @throws Exception */ public function api($addon) { return Addon::getAPI($addon); }
authenticateForRole('admin'); doStatamicVersionCheck($admin_app); if (!($config = Request::get('config'))) { die('No config provided'); } $config = unserialize(Helper::decrypt($config)); $destination = $config['destination']; $files = Addon::getAPI('file')->getServerFiles($config, $destination); $modal = Addon::getAPI('file')->generateModal($files, $destination); echo $modal; })->name('files'); // Delete file $admin_app->get('/file/delete', function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $result = Addon::getAPI('file')->deleteFile(); $response = $admin_app->response(); $response['Content-Type'] = 'application/json'; $response->status(200); $response->body(json_encode($result)); })->name('delete_file'); $admin_app->get('/url/unique', function () use($admin_app) { $folder = Request::get('folder'); $url = Request::get('url'); $path = URL::assemble($folder, $url); $data = array('exists' => Content::exists(Path::resolve($path))); $response = $admin_app->response(); $response['Content-Type'] = 'application/json'; $response->body(json_encode($data)); }); /*