예제 #1
0
 /**
  * Get compressed template
  *
  *  <code>
  *      echo Site::template();
  *  </code>
  *
  * @param  string $theme Theme name
  * @return mixed
  */
 public static function template($theme = null)
 {
     // Get specific theme or current theme
     $current_theme = $theme == null ? Option::get('theme_site_name') : $theme;
     // Get template
     $template = call_user_func(ucfirst(Uri::command()) . '::template');
     // Check whether is there such a template in the current theme
     // else return default template: index
     // also compress template file :)
     if (File::exists(THEMES_SITE . DS . $current_theme . DS . $template . '.template.php')) {
         if (!file_exists(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php') or filemtime(THEMES_SITE . DS . $current_theme . DS . $template . '.template.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php')) {
             $buffer = file_get_contents(THEMES_SITE . DS . $current_theme . DS . $template . '.template.php');
             $buffer = MinifyHTML::process($buffer);
             file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php', $buffer);
         }
         return 'minify.' . $template;
     } else {
         if (!File::exists(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php') or filemtime(THEMES_SITE . DS . $current_theme . DS . 'index.template.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php')) {
             $buffer = file_get_contents(THEMES_SITE . DS . $current_theme . DS . 'index.template.php');
             $buffer = MinifyHTML::process($buffer);
             file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php', $buffer);
         }
         return 'minify.index';
     }
 }
 /**
  * Get chunk
  *
  * @param string $name  Chunk name
  * @param string $theme Theme name
  */
 public static function get($name, $vars = array(), $theme = null)
 {
     // Redefine vars
     $name = (string) $name;
     $current_theme = $theme === null ? Option::get('theme_site_name') : (string) $theme;
     // Extract vars
     extract($vars);
     // Chunk path
     $chunk_path = THEMES_SITE . DS . $current_theme . DS;
     // Is chunk exist ?
     if (file_exists($chunk_path . $name . '.chunk.php')) {
         // Is chunk minified
         if (!file_exists(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php') or filemtime(THEMES_SITE . DS . $current_theme . DS . $name . '.chunk.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php')) {
             file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php', MinifyHTML::process(file_get_contents(THEMES_SITE . DS . $current_theme . DS . $name . '.chunk.php')));
         }
         // Include chunk
         include MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $name . '.chunk.php';
     }
 }