protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Friend Requests</h3> </div> <div class="panel-body"> <?php $counter = 0; foreach ($this->requests as $request) { $counter++; $userid = $request['fromid']; $user = UserRepository::getUserByID($userid); echo "<p><a href='" . \route\Route::get("userProfile")->generate(array("id" => $userid)) . "'>" . $user['username'] . "</a></p>"; } if ($counter == 0) { echo "<p>There are no new friend requests.</p>"; } ?> </div> </div> </div> <?php }
protected function outputHTML() { $user = UserRepository::getUserByID($this->message['senderid']); ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Message</h3> </div> <div class="panel-body"> <p>From: <?php echo $user['username']; ?> </p> <p>Content: <?php echo parseText($this->message['content']); ?> </p> <p><a href="<?php echo \route\Route::get("sendMessage")->generate(array("id" => $user['userid'])); ?> " class="btn btn-info">Reply</a></p> </div> </div> </div> <?php }
protected function outputHTML() { ?> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="<?php echo \route\Route::get("index")->generate(); ?> "><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo \route\Route::get("register")->generate(); ?> " role="button" class="btn btn-link"">Sign up</a></li> </ul> </div> </div> </nav> <?php }
protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Friends</h3> </div> <div class="panel-body"> <?php $myID = UserRepository::getIdByUsername($_SESSION['username']); $counter = 0; foreach ($this->users as $user) { $id = FriendRepository::isFriend($myID, $user['userid']); if (count($id) != 0) { $counter++; echo "<p><a href='" . \route\Route::get("userProfile")->generate(array("id" => $user['userid'])) . "'>" . $user['username'] . "</a></p>"; } } if ($counter == 0) { echo "<p>You do not have friends. Please add members.</p>"; } ?> </div> </div> </div> <?php }
protected function outputHTML() { ?> <div class="container"> <div class="jumbotron"> <div class="container"> <h1 align="center">Welcome to TwitterApp!</h1> <p align="center">This is a simple Twitter application which is used for learning.</p> </div> </div> </div> <div class="container"> <form class="form-horizontal" id="login-form" role="form" method="post" action="<?php echo \route\Route::get("index")->generate(); ?> "> <div class="form-group"> <h3 class="col-md-4 col-md-offset-4"> Log in to TwitterApp </h3> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <input type="text" class="form-control" name="username" id="username" placeholder="Enter username" required> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <input type="password" class="form-control" name="password" id="password" placeholder="Enter password" required> <div style="color: red" id="loginError"></div> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <input type="submit" class="btn btn-info btn-block" name="login" id="login" value="Login"> </div> </div> <div class="form-group"> <div class="text-center"> New to TwitterApp? <a href="<?php echo \route\Route::get("register")->generate(); ?> " tabindex="5" class="forget-login">Sign up here</a> </div> </div> </form> </div> <?php }
protected function outputHTML() { ?> <script src="/TwitterApp/assets/js/addGalleryValidation.js"></script> <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3"> <form class="form-horizontal" role="form" id="create-gallery-form" method="post" action="<?php \route\Route::get("addGallery")->generate(); ?> "> <div class="form-group"> <h3 class="col-md-6 col-md-offset-3"> Create gallery </h3> </div> <div class="form-group"> <label class="control-label col-md-3" for="email">Gallery Title:</label> <div class="col-md-9"> <input type="text" class="form-control" id="galleryTitle" name="galleryTitle" placeholder="Enter gallery title"> <div style="color: red" id="titleError"></div> </div> </div> <div class="form-group"> <label class="control-label col-md-3" for="pwd">Gallery Tag:</label> <div class="col-md-9"> <input type="text" class="form-control" id="galleryTag" name="galleryTag" placeholder="Enter gallery tag"> <div style="color: red" id="tagError"></div> </div> </div> <div class="form-group"> <div class="col-md-3 col-sm-offset-3"> <input type="submit" class="btn btn-block btn-danger" name="addGallery" id="addGallery" value="Create gallery"> </div> </div> </form> </div> </div> </div> <?php }
public function dispatch() { $request = $_SERVER["REQUEST_URI"]; if (($pos = strpos($request, "?")) !== false) { $request = substr($request, 0, $pos); } $this->matched = null; /* @var \route\Route $route */ foreach (Route::get() as $route) { if (!$route->match($request)) { continue; } $this->matched = $route; break; } if (null === $this->matched) { throw new \Exception(); } $controller = "\\Controllers\\" . ucfirst($this->matched->getParam("controller")); $action = $this->matched->getParam("action"); //dirty fix to try and load class $func = function ($className) { throw new \Exception(); }; spl_autoload_register($func); $ctl = null; try { $ctl = new $controller(); } catch (\Exception $e) { throw new \Exception(); } spl_autoload_unregister($func); if (!is_callable(array($ctl, $action))) { throw new \Exception(); } $ctl->{$action}(); }
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 action() { $photoID = getParamFromURL("id"); $filter = getParamFromURL("filter"); $photo = PhotoRepository::getPhotoByID($photoID); $path = substr($photo['path'], 12); $im = null; $imageType = null; if (endsWith($photo['image'], ".jpeg") || endsWith($photo['image'], ".jpg")) { $im = imagecreatefromjpeg($path); $imageType = "jpeg"; } else { if (endsWith($photo['image'], ".png")) { $im = imagecreatefrompng($path); $imageType = "png"; } } if ($filter === "blackwhite") { BlackWhite::filter($im); } else { if ($filter === "brightness") { $brightness = post('number'); Brightness::setBrightness($brightness); Brightness::filter($im); } else { if ($filter === "sepia") { Sepia::filter($im); } else { if ($filter === "blur") { Blur::filter($im); } } } } header('Content-Type: image/' . $imageType); if ($imageType === "jpeg") { imagejpeg($im); imagejpeg($im, $path); } else { imagepng($im); } imagedestroy($im); redirect(Route::get("viewPhoto")->generate(array("id" => $photo['photoid']))); }
public static function registerUser(User $user) { $db = Database::getInstance(); $query = $db->prepare('INSERT INTO users (firstname, lastname, username, password, email) VALUES (?, ?, ?, ?, ?)'); $query->execute([$user->getFirstName(), $user->getLastName(), $user->getUsername(), $user->getPassword(), $user->getEmail()]); $affected = $query->rowCount(); if ($affected == 1) { redirect(\route\Route::get("index")->generate()); } else { ?> <script> document.getElementById("failedRegister").innerHTML = "User already exists."; </script> <?php } }
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); }
/** * 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; }
protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Users</h3> </div> <div class="panel-body"> <?php foreach ($this->users as $user) { echo "<p><a href='" . \route\Route::get("userProfile")->generate(array("id" => $user['userid'])) . "'>" . $user['username'] . "</a></p>"; } ?> </div> </div> </div> <?php }
/** * 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(); } } } }
public function searchResult() { $data = ''; if (post('search')) { $str = post('search'); $str = preg_replace("#[^0-9a-z]#i", "", $str); $users = UserRepository::searchUsers($str); foreach ($users as $user) { ?> <div> <a href="<?php echo \route\Route::get("twitterWall")->generate(array("id" => $user['userid'])); ?> "> <?php echo $user['username']; ?> </a> </div> <?php } echo $data; } }
protected function outputHTML() { ?> <div class="container"> <?php //provjera da li su prijatelji ili da li je to sam korisnik if (checkPermissionToTweet()) { //forma za dodavanje novih tweetova ?> <script src="/TwitterApp/assets/js/postTweetForm.js"></script> <div class="col-md-4 col-md-offset-4"> <button id="open" class="btn btn-success btn-block">Post tweet</button> </div> <form class="form-horizontal" id="tweet-form" role="form" method="post" action="<?php echo \route\Route::get("postTweet")->generate(array("id" => getIdFromURL())); ?> "> <br><br> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <textarea class="form-control" rows="3" name="content" id="content" placeholder="What's happening?" required></textarea> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <input type="text" class="form-control" name="tag" id="tag" placeholder="Enter tweet tag (optional)"> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <select name="selectPhoto" id="sel1" class="form-control"> <option value="">Select photo...</option> <?php foreach ($this->userPhotos as $photo) { ?> <option value="<?php echo $photo['path']; ?> "><?php echo $photo['image']; ?> </option> <?php } ?> </select> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <div style="color: green" id="success"></div> </div> </div> <div class="form-group"> <div class="col-md-4 col-md-offset-4"> <input type="submit" class="btn btn-info btn-block" name="tweet" id="tweet" value="Tweet"> </div> </div> </form> <br><br> <?php } else { ?> <div class="col-md-4 col-md-offset-1"> <p>To post tweet on this wall you need to become friends.</p> <hr> </div> <?php } $counter = 0; //prikaži sve tweetove na korisnikovom zidu foreach ($this->tweets as $tweet) { $counter++; $user = UserRepository::getUserByID($tweet['fromid']); $numberOfComments = TweetRepository::getNumberOfComments($tweet['tweetid']); $value = "Comments"; if ($numberOfComments == 1) { $value = "Comment"; } ?> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Posted by: <?php echo $user['username']; ?> </h3> </div> <div class="panel-body"> <div> <?php echo parseText($tweet['content']); ?> </div> </div> <div class="panel-footer"> <div> <a href="<?php echo \route\Route::get("viewTweet")->generate(array("id" => $tweet['tweetid'])); ?> "><?php echo $numberOfComments . ' ' . $value; ?> </a> </div> </div> </div> </div> <?php } //ako nema tweetova, obavijeti korisnika if ($counter == 0) { ?> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Tweets</h3> </div> <div class="panel-body"> There are no tweets to show. </div> </div> </div> <?php } ?> </div> <?php }
public function logout() { UserRepository::logout(); redirect(\route\Route::get("index")->generate()); }
Route::register("listGalleries", new DefaultRoute("galleries", array("controller" => "listGalleries", "action" => "action"))); Route::register("viewGallery", new DefaultRoute("gallery/<id>", array("controller" => "viewGallery", "action" => "action"), array("id" => "\\d+"))); Route::register("addPhoto", new DefaultRoute("photo/add/<galleryID>", array("controller" => "addPhoto", "action" => "action"), array("galleryID" => "\\d+"))); Route::register("viewPhoto", new DefaultRoute("photo/<id>", array("controller" => "viewPhoto", "action" => "action"), array("id" => "\\d+"))); Route::register("setGalleryIcon", new DefaultRoute("icon/<id>", array("controller" => "viewPhoto", "action" => "setGalleryIcon"), array("id" => "\\d+"))); Route::register("setUserBackground", new DefaultRoute("background/<id>", array("controller" => "viewPhoto", "action" => "setUserBackground"), array("id" => "\\d+"))); Route::register("listUsers", new DefaultRoute("users", array("controller" => "listUsers", "action" => "action"))); Route::register("userProfile", new DefaultRoute("profile/<id>", array("controller" => "userProfile", "action" => "action"), array("id" => "\\d+"))); Route::register("sendFriendRequest", new DefaultRoute("request/send/<id>", array("controller" => "userProfile", "action" => "sendFriendRequest"), array("id" => "\\d+"))); Route::register("cancelRequest", new DefaultRoute("request/cancel/<id>", array("controller" => "userProfile", "action" => "cancelRequest"), array("id" => "\\d+"))); Route::register("acceptRequest", new DefaultRoute("request/accept/<id>", array("controller" => "userProfile", "action" => "acceptRequest"), array("id" => "\\d+"))); Route::register("deleteRequest", new DefaultRoute("request/delete/<id>", array("controller" => "userProfile", "action" => "deleteRequest"), array("id" => "\\d+"))); Route::register("unfriend", new DefaultRoute("unfriend/<id>", array("controller" => "userProfile", "action" => "unfriend"), array("id" => "\\d+"))); Route::register("blockUser", new DefaultRoute("block/<id>", array("controller" => "userProfile", "action" => "blockUser"), array("id" => "\\d+"))); Route::register("unblockUser", new DefaultRoute("unblock/<id>", array("controller" => "userProfile", "action" => "unblockUser"), array("id" => "\\d+"))); Route::register("showRequests", new DefaultRoute("requests", array("controller" => "listUsers", "action" => "showRequests"))); Route::register("showFriends", new DefaultRoute("friends", array("controller" => "listUsers", "action" => "showFriends"))); Route::register("sendMessage", new DefaultRoute("message/send/<id>", array("controller" => "messages", "action" => "action"), array("id" => "\\d+"))); Route::register("showMessages", new DefaultRoute("messages", array("controller" => "messages", "action" => "showMessages"))); Route::register("readMessage", new DefaultRoute("message/read/<id>", array("controller" => "messages", "action" => "readMessage"), array("id" => "\\d+"))); Route::register("sortMessages", new DefaultRoute("messages/sort/<order>", array("controller" => "sortMessages", "action" => "action"), array("order" => "newest|oldest|unread|read"))); Route::register("postTweet", new DefaultRoute("tweet/post/<id>", array("controller" => "twitterWall", "action" => "postTweet"), array("id" => "\\d+"))); Route::register("viewTweet", new DefaultRoute("tweet/<id>", array("controller" => "viewTweet", "action" => "action"), array("id" => "\\d+"))); Route::register("postTweetComment", new DefaultRoute("tweet/<id>/comment", array("controller" => "viewTweet", "action" => "postTweetComment"), array("id" => "\\d+"))); Route::register("postPhotoComment", new DefaultRoute("photo/<id>/comment", array("controller" => "viewPhoto", "action" => "postPhotoComment"), array("id" => "\\d+"))); Route::register("editPhotoTags", new DefaultRoute("photo/<id>/edit", array("controller" => "viewPhoto", "action" => "editPhotoTags"), array("id" => "\\d+"))); Route::register("photoRssFeed", new DefaultRoute("feed/rss/photo/<id>", array("controller" => "rssFeed", "action" => "photoCommentsRss"), array("id" => "\\d+"))); Route::register("tweetRssFeed", new DefaultRoute("feed/rss/tweet/<id>", array("controller" => "rssFeed", "action" => "tweetCommentsRss"), array("id" => "\\d+"))); Route::register("galleryRssFeed", new DefaultRoute("feed/rss/gallery/<id>", array("controller" => "rssFeed", "action" => "galleryRssFeed"), array("id" => "\\d+"))); Route::register("imageFilter", new DefaultRoute("photo/<id>/filter/<filter>", array("controller" => "imageFilters", "action" => "action"), array("id" => "\\d+", "filter" => "blackwhite|sepia|brightness|blur")));
protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Galleries</h3> </div> <?php foreach ($this->galleries as $gallery) { ?> <div class="panel-body"> <?php if ($gallery['icon'] == null) { ?> <p><?php echo "<img width='50' height='50' src='/TwitterApp/assets/images/profile/default.jpg' alt='Default Gallery Pic'>"; ?> </p> <?php } else { ?> <p><?php echo "<img width='50' height='50' src='/TwitterApp/assets/images/galleries/" . $gallery['title'] . '/' . $gallery['icon'] . "' alt='image'>"; ?> </p> <?php } ?> <p>Gallery Title: <?php echo $gallery['title']; ?> </p> <p>Gallery Tag: <?php echo $gallery['tag']; ?> </p> <p>Created: <?php echo $gallery['created']; ?> </p> <p> <a href="<?php echo \route\Route::get("viewGallery")->generate(array("id" => $gallery['galleryid'])); ?> ">View Gallery</a></p> </div> <?php } ?> <div class="panel-footer"> <p><a href="<?php echo \route\Route::get("addGallery")->generate(); ?> " class="btn btn-danger">Create gallery</a></p> </div> </div> </div> <?php }
<?php include_once "includes/config.php"; try { \dispatcher\DefaultDispatcher::instance()->dispatch(); } catch (Exception $e) { redirect(\route\Route::get("errorPage")->generate()); }
protected function outputHTML() { ?> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="<?php echo \route\Route::get("twitterWall")->generate(array("id" => $this->userid)); ?> "><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a> </div> <script> $(function () { $('#input').keyup(function () { var search = $('#input').val(); $.post("<?php echo \route\Route::get("searchBar")->generate(); ?> ", {"search": search}, function (data) { $('.entry').html(data); }); }); }); </script> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Menu <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li> <a href="<?php echo \route\Route::get("listGalleries")->generate(); ?> ">Galleries</a> </li> <li><a href="<?php echo \route\Route::get("listUsers")->generate(); ?> ">Users</a></li> <li><a href="<?php echo \route\Route::get("showFriends")->generate(); ?> ">Friends</a></li> </ul> <li> <?php $color = newRequestNotification(); ?> <a style="color: <?php echo $color; ?> " href="<?php echo \route\Route::get("showRequests")->generate(); ?> ">Requests</a> </li> <li> <?php $color = newMessageNotification(); ?> <a style="color: <?php echo $color; ?> " href="<?php echo \route\Route::get("showMessages")->generate(); ?> ">Messages</a> </li> <li> <form class="navbar-form navbar-left" role="search"> <div class="form-group"> <input type="text" name="search" id="input" class="form-control" placeholder="Search"> </div> </form> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li> <ul> <?php $image = UserRepository::getProfilePicture($_SESSION['username']); if ($image == "") { echo "<img width='50' height='50' src='/TwitterApp/assets/images/profile/default.jpg' alt='Default Profile Pic'>"; } else { echo "<img width='50' height='50' src='/TwitterApp/assets/images/profile/" . $image . "' alt='Default Profile Pic'>"; } ?> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-cog" aria-hidden="true"></span> Settings <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="<?php echo \route\Route::get("changeProfilePicture")->generate(); ?> ">Upload profile picture</a></li> <li><a href="<?php echo \route\Route::get("changeUsername")->generate(); ?> ">Change username</a></li> <li><a href="<?php echo \route\Route::get("changePassword")->generate(); ?> ">Change password</a></li> <?php $user = UserRepository::getUserByID($this->userid); if ($user['visibility'] == 1) { ?> <li><a href="<?php echo \route\Route::get("changeVisibility")->generate(); ?> ">Hide from users list</a></li> <?php } else { ?> <li><a href="<?php echo \route\Route::get("changeVisibility")->generate(); ?> ">Show in users list</a></li> <?php } ?> <li class="divider"></li> <li><a href="<?php echo \route\Route::get("logout")->generate(); ?> ">Log Out</a></li> </ul> </li> </ul> </div> </div> </nav> <?php }
public function unblockUser() { $profileID = getIdFromURL(); $activeUserID = UserRepository::getIdByUsername($_SESSION['username']); try { ResctrictionRepository::removeRestriction($activeUserID, $profileID); redirect(Route::get("userProfile")->generate(array("id" => $profileID))); } catch (\PDOException $e) { $e->getMessage(); } }
/** * Checks if user tried to enter page for which he has not access. * It redirects to unauthorized access page. */ function checkUnauthorizedAccess() { if (!isLoggedIn()) { redirect(\route\Route::get("unauthorizedAccess")->generate()); } }
protected function outputHTML() { ?> <h3>Search results</h3> <?php echo "<h5>Users:</h5>"; if (count($this->users) == 0) { echo "<div>No results</div>"; echo "<br>"; } else { foreach ($this->users as $user) { ?> <div> <a href="<?php echo \route\Route::get("twitterWall")->generate(array("id" => $user['userid'])); ?> "> <?php echo $user['username']; ?> </a> </div> <?php } echo "<br>"; } echo "<h5>Galleries:</h5>"; if (count($this->galleries) == 0) { echo "<div>No results</div>"; echo "<br>"; } else { foreach ($this->galleries as $photo) { ?> <div> <a href="<?php echo \route\Route::get("viewGallery")->generate(array("id" => $photo['galleryid'])); ?> "> <?php echo $photo['title']; ?> </a> </div> <?php } echo "<br>"; } echo "<h5>Photos:</h5>"; if (count($this->photos) == 0) { echo "<div>No results</div>"; echo "<br>"; } else { foreach ($this->photos as $photo) { ?> <div> <a href="<?php echo \route\Route::get("viewPhoto")->generate(array("id" => $photo['photoid'])); ?> "> <?php echo $photo['title']; ?> </a> </div> <?php } echo "<br>"; } ?> <br> <?php }
protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title"><?php echo $this->user['username']; ?> profile</h3> </div> <div class="panel-body"> <p>First name: <?php echo $this->user['firstname']; ?> </p> <p>Last name: <?php echo $this->user['lastname']; ?> </p> <p>E-mail address: <?php echo $this->user['email']; ?> </p> <p> <a href="<?php echo \route\Route::get("twitterWall")->generate(array("id" => $this->user['userid'])); ?> ">User wall</a></p> <?php $userid = UserRepository::getIdByUsername($_SESSION['username']); //ako otvoreni profil nije profil ulogiranog korisnika if (!($this->user['userid'] == $userid)) { $friendsID = FriendRepository::isFriend($userid, $this->user['userid']); //ako su prijatelji ponuditi opciju Unfriend if ($friendsID != null) { ?> <p><a href="<?php echo \route\Route::get("sendMessage")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-info">Send Message</a> <a href="<?php echo \route\Route::get("unfriend")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-danger">Unfriend</a> <?php $restrictionID = ResctrictionRepository::isBlocked($userid, $this->user['userid']); if ($restrictionID == null) { ?> <a href="<?php echo \route\Route::get("blockUser")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-warning">Block user</a></p> <?php } else { ?> <a href="<?php echo \route\Route::get("unblockUser")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-warning">Unblock user</a></p> <?php } ?> <?php //ako nisu prijatelji ponuditi opcije za prihvaćanje, odbijanje, uklanjanje //i slanje zahtjeva ovisno o situaciji } else { $getRequestID = RequestRepository::getRequest($this->user['userid'], $userid); $fromRequestID = RequestRepository::getRequest($userid, $this->user['userid']); if ($getRequestID != null) { ?> <p><a href="<?php echo \route\Route::get("acceptRequest")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-success">Accept</a> | <a href="<?php echo \route\Route::get("deleteRequest")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-danger">Delete</a> </p> <?php } else { if ($fromRequestID != null) { ?> <a href="<?php echo \route\Route::get("cancelRequest")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-danger">Cancel Request</a> <?php } else { ?> <a href="<?php echo \route\Route::get("sendFriendRequest")->generate(array("id" => $this->user['userid'])); ?> " class="btn btn-info">Send Friend Request</a> <?php } } } } ?> </div> </div> </div> <?php }
protected function outputHTML() { ?> <div class="container"> <div class="panel panel-info" id="comments"> <div class="panel-heading"> <h3 class="panel-title">Gallery <a href="<?php echo Route::get("galleryRssFeed")->generate(array("id" => $this->galleryID)); ?> " class="btn btn-info">RSS Feed</a></h3> </div> <?php $counter = 0; foreach ($this->photos as $photo) { $counter++; ?> <div class="panel-body"> <p><?php echo "<img width='100' height='100' src='" . $photo['path'] . "' alt='image'>"; ?> </p> <p>Photo Title: <?php echo $photo['title']; ?> </p> <p>Photo Tags: <?php echo $photo['tags']; ?> </p> <p>Created: <?php echo $photo['created']; ?> </p> <p> <a href="<?php echo \route\Route::get("viewPhoto")->generate(array("id" => $photo['photoid'])); ?> ">View Photo</a></p> </div> <?php } if ($counter == 0) { ?> <div class="panel-body"> <p>Gallery is empty. To add a photo click the button below.</p> </div> <?php } ?> <?php if (checkPermissionToAddPhotoToGallery($this->gallery)) { ?> <div class="panel-footer"> <p> <a href="<?php echo \route\Route::get("addPhoto")->generate(array("galleryID" => $this->galleryID)); ?> " class="btn btn-danger">Add Photo</a></p> </div> <?php } else { ?> <div class="panel-footer"> <p style='color: red'>Adding photos is enabled only for user who created the gallery.</p> </div> <?php } ?> </div> <?php }
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(); } } }
<?php require_once __DIR__ . '/vendor/autoload.php'; use Route\Route; $route = new Route(); require_once __DIR__ . '/src/Modules/' . $route->getModule() . '/' . $route->getController() . '.php'; $controller = 'Modules\\' . $route->getModule() . '\\' . $route->getController(); $controllerObject = new $controller(); $params = $route->getParams(); if (empty($params)) { $controllerObject->{$route->getAction()}(); } else { $controllerObject->{$route->getAction()}($params); }
protected function outputHTML() { ?> <script src="/TwitterApp/assets/js/viewPhoto.js"></script> <div class="container"> <ul class="nav nav-pills"> <li class="dropdown"> <button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Set As... <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <li><a href="<?php echo \route\Route::get("setGalleryIcon")->generate(array("id" => $this->photo['photoid'])); ?> ">Set As Gallery Icon</a></li> <li><a href="<?php echo \route\Route::get("setUserBackground")->generate(array("id" => $this->photo['photoid'])); ?> ">Set As Background</a></li> </ul> </li> <li> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Filters <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu2"> <li><a href="<?php echo \route\Route::get("imageFilter")->generate(array("id" => $this->photo['photoid'], "filter" => "blackwhite")); ?> ">Black and white</a></li> <li><a href="<?php echo \route\Route::get("imageFilter")->generate(array("id" => $this->photo['photoid'], "filter" => "sepia")); ?> ">Sepia</a></li> <li><a href="<?php echo \route\Route::get("imageFilter")->generate(array("id" => $this->photo['photoid'], "filter" => "blur")); ?> ">Blur</a></li> </ul> </li> <li> <form class="form-inline" role="form" method="post" action="<?php echo \route\Route::get("imageFilter")->generate(array("id" => $this->photo['photoid'], "filter" => "brightness")); ?> " id="brightnessForm"> <div class="form-group"> <input placeholder="Brightness strength" type="number" class="form-control" id="number" name="number"> <button type="submit" name="setBrightness" id="setBrightness" class="btn btn-default">Set brightness</button> </div> </form> </li> </ul> <br> <p><?php echo "<img width='1024' height='768' src='" . $this->photo['path'] . "' alt='image'>"; ?> </p> <p><button class="btn btn-danger" id="editTags">Edit tags</button> <button class="btn btn-danger" id="commentPhoto">Comment photo</button> <a href="<?php echo Route::get("photoRssFeed")->generate(array("id" => $this->photo['photoid'])); ?> " class="btn btn-info">RSS Feed</a> <button class="btn btn-default" id="closeEdit">Close</button></p> <div><h3>Photo tags</h3><p><?php echo $this->photo['tags']; ?> </p></div> <form class="form-horizontal" id="editPhotoTags" role="form" method="post" action="<?php echo \route\Route::get("editPhotoTags")->generate(array("id" => $this->photo['photoid'])); ?> "> <?php if (checkPermissionToCommentPhotoAndEditTags()) { ?> <div class="form-group"> <div class="col-md-4"> <input type="text" class="form-control" name="tags" id="tags" value="<?php echo $this->photo['tags']; ?> " required> </div> </div> <div class="form-group"> <div class="col-md-4"> <input type="submit" class="btn btn-info btn-block" name="postTags" id="postTags" value="Submit changes"> </div> </div> <?php } else { echo "<p style='color: red'>You must be friends with user who created gallery to edit tags.</p>"; } ?> </form> <div id="displayComments"> <h3>Photo comments</h3> <?php if (count($this->comments) == 0) { echo "There are no comments for this photo."; } else { foreach ($this->comments as $comment) { $user = UserRepository::getUserByID($comment['userid']); echo "<p>" . $user['username'] . ": " . parseText($comment['content']) . "</p>"; } } ?> </div> <form class="form-horizontal" id="comment-form" role="form" method="post" action="<?php echo \route\Route::get("postPhotoComment")->generate(array("id" => $this->photo['photoid'])); ?> "> <?php if (checkPermissionToCommentPhotoAndEditTags()) { ?> <div class="form-group"> <div class="col-md-4"> <textarea class="form-control" rows="3" name="comment" id="comment" placeholder="Enter comment..." required></textarea> </div> </div> <div class="form-group"> <div class="col-md-4"> <div style="color: green" id="success"></div> </div> </div> <div class="form-group"> <div class="col-md-4"> <input type="submit" class="btn btn-info btn-block" name="postComment" id="postComment" value="Post Comment"> </div> </div> <?php } else { echo "<p style='color: red'>You must be friends with user who created gallery to post comments.</p>"; } ?> </form> </div> <script type="text/javascript" > $(document).ready(function() { $('#postComment').on('click', function(e) { e.preventDefault(); var comm = $('#comment').val(); var url = "<?php echo Route::get('postPhotoComment')->generate(array("id" => $this->photo['photoid'])); ?> "; $.post(url, {'comment' : comm}, function(data) { a = JSON.parse(data); $('#displayComments').append('<p>' + a.user + ': ' + a.comment + '</p>'); $('#comment').val(''); }) }); }); </script> <?php }