[1578] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
[1716] | 4 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1578] | 5 | // +-----------------------------------------------------------------------+ |
---|
[1716] | 6 | // | file : $Id: plugins.php 2216 2008-02-27 02:31:51Z rvelices $ |
---|
[1578] | 7 | // | last update : $Date: 2008-02-27 02:31:51 +0000 (Wed, 27 Feb 2008) $ |
---|
| 8 | // | last modifier : $Author: rvelices $ |
---|
| 9 | // | revision : $Revision: 2216 $ |
---|
| 10 | // +-----------------------------------------------------------------------+ |
---|
| 11 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 12 | // | it under the terms of the GNU General Public License as published by | |
---|
| 13 | // | the Free Software Foundation | |
---|
| 14 | // | | |
---|
| 15 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 16 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 17 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 18 | // | General Public License for more details. | |
---|
| 19 | // | | |
---|
| 20 | // | You should have received a copy of the GNU General Public License | |
---|
| 21 | // | along with this program; if not, write to the Free Software | |
---|
| 22 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 23 | // | USA. | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | |
---|
| 26 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 27 | { |
---|
| 28 | die ("Hacking attempt!"); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 32 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 33 | |
---|
| 34 | $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins'; |
---|
| 35 | |
---|
[1584] | 36 | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | perform requested actions | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
[1994] | 40 | if ( isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser() ) |
---|
[1578] | 41 | { |
---|
[1852] | 42 | $plugin_id = $_GET['plugin']; |
---|
[1584] | 43 | $crt_db_plugin = get_db_plugins('', $plugin_id); |
---|
| 44 | if (!empty($crt_db_plugin)) |
---|
[1578] | 45 | { |
---|
[1584] | 46 | $crt_db_plugin=$crt_db_plugin[0]; |
---|
[1578] | 47 | } |
---|
| 48 | else |
---|
| 49 | { |
---|
[1584] | 50 | unset($crt_db_plugin); |
---|
[1578] | 51 | } |
---|
[1584] | 52 | |
---|
[1716] | 53 | $errors = array(); |
---|
[1584] | 54 | $file_to_include = PHPWG_PLUGINS_PATH.$plugin_id.'/maintain.inc.php'; |
---|
| 55 | |
---|
[1852] | 56 | switch ( $_GET['action'] ) |
---|
[1578] | 57 | { |
---|
[1584] | 58 | case 'install': |
---|
| 59 | if ( !empty($crt_db_plugin)) |
---|
| 60 | { |
---|
[1716] | 61 | array_push($errors, 'CANNOT install - ALREADY INSTALLED'); |
---|
| 62 | break; |
---|
[1584] | 63 | } |
---|
| 64 | $fs_plugins = get_fs_plugins(); |
---|
| 65 | if ( !isset( $fs_plugins[$plugin_id] ) ) |
---|
| 66 | { |
---|
[1716] | 67 | array_push($errors, 'CANNOT install - NO SUCH PLUGIN'); |
---|
| 68 | break; |
---|
[1584] | 69 | } |
---|
[1716] | 70 | if ( file_exists($file_to_include) ) |
---|
| 71 | { |
---|
| 72 | include_once($file_to_include); |
---|
| 73 | if ( function_exists('plugin_install') ) |
---|
| 74 | { |
---|
| 75 | plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | if (empty($errors)) |
---|
| 79 | { |
---|
| 80 | $query = ' |
---|
[1584] | 81 | INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("' |
---|
| 82 | .$plugin_id.'","'.$fs_plugins[$plugin_id]['version'].'" |
---|
| 83 | )'; |
---|
[1716] | 84 | pwg_query($query); |
---|
[1584] | 85 | } |
---|
| 86 | break; |
---|
| 87 | |
---|
| 88 | case 'activate': |
---|
| 89 | if ( !isset($crt_db_plugin) ) |
---|
| 90 | { |
---|
[1852] | 91 | array_push($errors, 'CANNOT '. $_GET['action'] .' - NOT INSTALLED'); |
---|
[1880] | 92 | break; |
---|
[1584] | 93 | } |
---|
| 94 | if ($crt_db_plugin['state']!='inactive') |
---|
| 95 | { |
---|
[1716] | 96 | array_push($errors, 'invalid current state '.$crt_db_plugin['state']); |
---|
[1880] | 97 | break; |
---|
[1584] | 98 | } |
---|
[1716] | 99 | if ( file_exists($file_to_include) ) |
---|
[1584] | 100 | { |
---|
[1716] | 101 | include_once($file_to_include); |
---|
| 102 | if ( function_exists('plugin_activate') ) |
---|
| 103 | { |
---|
| 104 | plugin_activate($plugin_id, $crt_db_plugin['version'], $errors); |
---|
| 105 | } |
---|
[1584] | 106 | } |
---|
[1716] | 107 | if (empty($errors)) |
---|
| 108 | { |
---|
| 109 | $query = ' |
---|
| 110 | UPDATE '.PLUGINS_TABLE.' SET state="active" WHERE id="'.$plugin_id.'"'; |
---|
| 111 | pwg_query($query); |
---|
| 112 | } |
---|
[1584] | 113 | break; |
---|
| 114 | |
---|
| 115 | case 'deactivate': |
---|
| 116 | if ( !isset($crt_db_plugin) ) |
---|
| 117 | { |
---|
[1852] | 118 | die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED'); |
---|
[1584] | 119 | } |
---|
| 120 | if ($crt_db_plugin['state']!='active') |
---|
| 121 | { |
---|
| 122 | die('invalid current state '.$crt_db_plugin['state']); |
---|
| 123 | } |
---|
| 124 | $query = ' |
---|
| 125 | UPDATE '.PLUGINS_TABLE.' SET state="inactive" WHERE id="'.$plugin_id.'"'; |
---|
| 126 | pwg_query($query); |
---|
| 127 | |
---|
| 128 | @include_once($file_to_include); |
---|
| 129 | if ( function_exists('plugin_deactivate') ) |
---|
| 130 | { |
---|
| 131 | plugin_deactivate($plugin_id); |
---|
| 132 | } |
---|
| 133 | break; |
---|
| 134 | |
---|
| 135 | case 'uninstall': |
---|
| 136 | if ( !isset($crt_db_plugin) ) |
---|
| 137 | { |
---|
[1852] | 138 | die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED'); |
---|
[1584] | 139 | } |
---|
| 140 | $query = ' |
---|
| 141 | DELETE FROM '.PLUGINS_TABLE.' WHERE id="'.$plugin_id.'"'; |
---|
| 142 | pwg_query($query); |
---|
| 143 | |
---|
| 144 | @include_once($file_to_include); |
---|
| 145 | if ( function_exists('plugin_uninstall') ) |
---|
| 146 | { |
---|
| 147 | plugin_uninstall($plugin_id); |
---|
| 148 | } |
---|
| 149 | break; |
---|
[1578] | 150 | } |
---|
[1716] | 151 | if (empty($errors)) |
---|
| 152 | { |
---|
| 153 | // do the redirection so that we allow the plugins to load/unload |
---|
| 154 | redirect($my_base_url); |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
| 159 | } |
---|
[1578] | 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
[1584] | 163 | // +-----------------------------------------------------------------------+ |
---|
| 164 | // | start template output | |
---|
| 165 | // +-----------------------------------------------------------------------+ |
---|
| 166 | $fs_plugins = get_fs_plugins(); |
---|
[2144] | 167 | uasort($fs_plugins, 'name_compare'); |
---|
[1584] | 168 | $db_plugins = get_db_plugins(); |
---|
| 169 | $db_plugins_by_id=array(); |
---|
[1588] | 170 | foreach ($db_plugins as $db_plugin) |
---|
[1584] | 171 | { |
---|
[1588] | 172 | $db_plugins_by_id[$db_plugin['id']] = $db_plugin; |
---|
[1584] | 173 | } |
---|
[1578] | 174 | |
---|
| 175 | |
---|
| 176 | $template->set_filenames(array('plugins' => 'admin/plugins.tpl')); |
---|
| 177 | |
---|
[1580] | 178 | $num=0; |
---|
[1584] | 179 | foreach( $fs_plugins as $plugin_id => $fs_plugin ) |
---|
[1580] | 180 | { |
---|
[1584] | 181 | $display_name = $fs_plugin['name']; |
---|
| 182 | if ( !empty($fs_plugin['uri']) ) |
---|
[1580] | 183 | { |
---|
[1584] | 184 | $display_name='<a href="'.$fs_plugin['uri'].'">'.$display_name.'</a>'; |
---|
[1580] | 185 | } |
---|
[1852] | 186 | $desc = $fs_plugin['description']; |
---|
| 187 | if (!empty($fs_plugin['author'])) |
---|
| 188 | { |
---|
| 189 | $desc.= ' (<em>'; |
---|
| 190 | if (!empty($fs_plugin['author uri'])) |
---|
| 191 | { |
---|
| 192 | $desc.= '<a href="'.$fs_plugin['author uri'].'">'.$fs_plugin['author'].'</a>'; |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | $desc.= $fs_plugin['author']; |
---|
| 197 | } |
---|
| 198 | $desc.= '</em>)'; |
---|
| 199 | } |
---|
[2216] | 200 | |
---|
| 201 | $tpl_plugin = |
---|
[1584] | 202 | array( |
---|
| 203 | 'NAME' => $display_name, |
---|
| 204 | 'VERSION' => $fs_plugin['version'], |
---|
[1852] | 205 | 'DESCRIPTION' => $desc, |
---|
[2216] | 206 | 'actions' => array(), |
---|
| 207 | ); |
---|
[1584] | 208 | |
---|
| 209 | |
---|
| 210 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
| 211 | if ( isset($db_plugins_by_id[$plugin_id]) ) |
---|
| 212 | { // already in the database |
---|
| 213 | // MAYBE TODO HERE: check for the version and propose upgrade action |
---|
| 214 | switch ($db_plugins_by_id[$plugin_id]['state']) |
---|
| 215 | { |
---|
| 216 | case 'active': |
---|
[2216] | 217 | $tpl_plugin['actions'][] = |
---|
[1584] | 218 | array( |
---|
| 219 | 'U_ACTION' => $action_url . '&action=deactivate', |
---|
| 220 | 'L_ACTION' => l10n('Deactivate'), |
---|
[2216] | 221 | ); |
---|
[1584] | 222 | break; |
---|
| 223 | case 'inactive': |
---|
[2216] | 224 | $tpl_plugin['actions'][] = |
---|
[1584] | 225 | array( |
---|
| 226 | 'U_ACTION' => $action_url . '&action=activate', |
---|
| 227 | 'L_ACTION' => l10n('Activate'), |
---|
[2216] | 228 | ); |
---|
| 229 | $tpl_plugin['actions'][] = |
---|
[1584] | 230 | array( |
---|
| 231 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
| 232 | 'L_ACTION' => l10n('Uninstall'), |
---|
[2216] | 233 | 'CONFIRM' => true, |
---|
| 234 | ); |
---|
[1584] | 235 | break; |
---|
| 236 | } |
---|
| 237 | } |
---|
[1580] | 238 | else |
---|
| 239 | { |
---|
[2216] | 240 | $tpl_plugin['actions'][] = |
---|
[1584] | 241 | array( |
---|
| 242 | 'U_ACTION' => $action_url . '&action=install', |
---|
| 243 | 'L_ACTION' => l10n('Install'), |
---|
[2216] | 244 | 'CONFIRM' => true, |
---|
| 245 | ); |
---|
[1580] | 246 | } |
---|
[2216] | 247 | $template->append('plugins', $tpl_plugin); |
---|
[1584] | 248 | } |
---|
| 249 | |
---|
| 250 | $missing_plugin_ids = array_diff( |
---|
| 251 | array_keys($db_plugins_by_id), array_keys($fs_plugins) |
---|
| 252 | ); |
---|
| 253 | foreach( $missing_plugin_ids as $plugin_id ) |
---|
| 254 | { |
---|
[2216] | 255 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
| 256 | |
---|
| 257 | $template->append( 'plugins', |
---|
[1580] | 258 | array( |
---|
[1584] | 259 | 'NAME' => $plugin_id, |
---|
| 260 | 'VERSION' => $db_plugins_by_id[$plugin_id]['version'], |
---|
| 261 | 'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", |
---|
[2216] | 262 | 'actions' => array ( array ( |
---|
| 263 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
| 264 | 'L_ACTION' => l10n('Uninstall'), |
---|
| 265 | ) ) |
---|
[1580] | 266 | ) |
---|
| 267 | ); |
---|
| 268 | } |
---|
| 269 | |
---|
[1578] | 270 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins'); |
---|
| 271 | ?> |
---|