source: trunk/admin/plugins_installed.php @ 10817

Last change on this file since 10817 was 10817, checked in by mistic100, 14 years ago

plugin manager : store display preferences into a session parameter

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