Skip to content

Commit

Permalink
Merge pull request #115 from matthewjackowski/mjjacko-devel
Browse files Browse the repository at this point in the history
cleaning up codebase
  • Loading branch information
Matthew Jackowski committed Feb 25, 2016
2 parents 8ebf55f + fb1ee0c commit be33ac3
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 79 deletions.
11 changes: 5 additions & 6 deletions includes/admin/transifex-live-integration-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ static function options_page() {
}

ob_start();
checked( $settings['rewrite_option_all'], '1' );
checked( $settings['rewrite_option_all'], 1 );
$checked_rewrite_option_all = ob_get_clean();



// These are used by the template: DO NOT REMOVE - Mjj 2/22/2016
$languages = [ ];
if ( $settings['transifex_languages'] !== '' ) {
$languages = $settings['transifex_languages'];
}

$languages_regex = [ ];
if ( $settings['languages_regex'] !== '' ) {
$languages_regex = $settings['languages_regex'];
}

$source_language = '';
if ( $settings['source_language'] !== '' ) {
$source_language = $settings['source_language'];
Expand All @@ -71,7 +71,6 @@ static function options_page() {
if ( $settings['language_map'] !== '' ) {
$language_map = $settings['language_map'];
}

$checked_custom_urls = ($settings['enable_custom_urls'] === "1") ? "1" : "0";

$url_options = $settings['url_options'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<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">
<td style="padding:0px"><span class="tx-language">Dummy</span></td>
<td style="padding:0px"><input class="tx-code" type="text" style="width:100px" name="dummy-name" id="dummy-id" value=""></td>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static function render_url_options( $options ) {
$i = 1;
foreach ($options as $option) {
ob_start();
checked( $option['checked'], '1' );
checked( $option['checked'], 1 );
$checked = ob_get_clean();
$text = $option['text'];
$id = $option['id'];
Expand Down
2 changes: 1 addition & 1 deletion includes/plugin-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Plugin_Debug {
* Define the core functionality of the plugin.
*/
public function __construct() {
self::$debug_mode = true;
self::$debug_mode = false;
$this->logTrace();

// Check to see if plugin is in debug mode
Expand Down
2 changes: 1 addition & 1 deletion includes/transifex-live-integration-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static function settings() {
'language_lookup' => null,
'language_map' => null,
'languages_regex' => null,
'rewrite_option_all' => "1",
'rewrite_option_all' => 0,

'enable_custom_urls' => 0,
'urls' => [
Expand Down
22 changes: 16 additions & 6 deletions includes/transifex-live-integration-javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class Transifex_Live_Integration_Javascript {
* Stores current plugin settings.
* @var array
*/
private $live_settings_keys = array( 'api_key');
private $live_settings_keys = array( 'api_key' );
private $live_settings;
private $is_detectlang;
private $tx_langs;
private $language_map;
private $source_language;

/**
* Public constructor, sets local settings
Expand All @@ -30,6 +32,8 @@ public function __construct( $settings, $is_detectlang ) {
}
$this->tx_langs = $settings['transifex_languages'];
$this->is_detectlang = $is_detectlang;
$this->language_map = json_decode( $settings['language_map'], true )[0];
$this->source_language = $settings['source_language'];
}

/**
Expand All @@ -39,16 +43,23 @@ function render() {
Plugin_Debug::logTrace();
$this->is_detectlang ? Plugin_Debug::logTrace( "overriding detectlang" ) : Plugin_Debug::logTrace( "skipped detectlang override" );
if ( $this->is_detectlang ) {
$lang = get_query_var( 'lang' );

$query_lang = get_query_var( 'lang' );
if ( $query_lang == $this->source_language ) {
$lang = $this->source_language;
} else {
$lang = array_search( $query_lang, $this->language_map );
if ( !$lang ) {
Plugin_Debug::logTrace( 'javascript render failed could not find key' );
return false;
}
}
$check_for_standard_lang = in_array( $lang, explode( ",", $this->tx_langs ) );
Plugin_Debug::logTrace( $check_for_standard_lang ? "standard lang detected, skipping override" : "not standard lang, overriding" );
Plugin_Debug::logTrace( $check_for_standard_lang ? "standard lang detected, skipping override" : "not standard lang, overriding" );
if ( !$check_for_standard_lang ) {
Plugin_Debug::logTrace( "Not a standard lang override" );
$detectlang = <<<DETECTLANG
function() { return "$lang";}
DETECTLANG;
Plugin_Debug::logTrace( $detectlang );
$this->live_settings = array_merge( $this->live_settings, array( 'detectlang' => '%function%' ) );
}
}
Expand All @@ -57,7 +68,6 @@ function() { return "$lang";}
$live_settings_string = str_replace( '"%function%"', $detectlang, $live_settings_string );
}

Plugin_Debug::logTrace( $live_settings_string );
$include = <<<LIVE
<script type="text/javascript">window.liveSettings=$live_settings_string;</script>
<script type="text/javascript" src="//cdn.transifex.com/live.js"></script>\n
Expand Down
169 changes: 169 additions & 0 deletions javascript/jquery.jloggins.1.0.1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
//****************************************************************************************************************************************************
// Copyright (c) 2012 AbstractLabs
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//****************************************************************************************************************************************************
(function (jQuery) {
var hash = new RegExp(/log\:?(all|debug|info|warn|error)/gi).exec(document.location.hash)
jQuery.log =
{
__window: null,
__level: "none",
__context: new Array(),
__operation: new Array(),
level: function (value) {
if (value != this.__level && (value == 'all' || value == 'debug' || value == 'info' || value == 'warn' || value == 'error')) {
this.__level = value;
this.write('Logging level is ' + this.__level)
}
return this.__level;
},
enabled: function (level) {
return (this.__level == 'all'
|| this.__level == 'debug'
|| (this.__level != 'none' && level == 'any')
|| (this.__level == 'info' && (level != 'debug'))
|| (this.__level == 'warn' && (level != 'debug' || level != 'info'))
|| (this.__level == 'error' && (level != 'debug' || level != 'info' || level != 'warn')));
},
context: function (depth) {
var result = null;
if (this.context.length > 0 && (typeof (depth) == 'undefined' || depth < this.__context.length)) result = this.__context[this.__context.length - 1];
return result;
},
enter: function (context) {
this.__context.push(context);
return this;
},
exit: function () {
if (this.__context.length > 0) this.__context.pop();
return this;
},
start: function (operation) {
this.__operation.push({ name: operation, timestamp: new Date().getTime() });
this.write('Start ' + operation, '->')
},
stop: function () {
if (this.__operation.length > 0) {
var operation = this.__operation.pop()
var elapsed = new Date();
elapsed.setTime(new Date().getTime() - operation.timestamp);
this.write('Stop ' + operation.name + ' ' + elapsed.getMinutes() + ':' + elapsed.getSeconds() + ':' + elapsed.getMilliseconds() + ' elapsed', '<-')
}
},
reset: function () {
this.__context = new Array();
this.__operations = new Array();
return this;
},
write: function (message, type) {
if (this.enabled('any')) {
if (typeof (type) != 'undefined') message = '[' + type + '] ' + message;
if (typeof (console) == 'object') console.log(message)
else if (typeof (opara) == 'object') opera.postError(message);
else {
if (this.__window == null) this.__window = window.open();
this.__window.document.write(message);
}
}
},
format: function () {
var result = (this.__context.length > 0) ? this.__context.join(' ') + ':' : '';
for (var index = 0; index < arguments.length; index++)
{
if(typeof(arguments[index]) == 'string')
{
result += arguments[index]
}
else if(JSON && JSON.stringify) result += JSON.stringify(arguments[index]);
else
{
results += '{';
for(p in arguments[index]) result += p +':'+ arguments[index][p]
results += '}';
}
}
return result;
},
debug: function () {
if (this.enabled('debug')) {
var message = this.format.apply(this, arguments);
if (typeof (console.debug) == 'function') console.debug(message)
else this.write(message, '*');
}
},
info: function () {
if (this.enabled('info')) {
var message = this.format.apply(this, arguments);
if (typeof (console.info) == 'function') console.info(message)
else this.write(message, '?');
}
},
warn: function () {
if (this.enabled('warn')) {
var message = this.format.apply(this, arguments);
if (typeof (console.warn) == 'function') console.warn(message)
else this.write(message, '+');
}
},
error: function () {
if (this.enabled('error')) {
var message = this.format.apply(this, arguments);
if (typeof (console.error) == 'function') console.error(message)
else this.write(message, '!');
}
},
exception: function (e) {
if (this.enabled('error')) {
var message = '';
if ('fileName' in e) message += e.fileName + ' ';
if ('lineNumber' in e) message += e.lineNumber + ' ';
if ('number' in e) message += e.number;
if (message.length > 0) message += ':';
message += e.message;
if ('description' in e) message += '-' + e.description;
}
}
},
jQuery.fn.log = function (jQuery) {
var $this = $(this);
var context = $this.prop('tagName');
if ($this.attr('id')) context += ' #' + $this.attr('id');
if ($this.attr('class')) context += ' ' + $this.attr('class');
return {
write: function (message, type) {
$.log.enter(context);
try { $.log.write.call($._log, message, type); }
finally { $.log.exit(); }
}
,
debug: function () {
$.log.enter(context);
try { $.log.debug.apply($.log, arguments); }
finally { $.log.exit(); }
},
info: function () {
$.log.enter(context);
try { $.log.info.apply($.log, arguments); }
finally { $.log.exit(); }
},
warn: function () {
$.log.enter(context);
try { $.log.warn.apply($.log, arguments); }
finally { $.log.exit(); }
},
error: function () {
$.log.enter(context);
try { $.log.error.apply($.log, arguments); }
finally { $.log.exit(); }
}
}
}
if (hash != null && hash.length > 1) try { $.log.level(hash[1]) } finally { }
})(jQuery);
Loading

0 comments on commit be33ac3

Please sign in to comment.