function edit() { $c = new Container($this->uri->segment(3, $_POST['container'])); // This includes deactivated plugins! They need to be filtered out $pm = new PluginManager(); $all_plugins = $pm->getPluginObjects(); $container_plugins = $c->getPlugins(); /* print Kohana::debug($all_plugins); print Kohana::debug($container_plugins); // This returns only the instantiated objects print Kohana::debug(array_intersect_key($all_plugins, $container_plugins));*/ $view = new View('containers_edit'); $view->container = $c; objectSort($all_plugins, 'column'); $view->all_plugins = $all_plugins; $view->plugin_instances = $container_plugins; $copy = $view->render(); $this->render($copy); }
/** * Sort an array of objects by field name. The sort algorithm is a * stable merge sort. * * @param string field The field to sort on * @param array $ar The array to be sorted * @param bool descending Sort descending (default FALSE) * @return array */ function objectSort($field, array $ar, $descending = FALSE) { // check stop condition if (count($ar) < 2) { return $ar; } // split in equal halves and sort both $split = floor(count($ar) / 2); $ar1 = objectSort($field, array_slice($ar, 0, $split), $descending); $ar2 = objectSort($field, array_slice($ar, $split), $descending); // now merge $result = array(); $i = $j = 0; while ($i < count($ar1) && $j < count($ar2)) { if ($descending) { if ($ar2[$j]->{$field} >= $ar1[$i]->{$field}) { $result[] = $ar2[$j]; $j++; } else { $result[] = $ar1[$i]; $i++; } } else { if ($ar1[$i]->{$field} <= $ar2[$j]->{$field}) { $result[] = $ar1[$i]; $i++; } else { $result[] = $ar2[$j]; $j++; } } } // add trailing elements for (; $i < count($ar1); $i++) { $result[] = $ar1[$i]; } for (; $j < count($ar2); $j++) { $result[] = $ar2[$j]; } return $result; }
/** * edit plugins * * @return void * @author Andy Bennett */ function edit() { $id = $this->input->post('form_id'); $model = steamcore::get_controls_model('containers'); // This includes deactivated plugins! They need to be filtered out $all_plugins = PluginManager::factory()->getPluginObjects(); $res = $model->get_plugins($id); $container_plugins = array(); foreach ($res as $row) { $container_plugins[$row->plugin_name]['column'] = $row->column; $container_plugins[$row->plugin_name]['order'] = $row->order; $container_plugins[$row->plugin_name]['template'] = $row->template; } $view = View::factory('containers_edit'); $view->container = $model->get_db()->select_row('container', array('id' => $id)); objectSort($all_plugins, 'column'); $view->all_plugins = $all_plugins; $view->plugin_instances = $container_plugins; $copy = $view->render(); $this->render($copy); }
function relevanssi_search($q, $cat = NULL, $excat = NULL, $expost = NULL, $post_type = NULL, $taxonomy = NULL, $taxonomy_term = NULL, $operator = "AND") { global $relevanssi_table, $wpdb; $hits = array(); $custom_cat = NULL; $o_cat = $cat; $o_excat = $excat; $o_expost = $expost; $o_post_type = $post_type; $o_taxonomy = $taxonomy; $o_taxonomy_term = $taxonomy_term; if ("custom" == $cat) { $custom_field = "custom"; $post_ids = array(); $results = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='$custom_field'"); foreach ($results as $row) { $post_ids[] = $row->post_id; } $custom_cat = implode(",", $post_ids); $cat = ""; } else if ($cat) { $cats = explode(",", $cat); $inc_term_tax_ids = array(); $ex_term_tax_ids = array(); foreach ($cats as $t_cat) { $exclude = false; if ($t_cat < 0) { // Negative category, ie. exclusion $exclude = true; $t_cat = substr($t_cat, 1); // strip the - sign. } $t_cat = $wpdb->escape($t_cat); $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id=$t_cat"); if ($term_tax_id) { $exclude ? $ex_term_tax_ids[] = $term_tax_id : $inc_term_tax_ids[] = $term_tax_id; } } $cat = implode(",", $inc_term_tax_ids); $excat_temp = implode(",", $ex_term_tax_ids); } if ($excat) { $excats = explode(",", $excat); $term_tax_ids = array(); foreach ($excats as $t_cat) { $t_cat = $wpdb->escape(trim($t_cat, ' -')); $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id=$t_cat"); if ($term_tax_id) { $term_tax_ids[] = $term_tax_id; } } $excat = implode(",", $term_tax_ids); } if (isset($excat_temp)) { $excat .= $excat_temp; } if (isset($taxonomy)) { $term_tax_id = null; $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->terms JOIN $wpdb->term_taxonomy USING(`term_id`) WHERE `slug` LIKE '$taxonomy_term' AND `taxonomy` LIKE '$taxonomy'"); if ($term_tax_id) { $taxonomy = $term_tax_id; } else { $taxonomy = null; } } if ($post_type) { if (!is_array($post_type)) { $post_types = explode(',', $post_type); } else { $post_types = $post_type; } $pt_array = array(); foreach ($post_types as $pt) { $pt = "'" . trim(mysql_real_escape_string($pt)) . "'"; array_push($pt_array, $pt); } $post_type = implode(",", $pt_array); } //Added by OdditY: //Exclude Post_IDs (Pages) for non-admin search -> if ($expost) { if ($expost != "") { $aexpids = explode(",",$expost); foreach ($aexpids as $exid){ $exid = $wpdb->escape(trim($exid, ' -')); $postex .= " AND doc !='$exid'"; } } } // <- OdditY End $remove_stopwords = false; $phrases = relevanssi_recognize_phrases($q); $terms = relevanssi_tokenize($q, $remove_stopwords); if (count($terms) < 1) { // Tokenizer killed all the search terms. return $hits; } $terms = array_keys($terms); // don't care about tf in query $D = $wpdb->get_var("SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table"); $total_hits = 0; $title_matches = array(); $tag_matches = array(); $comment_matches = array(); $body_matches = array(); $scores = array(); $term_hits = array(); $fuzzy = get_option('relevanssi_fuzzy'); $query_restrictions = ""; if ($expost) { //added by OdditY $query_restrictions .= $postex; } if ($cat) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(object_id) FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ($cat))"; } if ($excat) { $query_restrictions .= " AND doc NOT IN (SELECT DISTINCT(object_id) FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ($excat))"; } if ($post_type) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(ID) FROM $wpdb->posts WHERE post_type IN ($post_type))"; } if ($phrases) { $query_restrictions .= " AND doc IN ($phrases)"; } if ($custom_cat) { $query_restrictions .= " AND doc IN ($custom_cat)"; } if ($taxonomy) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(object_id) FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ($taxonomy))"; } if (isset($_REQUEST['by_date'])) { $n = $_REQUEST['by_date']; $u = substr($n, -1, 1); switch ($u) { case 'h': $unit = "HOUR"; break; case 'd': $unit = "DAY"; break; case 'm': $unit = "MONTH"; break; case 'y': $unit = "YEAR"; break; case 'w': $unit = "WEEK"; break; default: $unit = "DAY"; } $n = preg_replace('/[hdmyw]/', '', $n); if (is_numeric($n)) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(ID) FROM $wpdb->posts WHERE post_date > DATE_SUB(NOW(), INTERVAL $n $unit))"; } } $query_restrictions = apply_filters('relevanssi_where', $query_restrictions); // Charles St-Pierre foreach ($terms as $term) { $term = $wpdb->escape(like_escape($term)); if ("always" == $fuzzy) { $term_cond = "(term LIKE '%$term' OR term LIKE '$term%') "; } else { $term_cond = " term = '$term' "; } $query = "SELECT doc, term, tf, title FROM $relevanssi_table WHERE $term_cond $query_restrictions"; $matches = $wpdb->get_results($query); if (count($matches) < 1 && "sometimes" == $fuzzy) { $query = "SELECT doc, term, tf, title FROM $relevanssi_table WHERE (term LIKE '$term%' OR term LIKE '%$term') $query_restrictions"; $matches = $wpdb->get_results($query); } $total_hits += count($matches); $query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table WHERE $term_cond $query_restrictions"; $df = $wpdb->get_var($query); if ($df < 1 && "sometimes" == $fuzzy) { $query = "SELECT COUNT(DISTINCT(doc)) FROM $relevanssi_table WHERE (term LIKE '%$term' OR term LIKE '$term%') $query_restrictions"; $df = $wpdb->get_var($query); } $title_boost = floatval(get_option('relevanssi_title_boost')); $tag_boost = floatval(get_option('relevanssi_tag_boost')); $comment_boost = floatval(get_option('relevanssi_comment_boost')); $idf = log($D / (1 + $df)); // $doc_terms_temp = array(); foreach ($matches as $match) { $weight = $match->tf * $idf; if (!isset($term_hits[$match->doc][$term])) { $term_hits[$match->doc][$term] = 0; } switch ($match->title) { case "1": $weight = $weight * $title_boost; isset($title_matches[$match->doc]) ? $title_matches[$match->doc] += $match->tf : $title_matches[$match->doc] = $match->tf; $term_hits[$match->doc][$term] += $match->tf; break; case "2": $weight = $weight * $tag_boost; isset($tag_matches[$match->doc]) ? $tag_matches[$match->doc] += $match->tf : $tag_matches[$match->doc] = $match->tf; $term_hits[$match->doc][$term] += $match->tf; break; case "3": $weight = $weight * $comment_boost; isset($comment_matches[$match->doc]) ? $comment_matches[$match->doc] += $match->tf : $comment_matches[$match->doc] = $match->tf; $term_hits[$match->doc][$term] += $match->tf; break; default: isset($body_matches[$match->doc]) ? $body_matches[$match->doc] += $match->tf : $body_matches[$match->doc] = $match->tf; $term_hits[$match->doc][$term] += $match->tf; } $doc_terms[$match->doc][$term] = true; // count how many terms are matched to a doc isset($doc_weight[$match->doc]) ? $doc_weight[$match->doc] += $weight : $doc_weight[$match->doc] = $weight; isset($scores[$match->doc]) ? $scores[$match->doc] += $weight : $scores[$match->doc] = $weight; } } $total_terms = count($terms); if (isset($doc_weight) && count($doc_weight) > 0) { arsort($doc_weight); $i = 0; foreach ($doc_weight as $doc => $weight) { if (count($doc_terms[$doc]) < $total_terms && $operator == "AND") { // AND operator in action: // doc didn't match all terms, so it's discarded continue; } $status = get_post_status($doc); $post_ok = true; if ('private' == $status) { $post_ok = false; if (function_exists('awp_user_can')) { // Role-Scoper $current_user = wp_get_current_user(); $post_ok = awp_user_can('read_post', $doc, $current_user->ID); } else { // Basic WordPress version $type = get_post_type($doc); $cap = 'read_private_' . $type . 's'; if (current_user_can($cap)) { $post_ok = true; } } } if ($post_ok) $hits[intval($i++)] = get_post($doc); } } if (count($hits) < 1) { if ($operator == "AND" AND get_option('relevanssi_disable_or_fallback') != 'on') { $return = relevanssi_search($q, $o_cat, $o_excat, $o_expost, $o_post_type, $o_taxonomy, $o_taxonomy_term, "OR"); extract($return); } } global $wp; isset($wp->query_vars["orderby"]) ? $orderby = $wp->query_vars["orderby"] : $orderby = 'relevance'; isset($wp->query_vars["order"]) ? $order = $wp->query_vars["order"] : $order = 'desc'; if ($orderby != 'relevance') objectSort($hits, $orderby, $order); $return = array('hits' => $hits, 'body_matches' => $body_matches, 'title_matches' => $title_matches, 'tag_matches' => $tag_matches, 'comment_matches' => $comment_matches, 'scores' => $scores, 'term_hits' => $term_hits); return $return; }
function relevanssi_search($q, $cat = NULL, $excat = NULL, $expost = NULL, $post_type = NULL, $taxonomy = NULL, $taxonomy_term = NULL, $operator = "AND", $tag = NULL, $author = NULL) { global $relevanssi_table, $wpdb; $values_to_filter = array('q' => $q, 'cat' => $cat, 'tag' => $tag, 'excat' => $excat, 'expost' => $expost, 'post_type' => $post_type, 'taxonomy' => $taxonomy, 'taxonomy_term' => $taxonomy_term, 'operator' => $operator, 'author' => $author); $filtered_values = apply_filters('relevanssi_search_filters', $values_to_filter); $q = $filtered_values['q']; $cat = $filtered_values['cat']; $excat = $filtered_values['excat']; $tag = $filtered_values['tag']; $expost = $filtered_values['expost']; $post_type = $filtered_values['post_type']; $taxonomy = $filtered_values['taxonomy']; $taxonomy_term = $filtered_values['taxonomy_term']; $operator = $filtered_values['operator']; $author = $filtered_values['author']; $hits = array(); $custom_cat = NULL; $o_cat = $cat; $o_excat = $excat; $o_expost = $expost; $o_tag = $tag; $o_post_type = $post_type; $o_taxonomy = $taxonomy; $o_taxonomy_term = $taxonomy_term; $o_author = $author; if ("custom" == $cat) { $custom_field = "custom"; $post_ids = array(); $results = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='{$custom_field}'"); foreach ($results as $row) { $post_ids[] = $row->post_id; } $custom_cat = implode(",", $post_ids); $cat = ""; } else { if ($cat) { $cats = explode(",", $cat); $inc_term_tax_ids = array(); $ex_term_tax_ids = array(); foreach ($cats as $t_cat) { $exclude = false; if ($t_cat < 0) { // Negative category, ie. exclusion $exclude = true; $t_cat = substr($t_cat, 1); // strip the - sign. } $t_cat = $wpdb->escape($t_cat); $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy}\n\t\t\t\tWHERE term_id={$t_cat}"); if ($term_tax_id) { $exclude ? $ex_term_tax_ids[] = $term_tax_id : ($inc_term_tax_ids[] = $term_tax_id); $children = get_term_children($term_tax_id, 'category'); if (is_array($children)) { foreach ($children as $child) { $exclude ? $ex_term_tax_ids[] = $child : ($inc_term_tax_ids[] = $child); } } } } $cat = implode(",", $inc_term_tax_ids); $excat_temp = implode(",", $ex_term_tax_ids); } } if ($excat) { $excats = explode(",", $excat); $term_tax_ids = array(); foreach ($excats as $t_cat) { $t_cat = $wpdb->escape(trim($t_cat, ' -')); $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy}\n\t\t\t\tWHERE term_id={$t_cat}"); if ($term_tax_id) { $term_tax_ids[] = $term_tax_id; } } $excat = implode(",", $term_tax_ids); } if (isset($excat_temp)) { $excat .= $excat_temp; } if ($author) { $author = esc_sql($author); } if ($tag) { $tags = explode(",", $tag); $inc_term_tax_ids = array(); $ex_term_tax_ids = array(); foreach ($tags as $t_tag) { $t_tag = $wpdb->escape($t_tag); $term_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy}\n\t\t\t\tWHERE term_id={$t_tag}"); if ($term_tax_id) { $inc_term_tax_ids[] = $term_tax_id; } } $tag = implode(",", $inc_term_tax_ids); } if (!empty($taxonomy)) { $term_tax_id = null; $term_tax_id = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->terms}\n\t\t\tJOIN {$wpdb->term_taxonomy} USING(`term_id`)\n\t\t\t\tWHERE `slug` LIKE %s AND `taxonomy` LIKE %s", "%{$taxonomy_term}%", $taxonomy)); if ($term_tax_id) { $taxonomy = $term_tax_id; } else { $taxonomy = null; } } if (!$post_type && get_option('relevanssi_respect_exclude') == 'on') { if (function_exists('get_post_types')) { $pt_1 = get_post_types(array('exclude_from_search' => '0')); $pt_2 = get_post_types(array('exclude_from_search' => false)); $post_type = implode(',', array_merge($pt_1, $pt_2)); } } if ($post_type) { if (!is_array($post_type)) { $post_types = explode(',', $post_type); } else { $post_types = $post_type; } $pt_array = array(); foreach ($post_types as $pt) { $pt = "'" . trim(mysql_real_escape_string($pt)) . "'"; array_push($pt_array, $pt); } $post_type = implode(",", $pt_array); } //Added by OdditY: //Exclude Post_IDs (Pages) for non-admin search -> if ($expost) { if ($expost != "") { $aexpids = explode(",", $expost); foreach ($aexpids as $exid) { $exid = $wpdb->escape(trim($exid, ' -')); $postex .= " AND doc !='{$exid}'"; } } } // <- OdditY End $remove_stopwords = false; $phrases = relevanssi_recognize_phrases($q); $terms = relevanssi_tokenize($q, $remove_stopwords); if (count($terms) < 1) { // Tokenizer killed all the search terms. return $hits; } $terms = array_keys($terms); // don't care about tf in query $D = $wpdb->get_var("SELECT COUNT(DISTINCT(doc)) FROM {$relevanssi_table}"); $total_hits = 0; $title_matches = array(); $tag_matches = array(); $comment_matches = array(); $body_matches = array(); $scores = array(); $term_hits = array(); $fuzzy = get_option('relevanssi_fuzzy'); $query_restrictions = ""; if ($expost) { //added by OdditY $query_restrictions .= $postex; } if ($cat) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(object_id) FROM {$wpdb->term_relationships}\n\t\t WHERE term_taxonomy_id IN ({$cat}))"; } if ($excat) { $query_restrictions .= " AND doc NOT IN (SELECT DISTINCT(object_id) FROM {$wpdb->term_relationships}\n\t\t WHERE term_taxonomy_id IN ({$excat}))"; } if ($post_type) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(ID) FROM {$wpdb->posts}\n\t\t\tWHERE post_type IN ({$post_type}))"; } if ($tag) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(object_id) FROM {$wpdb->term_relationships}\n\t\t WHERE term_taxonomy_id IN ({$tag}))"; } if ($phrases) { $query_restrictions .= " AND doc IN ({$phrases})"; } if ($custom_cat) { $query_restrictions .= " AND doc IN ({$custom_cat})"; } if ($taxonomy) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(object_id) FROM {$wpdb->term_relationships}\n\t\t\tWHERE term_taxonomy_id IN ({$taxonomy}))"; } if ($author) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(ID) FROM {$wpdb->posts}\n\t\t WHERE post_author IN ({$author}))"; } if (isset($_REQUEST['by_date'])) { $n = $_REQUEST['by_date']; $u = substr($n, -1, 1); switch ($u) { case 'h': $unit = "HOUR"; break; case 'd': $unit = "DAY"; break; case 'm': $unit = "MONTH"; break; case 'y': $unit = "YEAR"; break; case 'w': $unit = "WEEK"; break; default: $unit = "DAY"; } $n = preg_replace('/[hdmyw]/', '', $n); if (is_numeric($n)) { $query_restrictions .= " AND doc IN (SELECT DISTINCT(ID) FROM {$wpdb->posts}\n\t\t\t\tWHERE post_date > DATE_SUB(NOW(), INTERVAL {$n} {$unit}))"; } } $query_restrictions = apply_filters('relevanssi_where', $query_restrictions); // Charles St-Pierre $no_matches = true; if ("always" == $fuzzy) { $o_term_cond = "(term LIKE '%#term#' OR term LIKE '#term#%') "; } else { $o_term_cond = " term = '#term#' "; } $min_word_length = get_option('relevanssi_min_word_length', 3); $search_again = false; do { foreach ($terms as $term) { if (strlen($term) < $min_word_length) { continue; } $term = $wpdb->escape(like_escape($term)); $term_cond = str_replace('#term#', $term, $o_term_cond); $query = "SELECT doc, term, tf, title FROM {$relevanssi_table} WHERE {$term_cond} {$query_restrictions}"; $query = apply_filters('relevanssi_query_filter', $query); $matches = $wpdb->get_results($query); if (count($matches) < 1) { continue; } else { $no_matches = false; } relevanssi_populate_array($matches); $total_hits += count($matches); $query = "SELECT COUNT(DISTINCT(doc)) FROM {$relevanssi_table} WHERE {$term_cond} {$query_restrictions}"; $query = apply_filters('relevanssi_df_query_filter', $query); $df = $wpdb->get_var($query); if ($df < 1 && "sometimes" == $fuzzy) { $query = "SELECT COUNT(DISTINCT(doc)) FROM {$relevanssi_table}\n\t\t\t\t\tWHERE (term LIKE '%{$term}' OR term LIKE '{$term}%') {$query_restrictions}"; $query = apply_filters('relevanssi_df_query_filter', $query); $df = $wpdb->get_var($query); } $title_boost = floatval(get_option('relevanssi_title_boost')); $tag_boost = floatval(get_option('relevanssi_tag_boost')); $comment_boost = floatval(get_option('relevanssi_comment_boost')); $idf = log($D / (1 + $df)); foreach ($matches as $match) { $weight = $match->tf * $idf; if (!isset($term_hits[$match->doc][$term])) { $term_hits[$match->doc][$term] = 0; } switch ($match->title) { case "1": $weight = $weight * $title_boost; isset($title_matches[$match->doc]) ? $title_matches[$match->doc] += $match->tf : ($title_matches[$match->doc] = $match->tf); $term_hits[$match->doc][$term] += $match->tf; break; case "2": $weight = $weight * $tag_boost; isset($tag_matches[$match->doc]) ? $tag_matches[$match->doc] += $match->tf : ($tag_matches[$match->doc] = $match->tf); $term_hits[$match->doc][$term] += $match->tf; break; case "3": $weight = $weight * $comment_boost; isset($comment_matches[$match->doc]) ? $comment_matches[$match->doc] += $match->tf : ($comment_matches[$match->doc] = $match->tf); $term_hits[$match->doc][$term] += $match->tf; break; default: isset($body_matches[$match->doc]) ? $body_matches[$match->doc] += $match->tf : ($body_matches[$match->doc] = $match->tf); $term_hits[$match->doc][$term] += $match->tf; } $doc_terms[$match->doc][$term] = true; // count how many terms are matched to a doc isset($doc_weight[$match->doc]) ? $doc_weight[$match->doc] += $weight : ($doc_weight[$match->doc] = $weight); isset($scores[$match->doc]) ? $scores[$match->doc] += $weight : ($scores[$match->doc] = $weight); } } if ($no_matches) { if ($search_again) { // no hits even with fuzzy search! $search_again = false; } else { if ("sometimes" == $fuzzy) { $search_again = true; $o_term_cond = "(term LIKE '%#term#' OR term LIKE '#term#%') "; } } } else { $search_again = false; } } while ($search_again); $strip_stops = true; $temp_terms_without_stops = array_keys(relevanssi_tokenize(implode(' ', $terms), $strip_stops)); $terms_without_stops = array(); foreach ($temp_terms_without_stops as $temp_term) { if (strlen($temp_term) >= $min_word_length) { array_push($terms_without_stops, $temp_term); } } $total_terms = count($terms_without_stops); $doc_weight = apply_filters('relevanssi_results', $doc_weight); if (isset($doc_weight) && count($doc_weight) > 0) { arsort($doc_weight); $i = 0; foreach ($doc_weight as $doc => $weight) { if (count($doc_terms[$doc]) < $total_terms && $operator == "AND") { // AND operator in action: // doc didn't match all terms, so it's discarded continue; } $status = relevanssi_get_post_status($doc); $post_ok = true; $post_ok = apply_filters('relevanssi_post_ok', $doc); if ($post_ok) { $hits[intval($i++)] = relevanssi_get_post($doc); } } } if (count($hits) < 1) { if ($operator == "AND" and get_option('relevanssi_disable_or_fallback') != 'on') { $return = relevanssi_search($q, $o_cat, $o_excat, $o_expost, $o_post_type, $o_taxonomy, $o_taxonomy_term, "OR", $o_tag, $o_author); extract($return); } } global $wp; $default_order = get_option('relevanssi_default_orderby', 'relevance'); isset($wp->query_vars["orderby"]) ? $orderby = $wp->query_vars["orderby"] : ($orderby = $default_order); isset($wp->query_vars["order"]) ? $order = $wp->query_vars["order"] : ($order = 'desc'); if ($orderby != 'relevance') { objectSort($hits, $orderby, $order); } $return = array('hits' => $hits, 'body_matches' => $body_matches, 'title_matches' => $title_matches, 'tag_matches' => $tag_matches, 'comment_matches' => $comment_matches, 'scores' => $scores, 'term_hits' => $term_hits, 'query' => $q); return $return; }
/** * Get POIs * * @param Filter $filter * * @return POI[] * * @throws Exception */ public function getPOIs(Filter $filter = NULL) { $libxmlErrorHandlingState = libxml_use_internal_errors(TRUE); $lat = $filter->lat; $lon = $filter->lon; $radius = $filter->radius; $accuracy = $filter->accuracy; // calculate here to prevent recalculation on each foreach loop later $dlat = GeoUtil::getLatitudinalDistance(($radius + $accuracy) * 1.25, $lat); $dlon = GeoUtil::getLongitudinalDistance(($radius + $accuracy) * 1.25, $lat); $simpleXML = $this->getSimpleXMLFromSource(); $result = array(); $requestedPOI = NULL; $xpathQuery = $this->buildQuery($filter); foreach ($simpleXML->xpath($xpathQuery) as $poiData) { $poi = new POI(); foreach ($poiData->children() as $child) { $nodeName = $child->getName(); if ($nodeName == "action") { $poi->actions[] = new POIAction($child); } else { if ($nodeName == "anchor") { $poi->anchor = new POIAnchor($child); } else { if ($nodeName == "icon") { $poi->icon = new POIIcon($child); } else { if ($nodeName == "object") { $poi->object = new POIObject($child); } else { if ($nodeName == "text") { $poi->text = new POIText($child); } else { if ($nodeName == "transform") { $poi->transform = new POITransform($child); } else { if ($nodeName == "animation") { if (in_array((string) $child, array("drop", "spin", "grow"))) { $poi->animations = (string) $child; } else { $events = (string) $child["events"]; if (!empty($events)) { foreach (array("onCreate", "onUpdate", "onDelete", "onFocus", "onClick") as $event) { if (strpos($events, $event) !== FALSE) { $poi->animations[$event][] = new Animation($child); } } } } } else { switch ($nodeName) { case "dimension": case "type": case "relativeAlt": $value = (int) $child; break; case "showSmallBiw": case "showBiwOnClick": case "doNotIndex": $value = (bool) (string) $child; break; default: $value = (string) $child; break; } $poi->{$nodeName} = $value; } } } } } } } } if (empty($filter)) { $result[] = $poi; } else { if (!empty($filter->requestedPoiId) && $filter->requestedPoiId == $poi->id) { // always return the requested POI at the top of the list to // prevent cutoff by the 50 POI response limit $poi->distance = GeoUtil::getGreatCircleDistance(deg2rad($lat), deg2rad($lon), deg2rad($poi->anchor->geolocation['lat']), deg2rad($poi->anchor->geolocation['lon'])); $requestedPOI = $poi; } else { if ($this->passesFilter($poi, $filter)) { if (empty($radius)) { $poi->distance = GeoUtil::getGreatCircleDistance(deg2rad($lat), deg2rad($lon), deg2rad($poi->anchor->geolocation['lat']), deg2rad($poi->anchor->geolocation['lon'])); $result[] = $poi; } else { // verify if POI falls in bounding box (with 25% margin) /** @todo handle wraparound */ if (isset($poi->anchor->referenceImage)) { $result[] = $poi; } elseif ((double) $poi->anchor->geolocation['lat'] >= $lat - $dlat && $poi->anchor->geolocation['lat'] <= $lat + $dlat && $poi->anchor->geolocation['lon'] >= $lon - $dlon && $poi->anchor->geolocation['lon'] <= $lon + $dlon) { $poi->distance = GeoUtil::getGreatCircleDistance(deg2rad($lat), deg2rad($lon), deg2rad($poi->anchor->geolocation['lat']), deg2rad($poi->anchor->geolocation['lon'])); // filter passed, see if radius allows for inclusion if ($poi->distance < $radius + $accuracy) { $result[] = $poi; } } } } } } } libxml_use_internal_errors($libxmlErrorHandlingState); if (!empty($filter)) { // sort if filter is set $result = objectSort("distance", $result); } if (!empty($requestedPOI)) { // always make sure that the requested POI is the first to be returned array_unshift($result, $requestedPOI); } return $result; }