]> 91.132.146.200 Git - insipid.git/commitdiff
code cleanup
authorBanana <banana@ironhide>
Tue, 23 Jul 2019 19:22:03 +0000 (21:22 +0200)
committerBanana <banana@ironhide>
Tue, 23 Jul 2019 19:22:03 +0000 (21:22 +0200)
webroot/lib/category.class.php
webroot/lib/link.class.php
webroot/lib/management.class.php
webroot/lib/simple-imap.class.php
webroot/lib/summoner.class.php
webroot/lib/tag.class.php
webroot/view/editlink.php
webroot/view/home.inc.php

index 197d222572d049767cc71645a3c30ffa54b43ce3..db216f892af79af36f184595ae92f99f388be49e 100644 (file)
  */
 
 class Category {
-    /**
-     * the database object
-     * @var object
-     */
-    private $DB;
+       /**
+        * the database object
+        * @var object
+        */
+       private $DB;
 
-    /**
-     * the current loaded category by DB id
-     * @var int
-     */
-    private $id;
+       /**
+        * the current loaded category by DB id
+        * @var int
+        */
+       private $id;
 
-    public function __construct($databaseConnectionObject) {
-        $this->DB = $databaseConnectionObject;
-    }
+       public function __construct($databaseConnectionObject) {
+               $this->DB = $databaseConnectionObject;
+       }
 
-    /**
-     * by given string load the info from the DB and even create if not existing
-     * @param string $string
-     */
-    public function initbystring($string) {
-        $this->id = false;
-        if(!empty($string)) {
-            $queryStr = "SELECT id FROM `".DB_PREFIX."_category`
-                            WHERE `name` = '".$this->DB->real_escape_string($string)."'";
-            $query = $this->DB->query($queryStr);
-            if(!empty($query) && $query->num_rows > 0) {
-                $result = $query->fetch_assoc();
-                $this->id = $result['id'];
-            }
-            else {
-                $queryStr = "INSERT INTO `".DB_PREFIX."_category`
-                                SET `name` = '".$this->DB->real_escape_string($string)."'";
-                $this->DB->query($queryStr);
-                if(!empty($this->DB->insert_id)) {
-                    $this->id = $this->DB->insert_id;
-                }
-            }
-        }
-    }
+       /**
+        * by given string load the info from the DB and even create if not existing
+        * @param string $string
+        */
+       public function initbystring($string) {
+               $this->id = false;
+               if(!empty($string)) {
+                       $queryStr = "SELECT id FROM `".DB_PREFIX."_category`
+                                                       WHERE `name` = '".$this->DB->real_escape_string($string)."'";
+                       $query = $this->DB->query($queryStr);
+                       if(!empty($query) && $query->num_rows > 0) {
+                               $result = $query->fetch_assoc();
+                               $this->id = $result['id'];
+                       }
+                       else {
+                               $queryStr = "INSERT INTO `".DB_PREFIX."_category`
+                                                               SET `name` = '".$this->DB->real_escape_string($string)."'";
+                               $this->DB->query($queryStr);
+                               if(!empty($this->DB->insert_id)) {
+                                       $this->id = $this->DB->insert_id;
+                               }
+                       }
+               }
+       }
 
-    /**
-     * by given DB table id load all the info we need
-     * @param int $id
-     */
-    public function initbyid($id) {
-        if(!empty($id)) {
-            $this->id = $id;
-        }
-    }
+       /**
+        * by given DB table id load all the info we need
+        * @param int $id
+        */
+       public function initbyid($id) {
+               if(!empty($id)) {
+                       $this->id = $id;
+               }
+       }
 
-    /**
-     * set the relation to the given link to the loaded category
-     * @param int $linkid
-     * @return void
-     */
-    public function setRelation($linkid) {
-        if(!empty($linkid) && !empty($this->id)) {
-            $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_categoryrelation`
-                            SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
-                                `categoryid` = '".$this->DB->real_escape_string($this->id)."'";
-            $this->DB->query($queryStr);
-        }
-    }
+       /**
+        * set the relation to the given link to the loaded category
+        * @param int $linkid
+        * @return void
+        */
+       public function setRelation($linkid) {
+               if(!empty($linkid) && !empty($this->id)) {
+                       $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_categoryrelation`
+                                                       SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
+                                                               `categoryid` = '".$this->DB->real_escape_string($this->id)."'";
+                       $this->DB->query($queryStr);
+               }
+       }
 }
- ?>
\ No newline at end of file
index df36008972bf020299260899e437d4e40573119b..8cecbf4397293d6a42e168f8b8752a8b70d9dc95 100644 (file)
@@ -121,7 +121,7 @@ class Link {
         $this->DB->query($queryStr);
         if($returnId === true) {
                $ret = $this->DB->insert_id;
-        }                
+        }
 
                return $ret;
        }
@@ -146,6 +146,8 @@ class Link {
                        $search .= ' '.implode(" ",$tagArr);
                        $search .= ' '.implode(" ",$catArr);
 
+                       $this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
                        # did the image url change?
                        $_imageUrlChanged = false;
                        if($this->_data['image'] != $data['image']) {
@@ -162,41 +164,48 @@ class Link {
 
                        $query = $this->DB->query($queryStr);
 
-                       $catObj = new Category($this->DB);
-                       $tagObj = new Tag($this->DB);
-                       // clean the relations first
-                       $this->_removeTagRelation(false);
-                       $this->_removeCategoryRelation(false);
-
-                       if(!empty($catArr)) {
-                               foreach($catArr as $c) {
-                                       $catObj->initbystring($c);
-                                       $catObj->setRelation($this->_data['id']);
+                       if($query !== false) {
+                               $catObj = new Category($this->DB);
+                               $tagObj = new Tag($this->DB);
+                               // clean the relations first
+                               $this->_removeTagRelation(false);
+                               $this->_removeCategoryRelation(false);
+
+                               if(!empty($catArr)) {
+                                       foreach($catArr as $c) {
+                                               $catObj->initbystring($c);
+                                               $catObj->setRelation($this->_data['id']);
+                                       }
                                }
-                       }
-                       if(!empty($tagArr)) {
-                               foreach($tagArr as $t) {
-                                       $tagObj->initbystring($t);
-                                       $tagObj->setRelation($this->_data['id']);
+                               if(!empty($tagArr)) {
+                                       foreach($tagArr as $t) {
+                                               $tagObj->initbystring($t);
+                                               $tagObj->setRelation($this->_data['id']);
+                                       }
                                }
-                       }
 
-                       # decide to store or remove the image
-                       if(isset($data['localImage'])) {
-                               $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
-                               if($data['localImage'] === true) {
-                                       if(!file_exists($image) || $_imageUrlChanged === true) {
-                                               Summoner::downloadFile($data['image'],$image);
+                               # decide to store or remove the image
+                               if(isset($data['localImage'])) {
+                                       $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
+                                       if($data['localImage'] === true) {
+                                               if(!file_exists($image) || $_imageUrlChanged === true) {
+                                                       Summoner::downloadFile($data['image'],$image);
+                                               }
                                        }
-                               }
-                               elseif($data['localImage'] === false) {
-                                       if(file_exists($image)) {
-                                               unlink($image);
+                                       elseif($data['localImage'] === false) {
+                                               if(file_exists($image)) {
+                                                       unlink($image);
+                                               }
                                        }
                                }
+
+                               $this->DB->commit();
+                               $ret = true;
+                       }
+                       else {
+                               $this->DB->rollback();
                        }
 
-                       $ret = true;
                }
 
                return $ret;
@@ -212,7 +221,7 @@ class Link {
                $ret = false;
 
                if(!empty($link)) {
-                       $queryStr = "SELECT 
+                       $queryStr = "SELECT
                                any_value(`hash`) as hash
                                FROM `".DB_PREFIX."_link`
                                WHERE `link` = '".$this->DB->real_escape_string($link)."'";
@@ -234,7 +243,7 @@ class Link {
                $ret = array();
 
                if(!empty($this->_data['hash'])) {
-                       $queryStr = "SELECT 
+                       $queryStr = "SELECT
                                DISTINCT(tag) as tag
                                FROM `".DB_PREFIX."_combined`
                                WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'";
@@ -260,7 +269,7 @@ class Link {
                $ret = array();
 
                if(!empty($this->_data['hash'])) {
-                       $queryStr = "SELECT 
+                       $queryStr = "SELECT
                                DISTINCT(category) FROM `".DB_PREFIX."_combined`
                                WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'";
                        $query = $this->DB->query($queryStr);
@@ -284,12 +293,12 @@ class Link {
                if(!empty($this->_data['id'])) {
                        $queryStr = false;
                        if($tagid === false) {
-                               $queryStr = "DELETE 
+                               $queryStr = "DELETE
                                        FROM `".DB_PREFIX."_tagrelation`
                                        WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'";
                        }
                        elseif(is_numeric($tagid)) {
-                               $queryStr = "DELETE 
+                               $queryStr = "DELETE
                                        FROM `".DB_PREFIX."_tagrelation`
                                        WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'
                                        AND `tagid` = '".$this->DB->real_escape_string($tagid)."'";
@@ -308,7 +317,7 @@ class Link {
                if(!empty($this->_data['id'])) {
                        $queryStr = false;
                        if($categoryid === false) {
-                               $queryStr = "DELETE 
+                               $queryStr = "DELETE
                                        FROM `".DB_PREFIX."_categoryrelation`
                                        WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'";
                        }
index 7f62b55809167aaa983c50bad02e051f265ae325..f66f8da1e2e158b4bb8b21f5fdb911edf6ee1fb9 100644 (file)
  */
 
 class Management {
-    /**
-     * the database object
-     * @var object
-     */
-    private $DB;
-
-    protected $COMBINED_SELECT_VALUES = "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,
-                               any_value(`tag`) as tag,
-                               any_value(`category`) as category,
-                               any_value(`categoryId`) as categoryId,
-                               any_value(`tagId`) as tagId";
-
-    public function __construct($databaseConnectionObject) {
-        $this->DB = $databaseConnectionObject;
-    }
+       /**
+        * the database object
+        * @var object
+        */
+       private $DB;
+
+       protected $COMBINED_SELECT_VALUES = "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,
+                               any_value(`tag`) as tag,
+                               any_value(`category`) as category,
+                               any_value(`categoryId`) as categoryId,
+                               any_value(`tagId`) as tagId";
+
+       public function __construct($databaseConnectionObject) {
+               $this->DB = $databaseConnectionObject;
+       }
 
        /**
         * get all the available categories from the DB.
@@ -58,15 +58,15 @@ class Management {
         * @param bool $stats
         * @return array
         */
-    public function categories($limit=false, $stats=false) {
-        $ret = array();
+       public function categories($limit=false, $stats=false) {
+               $ret = array();
                $statsInfo = array();
 
                if($stats === true) {
-                       $queryStr = "SELECT 
+                       $queryStr = "SELECT
                                COUNT(*) as amount,
                                any_value(categoryid) as categoryId
-                               FROM `".DB_PREFIX."_categoryrelation` 
+                               FROM `".DB_PREFIX."_categoryrelation`
                                GROUP BY categoryid";
                        $query = $this->DB->query($queryStr);
                        if(!empty($query)) {
@@ -76,28 +76,28 @@ class Management {
                        }
                }
 
-        $queryStr = "SELECT
-                       any_value(`id`) as id,
-                       any_value(`name`) as name
-                       FROM `".DB_PREFIX."_category` 
-                       ORDER BY `name` ASC";
-        if(!empty($limit)) {
-            $queryStr .= " LIMIT $limit";
-        }
-        $query = $this->DB->query($queryStr);
-        if(!empty($query)) {
-               while($result = $query->fetch_assoc()) {
-                       if($stats === true) {
+               $queryStr = "SELECT
+                       any_value(`id`) as id,
+                       any_value(`name`) as name
+                       FROM `".DB_PREFIX."_category`
+                       ORDER BY `name` ASC";
+               if(!empty($limit)) {
+                       $queryStr .= " LIMIT $limit";
+               }
+               $query = $this->DB->query($queryStr);
+               if(!empty($query)) {
+                       while($result = $query->fetch_assoc()) {
+                               if($stats === true) {
                                        $ret[$result['id']] = array('name' => $result['name'], 'amount' => $statsInfo[$result['id']]);
                                }
                                else {
                                        $ret[$result['id']] = array('name' => $result['name']);
                                }
                        }
-        }
+               }
 
-        return $ret;
-    }
+               return $ret;
+       }
 
        /**
         * get all the available tags from the DB.
@@ -107,15 +107,15 @@ class Management {
         * @param bool $stats
         * @return array
         */
-    public function tags($limit=false, $stats=false) {
-        $ret = array();
+       public function tags($limit=false, $stats=false) {
+               $ret = array();
                $statsInfo = array();
 
                if($stats === true) {
-                       $queryStr = "SELECT 
+                       $queryStr = "SELECT
                                COUNT(*) as amount,
                                any_value(`tagid`) as tagId
-                               FROM `".DB_PREFIX."_tagrelation` 
+                               FROM `".DB_PREFIX."_tagrelation`
                                GROUP BY tagId";
                        $query = $this->DB->query($queryStr);
                        if(!empty($query)) {
@@ -125,16 +125,16 @@ class Management {
                        }
                }
 
-        $queryStr = "SELECT
-               any_value(`id`) as id,
-                       any_value(`name`) as name
-                       FROM `".DB_PREFIX."_tag` 
-                       ORDER BY `name` ASC";
-        if(!empty($limit)) {
-            $queryStr .= " LIMIT $limit";
-        }
-        $query = $this->DB->query($queryStr);
-        if(!empty($query)) {
+               $queryStr = "SELECT
+                       any_value(`id`) as id,
+                       any_value(`name`) as name
+                       FROM `".DB_PREFIX."_tag`
+                       ORDER BY `name` ASC";
+               if(!empty($limit)) {
+                       $queryStr .= " LIMIT $limit";
+               }
+               $query = $this->DB->query($queryStr);
+               if(!empty($query)) {
                        while($result = $query->fetch_assoc()) {
                                if($stats === true) {
                                        $ret[$result['id']] = array('name' => $result['name'], 'amount' => $statsInfo[$result['id']]);
@@ -143,50 +143,50 @@ class Management {
                                        $ret[$result['id']] = array('name' => $result['name']);
                                }
                        }
-        }
+               }
 
-        return $ret;
-    }
+               return $ret;
+       }
 
        /**
         * return the latest added links
         * @param int $limit
         * @return array
         */
-    public function latestLinks($limit=5) {
-        $ret = array();
-
-        $queryStr = "SELECT * FROM `".DB_PREFIX."_link` WHERE `status` = 2 ORDER BY `created` DESC";
-        if(!empty($limit)) {
-            $queryStr .= " LIMIT $limit";
-        }
-        $query = $this->DB->query($queryStr);
-        if(!empty($query) && $query->num_rows > 0) {
-            $ret = $query->fetch_all(MYSQLI_ASSOC);
-        }
-
-        return $ret;
-    }
-
-    /**
-     * get all the categories ordered by link added date
-     */
-    public function categoriesByDateAdded() {
-        $ret = array();
-
-        $categories = $this->categories();
-        foreach($categories as $k=>$v) {
+       public function latestLinks($limit=5) {
+               $ret = array();
+
+               $queryStr = "SELECT * FROM `".DB_PREFIX."_link` WHERE `status` = 2 ORDER BY `created` DESC";
+               if(!empty($limit)) {
+                       $queryStr .= " LIMIT $limit";
+               }
+               $query = $this->DB->query($queryStr);
+               if(!empty($query) && $query->num_rows > 0) {
+                       $ret = $query->fetch_all(MYSQLI_ASSOC);
+               }
+
+               return $ret;
+       }
+
+       /**
+        * get all the categories ordered by link added date
+        */
+       public function categoriesByDateAdded() {
+               $ret = array();
+
+               $categories = $this->categories();
+               foreach($categories as $k=>$v) {
                        $latestLink = $this->latestLinkForCategory($k);
                        if(!empty($latestLink)) {
                                array_push($ret, array('created' => $latestLink[0]['created'], 'id' => $k, 'name' => $v['name']));
                        }
-        }
+               }
 
                $_created  = array_column($ret, 'created');
                array_multisort($_created, SORT_DESC, $ret);
 
-        return $ret;
-    }
+               return $ret;
+       }
 
        /**
         * find all links by given category string or id.
@@ -196,12 +196,12 @@ class Management {
         * @param int $limit
         * @return array
         */
-    public function linksByCategory($id,$string,$limit=5) {
-        $ret = array();
+       public function linksByCategory($id,$string,$limit=5) {
+               $ret = array();
 
-        $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
+               $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
                        FROM `".DB_PREFIX."_combined`
-            WHERE `status` = 2";
+                       WHERE `status` = 2";
                if(!empty($id) && is_numeric($id)) {
                        $queryStr .= " AND `categoryId` = '" . $this->DB->real_escape_string($id) . "'";
                }
@@ -213,17 +213,17 @@ class Management {
                }
 
                $queryStr .= "GROUP BY `hash`
-            ORDER BY `created` DESC";
-        if(!empty($limit)) {
-            $queryStr .= " LIMIT $limit";
-        }
-        $query = $this->DB->query($queryStr);
-        if(!empty($query) && $query->num_rows > 0) {
-            $ret = $query->fetch_all(MYSQLI_ASSOC);
-        }
-
-        return $ret;
-    }
+                       ORDER BY `created` DESC";
+               if(!empty($limit)) {
+                       $queryStr .= " LIMIT $limit";
+               }
+               $query = $this->DB->query($queryStr);
+               if(!empty($query) && $query->num_rows > 0) {
+                       $ret = $query->fetch_all(MYSQLI_ASSOC);
+               }
+
+               return $ret;
+       }
 
        /**
         * find all links by given tag string or id.
@@ -233,12 +233,12 @@ class Management {
         * @param int $limit
         * @return array
         */
-    public function linksByTag($id,$string,$limit=5) {
-        $ret = array();
+       public function linksByTag($id,$string,$limit=5) {
+               $ret = array();
 
                $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
                        FROM `".DB_PREFIX."_combined`
-            WHERE `status` = 2";
+                       WHERE `status` = 2";
                if(!empty($id) && is_numeric($id)) {
                        $queryStr .= " AND `tagId` = '" . $this->DB->real_escape_string($id) . "'";
                }
@@ -250,99 +250,99 @@ class Management {
                }
 
                $queryStr .= "GROUP BY `hash`
-            ORDER BY `created` DESC";
-        if(!empty($limit)) {
-            $queryStr .= " LIMIT $limit";
-        }
-        $query = $this->DB->query($queryStr);
-        if(!empty($query) && $query->num_rows > 0) {
-            $ret = $query->fetch_all(MYSQLI_ASSOC);
-        }
-
-        return $ret;
-    }
+                       ORDER BY `created` DESC";
+               if(!empty($limit)) {
+                       $queryStr .= " LIMIT $limit";
+               }
+               $query = $this->DB->query($queryStr);
+               if(!empty($query) && $query->num_rows > 0) {
+                       $ret = $query->fetch_all(MYSQLI_ASSOC);
+               }
+
+               return $ret;
+       }
 
        /**
         * return all links and Info we have from the combined view
         * @param bool | int $limit
         * @return array
         */
-    public function links($limit=false) {
-        $ret = array();
+       public function links($limit=false) {
+               $ret = array();
 
-        $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
+               $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
                        FROM `".DB_PREFIX."_combined`
-            WHERE `status` = 2
-            GROUP BY `hash`
-            ORDER BY `created` DESC";
-        $query = $this->DB->query($queryStr);
-        if(!empty($query) && $query->num_rows > 0) {
-            $ret = $query->fetch_all(MYSQLI_ASSOC);
-        }
+                       WHERE `status` = 2
+                       GROUP BY `hash`
+                       ORDER BY `created` DESC";
+               $query = $this->DB->query($queryStr);
+               if(!empty($query) && $query->num_rows > 0) {
+                       $ret = $query->fetch_all(MYSQLI_ASSOC);
+               }
 
-        return $ret;
-    }
+               return $ret;
+       }
 
        /**
         * return the latest added link for given category id
         * @param int $categoryid
         * @return array
         */
-    public function latestLinkForCategory($categoryid) {
-       $ret = array();
+       public function latestLinkForCategory($categoryid) {
+               $ret = array();
 
-       if(!empty($categoryid) && is_numeric($categoryid)) {
+               if(!empty($categoryid) && is_numeric($categoryid)) {
                        $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES."
                        FROM `".DB_PREFIX."_combined`
-            WHERE `status` = 2
-            AND `categoryId` = '" . $this->DB->real_escape_string($categoryid) . "' 
-            ORDER BY `created` DESC
-            LIMIT 1";
+                       WHERE `status` = 2
+                       AND `categoryId` = '" . $this->DB->real_escape_string($categoryid) . "'
+                       ORDER BY `created` DESC
+                       LIMIT 1";
                        $query = $this->DB->query($queryStr);
                        if(!empty($query) && $query->num_rows > 0) {
                                $ret = $query->fetch_all(MYSQLI_ASSOC);
                        }
                }
-       return $ret;
+               return $ret;
        }
 
-    /**
-     * for simpler management we have the search data in a separate 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);
-            }
-        }
-    }
+       /**
+        * for simpler management we have the search data in a separate 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);
+                       }
+               }
+       }
 }
 
 ?>
index 59e6551bb8a611470182ec7a56d8a3b6b16bc49a..1869742df08bbd9533eb5fc5b63460674d83c8f3 100644 (file)
@@ -228,5 +228,3 @@ class SimpleImap {
            imap_close($this->_connection);
        }
 }
-
-?>
\ No newline at end of file
index 6400cecdde63b34d1f5e22630844b7a61474bee2..576df0122a4f7f6e6e585358f8edbf4bbaffd388 100644 (file)
@@ -460,5 +460,3 @@ class Summoner {
                return $ret;
        }
 }
-
-?>
index ccf4eae71f27814b76001230bbe3a06f30233283..b15f749a45368336e1d369483558c1ae8e1c0c18 100644 (file)
  */
 
 class Tag {
-    /**
-     * the database object
-     * @var object
-     */
-    private $DB;
+       /**
+        * the database object
+        * @var object
+        */
+       private $DB;
 
-    /**
-     * the current loaded tag by DB id
-     * @var int
-     */
-    private $id;
+       /**
+        * the current loaded tag by DB id
+        * @var int
+        */
+       private $id;
 
-    public function __construct($databaseConnectionObject) {
-        $this->DB = $databaseConnectionObject;
-    }
+       public function __construct($databaseConnectionObject) {
+               $this->DB = $databaseConnectionObject;
+       }
 
-    /**
-     * by given string load the info from the DB and even create if not existing
-     * @param string $string
-     */
-    public function initbystring($string) {
-        $this->id = false;
-        if(!empty($string)) {
-            $queryStr = "SELECT id FROM `".DB_PREFIX."_tag`
-                            WHERE `name` = '".$this->DB->real_escape_string($string)."'";
-            $query = $this->DB->query($queryStr);
-            if(!empty($query) && $query->num_rows > 0) {
-                $result = $query->fetch_assoc();
-                $this->id = $result['id'];
-            }
-            else {
-                $queryStr = "INSERT INTO `".DB_PREFIX."_tag`
-                                SET `name` = '".$this->DB->real_escape_string($string)."'";
-                $this->DB->query($queryStr);
-                if(!empty($this->DB->insert_id)) {
-                    $this->id = $this->DB->insert_id;
-                }
-            }
-        }
-    }
+       /**
+        * by given string load the info from the DB and even create if not existing
+        * @param string $string
+        */
+       public function initbystring($string) {
+               $this->id = false;
+               if(!empty($string)) {
+                       $queryStr = "SELECT id FROM `".DB_PREFIX."_tag`
+                                                       WHERE `name` = '".$this->DB->real_escape_string($string)."'";
+                       $query = $this->DB->query($queryStr);
+                       if(!empty($query) && $query->num_rows > 0) {
+                               $result = $query->fetch_assoc();
+                               $this->id = $result['id'];
+                       }
+                       else {
+                               $queryStr = "INSERT INTO `".DB_PREFIX."_tag`
+                                                               SET `name` = '".$this->DB->real_escape_string($string)."'";
+                               $this->DB->query($queryStr);
+                               if(!empty($this->DB->insert_id)) {
+                                       $this->id = $this->DB->insert_id;
+                               }
+                       }
+               }
+       }
 
-    /**
-     * by given DB table id load all the info we need
-     * @param int $id
-     */
-    public function initbyid($id) {
-        if(!empty($id)) {
-            $this->id = $id;
-        }
-    }
+       /**
+        * by given DB table id load all the info we need
+        * @param int $id
+        */
+       public function initbyid($id) {
+               if(!empty($id)) {
+                       $this->id = $id;
+               }
+       }
 
-    /**
-     * set the relation to the given link to the loaded tag
-     * @param int $linkid
-     * @return boolean
-     */
-    public function setRelation($linkid) {
-        if(!empty($linkid) && !empty($this->id)) {
-            $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_tagrelation`
-                            SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
-                                `tagid` = '".$this->DB->real_escape_string($this->id)."'";
-            $this->DB->query($queryStr);
-        }
-    }
+       /**
+        * set the relation to the given link to the loaded tag
+        * @param int $linkid
+        * @return boolean
+        */
+       public function setRelation($linkid) {
+               if(!empty($linkid) && !empty($this->id)) {
+                       $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_tagrelation`
+                                                       SET `linkid` = '".$this->DB->real_escape_string($linkid)."',
+                                                               `tagid` = '".$this->DB->real_escape_string($this->id)."'";
+                       $this->DB->query($queryStr);
+               }
+       }
 }
- ?>
\ No newline at end of file
index f3676a2b0ec090829dd4d1e042adc1ece556b9a8..84bf049f07124abae0988e05878c114900fcb628 100644 (file)
@@ -26,7 +26,6 @@
  *
  */
 ?>
-
 <section class="section">
 <?php if(empty($linkData)) { ?>
        <div class="columns">
index de1321e1882f97ea0d2a390976e673af846d15a4..118df57892e6a163531db89c4acd5cc2ad6c2412 100644 (file)
@@ -36,153 +36,153 @@ $formData = false;
 $honeypotCheck = false;
 
 if((isset($_POST['password']) && !empty($_POST['password'])) || (isset($_POST['username']) && !empty($_POST['username']))) {
-    # those are hidden fields. A robot may input these. A valid user does not.
-    $honeypotCheck = true;
+       # those are hidden fields. A robot may input these. A valid user does not.
+       $honeypotCheck = true;
 }
 
 # search or new one.
 if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['submitsearch']) && $honeypotCheck === false) {
-    $searchValue = trim($_POST['data']['searchfield']);
-    $isUrl = Summoner::validate($searchValue,'url');
-    if($isUrl === true) {
-        # search for URL
-        $queryStr = "SELECT * FROM `".DB_PREFIX."_link`
-                        WHERE `link` = '".$DB->real_escape_string($searchValue)."'";
-    }
-    elseif(Summoner::validate($searchValue,'text')) {
-        $queryStr = "SELECT *, 
-               MATCH (`search`) AGAINST ('".$DB->real_escape_string($searchValue)."' IN BOOLEAN MODE) AS score
+       $searchValue = trim($_POST['data']['searchfield']);
+       $isUrl = Summoner::validate($searchValue,'url');
+       if($isUrl === true) {
+               # search for URL
+               $queryStr = "SELECT * FROM `".DB_PREFIX."_link`
+                                               WHERE `link` = '".$DB->real_escape_string($searchValue)."'";
+       }
+       elseif(Summoner::validate($searchValue,'text')) {
+               $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';
-    }
-
-    if(!empty($queryStr)) {
-        $query = $DB->query($queryStr);
-        if(!empty($query) && $query->num_rows > 0) {
-            $searchResult = $query->fetch_all(MYSQLI_ASSOC);
-        }
-    }
-
-    # new one?
-    if(empty($searchResult) && $isUrl === true) {
-        # try to gather some information automatically
-        $linkInfo = Summoner::gatherInfoFromURL($searchValue);
-        if(!empty($linkInfo)) {
-            if(isset($linkInfo['description'])) {
-                $formData['description'] = $linkInfo['description'];
-            }
-            if(isset($linkInfo['title'])) {
-                $formData['title'] = $linkInfo['title'];
-            }
-            if(isset($linkInfo['image'])) {
-                $formData['image'] = $linkInfo['image'];
-            }
-        }
-        # show the add form
-        $showAddForm = true;
-        $formData['url'] = $searchValue;
-    }
-    elseif(!empty($searchResult)) {
-        # something has been found
-    }
-    else {
-        # nothing found
-        $submitFeedback['message'] = 'Nothing found...';
-        $submitFeedback['status'] = 'error';
-    }
+       }
+       else {
+               $submitFeedback['message'] = 'Invalid input';
+               $submitFeedback['status'] = 'error';
+       }
+
+       if(!empty($queryStr)) {
+               $query = $DB->query($queryStr);
+               if(!empty($query) && $query->num_rows > 0) {
+                       $searchResult = $query->fetch_all(MYSQLI_ASSOC);
+               }
+       }
+
+       # new one?
+       if(empty($searchResult) && $isUrl === true) {
+               # try to gather some information automatically
+               $linkInfo = Summoner::gatherInfoFromURL($searchValue);
+               if(!empty($linkInfo)) {
+                       if(isset($linkInfo['description'])) {
+                               $formData['description'] = $linkInfo['description'];
+                       }
+                       if(isset($linkInfo['title'])) {
+                               $formData['title'] = $linkInfo['title'];
+                       }
+                       if(isset($linkInfo['image'])) {
+                               $formData['image'] = $linkInfo['image'];
+                       }
+               }
+               # show the add form
+               $showAddForm = true;
+               $formData['url'] = $searchValue;
+       }
+       elseif(!empty($searchResult)) {
+               # something has been found
+       }
+       else {
+               # nothing found
+               $submitFeedback['message'] = 'Nothing found...';
+               $submitFeedback['status'] = 'error';
+       }
 }
 
 # add a new one
 if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['addnewone']) && $honeypotCheck === false) {
-    $fData = $_POST['data'];
-
-    # very simple security check.
-    # can/should be extended in the future.
-    Summoner::simpleAuth();
-
-    $formData['private'] = 2;
-    if(isset($fData['private'])) {
-        $formData['private'] = 1;
-    }
-
-    $formData['url'] = trim($fData['url']);
-    $formData['description'] = trim($fData['description']);
-    $formData['title'] = trim($fData['title']);
-    $formData['image'] = trim($fData['image']);
-    $formData['category'] = trim($fData['category']);
-    $formData['tag'] = trim($fData['tag']);
-
-    $isUrl = Summoner::validate($formData['url'],'url');
-
-    if($isUrl === true && !empty($formData['title'])) {
-        $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);
-
-        $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
-
-        $linkObj = new Link($DB);
-        $linkID = $linkObj->create(array(
-            'hash' => $hash,
-            'search' => $search,
-            'link' => $formData['url'],
-            'status' => $formData['private'],
-            'description' => $formData['description'],
-            'title' => $formData['title'],
-            'image' => $formData['image']
-        ),true);
-
-        if(!empty($linkID)) {
-
-            if(!empty($catArr)) {
-                foreach($catArr as $c) {
-                    $catObj = new Category($DB);
-                    $catObj->initbystring($c);
-                    $catObj->setRelation($linkID);
-
-                    unset($catObj);
-                }
-            }
-            if(!empty($tagArr)) {
-                foreach($tagArr as $t) {
-                    $tagObj = new Tag($DB);
-                    $tagObj->initbystring($t);
-                    $tagObj->setRelation($linkID);
-
-                    unset($tagObj);
-                }
-            }
-
-            $DB->commit();
-
-            $submitFeedback['message'] = 'Link added successfully.';
-            $submitFeedback['status'] = 'success';
-            $TemplateData['refresh'] = 'index.php?p=linkinfo&id='.$hash;
-        }
-        else {
-            $DB->rollback();
-            $submitFeedback['message'] = 'Something went wrong...';
-            $submitFeedback['status'] = 'error';
-            $showAddForm = true;
-        }
-    }
-    else {
-        $submitFeedback['message'] = 'Please provide a valid URL and title.';
-        $submitFeedback['status'] = 'error';
-        $showAddForm = true;
-    }
+       $fData = $_POST['data'];
+
+       # very simple security check.
+       # can/should be extended in the future.
+       Summoner::simpleAuth();
+
+       $formData['private'] = 2;
+       if(isset($fData['private'])) {
+               $formData['private'] = 1;
+       }
+
+       $formData['url'] = trim($fData['url']);
+       $formData['description'] = trim($fData['description']);
+       $formData['title'] = trim($fData['title']);
+       $formData['image'] = trim($fData['image']);
+       $formData['category'] = trim($fData['category']);
+       $formData['tag'] = trim($fData['tag']);
+
+       $isUrl = Summoner::validate($formData['url'],'url');
+
+       if($isUrl === true && !empty($formData['title'])) {
+               $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);
+
+               $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
+               $linkObj = new Link($DB);
+               $linkID = $linkObj->create(array(
+                       'hash' => $hash,
+                       'search' => $search,
+                       'link' => $formData['url'],
+                       'status' => $formData['private'],
+                       'description' => $formData['description'],
+                       'title' => $formData['title'],
+                       'image' => $formData['image']
+               ),true);
+
+               if(!empty($linkID)) {
+
+                       if(!empty($catArr)) {
+                               foreach($catArr as $c) {
+                                       $catObj = new Category($DB);
+                                       $catObj->initbystring($c);
+                                       $catObj->setRelation($linkID);
+
+                                       unset($catObj);
+                               }
+                       }
+                       if(!empty($tagArr)) {
+                               foreach($tagArr as $t) {
+                                       $tagObj = new Tag($DB);
+                                       $tagObj->initbystring($t);
+                                       $tagObj->setRelation($linkID);
+
+                                       unset($tagObj);
+                               }
+                       }
+
+                       $DB->commit();
+
+                       $submitFeedback['message'] = 'Link added successfully.';
+                       $submitFeedback['status'] = 'success';
+                       $TemplateData['refresh'] = 'index.php?p=linkinfo&id='.$hash;
+               }
+               else {
+                       $DB->rollback();
+                       $submitFeedback['message'] = 'Something went wrong...';
+                       $submitFeedback['status'] = 'error';
+                       $showAddForm = true;
+               }
+       }
+       else {
+               $submitFeedback['message'] = 'Please provide a valid URL and title.';
+               $submitFeedback['status'] = 'error';
+               $showAddForm = true;
+       }
 }
 
 $existingCategories = $Management->categories();