Translated using Weblate (French)
[phpmyadmin.git] / setup / lib / Index.php
blob21177506de4cdf3c5468dc229980f615ff88252d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Various checks and message functions used on index page.
6 * @package PhpMyAdmin-Setup
7 */
8 declare(strict_types=1);
10 namespace PhpMyAdmin\Setup;
12 use PhpMyAdmin\VersionInformation;
13 use PhpMyAdmin\Sanitize;
15 /**
16 * PhpMyAdmin\Setup\Index class
18 * Various checks and message functions used on index page.
20 * @package PhpMyAdmin-Setup
22 class Index
24 /**
25 * Initializes message list
27 * @return void
29 public static function messagesBegin()
31 if (! isset($_SESSION['messages']) || ! is_array($_SESSION['messages'])) {
32 $_SESSION['messages'] = [
33 'error' => [],
34 'notice' => [],
36 } else {
37 // reset message states
38 foreach ($_SESSION['messages'] as &$messages) {
39 foreach ($messages as &$msg) {
40 $msg['fresh'] = false;
41 $msg['active'] = false;
47 /**
48 * Adds a new message to message list
50 * @param string $type one of: notice, error
51 * @param string $msgId unique message identifier
52 * @param string $title language string id (in $str array)
53 * @param string $message message text
55 * @return void
57 public static function messagesSet($type, $msgId, $title, $message)
59 $fresh = ! isset($_SESSION['messages'][$type][$msgId]);
60 $_SESSION['messages'][$type][$msgId] = [
61 'fresh' => $fresh,
62 'active' => true,
63 'title' => $title,
64 'message' => $message,
68 /**
69 * Cleans up message list
71 * @return void
73 public static function messagesEnd()
75 foreach ($_SESSION['messages'] as &$messages) {
76 $remove_ids = [];
77 foreach ($messages as $id => &$msg) {
78 if ($msg['active'] == false) {
79 $remove_ids[] = $id;
82 foreach ($remove_ids as $id) {
83 unset($messages[$id]);
88 /**
89 * Prints message list, must be called after self::messagesEnd()
91 * @return void
93 public static function messagesShowHtml()
95 foreach ($_SESSION['messages'] as $type => $messages) {
96 foreach ($messages as $id => $msg) {
97 if (! $msg['fresh'] && $type != 'error') {
98 $extra = ' hiddenmessage';
99 } else {
100 $extra = '';
102 echo '<div class="' , $type, $extra , '" id="' , $id , '">'
103 , '<h4>' , $msg['title'] , '</h4>'
104 , $msg['message'] , '</div>';
110 * Checks for newest phpMyAdmin version and sets result as a new notice
112 * @return void
114 public static function versionCheck()
116 // version check messages should always be visible so let's make
117 // a unique message id each time we run it
118 $message_id = uniqid('version_check');
120 // Fetch data
121 $versionInformation = new VersionInformation();
122 $version_data = $versionInformation->getLatestVersion();
124 if (empty($version_data)) {
125 self::messagesSet(
126 'error',
127 $message_id,
128 __('Version check'),
130 'Reading of version failed. '
131 . 'Maybe you\'re offline or the upgrade server does not respond.'
134 return;
137 $releases = $version_data->releases;
138 $latestCompatible = $versionInformation->getLatestCompatibleVersion($releases);
139 if ($latestCompatible != null) {
140 $version = $latestCompatible['version'];
141 $date = $latestCompatible['date'];
142 } else {
143 return;
146 $version_upstream = $versionInformation->versionToInt($version);
147 if ($version_upstream === false) {
148 self::messagesSet(
149 'error',
150 $message_id,
151 __('Version check'),
152 __('Got invalid version string from server')
154 return;
157 $version_local = $versionInformation->versionToInt(
158 $GLOBALS['PMA_Config']->get('PMA_VERSION')
160 if ($version_local === false) {
161 self::messagesSet(
162 'error',
163 $message_id,
164 __('Version check'),
165 __('Unparsable version string')
167 return;
170 if ($version_upstream > $version_local) {
171 $version = htmlspecialchars($version);
172 $date = htmlspecialchars($date);
173 self::messagesSet(
174 'notice',
175 $message_id,
176 __('Version check'),
177 sprintf(__('A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is %s, released on %s.'), $version, $date)
179 } else {
180 if ($version_local % 100 == 0) {
181 self::messagesSet(
182 'notice',
183 $message_id,
184 __('Version check'),
185 Sanitize::sanitize(sprintf(__('You are using Git version, run [kbd]git pull[/kbd] :-)[br]The latest stable version is %s, released on %s.'), $version, $date))
187 } else {
188 self::messagesSet(
189 'notice',
190 $message_id,
191 __('Version check'),
192 __('No newer stable version is available')