source: trunk/admin/plugins_installed.php @ 12033

Last change on this file since 12033 was 12033, checked in by mistic100, 13 years ago

bug:2426 admins shouldn't be able to perform any action on plugins

  • Property svn:eol-style set to LF
File size: 6.3 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    $plugins->perform_action('uninstall', $plugin_id);
142    $tpl_plugin['STATE'] = 'merged';
143    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
144    $merged_plugins = true;
145  }
146 
147  if ($tpl_plugin['STATE'] == 'active')
148  {
149    $active_plugins++;
150  }
151
152  array_push($tpl_plugins, $tpl_plugin);
153}
154
155$template->append('plugin_states', 'active');
156$template->append('plugin_states', 'inactive');
157
158if ($merged_plugins)
159{
160  $template->append('plugin_states', 'merged');
161}
162
163$missing_plugin_ids = array_diff(
164  array_keys($plugins->db_plugins_by_id),
165  array_keys($plugins->fs_plugins)
166  );
167
168if (count($missing_plugin_ids) > 0)
169{
170  foreach($missing_plugin_ids as $plugin_id)
171  {
172    array_push(
173      $tpl_plugins,
174      array(
175        'NAME' => $plugin_id,
176        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
177        'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
178        'U_ACTION' => sprintf($action_url, $plugin_id),
179        'STATE' => 'missing',
180        )
181      );
182  }
183  $template->append('plugin_states', 'missing');
184}
185
186// sort plugins by state then by name
187function cmp($a, $b)
188{ 
189  $s = array('merged' => 0, 'missing' => 1, 'active' => 2, 'inactive' => 3);
190 
191  if($a['STATE'] == $b['STATE'])
192    return strcasecmp($a['NAME'], $b['NAME']); 
193  else
194    return $s[$a['STATE']] >= $s[$b['STATE']]; 
195}
196usort($tpl_plugins, 'cmp');
197
198$template->assign(
199  array(
200    'plugins' => $tpl_plugins,
201    'active_plugins' => $active_plugins,
202    'PWG_TOKEN' => $pwg_token,
203    'base_url' => $base_url,
204    'show_details' => $show_details,
205    )
206  );
207
208$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
209?>
Note: See TracBrowser for help on using the repository browser.