/** * Prepare search filter */ public function prepareSearchFilter($h, $search, $return = 'posts') { $search_terms = strtolower($search); $search_terms = explode(" ", $search_terms); $search_terms = array_iunique($search_terms); $search_terms_clean = ''; $full_text = true; // Do a full text (better) search if all terms are longer than 3 characters foreach ($search_terms as $search_term) { if ($this->isStopword($search_term)) { continue; // don't include this in $search_terms_clean } if (strlen(trim($search_term)) < 4) { $full_text = false; } $search_term = trim($h->db->escape($search_term)); // if the urlencoded term contains a percent sign, we can't use a full text search if (strpos(urlencode($search_term), '%') !== false) { $full_text = false; } $search_terms_clean .= $search_term . " "; } // To prevent sql dieing when nothing is being search for if (!$search_terms_clean) { $h->messages[$h->lang['search_search_word_error']] = 'alert-info'; return array(); // return a blank array so extract doesnt get upset } // Undo the filter that limits results to either 'top', 'new' or archived (See submit.php -> sub_prepare_list()) if (isset($h->vars['filter']['post_status = %s'])) { unset($h->vars['filter']['post_status = %s']); } if (isset($h->vars['filter']['post_archived = %s'])) { unset($h->vars['filter']['post_archived = %s']); } // filter to top or new stories only: $h->vars['filter']['(post_status = %s OR post_status = %s)'] = array('top', 'new'); $select = $return == 'count' ? "count(*) AS number " : "*"; if ($full_text) { $h->vars['select'] = array($select . ", MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s) AS relevance" => trim($search_terms_clean)); $h->vars['orderby'] = "relevance DESC"; $h->vars['filter']["MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s IN BOOLEAN MODE)"] = trim($search_terms_clean); } else { $h->vars['select'] = $select; $h->vars['orderby'] = "post_date DESC"; $h->vars['filter_vars'] = array(); $where = $this->explodeSearch($h, 'post_title', $search_terms_clean) . " OR "; $where .= $this->explodeSearch($h, 'post_url', $search_terms_clean) . " OR "; $where .= $this->explodeSearch($h, 'post_content', $search_terms_clean); $where = '(' . $where . ')'; $h->vars['filter'][$where] = $h->vars['filter_vars']; } $prepared_search = array('select' => $h->vars['select'], 'orderby' => $h->vars['orderby'], 'filter' => $h->vars['filter']); return $prepared_search; }
/** * This function takes a list (array) of tags and changes any tags that have aliases * * @param string[] $tags Array of tags * @return array */ public static function resolve_aliases($tags) { assert('is_array($tags)'); $new = array(); $i = 0; $tag_count = count($tags); while ($i < $tag_count) { $aliases = explode(' ', Tag::resolve_alias($tags[$i])); foreach ($aliases as $alias) { if (!in_array($alias, $new)) { if ($tags[$i] == $alias) { $new[] = $alias; } elseif (!in_array($alias, $tags)) { $tags[] = $alias; $tag_count++; } } } $i++; } $new = array_iunique($new); // remove any duplicate tags return $new; }
public static function resolve_list($tags) { $tags = Tag::explode($tags); $new = array(); foreach ($tags as $tag) { $new_set = explode(' ', Tag::resolve_alias($tag)); foreach ($new_set as $new_one) { $new[] = $new_one; } } $new = array_map(array('Tag', 'sanitise'), $new); $new = array_iunique($new); // remove any duplicate tags return $new; }
//add manufacturers $hwman_new = array_iunique($hwman_new, SORT_STRING); foreach ($hwman_new as $hwm) { $hwm = ucfirst($hwm); $sql = "INSERT into agents (type,title) VALUEs ('8',:hwm)"; $stmt = db_execute2($dbh, $sql, array('hwm' => $hwm)); } //add users $user_new = array_iunique($user_new, SORT_STRING); foreach ($user_new as $usr) { $usr = strtolower($usr); $sql = "INSERT into users (username,usertype) VALUEs (:usr,1)"; $stmt = db_execute2($dbh, $sql, array('usr' => $usr)); } //item types $itypes_new = array_iunique($itypes_new, SORT_STRING); foreach ($itypes_new as $itype) { $itype = strtolower($itype); $sql = "INSERT into itemtypes (typedesc,hassoftware) VALUEs (:itype,1)"; $stmt = db_execute2($dbh, $sql, array('itype' => $itype)); } //addlocations/locareas foreach ($loc_new as $loca) { $location = $loca['loc']; $locarea = $loca['area']; //insert location if not already there $sql = "INSERT INTO locations (name)\n SELECT :location WHERE NOT EXISTS (SELECT 1 FROM locations WHERE name = :location)"; $stmt = db_execute2($dbh, $sql, array('location' => $location)); //insert locareaid $lr = getlocidsbynames($location, $locarea); if ($lr[0] < 0 && strlen($locarea)) {
echo stripcslashes(htmlspecialchars_decode($album)); ?> </h3> <?php } else { ?> <h3><?php echo stripcslashes(htmlspecialchars_decode($album)); ?> </h3> <?php } } } if (!empty($tags_array) && $filters_setting == 1 && $widget == "" && $gallery_type != "slideshow") { $tags = array_iunique($tags_array); ?> <div class="thumbs-fluid-layout"> <div class="gallery-bank-filter" style="margin-bottom: 60px;"> <div class="gallery-bank-filter-categories" id="bank_filters_<?php echo $unique_id; ?> "> <a href="#" id="gallery_filter_<?php echo $unique_id; ?> " class="act" data-filter="*"><?php _e("VIEW ALL", gallery_bank); ?> </a><?php foreach ($tags as $key => $value) {
/** * Prepare search filter */ public function prepareSearchFilter($h, $search, $return = 'posts') { $search_terms = strtolower($search); $search_terms = explode(" ", $search_terms); $search_terms = array_iunique($search_terms); $search_terms_clean = ''; $full_index = true; // Do a full index (better) search if all terms are longer than 3 characters foreach ($search_terms as $search_term) { if ($this->isStopword($search_term)) { continue; // don't include this in $search_terms_clean } if (strlen(trim($search_term)) < 4) { $full_index = false; } if ($this->isStopword($search_term) == false) { $search_terms_clean .= trim($h->db->escape($search_term)) . " "; } } // Undo the filter that limits results to either 'top', 'new' or archived (See submit.php -> sub_prepare_list()) if (isset($h->vars['filter']['post_status = %s'])) { unset($h->vars['filter']['post_status = %s']); } if (isset($h->vars['filter']['post_archived = %s'])) { unset($h->vars['filter']['post_archived = %s']); } // filter to top or new stories only: $h->vars['filter']['(post_status = %s OR post_status = %s)'] = array('top', 'new'); if ($full_index) { if ($return == 'count') { $select = "count(*) AS number "; } else { $select = "*"; } $h->vars['select'] = $select . ", MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST ('" . $search_terms_clean . "') AS relevance"; $h->vars['orderby'] = "relevance DESC"; $h->vars['filter']["MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s IN BOOLEAN MODE)"] = $search_terms_clean; } else { if ($return == 'count') { $select = "count(*) AS number "; } else { $select = "*"; } $h->vars['select'] = $select; $h->vars['orderby'] = "post_date DESC"; $h->vars['filter_vars'] = array(); $where = $this->explodeSearch($h, 'post_title', $search_terms_clean) . " OR "; $where .= $this->explodeSearch($h, 'post_url', $search_terms_clean) . " OR "; $where .= $this->explodeSearch($h, 'post_content', $search_terms_clean); $where = '(' . $where . ')'; $h->vars['filter'][$where] = $h->vars['filter_vars']; } $prepared_search = array('select' => $h->vars['select'], 'orderby' => $h->vars['orderby'], 'filter' => $h->vars['filter']); return $prepared_search; }