public function galleryRssFeed() { checkUnauthorizedAccess(); $galleryID = getIdFromURL(); checkIntValueOfId($galleryID); $gallery = GalleryRepository::getByID($galleryID); if ($gallery == null) { redirect(\route\Route::get("errorPage")->generate()); } $photos = PhotoRepository::getPhotosByGalleryID($galleryID); $title = $gallery['title']; $link = "http://192.168.56.101/TwitterApp/gallery/" . $galleryID; $description = "Images in selected gallery."; generateGalleryRss($title, $link, $description, $photos); }
/** * Function adds photo to gallery. * Photo has user id, title, list of tags, date of creation and name of chosen picture. */ public function action() { checkUnauthorizedAccess(); $id = \dispatcher\DefaultDispatcher::instance()->getMatched()->getParam("galleryID"); checkIntValueOfId($id); $gallery = GalleryRepository::getByID($id); if ($gallery == null) { redirect(\route\Route::get("errorPage")->generate()); } $main = new Main(); $body = new \templates\AddPhoto(); $main->setBody($body)->setPageTitle("Upload photo"); echo $main; if (post('submit')) { $title = trim(post('title')); $tags = trim(post('tags')); $error = false; if (strlen($title) < 4 || strlen($title) > 25) { $error = true; } if (strlen($tags) < 4 || strlen($tags) > 250) { $error = true; } if (!$error) { $dir = $gallery['title']; $path = 'assets/images/galleries/' . $dir; $localPath = $path . "/" . $_FILES['file']['name']; $completePath = "/TwitterApp/" . $path . "/" . $_FILES['file']['name']; $photo = new Photo(); $photo->setGalleryid($id); $photo->setTitle($title); $photo->setTags($tags); $photo->setCreated(date('Y-m-d H:i:s')); $photo->setImageName($_FILES['file']['name']); $photo->setImagePath($completePath); try { if (!file_exists($path)) { mkdir($path); } move_uploaded_file($_FILES['file']['tmp_name'], $localPath); PhotoRepository::addPhoto($photo); redirect(\route\Route::get("viewGallery")->generate(array("id" => $id))); } catch (\PDOException $e) { $e->getMessage(); } } } }
public function setUserBackground() { $id = getIdFromURL(); checkUnauthorizedAccess(); $photo = PhotoRepository::getPhotoByID($id); $galleryID = PhotoRepository::getGalleryID($id); $gallery = GalleryRepository::getByID($galleryID); $background = $gallery['title'] . '/' . $photo['image']; $userid = UserRepository::getIdByUsername($_SESSION['username']); try { UserRepository::setBackground($background, $userid); redirect(\route\Route::get("viewPhoto")->generate(array("id" => $photo['photoid']))); } catch (\PDOException $e) { $e->getMessage(); } }
/** * Opens selected gallery, shows gallery icon, title and date of creation. * Also provides option of adding a new photo to gallery. */ public function action() { checkUnauthorizedAccess(); $id = \dispatcher\DefaultDispatcher::instance()->getMatched()->getParam("id"); if (null === $id) { redirect(\route\Route::get("errorPage")->generate()); } if (intval($id) < 1) { redirect(\route\Route::get("errorPage")->generate()); } $gallery = GalleryRepository::getByID($id); if ($gallery == null) { redirect(\route\Route::get("errorPage")->generate()); } $main = new Main(); $body = new \templates\ViewGallery(); $photos = PhotoRepository::getPhotosByGalleryID($id); $gallery = GalleryRepository::getByID($id); $body->setGalleryID($id)->setPhotos($photos)->setGallery($gallery); $main->setBody($body)->setPageTitle("View gallery"); echo $main; }
/** * Checks if user has permission to comment on photo or edit tags. * User can comment photo or edit tags if he is friend with user that posted the tweet. * @return true if user has permission to comment photo or edit tag */ function checkPermissionToCommentPhotoAndEditTags() { $photoid = getIdFromURL(); $photo = \Repository\PhotoRepository::getPhotoByID($photoid); $activeUserID = \Repository\UserRepository::getIdByUsername($_SESSION['username']); $gallery = \Repository\GalleryRepository::getByID($photo['galleryid']); $galleryCreatorID = $gallery['userid']; if ($activeUserID != $galleryCreatorID) { if (\Repository\FriendRepository::isFriend($activeUserID, $galleryCreatorID) == null || \Repository\ResctrictionRepository::isBlocked($galleryCreatorID, $activeUserID) != null) { return false; } } return true; }