WordPress.org

Plugin Directory

Changeset 1773898


Ignore:
Timestamp:
11/23/17 10:16:21 (4 weeks ago)
Author:
netweblogic
Message:

updating to 1.1

Location:
events-manager-wpml/trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • events-manager-wpml/trunk/em-wpml-install.php

    r1217437 r1773898  
    22if( version_compare( '0.3.3', get_option('em_wpml_version') )){ 
    33    global $wpdb; 
    4     $wpdb->query('DROP TABLE '.$wpdb->prefix.'em_wpml_events'); 
     4    $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'em_wpml_events'); 
    55} 
    66update_option('em_wpml_version', EM_WPML_VERSION); 
  • events-manager-wpml/trunk/em-wpml-io.php

    r1217437 r1773898  
    2727        add_action('em_ml_transfer_original_event', 'EM_WPML_IO::transfer_original',10,2); 
    2828        add_action('em_ml_transfer_original_location', 'EM_WPML_IO::transfer_original',10,2); 
     29        //WPML translation editor, we swap the 'save_post' action until custom fields have been copied. 
     30        add_action('wp_ajax_wpml_save_job_ajax', 'EM_WPML_IO::wp_ajax_wpml_save_job_ajax', 1); 
    2931    } 
    3032     
     
    132134        switch( get_post_type($id) ){ 
    133135            case EM_POST_TYPE_EVENT: 
    134                 //WPML just duplicated an event into another language, so we simply need to load the event and resave it 
     136                //WPML just duplicated an event into another language, so we simply need to load the event and resave it without an event ID (so it's regenerated) and the original event location ID  which isn't copied over properly 
     137                $EM_Event = em_get_event($master_post_id, 'post_id'); 
     138                $location_id = $EM_Event->location_id; 
    135139                $EM_Event = em_get_event($id, 'post_id'); 
    136140                $EM_Event->event_id = null; 
     141                $EM_Event->location_id = $location_id; 
    137142                $EM_Event->save(); 
    138143                break; 
     
    204209        return $result; 
    205210    } 
     211     
     212    /** 
     213     * WPML translation editor, we swap the 'save_post' action until custom fields have been copied.  
     214     */ 
     215    public static function wp_ajax_wpml_save_job_ajax() { 
     216        remove_action('save_post',array('EM_Event_Post_Admin','save_post'),1); 
     217        add_action('wpml_tm_save_post',array('EM_Event_Post_Admin','save_post')); 
     218    } 
    206219} 
    207220EM_WPML_IO::init(); 
  • events-manager-wpml/trunk/em-wpml-permalinks.php

    r1217437 r1773898  
    33 
    44    public static function init(){ 
    5         add_filter('em_rewrite_rules_array_events','EM_WPML_Permalnks::em_rewrite_rules_array_events', 10, 2); 
     5        remove_filter('rewrite_rules_array',array('EM_Permalinks','rewrite_rules_array')); 
     6        add_filter('rewrite_rules_array',array('EM_WPML_Permalnks','rewrite_rules_array')); 
     7        //suggested fix by WPML 
     8        if ( preg_match('/[0-9]{4}\-[0-9]{2}-[0-9]{2}\/?$/', $_SERVER['REQUEST_URI']) ) { 
     9            add_filter( 'query', array( 'EM_WPML_Permalnks', 'get_page_by_path_filter' ) ); 
     10        } 
    611    } 
    712     
    8     public static function em_rewrite_rules_array_events($em_rules, $events_slug){ 
     13    /** 
     14     * This function replaces EM's EM_Permalinks::rewrite_rules_array() function/filter so that we switch languages to the default language when rewriting permalinks.  
     15     * Otherwise some of our permalink paths will be based off the translated pages and not the main EM pages.   
     16     * @param array $rules 
     17     * @return array 
     18     */ 
     19    public static function rewrite_rules_array( $rules ){ 
     20        global $sitepress; 
     21        //check and switch blog to original language if necessary 
     22        $current_lang = $sitepress->get_current_language(); 
     23        $default_lang = $sitepress->get_default_language(); 
     24        if( $current_lang != $default_lang ) $sitepress->switch_lang($default_lang); 
     25        //run the EM permalinks within the original language context 
     26        $em_rules = EM_Permalinks::rewrite_rules_array(array()); 
     27        $em_rules = self::rewrite_rules_array_langs($em_rules); 
     28        //switch blog back to current languate 
     29        if( $current_lang != $default_lang ) $sitepress->switch_lang($current_lang); 
     30        return $em_rules + $rules; 
     31    } 
     32     
     33    /** 
     34     * Adds extra permalink structures to the rewrites array to account for different variations of tralsnated pages. 
     35     * Specifically, this deals with the calendar day pages showing a list of events on a specific date, which has a dynamic date endpoint in the URL. 
     36     * @param array $em_rules 
     37     * @return array 
     38     */ 
     39    public static function rewrite_rules_array_langs($em_rules){ 
    940        global $sitepress; 
    1041        $events_page = get_post( get_option('dbem_events_page') ); 
     42        //Detect if there's an event page 
    1143        if( is_object($events_page) ){ 
    12             $trid = $sitepress->get_element_trid($events_page->ID); 
     44            //get event page, current language, translations and real wpml home url of this site for use later on 
     45            $trid = $sitepress->get_element_trid($events_page->ID); 
    1346            $translations = $sitepress->get_element_translations($trid); 
    14             $default_lang = $sitepress->get_default_language(); 
     47            $current_lang = $sitepress->get_current_language(); 
     48            $wpml_url_converter = new WPML_URL_Converter_Url_Helper(); 
     49            $home_url = $wpml_url_converter->get_abs_home(); 
     50            //get settings for current URL structure 
     51            $wpml_settings = $sitepress->get_settings(); 
     52            $language_negotiation_type = !empty($wpml_settings['language_negotiation_type']) ? $wpml_settings['language_negotiation_type'] : 0; 
     53            //go through each translation and generate a permalink rule for the calendar day page 
    1554            foreach( $translations as $lang => $translation ){ 
    16                 if( $lang != $default_lang && $translation->post_status == 'publish'){ 
    17                     $events_slug = urldecode(preg_replace('/\/$/', '', str_replace( trailingslashit(home_url()), '', get_permalink($translation->element_id)) )); 
    18                     $em_rules[trailingslashit($events_slug).'(\d{4}-\d{2}-\d{2})$'] = 'index.php?page_id='.$translation->element_id.'&calendar_day=$matches[1]'; //event calendar date search 
     55                if( $lang != $current_lang && $translation->post_status == 'publish'){ 
     56                    //get translated urls for processing permalink matching translation of events page 
     57                    $home_url_translated = $sitepress->convert_url($home_url, $lang); //translated base URL 
     58                    $event_page_translated = get_permalink($translation->element_id); //translated events page used as base for rewrite rule 
     59                    //if we are using parameters for the language we need to strip the parameter from the urls here for correct insertion into rewrite rules 
     60                    if( $language_negotiation_type == '3' ){ 
     61                        $home_url_translated_parts = explode('?', $home_url_translated); 
     62                        $home_url_translated = $home_url_translated_parts[0]; 
     63                        $event_page_translated_parts = explode('?', $event_page_translated); 
     64                        $event_page_translated = $event_page_translated_parts[0]; 
     65                    } 
     66                    //remove the base URL from the events slug 
     67                    $events_slug = urldecode( preg_replace('/\/$/', '', str_replace(trailingslashit($home_url_translated), '', $event_page_translated)) ); 
     68                    //remove the language query parameter from the start of the link if we have directory-based permalinks e.g. /fr/events/etc/ => /events/etc/ 
     69                    if( $language_negotiation_type == '2' ) $events_slug = preg_replace('/^'.$lang.'\//', '', $events_slug); 
     70                    //add the rewrite preg structure to end of events slug 
     71                    $events_preg = trailingslashit($events_slug).'(\d{4}-\d{2}-\d{2})$'; 
     72                    //NUANCE - we can only add the rewrite rule if the events page slug of translations isn't the same as the original page, otherwise see get_page_by_path_filter workaround by WPML team 
     73                    if( empty($em_rules[$events_preg]) ){ 
     74                        $em_rules[$events_preg] = 'index.php?page_id='.$translation->element_id.'&calendar_day=$matches[1]'; //event calendar date search 
     75                    } 
    1976                } 
    2077            } 
    2178        } 
     79        //echo "<pre>"; print_r(trailingslashit(home_url())); echo "</pre>"; die(); 
    2280        return $em_rules; 
     81    } 
     82     
     83    /** 
     84     * Suggested fix by WPML 
     85     * Fixes permalink issues when viewing calendar day pages which acts as a dynamic endpoint on the events page. 
     86     * Specifically fixes the issue when the translated events page slug is the same as the original page language. 
     87     * @param string $query 
     88     * @return string 
     89     */ 
     90    public static function get_page_by_path_filter( $query ) { 
     91        global $sitepress, $wpdb; /* @var SitePress $sitepress */ 
     92        $trace = version_compare( ICL_SITEPRESS_VERSION, '3.8.2', '>=' ) ? 7:6; 
     93        $debug_backtrace = $sitepress->get_backtrace( $trace, true ); 
     94 
     95        if ( isset( $debug_backtrace[$trace-1]['function'] ) && $debug_backtrace[$trace-1]['function'] == 'get_page_by_path' ) { 
     96            $where = $wpdb->prepare( "ID IN ( SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE language_code = %s AND element_type LIKE 'post_%%' ) AND ", $sitepress->get_current_language() ); 
     97            $query = str_replace( "WHERE ", "WHERE " . $where, $query ); 
     98        } 
     99 
     100        return $query; 
    23101    } 
    24102} 
  • events-manager-wpml/trunk/events-manager-wpml.php

    r1219520 r1773898  
    22/* 
    33Plugin Name: Events Manager and WPML Compatibility 
    4 Version: 1.0.1 
     4Version: 1.1 
    55Plugin URI: http://wp-events-plugin.com 
    66Description: Integrates the Events Manager and WPML plugins together to provide a smoother multilingual experience (EM and WPML also needed) 
     
    1010 
    1111/* 
    12 Copyright (c) 2015, Marcus Sykes 
     12Copyright (c) 2017, Marcus Sykes 
    1313 
    1414This program is free software; you can redistribute it and/or 
     
    6565//TODO what happens if you create a language first in a second languge? 
    6666 
    67 define('EM_WPML_VERSION','0.3.3'); 
     67define('EM_WPML_VERSION','1.1'); 
    6868 
    6969//stores all master event info within a script run, to save repetitive db calls e.g. within an event format output operation. 
     
    9898        if( is_admin() ){ 
    9999            include('em-wpml-admin.php'); 
    100             include('em-wpml-permalinks.php'); //don't think we need this outside of admin, only when permalinks are rewritten 
    101100        } 
     101        include('em-wpml-permalinks.php'); 
    102102        include('em-wpml-io.php'); 
    103103        include('em-wpml-search.php'); 
    104         if( get_option('dbem_categories_enabled') || get_option('dbem_tags_enabled') ) include('em-wpml-taxonomies.php'); 
    105104         
    106105        //force disable recurring events 
     
    248247            //check we are adding a new translation belonging to a trid set 
    249248            if( $pagenow == 'post-new.php' && !empty($_REQUEST['trid']) ) return false; 
    250             //check if a translation is being submitted 
     249            //if this is a translation being edited (not first time), WPML submits this variable 
    251250            if( $pagenow == 'post.php' && !empty($_REQUEST['icl_translation_of']) ) return false; 
     251            //if this is a translation submitted, we have a trid and post ID we can use to check out 
     252            if( $pagenow == 'post.php' && !empty($_REQUEST['icl_trid']) && $object->post_id == $_REQUEST['post_ID'] ){ 
     253                $original_post_id = SitePress::get_original_element_id_by_trid($_REQUEST['icl_trid']); 
     254                return $original_post_id == $object->post_id || $original_post_id === false; 
     255            } 
    252256        } 
    253257        //if we got this far, check that $object has a post_id as EM_Event and EM_Location would have, and get the original translation via WPML 
     
    281285            //check a few admin specific stuff if a standard check didn't work, in case we're in the admin area translating via WPML 
    282286            if( empty($original_post_id) && is_admin() ){ 
    283                 if( !empty($_REQUEST['trid']) ){ 
     287                if( !empty($_REQUEST['trid']) || !empty($_REQUEST['icl_trid']) ){ 
     288                    $trid = !empty($_REQUEST['trid']) ? $_REQUEST['trid'] : $_REQUEST['icl_trid']; 
    284289                    //we are adding a new translation belonging to a trid set 
    285                     $original_post_id = SitePress::get_original_element_id_by_trid($_REQUEST['trid']); 
     290                    $original_post_id = SitePress::get_original_element_id_by_trid($trid); 
    286291                }elseif( !empty($_REQUEST['icl_translation_of']) ){ 
    287292                    //a new translation has just been submitted 
     
    346351        $sitepress_langs = $sitepress->get_active_languages(); 
    347352        $sitepress_lang = $sitepress->get_current_language(); 
     353        if( empty($sitepress_langs[$sitepress_lang]['default_locale']) ){ 
     354            return $sitepress_langs[$sitepress->get_default_language()]['default_locale']; 
     355        } 
    348356        return $sitepress_langs[$sitepress_lang]['default_locale']; 
    349357    } 
  • events-manager-wpml/trunk/readme.txt

    r1551898 r1773898  
    1 === Events Manager and WPML Compatibility === 
     1=== Events Manager and WPML Compatibility === 
    22Contributors: netweblogic 
    33Donate link: http://wp-events-plugin.com 
    44Tags: events, multilingual, wpml, event, event registration, event calendar, events calendar, event management 
    55Requires at least: 3.3 
    6 Tested up to: 4.7 
    7 Stable tag: 1.0.1 
     6Tested up to: 4.9 
     7Stable tag: 1.1 
    88License: GPLv2 
    99 
     
    3333WPML and Events Manager are both very complex plugins and there are some inevitable nuances and features that currently won't work and more time is needed to find appropriate solutions: 
    3434 
    35 * Pro Booking forms currently aren't translatable yet, planned for version 1.1 
    3635* Pro event booking reminders aren't translated correctly, planned for version 1.1 
    3736* Certain placeholders that output extra static text (such as #_BOOKINGSUMMARY outputting price 'Total') aren't fully translated. 
    3837* Recurring events 
    39  * Recurring Events can't be translated when editing the recurrence template, they must be done one by one i.e. at single event level 
     38 * Recurring Events can't be translated when editing the recurrence template, they must be done one by one  i.e. at single event level 
    4039 * Recurring events are disabled by default due to the above 
    41 * Location Searching 
     40* Location Searching and Lists 
    4241 * currently autocompleter forces searches for current languages, we may want to change this in the future to search all languages but give precedence to showing the translated version if available 
     42 * event-related search attributes won't work due to architectural limitations, if using [locations_map], use [events_map] instead 
    4343* MultiSite 
    4444 * Event Manager's MultiSite Global Tables Mode will not work as expected, listing events and locations from other sites will not return the correct items (if at all). This is due to the architecture of WPML vs. EM when in Global Tables Mode.  
     
    5353 
    5454== Changelog == 
     55= 1.1 = 
     56* fixed validation issues on first submission of a translation due to recent WPML changes 
     57* added fix for translation editor validation issues (kudos David) 
     58* removed unnecessary taxonomy filters thanks to recent fixes in EM and how data is written to $wp_query globals 
     59* fixed calendar day display issues in recent WPML versions 
     60* fixed category page display issues (mainly fixed in Events Manager 5.8) 
     61* fixed PHP warning on trash pages when viewing all lanaguages 
     62* fixed duplicating events via WPML not copying location information first time around 
     63* special thanks David Garcia Watkins and the rest of the WPML dev team for their assistance with many of these bugs! 
     64 
    5565= 1.0.1 = 
    5666* fixed PHP error causing parse errors and blank screens in some setups 
Note: See TracChangeset for help on using the changeset viewer.