source: trunk/admin/plugins_installed.php @ 11844

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

'Deactivate all' link now visible if all plugins are active

  • Property svn:eol-style set to LF
File size: 6.1 KB
RevLine 
[2242]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2242]23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
[2263]29include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
[2255]30
[11048]31$template->set_filenames(array('plugins' => 'plugins_installed.tpl'));
[2255]32
[11010]33// display mode
[10817]34$plugin_display = isset($_GET['plugin_display']) ? $_GET['plugin_display'] : (pwg_get_session_var('plugin_display') != null ? pwg_get_session_var('plugin_display') : 'compact');
35pwg_set_session_var('plugin_display', $plugin_display);
[2255]36
[10817]37$base_url = get_root_url().'admin.php?page='.$page['page'];
[10305]38$pwg_token = get_pwg_token();
39$action_url = $base_url.'&amp;plugin='.'%s'.'&amp;pwg_token='.$pwg_token;
40
[2264]41$plugins = new plugins();
42
[2263]43//--------------------------------------------------perform requested actions
[8126]44if (isset($_GET['action']) and isset($_GET['plugin']))
[2255]45{
[9995]46  if (in_array($_GET['action'], array('install', 'uninstall')) AND !is_webmaster())
[9994]47  {
48    array_push($page['errors'], l10n('Webmaster status is required.'));
49  }
50  else
51  {
52    check_pwg_token();
[5691]53
[9994]54    $page['errors'] = $plugins->perform_action($_GET['action'], $_GET['plugin']);
[2264]55
[9994]56    if (empty($page['errors']))
[3950]57    {
[9994]58      if ($_GET['action'] == 'activate' or $_GET['action'] == 'deactivate')
59      {
60        $template->delete_compiled_templates();
61      }
62      redirect($base_url);
[3950]63    }
64  }
[2255]65}
66
[11047]67//--------------------------------------------------------Incompatible Plugins
68if (isset($_GET['incompatible_plugins']))
69{
70  $incompatible_plugins = array();
71  foreach ($plugins->get_incompatible_plugins() as $plugin => $version)
72  {
73    if ($plugin == '~~expire~~') continue;
74    array_push($incompatible_plugins, $plugin);
75   
76  }
77  echo json_encode($incompatible_plugins);
78  exit;
79}
80
[2255]81// +-----------------------------------------------------------------------+
82// |                     start template output                             |
83// +-----------------------------------------------------------------------+
[5474]84
[5475]85$plugins->sort_fs_plugins('name');
[11047]86$merged_extensions = $plugins->get_merged_extensions();
[10100]87$merged_plugins = false;
[10305]88$tpl_plugins = array();
[11227]89$active_plugins = 0;
[2264]90
[2263]91foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
[2242]92{
[10098]93  if (isset($_SESSION['incompatible_plugins'][$plugin_id])
94    and $fs_plugin['version'] != $_SESSION['incompatible_plugins'][$plugin_id])
95  {
96    // Incompatible plugins must be reinitilized
[11047]97    unset($_SESSION['incompatible_plugins']);
[10098]98  }
99
[5474]100  $tpl_plugin = array(
[10305]101    'ID' => $plugin_id,
[5474]102    'NAME' => $fs_plugin['name'],
103    'VISIT_URL' => $fs_plugin['uri'],
104    'VERSION' => $fs_plugin['version'],
105    'DESC' => $fs_plugin['description'],
106    'AUTHOR' => $fs_plugin['author'],
[5691]107    'AUTHOR_URL' => @$fs_plugin['author uri'],
[10098]108    'U_ACTION' => sprintf($action_url, $plugin_id),
[5474]109    );
[2242]110
[2263]111  if (isset($plugins->db_plugins_by_id[$plugin_id]))
[2293]112  {
113    $tpl_plugin['STATE'] = $plugins->db_plugins_by_id[$plugin_id]['state'];
[2242]114  }
115  else
116  {
[10293]117    $tpl_plugin['STATE'] = 'inactive';
[2242]118  }
[5474]119
[11047]120  if (isset($fs_plugin['extension']) and isset($merged_extensions[$fs_plugin['extension']]))
[10100]121  {
[10293]122    $plugins->perform_action('uninstall', $plugin_id);
[10100]123    $tpl_plugin['STATE'] = 'merged';
[10101]124    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
[10100]125    $merged_plugins = true;
126  }
[11227]127 
128  if ($tpl_plugin['STATE'] == 'active')
129  {
130    $active_plugins++;
131  }
[10100]132
[10305]133  array_push($tpl_plugins, $tpl_plugin);
[2242]134}
135
[10098]136$template->append('plugin_states', 'active');
137$template->append('plugin_states', 'inactive');
138
[10100]139if ($merged_plugins)
140{
141  $template->append('plugin_states', 'merged');
142}
143
[2242]144$missing_plugin_ids = array_diff(
[5474]145  array_keys($plugins->db_plugins_by_id),
146  array_keys($plugins->fs_plugins)
147  );
[2242]148
[10098]149if (count($missing_plugin_ids) > 0)
[2242]150{
[10098]151  foreach($missing_plugin_ids as $plugin_id)
152  {
[10305]153    array_push(
154      $tpl_plugins,
[10098]155      array(
156        'NAME' => $plugin_id,
157        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
[10101]158        'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
[10098]159        'U_ACTION' => sprintf($action_url, $plugin_id),
160        'STATE' => 'missing',
161        )
162      );
163  }
164  $template->append('plugin_states', 'missing');
[2242]165}
166
[11010]167// sort plugins by state then by name
168function cmp($a, $b)
169{ 
170  $s = array('merged' => 0, 'missing' => 1, 'active' => 2, 'inactive' => 3);
171 
172  if($a['STATE'] == $b['STATE'])
[10305]173    return strcasecmp($a['NAME'], $b['NAME']); 
[11010]174  else
175    return $s[$a['STATE']] >= $s[$b['STATE']]; 
[10305]176}
[11010]177usort($tpl_plugins, 'cmp');
[10305]178
179$template->assign(array(
180  'plugin_display' => $plugin_display,
181  'plugins' => $tpl_plugins,
[11227]182  'active_plugins' => $active_plugins,
[10305]183  'PWG_TOKEN' => $pwg_token,
184));
185
[2255]186$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
[2242]187?>
Note: See TracBrowser for help on using the repository browser.