Guest User

avia.js

a guest
Oct 12th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 23.71 KB | None | 0 0
  1. <?php
  2.  
  3. /* - WPML compatibility - */
  4. if(defined('ICL_SITEPRESS_VERSION') && defined('ICL_LANGUAGE_CODE'))
  5. {
  6.     add_filter( 'avia_filter_base_data' , 'avia_wpml_options_language' );
  7.     add_filter( 'avia_filter_backend_page_title' , 'avia_wpml_backend_page_title' );
  8.     //add_action( 'init', 'avia_wpml_register_post_type_permalink', 20);
  9.     add_action( 'avia_action_before_framework_init', 'avia_wpml_get_languages');
  10.     //add_filter( 'icl_ls_languages' , 'avia_wpml_url_filter' );
  11.     add_action( 'init', 'avia_wpml_backend_language_switch');
  12.     //add_action( 'avia_wpml_backend_language_switch', 'avia_default_dynamics');
  13.     add_action( 'avia_wpml_backend_language_switch', 'avia_wpml_copy_options');
  14.     add_action( 'wp_enqueue_scripts', 'avia_wpml_register_assets' );
  15.    
  16.     add_filter( 'avf_execute_avia_meta_header', '__return_true', 10, 1);
  17.  
  18.  
  19.  
  20.     /*
  21.     * This function makes it possible that all backend options can be saved several times
  22.     * for different languages. It appends a language string to the key of the options entry
  23.     * that is saved to the wordpress database.
  24.     *
  25.     * Since the Avia Framework only uses a single option array for the whole backend and
  26.     * then serializes that array and saves it to a single database entry this is a very
  27.     * easy and flexible method to setup your site in any way you want with muliple
  28.     * languages, layouts, logos, dynamic templates, etc for each language
  29.     */
  30.  
  31.     if(!function_exists('avia_wpml_options_language'))
  32.     {
  33.         function avia_wpml_options_language($base_data)
  34.         {
  35.             global $avia_config;
  36.             $wpml_options = $avia_config['wpml']['settings'];
  37.  
  38.             if((isset($wpml_options['default_language']) && $wpml_options['default_language'] != ICL_LANGUAGE_CODE) && 'all' != ICL_LANGUAGE_CODE && "" != ICL_LANGUAGE_CODE)
  39.             {
  40.                 $base_data['prefix_origin'] = $base_data['prefix'];
  41.                 $base_data['prefix'] = $base_data['prefix'] . "_" . ICL_LANGUAGE_CODE;
  42.             }
  43.  
  44.             return $base_data;
  45.         }
  46.     }
  47.  
  48.     /*check if we are using the default language*/
  49.     if(!function_exists('avia_wpml_is_default_language'))
  50.     {
  51.         function avia_wpml_is_default_language()
  52.         {
  53.             global $avia_config;
  54.             $wpml_options = $avia_config['wpml']['settings'];
  55.  
  56.             if((isset($wpml_options['default_language']) && $wpml_options['default_language'] != ICL_LANGUAGE_CODE) && 'all' != ICL_LANGUAGE_CODE && "" != ICL_LANGUAGE_CODE)
  57.             {
  58.                 return false;
  59.             }
  60.             else
  61.             {
  62.                 return true;
  63.             }
  64.         }
  65.     }
  66.  
  67.     /*fetch some default data necessary for the framework*/
  68.     if(!function_exists('avia_wpml_get_languages'))
  69.     {
  70.         function avia_wpml_get_languages()
  71.         {
  72.             global $sitepress, $avia_config;
  73.             $avia_config['wpml']['lang']        = $sitepress->get_active_languages();
  74.             $avia_config['wpml']['settings']    = get_option('icl_sitepress_settings');
  75.         }
  76.     }
  77.  
  78.     /*language switch hook for the backend*/
  79.     if(!function_exists('avia_wpml_backend_language_switch'))
  80.     {
  81.         function avia_wpml_backend_language_switch()
  82.         {
  83.             if(isset($_GET['lang']) && is_admin())
  84.             {
  85.                 do_action('avia_wpml_backend_language_switch');
  86.             }
  87.         }
  88.     }
  89.  
  90.  
  91.  
  92.     /*
  93.       get an option from the database based on the option key passed.
  94.       other then with the default avia_get_option function this one retrieves all language entries and passes them as array
  95.     */
  96.  
  97.     if(!function_exists('avia_wpml_get_options'))
  98.     {
  99.         function avia_wpml_get_options($option_key)
  100.         {
  101.             global $avia, $avia_config;
  102.  
  103.             if(!isset($avia->wpml))
  104.             {
  105.                 $key            = isset($avia->base_data['prefix_origin']) ? $avia->base_data['prefix_origin'] : $avia->base_data['prefix'];
  106.                 $key            = 'avia_options_'.avia_backend_safe_string( $key );
  107.                 $wpml_options   = $avia_config['wpml']['settings'];
  108.  
  109.                 $key_array = array();
  110.                 if(is_array($avia_config['wpml']['lang'] ))
  111.                 {
  112.                     foreach($avia_config['wpml']['lang'] as $lang => $values)
  113.                     {
  114.                         if($wpml_options['default_language'] != $lang)
  115.                         {
  116.                             $key_array[$lang] = $key ."_".$lang;
  117.                         }
  118.                         else
  119.                         {
  120.                             $key_array[$lang] = $key;
  121.                         }
  122.  
  123.                         $avia->wpml[$lang] = get_option($key_array[$lang]);
  124.                     }
  125.                 }
  126.             }
  127.  
  128.             $option = array();
  129.  
  130.             if(isset($avia->wpml))
  131.             {
  132.                 foreach($avia->wpml as $language => $option_set)
  133.                 {
  134.                     if(isset($option_set['avia']) && isset($option_set['avia'][$option_key]))
  135.                     {
  136.                         $option[$language] = $option_set['avia'][$option_key];
  137.                     }
  138.                     else
  139.                     {
  140.                         $option[$language] = false;
  141.                     }
  142.                 }
  143.             }
  144.             return $option;
  145.         }
  146.     }
  147.  
  148.     /*
  149.     * Filters the menu entry in the backend and displays the language in addition to the theme name
  150.     */
  151.     if(!function_exists('avia_wpml_backend_page_title'))
  152.     {
  153.         function avia_wpml_backend_page_title($title)
  154.         {
  155.             if(ICL_LANGUAGE_CODE == "") return $title;
  156.  
  157.             $append = "";
  158.             if('all' != ICL_LANGUAGE_CODE)
  159.             {
  160.                 $append = " (".strtoupper( ICL_LANGUAGE_CODE ).")";
  161.             }
  162.             else
  163.             {
  164.                 global $avia_config;
  165.  
  166.                 $wpml_options   = $avia_config['wpml']['settings'];
  167.                 $append         = " (".strtoupper( $wpml_options['default_language'] ).")";
  168.             }
  169.             return $title . $append;
  170.         }
  171.     }
  172.  
  173.     /*
  174.     * Creates an additional dynamic slug rewrite rule for custom categories
  175.     */
  176.     if(!function_exists('avia_wpml_register_post_type_permalink'))
  177.     {
  178.         function avia_wpml_register_post_type_permalink() {
  179.  
  180.             global $wp_post_types, $wp_rewrite, $wp, $avia_config;
  181.  
  182.             if(!isset($avia_config['custom_post'])) return false;
  183.  
  184.             $slug_array = avia_wpml_get_options('portfolio-slug');
  185.  
  186.             foreach($avia_config['wpml']['lang'] as $lang => $values)
  187.             {
  188.                 foreach($avia_config['custom_post'] as $post_type => $arguments)
  189.                 {
  190.                     $args = (object) $arguments['args'];
  191.                     $args->rewrite['slug'] = $slug_array[$lang];
  192.                     $args->permalink_epmask = EP_PERMALINK;
  193.                     $post_type = sanitize_key($post_type);
  194.  
  195.                     if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) )
  196.                     {
  197.                         $wp_rewrite->add_permastruct($post_type."_$lang", "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
  198.                     }
  199.                 }
  200.             }
  201.         }
  202.     }
  203.  
  204.     /*
  205.     * Filters the links generated for the language switcher in case a user is viewing a single portfolio entry and changes the portfolio slug if necessary
  206.     */
  207.     if(!function_exists('avia_wpml_url_filter'))
  208.     {
  209.         function avia_wpml_url_filter($lang)
  210.         {
  211.             $post_type  = get_post_type();
  212.  
  213.             if("portfolio" == $post_type)
  214.             {
  215.                 $slug       = avia_wpml_get_options('portfolio-slug');
  216.  
  217.                 $current    = isset($slug[ICL_LANGUAGE_CODE]) ? $slug[ICL_LANGUAGE_CODE] : "";
  218.                 foreach ($lang as $key => $options)
  219.                 {
  220.                     if(isset($options['url']) && $current != "" && $current != $slug[$key] && "" != $slug[$key])
  221.                     {
  222.                         $lang[$key]['url'] = str_replace("/".$current."/", "/".$slug[$key]."/", $lang[$key]['url']);
  223.                     }
  224.                 }
  225.             }
  226.             return $lang;
  227.         }
  228.     }
  229.  
  230.  
  231.     /*
  232.     * register css styles
  233.     */
  234.     if(!function_exists('avia_wpml_register_assets'))
  235.     {
  236.         function avia_wpml_register_assets()
  237.         {
  238.             $theme = wp_get_theme();
  239.             $version = ( false === $theme->parent() ) ? $theme->get( 'Version' ) : $theme->parent()->get( 'Version' );
  240.            
  241.             wp_enqueue_style( 'avia-wpml', AVIA_BASE_URL.'config-wpml/wpml-mod.css', array(), $version );
  242.             wp_enqueue_script( 'avia-wpml-script', AVIA_BASE_URL.'config-wpml/wpml-mod.js', array( 'jquery' ), $version );
  243.         }
  244.     }
  245.  
  246.     /*
  247.     * styleswitcher for the avia framework
  248.     */
  249.     if(!function_exists('avia_wpml_language_switch'))
  250.     {
  251.         add_action( 'avia_meta_header', 'avia_wpml_language_switch', 10);
  252.         add_action( 'ava_main_header_sidebar', 'avia_wpml_language_switch', 10);
  253.  
  254.         function avia_wpml_language_switch()
  255.         {
  256.             global $sitepress, $avia_config;
  257.            
  258.             if(empty($avia_config['wpml_language_menu_position'])) $avia_config['wpml_language_menu_position'] = apply_filters('avf_wpml_language_switcher_position', 'sub_menu');
  259.             if($avia_config['wpml_language_menu_position'] != 'sub_menu') return;
  260.  
  261.             $languages = icl_get_languages('skip_missing=0&orderby=custom');
  262.             $output = "";
  263.  
  264.             if(is_array($languages))
  265.             {
  266.                 $output .= "<ul class='avia_wpml_language_switch avia_wpml_language_switch_extra'>";
  267.  
  268.                 foreach($languages as $lang)
  269.                 {
  270.                     $currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
  271.  
  272.                     if(!avia_is_overview() && (is_home() || is_front_page())) $lang['url'] = $sitepress->language_url($lang['language_code']);
  273.                              
  274.                     $output .= "<li class='language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>";
  275.                     $output .= "    <span class='language_flag'><img title='".$lang['native_name']."' src='".$lang['country_flag_url']."' alt='".$lang['native_name']."' /></span>";
  276.                     $output .= "    <span class='language_native'>".$lang['native_name']."</span>";
  277.                     $output .= "    <span class='language_translated'>".$lang['translated_name']."</span>";
  278.                     $output .= "    <span class='language_code'>".$lang['language_code']."</span>";
  279.                     $output .= "</a></li>";
  280.                 }
  281.  
  282.                 $output .= "</ul>";
  283.             }
  284.  
  285.             echo $output;
  286.         }
  287.     }
  288.  
  289.     /*
  290.     * copy the default option set to the current language if no options set for this language is available yet
  291.     */
  292.     if(!function_exists('avia_wpml_copy_options'))
  293.     {
  294.         function avia_wpml_copy_options()
  295.         {
  296.             global $avia, $avia_config;
  297.  
  298.             $key            = isset($avia->base_data['prefix_origin']) ? $avia->base_data['prefix_origin'] : $avia->base_data['prefix'];
  299.             $original_key   = 'avia_options_'.avia_backend_safe_string( $key );
  300.             $language_key   = 'avia_options_'.avia_backend_safe_string( $avia->base_data['prefix'] );
  301.  
  302.             if($original_key !== $language_key)
  303.             {
  304.                 $lang_set = get_option($language_key);
  305.  
  306.                 if(empty($lang_set))
  307.                 {
  308.                     $lang_set = get_option($original_key);
  309.                     update_option($language_key, $lang_set);
  310.  
  311.                     wp_redirect( $_SERVER['REQUEST_URI'] );
  312.                     exit();
  313.                 }
  314.             }
  315.         }
  316.     }
  317.  
  318.  
  319.  
  320.  
  321.     //Add all the necessary filters. There are a LOT of WordPress functions, and you may need to add more filters for your site.
  322.     if(!function_exists('avia_wpml_correct_domain_in_url'))
  323.     {
  324.         // some installs require this fix: https://wpml.org/errata/enfold-theme-styles-not-loading-with-different-domains/
  325.         if (!is_admin()) {
  326.        
  327.             add_filter ('home_url', 'avia_wpml_correct_domain_in_url');
  328.             add_filter ('site_url', 'avia_wpml_correct_domain_in_url');
  329.             add_filter ('get_option_siteurl', 'avia_wpml_correct_domain_in_url');
  330.             add_filter ('stylesheet_directory_uri', 'avia_wpml_correct_domain_in_url');
  331.             add_filter ('template_directory_uri', 'avia_wpml_correct_domain_in_url');
  332.             add_filter ('post_thumbnail_html', 'avia_wpml_correct_domain_in_url');
  333.             add_filter ('plugins_url', 'avia_wpml_correct_domain_in_url');
  334.             add_filter ('admin_url', 'avia_wpml_correct_domain_in_url');
  335.             add_filter ('wp_get_attachment_url', 'avia_wpml_correct_domain_in_url');
  336.  
  337.         }
  338.  
  339.         /**
  340.         * Changes the domain for a URL so it has the correct domain for the current language
  341.         * Designed to be used by various filters
  342.         *
  343.         * @param string $url
  344.         * @return string
  345.         */
  346.         function avia_wpml_correct_domain_in_url($url)
  347.         {
  348.             if (function_exists('icl_get_home_url'))
  349.             {
  350.                 // Use the language switcher object, because that contains WPML settings, and it's available globally
  351.                 global $icl_language_switcher, $avia_config;
  352.  
  353.                 // Only make the change if we're using the languages-per-domain option
  354.                 if (isset($icl_language_switcher->settings['language_negotiation_type']) && $icl_language_switcher->settings['language_negotiation_type'] == 2)
  355.                 {
  356.                     if(!avia_wpml_is_default_language())
  357.                     {
  358.                         return str_replace(untrailingslashit( get_option('home') ), untrailingslashit(icl_get_home_url()), $url);
  359.                     }
  360.                 }
  361.             }
  362.             return $url;
  363.         }
  364.     }
  365.  
  366.  
  367.     if(!function_exists('avia_append_language_code_to_ajax_url'))
  368.     {
  369.         add_filter ('avia_ajax_url_filter', 'avia_append_language_code_to_ajax_url');
  370.  
  371.         function avia_append_language_code_to_ajax_url($url)
  372.         {
  373.             //conert url in case we are using different domain
  374.             $url = avia_wpml_correct_domain_in_url($url);
  375.  
  376.             //after converting the url in case it was necessary also append the language code
  377.             $url .= '?lang='.ICL_LANGUAGE_CODE;
  378.  
  379.             return $url;
  380.         }
  381.     }
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.     if(!function_exists('avia_backend_language_switch'))
  389.     {
  390.        add_filter( 'avia_options_page_header', 'avia_backend_language_switch' );
  391.  
  392.         function avia_backend_language_switch()
  393.         {
  394.             $current_page = basename($_SERVER['SCRIPT_NAME']);
  395.             $query = '?';
  396.             if(!empty($_SERVER['QUERY_STRING']))
  397.             {
  398.                 $query .= $_SERVER['QUERY_STRING'] . '&';
  399.             }
  400.  
  401.             $languages = icl_get_languages('skip_missing=0&orderby=id');
  402.             $output = "";
  403.  
  404.             if(is_array($languages) && !empty($languages))
  405.             {
  406.                 $output .= "<ul class='avia_wpml_language_switch'>";
  407.                 $output .= "<li><span class='avia_cur_lang_edit'>".__('Editing:', 'avia_framework')."</span><span class='avia_cur_lang'><img title='".$languages[ICL_LANGUAGE_CODE]['native_name']."' alt='".$languages[ICL_LANGUAGE_CODE]['native_name']."' src='".$languages[ICL_LANGUAGE_CODE]['country_flag_url']."' />";
  408.                 $output .= ICL_LANGUAGE_NAME_EN." (".__('Change', 'avia_framework').")</span>";
  409.                 unset($languages[ICL_LANGUAGE_CODE]);
  410.                 $output .= "<ul class='avia_sublanguages'>";
  411.  
  412.                 foreach($languages as $lang)
  413.                 {
  414.                     $linkurl = admin_url($current_page . $query .'lang=' . $lang['language_code']);
  415.  
  416.                     $output .= "<li class='language_".$lang['language_code']."'><a href='".$linkurl."'>";
  417.                     $output .= "    <span class='language_flag'><img title='".$lang['native_name']."' src='".$lang['country_flag_url']."' alt='".$lang['native_name']."' /></span>";
  418.                     $output .= "    <span class='language_native'>".$lang['native_name']."</span>";
  419.                     $output .= "</a></li>";
  420.                 }
  421.  
  422.                 $output .= "</ul></li></ul>";
  423.                 $output .="
  424.                 <style type='text/css'>
  425.                 .avia_wpml_language_switch {
  426.                    z-index: 100;
  427.                    padding: 10px;
  428.                    position: absolute;
  429.                    top: 13px;
  430.                    left: 0;
  431.                    margin:0;
  432.  
  433.                    }
  434.                 .avia_wpml_language_switch ul { display:none;
  435.                    z-index: 100;
  436.                    background-color: white;
  437.                    position: absolute;
  438.                    width: 128px;
  439.                    padding: 57px 10px 10px;
  440.                    left: -2px;
  441.                    border: 1px solid #E1E1E1;
  442.                    border-top: none;
  443.                    margin-top: 0;
  444.                    top:0;
  445.                    }
  446.                 .avia_wpml_language_switch li:hover ul{display:block;}
  447.                 .avia_wpml_language_switch li a{text-decoration:none;}
  448.                 .avia_sublanguages li{
  449.                 margin:0;
  450.                 padding: 7px 0;
  451.                 border-top:1px solid #e1e1e1;
  452.                 }
  453.                 .avia_cur_lang, .avia_cur_lang_edit{ font-size:11px; padding:3px 0; z-index:300; position:relative; cursor:pointer; color: #5C951E; display:block;}
  454.                 .avia_cur_lang_edit{ color: #7D8388;}
  455.                 .avia_cur_lang img{margin:0px 4px -1px 0;}
  456.                 </style>
  457.                 ";
  458.  
  459.  
  460.             }
  461.  
  462.             return $output;
  463.         }
  464.     }
  465.  
  466.  
  467.  
  468.     if(!function_exists('avia_wpml_filter_dropdown_post_query'))
  469.         {
  470.             add_filter( 'avf_dropdown_post_query', 'avia_wpml_filter_dropdown_post_query', 10, 4);
  471.  
  472.             function avia_wpml_filter_dropdown_post_query($prepare_sql, $table_name, $limit, $element)
  473.             {
  474.                 global $wpdb;
  475.                 $wpml_lang = ICL_LANGUAGE_CODE;
  476.                 $wpml_join = " INNER JOIN {$wpdb->prefix}icl_translations ON {$table_name}.ID = {$wpdb->prefix}icl_translations.element_id ";
  477.                 $wpml_where = " {$wpdb->prefix}icl_translations.language_code LIKE '{$wpml_lang}' AND ";
  478.  
  479.                 $prepare_sql = "SELECT distinct ID, post_title FROM {$table_name} {$wpml_join} WHERE {$wpml_where} post_status = 'publish' AND post_type = '".$element['subtype']."' ORDER BY post_title ASC LIMIT {$limit}";
  480.                 return $prepare_sql;
  481.             }
  482.         }
  483.        
  484.        
  485.        
  486.         if(!function_exists('avia_change_wpml_home_link'))
  487.     {
  488.         add_filter('WPML_filter_link','avia_change_wpml_home_link', 10, 2);
  489.         function avia_change_wpml_home_link($url, $lang)
  490.         {
  491.             global $sitepress;
  492.             if(is_front_page()) $url = $sitepress->language_url($lang['language_code']);
  493.             return $url;
  494.         }
  495.     }
  496.  
  497.  
  498.     if(!function_exists('avia_wpml_slideshow_slide_id_check'))
  499.     {
  500.         add_filter( 'avf_avia_builder_slideshow_filter', 'avia_wpml_slideshow_slide_id_check', 10, 1);
  501.         function avia_wpml_slideshow_slide_id_check($slideshow_data)
  502.         {
  503.             $id_array = $slideshow_data['id_array'];
  504.             $slides = $slideshow_data['slides'];
  505.        
  506.             if(empty($id_array) || empty($slides)) return $slideshow_data;
  507.        
  508.             foreach($id_array as $key => $id)
  509.             {
  510.                 if(!isset($slides[$id]))
  511.                 {
  512.                     $id_of_translated_attachment = icl_object_id($id, "attachment", true);
  513.        
  514.                     if($id_of_translated_attachment && isset($slides[$id_of_translated_attachment]))
  515.                     {
  516.                         $slides[$id] = $slides[$id_of_translated_attachment];
  517.                         unset($slides[$id_of_translated_attachment]);
  518.                     }
  519.                 }
  520.             }
  521.        
  522.             $slideshow_data['slides'] = $slides;
  523.             return $slideshow_data;
  524.         }
  525.     }
  526.    
  527.    
  528.    
  529.     if(!function_exists('avia_wpml_author_name_translation'))
  530.     {
  531.         add_filter( 'avf_author_name', 'avia_wpml_author_name_translation', 10, 2);
  532.         function avia_wpml_author_name_translation($name, $author_id)
  533.         {
  534.             if(function_exists('icl_t')) $name = icl_t('Authors', 'display_name_'.$author_id, $name);
  535.             return $name;
  536.         }
  537.     }
  538.  
  539.  
  540.  
  541.     if(!function_exists('avia_wpml_author_nickname_translation'))
  542.     {
  543.         add_filter( 'avf_author_nickname', 'avia_wpml_author_nickname_translation', 10, 2);
  544.         function avia_wpml_author_nickname_translation($name, $author_id)
  545.         {
  546.             if(function_exists('icl_t')) $name = icl_t('Authors', 'nickname_'.$author_id, $name);
  547.             return $name;
  548.         }
  549.     }
  550.  
  551.  
  552.  
  553.     if(!function_exists('avia_append_lang_flags'))
  554.     {
  555.         //first append search item to main menu
  556.         add_filter( 'wp_nav_menu_items', 'avia_append_lang_flags', 9998, 2 );
  557.         add_filter( 'avf_fallback_menu_items', 'avia_append_lang_flags', 9998, 2 );
  558.        
  559.         function avia_append_lang_flags( $items, $args )
  560.         {
  561.             if ((is_object($args) && $args->theme_location == 'avia'))
  562.             {
  563.                 global $avia_config, $sitepress;
  564.  
  565.                 if(empty($avia_config['wpml_language_menu_position'])) $avia_config['wpml_language_menu_position'] = apply_filters('avf_wpml_language_switcher_position', 'main_menu');
  566.                 if($avia_config['wpml_language_menu_position'] != 'main_menu') return $items;
  567.        
  568.                 $languages = icl_get_languages('skip_missing=0&orderby=custom');
  569.        
  570.                 if(is_array($languages))
  571.                 {
  572.                     foreach($languages as $lang)
  573.                     {
  574.                         $currentlang = (ICL_LANGUAGE_CODE == $lang['language_code']) ? 'avia_current_lang' : '';
  575.        
  576.                         if(is_front_page()) $lang['url'] = $sitepress->language_url($lang['language_code']);
  577.        
  578.                         $items .= "<li class='av-language-switch-item language_".$lang['language_code']." $currentlang'><a href='".$lang['url']."'>";
  579.                         $items .= " <span class='language_flag'><img title='".$lang['native_name']."' src='".$lang['country_flag_url']."' /></span>";
  580.                         $items .= "</a></li>";
  581.                     }
  582.                 }
  583.             }
  584.             return $items;
  585.         }
  586.     }
  587.    
  588.    
  589.    
  590.  
  591.     if(!function_exists('avia_wpml_translate_date_format'))
  592.     {
  593.         function avia_wpml_translate_date_format($format)
  594.         {
  595.             if (function_exists('icl_translate')) $format = icl_translate('Formats', $format, $format);
  596.             return $format;
  597.         }
  598.    
  599.         add_filter('option_date_format', 'avia_wpml_translate_date_format');
  600.     }
  601.    
  602.    
  603.  
  604.  
  605.     if(!function_exists('avia_wpml_translate_all_search_results_url'))
  606.     {
  607.         function avia_wpml_translate_all_search_results_url($search_messages, $search_query)
  608.         {
  609.             $search_messages['all_results_link'] =  icl_get_home_url() . '?' . $search_messages['all_results_query'];
  610.             return $search_messages;
  611.         }
  612.    
  613.         add_filter('avf_ajax_search_messages', 'avia_wpml_translate_all_search_results_url', 10, 2);
  614.     }
  615.    
  616.    
  617.  
  618.  
  619.     if(!function_exists('avia_translate_ids_from_query'))
  620.     {
  621.         function avia_translate_ids_from_query($query, $params)
  622.         {
  623.             $res = array();
  624.            
  625.             if(!empty($query['tax_query'][0]['terms']) && !empty($query['tax_query'][0]['taxonomy']))
  626.             {
  627.                 foreach ($query['tax_query'][0]['terms'] as $id)
  628.                 {
  629.                     $xlat = @icl_object_id($id, $query['tax_query'][0]['taxonomy'], true);
  630.                     if(!is_null($xlat)) $res[] = $xlat;
  631.                 }
  632.            
  633.                 if(!empty($res)) $query['tax_query'][0]['terms'] = $res;
  634.             }
  635.             else if(!empty($query['post__in']) && !empty($query['post_type']))
  636.             {
  637.                 foreach($query['post__in'] as $id)
  638.                 {
  639.                     $xlat = @icl_object_id($id, $query['post_type'], true);
  640.                     if(!is_null($xlat)) $res[] = $xlat;
  641.                 }
  642.                
  643.                 if(!empty($res)) $query['post__in'] = $res;
  644.             }
  645.        
  646.             return $query;
  647.         }
  648.        
  649.         add_filter('avia_masonry_entries_query', 'avia_translate_ids_from_query', 10, 2);
  650.         add_filter('avia_post_grid_query', 'avia_translate_ids_from_query', 10, 2);
  651.         add_filter('avia_post_slide_query', 'avia_translate_ids_from_query', 10, 2);
  652.         add_filter('avia_blog_post_query', 'avia_translate_ids_from_query', 10, 2);
  653.     }
  654.    
  655.    
  656.    
  657.     if(!function_exists('avia_translate_check_by_tag_values'))
  658.     {
  659.         function avia_translate_check_by_tag_values($value)
  660.         {
  661.             if(!empty($value) && is_array($value))
  662.             {
  663.                 foreach($value as $key => $data)
  664.                 {
  665.                     $orig_term = get_term_by('slug', $data, 'post_tag');
  666.                    
  667.                     if( false === $orig_term )
  668.                     {
  669.                         continue;
  670.                     }
  671.                        
  672.                     $translated_id = icl_object_id( $orig_term->term_id, 'post_tag', true );
  673.                     if( is_null( $translated_id ) || ( false === $translated_id ) )
  674.                     {
  675.                         continue;
  676.                     }
  677.                    
  678.                     $translated_term = icl_object_id( $translated_id->term_id, 'post_tag', true );
  679.                     if( is_null( $translated_term ) || ( false === $translated_term ) )
  680.                     {
  681.                         continue;
  682.                     }
  683.                     $value[$key] = $translated_term->slug;                 
  684.                 }
  685.             }
  686.             return $value;
  687.         }
  688.    
  689.         add_filter('avf_ratio_check_by_tag_values', 'avia_translate_check_by_tag_values', 10, 1);
  690.     }
  691.  
  692.  
  693.  
  694.  
  695. }
  696.  
  697. /*fix for: https://wpml.org/errata/translation-editor-support-avia-layout-builder-enfold/*/
  698. if(!function_exists('avia_wpml_sync_avia_layout_builder'))
  699. {
  700.     add_action( 'wpml_translation_job_saved', 'avia_wpml_sync_avia_layout_builder', 10, 3 );
  701.    
  702.     function avia_wpml_sync_avia_layout_builder( $new_post_id, $fields, $job ) {
  703.         if ( isset( $fields['body']['data'] ) ) {
  704.             if ( 'active' === get_post_meta( $new_post_id, '_aviaLayoutBuilder_active', true ) ) {
  705.                 update_post_meta(
  706.                     $new_post_id,
  707.                     '_aviaLayoutBuilderCleanData',
  708.                     $fields['body']['data']
  709.                 );
  710.             }
  711.         }
  712.     }
  713.    
  714. }
  715.  
  716.  
  717.  
  718. /*compatibility function for the portfolio problems*/
  719. if(!function_exists('avia_portfolio_compat') && defined('ICL_SITEPRESS_VERSION') && defined('ICL_LANGUAGE_CODE'))
  720. {
  721.     add_action( 'avia_action_before_framework_init', 'avia_portfolio_compat', 30);
  722.     function avia_portfolio_compat()
  723.     {
  724.         global $avia_config;
  725.         if(empty($avia_config['wpml']['settings']['custom_posts_sync_option']) || empty($avia_config['wpml']['settings']['custom_posts_sync_option']['portfolio']))
  726.         {
  727.             $settings = get_option('icl_sitepress_settings');
  728.             $settings['custom_posts_sync_option']['portfolio'] = 1;
  729.             $settings['taxonomies_sync_option']['portfolio_entries'] = 1;
  730.             update_option('icl_sitepress_settings', $settings);
  731.         }
  732.     }
  733. }
Advertisement
Add Comment
Please, Sign In to add comment