Permalink
Browse files

GlotPress as a WordPress plugin, first pass.

This initial pass switches from using the BackPress external to a WordPress install via `require 'wp-load.php';`. This took about 2 hours. With some additional work, it can be pivoted fully to a plugin. This would result in the deletion of additional code (more than has already been deleted here), given that WordPress can handle authentication, users, etc., most initialization that's currently happening in both gp-settings.php and wp-load.php, and such.

I don't see a need to abandon GlotPress's routes, things, or templates in any kind of switch to WP_Rewrite, custom post types, or a theme. That it "just works" by swapping out some files is pretty killer in and of itself. It will make it easier for people to contribute, work with it, and such.

There are surely some little issues that will be caught in a second pass. As I said, this was done in just two hours (and yes, I got it fully working locally in that time). As an example todo: we need to merge some POMO changes to upstream WordPress; some hook names like `plugins_loaded` also clash.

As for performance: locally, I was seeing 3 MB (GlotPress standalone) vs 6 MB (GlotPress with WordPress). That's peanuts and is well worth bringing GlotPress into the comfort zone that is WordPress. Additionally, this will provide significant benefits for feature development and general integration between GlotPress and WordPress.
  • Loading branch information...
nacin committed Jun 28, 2015
1 parent 1d96f2f commit d9d47271c6ce0c8e3d927088853ac47c1d100561
Showing with 306 additions and 2,200 deletions.
  1. +12 −22 gp-includes/assets-loader.php
  2. +0 −46 gp-includes/class.bp-options.php
  3. +4 −57 gp-includes/install-upgrade.php
  4. +0 −127 gp-includes/l10n.php
  5. +4 −14 gp-includes/meta.php
  6. +27 −0 gp-includes/misc.php
  7. +0 −2 gp-includes/routes/login.php
  8. +118 −189 gp-includes/schema.php
  9. +0 −26 gp-includes/system.php
  10. +0 −8 gp-includes/template.php
  11. +16 −4 gp-includes/thing.php
  12. +1 −0 gp-includes/things/glossary-entry.php
  13. +1 −1 gp-includes/things/glossary.php
  14. +1 −0 gp-includes/things/original.php
  15. +1 −1 gp-includes/things/permission.php
  16. +2 −2 gp-includes/things/project.php
  17. +1 −0 gp-includes/things/translation-set.php
  18. +4 −3 gp-includes/things/translation.php
  19. +28 −30 gp-includes/things/user.php
  20. +14 −202 gp-settings.php
  21. +1 −2 gp-templates/glossary-view.php
  22. +1 −1 gp-templates/locales.php
  23. +1 −1 gp-templates/project.php
  24. +2 −2 gp-templates/translations.php
  25. +1 −1 install.php
  26. +0 −6 js/jquery/jquery-ui.js
  27. +0 −5 js/jquery/jquery.js
  28. +22 −0 phpunit.xml.dist
  29. +0 −78 pomo/entry.php
  30. +0 −261 pomo/mo.php
  31. +0 −416 pomo/po.php
  32. +0 −209 pomo/streams.php
  33. +0 −275 pomo/translations.php
  34. +0 −26 t/all.php
  35. +16 −9 t/lib/bootstrap.php
  36. +1 −1 t/lib/factory.php
  37. +5 −80 t/lib/testcase.php
  38. +0 −23 t/phpunit.xml.dist
  39. 0 {pomo/sample → t/pomo-sample}/app.php
  40. 0 {pomo/sample → t/pomo-sample}/languages/app-side.pot
  41. 0 {pomo/sample → t/pomo-sample}/languages/app.pot
  42. BIN {pomo/sample → t/pomo-sample}/languages/bg-side.mo
  43. 0 {pomo/sample → t/pomo-sample}/languages/bg-side.po
  44. BIN {pomo/sample → t/pomo-sample}/languages/bg.mo
  45. 0 {pomo/sample → t/pomo-sample}/languages/bg.po
  46. +3 −3 t/tests/test_format_android.php
  47. +3 −3 t/tests/test_format_resx.php
  48. +3 −3 t/tests/test_format_strings.php
  49. +6 −6 t/tests/test_mo.php
  50. +3 −4 t/tests/test_permissions.php
  51. +3 −3 t/tests/test_po.php
  52. +1 −3 t/tests/tests_things/test_thing_translation_set.php
  53. +0 −45 t/unittests-config-sample.php
@@ -4,36 +4,26 @@
*/
function gp_styles_default( &$styles ) {
$styles->base_url = gp_url_base( 'css' );
$styles->default_version = gp_get_option( 'version' );
// TODO: get text direction for current locale
//$styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr';
$styles->text_direction = 'ltr';
$styles->add( 'base', '/style.css', array(), '20141019' );
$styles->add( 'install', '/install.css', array('base'), '20140902' );
$url = gp_url_public_root() . 'css';
$styles->add( 'base', $url . '/style.css', array(), '20141019' );
$styles->add( 'install', $url . '/install.css', array('base'), '20140902' );
}
add_action( 'wp_default_styles', 'gp_styles_default' );
function gp_scripts_default( &$scripts ) {
$scripts->base_url = gp_url_base( 'js' );
$scripts->default_version = gp_get_option( 'version' );
$url = gp_url_public_root() . 'js';
$bump = '20150430';
$scripts->add( 'jquery', '/jquery/jquery.js', array(), '1.11' );
$scripts->add( 'jquery-ui', '/jquery/jquery-ui.js', array('jquery'), '1.10.4' );
$scripts->add( 'jquery-ui-autocomplete', null, array('jquery-ui'), '1.10.4' );
$scripts->add( 'jquery-ui-selectable', null, array('jquery-ui'), '1.10.4' );
$scripts->add( 'jquery-ui-tabs', null, array('jquery-ui'), '1.10.4' );
$scripts->add( 'tablesorter', '/jquery.tablesorter.min.js', array('jquery'), '1.10.4' );
$scripts->add( 'common', '/common.js', array( 'jquery' ), $bump );
$scripts->add( 'editor', '/editor.js', array( 'common' ), $bump );
$scripts->add( 'glossary', '/glossary.js', array( 'common' ), $bump );
$scripts->add( 'translations-page', '/translations-page.js', array( 'common' ), $bump );
$scripts->add( 'mass-create-sets-page', '/mass-create-sets-page.js', array( 'common' ), $bump );
$scripts->add( 'tablesorter', $url . '/jquery.tablesorter.min.js', array('jquery'), '1.10.4' );
$scripts->add( 'gp-common', $url . '/common.js', array( 'jquery' ), $bump );
$scripts->add( 'gp-editor', $url . '/editor.js', array( 'gp-common', 'jquery-ui-tooltip' ), $bump );
$scripts->add( 'gp-glossary', $url . '/glossary.js', array( 'gp-common' ), $bump );
$scripts->add( 'translations-page', $url . '/translations-page.js', array( 'gp-common' ), $bump );
$scripts->add( 'mass-create-sets-page', $url . '/mass-create-sets-page.js', array( 'gp-common' ), $bump );
}
add_action( 'wp_default_scripts', 'gp_scripts_default' );

This file was deleted.

Oops, something went wrong.
@@ -7,12 +7,14 @@ function gp_update_db_version() {
function gp_upgrade_db() {
global $gpdb;
$alterations = BP_SQL_Schema_Parser::delta( $gpdb, gp_schema_get() );
$errors = $alterations['errors'];
dbDelta( implode( "\n", gp_schema_get() ) );
/*
Haha you really think dbDelta gives you errors?
if ( $errors ) {
return $errors;
}
*/
gp_upgrade_data( gp_get_option_from_db( 'gp_db_version' ) );
@@ -23,61 +25,6 @@ function gp_upgrade() {
return gp_upgrade_db();
}
/**
* Sets the rewrite rules
*
* @return bool Returns true on success and false on failure
*/
function gp_set_htaccess() {
// The server doesn't support mod rewrite
if ( ! apache_mod_loaded( 'mod_rewrite', true ) ) {
//return false;
}
if ( file_exists( '.htaccess' ) && ! is_writeable( '.htaccess' ) ) {
return false;
}
// check if the .htaccess is in place or try to write it
$htaccess_file = @fopen( '.htaccess', 'c+' );
//error opening htaccess, inform user!
if ( false === $htaccess_file ) {
return false;
}
//'# BEGIN GlotPress' not found, write the access rules
if ( false === strpos( stream_get_contents( $htaccess_file ), '# BEGIN GlotPress' ) ) {
fwrite( $htaccess_file, gp_mod_rewrite_rules() );
}
fclose( $htaccess_file );
return true;
}
/**
* Return the rewrite rules
*
* @return string Rewrite rules
*/
function gp_mod_rewrite_rules() {
$path = gp_add_slash( gp_url_path( guess_uri() ) );
return '
# BEGIN GlotPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase ' . $path . '
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ' . $path . 'index.php [L]
</IfModule>
# END GlotPress';
}
function gp_upgrade_data( $db_version ) {
global $gpdb;
if ( $db_version < 190 ) {

This file was deleted.

Oops, something went wrong.
@@ -52,13 +52,7 @@ function gp_update_meta( $object_id = 0, $meta_key, $meta_value, $type, $global
$object_type = 'gp_option';
break;
case 'user' :
global $wp_users_object;
$id = $object_id;
$return = $wp_users_object->update_meta( compact( 'id', 'meta_key', 'meta_value' ) );
if ( is_wp_error( $return ) ) {
return false;
}
return $return;
return update_user_meta( $object_id, $meta_key, $meta_value );
default :
$object_type = $type;
break;
@@ -108,9 +102,7 @@ function gp_delete_meta( $object_id = 0, $meta_key, $meta_value, $type, $global
$object_type = 'gp_option';
break;
case 'user':
global $wp_users_object;
$id = $object_id;
return $wp_users_object->update_meta( compact( 'id', 'meta_key', 'meta_value' ) );
return delete_user_meta( $object_id, $meta_key, $meta_value );
default:
$object_type = $type;
break;
@@ -154,10 +146,8 @@ function gp_delete_meta( $object_id = 0, $meta_key, $meta_value, $type, $global
function gp_append_meta( $object, $type )
{
global $gpdb;
switch ( $type ) {
case 'user':
global $wp_users_object;
return $wp_users_object->append_meta( $object );
if ( 'user' === $type ) {
return $object;
}
if ( is_array( $object ) && $object ) {
@@ -466,3 +466,30 @@ function gp_is_between( $value, $start, $end ) {
function gp_is_between_exclusive( $value, $start, $end ) {
return $value > $start && $value < $end;
}
/**
* Acts the same as core PHP setcookie() but its arguments are run through the backpress_set_cookie filter.
*
* If the filter returns false, setcookie() isn't called.
*/
function backpress_set_cookie() {
$args = func_get_args();
$args = apply_filters( 'backpress_set_cookie', $args );
if ( $args === false ) return;
call_user_func_array( 'setcookie', $args );
}
function backpress_gmt_strtotime( $string ) {
if ( is_numeric($string) )
return $string;
if ( !is_string($string) )
return -1;
if ( stristr($string, 'utc') || stristr($string, 'gmt') || stristr($string, '+0000') )
return strtotime($string);
if ( -1 == $time = strtotime($string . ' +0000') )
return strtotime($string);
return $time;
}
@@ -9,8 +9,6 @@ function login_get() {
}
function login_post() {
global $wp_users_object, $wp_auth_object;
$user = GP::$user->by_login( $_POST['user_login'] );
if ( !$user || is_wp_error($user) ) {
Oops, something went wrong.

0 comments on commit d9d4727

Please sign in to comment.