- md5
- 5c72f2f9fc10164cee341d95ff99387f
- sha1
- 2572de7a9e0f5117af42a16b317779cfa90cf1f3
- sha256
- c5707bcc32a29615674ac0d9429547c64a1550535de2a6ceeb56867aad380470
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* The Menu Type Controller
*
* @since 1.6
*/
class MenusControllerMenu extends JControllerForm
{
/**
* Dummy method to redirect back to standard controller
*
* @param boolean $cachable If true, the view output will be cached.
* @param array $urlparams 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)
{
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
}
/**
* Method to save a menu item.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*
* @since 1.6
*/
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$data = $this->input->post->get('jform', array(), 'array');
$context = 'com_menus.edit.menu';
$task = $this->getTask();
$recordId = $this->input->getInt('id');
// Make sure we are not trying to modify an administrator menu.
if (isset($data['client_id']) && $data['client_id'] == 1)
{
JError::raiseNotice(0, JText::_('COM_MENUS_MENU_TYPE_NOT_ALLOWED'));
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
return false;
}
// Prevent using 'menu' or 'main' as menutype as this is reserved for back-end menus
if (strtolower($data['menutype']) == 'menu' || strtolower($data['menutype']) == 'main')
{
$msg = JText::_('COM_MENUS_ERROR_MENUTYPE');
JFactory::getApplication()->enqueueMessage($msg, 'error');
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
return false;
}
// Populate the row id from the session.
$data['id'] = $recordId;
// Get the model and attempt to validate the posted data.
$model = $this->getModel('Menu');
$form = $model->getForm();
if (!$form)
{
JError::raiseError(500, $model->getError());
return false;
}
$data = $model->validate($form, $data);
// Check for validation errors.
if ($data === false)
{
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
if ($errors[$i] instanceof Exception)
{
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
}
else
{
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState('com_menus.edit.menu.data', $data);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
return false;
}
// Attempt to save the data.
if (!$model->save($data))
{
// Save the data in the session.
$app->setUserState('com_menus.edit.menu.data', $data);
// Redirect back to the edit screen.
$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
return false;
}
$this->setMessage(JText::_('COM_MENUS_MENU_SAVE_SUCCESS'));
// Redirect the user and adjust session state based on the chosen task.
switch ($task)
{
case 'apply':
// Set the record data in the session.
$recordId = $model->getState($this->context . '.id');
$this->holdEditId($context, $recordId);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit' . $this->getRedirectToItemAppend($recordId), false));
break;
case 'save2new':
// Clear the record id and data from the session.
$this->releaseEditId($context, $recordId);
$app->setUserState($context . '.data', null);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
break;
default:
// Clear the record id and data from the session.
$this->releaseEditId($context, $recordId);
$app->setUserState($context . '.data', null);
// Redirect to the list screen.
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
break;
}
}
}
The same content is in 22 releases, Joomla 3.5.0-beta2 to 3.6.2. See them all, or every version of this file.