Esempio n. 1
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;
 }
Esempio n. 2
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);
 }
Esempio n. 3
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();
             }
         }
     }
 }
Esempio n. 4
0
 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();
     }
 }
Esempio n. 5
0
 /**
  * Method lists users, galleries and images that match provided string.
  */
 public function action()
 {
     if (post('search')) {
         $str = post('search');
         $str = preg_replace("#[^0-9a-z]#i", "", $str);
         //getting search results that match given string
         $users = UserRepository::searchUsers($str);
         $galleries = GalleryRepository::searchGalleries($str);
         $photos = PhotoRepository::searchPhotos($str);
         //showing results
         $searchResults = new SearchResults();
         $searchResults->setUsers($users);
         $searchResults->setGalleries($galleries);
         $searchResults->setPhotos($photos);
         echo $searchResults;
     }
 }
Esempio n. 6
0
 public function action()
 {
     $id = getIdFromURL();
     $user = UserRepository::getUserByID($id);
     checkRequestURL($id, $user);
     $tweets = TweetRepository::getMyTweets($id);
     $userGalleries = GalleryRepository::getUserGalleries($id);
     $userPhotos = array();
     foreach ($userGalleries as $gallery) {
         $photos = PhotoRepository::getPhotosByGalleryID($gallery['galleryid']);
         foreach ($photos as $photo) {
             array_push($userPhotos, $photo);
         }
     }
     $main = new Main();
     $body = new \templates\TwitterWall();
     $body->setTweets($tweets)->setUserPhotos($userPhotos);
     echo $main->setPageTitle("TwitterApp")->setBody($body);
 }
Esempio n. 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;
 }
Esempio n. 8
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();
             }
         }
     }
 }
Esempio n. 9
0
/**
 * 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;
}