[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> install-upgrade.php (source)

   1  <?php
   2  /**
   3   * Guesses the final installed URI based on the location of the install script
   4   *
   5   * @return string The guessed URI
   6   */
   7  function guess_uri()
   8  {
   9      $schema = 'http://';
  10      if ( strtolower( gp_array_get( $_SERVER, 'HTTPS' ) ) == 'on' ) {
  11          $schema = 'https://';
  12      }
  13      $uri = preg_replace( '|/[^/]*$|i', '/', $schema . gp_array_get( $_SERVER, 'HTTP_HOST') . gp_array_get( $_SERVER, 'REQUEST_URI' ) );
  14  
  15      return rtrim( $uri, " \t\n\r\0\x0B/" ) . '/';
  16  }
  17  
  18  function gp_update_db_version() {
  19      gp_update_option( 'gp_db_version', gp_get_option( 'gp_db_version' ) );
  20  }
  21  
  22  function gp_upgrade_db() {
  23      global $gpdb;
  24  
  25      $alterations = BP_SQL_Schema_Parser::delta( $gpdb, gp_schema_get() );
  26      $messages = $alterations['messages'];
  27      $errors = $alterations['errors'];
  28      if ( $errors ) return $errors;
  29  
  30      gp_upgrade_data( gp_get_option_from_db( 'gp_db_version' ) );
  31  
  32      gp_update_db_version();
  33  }
  34  
  35  function gp_upgrade() {
  36      return gp_upgrade_db();
  37  }
  38  
  39  function gp_upgrade_data( $db_version ) {
  40      global $gpdb;
  41      if ( $db_version < 190 ) {
  42          $gpdb->query("UPDATE $gpdb->translations SET status = REPLACE(REPLACE(status, '-', ''), '+', '');");
  43      }
  44  }
  45  
  46  function gp_install() {
  47      global $gpdb;
  48  
  49      $errors = gp_upgrade_db();
  50  
  51      if ( $errors ) return $errors;
  52  
  53      gp_update_option( 'uri', guess_uri() );
  54  }
  55  
  56  function gp_create_initial_contents() {
  57      global $gpdb;
  58      $gpdb->insert( $gpdb->projects, array('name' => __('Sample'), 'slug' => __('sample'), 'description' => __('A Sample Project'), 'path' => __('sample') ) );
  59      $gpdb->insert( $gpdb->originals, array('project_id' => 1, 'singular' => __('GlotPress FTW'), 'comment' => __('FTW means For The Win'), 'context' => 'dashboard', 'references' => 'bigfile:666 little-dir/small-file.php:71' ) );
  60      $gpdb->insert( $gpdb->originals, array('project_id' => 1, 'singular' => __('A GlotPress'), 'plural' => __('Many GlotPresses') ) );
  61  
  62      $gpdb->insert( $gpdb->translation_sets, array( 'name' => __('My Translation'), 'slug' => __('my'), 'project_id' => 1, 'locale' => 'bg', ) );
  63  
  64      // TODO: ask the user for an e-mail -- borrow WordPress install process
  65      if ( !defined('CUSTOM_USER_TABLE') ) {
  66          $admin = GP::$user->create( array( 'user_login' => 'admin', 'user_pass' => 'a', 'user_email' => 'baba@baba.net' ) );
  67          GP::$permission->create( array( 'user_id' => $admin->id, 'action' => 'admin' ) );
  68      }
  69      // TODO: ask the user to choose an admin user if using custom table
  70  }


Generated: Sat May 25 03:59:55 2013 Hosted by follow the white rabbit.