<?php

require_once "../includes/session.php";
require_once "../includes/db_connection.php";
require_once "../includes/functions.php";
if (isset($_POST["submit"])) {
    $user_id = mysqli_real_escape_string($connection, $_POST["user_id"]);
    $comment_id = mysqli_real_escape_string($connection, $_POST["comment_id"]);
    if ($_POST["user_id"] == "-1" || !user_logged_in()) {
        die("<scirpt>window.location.replace(\"log_in.php\");");
    }
    if (already_upvoted($user_id, $comment_id)) {
        update_vote($user_id, $comment_id, "0");
    } else {
        if (already_downvoted($user_id, $comment_id) || exists_but_neutral($user_id, $comment_id)) {
            update_vote($user_id, $comment_id, "1");
        } else {
            add_vote($user_id, $comment_id, "1");
        }
    }
}
<?php

require_once "../includes/session.php";
require_once "../includes/db_connection.php";
require_once "../includes/functions.php";
if (isset($_POST["submit"])) {
    $user_id = mysqli_real_escape_string($connection, $_POST["user_id"]);
    $comment_id = mysqli_real_escape_string($connection, $_POST["comment_id"]);
    if ($_POST["user_id"] == "-1" || !user_logged_in()) {
        die("<scirpt>window.location.replace(\"log_in.php\");");
    }
    if (already_downvoted($user_id, $comment_id)) {
        update_vote($user_id, $comment_id, "0");
    } else {
        if (already_upvoted($user_id, $comment_id) || exists_but_neutral($user_id, $comment_id)) {
            update_vote($user_id, $comment_id, "-1");
        } else {
            add_vote($user_id, $comment_id, "-1");
        }
    }
}
Example #3
0
function make_comment_from_id($comment_id)
{
    $comment = get_comment_by_id($comment_id);
    $user = find_user_by_id($comment["user_id"]);
    $votes = get_votes_by_comment_id($comment_id);
    $formatted_votes = format_votes($votes);
    $avatar = get_user_avatar($comment["user_id"])["file_path"];
    // bug where time since doesn;'t show, figure it out later (edit, this fixes that)
    $time = format_time_in_words(strtotime($comment["date"]));
    if ($time == "") {
        $time_text = "now";
    } else {
        $time_text = $time . " ago ";
    }
    $output = "<div class=\"row comment_output_panel\" data-comment-id=\"{$comment_id}\">";
    $output .= "<div>";
    $output .= "<img class=\"left\" src=\"" . $avatar . "\"/>";
    $output .= "</div>";
    $output .= "<div class=\"comment_output\">";
    $output .= "<div ><span class=\"comment_output_info_label\">";
    $output .= "<a href=\"user.php?user="******"user_id"] . "\">" . $user["username"] . "</a>";
    $output .= "</span> ";
    $output .= "<span> " . $time_text . " </span></div>";
    $output .= "<div>";
    $output .= $comment["text"];
    $output .= "</div>";
    $output .= "<div class=\"vote_panel\">";
    $output .= "<span class=\"upvote_button  ";
    if (user_logged_in() && already_upvoted($_SESSION["user_id"], $comment_id)) {
        $output .= "upvote_button_clicked";
    }
    $output .= "\">";
    $output .= "<i class=\"fi-like\" ></i> Upvote <span class=\"vote_display_box ";
    if ($votes != "null" && (int) $votes > 0) {
        $output .= " positive_votes ";
    } else {
        if ($votes != "null" && (int) $votes < 0) {
            $output .= " negative_votes ";
        } else {
            if ($votes != "null" && (int) $votes == 0) {
                $output .= " zero_votes ";
            }
        }
    }
    $output .= "\" >" . $formatted_votes . "</span>";
    $output .= "</span>";
    $output .= "<span class=\"downvote_button ";
    if (user_logged_in() && already_downvoted($_SESSION["user_id"], $comment_id)) {
        $output .= "downvote_button_clicked";
    }
    $output .= "\">";
    $output .= "<i class=\"fi-dislike\" >   </i>";
    $output .= "</span>";
    $output .= "</div>";
    $output .= "</div>";
    $output .= "</div>";
    return $output;
}