| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 // Reminder: always indent with 4 spaces (no tabs). 4 // +---------------------------------------------------------------------------+ 5 // | Links plugin 1.0 for Geeklog | 6 // +---------------------------------------------------------------------------+ 7 // | install.php | 8 // | | 9 // | This file installs and removes the data structures for the | 10 // | Links 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 40 /** 41 * This file installs and removes the data structures for the 42 * Links plugin for Geeklog. 43 * 44 * @package Links 45 * @subpackage admin 46 * @filesource 47 * @version 1.0.1 48 * @since GL 1.4.0 49 * @copyright Copyright © 2005-2006 50 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 51 * @author Trinity Bays <trinity93@steubentech.com> 52 * @author Tony Bibbs <tony@tonybibbs.com> 53 * @author Tom Willett <twillett@users.sourceforge.net> 54 * @author Blaine Lang <langmail@sympatico.ca> 55 * @author Dirk Haun <dirk@haun-online.de> 56 * 57 */ 58 // $Id: install.php,v 1.17 2006/11/12 14:53:05 dhaun Exp $ 59 60 require_once ('../../../lib-common.php'); 61 require_once ($_CONF['path'] . 'plugins/links/config.php'); 62 63 // Plugin information 64 /** 65 * plugin display name 66 * @global string $pi_display_name 67 */ 68 $pi_display_name = 'Links'; 69 /** 70 * plugin name 71 * @global string $pi_name 72 */ 73 $pi_name = 'links'; 74 /** 75 * plugin version 76 * @global string $pi_version 77 */ 78 $pi_version = $_LI_CONF['version']; 79 /** 80 * plugin suported GL version 81 * @global string $gl_version 82 */ 83 $gl_version = '1.4.1'; 84 /** 85 * plugin suport website url 86 * @global string $pi_url 87 */ 88 $pi_url = 'http://www.geeklog.net/'; 89 /** 90 * name of the Admin group 91 * @global string $pi_admin 92 */ 93 $pi_admin = $pi_display_name . ' Admin'; 94 95 96 /** 97 * the plugin's groups - assumes first group to be the Admin group 98 * @global array $GROUPS 99 * 100 */ 101 $GROUPS = array(); 102 $GROUPS[$pi_admin] = 'Has full access to ' . $pi_name . ' features'; 103 104 /** 105 * @global array $FEATURES 106 * 107 */ 108 $FEATURES = array(); 109 $FEATURES['links.edit'] = 'Access to links editor'; 110 $FEATURES['links.moderate'] = 'Ability to moderate pending links'; 111 $FEATURES['links.submit'] = 'May skip the links submission queue'; 112 113 /** 114 * @global array $MAPPINGS 115 * 116 */ 117 $MAPPINGS = array(); 118 $MAPPINGS['links.edit'] = array ($pi_admin); 119 $MAPPINGS['links.moderate'] = array ($pi_admin); 120 $MAPPINGS['links.submit'] = array ($pi_admin); 121 122 /** 123 * (optional) data to pre-populate tables with 124 * Insert table name and sql to insert default data for your plugin. 125 * Note: '#group#' will be replaced with the id of the plugin's admin group. 126 * @global array $DEFVALUES 127 * @name $DEFVALUES 128 */ 129 $DEFVALUES = array(); 130 $DEFVALUES[] = "INSERT INTO {$_TABLES['links']} (lid, category, url, description, title, date, owner_id, group_id, perm_group) VALUES ('geeklog.net', 'Geeklog Sites', 'http://www.geeklog.net/', 'Visit the Geeklog homepage for support, FAQs, updates, add-ons, and a great community.', 'Geeklog Project Homepage', NOW(), 1, #group#, 3)"; 131 132 /** 133 * Checks the requirements for this plugin and if it is compatible with this 134 * version of Geeklog. 135 * 136 * @return boolean true = proceed with install, false = not compatible 137 * 138 */ 139 function plugin_compatible_with_this_geeklog_version () 140 { 141 if (!function_exists ('COM_truncate') || !function_exists ('MBYTE_strpos')) { 142 return false; 143 } 144 145 return true; 146 } 147 // 148 // ---------------------------------------------------------------------------- 149 // 150 // The code below should be the same for most plugins and usually won't 151 // require modifications. 152 153 $base_path = $_CONF['path'] . 'plugins/' . $pi_name . '/'; 154 $langfile = $base_path . $_CONF['language'] . '.php'; 155 if (file_exists ($langfile)) { 156 require_once ($langfile); 157 } else { 158 require_once ($base_path . 'language/english.php'); 159 } 160 require_once ($base_path . 'config.php'); 161 require_once ($base_path . 'functions.inc'); 162 163 164 // Only let Root users access this page 165 if (!SEC_inGroup ('Root')) { 166 // Someone is trying to illegally access this page 167 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); 168 169 $display = COM_siteHeader ('menu', $LANG_ACCESS['accessdenied']) 170 . COM_startBlock ($LANG_ACCESS['accessdenied']) 171 . $LANG_ACCESS['plugin_access_denied_msg'] 172 . COM_endBlock () 173 . COM_siteFooter (); 174 175 echo $display; 176 exit; 177 } 178 179 180 /** 181 * Puts the datastructures for this plugin into the Geeklog database 182 * @global array core config vars 183 * @global array core table data 184 * @global array core user data 185 * @global array plugin group data 186 * @global array plugin feature data 187 * @global array plugin feature mapping data 188 * @global array data to preopulate db 189 * @global string path data 190 * @global string plugin name 191 * @global string plugin display name 192 * @global string plugin version 193 * @global string geeklog supported version 194 * @global string plugin support url 195 * @return boolean true if compleated false if failed 196 */ 197 function plugin_install_now() 198 { 199 global $_CONF, $_TABLES, $_USER, $_DB_dbms, 200 $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, 201 $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url; 202 203 COM_errorLog ("Attempting to install the $pi_display_name plugin", 1); 204 205 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 206 207 // create the plugin's groups 208 $admin_group_id = 0; 209 foreach ($GROUPS as $name => $desc) { 210 COM_errorLog ("Attempting to create $name group", 1); 211 212 $grp_name = addslashes ($name); 213 $grp_desc = addslashes ($desc); 214 DB_query ("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('$grp_name', '$grp_desc')", 1); 215 if (DB_error ()) { 216 $uninstall_plugin (); 217 218 return false; 219 } 220 221 // replace the description with the new group id so we can use it later 222 $GROUPS[$name] = DB_insertId (); 223 224 // assume that the first group is the plugin's Admin group 225 if ($admin_group_id == 0) { 226 $admin_group_id = $GROUPS[$name]; 227 } 228 } 229 230 // Create the plugin's table(s) 231 $_SQL = array (); 232 if (file_exists ($base_path . 'sql/' . $_DB_dbms . '_install.php')) { 233 require_once ($base_path . 'sql/' . $_DB_dbms . '_install.php'); 234 } 235 236 if (count ($_SQL) > 0) { 237 $use_innodb = false; 238 if (($_DB_dbms == 'mysql') && 239 (DB_getItem ($_TABLES['vars'], 'value', "name = 'database_engine'") 240 == 'InnoDB')) { 241 $use_innodb = true; 242 } 243 foreach ($_SQL as $sql) { 244 $sql = str_replace ('#group#', $admin_group_id, $sql); 245 if ($use_innodb) { 246 $sql = str_replace ('MyISAM', 'InnoDB', $sql); 247 } 248 DB_query ($sql); 249 if (DB_error ()) { 250 COM_errorLog ('Error creating table', 1); 251 $uninstall_plugin (); 252 253 return false; 254 } 255 } 256 } 257 258 // Add the plugin's features 259 COM_errorLog ("Attempting to add $pi_display_name feature(s)", 1); 260 261 foreach ($FEATURES as $feature => $desc) { 262 $ft_name = addslashes ($feature); 263 $ft_desc = addslashes ($desc); 264 DB_query ("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " 265 . "VALUES ('$ft_name', '$ft_desc')", 1); 266 if (DB_error ()) { 267 $uninstall_plugin (); 268 269 return false; 270 } 271 272 $feat_id = DB_insertId (); 273 274 if (isset ($MAPPINGS[$feature])) { 275 foreach ($MAPPINGS[$feature] as $group) { 276 COM_errorLog ("Adding $feature feature to the $group group", 1); 277 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($feat_id, {$GROUPS[$group]})"); 278 if (DB_error ()) { 279 $uninstall_plugin (); 280 281 return false; 282 } 283 } 284 } 285 } 286 287 // Add plugin's Admin group to the Root user group 288 // (assumes that the Root group's ID is always 1) 289 COM_errorLog ("Attempting to give all users in the Root group access to the $pi_display_name's Admin group", 1); 290 291 DB_query ("INSERT INTO {$_TABLES['group_assignments']} VALUES " 292 . "($admin_group_id, NULL, 1)"); 293 if (DB_error ()) { 294 $uninstall_plugin (); 295 296 return false; 297 } 298 299 // Pre-populate tables or run any other SQL queries 300 COM_errorLog ('Inserting default data', 1); 301 foreach ($DEFVALUES as $sql) { 302 $sql = str_replace ('#group#', $admin_group_id, $sql); 303 DB_query ($sql, 1); 304 if (DB_error ()) { 305 $uninstall_plugin (); 306 307 return false; 308 } 309 } 310 311 // Finally, register the plugin with Geeklog 312 COM_errorLog ("Registering $pi_display_name plugin with Geeklog", 1); 313 314 // silently delete an existing entry 315 DB_delete ($_TABLES['plugins'], 'pi_name', $pi_name); 316 317 DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " 318 . "('$pi_name', '$pi_version', '$gl_version', '$pi_url', 1)"); 319 320 if (DB_error ()) { 321 $uninstall_plugin (); 322 323 return false; 324 } 325 326 // give the plugin a chance to perform any post-install operations 327 if (function_exists ('plugin_postinstall')) { 328 if (!plugin_postinstall ()) { 329 $uninstall_plugin (); 330 331 return false; 332 } 333 } 334 335 COM_errorLog ("Successfully installed the $pi_display_name plugin!", 1); 336 337 return true; 338 } 339 340 341 // MAIN 342 $display = ''; 343 344 if ($_REQUEST['action'] == 'uninstall') { 345 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 346 if ($uninstall_plugin ()) { 347 $display = COM_refresh ($_CONF['site_admin_url'] 348 . '/plugins.php?msg=45'); 349 } else { 350 $display = COM_refresh ($_CONF['site_admin_url'] 351 . '/plugins.php?msg=73'); 352 } 353 } else if (DB_count ($_TABLES['plugins'], 'pi_name', $pi_name) == 0) { 354 // plugin not installed 355 356 if (plugin_compatible_with_this_geeklog_version ()) { 357 if (plugin_install_now ()) { 358 $display = COM_refresh ($_CONF['site_admin_url'] 359 . '/plugins.php?msg=44'); 360 } else { 361 $display = COM_refresh ($_CONF['site_admin_url'] 362 . '/plugins.php?msg=72'); 363 } 364 } else { 365 // plugin needs a newer version of Geeklog 366 $display .= COM_siteHeader ('menu', $LANG32[8]) 367 . COM_startBlock ($LANG32[8]) 368 . '<p>' . $LANG32[9] . '</p>' 369 . COM_endBlock () 370 . COM_siteFooter (); 371 } 372 } else { 373 // plugin already installed 374 $display .= COM_siteHeader ('menu', $LANG01[77]) 375 . COM_startBlock ($LANG32[6]) 376 . '<p>' . $LANG32[7] . '</p>' 377 . COM_endBlock () 378 . COM_siteFooter(); 379 } 380 381 echo $display; 382 383 ?>
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 |
|