Skip to content

Commit

Permalink
Merge pull request #11 from AppThemes/escape-explode
Browse files Browse the repository at this point in the history
Use cp_explode(), and register escaped values
  • Loading branch information
meloniq authored Sep 21, 2016
2 parents c378998 + ab6d934 commit 3affacf
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 31 deletions.
21 changes: 11 additions & 10 deletions languages/appthemes-wpml.pot
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: AppThemes WPML Bridge 1.0\n"
"Project-Id-Version: AppThemes WPML Bridge\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-02-14 16:07+0100\n"
"POT-Creation-Date: 2016-09-07 21:33+0200\n"
"PO-Revision-Date: 2013-02-14 16:07+0100\n"
"Last-Translator: AppThemes\n"
"Language-Team: AppThemes\n"
"Language: English\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Poedit 1.5.5\n"
"X-Generator: Poedit 1.8.9\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_nx:1,2;_x:1,2c;_ex:1,2c;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:1,2,3c\n"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
"_n_noop:1,2;_nx_noop:1,2,3c\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SearchPath-0: ..\n"

#: ../wpml.php:55
#: ../wpml.php:75
msgid "AppThemes WPML Bridge could not run."
msgstr ""

#: ../wpml.php:58
#: ../wpml.php:78
msgid "AppThemes WPML Bridge does not support the current theme."
msgstr ""

#: ../wpml.php:61
#: ../wpml.php:82
msgid "AppThemes WPML Bridge require WPML Multilingual CMS plugin to work."
msgstr ""

#: ../wpml.php:64
#: ../wpml.php:86
msgid "AppThemes WPML Bridge require WPML String Translation plugin to work."
msgstr ""
13 changes: 10 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== AppThemes WPML Bridge ===
Contributors: appthemes
Tags: appthemes, wpml, integration, language, localization, multilingual, classipress
Requires at least: 3.4
Tested up to: 3.6
Stable tag: 1.2
Requires at least: 4.0
Tested up to: 4.6.1
Stable tag: 1.3

This plugin adds additional WPML compatibility for AppThemes themes.

Expand Down Expand Up @@ -43,6 +43,13 @@ Report it with details on [AppThemes support forum](http://forums.appthemes.com/

== Changelog ==

= 1.3 =

* Use new function cp_explode() to properly handle checkbox values
* Register in WPML also escaped checkbox values
* Corrected loading plugin textdomain
* Fix typo in variable name

= 1.2 =

* Make all fields labels and values translatable on the single ClassiPress Ad page
Expand Down
97 changes: 86 additions & 11 deletions wpml-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function app_wpml_orders_remove_language_metabox() {
/**
* Payments: language selector for frontend order pages
* Orders are available only in one language, remove others from language selector
*
* @param array $languages
*
* @return array
*/
function app_wpml_orders_ls( $languages ) {
global $sitepress, $post;
Expand All @@ -61,10 +65,11 @@ function app_wpml_orders_ls( $languages ) {
$languages = $sitepress->get_ls_languages( array( 'skip_missing' => false ) );
$url = get_permalink( $post->ID );
foreach ( $languages as $code => $lang ) {
if ( $code == $lang_code )
if ( $code == $lang_code ) {
$languages[ $code ]['url'] = $sitepress->convert_url( $url, $code );
else
} else {
unset( $languages[ $code ] );
}
}
add_filter( 'icl_ls_languages', 'app_wpml_orders_ls' );
}
Expand All @@ -76,12 +81,17 @@ function app_wpml_orders_ls( $languages ) {

/**
* ClassiPress: hook into cp_add_new_listing(), set proper language for new listing
*
* @param int $post_id
*
* @return void
*/
function app_wpml_cp_add_new_listing( $post_id ) {
global $sitepress;

if ( $sitepress->get_current_language() == $sitepress->get_default_language() )
if ( $sitepress->get_current_language() == $sitepress->get_default_language() ) {
return;
}

$post_type = get_post_type( $post_id );
$sitepress->set_element_language_details( $post_id, 'post_' . $post_type, null, $sitepress->get_current_language() );
Expand All @@ -91,22 +101,39 @@ function app_wpml_cp_add_new_listing( $post_id ) {

/**
* ClassiPress: hook into cp_get_ad_details()
*
* @param object $result
* @param object $post
* @param string $location
*
* @return object
*/
function app_wpml_cp_ad_details_field( $result, $post, $location ) {
add_filter( 'cp_ad_details_' . $result->field_name, 'app_wpml_cp_ad_details_concrete_field', 10, 2 );
return $result;
}
add_filter( 'cp_ad_details_field', 'app_wpml_cp_ad_details_field', 10, 3 );

function app_wpml_cp_ad_details_concrete_field ( $args, $field ) {

/**
* @param array $args
* @param object $result
*
* @return array
*/
function app_wpml_cp_ad_details_concrete_field( $args, $field ) {

$args['label'] = icl_translate( APP_TD, 'label_' . $field->field_name, $field->field_label );

$values = (array) $args['value'];

if ( 'checkbox' === $field->field_type ) {
$values = explode( ',', $value );
$values = array_map( 'trim', $value );
if ( function_exists( 'cp_explode' ) ) {
$values = cp_explode( ',', $values );
} else {
$values = explode( ',', $values );
}
$values = array_map( 'trim', $values );
}

foreach ( $values as &$value ) {
Expand All @@ -118,17 +145,27 @@ function app_wpml_cp_ad_details_concrete_field ( $args, $field ) {
return $args;
}


/**
* ClassiPress: hook into cp_formbuilder(), cp_formbuilder_review()
*
* @param object $result
*
* @return object
*/
function app_wpml_cp_formbuilder_field( $result ) {
$result->field_label = icl_translate( APP_TD, 'label_' . $result->field_name, $result->field_label );

if ( ! empty( $result->field_tooltip ) )
if ( ! empty( $result->field_tooltip ) ) {
$result->field_tooltip = icl_translate( APP_TD, 'tooltip_' . $result->field_name, $result->field_tooltip );
}

if ( ! empty( $result->field_values ) ) {
$options = explode( ',', $result->field_values );
if ( function_exists( 'cp_explode' ) ) {
$options = cp_explode( ',', $result->field_values );
} else {
$options = explode( ',', $result->field_values );
}
$new_options = array();
foreach ( $options as $option ) {
$new_options[] = icl_t( APP_TD, 'value_' . $result->field_name . ' ' . trim( $option ), $option );
Expand All @@ -145,17 +182,28 @@ function app_wpml_cp_formbuilder_field( $result ) {

/**
* ClassiPress: hook into cp_package_field filter
*
* @param object $result
* @param string $type
*
* @return object
*/
function app_wpml_cp_package_field( $result, $type ) {
$result->pack_name = icl_translate( APP_TD, 'pack_name_' . $result->pack_id, $result->pack_name );
$result->pack_desc = icl_translate( APP_TD, 'pack_desc_' . $result->pack_id, $result->pack_desc );

return $result;
}
add_filter( 'cp_package_field', 'app_wpml_cp_package_field', 10, 2 );


/**
* ClassiPress: hook into get_pack()
*
* @param object $package
* @param int $pack_id
*
* @return object
*/
function app_wpml_cp_get_package( $package, $pack_id ) {
if ( ! empty( $package ) ) {
Expand All @@ -169,6 +217,11 @@ function app_wpml_cp_get_package( $package, $pack_id ) {

/**
* ClassiPress: hook into cp_display_message()
*
* @param string $message
* @param string $tag
*
* @return string
*/
function app_wpml_cp_display_message( $message, $tag ) {
return icl_translate( APP_TD, 'message_' . $tag, $message );
Expand All @@ -178,6 +231,11 @@ function app_wpml_cp_display_message( $message, $tag ) {

/**
* ClassiPress: hook into cp_custom_fields(), (un)registers strings immediately on maintaining custom fields
*
* @param string $action
* @param int $field_id
*
* @return void
*/
function app_wpml_cp_custom_fields( $action, $field_id ) {
global $wpdb;
Expand All @@ -191,7 +249,13 @@ function app_wpml_cp_custom_fields( $action, $field_id ) {
icl_register_string( APP_TD, 'label_' . $field->field_name, $field->field_label );
icl_register_string( APP_TD, 'tooltip_' . $field->field_name, $field->field_tooltip );
if ( ! empty( $field->field_values ) ) {
$options = array_map( 'trim', explode( ',', $field->field_values ) );
if ( function_exists( 'cp_explode' ) ) {
$options = array_map( 'trim', cp_explode( ',', $field->field_values ) );
} else {
$options = array_map( 'trim', explode( ',', $field->field_values ) );
}
$options_escaped = array_map( 'esc_attr', $options );
$options = array_merge( $options, $options_escaped );
foreach ( $options as $option ) {
icl_register_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option );
}
Expand All @@ -201,7 +265,13 @@ function app_wpml_cp_custom_fields( $action, $field_id ) {
icl_unregister_string( APP_TD, 'label_' . $field->field_name, $field->field_label );
icl_unregister_string( APP_TD, 'tooltip_' . $field->field_name, $field->field_tooltip );
if ( ! empty( $field->field_values ) ) {
$options = array_map( 'trim', explode( ',', $field->field_values ) );
if ( function_exists( 'cp_explode' ) ) {
$options = array_map( 'trim', cp_explode( ',', $field->field_values ) );
} else {
$options = array_map( 'trim', explode( ',', $field->field_values ) );
}
$options_escaped = array_map( 'esc_attr', $options );
$options = array_merge( $options, $options_escaped );
foreach ( $options as $option ) {
icl_unregister_string( APP_TD, 'value_' . $field->field_name . ' ' . $option, $option );
}
Expand Down Expand Up @@ -233,6 +303,10 @@ function app_wpml_cp_form_layouts_show_all_categories() {

/**
* ClassiPress: language selector for frontend Edit Ad page
*
* @param array $languages
*
* @return array
*/
function app_wpml_cp_ls( $languages ) {
global $sitepress, $post;
Expand Down Expand Up @@ -267,8 +341,9 @@ function app_wpml_cp_ls( $languages ) {
function app_wpml_cp_sticky_posts() {
global $sitepress, $pagenow;

if ( ( $pagenow == 'edit.php' ) && ! isset( $_GET['post_type'] ) )
if ( ( $pagenow == 'edit.php' ) && ! isset( $_GET['post_type'] ) ) {
return;
}

remove_filter( 'option_sticky_posts', array( $sitepress, 'option_sticky_posts' ) );
}
Expand Down
30 changes: 23 additions & 7 deletions wpml.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
<?php
/*
Plugin Name: AppThemes WPML Bridge
Plugin URI: https://docs.appthemes.com/wpml-bridge-plugin/
Description: Creates bridge between AppThemes Products and WPML plugin.
AppThemes ID: appthemes-wpml
Version: 1.2
Version: 1.3
Author: AppThemes
Author URI: http://appthemes.com
Text Domain: appthemes-wpml
Domain Path: /languages
*/


/**
* Plugin version and textdomain constants.
*/
define( 'APP_WPML_VERSION', '1.1' );
define( 'APP_WPML_VERSION', '1.3' );
define( 'APP_WPML_TD', 'appthemes-wpml' );


/**
* Load Text-Domain.
*
* @return void
*/
load_plugin_textdomain( APP_WPML_TD, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
function app_wpml_load_textdomain() {
load_plugin_textdomain( APP_WPML_TD, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'app_wpml_load_textdomain' );


/**
* Setup the WPML Bridge.
*
* @return void
*/
function app_wpml_setup() {

Expand All @@ -36,13 +45,15 @@ function app_wpml_setup() {
return;
}

require_once dirname( __FILE__ ) . '/wpml-actions.php';
require_once( dirname( __FILE__ ) . '/wpml-actions.php' );
}
add_action( 'plugins_loaded', 'app_wpml_setup' );


/**
* Check for existence of AppThemes Products.
*
* @return void
*/
function app_wpml_check_appthemes() {

Expand All @@ -56,19 +67,24 @@ function app_wpml_check_appthemes() {

/**
* Displays warning when AppThemes Theme or WPML plugin is not installed.
*
* @return void
*/
function app_wpml_display_warning() {

$message = __( 'AppThemes WPML Bridge could not run.', APP_WPML_TD );

if ( ! function_exists( 'appthemes_init' ) )
if ( ! function_exists( 'appthemes_init' ) ) {
$message = __( 'AppThemes WPML Bridge does not support the current theme.', APP_WPML_TD );
}

if ( ! defined( 'ICL_SITEPRESS_VERSION' ) )
if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
$message = __( 'AppThemes WPML Bridge require WPML Multilingual CMS plugin to work.', APP_WPML_TD );
}

if ( ! defined( 'WPML_ST_VERSION' ) )
if ( ! defined( 'WPML_ST_VERSION' ) ) {
$message = __( 'AppThemes WPML Bridge require WPML String Translation plugin to work.', APP_WPML_TD );
}

echo '<div class="error fade"><p>' . $message . '</p></div>';
deactivate_plugins( plugin_basename( __FILE__ ) );
Expand Down

0 comments on commit 3affacf

Please sign in to comment.