private function _initCache() { if (isset($this->_themeMap)) { return; } $this->_themeMap = array(); foreach ($this->_themeRegistry->getAll() as $theme) { $this->_themeMap[$theme->getName()] = $theme; } }
/** * @return string */ public function getThemeDataAsJson() { $themes = $this->_themeRegistry->getAll(); $toReturn = array(); foreach ($themes as $theme) { $toReturn[$theme->getName()] = $this->_buildThemeData($theme); } $asJson = json_encode($toReturn); return htmlspecialchars($asJson, ENT_NOQUOTES); }
public function onAcceptableValues(tubepress_api_event_EventInterface $event) { $current = $event->getSubject(); if (!is_array($current)) { $current = array(); } $result = array(); $allThemes = $this->_themeRegistry->getAll(); foreach ($allThemes as $theme) { $result[$theme->getName()] = $theme->getTitle(); } ksort($result); $toSet = array_merge($current, $result); $event->setSubject($toSet); }
public function onPreValidationSet(tubepress_api_event_EventInterface $event) { $themeValue = $event->getArgument('optionValue'); $shouldLog = $this->_logger->isEnabled(); if (in_array($themeValue, self::$_LEGACY_THEME_VALUES)) { if ($shouldLog) { $this->_logger->debug(sprintf('Renaming theme value from %s to tubepress/legacy-%s', $themeValue, $themeValue)); } $event->setArgument('optionValue', "tubepress/legacy-{$themeValue}"); return; } $allThemes = $this->_themeRegistry->getAll(); foreach ($allThemes as $theme) { if ($theme->getName() !== "unknown/legacy-{$themeValue}") { continue; } if ($shouldLog) { $this->_logger->debug(sprintf('Renaming theme value from %s to unknown/legacy-%s', $themeValue, $themeValue)); } $event->setArgument('optionValue', "unknown/legacy-{$themeValue}"); } }
private function _recursivelyGetFromTheme(tubepress_api_theme_ThemeInterface $theme, $getter) { $toReturn = $theme->{$getter}($this->_environment->getBaseUrl(), $this->_environment->getUserContentUrl()); $parentThemeName = $theme->getParentThemeName(); if (!$parentThemeName) { return $toReturn; } $theme = $this->_themeRegistry->getInstanceByName($parentThemeName); if (!$theme) { return $toReturn; } $fromParent = $this->_recursivelyGetFromTheme($theme, $getter); if (is_array($fromParent)) { $toReturn = array_merge($fromParent, $toReturn); } else { $toReturn = $fromParent . $toReturn; } return $toReturn; }
/** * @param $templateName * * @return null|tubepress_api_theme_ThemeInterface */ private function _findThemeForTemplate($templateName) { $activeTheme = $this->_currentThemeService->getCurrentTheme(); $activeThemeName = $activeTheme->getName(); if (strpos($templateName, '::') !== false) { $exploded = explode('::', $templateName); if (count($exploded) === 2 && $this->_themeRegistry->getInstanceByName($exploded[0]) !== null) { $activeTheme = $this->_themeRegistry->getInstanceByName($exploded[0]); $activeThemeName = $activeTheme->getName(); $templateName = $exploded[1]; } } if ($this->_shouldLog) { $this->_logDebug(sprintf('Seeing if we can find <code>%s</code> in the theme hierarchy. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } if (isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName]) && isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName])) { $cachedValue = $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName]; if ($this->_shouldLog) { if ($cachedValue) { $this->_logDebug(sprintf('Theme for template <code>%s</code> was found in the cache to be contained in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $cachedValue->getName(), $cachedValue->getVersion(), $this->_loggerPostfix($activeTheme))); } else { $this->_logDebug(sprintf('We already tried to find a theme that contains <code>%s</code> in the theme hierarchy but didn\'t find it anywhere. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } return $cachedValue ? $cachedValue : null; } else { if ($this->_shouldLog) { $this->_logDebug(sprintf('Looks like this is the first time searching for a theme that contains <code>%s</code>. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } do { $activeThemeName = $activeTheme->getName(); if ($activeTheme->hasTemplateSource($templateName)) { if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = $activeTheme; if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was found in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $activeThemeName, $activeTheme->getVersion(), $this->_loggerPostfix($activeTheme))); } return $activeTheme; } $nextThemeNameToCheck = $activeTheme->getParentThemeName(); if ($nextThemeNameToCheck === null) { break; } if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was not found in theme <code>%s</code>. Now trying its parent theme: <code>%s</code>.', $templateName, $activeTheme->getName(), $nextThemeNameToCheck)); } try { $activeTheme = $this->_themeRegistry->getInstanceByName($nextThemeNameToCheck); } catch (InvalidArgumentException $e) { if ($this->_shouldLog) { $this->_logger->error(sprintf('Unable to get the theme instance for <code>%s</code>. This should never happen!', $nextThemeNameToCheck)); } break; } } while ($activeTheme !== null); if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = false; if ($this->_shouldLog) { $this->_logDebug(sprintf('Unable to find source of template <code>%s</code> from theme hierarchy.', $templateName)); } return null; }