[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Spam-X plugin 1.1.0 | 6 // +---------------------------------------------------------------------------+ 7 // | install.php | 8 // | | 9 // | This file installs and removes the data structures for the | 10 // | Spam-X plugin for Geeklog. | 11 // +---------------------------------------------------------------------------+ 12 // | Based on the Universal Plugin and prior work by the following authors: | 13 // | | 14 // | Copyright (C) 2002-2006 by the following authors: | 15 // | | 16 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | 17 // | Tom Willett - tom AT pigstye DOT net | 18 // | Blaine Lang - blaine AT portalparts DOT com | 19 // | Dirk Haun - dirk AT haun-online DOT de | 20 // | Vincent Furia - vinny01 AT users DOT sourceforge DOT net | 21 // +---------------------------------------------------------------------------+ 22 // | | 23 // | This program is free software; you can redistribute it and/or | 24 // | modify it under the terms of the GNU General Public License | 25 // | as published by the Free Software Foundation; either version 2 | 26 // | of the License, or (at your option) any later version. | 27 // | | 28 // | This program is distributed in the hope that it will be useful, | 29 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 30 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 31 // | GNU General Public License for more details. | 32 // | | 33 // | You should have received a copy of the GNU General Public License | 34 // | along with this program; if not, write to the Free Software Foundation, | 35 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 36 // | | 37 // +---------------------------------------------------------------------------+ 38 // 39 // $Id: install.php,v 1.19 2006/11/12 14:53:05 dhaun Exp $ 40 41 require_once ('../../../lib-common.php'); 42 require_once ($_CONF['path'] . 'plugins/spamx/config.php'); 43 44 // Plugin information 45 // 46 // ---------------------------------------------------------------------------- 47 // 48 $pi_display_name = 'Spam-X'; 49 $pi_name = 'spamx'; 50 $pi_version = $_SPX_CONF['version']; 51 $gl_version = '1.4.1'; 52 $pi_url = 'http://www.pigstye.net/gplugs/staticpages/index.php/spamx'; 53 54 // name of the Admin group 55 $pi_admin = $pi_name . ' Admin'; 56 57 // the plugin's groups - assumes first group to be the Admin group 58 $GROUPS = array(); 59 $GROUPS[$pi_admin] = 'Users in this group can administer the Spam-X plugin'; 60 61 $FEATURES = array(); 62 $FEATURES['spamx.admin'] = 'Full access to Spam-X plugin'; 63 64 $MAPPINGS = array(); 65 $MAPPINGS['spamx.admin'] = array ($pi_admin); 66 67 // (optional) data to pre-populate tables with 68 // Insert table name and sql to insert default data for your plugin. 69 // Note: '#group#' will be replaced with the id of the plugin's admin group. 70 $DEFVALUES = array(); 71 $DEFVALUES[] = "INSERT INTO {$_TABLES['vars']} VALUES ('spamx.counter', '0')"; 72 73 /** 74 * Checks the requirements for this plugin and if it is compatible with this 75 * version of Geeklog. 76 * 77 * @return boolean true = proceed with install, false = not compatible 78 * 79 */ 80 function plugin_compatible_with_this_geeklog_version () 81 { 82 if (function_exists ('PLG_spamAction')) { 83 return true; 84 } 85 86 return false; 87 } 88 // 89 // ---------------------------------------------------------------------------- 90 // 91 // The code below should be the same for most plugins and usually won't 92 // require modifications. 93 94 $base_path = $_CONF['path'] . 'plugins/' . $pi_name . '/'; 95 $langfile = $base_path . $_CONF['language'] . '.php'; 96 if (file_exists ($langfile)) { 97 require_once ($langfile); 98 } else { 99 require_once ($base_path . 'language/english.php'); 100 } 101 require_once ($base_path . 'config.php'); 102 require_once ($base_path . 'functions.inc'); 103 104 105 // Only let Root users access this page 106 if (!SEC_inGroup ('Root')) { 107 // Someone is trying to illegally access this page 108 COM_accessLog ("Someone has tried to illegally access the {$pi_display_name} install/uninstall page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$_SERVER['REMOTE_ADDR']}", 1); 109 110 $display = COM_siteHeader ('menu', $LANG_ACCESS['accessdenied']) 111 . COM_startBlock ($LANG_ACCESS['accessdenied']) 112 . $LANG_ACCESS['plugin_access_denied_msg'] 113 . COM_endBlock () 114 . COM_siteFooter (); 115 116 echo $display; 117 exit; 118 } 119 120 121 /** 122 * Puts the datastructures for this plugin into the Geeklog database 123 * 124 */ 125 function plugin_install_now() 126 { 127 global $_CONF, $_TABLES, $_USER, $_DB_dbms, 128 $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, 129 $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url; 130 131 COM_errorLog ("Attempting to install the $pi_display_name plugin", 1); 132 133 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 134 135 // create the plugin's groups 136 $admin_group_id = 0; 137 foreach ($GROUPS as $name => $desc) { 138 COM_errorLog ("Attempting to create $name group", 1); 139 140 $grp_name = addslashes ($name); 141 $grp_desc = addslashes ($desc); 142 DB_query ("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('$grp_name', '$grp_desc')", 1); 143 if (DB_error ()) { 144 $uninstall_plugin (); 145 146 return false; 147 } 148 149 // replace the description with the new group id so we can use it later 150 $GROUPS[$name] = DB_insertId (); 151 152 // assume that the first group is the plugin's Admin group 153 if ($admin_group_id == 0) { 154 $admin_group_id = $GROUPS[$name]; 155 } 156 } 157 158 // Create the plugin's table(s) 159 $_SQL = array (); 160 if (file_exists ($base_path . 'sql/' . $_DB_dbms . '_install.php')) { 161 require_once ($base_path . 'sql/' . $_DB_dbms . '_install.php'); 162 } 163 164 if (count ($_SQL) > 0) { 165 $use_innodb = false; 166 if (($_DB_dbms == 'mysql') && 167 (DB_getItem ($_TABLES['vars'], 'value', "name = 'database_engine'") 168 == 'InnoDB')) { 169 $use_innodb = true; 170 } 171 foreach ($_SQL as $sql) { 172 $sql = str_replace ('#group#', $admin_group_id, $sql); 173 if ($use_innodb) { 174 $sql = str_replace ('MyISAM', 'InnoDB', $sql); 175 } 176 DB_query ($sql); 177 if (DB_error ()) { 178 COM_errorLog ('Error creating table', 1); 179 $uninstall_plugin (); 180 181 return false; 182 } 183 } 184 } 185 186 // Add the plugin's features 187 COM_errorLog ("Attempting to add $pi_display_name feature(s)", 1); 188 189 foreach ($FEATURES as $feature => $desc) { 190 $ft_name = addslashes ($feature); 191 $ft_desc = addslashes ($desc); 192 DB_query ("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " 193 . "VALUES ('$ft_name', '$ft_desc')", 1); 194 if (DB_error ()) { 195 $uninstall_plugin (); 196 197 return false; 198 } 199 200 $feat_id = DB_insertId (); 201 202 if (isset ($MAPPINGS[$feature])) { 203 foreach ($MAPPINGS[$feature] as $group) { 204 COM_errorLog ("Adding $feature feature to the $group group", 1); 205 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($feat_id, {$GROUPS[$group]})"); 206 if (DB_error ()) { 207 $uninstall_plugin (); 208 209 return false; 210 } 211 } 212 } 213 } 214 215 // Add plugin's Admin group to the Root user group 216 // (assumes that the Root group's ID is always 1) 217 COM_errorLog ("Attempting to give all users in the Root group access to the $pi_display_name's Admin group", 1); 218 219 DB_query ("INSERT INTO {$_TABLES['group_assignments']} VALUES " 220 . "($admin_group_id, NULL, 1)"); 221 if (DB_error ()) { 222 $uninstall_plugin (); 223 224 return false; 225 } 226 227 // Pre-populate tables or run any other SQL queries 228 COM_errorLog ('Inserting default data', 1); 229 foreach ($DEFVALUES as $sql) { 230 $sql = str_replace ('#group#', $admin_group_id, $sql); 231 DB_query ($sql, 1); 232 if (DB_error ()) { 233 $uninstall_plugin (); 234 235 return false; 236 } 237 } 238 239 // Finally, register the plugin with Geeklog 240 COM_errorLog ("Registering $pi_display_name plugin with Geeklog", 1); 241 242 // silently delete an existing entry 243 DB_delete ($_TABLES['plugins'], 'pi_name', $pi_name); 244 245 DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " 246 . "('$pi_name', '$pi_version', '$gl_version', '$pi_url', 1)"); 247 248 if (DB_error ()) { 249 $uninstall_plugin (); 250 251 return false; 252 } 253 254 // give the plugin a chance to perform any post-install operations 255 if (function_exists ('plugin_postinstall')) { 256 if (!plugin_postinstall ()) { 257 $uninstall_plugin (); 258 259 return false; 260 } 261 } 262 263 COM_errorLog ("Successfully installed the $pi_display_name plugin!", 1); 264 265 return true; 266 } 267 268 269 // MAIN 270 $display = ''; 271 272 if ($_REQUEST['action'] == 'uninstall') { 273 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 274 if ($uninstall_plugin ()) { 275 $display = COM_refresh ($_CONF['site_admin_url'] 276 . '/plugins.php?msg=45'); 277 } else { 278 $display = COM_refresh ($_CONF['site_admin_url'] 279 . '/plugins.php?msg=73'); 280 } 281 } else if (DB_count ($_TABLES['plugins'], 'pi_name', $pi_name) == 0) { 282 // plugin not installed 283 284 if (plugin_compatible_with_this_geeklog_version ()) { 285 if (plugin_install_now ()) { 286 $display = COM_refresh ($_CONF['site_admin_url'] 287 . '/plugins.php?msg=44'); 288 } else { 289 $display = COM_refresh ($_CONF['site_admin_url'] 290 . '/plugins.php?msg=72'); 291 } 292 } else { 293 // plugin needs a newer version of Geeklog 294 $display .= COM_siteHeader ('menu', $LANG32[8]) 295 . COM_startBlock ($LANG32[8]) 296 . '<p>' . $LANG32[9] . '</p>' 297 . COM_endBlock () 298 . COM_siteFooter (); 299 } 300 } else { 301 // plugin already installed 302 $display .= COM_siteHeader ('menu', $LANG01[77]) 303 . COM_startBlock ($LANG32[6]) 304 . '<p>' . $LANG32[7] . '</p>' 305 . COM_endBlock () 306 . COM_siteFooter(); 307 } 308 309 echo $display; 310 311 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |