b2evolution PHP Cross Reference Blogging Systems

Source: /install/_functions_install.php - 1046 lines - 29241 bytes - Summary - Text - Print

Description: This file implements support functions for the installer b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements support functions for the installer
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   *
   9   * @package install
  10   */
  11  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  12  
  13  /**
  14   * Open a block
  15   */
  16  function block_open()
  17  {
  18      global $block_status;
  19      if( isset($block_status) && $block_status == 'open' )
  20      {
  21          return;
  22      }
  23      $block_status = 'open';
  24      echo '<div class="block1"><div class="block2"><div class="block3">';
  25  }
  26  
  27  /**
  28   * Close a block
  29   */
  30  function block_close()
  31  {
  32      global $block_status;
  33      if( !isset($block_status) || $block_status == 'closed' )
  34      {
  35          return;
  36      }
  37      $block_status = 'closed';
  38      echo '</div></div></div>';
  39  }
  40  
  41  /**
  42   * Language selector
  43   */
  44  function display_locale_selector()
  45  {
  46      global $locales, $default_locale, $action;
  47  
  48      static $selector_already_displayed = false;
  49  
  50      if( $selector_already_displayed )
  51      {
  52          return;
  53      }
  54      $selector_already_displayed = true;
  55      block_open();
  56      ?>
  57      <h2><?php echo T_('Language / Locale')?></h2>
  58      <form action="index.php" method="get">
  59      <?php
  60      echo '<div class="floatright"><a href="index.php?action=localeinfo&amp;locale='.$default_locale.'">'.T_('More languages').' &raquo;</a></div>';
  61  
  62      locale_flag( $default_locale, 'w16px', 'flag', '', true, /* Do not rely on $baseurl/$rsc_url here: */ '../rsc/flags' );
  63      echo '<select name="locale" onchange="this.form.submit()">';
  64      foreach( $locales as $lkey => $lvalue )
  65      {
  66          echo '<option';
  67          if( $default_locale == $lkey ) echo ' selected="selected"';
  68          echo ' value="'.$lkey.'">';
  69          echo T_( $lvalue['name'] );
  70          echo '</option>';
  71      }
  72      ?>
  73      </select>
  74      <noscript>
  75          <input type="submit" value="<?php echo T_('Select as default language/locale'); ?>" />
  76      </noscript>
  77      </form>
  78      <?php
  79      block_close();
  80  }
  81  
  82  /**
  83   * Base config recap
  84   */
  85  function display_base_config_recap()
  86  {
  87      global $default_locale, $conf_db_user, $conf_db_password, $conf_db_name, $conf_db_host, $db_config, $tableprefix, $baseurl, $admin_email;
  88  
  89      static $base_config_recap_already_displayed = false;
  90  
  91      if( $base_config_recap_already_displayed )
  92      {
  93          return;
  94      }
  95      $base_config_recap_already_displayed = true;
  96  
  97      block_open();
  98      ?>
  99      <h2><?php echo T_('Base config recap...')?></h2>
 100  
 101      <p><?php printf( T_('If you don\'t see correct settings here, STOP before going any further, and <a %s>update your base configuration</a>.'), 'href="index.php?action=start&amp;locale='.$default_locale.'"' ) ?></p>
 102  
 103      <?php
 104      if( !isset($conf_db_user) ) $conf_db_user = $db_config['user'];
 105      if( !isset($conf_db_password) ) $conf_db_password = $db_config['password'];
 106      if( !isset($conf_db_name) ) $conf_db_name = $db_config['name'];
 107      if( !isset($conf_db_host) ) $conf_db_host = isset($db_config['host']) ? $db_config['host'] : 'localhost';
 108  
 109      echo '<pre>',
 110      T_('MySQL Username').': '.$conf_db_user."\n".
 111      T_('MySQL Password').': '.(($conf_db_password != 'demopass' ? T_('(Set, but not shown for security reasons)') : 'demopass') )."\n".
 112      T_('MySQL Database name').': '.$conf_db_name."\n".
 113      T_('MySQL Host/Server').': '.$conf_db_host."\n".
 114      T_('MySQL tables prefix').': '.$tableprefix."\n\n".
 115      T_('Base URL').': '.$baseurl."\n\n".
 116      T_('Admin email').': '.$admin_email.
 117      '</pre>';
 118      block_close();
 119  }
 120  
 121  
 122  /**
 123   * Install new DB.
 124   */
 125  function install_newdb()
 126  {
 127      global $new_db_version, $admin_url, $random_password;
 128  
 129      /*
 130       * -----------------------------------------------------------------------------------
 131       * NEW DB: Create a plain new db structure + sample contents
 132       * -----------------------------------------------------------------------------------
 133       */
 134      require_once dirname(__FILE__).'/_functions_create.php';
 135  
 136      if( $old_db_version = get_db_version() )
 137      {
 138          echo '<p><strong>'.T_('OOPS! It seems b2evolution is already installed!').'</strong></p>';
 139  
 140          if( $old_db_version < $new_db_version )
 141          {
 142              echo '<p>'.sprintf( T_('Would you like to <a %s>upgrade your existing installation now</a>?'), 'href="?action=evoupgrade"' ).'</p>';
 143          }
 144  
 145          return;
 146      }
 147  
 148      $installer_version = param( 'installer_version', 'integer', 0 );
 149      if( $installer_version >= 10 )
 150      {
 151          $create_sample_contents = param( 'create_sample_contents', 'integer', 0 );
 152      }
 153      else
 154      {    // OLD INSTALLER call. Probably an automated script calling.
 155          // Let's force the sample contents since they haven't been explicitly disabled
 156          $create_sample_contents = 1;
 157      }
 158  
 159      /**
 160       * 1 - If current installation is local, test or intranet
 161       *     Used to turn off gravatar and all ping plugins
 162       *
 163       * @var integer
 164       */
 165      $local_installation = param( 'local_installation', 'integer', 0 );
 166  
 167      echo '<h2>'.T_('Creating b2evolution tables...').'</h2>';
 168      evo_flush();
 169      create_tables();
 170  
 171      echo '<h2>'.T_('Creating minimum default data...').'</h2>';
 172      evo_flush();
 173      create_default_data();
 174  
 175      if( $create_sample_contents )
 176      {
 177          global $Settings, $test_install_all_features;
 178  
 179          echo '<h2>'.T_('Installing sample contents...').'</h2>';
 180          evo_flush();
 181  
 182          // We're gonna need some environment in order to create the demo contents...
 183          load_class( 'settings/model/_generalsettings.class.php', 'GeneralSettings' );
 184          load_class( 'users/model/_usersettings.class.php', 'UserSettings' );
 185          /**
 186           * @var GeneralSettings
 187           */
 188          $Settings = new GeneralSettings();
 189  
 190          if( $test_install_all_features )
 191          {    // Set manual ordering of categories
 192              $Settings->set( 'chapter_ordering', 'manual' );
 193              $Settings->dbupdate();
 194          }
 195  
 196          /**
 197           * @var UserCache
 198           */
 199          $UserCache = & get_UserCache();
 200          // Create $current_User object.
 201          // (Assigning by reference does not work with "global" keyword (PHP 5.2.8))
 202          $GLOBALS['current_User'] = & $UserCache->get_by_ID( 1 );
 203  
 204          create_demo_contents();
 205      }
 206  
 207      track_step( 'install-success' );
 208      echo '<h2>'.T_('Installation successful!').'</h2>';
 209  
 210      echo '<p><strong>';
 211      printf( T_('Now you can <a %s>log in</a> with the following credentials:'), 'href="'.$admin_url.'"' );
 212      echo '</strong></p>';
 213  
 214      echo '<table>';
 215      echo '<tr><td>', T_( 'Login' ), ': &nbsp;</td><td><strong><evo:password>admin</evo:password></strong></td></tr>';
 216      printf( '<tr><td>%s: &nbsp;</td><td><strong><evo:password>%s</evo:password></strong></td></tr>', T_( 'Password' ), $random_password );
 217      echo '</table>';
 218  
 219      echo '<p>'.T_('Note that password carefully! It is a <em>random</em> password that is given to you when you install b2evolution. If you lose it, you will have to delete the database tables and re-install anew.').'</p>';
 220  }
 221  
 222  
 223  /**
 224   * Begin install task.
 225   * This will offer other display methods in the future
 226   */
 227  function task_begin( $title )
 228  {
 229      echo $title."\n";
 230      evo_flush();
 231  }
 232  
 233  
 234  /**
 235   * End install task.
 236   * This will offer other display methods in the future
 237   */
 238  function task_end()
 239  {
 240      echo "OK.<br />\n";
 241  }
 242  
 243  
 244  function get_db_version()
 245  {
 246      global $DB;
 247  
 248      $DB->save_error_state();
 249      $DB->halt_on_error = false;
 250      $DB->show_errors = false;
 251      $DB->log_errors = false;
 252  
 253      $r = NULL;
 254  
 255      if( db_col_exists( 'T_settings', 'set_name' ) )
 256      { // we have new table format (since 0.9)
 257          $r = $DB->get_var( 'SELECT set_value FROM T_settings WHERE set_name = "db_version"' );
 258      }
 259      else
 260      {
 261          $r = $DB->get_var( 'SELECT db_version FROM T_settings' );
 262      }
 263  
 264      $DB->restore_error_state();
 265  
 266      return $r;
 267  }
 268  
 269  
 270  /**
 271   * Get default locale from db
 272   */
 273  function get_default_locale_from_db()
 274  {
 275      global $DB;
 276  
 277      if( empty( $DB ) )
 278      { // DB doesn't exists yet
 279          return NULL;
 280      }
 281  
 282      $DB->save_error_state();
 283      $DB->halt_on_error = false;
 284      $DB->show_errors = false;
 285      $DB->log_errors = false;
 286  
 287      $r = NULL;
 288  
 289      if( db_col_exists( 'T_settings', 'set_name' ) )
 290      {
 291          $r = $DB->get_var( 'SELECT set_value FROM T_settings WHERE set_name = "default_locale"' );
 292      }
 293  
 294      $DB->restore_error_state();
 295  
 296      return $r;
 297  }
 298  
 299  
 300  /**
 301   * @return boolean Does a given column name exist in DB?
 302   */
 303  function db_col_exists( $table, $col_name )
 304  {
 305      global $DB;
 306  
 307      $col_name = strtolower($col_name);
 308  
 309      $r = false;
 310      $DB->save_error_state();
 311      foreach( $DB->get_results('SHOW COLUMNS FROM '.$table) as $row )
 312      {
 313          if( strtolower($row->Field) == $col_name )
 314          {
 315              $r = true;
 316              break;
 317          }
 318      }
 319      $DB->restore_error_state();
 320  
 321      return $r;
 322  }
 323  
 324  
 325  /**
 326   * Clean up extra quotes in comments
 327   */
 328  function cleanup_comment_quotes()
 329  {
 330      global $DB;
 331  
 332      task_begin( 'Checking for extra quote escaping in comments... ' );
 333      $query = "SELECT comment_ID, comment_content
 334                              FROM T_comments
 335                           WHERE comment_content LIKE '%\\\\\\\\\'%'
 336                                   OR comment_content LIKE '%\\\\\\\\\"%' ";
 337      /* FP: the above looks overkill, but MySQL is really full of surprises...
 338                      tested on 4.0.14-nt */
 339      // echo $query;
 340      $rows = $DB->get_results( $query, ARRAY_A );
 341      if( $DB->num_rows )
 342      {
 343          echo 'Updating '.$DB->num_rows.' comments... ';
 344          foreach( $rows as $row )
 345          {
 346              $query = "UPDATE T_comments
 347                                  SET comment_content = ".$DB->quote( stripslashes( $row['comment_content'] ) )."
 348                                  WHERE comment_ID = ".$row['comment_ID'];
 349              // echo '<br />'.$query;
 350              $DB->query( $query );
 351          }
 352      }
 353      task_end();
 354  
 355  }
 356  
 357  
 358  /**
 359   * Validate install requirements.
 360   *
 361   * @return array List of errors, empty array if ok.
 362   */
 363  function install_validate_requirements()
 364  {
 365      $errors = array();
 366  
 367      return $errors;
 368  }
 369  
 370  
 371  /**
 372   * Insert default locales into T_locales.
 373   */
 374  function create_default_locales()
 375  {
 376      task_begin( 'Activating default locales... ' );
 377      locale_insert_default();
 378      task_end();
 379  }
 380  
 381  
 382  /**
 383   * Insert default settings into T_settings.
 384   *
 385   * It only writes those to DB, that get overridden (passed as array), or have
 386   * no default in {@link _generalsettings.class.php} / {@link GeneralSettings::default}.
 387   *
 388   * @param array associative array (settings name => value to use), allows
 389   *              overriding of defaults
 390   */
 391  function create_default_settings( $override = array() )
 392  {
 393      global $DB, $new_db_version, $default_locale;
 394      global $Group_Admins, $Group_Privileged, $Group_Bloggers, $Group_Users, $Group_Suspect, $Group_Spam;
 395      global $test_install_all_features, $local_installation;
 396  
 397      $defaults = array(
 398          'db_version' => $new_db_version,
 399          'default_locale' => $default_locale,
 400          'newusers_grp_ID' => $Group_Users->ID,
 401          'default_blog_ID' => 1,
 402          'evocache_foldername' => '_evocache',
 403      );
 404      if( $test_install_all_features )
 405      {
 406          $defaults['gender_colored'] = 1;
 407          $defaults['newusers_canregister'] = 1;
 408          $defaults['registration_require_country'] = 1;
 409          $defaults['registration_require_gender'] = 'required';
 410          $defaults['location_country'] = 'required';
 411          $defaults['location_region'] = 'required';
 412          $defaults['location_subregion'] = 'required';
 413          $defaults['location_city'] = 'required';
 414      }
 415      if( !empty( $Group_Suspect ) )
 416      { // Set default antispam suspicious group
 417          $defaults['antispam_suspicious_group'] = $Group_Suspect->ID;
 418      }
 419      $antispam_trust_groups = array();
 420      if( !empty( $Group_Admins ) )
 421      {
 422          $antispam_trust_groups[] = $Group_Admins->ID;
 423      }
 424      if( !empty( $Group_Privileged ) )
 425      {
 426          $antispam_trust_groups[] = $Group_Privileged->ID;
 427      }
 428      if( !empty( $Group_Bloggers ) )
 429      {
 430          $antispam_trust_groups[] = $Group_Bloggers->ID;
 431      }
 432      if( !empty( $Group_Spam ) )
 433      {
 434          $antispam_trust_groups[] = $Group_Spam->ID;
 435      }
 436      if( count( $antispam_trust_groups ) > 0 )
 437      { // Set default antispam trust group
 438          $defaults['antispam_trust_groups'] = implode( ',', $antispam_trust_groups );
 439      }
 440      if( $local_installation )
 441      { // Current installation is local
 442          // Turn off gravatar and use 'Default gravatars' = 'Gravatar'
 443          $defaults['use_gravatar'] = 0;
 444          $defaults['default_gravatar'] = '';
 445      }
 446  
 447      $settings = array_merge( array_keys($defaults), array_keys($override) );
 448      $settings = array_unique( $settings );
 449      $insertvalues = array();
 450      foreach( $settings as $name )
 451      {
 452          if( isset($override[$name]) )
 453          {
 454              $insertvalues[] = '('.$DB->quote($name).', '.$DB->quote($override[$name]).')';
 455          }
 456          else
 457          {
 458              $insertvalues[] = '('.$DB->quote($name).', '.$DB->quote($defaults[$name]).')';
 459          }
 460      }
 461  
 462      task_begin( 'Creating default settings'.( count($override) ? ' (with '.count($override).' existing values)' : '' ).'... ' );
 463      $DB->query(
 464          "INSERT INTO T_settings (set_name, set_value)
 465          VALUES ".implode( ', ', $insertvalues ) );
 466      task_end();
 467  }
 468  
 469  
 470  /**
 471   * Install basic skins.
 472   */
 473  function install_basic_skins( $install_mobile_skins = true )
 474  {
 475      load_funcs( 'skins/_skin.funcs.php' );
 476  
 477      task_begin( 'Installing default skins... ' );
 478  
 479      // Note: Skin #1 will we used by Blog A
 480      skin_install( 'evopress' );
 481  
 482      // Note: Skin #2 will we used by Blog B
 483      skin_install( 'evocamp' );
 484  
 485      // Note: Skin #3 will we used by Linkblog
 486      skin_install( 'miami_blue' );
 487  
 488      // Note: Skin #4 will we used by Photoblog
 489      skin_install( 'photoblog' );
 490  
 491      // Note: Skin #5 will we used by Forums
 492      skin_install( 'forums' );
 493  
 494      // Note: Skin #6 will we used by Manual
 495      skin_install( 'manual' );
 496  
 497      skin_install( 'asevo' );
 498      skin_install( 'custom' );
 499      skin_install( 'dating_mood' );
 500      skin_install( 'glossyblue' );
 501      skin_install( 'intense' );
 502      skin_install( 'natural_pink' );
 503      skin_install( 'nifty_corners' );
 504      skin_install( 'pixelgreen' );
 505      skin_install( 'pluralism' );
 506      skin_install( 'terrafirma' );
 507      if( $install_mobile_skins )
 508      {
 509          skin_install( 'touch' );
 510      }
 511      skin_install( 'vastitude' );
 512      skin_install( '_atom' );
 513      skin_install( '_rss2' );
 514  
 515      task_end();
 516  }
 517  
 518  
 519  /**
 520   * Install basic plugins.
 521   *
 522   * This gets called separately on fresh installs.
 523   *
 524   * {@internal
 525   * NOTE: this won't call the "AfterInstall" method on the plugin nor install its DB schema.
 526   *       This get done in the plugins controller, on manually installing a plugin.
 527   *
 528   * If you change the plugins here, please also adjust {@link InstallUnitTestCase::basic_plugins}.
 529   * }}
 530   *
 531   * @param integer Old DB version, so that only new plugins gets installed
 532   */
 533  function install_basic_plugins( $old_db_version = 0 )
 534  {
 535      /**
 536       * @var Plugins_admin
 537       */
 538      global $Plugins_admin, $test_install_all_features;
 539  
 540      $Plugins_admin = & get_Plugins_admin();
 541  
 542      // Create global $Plugins instance, which is required during installation of basic plugins,
 543      // not only for the ones getting installed, but also during e.g. count_regs(), which instantiates
 544      // each plugin (which may then use (User)Settings in PluginInit (through Plugin::__get)).
 545      $GLOBALS['Plugins'] = & $Plugins_admin;
 546  
 547      if( $old_db_version < 9100 )
 548      {
 549          // Toolbars:
 550          install_plugin( 'quicktags_plugin' );
 551          // Renderers:
 552          install_plugin( 'auto_p_plugin' );
 553          install_plugin( 'autolinks_plugin' );
 554          install_plugin( 'texturize_plugin' );
 555  
 556          // SkinTags:
 557          install_plugin( 'calendar_plugin' );
 558          install_plugin( 'archives_plugin' );
 559      }
 560  
 561      if( $old_db_version < 9290 )
 562      {
 563          install_plugin( 'smilies_plugin' );
 564          install_plugin( 'videoplug_plugin' );
 565      }
 566  
 567      if( $old_db_version < 9330 )
 568      { // Upgrade to 1.9-beta
 569          install_plugin( 'ping_b2evonet_plugin' );
 570          install_plugin( 'ping_pingomatic_plugin' );
 571      }
 572  
 573      if( $old_db_version < 9930 )
 574      { // Upgrade to 3.1.0
 575          install_plugin( 'tinymce_plugin' );
 576      }
 577  
 578      if( $old_db_version < 9940 )
 579      { // Upgrade to 3.2.0
 580          install_plugin( 'twitter_plugin' );
 581      }
 582  
 583      if( $old_db_version < 10300 )
 584      { // Upgrade to 5.0.0
 585          install_plugin( 'flowplayer_plugin' );
 586  
 587          if( $test_install_all_features )
 588          {
 589              install_plugin( 'google_maps_plugin' );
 590          }
 591      }
 592  
 593      if( $old_db_version < 11000 )
 594      { // Upgrade to 5.0.0-alpha-4
 595          install_plugin( 'captcha_qstn_plugin' );
 596      }
 597  
 598      if( $old_db_version < 11100 )
 599      { // Upgrade to 5.0.1-alpha-5
 600          if( $test_install_all_features )
 601          {
 602              install_plugin( 'bbcode_plugin' );
 603              install_plugin( 'star_plugin' );
 604              install_plugin( 'code_highlight_plugin' );
 605          }
 606      }
 607  }
 608  
 609  
 610  /**
 611   * @return true on success
 612   */
 613  function install_plugin( $plugin )
 614  {
 615      /**
 616       * @var Plugins_admin
 617       */
 618      global $Plugins_admin;
 619  
 620      task_begin( 'Installing plugin: '.$plugin.'... ' );
 621      $edit_Plugin = & $Plugins_admin->install( $plugin, 'broken' ); // "broken" by default, gets adjusted later
 622      if( ! is_a( $edit_Plugin, 'Plugin' ) )
 623      {
 624          echo $edit_Plugin."<br />\n";
 625          return false;
 626      }
 627  
 628      load_funcs('plugins/_plugin.funcs.php');
 629      install_plugin_db_schema_action( $edit_Plugin, true );
 630  
 631      // Try to enable plugin:
 632      $enable_return = $edit_Plugin->BeforeEnable();
 633      if( $enable_return !== true )
 634      {
 635          $Plugins_admin->set_Plugin_status( $edit_Plugin, 'disabled' ); // does not unregister it
 636          echo $enable_return."<br />\n";
 637          return false;
 638      }
 639  
 640      $Plugins_admin->set_Plugin_status( $edit_Plugin, 'enabled' );
 641  
 642      task_end();
 643      return true;
 644  }
 645  
 646  
 647  /**
 648   * Install basic widgets.
 649   */
 650  function install_basic_widgets( $old_db_version = 0 )
 651  {
 652      /**
 653      * @var DB
 654      */
 655      global $DB;
 656  
 657      load_funcs( 'widgets/_widgets.funcs.php' );
 658  
 659      if( $old_db_version < 11010 )
 660      {
 661          $blog_ids = $DB->get_assoc( 'SELECT blog_ID, "std" FROM T_blogs' );
 662      }
 663      else
 664      {
 665          $blog_ids = $DB->get_assoc( 'SELECT blog_ID, blog_type FROM T_blogs' );
 666      }
 667  
 668      foreach( $blog_ids as $blog_id => $blog_type )
 669      {
 670          task_begin( 'Installing default widgets for blog #'.$blog_id.'... ' );
 671          insert_basic_widgets( $blog_id, true, $blog_type );
 672          task_end();
 673      }
 674  
 675  }
 676  
 677  
 678  
 679  function advanced_properties()
 680  {
 681      /*
 682  // file_path needs to be case sensitive on unix
 683  // Note: it should be ok on windows too if we take care of updating the db on case renames
 684  ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL
 685  or
 686  ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
 687      */
 688  }
 689  
 690  
 691  /**
 692   * Create relations
 693   *
 694   * @todo NOT UP TO DATE AT ALL :( -- update field names before activating this
 695   */
 696  function create_relations()
 697  {
 698      global $DB;
 699  
 700      task_begin( 'Creating relations... ' );
 701  
 702      $DB->query( 'alter table T_coll_user_perms
 703                                  add constraint FK_bloguser_blog_ID
 704                                              foreign key (bloguser_blog_ID)
 705                                              references T_blogs (blog_ID)
 706                                              on delete restrict
 707                                              on update restrict' );
 708  
 709      $DB->query( 'alter table T_coll_user_perms
 710                                  add constraint FK_bloguser_user_ID
 711                                              foreign key (bloguser_user_ID)
 712                                              references T_users (user_ID)
 713                                              on delete restrict
 714                                              on update restrict' );
 715  
 716      $DB->query( 'alter table T_categories
 717                                  add constraint FK_cat_blog_ID
 718                                              foreign key (cat_blog_ID)
 719                                              references T_blogs (blog_ID)
 720                                              on delete restrict
 721                                              on update restrict,
 722                                  add constraint FK_cat_parent_ID
 723                                              foreign key (cat_parent_ID)
 724                                              references T_categories (cat_ID)
 725                                              on delete restrict
 726                                              on update restrict' );
 727  
 728      $DB->query( 'alter table T_comments
 729                                  add constraint FK_comment_post_ID
 730                                              foreign key (comment_post_ID)
 731                                              references T_items__item (post_ID)
 732                                              on delete restrict
 733                                              on update restrict' );
 734  
 735      $DB->query( 'alter table T_postcats
 736                                  add constraint FK_postcat_cat_ID
 737                                              foreign key (postcat_cat_ID)
 738                                              references T_categories (cat_ID)
 739                                              on delete restrict
 740                                              on update restrict,
 741                                  add constraint FK_postcat_post_ID
 742                                              foreign key (postcat_post_ID)
 743                                              references T_items__item (post_ID)
 744                                              on delete restrict
 745                                              on update restrict' );
 746  
 747      $DB->query( 'alter table T_items__item
 748                                  add constraint FK_post_assigned_user_ID
 749                                              foreign key (post_assigned_user_ID)
 750                                              references T_users (user_ID)
 751                                              on delete restrict
 752                                              on update restrict,
 753                                  add constraint FK_post_lastedit_user_ID
 754                                              foreign key (post_lastedit_user_ID)
 755                                              references T_users (user_ID)
 756                                              on delete restrict
 757                                              on update restrict,
 758                                  add constraint FK_post_creator_user_ID
 759                                              foreign key (post_creator_user_ID)
 760                                              references T_users (user_ID)
 761                                              on delete restrict
 762                                              on update restrict,
 763                                  add constraint FK_post_main_cat_ID
 764                                              foreign key (post_main_cat_ID)
 765                                              references T_categories (cat_ID)
 766                                              on delete restrict
 767                                              on update restrict,
 768                                  add constraint FK_post_parent_ID
 769                                              foreign key (post_parent_ID)
 770                                              references T_items__item (post_ID)
 771                                              on delete restrict
 772                                              on update restrict,
 773                                  add constraint FK_post_pst_ID
 774                                              foreign key (post_pst_ID)
 775                                              references T_items__status (pst_ID)
 776                                              on delete restrict
 777                                              on update restrict,
 778                                  add constraint FK_post_ptyp_ID
 779                                              foreign key (post_ptyp_ID)
 780                                              references T_items__type (ptyp_ID)
 781                                              on delete restrict
 782                                              on update restrict' );
 783  
 784      $DB->query( 'alter table T_links
 785                                  add constraint FK_link_creator_user_ID
 786                                              foreign key (link_creator_user_ID)
 787                                              references T_users (user_ID)
 788                                              on delete restrict
 789                                              on update restrict' );
 790      $DB->query( 'alter table T_links
 791                                  add constraint FK_link_lastedit_user_ID
 792                                              foreign key (link_lastedit_user_ID)
 793                                              references T_users (user_ID)
 794                                              on delete restrict
 795                                              on update restrict' );
 796      $DB->query( 'alter table T_links
 797                                  add constraint FK_link_dest_itm_ID
 798                                              foreign key (link_dest_itm_ID)
 799                                              references T_items__item (post_ID)
 800                                              on delete restrict
 801                                              on update restrict' );
 802      $DB->query( 'alter table T_links
 803                                  add constraint FK_link_file_ID
 804                                              foreign key (link_file_ID)
 805                                              references T_files (file_ID)
 806                                              on delete restrict
 807                                              on update restrict' );
 808      $DB->query( 'alter table T_links
 809                                  add constraint FK_link_itm_ID
 810                                              foreign key (link_itm_ID)
 811                                              references T_items__item (post_ID)
 812                                              on delete restrict
 813                                              on update restrict' );
 814  
 815      $DB->query( 'alter table T_pluginsettings
 816                    add constraint FK_pset_plug_ID
 817                          foreign key (pset_plug_ID)
 818                          references T_plugins (plug_ID)
 819                          on delete restrict
 820                          on update restrict' );
 821  
 822      $DB->query( 'alter table T_pluginusersettings
 823                    add constraint FK_puset_plug_ID
 824                          foreign key (puset_plug_ID)
 825                          references T_plugins (plug_ID)
 826                          on delete restrict
 827                          on update restrict' );
 828  
 829      $DB->query( 'alter table T_pluginevents
 830                    add constraint FK_pevt_plug_ID
 831                          foreign key (pevt_plug_ID)
 832                          references T_plugins (plug_ID)
 833                          on delete restrict
 834                          on update restrict' );
 835  
 836      $DB->query( 'alter table T_users
 837                                  add constraint FK_user_grp_ID
 838                                              foreign key (user_grp_ID)
 839                                              references T_groups (grp_ID)
 840                                              on delete restrict
 841                                              on update restrict' );
 842  
 843      $DB->query( 'alter table T_users__usersettings
 844                                  add constraint FK_uset_user_ID
 845                                              foreign key (uset_user_ID)
 846                                              references T_users (user_ID)
 847                                              on delete restrict
 848                                              on update restrict' );
 849  
 850      $DB->query( 'alter table T_subscriptions
 851                                  add constraint FK_sub_coll_ID
 852                                              foreign key (sub_coll_ID)
 853                                              references T_blogs (blog_ID)
 854                                              on delete restrict
 855                                              on update restrict' );
 856  
 857      $DB->query( 'alter table T_subscriptions
 858                                  add constraint FK_sub_user_ID
 859                                              foreign key (sub_user_ID)
 860                                              references T_users (user_ID)
 861                                              on delete restrict
 862                                              on update restrict' );
 863  
 864      $DB->query( 'alter table T_slug
 865                                  add constraint FK_slug_itm_ID
 866                                              foreign key (slug_itm_ID)
 867                                              references T_items__item (post_ID)
 868                                              on delete restrict
 869                                              on update restrict' );
 870  
 871      task_end();
 872  }
 873  
 874  
 875  /**
 876   * Loads the b2evo database scheme.
 877   *
 878   * This gets updated through {@link db_delta()} which generates the queries needed to get
 879   * to this scheme.
 880   *
 881   * Please see {@link db_delta()} for things to take care of.
 882   */
 883  function load_db_schema()
 884  {
 885      global $schema_queries;
 886      global $modules, $inc_path;
 887  
 888      global $db_storage_charset, $DB;
 889      if( empty($db_storage_charset) )
 890      {    // If no specific charset has been requested for datstorage, use the one of the current connection (optimize for speed - no conversions)
 891          $db_storage_charset = $DB->connection_charset;
 892      }
 893      //pre_dump( 'db_storage_charset', $db_storage_charset );
 894  
 895      // Load modules:
 896      foreach( $modules as $module )
 897      {
 898          echo 'Loading module: '.$module.'/model/_'.$module.'.install.php<br />';
 899          require_once $inc_path.$module.'/model/_'.$module.'.install.php';
 900      }
 901  
 902  }
 903  
 904  
 905  /**
 906   * Install htaccess: Check if it works with the webserver, then install it for real.
 907   *
 908   * @return boolean TRUE if no errors
 909   */
 910  function install_htaccess( $upgrade = false )
 911  {
 912      echo '<p>Preparing to install .htaccess ... ';
 913  
 914      $server = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
 915      if( !empty($server) && preg_match('~(Nginx|Lighttpd|Microsoft-IIS)~i', $server) )
 916      {    // Skip installation if this is not an Apache server
 917          echo '<br /><b>.htaccess is not needed (not an Apache server)</b></p>';
 918          return true;
 919      }
 920  
 921      $error_message = do_install_htaccess( $upgrade );
 922  
 923      if( $error_message )
 924      {
 925          $htignore = param( 'htignore', 'integer', 0 );
 926  
 927          echo 'ERROR!<br/><b>'.$error_message.'</b>';
 928  
 929          if( $htignore )
 930          {    // Ignore errors with .htaccess file
 931              return true;
 932          }
 933          else
 934          {    // Some errors are existing with .htaccess file, Display a link to ignore the errors and continue instalation
 935              echo '<p style="text-align:center;font-size:150%;font-weight:bold;margin-top:10px"><a href="'.$_SERVER['REQUEST_URI'].'&htignore=1">'.T_('Continue installation &raquo;').'</a></p>';
 936              return false;
 937          }
 938      }
 939      echo '</p>';
 940  
 941      return true;
 942  }
 943  
 944  /**
 945   * This does the actual file manipulations for installing .htaccess
 946   * This will verify that the provided sample.htaccess does not crash apache in a test folder before installing it for real.
 947   *
 948   * @param boolean are we upgrading (vs installing)?
 949   * @return mixed
 950   */
 951  function do_install_htaccess( $upgrade = false )
 952  {
 953      global $baseurl;
 954      global $basepath;
 955  
 956      if( @file_exists($basepath.'.htaccess') )
 957      {
 958          if( $upgrade )
 959          {
 960              echo T_('Already installed.');
 961              return ''; // all is well :)
 962          }
 963  
 964          if( @file_exists( $basepath.'sample.htaccess' ) )
 965          {
 966              $content_htaccess = trim( file_get_contents( $basepath.'.htaccess' ) );
 967              $content_sample_htaccess = trim( file_get_contents( $basepath.'sample.htaccess' ) );
 968  
 969              if( $content_htaccess != $content_sample_htaccess )
 970              {    // The .htaccess file has content that different from a sample file
 971                  $error_message = '<p class="red">'.T_('There is already a file called .htaccess at the blog root. If you don\'t specifically need this file, it is recommended that you delete it or rename it to old.htaccess before you continue. This will allow b2evolution to create a new .htaccess file that is optimized for best results.').'</p>';
 972                  $error_message .= T_('Here are the contents of the current .htaccess file:');
 973                  $error_message .= '<div style="overflow:auto"><pre>'.htmlspecialchars( $content_htaccess ).'</pre></div><br />';
 974                  $error_message .= sprintf( T_('Again, we recommend you remove this file before continuing. If you chose to keep it, b2evolution will probably still work, but for optimization you should follow <a %s>these instructions</a>.'), 'href="http://b2evolution.net/man/htaccess-file" target="_blank"');
 975                  return $error_message;
 976              }
 977              else
 978              {
 979                  echo T_('Already installed.');
 980                  return '';
 981              }
 982          }
 983      }
 984  
 985      // Make sure we have a sample file to start with:
 986      if( ! @file_exists( $basepath.'sample.htaccess' ) )
 987      {
 988          return 'Cannot find file [ sample.htaccess ] in your base url folder.';
 989      }
 990  
 991      // Try to copy that file to the test folder:
 992      if( ! @copy( $basepath.'sample.htaccess', $basepath.'install/test/.htaccess' ) )
 993      {
 994          return 'Failed to copy files!';
 995      }
 996  
 997      // Make sure .htaccess does not crash in the test folder:
 998      load_funcs('_core/_url.funcs.php');
 999      $info = array();
1000      if( ! $remote_page = fetch_remote_page( $baseurl.'install/test/', $info ) )
1001      {
1002          return $info['error'];
1003      }
1004      if( substr( $remote_page, 0, 16 ) != 'Test successful.' )
1005      {
1006          return 'install/test/index.html was not found as expected.';
1007      }
1008  
1009      // Now we consider it's safe, copy .htaccess to its real location:
1010      if( ! @copy( $basepath.'sample.htaccess', $basepath.'.htaccess' ) )
1011      {
1012          return 'Test was successful, but failed to copy .htaccess into baseurl directory!';
1013      }
1014  
1015      echo 'Install successful.';
1016      return '';
1017  }
1018  
1019  
1020  /**
1021   * Return antispam SQL query.
1022   * This is obfuscated because some hosting companies prevent uploading PHP files
1023   * containing "spam" strings.
1024   *
1025   * @return string;
1026   */
1027  function get_antispam_query()
1028  {
1029      //used base64_encode() for getting this code
1030      $r = base64_decode('SU5TRVJUIElOVE8gVF9hbnRpc3BhbShhc3BtX3N0cmluZykgVkFMVUVTICgnb25saW5lLWNhc2lubycpLCAoJ3BlbmlzLWVubGFyZ2VtZW50JyksICgnb3JkZXItdmlhZ3JhJyksICgnb3JkZXItcGhlbnRlcm1pbmUnKSwgKCdvcmRlci14ZW5pY2FsJyksICgnb3JkZXItcHJvcGhlY2lhJyksICgnc2V4eS1saW5nZXJpZScpLCAoJy1wb3JuLScpLCAoJy1hZHVsdC0nKSwgKCctdGl0cy0nKSwgKCdidXktcGhlbnRlcm1pbmUnKSwgKCdvcmRlci1jaGVhcC1waWxscycpLCAoJ2J1eS14ZW5hZHJpbmUnKSwgKCdwYXJpcy1oaWx0b24nKSwgKCdwYXJpc2hpbHRvbicpLCAoJ2NhbWdpcmxzJyksICgnYWR1bHQtbW9kZWxzJyk=');
1031      // pre_dump($r);
1032      return $r;
1033  }
1034  
1035  /**
1036   * We use the following tracking to determine the installer reliability (% of failed vs successful installs).
1037   */
1038  function track_step( $current_step )
1039  {
1040      // echo 'Tracking '.$current_step;
1041      echo '<img src="http://b2evolution.net/htsrv/track.php?key='.$current_step.'" alt="" />';
1042  }
1043  
1044  
1045  
1046  ?>

title

Description

title

Description

title

Description

title

title

Body