当前位置: 首页>>代码示例>>PHP>>正文


PHP SitePress::get_wp_helper方法代码示例

本文整理汇总了PHP中SitePress::get_wp_helper方法的典型用法代码示例。如果您正苦于以下问题:PHP SitePress::get_wp_helper方法的具体用法?PHP SitePress::get_wp_helper怎么用?PHP SitePress::get_wp_helper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SitePress的用法示例。


在下文中一共展示了SitePress::get_wp_helper方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_string_translations

 public function get_string_translations()
 {
     $string_translations = array();
     $current_user = $this->sitepress->get_current_user();
     $current_user_can_translate_strings = $this->sitepress->get_wp_helper()->current_user_can_translate_strings();
     $user_lang_pairs = $this->sitepress->get_wp_helper()->get_user_language_pairs($current_user);
     $extra_cond = "";
     if ($current_user_can_translate_strings && isset($_GET['status']) && preg_match("#" . ICL_TM_WAITING_FOR_TRANSLATOR . "-(.+)#", $_GET['status'], $matches)) {
         $status_filter = ICL_TM_WAITING_FOR_TRANSLATOR;
         $status_filter_lang = $matches[1];
         $language_code_alias = str_replace('-', '', $status_filter_lang);
         $extra_cond .= " AND str_{$language_code_alias}.language = '{$status_filter_lang}' ";
     } else {
         $status_filter = isset($_GET['status']) ? intval($_GET['status']) : false;
     }
     $search_filter = isset($_GET['search']) ? $_GET['search'] : false;
     $exact_match = isset($_GET['em']) ? $_GET['em'] == 1 : false;
     if ($status_filter !== false) {
         if ($status_filter == ICL_TM_COMPLETE) {
             $extra_cond .= " AND s.status = " . ICL_TM_COMPLETE;
         } elseif ($status_filter != ICL_TM_WAITING_FOR_TRANSLATOR) {
             $extra_cond .= " AND status IN (" . ICL_STRING_TRANSLATION_PARTIAL . "," . ICL_TM_NEEDS_UPDATE . "," . ICL_TM_NOT_TRANSLATED . "," . ICL_TM_WAITING_FOR_TRANSLATOR . ")";
         }
     }
     if ($search_filter != false) {
         if ($exact_match) {
             $extra_cond .= " AND s.value = '" . esc_sql($search_filter) . "' ";
         } else {
             $extra_cond .= " AND s.value LIKE '%" . esc_sql($search_filter) . "%' ";
         }
     }
     $extra_cond .= isset($_GET['context']) ? " AND s.context = '" . esc_sql($_GET['context']) . "'" : '';
     if (isset($_GET['show_results']) && $_GET['show_results'] == 'all') {
         $limit = 9999;
         $offset = 0;
     } else {
         $limit = $this->get_strings_per_page();
         $_GET['paged'] = isset($_GET['paged']) ? $_GET['paged'] : 1;
         $offset = ($_GET['paged'] - 1) * $limit;
     }
     /* TRANSLATOR - START */
     if ($current_user_can_translate_strings) {
         $active_languages = $this->sitepress->get_active_languages();
         foreach ($user_lang_pairs as $source_lang_code => $pair) {
             if (!isset($active_languages[$source_lang_code])) {
                 $active_languages[$source_lang_code] = $this->sitepress->get_language_details($source_lang_code);
             }
             foreach (array_keys($pair) as $target_lang_code) {
                 if (!isset($active_languages[$target_lang_code])) {
                     $active_languages[$target_lang_code] = $this->sitepress->get_language_details($target_lang_code);
                 }
             }
         }
         $_joins = $_sels = $_where = array();
         foreach ($active_languages as $l) {
             $language_code_alias = esc_sql(str_replace('-', '', $l['code']));
             $_sels[] = "str_{$language_code_alias}.id AS id_{$language_code_alias},\n\t                             str_{$language_code_alias}.status AS status_{$language_code_alias},\n\t                             str_{$language_code_alias}.value AS value_{$language_code_alias},\n\t                             str_{$language_code_alias}.translator_id AS translator_{$language_code_alias},\n\t                             str_{$language_code_alias}.translation_date AS date_{$language_code_alias}\n\t                             ";
             $_joins[] = $this->wpdb->prepare("LEFT JOIN {$this->wpdb->prefix}icl_string_translations str_{$language_code_alias}\n\t                                                ON str_{$language_code_alias}.string_id = s.id AND str_{$language_code_alias}.language = %s ", $l['code']);
             if (empty($status_filter_lang)) {
                 if ($status_filter == ICL_TM_COMPLETE) {
                     $_where[] .= " AND str_{$language_code_alias}.status = " . ICL_TM_COMPLETE;
                 } else {
                     if (empty($_lwhere)) {
                         $_lwheres = array();
                         $_lwhere = ' AND (';
                         foreach ($active_languages as $l2) {
                             $l2code_alias = esc_sql(str_replace('-', '', $l2['code']));
                             $_lwheres[] = $this->wpdb->prepare(" str_{$l2code_alias}.status = %d\n\t                                                          OR str_{$l2code_alias}.translator_id = %d ", ICL_TM_WAITING_FOR_TRANSLATOR, $current_user->ID);
                         }
                         $_lwhere .= join(' OR ', $_lwheres) . ')';
                         $_where[] = $_lwhere;
                     }
                 }
             }
         }
         $sql_query = empty($status_filter_lang) ? " WHERE s.language IN ( " . wpml_prepare_in(array_keys($user_lang_pairs)) . " ) " . join(' ', $_where) : $this->wpdb->prepare(" WHERE str_{$status_filter_lang}.status = %d\n\t\t\t\t\t\t\t\t\t\t\tAND (str_{$status_filter_lang}.translator_id IS NULL\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR str_{$status_filter_lang}.translator_id = %d)", array(ICL_TM_WAITING_FOR_TRANSLATOR, $current_user->ID));
         $res = $this->get_results($sql_query, $extra_cond, $offset, $limit, $_joins, $_sels);
         if ($res) {
             $string_translations = empty($status_filter_lang) ? $this->rows_from_unfiltered($res, $active_languages, $string_translations) : $this->rows_from_lang_status_filtered($res, $active_languages, $string_translations);
         }
         /* TRANSLATOR - END */
     } else {
         if ($status_filter != ICL_TM_WAITING_FOR_TRANSLATOR) {
             $sql_query = " WHERE 1 ";
         } else {
             $sql_query = " JOIN {$this->wpdb->prefix}icl_string_translations str ON str.string_id = s.id\n\t                           WHERE str.status = " . ICL_TM_WAITING_FOR_TRANSLATOR;
         }
         $res = $this->get_results($sql_query, $extra_cond, $offset, $limit);
         if ($res) {
             $extra_cond = '';
             if (isset($_GET['translation_language'])) {
                 $extra_cond .= " AND language='" . esc_sql($_GET['translation_language']) . "'";
             }
             foreach ($res as $row) {
                 $string_translations[$row['string_id']] = $row;
                 $tr = $this->wpdb->get_results($this->wpdb->prepare("\n\t                    SELECT id, language, status, value, translator_id, translation_date  \n\t                    FROM {$this->wpdb->prefix}icl_string_translations \n\t                    WHERE string_id=%d {$extra_cond}\n\t                ", $row['string_id']), ARRAY_A);
                 if ($tr) {
                     foreach ($tr as $t) {
                         $string_translations[$row['string_id']]['translations'][$t['language']] = $t;
                     }
//.........这里部分代码省略.........
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:class-wpml-st-strings.php

示例2: get_string_translations

 public function get_string_translations()
 {
     $string_translations = array();
     $current_user = $this->sitepress->get_current_user();
     $active_languages = $this->sitepress->get_active_languages();
     //		error_log(serialize($active_languages), 3, WP_CONTENT_DIR . '/debug.log');
     $current_user_can_translate_strings = $this->sitepress->get_wp_helper()->current_user_can_translate_strings();
     $user_lang_pairs = $this->sitepress->get_wp_helper()->get_user_language_pairs($current_user);
     $extra_cond = "";
     if ($current_user_can_translate_strings && isset($_GET['status']) && preg_match("#" . ICL_TM_WAITING_FOR_TRANSLATOR . "-(.+)#", $_GET['status'], $matches)) {
         $status_filter = ICL_TM_WAITING_FOR_TRANSLATOR;
         $status_filter_lang = $matches[1];
         $language_code_alias = str_replace('-', '', $status_filter_lang);
         $extra_cond .= " AND str_{$language_code_alias}.language = '{$status_filter_lang}' ";
     } else {
         $status_filter = isset($_GET['status']) ? intval($_GET['status']) : false;
     }
     $search_filter = isset($_GET['search']) ? $_GET['search'] : false;
     $exact_match = isset($_GET['em']) ? $_GET['em'] == 1 : false;
     if ($status_filter !== false) {
         if ($status_filter == ICL_TM_COMPLETE) {
             $extra_cond .= " AND s.status = " . ICL_TM_COMPLETE;
         } elseif ($status_filter == ICL_TM_WAITING_FOR_TRANSLATOR) {
             // do nothing
         } else {
             $extra_cond .= " AND status IN (" . ICL_STRING_TRANSLATION_PARTIAL . "," . ICL_TM_NEEDS_UPDATE . "," . ICL_TM_NOT_TRANSLATED . "," . ICL_TM_WAITING_FOR_TRANSLATOR . ")";
         }
     }
     if ($search_filter != false) {
         if ($exact_match) {
             $extra_cond .= " AND s.value = '" . esc_sql($search_filter) . "' ";
         } else {
             $extra_cond .= " AND s.value LIKE '%" . esc_sql($search_filter) . "%' ";
         }
     }
     $context_filter = isset($_GET['context']) ? $_GET['context'] : false;
     if ($context_filter !== false) {
         $extra_cond .= " AND s.context = '" . esc_sql($context_filter) . "'";
     }
     if (isset($_GET['show_results']) && $_GET['show_results'] == 'all') {
         $limit = 9999;
         $offset = 0;
     } else {
         $limit = $this->sitepress_settings['st']['strings_per_page'];
         if (!isset($_GET['paged'])) {
             $_GET['paged'] = 1;
         }
         $offset = ($_GET['paged'] - 1) * $limit;
     }
     /* TRANSLATOR - START */
     if ($current_user_can_translate_strings) {
         if (!empty($status_filter_lang)) {
             $_joins = $_sels = $_where = array();
             foreach ($active_languages as $l) {
                 if ($l['code'] == $this->sitepress_settings['st']['strings_language']) {
                     continue;
                 }
                 $language_code_alias = esc_sql(str_replace('-', '', $l['code']));
                 $_sels[] = "str_{$language_code_alias}.id AS id_{$language_code_alias},\n\t                             str_{$language_code_alias}.status AS status_{$language_code_alias},\n\t                             str_{$language_code_alias}.value AS value_{$language_code_alias},\n\t                             str_{$language_code_alias}.translator_id AS translator_{$language_code_alias},\n\t                             str_{$language_code_alias}.translation_date AS date_{$language_code_alias}\n\t                             ";
                 $_joins[] = $this->wpdb->prepare(" LEFT JOIN {$this->wpdb->prefix}icl_string_translations str_{$language_code_alias}\n\t                                                ON str_{$language_code_alias}.string_id = s.id AND str_{$language_code_alias}.language = %s ", $l['code']);
             }
             $sql = "\n\t                SELECT SQL_CALC_FOUND_ROWS s.id AS string_id, s.language AS string_language, s.context, s.gettext_context, s.name, s.value, s.status,\n\t                    " . join(", ", $_sels) . "\n\t                FROM  {$this->wpdb->prefix}icl_strings s \n\t                " . join("\n", $_joins) . "\n\t                WHERE \n\t                    str_{$status_filter_lang}.status = %d AND\n\t                    (str_{$status_filter_lang}.translator_id IS NULL OR str_{$status_filter_lang}.translator_id = %d)\n\t                    {$extra_cond}\n\t                ORDER BY string_id DESC\n\t                LIMIT {$offset},{$limit}\n\t            ";
             $sql_prepared = $this->wpdb->prepare($sql, array(ICL_TM_WAITING_FOR_TRANSLATOR, $current_user->ID));
             $res = $this->wpdb->get_results($sql_prepared, ARRAY_A);
         } else {
             $_joins = $_sels = $_where = array();
             foreach ($active_languages as $l) {
                 if ($l['code'] == $this->sitepress_settings['st']['strings_language'] || empty($user_lang_pairs[$this->sitepress_settings['st']['strings_language']][$l['code']])) {
                     continue;
                 }
                 $language_code_alias = esc_sql(str_replace('-', '', $l['code']));
                 $_sels[] = "str_{$language_code_alias}.id AS id_{$language_code_alias},\n\t                             str_{$language_code_alias}.status AS status_{$language_code_alias},\n\t                             str_{$language_code_alias}.value AS value_{$language_code_alias},\n\t                             str_{$language_code_alias}.translator_id AS translator_{$language_code_alias},\n\t                             str_{$language_code_alias}.translation_date AS date_{$language_code_alias}\n\t                             ";
                 $_joins[] = $this->wpdb->prepare("LEFT JOIN {$this->wpdb->prefix}icl_string_translations str_{$language_code_alias}\n\t                                                ON str_{$language_code_alias}.string_id = s.id AND str_{$language_code_alias}.language = %s ", $l['code']);
                 if ($status_filter == ICL_TM_COMPLETE) {
                     $_where[] .= " AND str_{$language_code_alias}.status = " . ICL_TM_COMPLETE;
                 } else {
                     if (empty($_lwhere)) {
                         $_lwheres = array();
                         $_lwhere = ' AND (';
                         foreach ($active_languages as $l2) {
                             if ($l2['code'] == $this->sitepress_settings['st']['strings_language'] || empty($user_lang_pairs[$this->sitepress_settings['st']['strings_language']][$l2['code']])) {
                                 continue;
                             }
                             $l2code_alias = esc_sql(str_replace('-', '', $l2['code']));
                             $_lwheres[] = $this->wpdb->prepare(" str_{$l2code_alias}.status = %d\n\t                                                          OR str_{$l2code_alias}.translator_id = %d ", ICL_TM_WAITING_FOR_TRANSLATOR, $current_user->ID);
                         }
                         $_lwhere .= join(' OR ', $_lwheres) . ')';
                         $_where[] = $_lwhere;
                     }
                 }
             }
             $sql = "\n\t                SELECT SQL_CALC_FOUND_ROWS s.id AS string_id, s.language AS string_language, s.context, s.gettext_context, s.name, s.value, s.status, " . join(', ', $_sels) . "\n\t                FROM {$this->wpdb->prefix}icl_strings s " . join("\n", $_joins) . "\n\t                WHERE s.language = '{$this->sitepress_settings['st']['strings_language']}' " . join(' ', $_where) . "\n\t                    {$extra_cond}\n\t                ORDER BY s.id DESC\n\t                LIMIT {$offset},{$limit}\n\t                ";
             $res = $this->wpdb->get_results($sql, ARRAY_A);
         }
         $this->wp_query->found_posts = $this->wpdb->get_var("SELECT FOUND_ROWS()");
         $this->wp_query->query_vars['posts_per_page'] = $limit;
         $this->wp_query->max_num_pages = ceil($this->wp_query->found_posts / $limit);
         if ($res) {
             if (!empty($status_filter_lang)) {
                 foreach ($res as $row) {
//.........这里部分代码省略.........
开发者ID:crazyyy,项目名称:octagram,代码行数:101,代码来源:class-wpml-st-strings.php


注:本文中的SitePress::get_wp_helper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。