<?php include 'header.php'; $tempTweet = new Tweet(); $tempTweet->loadFromDB($conn, $_GET['displayTweet']); $tempTweet->loadUserFromDBforTweet($conn, $_GET['displayTweet']); $tempUser = new User(); $tempUser->loadFromDB($conn, $tempTweet->getId_user()); echo '<div class="container">'; echo "Author: " . $tempUser->getName(); echo "<hr>"; echo $tempTweet->getText(); echo "<hr>"; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['comment'])) { $tempComment = new Comments(); $tempComment->saveCommentsToDb($conn, $_SESSION['user_id'], $_GET['displayTweet'], $_POST['comment']); // $tempComment = null; } //if(!isset($tempComment)){ // $tempComment = new Comments(); // }; echo "<h4>Komentarze:</h4>"; //echo ("<hr>"); $retArray = $tempTweet->getAllComments($conn); echo "<br>"; foreach ($retArray as $comment) { ?> <br> <div class = 'text-center'> <?php echo $comment->getText();
/** * @param string $select query used to retrieve data * @return bool * Private function used to ask a DB */ private function getter($select) { $result = $this->conn->query($select); if ($result->num_rows > 0) { $numberOfRows = $result->num_rows; for ($i = 0; $i < $numberOfRows; ++$i) { $result->data_seek($i); $row = $result->fetch_array(MYSQLI_ASSOC); $tweet = new Tweet($this->conn); $tweet->loadFromDB($row['id']); $tweet->showTweetshort($this->email); } } else { return false; } }
<html lang="pl-PL"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>MyTwitt Twitt detils</title> <!-- Bootstrap --> <link href="css/bootstrap.css" rel="stylesheet"> <link href="css/index.css" rel="stylesheet"> </head> <body> <div class="container"> <!--Go back to the main site--> <a class="btn btn-default top-buffer" href="index.php">Wróć</a> <!--Show tweet details--> <div class="form-signin"> <h2 class="form-signin-heading">Szczegóły Tweeta:<br></h2> <?php $tweet = new Tweet($conn); $tweet->loadFromDB($_GET['tweetShow']); $tweet->showTweetlong(); ?> </div> </div> <!-- /container --> </body> </html>
$tweet = new Tweet($conn); if (strlen($_POST['tweetText']) > 140) { echo "Twój tweet jest za długi"; } else { if (!$tweet->createTweet($user->getId(), sanitizeMySQL($conn, $_POST['tweetText']))) { echo "BŁĄD!"; } } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['commentText'])) { if (strlen($_POST['commentText']) > 5) { $comment = new Comment($conn); $comment->createComment($user->getId(), sanitizeMySQL($conn, $_POST['tweetID']), sanitizeMySQL($conn, $_POST['commentText'])); } else { echo "Twój komentarz jest za krótki"; } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['tweetDelete'])) { $tweet = new Tweet($conn); $tweet->loadFromDB(sanitizeMySQL($conn, $_POST['tweetDelete'])); $tweet->deleteTweet(); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['commentDelete'])) { $comment = new Comment($conn); $comment->loadFromDB(sanitizeMySQL($conn, $_POST['commentDelete'])); $comment->deleteComment(); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['userLogout'])) { $user->logOut(); header("Location: index.php"); }
public function getAllOtherPost(mysqli $conn, $numberOfPosts) { $sql = "SELECT * FROM Tweets WHERE user_id != '" . $this->id . "'ORDER BY creation_date DESC LIMIT " . $numberOfPosts; $result = $conn->query($sql); $retArray = array(); if ($result->num_rows > 0) { while ($tweetData = $result->fetch_assoc()) { $tempTweet = new Tweet(); $tempTweet->loadFromDB($conn, $tweetData['id']); $retArray[] = $tempTweet; } } // get posts for all other users than one logged in return $retArray; }
<?php include 'header.php'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { //$newTweet = new Tweet(); $_SESSION['tweetToUpdateId'] = $_GET['updateTweet']; $newTweet = new Tweet(); $newTweet->loadFromDB($conn, $_GET['updateTweet']); echo "Stara treść tweeta: " . $newTweet->getText(); // niezbyt secure - przerobić na metodę POST } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $newTweet = new Tweet(); echo "Tweet zaktualizowany"; $newTweet->udpateTweetInDb($conn, $_SESSION['tweetToUpdateId'], $_POST['tweetUpdatedText']); // zmiana treści Tweeta } echo ' <div class="row"> <div class="col-sm-6 col-md-4 col-md-offset-4"> <!--<h1 class="text-center login-title">Sign in to continue to Bootsnipp</h1>--> <div class="account-wall"> <!--<img class="profile-img" src="img/login.jpg"alt="">--> <form class="form-signin" action="edit_tweet.php" method="post"> <h3><legend>Wpisz nowy text Tweeta</legend></h3> <label for="">Treść Tweeta</label><br> <textarea name ="tweetUpdatedText"rows="4" cols="70"></textarea></br> <button type="submit" class="btn btn-lg btn-primary btn-block">Wyslij</button> <span class="clearfix"></span> </form> </div>
<?php session_start(); require_once '../resources/require.php'; // Umożliwia wyśletanie odświeżonej treści strony, po dodaniu komentarza if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_GET['tweet_text'] = $_POST['tweet_text']; } // Tworzy obiekt tweet potrzebny do wyświetlania treści wpisu, który przekierował na tę stronę i dodawania do niego komentarzy $tweet = new Tweet($mysqli); $tweet->setText($_GET['tweet_text']); $tweet->loadFromDB(); // Tworzy nowy komentarz i uzupełnia treść informacji o sukcesie/błędach if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($_POST['comment_text']) != '') { $comment = new Comment($mysqli); $comment->setTweetId($tweet->getId()); $comment->setUserId($_SESSION['user_id']); $comment->setText($_POST['comment_text']); $comment->setCreationDate(date("Y-m-d H:i:s")); if (!$comment->create()) { $info = 'Błąd przy dodawaniu komentarza.'; } else { $info = 'Dodano komentarz.'; } } else { $info = 'Uzupełnij treść komentarza.'; } } ?> <!DOCTYPE html>
/** * @param mysqli $conn * @param $numberOfPosts * @return array * INDEX */ public function getAllTweets(mysqli $conn, $numberOfPosts) { $sql = "SELECT * FROM Tweets WHERE user_id='" . $this->id . "' LIMIT " . $numberOfPosts; $result = $conn->query($sql); $retArrayUser = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $tempTweet = new Tweet(); $tempTweet->loadFromDB($conn, $row['id']); $retArrayUser[] = $tempTweet; } } return $retArrayUser; }