/**
  * Set up header items based on contents of theme resource container.
  *
  * @return void
  */
 public function __invoke()
 {
     $resourceContainer = ThemeTools::getResourceContainer();
     // Set up encoding:
     $headMeta = $this->getView()->plugin('headmeta');
     $headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=' . $resourceContainer->getEncoding());
     // Load CSS (make sure we prepend them in the appropriate order; theme
     // resources should load before extras added by individual templates):
     $headLink = $this->getView()->plugin('headlink');
     foreach (array_reverse($resourceContainer->getCss()) as $current) {
         $parts = explode(':', $current);
         $headLink()->prependStylesheet(trim($parts[0]), isset($parts[1]) ? trim($parts[1]) : 'all', isset($parts[2]) ? trim($parts[2]) : false);
     }
     // Load Javascript (same ordering considerations as CSS, above):
     $headScript = $this->getView()->plugin('headscript');
     foreach (array_reverse($resourceContainer->getJs()) as $current) {
         $parts = explode(':', $current);
         $headScript()->prependFile(trim($parts[0]), 'text/javascript', isset($parts[1]) ? array('conditional' => trim($parts[1])) : array());
     }
     // If we have a favicon, load it now:
     $favicon = $resourceContainer->getFavicon();
     if (!empty($favicon)) {
         $imageLink = $this->getView()->plugin('imagelink');
         $headLink(array('href' => $imageLink($favicon), 'type' => 'image/x-icon', 'rel' => 'shortcut icon'));
     }
 }
示例#2
0
 /**
  * Returns an image path according the configured theme
  *
  * @param string $image image name/path
  *
  * @return string path, null if image not found
  */
 public function __invoke($image)
 {
     // Normalize href to account for themes:
     $relPath = 'images/' . $image;
     $currentTheme = ThemeTools::findContainingTheme($relPath);
     if (is_null($currentTheme)) {
         return null;
     }
     $urlHelper = $this->getView()->plugin('url');
     return $urlHelper('home') . "themes/{$currentTheme}/" . $relPath;
 }
示例#3
0
 /**
  * Create HTML link element from data item
  *
  * @param stdClass $item data item
  *
  * @return string
  */
 public function itemToString(\stdClass $item)
 {
     // Normalize href to account for themes, then call the parent class:
     $relPath = 'css/' . $item->href;
     $currentTheme = ThemeTools::findContainingTheme($relPath);
     if (!empty($currentTheme)) {
         $urlHelper = $this->getView()->plugin('url');
         $item->href = $urlHelper('home') . "themes/{$currentTheme}/" . $relPath;
     }
     return parent::itemToString($item);
 }
示例#4
0
 /**
  * Create script HTML
  *
  * @param mixed  $item        Item to convert
  * @param string $indent      String to add before the item
  * @param string $escapeStart Starting sequence
  * @param string $escapeEnd   Ending sequence
  *
  * @return string
  */
 public function itemToString($item, $indent, $escapeStart, $escapeEnd)
 {
     // Normalize href to account for themes:
     if (!empty($item->attributes['src'])) {
         $relPath = 'js/' . $item->attributes['src'];
         $currentTheme = ThemeTools::findContainingTheme($relPath);
         if (!empty($currentTheme)) {
             $urlHelper = $this->getView()->plugin('url');
             $item->attributes['src'] = $urlHelper('home') . "themes/{$currentTheme}/" . $relPath;
         }
     }
     return parent::itemToString($item, $indent, $escapeStart, $escapeEnd);
 }
示例#5
0
 /**
  * Find a file in the themes (return false if no file exists).
  *
  * @param string $path    Relative path of file to find.
  * @param array  $formats Optional array of suffixes to add to $path while
  * searching theme (used to check multiple extensions in each theme).
  *
  * @return string|bool
  */
 protected function searchTheme($path, $formats = array(''))
 {
     // Check all supported image formats:
     $filenames = array();
     foreach ($formats as $format) {
         $filenames[] = $path . $format;
     }
     $fileMatch = ThemeTools::findContainingTheme($filenames, true);
     return empty($fileMatch) ? false : $fileMatch;
 }