/
HtmlView.php
265 lines (230 loc) · 6.45 KB
/
HtmlView.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Joomlaupdate\Administrator\View\Joomlaupdate;
\defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Updater\Updater;
use Joomla\Database\ParameterType;
/**
* Joomla! Update's Default View
*
* @since 2.5.4
*/
class HtmlView extends BaseHtmlView
{
/**
* An array with the Joomla! update information.
*
* @var array
*
* @since 3.6.0
*/
protected $updateInfo = null;
/**
* PHP options.
*
* @var array Array of PHP config options
*
* @since 3.10.0
*/
protected $phpOptions = null;
/**
* PHP settings.
*
* @var array Array of PHP settings
*
* @since 3.10.0
*/
protected $phpSettings = null;
/**
* Non Core Extensions.
*
* @var array Array of Non-Core-Extensions
*
* @since 3.10.0
*/
protected $nonCoreExtensions = null;
/**
* The model state
*
* @var \JObject
* @since 4.0.0
*/
protected $state;
/**
* Flag if the update component itself has to be updated
*
* @var boolean True when update is available otherwise false
*
* @since 4.0.0
*/
protected $selfUpdateAvailable = false;
/**
* A special prefix used for the emptystate layout variable
*
* @var string The prefix
*
* @since 4.0.0
*/
protected $messagePrefix = '';
/**
* Renders the view
*
* @param string $tpl Template name
*
* @return void
*
* @since 2.5.4
*/
public function display($tpl = null)
{
$this->updateInfo = $this->get('UpdateInformation');
$this->selfUpdateAvailable = $this->get('CheckForSelfUpdate');
// Get results of pre update check evaluations
$this->phpOptions = $this->get('PhpOptions');
$this->phpSettings = $this->get('PhpSettings');
$this->nonCoreExtensions = $this->get('NonCoreExtensions');
$this->nonCoreCriticalPlugins = $this->get('NonCorePlugins');
// Set to true if a required PHP option is not ok
$isCritical = false;
foreach ($this->phpOptions as $option)
{
if (!$option->state)
{
$isCritical = true;
break;
}
}
$this->state = $this->get('State');
$hasUpdate = !empty($this->updateInfo['hasUpdate']);
$hasDownload = isset($this->updateInfo['object']->downloadurl->_data);
// Fresh update, show it
if ($this->getLayout() == 'complete')
{
// Complete message, nothing to do here
}
// There is an update for the updater itself. So we have to update it first
elseif ($this->selfUpdateAvailable)
{
$this->setLayout('selfupdate');
}
elseif (!$hasDownload || !$hasUpdate)
{
// Could be that we have a download file but no update, so we offer a re-install
if ($hasDownload)
{
// We can reinstall if we have a URL but no update
$this->setLayout('reinstall');
}
// No download available
else
{
if ($hasUpdate)
{
$this->messagePrefix = '_NODOWNLOAD';
}
$this->setLayout('noupdate');
}
}
// Here we have now two options: preupdatecheck or update
elseif ($this->getLayout() != 'update' || $isCritical)
{
$this->setLayout('preupdatecheck');
}
if (in_array($this->getLayout(), ['preupdatecheck', 'update', 'upload']))
{
$language = Factory::getLanguage();
$language->load('com_installer', JPATH_ADMINISTRATOR, 'en-GB', false, true);
$language->load('com_installer', JPATH_ADMINISTRATOR, null, true);
Factory::getApplication()->enqueueMessage(Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATE_NOTICE'), 'notice');
}
$params = ComponentHelper::getParams('com_joomlaupdate');
switch ($params->get('updatesource', 'default'))
{
// "Minor & Patch Release for Current version AND Next Major Release".
case 'sts':
case 'next':
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_NEXT';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT');
break;
// "Testing"
case 'testing':
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_TESTING';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING');
break;
// "Custom"
case 'custom':
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_CUSTOM';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_CUSTOM');
break;
/**
* "Minor & Patch Release for Current version (recommended and default)".
* The commented "case" below are for documenting where 'default' and legacy options falls
* case 'default':
* case 'lts':
* case 'nochange':
*/
default:
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_DEFAULT';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT');
}
// Remove temporary files
$this->getModel()->removePackageFiles();
$this->addToolbar();
// Render the view.
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 4.0.0
*/
protected function addToolbar()
{
// Set the toolbar information.
ToolbarHelper::title(Text::_('COM_JOOMLAUPDATE_OVERVIEW'), 'joomla install');
if (in_array($this->getLayout(), ['update', 'complete']))
{
$arrow = Factory::getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left';
ToolbarHelper::link('index.php?option=com_joomlaupdate', 'JTOOLBAR_BACK', $arrow);
ToolbarHelper::title(Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_TAB_UPLOAD'), 'joomla install');
}
elseif (!$this->selfUpdateAvailable)
{
ToolbarHelper::custom('update.purge', 'loop', '', 'COM_JOOMLAUPDATE_TOOLBAR_CHECK', false);
}
// Add toolbar buttons.
if (Factory::getUser()->authorise('core.admin'))
{
ToolbarHelper::preferences('com_joomlaupdate');
}
ToolbarHelper::divider();
ToolbarHelper::help('JHELP_COMPONENTS_JOOMLA_UPDATE');
}
/**
* Returns true, if the pre update check should be displayed.
* This logic is not hardcoded in tmpl files, because it is
* used by the Hathor tmpl too.
*
* @return boolean
*
* @since 3.10.0
*/
public function shouldDisplayPreUpdateCheck()
{
return isset($this->updateInfo['object']->downloadurl->_data)
&& !empty($this->updateInfo['hasUpdate']);
}
}