Example #1
0
 /**
  * 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;
 }
 /**
  * Copies folders
  * 
  * @return void
  */
 public function copyAssets()
 {
     foreach (Helper::ensureArray($this->config['copy']) as $folder) {
         $folder = str_replace('{theme}', Config::getTheme(), $folder);
         $full_from_path = Path::assemble(BASE_PATH, $folder);
         $full_to_path = Path::assemble(BASE_PATH, $this->config['destination'], $folder);
         Folder::copy($full_from_path, $full_to_path);
     }
 }
Example #3
0
File: pi.theme.php Project: nob/joi
 public function css()
 {
     $src = $this->fetchParam('src', Config::getTheme() . '.css', null, false, false);
     $file = $this->theme_path . $this->theme_assets_path . 'css/' . $src;
     $cache_bust = $this->fetchParam('cache_bust', Config::get('theme_cache_bust', false), false, true, true);
     # Add '.css' to the end if not present.
     if (!preg_match("(\\.css)", $file)) {
         $file .= '.css';
     }
     // Add cache busting query string
     if ($cache_bust && File::exists($file)) {
         $file .= '?v=' . ($last_modified = filemtime($file));
     }
     return $this->site_root . $file;
 }
Example #4
0
 public function css()
 {
     $src = $this->fetchParam('src', Config::getTheme() . '.css', null, false, false);
     $file = $this->theme_path . $this->theme_assets_path . 'css/' . $src;
     $cache_bust = $this->fetchParam('cache_bust', Config::get('theme_cache_bust', false), false, true, true);
     $tag = $this->fetchParam('tag', false, null, true, false);
     # Add '.css' to the end if not present.
     if (!preg_match("(\\.css)", $file)) {
         $file .= '.css';
     }
     // Add cache busting query string
     if ($cache_bust && File::exists($file)) {
         $file .= '?v=' . ($last_modified = filemtime($file));
     }
     $filename = URL::assemble($this->site_root, $file);
     return $tag ? '<link href="' . $filename . '" rel="stylesheet">' : $filename;
 }
 public function getThemeSettingsPath()
 {
     return Path::assemble(BASE_PATH, Config::getThemesPath(), Config::getTheme(), '/theme.yaml');
 }
Example #6
0
File: statamic.php Project: nob/joi
 public static function get_theme()
 {
     Log::warn("Use of Statamic::get_theme() is deprecated. Use Config::getTheme() instead.", "core", "Statamic");
     return Config::getTheme();
 }
Example #7
0
File: theme.php Project: nob/joi
 /**
  * Returns a list of layouts for a given $theme, or current theme if no $theme passed
  *
  * @param mixed  $theme  Theme to list layouts from, or current if none is passed
  * @return array
  */
 public static function getLayouts($theme = NULL)
 {
     $layouts = array();
     $list = glob("_themes/" . Helper::pick($theme, Config::getTheme()) . "/layouts/*");
     if ($list) {
         foreach ($list as $name) {
             $start = strrpos($name, "/") + 1;
             $end = strrpos($name, ".");
             $layouts[] = substr($name, $start, $end - $start);
         }
     }
     return $layouts;
 }
Example #8
0
File: config.php Project: nob/joi
 /**
  * Gets the current templates path
  *
  * @return string
  */
 public static function getTemplatesPath()
 {
     return self::get("templates.path", "./_themes/" . Config::getTheme());
 }