Esempio n. 1
0
 public static function renderLinks($inline = FALSE, $index = FALSE)
 {
     // build a var with the included css files
     $styles = self::$stylePaths;
     self::$stylePaths = array();
     // Get the session so we can track what assets are on the page
     $session = Session::instance();
     // If this is a full page load (ie not ajax) then there are no assest already on page
     if (!request::is_ajax()) {
         $session->delete('stylesheet.onPageAssets');
     }
     // Initialize the vars to track what has been added, and convience wrappers
     $onPageAssets = $session->get('stylesheet.onPageAssets', array());
     // loop all the css includes and determine what needs to go on this page
     // and in what order
     $styleOutputBuffer = array();
     foreach ($styles as $cond => $condblock) {
         // sort this condblock of style paths by weight
         ksort($condblock);
         $styleOutputBuffer[$cond] = array();
         foreach ($condblock as $stylePaths) {
             // make sure there are no duplicates in this array
             $stylePaths = array_unique($stylePaths);
             // make sure these css links are not already on the page
             // via ajax/parent or in another weight category (lowest weight wins)
             $stylePaths = array_diff($stylePaths, $onPageAssets);
             // add the filtered list to the array of assets to put on the page
             $styleOutputBuffer[$cond] = array_merge($styleOutputBuffer[$cond], $stylePaths);
             // keep track of what we add to the pages
             $onPageAssets = array_merge($onPageAssets, $stylePaths);
         }
     }
     // NOTICE: setting $session here causes segfault during ajax
     // made a hack to move this set outside the event .....
     Bluebox_Controller::$onPageAssets['css'] = $onPageAssets;
     //$session->set('stylesheet.onPageAssets', $onPageAssets);
     // run through everything that needs to be on the page and
     // make in conditional where apropriate then convert them into css links
     $linkList = '';
     foreach ($styleOutputBuffer as $cond => $stylePaths) {
         // if all the includes are already on page move on
         if (empty($stylePaths)) {
             continue;
         }
         // create the css links
         $links = html::stylesheet($stylePaths, 'screen', $index);
         // if these are conditional css pages then wrap the links
         // in the conditional statement
         if (array_key_exists($cond, self::$cssconditional)) {
             $links = sprintf(self::$cssconditional[$cond], "\n" . rtrim($links, "\n") . "\n");
         }
         // add these links to our string
         $linkList .= $links;
     }
     // are we displaying this inline or returning the string
     if ($inline) {
         echo $linkList;
     } else {
         return $linkList;
     }
 }