Example #1
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 = $this->themeInfo->findContainingTheme($relPath);
     if (is_null($currentTheme)) {
         return null;
     }
     $urlHelper = $this->getView()->plugin('url');
     return $urlHelper('home') . "themes/{$currentTheme}/" . $relPath;
 }
Example #2
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'];
         $details = $this->themeInfo->findContainingTheme($relPath, ThemeInfo::RETURN_ALL_DETAILS);
         if (!empty($details)) {
             $urlHelper = $this->getView()->plugin('url');
             $url = $urlHelper('home') . "themes/{$details['theme']}/" . $relPath;
             $url .= strstr($url, '?') ? '&_=' : '?_=';
             $url .= filemtime($details['path']);
             $item->attributes['src'] = $url;
         }
     }
     return parent::itemToString($item, $indent, $escapeStart, $escapeEnd);
 }
Example #3
0
 /**
  * Support method for init() -- set up theme once current settings are known.
  *
  * @param array $themes Theme configuration information.
  *
  * @return void
  */
 protected function setUpThemes($themes)
 {
     $templatePathStack = [];
     // Grab the resource manager for tracking CSS, JS, etc.:
     $resources = $this->serviceManager->get('VuFindTheme\\ResourceContainer');
     // Set generator if necessary:
     if (isset($this->config->generator)) {
         $resources->setGenerator($this->config->generator);
     }
     $lessActive = false;
     // Find LESS activity
     foreach ($themes as $key => $currentThemeInfo) {
         if (isset($currentThemeInfo['less']['active'])) {
             $lessActive = $currentThemeInfo['less']['active'];
         }
     }
     // Apply the loaded theme settings in reverse for proper inheritance:
     foreach ($themes as $key => $currentThemeInfo) {
         if (isset($currentThemeInfo['helpers'])) {
             $this->setUpThemeViewHelpers($currentThemeInfo['helpers']);
         }
         // Add template path:
         $templatePathStack[] = $this->tools->getBaseDir() . "/{$key}/templates";
         // Add CSS and JS dependencies:
         if ($lessActive && isset($currentThemeInfo['less'])) {
             $resources->addLessCss($currentThemeInfo['less']);
         }
         if (isset($currentThemeInfo['css'])) {
             $resources->addCss($currentThemeInfo['css']);
         }
         if (isset($currentThemeInfo['js'])) {
             $resources->addJs($currentThemeInfo['js']);
         }
         // Select encoding:
         if (isset($currentThemeInfo['encoding'])) {
             $resources->setEncoding($currentThemeInfo['encoding']);
         }
         // Select favicon:
         if (isset($currentThemeInfo['favicon'])) {
             $resources->setFavicon($currentThemeInfo['favicon']);
         }
     }
     // Inject the path stack generated above into the view resolver:
     $resolver = $this->serviceManager->get('viewmanager')->getResolver();
     if (!is_a($resolver, 'Zend\\View\\Resolver\\AggregateResolver')) {
         throw new \Exception('Unexpected resolver: ' . get_class($resolver));
     }
     foreach ($resolver as $current) {
         if (is_a($current, 'Zend\\View\\Resolver\\TemplatePathStack')) {
             $current->setPaths($templatePathStack);
         }
     }
     // Add theme specific language files for translation
     $this->updateTranslator($themes);
 }
Example #4
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 = [''])
 {
     // Check all supported image formats:
     $filenames = [];
     foreach ($formats as $format) {
         $filenames[] = $path . $format;
     }
     if (null === $this->themeTools) {
         throw new \Exception('\\VuFindTheme\\ThemeInfo object missing');
     }
     $fileMatch = $this->themeTools->findContainingTheme($filenames, true);
     return empty($fileMatch) ? false : $fileMatch;
 }
Example #5
0
 /**
  * Compile a less file to css and add to css folder
  *
  * @param string $file                  Path to less file
  * @param string $media                 Media type
  * @param string $conditionalStylesheet Load condition for file
  *
  * @return void
  */
 public function addLessStylesheet($file, $media = 'all', $conditionalStylesheet = false)
 {
     $relPath = 'less/' . $file;
     $urlHelper = $this->getView()->plugin('url');
     $currentTheme = $this->themeInfo->findContainingTheme($relPath);
     $helperHome = $urlHelper('home');
     $home = APPLICATION_PATH . '/themes/' . $currentTheme . '/';
     $cssDirectory = $helperHome . 'themes/' . $currentTheme . '/css/less/';
     try {
         $less_files = [APPLICATION_PATH . '/themes/' . $currentTheme . '/' . $relPath => $cssDirectory];
         $themeParents = array_keys($this->themeInfo->getThemeInfo());
         $directories = [];
         foreach ($themeParents as $theme) {
             $directories[APPLICATION_PATH . '/themes/' . $theme . '/less/'] = $helperHome . 'themes/' . $theme . '/css/less/';
         }
         $css_file_name = \Less_Cache::Get($less_files, ['cache_dir' => $home . 'css/less/', 'cache_method' => false, 'compress' => true, 'import_dirs' => $directories, 'output' => str_replace('.less', '.css', $file)]);
         $this->prependStylesheet($cssDirectory . $css_file_name, $media, $conditionalStylesheet);
     } catch (\Exception $e) {
         error_log($e->getMessage());
         list($fileName, ) = explode('.', $file);
         $this->prependStylesheet($urlHelper('home') . "themes/{$currentTheme}/css/{$fileName}.css");
     }
 }
Example #6
0
 /**
  * Compile a LESS file inside a theme.
  *
  * @param string $theme Theme containing file
  * @param string $less  Relative path to LESS file
  *
  * @return void
  */
 protected function compileFile($theme, $less)
 {
     $parts = explode(':', $less);
     $less = $parts[0];
     $finalOutDir = $this->basePath . '/themes/' . $theme . '/css/';
     list($fileName, ) = explode('.', $less);
     $finalFile = $finalOutDir . $fileName . '.css';
     $this->logMessage("\tcompiling '" . $less . "' into '" . $finalFile . "'");
     $start = microtime(true);
     $directories = [];
     $info = new ThemeInfo($this->basePath . '/themes', $theme);
     foreach (array_keys($info->getThemeInfo()) as $curTheme) {
         $directories["{$this->basePath}/themes/{$curTheme}/less/"] = $this->fakePath . "themes/{$curTheme}/css/less";
     }
     $lessDir = $this->basePath . '/themes/' . $theme . '/less/';
     if (!file_exists($lessDir . $less)) {
         $this->logMessage("\t\t" . $lessDir . $less . ' does not exist; skipping.');
         return;
     }
     $outFile = \Less_Cache::Get([$lessDir . $less => $this->fakePath . "themes/{$theme}/css/less"], ['cache_dir' => $this->tempPath, 'cache_method' => 'php', 'compress' => true, 'import_dirs' => $directories]);
     $css = file_get_contents($this->tempPath . '/' . $outFile);
     if (!is_dir(dirname($finalFile))) {
         mkdir(dirname($finalFile));
     }
     file_put_contents($finalFile, $this->makeRelative($css, $less));
     $this->logMessage("\t\t" . (microtime(true) - $start) . ' sec');
 }