Esempio n. 1
0
 /**
  * @return bool
  * @throws \Exception
  * @throws \Zend_Db_Table_Exception
  * @throws \Zend_Db_Table_Row_Exception
  */
 public function deleteImage()
 {
     if ($this->owner_id == $_SESSION['user']->userid && $this->owner_type === null) {
         $albums = new GalleryAlbums();
         $album = $albums->find($this->albumid);
         /** @noinspection PhpUndefinedMethodInspection */
         $album->current()->removeImage($this->id);
         $settings = Cunity::get("settings");
         $likes = new Likes();
         $comments = new Comments();
         $posts = new Posts();
         $posts->delete([$posts->getAdapter()->quote("type=`image`"), $posts->getAdapter()->quoteInto("content=?", $this->id)]);
         $comments->delete($this->_getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $this->id));
         $likes->delete($this->_getTable()->getAdapter()->quoteInto("ref_id=? AND ref_name='image'", $this->id));
         $filename = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/" . $this->filename;
         $filenameThumb = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/thumb_" . $this->filename;
         $filenameCr = "../data/uploads/" . $settings->getSetting("core.filesdir") . "/cr_" . $this->filename;
         if (file_exists($filename)) {
             unlink($filename);
         }
         if (file_exists($filenameThumb)) {
             unlink($filenameThumb);
         }
         if (file_exists($filenameCr)) {
             unlink($filenameCr);
         }
         return $this->delete() == 1;
     }
     return false;
 }