public function __call($method, $arguments) { $extensions = array(".html", ".md", ".markdown", ".textile"); $html = null; foreach ($extensions as $extension) { $full_src = Path::assemble(BASE_PATH, Config::getCurrentThemePath(), 'partials', ltrim($method . $extension, '/')); if (File::exists($full_src)) { // Merge additional variables passed as parameters Statamic_View::$_dataStore = $arguments + Statamic_View::$_dataStore; if ($this->fetchParam('use_context', false, false, true, false)) { $html = Parse::contextualTemplate(File::get($full_src), Statamic_View::$_dataStore, $this->context, 'Statamic_View::callback'); } else { $html = Parse::template(File::get($full_src), Statamic_View::$_dataStore, 'Statamic_View::callback'); } // parse contents if needed if ($extension == ".md" || $extension == ".markdown") { $html = Parse::markdown($html); } elseif ($extension == ".textile") { $html = Parse::textile($html); } } } if (Config::get('enable_smartypants', TRUE)) { $html = Parse::smartypants($html); } return $html; }
public function control_panel__add_routes() { $app = \Slim\Slim::getInstance(); $app->get('/globes', function () use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); Statamic_View::set_templates(array('globes-overview'), __DIR__ . '/templates'); $data = $this->tasks->getThemeSettings(); $app->render(null, array('route' => 'globes', 'app' => $app) + $data); })->name('globes'); // Update global vars $app->post('/globes/update', function () use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $data = $this->tasks->getThemeSettings(); $vars = Request::fetch('pageglobals'); foreach ($vars as $name => $var) { foreach ($data['globals'] as $key => $item) { if ($item['name'] === $name) { $data['globals'][$key]['value'] = $var; } } } File::put($this->tasks->getThemeSettingsPath(), YAML::dump($data, 1)); $app->flash('success', Localization::fetch('update_success')); $app->redirect($app->urlFor('globes')); }); }
public function control_panel__add_routes() { $app = \Slim\Slim::getInstance(); $core = $this->core; $app->get('/short-urls', function () use($app, $core) { authenticateForRole('admin'); doStatamicVersionCheck($app); $template_list = array("short-urls-overview"); Statamic_View::set_templates(array_reverse($template_list), __DIR__ . '/templates'); $data = $core->getOverviewData(); $app->render(null, array('route' => 'short-urls', 'app' => $app) + $data); })->name('short-urls'); }
public function partial() { $src = $this->fetchParam('src', null, null, false, false); if ($src) { $src .= ".html"; $partial_path = $this->theme_root . 'partials/' . ltrim($src, '/'); if (File::exists($partial_path)) { Statamic_View::$_dataStore = array_merge(Statamic_View::$_dataStore, $this->attributes); return Parse::template(file_get_contents($partial_path), Statamic_View::$_dataStore, 'Statamic_View::callback'); } } return null; }
public function control_panel__add_routes() { $app = \Slim\Slim::getInstance(); $tasks = $this->tasks; $app->get('/fetchphotos', function () use($app, $tasks) { authenticateForRole('admin'); $template_list = array("fetchphotos-admin"); Statamic_View::set_templates(array_reverse($template_list), __DIR__ . '/templates'); // run your task! $tasks->reportLocalPhotos(); $app->render(); })->name('fetchphotos'); $app->get('/fetchphotos/run', function () use($app, $tasks) { authenticateForRole('admin'); // run your task! $tasks->fetchPhotos(); $app->redirect('fetchphotos'); })->name('run_fetchphotos'); }
public function partial() { $start = time(); $src = $this->fetchParam('src', null, null, false, false); $extensions = array(".html", ".md", ".markdown", ".textile"); $html = null; // measurement $hash = Debug::markStart('partials', $src, $start); Debug::increment('partials', $src); if ($src) { foreach ($extensions as $extension) { $full_src = Path::assemble(BASE_PATH, $this->theme_root, 'partials', ltrim($src . $extension, '/')); if (File::exists($full_src)) { Statamic_View::$_dataStore = $this->attributes + Statamic_View::$_dataStore; if ($this->fetchParam('use_context', false, false, true, false)) { // to use context, we only want to pass the attributes as // the current data, as those will override into the context // set of data; if we were to include all of ::$_dataStore, // we run into the issue where all of the global-level variables // are overriding variables in context, when the variables in // context are more accurate scope-wise at this point in the parse $html = Parse::contextualTemplate(file_get_contents($full_src), $this->attributes, $this->context, array('statamic_view', 'callback'), true); } else { $html = Parse::template(file_get_contents($full_src), Statamic_View::$_dataStore); } // parse contents if needed if ($extension == ".md" || $extension == ".markdown") { $html = Parse::markdown($html); } elseif ($extension == ".textile") { $html = Parse::textile($html); } } } if (Config::get('enable_smartypants', TRUE)) { $html = Parse::smartypants($html); } } Debug::markEnd($hash); return $html; }
public function control_panel__add_routes() { // Get an instance of the Slim app. This is what holds the routes. $app = \Slim\Slim::getInstance(); // Create a reference to your core file. You won't be able to access it using $this->core from within the route itself. $core = $this->core; // Define your route. This is essentially what gets added to /admin/routes.php // and pass in $core so we can reference it // You'll access the page using /admin.php/gallery $app->get('/gallery', function () use($core, $app) { // Make sure only admin users can access this page, and perform a version check. This is just something that needs to be done in the CP. authenticateForRole('admin'); doStatamicVersionCheck($app); // Tell it which template to load. In this case its /_add-ons/gallery/templates/bar.html Statamic_View::set_templates(array('gallery-admin'), __DIR__ . '/templates'); // Create an array of variables you want your template to be able to use // It's probably best to put this logic somewhere else, like your core file, to keep things organized $data = $core->getCpData(); // Render the page, passing in the data $app->render(null, array_merge(array('route' => 'gallery', 'app' => $app), $data)); // The name here isn't required, but if you want to use named routes like $app->urlFor('gallery'), that's what this is for. })->name('gallery'); }
if ($admin_enabled !== true && strtolower($admin_enabled) != 'yes') { Statamic_View::set_templates(array_reverse(array("denied"))); Statamic_View::set_layout("layouts/disabled"); $admin_app->render(null, array('route' => 'disabled', 'app' => $admin_app)); exit; } /* |-------------------------------------------------------------------------- | Set Default Layout |-------------------------------------------------------------------------- | | This may be overwritten later, but let's go ahead and set the default | layout file to start assembling our front-end view. | */ Statamic_View::set_layout("layouts/default"); /* |-------------------------------------------------------------------------- | Set Global Variables, Defaults, and Environments |-------------------------------------------------------------------------- | | Numerous tag variables, helpers, and other config-dependent options | need to be loaded *before* the page is parsed. | */ Statamic::setDefaultTags(); /* |-------------------------------------------------------------------------- | Caching |-------------------------------------------------------------------------- |
$data = Content::get(Path::tidy(Config::getSiteRoot() . "/404")); $template_list = array('404'); $response_code = 404; // set template and layout if (isset($data['_template'])) { $template_list[] = $data['_template']; } if (isset($data['_layout'])) { Statamic_View::set_layout("layouts/{$data['_layout']}"); } // set up the view Statamic_View::set_templates(array_reverse($template_list)); /* |-------------------------------------------------------------------------- | HTTP Caching |-------------------------------------------------------------------------- | | We'll always set the last modified header, but leave the | cache_expires option to people's discretion and configuration. | */ if (array_get($data, '_http_cache_expires', Config::get('http_cache_expires', false))) { $app->lastModified(Cache::getLastCacheUpdate()); $app->expires('+'.Config::get('http_cache_expires', '30 minutes')); }
public function control_panel__add_routes() { $app = \Slim\Slim::getInstance(); $app->get('/raven', function () use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $template_list = array("raven-overview"); Statamic_View::set_templates(array_reverse($template_list), __DIR__ . '/templates'); $data = $this->tasks->getOverviewData(); if (count($data['formsets']) === 1) { $app->redirect($app->urlFor('raven') . '/' . key($data['formsets'])); } $app->render(null, array('route' => 'raven', 'app' => $app) + $data); })->name('raven'); $app->get('/raven/:formset', function ($formset) use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $template_list = array("raven-detail"); Statamic_View::set_templates(array_reverse($template_list), __DIR__ . '/templates'); $app->render(null, array('route' => 'raven', 'app' => $app) + $this->tasks->getFormsetData($formset)); }); $app->get('/raven/:formset/spam', function ($formset) use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $template_list = array("raven-spam"); Statamic_View::set_templates(array_reverse($template_list), __DIR__ . '/templates'); $app->render(null, array('route' => 'raven', 'app' => $app) + $this->tasks->getFormsetSpamData($formset)); }); $app->get('/raven/:formset/export', function ($formset) use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $res = $app->response(); $res['Content-Type'] = 'text/csv'; $res['Content-Disposition'] = 'attachment;filename=' . $formset . '-export.csv'; $this->tasks->exportCSV($formset); }); $app->post('/raven/:formset/batch', function ($formset) use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $files = (array) Request::fetch('files'); $action = Request::fetch('action'); $count = count($files); foreach ($files as $file) { switch ($action) { case "delete": File::delete($file); break; case "spam": $this->tasks->markAsSpam($file); break; case "ham": $this->tasks->markAsHam($file); break; } } $app->flash('success', Localization::fetch('batch_' . $action)); $app->redirect($app->urlFor('raven') . '/' . $formset); }); $app->map('/raven/:formset/delete', function ($formset) use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $files = (array) Request::fetch('files'); $count = count($files); foreach ($files as $file) { File::delete($file); } if ($count > 1) { $app->flash('success', Localization::fetch('files_deleted')); } else { $app->flash('success', Localization::fetch('file_deleted')); } $app->redirect($app->urlFor('raven') . '/' . $formset); })->via('GET', 'POST'); }
/** * Prepend any new data into this view's data store * * @param $data array Array of data to merge * @return void */ public static function prependNewData($data) { foreach ($data as $key => $item) { if (is_object($item)) { unset($data[$key]); } } Statamic_View::$_dataStore = Statamic_View::$_dataStore + $data; }
/** * _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 = $this->getTemplatesDirectory() . '/' . ltrim(self::$_layout, '/'); if ($template_type == 'html') { if (!file_exists($layout_path . ".html")) { Log::fatal("Can't find the specified theme", '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.'; } Statamic_View::$_dataStore = array_merge(Statamic_View::$_dataStore, $this->data); $html = $this->parser->parse(file_get_contents($layout_path . ".html"), Statamic_View::$_dataStore, array($this, 'callback'), true); $html = Lex\Parser::injectNoparse($html); } else { extract($this->data); ob_start(); require $layout_path . ".php"; $html = ob_get_clean(); } return $html; } return $_html; }
/** * Merges any new data into this view's data store * * @param $data array Array of data to merge * @return void */ function mergeNewData($data) { foreach ($data as $key => $item) { if (is_object($item)) { unset($data[$key]); } } Statamic_View::$_dataStore = $data + Statamic_View::$_dataStore; }