<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[GlotPress][953] trunk: Complete overhaul of the installation process.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://glotpress.trac.wordpress.org/changeset/953">953</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2014-09-02 13:56:23 +0000 (Tue, 02 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Complete overhaul of the installation process. You can now fill in your username, password and email address.
Props Secretmapper
Fixes <a href="http://glotpress.trac.wordpress.org/ticket/280">#280</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesassetsloaderphp">trunk/gp-includes/assets-loader.php</a></li>
<li><a href="#trunkgpincludesinstallupgradephp">trunk/gp-includes/install-upgrade.php</a></li>
<li><a href="#trunkgpincludesurlphp">trunk/gp-includes/url.php</a></li>
<li><a href="#trunkgptemplatesinstallphp">trunk/gp-templates/install.php</a></li>
<li><a href="#trunkinstallphp">trunk/install.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesassetsloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/assets-loader.php (952 => 953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/assets-loader.php 2014-09-02 12:32:02 UTC (rev 952)
+++ trunk/gp-includes/assets-loader.php 2014-09-02 13:56:23 UTC (rev 953)
</span><span class="lines">@@ -11,6 +11,7 @@
</span><span class="cx"> $styles->text_direction = 'ltr';
</span><span class="cx">
</span><span class="cx"> $styles->add( 'base', '/style.css', array(), '20140224' );
</span><ins>+ $styles->add( 'install', '/install.css', array('base'), '20140902' );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> add_action( 'wp_default_styles', 'gp_styles_default' );
</span></span></pre></div>
<a id="trunkgpincludesinstallupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/install-upgrade.php (952 => 953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/install-upgrade.php 2014-09-02 12:32:02 UTC (rev 952)
+++ trunk/gp-includes/install-upgrade.php 2014-09-02 13:56:23 UTC (rev 953)
</span><span class="lines">@@ -1,26 +1,5 @@
</span><span class="cx"> <?php
</span><del>-/**
- * Guesses the final installed URI based on the location of the install script
- *
- * @return string The guessed URI
- */
-function guess_uri()
-{
- $schema = 'http://';
- if ( strtolower( gp_array_get( $_SERVER, 'HTTPS' ) ) == 'on' ) {
- $schema = 'https://';
- }
</del><span class="cx">
</span><del>- if( gp_array_get( $_SERVER, 'DOCUMENT_URI' ) ) {
- $uri = preg_replace( '|/[^/]*$|i', '/', $schema . gp_array_get( $_SERVER, 'HTTP_HOST') . gp_array_get( $_SERVER, 'DOCUMENT_URI' ) );
- }
- else {
- $uri = $schema . gp_array_get( $_SERVER, 'HTTP_HOST');
- }
-
- return rtrim( $uri, " \t\n\r\0\x0B/" ) . '/';
-}
-
</del><span class="cx"> function gp_update_db_version() {
</span><span class="cx"> gp_update_option( 'gp_db_version', gp_get_option( 'gp_db_version' ) );
</span><span class="cx"> }
</span><span class="lines">@@ -83,7 +62,7 @@
</span><span class="cx"> * @return string Rewrite rules
</span><span class="cx"> */
</span><span class="cx"> function gp_mod_rewrite_rules() {
</span><del>- $path = gp_add_slash( gp_url_path() );
</del><ins>+ $path = gp_add_slash( gp_url_path( guess_uri() ) );
</ins><span class="cx">
</span><span class="cx"> return '
</span><span class="cx"> # BEGIN GlotPress
</span><span class="lines">@@ -116,18 +95,17 @@
</span><span class="cx"> gp_update_option( 'uri', guess_uri() );
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function gp_create_initial_contents() {
</del><ins>+function gp_create_initial_contents( $user_name = null, $admin_password = null, $admin_email = null ) {
</ins><span class="cx"> global $gpdb;
</span><del>- $gpdb->insert( $gpdb->projects, array('name' => __('Sample'), 'slug' => __('sample'), 'description' => __('A Sample Project'), 'path' => __('sample') ) );
- $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' ) );
- $gpdb->insert( $gpdb->originals, array('project_id' => 1, 'singular' => __('A GlotPress'), 'plural' => __('Many GlotPresses') ) );
</del><span class="cx">
</span><ins>+ $gpdb->insert( $gpdb->projects, array( 'name' => __('Sample'), 'slug' => __('sample'), 'description' => __('A Sample Project'), 'path' => __('sample') ) );
+ $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' ) );
+ $gpdb->insert( $gpdb->originals, array( 'project_id' => 1, 'singular' => __('A GlotPress'), 'plural' => __('Many GlotPresses') ) );
+
</ins><span class="cx"> $gpdb->insert( $gpdb->translation_sets, array( 'name' => __('My Translation'), 'slug' => __('my'), 'project_id' => 1, 'locale' => 'bg', ) );
</span><span class="cx">
</span><del>- // TODO: ask the user for an e-mail -- borrow WordPress install process
- if ( !defined('CUSTOM_USER_TABLE') ) {
- $admin = GP::$user->create( array( 'user_login' => 'admin', 'user_pass' => 'a', 'user_email' => 'baba@baba.net' ) );
</del><ins>+ if ( isset( $user_name, $admin_password, $admin_email ) ) {
+ $admin = GP::$user->create( array( 'user_login' => $user_name, 'user_pass' => $admin_password, 'user_email' => $admin_email ) );
</ins><span class="cx"> GP::$permission->create( array( 'user_id' => $admin->id, 'action' => 'admin' ) );
</span><span class="cx"> }
</span><del>- // TODO: ask the user to choose an admin user if using custom table
</del><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkgpincludesurlphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/url.php (952 => 953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/url.php 2014-09-02 12:32:02 UTC (rev 952)
+++ trunk/gp-includes/url.php 2014-09-02 13:56:23 UTC (rev 953)
</span><span class="lines">@@ -72,7 +72,8 @@
</span><span class="cx">
</span><span class="cx"> function gp_url_base_root() {
</span><span class="cx"> $url_from_db = gp_get_option( 'url' );
</span><del>- return gp_const_get( 'GP_BASE_URL', $url_from_db? $url_from_db : '' );
</del><ins>+
+ return gp_const_get( 'GP_BASE_URL', $url_from_db ? $url_from_db : guess_uri() );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function gp_url_public_root() {
</span><span class="lines">@@ -80,6 +81,28 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Guesses the final installed URI based on the location of the install script
+ *
+ * @return string The guessed URI
+ */
+function guess_uri()
+{
+ $schema = 'http://';
+ if ( strtolower( gp_array_get( $_SERVER, 'HTTPS' ) ) == 'on' ) {
+ $schema = 'https://';
+ }
+
+ if( gp_array_get( $_SERVER, 'DOCUMENT_URI' ) ) {
+ $uri = preg_replace( '|/[^/]*$|i', '/', $schema . gp_array_get( $_SERVER, 'HTTP_HOST') . gp_array_get( $_SERVER, 'DOCUMENT_URI' ) );
+ }
+ else {
+ $uri = $schema . gp_array_get( $_SERVER, 'HTTP_HOST');
+ }
+
+ return rtrim( $uri, " \t\n\r\0\x0B/" ) . '/';
+}
+
+/**
</ins><span class="cx"> * Constructs URL for a project and locale.
</span><span class="cx"> * /<project-path>/<locale>/<path>/<page>
</span><span class="cx"> */
</span></span></pre></div>
<a id="trunkgptemplatesinstallphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-templates/install.php (952 => 953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-templates/install.php 2014-09-02 12:32:02 UTC (rev 952)
+++ trunk/gp-templates/install.php 2014-09-02 13:56:23 UTC (rev 953)
</span><span class="lines">@@ -1,21 +1,23 @@
</span><span class="cx"> <?php
</span><span class="cx"> gp_title( __('Install < GlotPress') );
</span><span class="cx"> gp_breadcrumb( array(
</span><del>- 'install' == $action? __('Install') : __('Upgrade'),
</del><ins>+ 'upgrade' == $action? __('Upgrade') : __('Install'),
</ins><span class="cx"> ) );
</span><del>-
</del><ins>+wp_enqueue_style( 'install' );
</ins><span class="cx"> gp_tmpl_header();
</span><span class="cx"> ?>
</span><span class="cx">
</span><del>-<?php if ($errors): ?>
- <?php _e('There were some errors:'); ?>
- <pre>
- <?php echo implode("\n", $errors); ?>
- </pre>
</del><span class="cx"> <?php
</span><del>- else:
</del><ins>+if ( isset( $errors ) ) {
+ _e('There were some errors:');
+
+ echo '<pre class="message">';
+ echo implode( "\n", $errors );
+ echo '</pre>';
+}
+else if ( isset( $success_message ) ) {
</ins><span class="cx"> echo $success_message;
</span><del>- endif;
</del><ins>+}
</ins><span class="cx"> ?>
</span><span class="cx">
</span><span class="cx"> <?php
</span><span class="lines">@@ -25,9 +27,38 @@
</span><span class="cx"> <?php _e( 'If your <code>.htaccess</code> file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file.' ); ?>
</span><span class="cx">
</span><span class="cx"> <pre><?php echo esc_html( gp_mod_rewrite_rules() ); ?></pre>
</span><del>-
- <?php _e( '<strong>The default username is <code>admin</code>, whose password is simply <code>a</code>.</strong>' ); ?>
</del><span class="cx"> </p>
</span><span class="cx"> <?php endif; ?>
</span><span class="cx">
</span><ins>+<?php if ( $action == 'install' ): ?>
+ <form id="setup" method="post" action="install.php">
+ <table class="form-table">
+ <tr>
+ <th scope="row"><label for="user_login"><?php _e('Username'); ?></label></th>
+ <td>
+ <input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
+ <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.' ); ?></p>
+ </td>
+ </tr>
+ <tr>
+ <th scope="row">
+ <label for="admin_password"><?php _e('Password, twice'); ?></label>
+ <p><?php _e('A password will be automatically generated for you if you leave this blank.'); ?></p>
+ </th>
+ <td>
+ <input name="admin_password" type="password" id="pass1" size="25" value="" />
+ <input name="admin_password2" type="password" id="pass2" size="25" value="" />
+ <p><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'); ?></p>
+ </td>
+ </tr>
+ <tr>
+ <th scope="row"><label for="admin_email"><?php _e( 'Email Address' ); ?></label></th>
+ <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
+ <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
+ </tr>
+ </table>
+ <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install Glotpress' ); ?>" /></p>
+ </form>
+<?php endif; ?>
+
</ins><span class="cx"> <?php gp_tmpl_footer();
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkinstallphp"></a>
<div class="modfile"><h4>Modified: trunk/install.php (952 => 953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/install.php 2014-09-02 12:32:02 UTC (rev 952)
+++ trunk/install.php 2014-09-02 13:56:23 UTC (rev 953)
</span><span class="lines">@@ -14,24 +14,65 @@
</span><span class="cx">
</span><span class="cx"> if ( gp_get_option( 'gp_db_version' ) <= gp_get_option_from_db( 'gp_db_version' ) && ! isset( $_GET['force'] ) ) {
</span><span class="cx"> $success_message = __( 'You already have the latest version, no need to upgrade!' );
</span><del>- $errors = array();
</del><span class="cx"> }
</span><del>-else {
- if ( gp_is_installed() ) {
- $success_message = __( 'GlotPress was successully upgraded!' );
- $errors = gp_upgrade();
</del><ins>+else if ( gp_is_installed() ) {
+ $success_message = __( 'GlotPress was successully upgraded!' );
+ $errors = gp_upgrade();
+
+ $show_htaccess_instructions = ! gp_set_htaccess() && empty( $errors );
+}
+else if ( defined('CUSTOM_USER_TABLE') ) {
+ $errors = gp_install();
+
+ $success_message = __( 'GlotPress was successully installed!' );
+
+ if ( ! $errors ) {
+ gp_create_initial_contents();
</ins><span class="cx"> }
</span><del>- else {
- $success_message = __( 'GlotPress was successully installed!' );
</del><ins>+
+ $show_htaccess_instructions = ! gp_set_htaccess() && empty( $errors );
+ $action = 'installed';
+}
+else if( isset( $_POST['user_name'], $_POST['user_name'], $_POST['admin_password'], $_POST['admin_password2'], $_POST['admin_email'] ) ) {
+ $user_name = trim( stripslashes_deep( $_POST['user_name'] ) );
+ $admin_password = stripslashes_deep( $_POST['admin_password'] );
+ $admin_password_check = stripslashes_deep( $_POST['admin_password2'] );
+ $admin_email = trim( stripslashes_deep( $_POST['admin_email'] ) );
+
+ $errors = array();
+
+ if ( empty( $user_name ) ) {
+ $errors[] = __( 'Please provide a valid username.' );
+ } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
+ $errors[] = __( 'The username you provided has invalid characters.' );
+ } elseif ( empty( $admin_password ) ) {
+ $errors[] = __( 'Please specify a password.' );
+ } elseif ( $admin_password != $admin_password_check ) {
+ $errors[] = __( 'Your passwords do not match. Please try again.' );
+ } else if ( empty( $admin_email ) ) {
+ $errors[] = __( 'You must provide an email address.' );
+ } elseif ( ! is_email( $admin_email ) ) {
+ $errors[] = __( 'You have an invalid email Address.' );
+ }
+
+ if( ! $errors ) {
</ins><span class="cx"> $errors = gp_install();
</span><del>- $action = 'install';
</del><span class="cx">
</span><ins>+ $success_message = __( 'GlotPress was successully installed!' );
+
</ins><span class="cx"> if ( ! $errors ) {
</span><del>- gp_create_initial_contents();
</del><ins>+ gp_create_initial_contents( $user_name, $admin_password, $admin_email );
</ins><span class="cx"> }
</span><ins>+
+ $show_htaccess_instructions = ! gp_set_htaccess() && empty( $errors );
+ $action = 'installed';
+ } else {
+ $action = 'install';
</ins><span class="cx"> }
</span><del>-
- $show_htaccess_instructions = ! gp_set_htaccess() && empty( $errors );
</del><span class="cx"> }
</span><ins>+else {
+ $action = 'install';
+ $user_name = $admin_email = '';
+}
</ins><span class="cx">
</span><span class="cx"> gp_tmpl_load( 'install', get_defined_vars() );
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>