From: Banana Date: Sun, 27 Oct 2019 11:42:34 +0000 (+0100) Subject: deletion of a link and all its relations X-Git-Tag: 2.2_2019-12-27~12 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=0ada932d4334614c2c7d2976bd0f747745884fb5;p=insipid.git deletion of a link and all its relations --- diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index fa09003..1045b66 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -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"; } diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index cc63c9d..1076ac6 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -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; + } } } diff --git a/webroot/view/editcategories.php b/webroot/view/editcategories.php index 5289eea..66af4ca 100644 --- a/webroot/view/editcategories.php +++ b/webroot/view/editcategories.php @@ -90,7 +90,7 @@ - + diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index 30e4368..1123414 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -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 diff --git a/webroot/view/editlink.php b/webroot/view/editlink.php index 6a2651c..3bf8d73 100644 --- a/webroot/view/editlink.php +++ b/webroot/view/editlink.php @@ -149,13 +149,22 @@
-
+
/>
-
+
- + +
+
+
+
+ + +
+
+
diff --git a/webroot/view/edittags.php b/webroot/view/edittags.php index 864799c..6e32570 100644 --- a/webroot/view/edittags.php +++ b/webroot/view/edittags.php @@ -92,7 +92,7 @@ - +