* return the latest addded links
* @param number $limit
*/
- public function latest($limit=5) {
+ public function latestLinks($limit=5) {
$ret = array();
$queryStr = "SELECT * FROM `".DB_PREFIX."_link` WHERE `status` = 2 ORDER BY `created` DESC";
return $ret;
}
- public function all($limit=false) {
+ /**
+ * return all links and Info we have from the combined view
+ * @param int $limit
+ */
+ public function links($limit=false) {
$ret = array();
$queryStr = "SELECT * FROM `".DB_PREFIX."_combined`
return $ret;
}
+
+ /**
+ * for simpler management we have the search data in a seperate column
+ * it is not fancy or even technical nice but it damn works
+ */
+ private function _updateSearchIndex() {
+ $allLinks = array();
+ $queryStr = "SELECT hash FROM `".DB_PREFIX."_link`";
+ $query = $this->DB->query($queryStr);
+ if(!empty($query) && $query->num_rows > 0) {
+ $allLinks = $query->fetch_all(MYSQLI_ASSOC);
+ }
+
+ if(!empty($allLinks)) {
+ foreach($allLinks as $link) {
+ $LinkObj = new Link($this->DB);
+ $l = $LinkObj->load($link['hash']);
+
+ $searchStr = $l['title'];
+ $searchStr .= ' '.$l['description'];
+ foreach($l['tags'] as $t) {
+ $searchStr .= ' '.$t['tag'];
+ }
+ foreach($l['categories'] as $c) {
+ $searchStr .= ' '.$c['category'];
+ }
+
+ # now update the search string
+ $queryStr = "UPDATE `".DB_PREFIX."_link`
+ SET `search` = '".$this->DB->real_escape_string($searchStr)."'
+ WHERE `hash` = '".$this->DB->real_escape_string($link['hash'])."'";
+
+ $this->DB->query($queryStr);
+
+ unset($LinkObj,$l,$searchStr,$t,$c,$queryStr);
+ }
+ }
+
+
+ }
}
?>
\ No newline at end of file
}
elseif(Summoner::validate($searchValue,'text')) {
# search for this in more then one field
-
+ # remove mysql funktion stuff
+ $searchValue = str_replace("*", "", $searchValue);
+ $searchValue = str_replace("+", "", $searchValue);
+ $searchValue = str_replace("-", "", $searchValue);
+ $searchValue = str_replace("<", "", $searchValue);
+ $searchValue = str_replace(">", "", $searchValue);
+ $searchValue = str_replace("~", "", $searchValue);
+ $searchValue = str_replace("'", "", $searchValue);
+ $searchValue = str_replace('"', "", $searchValue);
+
+ $queryStr = "SELECT *, MATCH (search)
+ AGAINST ('*".$DB->real_escape_string($searchValue)."*' IN BOOLEAN MODE) AS score
+ FROM `".DB_PREFIX."_link`
+ WHERE MATCH (search)
+ AGAINST ('*".$DB->real_escape_string($searchValue)."*' IN BOOLEAN MODE)
+ ORDER BY score DESC";
}
else {
$submitFeedback['message'] = 'Invalid input';
if($isUrl === true && !empty($formData['title']) && $username === FRONTEND_USERNAME && $password === FRONTEND_PASSWORD) {
$hash = md5($formData['url']);
+
+ # categories and tag stuff
+ $catArr = Summoner::prepareTagOrCategoryStr($formData['category']);
+ $tagArr = Summoner::prepareTagOrCategoryStr($formData['tag']);
+
+ $search = $formData['title'];
+ $search .= ' '.$formData['description'];
+ $search .= ' '.implode(" ",$tagArr);
+ $search .= ' '.implode(" ",$catArr);
+
$queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_link` SET
`link` = '".$DB->real_escape_string($formData['url'])."',
`created` = NOW(),
`description` = '".$DB->real_escape_string($formData['description'])."',
`title` = '".$DB->real_escape_string($formData['title'])."',
`image` = '".$DB->real_escape_string($formData['image'])."',
- `hash` = '".$DB->real_escape_string($hash)."'";
+ `hash` = '".$DB->real_escape_string($hash)."',
+ `search` = '".$DB->real_escape_string($search)."'";
$DB->query($queryStr);
$linkID = $DB->insert_id;
if(!empty($linkID)) {
- # categories and tag stuff
- $catArr = Summoner::prepareTagOrCategorieStr($formData['category']);
- $tagArr = Summoner::prepareTagOrCategorieStr($formData['tag']);
+
if(!empty($catArr)) {
foreach($catArr as $c) {
$existingCategories = $Management->categories();
$existingTags = $Management->tags();
-$latestLinks = $Management->latest();
+$latestLinks = $Management->latestLinks();
$orderedCategories = $Management->categoriesByDateAdded();
\ No newline at end of file