/**
  * @param $language
  *
  * @return bool
  */
 private function has_any_strings_in_shared_cached($language)
 {
     $sql = "\n\t\t\tSELECT id FROM {$this->wpdb->prefix}icl_string_urls\n\t\t\tWHERE language = %s AND url IS NULL\n\t\t\tORDER BY id ASC LIMIT 1\n\t\t";
     $query = $this->wpdb->prepare($sql, array($language));
     $value = $this->wpdb->get_var($query);
     return (bool) $value;
 }
 /**
  * Adapated from interconnect/it's search/replace script.
  * Modified to use WordPress wpdb functions instead of PHP's native mysql/pdo functions.
  * 
  * @link https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  * 
  * @access public
  * @param  string $table 	The table to run the replacement on.
  * @param  string $search 	The string to replace.
  * @param  string $replace 	The string to replace with.
  * @return array   			Collection of information gathered during the run.
  */
 public function revisr_srdb($table, $search = '', $replace = '')
 {
     // Get a list of columns in this table.
     $columns = array();
     $fields = $this->wpdb->get_results('DESCRIBE ' . $table);
     foreach ($fields as $column) {
         $columns[$column->Field] = $column->Key == 'PRI' ? true : false;
     }
     $this->wpdb->flush();
     // Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
     $this->wpdb->get_results('SELECT COUNT(*) FROM ' . $table);
     $row_count = $this->wpdb->num_rows;
     if ($row_count == 0) {
         continue;
     }
     $page_size = 50000;
     $pages = ceil($row_count / $page_size);
     for ($page = 0; $page < $pages; $page++) {
         $current_row = 0;
         $start = $page * $page_size;
         $end = $start + $page_size;
         // Grab the content of the table.
         $data = $this->wpdb->get_results("SELECT * FROM {$table} LIMIT {$start}, {$end}", ARRAY_A);
         // Loop through the data.
         foreach ($data as $row) {
             $current_row++;
             $update_sql = array();
             $where_sql = array();
             $upd = false;
             foreach ($columns as $column => $primary_key) {
                 $edited_data = $data_to_fix = $row[$column];
                 // Run a search replace on the data that'll respect the serialisation.
                 $edited_data = $this->recursive_unserialize_replace($search, $replace, $data_to_fix);
                 // Something was changed
                 if ($edited_data != $data_to_fix) {
                     $update_sql[] = $column . ' = "' . $this->mysql_escape_mimic($edited_data) . '"';
                     $upd = true;
                 }
                 if ($primary_key) {
                     $where_sql[] = $column . ' = "' . $this->mysql_escape_mimic($data_to_fix) . '"';
                 }
             }
             if ($upd && !empty($where_sql)) {
                 $sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $update_sql) . ' WHERE ' . implode(' AND ', array_filter($where_sql));
                 $result = $this->wpdb->query($sql);
                 if (!$result) {
                     $error_msg = sprintf(__('Error updating the table: %s.', 'revisr'), $table);
                 }
             } elseif ($upd) {
                 $error_msg = sprintf(__('The table "%s" has no primary key. Manual change needed on row %s.', 'revisr'), $table, $current_row);
             }
         }
     }
     $this->wpdb->flush();
     if (isset($error_msg)) {
         Revisr_Admin::log($error_msg, 'error');
         return false;
     }
 }
 private function set_pagination_counts($limit)
 {
     if (!is_null($this->wp_query)) {
         $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);
     }
 }
 function get_element_lang_code($element_id)
 {
     $cache_key_array = array($element_id, $this->element_type);
     $cache_key = md5(serialize($cache_key_array));
     $cache_group = 'WPML_Element_Type_Translation::get_language_for_element';
     $cache_found = false;
     $cache = $this->cache_factory->get($cache_group);
     $result = $cache->get($cache_key, $cache_found);
     if (!$cache_found) {
         $language_for_element_prepared = $this->wpdb->prepare("SELECT language_code \n\t\t\t\tFROM {$this->wpdb->prefix}icl_translations\n\t\t\t\tWHERE element_id=%d\n\t\t\t\tAND element_type=%s\n\t\t\t\tLIMIT 1", array($element_id, $this->element_type));
         $result = $this->wpdb->get_var($language_for_element_prepared);
         if ($result) {
             $cache->set($cache_key, $result);
         }
     }
     return $result;
 }
 /**
  * Returns an array containing the size of each database table.
  * @access public
  * @return array
  */
 public function get_sizes()
 {
     $sizes = array();
     $tables = $this->wpdb->get_results('SHOW TABLE STATUS', ARRAY_A);
     foreach ($tables as $table) {
         $size = round($table['Data_length'] / 1024 / 1024, 2);
         $sizes[$table['Name']] = sprintf(__('(%s MB)', 'revisr'), $size);
     }
     return $sizes;
 }
 /**
  * @param $ids Array or string of log ID's to delete
  *
  * @return false|int
  */
 public function delete_by_id($ids)
 {
     if (is_array($ids)) {
         // create comma-separated string
         $ids = implode(',', $ids);
     }
     // escape string for usage in IN clause
     $ids = esc_sql($ids);
     $sql = sprintf("DELETE FROM `%s` WHERE ID IN (%s)", $this->table_name, $ids);
     return $this->db->query($sql);
 }
 function reset_pro_translation_configuration()
 {
     $translation_service_name = $this->TranslationProxy->get_current_service_name();
     $this->sitepress->set_setting('content_translation_languages_setup', false);
     $this->sitepress->set_setting('content_translation_setup_complete', false);
     $this->sitepress->set_setting('content_translation_setup_wizard_step', false);
     $this->sitepress->set_setting('translator_choice', false);
     $this->sitepress->set_setting('icl_lang_status', false);
     $this->sitepress->set_setting('icl_balance', false);
     $this->sitepress->set_setting('icl_support_ticket_id', false);
     $this->sitepress->set_setting('icl_current_session', false);
     $this->sitepress->set_setting('last_get_translator_status_call', false);
     $this->sitepress->set_setting('last_icl_reminder_fetch', false);
     $this->sitepress->set_setting('icl_account_email', false);
     $this->sitepress->set_setting('translators_management_info', false);
     $this->sitepress->set_setting('site_id', false);
     $this->sitepress->set_setting('access_key', false);
     $this->sitepress->set_setting('ts_site_id', false);
     $this->sitepress->set_setting('ts_access_key', false);
     if (class_exists('TranslationProxy_Basket')) {
         //Cleaning the basket
         TranslationProxy_Basket::delete_all_items_from_basket();
     }
     $sql_for_remote_rids = $this->wpdb->prepare("FROM {$this->wpdb->prefix}icl_translation_status\n\t\t\t\t\t\t\t\t \t\t\t\tWHERE translation_service != 'local'\n\t\t\t\t\t\t\t\t \t\t\t\t\tAND translation_service != 0\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND status IN ( %d, %d )", ICL_TM_WAITING_FOR_TRANSLATOR, ICL_TM_IN_PROGRESS);
     //Delete all translation service jobs with status "waiting for translator" or "in progress"
     $this->wpdb->query("DELETE FROM {$this->wpdb->prefix}icl_translate_job WHERE rid IN (SELECT rid {$sql_for_remote_rids})");
     //Delete all translation statuses with status "waiting for translator" or "in progress"
     $this->wpdb->query("DELETE {$sql_for_remote_rids}");
     //Cleaning up Translation Proxy settings
     $this->sitepress->set_setting('icl_html_status', false);
     $this->sitepress->set_setting('language_pairs', false);
     if (!$this->TranslationProxy->has_preferred_translation_service()) {
         $this->sitepress->set_setting('translation_service', false);
         $this->sitepress->set_setting('icl_translation_projects', false);
     }
     $this->sitepress->save_settings();
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_core_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_content_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_string_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_node");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_reminders");
     if ($this->TranslationProxy->has_preferred_translation_service() && $translation_service_name) {
         $confirm_message = 'The translation process with %1$s was reset.';
     } elseif ($translation_service_name) {
         $confirm_message = 'Your site was successfully disconnected from %1$s. Go to the translators tab to connect a new %1$s account or use a different translation service.';
     } else {
         $confirm_message = 'PRO translation has been reset.';
     }
     $response = sprintf(__($confirm_message, 'wpml-translation-management'), $translation_service_name);
     return $response;
 }
 private function get_translation_statuses()
 {
     $post_translations = $this->get_post_translations();
     $status = array();
     foreach ($post_translations as $language => $translation) {
         $res_query = "SELECT status as status_code, needs_update FROM {$this->wpdb->prefix}icl_translation_status WHERE translation_id=%d";
         $res_args = array($translation->translation_id);
         $res_prepare = $this->wpdb->prepare($res_query, $res_args);
         $res = $this->wpdb->get_row($res_prepare);
         if ($res) {
             $res->status = $res->status_code;
             switch ($res->status) {
                 case ICL_TM_WAITING_FOR_TRANSLATOR:
                     $res->status = __('Waiting for translator', 'wpml-string-translation');
                     break;
                 case ICL_TM_IN_PROGRESS:
                     $res->status = __('In progress', 'wpml-string-translation');
                     break;
                 case ICL_TM_NEEDS_UPDATE:
                     $res->status = '';
                     break;
                 case ICL_TM_COMPLETE:
                     $res->status = __('Complete', 'wpml-string-translation');
                     break;
                 default:
                     $res->status = __('Not translated', 'wpml-string-translation');
                     break;
             }
             if ($res->needs_update) {
                 if ($res->status) {
                     $res->status .= ' - ';
                 }
                 $res->status .= __('Needs update', 'wpml-string-translation');
             }
             $status[$language] = $res;
         }
     }
     return $status;
 }
Beispiel #9
0
 /**
  * Adapated from interconnect/it's search/replace script.
  *
  * Modified to use WordPress wpdb functions instead of PHP's native mysql/pdo functions,
  * and to be compatible with batch processing via AJAX.
  *
  * @link https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  *
  * @access public
  * @param  string 	$table 	The table to run the replacement on.
  * @param  int 		$page  	The page/block to begin the query on.
  * @param  array 	$args 	An associative array containing arguements for this run.
  * @return array
  */
 public function srdb($table, $page, $args)
 {
     // Load up the default settings for this chunk.
     $table = esc_sql($table);
     $current_page = absint($page);
     $pages = $this->get_pages_in_table($table);
     $done = false;
     $args['search_for'] = str_replace('#BSR_BACKSLASH#', '\\', $args['search_for']);
     $args['replace_with'] = str_replace('#BSR_BACKSLASH#', '\\', $args['replace_with']);
     $table_report = array('change' => 0, 'updates' => 0, 'start' => microtime(true), 'end' => microtime(true), 'errors' => array(), 'skipped' => false);
     // Get a list of columns in this table.
     list($primary_key, $columns) = $this->get_columns($table);
     // Bail out early if there isn't a primary key.
     if (null === $primary_key) {
         $table_report['skipped'] = true;
         return array(true, $table_report);
     }
     $current_row = 0;
     $start = $page * $this->page_size;
     $end = $this->page_size;
     // Grab the content of the table.
     $data = $this->wpdb->get_results("SELECT * FROM {$table} LIMIT {$start}, {$end}", ARRAY_A);
     // Loop through the data.
     foreach ($data as $row) {
         $current_row++;
         $update_sql = array();
         $where_sql = array();
         $upd = false;
         foreach ($columns as $column) {
             $data_to_fix = $row[$column];
             if ($column == $primary_key) {
                 $where_sql[] = $column . ' = "' . $this->mysql_escape_mimic($data_to_fix) . '"';
                 continue;
             }
             // Skip GUIDs by default.
             if ('on' !== $args['replace_guids'] && 'guid' == $column) {
                 continue;
             }
             if ($this->wpdb->options === $table) {
                 // Skip any BSR options as they may contain the search field.
                 if (isset($should_skip) && true === $should_skip) {
                     $should_skip = false;
                     continue;
                 }
                 // If the Site URL needs to be updated, let's do that last.
                 if (isset($update_later) && true === $update_later) {
                     $update_later = false;
                     $edited_data = $this->recursive_unserialize_replace($args['search_for'], $args['replace_with'], $data_to_fix, false, $args['case_insensitive']);
                     if ($edited_data != $data_to_fix) {
                         $table_report['change']++;
                         $table_report['updates']++;
                         update_option('bsr_update_site_url', $edited_data);
                         continue;
                     }
                 }
                 if ('_transient_bsr_results' === $data_to_fix || 'bsr_profiles' === $data_to_fix || 'bsr_update_site_url' === $data_to_fix) {
                     $should_skip = true;
                 }
                 if ('siteurl' === $data_to_fix && $args['dry_run'] !== 'on') {
                     $update_later = true;
                 }
             }
             // Run a search replace on the data that'll respect the serialisation.
             $edited_data = $this->recursive_unserialize_replace($args['search_for'], $args['replace_with'], $data_to_fix, false, $args['case_insensitive']);
             // Something was changed
             if ($edited_data != $data_to_fix) {
                 $update_sql[] = $column . ' = "' . $this->mysql_escape_mimic($edited_data) . '"';
                 $upd = true;
                 $table_report['change']++;
             }
         }
         // Determine what to do with updates.
         if ($args['dry_run'] === 'on') {
             // Don't do anything if a dry run
         } elseif ($upd && !empty($where_sql)) {
             // If there are changes to make, run the query.
             $sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $update_sql) . ' WHERE ' . implode(' AND ', array_filter($where_sql));
             $result = $this->wpdb->query($sql);
             if (!$result) {
                 $table_report['errors'][] = sprintf(__('Error updating row: %d.', 'better-search-replace'), $current_row);
             } else {
                 $table_report['updates']++;
             }
         }
     }
     // end row loop
     if ($current_page >= $pages - 1) {
         $done = true;
     }
     // Flush the results and return the report.
     $table_report['end'] = microtime(true);
     $this->wpdb->flush();
     return array('table_complete' => $done, 'table_report' => $table_report);
 }
 /**
  * Determine if a database supports a particular feature.
  *
  * Overridden here to work around differences between bbPress's
  * and WordPress's implementations. In particular, when
  * BuddyPress tries to run bbPress' SQL installation script,
  * the collation check always failed. The capability is long
  * supported by WordPress' minimum required MySQL version, so
  * this is safe.
  *
  * @see WPDB::has_cap() for a description of parameters and
  *      return values.
  *
  * @param string $db_cap See {@link WPDB::has_cap()}.
  * @param string $_table_name See {@link WPDB::has_cap()}.
  * @return bool See {@link WPDB::has_cap()}.
  */
 function has_cap($db_cap, $_table_name = '')
 {
     if ('collation' == $db_cap) {
         return true;
     }
     return parent::has_cap($db_cap);
 }
 private function get_language_for_element($id, $element_type)
 {
     $string_query = "SELECT language FROM {$this->wpdb->prefix}icl_strings WHERE id=%s";
     $string_prepared = $this->wpdb->prepare($string_query, $id);
     return $this->wpdb->get_var($string_prepared);
 }
 /**
  * @return array
  */
 public function get_all_contexts()
 {
     $sql = "\n\t\t\tSELECT DISTINCT context\n\t\t\tFROM {$this->wpdb->prefix}icl_strings \n\t\t";
     $rowset = $this->wpdb->get_col($sql);
     return array_unique(array_merge($rowset, $this->get_excluded_contexts()));
 }
 /**
  * Adapated from interconnect/it's search/replace script.
  * Modified to use WordPress wpdb functions instead of PHP's native mysql/pdo functions.
  *
  * @link https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  *
  * @access public
  * @param  string 	$table 				The table to run the replacement on.
  * @param  string 	$search 			The string to replace.
  * @param  string 	$replace 			The string to replace with.
  * @param  boolean 	$replace_guids 		Whether to skip the GUID column
  * @param  boolean 	$dry_run 			Whether to run as a dry run
  * @param  boolean  $case_insensitive 	If we should ignore case.
  * @return array
  */
 public function srdb($table, $search = '', $replace = '', $replace_guids, $dry_run, $case_insensitive)
 {
     $table = esc_sql($table);
     $table_report = array('change' => 0, 'updates' => 0, 'start' => microtime(true), 'end' => microtime(true), 'errors' => array());
     // Get a list of columns in this table.
     $columns = array();
     $fields = $this->wpdb->get_results('DESCRIBE ' . $table);
     foreach ($fields as $column) {
         $columns[$column->Field] = $column->Key == 'PRI' ? true : false;
     }
     $this->wpdb->flush();
     // Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
     $row_count = $this->wpdb->get_var("SELECT COUNT(*) FROM {$table}");
     if ($row_count == 0) {
         return $table_report;
     }
     // Default to a lower page size for shared hosting/large DB's.
     $page_size = get_option('bsr_page_size') ? get_option('bsr_page_size') : 20000;
     $pages = ceil($row_count / $page_size);
     for ($page = 0; $page < $pages; $page++) {
         $current_row = 0;
         $start = $page * $page_size;
         $end = $page_size;
         // Grab the content of the table.
         $data = $this->wpdb->get_results("SELECT * FROM {$table} LIMIT {$start}, {$end}", ARRAY_A);
         // Loop through the data.
         foreach ($data as $row) {
             $current_row++;
             $update_sql = array();
             $where_sql = array();
             $upd = false;
             foreach ($columns as $column => $primary_key) {
                 $data_to_fix = $row[$column];
                 // Skip GUIDs by default.
                 if (true !== $replace_guids && 'guid' == $column) {
                     continue;
                 }
                 // Run a search replace on the data that'll respect the serialisation.
                 $edited_data = $this->recursive_unserialize_replace($search, $replace, $data_to_fix, false, $case_insensitive);
                 // Something was changed
                 if ($edited_data != $data_to_fix) {
                     $update_sql[] = $column . ' = "' . $this->mysql_escape_mimic($edited_data) . '"';
                     $upd = true;
                     $this->report['change']++;
                     $table_report['change']++;
                 }
                 if ($primary_key) {
                     $where_sql[] = $column . ' = "' . $this->mysql_escape_mimic($data_to_fix) . '"';
                 }
             }
             // Determine what to do with updates.
             if ($dry_run === true) {
                 // Don't do anything if a dry run
             } elseif ($upd && !empty($where_sql)) {
                 // If there are changes to make, run the query.
                 $sql = 'UPDATE ' . $table . ' SET ' . implode(', ', $update_sql) . ' WHERE ' . implode(' AND ', array_filter($where_sql));
                 $result = $this->wpdb->query($sql);
                 if (!$result) {
                     $this->report['errors']++;
                     $table_report['errors'][] = sprintf(__('Error updating row: %d.', 'better-search-replace'), $current_row);
                 } else {
                     $this->report['updates']++;
                     $table_report['updates']++;
                 }
             } elseif ($upd) {
                 $this->report['errors']++;
                 $table_report['errors'][] = sprintf(__('Row %d has no primary key, manual change needed.', 'better-search-replace'), $current_row);
             }
         }
     }
     // Flush the results and return the report.
     $table_report['end'] = microtime(true);
     $this->wpdb->flush();
     return $table_report;
 }
 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) {
                     $_translations = 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']));
                         if ($row['id_' . $language_code_alias]) {
                             $_translations[$l['code']] = array('id' => $row['id_' . $language_code_alias], 'status' => $row['status_' . $language_code_alias], 'language' => $l['code'], 'value' => $row['value_' . $language_code_alias], 'translator_id' => $row['translator_' . $language_code_alias], 'translation_date' => $row['date_' . $language_code_alias]);
                         }
                     }
                     $string_translations[$row['string_id']] = array('string_id' => $row['string_id'], 'string_language' => $row['string_language'], 'context' => $row['context'], 'gettext_context' => $row['gettext_context'], 'name' => $row['name'], 'value' => $row['value'], 'status' => ICL_TM_WAITING_FOR_TRANSLATOR, 'translations' => $_translations);
                 }
             } else {
                 foreach ($res as $row) {
                     $_translations = array();
                     $_status = ICL_TM_NOT_TRANSLATED;
                     $_statuses = 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 = str_replace('-', '', $l['code']);
                         if ($row['id_' . $language_code_alias]) {
                             $_translations[$l['code']] = array('id' => $row['id_' . $language_code_alias], 'status' => $row['status_' . $language_code_alias], 'language' => $l['code'], 'value' => $row['value_' . $language_code_alias], 'translator_id' => $row['translator_' . $language_code_alias], 'translation_date' => $row['date_' . $language_code_alias]);
                         }
                         $_statuses[$l['code']] = intval($row['status_' . $language_code_alias]);
                         if ($row['status_' . $language_code_alias] == ICL_TM_WAITING_FOR_TRANSLATOR) {
                             $_status = ICL_TM_WAITING_FOR_TRANSLATOR;
                         }
                     }
                     $_statuses = array_values($_statuses);
                     $_statuses = array_unique($_statuses);
                     if ($_statuses == array(ICL_TM_NOT_TRANSLATED)) {
                         $_status = ICL_TM_NOT_TRANSLATED;
                     } elseif ($_statuses == array(ICL_TM_COMPLETE, ICL_TM_NOT_TRANSLATED)) {
                         $_status = ICL_STRING_TRANSLATION_PARTIAL;
                     } elseif ($_statuses == array(ICL_TM_COMPLETE)) {
                         $_status = ICL_TM_COMPLETE;
                     } elseif (in_array(ICL_TM_WAITING_FOR_TRANSLATOR, $_statuses) || in_array(ICL_TM_NEEDS_UPDATE, $_statuses)) {
                         $_status = ICL_TM_WAITING_FOR_TRANSLATOR;
                     }
                     $string_translations[$row['string_id']] = array('string_id' => $row['string_id'], 'string_language' => $row['string_language'], 'context' => $row['context'], 'gettext_context' => $row['gettext_context'], 'name' => $row['name'], 'value' => $row['value'], 'status' => $_status, 'translations' => $_translations);
                 }
             }
         }
         /* TRANSLATOR - END */
     } else {
         // removed check for language = default lang
         if ($status_filter != ICL_TM_WAITING_FOR_TRANSLATOR) {
             $res = $this->wpdb->get_results("\n\t                SELECT SQL_CALC_FOUND_ROWS id AS string_id, language AS string_language, context, gettext_context, name, value, status                \n\t                FROM  {$this->wpdb->prefix}icl_strings s\n\t                WHERE \n\t                    1\n\t                    {$extra_cond}\n\t                ORDER BY string_id DESC\n\t                LIMIT {$offset},{$limit}\n\t            ", ARRAY_A);
         } else {
             $res = $this->wpdb->get_results("\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, " . ICL_TM_WAITING_FOR_TRANSLATOR . " AS status\n\t                FROM  {$this->wpdb->prefix}icl_strings s\n\t                JOIN {$this->wpdb->prefix}icl_string_translations str ON str.string_id = s.id\n\t                WHERE \n\t                    str.status = " . ICL_TM_WAITING_FOR_TRANSLATOR . "\n\t                    {$extra_cond}\n\t                ORDER BY string_id DESC\n\t                LIMIT {$offset},{$limit}\n\t            ", ARRAY_A);
         }
         if (!is_null($this->wp_query)) {
             $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) {
             $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;
                     }
                 }
             }
         }
     }
     return $string_translations;
 }
 public function get_words_counts()
 {
     return $this->wpdb->get_results();
 }