[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/admin/plugins/polls/ -> install.php (source)

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


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics