本文整理汇总了PHP中MenusHelper类的典型用法代码示例。如果您正苦于以下问题:PHP MenusHelper类的具体用法?PHP MenusHelper怎么用?PHP MenusHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MenusHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInput
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
// Initialise variables.
$html = array();
$recordId = (int) $this->form->getValue('id');
$size = ($v = $this->element['size']) ? ' size="' . $v . '"' : '';
$class = ($v = $this->element['class']) ? ' class="' . $v . '"' : 'class="text_area"';
// Get a reverse lookup of the base link URL to Title
$model = JModel::getInstance('menutypes', 'menusModel');
$rlu = $model->getReverseLookup();
switch ($this->value) {
case 'url':
$value = JText::_('COM_MENUS_TYPE_EXTERNAL_URL');
break;
case 'alias':
$value = JText::_('COM_MENUS_TYPE_ALIAS');
break;
case 'separator':
$value = JText::_('COM_MENUS_TYPE_SEPARATOR');
break;
default:
$link = $this->form->getValue('link');
// Clean the link back to the option, view and layout
$value = JText::_(JArrayHelper::getValue($rlu, MenusHelper::getLinkKey($link)));
break;
}
// Load the javascript and css
JHtml::_('behavior.framework');
JHtml::_('behavior.modal');
$html[] = '<input type="text" readonly="readonly" disabled="disabled" value="' . $value . '"' . $size . $class . ' />';
$html[] = '<input type="button" value="' . JText::_('JSELECT') . '" onclick="SqueezeBox.fromElement(this, {handler:\'iframe\', size: {x: 600, y: 450}, url:\'' . JRoute::_('index.php?option=com_menus&view=menutypes&tmpl=component&recordId=' . $recordId) . '\'})" />';
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" />';
return implode("\n", $html);
}
示例2: display
/**
* Method to display a view.
*
* @param boolean If true, the view output will be cached
* @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
require_once JPATH_COMPONENT . '/helpers/menus.php';
// Load the submenu.
MenusHelper::addSubmenu(JRequest::getCmd('view'));
$view = JRequest::getCmd('view', 'menus');
$layout = JRequest::getCmd('layout', 'default');
$id = JRequest::getInt('id');
// Check for edit form.
if ($view == 'menu' && $layout == 'edit' && !$this->checkEditId('com_menus.edit.menu', $id)) {
// Somehow the person just went to the form - we don't allow that.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
return false;
} elseif ($view == 'item' && $layout == 'edit' && !$this->checkEditId('com_menus.edit.item', $id)) {
// Somehow the person just went to the form - we don't allow that.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=items', false));
return false;
}
parent::display();
return $this;
}
示例3: getTypeOptions
/**
* Method to get the available menu item type options.
*
* @return array Array of groups with menu item types.
* @since 1.6
*/
public function getTypeOptions()
{
// Initialise variables.
$lang = Lang::getRoot();
$list = array();
// Get the list of components.
$db = App::get('db');
$query = $db->getQuery(true);
$query->select('name, element AS ' . $db->qn('option'));
$query->from('#__extensions');
$query->where('type = ' . $db->q('component'));
$query->where('enabled = 1');
$query->order('name ASC');
$db->setQuery($query);
$components = $db->loadObjectList();
foreach ($components as $component) {
if ($options = $this->getTypeOptionsByComponent($component->option)) {
$list[$component->name] = $options;
// Create the reverse lookup for link-to-name.
foreach ($options as $option) {
if (isset($option->request)) {
$this->rlu[MenusHelper::getLinkKey($option->request)] = $option->get('title');
if (isset($option->request['option'])) {
$lang->load($option->request['option'] . '.sys', PATH_APP, null, false, true) || $lang->load($option->request['option'] . '.sys', PATH_CORE . '/components/' . $option->request['option'] . '/admin', null, false, true);
}
}
}
}
}
return $list;
}
示例4: getTypeOptions
/**
* Method to get the available menu item type options.
*
* @return array Array of groups with menu item types.
* @since 1.6
*/
public function getTypeOptions()
{
jimport('joomla.filesystem.file');
// Initialise variables.
$lang = JFactory::getLanguage();
$list = array();
// Get the list of components.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('name, element AS ' . $db->qn('option'));
$query->from('#__extensions');
$query->where('type = ' . $db->q('component'));
$query->where('enabled = 1');
$query->order('name ASC');
$db->setQuery($query);
$components = $db->loadObjectList();
foreach ($components as $component) {
if ($options = $this->getTypeOptionsByComponent($component->option)) {
$list[$component->name] = $options;
// Create the reverse lookup for link-to-name.
foreach ($options as $option) {
if (isset($option->request)) {
$this->rlu[MenusHelper::getLinkKey($option->request)] = $option->get('title');
if (isset($option->request['option'])) {
$lang->load($option->request['option'] . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($option->request['option'] . '.sys', JPATH_ADMINISTRATOR . '/components/' . $option->request['option'], null, false, false) || $lang->load($option->request['option'] . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($option->request['option'] . '.sys', JPATH_ADMINISTRATOR . '/components/' . $option->request['option'], $lang->getDefault(), false, false);
}
}
}
}
}
return $list;
}
示例5: association
/**
* Generate the markup to display the item associations
*
* @param int $itemid The menu item id
*
* @return string
*
* @since 3.0
*
* @throws Exception If there is an error on the query
*/
public static function association($itemid)
{
// Defaults
$html = '';
// Get the associations
if ($associations = MenusHelper::getAssociations($itemid)) {
// Get the associated menu items
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('m.id, m.title')->select('l.sef as lang_sef')->select('mt.title as menu_title')->from('#__menu as m')->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype')->where('m.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON m.language=l.lang_code')->select('l.image')->select('l.title as language_title');
$db->setQuery($query);
try {
$items = $db->loadObjectList('id');
} catch (runtimeException $e) {
throw new Exception($e->getMessage(), 500);
}
// Construct html
if ($items) {
foreach ($items as &$item) {
$text = strtoupper($item->lang_sef);
$url = JRoute::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id);
$tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title, '(' . $item->menu_title . ')');
$class = 'hasTooltip label label-association label-' . $item->lang_sef;
$item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, $class);
}
}
$html = JLayoutHelper::render('joomla.content.associations', $items);
}
return $html;
}
示例6: association
/**
* @param int $itemid The menu item id
*/
static function association($itemid)
{
// Get the associations
$associations = MenusHelper::getAssociations($itemid);
// Get the associated menu items
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('m.*');
$query->select('mt.title as menu_title');
$query->from('#__menu as m');
$query->leftJoin('#__menu_types as mt ON mt.menutype=m.menutype');
$query->where('m.id IN (' . implode(',', array_values($associations)) . ')');
$query->leftJoin('#__languages as l ON m.language=l.lang_code');
$query->select('l.image');
$query->select('l.title as language_title');
$db->setQuery($query);
$items = $db->loadObjectList('id');
// Check for a database error.
if ($error = $db->getErrorMsg()) {
JError::raiseWarning(500, $error);
return false;
}
// Construct html
$text = array();
foreach ($associations as $tag => $associated) {
if ($associated != $itemid) {
$text[] = JText::sprintf('COM_MENUS_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->title, $items[$associated]->menu_title);
}
}
return JHtml::_('tooltip', implode('<br />', $text), JText::_('COM_MENUS_TIP_ASSOCIATION'), 'menu/icon-16-links.png');
}
示例7: getGroups
/**
* Method to get the field option groups.
*
* @return array The field option objects as a nested array in groups.
*/
protected function getGroups()
{
// Initialize variables.
$groups = array();
// Initialize some field attributes.
$menuType = (string) $this->element['menu_type'];
$published = $this->element['published'] ? explode(',', (string) $this->element['published']) : array();
$disable = $this->element['disable'] ? explode(',', (string) $this->element['disable']) : array();
$language = $this->element['language'] ? explode(',', (string) $this->element['language']) : array();
// Get the menu items.
$items = \MenusHelper::getMenuLinks($menuType, 0, 0, $published, $language);
// Build group for a specific menu type.
if ($menuType) {
// Initialize the group.
$groups[$menuType] = array();
// Build the options array.
foreach ($items as $link) {
$groups[$menuType][] = Dropdown::option($link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
}
} else {
// Build the groups arrays.
foreach ($items as $menu) {
// Initialize the group.
$groups[$menu->menutype] = array();
// Build the options array.
foreach ($menu->links as $link) {
$groups[$menu->menutype][] = Dropdown::option($link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
}
}
}
// Merge any additional groups in the XML definition.
$groups = array_merge(parent::getGroups(), $groups);
return $groups;
}
示例8: addToolbar
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addToolbar()
{
JRequest::setVar('hidemainmenu', true);
$user = JFactory::getUser();
$isNew = $this->item->id == 0;
$canDo = MenusHelper::getActions($this->state->get('filter.parent_id'));
JToolBarHelper::title(JText::_($isNew ? 'COM_MENUS_VIEW_NEW_MENU_TITLE' : 'COM_MENUS_VIEW_EDIT_MENU_TITLE'), 'menu.png');
// 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')) {
JToolBarHelper::apply('menu.apply');
}
JToolBarHelper::save('menu.save');
}
// If user can edit, can save the item.
if (!$isNew && $canDo->get('core.edit')) {
JToolBarHelper::apply('menu.apply');
JToolBarHelper::save('menu.save');
}
// If the user can create new items, allow them to see Save & New
if ($canDo->get('core.create')) {
JToolBarHelper::save2new('menu.save2new');
}
if ($isNew) {
JToolBarHelper::cancel('menu.cancel');
} else {
JToolBarHelper::cancel('menu.cancel', 'JTOOLBAR_CLOSE');
}
JToolBarHelper::divider();
JToolBarHelper::help('JHELP_MENUS_MENU_MANAGER_EDIT');
}
示例9: addToolbar
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addToolbar()
{
JRequest::setVar('hidemainmenu', true);
$user = JFactory::getUser();
$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'));
JToolBarHelper::title(JText::_($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')) {
JToolBarHelper::apply('adminitem.apply');
}
JToolBarHelper::save('adminitem.save');
}
// If not checked out, can save the item.
if (!$isNew && !$checkedOut && $canDo->get('core.edit')) {
JToolBarHelper::apply('adminitem.apply');
JToolBarHelper::save('adminitem.save');
}
// If the user can create new items, allow them to see Save & New
if ($canDo->get('core.create')) {
JToolBarHelper::save2new('adminitem.save2new');
}
// If an existing item, can save to a copy only if we have create rights.
if (!$isNew && $canDo->get('core.create')) {
JToolBarHelper::save2copy('adminitem.save2copy');
}
if ($isNew) {
JToolBarHelper::cancel('adminitem.cancel');
} else {
JToolBarHelper::cancel('adminitem.cancel', 'JTOOLBAR_CLOSE');
}
}
示例10: _getGroups
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function _getGroups()
{
// Get the attributes
$menuType = (string) $this->_element->attributes()->menu_type;
$published = (string) $this->_element->attributes()->published ? explode(',', (string) $this->_element->attributes()->published) : array();
$disable = (string) $this->_element->attributes()->disable ? explode(',', (string) $this->_element->attributes()->disable) : array();
// Get the com_menus helper
require_once realpath(JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');
// Get the items
$items = MenusHelper::getMenuLinks($menuType, 0, 0, $published);
// Prepare return value
$groups = array();
// If a menu type was set
if ($menuType) {
$groups[$menuType] = array();
// Loop over links
foreach ($items as $link) {
// Generate an option disabling it if it's the case
$groups[$menuType][] = JHtml::_('select.option', $link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
}
} else {
// Loop over types
foreach ($items as $menu) {
$groups[$menu->menutype] = array();
// Loop over links
foreach ($menu->links as $link) {
// Generate an option disabling it if it's the case
$groups[$menu->menutype][] = JHtml::_('select.option', $link->value, $link->text, 'value', 'text', in_array($link->type, $disable));
}
}
}
// Merge any additional options in the XML definition.
$groups = array_merge(parent::_getGroups(), $groups);
return $groups;
}
示例11: links
public function links()
{
if (!CakePlugin::loaded('Menus')) {
CakePlugin::load('Menus');
}
App::uses('View', 'View');
App::uses('AppHelper', 'View/Helper');
App::uses('MenusHelper', 'Menus.View/Helper');
$Menus = new MenusHelper(new View());
$Link = ClassRegistry::init('Menus.Link');
$links = $Link->find('all', array('fields' => array('id', 'title', 'link')));
$count = 0;
foreach ($links as $link) {
if (!strstr($link['Link']['link'], 'controller:')) {
continue;
}
if (strstr($link['Link']['link'], 'plugin:')) {
continue;
}
$url = $Menus->linkStringToArray($link['Link']['link']);
if (isset($this->_controllerMap[$url['controller']])) {
$url['plugin'] = $this->_controllerMap[$url['controller']];
$linkString = $Menus->urlToLinkString($url);
$Link->id = $link['Link']['id'];
$this->out(__('Updating Link %s', $Link->id));
$this->warn(__('- %s', $link['Link']['link']));
$this->success(__('+ %s', $linkString), 2);
$Link->saveField('link', $linkString, false);
$count++;
}
}
$this->out(__('Links updated: %d rows', $count));
}
示例12: association
/**
* Generate the markup to display the item associations
*
* @param int $itemid The menu item id
*
* @return string
*
* @since 3.0
*
* @throws Exception If there is an error on the query
*/
public static function association($itemid)
{
// Defaults
$html = '';
// Get the associations
if ($associations = MenusHelper::getAssociations($itemid)) {
// Get the associated menu items
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('m.id, m.title')->select('l.sef as lang_sef, l.lang_code')->select('mt.title as menu_title')->from('#__menu as m')->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype')->where('m.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON m.language=l.lang_code')->select('l.image')->select('l.title as language_title');
$db->setQuery($query);
try {
$items = $db->loadObjectList('id');
} catch (runtimeException $e) {
throw new Exception($e->getMessage(), 500);
}
// Construct html
if ($items) {
foreach ($items as &$item) {
$text = strtoupper($item->lang_sef);
$url = JRoute::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id);
$tooltip = $item->title . '<br />' . JText::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title);
$classes = 'hasPopover label label-association label-' . $item->lang_sef;
$item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $tooltip . '" data-placement="top">' . $text . '</a>';
}
}
JHtml::_('bootstrap.popover');
$html = JLayoutHelper::render('joomla.content.associations', $items);
}
return $html;
}
示例13: getMenus
/**
* Return list of menus.
*
* @return array
* @throws \RuntimeException
*/
public function getMenus()
{
static $items;
if ($items === null) {
require_once JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php';
$items = (array) \MenusHelper::getMenuTypes();
}
return $items;
}
示例14: getList
public static function getList(&$params)
{
$user = JFactory::getUser();
$lang = JFactory::getLanguage();
$app = JFactory::getApplication();
$menu = $app->getMenu();
// Get menu home items
$homes = array();
foreach ($menu->getMenu() as $item) {
if ($item->home) {
$homes[$item->language] = $item;
}
}
// Load associations
$assoc = isset($app->menu_associations) ? $app->menu_associations : 0;
if ($assoc) {
$active = $menu->getActive();
if ($active) {
$associations = MenusHelper::getAssociations($active->id);
}
}
$levels = $user->getAuthorisedViewLevels();
$languages = JLanguageHelper::getLanguages();
// Filter allowed languages
foreach ($languages as $i => &$language) {
// Do not display language without frontend UI
if (!JLanguage::exists($language->lang_code)) {
unset($languages[$i]);
} elseif (!isset($homes[$language->lang_code])) {
unset($languages[$i]);
} elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
unset($languages[$i]);
} else {
$language->active = $language->lang_code == $lang->getTag();
if ($app->getLanguageFilter()) {
if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
$itemid = $associations[$language->lang_code];
if ($app->getCfg('sef') == '1') {
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid;
}
} else {
if ($app->getCfg('sef') == '1') {
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
} else {
$language->link = 'index.php?lang=' . $language->sef;
}
}
} else {
$language->link = JRoute::_('&Itemid=' . $homes['*']->id);
}
}
}
return $languages;
}
示例15: getInput
protected function getInput()
{
$size = (int) $this->def('size');
$multiple = $this->def('multiple', 1);
require_once JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php';
$options = MenusHelper::getMenuLinks();
require_once JPATH_PLUGINS . '/system/nnframework/helpers/html.php';
return nnHtml::selectlist($options, $this->name, $this->value, $this->id, $size, $multiple);
}