1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Registry\Registry;
13
14 15 16 17 18
19 class JApplicationAdministrator extends JApplicationCms
20 {
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
36 public function __construct(JInput $input = null, Registry $config = null, JApplicationWebClient $client = null)
37 {
38
39 $this->_name = 'administrator';
40
41
42 $this->_clientId = 1;
43
44
45 parent::__construct($input, $config, $client);
46
47
48 JUri::root(null, rtrim(dirname(JUri::base(true)), '/\\'));
49 }
50
51 52 53 54 55 56 57 58 59
60 public function dispatch($component = null)
61 {
62 if ($component === null)
63 {
64 $component = JAdministratorHelper::findOption();
65 }
66
67
68 $this->loadDocument();
69
70
71 $document = JFactory::getDocument();
72
73
74 JFactory::$document = $document;
75
76 switch ($document->getType())
77 {
78 case 'html':
79 $document->setMetaData('keywords', $this->get('MetaKeys'));
80
81
82 $template = $this->getTemplate(true);
83
84
85 $this->set('theme', $template->template);
86 $this->set('themeParams', $template->params);
87
88 break;
89
90 default:
91 break;
92 }
93
94 $document->setTitle($this->get('sitename') . ' - ' . JText::_('JADMINISTRATION'));
95 $document->setDescription($this->get('MetaDesc'));
96 $document->setGenerator('Joomla! - Open Source Content Management');
97
98 $contents = JComponentHelper::renderComponent($component);
99 $document->setBuffer($contents, 'component');
100
101
102 JPluginHelper::importPlugin('system');
103 $this->triggerEvent('onAfterDispatch');
104 }
105
106 107 108 109 110 111 112
113 protected function doExecute()
114 {
115
116 $login_lang = ($this->input->get('option') == 'com_login') ? $this->input->get('lang') : '';
117 $options = array('language' => $login_lang ?: $this->getUserState('application.lang'));
118
119
120 $this->initialiseApp($options);
121
122
123 if (get_magic_quotes_gpc())
124 {
125 $lang = $this->getLanguage();
126
127 if ($lang->hasKey('JERROR_MAGIC_QUOTES'))
128 {
129 $this->enqueueMessage(JText::_('JERROR_MAGIC_QUOTES'), 'error');
130 }
131 else
132 {
133 $this->enqueueMessage('Your host needs to disable magic_quotes_gpc to run this version of Joomla!', 'error');
134 }
135 }
136
137
138 JDEBUG ? $this->profiler->mark('afterInitialise') : null;
139
140
141 $this->route();
142
143
144 JDEBUG ? $this->profiler->mark('afterRoute') : null;
145
146 147 148 149 150 151 152
153 $this->checkUserRequireReset('com_admin', 'profile', 'edit', 'com_admin/profile.save,com_admin/profile.apply,com_login/logout');
154
155
156 $this->dispatch();
157
158
159 JDEBUG ? $this->profiler->mark('afterDispatch') : null;
160 }
161
162 163 164 165 166 167 168 169 170 171
172 public static function getRouter($name = 'administrator', array $options = array())
173 {
174 return parent::getRouter($name, $options);
175 }
176
177 178 179 180 181 182 183 184 185 186
187 public function getTemplate($params = false)
188 {
189 if (is_object($this->template))
190 {
191 if ($params)
192 {
193 return $this->template;
194 }
195
196 return $this->template->template;
197 }
198
199 $admin_style = JFactory::getUser()->getParam('admin_style');
200
201
202 $db = JFactory::getDbo();
203 $query = $db->getQuery(true)
204 ->select('template, s.params')
205 ->from('#__template_styles as s')
206 ->join('LEFT', '#__extensions as e ON e.type=' . $db->quote('template') . ' AND e.element=s.template AND e.client_id=s.client_id');
207
208 if ($admin_style)
209 {
210 $query->where('s.client_id = 1 AND id = ' . (int) $admin_style . ' AND e.enabled = 1', 'OR');
211 }
212
213 $query->where('s.client_id = 1 AND home = ' . $db->quote('1'), 'OR')
214 ->order('home');
215 $db->setQuery($query);
216 $template = $db->loadObject();
217
218 $template->template = JFilterInput::getInstance()->clean($template->template, 'cmd');
219 $template->params = new Registry($template->params);
220
221 if (!file_exists(JPATH_THEMES . '/' . $template->template . '/index.php'))
222 {
223 $this->enqueueMessage(JText::_('JERROR_ALERTNOTEMPLATE'), 'error');
224 $template->params = new Registry;
225 $template->template = 'isis';
226 }
227
228
229 $this->template = $template;
230
231 if (!file_exists(JPATH_THEMES . '/' . $template->template . '/index.php'))
232 {
233 throw new InvalidArgumentException(JText::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $template->template));
234 }
235
236 if ($params)
237 {
238 return $template;
239 }
240
241 return $template->template;
242 }
243
244 245 246 247 248 249 250 251 252
253 protected function initialiseApp($options = array())
254 {
255 $user = JFactory::getUser();
256
257
258 if ($user->guest)
259 {
260 $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
261 $user->groups = array($guestUsergroup);
262 }
263
264
265 if (empty($options['language']))
266 {
267 $lang = $user->getParam('admin_language');
268
269
270 if ($lang && JLanguageHelper::exists($lang))
271 {
272 $options['language'] = $lang;
273 }
274 else
275 {
276 $params = JComponentHelper::getParams('com_languages');
277 $options['language'] = $params->get('administrator', $this->get('language', 'en-GB'));
278 }
279 }
280
281
282 if (!JLanguageHelper::exists($options['language']))
283 {
284 $lang = $this->get('language', 'en-GB');
285
286 if (JLanguageHelper::exists($lang))
287 {
288 $options['language'] = $lang;
289 }
290 else
291 {
292
293 $options['language'] = 'en-GB';
294 }
295 }
296
297
298 parent::initialiseApp($options);
299 }
300
301 302 303 304 305 306 307 308 309 310
311 public function login($credentials, $options = array())
312 {
313
314 $options['group'] = 'Public Backend';
315
316
317 $options['autoregister'] = false;
318
319
320 if (!array_key_exists('entry_url', $options))
321 {
322 $options['entry_url'] = JUri::base() . 'index.php?option=com_users&task=login';
323 }
324
325
326 $options['action'] = 'core.login.admin';
327
328 $result = parent::login($credentials, $options);
329
330 if (!($result instanceof Exception))
331 {
332 $lang = $this->input->getCmd('lang');
333 $lang = preg_replace('/[^A-Z-]/i', '', $lang);
334
335 if ($lang)
336 {
337 $this->setUserState('application.lang', $lang);
338 }
339
340 static::purgeMessages();
341 }
342
343 return $result;
344 }
345
346 347 348 349 350 351 352
353 public static function purgeMessages()
354 {
355 $user = JFactory::getUser();
356 $userid = $user->get('id');
357
358 $db = JFactory::getDbo();
359 $query = $db->getQuery(true)
360 ->select('*')
361 ->from($db->quoteName('#__messages_cfg'))
362 ->where($db->quoteName('user_id') . ' = ' . (int) $userid, 'AND')
363 ->where($db->quoteName('cfg_name') . ' = ' . $db->quote('auto_purge'), 'AND');
364 $db->setQuery($query);
365 $config = $db->loadObject();
366
367
368 if (is_object($config) && $config->cfg_name === 'auto_purge')
369 {
370 $purge = $config->cfg_value;
371 }
372 else
373 {
374
375 $purge = 7;
376 }
377
378
379 if ($purge > 0)
380 {
381
382 $past = JFactory::getDate(time() - $purge * 86400);
383 $pastStamp = $past->toSql();
384
385 $query->clear()
386 ->delete($db->quoteName('#__messages'))
387 ->where($db->quoteName('date_time') . ' < ' . $db->quote($pastStamp), 'AND')
388 ->where($db->quoteName('user_id_to') . ' = ' . (int) $userid, 'AND');
389 $db->setQuery($query);
390 $db->execute();
391 }
392 }
393
394 395 396 397 398 399 400 401 402
403 protected function render()
404 {
405
406 $input = $this->input;
407
408 $component = $input->getCmd('option', 'com_login');
409 $file = $input->getCmd('tmpl', 'index');
410
411 if ($component === 'com_login')
412 {
413 $file = 'login';
414 }
415
416 $this->set('themeFile', $file . '.php');
417
418
419 $rootUser = $this->get('root_user');
420
421 if (property_exists('JConfig', 'root_user')
422 && (JFactory::getUser()->get('username') === $rootUser || JFactory::getUser()->id === (string) $rootUser))
423 {
424 $this->enqueueMessage(
425 JText::sprintf(
426 'JWARNING_REMOVE_ROOT_USER',
427 'index.php?option=com_config&task=config.removeroot&' . JSession::getFormToken() . '=1'
428 ),
429 'notice'
430 );
431 }
432
433 parent::render();
434 }
435
436 437 438 439 440 441 442 443 444 445 446 447
448 protected function route()
449 {
450 $uri = JUri::getInstance();
451
452 if ($this->get('force_ssl') >= 1 && strtolower($uri->getScheme()) !== 'https')
453 {
454
455 $uri->setScheme('https');
456 $this->redirect((string) $uri, 301);
457 }
458
459
460 JPluginHelper::importPlugin('system');
461 $this->triggerEvent('onAfterRoute');
462 }
463 }
464