/** * 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; }
/** * 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); }
/** * 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; }
/** * 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"); } }