protected function __construct() { parent::__construct(); $gantry = Gantry::instance(); if (isset($gantry['file.yaml.cache.path'])) { $this->setCachePath($gantry['file.yaml.cache.path']); } }
/** * Save assignments for the configuration. * * @param array $data */ public function save(array $data) { $data = $data['assignments']; foreach ($data as $tname => &$type) { foreach ($type as $gname => &$group) { foreach ($group as $key => $value) { if (!$value) { unset($group[$key]); } else { $group[$key] = (bool) $value; } } if (empty($group)) { unset($type[$gname]); } } if (empty($type)) { unset($data[$tname]); } } $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // Save layout into custom directory for the current theme. $save_dir = $locator->findResource("gantry-config://{$this->configuration}", true, true); $filename = "{$save_dir}/assignments.yaml"; $file = YamlFile::instance($filename); $file->save($data); $file->free(); }
/** * @return array */ public static function getThemes() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $files = Folder::all('gantry-themes://', ['recursive' => false, 'files' => false]); /** @var array|ThemeDetails[] $list */ $list = []; natsort($files); foreach ($files as $theme) { 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'] = $gantry['platform']->getThemePreviewUrl($theme); $details['admin_url'] = $gantry['platform']->getThemeAdminUrl($theme); $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; }
public function onThemeInitialized() { /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; $path = $locator('theme://'); $name = $this->name; if (!class_exists('\\Gantry5\\Loader')) { if ($this->isAdmin()) { $messages = $this->grav['messages']; $messages->add('Please enable Gantry 5 plugin in order to use current theme!', 'error'); return; } else { throw new \LogicException('Please install and enable Gantry 5 Framework plugin!'); } } // Setup Gantry 5 Framework or throw exception. \Gantry5\Loader::setup(); // Get Gantry instance. $gantry = Gantry::instance(); // Set the theme path from Grav variable. $gantry['theme.path'] = $path; $gantry['theme.name'] = $name; // Define the template. require $locator('theme://includes/theme.php'); // Define Gantry services. $gantry['theme'] = function ($c) { return new \Gantry\Theme\Hydrogen($c['theme.path'], $c['theme.name']); }; }
/** * @see AbstractTheme::init() */ protected function init() { parent::init(); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; \JPluginHelper::importPlugin('gantry5'); // Trigger the onGantryThemeInit event. $dispatcher = \JEventDispatcher::getInstance(); $dispatcher->trigger('onGantry5ThemeInit', ['theme' => $this]); $lang = \JFactory::getLanguage(); // FIXME: Do not hardcode this file. $lang->load('files_gantry5_nucleus', JPATH_SITE); if (\JFactory::getApplication()->isSite()) { // Load our custom positions file as frontend requires the strings to be there. $filename = $locator("gantry-theme://language/en-GB/en-GB.tpl_{$this->name}_positions.ini"); if ($filename) { $lang->load("tpl_{$this->name}_positions", dirname(dirname(dirname($filename))), 'en-GB'); } } $doc = \JFactory::getDocument(); $this->language = $doc->language; $this->direction = $doc->direction; $this->url = \JUri::root(true) . '/templates/' . $this->name; }
function gantry_admin_print_scripts() { $scripts = \Gantry\Framework\Gantry::instance()->scripts(); if ($scripts) { echo implode("\n", $scripts) . "\n"; } }
/** * Get global Gantry instance. * * @return Gantry */ public static function gantry() { // We cannot set variable directly for the trait as it doesn't work in HHVM. if (!self::$gantry) { self::$gantry = Gantry::instance(); } return self::$gantry; }
public static function delete($id) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $path = $locator->findResource('gantry-config://' . $id, true, true); if (is_dir($path)) { Folder::delete($path, true); } }
public function widgets_init() { $gantry = Gantry::instance(); $positions = $gantry['configurations']->positions(); foreach ($positions as $name => $title) { // FIXME // This should be handled by theme so translation plugins could catch it as part of theme. // This stuff might also need take Joomla chromes into account for cross-compatibility reasons register_sidebar(array('name' => __($title, 'gantry5'), 'id' => $name, 'description' => __($title, 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } }
public function __construct() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $finder = new ConfigFileFinder(); // Generate a flat list of all existing pages containing a list of file paths with timestamps. $this->items = $finder->listFiles($locator->findResources('gantry-pages://'), '|\\.html\\.twig|'); // And list the pages in alphabetical order. ksort($this->items); }
public function bodyAttributes($attributes = []) { $gantry = Gantry::instance(); $classes = ['site', "dir-ltr", "outline-{$gantry['configuration']}"]; $baseAttributes = (array) $this->config->get('page.body.attribs', []); if (!empty($baseAttributes['class'])) { $baseAttributes['class'] = array_merge((array) $baseAttributes['class'], $classes); } else { $baseAttributes['class'] = $classes; } return $this->getAttributes($baseAttributes, $attributes); }
public function loadAssignments() { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // Find all the assignment files. $paths = $locator->findResources("gantry-config://"); $files = (new ConfigFileFinder())->locateFileInFolder('assignments', $paths); $cache = $locator->findResource('gantry-cache://theme/compiled/config', true, true); $config = new CompiledConfig($cache, [$files]); return $config->load(); }
public function add_to_twig(\Twig_Environment $twig, \Twig_Loader_Filesystem $loader = null) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; if (!$loader) { $loader = $twig->getLoader(); } $loader->setPaths($locator->findResources('gantry-admin://templates'), 'gantry-admin'); $twig->addExtension(new TwigExtension()); return $twig; }
public function onGlobalSave(Event $event) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $filename = 'config://plugins/gantry5.yaml'; $file = YamlFile::instance($locator->findResource($filename, true, true)); $content = $file->content(); $content['production'] = (bool) $event->data['production']; $file->save($content); $file->free(); }
public function widgets_init() { $gantry = Gantry::instance(); $positions = (array) $gantry['config']->get('positions'); foreach ($positions as $name => $params) { $params = (array) $params; if (!isset($params['name'])) { $params['name'] = ucfirst($name); } register_sidebar(array('name' => __($params['name'], 'gantry5'), 'id' => $name, 'description' => __($params['name'], 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>')); } }
function gantry5_install_clear_cache($upgrader, $options) { // Clear gantry cache after plugin / theme installs. if (isset($options['type']) && in_array($options['type'], array('plugin', 'theme')) && class_exists('Gantry\\Framework\\Gantry')) { global $wp_filesystem; $gantry = \Gantry\Framework\Gantry::instance(); $path = $gantry['platform']->getCachePath(); if ($wp_filesystem->is_dir($path)) { $wp_filesystem->rmdir($path); } $upgrader->skin->feedback('Gantry 5 cache cleared.'); } }
public function render($file, array $context = array()) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-admin://templates')); $params = array('cache' => $locator->findResource('gantry-cache://theme/twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html'); $twig = new \Twig_Environment($loader, $params); $this->add_to_twig($twig); // Include Gantry specific things to the context. $context = $this->add_to_context($context); return $twig->render($file, $context); }
public static function copy($style, $old, $new) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $oldPath = $locator->findResource('gantry-config://' . $old, true, true); $newPath = $locator->findResource('gantry-config://' . $new, true, true); if (file_exists($oldPath)) { Folder::copy($oldPath, $newPath); } $installer = new TemplateInstaller($style->extension_id); $installer->updateStyle($new, ['configuration' => $new]); }
protected function __construct() { parent::__construct(); $gantry = Gantry::instance(); /** @var Config $global */ $global = $gantry['global']; if (!$global->get('compile_yaml', 1)) { $this->caching(false); } if (isset($gantry['file.yaml.cache.path'])) { $this->setCachePath($gantry['file.yaml.cache.path']); } }
public function __construct() { global $pagenow; parent::__construct('particle_widget', __('Gantry 5 Particle', 'gantry5'), ['description' => __('Displays Gantry 5 particle instance in a widget position.', 'gantry5'), 'gantry5' => true]); try { $this->container = Gantry::instance(); } catch (Exception $e) { } $ajax = $pagenow === 'admin-ajax.php' && (isset($_POST['action']) && $_POST['action'] === 'save-widget'); if (is_admin() && (in_array($pagenow, ['widgets.php', 'customize.php']) || $ajax)) { // Initialize administrator if already not done that. $this->initialiseGantry(); } }
public function render($file, array $context = array()) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-engine://twig')); $params = array('cache' => $locator('gantry-cache://twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html'); // FIXME: Get timezone from WP. $timezone = 'UTC'; $twig = new \Twig_Environment($loader, $params); $twig->getExtension('core')->setTimezone(new \DateTimeZone($timezone)); $this->add_to_twig($twig); // Include Gantry specific things to the context. $context = $this->add_to_context($context); return $twig->render($file, $context); }
public function renderer() { if (!$this->renderer) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-engine://twig')); $loader->setPaths($locator->findResources('gantry-pages://'), 'pages'); $loader->setPaths($locator->findResources('gantry-positions://'), 'positions'); $params = array('cache' => $locator('gantry-cache://twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html'); $twig = new \Twig_Environment($loader, $params); $this->add_to_twig($twig); $this->renderer = $twig; } return $this->renderer; }
public function runAdmin() { $theme = $this->grav['theme']; if (!$theme instanceof \Gantry\Framework\Theme) { return; } $gantry = Gantry::instance(); $gantry['base_url'] = $this->base; $gantry['router'] = function ($c) { return new Router($c); }; // Dispatch to the controller. //$gantry['router']->dispatch(); $this->grav['gantry5'] = $gantry; $this->enable(['onPagesInitialized' => ['onPagesInitialized', 900], 'onTwigInitialized' => ['onTwigInitialized', 900], 'onTwigSiteVariables' => ['onTwigSiteVariables', 900]]); }
public function renderer() { if (!$this->renderer) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-engine://twig')); $params = array('cache' => $locator('gantry-cache://twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html'); $twig = new \Twig_Environment($loader, $params); $this->add_to_twig($twig); $doc = \JFactory::getDocument(); $this->language = $doc->language; $this->direction = $doc->direction; $this->renderer = $twig; } return $this->renderer; }
protected function load($language, $section) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $section = strtolower($section); $filename = 'gantry-admin://translations/' . $language . '/' . $section . '.yaml'; $file = CompiledYamlFile::instance($filename); if (!$file->exists() && ($pos = strpos($language, '-')) > 0) { $filename = 'gantry-admin://translations/' . substr($language, 0, $pos) . '/' . $section . '.yaml'; $file = CompiledYamlFile::instance($filename); } $cachePath = $locator->findResource('gantry-cache://translations', true, true); $translations = (array) $file->setCachePath($cachePath)->content(); $file->free(); return $translations; }
public function renderer() { if (!$this->renderer) { $gantry = \Gantry\Framework\Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-engine://twig')); $params = array('cache' => $locator('gantry-cache://twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html'); // Get user timezone and if not set, use Joomla default. $timezone = \JFactory::getUser()->getParam('timezone', \JFactory::getConfig()->get('offset', 'UTC')); $twig = new \Twig_Environment($loader, $params); $twig->getExtension('core')->setTimezone(new \DateTimeZone($timezone)); $this->add_to_twig($twig); $doc = \JFactory::getDocument(); $this->language = $doc->language; $this->direction = $doc->direction; $this->renderer = $twig; } return $this->renderer; }
public function __construct() { global $pagenow; parent::__construct('particle_widget', __('Gantry 5 Particle', 'gantry5'), ['description' => __('Displays Gantry 5 particle instance in a widget position.', 'gantry5'), 'gantry5' => true]); try { $this->container = Gantry::instance(); } catch (Exception $e) { } $ajax = $pagenow === 'admin-ajax.php' && (isset($_POST['action']) && $_POST['action'] === 'save-widget'); if (is_admin() && (in_array($pagenow, ['widgets.php', 'customize.php']) || $ajax)) { // Initialize administrator if already not done that. if (!isset($this->container['router'])) { $this->container['router'] = function ($c) { return new Router($c); }; $this->container['router']->boot()->load(); $this->container['admin.theme']->render('@gantry-admin/partials/layout.html.twig', ['content' => '']); } } }
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; }
protected function createMeta($out, $md5) { $gantry = Gantry::instance(); if ($this->production) { return; } /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $uri = basename($out); $metaFile = PhpFile::instance($locator->findResource("gantry-cache://theme/scss/{$uri}.php", true, true)); $metaFile->save(['file' => $out, 'timestamp' => filemtime($locator->findResource($out)), 'md5' => $md5, 'variables' => $this->getVariables(), 'imports' => $this->compiler->getParsedFiles()]); $metaFile->free(); }
/** * @package Gantry 5 * @author RocketTheme http://www.rockettheme.com * @copyright Copyright (C) 2007 - 2015 RocketTheme, LLC * @license GNU/GPLv2 and later * * http://www.gnu.org/licenses/gpl-2.0.html */ defined('_JEXEC') or die; // Detect Gantry Framework or fail gracefully. if (!class_exists('Gantry\\Framework\\Gantry')) { $lang = JFactory::getLanguage(); JFactory::getApplication()->enqueueMessage(JText::sprintf('MOD_GANTRY5_PARTICLE_NOT_INITIALIZED', JText::_('MOD_GANTRY5_PARTICLE')), 'warning'); return; } $gantry = \Gantry\Framework\Gantry::instance(); /** @var Gantry\Framework\Theme $theme */ $theme = $gantry['theme']; /** @var object $params */ $data = json_decode($params->get('particle'), true); $type = $data['type']; $particle = $data['particle']; if ($gantry->debug()) { $enabled_outline = $gantry['config']->get("particles.{$particle}.enabled", true); $enabled = isset($data['options']['particle']['enabled']) ? $data['options']['particle']['enabled'] : true; $location = !$enabled_outline ? 'Outline' : (!$enabled ? 'Module' : null); if ($location) { echo '<div class="alert alert-error">The Particle has been disabled from the ' . $location . ' and won\'t render.</div>'; return; } }