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

Revision 9712, 6.4 KB checked in by patdenice, 9 years ago (diff)

Clean code.
Rename files.

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