]> 91.132.146.200 Git - insipid.git/commitdiff
some data loading brain fucks removed
authorBanana <mail@bananas-playground.net>
Mon, 8 Mar 2021 21:54:41 +0000 (22:54 +0100)
committerBanana <mail@bananas-playground.net>
Mon, 8 Mar 2021 21:54:41 +0000 (22:54 +0100)
ChangeLog
TODO
webroot/lib/link.class.php
webroot/lib/management.class.php
webroot/view/home.php
webroot/view/overview.inc.php

index ff1eb159d7eb5b8c8c6ff11cf5b551e036f2bb00..1a0f9d0a28474ac590dfac22e5920dfff86e4954 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
-version 2.5.3 - Hypostyle
+version 2.6 - Hypostyle
+
        + Fixed sql problems with Maria DB. Any_value is not supported there
+       + Fixed some query and data loading brain fucks..
 
 version 2.5.2 - Darkmere (2020-09-12)
 
diff --git a/TODO b/TODO
index d193e30fb517cbd73fe187536a66b5fde5e33af4..76a3096c9704d1ebbde620f972cd78db4518a499 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,9 +1,11 @@
 TODO / Feature list
 + translation support
++ adapt new php 7
+++ http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
+
 + stats cleanup. Management functions should be standalone
 + theme support
 + more "secure" user authentication
 ++ multiple user accounts and stuff
-+ adapt new php 7
-++ http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
 + combine cat and tag class into one.
++ view really still needed?
index 64793d6632282f26b5454c1ccd6f78a89fd0aa32..aa823f0708f18e4027e3d210204e412c923ba72b 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -86,6 +86,7 @@ class Link {
        /**
         * loads only the info needed to display the link
         * for edit use $this->load
+        *
         * @param $hash
         * @return array
         */
@@ -93,7 +94,7 @@ class Link {
                $this->_data = array();
 
                if (!empty($hash)) {
-                       $queryStr = "SELECT `id`,`link`,`description`,`title`,`image`,`hash`
+                       $queryStr = "SELECT `id`,`link`,`description`,`title`,`image`,`hash`, `created`
                                FROM `" . DB_PREFIX . "_link`
                                WHERE `hash` = '" . $this->DB->real_escape_string($hash) . "'";
 
@@ -109,8 +110,21 @@ class Link {
                return $this->_data;
        }
 
+       public function loadFromDataShortInfo($data) {
+               $this->_data = array();
+
+               if(isset($data['id']) && isset($data['link']) && isset($data['created']) && isset($data['status'])
+                       && isset($data['title']) && isset($data['hash']) && isset($data['description']) && isset($data['image'])) {
+                       $this->_data = $data;
+                       $this->_image();
+               }
+
+               return $this->_data;
+       }
+
        /**
         * return all or data for given key on the current loaded link
+        *
         * @param bool $key
         * @return array|mixed
         */
index 2fe8e719178db64dfd9cd6c3c8f17c669ee429ef..e26935480a684f68f9f51b0fb44b5c81fe760b39 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -227,12 +227,12 @@ class Management {
     /**
      * find all links by given category string or id.
      * Return array sorted by creation date DESC
+        *
      * @param int $id Category ID
-     * @param string $string Category as string
      * @param array $options Array with limit|offset|sort|sortDirection
      * @return array
      */
-       public function linksByCategory($id, $string, $options=array()) {
+       public function linksByCategory($id, $options=array()) {
                $ret = array();
 
                if(!isset($options['limit'])) $options['limit'] = 5;
@@ -240,20 +240,17 @@ class Management {
         if(!isset($options['sort'])) $options['sort'] = false;
         if(!isset($options['sortDirection'])) $options['sortDirection'] = false;
 
-               $querySelect = "SELECT ".self::COMBINED_SELECT_VALUES;
-               $queryFrom = " FROM `".DB_PREFIX."_combined` AS t";
+               $querySelect = "SELECT `id`, `link`, `created`, `status`, `title`, `hash`, `description`, `image`";
+               $queryFrom = " FROM `".DB_PREFIX."_link` AS t
+                                               LEFT JOIN insipid_categoryrelation AS cr ON cr.linkid = t.id";
                $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery();
                if(!empty($id) && is_numeric($id)) {
-                       $queryWhere .= " AND t.categoryId = '" . $this->DB->real_escape_string($id) . "'";
-               }
-               elseif(!empty($string) && is_string($string)) {
-                       $queryWhere .= " AND t.category = '" . $this->DB->real_escape_string($string) . "'";
+                       $queryWhere .= " AND cr.categoryId = '" . $this->DB->real_escape_string($id) . "'";
                }
                else {
                        return $ret;
                }
 
-        $queryGroup = " GROUP BY t.hash";
                $queryOrder = " ORDER BY";
                if(!empty($options['sort'])) {
             $queryOrder .= ' t.'.$options['sort'];
@@ -277,12 +274,12 @@ class Management {
                                $queryLimit .= " OFFSET ".$options['offset'];
                        }
                }
-               $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryGroup.$queryOrder.$queryLimit);
+               $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit);
 
                if(!empty($query) && $query->num_rows > 0) {
                        while($result = $query->fetch_assoc()) {
                                $linkObj = new Link($this->DB);
-                               $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
+                               $ret['results'][] = $linkObj->loadFromDataShortInfo($result);
                                unset($linkObj);
                        }
 
@@ -297,12 +294,12 @@ class Management {
     /**
      * find all links by given tag string or id.
      * Return array sorted by creation date DESC
+        *
      * @param int $id Tag id
-     * @param string $string Tag as string
      * @param array $options Array with limit|offset|sort|sortDirection
      * @return array
      */
-       public function linksByTag($id, $string, $options=array()) {
+       public function linksByTag($id, $options=array()) {
                $ret = array();
 
         if(!isset($options['limit'])) $options['limit'] = 5;
@@ -310,20 +307,17 @@ class Management {
         if(!isset($options['sort'])) $options['sort'] = false;
         if(!isset($options['sortDirection'])) $options['sortDirection'] = false;
 
-               $querySelect = "SELECT ".self::COMBINED_SELECT_VALUES;
-               $queryFrom = " FROM `".DB_PREFIX."_combined` AS t";
+               $querySelect = "SELECT `id`, `link`, `created`, `status`, `title`, `hash`, `description`, `image`";
+               $queryFrom = " FROM `".DB_PREFIX."_link` AS t
+                                               LEFT JOIN insipid_tagrelation AS tr ON tr.linkid = t.id";
                $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery();
                if(!empty($id) && is_numeric($id)) {
-                       $queryWhere .= " AND t.tagId = '" . $this->DB->real_escape_string($id) . "'";
-               }
-               elseif(!empty($string) && is_string($string)) {
-                       $queryWhere .= " AND t.tag = '" . $this->DB->real_escape_string($string) . "'";
+                       $queryWhere .= " AND tr.tagId = '".$this->DB->real_escape_string($id)."'";
                }
                else {
                        return $ret;
                }
 
-        $queryGroup = " GROUP BY t.hash";
         $queryOrder = " ORDER BY";
         if(!empty($options['sort'])) {
             $queryOrder .= ' t.'.$options['sort'];
@@ -347,12 +341,12 @@ class Management {
                 $queryLimit .= " OFFSET ".$options['offset'];
             }
         }
-        $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryGroup.$queryOrder.$queryLimit);
+        $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit);
 
                if(!empty($query) && $query->num_rows > 0) {
                        while($result = $query->fetch_assoc()) {
                                $linkObj = new Link($this->DB);
-                               $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
+                               $ret['results'][] = $linkObj->loadFromDataShortInfo($result);
                                unset($linkObj);
                        }
 
@@ -402,6 +396,7 @@ class Management {
 
        /**
         * return the latest added link for given category id
+        *
         * @param int $categoryid
         * @return array
         */
@@ -409,8 +404,9 @@ class Management {
                $ret = array();
 
                if(!empty($categoryid) && is_numeric($categoryid)) {
-                       $queryStr = "SELECT ".self::COMBINED_SELECT_VALUES." 
-                       FROM `".DB_PREFIX."_combined` AS t";
+                       $queryStr = "SELECT `id`, `link`, `created`, `status`, `description`, `title`, `image`, `hash`,
+                                               `tag`, `category`, `categoryId`, `tagId`
+                                               FROM `".DB_PREFIX."_combined` AS t";
                        $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery();
                        $queryStr .= " AND t.categoryId = '" . $this->DB->real_escape_string($categoryid) . "'
                        ORDER BY t.created DESC
index 72fbd04d48884e773ae7ea3e6a503a19e1b79cf7..3a990e186682ce9ef55e28646e981aa4003d5b2f 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
 <?php
        if(!empty($orderedCategories)) {
                foreach ($orderedCategories as $k=>$v) {
-                       $links = $Management->linksByCategory($v['id'],'');
+                       $links = $Management->linksByCategory($v['id']);
 ?>
                <div class="column is-one-quarter">
                        <div class="content">
index 44423b5853b69727cd20a71fa58908ead9f7d39b..9bb53a7dce27deedcaaed74fd81e622721287645 100644 (file)
@@ -3,7 +3,7 @@
  * Insipid
  * Personal web-bookmark-system
  *
- * Copyright 2016-2020 Johannes Keßler
+ * Copyright 2016-2021 Johannes Keßler
  *
  * Development starting from 2011: Johannes Keßler
  * https://www.bananas-playground.net/projekt/insipid/
@@ -98,7 +98,7 @@ switch($_requestMode) {
             $tagname = $tagObj->getData('name');
             $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
 
-                       $linkCollection = $Management->linksByTag($_id,'', $_LinkColllectionQueryOptions);
+                       $linkCollection = $Management->linksByTag($_id, $_LinkColllectionQueryOptions);
 
             $currentGetParameters['id'] = $_id;
                }
@@ -116,7 +116,7 @@ switch($_requestMode) {
             $catname = $catObj->getData('name');
             $subHeadline = $catname.' <i class="ion-md-filing"></i>';
 
-                       $linkCollection = $Management->linksByCategory($_id,'', $_LinkColllectionQueryOptions);
+                       $linkCollection = $Management->linksByCategory($_id, $_LinkColllectionQueryOptions);
 
             $currentGetParameters['id'] = $_id;
                }
@@ -169,4 +169,4 @@ else {
 
 $sortLink['default'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>false,'sd'=>false));
 $sortLink['name'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>'title','sd'=>false));
-$sortLink['direction'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('sd'=>'asc'));
\ No newline at end of file
+$sortLink['direction'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('sd'=>'asc'));