protected function getInput() { $app = JFactory::getApplication(); // Detect Gantry Framework or fail gracefully. if (!class_exists('Gantry5\\Loader')) { $app->enqueueMessage(JText::sprintf('MOD_GANTRY5_PLUGIN_MISSING', JText::_('MOD_GANTRY5_PARTICLE')), 'error'); return ''; } if (!defined('GANTRYADMIN_PATH')) { define('GANTRYADMIN_PATH', JPATH_ADMINISTRATOR . '/components/com_gantry5'); } // Initialize administrator or fail gracefully. try { Gantry5\Loader::setup(); $this->container = Gantry\Framework\Gantry::instance(); $this->container['router'] = function ($c) { return new \Gantry\Admin\Router($c); }; } catch (Exception $e) { $app->enqueueMessage(JText::sprintf($e->getMessage()), 'error'); return ''; } // FIXME: Better style detection. $style = \Gantry\Joomla\StyleHelper::getStyle(['home' => 1, 'client_id' => 0]); $this->container['router']->setStyle($style->id)->load(); $field = ['default' => true, 'scope' => '', 'name' => $this->name, 'field' => ['type' => 'gantry.particle', 'label' => 'Particle', 'class' => 'input-small', 'picker_label' => 'Pick a Particle', 'overridable' => false], 'value' => json_decode($this->value, true)]; $params = ['content' => $this->container['admin.theme']->render('@gantry-admin/forms/fields/gantry/particle.html.twig', $field)]; return $this->container['admin.theme']->render('@gantry-admin/partials/layout.html.twig', $params); }
public function setTheme($theme, $style) { if ($style) { \JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables'); $table = \JTable::getInstance('Style', 'TemplatesTable'); $table->load(['id' => $style, 'client_id' => 0]); $theme = $table->template; } if (!$theme) { $theme = StyleHelper::getDefaultStyle()->template; } $path = JPATH_SITE . '/templates/' . $theme; if (!is_file("{$path}/gantry/theme.yaml")) { $theme = null; $this->container['streams']->register(); /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; $this->container['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true); } $this->container['base_url'] = \JUri::base(true) . '/index.php?option=com_gantry5'; $this->container['ajax_suffix'] = '&format=json'; $token = \JSession::getFormToken(); $this->container['routes'] = ['1' => "&view=%s&theme={$theme}&{$token}=1", 'themes' => '&view=themes', 'picker/layouts' => "&view=layouts&theme={$theme}&{$token}=1"]; if (!$theme) { return $this; } $this->container['theme.path'] = $path; $this->container['theme.name'] = $theme; // Load language file for the template. $languageFile = 'tpl_' . $theme; $lang = \JFactory::getLanguage(); $lang->load($languageFile, JPATH_SITE) || $lang->load($languageFile, $path) || $lang->load($languageFile, $path, 'en-GB'); return $this; }
public function setStyle($style) { $style = $style ? $style : StyleHelper::getDefaultStyle()->id; if ($style) { \JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables'); $table = \JTable::getInstance('Style', 'TemplatesTable'); $table->load(['id' => $style, 'client_id' => 0]); $template = $table->template; $path = JPATH_SITE . '/templates/' . $template; $this->container['theme.path'] = $path; $this->container['theme.name'] = $template; // Load language file for the template. $languageFile = 'tpl_' . $template; $lang = \JFactory::getLanguage(); $lang->load($languageFile, JPATH_SITE) || $lang->load($languageFile, $path) || $lang->load($languageFile, $path, 'en-GB'); } $this->container['base_url'] = \JUri::base(true) . '/index.php?option=com_gantry5'; $this->container['ajax_suffix'] = '&format=json'; $token = \JSession::getFormToken(); $this->container['routes'] = ['1' => "&view=%s&style={$style}&{$token}=1", 'themes' => '&view=themes', 'picker/layouts' => "&view=layouts&style={$style}&{$token}=1"]; return $this; }
/** * @param string $id * @return boolean */ public function canDelete($id) { $model = StyleHelper::loadModel(); $item = $model->getTable(); $item->load($id); if (!$item->id) { throw new \RuntimeException('Outline not found', 404); } return $item->home ? false : true; }
public function setAssignment($value) { $options = $this->assignmentOptions(); if (!isset($options[$value])) { throw new \RuntimeException('Invalid value for default assignment!', 400); } $style = StyleHelper::getStyle($this->style_id); $style->home = $value; if (!$style->check() || !$style->store()) { throw new \RuntimeException($style->getError()); } // Clean the cache. CacheHelper::cleanTemplates(); }
public function delete($id) { $model = StyleHelper::loadModel(); $item = $model->getTable(); $item->load($id); if (!$item->id) { throw new \RuntimeException('Configuration not found', 404); } try { if (!$model->delete($id)) { $error = $model->getError(); // Well, Joomla can always send enqueue message instead! if (!$error) { $messages = \JFactory::getApplication()->getMessageQueue(); $message = reset($messages); $error = $message ? $message['message'] : 'Unknown error'; } throw new \RuntimeException($error); } } catch (\Exception $e) { throw new \RuntimeException('Deleting configuration failed: ' . $e->getMessage(), 400, $e); } // Remove configuration directory. $gantry = $this->container; $locator = $gantry['locator']; $path = $locator("gantry-config://{$item->id}", true, true); if ($path) { Folder::delete($path); } }