[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Static Pages Plugin 1.4.3 | 6 // +---------------------------------------------------------------------------+ 7 // | install.php | 8 // | | 9 // | This file installs and removes the data structures for the | 10 // | Static pages 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.26 2006/11/12 14:53:05 dhaun Exp $ 40 41 require_once ('../../../lib-common.php'); 42 require_once ($_CONF['path'] . 'plugins/staticpages/config.php'); 43 44 // Plugin information 45 // 46 // ---------------------------------------------------------------------------- 47 // 48 $pi_display_name = 'Static Page'; 49 $pi_name = 'staticpages'; 50 $pi_version = $_SP_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 = $pi_display_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 Static Pages plugin'; 60 61 $FEATURES = array(); 62 $FEATURES['staticpages.edit'] = 'Access to Static Pages editor'; 63 $FEATURES['staticpages.delete'] = 'Ability to delete static pages'; 64 $FEATURES['staticpages.PHP'] = 'Ability use PHP in static pages'; 65 66 $MAPPINGS = array(); 67 $MAPPINGS['staticpages.edit'] = array ($pi_admin); 68 $MAPPINGS['staticpages.delete'] = array ($pi_admin); 69 // Note: 'staticpages.PHP' is not assigned to any group by default 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 // no default data 76 77 /** 78 * Checks the requirements for this plugin and if it is compatible with this 79 * version of Geeklog. 80 * 81 * @return boolean true = proceed with install, false = not compatible 82 * 83 */ 84 function plugin_compatible_with_this_geeklog_version () 85 { 86 if (!function_exists ('SEC_getGroupDropdown')) { 87 return false; 88 } 89 90 return true; 91 } 92 // 93 // ---------------------------------------------------------------------------- 94 // 95 // The code below should be the same for most plugins and usually won't 96 // require modifications. 97 98 $base_path = $_CONF['path'] . 'plugins/' . $pi_name . '/'; 99 $langfile = $base_path . $_CONF['language'] . '.php'; 100 if (file_exists ($langfile)) { 101 require_once ($langfile); 102 } else { 103 require_once ($base_path . 'language/english.php'); 104 } 105 require_once ($base_path . 'config.php'); 106 require_once ($base_path . 'functions.inc'); 107 108 109 // Only let Root users access this page 110 if (!SEC_inGroup ('Root')) { 111 // Someone is trying to illegally access this page 112 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); 113 114 $display = COM_siteHeader ('menu', $LANG_ACCESS['accessdenied']) 115 . COM_startBlock ($LANG_ACCESS['accessdenied']) 116 . $LANG_ACCESS['plugin_access_denied_msg'] 117 . COM_endBlock () 118 . COM_siteFooter (); 119 120 echo $display; 121 exit; 122 } 123 124 125 /** 126 * Puts the datastructures for this plugin into the Geeklog database 127 * 128 */ 129 function plugin_install_now() 130 { 131 global $_CONF, $_TABLES, $_USER, $_DB_dbms, 132 $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, 133 $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url; 134 135 COM_errorLog ("Attempting to install the $pi_display_name plugin", 1); 136 137 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 138 139 // create the plugin's groups 140 $admin_group_id = 0; 141 foreach ($GROUPS as $name => $desc) { 142 COM_errorLog ("Attempting to create $name group", 1); 143 144 $grp_name = addslashes ($name); 145 $grp_desc = addslashes ($desc); 146 DB_query ("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('$grp_name', '$grp_desc')", 1); 147 if (DB_error ()) { 148 $uninstall_plugin (); 149 150 return false; 151 } 152 153 // replace the description with the new group id so we can use it later 154 $GROUPS[$name] = DB_insertId (); 155 156 // assume that the first group is the plugin's Admin group 157 if ($admin_group_id == 0) { 158 $admin_group_id = $GROUPS[$name]; 159 } 160 } 161 162 // Create the plugin's table(s) 163 $_SQL = array (); 164 if (file_exists ($base_path . 'sql/' . $_DB_dbms . '_install.php')) { 165 require_once ($base_path . 'sql/' . $_DB_dbms . '_install.php'); 166 } 167 168 if (count ($_SQL) > 0) { 169 $use_innodb = false; 170 if (($_DB_dbms == 'mysql') && 171 (DB_getItem ($_TABLES['vars'], 'value', "name = 'database_engine'") 172 == 'InnoDB')) { 173 $use_innodb = true; 174 } 175 foreach ($_SQL as $sql) { 176 $sql = str_replace ('#group#', $admin_group_id, $sql); 177 if ($use_innodb) { 178 $sql = str_replace ('MyISAM', 'InnoDB', $sql); 179 } 180 DB_query ($sql); 181 if (DB_error ()) { 182 COM_errorLog ('Error creating table', 1); 183 $uninstall_plugin (); 184 185 return false; 186 } 187 } 188 } 189 190 // Add the plugin's features 191 COM_errorLog ("Attempting to add $pi_display_name feature(s)", 1); 192 193 foreach ($FEATURES as $feature => $desc) { 194 $ft_name = addslashes ($feature); 195 $ft_desc = addslashes ($desc); 196 DB_query ("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " 197 . "VALUES ('$ft_name', '$ft_desc')", 1); 198 if (DB_error ()) { 199 $uninstall_plugin (); 200 201 return false; 202 } 203 204 $feat_id = DB_insertId (); 205 206 if (isset ($MAPPINGS[$feature])) { 207 foreach ($MAPPINGS[$feature] as $group) { 208 COM_errorLog ("Adding $feature feature to the $group group", 1); 209 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($feat_id, {$GROUPS[$group]})"); 210 if (DB_error ()) { 211 $uninstall_plugin (); 212 213 return false; 214 } 215 } 216 } 217 } 218 219 // Add plugin's Admin group to the Root user group 220 // (assumes that the Root group's ID is always 1) 221 COM_errorLog ("Attempting to give all users in the Root group access to the $pi_display_name's Admin group", 1); 222 223 DB_query ("INSERT INTO {$_TABLES['group_assignments']} VALUES " 224 . "($admin_group_id, NULL, 1)"); 225 if (DB_error ()) { 226 $uninstall_plugin (); 227 228 return false; 229 } 230 231 // Pre-populate tables or run any other SQL queries 232 COM_errorLog ('Inserting default data', 1); 233 foreach ($DEFVALUES as $sql) { 234 $sql = str_replace ('#group#', $admin_group_id, $sql); 235 DB_query ($sql, 1); 236 if (DB_error ()) { 237 $uninstall_plugin (); 238 239 return false; 240 } 241 } 242 243 // Finally, register the plugin with Geeklog 244 COM_errorLog ("Registering $pi_display_name plugin with Geeklog", 1); 245 246 // silently delete an existing entry 247 DB_delete ($_TABLES['plugins'], 'pi_name', $pi_name); 248 249 DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " 250 . "('$pi_name', '$pi_version', '$gl_version', '$pi_url', 1)"); 251 252 if (DB_error ()) { 253 $uninstall_plugin (); 254 255 return false; 256 } 257 258 // give the plugin a chance to perform any post-install operations 259 if (function_exists ('plugin_postinstall')) { 260 if (!plugin_postinstall ()) { 261 $uninstall_plugin (); 262 263 return false; 264 } 265 } 266 267 COM_errorLog ("Successfully installed the $pi_display_name plugin!", 1); 268 269 return true; 270 } 271 272 273 // MAIN 274 $display = ''; 275 276 if ($_REQUEST['action'] == 'uninstall') { 277 $uninstall_plugin = 'plugin_uninstall_' . $pi_name; 278 if ($uninstall_plugin ()) { 279 $display = COM_refresh ($_CONF['site_admin_url'] 280 . '/plugins.php?msg=45'); 281 } else { 282 $display = COM_refresh ($_CONF['site_admin_url'] 283 . '/plugins.php?msg=73'); 284 } 285 } else if (DB_count ($_TABLES['plugins'], 'pi_name', $pi_name) == 0) { 286 // plugin not installed 287 288 if (plugin_compatible_with_this_geeklog_version ()) { 289 if (plugin_install_now ()) { 290 $display = COM_refresh ($_CONF['site_admin_url'] 291 . '/plugins.php?msg=44'); 292 } else { 293 $display = COM_refresh ($_CONF['site_admin_url'] 294 . '/plugins.php?msg=72'); 295 } 296 } else { 297 // plugin needs a newer version of Geeklog 298 $display .= COM_siteHeader ('menu', $LANG32[8]) 299 . COM_startBlock ($LANG32[8]) 300 . '<p>' . $LANG32[9] . '</p>' 301 . COM_endBlock () 302 . COM_siteFooter (); 303 } 304 } else { 305 // plugin already installed 306 $display .= COM_siteHeader ('menu', $LANG01[77]) 307 . COM_startBlock ($LANG32[6]) 308 . '<p>' . $LANG32[7] . '</p>' 309 . COM_endBlock () 310 . COM_siteFooter(); 311 } 312 313 echo $display; 314 315 ?>
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 |
![]() |