function insertComment($comment, $sender, $receiver, $postid) { $conn = mysqli_connect("localhost", "adminID5Rju3", "Rz5h2JWnm4xd", "tweb"); if ($conn->connect_error) { header("Location postview.php?postid={$postid}&error=1"); } date_default_timezone_set('Europe/Copenhagen'); $date = date("Y-m-d H:i:s"); $sql = "INSERT INTO comment(text,date,user,postID,sender) \n \tVALUES('{$comment}','{$date}','{$receiver}','{$postid}','{$sender}')"; if ($conn->query($sql) === TRUE) { getPostComments($postid); } }
function getPostWithComments($postId) { $res = conn()->query("SELECT p.*, users.username, users.gender, users.profile_pic\n FROM (SELECT * FROM posts WHERE id='{$postId}') p\n INNER JOIN users ON (users.id = p.user_id);"); $posts = convertToArray($res); foreach ($posts as $ind => $post) { $posts[$ind]['comments'] = getPostComments($post['id']); $posts[$ind]['liked'] = isLiked($_SESSION["user_id"], $post['id']); $posts[$ind]['likes'] = getPostLikes($post['id']); foreach ($posts[$ind]['comments'] as $ind2 => $comment) { if (!$posts[$ind]['comments'][$ind2]['profile_pic']) { if ($posts[$ind]['comments'][$ind2]['gender'] == 'male') { $posts[$ind]['comments'][$ind2]['profile_pic'] = 'assets/uploaded_images/default/male.jpg'; } else { $posts[$ind]['comments'][$ind2]['profile_pic'] = 'assets/uploaded_images/default/female.jpg'; } } } } return $posts; }
?> </time> </div> </header> <div class="post-content col-xs-12"> <?php echo $post->text()->kirbytext(); ?> </div> <?php snippet('post-footer', array('post' => $post, 'author' => true, 'avatar' => true, 'tags' => true, 'categories' => true, 'comments' => c::get('comments'), 'class' => 'col-xs-12')); ?> </article> <?php echo snippet('nav-pager'); ?> <?php echo getPostComments($post); ?> </section> <?php snippet('sidebar'); ?> </div> </div> <?php snippet('footer');
if ($_SERVER['REQUEST_METHOD'] == "GET") { $result = $rm->inValidServerMethod(); return $result; } //Check request url is https or not if (!empty($_SERVER["HTTPS"])) { if ($_SERVER["HTTPS"] !== "off") { $postId = $rm->cleanData($_POST['postId']); $loggedInUserId = $rm->cleanData($_POST['userId']); $getArrayList = array(); //echo $ENCRYPTEDPWD = md5($PASSWORD); //echo $ENCRYPTEDPWD = base64_decode($PASSWORD); //$ENCRYPTEDPWD=$PASSWORD; if ($postId == "" || $loggedInUserId == "") { $result = $rm->fields_validation(); return $result; } else { $result = $rm->getAllPostComments($postId, $loggedInUserId); return $result; } } else { $result = $rm->ssl_error(); return $result; } } else { $result = $rm->ssl_error(); return $result; } } echo getPostComments();