/** * @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; }
/** * @throws \Zend_Db_Table_Exception */ private function upload() { $albums = new GalleryAlbums(); $images = new GalleryImages(); if (isset($_POST['newsfeed_post'])) { /** @var \Cunity\Gallery\Models\Db\Row\Album $album */ $album = $albums->fetchRow($albums->select()->where("type=?", "newsfeed")->where("owner_id=?", $_SESSION['user']->userid)->where("owner_type IS NULL")); if ($album === null) { $albumid = $albums->newNewsfeedAlbums($_SESSION['user']->userid); $album = $albums->fetchRow($albums->select()->where("id=?", $albumid)); } } else { $album = $albums->find($_POST['albumid'])->current(); } $result = $images->uploadImage($album->id, isset($_POST['newsfeed_post'])); $album->addImage(isset($_POST['newsfeed_post']) ? $result['content'] : $result['imageid']); if (isset($_POST['uploadtype']) && $_POST['uploadtype'] == 'single') { header("Location: " . Url::convertUrl("index.php?m=gallery&action=" . $_POST['albumid'])); exit; } else { $view = new View($result !== false); $view->addData($result); $view->sendResponse(); } }