source: branches/2.3/admin/plugins_installed.php @ 12529

Last change on this file since 12529 was 12378, checked in by patdenice, 13 years ago

merge r12359-12360 from trunk to branch 2.3
Avoid error if several obsolet plugins have to be uninstalled.
It's better to only deactivate obsolete plugins on loading.

  • Property svn:eol-style set to LF
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
30
31$template->set_filenames(array('plugins' => 'plugins_installed.tpl'));
32
33// should we display details on plugins?
34if (isset($_GET['show_details']))
35{
36  if (1 == $_GET['show_details'])
37  {
38    $show_details = true;
39  }
40  else
41  {
42    $show_details = false;
43  }
44
45  pwg_set_session_var('plugins_show_details', $show_details);
46}
47elseif (null != pwg_get_session_var('plugins_show_details'))
48{
49  $show_details = pwg_get_session_var('plugins_show_details');
50}
51else
52{
53  $show_details = false;
54}
55
56$base_url = get_root_url().'admin.php?page='.$page['page'];
57$pwg_token = get_pwg_token();
58$action_url = $base_url.'&amp;plugin='.'%s'.'&amp;pwg_token='.$pwg_token;
59
60$plugins = new plugins();
61
62//--------------------------------------------------perform requested actions
63if (isset($_GET['action']) and isset($_GET['plugin']))
64{
65  if (!is_webmaster())
66  {
67    array_push($page['errors'], l10n('Webmaster status is required.'));
68  }
69  else
70  {
71    check_pwg_token();
72
73    $page['errors'] = $plugins->perform_action($_GET['action'], $_GET['plugin']);
74
75    if (empty($page['errors']))
76    {
77      if ($_GET['action'] == 'activate' or $_GET['action'] == 'deactivate')
78      {
79        $template->delete_compiled_templates();
80      }
81      redirect($base_url);
82    }
83  }
84}
85
86//--------------------------------------------------------Incompatible Plugins
87if (isset($_GET['incompatible_plugins']))
88{
89  $incompatible_plugins = array();
90  foreach ($plugins->get_incompatible_plugins() as $plugin => $version)
91  {
92    if ($plugin == '~~expire~~') continue;
93    array_push($incompatible_plugins, $plugin);
94   
95  }
96  echo json_encode($incompatible_plugins);
97  exit;
98}
99
100// +-----------------------------------------------------------------------+
101// |                     start template output                             |
102// +-----------------------------------------------------------------------+
103
104$plugins->sort_fs_plugins('name');
105$merged_extensions = $plugins->get_merged_extensions();
106$merged_plugins = false;
107$tpl_plugins = array();
108$active_plugins = 0;
109
110foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
111{
112  if (isset($_SESSION['incompatible_plugins'][$plugin_id])
113    and $fs_plugin['version'] != $_SESSION['incompatible_plugins'][$plugin_id])
114  {
115    // Incompatible plugins must be reinitilized
116    unset($_SESSION['incompatible_plugins']);
117  }
118
119  $tpl_plugin = array(
120    'ID' => $plugin_id,
121    'NAME' => $fs_plugin['name'],
122    'VISIT_URL' => $fs_plugin['uri'],
123    'VERSION' => $fs_plugin['version'],
124    'DESC' => $fs_plugin['description'],
125    'AUTHOR' => $fs_plugin['author'],
126    'AUTHOR_URL' => @$fs_plugin['author uri'],
127    'U_ACTION' => sprintf($action_url, $plugin_id),
128    );
129
130  if (isset($plugins->db_plugins_by_id[$plugin_id]))
131  {
132    $tpl_plugin['STATE'] = $plugins->db_plugins_by_id[$plugin_id]['state'];
133  }
134  else
135  {
136    $tpl_plugin['STATE'] = 'inactive';
137  }
138
139  if (isset($fs_plugin['extension']) and isset($merged_extensions[$fs_plugin['extension']]))
140  {
141    // Deactivate manually plugin from database
142    $query = 'UPDATE '.PLUGINS_TABLE.' SET state=\'inactive\' WHERE id=\''.$plugin_id.'\'';
143    pwg_query($query);
144
145    $tpl_plugin['STATE'] = 'merged';
146    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
147    $merged_plugins = true;
148  }
149 
150  if ($tpl_plugin['STATE'] == 'active')
151  {
152    $active_plugins++;
153  }
154
155  array_push($tpl_plugins, $tpl_plugin);
156}
157
158$template->append('plugin_states', 'active');
159$template->append('plugin_states', 'inactive');
160
161if ($merged_plugins)
162{
163  $template->append('plugin_states', 'merged');
164}
165
166$missing_plugin_ids = array_diff(
167  array_keys($plugins->db_plugins_by_id),
168  array_keys($plugins->fs_plugins)
169  );
170
171if (count($missing_plugin_ids) > 0)
172{
173  foreach($missing_plugin_ids as $plugin_id)
174  {
175    array_push(
176      $tpl_plugins,
177      array(
178        'NAME' => $plugin_id,
179        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
180        'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
181        'U_ACTION' => sprintf($action_url, $plugin_id),
182        'STATE' => 'missing',
183        )
184      );
185  }
186  $template->append('plugin_states', 'missing');
187}
188
189// sort plugins by state then by name
190function cmp($a, $b)
191{ 
192  $s = array('merged' => 0, 'missing' => 1, 'active' => 2, 'inactive' => 3);
193 
194  if($a['STATE'] == $b['STATE'])
195    return strcasecmp($a['NAME'], $b['NAME']); 
196  else
197    return $s[$a['STATE']] >= $s[$b['STATE']]; 
198}
199usort($tpl_plugins, 'cmp');
200
201$template->assign(
202  array(
203    'plugins' => $tpl_plugins,
204    'active_plugins' => $active_plugins,
205    'PWG_TOKEN' => $pwg_token,
206    'base_url' => $base_url,
207    'show_details' => $show_details,
208    )
209  );
210
211$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
212?>
Note: See TracBrowser for help on using the repository browser.