function tfwpml_add_where_for_seek($current_string)
{
    $lang = substr(get_locale(), 0, 2);
    $post_type = TF_SEEK_HELPER::get_post_type();
    $where = "AND p.ID = ilc_trans.element_id AND ilc_trans.element_type = 'post_" . $post_type . "' AND ilc_trans.language_code = '" . $lang . "' ";
    return $current_string . $where;
}
 function action_tf_import_end($args)
 {
     global $wpdb;
     if (!$this->sql_imported) {
         // Cancel if sql was not importerd, because it contains old data, and double import is not correct
         return;
     }
     if (!sizeof($wpdb->get_results($wpdb->prepare("SHOW TABLES LIKE %s", TF_SEEK_HELPER::get_db_table_name())))) {
         return;
     }
     $table_structure = NULL;
     $results = $wpdb->get_results("SELECT * FROM " . TF_SEEK_HELPER::get_db_table_name() . "");
     if (sizeof($results)) {
         $sql_values = array();
         foreach ($results as $result) {
             if (is_null($table_structure)) {
                 $table_structure = array_keys(get_object_vars($result));
             }
             if (isset($args['processed_posts'][intval($result->post_id)])) {
                 $result->post_id = $args['processed_posts'][intval($result->post_id)];
             } else {
                 // do not include not processed posts, because their ids can conflict with processed
                 continue;
             }
             $result->_terms = explode($this->seek->index_table_terms_separator, trim($result->_terms, $this->seek->index_table_terms_separator));
             $new_terms = array();
             if (sizeof($result->_terms)) {
                 foreach ($result->_terms as $term) {
                     $term = intval($term);
                     if ($term < 1) {
                         continue;
                     }
                     $new_terms[(isset($args['processed_terms'][$term]) ? $args['processed_terms'][$term] : $term) . $this->seek->index_table_terms_separator] = '~';
                 }
             }
             $result->_terms = implode('', array_keys($new_terms));
             $sql = array();
             foreach ($result as $key => $val) {
                 $sql[] = $wpdb->prepare('%s', $val);
             }
             $sql = '(' . implode(', ', $sql) . ')';
             $sql_values[] = $sql;
         }
         unset($results);
         $sql = "INSERT INTO " . TF_SEEK_HELPER::get_db_table_name() . " (" . implode(', ', $table_structure) . ")" . " VALUES " . implode(', ', $sql_values);
         $wpdb->query("TRUNCATE TABLE " . TF_SEEK_HELPER::get_db_table_name());
         $wpdb->query($sql);
     }
 }
 public function do_search($params = array())
 {
     global $wpdb;
     $params = array_merge(array('return_type' => ARRAY_A, 'posts_per_page' => 10, 'debug' => false, 'orderby_options' => array('latest' => array('sql' => 'p.post_date DESC'))), $params);
     if ($this->request->empty_GET(TF_SEEK_HELPER::get_search_parameter('page'))) {
         $curr_page = 1;
     } else {
         $curr_page = (int) $this->request->GET(TF_SEEK_HELPER::get_search_parameter('page'));
         if ($curr_page < 1) {
             $curr_page = 1;
         }
     }
     $forms_options = $this->get->ext_options($this->_the_class_name, 'forms');
     $form_id = $this->request->GET($this->get_search_parameter('form_id'));
     if (!isset($forms_options[$form_id])) {
         $form_id = '';
         $built_where = array('sql' => '');
         $form_id = NULL;
     } else {
         $built_where = $this->build_form_search_where_sql($form_id);
     }
     $where_sql = trim($built_where['sql']);
     $where = $where_sql ? " AND " . $where_sql : "";
     // Build ORDER BY
     $order_by_sql = '';
     //
     $order_by_key = TF_SEEK_HELPER::get_input_value(TF_SEEK_HELPER::get_search_parameter('orderby'), '');
     if (isset($params['orderby_options'][$order_by_key])) {
         $order_by_sql = $params['orderby_options'][$order_by_key]['sql'];
     } elseif (sizeof($params['orderby_options'])) {
         $first_value = reset($params['orderby_options']);
         $order_by_sql = $first_value['sql'];
     }
     if ($order_by_sql) {
         $order_by_sql = ' ORDER BY ' . $order_by_sql . ' ';
     }
     // ^end Buld ORDER BY
     //ini_set("mysql.trace_mode", "0"); // for FOUND_ROWS() to work
     $sql = 'SELECT
         SQL_CALC_FOUND_ROWS *
             ' . $this->get_search_sql() . '
             ' . $where . '
         GROUP BY p.ID
         ' . $order_by_sql . '
         LIMIT ' . ($curr_page - 1) * $params['posts_per_page'] . ',' . $params['posts_per_page'];
     $sql = apply_filters('tf_filter_seek_search_sql', $sql, $params, $form_id);
     if ($params['debug']) {
         tf_print($sql);
     }
     $rows = $wpdb->get_results($sql, $params['return_type']);
     $tmp = $wpdb->get_row('SELECT FOUND_ROWS() as total_rows', ARRAY_A);
     $total = reset($tmp);
     $max_pages = intval($total / $params['posts_per_page']);
     if ($total % $params['posts_per_page']) {
         $max_pages++;
     }
     if ($curr_page > 1 && !($rows_on_page = count($rows))) {
         $curr_page = $max_pages;
     }
     $ret = array('rows' => $rows, 'total' => $total, 'curr_page' => $curr_page, 'max_pages' => $max_pages);
     do_action('tf_ext_seek_do_search');
     return $ret;
 }