Update po files
[phpmyadmin.git] / setup / lib / Index.php
blob5fb73cf04b0c9a8d7894cc49186464d11d611249
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 namespace PhpMyAdmin\Setup;
10 use PhpMyAdmin\VersionInformation;
11 use PhpMyAdmin\Sanitize;
13 /**
14 * PhpMyAdmin\Setup\Index class
16 * Various checks and message functions used on index page.
18 * @package PhpMyAdmin-Setup
20 class Index
22 /**
23 * Initializes message list
25 * @return void
27 public static function messagesBegin()
29 if (! isset($_SESSION['messages']) || !is_array($_SESSION['messages'])) {
30 $_SESSION['messages'] = array('error' => array(), 'notice' => array());
31 } else {
32 // reset message states
33 foreach ($_SESSION['messages'] as &$messages) {
34 foreach ($messages as &$msg) {
35 $msg['fresh'] = false;
36 $msg['active'] = false;
42 /**
43 * Adds a new message to message list
45 * @param string $type one of: notice, error
46 * @param string $msgId unique message identifier
47 * @param string $title language string id (in $str array)
48 * @param string $message message text
50 * @return void
52 public static function messagesSet($type, $msgId, $title, $message)
54 $fresh = ! isset($_SESSION['messages'][$type][$msgId]);
55 $_SESSION['messages'][$type][$msgId] = array(
56 'fresh' => $fresh,
57 'active' => true,
58 'title' => $title,
59 'message' => $message);
62 /**
63 * Cleans up message list
65 * @return void
67 public static function messagesEnd()
69 foreach ($_SESSION['messages'] as &$messages) {
70 $remove_ids = array();
71 foreach ($messages as $id => &$msg) {
72 if ($msg['active'] == false) {
73 $remove_ids[] = $id;
76 foreach ($remove_ids as $id) {
77 unset($messages[$id]);
82 /**
83 * Prints message list, must be called after self::messagesEnd()
85 * @return void
87 public static function messagesShowHtml()
89 foreach ($_SESSION['messages'] as $type => $messages) {
90 foreach ($messages as $id => $msg) {
91 if (! $msg['fresh'] && $type != 'error') {
92 $extra = ' hiddenmessage';
93 } else {
94 $extra = '';
96 echo '<div class="' , $type, $extra , '" id="' , $id , '">'
97 , '<h4>' , $msg['title'] , '</h4>'
98 , $msg['message'] , '</div>';
104 * Checks for newest phpMyAdmin version and sets result as a new notice
106 * @return void
108 public static function versionCheck()
110 // version check messages should always be visible so let's make
111 // a unique message id each time we run it
112 $message_id = uniqid('version_check');
114 // Fetch data
115 $versionInformation = new VersionInformation();
116 $version_data = $versionInformation->getLatestVersion();
118 if (empty($version_data)) {
119 self::messagesSet(
120 'error',
121 $message_id,
122 __('Version check'),
124 'Reading of version failed. '
125 . 'Maybe you\'re offline or the upgrade server does not respond.'
128 return;
131 $releases = $version_data->releases;
132 $latestCompatible = $versionInformation->getLatestCompatibleVersion($releases);
133 if ($latestCompatible != null) {
134 $version = $latestCompatible['version'];
135 $date = $latestCompatible['date'];
136 } else {
137 return;
140 $version_upstream = $versionInformation->versionToInt($version);
141 if ($version_upstream === false) {
142 self::messagesSet(
143 'error',
144 $message_id,
145 __('Version check'),
146 __('Got invalid version string from server')
148 return;
151 $version_local = $versionInformation->versionToInt(
152 $GLOBALS['PMA_Config']->get('PMA_VERSION')
154 if ($version_local === false) {
155 self::messagesSet(
156 'error',
157 $message_id,
158 __('Version check'),
159 __('Unparsable version string')
161 return;
164 if ($version_upstream > $version_local) {
165 $version = htmlspecialchars($version);
166 $date = htmlspecialchars($date);
167 self::messagesSet(
168 'notice',
169 $message_id,
170 __('Version check'),
171 sprintf(__('A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is %s, released on %s.'), $version, $date)
173 } else {
174 if ($version_local % 100 == 0) {
175 self::messagesSet(
176 'notice',
177 $message_id,
178 __('Version check'),
179 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))
181 } else {
182 self::messagesSet(
183 'notice',
184 $message_id,
185 __('Version check'),
186 __('No newer stable version is available')