Exemplo n.º 1
0
 function locale()
 {
     global $locale;
     add_filter('language_attributes', array($this, '_language_attributes'));
     $l = false;
     if (defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['action']) && isset($_REQUEST['lang'])) {
         $l = $this->get_locale($_REQUEST['lang']);
     }
     if (!$l) {
         if (defined('WP_ADMIN')) {
             if (get_user_meta($this->get_current_user()->ID, 'icl_admin_language_for_edit', true) && icl_is_post_edit()) {
                 $l = $this->get_locale($this->get_current_language());
             } else {
                 $l = $this->get_locale($this->admin_language);
             }
         } else {
             $l = $this->get_locale($this->this_lang);
         }
     }
     if ($l) {
         $locale = $l;
     }
     // theme localization
     remove_filter('locale', array($this, 'locale'));
     //avoid infinite loop
     static $theme_locales_loaded = false;
     if (!$theme_locales_loaded && !empty($this->settings['theme_localization_load_textdomain']) && !empty($this->settings['gettext_theme_domain_name']) && !empty($this->settings['theme_language_folders'])) {
         foreach ($this->settings['theme_language_folders'] as $folder) {
             load_textdomain($this->settings['gettext_theme_domain_name'], $folder . '/' . $locale . '.mo');
         }
         $theme_locales_loaded = true;
     }
     add_filter('locale', array($this, 'locale'));
     return $locale;
 }
    function js_scripts_setup()
    {
        //TODO: move javascript to external resource (use wp_localize_script() to pass arguments)
        global $pagenow, $wpdb;
        $default_language = $this->get_default_language();
        $current_language = $this->get_current_language();
        $this->get_user_preferences();
        if (isset($_GET['page'])) {
            $page = basename($_GET['page']);
            $page_basename = str_replace('.php', '', $page);
        } else {
            $page_basename = false;
        }
        $icl_ajax_url_root = rtrim(get_site_url(), '/');
        if (defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN) {
            $icl_ajax_url_root = str_replace('http://', 'https://', $icl_ajax_url_root);
        }
        $icl_ajax_url = $icl_ajax_url_root . '/wp-admin/admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/languages.php';
        ?>
		<script type="text/javascript">
			// <![CDATA[
			var icl_ajx_url;
			icl_ajx_url = '<?php 
        echo $icl_ajax_url;
        ?>
';
			var icl_ajx_saved = '<?php 
        echo icl_js_escape(__('Data saved', 'sitepress'));
        ?>
';
			var icl_ajx_error = '<?php 
        echo icl_js_escape(__('Error: data not saved', 'sitepress'));
        ?>
';
			var icl_default_mark = '<?php 
        echo icl_js_escape(__('default', 'sitepress'));
        ?>
';
			var icl_this_lang = '<?php 
        echo $this->this_lang;
        ?>
';
			var icl_ajxloaderimg_src = '<?php 
        echo ICL_PLUGIN_URL;
        ?>
/res/img/ajax-loader.gif';
			var icl_cat_adder_msg = '<?php 
        echo icl_js_escape(sprintf(__('To add categories that already exist in other languages go to the <a%s>category management page</a>', 'sitepress'), ' href="' . admin_url('edit-tags.php?taxonomy=category') . '"'));
        ?>
';
			// ]]>

			<?php 
        if (!$this->get_setting('ajx_health_checked')) {
            ?>
			addLoadEvent(function () {
				jQuery.ajax({type: "POST", url: icl_ajx_url, data: "icl_ajx_action=health_check", error: function (msg) {
					var icl_initial_language = jQuery('#icl_initial_language');
					if (icl_initial_language.length) {
						icl_initial_language.find('input').attr('disabled', 'disabled');
					}
					jQuery('.wrap').prepend('<div class="error"><p><?php 
            echo icl_js_escape(sprintf(__("WPML can't run normally. There is an installation or server configuration problem. %sShow details%s", 'sitepress'), '<a href="#" onclick="jQuery(this).parent().next().slideToggle()">', '</a>'));
            ?>
</p><p style="display:none"><?php 
            echo icl_js_escape(__('AJAX Error:', 'sitepress'));
            ?>
 ' + msg.statusText + ' [' + msg.status + ']<br />URL:' + icl_ajx_url + '</p></div>');
				}});
			});
			<?php 
        }
        ?>
		</script>
		<?php 
        if ('options-reading.php' == $pagenow) {
            list($warn_home, $warn_posts) = $this->verify_home_and_blog_pages_translations();
            if ($warn_home || $warn_posts) {
                ?>
				<script type="text/javascript">
					addLoadEvent(function () {
						jQuery('input[name="show_on_front"]').parent().parent().parent().parent().append('<?php 
                echo str_replace("'", "\\'", $warn_home . $warn_posts);
                ?>
');
					});
				</script>
			<?php 
            }
        }
        // display correct links on the posts by status break down
        // also fix links to category and tag pages
        if (('edit.php' == $pagenow || 'edit-pages.php' == $pagenow || 'categories.php' == $pagenow || 'edit-tags.php' == $pagenow) && $current_language != $default_language) {
            ?>
			<script type="text/javascript">
				addLoadEvent(function () {
					jQuery('.subsubsub li a').each(function () {
						var h = jQuery(this).attr('href');
						var urlg;
						if (-1 == h.indexOf('?')) urlg = '?'; else urlg = '&';
						jQuery(this).attr('href', h + urlg + 'lang=<?php 
            echo $current_language;
            ?>
');
					});
					jQuery('.column-categories a, .column-tags a, .column-posts a').each(function () {
						jQuery(this).attr('href', jQuery(this).attr('href') + '&lang=<?php 
            echo $current_language;
            ?>
');
					});
				});
			</script>
		<?php 
        }
        if ('edit-tags.php' == $pagenow) {
            ?>
			<script type="text/javascript">
				addLoadEvent(function () {
					var edit_tag = jQuery('#edittag');
					if (edit_tag.find('[name="_wp_original_http_referer"]').length && edit_tag.find('[name="_wp_http_referer"]').length) {
						edit_tag.find('[name="_wp_original_http_referer"]').val('<?php 
            $post_type = isset($_GET['post_type']) ? '&post_type=' . esc_html($_GET['post_type']) : '';
            echo admin_url('edit-tags.php?taxonomy=' . esc_js($_GET['taxonomy']) . '&lang=' . $current_language . '&message=3' . $post_type);
            ?>
');
					}
				});
			</script>
		<?php 
        }
        if ('post-new.php' == $pagenow) {
            if (isset($_GET['trid'])) {
                $translations = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $_GET['trid']));
                remove_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
                // remove filter used to get language relevant stickies. get them all
                $sticky_posts = get_option('sticky_posts');
                add_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
                // add filter back
                $is_sticky = false;
                foreach ($translations as $t) {
                    if (in_array($t, $sticky_posts)) {
                        $is_sticky = true;
                        break;
                    }
                }
                if (isset($_GET['trid']) && ($this->settings['sync_ping_status'] || $this->settings['sync_comment_status'])) {
                    $res = $wpdb->get_row($wpdb->prepare("SELECT comment_status, ping_status FROM {$wpdb->prefix}icl_translations t\r\n\t\t\t\t\tJOIN {$wpdb->posts} p ON t.element_id = p.ID WHERE t.trid=%d", $_GET['trid']));
                    ?>
					<script type="text/javascript">addLoadEvent(function () {
							var comment_status = jQuery('#comment_status');
							var ping_status = jQuery('#ping_status');
							<?php 
                    if ($this->settings['sync_comment_status']) {
                        ?>
							<?php 
                        if ($res->comment_status == 'open') {
                            ?>
							comment_status.attr('checked', 'checked');
							<?php 
                        } else {
                            ?>
							comment_status.removeAttr('checked');
							<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
							<?php 
                    if ($this->settings['sync_ping_status']) {
                        ?>
							<?php 
                        if ($res->ping_status == 'open') {
                            ?>
							ping_status.attr('checked', 'checked');
							<?php 
                        } else {
                            ?>
							ping_status.removeAttr('checked');
							<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
						});</script><?php 
                }
                if (isset($_GET['trid']) && $this->settings['sync_private_flag']) {
                    if ('private' == $wpdb->get_var($wpdb->prepare("\r\n\t\t\t\t\t\tSELECT p.post_status FROM {$wpdb->prefix}icl_translations t\r\n\t\t\t\t\t\tJOIN {$wpdb->posts} p ON t.element_id = p.ID\r\n\t\t\t\t\t\tWHERE t.trid=%d AND t.element_type='post_post'\r\n\t\t\t\t\t", $_GET['trid']))) {
                        ?>
						<script type="text/javascript">addLoadEvent(function () {
								jQuery('#visibility-radio-private').attr('checked', 'checked');
								jQuery('#post-visibility-display').html('<?php 
                        echo icl_js_escape(__('Private', 'sitepress'));
                        ?>
');
							});
						</script><?php 
                    }
                }
                if (isset($_GET['trid']) && $this->settings['sync_post_taxonomies']) {
                    $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
                    $source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
                    $translatable_taxs = $this->get_translatable_taxonomies(true, $post_type);
                    $all_taxs = get_object_taxonomies($post_type);
                    $translations = $this->get_element_translations($_GET['trid'], 'post_' . $post_type);
                    $js = array();
                    if (!empty($all_taxs)) {
                        foreach ($all_taxs as $tax) {
                            $tax_detail = get_taxonomy($tax);
                            $terms = get_the_terms($translations[$source_lang]->element_id, $tax);
                            $term_names = array();
                            if ($terms) {
                                foreach ($terms as $term) {
                                    if ($tax_detail->hierarchical) {
                                        if (in_array($tax, $translatable_taxs)) {
                                            $term_id = icl_object_id($term->term_id, $tax, false);
                                        } else {
                                            $term_id = $term->term_id;
                                        }
                                        $js[] = "jQuery('#in-" . $tax . "-" . $term_id . "').attr('checked', 'checked');";
                                    } else {
                                        if (in_array($tax, $translatable_taxs)) {
                                            $term_id = icl_object_id($term->term_id, $tax, false);
                                            if ($term_id) {
                                                $term = get_term_by('id', $term_id, $tax);
                                                $term_names[] = esc_js($term->name);
                                            }
                                        } else {
                                            $term_names[] = esc_js($term->name);
                                        }
                                    }
                                }
                            }
                            if ($term_names) {
                                $js[] = "jQuery('#{$tax} .taghint').css('visibility','hidden');";
                                $js[] = "jQuery('#new-tag-{$tax}').val('" . join(', ', $term_names) . "');";
                            }
                        }
                    }
                    if ($js) {
                        echo '<script type="text/javascript">';
                        echo PHP_EOL . '// <![CDATA[' . PHP_EOL;
                        echo 'addLoadEvent(function(){' . PHP_EOL;
                        echo join(PHP_EOL, $js);
                        echo PHP_EOL . 'jQuery().ready(function() {
							jQuery(".tagadd").click();
							jQuery(\'html, body\').prop({scrollTop:0});
							jQuery(\'#title\').focus();
							});' . PHP_EOL;
                        echo PHP_EOL . '});' . PHP_EOL;
                        echo PHP_EOL . '// ]]>' . PHP_EOL;
                        echo '</script>';
                    }
                }
                // sync custom fields
                if (!empty($this->settings['translation-management']) && !empty($this->settings['translation-management']['custom_fields_translation'])) {
                    foreach ((array) $this->settings['translation-management']['custom_fields_translation'] as $key => $sync_opt) {
                        if ($sync_opt == 1) {
                            $copied_cf[] = $key;
                        }
                    }
                }
                if (!empty($copied_cf)) {
                    $source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
                    $lang_details = $this->get_language_details($source_lang);
                    $original_custom = get_post_custom($translations[$source_lang]->element_id);
                    $copied_cf = array_intersect($copied_cf, array_keys($original_custom));
                    $copied_cf = apply_filters('icl_custom_fields_to_be_copied', $copied_cf, $translations[$source_lang]->element_id);
                    if (!empty($copied_cf) && (empty($this->user_preferences['notices']) || empty($this->user_preferences['notices']['hide_custom_fields_copy']))) {
                        $ccf_note = '<img src="' . ICL_PLUGIN_URL . '/res/img/alert.png" alt="Notice" width="16" height="16" style="margin-right:8px" />';
                        $ccf_note .= '<a class="icl_user_notice_hide" href="#hide_custom_fields_copy" style="float:right;margin-left:20px;">' . __('Never show this.', 'sitepress') . '</a>';
                        $ccf_note .= wp_nonce_field('save_user_preferences_nonce', '_icl_nonce_sup', false, false);
                        $ccf_note .= sprintf(__('WPML will copy %s from %s when you save this post.', 'sitepress'), '<i><strong>' . join('</strong>, <strong>', $copied_cf) . '</strong></i>', $lang_details['display_name']);
                        $this->admin_notices($ccf_note, 'error');
                    }
                }
            }
            ?>
			<?php 
            if (!empty($is_sticky) && $this->settings['sync_sticky_flag']) {
                ?>
				<script type="text/javascript">
					addLoadEvent(
						function () {
							jQuery('#sticky').attr('checked', 'checked');
							var post_visibility_display = jQuery('#post-visibility-display');
							post_visibility_display.html(post_visibility_display.html() + ', <?php 
                echo icl_js_escape(__('Sticky', 'sitepress'));
                ?>
');
						});
				</script>
			<?php 
            }
            ?>
		<?php 
        }
        if ('page-new.php' == $pagenow || 'post-new.php' == $pagenow && isset($_GET['post_type'])) {
            if (isset($_GET['trid']) && ($this->settings['sync_page_template'] || $this->settings['sync_page_ordering'])) {
                $res = $wpdb->get_row($wpdb->prepare("\r\n\t\t\t\t\tSELECT p.ID, p.menu_order FROM {$wpdb->prefix}icl_translations t\r\n\t\t\t\t\tJOIN {$wpdb->posts} p ON t.element_id = p.ID\r\n\t\t\t\t\tWHERE t.trid=%d AND p.post_type=%s AND t.element_type=%s\r\n\t\t\t\t", $_GET['trid'], $_GET['post_type'], 'post_' . $_GET['post_type']));
                if ($this->settings['sync_page_ordering']) {
                    $menu_order = $res->menu_order;
                } else {
                    $menu_order = false;
                }
                if ($this->settings['sync_page_template']) {
                    $page_template = get_post_meta($res->ID, '_wp_page_template', true);
                } else {
                    $page_template = false;
                }
                if ($menu_order || $page_template) {
                    ?>
					<script type="text/javascript">addLoadEvent(function () { <?php 
                    if ($menu_order) {
                        ?>
							jQuery('#menu_order').val(<?php 
                        echo $menu_order;
                        ?>
);
							<?php 
                    }
                    if ($page_template && 'default' != $page_template) {
                        ?>
							jQuery('#page_template').val('<?php 
                        echo $page_template;
                        ?>
');
							<?php 
                    }
                    ?>
						});</script><?php 
                }
            }
        } elseif ('edit-comments.php' == $pagenow || 'index.php' == $pagenow || 'post.php' == $pagenow) {
            wp_enqueue_script('sitepress-' . $page_basename, ICL_PLUGIN_URL . '/res/js/comments-translation.js', array(), ICL_SITEPRESS_VERSION);
        }
        // sync post dates
        if (icl_is_post_edit()) {
            // @since 3.1.5
            // Enqueing 'wp-jquery-ui-dialog', just in case it doesn't get automatically enqueued
            wp_enqueue_style('wp-jquery-ui-dialog');
            wp_enqueue_style('sitepress-post-edit', ICL_PLUGIN_URL . '/res/css/post-edit.css', array(), ICL_SITEPRESS_VERSION);
            wp_enqueue_script('sitepress-post-edit', ICL_PLUGIN_URL . '/res/js/post-edit.js', array('jquery-ui-dialog', 'jquery-ui-autocomplete', 'autosave'), ICL_SITEPRESS_VERSION);
            if ($this->settings['sync_post_date']) {
                $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
                if (isset($_GET['trid'])) {
                    $trid = intval($_GET['trid']);
                } else {
                    $post_id = @intval($_GET['post']);
                    $trid = $this->get_element_trid($post_id, 'post_' . $post_type);
                }
                $translations = $this->get_element_translations($trid, 'post_' . $post_type);
                if (!empty($translations) && isset($translations[$current_language]) && !$translations[$current_language]->original) {
                    $source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
                    if (isset($translations[$source_lang])) {
                        $original_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $translations[$source_lang]->element_id));
                        $exp = explode(' ', $original_date);
                        list($aa, $mm, $jj) = explode('-', $exp[0]);
                        list($hh, $mn, $ss) = explode(':', $exp[1]);
                        ?>
						<script type="text/javascript">
							addLoadEvent(
								function () {
									jQuery('#aa').val('<?php 
                        echo $aa;
                        ?>
').attr('readonly', 'readonly');
									jQuery('#mm').val('<?php 
                        echo $mm;
                        ?>
').attr('readonly', 'readonly');
									jQuery('#jj').val('<?php 
                        echo $jj;
                        ?>
').attr('readonly', 'readonly');
									jQuery('#hh').val('<?php 
                        echo $hh;
                        ?>
').attr('readonly', 'readonly');
									jQuery('#mn').val('<?php 
                        echo $mn;
                        ?>
').attr('readonly', 'readonly');
									jQuery('#ss').val('<?php 
                        echo $ss;
                        ?>
').attr('readonly', 'readonly');
									var timestamp = jQuery('#timestamp');
									timestamp.find('b').html('<?php 
                        esc_html_e('copy from original', 'sitepress');
                        ?>
');
									timestamp.next().html('<?php 
                        esc_html_e('show', 'sitepress');
                        ?>
');
								});
						</script>
					<?php 
                    }
                }
            }
        }
        if ('post-new.php' == $pagenow && isset($_GET['trid']) && $this->settings['sync_post_format'] && function_exists('get_post_format')) {
            $format = get_post_format($wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d and language_code=%s", $_GET['trid'], $_GET['source_lang'])));
            ?>
			<script type="text/javascript">
				addLoadEvent(function () {
					jQuery('#post-format-' + '<?php 
            echo $format;
            ?>
').attr('checked', 'checked');
				});
			</script><?php 
        }
        if (is_admin()) {
            wp_enqueue_script('thickbox');
            wp_enqueue_script('theme-preview');
            wp_enqueue_script('sitepress-icl_reminders', ICL_PLUGIN_URL . '/res/js/icl_reminders.js', array(), ICL_SITEPRESS_VERSION);
        }
        //if('content-translation' == $page_basename) {
        //    wp_enqueue_script('icl-sidebar-scripts', ICL_PLUGIN_URL . '/res/js/icl_sidebar.js', array(), ICL_SITEPRESS_VERSION);
        //}
        if ('languages' == $page_basename || 'string-translation' == $page_basename) {
            wp_enqueue_script('colorpicker');
            wp_enqueue_script('jquery-ui-sortable');
        }
    }
    public function wpml_js_scripts_setup()
    {
        //TODO: [WPML 3.3] move javascript to external resource (use wp_localize_script() to pass arguments)
        global $pagenow, $wpdb, $sitepress, $wpml_post_translations;
        $default_language = $this->default_language;
        $current_language = $this->current_language;
        $page_basename = $this->page;
        $this->print_js_globals();
        if ('options-reading.php' === $pagenow) {
            $this->print_reading_options_js();
        } elseif (in_array($pagenow, array('edit.php', 'edit-pages.php', 'categories.php', 'edit-tags.php'), true) && $current_language !== $default_language) {
            // display correct links on the posts by status break down
            // also fix links to category and tag pages
            ?>
			<script type="text/javascript">
				addLoadEvent(
					function () {
						jQuery(document).ready(
							function () {
								jQuery('.subsubsub:not(.icl_subsubsub) li a').each(
									function () {
										var h = jQuery(this).attr('href');
										var urlg;
										if (-1 == h.indexOf('?')) {
											urlg = '?';
										} else {
											urlg = '&';
										}
										jQuery(this).attr('href', h + urlg + 'lang=<?php 
            echo $current_language;
            ?>
');
									}
								);
								jQuery('.column-categories a, .column-tags a, .column-posts a').each(
									function () {
										jQuery(this).attr('href', jQuery(this).attr('href') + '&lang=<?php 
            echo $current_language;
            ?>
');
									}
								);
							}
						);
					}
				);
			</script>
		<?php 
        }
        if ('edit-tags.php' === $pagenow) {
            ?>
			<script type="text/javascript">
				addLoadEvent(function () {
					var edit_tag = jQuery('#edittag');
					if (edit_tag.find('[name="_wp_original_http_referer"]').length && edit_tag.find('[name="_wp_http_referer"]').length) {
						edit_tag.find('[name="_wp_original_http_referer"]').val('<?php 
            $post_type = isset($_GET['post_type']) ? '&post_type=' . esc_html($_GET['post_type']) : '';
            echo admin_url('edit-tags.php?taxonomy=' . esc_js($_GET['taxonomy']) . '&lang=' . $current_language . '&message=3' . $post_type);
            ?>
');
					}
				});
			</script>
		<?php 
        }
        $trid = filter_input(INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT);
        $source_lang = $trid !== null ? filter_input(INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : null;
        if ('post-new.php' === $pagenow) {
            if ($trid) {
                $translations = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $_GET['trid']));
                remove_filter('pre_option_sticky_posts', array($sitepress, 'option_sticky_posts'));
                // remove filter used to get language relevant stickies. get them all
                $sticky_posts = get_option('sticky_posts');
                add_filter('pre_option_sticky_posts', array($sitepress, 'option_sticky_posts'), 10, 2);
                // add filter back
                $is_sticky = false;
                foreach ($translations as $t) {
                    if (in_array($t, $sticky_posts)) {
                        $is_sticky = true;
                        break;
                    }
                }
                if ($sitepress->get_setting('sync_ping_status') || $sitepress->get_setting('sync_comment_status')) {
                    ?>
					<script type="text/javascript">addLoadEvent(function () {
							var comment_status = jQuery('#comment_status');
							var ping_status = jQuery('#ping_status');
							<?php 
                    if ($sitepress->get_setting('sync_comment_status')) {
                        ?>
							<?php 
                        if ($wpml_post_translations->get_original_comment_status($trid, $source_lang) === 'open') {
                            ?>
							comment_status.attr('checked', 'checked');
							<?php 
                        } else {
                            ?>
							comment_status.removeAttr('checked');
							<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
							<?php 
                    if ($sitepress->get_setting('sync_ping_status')) {
                        ?>
							<?php 
                        if ($wpml_post_translations->get_original_ping_status($trid, $source_lang) === 'open') {
                            ?>
							ping_status.attr('checked', 'checked');
							<?php 
                        } else {
                            ?>
							ping_status.removeAttr('checked');
							<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
						});</script><?php 
                }
                if ('private' === $wpml_post_translations->get_original_post_status($trid, $source_lang)) {
                    ?>
					<script type="text/javascript">addLoadEvent(function () {
							jQuery('#visibility-radio-private').attr('checked', 'checked');
							jQuery('#post-visibility-display').html('<?php 
                    echo icl_js_escape(__('Private', 'sitepress'));
                    ?>
');
						});
					</script><?php 
                }
                if ($sitepress->get_setting('sync_post_taxonomies')) {
                    $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
                    $source_lang = isset($_GET['source_lang']) ? filter_input(INPUT_GET, 'source_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : $default_language;
                    $translatable_taxs = $sitepress->get_translatable_taxonomies(true, $post_type);
                    $all_taxs = get_object_taxonomies($post_type);
                    $translations = $sitepress->get_element_translations($_GET['trid'], 'post_' . $post_type);
                    $js = array();
                    if (!empty($all_taxs)) {
                        foreach ($all_taxs as $tax) {
                            $tax_detail = get_taxonomy($tax);
                            $terms = get_the_terms($translations[$source_lang]->element_id, $tax);
                            $term_names = array();
                            if ($terms) {
                                foreach ($terms as $term) {
                                    if ($tax_detail->hierarchical) {
                                        $term_id = in_array($tax, $translatable_taxs) ? icl_object_id($term->term_id, $tax, false) : $term->term_id;
                                        $js[] = "jQuery('#in-" . $tax . "-" . $term_id . "').attr('checked', 'checked');";
                                    } else {
                                        if (in_array($tax, $translatable_taxs)) {
                                            $term_id = icl_object_id($term->term_id, $tax, false);
                                            if ($term_id) {
                                                $term = get_term($term_id, $tax);
                                                $term_names[] = esc_js($term->name);
                                            }
                                        } else {
                                            $term_names[] = esc_js($term->name);
                                        }
                                    }
                                }
                            }
                            if ($term_names) {
                                $js[] = "jQuery('#{$tax} .taghint').css('visibility','hidden');";
                                $js[] = "jQuery('#new-tag-{$tax}').val('" . join(', ', $term_names) . "');";
                            }
                        }
                    }
                    if ($js) {
                        echo '<script type="text/javascript">';
                        echo PHP_EOL . '// <![CDATA[' . PHP_EOL;
                        echo 'addLoadEvent(function(){' . PHP_EOL;
                        echo join(PHP_EOL, $js);
                        echo PHP_EOL . 'jQuery().ready(function() {
								jQuery(".tagadd").click();
								jQuery(\'html, body\').prop({scrollTop:0});
								jQuery(\'#title\').focus();
								});' . PHP_EOL;
                        echo PHP_EOL . '});' . PHP_EOL;
                        echo PHP_EOL . '// ]]>' . PHP_EOL;
                        echo '</script>';
                    }
                }
                // sync custom fields
                $tm_settings = $sitepress->get_setting('translation-management');
                $custom_fields_translation = !empty($tm_settings['custom_fields_translation']) ? (array) $tm_settings['custom_fields_translation'] : array();
                foreach ($custom_fields_translation as $key => $sync_opt) {
                    if ($sync_opt == 1) {
                        $copied_cf[] = $key;
                    }
                }
                if (!empty($copied_cf)) {
                    $source_lang = $source_lang ? $source_lang : $default_language;
                    $lang_details = $sitepress->get_language_details($source_lang);
                    $original_custom = get_post_custom($translations[$source_lang]->element_id);
                    $copied_cf = array_intersect($copied_cf, array_keys($original_custom));
                    $copied_cf = apply_filters('icl_custom_fields_to_be_copied', $copied_cf, $translations[$source_lang]->element_id);
                    $user_preferences = $sitepress->get_user_preferences();
                    if ($copied_cf && (!isset($user_preferences['notices']['hide_custom_fields_copy']) || !$user_preferences['notices']['hide_custom_fields_copy'])) {
                        $ccf_note = '<img src="' . ICL_PLUGIN_URL . '/res/img/alert.png" alt="Notice" width="16" height="16" style="margin-right:8px" />';
                        $ccf_note .= '<a class="icl_user_notice_hide" href="#hide_custom_fields_copy" style="float:right;margin-left:20px;">' . __('Never show this.', 'sitepress') . '</a>';
                        $ccf_note .= wp_nonce_field('save_user_preferences_nonce', '_icl_nonce_sup', false, false);
                        $ccf_note .= sprintf(__('WPML will copy %s from %s when you save this post.', 'sitepress'), '<i><strong>' . join('</strong>, <strong>', $copied_cf) . '</strong></i>', $lang_details['display_name']);
                        $sitepress->admin_notices($ccf_note, 'error');
                    }
                }
            }
            ?>
			<?php 
            if (!empty($is_sticky) && $sitepress->get_setting('sync_sticky_flag')) {
                ?>
				<script type="text/javascript">
					addLoadEvent(
						function () {
							jQuery('#sticky').attr('checked', 'checked');
							var post_visibility_display = jQuery('#post-visibility-display');
							post_visibility_display.html(post_visibility_display.html() + ', <?php 
                echo icl_js_escape(__('Sticky', 'sitepress'));
                ?>
');
						});
				</script>
			<?php 
            }
            ?>
		<?php 
        }
        if ('page-new.php' == $pagenow || 'post-new.php' == $pagenow && isset($_GET['post_type'])) {
            if ($trid && ($sitepress->get_setting('sync_page_template') || $sitepress->get_setting('sync_page_ordering'))) {
                $menu_order = $sitepress->get_setting('sync_page_ordering') ? $wpml_post_translations->get_original_menu_order($trid, $source_lang) : null;
                $page_template = $sitepress->get_setting('sync_page_template') ? get_post_meta($wpml_post_translations->get_original_post_ID($trid, $source_lang), '_wp_page_template', true) : null;
                if ($menu_order || $page_template) {
                    ?>
					<script type="text/javascript">addLoadEvent(function () { <?php 
                    if ($menu_order) {
                        ?>
							jQuery('#menu_order').val(<?php 
                        echo $menu_order;
                        ?>
);
							<?php 
                    }
                    if ($page_template && 'default' != $page_template) {
                        ?>
							jQuery('#page_template').val('<?php 
                        echo $page_template;
                        ?>
');
							<?php 
                    }
                    ?>
						});</script><?php 
                }
            }
        }
        // sync post dates
        if (icl_is_post_edit()) {
            // @since 3.1.5
            // Enqueing 'wp-jquery-ui-dialog', just in case it doesn't get automatically enqueued
            wp_enqueue_style('wp-jquery-ui-dialog');
            wp_enqueue_style('sitepress-post-edit', ICL_PLUGIN_URL . '/res/css/post-edit.css', array(), ICL_SITEPRESS_VERSION);
            wp_enqueue_script('sitepress-post-edit', ICL_PLUGIN_URL . '/res/js/post-edit.js', array('jquery-ui-dialog', 'jquery-ui-autocomplete', 'autosave'), ICL_SITEPRESS_VERSION);
            if ($sitepress->get_setting('sync_post_date')) {
                if (!$trid) {
                    $post_id = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT);
                    $trid = $post_id !== null ? $wpml_post_translations->get_element_trid($post_id) : null;
                }
                if ($trid) {
                    $original_date = $wpml_post_translations->get_original_post_date($trid, $source_lang);
                    $exp = explode(' ', $original_date);
                    list($aa, $mm, $jj) = explode('-', $exp[0]);
                    list($hh, $mn, $ss) = explode(':', $exp[1]);
                    ?>
					<script type="text/javascript">
						addLoadEvent(
							function () {
								jQuery('#aa').val('<?php 
                    echo $aa;
                    ?>
').attr('readonly', 'readonly');
								jQuery('#mm').val('<?php 
                    echo $mm;
                    ?>
').attr('readonly', 'readonly');
								jQuery('#jj').val('<?php 
                    echo $jj;
                    ?>
').attr('readonly', 'readonly');
								jQuery('#hh').val('<?php 
                    echo $hh;
                    ?>
').attr('readonly', 'readonly');
								jQuery('#mn').val('<?php 
                    echo $mn;
                    ?>
').attr('readonly', 'readonly');
								jQuery('#ss').val('<?php 
                    echo $ss;
                    ?>
').attr('readonly', 'readonly');
								var timestamp = jQuery('#timestamp');
								timestamp.find('b').append(( '<span> <?php 
                    esc_html_e('Copied From the Original', 'sitepress');
                    ?>
</span>'));
								timestamp.next().html('<span style="margin-left:1em;"><?php 
                    esc_html_e('Edit', 'sitepress');
                    ?>
</span>');
							});
					</script>
				<?php 
                }
            }
        }
        if ('post-new.php' === $pagenow && isset($_GET['trid']) && $sitepress->get_setting('sync_post_format') && function_exists('get_post_format')) {
            $format = $wpml_post_translations->get_original_post_format($trid, $source_lang);
            ?>
			<script type="text/javascript">
				addLoadEvent(function () {
					jQuery('#post-format-' + '<?php 
            echo $format;
            ?>
').attr('checked', 'checked');
				});
			</script><?php 
        }
        wp_enqueue_script('theme-preview');
        if ('languages' === $page_basename || 'string-translation' === $page_basename) {
            wp_enqueue_script('wp-color-picker');
            wp_register_style('wpml-color-picker', ICL_PLUGIN_URL . '/res/css/colorpicker.css', array('wp-color-picker'), ICL_SITEPRESS_VERSION);
            wp_enqueue_style('wpml-color-picker');
            wp_enqueue_script('jquery-ui-sortable');
        }
    }
Exemplo n.º 4
0
 function locale()
 {
     global $wpdb, $locale;
     add_filter('language_attributes', array($this, '_language_attributes'));
     if (defined('WP_ADMIN')) {
         if (function_exists('wp_get_current_user') && get_user_meta(get_current_user_id(), 'icl_admin_language_for_edit', true) && icl_is_post_edit()) {
             $l = $this->get_locale($this->get_current_language());
         } else {
             $l = $this->get_locale($this->admin_language);
         }
     } else {
         $l = $this->get_locale($this->this_lang);
     }
     if ($l) {
         $locale = $l;
     }
     $template_path = defined('TEMPLATEPATH') ? TEMPLATEPATH : get_template_directory();
     // theme localization
     remove_filter('locale', array($this, 'locale'));
     //avoid infinite loop
     static $theme_locales_loaded = false;
     if (!$theme_locales_loaded && !empty($this->settings['theme_localization_load_textdomain']) && !empty($this->settings['gettext_theme_domain_name']) && !empty($this->settings['theme_language_folders'])) {
         foreach ($this->settings['theme_language_folders'] as $folder) {
             load_textdomain($this->settings['gettext_theme_domain_name'], $folder . '/' . $locale . '.mo');
         }
         $theme_locales_loaded = true;
     }
     add_filter('locale', array($this, 'locale'));
     return $locale;
 }
Exemplo n.º 5
0
 function get_admin_language()
 {
     $current_user = $this->get_current_user();
     if (isset($current_user->ID) && get_user_meta($current_user->ID, 'icl_admin_language_for_edit', true) && icl_is_post_edit()) {
         $admin_language = $this->get_current_language();
     } else {
         $admin_language = $this->user_lang_by_authcookie();
     }
     return $admin_language;
 }