/** * @return array */ public static function getThemes() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $files = Folder::all('gantry-themes://', ['recursive' => false]); /** @var array|ThemeDetails[] $list */ $list = []; ksort($files); foreach ($files as $theme) { if (!is_dir($theme)) { continue; } if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) { $details = new ThemeDetails($theme); // Stream needs to be valid URL. $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $theme); if (!$locator->schemeExists($streamName)) { $locator->addPath($streamName, '', $details->getPaths()); } $details['name'] = $theme; $details['title'] = $details['details.name']; $details['preview_url'] = $locator('gantry-themes://' . $theme); // FIXME: $details['admin_url'] = 'FIXME'; $details['params'] = []; $list[$details->name] = $details; } } // Add Thumbnails links after adding all the paths to the locator. foreach ($list as $details) { $details['thumbnail'] = $details->getUrl("details.images.thumbnail"); } return $list; }
/** * @return array */ public static function getThemes() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $files = Folder::all('gantry-themes://', ['recursive' => false]); /** @var array|ThemeDetails[] $list */ $list = []; ksort($files); foreach ($files as $theme) { if (file_exists(PRIME_ROOT . '/themes/' . $theme . '/gantry/theme.yaml')) { $details = new ThemeDetails($theme); if (!$locator->schemeExists('gantry-theme-' . $theme)) { $locator->addPath('gantry-themes-' . $theme, '', $details->getPaths()); } $details['name'] = $theme; $details['title'] = $details['details.name']; $details['preview_url'] = rtrim(PRIME_URI, '/') . '/' . $theme; $details['admin_url'] = rtrim(PRIME_URI, '/') . '/' . $theme . '/admin/configurations/styles'; $details['params'] = []; $list[$details->name] = $details; } } // Add Thumbnails links after adding all the paths to the locator. foreach ($list as $details) { $details['thumbnail'] = $details->getUrl("details.images.thumbnail"); } return $list; }
/** * @return array */ public static function getStyles() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $files = Folder::all('gantry-themes://', ['recursive' => false]); $list = array(); foreach ($files as $theme) { if (file_exists($locator('gantry-themes://' . $theme . '/default/gantry/theme.yaml'))) { $details = new ThemeDetails($theme); if (!$locator->schemeExists('gantry-theme-' . $theme)) { $locator->addPath('gantry-themes-' . $theme, '', $details->getPaths()); } $details['name'] = $theme; $details['title'] = ucfirst($theme); $details['preview_url'] = '/' . $theme; $details['admin_url'] = '/' . $theme . '/admin'; $details['params'] = []; $list[$details->name] = $details; } } // Add Thumbnails links. foreach ($list as $details) { $details['thumbnail'] = self::getImage($locator, $details, 'thumbnail'); } return $list; }
/** * @return string */ public function addStreams() { $gantry = Gantry::instance(); // Initialize theme stream. $streamName = $this->addStream($this->offsetGet('name'), $this->getPaths()); // Initialize parent theme streams. $details = $this; while ($parent = $details->parent()) { $details = new ThemeDetails($parent); $this->addStream($parent, $details->getPaths()); } /** @var Streams $streams */ $streams = $gantry['streams']; $streams->register(); return $streamName; }
protected static function loadStyles() { // Load styles $db = \JFactory::getDbo(); $query = $db->getQuery(true)->select('s.id, e.extension_id, s.template AS name, s.title, s.params')->from('#__template_styles AS s')->where('s.client_id = 0')->where('e.enabled = 1')->leftJoin('#__extensions AS e ON e.element=s.template AND e.type=' . $db->quote('template') . ' AND e.client_id=s.client_id'); $db->setQuery($query); $templates = (array) $db->loadObjectList(); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; /** @var array|ThemeDetails[] $list */ $list = []; foreach ($templates as $template) { if (file_exists(JPATH_SITE . '/templates/' . $template->name . '/gantry/theme.yaml')) { $details = new ThemeDetails($template->name); // Stream needs to be valid URL. $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $template->name); if (!$locator->schemeExists($streamName)) { $locator->addPath($streamName, '', $details->getPaths()); } $params = new \JRegistry($template->params); $token = \JSession::getFormToken(); $details['id'] = $template->id; $details['extension_id'] = $template->extension_id; $details['name'] = $template->name; $details['title'] = $details['details.name']; $details['style'] = $template->title; $details['preview_url'] = \JUri::root(false) . 'index.php?templateStyle=' . $template->id; $details['admin_url'] = \JRoute::_("index.php?option=com_gantry5&view=configurations/default/styles&style={$template->id}&{$token}=1", false); $details['params'] = $params->toArray(); $list[$template->id] = $details; } } // Add Thumbnails links after adding all the paths to the locator. foreach ($list as $details) { $details['thumbnail'] = $details->getUrl('details.images.thumbnail'); } return $list; }
public function cleanup() { $name = $this->extension->name; $path = JPATH_SITE . '/templates/' . $name; // Remove compiled CSS files if they exist. $cssPath = $path . '/custom/css-compiled'; if (is_dir($cssPath)) { \JFolder::delete($cssPath); } elseif (is_file($cssPath)) { \JFile::delete($cssPath); } // Remove wrongly named file if it exists. $md5path = $path . '/MD5SUM'; if (is_file($md5path)) { \JFile::delete($md5path); } // Restart Gantry and initialize it. $gantry = Gantry::restart(); $gantry['theme.name'] = $name; $gantry['streams']->register(); // Only add error service if debug mode has been enabled. if ($gantry->debug()) { $gantry->register(new ErrorServiceProvider()); } /** @var Platform $patform */ $patform = $gantry['platform']; /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // Initialize theme stream. $details = new ThemeDetails($name); $locator->addPath('gantry-theme', '', $details->getPaths(), false, true); // Initialize theme cache stream and clear theme cache. $cachePath = $patform->getCachePath() . '/' . $name; if (is_dir($cachePath)) { Folder::delete($cachePath); } Folder::create($cachePath); $locator->addPath('gantry-cache', 'theme', [$cachePath], true, true); $gantry['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true); /** @var Outlines $outlines */ $outlines = $gantry['configurations']; // Update positions in manifest file. $positions = $outlines->positions(); $manifest = new Manifest($name); $manifest->setPositions(array_keys($positions)); $manifest->save(); }