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

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

Fix bug with htmlspecialchars on plugins name.

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          $fs_plugin_name = htmlspecialchars_decode($fs_plugin['name']);
89
90          if (in_array($fs_plugin_name, $ignore_list))
91          {
92            array_push($new_ignore_list, $fs_plugin_name);
93          }
94          else
95          {
96            $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name'];
97          }
98        }
99      }
100    }
101
102    // Update ignore list in database
103    $query = '
104UPDATE '.CONFIG_TABLE.'
105SET value = "'.addslashes(serialize($new_ignore_list)).'"
106WHERE param = "autoupdate_ignore_list"
107;';
108    pwg_query($query);
109  }
110}
111
112?>
Note: See TracBrowser for help on using the repository browser.