- md5
- 3aa249d190fe7fd7cf1ea0d73573d169
- sha1
- 5cecac59b77aa033233450f975b242b9668d7a75
- sha256
- 158038fa441f214c48933458099022c10bb61675cc24ae106b7e0235aa649cf9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
<?php
/**
* @version $Id: item.php 21744 2011-07-06 08:40:23Z chdemko $
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport( 'joomla.application.component.controllerform' );
/**
* The Menu Item Controller
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusControllerItem extends JControllerForm
{
/**
* Method to add a new menu item.
*
* @return void
* @since 1.6
*/
public function add()
{
// Initialise variables.
$app = JFactory::getApplication();
$context = 'com_menus.edit.item';
$result = parent::add();
if ($result) {
$app->setUserState($context.'.type', null);
$app->setUserState($context.'.link', null);
$menuType = $app->getUserStateFromRequest($this->context.'.filter.menutype', 'menutype', 'mainmenu', 'cmd');
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=item&menutype='.$menuType.$this->getRedirectToItemAppend(), false));
}
return $result;
}
/**
* Method to run batch opterations.
*
* @return void
* @since 1.6
*/
public function batch($model)
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$model = $this->getModel('Item', '', array());
// Preset the redirect
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=items'.$this->getRedirectToListAppend(), false));
return parent::batch($model);
}
/**
* Method to cancel an edit
*
* Checks the item in, sets item ID in the session to null, and then redirects to the list page.
*
* @return void
* @since 1.6
*/
public function cancel($key = null)
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$context = 'com_menus.edit.item';
$result = parent::cancel();
if ($result) {
// Clear the ancillary data from the session.
$app->setUserState($context.'.type', null);
$app->setUserState($context.'.link', null);
}
}
/**
* Method to edit an existing menu item.
*
* @return void
* @since 1.6
*/
public function edit($key = null, $urlVar = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$result = parent::edit();
if ($result) {
// Push the new ancillary data into the session.
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
}
return true;
}
/**
* Method to save a menu item.
*
* @return void
* @since 1.6
*/
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('Item', '', array());
$data = JRequest::getVar('jform', array(), 'post', 'array');
$task = $this->getTask();
$context = 'com_menus.edit.item';
$recordId = JRequest::getInt('id');
if (!$this->checkEditId($context, $recordId)) {
// Somehow the person just went to the form and saved it - we don't allow that.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=items'.$this->getRedirectToListAppend(), false));
return false;
}
// Populate the row id from the session.
$data['id'] = $recordId;
// The save2copy task needs to be handled slightly differently.
if ($task == 'save2copy') {
// Check-in the original row.
if ($model->checkin($data['id']) === false) {
// Check-in failed, go back to the item and display a notice.
$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()), 'warning');
return false;
}
// Reset the ID and then treat the request as for Apply.
$data['id'] = 0;
$data['associations'] = array();
$task = 'apply';
}
// Validate the posted data.
// This post is made up of two forms, one for the item and one for params.
$form = $model->getForm($data);
if (!$form) {
JError::raiseError(500, $model->getError());
return false;
}
$data = $model->validate($form, $data);
// Check for the special 'request' entry.
if ($data['type'] == 'component' && isset($data['request']) && is_array($data['request']) && !empty($data['request'])) {
// Parse the submitted link arguments.
$args = array();
parse_str(parse_url($data['link'], PHP_URL_QUERY), $args);
// Merge in the user supplied request arguments.
$args = array_merge($args, $data['request']);
$data['link'] = 'index.php?'.urldecode(http_build_query($args,'','&'));
unset($data['request']);
}
// 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 (JError::isError($errors[$i])) {
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
}
else {
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId), false));
return false;
}
// Attempt to save the data.
if (!$model->save($data)) {
// Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
// Redirect back to the edit screen.
$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'warning');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId), false));
return false;
}
// Save succeeded, check-in the row.
if ($model->checkin($data['id']) === false) {
// Check-in failed, go back to the row and display a notice.
$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()), 'warning');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId), false));
return false;
}
$this->setMessage(JText::_('COM_MENUS_SAVE_SUCCESS'));
// Redirect the user and adjust session state based on the chosen task.
switch ($task) {
case 'apply':
// Set the row data in the session.
$recordId = $model->getState($this->context.'.id');
$this->holdEditId($context, $recordId);
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId), false));
break;
case 'save2new':
// Clear the row id and data in the session.
$this->releaseEditId($context, $recordId);
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
$app->setUserState('com_menus.edit.item.menutype', $model->getState('item.menutype'));
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend(), false));
break;
default:
// Clear the row id and data in the session.
$this->releaseEditId($context, $recordId);
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
// Redirect to the list screen.
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
break;
}
}
/**
* Sets the type of the menu item currently being editted.
*
* @return void
* @since 1.6
*/
function setType()
{
// Initialise variables.
$app = JFactory::getApplication();
// Get the posted values from the request.
$data = JRequest::getVar('jform', array(), 'post', 'array');
$recordId = JRequest::getInt('id');
// Get the type.
$type = $data['type'];
$type = json_decode(base64_decode($type));
$title = isset($type->title) ? $type->title : null;
$recordId = isset($type->id) ? $type->id : 0;
if ($title != 'alias' && $title != 'separator' && $title != 'url') {
$title = 'component';
}
$app->setUserState('com_menus.edit.item.type', $title);
if ($title == 'component') {
if (isset($type->request)) {
$component = JComponentHelper::getComponent($type->request->option);
$data['component_id'] = $component->id;
$app->setUserState(
'com_menus.edit.item.link',
'index.php?' . JURI::buildQuery((array)$type->request));
}
}
// If the type is alias you just need the item id from the menu item referenced.
else if ($title == 'alias') {
$app->setUserState('com_menus.edit.item.link', 'index.php?Itemid=');
}
unset($data['request']);
$data['type'] = $title;
if (JRequest::getCmd('fieldtype') == 'type') {
$data['link'] = $app->getUserState('com_menus.edit.item.link');
}
//Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
$this->type = $type;
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId), false));
}
}
The same content is in 3 releases, Joomla 1.7.0 to 1.7.2. See them all, or every version of this file.