コード例 #1
0
ファイル: search.php プロジェクト: Aqro/NewDWM
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;
}
コード例 #2
0
ファイル: search.php プロジェクト: booklein/wpbookle
function ajaxsearchpro_autocomplete()
{
    global $wpdb;
    $s = trim($_POST['sauto']);
    $s = preg_replace('/\\s+/', ' ', $s);
    do_action('asp_before_autocomplete', $s);
    if (!isset($_POST['asid'])) {
        return "";
    }
    // Set the prefix for multisites
    if (isset($wpdb->base_prefix)) {
        $_prefix = $wpdb->base_prefix;
    } else {
        $_prefix = $wpdb->prefix;
    }
    // Forcing numeric value
    $_POST['asid'] = $_POST['asid'] + 0;
    $search = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $_prefix . "ajaxsearchpro WHERE id=%d", $_POST['asid']), ARRAY_A);
    if (!isset($search['data'])) {
        return;
    }
    $sd = json_decode($search['data'], true);
    $keyword = '';
    $types = array();
    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']);
    }
    foreach (w_isset_def($sd['selected-autocomplete_source'], array('google')) as $source) {
        $taxonomy = "";
        // Check if this is a taxonomy
        if (strpos($source, 'xtax_') !== false) {
            $taxonomy = str_replace('xtax_', '', $source);
            $source = "terms";
        }
        $t = new wpd_keywordSuggest($source, array('maxCount' => 10, 'maxCharsPerWord' => w_isset_def($sd['autocomplete_length'], 60), 'postTypes' => $types, 'lang' => $sd['keywordsuggestionslang'], 'overrideUrl' => '', 'taxonomy' => $taxonomy, 'match_start' => true));
        $res = $t->getKeywords($s);
        if (isset($res[0]) && ($keyword = $res[0])) {
            break;
        }
    }
    do_action('asp_after_autocomplete', $s, $keyword);
    print $keyword;
    die;
}