Ejemplo n.º 1
0
 /**
  * Parse the JS, CSS files and meta-info into the head of the HTML-document
  */
 public function parse()
 {
     $cssFiles = array();
     $jsFiles = array();
     // get last modified time for the header template
     $lastModifiedTime = @filemtime($this->tpl->getCompileDirectory() . '/' . md5(realpath(BACKEND_CORE_PATH . '/layout/templates/header.tpl')) . '_header.tpl.php');
     // reset lastmodified time if needed (SPOON_DEBUG is enabled or we don't get a decent timestamp)
     if ($lastModifiedTime === false || SPOON_DEBUG) {
         $lastModifiedTime = time();
     }
     // if there aren't any CSS-files added we don't need to do something
     if (!empty($this->cssFiles)) {
         // loop the CSS-files and add the modified-time
         foreach ($this->cssFiles as $file) {
             // add lastmodified time
             if ($file['add_timestamp'] !== false) {
                 $file['path'] .= strpos($file['path'], '?') !== false ? '&m=' . $lastModifiedTime : '?m=' . $lastModifiedTime;
             }
             // add
             $cssFiles[] = array('path' => $file['path']);
         }
     }
     // assign CSS-files
     $this->tpl->assign('cssFiles', $cssFiles);
     // if there aren't any JS-files added we don't need to do something
     if (!empty($this->jsFiles)) {
         // some files should be cached, even if we don't want cached (mostly libraries)
         $ignoreCache = array('/backend/core/js/jquery/jquery.js', '/backend/core/js/jquery/jquery.ui.js', '/backend/core/js/ckeditor/jquery.ui.dialog.patch.js', '/backend/core/js/jquery/jquery.tools.js', '/backend/core/js/jquery/jquery.backend.js', '/backend/core/js/ckeditor/ckeditor.js', '/backend/core/js/ckeditor/adapters/jquery.js', '/backend/core/js/ckfinder/ckfinder.js');
         foreach ($this->jsFiles as $file) {
             // some files shouldn't be uncachable
             if (in_array($file['path'], $ignoreCache) || $file['add_timestamp'] === false) {
                 $jsFiles[] = array('path' => $file['path']);
             } else {
                 // if the file is processed by PHP we don't want any caching
                 if (substr($file['path'], 0, 11) == '/backend/js') {
                     $jsFiles[] = array('path' => $file['path'] . '&m=' . time());
                 } else {
                     if (strpos($file['path'], '?') !== false) {
                         $path = $file['path'] . '&m=' . $lastModifiedTime;
                     } else {
                         $path = $file['path'] . '?m=' . $lastModifiedTime;
                     }
                     $jsFiles[] = array('path' => $path);
                 }
             }
         }
     }
     // assign JS-files
     $this->tpl->assign('jsFiles', $jsFiles);
 }