*
  */
 
-class Link
-{
+class Link {
 
        /**
         * the database object
         */
        private $_data;
 
-       public function __construct($databaseConnectionObject)
-       {
+       public function __construct($databaseConnectionObject) {
                $this->DB = $databaseConnectionObject;
        }
 
         * @param string $hash
         * @return mixed
         */
-       public function load($hash)
-       {
+       public function load($hash) {
 
                $this->_data = array();
 
         * @param $hash
         * @return array
         */
-       public function loadShortInfo($hash)
-       {
+       public function loadShortInfo($hash) {
                $this->_data = array();
 
                if (!empty($hash)) {
         * @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])) {
        /**
         * reload the current id from DB
         */
-       public function reload()
-       {
+       public function reload() {
                $this->load($this->_data['hash']);
        }
 
         * @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;
         * @param array $data
         * @return boolean|int
         */
-       public function update($data)
-       {
+       public function update($data) {
 
                $ret = false;
 
                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'])) {
         * 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'])) {
         * 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) {
         * 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) {
         * 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";
                }
 
         * 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) {
                                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;
+                               }
                        }
                }