Exemple #1
0
 function set($key, $value)
 {
     if (ICL_DISABLE_CACHE) {
         return;
     }
     $this->data[$key] = $value;
     if ($this->cache_to_option) {
         icl_cache_set($this->name . '_cache_class', $this->data);
     }
 }
    function language_filter()
    {
        require_once ICL_PLUGIN_PATH . '/inc/cache.php';
        global $wpdb;
        $type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
        if (!in_array($type, array('post', 'page')) && !in_array($type, array_keys($this->get_translatable_documents()))) {
            return;
        }
        $active_languages = $this->get_active_languages();
        $post_status = get_query_var('post_status');
        if (is_string($post_status)) {
            $post_status = $post_status ? array($post_status) : array();
        }
        $key = join(',', $post_status);
        if ($key) {
            $key = '#' . $key;
        }
        $languages = icl_cache_get($type . 's_per_language' . $key);
        if (!$languages) {
            $extra_conditions = "";
            if ($post_status) {
                $extra_conditions .= apply_filters('_icl_posts_language_count_status', " AND post_status IN('" . join("','", $post_status) . "') ");
            }
            if ($post_status != array('trash')) {
                $extra_conditions .= " AND post_status <> 'trash'";
            }
            // dont count auto drafts
            $extra_conditions .= " AND post_status <> 'auto-draft'";
            // only active language
            $extra_conditions .= " AND t.language_code IN ('" . join("','", array_keys($active_languages)) . "') ";
            $res = $wpdb->get_results("\r\n\t\t\t\tSELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t\r\n\t\t\t\tJOIN {$wpdb->posts} p ON t.element_id=p.ID\r\n\t\t\t\tJOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1\r\n\t\t\t\tWHERE p.post_type='{$type}' AND t.element_type='post_{$type}' {$extra_conditions}\r\n\t\t\t\tGROUP BY language_code\r\n\t\t\t\t");
            $languages['all'] = 0;
            foreach ($res as $r) {
                $languages[$r->language_code] = $r->c;
                $languages['all'] += $r->c;
            }
            icl_cache_set($type . 's_per_language' . $key, $languages);
        }
        $active_languages[] = array('code' => 'all', 'display_name' => __('All languages', 'sitepress'));
        $as = array();
        foreach ($active_languages as $lang) {
            if ($lang['code'] == $this->this_lang) {
                $px = '<strong>';
                $sx = ' <span class="count">(' . @intval($languages[$lang['code']]) . ')<\\/span><\\/strong>';
            } elseif (!isset($languages[$lang['code']])) {
                $px = '<span>';
                $sx = '<\\/span>';
            } else {
                if ($post_status) {
                    $px = '<a href="?post_type=' . $type . '&post_status=' . join(',', $post_status) . '&lang=' . $lang['code'] . '">';
                } else {
                    $px = '<a href="?post_type=' . $type . '&lang=' . $lang['code'] . '">';
                }
                $sx = '<\\/a> <span class="count">(' . intval($languages[$lang['code']]) . ')<\\/span>';
            }
            $as[] = $px . $lang['display_name'] . $sx;
        }
        $allas = join(' | ', $as);
        if (empty($this->settings['hide_how_to_translate']) && $type == 'page' && !$this->get_icl_translation_enabled()) {
            $prot_link = '<span id="icl_how_to_translate_link" class="button" style="padding-right:3px;" ><img align="baseline" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" width="16" height="16" style="margin-bottom:-4px" /> <a href="https://wpml.org/?page_id=3416">' . __('How to translate', 'sitepress') . '</a><a href="#" title="' . esc_attr__('hide this', 'sitepress') . '" onclick=" if(confirm(\\\'' . __('Are you sure you want to remove this button?', 'sitepress') . '\\\')) jQuery.ajax({url:icl_ajx_url,type:\\\'POST\\\',data:{icl_ajx_action:\\\'update_option\\\', option:\\\'hide_how_to_translate\\\',value:1,_icl_nonce:\\\'' . wp_create_nonce('update_option_nonce') . '\\\'},success:function(){jQuery(\\\'#icl_how_to_translate_link\\\').fadeOut()}});return false;" style="outline:none;"><img src="' . ICL_PLUGIN_URL . '/res/img/close2.png" width="10" height="10" style="border:none" alt="' . esc_attr__('hide', 'sitepress') . '" /><\\/a>' . '<\\/span>';
        } else {
            $prot_link = '';
        }
        ?>
		<script type="text/javascript">
			jQuery(".subsubsub").append('<br /><span id="icl_subsubsub"><?php 
        echo $allas;
        ?>
</span><br /><?php 
        echo $prot_link;
        ?>
');
		</script>
	<?php 
    }
    function language_filter()
    {
        require_once ICL_PLUGIN_PATH . '/inc/cache.php';
        global $wpdb, $pagenow;
        /* preWP3 compatibility  - start */
        if (ICL_PRE_WP3) {
            if ($pagenow == 'edit.php') {
                $type = 'post';
            } else {
                $type = 'page';
            }
        } else {
            /* preWP3 compatibility  - end */
            $type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
        }
        if (!in_array($type, array('post', 'page')) && !in_array($type, array_keys($this->get_translatable_documents()))) {
            return;
        }
        $active_languages = $this->get_active_languages();
        $post_status = get_query_var('post_status');
        $langs = icl_cache_get($type . 's_per_language#' . $post_status);
        if (!$langs) {
            $extra_cond = "";
            if ($post_status) {
                $extra_cond .= " AND post_status = '" . $post_status . "'";
            }
            if ($post_status != 'trash') {
                $extra_cond .= " AND post_status <> 'trash'";
            }
            $res = $wpdb->get_results("\n                SELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t\n                JOIN {$wpdb->posts} p ON t.element_id=p.ID\n                JOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1\n                WHERE p.post_type='{$type}' AND t.element_type='post_{$type}' {$extra_cond}\n                GROUP BY language_code\n                ");
            $langs['all'] = 0;
            foreach ($res as $r) {
                $langs[$r->language_code] = $r->c;
                $langs['all'] += $r->c;
            }
            icl_cache_set($type . 's_per_language', $langs);
        }
        $active_languages[] = array('code' => 'all', 'display_name' => __('All languages', 'sitepress'));
        foreach ($active_languages as $lang) {
            if ($lang['code'] == $this->this_lang) {
                $px = '<strong>';
                $sx = ' <span class="count">(' . @intval($langs[$lang['code']]) . ')<\\/span><\\/strong>';
            } elseif (!isset($langs[$lang['code']])) {
                $px = '<span>';
                $sx = '<\\/span>';
            } else {
                if ($post_status) {
                    $px = '<a href="?post_type=' . $type . '&post_status=' . $post_status . '&lang=' . $lang['code'] . '">';
                } else {
                    $px = '<a href="?post_type=' . $type . '&lang=' . $lang['code'] . '">';
                }
                $sx = '<\\/a> <span class="count">(' . intval($langs[$lang['code']]) . ')<\\/span>';
            }
            $as[] = $px . $lang['display_name'] . $sx;
        }
        $allas = join(' | ', $as);
        if ($type == 'page' && !$this->get_icl_translation_enabled()) {
            $prot_link = '<span class="button" style="padding:4px;margin-top:10px;"><img align="baseline" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" width="16" height="16" style="margin-bottom:-4px" /> <a href="http://wpml.org/?page_id=3416">' . __('How to translate', 'sitepress') . '<\\/a>' . '<\\/span>';
        } else {
            $prot_link = '';
        }
        ?>
        <script type="text/javascript">
            jQuery(".subsubsub").append('<br /><span id="icl_subsubsub"><?php 
        echo $allas;
        ?>
<\/span><br /><?php 
        echo $prot_link;
        ?>
');
        </script>
        <?php 
    }
Exemple #4
0
 function save_cache_if_requred()
 {
     if ($this->cache_needs_saving) {
         icl_cache_set($this->name . '_cache_class', $this->data);
         $this->cache_needs_saving = false;
     }
 }