示例#1
0
 function check_for_translations_permalinks($arrays, $desing_menu_flag_size)
 {
     global $post, $wpdb, $etm_check, $easy_translation_manager_plugin;
     $easy_translation_manager_plugin->check_languages();
     $url_tag_array = $url_tag_array_tmp = $url_tag_string = $permalink_array = $fade_trans = '';
     if (!empty($arrays)) {
         // Hide flags if not translations
         if (is_singular() && !is_admin() && !empty($easy_translation_manager_plugin->etm_tools_retrive['fade_none_translation_menu']) && !empty($easy_translation_manager_plugin->current_translatede_post_id)) {
             $fade_trans = $wpdb->get_col("SELECT SUBSTR(meta_key,-2) as lang FROM {$wpdb->prefix}postmeta WHERE (substring(meta_key,1,17) = 'ect_tran_content_' or substring(meta_key,1,15) = 'ect_tran_title_') and meta_key != '' and post_id=" . $easy_translation_manager_plugin->current_translatede_post_id . ' Group by lang');
             if (!empty($fade_trans)) {
                 $fade_trans = array_flip($fade_trans);
                 foreach ($fade_trans as $t_k => $t_d) {
                     $fade_trans[$t_k] = true;
                 }
             }
         }
         // Get permalinks data
         if (!empty($easy_translation_manager_plugin->current_translatede_post_id) && !empty($easy_translation_manager_plugin->etm_tools_retrive['use_permalink']) && !is_admin() && !empty($easy_translation_manager_plugin->permalink_structur)) {
             $tran_permalink = $wpdb->get_results("SELECT SUBSTR(meta_key,-2) as lang,meta_value FROM {$wpdb->prefix}postmeta WHERE  substring(meta_key,1,19) = 'ect_tran_permalink_' and meta_value != '/' and post_id=" . $easy_translation_manager_plugin->current_translatede_post_id . " Group by lang");
             if (!empty($tran_permalink)) {
                 foreach ($tran_permalink as $_data_array) {
                     $permalink_array[$_data_array->lang] = trailingslashit(get_option('siteurl')) . $_data_array->meta_value;
                 }
             }
         }
         // Get url tag data
         if (!empty($easy_translation_manager_plugin->etm_tools_retrive['GP_name'])) {
             $url_tag_array = explode('|', $easy_translation_manager_plugin->etm_tools_retrive['GP_name']);
         } else {
             $url_tag_array = array('la');
         }
         // Generate url for non permalink
         $url_tag_array_tmp = array_fill_keys($url_tag_array, '[LANG]');
         $url_tag_string = etm_query_arg_add($url_tag_array_tmp, $easy_translation_manager_plugin->curPageURL());
         $url_tag_string_no = etm_query_arg_add(array(), $easy_translation_manager_plugin->curPageURL());
         $global_terms = '';
         if (is_archive()) {
             global $wp_query;
             $global_terms = $wp_query->get_queried_object();
         }
         if (!empty($easy_translation_manager_plugin->etm_tools_retrive['default_language']) && empty($permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']])) {
             $permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']] = get_permalink($easy_translation_manager_plugin->current_translatede_post_id);
             if (empty($easy_translation_manager_plugin->etm_tools_retrive['dont_save_overwrite'])) {
                 $permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']] = etm_query_arg_add($url_tag_array_tmp, $permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']]);
                 $permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']] = str_replace('[LANG]', $easy_translation_manager_plugin->etm_tools_retrive['default_language'], $permalink_array[$easy_translation_manager_plugin->etm_tools_retrive['default_language']]);
             }
         } else {
             if (empty($permalink_array['en'])) {
                 $permalink_array['en'] = get_permalink($easy_translation_manager_plugin->current_translatede_post_id);
                 if (empty($easy_translation_manager_plugin->etm_tools_retrive['dont_save_overwrite'])) {
                     $permalink_array['en'] = etm_query_arg_add($url_tag_array_tmp, $permalink_array['en']);
                     $permalink_array['en'] = str_replace('[LANG]', 'en', $permalink_array['en']);
                 }
             } else {
                 if (empty($permalink_array['us'])) {
                     $permalink_array['us'] = get_permalink($easy_translation_manager_plugin->current_translatede_post_id);
                     if (empty($easy_translation_manager_plugin->etm_tools_retrive['dont_save_overwrite'])) {
                         $permalink_array['us'] = etm_query_arg_add($url_tag_array_tmp, $permalink_array['us']);
                         $permalink_array['us'] = str_replace('[LANG]', 'us', $permalink_array['us']);
                     }
                 }
             }
         }
         // title
         if (!empty($easy_translation_manager_plugin->etm_tools_retrive['desing_menu_lang_string'])) {
             $desing_menu_lang_string = $easy_translation_manager_plugin->etm_tools_retrive['desing_menu_lang_string'];
         } else {
             $desing_menu_lang_string = '[ORG] ([ENG])';
         }
         // Add all data to array
         foreach ($arrays as $_key_array => $_data_array) {
             // check if flag has to be hidden
             if (is_singular() && !is_admin() && $easy_translation_manager_plugin->etm_tools_retrive['fade_none_translation_menu'] && !empty($easy_translation_manager_plugin->current_translatede_post_id)) {
                 if (!empty($fade_trans[$_data_array['code']])) {
                     $arrays[$_key_array]['fade'] = false;
                 } else {
                     if (!empty($easy_translation_manager_plugin->selectede_lang) && $_data_array['code'] == $easy_translation_manager_plugin->selectede_lang || !empty($easy_translation_manager_plugin->etm_tools_retrive['default_language']) && $easy_translation_manager_plugin->etm_tools_retrive['default_language'] == $_data_array['code']) {
                         $arrays[$_key_array]['fade'] = false;
                     } else {
                         $arrays[$_key_array]['fade'] = true;
                     }
                 }
             } else {
                 $arrays[$_key_array]['fade'] = false;
             }
             //generate title
             $tmp_string_text = str_replace('[ORG]', $arrays[$_key_array]['org_name'], $desing_menu_lang_string);
             $tmp_string_text = str_replace('[ENG]', $arrays[$_key_array]['english_name'], $tmp_string_text);
             $arrays[$_key_array]['title'] = $tmp_string_text;
             // get icon url
             $arrays[$_key_array]['icon'] = etm_tools_create_icons_url($arrays[$_key_array]['icon'], $desing_menu_flag_size);
             // add link data
             if (is_admin()) {
                 $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
             } else {
                 if (empty($easy_translation_manager_plugin->permalink_structur) || is_front_page() || is_home()) {
                     $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
                 } else {
                     if (is_archive() && (is_category() || is_tag()) && !empty($global_terms)) {
                         $tran_terms_data = get_option('ect_tran_terms_' . $_data_array['code']);
                         if (!empty($tran_terms_data[$global_terms->term_id])) {
                             $arrays[$_key_array]['link'] = trailingslashit(get_option('siteurl')) . $global_terms->taxonomy . '/' . $tran_terms_data[$global_terms->term_id]->slug;
                         } else {
                             $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
                         }
                     } else {
                         if (is_singular()) {
                             if (!empty($easy_translation_manager_plugin->current_translatede_post_id)) {
                                 if (!empty($permalink_array[$_data_array['code']]) && $permalink_array[$_data_array['code']] != '/') {
                                     $arrays[$_key_array]['link'] = $permalink_array[$_data_array['code']];
                                 } else {
                                     $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
                                 }
                             } else {
                                 $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
                             }
                         }
                     }
                 }
             }
             if (!empty($easy_translation_manager_plugin->etm_tools_retrive['domain_list'][$_data_array['code']])) {
                 $testdata = str_replace(array('http://', 'https://'), array('', ''), $easy_translation_manager_plugin->etm_tools_retrive['domain_list'][$_data_array['code']]);
                 $testdata2 = str_replace(array('http://', 'https://'), array('', ''), $_SERVER['HTTP_HOST']);
                 $arrays[$_key_array]['link'] = str_replace(get_option('siteurl'), $easy_translation_manager_plugin->etm_tools_retrive['domain_list'][$_data_array['code']], $arrays[$_key_array]['link']);
                 if (!empty($testdata) && !empty($testdata2) && $testdata == $testdata2 && strpos($arrays[$_key_array]['link'], '?') > 0) {
                     $arrays[$_key_array]['link'] = etm_query_arg_add($url_tag_array_tmp, $arrays[$_key_array]['link']);
                     $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $arrays[$_key_array]['link']);
                 } else {
                     if (!empty($testdata) && !empty($testdata2) && $testdata != $testdata2 && strpos($arrays[$_key_array]['link'], '?') > 0 && !empty($easy_translation_manager_plugin->permalink_structur)) {
                         $arrays[$_key_array]['link'] = substr($arrays[$_key_array]['link'], 0, strpos($arrays[$_key_array]['link'], '?'));
                     } else {
                         if (!empty($testdata) && !empty($testdata2) && $testdata != $testdata2 && strpos($arrays[$_key_array]['link'], '?') > 0) {
                             $arrays[$_key_array]['link'] = substr($arrays[$_key_array]['link'], 0, strpos($arrays[$_key_array]['link'], '?'));
                             foreach ($url_tag_array as $tmp_d_d) {
                                 if (!empty($_GET[$tmp_d_d])) {
                                     unset($_GET[$tmp_d_d]);
                                 }
                             }
                             $http_build_query = http_build_query($_GET);
                             if (!empty($http_build_query)) {
                                 $arrays[$_key_array]['link'] = $arrays[$_key_array]['link'] . '?' . $http_build_query;
                             }
                         }
                     }
                 }
             }
             if (empty($arrays[$_key_array]['link'])) {
                 $arrays[$_key_array]['link'] = str_replace('[LANG]', $_data_array['code'], $url_tag_string);
             }
             // add current flag data
             if (!empty($easy_translation_manager_plugin->selectede_lang) && $_data_array['code'] == $easy_translation_manager_plugin->selectede_lang) {
                 $arrays[$_key_array]['selected_lang'] = true;
                 if (!empty($arrays[$_key_array]['rtl'])) {
                     $this->translation_dir = 'rtl';
                 }
             } else {
                 $arrays[$_key_array]['selected_lang'] = false;
             }
         }
     }
     return $arrays;
 }
 /**
  * Get adjacent pages link for archives
  *
  * @param string  $rel                  Link relationship, prev or next.
  * @param string  $url                  the unpaginated URL of the current archive.
  * @param string  $page                 the page number to add on to $url for the $link tag.
  * @param boolean $incl_pagination_base whether or not to include /page/ or not.
  *
  * @return string $link link element
  *
  * @since 1.0.2
  */
 private function adjacent_rel_link($rel, $url, $page, $incl_pagination_base)
 {
     global $wp_rewrite;
     if (!$wp_rewrite->using_permalinks()) {
         if ($page > 1) {
             $url = etm_query_arg_add('paged', $page, $url);
         }
     } else {
         if ($page > 1) {
             $base = '';
             if ($incl_pagination_base) {
                 $base = trailingslashit($wp_rewrite->pagination_base);
             }
             $url = user_trailingslashit(trailingslashit($url) . $base . $page);
         }
     }
     /**
      * Filter: 'wpseo_' . $rel . '_rel_link' - Allow changing link rel output by WP SEO
      *
      * @api string $unsigned The full `<link` element.
      */
     $link = apply_filters('wpseo_' . $rel . '_rel_link', '<link rel="' . $rel . '" href="' . esc_url($url) . "\" />\n");
     if (is_string($link) && $link !== '') {
         echo $link;
     }
 }
 function etm_tools_check_lang_createstring($languashed, $tmp_current = '', $admin_url = '', $post_id = '', $img_size = 24, $style = 'text-align: center')
 {
     global $easy_translation_manager_plugin, $wpdb;
     $string_retun = '';
     $current_translatet = array();
     if (!empty($post_id)) {
         $myrows = $wpdb->get_col("SELECT RIGHT(meta_key,2) as translatet FROM " . $wpdb->postmeta . " WHERE post_id=" . $post_id . " and (LEFT(meta_key,16) = 'ect_tran_content' or LEFT(meta_key, 20) = 'etm_content_excerpts' or LEFT(meta_key, 14) = 'ect_tran_title') group by translatet", 0);
         if (!empty($myrows)) {
             $current_translatet = array_flip($myrows);
             array_walk($current_translatet, function (&$value, $key) {
                 $value = true;
             });
         }
     }
     $string_retun .= '<div style="' . $style . '">';
     foreach ($languashed as $langedtemp) {
         if (empty($tmp_current) || $langedtemp['code'] != $tmp_current) {
             $tmpurl = etm_query_arg_add(array('ETMSAVE' => $langedtemp['code']), $admin_url);
             $string_retun .= '<a href="' . $tmpurl . '" style="height: ' . $img_size . 'px; display: inline-block;"><img class="icon_lang_' . $langedtemp['code'] . '" style="opacity:' . (!empty($current_translatet[$langedtemp['code']]) == true ? '1.0' : '0.5') . ';cursor: pointer; display: inline-block; height: ' . $img_size . 'px; margin-right: 2px; margin-left: 2px; border-radius: 5px;" title="' . $langedtemp['org_name'] . ' (' . $langedtemp['english_name'] . ')" src="' . etm_tools_create_icons_url($langedtemp['icon'], 1) . '"></a>';
         }
     }
     $string_retun .= '</div>';
     return $string_retun;
 }