Date: Thu, 24 Mar 2016 16:14:30 -0700
Subject: [PATCH 05/29] refactored bot logic
---
...ansifex-live-integration-settings-page.php | 2 +-
...fex-live-integration-settings-template.php | 2 ++
includes/plugin-debug.php | 2 +-
.../transifex-live-integration-defaults.php | 2 +-
.../transifex-live-integration-prerender.php | 24 ++++++++++++-------
tests/unit/PrerenderCheckTest.php | 23 ++++++++++++++----
6 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/includes/admin/transifex-live-integration-settings-page.php b/includes/admin/transifex-live-integration-settings-page.php
index ceff26b2..3244edb8 100644
--- a/includes/admin/transifex-live-integration-settings-page.php
+++ b/includes/admin/transifex-live-integration-settings-page.php
@@ -230,7 +230,7 @@ static public function sanitize_settings( $settings ) {
$settings['transifex_live_settings']['subdomain_pattern'] = ( isset( $settings['transifex_live_settings']['subdomain_pattern'] )) ? sanitize_text_field( $settings['transifex_live_settings']['subdomain_pattern'] ) : '';
$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_settings']['language_map'] = ( 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'] ) ) : '';
diff --git a/includes/admin/transifex-live-integration-settings-template.php b/includes/admin/transifex-live-integration-settings-template.php
index 5528ae86..8cffffac 100644
--- a/includes/admin/transifex-live-integration-settings-template.php
+++ b/includes/admin/transifex-live-integration-settings-template.php
@@ -85,6 +85,8 @@
+
+
diff --git a/includes/plugin-debug.php b/includes/plugin-debug.php
index eb16b5a8..60729ff0 100644
--- a/includes/plugin-debug.php
+++ b/includes/plugin-debug.php
@@ -18,7 +18,7 @@ class Plugin_Debug {
* Define the core functionality of the plugin.
*/
public function __construct() {
- self::$debug_mode = false;
+ self::$debug_mode = true;
$this->logTrace();
// Check to see if plugin is in debug mode
diff --git a/includes/transifex-live-integration-defaults.php b/includes/transifex-live-integration-defaults.php
index 61332f97..586fb7c4 100644
--- a/includes/transifex-live-integration-defaults.php
+++ b/includes/transifex-live-integration-defaults.php
@@ -83,7 +83,7 @@ static function settings() {
'url_options' => 1,
'subdomain_pattern' => '',
'whitelist_crawlers' =>
- 'googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0.|developers.google.com\/\+\/web\/snippet|slackbot|vkShare|w3c_validator|redditbot|applebot|whatsapp|flipboard',
+ 'googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard',
'generic_bot_types' => 'bot|crawl|slurp|spider'
);
}
diff --git a/includes/transifex-live-integration-prerender.php b/includes/transifex-live-integration-prerender.php
index a2c111bb..ede421f7 100644
--- a/includes/transifex-live-integration-prerender.php
+++ b/includes/transifex-live-integration-prerender.php
@@ -7,28 +7,34 @@ public function __construct() {
}
static public function is_whitelist_name( $agent, $whitelist_names ) {
- return !empty( $agent ) ? (preg_match( "/{$whitelist_names}/", $agent ) > 0) : false;
+ Plugin_Debug::logTrace();
+ return !empty( $agent ) ? (preg_match( "/{$whitelist_names}/i", $agent ) > 0) : false;
}
static public function is_bot_type( $agent, $bot_types ) {
- return !empty( $agent ) ? (preg_match( "/{$bot_types}/", $agent ) > 0) : false;
+ Plugin_Debug::logTrace();
+ return !empty( $agent ) ? (preg_match( "/{$bot_types}/i", $agent ) > 0) : false;
}
static public function prerender_check( $req_user_agent, $req_escaped_fragment,
$bot_types, $whitelist_names ) {
- $bool = self::is_bot_type( $req_user_agent, $bot_types );
-
- $bool = ($bool) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names );
+ Plugin_Debug::logTrace();
+ if (strpos( $req_user_agent , 'prerender' )) {
+ return false;
+ }
+ $bot_types = addcslashes ($bot_types,'/');
+ $whitelist_names = addcslashes ($whitelist_names, '/');
- $bool = ($bool) ? true : ($req_escaped_fragment) ? true : false;
+ $is_bot = self::is_bot_type( $req_user_agent, $bot_types );
+ $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names );
+ $prerender_ok = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
- $bool = (strpos( strtolower( $req_user_agent ), 'prerender' )) ? false : $bool;
- return $bool;
+ return $prerender_ok;
}
static function create_prerender( $settings ) {
Plugin_Debug::logTrace();
- $req_user_agent = $_SERVER["HTTP_USER_AGENT"];
+ $req_user_agent = (isset($_SERVER['HTTP_USER_AGENT']))?strtolower( $_SERVER['HTTP_USER_AGENT']):false;
$req_escaped_fragment = (isset( $_GET['_escaped_fragment_'] )) ? $_GET['_escaped_fragment_'] : false;
$check = self::prerender_check( $req_user_agent, $req_escaped_fragment, $settings['generic_bot_types'], $settings['whitelist_crawlers'] );
diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php
index b59af59c..30c78e58 100644
--- a/tests/unit/PrerenderCheckTest.php
+++ b/tests/unit/PrerenderCheckTest.php
@@ -11,31 +11,44 @@ protected function setUp() {
$settings = Transifex_Live_Integration_Defaults::settings();
$whitelist = $settings['whitelist_crawlers'];
$bot_types = $settings['generic_bot_types'];
- $this->data = [[
+ $this->data = [[ // Standard Chrome Agent
'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'fragment' => NULL,
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => false
- ], [
+ ],[ // Standard Firefox Agent
+ 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:46.0) Gecko/20100101 Firefox/46.0',
+ 'fragment' => NULL,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => false
+ ], [ // Prerender added
'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 Prerender (+https://github.com/prerender/prerender)',
'fragment' => NULL,
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => false
- ], [
+ ], [ // Standard Googlebot
'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
'fragment' => NULL,
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => true
- ], [
+ ], [ // Googlebot with prerender added
'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Prerender (+https://github.com/prerender/prerender)',
'fragment' => NULL,
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => false
- ], [
+ ],[ // Slackbot with
+ 'agent' => 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
+ 'fragment' => NULL,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ],
+ [ // some fragment
'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'fragment' => '/some-frament',
'bot_types' => $bot_types,
From dd772227041b342faa188ba6baf6ea3fc063324d Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Fri, 25 Mar 2016 13:00:30 -0700
Subject: [PATCH 06/29] fixed test
---
tests/unit/PrerenderCheckTest.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php
index 39e8d802..3c786775 100644
--- a/tests/unit/PrerenderCheckTest.php
+++ b/tests/unit/PrerenderCheckTest.php
@@ -41,9 +41,7 @@ protected function setUp() {
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => false
- ], [ // some fragment
-=======
- ],[ // Slackbot with
+ ], [ // Slackbot with
'agent' => 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
'fragment' => NULL,
'bot_types' => $bot_types,
From 8a5015ccc59a53bd0c125d3d5b254a243f4ee2f3 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Fri, 25 Mar 2016 16:43:32 -0700
Subject: [PATCH 07/29] Added 'slackbot'
---
tests/unit/PrerenderCheckTest.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php
index 3c786775..1736cf62 100644
--- a/tests/unit/PrerenderCheckTest.php
+++ b/tests/unit/PrerenderCheckTest.php
@@ -47,6 +47,12 @@ protected function setUp() {
'bot_types' => $bot_types,
'whitelist' => $whitelist,
'result' => true
+ ],[ // Slackbot with
+ 'agent' => 'slackbot',
+ 'fragment' => NULL,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
],
[ // some fragment
'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
From ca96c53063da858519be283ec256b38c3ffb5f13 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Fri, 25 Mar 2016 14:14:19 -0700
Subject: [PATCH 08/29] Added prerender header, and 404 status meta
---
curl_and_get_header.php | 34 +
includes/plugin-debug.php | 2 +-
.../transifex-live-integration-prerender.php | 56 +-
test | 737 ++++++++++++++++++
tests/unit/PrerenderCheckTest.php | 2 +-
transifex-live-integration.php | 12 +-
6 files changed, 825 insertions(+), 18 deletions(-)
create mode 100644 curl_and_get_header.php
create mode 100644 test
diff --git a/curl_and_get_header.php b/curl_and_get_header.php
new file mode 100644
index 00000000..393258d5
--- /dev/null
+++ b/curl_and_get_header.php
@@ -0,0 +1,34 @@
+
\ No newline at end of file
diff --git a/includes/plugin-debug.php b/includes/plugin-debug.php
index eb16b5a8..60729ff0 100644
--- a/includes/plugin-debug.php
+++ b/includes/plugin-debug.php
@@ -18,7 +18,7 @@ class Plugin_Debug {
* Define the core functionality of the plugin.
*/
public function __construct() {
- self::$debug_mode = false;
+ self::$debug_mode = true;
$this->logTrace();
// Check to see if plugin is in debug mode
diff --git a/includes/transifex-live-integration-prerender.php b/includes/transifex-live-integration-prerender.php
index ede421f7..e4054240 100644
--- a/includes/transifex-live-integration-prerender.php
+++ b/includes/transifex-live-integration-prerender.php
@@ -16,25 +16,49 @@ static public function is_bot_type( $agent, $bot_types ) {
return !empty( $agent ) ? (preg_match( "/{$bot_types}/i", $agent ) > 0) : false;
}
+ static public function is_prerender_req() {
+ $req_user_agent = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
+ $ret = (strpos( $req_user_agent, 'prerender' )) ? true : false;
+ Plugin_Debug::logTrace( $req_user_agent );
+ Plugin_Debug::logTrace( $ret );
+ return $ret;
+ }
+
+ function wp_head_hook() {
+ Plugin_Debug::logTrace();
+ $status = '';
+ if ( is_404() ) {
+ $status .= <<< STATUS
+ \n
+STATUS;
+ }
+ echo $status;
+ }
+
+ function wp_headers_hook( $headers ) {
+ Plugin_Debug::logTrace();
+ $headers['X-PreRender-Req'] = 'TRUE';
+ return $headers;
+ }
+
static public function prerender_check( $req_user_agent, $req_escaped_fragment,
$bot_types, $whitelist_names ) {
Plugin_Debug::logTrace();
- if (strpos( $req_user_agent , 'prerender' )) {
- return false;
- }
- $bot_types = addcslashes ($bot_types,'/');
- $whitelist_names = addcslashes ($whitelist_names, '/');
- $is_bot = self::is_bot_type( $req_user_agent, $bot_types );
- $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names );
- $prerender_ok = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
+ $bot_types_escaped = addcslashes( $bot_types, '/' );
+ $whitelist_names_escaped = addcslashes( $whitelist_names, '/' );
+
+ $is_bot = self::is_bot_type( $req_user_agent, $bot_types_escaped );
+ $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names_escaped );
+ $has_escaped_fragment = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
+ $prerender_ok = ($has_escaped_fragment) ? true : self::is_prerender_req();
return $prerender_ok;
}
static function create_prerender( $settings ) {
Plugin_Debug::logTrace();
- $req_user_agent = (isset($_SERVER['HTTP_USER_AGENT']))?strtolower( $_SERVER['HTTP_USER_AGENT']):false;
+ $req_user_agent = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
$req_escaped_fragment = (isset( $_GET['_escaped_fragment_'] )) ? $_GET['_escaped_fragment_'] : false;
$check = self::prerender_check( $req_user_agent, $req_escaped_fragment, $settings['generic_bot_types'], $settings['whitelist_crawlers'] );
@@ -42,7 +66,6 @@ static function create_prerender( $settings ) {
}
function callback( $buffer ) {
-
global $wp;
$output = $buffer;
$page_url = home_url( $wp->request );
@@ -51,12 +74,19 @@ function callback( $buffer ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'http://secure-refuge-63401.herokuapp.com/' . $page_url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- $result = curl_exec( $ch );
- if ( $result === false ) {
+ curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
+ curl_setopt( $ch, CURLOPT_HEADER, 1 );
+ $response = curl_exec( $ch );
+ $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
+ $header = substr( $response, 0, $header_size );
+ $body = substr( $response, $header_size );
+ if ( $response === false ) {
$error = curl_error( $ch );
// write to db??
} else {
- $output = $result;
+ if ( strpos( $header, 'X-PreRender-Req: TRUE' ) ) {
+ $output = $body;
+ }
}
curl_close( $ch );
return $output;
diff --git a/test b/test
new file mode 100644
index 00000000..772c1ad0
--- /dev/null
+++ b/test
@@ -0,0 +1,737 @@
+
+
+
+Hello world! - Test-WP-PluginTest-WP-Plugin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Just another WordPress site
+
+
+
+
+
+
+
+
+
+ Main menu
+
+
+
+
+
+
+
+
+
+
+
+
+ Post navigation
+ ← Previous
+ Next →
+
+
+
+
+
+
+
+
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Plugin: Plugin Debug Mode Output
+*File: transifex-live-integration.php - Line #: 67 Class: Plugin_Debug - Function: __construct Type: method call - Parameters: Array
+(
+)
+ **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ **File: transifex-live-integration.php - Line #: 98 Class: Transifex_Live_Integration_Subdomain - Function: create_subdomains Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ **File: transifex-live-integration.php - Line #: 98 Class: Transifex_Live_Integration_Subdomain - Function: create_subdomains Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ settings[url_options] not subdomain **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ subdomains skipped **File: transifex-live-integration.php - Line #: 107 Class: Transifex_Live_Integration_Rewrite - Function: create_rewrite Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+ [1] => Array
+ (
+ [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
+ )
+
+)
+ **File: transifex-live-integration.php - Line #: 107 Class: Transifex_Live_Integration_Rewrite - Function: create_rewrite Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+ [1] => Array
+ (
+ [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
+ )
+
+)
+ settings[languages_regex] not set **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ rewrite skipped **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ adding admin bar actions **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ user_agent **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34 Prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration-prerender.php - Line #: 55 Class: Transifex_Live_Integration_Prerender - Function: prerender_check Type: static method call - Parameters: Array
+(
+ [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
+ [1] =>
+ [2] => bot|crawl|slurp|spider
+ [3] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+)
+ **File: transifex-live-integration-prerender.php - Line #: 40 Class: Transifex_Live_Integration_Prerender - Function: is_bot_type Type: static method call - Parameters: Array
+(
+ [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
+ [1] => bot|crawl|slurp|spider
+)
+ **File: transifex-live-integration-prerender.php - Line #: 41 Class: Transifex_Live_Integration_Prerender - Function: is_whitelist_name Type: static method call - Parameters: Array
+(
+ [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
+ [1] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0.|developers.google.com\/+\/web\/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+)
+ **File: transifex-live-integration-prerender.php - Line #: 43 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
+(
+)
+ mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration-prerender.php - Line #: 43 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
+(
+)
+ 1 **File: transifex-live-integration-prerender.php - Line #: 56 Class: Transifex_Live_Integration_Prerender - Function: __construct Type: method call - Parameters: Array
+(
+)
+ **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ prerender created **File: transifex-live-integration.php - Line #: 206 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
+(
+)
+ mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration.php - Line #: 206 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
+(
+)
+ 1 **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ prerender request detected **File: transifex-live-integration.php - Line #: 218 Class: Transifex_Live_Integration_Hreflang - Function: __construct Type: method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+ [1] => 1
+)
+ **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ Severity: 8 File: transifex-live-integration-hreflang.php Line: 29: Undefined offset: 0 **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ Severity: 8 File: transifex-live-integration-hreflang.php Line: 31: Undefined index: tokenized_url **File: transifex-live-integration.php - Line #: 219 Class: Transifex_Live_Integration_Hreflang - Function: ok_to_add Type: method call - Parameters: Array
+(
+)
+ settings[api_key] not set...skipping hreflang **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ skipping hreflang **File: transifex-live-integration.php - Line #: 220 Class: Transifex_Live_Integration_Hreflang - Function: ok_to_add Type: method call - Parameters: Array
+(
+)
+ settings[api_key] not set...skipping hreflang **File: transifex-live-integration.php - Line #: 225 Class: Transifex_Live_Integration_Javascript - Function: __construct Type: method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+ [1] =>
+)
+ **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ Severity: 8 File: transifex-live-integration-javascript.php Line: 35: Undefined offset: 0 **File: transifex-live-integration.php - Line #: 229 Class: Transifex_Live_Integration_Picker - Function: create_picker Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ **File: transifex-live-integration.php - Line #: 229 Class: Transifex_Live_Integration_Picker - Function: create_picker Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [api_key] =>
+ [previous_api_key] =>
+ [raw_transifex_languages] =>
+ [transifex_languages] =>
+ [language_lookup] =>
+ [language_map] => []
+ [languages_regex] =>
+ [rewrite_option_all] => 0
+ [enable_custom_urls] => 0
+ [urls] => Array
+ (
+ [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] =>
+ [enable_picker] =>
+ [add_language_rewrites] => none selected
+ [source_language] =>
+ [languages] =>
+ [hreflang] =>
+ [url_options] => 1
+ [subdomain_pattern] =>
+ [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
+ [generic_bot_types] => bot|crawl|slurp|spider
+ )
+
+)
+ settings[enable_picker] not truthy **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
+(
+ [0] =>
+ [1] => 1.2.5
+)
+ picker skipped **Class: Transifex_Live_Integration - Function: query_vars_hook Type: static method call - Parameters: Array
+(
+ [0] => Array
+ (
+ [0] => m
+ [1] => p
+ [2] => posts
+ [3] => w
+ [4] => cat
+ [5] => withcomments
+ [6] => withoutcomments
+ [7] => s
+ [8] => search
+ [9] => exact
+ [10] => sentence
+ [11] => calendar
+ [12] => page
+ [13] => paged
+ [14] => more
+ [15] => tb
+ [16] => pb
+ [17] => author
+ [18] => order
+ [19] => orderby
+ [20] => year
+ [21] => monthnum
+ [22] => day
+ [23] => hour
+ [24] => minute
+ [25] => second
+ [26] => name
+ [27] => category_name
+ [28] => tag
+ [29] => feed
+ [30] => author_name
+ [31] => static
+ [32] => pagename
+ [33] => page_id
+ [34] => error
+ [35] => comments_popup
+ [36] => attachment
+ [37] => attachment_id
+ [38] => subpost
+ [39] => subpost_id
+ [40] => preview
+ [41] => robots
+ [42] => taxonomy
+ [43] => term
+ [44] => cpage
+ [45] => post_type
+ [46] => embed
+ [47] => post_format
+ [48] => sitemap
+ [49] => sitemap_n
+ [50] => xsl
+ [51] => rest_route
+ )
+
+)
+ **Class: Transifex_Live_Integration_Javascript - Function: render Type: method call - Parameters: Array
+(
+ [0] =>
+)
+ **Class: Transifex_Live_Integration_Javascript - Function: render Type: method call - Parameters: Array
+(
+ [0] =>
+)
+ skipped detectlang override *
+
+
+
+
\ No newline at end of file
diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php
index 1736cf62..3289bdee 100644
--- a/tests/unit/PrerenderCheckTest.php
+++ b/tests/unit/PrerenderCheckTest.php
@@ -40,7 +40,7 @@ protected function setUp() {
'fragment' => NULL,
'bot_types' => $bot_types,
'whitelist' => $whitelist,
- 'result' => false
+ 'result' => true
], [ // Slackbot with
'agent' => 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
'fragment' => NULL,
diff --git a/transifex-live-integration.php b/transifex-live-integration.php
index c6c199e6..8b975daf 100755
--- a/transifex-live-integration.php
+++ b/transifex-live-integration.php
@@ -203,9 +203,15 @@ static function do_plugin( $is_admin, $version ) {
$prerender = Transifex_Live_Integration_Prerender::create_prerender($settings);
($prerender) ? Plugin_Debug::logTrace( 'prerender created' ) : Plugin_Debug::logTrace( 'prerender skipped' );
if ( $prerender ) {
- add_action( 'wp_head', [ $prerender, 'wp_head_hook' ] );
- add_action('after_setup_theme', [ $prerender, 'after_setup_theme_hook']);
- add_action('shutdown', [ $prerender, 'shutdown_hook']);
+ if (Transifex_Live_Integration_Prerender::is_prerender_req() ) {
+ Plugin_Debug::logTrace( 'prerender request detected' );
+ add_filter( 'wp_headers', [$prerender, 'wp_headers_hook'] );
+ add_action( 'wp_head', [$prerender, 'wp_head_hook'], 1 );
+ } else {
+ Plugin_Debug::logTrace( 'invoke prerender call' );
+ add_action('after_setup_theme', [ $prerender, 'after_setup_theme_hook']);
+ add_action('shutdown', [ $prerender, 'shutdown_hook']);
+ }
}
From 90cd268b3e050c823250f0c01d7ebfc897085765 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Mon, 28 Mar 2016 14:21:51 -0700
Subject: [PATCH 09/29] version 1.3.0 spring cleaning refactor added prerender
settings and initial ui
---
Gruntfile.js | 314 +++---
curl_and_get_header.php | 34 -
hreflang_languages.php | 33 -
...ransifex-live-integration-action-links.php | 15 -
...sifex-live-integration-admin-template.php} | 25 +-
...transifex-live-integration-admin-util.php} | 28 +-
...p => transifex-live-integration-admin.php} | 22 +-
includes/common/plugin-debug.php | 124 +++
.../transifex-live-integration-common.php | 132 +++
...-live-integration-static-files-handler.php | 94 ++
.../transifex-live-integration-validators.php | 81 ++
.../transifex-live-integration-hreflang.php | 31 +-
.../transifex-live-integration-javascript.php | 90 ++
.../lib/transifex-live-integration-picker.php | 50 +
.../transifex-live-integration-prerender.php | 88 ++
.../transifex-live-integration-rewrite.php | 505 ++++++++++
.../transifex-live-integration-subdomain.php | 82 ++
...ive-integration-generate-rewrite-rules.php | 334 +++++++
includes/plugin-debug.php | 114 ---
.../transifex-live-integration-defaults.php | 157 +--
...ive-integration-generate-rewrite-rules.php | 324 ------
.../transifex-live-integration-javascript.php | 78 --
includes/transifex-live-integration-lib.php | 114 ---
.../transifex-live-integration-picker.php | 76 --
.../transifex-live-integration-prerender.php | 103 --
.../transifex-live-integration-rewrite.php | 480 ---------
...nsifex-live-integration-static-factory.php | 122 +++
...-live-integration-static-files-handler.php | 87 --
.../transifex-live-integration-subdomain.php | 81 --
includes/transifex-live-integration-util.php | 52 +
.../transifex-live-integration-validators.php | 74 --
...ransifex-live-integration-settings-page.js | 932 +++++++++---------
...fex-live-integration-transifex-settings.js | 38 +-
language_mapper.php | 52 -
parse_transifex_languages.php | 46 -
readme.md | 10 +-
readme.txt | 8 +-
regex_string_serial-deserial.php | 19 -
reverse_hard_link.php | 41 -
...ansifex-live-integration-settings-page.css | 80 +-
test | 737 --------------
tests/_support/AcceptanceTester.php | 3 +-
tests/_support/FunctionalTester.php | 3 +-
tests/_support/UnitTester.php | 3 +-
tests/unit/GenerateLanguageUrlMapTest.php | 67 +-
tests/unit/GenerateTokenizedUrlTest.php | 61 +-
tests/unit/PrerenderCheckTest.php | 139 +--
tests/unit/ReverseHardLinkTest.php | 16 +-
transifex-live-integration.php | 277 +++---
uninstall.php | 14 +-
50 files changed, 2917 insertions(+), 3573 deletions(-)
delete mode 100644 curl_and_get_header.php
delete mode 100644 hreflang_languages.php
delete mode 100644 includes/admin/transifex-live-integration-action-links.php
rename includes/admin/{transifex-live-integration-settings-template.php => transifex-live-integration-admin-template.php} (87%)
rename includes/admin/{transifex-live-integration-settings-util.php => transifex-live-integration-admin-util.php} (68%)
rename includes/admin/{transifex-live-integration-settings-page.php => transifex-live-integration-admin.php} (94%)
create mode 100644 includes/common/plugin-debug.php
create mode 100644 includes/common/transifex-live-integration-common.php
create mode 100644 includes/common/transifex-live-integration-static-files-handler.php
create mode 100644 includes/common/transifex-live-integration-validators.php
rename includes/{ => lib}/transifex-live-integration-hreflang.php (69%)
create mode 100644 includes/lib/transifex-live-integration-javascript.php
create mode 100644 includes/lib/transifex-live-integration-picker.php
create mode 100644 includes/lib/transifex-live-integration-prerender.php
create mode 100644 includes/lib/transifex-live-integration-rewrite.php
create mode 100644 includes/lib/transifex-live-integration-subdomain.php
create mode 100644 includes/override/transifex-live-integration-generate-rewrite-rules.php
delete mode 100644 includes/plugin-debug.php
delete mode 100644 includes/transifex-live-integration-generate-rewrite-rules.php
delete mode 100644 includes/transifex-live-integration-javascript.php
delete mode 100644 includes/transifex-live-integration-lib.php
delete mode 100644 includes/transifex-live-integration-picker.php
delete mode 100644 includes/transifex-live-integration-prerender.php
delete mode 100644 includes/transifex-live-integration-rewrite.php
create mode 100644 includes/transifex-live-integration-static-factory.php
delete mode 100644 includes/transifex-live-integration-static-files-handler.php
delete mode 100644 includes/transifex-live-integration-subdomain.php
create mode 100644 includes/transifex-live-integration-util.php
delete mode 100644 includes/transifex-live-integration-validators.php
delete mode 100644 language_mapper.php
delete mode 100644 parse_transifex_languages.php
delete mode 100644 regex_string_serial-deserial.php
delete mode 100644 reverse_hard_link.php
delete mode 100644 test
diff --git a/Gruntfile.js b/Gruntfile.js
index 4f22aacf..e59445ed 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,173 +1,175 @@
module.exports = function(grunt) {
- // Load multiple grunt tasks using globbing patterns
- require('load-grunt-tasks')(grunt);
+ // Load multiple grunt tasks using globbing patterns
+ require('load-grunt-tasks')(grunt);
- // Project configuration.
- grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
+ // Project configuration.
+ grunt.initConfig(
+ {
+ pkg: grunt.file.readJSON('package.json'),
- makepot: {
- target: {
- options: {
- domainPath: '/languages', // Where to save the POT file.
- exclude: ['build/.*'],
- mainFile: 'transifex-live-integration.php', // Main project file.
- potFilename: 'transifex-live-integration.pot', // Name of the POT file.
- potHeaders: {
- poedit: true, // Includes common Poedit headers.
- 'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
- },
- type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
- updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
- updatePoFiles: true, // Whether to update PO files in the same directory as the POT file.
- processPot: function(pot, options) {
- pot.headers['report-msgid-bugs-to'] = 'http://wp-translations.org/';
- pot.headers['last-translator'] = 'WP-Translations ';
- pot.headers['language-team'] = 'WP-Translations (http://wp-translations.org/)';
- pot.headers['language'] = 'en_US';
- var translation, // Exclude meta data from pot.
- excluded_meta = [
- 'Plugin Name of the plugin/theme',
- 'Plugin URI of the plugin/theme',
- 'Author of the plugin/theme',
- 'Author URI of the plugin/theme'
- ];
- for (translation in pot.translations['']) {
- if ('undefined' !== typeof pot.translations[''][translation].comments.extracted) {
- if (excluded_meta.indexOf(pot.translations[''][translation].comments.extracted) >= 0) {
- console.log('Excluded meta: ' + pot.translations[''][translation].comments.extracted);
- delete pot.translations[''][translation];
- }
- }
- }
- return pot;
- }
- }
- }
- },
+ makepot: {
+ target: {
+ options: {
+ domainPath: '/languages', // Where to save the POT file.
+ exclude: ['build/.*'],
+ mainFile: 'transifex-live-integration.php', // Main project file.
+ potFilename: 'transifex-live-integration.pot', // Name of the POT file.
+ potHeaders: {
+ poedit: true, // Includes common Poedit headers.
+ 'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
+ },
+ type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
+ updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
+ updatePoFiles: true, // Whether to update PO files in the same directory as the POT file.
+ processPot: function(pot, options) {
+ pot.headers['report-msgid-bugs-to'] = 'http://wp-translations.org/';
+ pot.headers['last-translator'] = 'WP-Translations ';
+ pot.headers['language-team'] = 'WP-Translations (http://wp-translations.org/)';
+ pot.headers['language'] = 'en_US';
+ var translation, // Exclude meta data from pot.
+ excluded_meta = [
+ 'Plugin Name of the plugin/theme',
+ 'Plugin URI of the plugin/theme',
+ 'Author of the plugin/theme',
+ 'Author URI of the plugin/theme'
+ ];
+ for (translation in pot.translations['']) {
+ if ('undefined' !== typeof pot.translations[''][translation].comments.extracted) {
+ if (excluded_meta.indexOf(pot.translations[''][translation].comments.extracted) >= 0) {
+ console.log('Excluded meta: ' + pot.translations[''][translation].comments.extracted);
+ delete pot.translations[''][translation];
+ }
+ }
+ }
+ return pot;
+ }
+ }
+ }
+ },
- checktextdomain: {
- options:{
- text_domain: 'transifex-live-integration', //Name of Your textdomain
- create_report_file: true,
- keywords: [
- '__:1,2d',
- '_e:1,2d',
- '_x:1,2c,3d',
- 'esc_html__:1,2d',
- 'esc_html_e:1,2d',
- 'esc_html_x:1,2c,3d',
- 'esc_attr__:1,2d',
- 'esc_attr_e:1,2d',
- 'esc_attr_x:1,2c,3d',
- '_ex:1,2c,3d',
- '_n:1,2,4d',
- '_nx:1,2,4c,5d',
- '_n_noop:1,2,3d',
- '_nx_noop:1,2,3c,4d',
- ' __ngettext:1,2,3d',
- '__ngettext_noop:1,2,3d',
- '_c:1,2d',
- '_nc:1,2,4c,5d'
- ]
- },
- files: {
- src: [
- '**/*.php', // Include all files
- '!node_modules/**', // Exclude node_modules/
- '!build/.*'// Exclude build/
- ],
- expand: true
- }
- },
+ checktextdomain: {
+ options:{
+ text_domain: 'transifex-live-integration', //Name of Your textdomain
+ create_report_file: true,
+ keywords: [
+ '__:1,2d',
+ '_e:1,2d',
+ '_x:1,2c,3d',
+ 'esc_html__:1,2d',
+ 'esc_html_e:1,2d',
+ 'esc_html_x:1,2c,3d',
+ 'esc_attr__:1,2d',
+ 'esc_attr_e:1,2d',
+ 'esc_attr_x:1,2c,3d',
+ '_ex:1,2c,3d',
+ '_n:1,2,4d',
+ '_nx:1,2,4c,5d',
+ '_n_noop:1,2,3d',
+ '_nx_noop:1,2,3c,4d',
+ ' __ngettext:1,2,3d',
+ '__ngettext_noop:1,2,3d',
+ '_c:1,2d',
+ '_nc:1,2,4c,5d'
+ ]
+ },
+ files: {
+ src: [
+ '**/*.php', // Include all files
+ '!node_modules/**', // Exclude node_modules/
+ '!build/.*'// Exclude build/
+ ],
+ expand: true
+ }
+ },
- exec: {
- npmUpdate: {
- command: 'npm update'
- },
- txpull: { // Pull Transifex translation - grunt exec:txpull
- cmd: 'tx pull -a -f --minimum-perc=100' // Change the percentage with --minimum-perc=yourvalue
- },
- txpush_s: { // Push pot to Transifex - grunt exec:txpush_s
- cmd: 'tx push -s'
- }
- },
+ exec: {
+ npmUpdate: {
+ command: 'npm update'
+ },
+ txpull: { // Pull Transifex translation - grunt exec:txpull
+ cmd: 'tx pull -a -f --minimum-perc=100' // Change the percentage with --minimum-perc=yourvalue
+ },
+ txpush_s: { // Push pot to Transifex - grunt exec:txpush_s
+ cmd: 'tx push -s'
+ }
+ },
- dirs: {
- lang: 'languages' // It should be languages or lang
- },
+ dirs: {
+ lang: 'languages' // It should be languages or lang
+ },
- potomo: {
- dist: {
- options: {
- poDel: false // Set to true if you want to erase the .po
- },
- files: [{
- expand: true,
- cwd: '<%= dirs.lang %>',
- src: ['*.po'],
- dest: '<%= dirs.lang %>',
- ext: '.mo',
- nonull: true
- }]
- }
- },
+ potomo: {
+ dist: {
+ options: {
+ poDel: false // Set to true if you want to erase the .po
+ },
+ files: [{
+ expand: true,
+ cwd: '<%= dirs.lang %>',
+ src: ['*.po'],
+ dest: '<%= dirs.lang %>',
+ ext: '.mo',
+ nonull: true
+ }]
+ }
+ },
- // Clean up build directory
- clean: {
- main: ['build/<%= pkg.name %>']
- },
+ // Clean up build directory
+ clean: {
+ main: ['build/<%= pkg.name %>']
+ },
- // Copy the theme into the build directory
- copy: {
- main: {
- src: [
- '**',
- '!node_modules/**',
- '!build/**',
- '!.git/**',
- '!Gruntfile.js',
- '!package.json',
- '!.gitignore',
- '!.gitmodules',
- '!.tx/**',
- '!**/Gruntfile.js',
- '!**/package.json',
- '!**/README.md',
- '!**/*~'
- ],
- dest: 'build/<%= pkg.name %>/'
- }
- },
+ // Copy the theme into the build directory
+ copy: {
+ main: {
+ src: [
+ '**',
+ '!node_modules/**',
+ '!build/**',
+ '!.git/**',
+ '!Gruntfile.js',
+ '!package.json',
+ '!.gitignore',
+ '!.gitmodules',
+ '!.tx/**',
+ '!**/Gruntfile.js',
+ '!**/package.json',
+ '!**/README.md',
+ '!**/*~'
+ ],
+ dest: 'build/<%= pkg.name %>/'
+ }
+ },
- // Compress build directory into .zip and -.zip
- compress: {
- main: {
- options: {
- mode: 'zip',
- archive: './build/<%= pkg.name %>.zip'
- },
- expand: true,
- cwd: 'build/<%= pkg.name %>/',
- src: ['**/*'],
- dest: '<%= pkg.name %>/'
- }
- }
- });
+ // Compress build directory into .zip and -.zip
+ compress: {
+ main: {
+ options: {
+ mode: 'zip',
+ archive: './build/<%= pkg.name %>.zip'
+ },
+ expand: true,
+ cwd: 'build/<%= pkg.name %>/',
+ src: ['**/*'],
+ dest: '<%= pkg.name %>/'
+ }
+ }
+ }
+ );
- // Default task. - grunt makepot
- grunt.registerTask('default', 'makepot');
+ // Default task. - grunt makepot
+ grunt.registerTask('default', 'makepot');
- // Checktextdomain and makepot task(s)
- grunt.registerTask('go-pot', ['checktextdomain', 'makepot', 'potomo']);
+ // Checktextdomain and makepot task(s)
+ grunt.registerTask('go-pot', ['checktextdomain', 'makepot', 'potomo']);
- // Makepot and push it on Transifex task(s).
- grunt.registerTask('tx-push', ['makepot', 'exec:txpush_s']);
+ // Makepot and push it on Transifex task(s).
+ grunt.registerTask('tx-push', ['makepot', 'exec:txpush_s']);
- // Pull from Transifex and create .mo task(s).
- grunt.registerTask('tx-pull', ['exec:txpull', 'potomo']);
+ // Pull from Transifex and create .mo task(s).
+ grunt.registerTask('tx-pull', ['exec:txpull', 'potomo']);
- // Build task(s).
- grunt.registerTask('build', ['clean', 'copy', 'compress']);
+ // Build task(s).
+ grunt.registerTask('build', ['clean', 'copy', 'compress']);
};
diff --git a/curl_and_get_header.php b/curl_and_get_header.php
deleted file mode 100644
index 393258d5..00000000
--- a/curl_and_get_header.php
+++ /dev/null
@@ -1,34 +0,0 @@
-
\ No newline at end of file
diff --git a/hreflang_languages.php b/hreflang_languages.php
deleted file mode 100644
index 4beb0592..00000000
--- a/hreflang_languages.php
+++ /dev/null
@@ -1,33 +0,0 @@
- "zh_CN","de_DE" => "de_DE","ko" => "ko"];
-
- $ret = [];
- $tokenized_url = str_replace( $lang , "%lang%", $raw_url, $count);
- if ($count !== 0) {
- foreach ($languages as $language) {
- $arr = [];
- $hreflang_code = $languages_map[$language];
- $language_url = str_replace( '%lang%', $hreflang_code, $tokenized_url );
- $arr['href'] = $language_url;
- $arr['hreflang'] = $hreflang_code;
- array_push($ret,$arr);
- }
- }
- eval(\Psy\sh());
- // $this->assertEquals($i['expected_source'],$source_string);
- // $this->assertEquals(ksort($i['expected_languages']),ksort($language_array));
-}
-
-}
-
-?>
\ No newline at end of file
diff --git a/includes/admin/transifex-live-integration-action-links.php b/includes/admin/transifex-live-integration-action-links.php
deleted file mode 100644
index 6b93d16d..00000000
--- a/includes/admin/transifex-live-integration-action-links.php
+++ /dev/null
@@ -1,15 +0,0 @@
- TRANSIFEX_LIVE_INTEGRATION_NAME ], admin_url( 'options-general.php' ) );
- $settings_text = __( 'Settings', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN );
- $settings_link = <<$settings_text
-SETTINGS;
- return array_merge( [ $settings_link ], $links );
- }
-
-}
diff --git a/includes/admin/transifex-live-integration-settings-template.php b/includes/admin/transifex-live-integration-admin-template.php
similarity index 87%
rename from includes/admin/transifex-live-integration-settings-template.php
rename to includes/admin/transifex-live-integration-admin-template.php
index 8cffffac..d0203645 100644
--- a/includes/admin/transifex-live-integration-settings-template.php
+++ b/includes/admin/transifex-live-integration-admin-template.php
@@ -25,6 +25,24 @@
+ SEO Prerendering
+
+
Advanced SEO Settings
This plugin lets you set unique, language/region-specific URLs for your site and tells search engines what language a page is in. This is done by creating new language subdirectories through the plugin, or by pointing to existing language subdomains. In all cases, the plugin will add the Transifex Live JavaScript snippet to your site.
Having trouble getting language/region-specific URLs working? Check out our additional troubleshooting tips!
-
@@ -85,8 +102,8 @@
-
-
+
+
diff --git a/includes/admin/transifex-live-integration-settings-util.php b/includes/admin/transifex-live-integration-admin-util.php
similarity index 68%
rename from includes/admin/transifex-live-integration-settings-util.php
rename to includes/admin/transifex-live-integration-admin-util.php
index 8b419f5f..9e98b4a1 100644
--- a/includes/admin/transifex-live-integration-settings-util.php
+++ b/includes/admin/transifex-live-integration-admin-util.php
@@ -1,6 +1,6 @@
TRANSIFEX_LIVE_INTEGRATION_NAME ], admin_url( 'options-general.php' ) );
+ $settings_text = __( 'Settings', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN );
+ $settings_link = <<$settings_text
+SETTINGS;
+ return array_merge( [ $settings_link ], $links );
+ }
+
+ /**
+ * Callback function for admin_menu action
+ */
+ static function admin_menu_hook()
+ {
+ Plugin_Debug::logTrace();
+ add_options_page('Transifex Live', 'Transifex Live', 'manage_options', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN, [ 'Transifex_Live_Integration_Admin', 'options_page' ] );
+ }
}
diff --git a/includes/admin/transifex-live-integration-settings-page.php b/includes/admin/transifex-live-integration-admin.php
similarity index 94%
rename from includes/admin/transifex-live-integration-settings-page.php
rename to includes/admin/transifex-live-integration-admin.php
index 3244edb8..a12b0b3c 100644
--- a/includes/admin/transifex-live-integration-settings-page.php
+++ b/includes/admin/transifex-live-integration-admin.php
@@ -1,8 +1,8 @@
logTrace();
+
+ // Check to see if plugin is in debug mode
+ // If not, skip all display handlers and custom error handling
+ if (self::$debug_mode ) {
+ set_error_handler(array( 'Plugin_Debug', 'logError' ));
+ // Check for admin level if not surpress all debug output hooks
+ //TODO: Reimplement admin check
+ if (true ) {
+ add_action('wp_footer', array( 'Plugin_Debug', 'printLog' ));
+ add_action('admin_footer', array( 'Plugin_Debug', 'printLog' ));
+ } // End if Wordpress user admin check
+ } // End if debug mode check
+ }
+
+ public static function logTrace( $message = null )
+ {
+ if (self::$debug_mode ) {
+ if (!is_array(self::$calls) ) {
+ self::$calls = array();
+ }
+ $call = debug_backtrace(false);
+ $call = (isset($call[1])) ? $call[1] : $call[0];
+ $call['message'] = $message;
+ array_push(self::$calls, $call);
+ }
+ }
+
+ public static function logError( $severity, $message, $filename, $lineno )
+ {
+ if (self::$debug_mode ) {
+ if (!is_array(self::$calls) ) {
+ self::$calls = array();
+ }
+ if (strpos($filename, 'transifex-live-integration') ) {
+ $call = debug_backtrace(false);
+ $call = (isset($call[2])) ? $call[2] : $call[1];
+ $call['message'] = 'Severity: '.$severity. ' File: ' . basename($filename) . ' Line: ' . $lineno . ': ' . $message;
+ array_push(self::$calls, $call);
+ }
+ }
+ }
+
+ public function printLog()
+ {
+ if (self::$debug_mode ) {
+ echo ('' . "\n");
+ echo ('
Plugin: Plugin Debug Mode Output ' . "\n");
+ array_walk(self::$calls, array( 'Plugin_Debug', 'printLogCallback' ));
+ echo "
";
+ }
+ }
+
+ static function printLogCallback( $value, $key )
+ {
+ if (self::$debug_mode ) {
+ echo "* ";
+ if (array_key_exists('file', $value) ) {
+ echo ("File: " . basename($value['file']) . " - ");
+ }
+ if (array_key_exists('line', $value) ) {
+ echo ('Line #: ' . $value['line'] . ' ');
+ }
+ echo " ";
+ if (array_key_exists('class', $value) ) {
+ echo ("Class: " . $value['class'] . " - ");
+ }
+ if (array_key_exists('function', $value) ) {
+ echo ('Function: ' . $value['function'] . ' ');
+ }
+ echo " ";
+ if (array_key_exists('type', $value) ) {
+ echo ("Type: ");
+ switch ($value['type']) {
+ case "::":
+ echo ("static method call");
+ break;
+ case "->" :
+ echo ("method call");
+ break;
+ default :
+ echo ("function call");
+ }
+ echo(" - ");
+ }
+ if (array_key_exists('args', $value) ) {
+ echo ('Parameters: ');
+ print_r($value['args']);
+ echo (' ');
+ }
+ echo " ";
+ if (array_key_exists('message', $value) && $value['message'] != null ) {
+ echo ('');
+ }
+ print_r($value['message']);
+ echo (' ');
+ echo " *";
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/includes/common/transifex-live-integration-common.php b/includes/common/transifex-live-integration-common.php
new file mode 100644
index 00000000..dd6a7ba9
--- /dev/null
+++ b/includes/common/transifex-live-integration-common.php
@@ -0,0 +1,132 @@
+ $v) {
+ $unslashed_url = str_replace('%lang%', $v, $trimmed_tokenized_url) . '/' . $trimmed_url;
+ $ret[$k] = rtrim($unslashed_url, '/') . '/';
+ }
+
+ return $ret;
+ }
+
+ /**
+ * This file is part of the array_column library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+ /**
+ * Returns the values from a single column of the input array, identified by
+ * the $columnKey.
+ *
+ * Optionally, you may provide an $indexKey to index the values in the returned
+ * array by the values from the $indexKey column in the input array.
+ *
+ * @param array $input A multi-dimensional array (record set) from which to pull a column of values.
+ * a column of values.
+ * @param mixed $columnKey The column of values to return. This value may be the
+ * integer key of the column you wish to retrieve, or it
+ * may be the string key name for an associative array.
+ * @param mixed $indexKey (Optional.) The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the string key name.
+ * the returned array. This value may be the integer key
+ * of the column, or it may be the string key name.
+ * @return array
+ */
+ static public function array_column( $input = null, $columnKey = null,
+ $indexKey = null
+ ) {
+ // Using func_get_args() in order to check for proper number of
+ // parameters and trigger errors exactly as the built-in array_column()
+ // does in PHP 5.5.
+ $argc = func_num_args();
+ $params = func_get_args();
+
+ if ($argc < 2 ) {
+ trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
+ return null;
+ }
+
+ if (!is_array($params[0]) ) {
+ trigger_error(
+ 'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', E_USER_WARNING
+ );
+ return null;
+ }
+
+ if (!is_int($params[1]) && !is_float($params[1]) && !is_string($params[1]) && $params[1] !== null && !(is_object($params[1]) && method_exists($params[1], '__toString'))
+ ) {
+ trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
+ return false;
+ }
+
+ if (isset($params[2]) && !is_int($params[2]) && !is_float($params[2]) && !is_string($params[2]) && !(is_object($params[2]) && method_exists($params[2], '__toString'))
+ ) {
+ trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
+ return false;
+ }
+
+ $paramsInput = $params[0];
+ $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
+
+ $paramsIndexKey = null;
+ if (isset($params[2]) ) {
+ if (is_float($params[2]) || is_int($params[2]) ) {
+ $paramsIndexKey = (int) $params[2];
+ } else {
+ $paramsIndexKey = (string) $params[2];
+ }
+ }
+
+ $resultArray = array();
+
+ foreach ($paramsInput as $row) {
+ $key = $value = null;
+ $keySet = $valueSet = false;
+
+ if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row) ) {
+ $keySet = true;
+ $key = (string) $row[$paramsIndexKey];
+ }
+
+ if ($paramsColumnKey === null ) {
+ $valueSet = true;
+ $value = $row;
+ } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row) ) {
+ $valueSet = true;
+ $value = $row[$paramsColumnKey];
+ }
+
+ if ($valueSet ) {
+ if ($keySet ) {
+ $resultArray[$key] = $value;
+ } else {
+ $resultArray[] = $value;
+ }
+ }
+ }
+
+ return $resultArray;
+ }
+
+}
diff --git a/includes/common/transifex-live-integration-static-files-handler.php b/includes/common/transifex-live-integration-static-files-handler.php
new file mode 100644
index 00000000..4b14c8f1
--- /dev/null
+++ b/includes/common/transifex-live-integration-static-files-handler.php
@@ -0,0 +1,94 @@
+css_files = array();
+ $this->js_files = array();
+ }
+
+ /**
+ * Adds a single css file to plugin
+ * @param string $version Current plugin version.
+ * @param string $url Url to static file (can be external).
+ * @param string $handle Identifier if it might be used previously, otherwise generate a random one.
+ * @return array Associatative array in a format that can be enqueued.
+ */
+ public function add_css_file( $version, $url, $handle = null )
+ {
+ if (null === $handle ) {
+ $length = 4;
+ $randomString = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length);
+ $handle = TRANSIFEX_LIVE_INTEGRATION_NAME . $randomString;
+ }
+ $arr = [ 'version' => $version, 'url' => $url, 'handle' => $handle ];
+ return array_push($this->css_files, $arr);
+ }
+
+ /**
+ * Adds a single js file to plugin
+ * @param string $version Current plugin version.
+ * @param string $url Url to static file (can be external).
+ * @param string $handle Identifier if it might be used previously, otherwise generate a random one.
+ * @return array Associatative array in a format that can be enqueued.
+ */
+ public function add_js_file( $version, $url, $handle = null )
+ {
+ if (null === $handle ) {
+ $length = 4;
+ $randomString = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length);
+ $handle = TRANSIFEX_LIVE_INTEGRATION_NAME . $randomString;
+ }
+ $arr = [ 'version' => $version, 'url' => $url, 'handle' => $handle ];
+ return array_push($this->js_files, $arr);
+ }
+
+ /**
+ * Renders css through enqueue
+ */
+ public function render_css()
+ {
+ Plugin_Debug::logTrace();
+ foreach ($this->css_files as $file) {
+ wp_enqueue_style($file['handle'], $file['url'], false, $file['version'], 'all');
+ }
+ }
+
+ /**
+ * Renders js through enqueue
+ */
+ public function render_js()
+ {
+ Plugin_Debug::logTrace();
+ foreach ($this->js_files as $file) {
+ wp_enqueue_script($file['handle'], $file['url'], false, $file['version'], 'all');
+ }
+ }
+
+}
diff --git a/includes/common/transifex-live-integration-validators.php b/includes/common/transifex-live-integration-validators.php
new file mode 100644
index 00000000..4064e878
--- /dev/null
+++ b/includes/common/transifex-live-integration-validators.php
@@ -0,0 +1,81 @@
+ substr_count($link, '/') ) { //Note: this will return for home urls wo the trailing slash
+ Plugin_Debug::logTrace('failed validator slash count');
+ return false;
+ }
+ return true;
+ }
+
+ static function is_rules_ok( $rules )
+ {
+ if (!self::is_ok($rules) ) {
+ Plugin_Debug::logTrace('failed validator');
+ return false;
+ }
+ if (!is_array($rules) ) {
+ Plugin_Debug::logTrace('failed validator is_array');
+ return false;
+ }
+ return true;
+ }
+
+ static function is_permalink_ok( $permalink )
+ {
+ return self::is_ok($permalink);
+ }
+
+ static function is_query_ok( $query )
+ {
+ if (!self::is_ok($query) ) {
+ Plugin_Debug::logTrace('failed validator');
+ return false;
+ }
+ $query_vars = (isset($query->query_vars)) ? $query->query_vars : false;
+ if (!self::is_query_vars_ok($query_vars) ) {
+ Plugin_Debug::logTrace('failed validator query vars');
+ return false;
+ }
+ return true;
+ }
+
+ static function is_query_vars_ok( $query_vars )
+ {
+ return self::is_ok($query_vars);
+ }
+
+ static function is_ok( $o )
+ {
+ if (!$o ) {
+ Plugin_Debug::logTrace('failed validator is_ok false');
+ return false;
+ }
+ if (!isset($o) ) {
+ Plugin_Debug::logTrace('failed validator is_ok not isset');
+ return false;
+ }
+ if (empty($o) ) {
+ Plugin_Debug::logTrace('failed validator is_ok empty');
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/includes/transifex-live-integration-hreflang.php b/includes/lib/transifex-live-integration-hreflang.php
similarity index 69%
rename from includes/transifex-live-integration-hreflang.php
rename to includes/lib/transifex-live-integration-hreflang.php
index abee77c8..585255a3 100644
--- a/includes/transifex-live-integration-hreflang.php
+++ b/includes/lib/transifex-live-integration-hreflang.php
@@ -1,5 +1,5 @@
tokenized_url = $settings['tokenized_url'];
}
- public function ok_to_add() {
- if ( !isset( $this->settings['api_key'] ) ) {
- Plugin_Debug::logTrace( 'settings[api_key] not set...skipping hreflang' );
- return false;
- }
- if ( !isset( $this->settings['languages'] ) ) {
- Plugin_Debug::logTrace( 'settings[languages] not set...skipping hreflang' );
- return false;
- }
- if ( $this->settings['url_options'] === '1' ) {
- Plugin_Debug::logTrace( 'settings[url_options] set to none...skipping hreflang' );
- return false;
- }
- if ( !isset( $this->settings['tokenized_url'] ) ) {
- Plugin_Debug::logTrace( 'settings[tokenized_url] not set...skipping hreflang' );
- return false;
- }
- return true;
- }
-
private function generate_languages_hreflang( $raw_url, $languages,
- $language_map ) {
+ $language_map
+ ) {
Plugin_Debug::logTrace();
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-picker.php';
- $url_map = Transifex_Live_Integration_Picker::generate_language_url_map( $raw_url, $this->tokenized_url, $language_map );
+ $url_map = Transifex_Live_Integration_Common::generate_language_url_map( $raw_url, $this->tokenized_url, $language_map );
$ret = [ ];
foreach ($languages as $language) {
$arr = [ ];
@@ -74,12 +54,11 @@ public function render_hreflang() {
Plugin_Debug::logTrace();
global $wp;
$lang = get_query_var( 'lang' );
- $raw_url = home_url( $wp->request );
$url_path = add_query_arg( array(), $wp->request );
$source_url_path = (substr( $url_path, 0, strlen( $lang ) ) === $lang) ? substr( $url_path, strlen( $lang ), strlen( $url_path ) ) : $url_path;
$source = $this->settings['source_language'];
$unslashed_source_url = site_url() . $source_url_path;
- $source_url = rtrim($unslashed_source_url, '/') . '/';
+ $source_url = rtrim( $unslashed_source_url, '/' ) . '/';
$hreflang_out = '';
$hreflang_out .= << \n
diff --git a/includes/lib/transifex-live-integration-javascript.php b/includes/lib/transifex-live-integration-javascript.php
new file mode 100644
index 00000000..2a5fed97
--- /dev/null
+++ b/includes/lib/transifex-live-integration-javascript.php
@@ -0,0 +1,90 @@
+live_settings['api_key'] = $settings['api_key'];
+ $this->lang = false;
+ $this->source_language = $settings['source_language'];
+ $this->language_map = $settings['language_map'];
+ }
+
+ function wp_hook() {
+ Plugin_Debug::logTrace();
+ $this->lang = self::lang_check(
+ get_query_var( 'lang' ), $this->source_language, $this->language_map
+ );
+ }
+
+ static function lang_check( $query_var, $source_language, $language_map ) {
+ Plugin_Debug::logTrace();
+ if ( !isset( $query_var ) || !isset( $source_language ) || !isset( $language_map ) ) {
+ Plugin_Debug::logTrace( 'lang_check params not set, defaulting to native lang detection' );
+ return false;
+ }
+
+ $lm = json_decode( $language_map, true )[0];
+ $lang = false;
+ if ( $query_var == $source_language ) {
+ $lang = $source_language;
+ Plugin_Debug::logTrace( 'lang is source, overriding live with source' );
+ } else {
+ $lang = array_search( $query_var, $lm );
+ if ( $lang ){
+ Plugin_Debug::logTrace( 'lang is set, overriding live detection' );
+ } else {
+ Plugin_Debug::logTrace( 'lang missing, defaulting to native detection' );
+ $lang = false;
+ }
+ }
+ return $lang;
+ }
+
+ /**
+ * Renders javascript includes in the page
+ */
+ function wp_head_hook() {
+ Plugin_Debug::logTrace();
+ $lang = $this->lang;
+ $live_settings = $this->live_settings;
+ if ( $lang ) {
+ $detectlang = << '%function%' ] );
+ $live_settings_json = json_encode( $live_settings );
+ $live_settings_string = str_replace( '"%function%"', $detectlang, $live_settings_json );
+ } else {
+ $live_settings_string = json_encode( $live_settings );
+ }
+
+ $snippet = <<window.liveSettings=$live_settings_string;
+\n
+SNIPPET;
+ echo $snippet;
+ }
+
+}
diff --git a/includes/lib/transifex-live-integration-picker.php b/includes/lib/transifex-live-integration-picker.php
new file mode 100644
index 00000000..9d0ca992
--- /dev/null
+++ b/includes/lib/transifex-live-integration-picker.php
@@ -0,0 +1,50 @@
+language_map = json_decode($language_map, true)[0];
+ $this->tokenized_url = $tokenized_url;
+ $this->enable_picker = $enable_picker;
+ $this->source_language = $source_language;
+ }
+
+
+ function render()
+ {
+ Plugin_Debug::logTrace();
+ global $wp;
+ $lang = get_query_var('lang');
+ $home_url = home_url($wp->request);
+ $url_path = add_query_arg(array(), $wp->request);
+ $source_url_path = (substr($url_path, 0, strlen($lang)) === $lang) ? substr($url_path, strlen($lang), strlen($url_path)) : $url_path;
+ $url_map = Transifex_Live_Integration_Common::generate_language_url_map($source_url_path, $this->tokenized_url, $this->language_map);
+ $unslashed_source_url = site_url() . $source_url_path;
+ $url_map[$this->source_language] = rtrim($unslashed_source_url, '/') . '/';
+ $string_url_map = json_encode($url_map, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
+
+ $include = <<
+ Transifex.live.onBeforeTranslatePage(function(params) {
+ var locale_urls = $string_url_map;
+ if(Transifex.live.ready === true && Transifex.live.getSelectedLanguageCode() !== params.lang_code){
+ params.noop = true;
+ window.location.href = locale_urls[params.lang_code];
+ }
+ });
+
+JSONP;
+ echo $include;
+ }
+
+}
diff --git a/includes/lib/transifex-live-integration-prerender.php b/includes/lib/transifex-live-integration-prerender.php
new file mode 100644
index 00000000..4ab33383
--- /dev/null
+++ b/includes/lib/transifex-live-integration-prerender.php
@@ -0,0 +1,88 @@
+prerender_url = $prerender_url;
+ }
+
+ function wp_head_hook()
+ {
+ Plugin_Debug::logTrace();
+ $status = '';
+ if (is_404() ) {
+ $status .= <<< STATUS
+ \n
+STATUS;
+ }
+ echo $status;
+ }
+
+ function wp_headers_hook( $headers )
+ {
+ Plugin_Debug::logTrace();
+ $headers['X-PreRender-Req'] = 'TRUE';
+ return $headers;
+ }
+
+ static public function prerender_check( $req_user_agent, $req_escaped_fragment,
+ $bot_types, $whitelist_names
+ ) {
+ Plugin_Debug::logTrace();
+
+ $bot_types_escaped = addcslashes($bot_types, '/');
+ $whitelist_names_escaped = addcslashes($whitelist_names, '/');
+
+ $is_bot = self::is_bot_type($req_user_agent, $bot_types_escaped);
+ $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name($req_user_agent, $whitelist_names_escaped);
+ $has_escaped_fragment = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
+ $prerender_ok = ($has_escaped_fragment) ? true : self::is_prerender_req();
+
+ return $prerender_ok;
+ }
+
+
+ function callback( $buffer )
+ {
+ global $wp;
+ $output = $buffer;
+ $page_url = home_url($wp->request);
+ $page_url = rtrim($page_url, '/') . '/';
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->prerender_url . $page_url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ $response = curl_exec($ch);
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $header = substr($response, 0, $header_size);
+ $body = substr($response, $header_size);
+ if ($response === false ) {
+ $error = curl_error($ch);
+ // write to db??
+ } else {
+ if (strpos($header, 'X-PreRender-Req: TRUE') ) {
+ $output = $body;
+ }
+ }
+ curl_close($ch);
+ return $output;
+ }
+
+ function after_setup_theme_hook()
+ {
+ ob_start([$this, 'callback' ]);
+ }
+
+ function shutdown_hook()
+ {
+ ob_end_flush();
+ }
+
+}
diff --git a/includes/lib/transifex-live-integration-rewrite.php b/includes/lib/transifex-live-integration-rewrite.php
new file mode 100644
index 00000000..150e1388
--- /dev/null
+++ b/includes/lib/transifex-live-integration-rewrite.php
@@ -0,0 +1,505 @@
+rewrite_options = [ ];
+ $this->languages_regex = $settings['languages_regex'];
+ $this->source_language = $settings['source_language'];
+ $this->languages_map = json_decode($settings['language_map'], true)[0];
+ $this->lang = false;
+ if (isset($rewrite_options['add_rewrites_post']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_post']) ? 'post' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_root']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_root']) ? 'root' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_date']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_date']) ? 'date' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_page']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_page']) ? 'page' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_author']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_author']) ? 'author' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_tag']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_tag']) ? 'tag' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_category']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_category']) ? 'category' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_search']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_search']) ? 'search' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_feed']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_feed']) ? 'feed' : '';
+ }
+ if (isset($rewrite_options['add_rewrites_feed']) ) {
+ $this->rewrite_options[] = ($rewrite_options['add_rewrites_permalink_tag']) ? 'permalink_tag' : '';
+ }
+ if (!empty($settings['languages']) ) {
+ $b = strpos(',', $settings['languages']);
+ if (false === $b ) {
+ $this->language_codes = array( $settings['languages'] );
+ } else {
+ $this->language_codes = explode(',', $settings['languages']);
+ }
+ }
+ }
+
+ function wp_hook() {
+ Plugin_Debug::logTrace();
+ $this->lang = get_query_var( 'lang' );
+ Plugin_Debug::logTrace($this->lang);
+ }
+
+ /**
+ * Callback function to the WP init hook
+ */
+ function init_hook()
+ {
+ Plugin_Debug::logTrace();
+ add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ }
+
+ /**
+ * Callback function to the WP parse_query hook
+ * @param array $query WP query object.
+ */
+ function parse_query_hook( $query )
+ {
+ if (!Transifex_Live_Integration_Validators::is_query_ok($query) ) {
+ return $query;
+ }
+ $qv = &$query->query_vars;
+ $qv['lang'] = isset($query->query_vars['lang']) ? $query->query_vars['lang'] : $this->source_language;
+ if ($query->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
+ $query->is_page = true;
+ $query->is_home = false;
+ $qv['page_id'] = get_option('page_on_front');
+ // Correct for page_on_front
+ if (!empty($qv['paged']) ) {
+ $qv['page'] = $qv['paged'];
+ unset($qv['paged']);
+ }
+ }
+ return $query;
+ }
+
+
+ static function reverse_hard_link( $lang, $link, $languages_map, $source_lang )
+ {
+ Plugin_Debug::logTrace();
+ if (empty($lang) ) {
+ return $link;
+ }
+ if (empty($languages_map) ) {
+ return $link;
+ }
+ $modified_link = $link;
+ $reverse_url = true;
+
+ $reverse_url = ($reverse_url) ? (isset($lang)) : false;
+
+ if (!empty($lang) ) {
+ $reverse_url = ($reverse_url) ? (!strpos($modified_link, $lang)) : false;
+ }
+ $reverse_url = ($reverse_url) ? (in_array($lang, $languages_map)) : false;
+ $reverse_url = ($reverse_url) ? (!($source_lang == $lang)) : false;
+
+ //TODO This can be dep'd
+ if ($reverse_url && (3 <= substr_count($link, '/')) ) {
+ $array_url = explode('/', $link);
+ $array_url[3] = $lang . '/' . $array_url[3];
+ $modified_link = implode('/', $array_url);
+ }
+ return $modified_link;
+ }
+ function pre_post_link_hook( $permalink, $post, $leavename )
+ {
+ if (!Transifex_Live_Integration_Validators::is_permalink_ok($permalink) ) {
+ return $permalink;
+ }
+ $lang = $this->lang;
+ $p = $permalink;
+ if ( $lang ) {
+ $p = ($this->source_language !== $lang) ? $lang . $permalink : $permalink;
+ }
+ return $p;
+ }
+
+
+ function term_link_hook( $termlink, $term, $taxonomy )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($termlink) ) {
+ return $termlink;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $termlink, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function post_link_hook( $permalink, $post, $leavename )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($permalink) ) {
+ return $permalink;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $permalink, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function post_type_archive_link_hook( $link, $post_type )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($link) ) {
+ return $link;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $link, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function day_link_hook( $daylink, $year, $month, $day )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($daylink) ) {
+ return $daylink;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $daylink, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function month_link_hook( $monthlink, $year, $month )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($monthlink) ) {
+ return $monthlink;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $monthlink, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function year_link_hook( $yearlink, $year )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($yearlink) ) {
+ return $yearlink;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $yearlink, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function page_link_hook( $link, $id, $sample )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($link) ) {
+ return $link;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $link, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ function home_url_hook( $url )
+ {
+ if (!Transifex_Live_Integration_Validators::is_hard_link_ok($url) ) {
+ return $url;
+ }
+ $retlink = $this->reverse_hard_link($this->lang, $url, $this->languages_map, $this->source_language);
+ return $retlink;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_post_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->permalink_structure;
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function post_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_post_permastruct();
+ $this->post_permastruct = $pp;
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_PERMALINK, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_date_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_date_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function date_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_date_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_DATE, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_page_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_page_permastruct();
+ $pp = '%lang%/' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function page_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%pagename%', '(.?.+?)', 'pagename=');
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_page_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_PAGES, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_author_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_author_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function author_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_author_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_AUTHORS, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_tag_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_tag_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function tag_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_tag_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_TAGS, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_category_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_category_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function category_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_category_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_CATEGORIES, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_search_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_search_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function search_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_page_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_SEARCH, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build page permastructs
+ */
+ function generate_feed_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ $p = $wp_rewrite->get_feed_permastruct();
+ $pp = '%lang%' . $p;
+ return $pp;
+ }
+
+ /**
+ * Callback function to the WP page_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function feed_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_feed_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_NONE, true, false, false, false);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+ /**
+ * Function to build 'all' = root permastructs
+ */
+ function generate_root_permastruct()
+ {
+ Plugin_Debug::logTrace();
+ global $wp_rewrite;
+ return '%lang%' . $wp_rewrite->root . '/';
+ }
+
+ /**
+ * Callback function to the WP root_rewrite_rules
+ * @param array $rules Associative array of rewrite rules in WP.
+ */
+ function root_rewrite_rules_hook( $rules )
+ {
+ if (!Transifex_Live_Integration_Validators::is_rules_ok($rules) ) {
+ return $rules;
+ }
+ global $wp_rewrite;
+ $wp_rewrite->add_rewrite_tag('%lang%', $this->languages_regex, 'lang=');
+ $pp = $this->generate_root_permastruct();
+ $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules($pp, EP_ROOT);
+ Plugin_Debug::logTrace($rr);
+ $rewrite = array_merge($rr, $rules);
+ return $rewrite;
+ }
+
+}
diff --git a/includes/lib/transifex-live-integration-subdomain.php b/includes/lib/transifex-live-integration-subdomain.php
new file mode 100644
index 00000000..198302b0
--- /dev/null
+++ b/includes/lib/transifex-live-integration-subdomain.php
@@ -0,0 +1,82 @@
+subdomain_pattern = '/' . html_entity_decode(str_replace('/', '\/', $settings['subdomain_pattern'])) . '/';
+ Plugin_Debug::logTrace($this->subdomain_pattern);
+ $this->source_language = $settings['source_language'];
+ if (!empty($settings['languages']) ) {
+ $b = strpos(',', $settings['languages']);
+ if (false === $b ) {
+ $this->language_codes = array( $settings['languages'] );
+ } else {
+ $this->language_codes = explode(',', $settings['languages']);
+ }
+ }
+ }
+
+ /**
+ * Factory function to create a rewrite object
+ * @param array $settings Associative array used to store plugin settings.
+ */
+ static function create_subdomains( $settings )
+ {
+ Plugin_Debug::logTrace();
+ if (!isset($settings['languages']) ) {
+ Plugin_Debug::logTrace('settings[languages] not set');
+ return false;
+ }
+
+ if ($settings['url_options'] != '2' ) {
+ Plugin_Debug::logTrace('settings[url_options] not subdomain');
+ return false;
+ }
+
+ return new Transifex_Live_Integration_Subdomain($settings);
+ }
+
+ /**
+ * Callback function to the WP parse_query hook
+ * @param array $query WP query object.
+ */
+ function parse_query_hook( $query )
+ {
+ $m = array();
+ if (preg_match($this->subdomain_pattern, site_url(), $m) ) {
+ $query->query_vars['lang'] = $m[1];
+ } else {
+ $query->query_vars['lang'] = $this->source_language;
+ }
+ return $query;
+ }
+
+}
diff --git a/includes/override/transifex-live-integration-generate-rewrite-rules.php b/includes/override/transifex-live-integration-generate-rewrite-rules.php
new file mode 100644
index 00000000..8a579b5c
--- /dev/null
+++ b/includes/override/transifex-live-integration-generate-rewrite-rules.php
@@ -0,0 +1,334 @@
+feeds as $feed_name) {
+ $feedregex2 .= $feed_name . '|';
+ }
+ $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
+ /*
+ * $feedregex is identical but with /feed/ added on as well, so URLs like /feed/atom
+ * and /atom are both possible
+ */
+ $feedregex = $wp_rewrite->feed_base . '/' . $feedregex2;
+ // Build a regex to match the trackback and page/xx parts of URLs.
+ $trackbackregex = 'trackback/?$';
+ $pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$';
+ $commentregex = $wp_rewrite->comments_pagination_base . '-([0-9]{1,})/?$';
+ $embedregex = 'embed/?$';
+ // Build up an array of endpoint regexes to append => queries to append.
+ if ($endpoints ) {
+ $ep_query_append = array();
+ foreach ((array) $wp_rewrite->endpoints as $endpoint) {
+ // Match everything after the endpoint name, but allow for nothing to appear there.
+ $epmatch = $endpoint[1] . '(/(.*))?/?$';
+ // This will be appended on to the rest of the query for each dir.
+ $epquery = '&' . $endpoint[2] . '=';
+ $ep_query_append[$epmatch] = array( $endpoint[0], $epquery );
+ }
+ }
+ // Get everything up to the first rewrite tag.
+ $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
+ // Build an array of the tags (note that said array ends up being in $tokens[0]).
+ preg_match_all('/%.+?%/', $permalink_structure, $tokens);
+ $num_tokens = count($tokens[0]);
+ $index = $wp_rewrite->index; //probably 'index.php'
+ $feedindex = $index;
+ $trackbackindex = $index;
+ $embedindex = $index;
+ /*
+ * Build a list from the rewritecode and queryreplace arrays, that will look something
+ * like tagname=$matches[i] where i is the current $i.
+ */
+ $queries = array();
+ for ($i = 0; $i < $num_tokens; ++$i) {
+ if (0 < $i ) {
+ $queries[$i] = $queries[$i - 1] . '&';
+ }
+ else {
+ $queries[$i] = '';
+ }
+ $query_token = str_replace($wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i]) . $wp_rewrite->preg_index($i + 1);
+ $queries[$i] .= $query_token;
+ }
+ // Get the structure, minus any cruft (stuff that isn't tags) at the front.
+ $structure = $permalink_structure;
+ if ($front != '/' ) {
+ $structure = str_replace($front, '', $structure);
+ }
+ /*
+ * Create a list of dirs to walk over, making rewrite rules for each level
+ * so for example, a $structure of /%year%/%monthnum%/%postname% would create
+ * rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
+ */
+ $structure = trim($structure, '/');
+ $dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
+ $num_dirs = count($dirs);
+ // Strip slashes from the front of $front.
+ $front = preg_replace('|^/+|', '', $front);
+ // The main workhorse loop.
+ $post_rewrite = array();
+ $struct = $front;
+ for ($j = 0; $j < $num_dirs; ++$j) {
+ // Get the struct for this dir, and trim slashes off the front.
+ $struct .= $dirs[$j] . '/'; // Accumulate. see comment near explode('/', $structure) above.
+ $struct = ltrim($struct, '/');
+ // Replace tags with regexes.
+ $match = str_replace($wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $struct);
+ Plugin_Debug::logTrace($match);
+ // Make a list of tags, and store how many there are in $num_toks.
+ $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
+ Plugin_Debug::logTrace($num_toks);
+ // Get the 'tagname=$matches[i]'.
+ $query = (!empty($num_toks) && isset($queries[$num_toks - 1]) ) ? $queries[$num_toks - 1] : '';
+ Plugin_Debug::logTrace($query);
+ // Set up $ep_mask_specific which is used to match more specific URL types.
+ switch ($dirs[$j]) {
+ case '%year%':
+ $ep_mask_specific = EP_YEAR;
+ break;
+ case '%monthnum%':
+ $ep_mask_specific = EP_MONTH;
+ break;
+ case '%day%':
+ $ep_mask_specific = EP_DAY;
+ break;
+ default:
+ $ep_mask_specific = EP_NONE;
+ }
+ // Create query for /page/xx.
+ $pagematch = $match . $pageregex;
+ $pagequery = $index . '?' . $query . '&paged=' . $wp_rewrite->preg_index($num_toks + 1);
+ // Create query for /comment-page-xx.
+ $commentmatch = $match . $commentregex;
+ $commentquery = $index . '?' . $query . '&cpage=' . $wp_rewrite->preg_index($num_toks + 1);
+ if (get_option('page_on_front') ) {
+ // Create query for Root /comment-page-xx.
+ $rootcommentmatch = $match . $commentregex;
+ $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option('page_on_front') . '&cpage=' . $wp_rewrite->preg_index($num_toks + 1);
+ }
+ // Create query for /feed/(feed|atom|rss|rss2|rdf).
+ $feedmatch = $match . $feedregex;
+ $feedquery = $feedindex . '?' . $query . '&feed=' . $wp_rewrite->preg_index($num_toks + 1);
+ // Create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex).
+ $feedmatch2 = $match . $feedregex2;
+ $feedquery2 = $feedindex . '?' . $query . '&feed=' . $wp_rewrite->preg_index($num_toks + 1);
+ // If asked to, turn the feed queries into comment feed ones.
+ if ($forcomments ) {
+ $feedquery .= '&withcomments=1';
+ $feedquery2 .= '&withcomments=1';
+ }
+ // Start creating the array of rewrites for this dir.
+ $rewrite = array();
+ // ...adding on /feed/ regexes => queries
+ if ($feed ) {
+ $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );
+ }
+ //...and /page/xx ones
+ if ($paged ) {
+ $rewrite = array_merge($rewrite, array( $pagematch => $pagequery ));
+ }
+ // Only on pages with comments add ../comment-page-xx/.
+ if (EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
+ $rewrite = array_merge($rewrite, array( $commentmatch => $commentquery ));
+ } elseif (EP_ROOT & $ep_mask && get_option('page_on_front') ) {
+ $rewrite = array_merge($rewrite, array( $rootcommentmatch => $rootcommentquery ));
+ }
+ // Do endpoints.
+ if ($endpoints ) {
+ foreach ((array) $ep_query_append as $regex => $ep) {
+ // Add the endpoints on if the mask fits.
+ if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) {
+ $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $wp_rewrite->preg_index($num_toks + 2);
+ }
+ }
+ }
+ // If we've got some tags in this dir.
+ if ($num_toks ) {
+ $post = false;
+ $page = false;
+ /*
+ * Check to see if this dir is permalink-level: i.e. the structure specifies an
+ * individual post. Do this by checking it contains at least one of 1) post name,
+ * 2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
+ * minute all present). Set these flags now as we need them for the endpoints.
+ */
+ if (strpos($struct, '%postname%') !== false || strpos($struct, '%post_id%') !== false || strpos($struct, '%pagename%') !== false || (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false)
+ ) {
+ $post = true;
+ if (strpos($struct, '%pagename%') !== false ) {
+ $page = true;
+ }
+ }
+ if (!$post ) {
+ // For custom post types, we need to add on endpoints as well.
+ foreach (get_post_types(array( '_builtin' => false )) as $ptype) {
+ if (strpos($struct, "%$ptype%") !== false ) {
+ $post = true;
+ // This is for page style attachment URLs.
+ $page = is_post_type_hierarchical($ptype);
+ break;
+ }
+ }
+ }
+ Plugin_Debug::logTrace('post check');
+ Plugin_Debug::logTrace($post);
+ // If creating rules for a permalink, do all the endpoints like attachments etc.
+ if ($post ) {
+ // Create query and regex for trackback.
+ $trackbackmatch = $match . $trackbackregex;
+ $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
+ // Create query and regex for embeds.
+ $embedmatch = $match . $embedregex;
+ $embedquery = $embedindex . '?' . $query . '&embed=true';
+ // Trim slashes from the end of the regex for this dir.
+ $match = rtrim($match, '/');
+ // Get rid of brackets.
+ $submatchbase_org = str_replace(array( '(', ')' ), '', $match);
+ $submatchbase = str_replace('(', '(?:', $match); // Replace with non capturing group
+ Plugin_Debug::logTrace($submatchbase_org);
+ Plugin_Debug::logTrace($submatchbase);
+ // Add a rule for at attachments, which take the form of /some-text.
+ $sub1 = $submatchbase . '/([^/]+)/';
+ // Add trackback regex /trackback/...
+ $sub1tb = $sub1 . $trackbackregex;
+ // And /feed/(atom|...)
+ $sub1feed = $sub1 . $feedregex;
+ // And /(feed|atom...)
+ $sub1feed2 = $sub1 . $feedregex2;
+ // And /comment-page-xx
+ $sub1comment = $sub1 . $commentregex;
+ // And /embed/...
+ $sub1embed = $sub1 . $embedregex;
+ /*
+ * Add another rule to match attachments in the explicit form:
+ * /attachment/some-text
+ */
+ $sub2 = $submatchbase . '/attachment/([^/]+)/';
+ // And add trackbacks /attachment/trackback.
+ $sub2tb = $sub2 . $trackbackregex;
+ // Feeds, /attachment/feed/(atom|...)
+ $sub2feed = $sub2 . $feedregex;
+ // And feeds again on to this /attachment/(feed|atom...)
+ $sub2feed2 = $sub2 . $feedregex2;
+ // And /comment-page-xx
+ $sub2comment = $sub2 . $commentregex;
+ // And /embed/...
+ $sub2embed = $sub2 . $embedregex;
+ // Create queries for these extra tag-ons we've just dealt with.
+ $subquery = $index . '?attachment=' . $wp_rewrite->preg_index(1);
+ $subtbquery = $subquery . '&tb=1';
+ $subfeedquery = $subquery . '&feed=' . $wp_rewrite->preg_index(2);
+ $subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index(2);
+ $subembedquery = $subquery . '&embed=true';
+ // Do endpoints for attachments.
+ if (!empty($endpoints) ) {
+ foreach ((array) $ep_query_append as $regex => $ep) {
+ if ($ep[0] & EP_ATTACHMENT ) {
+ $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $wp_rewrite->preg_index(3);
+ $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $wp_rewrite->preg_index(3);
+ }
+ }
+ }
+ /*
+ * Now we've finished with endpoints, finish off the $sub1 and $sub2 matches
+ * add a ? as we don't have to match that last slash, and finally a $ so we
+ * match to the end of the URL
+ */
+ $sub1 .= '?$';
+ $sub2 .= '?$';
+ /*
+ * Post pagination, e.g. /2/
+ * Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
+ * When cast to int, returned 0.
+ */
+ $match = $match . '(?:/([0-9]+))?/?$';
+ $query = $index . '?' . $query . '&page=' . $wp_rewrite->preg_index($num_toks + 1);
+ // Not matching a permalink so this is a lot simpler.
+ } else {
+ // Close the match and finalise the query.
+ $match .= '?$';
+ $query = $index . '?' . $query;
+ }
+ /*
+ * Create the final array for this dir by joining the $rewrite array (which currently
+ * only contains rules/queries for trackback, pages etc) to the main regex/query for
+ * this dir
+ */
+ $rewrite = array_merge($rewrite, array( $match => $query ));
+ // If we're matching a permalink, add those extras (attachments etc) on.
+ if ($post ) {
+ // Add trackback.
+ $rewrite = array_merge(array( $trackbackmatch => $trackbackquery ), $rewrite);
+ // Add embed.
+ $rewrite = array_merge(array( $embedmatch => $embedquery ), $rewrite);
+ // Add regexes/queries for attachments, attachment trackbacks and so on.
+ if (!$page ) {
+ // Require /attachment/stuff form for pages because of confusion with subpages.
+ $rewrite = array_merge(
+ $rewrite, array(
+ $sub1 => $subquery,
+ $sub1tb => $subtbquery,
+ $sub1feed => $subfeedquery,
+ $sub1feed2 => $subfeedquery,
+ $sub1comment => $subcommentquery,
+ $sub1embed => $subembedquery
+ )
+ );
+ }
+ $rewrite = array_merge(array( $sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery, $sub2embed => $subembedquery ), $rewrite);
+ }
+ }
+ // Add the rules for this dir to the accumulating $post_rewrite.
+ $post_rewrite = array_merge($rewrite, $post_rewrite);
+ }
+ // The finished rules. phew!
+ return $post_rewrite;
+ }
+
+}
diff --git a/includes/plugin-debug.php b/includes/plugin-debug.php
deleted file mode 100644
index 60729ff0..00000000
--- a/includes/plugin-debug.php
+++ /dev/null
@@ -1,114 +0,0 @@
-logTrace();
-
- // Check to see if plugin is in debug mode
- // If not, skip all display handlers and custom error handling
- if ( self::$debug_mode ) {
- set_error_handler( array( 'Plugin_Debug', 'logError' ) );
- // Check for admin level if not surpress all debug output hooks
- //TODO: Reimplement admin check
- if ( true ) {
- add_action( 'wp_footer', array( 'Plugin_Debug', 'printLog' ) );
- add_action( 'admin_footer', array( 'Plugin_Debug', 'printLog' ) );
- } // End if Wordpress user admin check
- } // End if debug mode check
- }
-
- public static function logTrace( $message = null ) {
- if ( self::$debug_mode ) {
- if ( !is_array( self::$calls ) ){
- self::$calls = array();
- }
- $call = debug_backtrace( false );
- $call = (isset( $call[1] )) ? $call[1] : $call[0];
- $call['message'] = $message;
- array_push( self::$calls, $call );
- }
- }
-
- public static function logError( $severity, $message, $filename, $lineno ) {
- if ( self::$debug_mode ) {
- if ( !is_array( self::$calls ) ){
- self::$calls = array();
- }
- if ( strpos( $filename, 'transifex-live-integration' ) ) {
- $call = debug_backtrace( false );
- $call = (isset( $call[2] )) ? $call[2] : $call[1];
- $call['message'] = 'Severity: '.$severity. ' File: ' . basename( $filename ) . ' Line: ' . $lineno . ': ' . $message;
- array_push( self::$calls, $call );
- }
- }
- }
-
- public function printLog() {
- if ( self::$debug_mode ) {
- echo ('' . "\n");
- echo ('
Plugin: Plugin Debug Mode Output ' . "\n");
- array_walk( self::$calls, array( 'Plugin_Debug', 'printLogCallback' ) );
- echo "";
- }
- }
-
- static function printLogCallback( $value, $key ) {
- if ( self::$debug_mode ) {
- echo "* ";
- if ( array_key_exists( 'file', $value ) )
- echo ("File: " . basename( $value['file'] ) . " - ");
- if ( array_key_exists( 'line', $value ) )
- echo ('Line #: ' . $value['line'] . ' ');
- echo " ";
- if ( array_key_exists( 'class', $value ) )
- echo ("Class: " . $value['class'] . " - ");
- if ( array_key_exists( 'function', $value ) )
- echo ('Function: ' . $value['function'] . ' ');
- echo " ";
- if ( array_key_exists( 'type', $value ) ) {
- echo ("Type: ");
- switch ($value['type']) {
- case "::":
- echo ("static method call");
- break;
- case "->" :
- echo ("method call");
- break;
- default :
- echo ("function call");
- }
- echo(" - ");
- }
- if ( array_key_exists( 'args', $value ) ) {
- echo ('Parameters: ');
- print_r( $value['args'] );
- echo (' ');
- }
- echo " ";
- if ( array_key_exists( 'message', $value ) && $value['message'] != null ){
- echo ('');
- }
- print_r( $value['message'] );
- echo (' ');
- echo " *";
- }
- }
-
-}
\ No newline at end of file
diff --git a/includes/transifex-live-integration-defaults.php b/includes/transifex-live-integration-defaults.php
index 586fb7c4..c67efd56 100644
--- a/includes/transifex-live-integration-defaults.php
+++ b/includes/transifex-live-integration-defaults.php
@@ -8,84 +8,91 @@
/**
* Static class for settings defaults
*/
-class Transifex_Live_Integration_Defaults {
+class Transifex_Live_Integration_Defaults
+{
- static function options_values() {
- 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
- ];
- }
+ static function options_values()
+ {
+ 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
+ ];
+ }
- 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];
- }
+ 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];
+ }
- 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 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() {
- 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' => '[]',
- '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' => '',
- 'whitelist_crawlers' =>
- 'googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard',
- 'generic_bot_types' => 'bot|crawl|slurp|spider'
- );
- }
+ /**
+ * Static function for settings defaults
+ * @return array Returns the settings array
+ */
+ static function settings()
+ {
+ 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' => '[]',
+ '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' => '',
+ 'enable_prerender' => false,
+ 'prerender_url' => '',
+ 'whitelist_crawlers' =>
+ 'googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard',
+ 'generic_bot_types' => 'bot|crawl|slurp|spider'
+ );
+ }
}
diff --git a/includes/transifex-live-integration-generate-rewrite-rules.php b/includes/transifex-live-integration-generate-rewrite-rules.php
deleted file mode 100644
index e6773c7f..00000000
--- a/includes/transifex-live-integration-generate-rewrite-rules.php
+++ /dev/null
@@ -1,324 +0,0 @@
-feeds as $feed_name)
- $feedregex2 .= $feed_name . '|';
- $feedregex2 = '(' . trim( $feedregex2, '|' ) . ')/?$';
- /*
- * $feedregex is identical but with /feed/ added on as well, so URLs like /feed/atom
- * and /atom are both possible
- */
- $feedregex = $wp_rewrite->feed_base . '/' . $feedregex2;
- // Build a regex to match the trackback and page/xx parts of URLs.
- $trackbackregex = 'trackback/?$';
- $pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$';
- $commentregex = $wp_rewrite->comments_pagination_base . '-([0-9]{1,})/?$';
- $embedregex = 'embed/?$';
- // Build up an array of endpoint regexes to append => queries to append.
- if ( $endpoints ) {
- $ep_query_append = array();
- foreach ((array) $wp_rewrite->endpoints as $endpoint) {
- // Match everything after the endpoint name, but allow for nothing to appear there.
- $epmatch = $endpoint[1] . '(/(.*))?/?$';
- // This will be appended on to the rest of the query for each dir.
- $epquery = '&' . $endpoint[2] . '=';
- $ep_query_append[$epmatch] = array( $endpoint[0], $epquery );
- }
- }
- // Get everything up to the first rewrite tag.
- $front = substr( $permalink_structure, 0, strpos( $permalink_structure, '%' ) );
- // Build an array of the tags (note that said array ends up being in $tokens[0]).
- preg_match_all( '/%.+?%/', $permalink_structure, $tokens );
- $num_tokens = count( $tokens[0] );
- $index = $wp_rewrite->index; //probably 'index.php'
- $feedindex = $index;
- $trackbackindex = $index;
- $embedindex = $index;
- /*
- * Build a list from the rewritecode and queryreplace arrays, that will look something
- * like tagname=$matches[i] where i is the current $i.
- */
- $queries = array();
- for ($i = 0; $i < $num_tokens; ++$i) {
- if ( 0 < $i )
- $queries[$i] = $queries[$i - 1] . '&';
- else
- $queries[$i] = '';
- $query_token = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i] ) . $wp_rewrite->preg_index( $i + 1 );
- $queries[$i] .= $query_token;
- }
- // Get the structure, minus any cruft (stuff that isn't tags) at the front.
- $structure = $permalink_structure;
- if ( $front != '/' )
- $structure = str_replace( $front, '', $structure );
- /*
- * Create a list of dirs to walk over, making rewrite rules for each level
- * so for example, a $structure of /%year%/%monthnum%/%postname% would create
- * rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
- */
- $structure = trim( $structure, '/' );
- $dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure );
- $num_dirs = count( $dirs );
- // Strip slashes from the front of $front.
- $front = preg_replace( '|^/+|', '', $front );
- // The main workhorse loop.
- $post_rewrite = array();
- $struct = $front;
- for ($j = 0; $j < $num_dirs; ++$j) {
- // Get the struct for this dir, and trim slashes off the front.
- $struct .= $dirs[$j] . '/'; // Accumulate. see comment near explode('/', $structure) above.
- $struct = ltrim( $struct, '/' );
- // Replace tags with regexes.
- $match = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $struct );
- Plugin_Debug::logTrace( $match );
- // Make a list of tags, and store how many there are in $num_toks.
- $num_toks = preg_match_all( '/%.+?%/', $struct, $toks );
- Plugin_Debug::logTrace( $num_toks );
- // Get the 'tagname=$matches[i]'.
- $query = (!empty( $num_toks ) && isset( $queries[$num_toks - 1] ) ) ? $queries[$num_toks - 1] : '';
- Plugin_Debug::logTrace( $query );
- // Set up $ep_mask_specific which is used to match more specific URL types.
- switch ($dirs[$j]) {
- case '%year%':
- $ep_mask_specific = EP_YEAR;
- break;
- case '%monthnum%':
- $ep_mask_specific = EP_MONTH;
- break;
- case '%day%':
- $ep_mask_specific = EP_DAY;
- break;
- default:
- $ep_mask_specific = EP_NONE;
- }
- // Create query for /page/xx.
- $pagematch = $match . $pageregex;
- $pagequery = $index . '?' . $query . '&paged=' . $wp_rewrite->preg_index( $num_toks + 1 );
- // Create query for /comment-page-xx.
- $commentmatch = $match . $commentregex;
- $commentquery = $index . '?' . $query . '&cpage=' . $wp_rewrite->preg_index( $num_toks + 1 );
- if ( get_option( 'page_on_front' ) ) {
- // Create query for Root /comment-page-xx.
- $rootcommentmatch = $match . $commentregex;
- $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option( 'page_on_front' ) . '&cpage=' . $wp_rewrite->preg_index( $num_toks + 1 );
- }
- // Create query for /feed/(feed|atom|rss|rss2|rdf).
- $feedmatch = $match . $feedregex;
- $feedquery = $feedindex . '?' . $query . '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 );
- // Create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex).
- $feedmatch2 = $match . $feedregex2;
- $feedquery2 = $feedindex . '?' . $query . '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 );
- // If asked to, turn the feed queries into comment feed ones.
- if ( $forcomments ) {
- $feedquery .= '&withcomments=1';
- $feedquery2 .= '&withcomments=1';
- }
- // Start creating the array of rewrites for this dir.
- $rewrite = array();
- // ...adding on /feed/ regexes => queries
- if ( $feed ) {
- $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );
- }
- //...and /page/xx ones
- if ( $paged ) {
- $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) );
- }
- // Only on pages with comments add ../comment-page-xx/.
- if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
- $rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) );
- } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) {
- $rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) );
- }
- // Do endpoints.
- if ( $endpoints ) {
- foreach ((array) $ep_query_append as $regex => $ep) {
- // Add the endpoints on if the mask fits.
- if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific )
- $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 );
- }
- }
- // If we've got some tags in this dir.
- if ( $num_toks ) {
- $post = false;
- $page = false;
- /*
- * Check to see if this dir is permalink-level: i.e. the structure specifies an
- * individual post. Do this by checking it contains at least one of 1) post name,
- * 2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
- * minute all present). Set these flags now as we need them for the endpoints.
- */
- if ( strpos( $struct, '%postname%' ) !== false || strpos( $struct, '%post_id%' ) !== false || strpos( $struct, '%pagename%' ) !== false || (strpos( $struct, '%year%' ) !== false && strpos( $struct, '%monthnum%' ) !== false && strpos( $struct, '%day%' ) !== false && strpos( $struct, '%hour%' ) !== false && strpos( $struct, '%minute%' ) !== false && strpos( $struct, '%second%' ) !== false)
- ) {
- $post = true;
- if ( strpos( $struct, '%pagename%' ) !== false )
- $page = true;
- }
- if ( !$post ) {
- // For custom post types, we need to add on endpoints as well.
- foreach (get_post_types( array( '_builtin' => false ) ) as $ptype) {
- if ( strpos( $struct, "%$ptype%" ) !== false ) {
- $post = true;
- // This is for page style attachment URLs.
- $page = is_post_type_hierarchical( $ptype );
- break;
- }
- }
- }
- Plugin_Debug::logTrace( 'post check' );
- Plugin_Debug::logTrace( $post );
- // If creating rules for a permalink, do all the endpoints like attachments etc.
- if ( $post ) {
- // Create query and regex for trackback.
- $trackbackmatch = $match . $trackbackregex;
- $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
- // Create query and regex for embeds.
- $embedmatch = $match . $embedregex;
- $embedquery = $embedindex . '?' . $query . '&embed=true';
- // Trim slashes from the end of the regex for this dir.
- $match = rtrim( $match, '/' );
- // Get rid of brackets.
- $submatchbase_org = str_replace( array( '(', ')' ), '', $match );
- $submatchbase = str_replace( '(', '(?:', $match ); // Replace with non capturing group
- Plugin_Debug::logTrace( $submatchbase_org );
- Plugin_Debug::logTrace( $submatchbase );
- // Add a rule for at attachments, which take the form of /some-text.
- $sub1 = $submatchbase . '/([^/]+)/';
- // Add trackback regex /trackback/...
- $sub1tb = $sub1 . $trackbackregex;
- // And /feed/(atom|...)
- $sub1feed = $sub1 . $feedregex;
- // And /(feed|atom...)
- $sub1feed2 = $sub1 . $feedregex2;
- // And /comment-page-xx
- $sub1comment = $sub1 . $commentregex;
- // And /embed/...
- $sub1embed = $sub1 . $embedregex;
- /*
- * Add another rule to match attachments in the explicit form:
- * /attachment/some-text
- */
- $sub2 = $submatchbase . '/attachment/([^/]+)/';
- // And add trackbacks /attachment/trackback.
- $sub2tb = $sub2 . $trackbackregex;
- // Feeds, /attachment/feed/(atom|...)
- $sub2feed = $sub2 . $feedregex;
- // And feeds again on to this /attachment/(feed|atom...)
- $sub2feed2 = $sub2 . $feedregex2;
- // And /comment-page-xx
- $sub2comment = $sub2 . $commentregex;
- // And /embed/...
- $sub2embed = $sub2 . $embedregex;
- // Create queries for these extra tag-ons we've just dealt with.
- $subquery = $index . '?attachment=' . $wp_rewrite->preg_index( 1 );
- $subtbquery = $subquery . '&tb=1';
- $subfeedquery = $subquery . '&feed=' . $wp_rewrite->preg_index( 2 );
- $subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 );
- $subembedquery = $subquery . '&embed=true';
- // Do endpoints for attachments.
- if ( !empty( $endpoints ) ) {
- foreach ((array) $ep_query_append as $regex => $ep) {
- if ( $ep[0] & EP_ATTACHMENT ) {
- $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $wp_rewrite->preg_index( 3 );
- $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $wp_rewrite->preg_index( 3 );
- }
- }
- }
- /*
- * Now we've finished with endpoints, finish off the $sub1 and $sub2 matches
- * add a ? as we don't have to match that last slash, and finally a $ so we
- * match to the end of the URL
- */
- $sub1 .= '?$';
- $sub2 .= '?$';
- /*
- * Post pagination, e.g. /2/
- * Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
- * When cast to int, returned 0.
- */
- $match = $match . '(?:/([0-9]+))?/?$';
- $query = $index . '?' . $query . '&page=' . $wp_rewrite->preg_index( $num_toks + 1 );
- // Not matching a permalink so this is a lot simpler.
- } else {
- // Close the match and finalise the query.
- $match .= '?$';
- $query = $index . '?' . $query;
- }
- /*
- * Create the final array for this dir by joining the $rewrite array (which currently
- * only contains rules/queries for trackback, pages etc) to the main regex/query for
- * this dir
- */
- $rewrite = array_merge( $rewrite, array( $match => $query ) );
- // If we're matching a permalink, add those extras (attachments etc) on.
- if ( $post ) {
- // Add trackback.
- $rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite );
- // Add embed.
- $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite );
- // Add regexes/queries for attachments, attachment trackbacks and so on.
- if ( !$page ) {
- // Require /attachment/stuff form for pages because of confusion with subpages.
- $rewrite = array_merge( $rewrite, array(
- $sub1 => $subquery,
- $sub1tb => $subtbquery,
- $sub1feed => $subfeedquery,
- $sub1feed2 => $subfeedquery,
- $sub1comment => $subcommentquery,
- $sub1embed => $subembedquery
- ) );
- }
- $rewrite = array_merge( array( $sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery, $sub2embed => $subembedquery ), $rewrite );
- }
- }
- // Add the rules for this dir to the accumulating $post_rewrite.
- $post_rewrite = array_merge( $rewrite, $post_rewrite );
- }
- // The finished rules. phew!
- return $post_rewrite;
- }
-
-}
diff --git a/includes/transifex-live-integration-javascript.php b/includes/transifex-live-integration-javascript.php
deleted file mode 100644
index 3e634457..00000000
--- a/includes/transifex-live-integration-javascript.php
+++ /dev/null
@@ -1,78 +0,0 @@
-live_settings_keys as $k) {
- $this->live_settings[$k] = $settings[$k];
- }
- $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'];
- }
-
- /**
- * Renders javascript includes in the page
- */
- function render() {
- Plugin_Debug::logTrace();
- $this->is_detectlang ? Plugin_Debug::logTrace( "overriding detectlang" ) : Plugin_Debug::logTrace( "skipped detectlang override" );
- if ( $this->is_detectlang ) {
- $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" );
- if ( !$check_for_standard_lang ) {
- Plugin_Debug::logTrace( "Not a standard lang override" );
- $detectlang = <<live_settings = array_merge( $this->live_settings, array( 'detectlang' => '%function%' ) );
- }
- }
- $live_settings_string = json_encode( $this->live_settings );
- if ( isset( $detectlang ) ) {
- $live_settings_string = str_replace( '"%function%"', $detectlang, $live_settings_string );
- }
-
- $include = <<window.liveSettings=$live_settings_string;
-\n
-LIVE;
- echo $include;
- }
-
-}
diff --git a/includes/transifex-live-integration-lib.php b/includes/transifex-live-integration-lib.php
deleted file mode 100644
index 9f8d420b..00000000
--- a/includes/transifex-live-integration-lib.php
+++ /dev/null
@@ -1,114 +0,0 @@
-language_map = json_decode( $language_map, true )[0];
- $this->tokenized_url = $tokenized_url;
- $this->enable_picker = $enable_picker;
- $this->source_language = $source_language;
- }
-
- static function create_picker( $settings ) {
- Plugin_Debug::logTrace();
- if ( !isset( $settings['enable_picker'] ) ) {
- Plugin_Debug::logTrace( 'settings[enable_picker] not set' );
- return false;
- }
- if ( !($settings['enable_picker']) ) {
- Plugin_Debug::logTrace( 'settings[enable_picker] not truthy' );
- return false;
- }
- if ( !isset( $settings['tokenized_url'] ) || !( $settings['tokenized_url'] ) ) {
- Plugin_Debug::logTrace( 'settings[tokenized_url] not set and not truthy' );
- return false;
- }
- return new Transifex_Live_Integration_Picker( $settings['language_map'], $settings['tokenized_url'], $settings['enable_picker'], $settings['source_language'] );
- }
-
- static function generate_language_url_map( $raw_url, $tokenized_url,
- $language_map ) {
- Plugin_Debug::logTrace();
- $trimmed_tokenized_url = rtrim( $tokenized_url, '/' );
- $trimmed_url = ltrim( $raw_url, '/' );
- $ret = [ ];
- foreach ($language_map as $k => $v) {
- $unslashed_url = str_replace( '%lang%', $v, $trimmed_tokenized_url ) . '/' . $trimmed_url;
- $ret[$k] = rtrim($unslashed_url, '/') . '/';
- }
-
- return $ret;
- }
-
- function render() {
- Plugin_Debug::logTrace();
- global $wp;
- $lang = get_query_var( 'lang' );
- $home_url = home_url( $wp->request );
- $url_path = add_query_arg( array(), $wp->request );
- $source_url_path = (substr( $url_path, 0, strlen( $lang ) ) === $lang) ? substr( $url_path, strlen( $lang ), strlen( $url_path ) ) : $url_path;
- $url_map = $this->generate_language_url_map( $source_url_path, $this->tokenized_url, $this->language_map );
- $unslashed_source_url = site_url() . $source_url_path;
- $url_map[$this->source_language] = rtrim($unslashed_source_url, '/') . '/';
- $string_url_map = json_encode( $url_map, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
-
- $include = <<
- Transifex.live.onBeforeTranslatePage(function(params) {
- var locale_urls = $string_url_map;
- if(Transifex.live.ready === true && Transifex.live.getSelectedLanguageCode() !== params.lang_code){
- params.noop = true;
- window.location.href = locale_urls[params.lang_code];
- }
- });
-
-JSONP;
- echo $include;
- }
-
-}
diff --git a/includes/transifex-live-integration-prerender.php b/includes/transifex-live-integration-prerender.php
deleted file mode 100644
index e4054240..00000000
--- a/includes/transifex-live-integration-prerender.php
+++ /dev/null
@@ -1,103 +0,0 @@
- 0) : false;
- }
-
- static public function is_bot_type( $agent, $bot_types ) {
- Plugin_Debug::logTrace();
- return !empty( $agent ) ? (preg_match( "/{$bot_types}/i", $agent ) > 0) : false;
- }
-
- static public function is_prerender_req() {
- $req_user_agent = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
- $ret = (strpos( $req_user_agent, 'prerender' )) ? true : false;
- Plugin_Debug::logTrace( $req_user_agent );
- Plugin_Debug::logTrace( $ret );
- return $ret;
- }
-
- function wp_head_hook() {
- Plugin_Debug::logTrace();
- $status = '';
- if ( is_404() ) {
- $status .= <<< STATUS
- \n
-STATUS;
- }
- echo $status;
- }
-
- function wp_headers_hook( $headers ) {
- Plugin_Debug::logTrace();
- $headers['X-PreRender-Req'] = 'TRUE';
- return $headers;
- }
-
- static public function prerender_check( $req_user_agent, $req_escaped_fragment,
- $bot_types, $whitelist_names ) {
- Plugin_Debug::logTrace();
-
- $bot_types_escaped = addcslashes( $bot_types, '/' );
- $whitelist_names_escaped = addcslashes( $whitelist_names, '/' );
-
- $is_bot = self::is_bot_type( $req_user_agent, $bot_types_escaped );
- $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names_escaped );
- $has_escaped_fragment = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
- $prerender_ok = ($has_escaped_fragment) ? true : self::is_prerender_req();
-
- return $prerender_ok;
- }
-
- static function create_prerender( $settings ) {
- Plugin_Debug::logTrace();
- $req_user_agent = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
- $req_escaped_fragment = (isset( $_GET['_escaped_fragment_'] )) ? $_GET['_escaped_fragment_'] : false;
-
- $check = self::prerender_check( $req_user_agent, $req_escaped_fragment, $settings['generic_bot_types'], $settings['whitelist_crawlers'] );
- return ($check) ? new Transifex_Live_Integration_Prerender( ) : false;
- }
-
- function callback( $buffer ) {
- global $wp;
- $output = $buffer;
- $page_url = home_url( $wp->request );
- $page_url = rtrim( $page_url, '/' ) . '/';
-
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, 'http://secure-refuge-63401.herokuapp.com/' . $page_url );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
- curl_setopt( $ch, CURLOPT_HEADER, 1 );
- $response = curl_exec( $ch );
- $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
- $header = substr( $response, 0, $header_size );
- $body = substr( $response, $header_size );
- if ( $response === false ) {
- $error = curl_error( $ch );
- // write to db??
- } else {
- if ( strpos( $header, 'X-PreRender-Req: TRUE' ) ) {
- $output = $body;
- }
- }
- curl_close( $ch );
- return $output;
- }
-
- function after_setup_theme_hook() {
- ob_start( [$this, 'callback' ] );
- }
-
- function shutdown_hook() {
- ob_end_flush();
- }
-
-}
diff --git a/includes/transifex-live-integration-rewrite.php b/includes/transifex-live-integration-rewrite.php
deleted file mode 100644
index f85dbba0..00000000
--- a/includes/transifex-live-integration-rewrite.php
+++ /dev/null
@@ -1,480 +0,0 @@
-rewrite_options = [ ];
- $this->languages_regex = $settings['languages_regex'];
- $this->source_language = $settings['source_language'];
- $this->languages_map = json_decode( $settings['language_map'], true )[0];
- if ( isset( $rewrite_options['add_rewrites_post'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_post']) ? 'post' : '';
- if ( isset( $rewrite_options['add_rewrites_root'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_root']) ? 'root' : '';
- if ( isset( $rewrite_options['add_rewrites_date'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_date']) ? 'date' : '';
- if ( isset( $rewrite_options['add_rewrites_page'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_page']) ? 'page' : '';
- if ( isset( $rewrite_options['add_rewrites_author'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_author']) ? 'author' : '';
- if ( isset( $rewrite_options['add_rewrites_tag'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_tag']) ? 'tag' : '';
- if ( isset( $rewrite_options['add_rewrites_category'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_category']) ? 'category' : '';
- if ( isset( $rewrite_options['add_rewrites_search'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_search']) ? 'search' : '';
- if ( isset( $rewrite_options['add_rewrites_feed'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_feed']) ? 'feed' : '';
- if ( isset( $rewrite_options['add_rewrites_feed'] ) )
- $this->rewrite_options[] = ($rewrite_options['add_rewrites_permalink_tag']) ? 'permalink_tag' : '';
- if ( !empty( $settings['languages'] ) ) {
- $b = strpos( ',', $settings['languages'] );
- if ( false === $b ) {
- $this->language_codes = array( $settings['languages'] );
- } else {
- $this->language_codes = explode( ',', $settings['languages'] );
- }
- }
- }
-
- /**
- * Factory function to create a rewrite object
- * @param array $settings Associative array used to store plugin settings.
- */
- static function create_rewrite( $settings, $rewrite_options ) {
- Plugin_Debug::logTrace();
- if ( !isset( $settings['languages'] ) ) {
- Plugin_Debug::logTrace( 'settings[languages] not set' );
- return false;
- }
- if ( !isset( $settings['languages_regex'] ) ) {
- Plugin_Debug::logTrace( 'settings[languages_regex] not set' );
- return false;
- }
-
- if ( $settings['url_options'] != '3' ) {
- Plugin_Debug::logTrace( 'settings[url_options] not subdirectory' );
- return false;
- }
-
- if ( !preg_match( self::REGEX_PATTERN_CHECK_PATTERN, $settings['languages_regex'] ) ) {
- Plugin_Debug::logTrace( 'settings[languages_regex] failed pattern check' );
- return false;
- }
- return new Transifex_Live_Integration_Rewrite( $settings, $rewrite_options );
- }
-
- /**
- * Callback function to the WP init hook
- */
- function init_hook() {
- Plugin_Debug::logTrace();
- add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- }
-
- /**
- * Callback function to the WP parse_query hook
- * @param array $query WP query object.
- */
- function parse_query_hook( $query ) {
- if ( !Transifex_Live_Integration_Validators::is_query_ok( $query ) ) {
- return $query;
- }
- $qv = &$query->query_vars;
- $qv['lang'] = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : $this->source_language;
- if ( $query->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
- $query->is_page = true;
- $query->is_home = false;
- $qv['page_id'] = get_option( 'page_on_front' );
- // Correct for page_on_front
- if ( !empty( $qv['paged'] ) ) {
- $qv['page'] = $qv['paged'];
- unset( $qv['paged'] );
- }
- }
- return $query;
- }
-
- function pre_post_link_hook( $permalink, $post, $leavename ) {
- if ( !Transifex_Live_Integration_Validators::is_permalink_ok( $permalink ) ) {
- return $permalink;
- }
- $p = $permalink;
- if ( get_query_var( 'lang', false ) ) {
- $p = ($this->source_language !== get_query_var( 'lang' )) ? get_query_var( 'lang' ) . $permalink : $permalink;
- }
- return $p;
- }
-
- static function reverse_hard_link( $lang, $link, $languages_map, $source_lang ) {
- Plugin_Debug::logTrace();
- if (empty($lang)) {
- return $link;
- }
- if (empty($languages_map)) {
- return $link;
- }
- $modified_link = $link;
- $reverse_url = true;
-
- $reverse_url = ($reverse_url) ? (isset( $lang )) : false;
-
- if ( !empty( $lang ) ) {
- $reverse_url = ($reverse_url) ? (!strpos( $modified_link, $lang )) : false;
- }
- $reverse_url = ($reverse_url) ? (in_array( $lang, $languages_map )) : false;
- $reverse_url = ($reverse_url) ? (!($source_lang == $lang)) : false;
-
- //TODO This can be dep'd
- if ( $reverse_url && (3 <= substr_count( $link, '/' )) ) {
- $array_url = explode( '/', $link );
- $array_url[3] = $lang . '/' . $array_url[3];
- $modified_link = implode( '/', $array_url );
- }
- return $modified_link;
- }
-
- function term_link_hook( $termlink, $term, $taxonomy ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $termlink ) ) {
- return $termlink;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $termlink, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function post_link_hook( $permalink, $post, $leavename ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $permalink ) ) {
- return $permalink;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $permalink, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function post_type_archive_link_hook( $link, $post_type ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $link ) ) {
- return $link;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $link, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function day_link_hook( $daylink, $year, $month, $day ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $daylink ) ) {
- return $daylink;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $daylink, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function month_link_hook( $monthlink, $year, $month ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $monthlink ) ) {
- return $monthlink;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $monthlink, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function year_link_hook( $yearlink, $year ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $yearlink ) ) {
- return $yearlink;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $yearlink, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function page_link_hook( $link, $id, $sample ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $link ) ) {
- return $link;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $link, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- function home_url_hook( $url ) {
- if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $url ) ) {
- return $url;
- }
- $retlink = $this->reverse_hard_link( get_query_var( 'lang' ), $url, $this->languages_map, $this->source_language );
- return $retlink;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_post_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->permalink_structure;
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function post_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_post_permastruct();
- $this->post_permastruct = $pp;
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_PERMALINK, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_date_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_date_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function date_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_date_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_DATE, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_page_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_page_permastruct();
- $pp = '%lang%/' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function page_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_page_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_PAGES, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_author_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_author_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function author_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_author_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_AUTHORS, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_tag_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_tag_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function tag_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_tag_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_TAGS, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_category_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_category_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function category_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_category_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_CATEGORIES, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_search_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_search_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function search_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_page_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_SEARCH, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build page permastructs
- */
- function generate_feed_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- $p = $wp_rewrite->get_feed_permastruct();
- $pp = '%lang%' . $p;
- return $pp;
- }
-
- /**
- * Callback function to the WP page_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function feed_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_feed_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_NONE, true, false, false, false );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
- /**
- * Function to build 'all' = root permastructs
- */
- function generate_root_permastruct() {
- Plugin_Debug::logTrace();
- global $wp_rewrite;
- return '%lang%' . $wp_rewrite->root . '/';
- }
-
- /**
- * Callback function to the WP root_rewrite_rules
- * @param array $rules Associative array of rewrite rules in WP.
- */
- function root_rewrite_rules_hook( $rules ) {
- if ( !Transifex_Live_Integration_Validators::is_rules_ok( $rules ) ) {
- return $rules;
- }
- global $wp_rewrite;
- $wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
- $pp = $this->generate_root_permastruct();
- $rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_ROOT );
- Plugin_Debug::logTrace( $rr );
- $rewrite = array_merge( $rr, $rules );
- return $rewrite;
- }
-
-}
diff --git a/includes/transifex-live-integration-static-factory.php b/includes/transifex-live-integration-static-factory.php
new file mode 100644
index 00000000..1efef5e4
--- /dev/null
+++ b/includes/transifex-live-integration-static-factory.php
@@ -0,0 +1,122 @@
+css_files = array();
- $this->js_files = array();
- }
-
- /**
- * Adds a single css file to plugin
- * @param string $version Current plugin version.
- * @param string $url Url to static file (can be external).
- * @param string $handle Identifier if it might be used previously, otherwise generate a random one.
- * @return array Associatative array in a format that can be enqueued.
- */
- public function add_css_file( $version, $url, $handle = null ) {
- if ( null === $handle ) {
- $length = 4;
- $randomString = substr( str_shuffle( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ), 0, $length );
- $handle = TRANSIFEX_LIVE_INTEGRATION_NAME . $randomString;
- }
- $arr = [ 'version' => $version, 'url' => $url, 'handle' => $handle ];
- return array_push( $this->css_files, $arr );
- }
-
- /**
- * Adds a single js file to plugin
- * @param string $version Current plugin version.
- * @param string $url Url to static file (can be external).
- * @param string $handle Identifier if it might be used previously, otherwise generate a random one.
- * @return array Associatative array in a format that can be enqueued.
- */
- public function add_js_file( $version, $url, $handle = null ) {
- if ( null === $handle ) {
- $length = 4;
- $randomString = substr( str_shuffle( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ), 0, $length );
- $handle = TRANSIFEX_LIVE_INTEGRATION_NAME . $randomString;
- }
- $arr = [ 'version' => $version, 'url' => $url, 'handle' => $handle ];
- return array_push( $this->js_files, $arr );
- }
-
- /**
- * Renders css through enqueue
- */
- public function render_css() {
- Plugin_Debug::logTrace();
- foreach ( $this->css_files as $file ) {
- wp_enqueue_style( $file['handle'], $file['url'], false, $file['version'], 'all' );
- }
- }
-
- /**
- * Renders js through enqueue
- */
- public function render_js() {
- Plugin_Debug::logTrace();
- foreach ( $this->js_files as $file ) {
- wp_enqueue_script( $file['handle'], $file['url'], false, $file['version'], 'all' );
- }
- }
-
-}
diff --git a/includes/transifex-live-integration-subdomain.php b/includes/transifex-live-integration-subdomain.php
deleted file mode 100644
index 136ffb27..00000000
--- a/includes/transifex-live-integration-subdomain.php
+++ /dev/null
@@ -1,81 +0,0 @@
-subdomain_pattern = '/'.html_entity_decode(str_replace('/','\/',$settings['subdomain_pattern'])) . '/';
- Plugin_Debug::logTrace($this->subdomain_pattern);
- $this->source_language = $settings['source_language'];
- if ( ! empty($settings['languages'] )) {
- $b = strpos( ',', $settings['languages'] );
- if ( false === $b ) {
- $this->language_codes = array( $settings['languages'] );
- } else {
- $this->language_codes = explode( ',', $settings['languages'] );
- }
- }
- }
-
- /**
- * Factory function to create a rewrite object
- * @param array $settings Associative array used to store plugin settings.
- */
- static function create_subdomains( $settings ) {
- Plugin_Debug::logTrace();
- if ( !isset( $settings['languages'] ) ) {
- Plugin_Debug::logTrace( 'settings[languages] not set' );
- return false;
- }
-
- if ( $settings['url_options'] != '2' ) {
- Plugin_Debug::logTrace( 'settings[url_options] not subdomain' );
- return false;
- }
-
- return new Transifex_Live_Integration_Subdomain( $settings );
- }
-
- /**
- * Callback function to the WP parse_query hook
- * @param array $query WP query object.
- */
- function parse_query_hook( $query ) {
- Plugin_Debug::logTrace();
- $m = array();
- if (preg_match($this->subdomain_pattern,site_url(),$m)){
- $query->query_vars['lang'] = $m[1];
- } else {
- $query->query_vars['lang'] = $this->source_language;
- }
- return $query;
- }
-
-
-}
diff --git a/includes/transifex-live-integration-util.php b/includes/transifex-live-integration-util.php
new file mode 100644
index 00000000..0138f945
--- /dev/null
+++ b/includes/transifex-live-integration-util.php
@@ -0,0 +1,52 @@
+ 0) : false;
+ }
+
+ static function get_user_agent() {
+ Plugin_Debug::logTrace();
+ return (isset( $_SERVER['HTTP_USER_AGENT'] )) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : false;
+ }
+
+ static function is_bot_type( $agent, $bot_types ) {
+ Plugin_Debug::logTrace();
+ return !empty( $agent ) ? (preg_match( "/{$bot_types}/i", $agent ) > 0) : false;
+ }
+
+ static function is_prerender_req( $agent ) {
+ Plugin_Debug::logTrace();
+ $ret = (strpos( $agent, 'prerender' )) ? true : false;
+ return $ret;
+ }
+
+ static function prerender_check( $req_user_agent, $req_escaped_fragment,
+ $bot_types, $whitelist_names
+ ) {
+ Plugin_Debug::logTrace();
+
+ $bot_types_escaped = addcslashes( $bot_types, '/' );
+ $whitelist_names_escaped = addcslashes( $whitelist_names, '/' );
+
+ $is_bot = self::is_bot_type( $req_user_agent, $bot_types_escaped );
+ $is_whitelisted = ($is_bot) ? true : self::is_whitelist_name( $req_user_agent, $whitelist_names_escaped );
+ $has_escaped_fragment = ($is_whitelisted) ? true : ($req_escaped_fragment) ? true : false;
+ $prerender_ok = ($has_escaped_fragment) ? true : self::is_prerender_req( self::get_user_agent() );
+
+ return $prerender_ok;
+ }
+
+}
diff --git a/includes/transifex-live-integration-validators.php b/includes/transifex-live-integration-validators.php
deleted file mode 100644
index 69fab45c..00000000
--- a/includes/transifex-live-integration-validators.php
+++ /dev/null
@@ -1,74 +0,0 @@
- substr_count( $link, '/' ) ) { //Note: this will return for home urls wo the trailing slash
- Plugin_Debug::logTrace( 'failed validator slash count' );
- return false;
- }
- return true;
- }
-
- static function is_rules_ok( $rules ) {
- if ( !self::is_ok( $rules ) ) {
- Plugin_Debug::logTrace( 'failed validator' );
- return false;
- }
- if ( !is_array( $rules ) ) {
- Plugin_Debug::logTrace( 'failed validator is_array' );
- return false;
- }
- return true;
- }
-
- static function is_permalink_ok( $permalink ) {
- return self::is_ok( $permalink );
- }
-
- static function is_query_ok( $query ) {
- if ( !self::is_ok( $query ) ) {
- Plugin_Debug::logTrace( 'failed validator' );
- return false;
- }
- $query_vars = (isset( $query->query_vars )) ? $query->query_vars : false;
- if ( !self::is_query_vars_ok( $query_vars ) ) {
- Plugin_Debug::logTrace( 'failed validator query vars' );
- return false;
- }
- return true;
- }
-
- static function is_query_vars_ok( $query_vars ) {
- return self::is_ok( $query_vars );
- }
-
- static function is_ok( $o ) {
- if ( !$o ) {
- Plugin_Debug::logTrace( 'failed validator is_ok false' );
- return false;
- }
- if ( !isset( $o ) ) {
- Plugin_Debug::logTrace( 'failed validator is_ok not isset' );
- return false;
- }
- if ( empty( $o ) ) {
- Plugin_Debug::logTrace( 'failed validator is_ok empty' );
- return false;
- }
- return true;
- }
-
-}
diff --git a/javascript/transifex-live-integration-settings-page.js b/javascript/transifex-live-integration-settings-page.js
index 1f3b8101..b9cf7e1f 100755
--- a/javascript/transifex-live-integration-settings-page.js
+++ b/javascript/transifex-live-integration-settings-page.js
@@ -19,10 +19,12 @@ function transifex_live_integration_map_update(tl) {
var local_lm = [];
var arr = {};
// loop through transifex languages
- jQuery.each(t, function (i, s) {
- var l = jQuery('#transifex-integration-live-' + s).val();
- arr[s] = l;
- });
+ jQuery.each(
+ t, function (i, s) {
+ var l = jQuery('#transifex-integration-live-' + s).val();
+ arr[s] = l;
+ }
+ );
local_lm.push(arr);
jQuery('#transifex_live_settings_language_map').val(JSON.stringify(local_lm));
return true;
@@ -38,15 +40,17 @@ function transifex_live_integration_convert(l) {
language_lookup = [];
language_map = [];
var arrr = {};
- jQuery.each(t, function (i, o) {
- h.push(transifex_live_integration_mapper(o));
- transifex_languages.push(o['code']);
- var arr = {};
- arr['tx_name'] = o['tx_name'];
- arr['code'] = o['code'];
- language_lookup.push(arr);
- arrr[o['code']] = o['code'];
- });
+ jQuery.each(
+ t, function (i, o) {
+ h.push(transifex_live_integration_mapper(o));
+ transifex_languages.push(o['code']);
+ var arr = {};
+ arr['tx_name'] = o['tx_name'];
+ arr['code'] = o['code'];
+ language_lookup.push(arr);
+ arrr[o['code']] = o['code'];
+ }
+ );
language_map.push(arrr);
var s = {
caption: 'Source:' + l['source']['tx_name'],
@@ -65,23 +69,29 @@ function transifex_live_integration_convert(l) {
function transifexLanguages() {
var apikey = jQuery('#transifex_live_settings_api_key').val();
if (apikey != '') {
- jQuery.ajax({
- url: "https://cdn.transifex.com/" + apikey + "/latest/languages.jsonp",
- jsonpCallback: "transifex_languages",
- jsonp: true,
- dataType: "jsonp",
- timeout: 3000
- }).done(function (data) {
- if (data['translation'] != undefined && data['translation'].length > 0) {
- globaldata = data;
- transifex_language_fields = transifex_live_integration_convert(data);
- jQuery('#transifex_live_settings_api_key').trigger('success');
- } else {
- jQuery('#transifex_live_settings_api_key').trigger('notranslation');
+ jQuery.ajax(
+ {
+ url: "https://cdn.transifex.com/" + apikey + "/latest/languages.jsonp",
+ jsonpCallback: "transifex_languages",
+ jsonp: true,
+ dataType: "jsonp",
+ timeout: 3000
}
- }).fail(function () {
- jQuery('#transifex_live_settings_api_key').trigger('error');
- });
+ ).done(
+ function (data) {
+ if (data['translation'] != undefined && data['translation'].length > 0) {
+ globaldata = data;
+ transifex_language_fields = transifex_live_integration_convert(data);
+ jQuery('#transifex_live_settings_api_key').trigger('success');
+ } else {
+ jQuery('#transifex_live_settings_api_key').trigger('notranslation');
+ }
+ }
+ ).fail(
+ function () {
+ jQuery('#transifex_live_settings_api_key').trigger('error');
+ }
+ );
} else {
jQuery('#transifex_live_settings_api_key').trigger('blank');
}
@@ -95,43 +105,61 @@ function addTransifexLanguages(obj) {
var myName = '';
var myId = '';
var tl = JSON.parse(jQuery('#transifex_live_settings_transifex_languages').val());
- jQuery.each(obj, function (i, o) {
- myName = 'transifex-integration-live-' + o.code;
- myId = 'transifex-integration-live-' + o.code;
- jQuery('#transifex_live_language_map_table').append(jQuery('#transifex_live_language_map_template').clone().show().addClass('cloned-language-map').each(function (ii, oo) {
- jQuery(oo).find('span.tx-language').text(o.tx_name);
- jQuery(oo).find('input.tx-code').attr('id', myId).attr('name', myName).val(lm[0][o.code]);
- }));
- });
+ jQuery.each(
+ obj, function (i, o) {
+ myName = 'transifex-integration-live-' + o.code;
+ myId = 'transifex-integration-live-' + o.code;
+ jQuery('#transifex_live_language_map_table').append(
+ jQuery('#transifex_live_language_map_template').clone().show().addClass('cloned-language-map').each(
+ function (ii, oo) {
+ jQuery(oo).find('span.tx-language').text(o.tx_name);
+ jQuery(oo).find('input.tx-code').attr('id', myId).attr('name', myName).val(lm[0][o.code]);
+ }
+ )
+ );
+ }
+ );
- jQuery.each(obj, function (i, o) {
- jQuery('#transifex-integration-live-' + o.code).machine({defaultState: {onEnter: function () {
+ jQuery.each(
+ obj, function (i, o) {
+ jQuery('#transifex-integration-live-' + o.code).machine(
+ {defaultState: {onEnter: function () {
transifex_live_integration_map_update(tl);
},
- events: {change: 'defaultState'}}, });
- });
+ events: {change: 'defaultState'}}, }
+ );
+ }
+ );
} else {
var tlslm = JSON.parse(jQuery('#transifex_live_settings_language_map').val());
language_map = (tlslm.length < 1) ? language_map : [];
- jQuery.each(transifex_language_fields['html'], function (i, o) {
- jQuery('#transifex_live_language_map_table').append(jQuery('#transifex_live_language_map_template').clone().show().addClass('cloned-language-map').each(function () {
- jQuery(this).find('span.tx-language').text(o.caption);
- if (tlslm.length < 1) {
- jQuery(this).find('input.tx-code').attr('id', o.id).attr('name', o.name).val(o.value);
- } else {
- jQuery(this).find('input.tx-code').attr('id', o.id).attr('name', o.name).val(tlslm[0][o.value]);
- var e = {};
- e[o.value] = tlslm[0][o.value];
- language_map.push(e);
- }
- jQuery(this).machine({defaultState: {onEnter: function () {
- transifex_live_integration_map_update();
- },
- events: {change: 'defaultState'}}, });
- }));
- });
+ jQuery.each(
+ transifex_language_fields['html'], function (i, o) {
+ jQuery('#transifex_live_language_map_table').append(
+ jQuery('#transifex_live_language_map_template').clone().show().addClass('cloned-language-map').each(
+ function () {
+ jQuery(this).find('span.tx-language').text(o.caption);
+ if (tlslm.length < 1) {
+ jQuery(this).find('input.tx-code').attr('id', o.id).attr('name', o.name).val(o.value);
+ } else {
+ jQuery(this).find('input.tx-code').attr('id', o.id).attr('name', o.name).val(tlslm[0][o.value]);
+ var e = {};
+ e[o.value] = tlslm[0][o.value];
+ language_map.push(e);
+ }
+ jQuery(this).machine(
+ {defaultState: {onEnter: function () {
+ transifex_live_integration_map_update();
+ },
+ events: {change: 'defaultState'}}, }
+ );
+ }
+ )
+ );
+ }
+ );
jQuery('#transifex_live_settings_source_language').val(source_language);
jQuery('#transifex_live_settings_transifex_languages').val(JSON.stringify(transifex_languages));
jQuery('#transifex_live_settings_language_lookup').val(JSON.stringify(language_lookup));
@@ -145,429 +173,453 @@ function updateTransifexSettingsFields(obj) {
}
(function ($) {
- $('#transifex_live_languages').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('#transifex_live_languages:defaultState:onEnter');
- ($('#transifex_live_settings_language_lookup').val() !== '') ? this.trigger('render') : this.trigger('wait');
+ $('#transifex_live_languages').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_languages:defaultState:onEnter');
+ ($('#transifex_live_settings_language_lookup').val() !== '') ? this.trigger('render') : this.trigger('wait');
- },
- events: {render: 'render', wait: 'wait'}
- },
- wait: {
- onEnter: function () {
- $.log.debug('#transifex_live_languages:wait:onEnter');
- },
- events: {load: 'loadnew'}
- },
- loadnew: {
- onEnter: function () {
- $.log.debug('#transifex_live_languages:load:onEnter');
- $("#transifex_live_languages_message").toggleClass('hide-if-js', true);
- $(".cloned-language-map").remove();
- addTransifexLanguages();
- },
- events: {load: 'loadnew'}
- },
- render: {
- onEnter: function () {
- $.log.debug('#transifex_live_languages:render:onEnter');
- $("#transifex_live_languages_message").toggleClass('hide-if-js', true);
- var obj = jQuery.parseJSON(jQuery('#transifex_live_settings_language_lookup').val());
- myobj = obj;
- addTransifexLanguages(obj);
- },
- events: {load: 'loadnew'}
- }
- }, {setClass: true});
+ },
+ events: {render: 'render', wait: 'wait'}
+ },
+ wait: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_languages:wait:onEnter');
+ },
+ events: {load: 'loadnew'}
+ },
+ loadnew: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_languages:load:onEnter');
+ $("#transifex_live_languages_message").toggleClass('hide-if-js', true);
+ $(".cloned-language-map").remove();
+ addTransifexLanguages();
+ },
+ events: {load: 'loadnew'}
+ },
+ render: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_languages:render:onEnter');
+ $("#transifex_live_languages_message").toggleClass('hide-if-js', true);
+ var obj = jQuery.parseJSON(jQuery('#transifex_live_settings_language_lookup').val());
+ myobj = obj;
+ addTransifexLanguages(obj);
+ },
+ events: {load: 'loadnew'}
+ }
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('#transifex_live_settings_api_key_button').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key_button::defaultState::onEnter');
- ($('#transifex_live_settings_api_key').val() !== '') ? this.trigger('hidden') : this.trigger('wait');
- },
- events: {wait: 'wait', hidden: 'hidden'}
- },
- wait: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key_button::wait::onEnter');
- this.show();
- this.attr('disabled', false);
- },
- events: {click: 'checking'}
- },
- checking: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key_button::checking::onEnter');
- $('#transifex_live_settings_api_key').trigger('validating');
- this.attr('disabled', true);
- },
- events: {wait: 'wait', hidden: 'hidden'}
- },
- hidden: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key_button::hidden::onEnter');
- this.hide();
- },
- events: {wait: 'wait'}
- }
- }, {setClass: true});
+ $('#transifex_live_settings_api_key_button').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key_button::defaultState::onEnter');
+ ($('#transifex_live_settings_api_key').val() !== '') ? this.trigger('hidden') : this.trigger('wait');
+ },
+ events: {wait: 'wait', hidden: 'hidden'}
+ },
+ wait: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key_button::wait::onEnter');
+ this.show();
+ this.attr('disabled', false);
+ },
+ events: {click: 'checking'}
+ },
+ checking: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key_button::checking::onEnter');
+ $('#transifex_live_settings_api_key').trigger('validating');
+ this.attr('disabled', true);
+ },
+ events: {wait: 'wait', hidden: 'hidden'}
+ },
+ hidden: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key_button::hidden::onEnter');
+ this.hide();
+ },
+ events: {wait: 'wait'}
+ }
+ }, {setClass: true}
+ );
})(jQuery);
(function (Transifex, $) {
- $('#transifex_live_settings_api_key').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key:defaultState:onEnter');
- languages_override = false;
- this.trigger('validating');
- },
- events: {validating: 'validating'}
- },
- validating: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key:validating:onEnter');
+ $('#transifex_live_settings_api_key').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key:defaultState:onEnter');
+ languages_override = false;
+ this.trigger('validating');
+ },
+ events: {validating: 'validating'}
+ },
+ validating: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key:validating:onEnter');
- $('#transifex_live_settings_url_options_none').attr('disabled', true);
- $('#transifex_live_settings_url_options_subdirectory').attr('disabled', true);
- $('#transifex_live_settings_url_options_subdomain').attr('disabled', true);
- $('input#transifex_live_submit').trigger('disable');
- $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', false);
- $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', true);
- transifexLanguages();
- transifex_settings_params = {
- url: "https://cdn.transifex.com/" + this.val() + "/latest/settings.all.jsonp",
- done: function (data) {
- if (data) {
- updateTransifexSettingsFields(data);
- $('#transifex_live_settings_api_key').trigger('success');
- } else {
+ $('#transifex_live_settings_url_options_none').attr('disabled', true);
+ $('#transifex_live_settings_url_options_subdirectory').attr('disabled', true);
+ $('#transifex_live_settings_url_options_subdomain').attr('disabled', true);
+ $('input#transifex_live_submit').trigger('disable');
+ $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', false);
+ $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', true);
+ transifexLanguages();
+ transifex_settings_params = {
+ url: "https://cdn.transifex.com/" + this.val() + "/latest/settings.all.jsonp",
+ done: function (data) {
+ if (data) {
+ updateTransifexSettingsFields(data);
+ $('#transifex_live_settings_api_key').trigger('success');
+ } else {
+ $('#transifex_live_settings_api_key').trigger('error');
+ }
+ },
+ fail: function () {
$('#transifex_live_settings_api_key').trigger('error');
}
- },
- fail: function () {
- $('#transifex_live_settings_api_key').trigger('error');
- }
- };
+ };
- Transifex.httpGet(transifex_settings_params);
- },
- events: {success: 'validating2', blank: 'blank', error: 'error', notranslation: 'missing', change: 'validating'}
- },
- validating2: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key:validating2:onEnter');
- },
- events: {success: 'valid', blank: 'blank', error: 'error', notranslation: 'missing', change: 'validating'}
- },
- valid: {
- onEnter: function () {
- $.log.debug('#transifex_live_settings_api_key:valid:onEnter');
- $('#transifex_live_settings_api_key_button').trigger('hidden');
- $('#transifex_live_settings_url_options_none').attr('disabled', false);
- $('#transifex_live_settings_url_options_subdirectory').attr('disabled', false);
- $('#transifex_live_settings_url_options_subdomain').attr('disabled', false);
- if (jQuery('#transifex_live_settings_language_map').val() == '[]' || languages_override) {
- $('#transifex_live_languages').trigger('load');
- languages_override = false;
- }
- $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', false);
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {success: 'valid', change: 'validating', validating: 'validating'}
- },
- error: {
- onEnter: function () {
- $.log.debug('error:onEnter');
- $('#transifex_live_settings_api_key_button').trigger('wait');
- $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', false);
- },
- events: {change: 'validating', validating: 'validating'}
- },
- blank: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_api_key:blank:onEnter');
- $('#transifex_live_settings_api_key_button').trigger('wait');
- $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', true);
- },
- events: {change: 'validating', validating: 'validating'}
- },
- missing: {
- onEnter: function () {
- $.log.debug('#transifex_live_settings_api_key:missing:onEnter');
- $('#transifex_live_settings_api_key_button').trigger('wait');
- $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', false);
- },
- events: {validating: 'validating'}
- }
- }, {setClass: true});
+ Transifex.httpGet(transifex_settings_params);
+ },
+ events: {success: 'validating2', blank: 'blank', error: 'error', notranslation: 'missing', change: 'validating'}
+ },
+ validating2: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key:validating2:onEnter');
+ },
+ events: {success: 'valid', blank: 'blank', error: 'error', notranslation: 'missing', change: 'validating'}
+ },
+ valid: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_settings_api_key:valid:onEnter');
+ $('#transifex_live_settings_api_key_button').trigger('hidden');
+ $('#transifex_live_settings_url_options_none').attr('disabled', false);
+ $('#transifex_live_settings_url_options_subdirectory').attr('disabled', false);
+ $('#transifex_live_settings_url_options_subdomain').attr('disabled', false);
+ if (jQuery('#transifex_live_settings_language_map').val() == '[]' || languages_override) {
+ $('#transifex_live_languages').trigger('load');
+ languages_override = false;
+ }
+ $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', false);
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {success: 'valid', change: 'validating', validating: 'validating'}
+ },
+ error: {
+ onEnter: function () {
+ $.log.debug('error:onEnter');
+ $('#transifex_live_settings_api_key_button').trigger('wait');
+ $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', false);
+ },
+ events: {change: 'validating', validating: 'validating'}
+ },
+ blank: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_api_key:blank:onEnter');
+ $('#transifex_live_settings_api_key_button').trigger('wait');
+ $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_valid').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_error').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', true);
+ },
+ events: {change: 'validating', validating: 'validating'}
+ },
+ missing: {
+ onEnter: function () {
+ $.log.debug('#transifex_live_settings_api_key:missing:onEnter');
+ $('#transifex_live_settings_api_key_button').trigger('wait');
+ $('#transifex_live_settings_api_key_message_validating').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_api_key_message_missing').toggleClass('hide-if-js', false);
+ },
+ events: {validating: 'validating'}
+ }
+ }, {setClass: true}
+ );
})(window.Transifex, jQuery);
(function ($) {
- $('#transifex_live_settings_url_options_none').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_none::defaultState::onEnter');
- },
- events: {click: 'on'}
- },
- on: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_none::on::onEnter');
- $('#transifex_live_settings_url_options').trigger('none');
- },
- events: {click: 'on'}
- },
- }, {setClass: true});
+ $('#transifex_live_settings_url_options_none').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_none::defaultState::onEnter');
+ },
+ events: {click: 'on'}
+ },
+ on: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_none::on::onEnter');
+ $('#transifex_live_settings_url_options').trigger('none');
+ },
+ events: {click: 'on'}
+ },
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('#transifex_live_settings_url_options_subdirectory').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdirectory::defaultState::onEnter');
- },
- events: {click: 'on'}
- },
- on: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdirectory::on::onEnter');
- $('#transifex_live_settings_url_options').trigger('subdirectory');
- },
- events: {click: 'on'}
- },
- }, {setClass: true});
+ $('#transifex_live_settings_url_options_subdirectory').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdirectory::defaultState::onEnter');
+ },
+ events: {click: 'on'}
+ },
+ on: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdirectory::on::onEnter');
+ $('#transifex_live_settings_url_options').trigger('subdirectory');
+ },
+ events: {click: 'on'}
+ },
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('#transifex_live_settings_url_options_subdomain').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdomain::defaultState::onEnter');
- },
- events: {click: 'on'}
- },
- on: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdomain::on::onEnter');
- $('#transifex_live_settings_url_options').trigger('subdomain');
- },
- events: {click: 'on'}
- },
- }, {setClass: true});
+ $('#transifex_live_settings_url_options_subdomain').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdomain::defaultState::onEnter');
+ },
+ events: {click: 'on'}
+ },
+ on: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdomain::on::onEnter');
+ $('#transifex_live_settings_url_options').trigger('subdomain');
+ },
+ events: {click: 'on'}
+ },
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('#transifex_live_settings_url_options').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options::defaultState::onEnter');
- (this.val() === "1") ? this.trigger('none') : (this.val() === "2") ? this.trigger('subdomain') : this.trigger('subdirectory');
- },
- events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
- },
- none: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options::none::onEnter');
- $('.url-structure-subdirectory').toggleClass('hide-if-js', true);
- $('.url-structure-subdomain').toggleClass('hide-if-js', true);
- $('.custom-urls-settings').toggleClass('hide-if-js', true);
- $('#transifex_live_settings_url_options_subdirectory').prop("checked", false);
- $('#transifex_live_settings_url_options_subdomain').prop("checked", false);
- this.val('1');
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
- },
- subdirectory: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options::subdirectory::onEnter');
- $('#transifex_live_settings_custom_urls').val("1");
- $('.url-structure-subdirectory').toggleClass('hide-if-js', false);
- $('.url-structure-subdomain').toggleClass('hide-if-js', true);
- $('.custom-urls-settings').toggleClass('hide-if-js', false);
- $('#transifex_live_options_all').trigger('activate');
- $('#transifex_live_settings_url_options_none').prop("checked", false);
- $('#transifex_live_settings_url_options_subdomain').prop("checked", false);
- this.val('3');
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
- },
- subdomain: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options::subdomain::onEnter');
- $('#transifex_live_settings_custom_urls').val("1");
- $('.url-structure-subdirectory').toggleClass('hide-if-js', true);
- $('.url-structure-subdomain').toggleClass('hide-if-js', false);
- $('.custom-urls-settings').toggleClass('hide-if-js', false);
- $('#transifex_live_options_all').trigger('activate');
- $('#transifex_live_settings_url_options_subdirectory').prop("checked", false);
- $('#transifex_live_settings_url_options_none').prop("checked", false);
- this.val('2');
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
- }
- }, {setClass: true});
+ $('#transifex_live_settings_url_options').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options::defaultState::onEnter');
+ (this.val() === "1") ? this.trigger('none') : (this.val() === "2") ? this.trigger('subdomain') : this.trigger('subdirectory');
+ },
+ events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
+ },
+ none: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options::none::onEnter');
+ $('.url-structure-subdirectory').toggleClass('hide-if-js', true);
+ $('.url-structure-subdomain').toggleClass('hide-if-js', true);
+ $('.custom-urls-settings').toggleClass('hide-if-js', true);
+ $('#transifex_live_settings_url_options_subdirectory').prop("checked", false);
+ $('#transifex_live_settings_url_options_subdomain').prop("checked", false);
+ this.val('1');
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
+ },
+ subdirectory: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options::subdirectory::onEnter');
+ $('#transifex_live_settings_custom_urls').val("1");
+ $('.url-structure-subdirectory').toggleClass('hide-if-js', false);
+ $('.url-structure-subdomain').toggleClass('hide-if-js', true);
+ $('.custom-urls-settings').toggleClass('hide-if-js', false);
+ $('#transifex_live_options_all').trigger('activate');
+ $('#transifex_live_settings_url_options_none').prop("checked", false);
+ $('#transifex_live_settings_url_options_subdomain').prop("checked", false);
+ this.val('3');
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
+ },
+ subdomain: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options::subdomain::onEnter');
+ $('#transifex_live_settings_custom_urls').val("1");
+ $('.url-structure-subdirectory').toggleClass('hide-if-js', true);
+ $('.url-structure-subdomain').toggleClass('hide-if-js', false);
+ $('.custom-urls-settings').toggleClass('hide-if-js', false);
+ $('#transifex_live_options_all').trigger('activate');
+ $('#transifex_live_settings_url_options_subdirectory').prop("checked", false);
+ $('#transifex_live_settings_url_options_none').prop("checked", false);
+ this.val('2');
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {none: 'none', subdomain: 'subdomain', subdirectory: 'subdirectory'}
+ }
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('#transifex_live_settings_rewrite_option_all').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_rewrite_option_all::defaultState::onEnter');
- if (this.prop('checked')) {
- this.trigger('seton');
- } else {
- this.trigger('setoff');
- }
- },
- events: {seton: 'on', setoff: 'off'}
- },
- on: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_rewrite_option_all::on::onEnter');
- this.prop('checked', true);
- $('.all_selector').trigger('on');
- },
- events: {click: 'off', off: 'off', singleoff: 'singleoff'}
- },
- off: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_rewrite_option_all::off::onEnter');
- this.prop('checked', false);
- $('.all_selector').trigger('off');
- $('input#transifex_live_submit').trigger('disable');
- },
- events: {click: 'on'}
- },
- singleoff: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_rewrite_option_all::singleoff::onEnter');
- this.prop("checked", false);
- },
- events: {click: 'on'}
- }
- }, {setClass: true});
+ $('#transifex_live_settings_rewrite_option_all').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_rewrite_option_all::defaultState::onEnter');
+ if (this.prop('checked')) {
+ this.trigger('seton');
+ } else {
+ this.trigger('setoff');
+ }
+ },
+ events: {seton: 'on', setoff: 'off'}
+ },
+ on: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_rewrite_option_all::on::onEnter');
+ this.prop('checked', true);
+ $('.all_selector').trigger('on');
+ },
+ events: {click: 'off', off: 'off', singleoff: 'singleoff'}
+ },
+ off: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_rewrite_option_all::off::onEnter');
+ this.prop('checked', false);
+ $('.all_selector').trigger('off');
+ $('input#transifex_live_submit').trigger('disable');
+ },
+ events: {click: 'on'}
+ },
+ singleoff: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_rewrite_option_all::singleoff::onEnter');
+ this.prop("checked", false);
+ },
+ events: {click: 'on'}
+ }
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('.all_selector').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('all_selector::defaultState::onEnter');
- if (this.prop('checked')) {
- this.trigger('seton');
- } else {
- this.trigger('setoff');
- }
- },
- events: {seton: 'on', setoff: 'off'}
- },
- on: {
- onEnter: function () {
- $.log.debug('all_selector::on::onEnter');
- this.prop("checked", true);
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {click: 'off', off: 'off'}
- },
- off: {
- onEnter: function () {
- $.log.debug('all_selector::off::onEnter');
- this.prop("checked", false);
- $('#transifex_live_settings_rewrite_option_all').trigger('singleoff');
- $('input#transifex_live_submit').trigger('enable');
- },
- events: {click: 'on', on: 'on'}
- }
- }, {setClass: true});
+ $('.all_selector').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('all_selector::defaultState::onEnter');
+ if (this.prop('checked')) {
+ this.trigger('seton');
+ } else {
+ this.trigger('setoff');
+ }
+ },
+ events: {seton: 'on', setoff: 'off'}
+ },
+ on: {
+ onEnter: function () {
+ $.log.debug('all_selector::on::onEnter');
+ this.prop("checked", true);
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {click: 'off', off: 'off'}
+ },
+ off: {
+ onEnter: function () {
+ $.log.debug('all_selector::off::onEnter');
+ this.prop("checked", false);
+ $('#transifex_live_settings_rewrite_option_all').trigger('singleoff');
+ $('input#transifex_live_submit').trigger('enable');
+ },
+ events: {click: 'on', on: 'on'}
+ }
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('input#transifex_live_submit').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdomain::input#transifex_live_submit::onEnter');
- this.trigger('disable');
- },
- events: {disable: 'disable'}
- },
- enable: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdomain::enable::onEnter');
- this.attr('disabled', false);
- if (jQuery('#transifex_live_settings_url_options').data('state') == 'subdirectory') {
- var checkOptions = false;
- $.each($('.all_selector'), function (i, o) {
+ $('input#transifex_live_submit').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdomain::input#transifex_live_submit::onEnter');
+ this.trigger('disable');
+ },
+ events: {disable: 'disable'}
+ },
+ enable: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdomain::enable::onEnter');
+ this.attr('disabled', false);
+ if (jQuery('#transifex_live_settings_url_options').data('state') == 'subdirectory') {
+ var checkOptions = false;
+ $.each(
+ $('.all_selector'), function (i, o) {
+ if (!checkOptions) {
+ checkOptions = ($(o).prop('checked')) ? true : false;
+ }
+ }
+ );
if (!checkOptions) {
- checkOptions = ($(o).prop('checked')) ? true : false;
+ this.trigger('disable');
}
- });
- if (!checkOptions) {
- this.trigger('disable');
}
- }
- },
- events: {disable: 'disable', enable: 'enable'}
- },
- disable: {
- onEnter: function () {
- $.log.debug('transifex_live_settings_url_options_subdomain::enable::onEnter');
- this.attr('disabled', true);
- },
- events: {enable: 'enable'}
- },
- }, {setClass: true});
+ },
+ events: {disable: 'disable', enable: 'enable'}
+ },
+ disable: {
+ onEnter: function () {
+ $.log.debug('transifex_live_settings_url_options_subdomain::enable::onEnter');
+ this.attr('disabled', true);
+ },
+ events: {enable: 'enable'}
+ },
+ }, {setClass: true}
+ );
})(jQuery);
(function ($) {
- $('input#transifex_live_sync').machine({
- defaultState: {
- onEnter: function () {
- $.log.debug('input#transifex_live_sync::defaultState::onEnter');
- this.trigger('wait');
- },
- events: {wait: 'wait'}
- },
- wait: {
- onEnter: function () {
- $.log.debug('input#transifex_live_sync::wait::onEnter');
- },
- events: {click: 'confirm'}
- },
- confirm: {
- onEnter: function () {
- $.log.debug('input#transifex_live_sync::confirm::onEnter');
- this.trigger('refresh');
- //this.trigger('wait');
- },
- events: {refresh: 'refresh', wait: 'wait'}
- },
- refresh: {
- onEnter: function () {
- $.log.debug('input#transifex_live_sync::refresh::onEnter');
- languages_override = true;
- jQuery('#transifex_live_settings_api_key').trigger('validating');
+ $('input#transifex_live_sync').machine(
+ {
+ defaultState: {
+ onEnter: function () {
+ $.log.debug('input#transifex_live_sync::defaultState::onEnter');
+ this.trigger('wait');
+ },
+ events: {wait: 'wait'}
+ },
+ wait: {
+ onEnter: function () {
+ $.log.debug('input#transifex_live_sync::wait::onEnter');
+ },
+ events: {click: 'confirm'}
+ },
+ confirm: {
+ onEnter: function () {
+ $.log.debug('input#transifex_live_sync::confirm::onEnter');
+ this.trigger('refresh');
+ //this.trigger('wait');
+ },
+ events: {refresh: 'refresh', wait: 'wait'}
+ },
+ refresh: {
+ onEnter: function () {
+ $.log.debug('input#transifex_live_sync::refresh::onEnter');
+ languages_override = true;
+ jQuery('#transifex_live_settings_api_key').trigger('validating');
- this.trigger('wait');
+ this.trigger('wait');
+ },
+ events: {wait: 'wait'}
},
- events: {wait: 'wait'}
- },
- }, {setClass: true});
+ }, {setClass: true}
+ );
})(jQuery);
\ No newline at end of file
diff --git a/javascript/transifex-live-integration-transifex-settings.js b/javascript/transifex-live-integration-transifex-settings.js
index 71353be3..a5074ca4 100755
--- a/javascript/transifex-live-integration-transifex-settings.js
+++ b/javascript/transifex-live-integration-transifex-settings.js
@@ -5,17 +5,23 @@ window.Transifex = window.Transifex || {};
}
exports.httpGet = function (params) {
- $.ajax({
- url: params.url || "BADURL",
- jsonpCallback: params.jsonpCallback || "transifex_settings",
- jsonp: params.jsonp || true,
- dataType: params.dataType || "jsonp",
- timeout: params.timeout || 3000
- }).done(function (data) {
- params.done(self.validate(data));
- }).fail(function () {
- params.fail();
- });
+ $.ajax(
+ {
+ url: params.url || "BADURL",
+ jsonpCallback: params.jsonpCallback || "transifex_settings",
+ jsonp: params.jsonp || true,
+ dataType: params.dataType || "jsonp",
+ timeout: params.timeout || 3000
+ }
+ ).done(
+ function (data) {
+ params.done(self.validate(data));
+ }
+ ).fail(
+ function () {
+ params.fail();
+ }
+ );
};
@@ -24,10 +30,12 @@ window.Transifex = window.Transifex || {};
var expected_keys = ['picker', 'domain'];
var keys = Object.keys(obj['production']);
var diff = [];
- $.grep(expected_keys, function (e) {
- if ($.inArray(e, keys) === -1)
- diff.push(e);
- });
+ $.grep(
+ expected_keys, function (e) {
+ if ($.inArray(e, keys) === -1) {
+ diff.push(e); }
+ }
+ );
if (diff.length === 0) {
ret = obj;
diff --git a/language_mapper.php b/language_mapper.php
deleted file mode 100644
index e8f71b7a..00000000
--- a/language_mapper.php
+++ /dev/null
@@ -1,52 +0,0 @@
- "fr","name" => "French"]];
- $test_data['expected_source'] = 'en';
- array_push($arr,$test_data);
-
- $test_data['input'] = 'transifex_languages({"timestamp": "1450373800.92", "translation": [{"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/zh_CN.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Chinese (China)", "code": "zh_CN", "name": "\u4e2d\u6587 (\u4e2d\u56fd)", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/fr.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "French", "code": "fr", "name": "Fran\u00e7ais", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/de_DE.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "German (Germany)", "code": "de_DE", "name": "Deutsch", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/ko.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Korean", "code": "ko", "name": "\ud55c\uad6d\uc5b4", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/es.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Spanish", "code": "es", "name": "Espa\u00f1ol", "rtl": false}], "source": {"tx_name": "English", "code": "en", "name": "English", "rtl": false}});';
- $test_data['expected_languages'] = [["code" => "fr","name" => "French"],["tx_name"=> "Chinese (China)", "code"=> "zh_CN"],["tx_name"=> "German (Germany)", "code"=> "de_DE"],["tx_name"=> "Spanish", "code"=> "es"],["tx_name"=> "Korean", "code"=> "ko"]];
- $test_data['expected_source'] = 'en';
- array_push($arr,$test_data);
-
- $reg = '/\s*transifex_languages\(\s*(.+?)\s*\);/';
-
- foreach ($arr as $i) {
- preg_match($reg,$i['input'],$m);
- $tl_array = json_decode($m[1],true);
-
- $tl_t_array = $tl_array['translation'];
-
- $language_array = array_map(
- function($x) {
- $arr = ["code" => $x['code'],"name" => $x['tx_name']];
- return $arr; },
- $tl_t_array
- );
- }
- $mapper = "";
- foreach ($language_array as $item) {
- $name = $item['name'];
- $code = $item['code'];
- $mapper .= <<
-
-
-MAPPER;
-}
-eval(\Psy\sh());
-}
-
-
-}
-
-
-
-?>
\ No newline at end of file
diff --git a/parse_transifex_languages.php b/parse_transifex_languages.php
deleted file mode 100644
index eeba40c3..00000000
--- a/parse_transifex_languages.php
+++ /dev/null
@@ -1,46 +0,0 @@
- "fr","name" => "French"]];
- $test_data['expected_source'] = 'en';
- array_push($arr,$test_data);
-
- $test_data['input'] = 'transifex_languages({"timestamp": "1450373800.92", "translation": [{"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/zh_CN.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Chinese (China)", "code": "zh_CN", "name": "\u4e2d\u6587 (\u4e2d\u56fd)", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/fr.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "French", "code": "fr", "name": "Fran\u00e7ais", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/de_DE.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "German (Germany)", "code": "de_DE", "name": "Deutsch", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/ko.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Korean", "code": "ko", "name": "\ud55c\uad6d\uc5b4", "rtl": false}, {"url": "//cdn.transifex.com/2699bc66df6546008d0a14acf26732a1/latest/es.f5a69719038448b9926a8950554ab9f4.jsonp", "tx_name": "Spanish", "code": "es", "name": "Espa\u00f1ol", "rtl": false}], "source": {"tx_name": "English", "code": "en", "name": "English", "rtl": false}});';
- $test_data['expected_languages'] = [["code" => "fr","name" => "French"],["tx_name"=> "Chinese (China)", "code"=> "zh_CN"],["tx_name"=> "German (Germany)", "code"=> "de_DE"],["tx_name"=> "Spanish", "code"=> "es"],["tx_name"=> "Korean", "code"=> "ko"]];
- $test_data['expected_source'] = 'en';
- array_push($arr,$test_data);
-
- $reg = '/\s*transifex_languages\(\s*(.+?)\s*\);/';
-
- foreach ($arr as $i) {
- preg_match($reg,$i['input'],$m);
- $tl_array = json_decode($m[1],true);
-
- $tl_s_array = $tl_array['source'];
- $source_string = $tl_s_array['code'];
-
- $tl_t_array = $tl_array['translation'];
-
- $language_array = array_map(
- function($x) {
- $arr = ["code" => $x['code'],"name" => $x['tx_name']];
- return $arr; },
- $tl_t_array
- );
- eval(\Psy\sh());
- $this->assertEquals($i['expected_source'],$source_string);
- $this->assertEquals(ksort($i['expected_languages']),ksort($language_array));
-}
- eval(\Psy\sh());
-}
-}
-
-
-
-?>
\ No newline at end of file
diff --git a/readme.md b/readme.md
index c3b12551..4bf607e5 100755
--- a/readme.md
+++ b/readme.md
@@ -19,8 +19,10 @@ In order to use Transifex Live, you will need to [sign up here for an account](h
* Simple installation of Transifex Live.
* Automatically identify new or changed content on your site.
* Translate your website in context.
-* Easily set unique language or region-specific URLs.
+* Easily set unique language or region-specific URLs either by subdomain or subdirectory.
+* Integrated language picker
* Add hreflang tags to your pages and tell search engines what language a page is in.
+* Supports using a prerendered server for SEO purposes
== Get Involved ==
@@ -100,4 +102,8 @@ Improved admin UI
= 1.2.4 =
Added picker support that respects locale
-Additional admin API key validation
\ No newline at end of file
+Additional admin API key validation
+
+= 1.3.0 =
+Added Prerendering capability
+Fixed some timing issues with the WP loop
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
index de300d02..f9faa577 100755
--- a/readme.txt
+++ b/readme.txt
@@ -23,8 +23,10 @@ Features:
* Simple installation of Transifex Live.
* Automatically identify new or changed content on your site.
* Translate your website in context.
-* Easily set unique language or region-specific URLs.
+* Easily set unique language or region-specific URLs either by subdomain or subdirectory.
+* Integrated language picker
* Add hreflang tags to your pages and tell search engines what language a page is in.
+* Supports using a prerendered server for SEO purposes
Learn more about the [Transifex Live Translation Plugin](https://www.transifex.com/integrations/wordpress-multilingual-plugin/?utm_source=wp-directory&utm_campaign=int-wp).
@@ -109,3 +111,7 @@ Improved admin UI
= 1.2.4 =
Added picker support that respects locale
Additional admin API key validation
+
+= 1.3.0 =
+Added Prerendering capability
+Fixed some timing issues with the WP loop
\ No newline at end of file
diff --git a/regex_string_serial-deserial.php b/regex_string_serial-deserial.php
deleted file mode 100644
index 49b8d8af..00000000
--- a/regex_string_serial-deserial.php
+++ /dev/null
@@ -1,19 +0,0 @@
-
\ No newline at end of file
diff --git a/reverse_hard_link.php b/reverse_hard_link.php
deleted file mode 100644
index 71389cc0..00000000
--- a/reverse_hard_link.php
+++ /dev/null
@@ -1,41 +0,0 @@
- "zh_CN","de_DE" => "de_DE","ko" => "ko"];
-
- $modified_link = $link;
- $reverse_url = true;
- $condition = "";
- $reverse_url = ($reverse_url)?(isset($lang)):false;
- $condition .= ($reverse_url)?"A OK":"A Failed";
- $reverse_url = ($reverse_url)?(!strpos($modified_link,$lang)):false;
- $condition .= ($reverse_url)?"B OK":"B Failed";
- $reverse_url = ($reverse_url)?(array_key_exists($lang,$languages_map)):false;
- $condition .= ($reverse_url)?"C OK":"C Failed";
- $reverse_url = ($reverse_url)?(!($source == $lang)):false;
- $condition .= ($reverse_url)?"D OK":"D Failed";
-
- if ($reverse_url) {
- $array_url = explode( '/', $link );
- $array_url[3] = $languages_map[$lang]. '/' . $array_url[3];
- $modified_link = implode( '/', $array_url );
- }
-
-
- eval(\Psy\sh());
- // $this->assertEquals($i['expected_source'],$source_string);
- // $this->assertEquals(ksort($i['expected_languages']),ksort($language_array));
-}
-
-}
-
-?>
\ No newline at end of file
diff --git a/stylesheets/transifex-live-integration-settings-page.css b/stylesheets/transifex-live-integration-settings-page.css
index d369f159..6a2f9e4d 100755
--- a/stylesheets/transifex-live-integration-settings-page.css
+++ b/stylesheets/transifex-live-integration-settings-page.css
@@ -1,13 +1,13 @@
.transifex-live-settings table.form-table fieldset:first-child {
- margin-top: 0;
+ margin-top: 0;
}
.transifex-live-settings table.form-table, .transifex-live-settings table.form-table .forminp-radio ul {
- margin: 0;
+ margin: 0;
}
.transifex-live-settings table.form-table .forminp-radio ul li {
- display: inline;
- margin-right: 20px;
- text-transform: uppercase;
+ display: inline;
+ margin-right: 20px;
+ text-transform: uppercase;
}
.transifex-live-settings table.form-table .enable_checkbox {
@@ -16,56 +16,56 @@
}
.transifex-live-settings table.form-table .color-box {
- border: 1px solid #ccc;
- box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -moz-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -webkit-border-radius: 3px;
- -moz-border-radius: 3px;
- border-radius: 3px;
- padding: 4px 6px;
- float: left;
- width: 90px;
- margin: 0 10px 10px 0;
+ border: 1px solid #ccc;
+ box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -moz-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ padding: 4px 6px;
+ float: left;
+ width: 90px;
+ margin: 0 10px 10px 0;
}
.transifex-live-settings table.form-table .color-box strong {
- text-align: left;
- display: block;
- padding: 0 0 2px;
- font-size: .92em;
- word-wrap: break-word;
+ text-align: left;
+ display: block;
+ padding: 0 0 2px;
+ font-size: .92em;
+ word-wrap: break-word;
}
.transifex-live-settings table.form-table .color-box input.colorpick {
- width: 100%;
- margin: 0;
- font-family: monospace;
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- box-sizing: border-box;
+ width: 100%;
+ margin: 0;
+ font-family: monospace;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
}
.transifex-live-settings table.form-table .color-box .iris-picker {
- z-index: 100;
- position: absolute;
- display: none;
- border: 1px solid #ccc;
- box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -moz-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
- -webkit-border-radius: 3px;
- -moz-border-radius: 3px;
- border-radius: 3px;
- margin: 15px 0 0 -7px;
+ z-index: 100;
+ position: absolute;
+ display: none;
+ border: 1px solid #ccc;
+ box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -moz-box-shadow: 1px 1px 3px rgba(0,0,0,.2);
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ margin: 15px 0 0 -7px;
}
.text_field_fix {
- width: 120px;
+ width: 120px;
}
.language_picker_fix {
- width: 200px;
+ width: 200px;
}
#transifex_live_settings_api_key_button.hidden {
diff --git a/test b/test
deleted file mode 100644
index 772c1ad0..00000000
--- a/test
+++ /dev/null
@@ -1,737 +0,0 @@
-
-
-
-Hello world! - Test-WP-PluginTest-WP-Plugin
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Just another WordPress site
-
-
-
-
-
-
-
-
-
- Main menu
-
-
-
-
-
-
-
-
-
-
-
-
- Post navigation
- ← Previous
- Next →
-
-
-
-
-
-
-
-
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Plugin: Plugin Debug Mode Output
-*File: transifex-live-integration.php - Line #: 67 Class: Plugin_Debug - Function: __construct Type: method call - Parameters: Array
-(
-)
- **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- **File: transifex-live-integration.php - Line #: 98 Class: Transifex_Live_Integration_Subdomain - Function: create_subdomains Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- **File: transifex-live-integration.php - Line #: 98 Class: Transifex_Live_Integration_Subdomain - Function: create_subdomains Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- settings[url_options] not subdomain **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- subdomains skipped **File: transifex-live-integration.php - Line #: 107 Class: Transifex_Live_Integration_Rewrite - Function: create_rewrite Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
- [1] => Array
- (
- [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
- )
-
-)
- **File: transifex-live-integration.php - Line #: 107 Class: Transifex_Live_Integration_Rewrite - Function: create_rewrite Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
- [1] => Array
- (
- [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
- )
-
-)
- settings[languages_regex] not set **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- rewrite skipped **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- adding admin bar actions **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- user_agent **File: transifex-live-integration.php - Line #: 203 Class: Transifex_Live_Integration_Prerender - Function: create_prerender Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34 Prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration-prerender.php - Line #: 55 Class: Transifex_Live_Integration_Prerender - Function: prerender_check Type: static method call - Parameters: Array
-(
- [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
- [1] =>
- [2] => bot|crawl|slurp|spider
- [3] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
-)
- **File: transifex-live-integration-prerender.php - Line #: 40 Class: Transifex_Live_Integration_Prerender - Function: is_bot_type Type: static method call - Parameters: Array
-(
- [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
- [1] => bot|crawl|slurp|spider
-)
- **File: transifex-live-integration-prerender.php - Line #: 41 Class: Transifex_Live_Integration_Prerender - Function: is_whitelist_name Type: static method call - Parameters: Array
-(
- [0] => mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender)
- [1] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0.|developers.google.com\/+\/web\/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
-)
- **File: transifex-live-integration-prerender.php - Line #: 43 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
-(
-)
- mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration-prerender.php - Line #: 43 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
-(
-)
- 1 **File: transifex-live-integration-prerender.php - Line #: 56 Class: Transifex_Live_Integration_Prerender - Function: __construct Type: method call - Parameters: Array
-(
-)
- **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- prerender created **File: transifex-live-integration.php - Line #: 206 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
-(
-)
- mozilla/5.0 (unknown; linux x86_64) applewebkit/534.34 (khtml, like gecko) phantomjs/1.9.8 safari/534.34 prerender (+https://github.com/prerender/prerender) **File: transifex-live-integration.php - Line #: 206 Class: Transifex_Live_Integration_Prerender - Function: is_prerender_req Type: static method call - Parameters: Array
-(
-)
- 1 **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- prerender request detected **File: transifex-live-integration.php - Line #: 218 Class: Transifex_Live_Integration_Hreflang - Function: __construct Type: method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
- [1] => 1
-)
- **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- Severity: 8 File: transifex-live-integration-hreflang.php Line: 29: Undefined offset: 0 **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- Severity: 8 File: transifex-live-integration-hreflang.php Line: 31: Undefined index: tokenized_url **File: transifex-live-integration.php - Line #: 219 Class: Transifex_Live_Integration_Hreflang - Function: ok_to_add Type: method call - Parameters: Array
-(
-)
- settings[api_key] not set...skipping hreflang **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- skipping hreflang **File: transifex-live-integration.php - Line #: 220 Class: Transifex_Live_Integration_Hreflang - Function: ok_to_add Type: method call - Parameters: Array
-(
-)
- settings[api_key] not set...skipping hreflang **File: transifex-live-integration.php - Line #: 225 Class: Transifex_Live_Integration_Javascript - Function: __construct Type: method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
- [1] =>
-)
- **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- Severity: 8 File: transifex-live-integration-javascript.php Line: 35: Undefined offset: 0 **File: transifex-live-integration.php - Line #: 229 Class: Transifex_Live_Integration_Picker - Function: create_picker Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- **File: transifex-live-integration.php - Line #: 229 Class: Transifex_Live_Integration_Picker - Function: create_picker Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [api_key] =>
- [previous_api_key] =>
- [raw_transifex_languages] =>
- [transifex_languages] =>
- [language_lookup] =>
- [language_map] => []
- [languages_regex] =>
- [rewrite_option_all] => 0
- [enable_custom_urls] => 0
- [urls] => Array
- (
- [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] =>
- [enable_picker] =>
- [add_language_rewrites] => none selected
- [source_language] =>
- [languages] =>
- [hreflang] =>
- [url_options] => 1
- [subdomain_pattern] =>
- [whitelist_crawlers] => googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard
- [generic_bot_types] => bot|crawl|slurp|spider
- )
-
-)
- settings[enable_picker] not truthy **File: transifex-live-integration.php - Line #: 271 Class: Transifex_Live_Integration - Function: do_plugin Type: static method call - Parameters: Array
-(
- [0] =>
- [1] => 1.2.5
-)
- picker skipped **Class: Transifex_Live_Integration - Function: query_vars_hook Type: static method call - Parameters: Array
-(
- [0] => Array
- (
- [0] => m
- [1] => p
- [2] => posts
- [3] => w
- [4] => cat
- [5] => withcomments
- [6] => withoutcomments
- [7] => s
- [8] => search
- [9] => exact
- [10] => sentence
- [11] => calendar
- [12] => page
- [13] => paged
- [14] => more
- [15] => tb
- [16] => pb
- [17] => author
- [18] => order
- [19] => orderby
- [20] => year
- [21] => monthnum
- [22] => day
- [23] => hour
- [24] => minute
- [25] => second
- [26] => name
- [27] => category_name
- [28] => tag
- [29] => feed
- [30] => author_name
- [31] => static
- [32] => pagename
- [33] => page_id
- [34] => error
- [35] => comments_popup
- [36] => attachment
- [37] => attachment_id
- [38] => subpost
- [39] => subpost_id
- [40] => preview
- [41] => robots
- [42] => taxonomy
- [43] => term
- [44] => cpage
- [45] => post_type
- [46] => embed
- [47] => post_format
- [48] => sitemap
- [49] => sitemap_n
- [50] => xsl
- [51] => rest_route
- )
-
-)
- **Class: Transifex_Live_Integration_Javascript - Function: render Type: method call - Parameters: Array
-(
- [0] =>
-)
- **Class: Transifex_Live_Integration_Javascript - Function: render Type: method call - Parameters: Array
-(
- [0] =>
-)
- skipped detectlang override *
-
-
-
-
\ No newline at end of file
diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php
index bfa59cbb..36dcbba3 100644
--- a/tests/_support/AcceptanceTester.php
+++ b/tests/_support/AcceptanceTester.php
@@ -3,6 +3,7 @@
/**
* Inherited Methods
+ *
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
@@ -20,7 +21,7 @@ class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
- /**
+ /**
* Define custom actions here
*/
}
diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php
index 8f9d5f23..f9fb51eb 100644
--- a/tests/_support/FunctionalTester.php
+++ b/tests/_support/FunctionalTester.php
@@ -3,6 +3,7 @@
/**
* Inherited Methods
+ *
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
@@ -20,7 +21,7 @@ class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
- /**
+ /**
* Define custom actions here
*/
}
diff --git a/tests/_support/UnitTester.php b/tests/_support/UnitTester.php
index 68c09cf8..3f0aab8c 100644
--- a/tests/_support/UnitTester.php
+++ b/tests/_support/UnitTester.php
@@ -3,6 +3,7 @@
/**
* Inherited Methods
+ *
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
@@ -20,7 +21,7 @@ class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
- /**
+ /**
* Define custom actions here
*/
}
diff --git a/tests/unit/GenerateLanguageUrlMapTest.php b/tests/unit/GenerateLanguageUrlMapTest.php
index 0bad0b95..73c92a57 100644
--- a/tests/unit/GenerateLanguageUrlMapTest.php
+++ b/tests/unit/GenerateLanguageUrlMapTest.php
@@ -1,41 +1,44 @@
data = [
- [
- 'raw_url' => '/about/',
- 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
- 'language_map' => [ 'zh_CN' => 'cn'],
- 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/about/']
- ], [
- 'raw_url' => '2015/12/17/hello-world/',
- 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
- 'language_map' => [ 'zh_CN' => 'cn'],
- 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/2015/12/17/hello-world/']
- ],[
- 'raw_url' => '2015/12/17/hello-world',
- 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
- 'language_map' => [ 'zh_CN' => 'cn'],
- 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/2015/12/17/hello-world/']
- ]
- ];
- // negative options go here
+ protected function setUp()
+ {
+ include_once './includes/common/plugin-debug.php';
+ include_once './includes/common/transifex-live-integration-common.php';
+ $this->data = [
+ [
+ 'raw_url' => '/about/',
+ 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
+ 'language_map' => [ 'zh_CN' => 'cn'],
+ 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/about/']
+ ], [
+ 'raw_url' => '2015/12/17/hello-world/',
+ 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
+ 'language_map' => [ 'zh_CN' => 'cn'],
+ 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/2015/12/17/hello-world/']
+ ],[
+ 'raw_url' => '2015/12/17/hello-world',
+ 'tokenized_url' => 'http://192.168.99.100:32777/%lang%/',
+ 'language_map' => [ 'zh_CN' => 'cn'],
+ 'result' => ['zh_CN' => 'http://192.168.99.100:32777/cn/2015/12/17/hello-world/']
+ ]
+ ];
+ // negative options go here
- }
+ }
- public function testMe() {
- foreach ($this->data as $d) {
- $result = Transifex_Live_Integration_Picker::generate_language_url_map( $d['raw_url'], $d['tokenized_url'], $d['language_map'] );
+ public function testMe()
+ {
+ foreach ($this->data as $d) {
+ $result = Transifex_Live_Integration_Common::generate_language_url_map($d['raw_url'], $d['tokenized_url'], $d['language_map']);
- // eval(\Psy\sh());
- $this->assertEquals( $d['result'], $result );
- }
- }
+ // eval(\Psy\sh());
+ $this->assertEquals($d['result'], $result);
+ }
+ }
}
diff --git a/tests/unit/GenerateTokenizedUrlTest.php b/tests/unit/GenerateTokenizedUrlTest.php
index 4df940dc..ff6323c0 100644
--- a/tests/unit/GenerateTokenizedUrlTest.php
+++ b/tests/unit/GenerateTokenizedUrlTest.php
@@ -1,37 +1,40 @@
data = [[
- 'site_url' => 'http://192.168.99.100:32777',
- 'url_option_setting' => '2', // Subdomain option
- 'result' => 'http://%lang%.168.99.100:32777/'
- ],
- [
- 'site_url' => 'http://192.168.99.100:32777',
- 'url_option_setting' => '3', // Subdirectory option
- 'result' => 'http://192.168.99.100:32777/%lang%/'
- ],
- ];
- // negative options tests
- $neg_options = [1, '1', '', ' ', null ];
- foreach ($neg_options as $o) {
- array_push( $this->data, ['site_url' => 'http://192.168.99.100:32777', 'url_option_setting' => $o, 'result' => false ] );
- }
- }
+ protected function setUp()
+ {
+ include_once './includes/common/plugin-debug.php';
+ include_once './includes/admin/transifex-live-integration-admin-util.php';
+ $this->data = [[
+ 'site_url' => 'http://192.168.99.100:32777',
+ 'url_option_setting' => '2', // Subdomain option
+ 'result' => 'http://%lang%.168.99.100:32777/'
+ ],
+ [
+ 'site_url' => 'http://192.168.99.100:32777',
+ 'url_option_setting' => '3', // Subdirectory option
+ 'result' => 'http://192.168.99.100:32777/%lang%/'
+ ],
+ ];
+ // negative options tests
+ $neg_options = [1, '1', '', ' ', null ];
+ foreach ($neg_options as $o) {
+ array_push($this->data, ['site_url' => 'http://192.168.99.100:32777', 'url_option_setting' => $o, 'result' => false ]);
+ }
+ }
- public function testMe() {
- foreach ($this->data as $d) {
- $result = Transifex_Live_Integration_Settings_Util::generate_tokenized_url( $d['site_url'], $d['url_option_setting'] );
+ public function testMe()
+ {
+ foreach ($this->data as $d) {
+ $result = Transifex_Live_Integration_Admin_Util::generate_tokenized_url($d['site_url'], $d['url_option_setting']);
- // eval(\Psy\sh());
- $this->assertEquals( $d['result'], $result );
- }
- }
+ // eval(\Psy\sh());
+ $this->assertEquals($d['result'], $result);
+ }
+ }
}
diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php
index 3289bdee..389e55c4 100644
--- a/tests/unit/PrerenderCheckTest.php
+++ b/tests/unit/PrerenderCheckTest.php
@@ -1,76 +1,79 @@
data = [[ // Standard Chrome Agent
- 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => false
- ],[ // Standard Firefox Agent
- 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:46.0) Gecko/20100101 Firefox/46.0',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => false
- ], [ // Prerender added
- 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 Prerender (+https://github.com/prerender/prerender)',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => false
- ], [ // Standard Googlebot
- 'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => true
- ], [ // Googlebot with prerender added
- 'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Prerender (+https://github.com/prerender/prerender)',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => true
- ], [ // Slackbot with
- 'agent' => 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => true
- ],[ // Slackbot with
- 'agent' => 'slackbot',
- 'fragment' => NULL,
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => true
- ],
- [ // some fragment
- 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
- 'fragment' => '/some-frament',
- 'bot_types' => $bot_types,
- 'whitelist' => $whitelist,
- 'result' => true
- ]
- ];
- }
+ protected function setUp()
+ {
+ include_once './includes/common/plugin-debug.php';
+ include_once './includes/transifex-live-integration-util.php';
+ include_once './includes/transifex-live-integration-defaults.php';
+ $settings = Transifex_Live_Integration_Defaults::settings();
+ $whitelist = $settings['whitelist_crawlers'];
+ $bot_types = $settings['generic_bot_types'];
+ $this->data = [[ // Standard Chrome Agent
+ 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => false
+ ],[ // Standard Firefox Agent
+ 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:46.0) Gecko/20100101 Firefox/46.0',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => false
+ ], [ // Prerender added
+ 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 Prerender (+https://github.com/prerender/prerender)',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => false
+ ], [ // Standard Googlebot
+ 'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ], [ // Googlebot with prerender added
+ 'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Prerender (+https://github.com/prerender/prerender)',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ], [ // Slackbot with
+ 'agent' => 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ],[ // Slackbot with
+ 'agent' => 'slackbot',
+ 'fragment' => null,
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ],
+ [ // some fragment
+ 'agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
+ 'fragment' => '/some-frament',
+ 'bot_types' => $bot_types,
+ 'whitelist' => $whitelist,
+ 'result' => true
+ ]
+ ];
+ }
- public function testMe() {
- foreach ($this->data as $i) {
- $result = Transifex_Live_Integration_Prerender::prerender_check( $i['agent'], $i['fragment'], $i['bot_types'], $i['whitelist'] );
+ public function testMe()
+ {
+ foreach ($this->data as $i) {
+ $result = Transifex_Live_Integration_Util::prerender_check($i['agent'], $i['fragment'], $i['bot_types'], $i['whitelist']);
- //eval(\Psy\sh());
- $this->assertEquals( $i['result'], $result );
- }
- }
+ //eval(\Psy\sh());
+ $this->assertEquals($i['result'], $result);
+ }
+ }
}
diff --git a/tests/unit/ReverseHardLinkTest.php b/tests/unit/ReverseHardLinkTest.php
index 02cf1ef9..4b19ee7b 100644
--- a/tests/unit/ReverseHardLinkTest.php
+++ b/tests/unit/ReverseHardLinkTest.php
@@ -6,8 +6,8 @@ class ReverseHardLinkTest extends \PHPUnit_Framework_TestCase
private $data;
protected function setUp()
{
- require_once './includes/plugin-debug.php';
- include_once './includes/transifex-live-integration-rewrite.php';
+ include_once './includes/common/plugin-debug.php';
+ include_once './includes/lib/transifex-live-integration-rewrite.php';
$this->data = [[
'lang' => 'zh_CN',
'link' => 'http://192.168.99.100:32777/page-markup-and-formatting',
@@ -56,12 +56,14 @@ protected function setUp()
public function testMe()
{
foreach ($this->data as $i) {
- $result = Transifex_Live_Integration_Rewrite::reverse_hard_link($i['lang'], $i['link'],
- $i['languages_map'], $i['souce_lang']);
+ $result = Transifex_Live_Integration_Rewrite::reverse_hard_link(
+ $i['lang'], $i['link'],
+ $i['languages_map'], $i['souce_lang']
+ );
- //eval(\Psy\sh());
- $this->assertEquals($i['result'], $result);
- }
+ //eval(\Psy\sh());
+ $this->assertEquals($i['result'], $result);
+ }
}
}
diff --git a/transifex-live-integration.php b/transifex-live-integration.php
index 8b975daf..22a4d1aa 100755
--- a/transifex-live-integration.php
+++ b/transifex-live-integration.php
@@ -5,13 +5,13 @@
*
* @link http://docs.transifex.com/developer/integrations/wordpress
* @package TransifexLiveIntegration
- * @version 1.2.5
+ * @version 1.3.0
*
* @wordpress-plugin
* Plugin Name: Transifex Live Translation Plugin
* Plugin URI: http://docs.transifex.com/developer/integrations/wordpress
* Description: Translate your WordPress website or blog without the usual complex setups.
- * Version: 1.2.5
+ * Version: 1.3.0
* License: GNU General Public License
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: transifex-live-integration
@@ -31,7 +31,11 @@
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_NAME' ) ) {
define( 'TRANSIFEX_LIVE_INTEGRATION_NAME', 'transifex-live-integration' );
}
-
+
+if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_BASENAME' ) ) {
+ define( 'TRANSIFEX_LIVE_INTEGRATION_BASENAME', plugin_basename( __FILE__ ) );
+}
+
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE' ) ) {
define( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE', dirname( __FILE__ ) );
}
@@ -41,7 +45,7 @@
}
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS' ) ) {
- define( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS', 'plugin_action_links_transifex_live_integration' );
+ define( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS', 'plugin_action_links_'.TRANSIFEX_LIVE_INTEGRATION_BASENAME );
}
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN' ) ) {
@@ -60,11 +64,12 @@
define( 'TRANSIFEX_LIVE_INTEGRATION_JAVASCRIPT', TRANSIFEX_LIVE_INTEGRATION_URL . 'javascript' );
}
-define( 'LANG_PARAM', 'lang' );
+if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_REGEX_PATTERN_CHECK_PATTERN' ) ) {
+ define( 'TRANSIFEX_LIVE_INTEGRATION_REGEX_PATTERN_CHECK_PATTERN', "/\(.*\?|.*\)/" );
+}
-require_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/plugin-debug.php';
-$version = '1.2.5';
-$debug = new Plugin_Debug();
+define( 'LANG_PARAM', 'lang' );
+$version = '1.3.0';
/**
* Main Plugin Class
@@ -77,114 +82,45 @@ class Transifex_Live_Integration {
* @param string $version Stores current version number.
*/
static function do_plugin( $is_admin, $version ) {
- Plugin_Debug::logTrace();
+ // Plugin 'global' functions
+ require_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/plugin-debug.php';
+ new Plugin_Debug(true);
+ Plugin_Debug::logTrace( 'debug initialized' );
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-defaults.php';
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-factory.php';
+
+// Load general settings
$settings = get_option( 'transifex_live_settings', array() );
if ( !$settings ) {
$settings = Transifex_Live_Integration_Defaults::settings();
}
+// Load rewrite settings
$rewrite_options = get_option( 'transifex_live_options', array() );
if ( !$rewrite_options ) {
$rewrite_options = Transifex_Live_Integration_Defaults::options_values();
}
- add_filter( 'query_vars', array( 'Transifex_Live_Integration', 'query_vars_hook' ) );
-
-
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-subdomain.php';
- $subdomain = Transifex_Live_Integration_Subdomain::create_subdomains( $settings );
- ($subdomain) ? Plugin_Debug::logTrace( 'subdomains created' ) : Plugin_Debug::logTrace( 'subdomains skipped' );
- if ( $subdomain ) {
- add_action( 'parse_query', [ $subdomain, 'parse_query_hook' ] );
- }
-
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-rewrite.php';
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-generate-rewrite-rules.php';
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-validators.php';
- $rewrite = Transifex_Live_Integration_Rewrite::create_rewrite( $settings, $rewrite_options );
- ($rewrite) ? Plugin_Debug::logTrace( 'rewrite created' ) : Plugin_Debug::logTrace( 'rewrite skipped' );
- if ( $rewrite ) {
- if ( isset( $rewrite_options['add_rewrites_reverse_template_links'] ) ) {
- Plugin_Debug::logTrace( 'adding reverse template links' );
- add_filter( 'pre_post_link', [$rewrite, 'pre_post_link_hook' ], 10, 3 );
- add_filter( 'term_link', [$rewrite, 'term_link_hook' ], 10, 3 );
- add_filter( 'post_link', [$rewrite, 'term_link_hook' ], 10, 3 );
- add_filter( 'post_type_archive_link', [$rewrite, 'post_type_archive_link_hook' ], 10, 2 );
- add_filter( 'page_link', [$rewrite, 'page_link_hook' ], 10, 3 );
- add_filter( 'day_link', [$rewrite, 'day_link_hook' ], 10, 4 );
- add_filter( 'month_link', [$rewrite, 'month_link_hook' ], 10, 3 );
- add_filter( 'year_link', [$rewrite, 'year_link_hook' ], 10, 2 );
-/* Turned off for compatibility with Yoast SEO - Mjj 3-7
- * add_filter( 'home_url', [$rewrite, 'home_url_hook' ] );
- */
- }
- foreach ($rewrite->rewrite_options as $option) {
- Plugin_Debug::logTrace( $option );
- switch ($option) {
- case 'date';
- add_filter( 'date_rewrite_rules', [ $rewrite, 'date_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'page';
- add_filter( 'page_rewrite_rules', [ $rewrite, 'page_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'author';
- add_filter( 'author_rewrite_rules', [ $rewrite, 'author_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'tag';
- add_filter( 'tag_rewrite_rules', [ $rewrite, 'tag_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'category';
- add_filter( 'category_rewrite_rules', [ $rewrite, 'category_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'search';
- add_filter( 'search_rewrite_rules', [ $rewrite, 'search_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'feed';
- add_filter( 'feed_rewrite_rules', [ $rewrite, 'feed_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'post';
- add_filter( 'post_rewrite_rules', [ $rewrite, 'post_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'root';
- add_filter( 'root_rewrite_rules', [ $rewrite, 'root_rewrite_rules_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- case 'permalink_tag';
- add_action( 'init', [ $rewrite, 'init_hook' ] );
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
- break;
- }
- }
- }
+// Add notranslate to admin bar
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-admin-util.php';
+ add_action( 'wp_before_admin_bar_render', [ 'Transifex_Live_Integration_Admin_Util', 'wp_before_admin_bar_render_hook' ] );
+ add_action( 'wp_after_admin_bar_render', [ 'Transifex_Live_Integration_Admin_Util', 'wp_after_admin_bar_render_hook' ] );
- Plugin_Debug::logTrace( 'adding admin bar actions' );
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-settings-util.php';
- add_action( 'wp_before_admin_bar_render', [ 'Transifex_Live_Integration_Settings_Util', 'wp_before_admin_bar_render_hook' ] );
- add_action( 'wp_after_admin_bar_render', [ 'Transifex_Live_Integration_Settings_Util', 'wp_after_admin_bar_render_hook' ] );
-
-
- if ( $is_admin ) {
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-action-links.php';
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( 'Transifex_Live_Integration_Action_Links', 'action_links' ) );
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-settings-page.php';
- add_action( 'admin_menu', [ 'Transifex_Live_Integration', 'admin_menu_hook' ] );
- add_action( 'admin_init', [ 'Transifex_Live_Integration_Settings_Page', 'admin_init_hook' ] );
+ if ( $is_admin ) { // If user is on admin pages
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-admin.php';
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-admin-util.php';
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/transifex-live-integration-static-files-handler.php';
- add_action( 'admin_notices', [ 'Transifex_Live_Integration_Settings_Page', 'admin_notices_hook' ] );
+// Setup admin dashboard backend
+ add_filter( TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS, [ 'Transifex_Live_Integration_Admin_Util', 'action_links' ] );
+ add_action( 'admin_menu', [ 'Transifex_Live_Integration_Admin_Util', 'admin_menu_hook' ] );
+ add_action( 'admin_init', [ 'Transifex_Live_Integration_Admin', 'admin_init_hook' ] );
+ add_action( 'admin_notices', [ 'Transifex_Live_Integration_Admin', 'admin_notices_hook' ] );
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-files-handler.php';
+// Setup admin dashboard frontend
$handler = new Transifex_Live_Integration_Static_Files_Handler();
$handler->add_css_file( $version, TRANSIFEX_LIVE_INTEGRATION_STYLESHEETS . '/transifex-live-integration-settings-page.css' );
@@ -192,65 +128,121 @@ static function do_plugin( $is_admin, $version ) {
$handler->add_js_file( $version, TRANSIFEX_LIVE_INTEGRATION_JAVASCRIPT . '/jquery-machine.1.0.1.min.js', 'jquery-machine' );
$handler->add_js_file( $version, TRANSIFEX_LIVE_INTEGRATION_JAVASCRIPT . '/transifex-live-integration-transifex-settings.js' );
$handler->add_js_file( $version, TRANSIFEX_LIVE_INTEGRATION_JAVASCRIPT . '/transifex-live-integration-settings-page.js' );
-
+
add_action( 'admin_enqueue_scripts', [ $handler, 'render_css' ] );
add_action( 'admin_enqueue_scripts', [ $handler, 'render_js' ] );
load_plugin_textdomain( TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN, false, TRANSIFEX_LIVE_INTEGRATION_LANGUAGES_PATH );
- } else {
+ }
+
+ if ( !($is_admin) ) { // If user is on regular page
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-factory.php';
+ include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-util.php';
+// Set lang parameter in query var
+ add_filter( 'query_vars', [ 'Transifex_Live_Integration_Util', 'query_vars_hook' ] );
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-prerender.php';
- $prerender = Transifex_Live_Integration_Prerender::create_prerender($settings);
- ($prerender) ? Plugin_Debug::logTrace( 'prerender created' ) : Plugin_Debug::logTrace( 'prerender skipped' );
- if ( $prerender ) {
- if (Transifex_Live_Integration_Prerender::is_prerender_req() ) {
- Plugin_Debug::logTrace( 'prerender request detected' );
- add_filter( 'wp_headers', [$prerender, 'wp_headers_hook'] );
- add_action( 'wp_head', [$prerender, 'wp_head_hook'], 1 );
- } else {
- Plugin_Debug::logTrace( 'invoke prerender call' );
- add_action('after_setup_theme', [ $prerender, 'after_setup_theme_hook']);
- add_action('shutdown', [ $prerender, 'shutdown_hook']);
+// Load snippet
+ $live_snippet = Transifex_Live_Integration_Static_Factory::create_live_snippet( $settings );
+ if ( $live_snippet ) {
+ // We need to wait until wp is setup to retrieve query var
+ add_action( 'wp', [ $live_snippet, 'wp_hook' ]);
+ add_action( 'wp_head', [ $live_snippet, 'wp_head_hook' ], 1 );
+ }
+
+
+// Load prerender feature
+ $prerender = Transifex_Live_Integration_Static_Factory::create_prerender( $settings );
+ ($prerender) ? Plugin_Debug::logTrace( 'prerender created' ) : Plugin_Debug::logTrace( 'prerender skipped' );
+ if ( $prerender ) {
+ if ( Transifex_Live_Integration_Util::is_prerender_req(Transifex_Live_Integration_Util::get_user_agent()) ) {
+ Plugin_Debug::logTrace( 'prerender request detected' );
+ add_filter( 'wp_headers', [$prerender, 'wp_headers_hook' ] );
+ add_action( 'wp_head', [$prerender, 'wp_head_hook' ], 1 );
+ } else {
+ Plugin_Debug::logTrace( 'invoke prerender call' );
+ add_action( 'after_setup_theme', [ $prerender, 'after_setup_theme_hook' ] );
+ add_action( 'shutdown', [ $prerender, 'shutdown_hook' ] );
+ }
}
- }
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-hreflang.php';
- $hreflang = new Transifex_Live_Integration_Hreflang( $settings, true );
- ($hreflang->ok_to_add()) ? Plugin_Debug::logTrace( 'adding hreflang' ) : Plugin_Debug::logTrace( 'skipping hreflang' );
- if ( $hreflang->ok_to_add() ) {
+// Load hreflang feature
+ $hreflang = Transifex_Live_Integration_Static_Factory::create_hreflang( $settings );
+ ($hreflang) ? Plugin_Debug::logTrace( 'adding hreflang' ) : Plugin_Debug::logTrace( 'skipping hreflang' );
+ if ( $hreflang ) {
add_action( 'wp_head', [ $hreflang, 'render_hreflang' ], 1 );
}
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-javascript.php';
- $javascript = new Transifex_Live_Integration_Javascript( $settings, $rewrite ? true : false );
- add_action( 'wp_head', [ $javascript, 'render' ], 1 );
-
- include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-picker.php';
- $picker = Transifex_Live_Integration_Picker::create_picker($settings);
+// Load language picker feature
+ $picker = Transifex_Live_Integration_Static_Factory::create_picker( $settings );
($picker) ? Plugin_Debug::logTrace( 'picker created' ) : Plugin_Debug::logTrace( 'picker skipped' );
if ( $picker ) {
add_action( 'wp_head', [ $picker, 'render' ], 1 );
}
- }
- }
- /**
- * Callback function for query_vars action
- * @param array $vars list of vars passed from WP.
- */
- static function query_vars_hook( $vars ) {
- Plugin_Debug::logTrace();
- $vars[] = 'lang';
- return $vars;
- }
+// Load subdomain feature
+ $subdomain = Transifex_Live_Integration_Static_Factory::create_subdomains( $settings );
+ ($subdomain) ? Plugin_Debug::logTrace( 'subdomains created' ) : Plugin_Debug::logTrace( 'subdomains skipped' );
+ if ( $subdomain ) {
+ add_action( 'parse_query', [ $subdomain, 'parse_query_hook' ] );
+ }
- /**
- * Callback function for admin_menu action
- */
- static function admin_menu_hook() {
- Plugin_Debug::logTrace();
- add_options_page( 'Transifex Live', 'Transifex Live', 'manage_options', TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN, array( 'Transifex_Live_Integration_Settings_Page', 'options_page' ) );
+// Load subdirectory feature
+ $rewrite = Transifex_Live_Integration_Static_Factory::create_rewrite( $settings, $rewrite_options );
+ ($rewrite) ? Plugin_Debug::logTrace( 'rewrite created' ) : Plugin_Debug::logTrace( 'rewrite skipped' );
+ if ( $rewrite ) {
+ if ( isset( $rewrite_options['add_rewrites_reverse_template_links'] ) ) {
+ Plugin_Debug::logTrace( 'adding reverse template links' );
+ add_action( 'wp', [ $rewrite, 'wp_hook' ]);
+ add_filter( 'pre_post_link', [$rewrite, 'pre_post_link_hook' ], 10, 3 );
+ add_filter( 'term_link', [$rewrite, 'term_link_hook' ], 10, 3 );
+ add_filter( 'post_link', [$rewrite, 'term_link_hook' ], 10, 3 );
+ add_filter( 'post_type_archive_link', [$rewrite, 'post_type_archive_link_hook' ], 10, 2 );
+ add_filter( 'page_link', [$rewrite, 'page_link_hook' ], 10, 3 );
+ add_filter( 'day_link', [$rewrite, 'day_link_hook' ], 10, 4 );
+ add_filter( 'month_link', [$rewrite, 'month_link_hook' ], 10, 3 );
+ add_filter( 'year_link', [$rewrite, 'year_link_hook' ], 10, 2 );
+ add_filter( 'home_url', [$rewrite, 'home_url_hook' ] );
+
+ }
+ add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
+
+ foreach ($rewrite->rewrite_options as $option) {
+ switch ($option) {
+ case 'date';
+ add_filter( 'date_rewrite_rules', [ $rewrite, 'date_rewrite_rules_hook' ] );
+ break;
+ case 'page';
+ add_filter( 'page_rewrite_rules', [ $rewrite, 'page_rewrite_rules_hook' ] );
+ break;
+ case 'author';
+ add_filter( 'author_rewrite_rules', [ $rewrite, 'author_rewrite_rules_hook' ] );
+ break;
+ case 'tag';
+ add_filter( 'tag_rewrite_rules', [ $rewrite, 'tag_rewrite_rules_hook' ] );
+ break;
+ case 'category';
+ add_filter( 'category_rewrite_rules', [ $rewrite, 'category_rewrite_rules_hook' ] );
+ break;
+ case 'search';
+ add_filter( 'search_rewrite_rules', [ $rewrite, 'search_rewrite_rules_hook' ] );
+ break;
+ case 'feed';
+ add_filter( 'feed_rewrite_rules', [ $rewrite, 'feed_rewrite_rules_hook' ] );
+ break;
+ case 'post';
+ add_filter( 'post_rewrite_rules', [ $rewrite, 'post_rewrite_rules_hook' ] );
+ break;
+ case 'root';
+ add_filter( 'root_rewrite_rules', [ $rewrite, 'root_rewrite_rules_hook' ] );
+ break;
+ case 'permalink_tag';
+ add_action( 'init', [ $rewrite, 'init_hook' ] );
+ break;
+ }
+ }
+ }
+ }
}
/**
@@ -268,5 +260,4 @@ static function activation_hook() {
}
}
-
-Transifex_Live_Integration::do_plugin( is_admin(), $version );
+Transifex_Live_Integration::do_plugin( is_admin(), $version );
\ No newline at end of file
diff --git a/uninstall.php b/uninstall.php
index 878d32e7..c1793fe4 100755
--- a/uninstall.php
+++ b/uninstall.php
@@ -19,26 +19,26 @@
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
- * @package Transifex_Live_Integration
+ * @package Transifex_Live_Integration
*/
// If uninstall not called from WordPress, then exit.
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
- exit;
+if (! defined('WP_UNINSTALL_PLUGIN') ) {
+ exit;
}
$settings_option_name = 'transifex_live_settings';
-delete_option( $settings_option_name );
+delete_option($settings_option_name);
$colors_option_name = 'transifex_live_colors';
-delete_option( $colors_option_name );
+delete_option($colors_option_name);
$options_option_name = 'transifex_live_options';
-delete_option( $options_option_name );
+delete_option($options_option_name);
$transifex_settings_option_name = 'transifex_live_transifex_settings';
-delete_option( $transifex_settings_option_name );
+delete_option($transifex_settings_option_name);
From 5b3bb0af9e128ae95b364875c1236263075b4fc5 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Tue, 29 Mar 2016 16:43:15 -0700
Subject: [PATCH 10/29] turn off debug
---
transifex-live-integration.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/transifex-live-integration.php b/transifex-live-integration.php
index 22a4d1aa..36334f4c 100755
--- a/transifex-live-integration.php
+++ b/transifex-live-integration.php
@@ -84,7 +84,7 @@ class Transifex_Live_Integration {
static function do_plugin( $is_admin, $version ) {
// Plugin 'global' functions
require_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/plugin-debug.php';
- new Plugin_Debug(true);
+ new Plugin_Debug(false);
Plugin_Debug::logTrace( 'debug initialized' );
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-defaults.php';
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-factory.php';
From cdb76d5d5879d4df0d1380742c0d1bdd9498caa8 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Wed, 30 Mar 2016 11:53:21 -0700
Subject: [PATCH 11/29] refactored parse query and rewrite
---
.../transifex-live-integration-rewrite.php | 11 +-
transifex-live-integration.php | 130 +++++++++---------
2 files changed, 75 insertions(+), 66 deletions(-)
diff --git a/includes/lib/transifex-live-integration-rewrite.php b/includes/lib/transifex-live-integration-rewrite.php
index 150e1388..9d48e449 100644
--- a/includes/lib/transifex-live-integration-rewrite.php
+++ b/includes/lib/transifex-live-integration-rewrite.php
@@ -112,10 +112,19 @@ function parse_query_hook( $query )
}
$qv = &$query->query_vars;
$qv['lang'] = isset($query->query_vars['lang']) ? $query->query_vars['lang'] : $this->source_language;
+ return $query;
+ }
+
+ function parse_query_root_hook( $query )
+ {
+ if (!Transifex_Live_Integration_Validators::is_query_ok($query) ) {
+ return $query;
+ }
+ $qv = &$query->query_vars;
if ($query->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) {
$query->is_page = true;
$query->is_home = false;
- $qv['page_id'] = get_option('page_on_front');
+// Dep'd 3/30/2016 Mjj $qv['page_id'] = get_option('page_on_front');
// Correct for page_on_front
if (!empty($qv['paged']) ) {
$qv['page'] = $qv['paged'];
diff --git a/transifex-live-integration.php b/transifex-live-integration.php
index 36334f4c..bdf02d11 100755
--- a/transifex-live-integration.php
+++ b/transifex-live-integration.php
@@ -31,11 +31,11 @@
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_NAME' ) ) {
define( 'TRANSIFEX_LIVE_INTEGRATION_NAME', 'transifex-live-integration' );
}
-
+
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_BASENAME' ) ) {
define( 'TRANSIFEX_LIVE_INTEGRATION_BASENAME', plugin_basename( __FILE__ ) );
-}
-
+}
+
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE' ) ) {
define( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE', dirname( __FILE__ ) );
}
@@ -45,7 +45,7 @@
}
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS' ) ) {
- define( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS', 'plugin_action_links_'.TRANSIFEX_LIVE_INTEGRATION_BASENAME );
+ define( 'TRANSIFEX_LIVE_INTEGRATION_ACTION_LINKS', 'plugin_action_links_' . TRANSIFEX_LIVE_INTEGRATION_BASENAME );
}
if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_TEXT_DOMAIN' ) ) {
@@ -84,7 +84,7 @@ class Transifex_Live_Integration {
static function do_plugin( $is_admin, $version ) {
// Plugin 'global' functions
require_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/plugin-debug.php';
- new Plugin_Debug(false);
+ new Plugin_Debug( true );
Plugin_Debug::logTrace( 'debug initialized' );
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-defaults.php';
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-factory.php';
@@ -107,7 +107,7 @@ static function do_plugin( $is_admin, $version ) {
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-admin-util.php';
add_action( 'wp_before_admin_bar_render', [ 'Transifex_Live_Integration_Admin_Util', 'wp_before_admin_bar_render_hook' ] );
add_action( 'wp_after_admin_bar_render', [ 'Transifex_Live_Integration_Admin_Util', 'wp_after_admin_bar_render_hook' ] );
-
+
if ( $is_admin ) { // If user is on admin pages
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/admin/transifex-live-integration-admin.php';
@@ -140,21 +140,21 @@ static function do_plugin( $is_admin, $version ) {
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-util.php';
// Set lang parameter in query var
add_filter( 'query_vars', [ 'Transifex_Live_Integration_Util', 'query_vars_hook' ] );
-
+
// Load snippet
$live_snippet = Transifex_Live_Integration_Static_Factory::create_live_snippet( $settings );
if ( $live_snippet ) {
// We need to wait until wp is setup to retrieve query var
- add_action( 'wp', [ $live_snippet, 'wp_hook' ]);
+ add_action( 'wp', [ $live_snippet, 'wp_hook' ] );
add_action( 'wp_head', [ $live_snippet, 'wp_head_hook' ], 1 );
}
-
+
// Load prerender feature
$prerender = Transifex_Live_Integration_Static_Factory::create_prerender( $settings );
($prerender) ? Plugin_Debug::logTrace( 'prerender created' ) : Plugin_Debug::logTrace( 'prerender skipped' );
if ( $prerender ) {
- if ( Transifex_Live_Integration_Util::is_prerender_req(Transifex_Live_Integration_Util::get_user_agent()) ) {
+ if ( Transifex_Live_Integration_Util::is_prerender_req( Transifex_Live_Integration_Util::get_user_agent() ) ) {
Plugin_Debug::logTrace( 'prerender request detected' );
add_filter( 'wp_headers', [$prerender, 'wp_headers_hook' ] );
add_action( 'wp_head', [$prerender, 'wp_head_hook' ], 1 );
@@ -186,60 +186,59 @@ static function do_plugin( $is_admin, $version ) {
if ( $subdomain ) {
add_action( 'parse_query', [ $subdomain, 'parse_query_hook' ] );
}
-
-// Load subdirectory feature
- $rewrite = Transifex_Live_Integration_Static_Factory::create_rewrite( $settings, $rewrite_options );
- ($rewrite) ? Plugin_Debug::logTrace( 'rewrite created' ) : Plugin_Debug::logTrace( 'rewrite skipped' );
- if ( $rewrite ) {
- if ( isset( $rewrite_options['add_rewrites_reverse_template_links'] ) ) {
- Plugin_Debug::logTrace( 'adding reverse template links' );
- add_action( 'wp', [ $rewrite, 'wp_hook' ]);
- add_filter( 'pre_post_link', [$rewrite, 'pre_post_link_hook' ], 10, 3 );
- add_filter( 'term_link', [$rewrite, 'term_link_hook' ], 10, 3 );
- add_filter( 'post_link', [$rewrite, 'term_link_hook' ], 10, 3 );
- add_filter( 'post_type_archive_link', [$rewrite, 'post_type_archive_link_hook' ], 10, 2 );
- add_filter( 'page_link', [$rewrite, 'page_link_hook' ], 10, 3 );
- add_filter( 'day_link', [$rewrite, 'day_link_hook' ], 10, 4 );
- add_filter( 'month_link', [$rewrite, 'month_link_hook' ], 10, 3 );
- add_filter( 'year_link', [$rewrite, 'year_link_hook' ], 10, 2 );
- add_filter( 'home_url', [$rewrite, 'home_url_hook' ] );
-
- }
- add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
-
- foreach ($rewrite->rewrite_options as $option) {
- switch ($option) {
- case 'date';
- add_filter( 'date_rewrite_rules', [ $rewrite, 'date_rewrite_rules_hook' ] );
- break;
- case 'page';
- add_filter( 'page_rewrite_rules', [ $rewrite, 'page_rewrite_rules_hook' ] );
- break;
- case 'author';
- add_filter( 'author_rewrite_rules', [ $rewrite, 'author_rewrite_rules_hook' ] );
- break;
- case 'tag';
- add_filter( 'tag_rewrite_rules', [ $rewrite, 'tag_rewrite_rules_hook' ] );
- break;
- case 'category';
- add_filter( 'category_rewrite_rules', [ $rewrite, 'category_rewrite_rules_hook' ] );
- break;
- case 'search';
- add_filter( 'search_rewrite_rules', [ $rewrite, 'search_rewrite_rules_hook' ] );
- break;
- case 'feed';
- add_filter( 'feed_rewrite_rules', [ $rewrite, 'feed_rewrite_rules_hook' ] );
- break;
- case 'post';
- add_filter( 'post_rewrite_rules', [ $rewrite, 'post_rewrite_rules_hook' ] );
- break;
- case 'root';
- add_filter( 'root_rewrite_rules', [ $rewrite, 'root_rewrite_rules_hook' ] );
- break;
- case 'permalink_tag';
- add_action( 'init', [ $rewrite, 'init_hook' ] );
- break;
- }
+ }
+ // Load subdirectory feature
+ $rewrite = Transifex_Live_Integration_Static_Factory::create_rewrite( $settings, $rewrite_options );
+ ($rewrite) ? Plugin_Debug::logTrace( 'rewrite created' ) : Plugin_Debug::logTrace( 'rewrite skipped' );
+ if ( $rewrite ) {
+ if ( isset( $rewrite_options['add_rewrites_reverse_template_links'] ) ) {
+ Plugin_Debug::logTrace( 'adding reverse template links' );
+ add_action( 'wp', [ $rewrite, 'wp_hook' ] );
+ add_filter( 'pre_post_link', [$rewrite, 'pre_post_link_hook' ], 10, 3 );
+ add_filter( 'term_link', [$rewrite, 'term_link_hook' ], 10, 3 );
+ add_filter( 'post_link', [$rewrite, 'term_link_hook' ], 10, 3 );
+ add_filter( 'post_type_archive_link', [$rewrite, 'post_type_archive_link_hook' ], 10, 2 );
+ add_filter( 'page_link', [$rewrite, 'page_link_hook' ], 10, 3 );
+ add_filter( 'day_link', [$rewrite, 'day_link_hook' ], 10, 4 );
+ add_filter( 'month_link', [$rewrite, 'month_link_hook' ], 10, 3 );
+ add_filter( 'year_link', [$rewrite, 'year_link_hook' ], 10, 2 );
+ add_filter( 'home_url', [$rewrite, 'home_url_hook' ] );
+ }
+ add_action( 'parse_query', [ $rewrite, 'parse_query_hook' ] );
+
+ foreach ($rewrite->rewrite_options as $option) {
+ switch ($option) {
+ case 'date';
+ add_filter( 'date_rewrite_rules', [ $rewrite, 'date_rewrite_rules_hook' ] );
+ break;
+ case 'page';
+ add_filter( 'page_rewrite_rules', [ $rewrite, 'page_rewrite_rules_hook' ] );
+ break;
+ case 'author';
+ add_filter( 'author_rewrite_rules', [ $rewrite, 'author_rewrite_rules_hook' ] );
+ break;
+ case 'tag';
+ add_filter( 'tag_rewrite_rules', [ $rewrite, 'tag_rewrite_rules_hook' ] );
+ break;
+ case 'category';
+ add_filter( 'category_rewrite_rules', [ $rewrite, 'category_rewrite_rules_hook' ] );
+ break;
+ case 'search';
+ add_filter( 'search_rewrite_rules', [ $rewrite, 'search_rewrite_rules_hook' ] );
+ break;
+ case 'feed';
+ add_filter( 'feed_rewrite_rules', [ $rewrite, 'feed_rewrite_rules_hook' ] );
+ break;
+ case 'post';
+ add_filter( 'post_rewrite_rules', [ $rewrite, 'post_rewrite_rules_hook' ] );
+ break;
+ case 'root';
+ add_filter( 'root_rewrite_rules', [ $rewrite, 'root_rewrite_rules_hook' ] );
+ add_action( 'parse_query', [ $rewrite, 'parse_query_root_hook' ] );
+ break;
+ case 'permalink_tag';
+ add_action( 'init', [ $rewrite, 'init_hook' ] );
+ break;
}
}
}
@@ -260,4 +259,5 @@ static function activation_hook() {
}
}
-Transifex_Live_Integration::do_plugin( is_admin(), $version );
\ No newline at end of file
+
+Transifex_Live_Integration::do_plugin( is_admin(), $version );
From f803499f4fbe753f856bd44d9c1e19a7bb65bdfa Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Wed, 30 Mar 2016 13:07:37 -0700
Subject: [PATCH 12/29] debug off
---
transifex-live-integration.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/transifex-live-integration.php b/transifex-live-integration.php
index bdf02d11..83930dcc 100755
--- a/transifex-live-integration.php
+++ b/transifex-live-integration.php
@@ -84,7 +84,7 @@ class Transifex_Live_Integration {
static function do_plugin( $is_admin, $version ) {
// Plugin 'global' functions
require_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/plugin-debug.php';
- new Plugin_Debug( true );
+ new Plugin_Debug( false );
Plugin_Debug::logTrace( 'debug initialized' );
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-defaults.php';
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/transifex-live-integration-static-factory.php';
From 0017172164360094f5158155ae7d7adefc8f07d3 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Wed, 30 Mar 2016 14:39:10 -0700
Subject: [PATCH 13/29] Added prerender header override This is for cases when
servers are managing our custom header
---
.../admin/transifex-live-integration-admin-template.php | 1 +
includes/admin/transifex-live-integration-admin.php | 5 ++++-
includes/lib/transifex-live-integration-prerender.php | 6 ++++--
includes/transifex-live-integration-defaults.php | 1 +
includes/transifex-live-integration-static-factory.php | 2 +-
5 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/includes/admin/transifex-live-integration-admin-template.php b/includes/admin/transifex-live-integration-admin-template.php
index d0203645..4e34a9f5 100644
--- a/includes/admin/transifex-live-integration-admin-template.php
+++ b/includes/admin/transifex-live-integration-admin-template.php
@@ -38,6 +38,7 @@
+ />Override Prerender Header Check
diff --git a/includes/admin/transifex-live-integration-admin.php b/includes/admin/transifex-live-integration-admin.php
index a12b0b3c..9d701e71 100644
--- a/includes/admin/transifex-live-integration-admin.php
+++ b/includes/admin/transifex-live-integration-admin.php
@@ -62,7 +62,10 @@ static function options_page() {
checked( $settings['enable_prerender'], 1 );
$checked_enable_prerender = ob_get_clean();
-
+ ob_start();
+ checked( $settings['override_prerender_check'], 1 );
+ $checked_override_prerender_check = ob_get_clean();
+
// These are used by the template: DO NOT REMOVE - Mjj 2/22/2016
$languages = [ ];
if ( $settings['transifex_languages'] !== '' ) {
diff --git a/includes/lib/transifex-live-integration-prerender.php b/includes/lib/transifex-live-integration-prerender.php
index 4ab33383..4b69f89a 100644
--- a/includes/lib/transifex-live-integration-prerender.php
+++ b/includes/lib/transifex-live-integration-prerender.php
@@ -4,11 +4,13 @@ class Transifex_Live_Integration_Prerender
{
private $prerender_url;
+ private $override_prerender_check;
- public function __construct($prerender_url)
+ public function __construct($prerender_url, $override_prerender_check)
{
Plugin_Debug::logTrace();
$this->prerender_url = $prerender_url;
+ $this->override_prerender_check = ($override_prerender_check)?true:false;
}
function wp_head_hook()
@@ -67,7 +69,7 @@ function callback( $buffer )
$error = curl_error($ch);
// write to db??
} else {
- if (strpos($header, 'X-PreRender-Req: TRUE') ) {
+ if (strpos($header, 'X-PreRender-Req: TRUE') || $this->override_prerender_check ) {
$output = $body;
}
}
diff --git a/includes/transifex-live-integration-defaults.php b/includes/transifex-live-integration-defaults.php
index c67efd56..40104430 100644
--- a/includes/transifex-live-integration-defaults.php
+++ b/includes/transifex-live-integration-defaults.php
@@ -89,6 +89,7 @@ static function settings()
'subdomain_pattern' => '',
'enable_prerender' => false,
'prerender_url' => '',
+ 'override_prerender_check' => false,
'whitelist_crawlers' =>
'googlebot|yahoo|bingbot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest/0.|developers.google.com/+/web/snippet|slackbot|vkshare|w3c_validator|redditbot|applebot|whatsapp|flipboard',
'generic_bot_types' => 'bot|crawl|slurp|spider'
diff --git a/includes/transifex-live-integration-static-factory.php b/includes/transifex-live-integration-static-factory.php
index 1efef5e4..a64c9354 100644
--- a/includes/transifex-live-integration-static-factory.php
+++ b/includes/transifex-live-integration-static-factory.php
@@ -116,7 +116,7 @@ static function create_prerender( $settings ) {
include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/lib/transifex-live-integration-prerender.php';
$check = Transifex_Live_Integration_Util::prerender_check( $agent, $req_escaped_fragment, $settings['generic_bot_types'], $settings['whitelist_crawlers'] );
- return ($check) ? new Transifex_Live_Integration_Prerender($settings['prerender_url']) : false;
+ return ($check) ? new Transifex_Live_Integration_Prerender($settings['prerender_url'], $settings['override_prerender_check']) : false;
}
}
From 003d9e2b391281ecf740d920076d567b10f21350 Mon Sep 17 00:00:00 2001
From: Matthew Jackowski
Date: Wed, 30 Mar 2016 16:38:23 -0700
Subject: [PATCH 14/29] Added additional options in admin page
---
...nsifex-live-integration-admin-template.php | 4 ++
.../transifex-live-integration-admin.php | 4 ++
includes/common/plugin-debug.php | 2 +-
.../transifex-live-integration-defaults.php | 2 +
transifex-live-integration.php | 40 ++++++++-----------
5 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/includes/admin/transifex-live-integration-admin-template.php b/includes/admin/transifex-live-integration-admin-template.php
index 4e34a9f5..4b67a7fe 100644
--- a/includes/admin/transifex-live-integration-admin-template.php
+++ b/includes/admin/transifex-live-integration-admin-template.php
@@ -92,6 +92,9 @@
Hi, this is a comment.
++To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.