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); }
/** * Checks if user has permission to comment on tweet. * User can comment tweet only if he is friend with user that posted tweet. * @return true if user has permission to comment tweet */ function checkPermissionToCommentTweet() { $tweetid = getIdFromURL(); $tweet = \Repository\TweetRepository::getTweetById($tweetid); $fromID = $tweet['fromid']; $toid = $tweet['toid']; $currentID = \Repository\UserRepository::getIdByUsername($_SESSION['username']); checkIntValueOfId($tweetid); if ($toid != $currentID) { if (\Repository\FriendRepository::isFriend($currentID, $toid) == null || \Repository\ResctrictionRepository::isBlocked($toid, $currentID) != null) { return false; } } return true; }
/** * 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 postTweetComment() { checkUnauthorizedAccess(); $id = getIdFromURL(); checkIntValueOfId($id); if (post('comment')) { $tweetid = $id; $username = $_SESSION['username']; $userid = UserRepository::getIdByUsername($username); $content = htmlentities(trim(post('comment'))); $comment = new TweetComment(); $comment->setTweetid($tweetid); $comment->setUserid($userid); $comment->setContent($content); try { TweetCommentRepository::postComment($comment); echo json_encode(['comment' => parseText($comment->getContent()), 'user' => $username]); } catch (\PDOException $e) { $e->getMessage(); } } }
public function editPhotoTags() { checkUnauthorizedAccess(); $id = getIdFromURL(); checkIntValueOfId($id); if (post('postTags')) { $tags = post('tags'); try { PhotoRepository::editPhotoTags($tags, $id); redirect(\route\Route::get("viewPhoto")->generate(array("id" => $id))); } catch (\PDOException $e) { $e->getMessage(); } } }