Modernise some of the new admin section.
[bugdar.git] / admin / home.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2013 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 namespace bugdar\admin;
23
24 use \bugdar;
25 use \hoplite\http;
26
27 require_once HOPLITE_ROOT . '/http/action.php';
28
29 class HomeAction extends http\Action implements TemplatePreCaching
30 {
31 public function TemplateSet()
32 {
33 return ['admin_index'];
34 }
35
36 public function Invoke(http\Request $request, http\Response $response)
37 {
38 // TODO(port): Migrate.
39 global $funct;
40
41 $response->data['title'] = T('Home');
42
43 $response->data['new_version_number'] = $this->_DoVersionCheck();
44 $response->data['current_version'] = Bugdar::$options['trackerversion'];
45
46 $response->data['php_version'] = phpversion();
47 $response->data['mysql_version'] = Bugdar::$db->Query("SELECT VERSION() AS version")->FetchObject()->version;
48 $response->data['web_server'] = $_SERVER['SERVER_SOFTWARE'];
49
50 $response->data['mysql_max_packet'] = Bugdar::$db->Query("SHOW VARIABLES LIKE 'max_allowed_packet'")->FetchObject()->Value;
51 $response->data['max_upload_size'] = $funct->fetch_max_attachment_size();
52 $response->data['mysql_ft_min_length'] = Bugdar::$db->Query("SHOW VARIABLES LIKE 'ft_min_word_len'")->FetchObject()->Value;
53
54 $response->context['template'] = 'admin_index';
55 }
56
57 // Contacts Blue Static to see if Bugdar is up-to-date. Returns NULL if the
58 // current version is the latest, or a string version number of the latest
59 // version.
60 private function _DoVersionCheck()
61 {
62 global $bugsys;
63
64 if (defined('NO_VERSION_CHECK') && constant('NO_VERSION_CHECK'))
65 return;
66
67 $check = @file_get_contents('https://www.bluestatic.org/versioncheck.php?prod=bugdar&ver=' . str_replace(' ', '-', Bugdar::$options['trackerversion']));
68 if (strpos($check, '<version-check>') !== false) {
69 if (!isset($check['version-check']['update']))
70 return NULL;
71
72 // TODO(rsesek): Switch to SimpleXML.
73 $check = $bugsys->xml->parse($check);
74 return $check['version-check']['update']['value'];
75 }
76 }
77 }