[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Calendar plugin 1.0 for Geeklog | 6 // +---------------------------------------------------------------------------+ 7 // | install.php | 8 // | | 9 // | This file installs and removes the data structures for the | 10 // | Calendar 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.10 2006/11/12 14:53:06 dhaun Exp $ 40 41 require_once ('../../../lib-common.php'); 42 require_once ($_CONF['path'] . 'plugins/calendar/config.php'); 43 44 // Plugin information 45 // 46 // ---------------------------------------------------------------------------- 47 // 48 $pi_display_name = 'Calendar'; 49 $pi_name = 'calendar'; 50 $pi_version = $_CA_CONF['version']; 51 $gl_version = '1.4.1'; 52 $pi_url = 'http://www.geeklog.net/'; 53 54 // name of the Admin group 55 $pi_admin = 'Calendar Admin'; 56 57 // the plugin's groups - assumes first group to be the Admin group 58 $GROUPS = array(); 59 $GROUPS[$pi_admin] = 'Has full access to ' . $pi_name . ' features'; 60 61 $FEATURES = array(); 62 $FEATURES['calendar.moderate'] = 'Ability to moderate pending events'; 63 $FEATURES['calendar.edit'] = 'Access to event editor'; 64 $FEATURES['calendar.submit'] = 'May skip the event submission queue'; 65 66 $MAPPINGS = array(); 67 $MAPPINGS['calendar.moderate'] = array ($pi_admin); 68 $MAPPINGS['calendar.edit'] = array ($pi_admin); 69 $MAPPINGS['calendar.submit'] = array ($pi_admin); 70 71 // (optional) data to pre-populate tables with 72 // Insert table name and sql to insert default data for your plugin. 73 // Note: '#group#' will be replaced with the id of the plugin's admin group. 74 $DEFVALUES = array(); 75 76 /** 77 * Checks the requirements for this plugin and if it is compatible with this 78 * version of Geeklog. 79 * 80 * @return boolean true = proceed with install, false = not compatible 81 * 82 */ 83 function plugin_compatible_with_this_geeklog_version () 84 { 85 if (function_exists ('COM_printUpcomingEvents')) { 86 // if this function exists, then someone's trying to install the 87 // plugin on Geeklog 1.4.0 or older - sorry, but that won't work 88 return false; 89 } 90 91 if (!function_exists ('MBYTE_strpos')) { 92 // the plugin requires the multi-byte functions 93 return false; 94 } 95 96 return true; 97 } 98 99 /** 100 * When the install went through, give the plugin a chance for any 101 * plugin-specific post-install fixes 102 * 103 * @return boolean true = proceed with install, false = an error occured 104 * 105 */ 106 function plugin_postinstall () 107 { 108 global $_CONF, $_TABLES, $LANG_CAL_1; 109 110 // fix Upcoming Events block group ownership 111 $blockAdminGroup = DB_getItem ($_TABLES['groups'], 'grp_id', 112 "grp_name = 'Block Admin'"); 113 if ($blockAdminGroup > 0) { 114 // set the block's permissions 115 $A = array (); 116 SEC_setDefaultPermissions ($A, $_CONF['default_permissions_block']); 117 118 // set the block's title in the current language, while we're at it 119 $title = addslashes ($LANG_CAL_1[7]); 120 121 // ... and make it the last block on the left side 122 $result = DB_query ("SELECT MAX(blockorder) FROM {$_TABLES['blocks']} WHERE onleft = 1"); 123 list($order) = DB_fetchArray ($result); 124 $order += 10; 125 126 DB_query ("UPDATE {$_TABLES['blocks']} SET group_id = $blockAdminGroup, title = '$title', blockorder = $order, perm_owner = {$A['perm_owner']}, perm_group = {$A['perm_group']}, perm_members = {$A['perm_members']}, perm_anon = {$A['perm_anon']} WHERE (type = 'phpblock') AND (phpblockfn = 'phpblock_calendar')"); 127 128 return true; 129 } 130 131 return false; 132 } 133 134 // 135 // ---------------------------------------------------------------------------- 136 // 137 // The code below should be the same for most plugins and usually won't 138 // require modifications. 139 140 $base_path = $_CONF['path'] . 'plugins/' . $pi_name . '/'; 141 $langfile = $base_path . $_CONF['language'] . '.php'; 142 if (file_exists ($langfile)) { 143 require_once ($langfile); 144 } else { 145 require_once ($base_path . 'language/english.php'); 146 } 147 require_once ($base_path . 'config.php'); 148 require_once ($base_path . 'functions.inc'); 149 150 151 // Only let Root users access this page 152 if (!SEC_inGroup ('Root')) { 153 // Someone is trying to illegally access this page 154 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); 155 156 $display = COM_siteHeader ('menu', $LANG_ACCESS['accessdenied']) 157 . COM_startBlock ($LANG_ACCESS['accessdenied']) 158 . $LANG_ACCESS['plugin_access_denied_msg'] 159 . COM_endBlock () 160 . COM_siteFooter (); 161 162 echo $display; 163 exit; 164 } 165 166 167 /** 168 * Puts the datastructures for this plugin into the Geeklog database 169 * 170 */ 171 function plugin_install_now() 172 { 173 global $_CONF, $_TABLES, $_USER, $_DB_dbms, 174 $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, 175 $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url; 176 177 COM_errorLog ("Attempting to install the $pi_display_name plugin", 1); 178 179 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 180 181 // create the plugin's groups 182 $admin_group_id = 0; 183 foreach ($GROUPS as $name => $desc) { 184 COM_errorLog ("Attempting to create $name group", 1); 185 186 $grp_name = addslashes ($name); 187 $grp_desc = addslashes ($desc); 188 DB_query ("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('$grp_name', '$grp_desc')", 1); 189 if (DB_error ()) { 190 $uninstall_plugin (); 191 192 return false; 193 } 194 195 // replace the description with the new group id so we can use it later 196 $GROUPS[$name] = DB_insertId (); 197 198 // assume that the first group is the plugin's Admin group 199 if ($admin_group_id == 0) { 200 $admin_group_id = $GROUPS[$name]; 201 } 202 } 203 204 // Create the plugin's table(s) 205 $_SQL = array (); 206 if (file_exists ($base_path . 'sql/' . $_DB_dbms . '_install.php')) { 207 require_once ($base_path . 'sql/' . $_DB_dbms . '_install.php'); 208 } 209 210 if (count ($_SQL) > 0) { 211 $use_innodb = false; 212 if (($_DB_dbms == 'mysql') && 213 (DB_getItem ($_TABLES['vars'], 'value', "name = 'database_engine'") 214 == 'InnoDB')) { 215 $use_innodb = true; 216 } 217 foreach ($_SQL as $sql) { 218 $sql = str_replace ('#group#', $admin_group_id, $sql); 219 if ($use_innodb) { 220 $sql = str_replace ('MyISAM', 'InnoDB', $sql); 221 } 222 DB_query ($sql); 223 if (DB_error ()) { 224 COM_errorLog ('Error creating table', 1); 225 $uninstall_plugin (); 226 227 return false; 228 } 229 } 230 } 231 232 // Add the plugin's features 233 COM_errorLog ("Attempting to add $pi_display_name feature(s)", 1); 234 235 foreach ($FEATURES as $feature => $desc) { 236 $ft_name = addslashes ($feature); 237 $ft_desc = addslashes ($desc); 238 DB_query ("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " 239 . "VALUES ('$ft_name', '$ft_desc')", 1); 240 if (DB_error ()) { 241 $uninstall_plugin (); 242 243 return false; 244 } 245 246 $feat_id = DB_insertId (); 247 248 if (isset ($MAPPINGS[$feature])) { 249 foreach ($MAPPINGS[$feature] as $group) { 250 COM_errorLog ("Adding $feature feature to the $group group", 1); 251 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($feat_id, {$GROUPS[$group]})"); 252 if (DB_error ()) { 253 $uninstall_plugin (); 254 255 return false; 256 } 257 } 258 } 259 } 260 261 // Add plugin's Admin group to the Root user group 262 // (assumes that the Root group's ID is always 1) 263 COM_errorLog ("Attempting to give all users in the Root group access to the $pi_display_name's Admin group", 1); 264 265 DB_query ("INSERT INTO {$_TABLES['group_assignments']} VALUES " 266 . "($admin_group_id, NULL, 1)"); 267 if (DB_error ()) { 268 $uninstall_plugin (); 269 270 return false; 271 } 272 273 // Pre-populate tables or run any other SQL queries 274 COM_errorLog ('Inserting default data', 1); 275 foreach ($DEFVALUES as $sql) { 276 $sql = str_replace ('#group#', $admin_group_id, $sql); 277 DB_query ($sql, 1); 278 if (DB_error ()) { 279 $uninstall_plugin (); 280 281 return false; 282 } 283 } 284 285 // Finally, register the plugin with Geeklog 286 COM_errorLog ("Registering $pi_display_name plugin with Geeklog", 1); 287 288 // silently delete an existing entry 289 DB_delete ($_TABLES['plugins'], 'pi_name', $pi_name); 290 291 DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " 292 . "('$pi_name', '$pi_version', '$gl_version', '$pi_url', 1)"); 293 294 if (DB_error ()) { 295 $uninstall_plugin (); 296 297 return false; 298 } 299 300 // give the plugin a chance to perform any post-install operations 301 if (function_exists ('plugin_postinstall')) { 302 if (!plugin_postinstall ()) { 303 $uninstall_plugin (); 304 305 return false; 306 } 307 } 308 309 COM_errorLog ("Successfully installed the $pi_display_name plugin!", 1); 310 311 return true; 312 } 313 314 315 // MAIN 316 $display = ''; 317 318 if ($_REQUEST['action'] == 'uninstall') { 319 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 320 if ($uninstall_plugin ()) { 321 $display = COM_refresh ($_CONF['site_admin_url'] 322 . '/plugins.php?msg=45'); 323 } else { 324 $display = COM_refresh ($_CONF['site_admin_url'] 325 . '/plugins.php?msg=73'); 326 } 327 } else if (DB_count ($_TABLES['plugins'], 'pi_name', $pi_name) == 0) { 328 // plugin not installed 329 330 if (plugin_compatible_with_this_geeklog_version ()) { 331 if (plugin_install_now ()) { 332 $display = COM_refresh ($_CONF['site_admin_url'] 333 . '/plugins.php?msg=44'); 334 } else { 335 $display = COM_refresh ($_CONF['site_admin_url'] 336 . '/plugins.php?msg=72'); 337 } 338 } else { 339 // plugin needs a newer version of Geeklog 340 $display .= COM_siteHeader ('menu', $LANG32[8]) 341 . COM_startBlock ($LANG32[8]) 342 . '<p>' . $LANG32[9] . '</p>' 343 . COM_endBlock () 344 . COM_siteFooter (); 345 } 346 } else { 347 // plugin already installed 348 $display .= COM_siteHeader ('menu', $LANG01[77]) 349 . COM_startBlock ($LANG32[6]) 350 . '<p>' . $LANG32[7] . '</p>' 351 . COM_endBlock () 352 . COM_siteFooter(); 353 } 354 355 echo $display; 356 357 ?>
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 |
![]() |