Skip to content

Commit

Permalink
Merge pull request #132 from transifex/devel
Browse files Browse the repository at this point in the history
1.2.4 release
  • Loading branch information
Matthew Jackowski committed Mar 17, 2016
2 parents be33ac3 + 0963903 commit 7195fb5
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 134 deletions.
47 changes: 42 additions & 5 deletions includes/admin/transifex-live-integration-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ static function load_rewrite_options() {
return array_merge( Transifex_Live_Integration_Defaults::options_values(), $db_opt_settings );
}

static function load_transifex_settings() {

$db_settings = get_option( 'transifex_live_transifex_settings', array() );
if ( !$db_settings ) {

$db_settings = Transifex_Live_Integration_Defaults::transifex_settings();
}
Plugin_Debug::logTrace( array_merge( Transifex_Live_Integration_Defaults::transifex_settings(), $db_settings ) );
return array_merge( Transifex_Live_Integration_Defaults::transifex_settings(), $db_settings );
}

static function options_page() {

$settings = self::load_settings();
Expand All @@ -40,6 +51,19 @@ static function options_page() {
array_push( $rewrite_options_array, $arr );
}

$transifex_settings = self::load_transifex_settings();
$transifex_settings_settings = $transifex_settings['settings'];
/* $transifex_settings_array = [ ];
$transifex_settings_settings = '';
foreach ($transifex_settings as $key => $value) {
$arr = [ ];
$arr['value'] = $value;
$arr['id'] = 'transifex_live_transifex_settings_' . $key;
$arr['name'] = 'transifex_live_transifex_settings[' . $key . ']';
array_push( $transifex_settings_array, $arr );
}
*/
Plugin_Debug::logTrace( $settings['language_map'] );
ob_start();
checked( $settings['rewrite_option_all'], 1 );
$checked_rewrite_option_all = ob_get_clean();
Expand Down Expand Up @@ -109,14 +133,20 @@ public function admin_init_hook() {
static public function update_settings( $settings ) {
Plugin_Debug::logTrace();

if ( isset( $settings['transifex_live_transifex_settings']['settings'] ) ) {
$p = json_decode( $settings['transifex_live_transifex_settings']['settings'], true )['production']['picker'];
$settings['transifex_live_settings']['enable_picker'] = ($p !== 'no-picker') ? true : false;
}

$transifex_languages = json_decode( stripslashes( $settings['transifex_live_settings']['transifex_languages'] ), true );
$tokenized_url = Transifex_Live_Integration_Settings_Util::generate_tokenized_url( site_url(), $settings['transifex_live_settings']['url_options'] );
$settings['transifex_live_settings']['tokenized_url'] = $tokenized_url;

$languages_map = $settings['transifex_live_settings']['language_map'];
$languages_map_string = $languages_map; // TODO: Switch to wp_json_encode.


$languages_map = (array) json_decode( stripslashes( $languages_map ), true );
Plugin_Debug::logTrace( $transifex_languages );
Plugin_Debug::logTrace( $languages_map );
$trim = false;

$languages = '';
Expand All @@ -128,8 +158,7 @@ static public function update_settings( $settings ) {
$languages_regex .= $languages_map[0][$lang];
$languages_regex .= "|";
}
Plugin_Debug::logTrace( $languages );
Plugin_Debug::logTrace( $languages_regex );

$languages = ($trim) ? rtrim( $languages, ',' ) : '';
$languages_regex = ($trim) ? rtrim( $languages_regex, '|' ) : '';
$languages_regex = '(' . $languages_regex . ')';
Expand All @@ -143,8 +172,8 @@ static public function update_settings( $settings ) {
$subdomain_pattern = implode( '/', $array_url );
}


$settings['transifex_live_settings']['subdomain_pattern'] = $subdomain_pattern;
$settings['transifex_live_settings']['language_map'] = $languages_map_string;
$settings['transifex_live_settings']['languages_regex'] = $languages_regex;
$settings['transifex_live_settings']['languages'] = $languages;
if ( isset( $settings['transifex_live_settings'] ) ) {
Expand All @@ -155,6 +184,11 @@ static public function update_settings( $settings ) {
Plugin_Debug::logTrace( $settings['transifex_live_options'] );
update_option( 'transifex_live_options', $settings['transifex_live_options'] );
}

if ( isset( $settings['transifex_live_transifex_settings'] ) ) {
Plugin_Debug::logTrace( $settings['transifex_live_transifex_settings'] );
update_option( 'transifex_live_transifex_settings', $settings['transifex_live_transifex_settings'] );
}
}

/**
Expand Down Expand Up @@ -207,6 +241,9 @@ static public function sanitize_settings( $settings ) {
$settings['transifex_live_settings']['languages_regex'] = ( isset( $settings['transifex_live_settings']['languages_regex'] )) ? sanitize_text_field( $settings['transifex_live_settings']['languages_regex'] ) : '';
$settings['transifex_live_settings']['transifex_languages'] = ( isset( $settings['transifex_live_settings']['transifex_languages'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_settings']['transifex_languages'] ) ) : '';
$settings['transifex_live_settings']['subdomain_pattern'] = ( isset( $settings['transifex_live_settings']['language_map'] )) ? sanitize_text_field( $settings['transifex_live_settings']['language_map'] ) : '';


$settings['transifex_live_transifex_settings']['settings'] = ( isset( $settings['transifex_live_transifex_settings']['settings'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_transifex_settings']['settings'] ) ) : '';
return $settings;
}

Expand Down
29 changes: 19 additions & 10 deletions includes/admin/transifex-live-integration-settings-template.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="wrap transifex-live-settings">
<h2><?php _e( 'Transifex Live Translation Plugin Settings', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?></h2>

<form id="settings_form" method="post" enctype="multipart/form-data">
<form id="transifex_live_settings_form" method="post" enctype="multipart/form-data">
<?php wp_nonce_field( 'transifex_live_settings', 'transifex_live_nonce' ); ?>
<p><?php _e( 'Translate your WordPress site without complexities.', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?></p>
<p><?php _e( 'Before using this plugin, be sure you have a Transifex Live API key. ' ); ?>&nbsp;<a target="_blank" href="<?php echo $settings['urls']['api_key_landing_page']; ?>"><?php _e( 'Click here to sign up and get an API key.' ) ?></a>
Expand All @@ -15,7 +15,12 @@
<input type="hidden" value="<?php echo $settings['api_key']; ?>" name="transifex_live_settings[previous_api_key]" id="transifex_live_settings_raw_transifex_previous_api_key" />
<input type="button" disabled="true" name="check" id="transifex_live_settings_api_key_button" class="button button-primary" value="Check">
</p>
<p id="transifex_live_settings_api_key_message">&nbsp;</p>
<p id="transifex_live_settings_api_key_message">
<span id="transifex_live_settings_api_key_message_validating" class="hide-if-js">Validating your key!</span>
<span id="transifex_live_settings_api_key_message_valid" class="hide-if-js">Success! Advanced SEO settings enabled.</span>
<span id="transifex_live_settings_api_key_message_error" class="hide-if-js">Oops! Please make sure you’ve entered a valid API key.</span>
<span id="transifex_live_settings_api_key_message_missing" class="hide-if-js">D’oh! No languages have been published from Transifex Live yet.</span>
</p>
</td>
</tr>
<tr valign="top">
Expand All @@ -42,16 +47,18 @@
<br/>
<input type="hidden" value="<?php echo $source_language ?>" name="transifex_live_settings[source_language]" id="transifex_live_settings_source_language" />
<p id="transifex_live_languages">
<table id="language_map_table"><tr><th scope="row">Language</th><th scope="row">Code</th></tr>
<tr id="language_map_template" style="display:none">
<table id="transifex_live_language_map_table"><tr><th scope="row">Language</th><th scope="row">Code</th></tr>
<tr id="transifex_live_language_map_template" style="display:none">
<td style="padding:0px"><span class="tx-language"></span></td>
<td style="padding:0px"><input class="tx-code" type="text" style="width:100px"></td>
</tr>
</table>
<span id="transifex_live_languages_message">Your languages can't be loaded. Please re-check your API key.</span>
<span id="transifex_live_languages_message" class="hide-if-js">Your languages can't be loaded. Please re-check your API key.</span>
<span id="transifex_live_sync_message" class="hide-if-js">Refreshing languages will replace your current codes with those from Transifex Live. Continue?</span>
</p>
<p class="submit"><input type="button" name="sync" id="sync" class="button button-primary" value="Refresh Languages List"></p>
<p class="description" id="tagline-description">Tweak your localized urls.</p>

<p class="submit"><input type="button" name="sync" id="transifex_live_sync" class="button button-primary" value="Refresh Languages List"></p>
<p class="description" id="transifex_live_tagline-description">Tweak your localized urls.</p>
</td>
</tr>
<tr class="url-structure-subdirectory">
Expand All @@ -70,16 +77,18 @@
</td></tr>
</tbody>
</table>
<?php /* Transifex_Live_Integration_Settings_Util::render_transifex_settings( $transifex_settings_array ); */ ?>
<input name="transifex_live_settings[enable_custom_urls]" id="transifex_live_settings_custom_urls" type="hidden" value="<?php echo $checked_custom_urls ?>" >
<input type="hidden" value="<?php echo htmlentities( stripslashes( $language_map ) ) ?>" name="transifex_live_settings[language_map]" id="transifex_live_settings_language_map" />
<input type="hidden" value="<?php echo htmlentities( stripslashes( $transifex_settings_settings ) ) ?>" name="transifex_live_transifex_settings[settings]" id="transifex_live_transifex_settings_settings" />
<input type="hidden" value="<?php echo htmlentities( $settings['subdomain_pattern'] ) ?>" name="transifex_live_settings[subdomain_pattern]" id="transifex_live_settings_subdomain_pattern" />
<input type="hidden" value="<?php echo htmlentities( stripslashes( $languages_regex ) ) ?>" name="transifex_live_settings[languages_regex]" id="transifex_live_settings_languages_regex" />
<input type="hidden" value="<?php echo htmlentities( stripslashes( $languages ) ) ?>" name="transifex_live_settings[transifex_languages]" id="transifex_live_settings_transifex_languages" />
<input type="hidden" value="<?php echo htmlentities( stripslashes( $language_lookup ) ) ?>" name="transifex_live_settings[language_lookup]" id="transifex_live_settings_language_lookup" />
<input type="hidden" value="<?php echo htmlentities( stripslashes( $language_map ) ) ?>" name="transifex_live_settings[language_map]" id="transifex_live_settings_language_map" />
<p class="submit"><input disabled="true" type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?>"></p>
<p class="submit"><input disabled="true" type="submit" name="submit" id="transifex_live_submit" class="button button-primary" value="<?php _e( 'Save Changes', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?>"></p>
</form>
<p>
<a href="http://docs.transifex.com/integrations/wordpress/" target="_blank" ><?php _e( 'Plugin documentation', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?></a> | <?php _e( 'Thank you for using Transifex!', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?>
<a href="http://docs.transifex.com/integrations/wordpress/" target="_blank" ><?php _e( 'Plugin documentation', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?></a> | <?php _e( 'Thank you for using Transifex!', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ); ?>
</a>
</p>
</div>
54 changes: 54 additions & 0 deletions includes/admin/transifex-live-integration-settings-util.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@

class Transifex_Live_Integration_Settings_Util {

static function wp_before_admin_bar_render_hook() {
Plugin_Debug::logTrace();
echo ('<div class="notranslate">');
}

static function wp_after_admin_bar_render_hook() {
Plugin_Debug::logTrace();
echo ('</div>');
}

static function generate_tokenized_url( $site_url, $url_option_setting ) {
Plugin_Debug::logTrace();
$tokenized_url = false;

if ( $url_option_setting !== '2' && $url_option_setting != '3' ) {
Plugin_Debug::logTrace( 'No URL option, skipping tokenization' );
return false;
}

if ( !($site_url) ) {
Plugin_Debug::logTrace( 'Failed site URL truthiness, skipping tokenization' );
return false;
}

$slashes = [ ];
$slashes = explode( "/", $site_url );
if ( $url_option_setting === '3' ) { // Subdirectory option
array_push( $slashes, '%lang%' );
array_push( $slashes, '' );
}
if ( $url_option_setting === '2' ) { // Subdomain option
$dots = explode( ".", $slashes[2] );
$dots[0] = '%lang%';
$slashes[2] = implode( '.', $dots );
array_push( $slashes, '' );
}
$tokenized_url = implode( '/', $slashes );

return $tokenized_url;
}

static function render_url_options( $options ) {
$html = '';
$row = '';
Expand All @@ -25,4 +66,17 @@ static function render_url_options( $options ) {
echo $html;
}

static function render_transifex_settings( $settings ) {
$html = '';
foreach ($settings as $setting) {
$text = $setting['value'];
$id = $setting['id'];
$name = $setting['name'];
$html .= <<<HTML
<input type="hidden" value="$value" name="$name" id="$id" />
HTML;
}
echo $html;
}

}
2 changes: 1 addition & 1 deletion includes/plugin-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function logError( $severity, $message, $filename, $lineno ) {

public function printLog() {
if ( self::$debug_mode ) {
echo ('<div id="miw_debug" class="transparent" style="width:90%;margin: 1em auto;padding: 10px 160px;text-align: left;z-index: 999;">' . "\n");
echo ('<div id="miw_debug" class="transparent notranslate" style="width:90%;margin: 1em auto;padding: 10px 160px;text-align: left;z-index: 999;">' . "\n");
echo ('<h3>Plugin: Plugin Debug Mode Output</h3>' . "\n");
array_walk( self::$calls, array( 'Plugin_Debug', 'printLogCallback' ) );
echo "</div>";
Expand Down
75 changes: 42 additions & 33 deletions includes/transifex-live-integration-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,78 @@
*/
class Transifex_Live_Integration_Defaults {


static function options_values() {
Plugin_Debug::logTrace();
return [
'add_rewrites_post' => 0,
'add_rewrites_page' => 0,
'add_rewrites_author' => 0,
'add_rewrites_date' => 0,
'add_rewrites_tag' => 0,
'add_rewrites_category' => 0,
'add_rewrites_search' => 0,
'add_rewrites_root' => 0,
'add_rewrites_reverse_template_links' => 0,
'add_rewrites_permalink_tag' => 0
];
'add_rewrites_post' => 0,
'add_rewrites_page' => 0,
'add_rewrites_author' => 0,
'add_rewrites_date' => 0,
'add_rewrites_tag' => 0,
'add_rewrites_category' => 0,
'add_rewrites_search' => 0,
'add_rewrites_root' => 0,
'add_rewrites_reverse_template_links' => 0,
'add_rewrites_permalink_tag' => 0
];
}

static function get_options_text($key) {
Plugin_Debug::logTrace();

static function get_options_text( $key ) {
$arr = [
'add_rewrites_post' => 'Posts',
'add_rewrites_page' => 'Pages',
'add_rewrites_author' => 'Authors',
'add_rewrites_date' => 'Date',
'add_rewrites_tag' => 'Tags',
'add_rewrites_category' => 'Categories',
'add_rewrites_search' => 'Search',
'add_rewrites_root' => 'Root',
'add_rewrites_reverse_template_links' => 'Reverse Template Links',
'add_rewrites_permalink_tag' => 'Permalink Tag'
];
return $arr[$key];

'add_rewrites_post' => 'Posts',
'add_rewrites_page' => 'Pages',
'add_rewrites_author' => 'Authors',
'add_rewrites_date' => 'Date',
'add_rewrites_tag' => 'Tags',
'add_rewrites_category' => 'Categories',
'add_rewrites_search' => 'Search',
'add_rewrites_root' => 'Root',
'add_rewrites_reverse_template_links' => 'Reverse Template Links',
'add_rewrites_permalink_tag' => 'Permalink Tag'
];
return $arr[$key];
}

static function transifex_settings() {
return [
'settings' => null,
'picker' => 'no-picker',
'domain' => 'wpliveplugin.onpressidium.com',
'ignore_tags' => [ ],
'autocollect' => false,
'parse_attr' => [ ],
'dynamic' => false,
'detectlang' => false,
'ignore_class' => [ ]
];
}

/**
* Static function for settings defaults
* @return array Returns the settings array
*/
static function settings() {
Plugin_Debug::logTrace();
return array(
'api_key' => null, // This is the only required field and needs to be copied from Live
'previous_api_key' => null,
'raw_transifex_languages' => null,
'transifex_languages' => null,
'language_lookup' => null,
'language_map' => null,
'language_map' => '[]',
'languages_regex' => null,
'rewrite_option_all' => 0,

'enable_custom_urls' => 0,
'urls' => [
'rate_us' => 'https://wordpress.org/support/view/plugin-reviews/transifex-live-integration?rate=5#postform',
'api_key_landing_page' => 'https://www.transifex.com/signup/?utm_source=liveplugin',
],
'enable_language_urls' => false,
'enable_picker' => false,
'add_language_rewrites' => 'none selected',
'source_language' => '',
'languages' => '',
'hreflang' => false,
'url_options' => 1,
'subdomain_pattern' => ''

);
}

Expand Down
Loading

0 comments on commit 7195fb5

Please sign in to comment.