source: extensions/autoupdate/trunk/include/functions_remote.inc.php @ 6196

Last change on this file since 6196 was 6196, checked in by patdenice, 14 years ago

Webmaster status is required to launch any upgrade process.
Display "save template directory" fielset only if Piwigo version < 2.1.
Add random parameter in all_version url (to avoid cache server).
Move empty directory to trash is rmdir fail.

File size: 3.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5function autoupdate_check_version($version=PHPWG_VERSION)
6{
7  global $conf;
8
9  if (!isset($_SESSION['need_update']))
10  {
11    $_SESSION['need_update'] = null;
12
13    if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches)
14      and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result))
15    {
16      $all_versions = @explode("\n", $result);
17      $new_version = trim($all_versions[0]);
18      $_SESSION['need_update'] = version_compare($version, $new_version, '<');
19    }
20  }
21
22  if ($_SESSION['need_update'])
23  {
24    return l10n('A new version of Piwigo is available.').'<br>'
25          . '<a href="admin.php?page=plugin&amp;section=autoupdate%2Fautoupdate.php">'.l10n('Click here to upgrade automatically').'</a>';
26  }
27  else
28  {
29    // Gallery is up to date
30    // Check plugins upgrade
31    include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
32    $plugins = new plugins();
33    $ignore_list = unserialize($conf['autoupdate_ignore_list']);
34
35    if (!isset($_SESSION['plugins_need_update']))
36    {
37      $_SESSION['plugins_need_update'] = null;
38      autoupdate_check_plugins_upgrade($plugins, $ignore_list);
39    }
40    elseif (!empty($_SESSION['plugins_need_update']))
41    {
42      // Check if plugins have been upgraded since last check
43      foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
44      {
45        if (isset($_SESSION['plugins_need_update'][$plugin_id])
46          and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['plugins_need_update'][$plugin_id]))
47        {
48          // Plugin have been updated
49          autoupdate_check_plugins_upgrade($plugins, $ignore_list);
50        }
51      }
52    }
53
54    if (!empty($_SESSION['plugins_need_update']))
55    {
56      return l10n('Some upgrades are available for you plugins').'<br>'
57        . '<a href="admin.php?page=plugins_update">'.l10n('Click here see upgrade plugins page').'</a>';
58    }
59  }
60
61  if ($_SESSION['need_update'] === false and $_SESSION['plugins_need_update'] === array())
62  {
63    return l10n('Gallery and plugins are up to date');
64  }
65  else
66  {
67    return l10n('Unable to check upgrades...')
68      . '<br><a href="admin.php?action=check_autoupdate">'
69      . l10n('Click here to check upgrades now') . '</a>';
70  }
71}
72
73function autoupdate_check_plugins_upgrade($plugins, $ignore_list)
74{
75  if ($plugins->get_server_plugins())
76  {
77    $new_ignore_list = array();
78    $_SESSION['plugins_need_update'] = array();
79
80    foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
81    {
82      if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']]))
83      {
84        $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
85
86        if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
87        {
88          if (in_array($fs_plugin['name'], $ignore_list))
89          {
90            array_push($new_ignore_list, $fs_plugin['name']);
91          }
92          else
93          {
94            $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name'];
95          }
96        }
97      }
98    }
99
100    // Update ignore list in database
101    $query = '
102UPDATE '.CONFIG_TABLE.'
103SET value = "'.addslashes(serialize($new_ignore_list)).'"
104WHERE param = "autoupdate_ignore_list"
105;';
106    pwg_query($query);
107  }
108}
109
110?>
Note: See TracBrowser for help on using the repository browser.