]> 91.132.146.200 Git - insipid.git/commitdiff
code cleanup and sql fixes
authorBanana <banana@optimus.de>
Mon, 15 Jul 2019 20:26:16 +0000 (22:26 +0200)
committerBanana <banana@optimus.de>
Mon, 15 Jul 2019 20:26:16 +0000 (22:26 +0200)
webroot/lib/link.class.php
webroot/view/home.inc.php
webroot/view/linkinfo.php
webroot/view/overview.inc.php
webroot/view/overview.php

index 7f1db08e768c2732ee1ac79e1545dd078d567254..97ae77e39d45df477d3a5bf01357c098ea6142af 100644 (file)
@@ -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);
index afade485c725a01a5d00e7fbb28052a9a634b890..5de9c924d9cd5aa27b27c7edea06c7d7a30f42a3 100644 (file)
@@ -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) {
index 364f90fb3a493f2ebf3040c2eca36f55724dc1a7..3f266b80695024bf030b91e5ffcface2e2c4d466 100644 (file)
                 if(!empty($linkData['tags'])) {
                      foreach($linkData['tags'] as $k=>$v) {
             ?>
-               <a href="index.php?p=overview&m=tag&id=<?php echo urlencode($v['tag']); ?>" class="button is-small">
+               <a href="index.php?p=overview&m=tag&id=<?php echo urlencode($k); ?>" class="button is-small">
                        <span class="icon"><i class="ion-md-pricetag"></i></span>
                        <span><?php echo $v; ?></span>
                </a>
                 if(!empty($linkData['categories'])) {
                      foreach($linkData['categories'] as $k=>$v) {
             ?>
-               <a href="index.php?p=overview&m=category&id=<?php echo urlencode($v['category']); ?>" class="button is-small">
+               <a href="index.php?p=overview&m=category&id=<?php echo urlencode($k); ?>" class="button is-small">
                        <span class="icon"><i class="ion-md-list"></i></span>
                        <span><?php echo $v; ?></span>
                </a>
index f9850c1860db01a2d7f8e38a10e7d6fec00c45a2..fe903b038b09e2b45f3fc3cbb5b4021a862da6c6 100644 (file)
@@ -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/
index 20aa6d61f8d98615a4a75f8a4d4bf42a00329207..6eaa928c9459989ae74f7da2900e8bb158ee0ff3 100644 (file)
        <div class="columns">
                <div class="column">
                <p class="has-text-right">
-                       <a href="index.php?p=overview&m=tag" title="all tags" class="is-small button">
+                       <a href="index.php?p=overview&m=tag" title="all tags" class="button">
                                <span class="icon"><i class="ion-md-pricetag"></i></span>
                        </a>
-                       <a href="index.php?p=overview&m=category" title="all categories" class="is-small button">
+                       <a href="index.php?p=overview&m=category" title="all categories" class="button">
                                <span class="icon"><i class="ion-md-list"></i></span>
                        </a>
-                       <a href="index.php" title="... back to home" class="is-small button">
+                       <a href="index.php" title="... back to home" class="button">
                                <span class="icon"><i class="ion-md-home"></i></span>
                        </a>
                </p>