/** * Configure the Submenu links. * * @param string The extension being used for the categories. * * @return void * @since 1.6 */ public static function addSubmenu($extension) { // Avoid nonsense situation. if ($extension == 'com_categories') { return; } $parts = explode('.', $extension); $component = $parts[0]; if (count($parts) > 1) { $section = $parts[1]; } // Try to find the component helper. $eName = str_replace('com_', '', $component); $file = Filesystem::cleanPath(PATH_CORE . '/components/' . $component . '/admin/helpers/' . $eName . '.php'); if (file_exists($file)) { require_once $file; $prefix = ucfirst(str_replace('com_', '', $component)); $cName = $prefix . 'Helper'; if (class_exists($cName)) { if (is_callable(array($cName, 'addSubmenu'))) { $lang = Lang::getRoot(); // loading language file from the administrator/language directory then // loading language file from the administrator/components/*extension*/language directory $lang->load($component, JPATH_BASE, null, false, true) || $lang->load($component, Filesystem::cleanPath(PATH_CORE . '/components/' . $component . '/admin'), null, false, true); call_user_func(array($cName, 'addSubmenu'), 'categories' . (isset($section) ? '.' . $section : '')); } } } }
/** * Method to get a list of all the files to edit in a template. * * @return array A nested array of relevant files. * @since 1.6 */ public function getFiles() { // Initialise variables. $result = array(); if ($template = $this->getTemplate()) { $client = JApplicationHelper::getClientInfo($template->client_id); $path = Filesystem::cleanPath($client->path . '/templates/' . $template->element . '/'); $lang = Lang::getRoot(); // Load the core and/or local language file(s). $lang->load('tpl_' . $template->element, $client->path, null, false, true) || $lang->load('tpl_' . $template->element, $client->path . '/templates/' . $template->element, null, false, true); // Check if the template path exists. if (is_dir($path)) { $result['main'] = array(); $result['css'] = array(); $result['clo'] = array(); $result['mlo'] = array(); $result['html'] = array(); // Handle the main PHP files. $result['main']['index'] = $this->getFile($path, 'index.php'); $result['main']['error'] = $this->getFile($path, 'error.php'); $result['main']['print'] = $this->getFile($path, 'component.php'); $result['main']['offline'] = $this->getFile($path, 'offline.php'); // Handle the CSS files. $files = Filesystem::files($path . '/css', '\\.css$', true, true); foreach ($files as $file) { $file = str_replace($client->path . '/templates/' . $template->element . '/', '', $file); $result['css'][] = $this->getFile($path . '/css/', $file); } } else { $this->setError(Lang::txt('COM_TEMPLATES_ERROR_TEMPLATE_FOLDER_NOT_FOUND')); return false; } } return $result; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { Request::setVar('hidemainmenu', true); $isNew = $this->item->id == 0; $canDo = TemplatesHelper::getActions(); Toolbar::title($isNew ? Lang::txt('COM_TEMPLATES_MANAGER_ADD_STYLE') : Lang::txt('COM_TEMPLATES_MANAGER_EDIT_STYLE'), 'thememanager'); // If not checked out, can save the item. if ($canDo->get('core.edit')) { Toolbar::apply('style.apply'); Toolbar::save('style.save'); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { Toolbar::save2copy('style.save2copy'); } if (empty($this->item->id)) { Toolbar::cancel('style.cancel'); } else { Toolbar::cancel('style.cancel', 'JTOOLBAR_CLOSE'); } Toolbar::divider(); // Get the help information for the template item. $lang = Lang::getRoot(); $help = $this->get('Help'); if ($lang->hasKey($help->url)) { $debug = $lang->setDebug(false); $url = Lang::txt($help->url); $lang->setDebug($debug); } else { $url = null; } Toolbar::help('style'); //$help->key, false, $url); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { Request::setVar('hidemainmenu', true); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == User::get('id')); $canDo = MenusHelper::getActions($this->state->get('filter.parent_id')); Toolbar::title(Lang::txt($isNew ? 'COM_MENUS_VIEW_NEW_ITEM_TITLE' : 'COM_MENUS_VIEW_EDIT_ITEM_TITLE'), 'menu-add'); // If a new item, can save the item. Allow users with edit permissions to apply changes to prevent returning to grid. if ($isNew && $canDo->get('core.create')) { if ($canDo->get('core.edit')) { Toolbar::apply('item.apply'); } Toolbar::save('item.save'); } // If not checked out, can save the item. if (!$isNew && !$checkedOut && $canDo->get('core.edit')) { Toolbar::apply('item.apply'); Toolbar::save('item.save'); } // If the user can create new items, allow them to see Save & New if ($canDo->get('core.create')) { Toolbar::save2new('item.save2new'); } // If an existing item, can save to a copy only if we have create rights. if (!$isNew && $canDo->get('core.create')) { Toolbar::save2copy('item.save2copy'); } if ($isNew) { Toolbar::cancel('item.cancel'); } else { Toolbar::cancel('item.cancel', 'JTOOLBAR_CLOSE'); } Toolbar::divider(); // Get the help information for the menu item. $lang = Lang::getRoot(); $help = $this->get('Help'); if ($lang->hasKey($help->url)) { $debug = $lang->setDebug(false); $url = Lang::txt($help->url); $lang->setDebug($debug); } else { $url = $help->url; } Toolbar::help('item'); //$help->key, $help->local, $url); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { Request::setVar('hidemainmenu', true); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == User::get('id')); $canDo = ModulesHelper::getActions($this->state->get('filter.category_id'), $this->item->id); $item = $this->get('Item'); Toolbar::title(Lang::txt('COM_MODULES_MANAGER_MODULE', Lang::txt($this->item->module)), 'module.png'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { Toolbar::apply('module.apply'); Toolbar::save('module.save'); } if (!$checkedOut && $canDo->get('core.create')) { Toolbar::save2new('module.save2new'); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { Toolbar::save2copy('module.save2copy'); } if (empty($this->item->id)) { Toolbar::cancel('module.cancel'); } else { Toolbar::cancel('module.cancel', 'JTOOLBAR_CLOSE'); } // Get the help information for the menu item. $lang = Lang::getRoot(); $help = $this->get('Help'); if ($lang->hasKey($help->url)) { $debug = $lang->setDebug(false); $url = Lang::txt($help->url); $lang->setDebug($debug); } else { $url = null; } Toolbar::help('module'); //$help->key, false, $url); }
/** * Display the view */ public function display($tpl = null) { $lang = Lang::getRoot(); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); } $this->ordering = array(); // Preprocess the list of items to find ordering divisions. foreach ($this->items as $item) { $this->ordering[$item->parent_id][] = $item->id; // item type text switch ($item->type) { case 'url': $value = Lang::txt('COM_MENUS_TYPE_EXTERNAL_URL'); break; case 'alias': $value = Lang::txt('COM_MENUS_TYPE_ALIAS'); break; case 'separator': $value = Lang::txt('COM_MENUS_TYPE_SEPARATOR'); break; case 'component': default: // load language $lang->load($item->componentname . '.sys', PATH_APP, null, false, true) || $lang->load($item->componentname . '.sys', PATH_APP . '/components/' . $item->componentname . '/admin', null, false, true) || $lang->load($item->componentname . '.sys', PATH_CORE . '/components/' . $item->componentname . '/admin', null, false, true); if (!empty($item->componentname)) { $value = Lang::txt($item->componentname); $vars = null; parse_str($item->link, $vars); if (isset($vars['view'])) { // Attempt to load the view xml file. $file = JPATH_SITE . '/components/' . $item->componentname . '/views/' . $vars['view'] . '/metadata.xml'; if (Filesystem::exists($file) && ($xml = simplexml_load_file($file))) { // Look for the first view node off of the root node. if ($view = $xml->xpath('view[1]')) { if (!empty($view[0]['title'])) { $vars['layout'] = isset($vars['layout']) ? $vars['layout'] : 'default'; // Attempt to load the layout xml file. // If Alternative Menu Item, get template folder for layout file if (strpos($vars['layout'], ':') > 0) { // Use template folder for layout file $temp = explode(':', $vars['layout']); $file = JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $item->componentname . '/' . $vars['view'] . '/' . $temp[1] . '.xml'; // Load template language file $lang->load('tpl_' . $temp[0] . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $temp[0] . '.sys', JPATH_SITE . '/templates/' . $temp[0], null, false, true); } else { // Get XML file from component folder for standard layouts $file = JPATH_SITE . '/components/' . $item->componentname . '/views/' . $vars['view'] . '/tmpl/' . $vars['layout'] . '.xml'; } if (Filesystem::exists($file) && ($xml = simplexml_load_file($file))) { // Look for the first view node off of the root node. if ($layout = $xml->xpath('layout[1]')) { if (!empty($layout[0]['title'])) { $value .= ' » ' . Lang::txt(trim((string) $layout[0]['title'])); } } if (!empty($layout[0]->message[0])) { $item->item_type_desc = Lang::txt(trim((string) $layout[0]->message[0])); } } } } unset($xml); } else { // Special case for absent views $value .= ' » ' . Lang::txt($item->componentname . '_' . $vars['view'] . '_VIEW_DEFAULT_TITLE'); } } } else { if (preg_match("/^index.php\\?option=([a-zA-Z\\-0-9_]*)/", $item->link, $result)) { $value = Lang::txt('COM_MENUS_TYPE_UNEXISTING', $result[1]); } else { $value = Lang::txt('COM_MENUS_TYPE_UNKNOWN'); } } break; } $item->item_type = $value; } // Levels filter. $options = array(); $options[] = Html::select('option', '1', Lang::txt('J1')); $options[] = Html::select('option', '2', Lang::txt('J2')); $options[] = Html::select('option', '3', Lang::txt('J3')); $options[] = Html::select('option', '4', Lang::txt('J4')); $options[] = Html::select('option', '5', Lang::txt('J5')); $options[] = Html::select('option', '6', Lang::txt('J6')); $options[] = Html::select('option', '7', Lang::txt('J7')); $options[] = Html::select('option', '8', Lang::txt('J8')); $options[] = Html::select('option', '9', Lang::txt('J9')); $options[] = Html::select('option', '10', Lang::txt('J10')); $this->f_levels = $options; parent::display($tpl); $this->addToolbar(); }
/** * @param object A form object. * @param mixed The data expected for the form. * @throws Exception if there is an error in the form event. * @since 1.6 */ protected function preprocessForm(JForm $form, $data, $group = 'content') { // Initialise variables. $clientId = $this->getState('item.client_id'); $template = $this->getState('item.template'); $lang = Lang::getRoot(); $client = \Hubzero\Base\ClientManager::client($clientId); if (!$form->loadFile('style_' . $client->name, true)) { throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED')); } $base = PATH_CORE; if (is_dir(PATH_APP . '/templates/' . $template)) { $base = PATH_APP; } $formFile = Filesystem::cleanPath($base . '/templates/' . $template . '/templateDetails.xml'); // Load the core and/or local language file(s). $lang->load('tpl_' . $template, $base . '/bootstrap/' . $client->name, null, false, true) || $lang->load('tpl_' . $template, $base . '/templates/' . $template, null, false, true); if (file_exists($formFile)) { // Get the template form. if (!$form->loadFile($formFile, false, '//config')) { throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED')); } } // Disable home field if it is default style if (is_array($data) && array_key_exists('home', $data) && $data['home'] == '1' || is_object($data) && isset($data->home) && $data->home == '1') { $form->setFieldAttribute('home', 'readonly', 'true'); } // Attempt to load the xml file. if (!($xml = simplexml_load_file($formFile))) { throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED')); } // Get the help data from the XML file if present. $help = $xml->xpath('/extension/help'); if (!empty($help)) { $helpKey = trim((string) $help[0]['key']); $helpURL = trim((string) $help[0]['url']); $this->helpKey = $helpKey ? $helpKey : $this->helpKey; $this->helpURL = $helpURL ? $helpURL : $this->helpURL; } // Trigger the default form events. parent::preprocessForm($form, $data, $group); }
/** * Constructor * * @param array $config Optional configurations to be used * @return void */ public function __construct($config = array()) { $this->_redirect = null; $this->_message = null; $this->_messageType = 'message'; // Get the reflection info $r = new ReflectionClass($this); // Is it namespaced? if ($r->inNamespace()) { // It is! This makes things easy. $this->_controller = strtolower($r->getShortName()); } // Set the name if (empty($this->_name)) { if (isset($config['name'])) { $this->_name = $config['name']; } else { $segments = null; $cls = $r->getName(); // If namespaced... if (strstr($cls, '\\')) { $segments = explode('\\', $cls); } else { if (preg_match('/(.*)Controller(.*)/i', $cls, $segments)) { $this->_controller = isset($segments[2]) ? strtolower($segments[2]) : null; } else { throw new InvalidControllerException(Lang::txt('Controller::__construct() : Can\'t get or parse class name.'), 500); } } $this->_name = strtolower($segments[1]); } } // Set the base path if (array_key_exists('base_path', $config)) { $this->_basePath = $config['base_path']; } else { // Set base path relative to the controller file rather than // an absolute path. This gives us a little more flexibility. $this->_basePath = dirname(dirname($r->getFileName())); } // Set the component name $this->_option = 'com_' . $this->_name; // Determine the methods to exclude from the base class. $xMethods = get_class_methods('\\Hubzero\\Component\\SiteController'); // Get all the public methods of this class foreach ($r->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $name = $method->getName(); // Ensure task isn't in the exclude list and ends in 'Task' if ((!in_array($name, $xMethods) || $name == 'displayTask') && substr(strtolower($name), -4) == 'task') { // Remove the 'Task' suffix $name = substr($name, 0, -4); // Auto register the methods as tasks. $this->_taskMap[strtolower($name)] = $name; } } // get language object & get any loaded lang for option $lang = \Lang::getRoot(); $loaded = $lang->getPaths($this->_option); // Load language file if we dont have one yet if (!isset($loaded) || empty($loaded)) { $lang->load($this->_option, $this->_basePath . '/../..'); } // Set some commonly used vars // // [!] Deprecated // These will be going away in a future version. Do not use. $this->juser = \User::getRoot(); $this->database = \App::get('db'); $this->config = \Component::params($this->_option); }
<?php /** * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @since 1.6 */ defined('_HZEXEC_') or die; Html::behavior('keepalive'); Html::behavior('tooltip'); Html::behavior('formvalidation'); //load user_profile plugin language $lang = Lang::getRoot(); $lang->load('plg_user_profile', PATH_APP) || $lang->load('plg_user_profile', PATH_CORE . DS . 'plugins' . DS . 'user' . 'profile'); ?> <div class="profile-edit<?php echo $this->pageclass_sfx; ?> "> <?php if ($this->params->get('show_page_heading')) { ?> <h1><?php echo $this->escape($this->params->get('page_heading')); ?> </h1> <?php } ?>
protected function getTypeOptionsFromLayouts($component, $view) { // Initialise variables. $options = array(); $layouts = array(); $layoutNames = array(); $templateLayouts = array(); $lang = Lang::getRoot(); // Get the layouts from the view folder. $path = PATH_CORE . '/components/' . $component . '/views/' . $view . '/tmpl'; $path2 = PATH_CORE . '/components/' . $component . '/site/views/' . $view . '/tmpl'; if (Filesystem::exists($path)) { $layouts = array_merge($layouts, Filesystem::files($path, '.xml$', false, true)); } else { if (Filesystem::exists($path2)) { $layouts = array_merge($layouts, Filesystem::files($path2, '.xml$', false, true)); } else { return $options; } } // build list of standard layout names foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layoutNames[] = Filesystem::name(basename($layout)); } } // get the template layouts // TODO: This should only search one template -- the current template for this item (default of specified) $folders = Filesystem::directories(JPATH_SITE . '/templates', '', false, true); // Array to hold association between template file names and templates $templateName = array(); foreach ($folders as $folder) { if (Filesystem::exists($folder . '/html/' . $component . '/' . $view)) { $template = basename($folder); $lang->load('tpl_' . $template . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $template . '.sys', JPATH_SITE . '/templates/' . $template, null, false, true); $templateLayouts = Filesystem::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true); foreach ($templateLayouts as $layout) { $file = trim($layout, '/'); // Get the layout name. $templateLayoutName = Filesystem::name(basename($layout)); // add to the list only if it is not a standard layout if (array_search($templateLayoutName, $layoutNames) === false) { $layouts[] = $layout; // Set template name array so we can get the right template for the layout $templateName[$layout] = basename($folder); } } } } // Process the found layouts. foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layout = Filesystem::name(basename($layout)); // Create the menu option for the layout. $o = new \Hubzero\Base\Object(); $o->title = ucfirst($layout); $o->description = ''; $o->request = array('option' => $component, 'view' => $view); // Only add the layout request argument if not the default layout. if ($layout != 'default') { // If the template is set, add in format template:layout so we save the template name $o->request['layout'] = isset($templateName[$file]) ? $templateName[$file] . ':' . $layout : $layout; } // Load layout metadata if it exists. if (is_file($file)) { // Attempt to load the xml file. if ($xml = simplexml_load_file($file)) { // Look for the first view node off of the root node. if ($menu = $xml->xpath('layout[1]')) { $menu = $menu[0]; // If the view is hidden from the menu, discard it and move on to the next view. if (!empty($menu['hidden']) && $menu['hidden'] == 'true') { unset($xml); unset($o); continue; } // Populate the title and description if they exist. if (!empty($menu['title'])) { $o->title = trim((string) $menu['title']); } if (!empty($menu->message[0])) { $o->description = trim((string) $menu->message[0]); } } } } // Add the layout to the options array. $options[] = $o; } } return $options; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { // Initialise variables. $extension = Request::getCmd('extension'); $userId = User::get('id'); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId); // Avoid nonsense situation. if ($extension == 'com_categories') { return; } // The extension can be in the form com_foo.section $parts = explode('.', $extension); $component = $parts[0]; $section = count($parts) > 1 ? $parts[1] : null; // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = Lang::getRoot(); $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, PATH_CORE . '/components/' . $component . '/admin', null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, PATH_CORE . '/components/' . $component . '/admin', $lang->getDefault(), false, false); // Load the category helper. require_once JPATH_COMPONENT . '/helpers/categories.php'; // Get the results for each action. $canDo = CategoriesHelper::getActions($component, $this->item->id); // If a component categories title string is present, let's use it. if ($lang->hasKey($component_title_key = $component . ($section ? "_{$section}" : '') . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE')) { $title = Lang::txt($component_title_key); } elseif ($lang->hasKey($component_section_key = $component . ($section ? "_{$section}" : ''))) { $title = Lang::txt('COM_CATEGORIES_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', $this->escape(Lang::txt($component_section_key))); } else { $title = Lang::txt('COM_CATEGORIES_CATEGORY_BASE_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE'); } // Load specific css component Html::asset('stylesheet', $component . '/administrator/categories.css', array(), true); // Prepare the toolbar. Toolbar::title($title, 'category-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-{$section}" : '') . '-category-' . ($isNew ? 'add' : 'edit')); // For new records, check the create permission. if ($isNew && count(User::getAuthorisedCategories($component, 'core.create')) > 0) { Toolbar::apply('category.apply'); Toolbar::save('category.save'); Toolbar::save2new('category.save2new'); } elseif (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_user_id == $userId)) { Toolbar::apply('category.apply'); Toolbar::save('category.save'); if ($canDo->get('core.create')) { Toolbar::save2new('category.save2new'); } } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { Toolbar::save2copy('category.save2copy'); } if (empty($this->item->id)) { Toolbar::cancel('category.cancel'); } else { Toolbar::cancel('category.cancel', 'JTOOLBAR_CLOSE'); } Toolbar::divider(); // Compute the ref_key if it does exist in the component if (!$lang->hasKey($ref_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_HELP_KEY')) { $ref_key = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT'); } // Get help for the category/section view for the component by // -remotely searching in a language defined dedicated URL: *component*_HELP_URL // -locally searching in a component help file if helpURL param exists in the component and is set to '' // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { $debug = $lang->setDebug(false); $url = Lang::txt($lang_help_url); $lang->setDebug($debug); } else { $url = null; } Toolbar::help('category'); //$ref_key, Component::params( $component )->exists('helpURL'), $url, $component); }
/** * Method to get an array of data items. * * @return mixed An array of data items on success, false on failure. * @since 1.6 */ public function getItems() { if (!isset($this->items)) { $lang = Lang::getRoot(); $search = $this->getState('filter.search'); $state = $this->getState('filter.state'); $clientId = $this->getState('filter.client_id'); $filter_template = $this->getState('filter.template'); $type = $this->getState('filter.type'); $ordering = $this->getState('list.ordering'); $direction = $this->getState('list.direction'); $limitstart = $this->getState('list.start'); $limit = $this->getState('list.limit'); $client = JApplicationHelper::getClientInfo($clientId); if ($type != 'template') { // Get the database object and a new query object. $query = $this->_db->getQuery(true); $query->select('DISTINCT(position) as value'); $query->from('#__modules'); $query->where($this->_db->quoteName('client_id') . ' = ' . (int) $clientId); if ($search) { $query->where('position LIKE ' . $this->_db->quote('%' . $this->_db->escape($search, true) . '%')); } $this->_db->setQuery($query); $positions = $this->_db->loadObjectList('value'); // Check for a database error. if ($error = $this->_db->getErrorMsg()) { $this->setError($error); return false; } foreach ($positions as $value => $position) { $positions[$value] = array(); } } else { $positions = array(); } // Load the positions from the installed templates. foreach (ModulesHelper::getTemplates($clientId) as $template) { $path = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/templateDetails.xml'); if (file_exists($path)) { $xml = simplexml_load_file($path); if (isset($xml->positions[0])) { $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, true) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true); foreach ($xml->positions[0] as $position) { $value = (string) $position['value']; $label = (string) $position; if (!$value) { $value = $label; $label = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'TPL_' . $template->element . '_POSITION_' . $value); $altlabel = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'COM_MODULES_POSITION_' . $value); if (!$lang->hasKey($label) && $lang->hasKey($altlabel)) { $label = $altlabel; } } if ($type == 'user' || $state != '' && $state != $template->enabled) { unset($positions[$value]); } elseif (preg_match(chr(1) . $search . chr(1) . 'i', $value) && ($filter_template == '' || $filter_template == $template->element)) { if (!isset($positions[$value])) { $positions[$value] = array(); } $positions[$value][$template->name] = $label; } } } } } $this->total = count($positions); if ($limitstart >= $this->total) { $limitstart = $limitstart < $limit ? 0 : $limitstart - $limit; $this->setState('list.start', $limitstart); } if ($ordering == 'value') { if ($direction == 'asc') { ksort($positions); } else { krsort($positions); } } else { if ($direction == 'asc') { asort($positions); } else { arsort($positions); } } $this->items = array_slice($positions, $limitstart, $limit ? $limit : null); } return $this->items; }
/** * Method to preprocess the form * * @param JForm $form A form object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * * @since 1.6 * @throws Exception if there is an error loading the form. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { // Initialise variables. $lang = Lang::getRoot(); $clientId = $this->getState('item.client_id'); $module = $this->getState('item.module'); $client = \Hubzero\Base\ClientManager::client($clientId); //$formFile = JPath::clean($client->path.'/modules/'.$module.'/'.$module.'.xml'); $formFile = null; $patha = JPath::clean(PATH_APP . '/modules/' . $module . '/' . $module . '.xml'); $pathc = JPath::clean(PATH_CORE . '/modules/' . $module . '/' . $module . '.xml'); if (file_exists($patha)) { $formFile = $patha; } elseif (file_exists($pathc)) { $formFile = $pathc; } // Load the core and/or local language file(s). $lang->load($module, PATH_APP . '/bootstrap/' . $client->name, null, false, true) || $lang->load($module, PATH_APP . '/modules/' . $module, null, false, true) || $lang->load($module, PATH_CORE . '/modules/' . $module, null, false, true); if ($formFile) { // Get the module form. if (!$form->loadFile($formFile, false, '//config')) { throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED')); } // Attempt to load the xml file. if (!($xml = simplexml_load_file($formFile))) { throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED')); } // Get the help data from the XML file if present. $help = $xml->xpath('/extension/help'); if (!empty($help)) { $helpKey = trim((string) $help[0]['key']); $helpURL = trim((string) $help[0]['url']); $this->helpKey = $helpKey ? $helpKey : $this->helpKey; $this->helpURL = $helpURL ? $helpURL : $this->helpURL; } } // Trigger the default form events. parent::preprocessForm($form, $data, $group); }
/** * Method to get a menu item. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Menu item data object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { // Initialise variables. $pk = !empty($pk) ? $pk : (int) $this->getState('item.id'); // Get a level row instance. $table = $this->getTable(); // Attempt to load the row. $table->load($pk); // Check for a table object error. if ($error = $table->getError()) { $this->setError($error); $false = false; return $false; } // Prime required properties. if ($type = $this->getState('item.type')) { $table->type = $type; } if (empty($table->id)) { $table->parent_id = $this->getState('item.parent_id'); $table->menutype = $this->getState('item.menutype'); $table->params = '{}'; } // If the link has been set in the state, possibly changing link type. if ($link = $this->getState('item.link')) { // Check if we are changing away from the actual link type. if (MenusHelper::getLinkKey($table->link) != MenusHelper::getLinkKey($link)) { $table->link = $link; } } switch ($table->type) { case 'alias': $table->component_id = 0; $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); break; case 'separator': $table->link = ''; $table->component_id = 0; break; case 'url': $table->component_id = 0; parse_str(parse_url($table->link, PHP_URL_QUERY)); break; case 'component': default: // Enforce a valid type. $table->type = 'component'; // Ensure the integrity of the component_id field is maintained, particularly when changing the menu item type. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); if (isset($args['option'])) { // Load the language file for the component. $lang = Lang::getRoot(); $lang->load($args['option'], PATH_APP, null, false, true) || $lang->load($args['option'], PATH_APP . '/components/' . $args['option'] . '/admin', null, false, true) || $lang->load($args['option'], PATH_CORE . '/components/' . $args['option'] . '/admin', null, false, true); // Determine the component id. $component = Component::load($args['option']); if (isset($component->id)) { $table->component_id = $component->id; } } break; } // We have a valid type, inject it into the state for forms to use. $this->setState('item.type', $table->type); // Convert to the Object before adding the params. $properties = $table->getProperties(1); $result = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object'); // Convert the params field to an array. $registry = new \Hubzero\Config\Registry($table->params); $result->params = $registry->toArray(); // Merge the request arguments in to the params for a component. if ($table->type == 'component') { // Note that all request arguments become reserved parameter names. $result->request = $args; $result->params = array_merge($result->params, $args); } if ($table->type == 'alias') { // Note that all request arguments become reserved parameter names. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); $result->params = array_merge($result->params, $args); } if ($table->type == 'url') { // Note that all request arguments become reserved parameter names. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); $result->params = array_merge($result->params, $args); } // Load associated menu items if (JFactory::getApplication()->get('menu_associations', 0)) { if ($pk != null) { $result->associations = MenusHelper::getAssociations($pk); } else { $result->associations = array(); } } $result->menuordering = $pk; return $result; }
/** * Method to get a list of items. * * @return mixed An array of objects on success, false on failure. */ public function getItems() { // Get the list of items from the database. $items = parent::getItems(); // Initialise variables. $client = \Hubzero\Base\ClientManager::client($this->getState('filter.client_id', 0)); $client->path = PATH_CORE; $lang = Lang::getRoot(); // Loop through the results to add the XML metadata, // and load language support. foreach ($items as &$item) { $path = \Hubzero\Filesystem\Util::normalizePath($client->path . '/modules/' . $item->module . '/' . $item->module . '.xml'); if (file_exists($path)) { $item->xml = simplexml_load_file($path); } else { $item->xml = null; } // 1.5 Format; Core files or language packs then // 1.6 3PD Extension Support $lang->load($item->module . '.sys', PATH_APP . DS . 'bootstrap' . DS . $client->name, null, false, true) || $lang->load($item->module . '.sys', PATH_APP . '/modules/' . $item->module, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true); $item->name = Lang::txt($item->name); if (isset($item->xml) && ($text = trim($item->xml->description))) { $item->desc = Lang::txt($text); } else { $item->desc = Lang::txt('COM_MODULES_NODESCRIPTION'); } } $items = \Hubzero\Utility\Arr::sortObjects($items, 'name', 1, true, $lang->getLocale()); // TODO: Use the cached XML from the extensions table? return $items; }
/** * Get a list of the actions for the component or code actions. * * @param string The name of the component. * * @return array * @since 1.6 */ public static function getDebugActions($component = null) { $actions = array(); // Try to get actions for the component if (!empty($component)) { $component_actions = JAccess::getActions($component); if (!empty($component_actions)) { foreach ($component_actions as &$action) { $actions[$action->title] = array($action->name, $action->description); } } } // Use default actions from configuration if no component selected or component doesn't have actions if (empty($actions)) { $filename = PATH_CORE . '/components/com_config/admin/models/forms/application.xml'; if (is_file($filename)) { $xml = simplexml_load_file($filename); foreach ($xml->children()->fieldset as $fieldset) { if ('permissions' == (string) $fieldset['name']) { foreach ($fieldset->children() as $field) { if ('rules' == (string) $field['name']) { foreach ($field->children() as $action) { $actions[(string) $action['title']] = array((string) $action['name'], (string) $action['description']); } break; break; break; } } } } // Load language $lang = Lang::getRoot(); $extension = 'com_config'; $source = PATH_CORE . '/components/' . $extension . '/admin'; $lang->load("{$extension}.sys", PATH_APP, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true); } } return $actions; }
/** * Get a list of the unique modules installed in the client application. * * @param int The client id. * * @return array */ public static function getModules($clientId) { $db = App::get('db'); $query = $db->getQuery(true); $query->select('element AS value, name AS text'); $query->from('#__extensions as e'); $query->where('e.client_id = ' . (int) $clientId); $query->where('type = ' . $db->quote('module')); $query->leftJoin('#__modules as m ON m.module=e.element AND m.client_id=e.client_id'); $query->where('m.module IS NOT NULL'); $query->group('element,name'); $db->setQuery($query); $modules = $db->loadObjectList(); $lang = Lang::getRoot(); foreach ($modules as $i => $module) { $extension = $module->value; $path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE; $source = $path . "/modules/{$extension}"; $lang->load("{$extension}.sys", $path, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true); $modules[$i]->text = Lang::txt($module->text); } \Hubzero\Utility\Arr::sortObjects($modules, 'text', 1, true, $lang->getLocale()); return $modules; }