From: Banana Date: Mon, 15 Jul 2019 20:26:16 +0000 (+0200) Subject: code cleanup and sql fixes X-Git-Tag: 2.1-alpha-2019-0-29~20 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=fecb4e18b63869e1fe9d47837d87274f63e8eedf;p=insipid.git code cleanup and sql fixes --- diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index 7f1db08..97ae77e 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -54,8 +54,17 @@ class Link { $this->_data = array(); if(!empty($hash)) { - $queryStr = "SELECT * FROM `".DB_PREFIX."_link` - WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; + $queryStr = "SELECT + any_value(`id`) as id, + any_value(`link`) as link, + any_value(`created`) as created, + any_value(`status`) as status, + any_value(`description`) as description, + any_value(`title`) as title, + any_value(`image`) as image, + any_value(`hash`) as hash + FROM `".DB_PREFIX."_link` + WHERE `hash` = '".$this->DB->real_escape_string($hash)."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows == 1) { $ret = $query->fetch_assoc(); @@ -160,8 +169,10 @@ class Link { $ret = false; if(!empty($link)) { - $queryStr = "SELECT * FROM `".DB_PREFIX."_link` - WHERE `link` = '".$this->DB->real_escape_string($link)."'"; + $queryStr = "SELECT + any_value(`hash`) as hash + FROM `".DB_PREFIX."_link` + WHERE `link` = '".$this->DB->real_escape_string($link)."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { $result = $query->fetch_assoc(); @@ -180,13 +191,15 @@ class Link { $ret = array(); if(!empty($this->_data['hash'])) { - $queryStr = "SELECT DISTINCT(tag) FROM `".DB_PREFIX."_combined` - WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; + $queryStr = "SELECT + DISTINCT(tag) as tag + FROM `".DB_PREFIX."_combined` + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { while($result = $query->fetch_assoc()) { if($result['tag'] !== NULL) { - $ret[] = $result['tag']; + $ret[$result['tag']] = $result['tag']; } } @@ -204,13 +217,14 @@ class Link { $ret = array(); if(!empty($this->_data['hash'])) { - $queryStr = "SELECT DISTINCT(category) FROM `".DB_PREFIX."_combined` - WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; + $queryStr = "SELECT + DISTINCT(category) FROM `".DB_PREFIX."_combined` + WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'"; $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { while($result = $query->fetch_assoc()) { if($result['category'] !== NULL) { - $ret[] = $result['category']; + $ret[$result['category']] = $result['category']; } } } @@ -227,13 +241,15 @@ class Link { if(!empty($this->_data['id'])) { $queryStr = false; if($tagid === false) { - $queryStr = "DELETE FROM `".DB_PREFIX."_tagrelation` - WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; + $queryStr = "DELETE + FROM `".DB_PREFIX."_tagrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; } elseif(is_numeric($tagid)) { - $queryStr = "DELETE FROM `".DB_PREFIX."_tagrelation` - WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' - AND `tagid` = '".$this->DB->real_escape_string($tagid)."'"; + $queryStr = "DELETE + FROM `".DB_PREFIX."_tagrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' + AND `tagid` = '".$this->DB->real_escape_string($tagid)."'"; } if(!empty($queryStr)) { $this->DB->query($queryStr); @@ -249,13 +265,15 @@ class Link { if(!empty($this->_data['id'])) { $queryStr = false; if($categoryid === false) { - $queryStr = "DELETE FROM `".DB_PREFIX."_categoryrelation` - WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; + $queryStr = "DELETE + FROM `".DB_PREFIX."_categoryrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'"; } elseif(is_numeric($categoryid)) { - $queryStr = "DELETE FROM `".DB_PREFIX."_categoryrelation` - WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' - AND `categoryid` = '".$this->DB->real_escape_string($categoryid)."'"; + $queryStr = "DELETE + FROM `".DB_PREFIX."_categoryrelation` + WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."' + AND `categoryid` = '".$this->DB->real_escape_string($categoryid)."'"; } if(!empty($queryStr)) { $this->DB->query($queryStr); diff --git a/webroot/view/home.inc.php b/webroot/view/home.inc.php index afade48..5de9c92 100644 --- a/webroot/view/home.inc.php +++ b/webroot/view/home.inc.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2018 Johannes Keßler + * Copyright 2016-2019 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -61,20 +61,17 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['submitsearch $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"; + $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'; $submitFeedback['status'] = 'error'; } - #var_dump($queryStr); - if(!empty($queryStr)) { $query = $DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { diff --git a/webroot/view/linkinfo.php b/webroot/view/linkinfo.php index 364f90f..3f266b8 100644 --- a/webroot/view/linkinfo.php +++ b/webroot/view/linkinfo.php @@ -112,7 +112,7 @@ if(!empty($linkData['tags'])) { foreach($linkData['tags'] as $k=>$v) { ?> - + @@ -131,7 +131,7 @@ if(!empty($linkData['categories'])) { foreach($linkData['categories'] as $k=>$v) { ?> - + diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index f9850c1..fe903b0 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2017 Johannes Keßler + * Copyright 2016-2019 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ diff --git a/webroot/view/overview.php b/webroot/view/overview.php index 20aa6d6..6eaa928 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -31,13 +31,13 @@