]> 91.132.146.200 Git - insipid.git/commitdiff
deletion of a link and all its relations
authorBanana <banana@optimus.de>
Sun, 27 Oct 2019 11:42:34 +0000 (12:42 +0100)
committerBanana <banana@optimus.de>
Sun, 27 Oct 2019 11:42:34 +0000 (12:42 +0100)
webroot/lib/link.class.php
webroot/lib/management.class.php
webroot/view/editcategories.php
webroot/view/editlink.inc.php
webroot/view/editlink.php
webroot/view/edittags.php

index fa09003b3c958e59fdb20b011f4e7c6b7f4e59b0..1045b6698ab319e6d1145404287bc0b95afdc0ee 100644 (file)
@@ -26,8 +26,7 @@
  *
  */
 
-class Link
-{
+class Link {
 
        /**
         * the database object
@@ -41,8 +40,7 @@ class Link
         */
        private $_data;
 
-       public function __construct($databaseConnectionObject)
-       {
+       public function __construct($databaseConnectionObject) {
                $this->DB = $databaseConnectionObject;
        }
 
@@ -51,8 +49,7 @@ class Link
         * @param string $hash
         * @return mixed
         */
-       public function load($hash)
-       {
+       public function load($hash) {
 
                $this->_data = array();
 
@@ -90,8 +87,7 @@ class Link
         * @param $hash
         * @return array
         */
-       public function loadShortInfo($hash)
-       {
+       public function loadShortInfo($hash) {
                $this->_data = array();
 
                if (!empty($hash)) {
@@ -122,8 +118,7 @@ class 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])) {
@@ -136,8 +131,7 @@ class Link
        /**
         * reload the current id from DB
         */
-       public function reload()
-       {
+       public function reload() {
                $this->load($this->_data['hash']);
        }
 
@@ -146,8 +140,7 @@ 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;
@@ -177,8 +170,7 @@ class Link
         * @param array $data
         * @return boolean|int
         */
-       public function update($data)
-       {
+       public function update($data) {
 
                $ret = false;
 
@@ -256,12 +248,21 @@ class Link
                return $ret;
        }
 
+       /**
+        * call this to delete all the relations to this link.
+        * To completely remove the link use Management->deleteLink()
+        */
+       public function deleteRelations() {
+               $this->_removeTagRelation(false);
+               $this->_removeCategoryRelation(false);
+               $this->_deleteImage();
+       }
+
        /**
         * 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'])) {
@@ -287,8 +288,7 @@ 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'])) {
@@ -313,8 +313,7 @@ class Link
         * remove all or given tag relation to the current loaded link
         * @param mixed $tagid
         */
-       private function _removeTagRelation($tagid)
-       {
+       private function _removeTagRelation($tagid) {
                if (!empty($this->_data['id'])) {
                        $queryStr = false;
                        if ($tagid === false) {
@@ -337,8 +336,7 @@ class Link
         * remove all or given category relation to the current loaded link
         * @param mixed $categoryid
         */
-       private function _removeCategoryRelation($categoryid)
-       {
+       private function _removeCategoryRelation($categoryid) {
                if (!empty($this->_data['id'])) {
                        $queryStr = false;
                        if ($categoryid === false) {
@@ -361,23 +359,33 @@ class Link
         * determine of we have a local stored image
         * if so populate the localImage attribute
         */
-       private function _image()
-       {
+       private function _image() {
                if (!empty($this->_data['hash'])) {
                        $this->_data['imageToShow'] = $this->_data['image'];
-                       $image = ABSOLUTE_PATH . '/' . 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['imageToShow'] = LOCAL_STORAGE.'/thumbnail-'.$this->_data['hash'];
                                $this->_data['localImage'] = true;
                        }
                }
        }
 
+       /**
+        * remove the local stored image
+        */
+       private function _deleteImage() {
+               if (!empty($this->_data['hash']) && !empty($this->_data['imageToShow'])) {
+                       $image = ABSOLUTE_PATH.'/'.$this->_data['imageToShow'];
+                       if (file_exists($image)) {
+                               unlink($image);
+                       }
+               }
+       }
+
        /**
         * check if the status is private and set the info
         */
-       private function _private()
-       {
+       private function _private() {
                if (!empty($this->_data['status']) && $this->_data['status'] == "1") {
                        $this->_data['private'] = "1";
                }
index cc63c9de914aea74a105db91d7525349075ea7ab..1076ac601973faf413091d5da20b97697b3ca6d6 100644 (file)
@@ -517,17 +517,18 @@ class Management {
         * Otherwise the authentication will be ignored.
         * @param $hash
         * @param bool $fullInfo
+        * @param $withObject
         * @return array|mixed
         */
-       public function loadLink($hash,$fullInfo=true) {
+       public function loadLink($hash,$fullInfo=true,$withObject=false) {
                $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) . "'";
+                       $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) {
@@ -538,6 +539,38 @@ class Management {
                                else {
                                        $ret = $linkObj->loadShortInfo($hash);
                                }
+
+                               if($withObject === true) {
+                                       $ret = array(
+                                               'data' => $ret,
+                                               'obj' => $linkObj
+                                       );
+                               }
+                       }
+               }
+
+               return $ret;
+       }
+
+       /**
+        * Delete link by given hash
+        * @param $hash
+        * @return bool
+        */
+       public function deleteLink($hash) {
+               $ret = false;
+
+               if (!empty($hash)) {
+                       $linkData = $this->loadLink($hash,false,true);
+                       if(!empty($linkData)) {
+                               $linkData['obj']->deleteRelations();
+
+                               $queryStr = "DELETE FROM `" . DB_PREFIX . "_link` 
+                                               WHERE `hash` = '" . $this->DB->real_escape_string($hash) . "'";
+                               $query = $this->DB->query($queryStr);
+                               if (!empty($query)) {
+                                       $ret = true;
+                               }
                        }
                }
 
index 5289eea7af9e5311bbbe9dd575d49cd550c2984d..66af4cab61cc0ca1a05c62ec0035baccecd0a022 100644 (file)
@@ -90,7 +90,7 @@
                                </tr>
                                <tr>
                                        <td colspan="3">
-                                               <input type="submit" class="button is-primary" name="updateCategories" value="Update categories">
+                                               <input type="submit" class="button is-success" name="updateCategories" value="Update categories">
                                        </td>
                                </tr>
                        </table>
index 30e4368ea13d83273c5c773169d56c9652774062..1123414083450d500b7107a876d3e004b70e21b5 100644 (file)
@@ -113,6 +113,21 @@ elseif(isset($_POST['refreshlink'])) {
                }
        }
 }
+elseif(isset($_POST['deleteLink'])) {
+       $fData = $_POST['data'];
+       if(isset($fData['delete'])) {
+               $do = $Management->deleteLink($_id);
+               if($do === true) {
+                       if($_isAwm === true) {
+                               header('Location: index.php?p=overview&m=awm');
+                       }
+                       else {
+                               header('Location: index.php');
+                       }
+                       exit();
+               }
+       }
+}
 
 $formData = $linkData;
 # prepare the tag string
index 6a2651c161a241afa91fc77279968009db310e0c..3bf8d73e9401cb47d0781d7034c62846f18e1654 100644 (file)
                        </div>
                </div>
                <div class="columns">
-                       <div class="column is-half">
+                       <div class="column is-one-quarter">
                                <label>Private</label>
                                <input class="checkbox" type="checkbox" name="data[private]" value="1" <?php if(Summoner::ifset($formData, 'private')) echo "checked"; ?> />
                        </div>
-                       <div class="column is-half">
+                       <div class="column">
                                <input type="submit" class="button is-info" name="refreshlink" value="Refresh from source">
-                               <input type="submit" class="button is-primary" name="editlink" value="Save">
+                               <input type="submit" class="button is-success" name="editlink" value="Save">
+                       </div>
+               </div>
+               <div class="columns">
+                       <div class="column is-one-quarter">
+                               <label>DELETE</label>
+                               <input class="checkbox" type="checkbox" name="data[delete]" value="1" />
+                       </div>
+                       <div class="column">
+                               <input type="submit" class="button is-danger" name="deleteLink" value="DELETE">
                        </div>
                </div>
        </form>
index 864799c3c91a4e9c62bdedc7d1d983b962c9dae8..6e325701ce404c8ba7c57ee3940f9cb4f36770e5 100644 (file)
@@ -92,7 +92,7 @@
                                </tr>
                                <tr>
                                        <td colspan="3">
-                                               <input type="submit" class="button is-primary" name="updateTags" value="Update tags">
+                                               <input type="submit" class="button is-success" name="updateTags" value="Update tags">
                                        </td>
                                </tr>
                        </table>