source: trunk/admin/plugins_installed.php @ 28989

Last change on this file since 28989 was 28432, checked in by rvelices, 11 years ago

added a persistent cache mechanism; used so far to cache image ids in flat view mode

  • 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-2014 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    $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        $persistent_cache->purge(true);
81      }
82      redirect($base_url);
83    }
84  }
85}
86
87//--------------------------------------------------------Incompatible Plugins
88if (isset($_GET['incompatible_plugins']))
89{
90  $incompatible_plugins = array();
91  foreach ($plugins->get_incompatible_plugins() as $plugin => $version)
92  {
93    if ($plugin == '~~expire~~') continue;
94    $incompatible_plugins[] = $plugin;
95   
96  }
97  echo json_encode($incompatible_plugins);
98  exit;
99}
100
101// +-----------------------------------------------------------------------+
102// |                     start template output                             |
103// +-----------------------------------------------------------------------+
104
105$plugins->sort_fs_plugins('name');
106$merged_extensions = $plugins->get_merged_extensions();
107$merged_plugins = false;
108$tpl_plugins = array();
109$active_plugins = 0;
110
111foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
112{
113  if (isset($_SESSION['incompatible_plugins'][$plugin_id])
114    and $fs_plugin['version'] != $_SESSION['incompatible_plugins'][$plugin_id])
115  {
116    // Incompatible plugins must be reinitilized
117    unset($_SESSION['incompatible_plugins']);
118  }
119
120  $tpl_plugin = array(
121    'ID' => $plugin_id,
122    'NAME' => $fs_plugin['name'],
123    'VISIT_URL' => $fs_plugin['uri'],
124    'VERSION' => $fs_plugin['version'],
125    'DESC' => $fs_plugin['description'],
126    'AUTHOR' => $fs_plugin['author'],
127    'AUTHOR_URL' => @$fs_plugin['author uri'],
128    'U_ACTION' => sprintf($action_url, $plugin_id),
129    );
130
131  if (isset($plugins->db_plugins_by_id[$plugin_id]))
132  {
133    $tpl_plugin['STATE'] = $plugins->db_plugins_by_id[$plugin_id]['state'];
134  }
135  else
136  {
137    $tpl_plugin['STATE'] = 'inactive';
138  }
139
140  if (isset($fs_plugin['extension']) and isset($merged_extensions[$fs_plugin['extension']]))
141  {
142    // Deactivate manually plugin from database
143    $query = 'UPDATE '.PLUGINS_TABLE.' SET state=\'inactive\' WHERE id=\''.$plugin_id.'\'';
144    pwg_query($query);
145
146    $tpl_plugin['STATE'] = 'merged';
147    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
148    $merged_plugins = true;
149  }
150 
151  if ($tpl_plugin['STATE'] == 'active')
152  {
153    $active_plugins++;
154  }
155
156  $tpl_plugins[] = $tpl_plugin;
157}
158
159$template->append('plugin_states', 'active');
160$template->append('plugin_states', 'inactive');
161
162if ($merged_plugins)
163{
164  $template->append('plugin_states', 'merged');
165}
166
167$missing_plugin_ids = array_diff(
168  array_keys($plugins->db_plugins_by_id),
169  array_keys($plugins->fs_plugins)
170  );
171
172if (count($missing_plugin_ids) > 0)
173{
174  foreach ($missing_plugin_ids as $plugin_id)
175  {
176    $tpl_plugins[] = array(
177      'NAME' => $plugin_id,
178      'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
179      'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
180      'U_ACTION' => sprintf($action_url, $plugin_id),
181      'STATE' => 'missing',
182      );
183  }
184  $template->append('plugin_states', 'missing');
185}
186
187// sort plugins by state then by name
188function cmp($a, $b)
189{ 
190  $s = array('merged' => 0, 'missing' => 1, 'active' => 2, 'inactive' => 3);
191 
192  if($a['STATE'] == $b['STATE'])
193    return strcasecmp($a['NAME'], $b['NAME']); 
194  else
195    return $s[$a['STATE']] >= $s[$b['STATE']]; 
196}
197usort($tpl_plugins, 'cmp');
198
199$template->assign(
200  array(
201    'plugins' => $tpl_plugins,
202    'active_plugins' => $active_plugins,
203    'PWG_TOKEN' => $pwg_token,
204    'base_url' => $base_url,
205    'show_details' => $show_details,
206    )
207  );
208
209$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
210?>
Note: See TracBrowser for help on using the repository browser.