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; }
} echo $asp_res_ids; ?> .results .item .asp_image { width: <?php echo $style['image_width']; ?> px; height: <?php echo $style['image_height']; ?> px; } <?php $_vimagew = wpdreams_width_from_px($style['hreswidth']); $_vimageratio = $_vimagew / $style['image_width']; $_vimageh = $_vimageratio * $style['image_height']; ?> <?php if ($use_compatibility == true) { ?> <?php echo $asp_res_ids1; ?> .results .item .asp_content, <?php echo $asp_res_ids2; ?> .results .item .asp_content,
; } #ajaxsearchprores<?php echo $id; ?> .photostack-img { outline: none; display: block; width: <?php echo wpdreams_width_from_px($style['preswidth']) - 2 * wpdreams_width_from_px($style['prespadding']); ?> px; height: <?php echo wpdreams_width_from_px($style['preswidth']) - 2 * wpdreams_width_from_px($style['prespadding']); ?> px; background: #f9f9f9; <?php echo $style['pressubtitlefont']; ?> ; } #ajaxsearchprores<?php echo $id; ?> .photostack-back { display: none; position: absolute;
function ajaxsearchpro_search($forceMulti = false, $dontGroup = false) { global $wpdb; global $switched; global $search; $multi_posts = array(); // Posts/Custom Posts arranged by Multisite id $perf_options = get_option('asp_performance'); $caching_options = w_boolean_def(get_option('asp_caching'), get_option('asp_caching_def')); if (w_isset_def($perf_options['enabled'], 1)) { $performance = new wpd_Performance('asp_performance_stats'); $performance->start_measuring(); } /*print "in ajaxsearchpro_search();"; print_r(array()); return; */ $s = $_POST['aspp']; $s = apply_filters('asp_search_phrase_before_cleaning', $s); $s = stripcslashes($s); $s = trim($s); $s = preg_replace('/\\s+/', ' ', $s); $s = apply_filters('asp_search_phrase_after_cleaning', $s); $id = (int) $_POST['asid']; $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($wpdb->prepare("UPDATE " . $_prefix . "ajaxsearchpro_statistics SET num=num+1, last_date=%d WHERE (keyword='%s' AND search_id=%d)", time(), strip_tags($s), $id)); if ($in == false) { $wpdb->query($wpdb->prepare("INSERT INTO " . $_prefix . "ajaxsearchpro_statistics (search_id, keyword, num, last_date) VALUES (%d, '%s', 1, %d)", $id, strip_tags($s), time())); } } $def_data = get_option('asp_defaults'); $search = $wpdb->get_row("SELECT * FROM " . $_prefix . "ajaxsearchpro WHERE id=" . $id, ARRAY_A); $search['data'] = json_decode($search['data'], true); $search['data'] = array_merge($def_data, $search['data']); //var_dump(current_user_can("manage_options")); die(); // See if we post the preview data through if (!empty($_POST['asp_preview_options']) && current_user_can("manage_options")) { //$search['data'] = array_merge($search['data'], unserialize(base64_decode($_POST['asp_preview_options']))); $search['data'] = array_merge($search['data'], unserialize(base64_decode($_POST['asp_preview_options']))); } $sd = $search['data']; $search['data']['image_options'] = array('image_cropping' => w_isset_def($caching_options['image_cropping'], 1), 'show_images' => $search['data']['show_images'], 'image_bg_color' => $search['data']['image_bg_color'], 'image_transparency' => $search['data']['image_transparency'], 'image_crop_location' => w_isset_def($search['data']['image_crop_location'], "c"), 'apply_content_filter' => w_isset_def($search['data']['image_apply_content_filter'], 0), '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']); if (isset($_POST['asp_get_as_array'])) { $search['data']['image_options']['show_images'] = 0; } // ----------------- 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']['hreswidth']); $search['data']['image_options']['image_height'] = wpdreams_width_from_px($search['data']['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'])) { if (is_array($_POST['options'])) { $search['options'] = $_POST['options']; } else { parse_str($_POST['options'], $search['options']); } } $blogresults = array(); $allbuddypresults = array('repliesresults' => array(), 'groupresults' => array(), 'userresults' => array(), 'activityresults' => array()); $alltermsresults = array(); $allpageposts = array(); $pageposts = array(); $repliesresults = array(); $allcommentsresults = array(); $commentsresults = array(); $userresults = array(); $attachment_results = array(); $search['data']['selected-blogs'] = w_isset_def($search['data']['selected-blogs'], array(0 => get_current_blog_id())); if ($search['data']['selected-blogs'] === "all") { if (is_multisite()) { $search['data']['selected-blogs'] = wpdreams_get_blog_list(0, "all", true); } else { $search['data']['selected-blogs'] = array(0 => get_current_blog_id()); } } if (count($search['data']['selected-blogs']) <= 0) { $search['data']['selected-blogs'] = array(0 => get_current_blog_id()); } do_action('asp_before_search', $s); if (is_array($caching_options) && w_isset_def($caching_options['caching'], 0) && ASP_DEBUG != 1) { $filename = ASP_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR . md5(json_encode($search['options']) . $s . $_POST['asp_inst_id']) . ".wp"; $textcache = new wpdreamsTextCache($filename, w_isset_def($caching_options['cachinginterval'], 3600) * 60); $cache_content = $textcache->getCache(); if ($cache_content != false) { $cache_content = apply_filters('asp_cached_content', $cache_content); do_action('asp_after_search', $s, json_decode($cache_content, true)); print "cached(" . date("F d Y H:i:s.", filemtime($filename)) . ")"; print_r($cache_content); die; } } // True if only CPT search in the index table is active $search_only_it_posts = w_isset_def($search['data']['search_engine'], 'regular') != 'regular' && w_isset_def($search['data']['return_categories'], 0) == 0 && w_isset_def($search['data']['return_terms'], '') == '' && w_isset_def($search['data']['return_attachments'], 0) == 0; if (is_multisite() && $search_only_it_posts) { // Save huge amounts of server resources by not swapping all the blogs around if ($_POST['asid'] == "") { $_dposts = new wpdreams_searchDemo(array()); $dpageposts = $_dposts->search($s); $allpageposts = array_merge($allpageposts, $dpageposts); } else { $search['options']['switch_on_preprocess'] = 1; $search['options']['dont_group'] = $dontGroup; $params = array('id' => $id, 'data' => $search['data'], 'options' => $search['options']); $_posts = new asp_searchIndexTable($params); $pageposts = $_posts->search($s); do_action('asp_after_pagepost_results', $s, $pageposts); $allpageposts = array_merge($allpageposts, $pageposts); } } else { // Regularly swap through blogs foreach ($search['data']['selected-blogs'] as $blog) { if (is_multisite()) { switch_to_blog($blog); } aspDebug::start('search-blog-' . $blog); if ($_POST['asid'] == "") { $_dposts = new wpdreams_searchDemo(array()); $dpageposts = $_dposts->search($s); $allpageposts = array_merge($allpageposts, $dpageposts); } else { $search['options']['dont_group'] = $dontGroup; $params = array('id' => $id, 'data' => $search['data'], 'options' => $search['options']); $_terms = new wpdreams_searchTerms($params); $termsresults = $_terms->search($s); $alltermsresults = array_merge($alltermsresults, $termsresults); // For exact matches the regular engine is used if (w_isset_def($search['data']['search_engine'], 'regular') == 'regular' || isset($params['options']['set_exactonly'])) { $_posts = new wpdreams_searchContent($params); } else { $_posts = new asp_searchIndexTable($params); } $pageposts = $_posts->search($s); //var_dump($pageposts);die(); $allpageposts = array_merge($allpageposts, $pageposts); if ($forceMulti) { foreach ($pageposts as $kk => $vv) { $pageposts[$kk]->blogid = $blog; } $multi_posts[$blog] = $pageposts; } do_action('asp_after_pagepost_results', $s, $pageposts); $_comments = new wpdreams_searchComments($params); $commentsresults = $_comments->search($s); $allcommentsresults = array_merge($allcommentsresults, $commentsresults); if (w_isset_def($search['data']['return_attachments'], 0)) { $_attachments = new wpdreams_searchAttachments($params); $attachment_results = array_merge($attachment_results, $_attachments->search($s)); } do_action('asp_after_attachment_results', $s, $attachment_results); } } } 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 (w_isset_def($search['data']['user_search'], 0)) { $_users = new wpdreams_searchUsers($params); $userresults = $_users->search($s); } do_action('asp_after_user_results', $s, $userresults); aspDebug::stop('search-blog-' . $blog); if (is_multisite()) { restore_current_blog(); } $_blogs = new wpdreams_searchBlogs($params); $blogresults = $_blogs->search($s); $alltermsresults = apply_filters('asp_terms_results', $alltermsresults, $id); $allpageposts = apply_filters('asp_pagepost_results', $allpageposts, $id); $allcommentsresults = apply_filters('asp_comment_results', $allcommentsresults, $id); $buddypresults = apply_filters('asp_buddyp_results', $buddypresults, $id); $blogresults = apply_filters('asp_blog_results', $blogresults, $id); $userresults = apply_filters('asp_user_results', $userresults, $id); $attachment_results = apply_filters('asp_attachment_results', $attachment_results, $id); /* 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]); } } } // Results as array, unordered $results_arr = array('terms' => $alltermsresults, 'blogs' => $blogresults, 'bp_activities' => $allbuddypresults['activityresults'], 'comments' => $allcommentsresults, 'bp_groups' => $allbuddypresults['groupresults'], 'bp_users' => $userresults, 'post_page_cpt' => $allpageposts, 'attachments' => $attachment_results); $results_order = w_isset_def($search['data']['results_order'], 'terms|blogs|bp_activities|comments|bp_groups|bp_users|post_page_cpt|attachments'); if (strpos($results_order, 'attachments') === false) { $results_order .= "|attachments"; } // These keys are in the right order $results_order_arr = explode('|', $results_order); // Grouping again, respecting ordering if ($search['data']['resultstype'] == 'vertical' && ($search['data']['groupby'] == 1 || $search['data']['groupby'] == 2) && !$forceMulti) { $results = $allpageposts; $results['items'] = array(); $results['grouped'] = 1; // CPM if (count($allpageposts) > 0) { $i = 9000 + strpos($results_order, 'post_page_cpt'); $results['items'][$i] = array(); $results['items'][$i]['data'] = $allpageposts; $results['items'][$i]['digdeeper'] = 1; } // Term results if (count($alltermsresults) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($alltermsresults) . ")" : ""; $i = 9000 + strpos($results_order, 'terms'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("Term group header", w_isset_def($search['data']['term_group_text'], 'Terms')) . $num; $results['items'][$i]['data'] = $alltermsresults; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Blog results if (count($blogresults) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($blogresults) . ")" : ""; $i = 9000 + strpos($results_order, 'blogs'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("Blog results group header", $search['data']['blogresultstext']) . $num; $results['items'][$i]['data'] = $blogresults; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Activity results if (count($allbuddypresults['activityresults']) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allbuddypresults['activityresults']) . ")" : ""; $i = 9000 + strpos($results_order, 'bp_activities'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("BuddyPress activity group header", $search['data']['bbpressreplytext']) . $num; $results['items'][$i]['data'] = $allbuddypresults['activityresults']; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Comments results if (count($allcommentsresults) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allcommentsresults) . ")" : ""; $i = 9000 + strpos($results_order, 'comments'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("Group by comments header", $search['data']['commentstext']) . $num; $results['items'][$i]['data'] = $allcommentsresults; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Buddypress groups if (count($allbuddypresults['groupresults']) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($allbuddypresults['groupresults']) . ")" : ""; $i = 9000 + strpos($results_order, 'bp_groups'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("BuddyPress group header", $search['data']['bbpressgroupstext']) . $num; $results['items'][$i]['data'] = $allbuddypresults['groupresults']; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Users if (count($userresults) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($userresults) . ")" : ""; $i = 9000 + strpos($results_order, 'bp_users'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("User group header", $search['data']['bbpressuserstext']) . $num; $results['items'][$i]['data'] = $userresults; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } // Attachments if (count($attachment_results) > 0) { $num = $search['data']['showpostnumber'] == 1 ? " (" . count($attachment_results) . ")" : ""; $i = 9000 + strpos($results_order, 'attachments'); $results['items'][$i] = array(); $results['items'][$i]['name'] = asp_icl_t("Attachment group header", w_isset_def($search['data']['attachment_group_text'], 'Attachments')) . $num; $results['items'][$i]['data'] = $attachment_results; $results['items'][$i]['digdeeper'] = 0; $results['grouped'] = 1; } if (isset($results['items']) && count($results['items']) > 0) { ksort($results['items']); } else { $results = array(); } } else { $results = array(); foreach ($results_order_arr as $rk => $rv) { $results = array_merge($results, $results_arr[$rv]); } } if (count($results) <= 0 && $search['data']['keywordsuggestions']) { $keywords = array(); $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($search['data']['selected-keyword_suggestion_source'], array('google')) as $source) { $remaining_count = w_isset_def($sd['keyword_suggestion_count'], 10) - count($keywords); if ($remaining_count <= 0) { break; } $taxonomy = ""; // Check if this is a taxonomy if (strpos($source, 'xtax_') !== false) { $taxonomy = str_replace('xtax_', '', $source); $source = "terms"; } //$class_name = "wpd_" . $source . "KeywordSuggest"; $t = new wpd_keywordSuggest($source, array('maxCount' => $remaining_count, 'maxCharsPerWord' => w_isset_def($sd['keyword_suggestion_length'], 50), 'postTypes' => $types, 'lang' => $sd['keywordsuggestionslang'], 'overrideUrl' => '', 'taxonomy' => $taxonomy)); $keywords = array_merge($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, $id); do_action('asp_after_search', $s, $results, $id); // if (w_isset_def($perf_options['enabled'], 1)) { $performance->stop_measuring(); //$performance->dump_data(); } // If preview, we need the details if (isset($_POST['action']) && $_POST['action'] == "ajaxsearchpro_preview") { print "wassup!"; require_once ASP_PATH . "backend" . DIRECTORY_SEPARATOR . "settings" . DIRECTORY_SEPARATOR . "types.inc.php"; parse_str($_POST['formdata'], $preview_params); $preview_params = wpdreams_parse_params($preview_params); $preview_params = wp_parse_args($preview_params, $search['data']); $html_results = asp_generate_html_results($results, $preview_params, $search['data']['resultstype']); } else { $html_results = asp_generate_html_results($results, $search['data'], $search['data']['resultstype']); } if (is_array($caching_options) && w_isset_def($caching_options['caching'], 0) && ASP_DEBUG != 1) { $cache_content = $textcache->setCache('!!ASPSTART!!' . $html_results . "!!ASPEND!!"); } // Override from hooks.php if (isset($_POST['asp_get_as_array'])) { if ($forceMulti) { $results['_multi'] = $results; } return $results; } /* Clear output buffer, possible warnings */ print "!!ASPSTART!!"; //var_dump($results);die(); //print_r(json_encode($results)); print_r($html_results); print "!!ASPEND!!"; die; }
function ajaxsearchpro_precache() { global $wpdb; $from = $_POST['from']; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $start = microtime(true); $querystr = "\n \t\tSELECT \n {$wpdb->posts}.post_title as title,\n {$wpdb->posts}.ID as id,\n {$wpdb->posts}.post_date as date,\n {$wpdb->posts}.post_content as content,\n {$wpdb->posts}.post_excerpt as excerpt,\n {$wpdb->posts}.post_type as post_type\n \t\tFROM {$wpdb->posts}\n \t\tWHERE\n {$wpdb->posts}.ID > {$from} AND\n {$wpdb->posts}.post_status='publish'\n LIMIT 5\n \t "; $pageposts = $wpdb->get_results($querystr, OBJECT); $searches = $wpdb->get_results("SELECT * FROM " . $_prefix . "ajaxsearchpro", ARRAY_A); if (is_array($searches)) { foreach ($searches as $search) { $search['data'] = json_decode($search['data'], true); $searchData = $search['data']; if ($search['data']['selected-imagesettings']['show'] == 1) { $imgs = $search['data']['selected-imagesettings']; if ($searchData['resultstype'] == 'vertical') { $_width = $imgs['width']; $_height = $imgs['height']; } else { $_width = wpdreams_width_from_px($searchData['hreswidth']); $_vimageratio = $_width / $searchData['selected-imagesettings']['width']; $_height = $_vimageratio * $searchData['selected-imagesettings']['height']; } if (is_array($pageposts) && count($pageposts) > 0) { foreach ($pageposts as $_post) { $im = wp_get_attachment_url(get_post_thumbnail_id($_post->id)); $img = new wpdreamsImageCache($im, "post" . $_post->id, AJAXSEARCHPRO_PATH . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, -1, $searchData['imagebg']); $img = new wpdreamsImageCache($_post->content, "post" . $_post->id, AJAXSEARCHPRO_PATH . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']); $img = new wpdreamsImageCache($_post->excerpt, "post" . $_post->id, AJAXSEARCHPRO_PATH . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']); } } else { print_r(json_encode(array('msg' => 'Done!', 'affected' => 0, 'lastid' => $from))); exit; } } } $current = microtime(true); $runtime = $current - $start; print_r(json_encode(array('msg' => 'Done!', 'affected' => count($pageposts), 'lastid' => $from + count($pageposts)))); exit; } print_r(json_encode(array('msg' => 'Error!', 'affected' => 0, 'lastid' => $from))); exit; }
protected function do_search() { global $wpdb; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; $repliesresults = array(); $userresults = array(); $groupresults = array(); if (function_exists('bp_core_get_user_domain')) { /* BP users */ $like = ""; if ($options['set_inbpusers']) { if ($not_exactonly) { $sr = implode("%' OR lower({$wpdb->users}.display_name) like '%", $_s); if ($like != "") { $sr = " OR lower({$wpdb->users}.display_name) like '%" . $sr . "%'"; } else { $sr = " lower({$wpdb->users}.display_name) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower({$wpdb->users}.display_name) like '%" . $s . "%'"; } else { $sr = " lower({$wpdb->users}.display_name) like '%" . $s . "%'"; } } $like .= $sr; } $querystr = "\n SELECT\n {$wpdb->users}.ID as id,\n {$wpdb->users}.display_name as title,\n '' as date,\n '' as author\n FROM\n {$wpdb->users}\n WHERE \n (" . $like . ") \n "; $userresults = $wpdb->get_results($querystr, OBJECT); foreach ($userresults as $k => $v) { $userresults[$k]->link = bp_core_get_user_domain($v->id); $imgs = $searchData['settings-imagesettings']; if ($searchData['settings-imagesettings']['show'] == 1) { $im = bp_core_fetch_avatar('item_id=' . $userresults[$k]->id); if ($searchData['resultstype'] == 'vertical') { $_width = $imgs['width']; $_height = $imgs['height']; } else { $_width = wpdreams_width_from_px($searchData['hreswidth']); $_vimageratio = $_width / $searchData['selected-imagesettings']['width']; $_height = $_vimageratio * $searchData['selected-imagesettings']['height']; } $img = new wpdreamsImageCache($im, "user" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, 1, $searchData['imagebg']); $res = $img->get_image(); if ($res != '') { $userresults[$k]->image = plugins_url('/ajax-search-pro/cache/' . $res); } } $update = get_usermeta($v->id, 'bp_latest_update'); if (is_array($update) && isset($update['content'])) { $userresults[$k]->content = $update['content']; } if ($userresults[$k]->content != '') { $userresults[$k]->content = substr(strip_tags($userresults[$k]->content), 0, $searchData['descriptionlength']) . "..."; } else { $userresults[$k]->content = ""; } } /* BP groups */ $like = ""; if ($options['set_inbpgroups']) { if ($not_exactonly) { $sr = implode("%' OR lower(" . $wpdb->prefix . "bp_groups.name) like '%", $_s); if ($like != "") { $sr = " OR lower(" . $wpdb->prefix . "bp_groups.name) like '%" . $sr . "%'"; } else { $sr = " lower(" . $wpdb->prefix . "bp_groups.name) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower(" . $wpdb->prefix . "bp_groups.name) like '%" . $s . "%'"; } else { $sr = " lower(" . $wpdb->prefix . "bp_groups.name) like '%" . $s . "%'"; } } $like .= $sr; if ($not_exactonly) { $sr = implode("%' OR lower(" . $wpdb->prefix . "bp_groups.description) like '%", $_s); if ($like != "") { $sr = " OR lower(" . $wpdb->prefix . "bp_groups.description) like '%" . $sr . "%'"; } else { $sr = " lower(" . $wpdb->prefix . "bp_groups.description) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower(" . $wpdb->prefix . "bp_groups.description) like '%" . $s . "%'"; } else { $sr = " lower(" . $wpdb->prefix . "bp_groups.description) like '%" . $s . "%'"; } } $like .= $sr; if (isset($searchData['searchinbpprivategroups']) && $searchData['searchinbpprivategroups'] == 0) { $_and = "AND " . $wpdb->prefix . "bp_groups.status = 'public'"; } else { $_and = ""; } $querystr = "\n SELECT\n " . $wpdb->prefix . "bp_groups.id as id,\n " . $wpdb->prefix . "bp_groups.name as title,\n " . $wpdb->prefix . "bp_groups.description as content,\n " . $wpdb->prefix . "bp_groups.date_created as date,\n {$wpdb->users}.user_nicename as author \n FROM\n " . $wpdb->prefix . "bp_groups\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = " . $wpdb->prefix . "bp_groups.creator_id\n WHERE \n (" . $like . ")\n " . $_and; //AND ".$wpdb->prefix."bp_groups.status = 'public' $groupresults = $wpdb->get_results($querystr, OBJECT); foreach ($groupresults as $k => $v) { $group = new BP_Groups_Group($v->id); $groupresults[$k]->link = bp_get_group_permalink($group); $imgs = $searchData['settings-imagesettings']; if ($searchData['settings-imagesettings']['show'] == 1) { $avatar_options = array('item_id' => $v->id, 'object' => 'group', 'type' => 'full', 'html' => true); if ($searchData['resultstype'] == 'vertical') { $_width = $imgs['width']; $_height = $imgs['height']; } else { $_width = wpdreams_width_from_px($searchData['hreswidth']); $_vimageratio = $_width / $searchData['selected-imagesettings']['width']; $_height = $_vimageratio * $searchData['selected-imagesettings']['height']; } $im = bp_core_fetch_avatar($avatar_options); $img = new wpdreamsImageCache($im, "bp" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, 1, $searchData['imagebg']); $res = $img->get_image(); if ($res != '') { $groupresults[$k]->image = plugins_url('/ajax-search-pro/cache/' . $res); } } if ($groupresults[$k]->content != '') { $groupresults[$k]->content = substr(strip_tags($groupresults[$k]->content), 0, $searchData['descriptionlength']) . "..."; } } } do_action('bbpress_init'); /* if ($searchinbpforums && class_exists('BB_Query_Form')) { $like = ""; if ($not_exactonly) { $sr = implode("%' OR lower(".$wpdb->prefix."bb_forums.forum_name) like '%",$_s); if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_forums.forum_name) like '%".$sr."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_forums.forum_name) like '%".$sr."%'"; } } else { if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_forums.forum_name) like '%".$s."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_forums.forum_name) like '%".$s."%'"; } } $like .= $sr; if ($not_exactonly) { $sr = implode("%' OR lower(".$wpdb->prefix."bb_topics.topic_title) like '%",$_s); if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_topics.topic_title) like '%".$sr."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_topics.topic_title) like '%".$sr."%'"; } } else { if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_topics.topic_title) like '%".$s."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_topics.topic_title) like '%".$s."%'"; } } $like .= $sr; if ($not_exactonly) { $sr = implode("%' OR lower(".$wpdb->prefix."bb_posts.post_text) like '%",$_s); if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_posts.post_text) like '%".$sr."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_posts.post_text) like '%".$sr."%'"; } } else { if ($like!="") { $sr = " OR lower(".$wpdb->prefix."bb_posts.post_text) like '%".$s."%'"; } else { $sr = " lower(".$wpdb->prefix."bb_posts.post_text) like '%".$s."%'"; } } $like .= $sr; $querystr = " SELECT ".$wpdb->prefix."bb_posts.post_id as id, ".$wpdb->prefix.$searchData['bpgroupstitle'].", ".$wpdb->prefix."bb_posts.post_text as content, ".$wpdb->prefix."bb_posts.post_time as date, ".$wpdb->prefix."bb_topics.topic_id as topic_id, $wpdb->users.user_nicename as author FROM ".$wpdb->prefix."bb_posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = ".$wpdb->prefix."bb_posts.poster_id LEFT JOIN ".$wpdb->prefix."bb_topics ON ".$wpdb->prefix."bb_posts.topic_id = ".$wpdb->prefix."bb_topics.topic_id LEFT JOIN ".$wpdb->prefix."bb_forums ON ".$wpdb->prefix."bb_posts.forum_id = ".$wpdb->prefix."bb_forums.forum_id WHERE (".$like.") "; $repliesresults = $wpdb->get_results($querystr, OBJECT); foreach ($repliesresults as $k=>$v) { $topic_query_vars = array( 'topic_id'=> $v->topic_id, 'topic_status' => 'normal', 'open' => 'open'); $topic_query = new BB_Query_Form( 'topic', $topic_query_vars ); $topics = $topic_query->results; if (is_array($topics)) { foreach ( $topics as $topic ) : $first_post = bb_get_first_post( $topic ); $_qs = "SELECT post_id as id FROM ".$wpdb->prefix."bb_posts WHERE topic_id=".$v->topic_id; $_posts = $wpdb->get_results($_qs, OBJECT); $_count = 0; foreach ($_posts as $_post) { $_count++; if ($_post->id==$v->id) break; } $_bbp_post_count = get_option("_bbp_replies_per_page", 15); $_page = intval(($_count-1) / $_bbp_post_count); if ($_page>0) { $_page = "?topic_page=".($_page+1); } else { $_page = ""; } $repliesresults[$k]->link = get_bloginfo('url')."/groups/".$topic->object_slug."/forum/topic/".$topic->topic_slug."/".$_page."#post-".$v->id; endforeach; } if ($searchData['settings-imagesettings']['show']==1) { $im = $repliesresults[$k]->content; $img = new wpdreamsImageCache($im, AJAXSEARCHPRO_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR, $imgs['width'], $imgs['height'], 1, $searchData['imagebg']); $res = $img->get_image(); if ($res!='') { $repliesresults[$k]->image = plugins_url('/ajax-search-pro/cache/'.$res ); } } if ($repliesresults[$k]->content!='') $repliesresults[$k]->content = substr(strip_tags($repliesresults[$k]->content), 0, $searchData['descriptionlength'])."..."; $repliesresults[$k]->title = substr(strip_tags($repliesresults[$k]->title), 0, 30)."..."; } } Forum search Deprecated */ } $this->results = array('repliesresults' => $repliesresults, 'groupresults' => $groupresults, 'userresults' => $userresults); return $this->results; }
protected function post_process() { $pageposts = $this->results; $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; /* Category filtering */ $_selected_categories = array(); if (isset($options['categoryset'])) { $_selected_categories = $options['categoryset']; } $_all_categories = get_all_category_ids(); if (count($_selected_categories) > 0 && count($_all_categories) != count($_selected_categories)) { foreach ($pageposts as $k => $v) { if ($v->term_id == null) { $v->term_id = ""; continue; } if ($v->post_type != 'post' && $searchData['pageswithcategories'] != 1) { continue; } $_term_ids = explode(',', $v->term_id); if (count($_term_ids) <= 0) { $_term_ids = array($v->term_id); } $match = false; $_new_terms = array(); foreach ($_term_ids as $_term_id) { if (in_array($_term_id, $_selected_categories)) { $match = true; $_new_terms[] = $_term_id; } } if (!$match) { unset($pageposts[$k]); } else { $v->term_id = implode(",", $_new_terms); } } } /* !Category filtering */ /* TERM filtering */ if (isset($options['termset'])) { $terms = array(); $o_terms = array(); foreach ($options['termset'] as $term => $tax) { if ($tax != "0") { $o_terms[$tax][] = $term; } } //var_dump($o_terms); foreach ($pageposts as $k => $v) { $terms = $o_terms; foreach ($terms as $ex_taxonomy => $ex_terms) { $_post_terms = wp_get_post_terms($v->id, $ex_taxonomy); $post_terms = array(); if (is_array($_post_terms) && isset($_post_terms[0])) { foreach ($_post_terms as $_term) { $post_terms[] = (int) $_term->term_id; } foreach ($ex_terms as $_term) { /* Get all child terms of the current term */ $args = array('child_of' => $_term); $termchildren = get_terms($ex_taxonomy, $args); if (isset($termchildren) && count($termchildren) > 0) { foreach ($termchildren as $child_term) { if (!in_array((int) $child_term->term_id, $ex_terms)) { $ex_terms[] = (int) $child_term->term_id; } } } /* Get the parent term of the current term */ $parent = get_term_by('id', $_term, $ex_taxonomy); if (isset($parent) && isset($parent->term_id) && $parent->term_id != 0) { $ex_terms[] = $parent->term_id; } } $diff = array_unique(array_diff($post_terms, $ex_terms)); //var_dump($post_terms); //var_dump($ex_terms); //var_dump($diff); //exit; if (!is_array($diff) || count($diff) < 1) { unset($pageposts[$k]); break; } } } } } /* !TERM filtering */ /* Images, title, desc */ foreach ($pageposts as $k => $v) { // Let's simplify things $r =& $pageposts[$k]; $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id); $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id); $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id); $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id); $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id); $r->link = get_permalink($v->id); $use_timthumb = get_option('asp_usetimbthumb'); if ($use_timthumb) { if ($searchData['settings-imagesettings']['show'] == 1) { $imgs = $searchData['settings-imagesettings']; ksort($imgs['from']); if ($searchData['resultstype'] == 'vertical') { $_width = $imgs['width']; $_height = $imgs['height']; } else { $_width = wpdreams_width_from_px($searchData['hreswidth']); $_vimageratio = $_width / $searchData['selected-imagesettings']['width']; $_height = $_vimageratio * $searchData['selected-imagesettings']['height']; } foreach ($imgs['from'] as $kk => $source) { if ($kk == -11) { continue; } if (isset($r->image) || $r->image != '') { continue; } if ($source == 'featured') { $im = wp_get_attachment_url(get_post_thumbnail_id($v->id)); } else { if ($source == 'content') { $im = wpdreams_get_image_from_content($v->content, $imgs['imagenum']); } else { if ($source == 'excerpt') { $im = wpdreams_get_image_from_content($v->excerpt, $imgs['imagenum']); } else { if ($source == 'usecustom') { if (isset($imgs['customname']) && $imgs['customname'] != '') { $im = get_post_meta($v->id, $imgs['customname'], true); if ($im != '' && $im != false) { } else { continue; } } else { continue; } } } } } if ($im !== false && $im != '') { $r->image = plugins_url('/ajax-search-pro/includes/timthumb.php') . '?cc=' . str_replace('#', '', wpdreams_rgb2hex($searchData['imagebg'])) . '&ct=0&q=95&w=' . $_width . '&h=' . $_height . '&src=' . rawurlencode($im); break; } } } } else { if ($searchData['settings-imagesettings']['show'] == 1) { $imgs = $searchData['settings-imagesettings']; ksort($imgs['from']); if ($searchData['resultstype'] == 'vertical') { $_width = $imgs['width']; $_height = $imgs['height']; } else { if ($searchData['resultstype'] == 'horizontal') { $_width = wpdreams_width_from_px($searchData['hreswidth']); $_vimageratio = $_width / $searchData['selected-imagesettings']['width']; $_height = $_vimageratio * $searchData['selected-imagesettings']['height']; } else { $_width = wpdreams_width_from_px($searchData['preswidth']) - 2 * wpdreams_width_from_px($searchData['prespadding']); $_height = $_width; } } foreach ($imgs['from'] as $kk => $source) { if ($kk == -11) { continue; } if (isset($r->image) || $r->image != '') { continue; } // Calculate the image size if ($source == 'featured') { //$im = get_the_post_thumbnail($v->id); $im = wp_get_attachment_url(get_post_thumbnail_id($v->id)); //var_dump($im); $img = new wpdreamsImageCache($im, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, -1, $searchData['imagebg']); } else { if ($source == 'content') { $img = new wpdreamsImageCache($v->content, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']); } else { if ($source == 'excerpt') { $img = new wpdreamsImageCache($v->excerpt, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, $imgs['imagenum'], $searchData['imagebg']); } else { if ($source == 'usecustom') { if (isset($imgs['customname']) && $imgs['customname'] != '') { $im = get_post_meta($v->id, $imgs['customname'], true); if ($im != '' && $im != false) { $img = new wpdreamsImageCache($im, "post" . $v->id, AJAXSEARCHPRO_PATH . DIRECTORY_SEPARATOR . "cache" . DIRECTORY_SEPARATOR, $_width, $_height, -1, $searchData['imagebg']); } else { continue; } } else { continue; } } } } } $res = $img->get_image(); if ($res != '') { $r->image = plugins_url('/ajax-search-pro/cache/' . $res); break; } } } } if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) { $r->title = get_the_title($r->id); } else { if ($searchData['titlefield'] == "1") { if (strlen($r->excerpt) >= 200) { $r->title = substr($r->excerpt, 0, 200); } else { $r->title = $r->excerpt; } } else { $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id); if (isset($mykey_values[0])) { $r->title = $mykey_values[0]; } else { $r->title = get_the_title($r->id); } } } if (!isset($searchData['striptagsexclude'])) { $searchData['striptagsexclude'] = "<a><span>"; } if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) { if (function_exists('qtrans_getLanguage')) { $r->content = apply_filters('the_content', $r->content); } $_content = strip_tags($r->content, $searchData['striptagsexclude']); } else { if ($searchData['descriptionfield'] == "1") { $_content = strip_tags($r->excerpt, $searchData['striptagsexclude']); } else { if ($searchData['descriptionfield'] == "2") { $_content = strip_tags(get_the_title($r->id), $searchData['striptagsexclude']); } else { $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id); if (isset($mykey_values[0])) { $_content = strip_tags($mykey_values[0], $searchData['striptagsexclude']); } else { $_content = strip_tags(get_content_w($r->content), $searchData['striptagsexclude']); } } } } if ($_content == "") { $_content = $r->content; } if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) { if ($_content != "") { $_content = apply_filters('the_content', $_content); } if ($_content != "") { $_content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $_content); } } if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) { if ($_content != "") { $_content = strip_shortcodes($_content); } } $_content = strip_tags($_content, $searchData['striptagsexclude']); if ($_content != '' && strlen($_content) > $searchData['descriptionlength']) { $r->content = substr($_content, 0, $searchData['descriptionlength']) . "..."; } else { $r->content = $_content . "..."; } $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id); $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id); $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id); $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id); $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id); } /* !Images, title, desc */ //var_dump($pageposts); die(); $this->results = $pageposts; return $pageposts; }