/
component.php
107 lines (92 loc) · 2.95 KB
/
component.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_config
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Note: this view is intended only to be opened in a popup
* @package Joomla.Administrator
* @subpackage com_config
*/
class ConfigControllerComponent extends JController
{
/**
* Class Constructor
*
* @param array $config An optional associative array of configuration settings.
* @return void
* @since 1.5
*/
function __construct($config = array())
{
parent::__construct($config);
// Map the apply task to the save method.
$this->registerTask('apply', 'save');
}
/**
* Save the configuration
*/
function save()
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('Invalid_Token'));
// Set FTP credentials, if given.
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('Component');
$form = $model->getForm();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$id = JRequest::getInt('id');
$option = JRequest::getWord('component');
// Check if the user is authorized to do this.
if (!JFactory::getUser()->authorize('core.admin', $option))
{
JFactory::getApplication()->redirect('index.php', JText::_('ALERTNOTAUTH'));
return;
}
// Validate the posted data.
$return = $model->validate($form, $data);
// Check for validation errors.
if ($return === 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(), 'notice');
} else {
$app->enqueueMessage($errors[$i], 'notice');
}
}
// Save the data in the session.
$app->setUserState('com_config.config.global.data', $data);
// Redirect back to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_config&view=component&component='.$option.'&tmpl=component', false));
return false;
}
// Attempt to save the configuration.
$data = array(
'params' => $return,
'id' => $id,
'option' => $option
);
$return = $model->save($data);
// Check the return value.
if ($return === false)
{
// Save the data in the session.
$app->setUserState('com_config.config.global.data', $data);
// Save failed, go back to the screen and display a notice.
$message = JText::sprintf('JError_Save_Failed', $model->getError());
$this->setRedirect('index.php?option=com_config&view=component&component='.$option.'&tmpl=component', $message, 'error');
return false;
}
$this->setRedirect('index.php?option=com_config&view=close&tmpl=component');
return true;
}
}