Example #1
0
function ajaxsearchpro_deactivate_fulltext()
{
    global $wpdb;
    $fulltext = wpdreamsFulltext::getInstance();
    $indexes = array('posts' => array('asp_title', 'asp_content', 'asp_excerpt', 'asp_title_content', 'asp_title_excerpt', 'asp_content_excerpt', 'asp_title_content_excerpt'));
    $blogs = wpdreams_get_blog_list(0, 'all');
    if (is_multisite() && is_array($blogs) && count($blogs)) {
        foreach ($blogs as $k => $blog) {
            switch_to_blog($blog['blog_id']);
            $fulltext->removeIndexes($indexes);
        }
        restore_current_blog();
    } else {
        $fulltext->removeIndexes($indexes);
    }
    update_option('asp_fulltext_indexed', 0);
    print "<div class='psuccessMsg'>Indexes removed!</div>";
    die;
}
Example #2
0
 /**
  *  Checks if fulltext is available
  */
 function fulltext()
 {
     global $wpdb;
     $fulltext = wpdreamsFulltext::getInstance();
     $tables = array('posts');
     $blogs = wpdreams_get_blog_list(0, 'all');
     update_option('asp_fulltext', $fulltext->isFulltextAvailable());
     update_option('asp_fulltext_indexed', 0);
 }
 /**
  * The search function
  *
  * @return array|string
  */
 protected function do_search()
 {
     global $wpdb;
     global $q_config;
     $options = $this->options;
     $searchData = $this->searchData;
     $parts = array();
     $relevance_parts = array();
     $types = array();
     $post_types = "";
     $s = $this->s;
     // full keyword
     $_s = $this->_s;
     // array of keywords
     $_si = implode('|', $_s);
     // imploded phrase for regexp
     $_si = $_si != '' ? $_si : $s;
     //$kw_logic = w_isset_def($searchData['keyword_logic'], 'or');
     $q_config['language'] = $options['qtranslate_lang'];
     if (isset($wpdb->base_prefix)) {
         $_prefix = $wpdb->base_prefix;
     } else {
         $_prefix = $wpdb->prefix;
     }
     /*------------------------- Statuses ----------------------------*/
     $statuses = array('publish');
     if ($searchData['searchinpending']) {
         $statuses[] = 'pending';
     }
     if ($searchData['searchindrafts']) {
         $statuses[] = 'draft';
     }
     $words = implode('|', $statuses);
     $post_statuses = "(lower({$wpdb->posts}.post_status) REGEXP '{$words}')";
     /*---------------------------------------------------------------*/
     /*----------------------- Gather Types --------------------------*/
     if ($options['set_inposts'] == 1) {
         $types[] = "post";
     }
     if ($options['set_inpages']) {
         $types[] = "page";
     }
     if (isset($options['customset']) && count($options['customset']) > 0) {
         $types = array_merge($types, $options['customset']);
     }
     if (count($types) < 1) {
         return '';
     } else {
         $words = implode('[[:>:]]|[[:<:]]', $types);
         $post_types = "({$wpdb->posts}.post_type REGEXP '[[:<:]]" . $words . "[[:>:]]')";
     }
     /*---------------------------------------------------------------*/
     $is_too_short = false;
     $not_exact_phrase = '';
     $fulltext = wpdreamsFulltext::getInstance();
     foreach ($_s as $_pp) {
         if (strlen($_pp) < $fulltext->getMinWordLength() || !$options['set_exactonly']) {
             $is_too_short = true;
             $not_exact_phrase .= " *" . $_pp . "*";
         } else {
             $not_exact_phrase .= " " . $_pp;
         }
     }
     $not_exact_phrase = trim($not_exact_phrase);
     $exact_phrase = '"' . $s . '"';
     $ful_options = get_option('asp_fulltexto');
     if (w_isset_def($ful_options['dbuseregularwhenshort'], 0) && $is_too_short) {
         return parent::do_search();
     }
     /**
      * Construct the INDEX name to search
      */
     $match_against = '1';
     $relevance = '';
     $fixed_phrase = $options['set_exactonly'] ? $exact_phrase : $not_exact_phrase;
     $boolean_mode = get_option('asp_fulltext_indexed') == 0 || $is_too_short || !$options['set_exactonly'] ? ' IN BOOLEAN MODE' : '';
     $index_name = $options['set_intitle'] ? "{$wpdb->posts}.post_title" : '';
     if ($index_name == '') {
         $index_name .= $options['set_incontent'] ? "{$wpdb->posts}.post_content" : '';
     } else {
         $index_name .= $options['set_incontent'] ? ", {$wpdb->posts}.post_content" : '';
     }
     if ($index_name == '') {
         $index_name .= $options['set_inexcerpt'] ? "{$wpdb->posts}.post_excerpt" : '';
     } else {
         $index_name .= $options['set_inexcerpt'] ? ", {$wpdb->posts}.post_excerpt" : '';
     }
     if ($index_name != '') {
         $match_against = " MATCH(" . $index_name . ") AGAINST ('" . $fixed_phrase . "'" . $boolean_mode . ") ";
     }
     if ($match_against != '1') {
         $relevance = "\r\n          (\r\n           MATCH(" . $index_name . ") AGAINST ('" . $exact_phrase . "'" . $boolean_mode . ") +\r\n           MATCH(" . $index_name . ") AGAINST ('" . $not_exact_phrase . "'" . $boolean_mode . ")\r\n           )\r\n        ";
     }
     // ------------------------ Categories/taxonomies ----------------------
     if (!isset($options['categoryset']) || $options['categoryset'] == "") {
         $options['categoryset'] = array();
     }
     if (!isset($options['termset']) || $options['termset'] == "") {
         $options['termset'] = array();
     }
     $exclude_categories = array();
     $searchData['selected-exsearchincategories'] = w_isset_def($searchData['selected-exsearchincategories'], array());
     $searchData['selected-excludecategories'] = w_isset_def($searchData['selected-excludecategories'], array());
     $_all_cat = get_terms('category', array('fields' => 'ids'));
     $_needed_cat = array_diff($_all_cat, $searchData['selected-exsearchincategories']);
     $_needed_cat = !is_array($_needed_cat) ? array() : $_needed_cat;
     $exclude_categories = array_diff(array_merge($_needed_cat, $searchData['selected-excludecategories']), $options['categoryset']);
     $exclude_terms = array();
     $exclude_showterms = array();
     $searchData['selected-showterms'] = w_isset_def($searchData['selected-showterms'], array());
     $searchData['selected-excludeterms'] = w_isset_def($searchData['selected-excludeterms'], array());
     foreach ($searchData['selected-excludeterms'] as $tax => $terms) {
         $exclude_terms = array_merge($exclude_terms, $terms);
     }
     foreach ($searchData['selected-showterms'] as $tax => $terms) {
         $exclude_showterms = array_merge($exclude_showterms, $terms);
     }
     $exclude_terms = array_diff(array_merge($exclude_terms, $exclude_showterms), $options['termset']);
     $all_terms = array();
     $all_terms = array_merge($exclude_categories, $exclude_terms);
     if (count($all_terms) > 0) {
         $words = '--' . implode('--|--', $all_terms) . '--';
         $term_query = "HAVING (ttid NOT REGEXP '{$words}')";
     }
     // ---------------------------------------------------------------------
     /*------------- Custom Fields with Custom selectors -------------*/
     if (isset($options['aspf']) && isset($options['aspfdata'])) {
         $parts = array();
         foreach ($options['aspfdata'] as $u_data) {
             $data = json_decode(base64_decode($u_data));
             $posted = $options['aspf'][$data->asp_f_field];
             $ll_like = "";
             $rr_like = "";
             $operator = "=";
             if (isset($data->asp_f_operator)) {
                 switch ($data->asp_f_operator) {
                     case 'eq':
                         $operator = "=";
                         break;
                     case 'neq':
                         $operator = "<>";
                         break;
                     case 'lt':
                         $operator = "<";
                         break;
                     case 'gt':
                         $operator = ">";
                         break;
                     case 'elike':
                         $operator = "=";
                         $ll_like = "'";
                         $rr_like = "'";
                         break;
                     case 'like':
                         $operator = "LIKE";
                         $ll_like = "'%";
                         $rr_like = "%'";
                         break;
                     default:
                         $operator = "=";
                         break;
                 }
             }
             //var_dump($data);
             /*if (w_isset_def($searchData['cf_null_values'], 1) == 1) {
                   $cf_key_is_null .= " OR $wpdb->postmeta.meta_key IS NULL";
                   $cf_val_is_null .= " OR $wpdb->postmeta.meta_value IS NULL";
               }*/
             if ($data->asp_f_type == 'range' && isset($posted['lower'])) {
                 $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n                                     ({$wpdb->postmeta}.meta_value BETWEEN " . $posted['lower'] . " AND " . $posted['upper'] . " ) )";
             } else {
                 if ($data->asp_f_type == 'slider' && isset($posted)) {
                     $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n                                     ({$wpdb->postmeta}.meta_value {$operator} {$posted}  ) )";
                 } else {
                     if ($data->asp_f_type == 'radio' && isset($posted)) {
                         $parts[] = " ( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n                                     ({$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $posted . $rr_like . " ) )";
                     } else {
                         if ($data->asp_f_type == 'dropdown' && isset($posted)) {
                             if (isset($data->asp_f_dropdown_multi) && count($posted) > 0) {
                                 // The AND logic doesn't make any sense
                                 $logic = 'OR';
                                 $values = '';
                                 foreach ($posted as $v) {
                                     if ($values != '') {
                                         $values .= " {$logic} {$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like;
                                     } else {
                                         $values .= "{$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like;
                                     }
                                 }
                                 $values = $values == '' ? '0' : $values;
                                 $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND ({$values}) )";
                             } else {
                                 $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND\r\n                                        ({$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $posted . $rr_like . " ) )";
                             }
                         } else {
                             if ($data->asp_f_type == 'checkboxes' && isset($posted)) {
                                 $logic = $data->asp_f_checkboxes_logic;
                                 $values = '';
                                 foreach ($posted as $v => $vv) {
                                     if ($values != '') {
                                         $values .= " {$logic} {$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like;
                                     } else {
                                         $values .= "{$wpdb->postmeta}.meta_value {$operator} " . $ll_like . $v . $rr_like;
                                     }
                                 }
                                 $values = $values == '' ? '0' : $values;
                                 $parts[] = "( ({$wpdb->postmeta}.meta_key='{$data->asp_f_field}') AND ({$values}) )";
                             }
                         }
                     }
                 }
             }
         }
         $this->cf_parts = $parts;
     }
     $meta_count = count($this->cf_parts);
     $cf_query = implode(" OR ", $this->cf_parts);
     if ($cf_query == "") {
         $cf_select = "0";
         $cf_having = "";
     } else {
         $cf_select = "\r\n                SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE\r\n                    {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\r\n                AND\r\n                    ({$cf_query})";
         if (w_isset_def($searchData['cf_logic'], 'AND') == 'AND') {
             $cf_having = "meta_matches >= " . $meta_count;
         } else {
             $cf_having = "meta_matches >= 1";
         }
         if ($term_query != '') {
             $cf_having = " AND " . $cf_having;
         } else {
             $cf_having = "HAVING " . $cf_having;
         }
     }
     /*---------------------------------------------------------------*/
     /*---------------------- Custom Fields --------------------------*/
     if (isset($searchData['selected-customfields'])) {
         $selected_customfields = $searchData['selected-customfields'];
         if (is_array($selected_customfields) && count($selected_customfields) > 0) {
             $words = $options['set_exactonly'] == 1 ? $s : $_si;
             foreach ($selected_customfields as $cfield) {
                 $parts[] = "({$wpdb->postmeta}.meta_key='{$cfield}' AND\r\n                                   lower({$wpdb->postmeta}.meta_value) REGEXP '{$words}')";
             }
         }
     }
     /*---------------------------------------------------------------*/
     /*------------------------ Exclude id's -------------------------*/
     if (isset($searchData['excludeposts']) && $searchData['excludeposts'] != "") {
         $exclude_posts = "{$wpdb->posts}.ID NOT IN (" . $searchData['excludeposts'] . ")";
     } else {
         $exclude_posts = "{$wpdb->posts}.ID NOT IN (-55)";
     }
     /*---------------------------------------------------------------*/
     /*------------------------- Build like --------------------------*/
     $like_query = implode(' OR ', $parts);
     if ($like_query == "") {
         $like_query = "(0)";
     } else {
         $like_query = "({$like_query})";
     }
     /*---------------------------------------------------------------*/
     /*------------------------- WPML filter -------------------------*/
     $wpml_join = "";
     if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE != '' && w_isset_def($searchData['wpml_compatibility'], 1) == 1) {
         $wpml_join = "RIGHT JOIN " . $wpdb->base_prefix . "icl_translations ON ({$wpdb->posts}.ID = " . $wpdb->base_prefix . "icl_translations.element_id AND " . $wpdb->base_prefix . "icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "')";
     }
     /*---------------------------------------------------------------*/
     $orderby = isset($searchData['selected-orderby']) && $searchData['selected-orderby'] != '' ? $searchData['selected-orderby'] : "post_date DESC";
     $querystr = "\r\n    \t\tSELECT \r\n          {$wpdb->posts}.post_title as title,\r\n          {$wpdb->posts}.ID as id,\r\n          {$wpdb->posts}.post_date as date,               \r\n          {$wpdb->posts}.post_content as content,\r\n          {$wpdb->posts}.post_excerpt as excerpt,\r\n          {$wpdb->users}.user_nicename as author,\r\n          'pagepost' as content_type,\r\n          {$wpdb->posts}.post_type as post_type,\r\n          ({$cf_select}) as meta_matches,\r\n            CASE WHEN " . $_prefix . "ajaxsearchpro_priorities.priority IS NULL\r\n                   THEN 100\r\n                   ELSE " . $_prefix . "ajaxsearchpro_priorities.priority\r\n            END AS priority,\r\n          CONCAT('--', GROUP_CONCAT(DISTINCT {$wpdb->terms}.term_id SEPARATOR '----'), '--') as ttid,\r\n          {$wpdb->posts}.post_type as post_type,";
     if ($searchData['userelevance'] == 1 && $relevance != '') {
         $querystr .= $relevance;
     } else {
         $querystr .= "1 ";
     }
     $querystr .= "\r\n          as relevance\r\n    \t\tFROM {$wpdb->posts}\r\n        LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\r\n        LEFT JOIN " . $_prefix . "ajaxsearchpro_priorities ON (" . $_prefix . "ajaxsearchpro_priorities.post_id = {$wpdb->posts}.ID AND " . $_prefix . "ajaxsearchpro_priorities.blog_id = " . get_current_blog_id() . ")\r\n        LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = {$wpdb->posts}.post_author\r\n        LEFT JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id\r\n        LEFT JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id\r\n        LEFT JOIN {$wpdb->terms} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id\r\n        {$wpml_join}\r\n    \t\tWHERE\r\n            {$post_types}\r\n        AND {$post_statuses}\r\n        AND (" . $match_against . " OR (" . $like_query . "))\r\n        AND (" . $exclude_posts . ")\r\n        GROUP BY\r\n          {$wpdb->posts}.ID\r\n          {$term_query}\r\n          {$cf_having}\r\n         ";
     $querystr .= " ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "\r\n        LIMIT " . $searchData['maxresults'];
     $pageposts = $wpdb->get_results($querystr, OBJECT);
     //var_dump($querystr); var_dump($pageposts);die("!!");
     $this->results = $pageposts;
     return $pageposts;
 }
<?php

/* Prevent direct access */
defined('ABSPATH') or die("You can't access this file directly.");
$com_options = get_option('asp_compatibility');
$ful_options = get_option('asp_fulltexto');
$fulltext = wpdreamsFulltext::getInstance();
/**
 * @deprecated since 4.5
 * $fulltext_enabled = $fulltext->check(array('posts'));
 * $fulltext_indexed = $fulltext->indexExists('posts', 'asp_title');
 */
$fulltext_enabled = false;
$fulltext_indexed = false;
if (ASP_DEMO) {
    $_POST = null;
}
?>

<div id="wpdreams" class='wpdreams wrap'>
    <div class="wpdreams-box">

        <?php 
ob_start();
?>

        <div tabid="1">
            <fieldset>
                <legend>CSS and JS compatibility</legend>

                <?php