Skip to content

Commit

Permalink
Merge pull request #15 from matthewjackowski/devel
Browse files Browse the repository at this point in the history
Cleaning up the codebase
  • Loading branch information
Matthew Jackowski committed Sep 29, 2015
2 parents 5d0b166 + 42213b1 commit 168979a
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tests/_output/*
tests/_support/*

languages/
build/
tests/_output/*
Binary file added assets/banner-1544x500.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner-772x250.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-128x128.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-256x256.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function admin_notices() {
$notice .= '<p>' . __( 'Your changes to the colors have been saved!', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ) . '</p>';
}

echo '<div class="notice">' . $notice . '</div>';
echo '<div class="notice">' . $notice . '</div>';
}

static public function sanitize_settings( $settings ) {
Expand Down
75 changes: 38 additions & 37 deletions includes/plugin-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Class Name: Plugin Debug
* Description: An plugin/application error/trace log handler. It *only* traps info from the plugin, and the display is controllable from "Settings" page
* Author: Matthew Jackowski
* Version: 0.2.0
* Author URI: http://www.linkedin.com/pub/matthew-jackowski/6/6b2/242
* Version: 0.2.1
* Author URI: https://github.com/matthewjackowski/
* License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
*/
?>
Expand All @@ -21,7 +21,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 Expand Up @@ -70,43 +70,44 @@ public function printLog() {
}

static function printLogCallback( $value, $key ) {
// $options = get_option('debug_section');
echo "*<br/>";
if ( array_key_exists( 'file', $value ) )
echo ("<b>File: " . basename( $value['file'] ) . "</b> - ");
if ( array_key_exists( 'line', $value ) )
echo ('<font color="green">Line #: ' . $value['line'] . '</font>');
echo "<br/>";
if ( array_key_exists( 'class', $value ) )
echo ("<b>Class: " . $value['class'] . "</b> - ");
if ( array_key_exists( 'function', $value ) )
echo ('<font color="green">Function: ' . $value['function'] . '</font>');
echo "<br/>";
if ( array_key_exists( 'type', $value ) ) {
echo ("<b>Type: ");
switch ($value['type']) {
case "::":
echo ("static method call");
break;
case "->" :
echo ("method call");
break;
default :
echo ("function call");
if ( self::$debug_mode ) {
echo "*<br/>";
if ( array_key_exists( 'file', $value ) )
echo ("<b>File: " . basename( $value['file'] ) . "</b> - ");
if ( array_key_exists( 'line', $value ) )
echo ('<font color="green">Line #: ' . $value['line'] . '</font>');
echo "<br/>";
if ( array_key_exists( 'class', $value ) )
echo ("<b>Class: " . $value['class'] . "</b> - ");
if ( array_key_exists( 'function', $value ) )
echo ('<font color="green">Function: ' . $value['function'] . '</font>');
echo "<br/>";
if ( array_key_exists( 'type', $value ) ) {
echo ("<b>Type: ");
switch ($value['type']) {
case "::":
echo ("static method call");
break;
case "->" :
echo ("method call");
break;
default :
echo ("function call");
}
echo("</b> - ");
}
echo("</b> - ");
}
if ( array_key_exists( 'args', $value ) ) {
echo ('<font color="green">Parameters: ');
print_r( $value['args'] );
if ( array_key_exists( 'args', $value ) ) {
echo ('<font color="green">Parameters: ');
print_r( $value['args'] );
echo ('</font>');
}
echo "<br/>";
if ( array_key_exists( 'message', $value ) && $value['message'] != null )
echo ('<font color="red">');
print_r( $value['message'] );
echo ('</font>');
echo "<br/>*";
}
echo "<br/>";
if ( array_key_exists( 'message', $value ) && $value['message'] != null )
echo ('<font color="red">');
print_r( $value['message'] );
echo ('</font>');
echo "<br/>*";
}

}
Expand Down
31 changes: 27 additions & 4 deletions includes/transifex-live-integration-css.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
<?php
/**
* Includes CSS for restyling the language picker
* @package TransifexLiveIntegration
*/

include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-lib.php';

/**
* Class sets whether restyling occurs based on admin settings
*/
class Transifex_Live_Integration_Css {

/**
* Copy of current plugin settings
* @var settings array
*/
private $settings;

/**
* Determines whether to display CSS
* @var boolean
*/
private $ok_add_css;

/**
* Public constructor, sets boolean based on plugin settings
* @param array $settings Associative array used to store plugin settings.
*/
public function __construct( $settings ) {
Plugin_Debug::logTrace();
if ( isset( $settings['enable_frontend_css'] ) && $settings['enable_frontend_css'] ) {
Expand All @@ -17,15 +37,18 @@ public function __construct( $settings ) {
$this->settings = $settings;
}

/**
* Renders CSS inline on the page
*/
function inline_render() {
Plugin_Debug::logTrace();

if ( $this->ok_add_css ) {

$colors = array_map( 'esc_attr', (array) get_option( 'transifex_live_colors', array() ) );
foreach ($colors as $key => $values) {
if ( empty( $colors[$key] ) ) {
$colors[$key] = $values['default'];
foreach ( $colors as $key => $values ) {
if ( empty( $colors[ $key ] ) ) {
$colors[ $key ] = $values['default'];
}
}

Expand Down Expand Up @@ -61,7 +84,7 @@ function inline_render() {
}
</style>
CSS;
Transifex_Live_Integration_Lib::enqueue_inline_styles( 'transifex-live-integration-css', $css );
wp_add_inline_style( 'transifex-live-integration-css', $css );
}
}

Expand Down
19 changes: 15 additions & 4 deletions includes/transifex-live-integration-defaults.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php
/**
* Defaults for plugin settings
* @package TransifexLiveIntegration
*/

/**
* Static class for settings defaults
*/
class Transifex_Live_Integration_Defaults {

/**
* Static function for settings defaults
* @return array Returns the settings array
*/
static function settings() {
Plugin_Debug::logTrace();
return array(
Expand All @@ -14,19 +25,19 @@ static function settings() {
'text' => '#ffffff',
'background' => '#000000',
'menu' => '#eaf1f7',
'languages' => '#666666'
'languages' => '#666666',
],
'color_labels' => [
'accent' => __( 'Accent', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ),
'text' => __( 'Text', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ),
'background' => __( 'Background', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ),
'menu' => __( 'Menu', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ),
'languages' => __( 'Languages', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN )
'languages' => __( 'Languages', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN ),
],
'urls' => [
'rate_us' => 'https://wordpress.org/support/view/plugin-reviews/transifex-live-integration?rate=5#postform',
'api_key_landing_page' => 'https://www.transifex.com/live/?utm_source=liveplugin'
]
'api_key_landing_page' => 'https://www.transifex.com/live/?utm_source=liveplugin',
],
);
}

Expand Down
21 changes: 20 additions & 1 deletion includes/transifex-live-integration-javascript.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
<?php
/**
* Includes Transifex Live javascript snippet
* @package TransifexLiveIntegration
*/

/**
* Class that creates javascript snippet based on settings
*/
class Transifex_Live_Integration_Javascript {

/**
* Stores current plugin settings.
* @var array
*/
private $live_settings = array();

/**
* Public constructor, sets local settings
* @param array $live_settings Associative array of plugin settings.
*/
public function __construct( $live_settings ) {
Plugin_Debug::logTrace();
$this->live_settings = $live_settings;
}

/**
* Renders javascript includes in the page
*/
function render() {
Plugin_Debug::logTrace();
$live_settings_string = json_encode( $this->live_settings );
Plugin_Debug::logTrace( $live_settings_string );
echo <<<LIVE
$include = <<<LIVE
<script type="text/javascript">window.liveSettings=$live_settings_string;</script>
<script type="text/javascript" src="//cdn.transifex.com/live.js"></script>
LIVE;
echo $include;
}

}
27 changes: 7 additions & 20 deletions includes/transifex-live-integration-lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php
/**
* Common libraries
* @package TransifexLiveIntegration
*/

/**
* Common PHP Libraries from other sources
*/
class Transifex_Live_Integration_Lib {

/**
Expand All @@ -26,25 +33,5 @@ static public function hex2rgb( $hex ) {
return $rgb; // returns an array with the rgb values
}

/**
* Enqueue inline CSS. @see wp_enqueue_style().
*
*
* @param string $handle Identifying name for script
* @param string $src The JavaScript codez
*
* @return null
*/
static function enqueue_inline_styles( $handle, $js ) {
$cb = function()use( $handle, $js ) {
if ( wp_script_is( $handle, 'done' ) )
return;
echo "\n$js\n";
global $wp_styles;
$wp_styles->done[] = $handle;
};
$hook = 'wp_print_styles';
add_action( $hook, $cb );
}

}
Loading

0 comments on commit 168979a

Please sign in to comment.