Пример #1
0
/**
 * Checks if id is numerical and if user with provided id exists.
 * @param $id
 * @param $user
 */
function checkRequestURL($id, $user)
{
    checkUnauthorizedAccess();
    checkIntValueOfId($id);
    if ($user == null) {
        redirect(\route\Route::get("errorPage")->generate());
    }
}
Пример #2
0
 /**
  * Function lists all galleries stored in database.
  */
 public function action()
 {
     checkUnauthorizedAccess();
     $main = new Main();
     $body = new \templates\ListGalleries();
     $galleries = GalleryRepository::listGalleries();
     $body->setGalleries($galleries);
     $main->setPageTitle("Galleries")->setBody($body);
     echo $main;
 }
Пример #3
0
 public function showFriends()
 {
     checkUnauthorizedAccess();
     $users = UserRepository::getAllUsers();
     $main = new Main();
     $body = new ShowFriends();
     $body->setUsers($users);
     $main->setPageTitle("Friends")->setBody($body);
     echo $main;
 }
Пример #4
0
 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);
 }
Пример #5
0
 /**
  * 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();
             }
         }
     }
 }
Пример #6
0
 public function readMessage()
 {
     checkUnauthorizedAccess();
     $id = getIdFromURL();
     if (null === $id) {
         redirect(\route\Route::get("errorPage")->generate());
     }
     if (intval($id) < 1) {
         redirect(\route\Route::get("errorPage")->generate());
     }
     //dohvati poruku preko id-a
     $message = MessageRepository::getMessageByID($id);
     //obavijesti da je poruka pročitana
     MessageRepository::setRead($id);
     $main = new Main();
     $body = new ReadMessage();
     $body->setMessage($message);
     echo $main->setPageTitle("Read Message")->setBody($body);
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 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();
         }
     }
 }
Пример #9
0
 /**
  * Sorts messages by id. Newer messages are listed first.
  * Bigger id means that message is sent later.
  */
 public function action()
 {
     checkUnauthorizedAccess();
     $order = getSortingOrderFromURL();
     $myID = UserRepository::getIdByUsername($_SESSION['username']);
     $messages = MessageRepository::newestFirst($myID);
     if ($order == "oldest") {
         $messages = MessageRepository::oldestFirst($myID);
     } else {
         if ($order == "unread") {
             $messages = MessageRepository::unreadFirst($myID);
         } else {
             if ($order == "read") {
                 $messages = MessageRepository::readFirst($myID);
             }
         }
     }
     $main = new Main();
     $body = new ShowMessages();
     $body->setMessages($messages);
     echo $main->setPageTitle("Messages")->setBody($body);
 }
Пример #10
0
 public function postTweet()
 {
     checkUnauthorizedAccess();
     if (post('tweet')) {
         $fromid = UserRepository::getIdByUsername($_SESSION['username']);
         $toid = getIdFromURL();
         $content = htmlentities(trim(post('content')));
         $tag = htmlentities(trim(post('tag')));
         $photo = post('selectPhoto');
         $tweet = new Tweet();
         $tweet->setFromid($fromid);
         $tweet->setToid($toid);
         $tweet->setContent($content);
         $tweet->setImage($photo);
         $tweet->setTag($tag);
         try {
             TweetRepository::postTweet($tweet);
             redirect(\route\Route::get("twitterWall")->generate(array("id" => $toid)));
         } catch (\PDOException $e) {
             $e->getMessage();
         }
     }
 }
Пример #11
0
 /**
  * Function creates new gallery and saves it to database.
  * Gallery has user id, title, tag and date of creation.
  * Title and tag are entered by user.
  */
 public function action()
 {
     checkUnauthorizedAccess();
     $main = new Main();
     $main->setPageTitle("Create gallery");
     $body = new \templates\AddGallery();
     $main->setBody($body);
     echo $main;
     $username = $_SESSION['username'];
     if (post('addGallery')) {
         $userID = UserRepository::getIdByUsername($username);
         $title = trim(post('galleryTitle'));
         $tag = trim(post('galleryTag'));
         $dateOfCreation = date('Y-m-d H:i:s');
         //server side validation of data
         $error = false;
         if (strlen($title) < 4 || strlen($title) > 25) {
             $error = true;
         }
         if (strlen($tag) < 3 || strlen($tag) > 25) {
             $error = true;
         }
         if (!$error) {
             $gallery = new Gallery();
             $gallery->setUserID($userID);
             $gallery->setTitle($title);
             $gallery->setTag($tag);
             $gallery->setCreated($dateOfCreation);
             try {
                 GalleryRepository::addGallery($gallery);
                 redirect(\route\Route::get("listGalleries")->generate());
             } catch (\PDOException $e) {
                 $e->getMessage();
             }
         }
     }
 }
Пример #12
0
 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();
         }
     }
 }
Пример #13
0
 /**
  * Changes visibility of a user.
  */
 public function changeVisibility()
 {
     checkUnauthorizedAccess();
     $userid = UserRepository::getIdByUsername($_SESSION['username']);
     $user = UserRepository::getUserByID($userid);
     if ($user['visibility'] == 1) {
         UserRepository::hideFromUsersList($userid);
         redirect(Route::get("listUsers")->generate());
     } else {
         UserRepository::showInUsersList($userid);
         redirect(Route::get("listUsers")->generate());
     }
 }