Skip to content

Commit

Permalink
Merge branch 'devel' of github.com:transifex/transifex-live-wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Jackowski committed May 13, 2016
2 parents 7fcb2fd + ecd9c8d commit 4fcad4b
Show file tree
Hide file tree
Showing 16 changed files with 1,200 additions and 1,097 deletions.
Binary file modified assets/screenshot-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshot-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshot-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
259 changes: 133 additions & 126 deletions includes/admin/transifex-live-integration-admin-template.php

Large diffs are not rendered by default.

47 changes: 29 additions & 18 deletions includes/admin/transifex-live-integration-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ static function options_page() {
ob_start();
checked( $settings['enable_prerender'], 1 );
$checked_enable_prerender = ob_get_clean();

ob_start();
checked( $settings['enable_prerender_check'], 1 );
$checked_enable_prerender_check = ob_get_clean();

ob_start();
checked( $settings['prerender_enable_response_header'], 1 );
$checked_prerender_enable_response_header = ob_get_clean();
Expand All @@ -105,6 +105,10 @@ static function options_page() {
checked( $settings['static_frontpage_support'], 1 );
$checked_static_frontpage_support = ob_get_clean();

ob_start();
checked( $settings['enable_seo'], 1 );
$checked_enable_seo = ob_get_clean();

// These are used by the template: DO NOT REMOVE - Mjj 2/22/2016
$languages = [ ];
if ( $settings['transifex_languages'] !== '' ) {
Expand All @@ -121,7 +125,7 @@ static function options_page() {
$source_language = $settings['source_language'];
}

$language_lookup = [ ];
$language_lookup = '';
if ( $settings['language_lookup'] !== '' ) {
$language_lookup = $settings['language_lookup'];
}
Expand All @@ -130,17 +134,22 @@ static function options_page() {
if ( $settings['language_map'] !== '' ) {
$language_map = $settings['language_map'];
}


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

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

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

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

$url_options = $settings['url_options'];
Expand All @@ -153,8 +162,8 @@ static function options_page() {
ob_start();
checked( $settings['url_options'], '3' );
$url_options_subdirectory = ob_get_clean();


$site_url = site_url();
$site_url_subdirectory_example = $site_url . '/%lang%';
$site_url_array = explode( '/', $site_url );
Expand Down Expand Up @@ -206,13 +215,14 @@ static public function update_settings( $settings ) {

$languages = '';
$languages_regex = '';
foreach ($transifex_languages as $lang) {
$trim = true;
$languages .= $languages_map[0][$lang];
$languages .= ",";
$languages_regex .= $languages_map[0][$lang];
$languages_regex .= "|";
}
if ( $transifex_languages != null )
foreach ($transifex_languages as $lang) {
$trim = true;
$languages .= $languages_map[0][$lang];
$languages .= ",";
$languages_regex .= $languages_map[0][$lang];
$languages_regex .= "|";
}

$languages = ($trim) ? rtrim( $languages, ',' ) : '';
$languages_regex = ($trim) ? rtrim( $languages_regex, '|' ) : '';
Expand Down Expand Up @@ -271,7 +281,7 @@ static public function admin_notices_hook() {
}

if ( $is_admin_page_notice ) {
echo '<div class="notice is-dismissable">' . $notice . '</div>';
echo '<div class="notice notice-success is-dismissable">' . $notice . '</div>';
}
if ( $is_admin_dashboard_notice ) {
echo '<div class="clear"></div>';
Expand All @@ -290,6 +300,7 @@ static public function sanitize_settings( $settings ) {
$settings['transifex_live_settings']['languages'] = ( isset( $settings['transifex_live_settings']['languages'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_settings']['languages'] ) ) : '';
$settings['transifex_live_settings']['language_lookup'] = ( isset( $settings['transifex_live_settings']['language_lookup'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_settings']['language_lookup'] ) ) : '';
$settings['transifex_live_settings']['language_map'] = ( isset( $settings['transifex_live_settings']['language_map'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_settings']['language_map'] ) ) : '';
$settings['transifex_live_settings']['hreflang_map'] = ( isset( $settings['transifex_live_settings']['hreflang_map'] )) ? sanitize_text_field( stripslashes( $settings['transifex_live_settings']['hreflang_map'] ) ) : '';
$settings['transifex_live_settings']['source_language'] = ( isset( $settings['transifex_live_settings']['source_language'] )) ? sanitize_text_field( $settings['transifex_live_settings']['source_language'] ) : '';
$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'] ) : '';
Expand All @@ -300,4 +311,4 @@ static public function sanitize_settings( $settings ) {
return $settings;
}

}
}
43 changes: 24 additions & 19 deletions includes/lib/transifex-live-integration-hreflang.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/transifex-live-integration-common.php';
/**
* Includes hreflang tag attribute on each page
Expand All @@ -15,25 +16,25 @@ class Transifex_Live_Integration_Hreflang {
* @var settings array
*/
private $settings;

private $hreflang_map;

/*
* A key/value array that maps Transifex locale->plugin code
* @var language_map array
*/
private $language_map;

/*
* A list of Transifex locales, for enabled languages
* @var languages array
*/
private $languages;

/*
* The site_url with a placeholder for language
* @var tokenized_url string
*/
private $tokenized_url;

private $rewrite_options;

/**
Expand All @@ -47,35 +48,36 @@ public function __construct( $settings, $rewrite_options ) {
$this->languages = json_decode( $settings['transifex_languages'], true );
$this->tokenized_url = $settings['tokenized_url'];
$this->rewrite_options = $rewrite_options;
$this->hreflang_map = json_decode( $settings['hreflang_map'], true )[0];
}

public function check_rewrite_options() {
Plugin_Debug::logTrace();
if ( isset( $this->rewrite_options['add_rewrites_post'] ) && is_single ()) {
if ( isset( $this->rewrite_options['add_rewrites_post'] ) && is_single() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_root'] ) && is_home()) {
if ( isset( $this->rewrite_options['add_rewrites_root'] ) && is_home() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_date'] ) && is_archive()) {
if ( isset( $this->rewrite_options['add_rewrites_date'] ) && is_archive() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_page'] ) && is_page ()) {
if ( isset( $this->rewrite_options['add_rewrites_page'] ) && is_page() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_author'] ) && is_author()) {
if ( isset( $this->rewrite_options['add_rewrites_author'] ) && is_author() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_tag'] ) && is_tag()) {
if ( isset( $this->rewrite_options['add_rewrites_tag'] ) && is_tag() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_category'] ) && is_category()) {
if ( isset( $this->rewrite_options['add_rewrites_category'] ) && is_category() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_search'] ) && is_search()) {
if ( isset( $this->rewrite_options['add_rewrites_search'] ) && is_search() ) {
return true;
}
if ( isset( $this->rewrite_options['add_rewrites_feed'] ) && is_feed()) {
if ( isset( $this->rewrite_options['add_rewrites_feed'] ) && is_feed() ) {
return true;
}
return false;
Expand All @@ -88,8 +90,9 @@ public function check_rewrite_options() {
* @param array $language_map The key/value list of Transifex locale->plugin code
* @return array A list of attributes for HREFLANG tags
*/

private function generate_languages_hreflang( $raw_url, $languages,
$language_map
$language_map, $hreflang_map
) {
Plugin_Debug::logTrace();
$url_map = Transifex_Live_Integration_Common::generate_language_url_map( $raw_url, $this->tokenized_url, $language_map );
Expand All @@ -98,7 +101,7 @@ private function generate_languages_hreflang( $raw_url, $languages,
$arr = [ ];

$arr['href'] = $url_map[$language];
$arr['hreflang'] = $language_map[$language];
$arr['hreflang'] = $hreflang_map[$language];
array_push( $ret, $arr );
}
return $ret;
Expand All @@ -109,21 +112,23 @@ private function generate_languages_hreflang( $raw_url, $languages,
*/
public function render_hreflang() {
Plugin_Debug::logTrace();
if ( !($this->check_rewrite_options())) {
if ( !($this->check_rewrite_options()) ) {
return false;
}
global $wp;
$lang = get_query_var( 'lang' );
$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;
$site_url_slash_maybe = site_url();
$site_url = rtrim( $site_url_slash_maybe, '/' ) . '/';
$unslashed_source_url = $site_url . $source_url_path;
$source_url = rtrim( $unslashed_source_url, '/' ) . '/';
$hreflang_out = '';
$hreflang_out .= <<<SOURCE
<link rel="alternate" href="$source_url" hreflang="$source"/>\n
SOURCE;
$hreflangs = $this->generate_languages_hreflang( $source_url_path, $this->languages, $this->language_map );
$hreflangs = $this->generate_languages_hreflang( $source_url_path, $this->languages, $this->language_map, $this->hreflang_map );
foreach ($hreflangs as $hreflang) {
$href_attr = $hreflang['href'];
$hreflang_attr = $hreflang['hreflang'];
Expand Down
6 changes: 3 additions & 3 deletions includes/lib/transifex-live-integration-prerender.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public function __construct( $prerender_url, $enable_prerender_check, $settings
$this->prerender_enable_response_header = (isset( $settings['prerender_enable_response_header'] )) ? true : false;
$this->generic_bot_types = $settings['generic_bot_types'];
$this->whitelist_crawlers = $settings['whitelist_crawlers'];

$this->prerender_response_headers = [ ];
if ( isset( $settings['prerender_response_headers'] ) ) {
$this->prerender_response_headers = json_decode( stripslashes($settings['prerender_response_headers']), true );
$this->prerender_response_headers = json_decode( stripslashes( $settings['prerender_response_headers'] ), true );
}

$this->prerender_enable_cookie = (isset( $settings['prerender_enable_cookie'] )) ? true : false;
$this->prerender_cookie = [ ];
if ( isset( $settings['prerender_cookie'] ) ) {
$this->prerender_cookie = json_decode( stripslashes($settings['prerender_cookie']), true );
$this->prerender_cookie = json_decode( stripslashes( $settings['prerender_cookie'] ), true );
}
}

Expand Down
4 changes: 2 additions & 2 deletions includes/lib/transifex-live-integration-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function post_rewrite_rules_hook( $rules ) {
$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 );
$rr = Transifex_Live_Integration_Generate_Rewrite_Rules::generate_rewrite_rules( $pp, EP_PERMALINK, true, false, false, true );
$rewrite = array_merge( $rr, $rules );
return $rewrite;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ function search_rewrite_rules_hook( $rules ) {
}
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag( '%lang%', $this->languages_regex, 'lang=' );
$pp = $this->generate_page_permastruct();
$pp = $this->generate_search_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;
Expand Down
Loading

0 comments on commit 4fcad4b

Please sign in to comment.