source: trunk/admin/plugins_installed.php @ 20645

Last change on this file since 20645 was 19703, checked in by plg, 12 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

  • Property svn:eol-style set to LF
File size: 6.4 KB
RevLine 
[2242]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 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
[12029]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  }
[2255]44
[12029]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
[10817]56$base_url = get_root_url().'admin.php?page='.$page['page'];
[10305]57$pwg_token = get_pwg_token();
58$action_url = $base_url.'&amp;plugin='.'%s'.'&amp;pwg_token='.$pwg_token;
59
[2264]60$plugins = new plugins();
61
[2263]62//--------------------------------------------------perform requested actions
[8126]63if (isset($_GET['action']) and isset($_GET['plugin']))
[2255]64{
[12033]65  if (!is_webmaster())
[9994]66  {
67    array_push($page['errors'], l10n('Webmaster status is required.'));
68  }
69  else
70  {
71    check_pwg_token();
[5691]72
[9994]73    $page['errors'] = $plugins->perform_action($_GET['action'], $_GET['plugin']);
[2264]74
[9994]75    if (empty($page['errors']))
[3950]76    {
[9994]77      if ($_GET['action'] == 'activate' or $_GET['action'] == 'deactivate')
78      {
79        $template->delete_compiled_templates();
80      }
81      redirect($base_url);
[3950]82    }
83  }
[2255]84}
85
[11047]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
[2255]100// +-----------------------------------------------------------------------+
101// |                     start template output                             |
102// +-----------------------------------------------------------------------+
[5474]103
[5475]104$plugins->sort_fs_plugins('name');
[11047]105$merged_extensions = $plugins->get_merged_extensions();
[10100]106$merged_plugins = false;
[10305]107$tpl_plugins = array();
[11227]108$active_plugins = 0;
[2264]109
[2263]110foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
[2242]111{
[10098]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
[11047]116    unset($_SESSION['incompatible_plugins']);
[10098]117  }
118
[5474]119  $tpl_plugin = array(
[10305]120    'ID' => $plugin_id,
[5474]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'],
[5691]126    'AUTHOR_URL' => @$fs_plugin['author uri'],
[10098]127    'U_ACTION' => sprintf($action_url, $plugin_id),
[5474]128    );
[2242]129
[2263]130  if (isset($plugins->db_plugins_by_id[$plugin_id]))
[2293]131  {
132    $tpl_plugin['STATE'] = $plugins->db_plugins_by_id[$plugin_id]['state'];
[2242]133  }
134  else
135  {
[10293]136    $tpl_plugin['STATE'] = 'inactive';
[2242]137  }
[5474]138
[11047]139  if (isset($fs_plugin['extension']) and isset($merged_extensions[$fs_plugin['extension']]))
[10100]140  {
[12360]141    // Deactivate manually plugin from database
142    $query = 'UPDATE '.PLUGINS_TABLE.' SET state=\'inactive\' WHERE id=\''.$plugin_id.'\'';
[12359]143    pwg_query($query);
144
[10100]145    $tpl_plugin['STATE'] = 'merged';
[10101]146    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
[10100]147    $merged_plugins = true;
148  }
[11227]149 
150  if ($tpl_plugin['STATE'] == 'active')
151  {
152    $active_plugins++;
153  }
[10100]154
[10305]155  array_push($tpl_plugins, $tpl_plugin);
[2242]156}
157
[10098]158$template->append('plugin_states', 'active');
159$template->append('plugin_states', 'inactive');
160
[10100]161if ($merged_plugins)
162{
163  $template->append('plugin_states', 'merged');
164}
165
[2242]166$missing_plugin_ids = array_diff(
[5474]167  array_keys($plugins->db_plugins_by_id),
168  array_keys($plugins->fs_plugins)
169  );
[2242]170
[10098]171if (count($missing_plugin_ids) > 0)
[2242]172{
[10098]173  foreach($missing_plugin_ids as $plugin_id)
174  {
[10305]175    array_push(
176      $tpl_plugins,
[10098]177      array(
178        'NAME' => $plugin_id,
179        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
[10101]180        'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
[10098]181        'U_ACTION' => sprintf($action_url, $plugin_id),
182        'STATE' => 'missing',
183        )
184      );
185  }
186  $template->append('plugin_states', 'missing');
[2242]187}
188
[11010]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'])
[10305]195    return strcasecmp($a['NAME'], $b['NAME']); 
[11010]196  else
197    return $s[$a['STATE']] >= $s[$b['STATE']]; 
[10305]198}
[11010]199usort($tpl_plugins, 'cmp');
[10305]200
[12029]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  );
[10305]210
[2255]211$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
[2242]212?>
Note: See TracBrowser for help on using the repository browser.