Major search overhaul
This commit is contained in:
parent
9f4bc39e55
commit
78ac0574b9
@ -1,27 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
class Entity {
|
abstract class Entity {
|
||||||
protected function __construct() {
|
protected function __construct() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function specify_search($searchterms, $searchfields) {
|
abstract public function matches($term, $ldap);
|
||||||
if(array_key_exists('fritext', $searchterms)) {
|
|
||||||
$freeterm = $searchterms['fritext'];
|
|
||||||
unset($searchterms['fritext']);
|
|
||||||
foreach($searchfields as $field) {
|
|
||||||
if(array_key_exists($field, $searchterms)) {
|
|
||||||
$term = $searchterms[$field];
|
|
||||||
if(is_array($term)) {
|
|
||||||
$term[] = $freeterm;
|
|
||||||
} else {
|
|
||||||
$searchterms[$field] = array($term, $freeterm);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$searchterms[$field] = $freeterm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $searchterms;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -110,58 +110,117 @@ class Product extends Entity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function matches($terms, $matchAll=false) {
|
/*
|
||||||
print('DEBUG $terms in matches: ');
|
Return a list of field-value mappings containing all matching search terms.
|
||||||
var_dump($terms);
|
*/
|
||||||
print('<br><br>');
|
public function matches($terms, $ldap) {
|
||||||
$terms = $this->specify_search($terms, array('brand',
|
|
||||||
'name',
|
|
||||||
'serial',
|
|
||||||
'invoice',
|
|
||||||
'status',
|
|
||||||
'tag'));
|
|
||||||
print('DEBUG $terms POST TRANSLATION: ');
|
|
||||||
var_dump($terms);
|
|
||||||
print('<br><br>');
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
foreach($terms as $field => $values) {
|
|
||||||
if(property_exists($this, $field)) {
|
// Create a list mapping all basic fields to getters
|
||||||
if(match($values, $this->$field)) {
|
$fields = array('brand' => 'get_brand',
|
||||||
$matches[$field] = $this->$field;
|
'name' => 'get_name',
|
||||||
} else {
|
'invoice' => 'get_invoice',
|
||||||
if($matchAll) {
|
'serial' => 'get_serial');
|
||||||
return array();
|
|
||||||
|
foreach($terms as $term) {
|
||||||
|
$key = $term->get_key();
|
||||||
|
$matched = false;
|
||||||
|
switch($key) {
|
||||||
|
case 'brand':
|
||||||
|
case 'name':
|
||||||
|
case 'invoice':
|
||||||
|
case 'serial':
|
||||||
|
// If $key is a standard field, check against its value
|
||||||
|
$getter = $fields[$key];
|
||||||
|
$value = $this->$getter();
|
||||||
|
if(match($term, $value)) {
|
||||||
|
//Record a successful match
|
||||||
|
$matches[$key] = $value;
|
||||||
|
$matched = true;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else if(array_key_exists($field, $this->get_info())) {
|
case 'tag':
|
||||||
if(match($values, $this->get_info()[$field])) {
|
// If $key is tag, iterate over the tags
|
||||||
$matches[$field] = $this->get_info()[$field];
|
$matched_tags = $this->match_tags($term);
|
||||||
} else {
|
if($matched_tags) {
|
||||||
if($matchAll) {
|
// Record a successful match
|
||||||
return array();
|
$matched = true;
|
||||||
}
|
if(!isset($matches['tags'])) {
|
||||||
}
|
// This is the first list of matching tags
|
||||||
} else if($field == 'tag') {
|
$matches['tags'] = $matched_tags;
|
||||||
foreach($this->get_tags() as $tag) {
|
} else {
|
||||||
if(match($values, $tag)) {
|
// Merge these results with existing results
|
||||||
if(!array_key_exists('tags', $matches)) {
|
$matches['tags'] = array_unique(
|
||||||
$matches['tags'] = array();
|
array_merge($matches['tags'],
|
||||||
}
|
$matched_tags));
|
||||||
$matches['tags'][] = $tag;
|
|
||||||
} else {
|
|
||||||
if($matchAll) {
|
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else if($field == 'status') {
|
case 'fritext':
|
||||||
if(match($values, $this->get_status())) {
|
// if $key is fritext:
|
||||||
$matches['status'] = $this->get_status();
|
// First check basic fields
|
||||||
} else {
|
foreach($fields as $field => $getter) {
|
||||||
if($matchAll) {
|
$value = $this->$getter();
|
||||||
return array();
|
if(match($term, $value)) {
|
||||||
|
$matches[$field] = $value;
|
||||||
|
$matched = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// Then tags
|
||||||
|
$matched_tags = $this->match_tags($term);
|
||||||
|
if($matched_tags) {
|
||||||
|
$matched = true;
|
||||||
|
if(!isset($matches['tags'])) {
|
||||||
|
$matches['tags'] = $matched_tags;
|
||||||
|
} else {
|
||||||
|
$matches['tags'] = array_unique(
|
||||||
|
array_merge($matches['tags'],
|
||||||
|
$matched_tags));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Then custom fields
|
||||||
|
foreach($this->get_info() as $field => $value) {
|
||||||
|
if(match($term, $value)) {
|
||||||
|
//Record a successful match
|
||||||
|
$matches[$field] = $value;
|
||||||
|
$matched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Handle custom fields
|
||||||
|
$info = $this->get_info();
|
||||||
|
if(isset($info[$key])) {
|
||||||
|
// If $key is a valid custom field on this product
|
||||||
|
$value = $info[$key];
|
||||||
|
if(match($term, $value)) {
|
||||||
|
//Record a successful match
|
||||||
|
$matches[$key] = $value;
|
||||||
|
$matched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If a mandatory match failed, the entire search has failed
|
||||||
|
// and we return an empty result.
|
||||||
|
if($term->is_mandatory() && !$matched) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
// If a negative match succeeded, the entire search has failed
|
||||||
|
// and we return an empty result.
|
||||||
|
if($term->is_negative() && $matched) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function match_tags($term) {
|
||||||
|
$tags = $this->get_tags();
|
||||||
|
$matches = array();
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
if(match($term, $tag)) {
|
||||||
|
$matches[] = $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $matches;
|
return $matches;
|
||||||
|
@ -28,11 +28,7 @@ class SearchPage extends Page {
|
|||||||
if(!$this->terms) {
|
if(!$this->terms) {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
print('<br>');
|
|
||||||
foreach(array('user', 'product') as $type) {
|
foreach(array('user', 'product') as $type) {
|
||||||
// print('=== DEBUG $type: ');
|
|
||||||
// print_r($type);
|
|
||||||
// print(' ===<br><br>');
|
|
||||||
$result = $this->search($type, $this->terms);
|
$result = $this->search($type, $this->terms);
|
||||||
if($result) {
|
if($result) {
|
||||||
$out[$type] = $result;
|
$out[$type] = $result;
|
||||||
@ -42,148 +38,32 @@ class SearchPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function search($type, $terms) {
|
private function search($type, $terms) {
|
||||||
|
$matches = array();
|
||||||
/*
|
foreach(get_items($type) as $item) {
|
||||||
==================================================
|
if($result = $item->matches($terms, $this->ldap)) {
|
||||||
|
$matches[] = array($item, $result);
|
||||||
ORIGINAL CODE || BACKUP || FOR REFERENCE
|
|
||||||
|
|
||||||
$items = get_items($type);
|
|
||||||
$out = array();
|
|
||||||
foreach($items as $item) {
|
|
||||||
$result = $item->matches($terms);
|
|
||||||
if($result) {
|
|
||||||
$out[] = array($item, $result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $out;
|
return $matches;
|
||||||
|
|
||||||
==================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
$mustMatchArray = array();
|
|
||||||
$cannotMatchArray = array();
|
|
||||||
$mayMatchArray = array();
|
|
||||||
foreach($terms as $key => $value) {
|
|
||||||
if(!is_array($value)) {
|
|
||||||
$value = array($value);
|
|
||||||
}
|
|
||||||
foreach($value as $term) {
|
|
||||||
switch ($term[0]) {
|
|
||||||
case "+":
|
|
||||||
if (!array_key_exists($key, $mustMatchArray)) {
|
|
||||||
$mustMatchArray[$key] = array();
|
|
||||||
}
|
|
||||||
$mustMatchArray[$key][] = substr($term, 1);
|
|
||||||
break;
|
|
||||||
case "!":
|
|
||||||
case "-":
|
|
||||||
if (!array_key_exists($key, $cannotMatchArray)) {
|
|
||||||
$cannotMatchArray[$key] = array();
|
|
||||||
}
|
|
||||||
$cannotMatchArray[$key][] = substr($term, 1);
|
|
||||||
break;
|
|
||||||
case "~":
|
|
||||||
if (!array_key_exists($key, $mayMatchArray)) {
|
|
||||||
$mayMatchArray[$key] = array();
|
|
||||||
}
|
|
||||||
$mayMatchArray[$key][] = substr($term, 1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!array_key_exists($key, $mayMatchArray)) {
|
|
||||||
$mayMatchArray[$key] = array();
|
|
||||||
}
|
|
||||||
$mayMatchArray[$key][] = $term;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$items = get_items($type);
|
|
||||||
$sanitizedItems = array();
|
|
||||||
foreach($items as $item) {
|
|
||||||
$result = $item->matches($mustMatchArray, True);
|
|
||||||
if($result) {
|
|
||||||
$sanitizedItems[] = array($item, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// $mustMatchCheck = array();
|
|
||||||
// foreach($mustMatchArray as $mustMatchTerm) {
|
|
||||||
|
|
||||||
// $matchResult = $item->matches($mustMatchTerm);
|
|
||||||
// if($matchResult) {
|
|
||||||
// $mustMatchCheck[] = True;
|
|
||||||
// } else {
|
|
||||||
// $mustMatchCheck[] = False;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if(in_array(False, $mustMatchCheck, True) === False) {
|
|
||||||
// $sanitizedItems[] = array($item, $matchResult);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $mustExcludeCheck = array();
|
|
||||||
// foreach($mustExcludeArray as $mustExcludeTerm) {
|
|
||||||
// if($item->matches($mustExcludeTerm)) {
|
|
||||||
// $mustExcludeCheck[] = False;
|
|
||||||
// } else {
|
|
||||||
// $mustExcludeCheck[] = True;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (in_array(False, $mustIncludeCheck, True) === False) {
|
|
||||||
// if(in_array(False, $mustExcludeCheck, True) === True) {
|
|
||||||
|
|
||||||
// // === IF TRUE DO NOTHING ===
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// foreach ($canIncludeArray as $canIncludeTerm) {
|
|
||||||
// $result = $item->matches($canIncludeTerm);
|
|
||||||
// if($result) {
|
|
||||||
// $out[] = array($item, $result);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
print('DEBUG $sanitizedItems: ');
|
|
||||||
var_dump($sanitizedItems);
|
|
||||||
print('<br><br>');
|
|
||||||
// $out = array();
|
|
||||||
// foreach($sanitizedItems as $sanitizedItem) {
|
|
||||||
// print('DEBUG $sanitizedItem: ');
|
|
||||||
// var_dump($sanitizedItem);
|
|
||||||
// print('<br><br>');
|
|
||||||
|
|
||||||
// if($sanitizedItem->matches($cannotMatchArray)) {
|
|
||||||
|
|
||||||
// // === IF TRUE DO NOTHING ===
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// $result = $sanitizedItem->matches($mayMatchArray);
|
|
||||||
// if($result) {
|
|
||||||
// $out[] = array($sanitizedItem, $result);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return array();
|
|
||||||
// return $out;
|
|
||||||
return $sanitizedItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translate_terms($terms) {
|
private function translate_terms($terms) {
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
||||||
|
// If there is a q-query
|
||||||
|
// and it contains a : character
|
||||||
if(isset($terms['q']) && preg_match('/([^:]+):(.*)/',
|
if(isset($terms['q']) && preg_match('/([^:]+):(.*)/',
|
||||||
$terms['q'],
|
$terms['q'],
|
||||||
$matches)) {
|
$matches)) {
|
||||||
|
// remove the q key
|
||||||
unset($terms['q']);
|
unset($terms['q']);
|
||||||
|
// insert the term, using whatever came before
|
||||||
|
// the : as the key and whatever came after as the value
|
||||||
$terms[$matches[1]] = $matches[2];
|
$terms[$matches[1]] = $matches[2];
|
||||||
}
|
}
|
||||||
$translated = array();
|
$translated = array();
|
||||||
foreach($terms as $key => $value) {
|
// Translate all keys into a standard format
|
||||||
|
foreach($terms as $key => $values) {
|
||||||
$newkey = $key;
|
$newkey = $key;
|
||||||
switch($key) {
|
switch($key) {
|
||||||
case 'q':
|
case 'q':
|
||||||
@ -204,17 +84,38 @@ class SearchPage extends Page {
|
|||||||
$newkey = 'serial';
|
$newkey = 'serial';
|
||||||
break;
|
break;
|
||||||
case 'tagg':
|
case 'tagg':
|
||||||
|
case 'tags':
|
||||||
$newkey = 'tag';
|
$newkey = 'tag';
|
||||||
break;
|
break;
|
||||||
|
case 'anteckning':
|
||||||
|
$newkey = 'note';
|
||||||
|
break;
|
||||||
|
case 'e-post':
|
||||||
|
case 'epost':
|
||||||
|
case 'mail':
|
||||||
|
$newkey = 'email';
|
||||||
|
break;
|
||||||
case 'status':
|
case 'status':
|
||||||
$value = $this->translate_values($value);
|
// Translate all status values into a standard format
|
||||||
|
$values = $this->translate_values($values);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!array_key_exists($newkey, $translated)) {
|
// Wrap the value in an array if it isn't one
|
||||||
$translated[$newkey] = $value;
|
if(!is_array($values)) {
|
||||||
} else {
|
$values = array($values);
|
||||||
$temp = $translated[$newkey];
|
}
|
||||||
$translated[$newkey] = array_merge((array)$temp, (array)$value);
|
// Make a SearchTerm object from each term
|
||||||
|
foreach($values as $value) {
|
||||||
|
// Check for flags
|
||||||
|
$flag = SearchTerm::OPTIONAL;
|
||||||
|
if(in_array($value[0], array(SearchTerm::MANDATORY,
|
||||||
|
SearchTerm::OPTIONAL,
|
||||||
|
SearchTerm::NEGATIVE))) {
|
||||||
|
$flag = $value[0];
|
||||||
|
$value = substr($value, 1);
|
||||||
|
}
|
||||||
|
// Collect the new SearchTerm
|
||||||
|
$translated[] = new SearchTerm($key, $value, $flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $translated;
|
return $translated;
|
||||||
@ -270,16 +171,15 @@ class SearchPage extends Page {
|
|||||||
$terms = '';
|
$terms = '';
|
||||||
if($this->terms) {
|
if($this->terms) {
|
||||||
$hidden = '';
|
$hidden = '';
|
||||||
foreach($this->terms as $key => $value) {
|
foreach($this->terms as $term) {
|
||||||
if(!is_array($value)) {
|
$key = $term->get_key();
|
||||||
$value = array($value);
|
$flag = $term->get_flag();
|
||||||
}
|
$query = $term->get_query();
|
||||||
foreach($value as $item) {
|
$fullterm = ucfirst($key).": ".$flag.$query;
|
||||||
$terms .= replace(array('term' => ucfirst($key).": $item",
|
$terms .= replace(array('term' => $fullterm,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $item),
|
'value' => $flag.$query),
|
||||||
$this->fragments['search_term']);
|
$this->fragments['search_term']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$products = 'Inga artiklar hittade.';
|
$products = 'Inga artiklar hittade.';
|
||||||
@ -327,4 +227,53 @@ class SearchPage extends Page {
|
|||||||
. $data . '<br/>';
|
. $data . '<br/>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SearchTerm {
|
||||||
|
public const MANDATORY = '+';
|
||||||
|
public const OPTIONAL = '~';
|
||||||
|
public const NEGATIVE = '-';
|
||||||
|
|
||||||
|
private $key;
|
||||||
|
private $query;
|
||||||
|
private $flag;
|
||||||
|
|
||||||
|
public function __construct($key, $query, $flag=SearchTerm::OPTIONAL) {
|
||||||
|
$this->key = $key;
|
||||||
|
$this->query = $query;
|
||||||
|
$this->flag = $flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_key() {
|
||||||
|
return $this->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_query() {
|
||||||
|
return $this->query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_flag() {
|
||||||
|
return $this->flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_optional() {
|
||||||
|
if($this->flag == SearchTerm::OPTIONAL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_mandatory() {
|
||||||
|
if($this->flag == SearchTerm::MANDATORY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_negative() {
|
||||||
|
if($this->flag == SearchTerm::NEGATIVE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -45,37 +45,60 @@ class User extends Entity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function matches($terms, $ldap, $matchAll=false) {
|
public function matches($terms, $ldap) {
|
||||||
$terms = $this->specify_search($terms, array('name',
|
|
||||||
'email',
|
|
||||||
'notes'));
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
foreach($terms as $field => $values) {
|
foreach($terms as $term) {
|
||||||
switch($field) {
|
// Iterate over the terms
|
||||||
|
$matched = false;
|
||||||
|
$key = $term->get_key();
|
||||||
|
switch($key) {
|
||||||
case 'name':
|
case 'name':
|
||||||
if(match($values, $this->name)) {
|
// If the key is name, check username and displayname
|
||||||
$matches['name'] = $this->name;
|
$name = $this->get_name();
|
||||||
|
if(match($term, $name)) {
|
||||||
|
$matches['name'] = $name;
|
||||||
|
$matched = true;
|
||||||
}
|
}
|
||||||
$dname = $this->get_displayname($ldap);
|
$dname = $this->get_displayname($ldap);
|
||||||
if(match($values, $dname)) {
|
if(match($term, $dname)) {
|
||||||
$matches['displayname'] = $dname;
|
$matches['displayname'] = $dname;
|
||||||
|
$matched = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'note':
|
||||||
|
// If the key is note, check it.
|
||||||
|
$note = $this->get_note();
|
||||||
|
if($note && match($term, $note)) {
|
||||||
|
$matches['note'] = $note;
|
||||||
|
$matched = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
$email = $this->get_email($ldap, false);
|
$email = $this->get_email($ldap, false);
|
||||||
if($email && match($values, $email)) {
|
if($email && match($term, $email)) {
|
||||||
$matches['email'] = $email;
|
$matches['email'] = $email;
|
||||||
|
$matched = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'notes':
|
case 'fritext':
|
||||||
if(match($values, $this->notes)) {
|
//Check everything if the key is fritext
|
||||||
$matches['notes'] = $this->notes;
|
$name = $this->get_name();
|
||||||
|
if(match($term, $name)) {
|
||||||
|
$matches['name'] = $name;
|
||||||
|
$matched = true;
|
||||||
|
}
|
||||||
|
$dname = $this->get_displayname($ldap);
|
||||||
|
if(match($term, $dname)) {
|
||||||
|
$matches['displayname'] = $dname;
|
||||||
|
$matched = true;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if($term->is_mandatory() && !$matched) {
|
||||||
if($matchAll && array_diff_assoc($terms, $matches)) {
|
return array();
|
||||||
return array();
|
}
|
||||||
|
if($term->is_negative() && $matched) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
@ -253,18 +253,23 @@ function suggest_content($fieldname) {
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function match($searchterms, $subject) {
|
function match($term, $subject) {
|
||||||
if(!is_array($searchterms)) {
|
if(fnmatch('*'.$term->get_query().'*', $subject, FNM_CASEFOLD)) {
|
||||||
$searchterms = array($searchterms);
|
return true;
|
||||||
}
|
|
||||||
foreach($searchterms as $term) {
|
|
||||||
if(fnmatch('*'.$term.'*', $subject, FNM_CASEFOLD)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function match_tags($searchterm, $tags) {
|
||||||
|
$found = array();
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
if(fnmatch('*'.$tag.'*', $searchterm, FNM_CASEFOLD)) {
|
||||||
|
$found[] = $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $found;
|
||||||
|
}
|
||||||
|
|
||||||
function format_date($date) {
|
function format_date($date) {
|
||||||
if($date) {
|
if($date) {
|
||||||
return gmdate('Y-m-d', $date);
|
return gmdate('Y-m-d', $date);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user