/** * Prepare data hook. * * @return void */ protected function prepareData() { require_once JPATH_SITE . '/components/com_content/helpers/route.php'; $app = JFactory::getApplication(); $data = $this->getData(); $data->params = JComponentHelper::getParams('com_content'); $data->user = $user = JUser::getInstance($app->input->getUsername('username')); JModelLegacy::addIncludePath(\Windwalker\Helper\PathHelper::getSite('com_content') . '/models'); $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); $model->setState('params', $data->params); $access = !JComponentHelper::getParams('com_content')->get('show_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $model->setState('filter.published', 1); $model->setState('filter.access', $access); $model->setState('filter.author_id', (int) $user->id); $model->setState('list.ordering', 'a.created'); $model->setState('list.direction', 'DESC'); $model->setState('list.limit', 10); $data->items = $model->getItems(); $data->pagination = $model->getPagination(); foreach ($data->items as &$item) { $item->slug = $item->id . ':' . $item->alias; $item->catslug = $item->catid . ':' . $item->category_alias; $item->params = $data->params; if ($access || in_array($item->access, $authorised)) { // We know that user has the privilege to view the article $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language)); } else { $item->link = JRoute::_('index.php?option=com_users&view=login'); } $item->parent_slug = $item->parent_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // No link for ROOT category if ($item->parent_alias == 'root') { $item->parent_slug = null; } $item->event = new stdClass(); $dispatcher = JEventDispatcher::getInstance(); // Old plugins: Ensure that text property is available if (!isset($item->text)) { $item->text = $item->introtext; } $app->input->set('option', 'com_content'); $app->input->set('view', 'category'); $app->input->set('layout', 'blog'); JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentPrepare', array('com_content.category', &$item, &$item->params, 0)); // Old plugins: Use processed text as introtext $item->introtext = $item->text; $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); $app->input->set('option', 'com_userxtd'); $app->input->set('view', 'content'); $app->input->set('layout', 'default'); } $this->setTitle(); }
/** * Get routing config. * * @param string $option The component option name. * * @return mixed */ public static function getRouting($option) { if (self::$routing) { return self::$routing; } $path = PathHelper::getSite($option); return self::$routing = json_decode(file_get_contents($path . '/routing.json')); }
/** * Method to get the record form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return JForm A JForm object on success, false on failure */ public function getForm($data = array(), $loadData = true) { // Get Registration Form from om_users JForm::addFormPath(\Windwalker\Helper\PathHelper::getSite('com_users') . '/models/forms'); $form = $this->loadForm("{$this->option}.{$this->viewItem}", 'registration', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } return $form; }
/** * Get routing config. * * @param string $option The component option name. * @param string $type The routing file type. * * @return mixed */ public static function getRouting($option, $type = self::TYPE_YAML) { if (self::$routing) { return self::$routing; } $path = PathHelper::getSite($option); $fileType = $type == static::TYPE_YAML ? 'yml' : $type; $data = new Registry(); $data->loadFile($path . '/routing.' . $fileType, $type); return self::$routing = $data->toArray(); }
/** * configurePath * * @return $this */ protected function configurePath() { $config = $this->config; $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client'])); $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']); $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']); // Replace DS $config['dir.dest'] = Path::clean($config['dir.dest']); $config['dir.tmpl'] = Path::clean($config['dir.tmpl']); $config['dir.src'] = Path::clean($config['dir.src']); return $this; }
/** * prepareExecute * * @return void */ protected function prepareExecute() { $element = $this->getArgument(1); $client = strtolower($this->getOption('c')); $class = $this->getOption('class'); if ($element) { list($type, $name, $group) = array_values(ExtensionHelper::extractElement($element)); if ($client == 'admin') { $client = 'administrator'; } if ($type == 'plugin') { $client = 'site'; } elseif ($type == 'component') { $client = 'administrator'; } } $path = JPATH_ROOT . '/resources/seeders'; $classPath = $path . '/' . $class . '.php'; if (!file_exists($classPath) && $element) { $path = PathHelper::get($element, $client); $classPath = $path . '/src/' . ucfirst($name) . '/Seed/' . $class . '.php'; } if (file_exists($classPath)) { include_once $classPath; } $className = $class; if (!class_exists($className)) { $className = sprintf('%s\\Seed\\%s', ucfirst($name), ucfirst($class)); } if (!class_exists($className)) { throw new \UnexpectedValueException('Class: ' . $class . ' not found.'); } // Auto include classes $path = dirname(ReflectionHelper::getPath($className)); $files = \JFolder::files($path, '.', false, true); /** @var \SplFileInfo $file */ foreach ($files as $file) { $file = new \SplFileInfo($file); \JLoader::register($file->getBasename('.php'), $file->getPathname()); } $this->app->set('seed.class', $className); }
/** * Constructor. * * @param \Windwalker\DI\Container $container * @param \Muse\IO\IOInterface $io * @param Registry $config */ public function __construct(Container $container, IOInterface $io, Registry $config = null) { // Get item & list name $ctrl = $config['ctrl'] ?: $io->getArgument(1); $ctrl = explode('.', $ctrl); $inflector = \JStringInflector::getInstance(); if (empty($ctrl[0])) { $ctrl[0] = 'item'; } if (empty($ctrl[1])) { $ctrl[1] = $inflector->toPlural($ctrl[0]); } list($itemName, $listName) = $ctrl; $replace['extension.element.lower'] = strtolower($config['element']); $replace['extension.element.upper'] = strtoupper($config['element']); $replace['extension.element.cap'] = ucfirst($config['element']); $replace['extension.name.lower'] = strtolower($config['name']); $replace['extension.name.upper'] = strtoupper($config['name']); $replace['extension.name.cap'] = ucfirst($config['name']); $replace['controller.list.name.lower'] = strtolower($listName); $replace['controller.list.name.upper'] = strtoupper($listName); $replace['controller.list.name.cap'] = ucfirst($listName); $replace['controller.item.name.lower'] = strtolower($itemName); $replace['controller.item.name.upper'] = strtoupper($itemName); $replace['controller.item.name.cap'] = ucfirst($itemName); // Set replace to config. foreach ($replace as $key => $val) { $config->set('replace.' . $key, $val); } // Set copy dir. $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client'])); $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']); $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']); // Replace DS $config['dir.dest'] = Path::clean($config['dir.dest']); $config['dir.tmpl'] = Path::clean($config['dir.tmpl']); $config['dir.src'] = Path::clean($config['dir.src']); // Push container $this->container = $container; parent::__construct($io, $config, $replace); }
/** * Execute Component. * * @param string $option Component option name. * @param string $client `admin` or `site`. * @param array $input Input object. * * @return mixed */ public static function executeComponent($option, $client = 'site', $input = array()) { $element = ExtensionHelper::extractElement($option); $input = new \JInput($input); // Prevent class conflict class_alias('JString', 'Joomla\\String\\String'); if (!defined('JPATH_COMPONENT_ADMINISTRATOR')) { define('JPATH_COMPONENT_ADMINISTRATOR', PathHelper::get($option, 'admin')); define('JPATH_COMPONENT_SITE', PathHelper::get($option, 'site')); define('JPATH_COMPONENT', PathHelper::get($option, $client)); } $_SERVER['HTTP_HOST'] = 'windwalker'; if ($client == 'admin') { $client = 'administrator'; } $appClass = 'JApplication' . ucfirst($client); $console = \JFactory::$application; \JFactory::$application = $appClass::getInstance('site', $input); $class = ucfirst($element['name']) . 'Component'; $component = new $class(ucfirst($element['name']), $input, \JFactory::$application); $result = $component->execute(); \JFactory::$application = $console; return $result; }
/** * Get search fields from form xml. * * @return array Search fields. */ public function getSearchFields() { if ($this->searchFields) { return $this->searchFields; } $file = PathHelper::get($this->option) . '/model/form/' . $this->name . '/filter.xml'; if (!is_file($file)) { return array(); } $xml = simplexml_load_file($file); $field = $xml->xpath('//fields[@name="search"]/field[@name="field"]'); $options = $field[0]->option; $fields = array(); foreach ($options as $option) { $attr = $option->attributes(); if ('*' == (string) $attr['value']) { continue; } $fields[] = (string) $attr['value']; } return $this->searchFields = $fields; }
/** * Load language from an extension. * * @param string $ext Extension element name, eg: com_content, plg_group_name. * @param string $client site or admin. * * @return boolean */ public static function loadLanguage($ext, $client = 'site') { $lang = Container::getInstance()->get('language'); return $lang->load($ext, JPATH_BASE, null, false, false) || $lang->load($ext, PathHelper::get($ext, $client), null, false, false) || $lang->load($ext, JPATH_BASE, null, true) || $lang->load($ext, PathHelper::get($ext, $client), null, true); }
/** * Get config file path. * * @return string */ public static function getPath() { $type = static::$type; $ext = static::$type == 'yaml' ? 'yml' : $type; return PathHelper::getAdmin('COPYMODULES') . '/etc/config.' . $ext; }
* * @copyright Copyright (C) 2015 {ORGANIZATION}. All rights reserved. * @license GNU General Public License version 2 or later; */ /** * @var \Windwalker\View\Engine\PhpEngine $this */ $params = $this->params = $data->params; foreach ($data as $k => $v) { $this->{$k} = $v; } // Templates $app = JFactory::getApplication(); $layout = JPATH_THEMES . '/' . $app->getTemplate() . '/html/com_content/category/blog_item.php'; if (!is_file($layout)) { $layout = \Windwalker\Helper\PathHelper::getSite('com_content') . '/views/category/tmpl/blog_item.php'; } ?> <div class="row-fluid"> <div class="span12"> <?php $article = new stdClass(); $article->created_by = $data->user->id; echo \Userxtd\Content\UserInfo::createInfoBox(\Windwalker\DI\Container::getInstance('com_userxtd'), $article); ?> <?php foreach ($data->items as $item) { ?> <?php $this->item = $item;
/** * testException * * @expectedException InvalidArgumentException * * @return void */ public function testException() { PathHelper::get(null, null, null); }