Ejemplo n.º 1
0
function ajaxsearchlite_search()
{
    global $wpdb;
    global $search;
    /*print "in ajaxsearchlite_search();";
      print_r(array()); return;  */
    $s = $_POST['aslp'];
    $s = apply_filters('asl_search_phrase_before_cleaning', $s);
    $s = stripcslashes($s);
    $s = trim($s);
    $s = preg_replace('/\\s+/', ' ', $s);
    $s = apply_filters('asl_search_phrase_after_cleaning', $s);
    $def_data = get_option('asl_defaults');
    $search = array();
    $search['data'] = get_option('asl_options');
    $search['data'] = array_merge($def_data, $search['data']);
    $search['data']['image_options'] = array('show_images' => $search['data']['show_images'], 'image_bg_color' => '#FFFFFF', 'image_transparency' => 1, 'image_crop_location' => w_isset_def($search['data']['image_crop_location'], "c"), 'image_width' => $search['data']['image_width'], 'image_height' => $search['data']['image_height'], 'image_source1' => $search['data']['image_source1'], 'image_source2' => $search['data']['image_source2'], 'image_source3' => $search['data']['image_source3'], 'image_source4' => $search['data']['image_source4'], 'image_source5' => $search['data']['image_source5'], 'image_default' => $search['data']['image_default'], 'image_custom_field' => $search['data']['image_custom_field']);
    // ----------------- Recalculate image width/height ---------------
    switch ($search['data']['resultstype']) {
        case "horizontal":
            /* Same width as height */
            $search['data']['image_options']['image_width'] = wpdreams_width_from_px($search['data']['image_options']['hreswidth']);
            $search['data']['image_options']['image_height'] = wpdreams_width_from_px($search['data']['image_options']['hreswidth']);
            break;
        case "polaroid":
            $search['data']['image_options']['image_width'] = intval($search['data']['preswidth']);
            $search['data']['image_options']['image_height'] = intval($search['data']['preswidth']);
            break;
        case "isotopic":
            $search['data']['image_options']['image_width'] = intval($search['data']['i_item_width'] * 1.5);
            $search['data']['image_options']['image_height'] = intval($search['data']['i_item_height'] * 1.5);
            break;
    }
    if (isset($search['data']['selected-imagesettings'])) {
        $search['data']['settings-imagesettings'] = $search['data']['selected-imagesettings'];
    }
    /*if (isset($search) && $search['data']['exactonly']!=1) {
        $_s = explode(" ", $s);
      }*/
    if (isset($_POST['options'])) {
        parse_str($_POST['options'], $search['options']);
    }
    $blogresults = array();
    $allpageposts = array();
    $pageposts = array();
    do_action('asl_before_search', $s);
    $params = array('data' => $search['data'], 'options' => $search['options']);
    $_posts = new wpdreams_searchContent($params);
    $pageposts = $_posts->search($s);
    $allpageposts = array_merge($allpageposts, $pageposts);
    do_action('asl_after_pagepost_results', $s, $pageposts);
    $allpageposts = apply_filters('asl_pagepost_results', $allpageposts);
    $results = array_merge($allpageposts);
    // Keyword suggestions
    if (count($results) <= 0 && w_isset_def($search['data']['kw_suggestions'], 1) == 1) {
        $keywords = array();
        $types = array();
        $sd = $search['data'];
        if ($sd['searchinposts'] == 1) {
            $types[] = "post";
        }
        if ($sd['searchinpages'] == 1) {
            $types[] = "page";
        }
        if (isset($sd['selected-customtypes']) && count($sd['selected-customtypes']) > 0) {
            $types = array_merge($types, $sd['selected-customtypes']);
        }
        $t = new wpd_keywordSuggest("google", array('maxCount' => w_isset_def($sd['kw_count'], 10), 'maxCharsPerWord' => w_isset_def($sd['kw_length'], 60), 'postTypes' => $types, 'lang' => w_isset_def($sd['kw_google_lang'], "en"), 'overrideUrl' => ''));
        $keywords = $t->getKeywords($s);
        if ($keywords != false) {
            $results['keywords'] = $keywords;
            $results['nores'] = 1;
            $results = apply_filters('asl_only_keyword_results', $results);
        }
    } else {
        if (count($results > 0)) {
            $results = apply_filters('asl_only_non_keyword_results', $results);
        }
    }
    $results = apply_filters('asl_results', $results);
    do_action('asl_after_search', $s, $results);
    // Generate the results here
    $html_results = asl_generate_html_results($results, $search['data']);
    /* Clear output buffer, possible warnings */
    print "!!ASLSTART!!";
    //var_dump($results);die();
    print_r($html_results);
    print "!!ASLEND!!";
    die;
}
Ejemplo n.º 2
0
function ajaxsearchpro_search()
{
    global $wpdb;
    global $switched;
    global $search;
    /*print "in ajaxsearchpro_search();";
      print_r(array()); return;  */
    $s = $_POST['aspp'];
    $s = apply_filters('asp_search_phrase_before_cleaning', $s);
    $s = strtolower(trim($s));
    $s = preg_replace('/\\s+/', ' ', $s);
    $s = apply_filters('asp_search_phrase_after_cleaning', $s);
    $stat = get_option("asp_stat");
    if (isset($wpdb->base_prefix)) {
        $_prefix = $wpdb->base_prefix;
    } else {
        $_prefix = $wpdb->prefix;
    }
    if ($stat == 1) {
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        $in = $wpdb->query("UPDATE " . $_prefix . "ajaxsearchpro_statistics SET num=num+1, last_date=" . time() . " WHERE (keyword='" . $s . "' AND search_id=" . $_POST['asid'] . ")");
        if ($in == false) {
            dbDelta("INSERT INTO " . $_prefix . "ajaxsearchpro_statistics (search_id, keyword, num, last_date) VALUES (" . $_POST['asid'] . ", '" . $s . "', 1, " . time() . ")");
        }
    }
    $search = $wpdb->get_row("SELECT * FROM " . $_prefix . "ajaxsearchpro WHERE id=" . $_POST['asid'], ARRAY_A);
    $search['data'] = json_decode($search['data'], true);
    if (isset($search['data']['selected-imagesettings'])) {
        $search['data']['settings-imagesettings'] = $search['data']['selected-imagesettings'];
    }
    /*if (isset($search) && $search['data']['exactonly']!=1) {
        $_s = explode(" ", $s);
      }*/
    if (isset($_POST['options'])) {
        parse_str($_POST['options'], $search['options']);
    }
    //Advanced title and description fields
    add_filter('asp_result_title_after_prostproc', 'adv_title', 1, 2);
    add_filter('asp_result_content_after_prostproc', 'adv_desc', 1, 2);
    function adv_title($title, $id)
    {
        global $search;
        $titlefield = $search['data']['advtitlefield'];
        if ($titlefield == '') {
            return $title;
        }
        preg_match_all("/{(.*?)}/", $titlefield, $matches);
        if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
            foreach ($matches[1] as $field) {
                if ($field == 'titlefield') {
                    $titlefield = str_replace('{titlefield}', $title, $titlefield);
                } else {
                    $val = get_post_meta($id, $field, true);
                    $titlefield = str_replace('{' . $field . '}', $val, $titlefield);
                }
            }
        }
        return $titlefield;
    }
    function adv_desc($desc, $id)
    {
        global $search;
        $descfield = $search['data']['advdescriptionfield'];
        if ($descfield == '') {
            return $desc;
        }
        preg_match_all("/{(.*?)}/", $descfield, $matches);
        if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
            foreach ($matches[1] as $field) {
                if ($field == 'descriptionfield') {
                    $descfield = str_replace('{descriptionfield}', $desc, $descfield);
                } else {
                    $val = get_post_meta($id, $field, true);
                    $descfield = str_replace('{' . $field . '}', $val, $descfield);
                }
            }
        }
        return $descfield;
    }
    $blogresults = array();
    $allbuddypresults = array('repliesresults' => array(), 'groupresults' => array(), 'userresults' => array());
    $allpageposts = array();
    $pageposts = array();
    $repliesresults = array();
    $allcommentsresults = array();
    $commentsresults = array();
    if (!isset($search['data']['selected-blogs']) || $search['data']['selected-blogs'] == null || count($search['data']['selected-blogs']) <= 0) {
        $search['data']['selected-blogs'] = array(0 => 1);
    }
    do_action('asp_before_search', $s);
    if (get_option('asp_caching') && AJAXSEARCHPRO_DEBUG != 1) {
        $filename = AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR . md5(json_encode($options) . $s) . ".wp";
        $textcache = new wpdreamsTextCache($filename, get_option('asp_cachinginterval') * 60);
        $cache_content = $textcache->getCache();
        if ($cache_content != false) {
            $cache_content = apply_filters('asp_cached_content_json', $cache_content);
            do_action('asp_after_search', $s, json_decode($cache_content, true));
            print_r($cache_content);
            die;
        }
    }
    foreach ($search['data']['selected-blogs'] as $blog) {
        if (is_multisite()) {
            switch_to_blog($blog);
        }
        if ($_POST['asid'] == "") {
            $_dposts = new wpdreams_searchDemo(array());
            $dpageposts = $_dposts->search($s);
            $allpageposts = array_merge($allpageposts, $dpageposts);
        } else {
            $params = array('data' => $search['data'], 'options' => $search['options']);
            if (get_option('asp_dbusefulltext') && get_option('asp_fulltext') == 1) {
                $_posts = new wpdreams_searchContentFulltext($params);
            } else {
                $_posts = new wpdreams_searchContent($params);
            }
            $pageposts = $_posts->search($s);
            $allpageposts = array_merge($allpageposts, $pageposts);
            do_action('asp_after_pagepost_results', $s, $pageposts);
            $_comments = new wpdreams_searchComments($params);
            $commentsresults = $_comments->search($s);
            $allcommentsresults = array_merge($allcommentsresults, $commentsresults);
            do_action('asp_after_comments_results', $s, $commentsresults);
            $_buddyp = new wpdreams_searchBuddyPress($params);
            $buddypresults = $_buddyp->search($s);
            // !!! returns array for each result (group, user, reply) !!!
            foreach ($buddypresults as $k => $v) {
                $allbuddypresults[$k] = array_merge($allbuddypresults[$k], $v);
            }
            do_action('asp_after_buddypress_results', $s, $buddypresults);
        }
    }
    if (is_multisite()) {
        restore_current_blog();
    }
    $_blogs = new wpdreams_searchBlogs($params);
    $blogresults = $_blogs->search($s);
    $allpageposts = apply_filters('asp_pagepost_results', $allpageposts);
    $allcommentsresults = apply_filters('asp_comment_results', $allcommentsresults);
    $buddypresults = apply_filters('asp_buddyp_results', $buddypresults);
    $blogresults = apply_filters('asp_blog_results', $blogresults);
    /* Remove the results in polaroid mode */
    if ($search['data']['resultstype'] == 'polaroid' && $search['data']['pifnoimage'] == 'removeres') {
        foreach ($allpageposts as $_k => $_v) {
            if ($_v->image == null || $_v->image == '') {
                unset($allpageposts[$_k]);
            }
        }
        foreach ($allcommentsresults as $_k => $_v) {
            if ($_v->image == null || $_v->image == '') {
                unset($allcommentsresults[$_k]);
            }
        }
        foreach ($buddypresults as $_k => $_v) {
            if ($_v->image == null || $_v->image == '') {
                unset($buddypresults[$_k]);
            }
        }
        foreach ($blogresults as $_k => $_v) {
            if ($_v->image == null || $_v->image == '') {
                unset($blogresults[$_k]);
            }
        }
    }
    // Grouping again
    if ($search['data']['resultstype'] == 'vertical' && ($search['data']['groupby'] == 1 || $search['data']['groupby'] == 2)) {
        $results = $allpageposts;
        if (!isset($results['items']) && count($allpageposts) > 0) {
            $results['items'] = array();
            $results['grouped'] = 1;
        }
        if (count($blogresults) > 0) {
            if ($search['data']['showpostnumber'] == 1) {
                $num = " (" . count($blogresults) . ")";
            } else {
                $num = "";
            }
            $results['items'][90000] = array();
            $results['items'][90000]['name'] = $search['data']['blogresultstext'] . $num;
            $results['items'][90000]['data'] = $blogresults;
            $results['grouped'] = 1;
        }
        $repliesresults = $allbuddypresults['repliesresults'];
        if (count($repliesresults) > 0) {
            if ($search['data']['showpostnumber'] == 1) {
                $num = " (" . count($repliesresults) . ")";
            } else {
                $num = "";
            }
            $results['items'][90001] = array();
            $results['items'][90001]['name'] = $search['data']['bbpressreplytext'] . $num;
            $results['items'][90001]['data'] = $repliesresults;
            $results['grouped'] = 1;
        }
        if (count($allcommentsresults) > 0) {
            if ($search['data']['showpostnumber'] == 1) {
                $num = " (" . count($allcommentsresults) . ")";
            } else {
                $num = "";
            }
            $results['items'][90002] = array();
            $results['items'][90002]['name'] = $search['data']['commentstext'] . $num;
            $results['items'][90002]['data'] = $allcommentsresults;
            $results['grouped'] = 1;
        }
        $groupresults = $allbuddypresults['groupresults'];
        if (count($groupresults) > 0) {
            if ($search['data']['showpostnumber'] == 1) {
                $num = " (" . count($groupresults) . ")";
            } else {
                $num = "";
            }
            $results['items'][90003] = array();
            $results['items'][90003]['name'] = $search['data']['bbpressgroupstext'] . $num;
            $results['items'][90003]['data'] = $groupresults;
            $results['grouped'] = 1;
        }
        $userresults = $allbuddypresults['userresults'];
        if (count($userresults) > 0) {
            if ($search['data']['showpostnumber'] == 1) {
                $num = " (" . count($userresults) . ")";
            } else {
                $num = "";
            }
            $results['items'][90004] = array();
            $results['items'][90004]['name'] = $search['data']['bbpressuserstext'] . $num;
            $results['items'][90004]['data'] = $userresults;
            $results['grouped'] = 1;
        }
    } else {
        $results = array_merge($blogresults, $allbuddypresults['repliesresults'], $allcommentsresults, $allbuddypresults['groupresults'], $allbuddypresults['userresults'], $allpageposts);
    }
    if (count($results) <= 0 && $search['data']['keywordsuggestions']) {
        $t = new keywordSuggest($search['data']['keywordsuggestionslang']);
        $keywords = $t->getKeywords($s);
        if ($keywords != false) {
            $results['keywords'] = $keywords;
            $results['nores'] = 1;
            $results = apply_filters('asp_only_keyword_results', $results);
        }
    } else {
        if (count($results > 0)) {
            $results = apply_filters('asp_only_non_keyword_results', $results);
        }
    }
    $results = apply_filters('asp_results', $results);
    do_action('asp_after_search', $s, $results);
    if (get_option('asp_caching') && AJAXSEARCHPRO_DEBUG != 1) {
        $cache_content = $textcache->setCache('!!ASPSTART!!' . json_encode($results) . "!!ASPEND!!");
    }
    /* Clear output buffer, possible warnings */
    print "!!ASPSTART!!";
    //var_dump($results);die();
    print_r(json_encode($results));
    print "!!ASPEND!!";
    die;
}