]> 91.132.146.200 Git - insipid.git/commitdiff
moved status check out of class from object. Moderation of links via stats page....
authorBanana <banana@optimus.de>
Sat, 26 Oct 2019 10:21:01 +0000 (12:21 +0200)
committerBanana <banana@optimus.de>
Sat, 26 Oct 2019 10:21:01 +0000 (12:21 +0200)
ChangeLog
webroot/lib/link.class.php
webroot/lib/management.class.php
webroot/view/_displaySubmitStatus.inc.php
webroot/view/_foot.php
webroot/view/editlink.inc.php
webroot/view/editlink.php
webroot/view/linkinfo.inc.php
webroot/view/overview.inc.php
webroot/view/overview.php
webroot/view/stats.php

index e34389aa2a3a31ea46f08f15f7b470ac3141fd44..efc8c7629b54beab245824a8530bec13a7bdda6e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,11 @@ version 2.2alpha - Guardian of Ice - (tba)
        * code cleanups
        * using mysql transactions if needed
        * pagination
+       * authentication with an extra url now (index.php?m=auth)
+       * management actions shown only if authenticated
+       * small stats overview
+       * links can now be deleted...
+       * awaiting moderation links can new be moderated
 
 version 2.1alpha - Guardian of Fire - (2019-09-29)
 
index 70eb1690ae0121736b63a92b7f018477e69c1e73..fa09003b3c958e59fdb20b011f4e7c6b7f4e59b0 100644 (file)
@@ -26,7 +26,9 @@
  *
  */
 
-class Link {
+class Link
+{
+
        /**
         * the database object
         * @var object
@@ -39,36 +41,22 @@ class Link {
         */
        private $_data;
 
-       /**
-        * Show private links too
-        * @var bool
-        */
-       private $_showPrivate = false;
-
-       public function __construct($databaseConnectionObject) {
+       public function __construct($databaseConnectionObject)
+       {
                $this->DB = $databaseConnectionObject;
        }
 
-       /**
-        * Show private links or not
-        * @param $bool
-        */
-       public function setShowPrivate($bool) {
-               if(is_bool($bool)) {
-                       $this->_showPrivate = $bool;
-               }
-       }
-
        /**
         * load all the info we have about a link by given hash
         * @param string $hash
         * @return mixed
         */
-       public function load($hash) {
+       public function load($hash)
+       {
 
                $this->_data = array();
 
-               if(!empty($hash)) {
+               if (!empty($hash)) {
                        $queryStr = "SELECT
                                any_value(`id`) as id,
                                any_value(`link`) as link,
@@ -79,16 +67,10 @@ class Link {
                                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)."'";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " AND `status` IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " AND `status` = 2";
-                       }
+                               FROM `" . DB_PREFIX . "_link`
+                               WHERE `hash` = '" . $this->DB->real_escape_string($hash) . "'";
                        $query = $this->DB->query($queryStr);
-                       if(!empty($query) && $query->num_rows == 1) {
+                       if (!empty($query) && $query->num_rows == 1) {
                                $this->_data = $query->fetch_assoc();
 
                                # add stuff
@@ -108,10 +90,11 @@ class Link {
         * @param $hash
         * @return array
         */
-       public function loadShortInfo($hash) {
+       public function loadShortInfo($hash)
+       {
                $this->_data = array();
 
-               if(!empty($hash)) {
+               if (!empty($hash)) {
                        $queryStr = "SELECT
                                any_value(`id`) as id,
                                any_value(`link`) as link,
@@ -119,16 +102,11 @@ class Link {
                                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)."'";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " AND `status` IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " AND `status` = 2";
-                       }
+                               FROM `" . DB_PREFIX . "_link`
+                               WHERE `hash` = '" . $this->DB->real_escape_string($hash) . "'";
+
                        $query = $this->DB->query($queryStr);
-                       if(!empty($query) && $query->num_rows == 1) {
+                       if (!empty($query) && $query->num_rows == 1) {
                                $this->_data = $query->fetch_assoc();
 
                                # add stuff
@@ -140,14 +118,15 @@ class Link {
        }
 
        /**
-        * return all or data fpr given key on the current loaded link
+        * return all or data for given key on the current loaded link
         * @param bool $key
         * @return array|mixed
         */
-       public function getData($key=false) {
+       public function getData($key = false)
+       {
                $ret = $this->_data;
 
-               if(!empty($key) && isset($this->_data[$key])) {
+               if (!empty($key) && isset($this->_data[$key])) {
                        $ret = $this->_data[$key];
                }
 
@@ -157,7 +136,8 @@ class Link {
        /**
         * reload the current id from DB
         */
-       public function reload() {
+       public function reload()
+       {
                $this->load($this->_data['hash']);
        }
 
@@ -166,27 +146,28 @@ class Link {
         * @param array $data
         * @return boolean|int
         */
-       public function create($data,$returnId=false) {
+       public function create($data, $returnId = false)
+       {
                $ret = false;
 
-               if(!isset($data['link']) || empty($data['link'])) return false;
-               if(!isset($data['hash']) || empty($data['hash'])) return false;
-               if(!isset($data['title']) || empty($data['title'])) return false;
+               if (!isset($data['link']) || empty($data['link'])) return false;
+               if (!isset($data['hash']) || empty($data['hash'])) return false;
+               if (!isset($data['title']) || empty($data['title'])) return false;
 
-               $queryStr = "INSERT INTO `".DB_PREFIX."_link` SET
-                        `link` = '".$this->DB->real_escape_string($data['link'])."',
+               $queryStr = "INSERT INTO `" . DB_PREFIX . "_link` SET
+                        `link` = '" . $this->DB->real_escape_string($data['link']) . "',
                         `created` = NOW(),
-                        `status` = '".$this->DB->real_escape_string($data['status'])."',
-                        `description` = '".$this->DB->real_escape_string($data['description'])."',
-                        `title` = '".$this->DB->real_escape_string($data['title'])."',
-                        `image` = '".$this->DB->real_escape_string($data['image'])."',
-                        `hash` = '".$this->DB->real_escape_string($data['hash'])."',
-                        `search` = '".$this->DB->real_escape_string($data['search'])."'";
-
-        $this->DB->query($queryStr);
-        if($returnId === true) {
-               $ret = $this->DB->insert_id;
-        }
+                        `status` = '" . $this->DB->real_escape_string($data['status']) . "',
+                        `description` = '" . $this->DB->real_escape_string($data['description']) . "',
+                        `title` = '" . $this->DB->real_escape_string($data['title']) . "',
+                        `image` = '" . $this->DB->real_escape_string($data['image']) . "',
+                        `hash` = '" . $this->DB->real_escape_string($data['hash']) . "',
+                        `search` = '" . $this->DB->real_escape_string($data['search']) . "'";
+
+               $this->DB->query($queryStr);
+               if ($returnId === true) {
+                       $ret = $this->DB->insert_id;
+               }
 
                return $ret;
        }
@@ -196,69 +177,69 @@ class Link {
         * @param array $data
         * @return boolean|int
         */
-       public function update($data) {
+       public function update($data)
+       {
 
                $ret = false;
 
-               if(isset($data['title']) && !empty($data['title'])) {
+               if (isset($data['title']) && !empty($data['title'])) {
 
                        # categories and tag stuff
                        $catArr = Summoner::prepareTagOrCategoryStr($data['category']);
                        $tagArr = Summoner::prepareTagOrCategoryStr($data['tag']);
 
                        $search = $data['title'];
-                       $search .= ' '.$data['description'];
-                       $search .= ' '.implode(" ",$tagArr);
-                       $search .= ' '.implode(" ",$catArr);
+                       $search .= ' ' . $data['description'];
+                       $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']) {
+                       if ($this->_data['image'] != $data['image']) {
                                $_imageUrlChanged = true;
                        }
 
-                       $queryStr = "UPDATE `".DB_PREFIX."_link` SET
-                                                       `status` = '".$this->DB->real_escape_string($data['private'])."',
-                                                       `description` = '".$this->DB->real_escape_string($data['description'])."',
-                                                       `title` = '".$this->DB->real_escape_string($data['title'])."',
-                                                       `image` = '".$this->DB->real_escape_string($data['image'])."',
-                                                       `search` = '".$this->DB->real_escape_string($search)."'
-                                                 WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'";
+                       $queryStr = "UPDATE `" . DB_PREFIX . "_link` SET
+                                                       `status` = '" . $this->DB->real_escape_string($data['private']) . "',
+                                                       `description` = '" . $this->DB->real_escape_string($data['description']) . "',
+                                                       `title` = '" . $this->DB->real_escape_string($data['title']) . "',
+                                                       `image` = '" . $this->DB->real_escape_string($data['image']) . "',
+                                                       `search` = '" . $this->DB->real_escape_string($search) . "'
+                                                 WHERE `hash` = '" . $this->DB->real_escape_string($this->_data['hash']) . "'";
 
                        $query = $this->DB->query($queryStr);
 
-                       if($query !== false) {
+                       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) {
+                               if (!empty($catArr)) {
+                                       foreach ($catArr as $c) {
                                                $catObj->initbystring($c);
                                                $catObj->setRelation($this->_data['id']);
                                        }
                                }
-                               if(!empty($tagArr)) {
-                                       foreach($tagArr as $t) {
+                               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);
+                               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)) {
+                                       } elseif ($data['localImage'] === false) {
+                                               if (file_exists($image)) {
                                                        unlink($image);
                                                }
                                        }
@@ -266,8 +247,7 @@ class Link {
 
                                $this->DB->commit();
                                $ret = true;
-                       }
-                       else {
+                       } else {
                                $this->DB->rollback();
                        }
 
@@ -280,18 +260,19 @@ class Link {
         * load all the tags we have to the already loaded link
         * needs $this->load called first
         */
-       private function _tags() {
+       private function _tags()
+       {
                $ret = array();
 
-               if(!empty($this->_data['hash'])) {
+               if (!empty($this->_data['hash'])) {
                        $queryStr = "SELECT
                                DISTINCT tag, tagId
-                               FROM `".DB_PREFIX."_combined`
-                               WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'";
+                               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) {
+                       if (!empty($query) && $query->num_rows > 0) {
+                               while ($result = $query->fetch_assoc()) {
+                                       if ($result['tag'] !== NULL) {
                                                $ret[$result['tagId']] = $result['tag'];
                                        }
                                }
@@ -306,18 +287,19 @@ class Link {
         * load all the categories we have to the already loaded link
         * needs $this->load called first
         */
-       private function _categories() {
+       private function _categories()
+       {
                $ret = array();
 
-               if(!empty($this->_data['hash'])) {
+               if (!empty($this->_data['hash'])) {
                        $queryStr = "SELECT
                                DISTINCT category, categoryId
-                               FROM `".DB_PREFIX."_combined`
-                               WHERE `hash` = '".$this->DB->real_escape_string($this->_data['hash'])."'";
+                               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) {
+                       if (!empty($query) && $query->num_rows > 0) {
+                               while ($result = $query->fetch_assoc()) {
+                                       if ($result['category'] !== NULL) {
                                                $ret[$result['categoryId']] = $result['category'];
                                        }
                                }
@@ -331,21 +313,21 @@ class Link {
         * remove all or given tag relation to the current loaded link
         * @param mixed $tagid
         */
-       private function _removeTagRelation($tagid) {
-               if(!empty($this->_data['id'])) {
+       private function _removeTagRelation($tagid)
+       {
+               if (!empty($this->_data['id'])) {
                        $queryStr = false;
-                       if($tagid === false) {
+                       if ($tagid === false) {
                                $queryStr = "DELETE
-                                       FROM `".DB_PREFIX."_tagrelation`
-                                       WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'";
-                       }
-                       elseif(is_numeric($tagid)) {
+                                       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)."'";
+                                       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)) {
+                       if (!empty($queryStr)) {
                                $this->DB->query($queryStr);
                        }
                }
@@ -355,21 +337,21 @@ class Link {
         * remove all or given category relation to the current loaded link
         * @param mixed $categoryid
         */
-       private function _removeCategoryRelation($categoryid) {
-               if(!empty($this->_data['id'])) {
+       private function _removeCategoryRelation($categoryid)
+       {
+               if (!empty($this->_data['id'])) {
                        $queryStr = false;
-                       if($categoryid === false) {
+                       if ($categoryid === false) {
                                $queryStr = "DELETE
-                                       FROM `".DB_PREFIX."_categoryrelation`
-                                       WHERE `linkid` = '".$this->DB->real_escape_string($this->_data['id'])."'";
-                       }
-                       elseif(is_numeric($categoryid)) {
+                                       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)."'";
+                                       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)) {
+                       if (!empty($queryStr)) {
                                $this->DB->query($queryStr);
                        }
                }
@@ -379,12 +361,13 @@ class Link {
         * determine of we have a local stored image
         * if so populate the localImage attribute
         */
-       private function _image() {
-               if(!empty($this->_data['hash'])) {
+       private function _image()
+       {
+               if (!empty($this->_data['hash'])) {
                        $this->_data['imageToShow'] = $this->_data['image'];
-                       $image = ABSOLUTE_PATH.'/'.LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
-                       if(file_exists($image)) {
-                               $this->_data['imageToShow'] = LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
+                       $image = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/thumbnail-' . $this->_data['hash'];
+                       if (file_exists($image)) {
+                               $this->_data['imageToShow'] = LOCAL_STORAGE . '/thumbnail-' . $this->_data['hash'];
                                $this->_data['localImage'] = true;
                        }
                }
@@ -393,10 +376,10 @@ class Link {
        /**
         * check if the status is private and set the info
         */
-       private function _private() {
-               if(!empty($this->_data['status']) && $this->_data['status'] == "1") {
+       private function _private()
+       {
+               if (!empty($this->_data['status']) && $this->_data['status'] == "1") {
                        $this->_data['private'] = "1";
                }
        }
 }
-
index 07ad6c4cf1ef6b327eae093f3ebd10c05ff64880..cc63c9de914aea74a105db91d7525349075ea7ab 100644 (file)
  */
 
 class Management {
-       /**
-        * the database object
-        * @var object
-        */
-       private $DB;
 
-       /**
-        * Show private links too
-        * @var bool
-        */
-       private $_showPrivate = false;
+       const LINK_QUERY_STATUS = 2;
 
-       protected $COMBINED_SELECT_VALUES = "any_value(`id`) as id,
+       const COMBINED_SELECT_VALUES = "any_value(`id`) as id,
                                any_value(`link`) as link,
                                any_value(`created`) as created,
                                any_value(`status`) as `status`,
@@ -52,6 +43,20 @@ class Management {
                                any_value(`categoryId`) as categoryId,
                                any_value(`tagId`) as tagId";
 
+       /**
+        * the database object
+        * @var object
+        */
+       private $DB;
+
+       /**
+        * Type of links based on status to show
+        * @var bool
+        */
+       private $_queryStatus = self::LINK_QUERY_STATUS;
+
+
+
        public function __construct($databaseConnectionObject) {
                $this->DB = $databaseConnectionObject;
        }
@@ -61,8 +66,20 @@ class Management {
         * @param $bool
         */
        public function setShowPrivate($bool) {
-               if(is_bool($bool)) {
-                       $this->_showPrivate = $bool;
+               $this->_queryStatus = self::LINK_QUERY_STATUS;
+               if($bool === true) {
+                       $this->_queryStatus = 1;
+               }
+       }
+
+       /**
+        * Show awaiting moderation links or not
+        * @param $bool
+        */
+       public function setShowAwm($bool) {
+               $this->_queryStatus = self::LINK_QUERY_STATUS;
+               if($bool === true) {
+                       $this->_queryStatus = 3;
                }
        }
 
@@ -80,16 +97,11 @@ class Management {
 
                if($stats === true) {
                        $queryStr = "SELECT
-                               COUNT(*) as amount,
-                               any_value(cr.categoryid) as categoryId
-                               FROM `".DB_PREFIX."_categoryrelation` AS cr, `".DB_PREFIX."_link` AS l
-                               WHERE cr.linkid = l.id";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " AND l.status IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " AND l.status = 2";
-                       }
+                               COUNT(*) AS amount,
+                               any_value(cr.categoryid) AS categoryId
+                               FROM `".DB_PREFIX."_categoryrelation` AS cr, `".DB_PREFIX."_link` AS t
+                               WHERE cr.linkid = t.id";
+                       $queryStr .= " AND ".$this->_decideLinkTypeForQuery();
                        $queryStr .= " GROUP BY categoryid";
 
                        $query = $this->DB->query($queryStr);
@@ -137,16 +149,11 @@ class Management {
 
                if($stats === true) {
                        $queryStr = "SELECT
-                               COUNT(*) as amount,
-                               any_value(tr.tagid) as tagId
-                               FROM `".DB_PREFIX."_tagrelation` AS tr,  `".DB_PREFIX."_link` AS l
-                               WHERE tr.linkid = l.id";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " AND l.status IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " AND l.status = 2";
-                       }
+                               COUNT(*) AS amount,
+                               any_value(tr.tagid) AS tagId
+                               FROM `".DB_PREFIX."_tagrelation` AS tr,  `".DB_PREFIX."_link` AS t
+                               WHERE tr.linkid = t.id";
+                       $queryStr .= " AND ".$this->_decideLinkTypeForQuery();
                        $queryStr .= "GROUP BY tagId";
 
                        $query = $this->DB->query($queryStr);
@@ -188,13 +195,8 @@ class Management {
        public function latestLinks($limit=5) {
                $ret = array();
 
-               $queryStr = "SELECT `title`, `link` FROM `".DB_PREFIX."_link`";
-               if($this->_showPrivate === true) {
-                       $queryStr .= " WHERE `status` IN (2,1)";
-               }
-               else {
-                       $queryStr .= " WHERE `status` = 2";
-               }
+               $queryStr = "SELECT `title`, `link` FROM `".DB_PREFIX."_link` AS t";
+               $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery();
                $queryStr .= " ORDER BY `created` DESC";
                if(!empty($limit)) {
                        $queryStr .= " LIMIT $limit";
@@ -239,24 +241,21 @@ class Management {
        public function linksByCategory($id, $string, $limit=5, $offset=false) {
                $ret = array();
 
-               $querySelect = "SELECT ".$this->COMBINED_SELECT_VALUES;
-               $queryFrom = " FROM `".DB_PREFIX."_combined`";
-               $queryWhere = " WHERE `status` = 2";
-               if($this->_showPrivate === true) {
-                       $queryWhere = " WHERE `status` IN (2,1)";
-               }
+               $querySelect = "SELECT ".self::COMBINED_SELECT_VALUES;
+               $queryFrom = " FROM `".DB_PREFIX."_combined` AS t";
+               $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery();
                if(!empty($id) && is_numeric($id)) {
-                       $queryWhere .= " AND `categoryId` = '" . $this->DB->real_escape_string($id) . "'";
+                       $queryWhere .= " AND t.categoryId = '" . $this->DB->real_escape_string($id) . "'";
                }
                elseif(!empty($string) && is_string($string)) {
-                       $queryWhere .= " AND `category` = '" . $this->DB->real_escape_string($string) . "'";
+                       $queryWhere .= " AND t.category = '" . $this->DB->real_escape_string($string) . "'";
                }
                else {
                        return $ret;
                }
 
-               $queryOrder = "GROUP BY `hash`
-                       ORDER BY `created` DESC";
+               $queryOrder = "GROUP BY t.hash
+                       ORDER BY t.created DESC";
                $queryLimit = '';
                if(!empty($limit)) {
                        $queryLimit .= " LIMIT $limit";
@@ -268,12 +267,11 @@ class Management {
                if(!empty($query) && $query->num_rows > 0) {
                        while($result = $query->fetch_assoc()) {
                                $linkObj = new Link($this->DB);
-                               $linkObj->setShowPrivate($this->_showPrivate);
                                $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
                                unset($linkObj);
                        }
 
-                       $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS amount ".$queryFrom.$queryWhere);
+                       $query = $this->DB->query("SELECT COUNT(DISTINCT(t.hash)) AS amount ".$queryFrom.$queryWhere);
                        $result = $query->fetch_assoc();
                        $ret['amount'] = $result['amount'];
                }
@@ -293,24 +291,21 @@ class Management {
        public function linksByTag($id, $string, $limit=5, $offset=false) {
                $ret = array();
 
-               $querySelect = "SELECT ".$this->COMBINED_SELECT_VALUES;
-               $queryFrom = " FROM `".DB_PREFIX."_combined`";
-               $queryWhere = " WHERE `status` = 2";
-               if($this->_showPrivate === true) {
-                       $queryWhere = " WHERE `status` IN (2,1)";
-               }
+               $querySelect = "SELECT ".self::COMBINED_SELECT_VALUES;
+               $queryFrom = " FROM `".DB_PREFIX."_combined` AS t";
+               $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery();
                if(!empty($id) && is_numeric($id)) {
-                       $queryWhere .= " AND `tagId` = '" . $this->DB->real_escape_string($id) . "'";
+                       $queryWhere .= " AND t.tagId = '" . $this->DB->real_escape_string($id) . "'";
                }
                elseif(!empty($string) && is_string($string)) {
-                       $queryWhere .= " AND `tag` = '" . $this->DB->real_escape_string($string) . "'";
+                       $queryWhere .= " AND t.tag = '" . $this->DB->real_escape_string($string) . "'";
                }
                else {
                        return $ret;
                }
 
-               $queryOrder = "GROUP BY `hash`
-                       ORDER BY `created` DESC";
+               $queryOrder = "GROUP BY t.hash
+                       ORDER BY t.created DESC";
                $queryLimit = '';
                if(!empty($limit)) {
                        $queryLimit .= " LIMIT $limit";
@@ -322,12 +317,11 @@ class Management {
                if(!empty($query) && $query->num_rows > 0) {
                        while($result = $query->fetch_assoc()) {
                                $linkObj = new Link($this->DB);
-                               $linkObj->setShowPrivate($this->_showPrivate);
                                $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
                                unset($linkObj);
                        }
 
-                       $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS amount ".$queryFrom.$queryWhere);
+                       $query = $this->DB->query("SELECT COUNT(DISTINCT(t.hash)) AS amount ".$queryFrom.$queryWhere);
                        $result = $query->fetch_assoc();
                        $ret['amount'] = $result['amount'];
                }
@@ -345,11 +339,8 @@ class Management {
                $ret = array();
 
                $querySelect = "SELECT `hash`";
-               $queryFrom = " FROM `".DB_PREFIX."_link`";
-               $queryWhere = " WHERE `status` = 2";
-               if($this->_showPrivate === true) {
-                       $queryWhere = " WHERE `status` IN (2,1)";
-               }
+               $queryFrom = " FROM `".DB_PREFIX."_link` AS t";
+               $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery();
                $queryOrder = " ORDER BY `created` DESC";
                $queryLimit = "";
                if(!empty($limit)) {
@@ -362,12 +353,11 @@ class Management {
                if(!empty($query) && $query->num_rows > 0) {
                        while($result = $query->fetch_assoc()) {
                                $linkObj = new Link($this->DB);
-                               $linkObj->setShowPrivate($this->_showPrivate);
                                $ret['results'][] = $linkObj->loadShortInfo($result['hash']);
                                unset($linkObj);
                        }
 
-                       $query = $this->DB->query("SELECT COUNT(hash) AS amount ".$queryFrom.$queryWhere);
+                       $query = $this->DB->query("SELECT COUNT(t.hash) AS amount ".$queryFrom.$queryWhere);
                        $result = $query->fetch_assoc();
                        $ret['amount'] = $result['amount'];
                }
@@ -384,16 +374,11 @@ class Management {
                $ret = array();
 
                if(!empty($categoryid) && is_numeric($categoryid)) {
-                       $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES." 
-                       FROM `".DB_PREFIX."_combined`";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " WHERE `status` IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " WHERE `status` = 2";
-                       }
-                       $queryStr .= " AND `categoryId` = '" . $this->DB->real_escape_string($categoryid) . "'
-                       ORDER BY `created` DESC
+                       $queryStr = "SELECT ".self::COMBINED_SELECT_VALUES." 
+                       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
                        LIMIT 1";
                        $query = $this->DB->query($queryStr);
                        if(!empty($query) && $query->num_rows > 0) {
@@ -412,14 +397,9 @@ class Management {
                $ret = false;
 
                if(!empty($url)) {
-                       $queryStr = "SELECT * FROM `".DB_PREFIX."_link`";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " WHERE `status` IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " WHERE `status` = 2";
-                       }
-                       $queryStr .= " AND `link` = '".$this->DB->real_escape_string($url)."'";
+                       $queryStr = "SELECT * FROM `".DB_PREFIX."_link` AS t";
+                       $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery();
+                       $queryStr .= " AND t.link = '".$this->DB->real_escape_string($url)."'";
 
                        $query = $this->DB->query($queryStr);
                        if(!empty($query) && $query->num_rows > 0) {
@@ -441,14 +421,9 @@ class Management {
                if(!empty($searchStr)) {
                        $queryStr = "SELECT *,
                                MATCH (`search`) AGAINST ('".$this->DB->real_escape_string($searchStr)."' IN BOOLEAN MODE) AS score
-                               FROM `".DB_PREFIX."_link`
+                               FROM `".DB_PREFIX."_link` AS t
                                WHERE MATCH (`search`) AGAINST ('".$this->DB->real_escape_string($searchStr)."' IN BOOLEAN MODE)";
-                       if($this->_showPrivate === true) {
-                               $queryStr .= " WHERE `status` IN (2,1)";
-                       }
-                       else {
-                               $queryStr .= " WHERE `status` = 2";
-                       }
+                       $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery();
                        $queryStr .= " ORDER BY score DESC";
 
                        $query = $this->DB->query($queryStr);
@@ -467,13 +442,9 @@ class Management {
        public function linkAmount() {
                $ret = 0;
 
-               $queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_link`";
-               if($this->_showPrivate === true) {
-                       $queryStr .= " WHERE `status` IN (2,1)";
-               }
-               else {
-                       $queryStr .= " WHERE `status` = 2";
-               }
+               $queryStr = "SELECT COUNT(*) AS amount 
+                                               FROM `".DB_PREFIX."_link` AS t";
+               $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery();
 
                $query = $this->DB->query($queryStr);
                if(!empty($query) && $query->num_rows > 0) {
@@ -540,6 +511,39 @@ class Management {
                return $ret;
        }
 
+
+       /**
+        * Load link by given hash. Do not use Link class directly.
+        * Otherwise the authentication will be ignored.
+        * @param $hash
+        * @param bool $fullInfo
+        * @return array|mixed
+        */
+       public function loadLink($hash,$fullInfo=true) {
+               $ret = array();
+
+               if (!empty($hash)) {
+
+                       $querySelect = "SELECT `hash`";
+                       $queryFrom = " FROM `" . DB_PREFIX . "_link` AS t";
+                       $queryWhere = " WHERE " . $this->_decideLinkTypeForQuery();
+                       $queryWhere .= " AND t.hash = '" . $this->DB->real_escape_string($hash) . "'";
+
+                       $query = $this->DB->query($querySelect.$queryFrom.$queryWhere);
+                       if (!empty($query) && $query->num_rows == 1) {
+                               $linkObj = new Link($this->DB);
+                               if($fullInfo === true) {
+                                       $ret = $linkObj->load($hash);
+                               }
+                               else {
+                                       $ret = $linkObj->loadShortInfo($hash);
+                               }
+                       }
+               }
+
+               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
@@ -555,7 +559,6 @@ class Management {
                if(!empty($allLinks)) {
                        foreach($allLinks as $link) {
                                $LinkObj = new Link($this->DB);
-                               $LinkObj->setShowPrivate($this->_showPrivate);
                                $l = $LinkObj->load($link['hash']);
 
                                $searchStr = $l['title'];
@@ -578,5 +581,24 @@ class Management {
                        }
                }
        }
+
+       /**
+        * Return the query string for the correct status type
+        * @return string
+        */
+       private function _decideLinkTypeForQuery() {
+               switch ($this->_queryStatus) {
+                       case 1:
+                               $ret = "t.status IN (2,1)";
+                               break;
+                       case 3:
+                               $ret = "t.status = 3";
+                               break;
+
+                       default:
+                               $ret = "t.status = 2";
+               }
+               return $ret;
+       }
 }
 
index 7de6151d1c54290ce5c3ed6463b927aff78b4137..6ac5dcbdb33b7f6253f434becbaa939a5f6c6518 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 if(!empty($submitFeedback)) {
        $cssClass="is-success";
-       if($submitFeedback['status'] == "error") {
+       if(isset($submitFeedback['status']) && $submitFeedback['status'] == "error") {
                $cssClass="is-danger";
        }
        $message = $submitFeedback['message'];
index de505804f220d5c5f9504ff4b39906e7a29eaf93..a24ad7c4653dfd355f03cf407daa48c217ab589d 100644 (file)
@@ -31,6 +31,7 @@
                <div class="column">
                                <div class="content has-text-centered">
                                        &copy; 2016 - <?php echo date('Y'); ?> <a href="https://www.bananas-playground.net/projekt/insipid/" target="_blank">Insipid</a>
+                                       - <a href="index.php?p=stats">Stats</a>
                                </div>
                        </div>
                </div>
index 48dd0eed330b3753ea0bf4b85a80eb400af13d4b..30e4368ea13d83273c5c773169d56c9652774062 100644 (file)
@@ -39,12 +39,25 @@ if(isset($_GET['id']) && !empty($_GET['id'])) {
        $_id = Summoner::validate($_id,'nospace') ? $_id : false;
 }
 
-$linkObj = new Link($DB);
-$linkObj->setShowPrivate(Summoner::simpleAuthCheck());
-$linkObj->load($_id);
-$linkData = $linkObj->getData();
+$_isAwm = false;
+if(isset($_GET['awm']) && !empty($_GET['awm'])) {
+       $_isAwm = trim($_GET['awm']);
+       $_isAwm = Summoner::validate($_isAwm,'digit') ? true : false;
+       $Management->setShowAwm($_isAwm);
+}
+
+$linkData = $Management->loadLink($_id);
 if(empty($linkData)) {
        header("HTTP/1.0 404 Not Found");
+       exit();
+}
+
+$linkObj = new Link($DB);
+$linkObj->load($_id);
+
+if($_isAwm === true) {
+       $submitFeedback['message'] = 'To accept this link (link has moderation status), just save it. Otherwise just delete.';
+       $submitFeedback['status'] = 'success';
 }
 
 if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) {
@@ -60,7 +73,6 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink']))
                $formData['localImage'] = true;
        }
 
-
        $formData['description'] = trim($fData['description']);
        $formData['title'] = trim($fData['title']);
        $formData['image'] = trim($fData['image']);
index bf345f55f0fd88a17687216a2929991e092d6123..6a2651c161a241afa91fc77279968009db310e0c 100644 (file)
@@ -94,7 +94,7 @@
                                <p>URL:</p>
                        </div>
                        <div class="column">
-                               <p><?php echo $linkData['link']; ?></p>
+                               <p><a href="<?php echo $linkData['link']; ?>" target="_blank"><?php echo $linkData['link']; ?></a></p>
                        </div>
                </div>
                <div class="columns">
index a310e9c1c666a60f12e0b3df4a5622985c54fcd1..a0d8d95ac5ce86ec94624de0358ba25a5babfd4b 100644 (file)
@@ -32,11 +32,10 @@ if(isset($_GET['id']) && !empty($_GET['id'])) {
     $_id = Summoner::validate($_id,'nospace') ? $_id : false;
 }
 
-$linkObj = new Link($DB);
-$linkObj->setShowPrivate(Summoner::simpleAuthCheck());
-$linkData = $linkObj->load($_id);
+$linkData = $Management->loadLink($_id);
 if(empty($linkData)) {
     header("HTTP/1.0 404 Not Found");
+    exit();
 }
 
 $_displayEditButton = false;
index 8910eb07f383381c825d939324136510e0a51759..18ad32033c12722742c0138a9d3a38c5b1590b49 100644 (file)
@@ -47,10 +47,11 @@ $subHeadline = false;
 $tagCollection = array();
 $categoryCollection = array();
 $pagination = array('pages' => 0);
+$displayEditButton = false;
+$isAwm = false;
 
-$_displayEditButton = false;
 if(Summoner::simpleAuthCheck() === true) {
-       $_displayEditButton = true;
+       $displayEditButton = true;
 }
 
 switch($_requestMode) {
@@ -86,6 +87,13 @@ switch($_requestMode) {
                        $subHeadline = 'All the categories <i class="ion-md-filing"></i>';
                }
        break;
+       case 'awm':
+               Summoner::simpleAuth();
+               $isAwm = true;
+               $subHeadline = 'Awaiting moderation';
+               $Management->setShowAwm(true);
+               $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+       break;
        case 'all':
        default:
                # show all
index 4a40e096363b3154c7d23ffb9f73dfff477977f9..4fa3504afc87a8082fc2da76ababd4bccd8414fc 100644 (file)
                        </div>
                        <footer class="card-footer">
                                <a href="<?php echo $link['link']; ?>" target="_blank" class="card-footer-item">Visit link</a>
+                               <?php if($isAwm === true) { ?>
+                               <a href="index.php?p=editlink&id=<?php echo $link['hash']; ?>&awm=1" class="card-footer-item">Edit</a>
+                               <?php } else { ?>
                                <a href="index.php?p=linkinfo&id=<?php echo $link['hash']; ?>" class="card-footer-item">More details</a>
+                               <?php } ?>
                        </footer>
                </div>
        </div>
                <?php } ?>
                </table>
        </div>
-       <?php if($_displayEditButton === true) { ?>
+       <?php if($displayEditButton === true) { ?>
        <div class="column">
                <div class="content">
                        <a href="index.php?p=edittags" class="button is-small is-danger">
                <?php } ?>
                </table>
        </div>
-       <?php if($_displayEditButton === true) { ?>
+       <?php if($displayEditButton === true) { ?>
        <div class="column">
                <div class="content">
                        <a href="index.php?p=editcategories" class="button is-small is-danger">
index dcf762817e63d461a2fc73ecf28d6cf8b58fd60a..0a4ddd30dc1fc3b4e126befea30eba72091a17c6 100644 (file)
 </section>
 
 <section class="section">
-       <div class="columns">
-               <div class="column">
+       <div class="columns is-multiline">
+               <div class="column is-one-quarter">
                        <h3 class="is-size-3">Links</h3>
                        <p># of Links: <?php echo $linkAmount; ?></p>
                        <p><a href="index.php?p=overview&m=all">View all</a></p>
                </div>
-               <div class="column">
+               <div class="column is-one-quarter">
                        <h3 class="is-size-3">Tags</h3>
                        <p># of Tags: <?php echo $tagAmount; ?></p>
                        <p><a href="index.php?p=overview&m=tag">View all</a></p>
                </div>
-               <div class="column">
+               <div class="column is-one-quarter">
                        <h3 class="is-size-3">Categories</h3>
                        <p># of Categories: <?php echo $categoryAmount; ?></p>
                        <p><a href="index.php?p=overview&m=category">View all</a></p>
                </div>
                <?php if($_displayEditButton === true) { ?>
-               <div class="column">
+               <div class="column is-one-quarter">
                        <h3 class="is-size-3">Moderation</h3>
                        <p># Moderation needed: <?php echo $moderationAmount; ?></p>
+                       <p><a href="index.php?p=overview&m=awm">View all</a></p>
+               </div>
+               <div class="column is-one-quarter">
+                       <h3 class="is-size-3">Local image storage</h3>
+                       <p># Moderation needed: <?php echo $moderationAmount; ?></p>
+                       <p><a href="index.php?p=overview&m=category">Delete all</a></p>
                </div>
                <?php } ?>
        </div>