source: extensions/autoupdate/trunk/ajax/check_updates.php @ 9710

Revision 9710, 6.5 KB checked in by patdenice, 9 years ago (diff)

New languages keys.

Line 
1<?php
2
3define('PHPWG_ROOT_PATH','../../../');
4define('IN_ADMIN', true);
5include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
6include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
7include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
8
9check_status(ACCESS_ADMINISTRATOR);
10
11// Check if gallery or plugins are up to date
12load_language('plugin.lang', dirname(dirname(__FILE__)).'/');
13header('Content-Type: text/html; charset=UTF-8');
14
15if (!isset($_SESSION['need_update']))
16{
17  $_SESSION['need_update'] = null;
18
19  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)
20    and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result))
21  {
22    $all_versions = @explode("\n", $result);
23    $new_version = trim($all_versions[0]);
24    $_SESSION['need_update'] = version_compare(PHPWG_VERSION, $new_version, '<');
25  }
26}
27
28if ($_SESSION['need_update'])
29{
30  echo 'piwigo_upgrade'; exit();
31}
32else
33{
34  // Gallery is up to date
35  // Check plugins upgrade
36  include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
37  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
38  include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
39  $plugins = new plugins();
40  $themes = new themes();
41  $languages = new languages();
42
43  if (!isset($_SESSION['extensions_need_update']))
44  {
45    $_SESSION['extensions_need_update'] = array();
46    autoupdate_check_plugins_upgrade($plugins);
47    autoupdate_check_themes_upgrade($themes);
48    autoupdate_check_languages_upgrade($languages);
49  }
50  else
51  {
52    if (!empty($_SESSION['extensions_need_update']['plugins']))
53    {
54      // Check if plugins have been upgraded since last check
55      foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
56      {
57        if (isset($_SESSION['extensions_need_update']['plugins'][$plugin_id])
58          and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['extensions_need_update']['plugins'][$plugin_id]))
59        {
60          // Plugin have been updated
61          autoupdate_check_plugins_upgrade($plugins);
62        }
63      }
64    }
65    if (!empty($_SESSION['extensions_need_update']['themes']))
66    {
67      // Check if themes have been upgraded since last check
68      foreach($themes->fs_themes as $theme_id => $fs_theme)
69      {
70        if (isset($_SESSION['extensions_need_update']['themes'][$theme_id])
71          and $themes->theme_version_compare($fs_theme['version'], $_SESSION['extensions_need_update']['themes'][$theme_id]))
72        {
73          // theme have been updated
74          autoupdate_check_themes_upgrade($themes);
75        }
76      }
77    }
78    if (!empty($_SESSION['extensions_need_update']['languages']))
79    {
80      // Check if languages have been upgraded since last check
81      foreach($languages->fs_languages as $language_id => $fs_language)
82      {
83        if (isset($_SESSION['extensions_need_update']['languages'][$language_id])
84          and $languages->language_version_compare($fs_language['version'], $_SESSION['extensions_need_update']['languages'][$language_id]))
85        {
86          // language have been updated
87          autoupdate_check_languages_upgrade($languages);
88        }
89      }
90    }
91  }
92
93  if (!empty($_SESSION['extensions_need_update']))
94  {
95    echo 'ext_upgrade'; exit;
96  }
97}
98
99if ($_SESSION['need_update'] === false and $_SESSION['extensions_need_update'] === array())
100{
101  echo 'up_to_date'; exit;
102}
103else
104{
105  autoupdate_error();
106}
107
108function autoupdate_check_plugins_upgrade($plugins)
109{
110  global $conf;
111
112  if (!$plugins->get_server_plugins())
113  {
114    autoupdate_error();
115  }
116
117  $plugins_ignore_list = array();
118  $need_upgrade = array();
119
120  foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
121  {
122    if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']]))
123    {
124      $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
125
126      if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
127      {
128        if (in_array($plugin_id, $conf['AU_ignore']['plugins']))
129        {
130          array_push($plugins_ignore_list, $plugin_id);
131        }
132        else
133        {
134          $_SESSION['extensions_need_update']['plugins'][$plugin_id] = $plugin_info['revision_name'];
135        }
136      }
137    }
138  }
139
140  $conf['AU_ignore']['plugins'] = $plugins_ignore_list;
141  conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore'])));
142}
143
144function autoupdate_check_themes_upgrade($themes)
145{
146  global $conf;
147
148  if (!$themes->get_server_themes())
149  {
150    autoupdate_error();
151  }
152 
153  $themes_ignore_list = array();
154  $need_upgrade = array();
155
156  foreach($themes->fs_themes as $theme_id => $fs_theme)
157  {
158    if (isset($fs_theme['extension']) and isset($themes->server_themes[$fs_theme['extension']]))
159    {
160      $theme_info = $themes->server_themes[$fs_theme['extension']];
161
162      if (!$themes->theme_version_compare($fs_theme['version'], $theme_info['revision_name']))
163      {
164        if (in_array($theme_id, $conf['AU_ignore']['theme']))
165        {
166          array_push($themes_ignore_list, $theme_id);
167        }
168        else
169        {
170          $_SESSION['extensions_need_update']['themes'][$theme_id] = $theme_info['revision_name'];
171        }
172      }
173    }
174  }
175
176  $conf['AU_ignore']['themes'] = $themes_ignore_list;
177  conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore'])));
178}
179
180function autoupdate_check_languages_upgrade($languages)
181{
182  global $conf;
183
184  if (!$languages->get_server_languages())
185  {
186    autoupdate_error();
187  }
188
189  $languages_ignore_list = array();
190  $need_upgrade = array();
191
192  foreach($languages->fs_languages as $language_id => $fs_language)
193  {
194    if (isset($fs_language['extension']) and isset($languages->server_languages[$fs_language['extension']]))
195    {
196      $language_info = $languages->server_languages[$fs_language['extension']];
197
198      if (!$languages->language_version_compare($fs_language['version'], $language_info['revision_name']))
199      {
200        if (in_array($language_id, $conf['AU_ignore']['languages']))
201        {
202          array_push($languages_ignore_list, $language_id);
203        }
204        else
205        {
206          $_SESSION['extensions_need_update']['languages'][$language_id] = $language_info['revision_name'];
207        }
208      }
209    }
210  }
211
212  $conf['AU_ignore']['languages'] = $languages_ignore_list;
213  conf_update_param('autoupdate_ignore_list', pwg_db_real_escape_string(serialize($conf['AU_ignore'])));
214}
215
216function autoupdate_error()
217{
218  $_SESSION['extensions_need_update'] = null;
219 
220  echo 'error'; exit;
221}
222
223?>
Note: See TracBrowser for help on using the repository browser.