first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,345 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2013 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 Item Controller
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusControllerItem extends JControllerForm
{
/**
* Method to add a new menu item.
*
* @return mixed True if the record can be added, a JError object if not.
*
* @since 1.6
*/
public function add()
{
$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 operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 1.6
*/
public function batch($model = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$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.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 1.6
*/
public function cancel($key = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$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 record.
*
* @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 access level check and checkout passes, false otherwise.
*
* @since 1.6
*/
public function edit($key = null, $urlVar = null)
{
$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 record.
*
* @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();
$model = $this->getModel('Item', '', array());
$data = $this->input->post->get('jform', array(), 'array');
$task = $this->getTask();
$context = 'com_menus.edit.item';
$recordId = $this->input->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 ($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.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 edited.
*
* @return void
*
* @since 1.6
*/
public function setType()
{
$app = JFactory::getApplication();
// Get the posted values from the request.
$data = $this->input->post->get('jform', array(), 'array');
// 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;
$specialTypes = array('alias', 'separator', 'url', 'heading');
if (!in_array($title, $specialTypes))
{
$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.
elseif ($title == 'alias')
{
$app->setUserState('com_menus.edit.item.link', 'index.php?Itemid=');
}
unset($data['request']);
$data['type'] = $title;
if ($this->input->get('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));
}
}

View File

@ -0,0 +1,131 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2013 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 Item Controller
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusControllerItems extends JControllerAdmin
{
public function __construct($config = array())
{
parent::__construct($config);
$this->registerTask('unsetDefault', 'setDefault');
}
/**
* Proxy for getModel
* @since 1.6
*/
public function getModel($name = 'Item', $prefix = 'MenusModel', $config = array())
{
return parent::getModel($name, $prefix, array('ignore_request' => true));
}
/**
* Rebuild the nested set tree.
*
* @return bool False on failure or error, true on success.
* @since 1.6
*/
public function rebuild()
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$this->setRedirect('index.php?option=com_menus&view=items');
$model = $this->getModel();
if ($model->rebuild())
{
// Reorder succeeded.
$this->setMessage(JText::_('COM_MENUS_ITEMS_REBUILD_SUCCESS'));
return true;
}
else
{
// Rebuild failed.
$this->setMessage(JText::sprintf('COM_MENUS_ITEMS_REBUILD_FAILED'));
return false;
}
}
public function saveorder()
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Get the arrays from the Request
$order = $this->input->post->get('order', null, 'array');
$originalOrder = explode(',', $this->input->getString('original_order_values'));
// Make sure something has changed
if (!($order === $originalOrder))
{
parent::saveorder();
}
else
{
// Nothing to reorder
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
return true;
}
}
/**
* Method to set the home property for a list of items
*
* @since 1.6
*/
public function setDefault()
{
// Check for request forgeries
JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN'));
// Get items to publish from the request.
$cid = $this->input->get('cid', array(), 'array');
$data = array('setDefault' => 1, 'unsetDefault' => 0);
$task = $this->getTask();
$value = JArrayHelper::getValue($data, $task, 0, 'int');
if (empty($cid))
{
JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
}
else
{
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
JArrayHelper::toInteger($cid);
// Publish the items.
if (!$model->setHome($cid, $value))
{
JError::raiseWarning(500, $model->getError());
} else {
if ($value == 1)
{
$ntext = 'COM_MENUS_ITEMS_SET_HOME';
}
else {
$ntext = 'COM_MENUS_ITEMS_UNSET_HOME';
}
$this->setMessage(JText::plural($ntext, count($cid)));
}
}
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
}
}

View File

@ -0,0 +1,158 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2013 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
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusControllerMenu extends JControllerForm
{
/**
* Dummy method to redirect back to standard controller
*
* @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)
{
$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
}
/**
* Method to save a menu item.
*
* @return void
*/
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');
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='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
return false;
}
// 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;
}
// 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()), 'warning');
$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;
}
}
}

View File

@ -0,0 +1,202 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2013 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 List Controller
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusControllerMenus extends JControllerLegacy
{
/**
* Display the 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.6
*/
public function display($cachable = false, $urlparams = false)
{
}
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 1.6
*/
public function getModel($name = 'Menu', $prefix = 'MenusModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
/**
* Removes an item
*/
public function delete()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = $this->input->get('cid', array(), 'array');
if (!is_array($cid) || count($cid) < 1)
{
JError::raiseWarning(500, JText::_('COM_MENUS_NO_MENUS_SELECTED'));
}
else
{
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);
// Remove the items.
if (!$model->delete($cid))
{
$this->setMessage($model->getError());
}
else
{
$this->setMessage(JText::plural('COM_MENUS_N_MENUS_DELETED', count($cid)));
}
}
$this->setRedirect('index.php?option=com_menus&view=menus');
}
/**
* Rebuild the menu tree.
*
* @return bool False on failure or error, true on success.
*/
public function rebuild()
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$this->setRedirect('index.php?option=com_menus&view=menus');
$model = $this->getModel('Item');
if ($model->rebuild())
{
// Reorder succeeded.
$this->setMessage(JText::_('JTOOLBAR_REBUILD_SUCCESS'));
return true;
}
else
{
// Rebuild failed.
$this->setMessage(JText::sprintf('JTOOLBAR_REBUILD_FAILED', $model->getMessage()));
return false;
}
}
/**
* Temporary method. This should go into the 1.5 to 1.6 upgrade routines.
*/
public function resync()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$parts = null;
try
{
$query->select('element, extension_id')
->from('#__extensions')
->where('type = ' . $db->quote('component'));
$db->setQuery($query);
$components = $db->loadAssocList('element', 'extension_id');
}
catch (RuntimeException $e)
{
return JError::raiseWarning(500, $e->getMessage());
}
// Load all the component menu links
$query->select($db->quoteName('id'))
->select($db->quoteName('link'))
->select($db->quoteName('component_id'))
->from('#__menu')
->where($db->quoteName('type') . ' = ' . $db->quote('component.item'));
$db->setQuery($query);
try
{
$items = $db->loadObjectList();
}
catch (RuntimeException $e)
{
return JError::raiseWarning(500, $e->getMessage());
}
foreach ($items as $item)
{
// Parse the link.
parse_str(parse_url($item->link, PHP_URL_QUERY), $parts);
// Tease out the option.
if (isset($parts['option']))
{
$option = $parts['option'];
// Lookup the component ID
if (isset($components[$option]))
{
$componentId = $components[$option];
}
else
{
// Mismatch. Needs human intervention.
$componentId = -1;
}
// Check for mis-matched component id's in the menu link.
if ($item->component_id != $componentId)
{
// Update the menu table.
$log = "Link $item->id refers to $item->component_id, converting to $componentId ($item->link)";
echo "<br/>$log";
$query->clear();
$query->update('#__menu')
->set('component_id = ' . $componentId)
->where('id = ' . $item->id);
try
{
$db->setQuery($query)->execute();
}
catch (RuntimeException $e)
{
return JError::raiseWarning(500, $e->getMessage());
}
//echo "<br>".$db->getQuery();
}
}
}
}
}