Example #1
0
/**
 * returns a list of comments for a given thread id
 *   
 */
function get_comments($thread_id, $privileges, $login, $output = '')
{
    $action = new action();
    $action->set_result(False);
    $escaped_threadid = mysql_real_escape_string($thread_id);
    $escaped_name = mysql_real_escape_string($login);
    $result = @mysql_query(sprintf("(SELECT C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name,\n\tSUM(V.vote) AS pro_vote, COUNT(V.vote) AS total_vote, \n\tMAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop) AS my_vote, \n\tMAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop AND V.vote) AS my_provote\n\tFROM comment C, vote_comment V\n\tWHERE C.thread_id='%s' AND V.comment_id=C.comment_id\n\tGROUP BY C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name)\n\tUNION\n\t(SELECT C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name,\n\t0 AS pro_vote, 0 AS total_vote,0 AS my_vote, 0 AS my_provote\n\tFROM comment C\n\tWHERE C.thread_id='%s' AND C.comment_id<>ALL(SELECT comment_id FROM vote_comment))\n\tORDER BY date ASC", $escaped_name, $escaped_name, $escaped_threadid, $escaped_threadid));
    if ($result) {
        while ($row = mysql_fetch_assoc($result)) {
            $is_proprio = check_property($row["rand_prop"], $row["hash_prop"]);
            $is_valid = $row["is_valid"];
            if ($is_valid || $is_proprio || $privileges > 3) {
                $comment = array();
                $comment['comment_id'] = $row["comment_id"];
                // comment id
                $comment['is_proprio'] = check_property($row["rand_prop"], $row["hash_prop"]);
                // 1 if the current user has posted the comment, else 0
                $comment['is_valid'] = $row["is_valid"];
                // 1 if comment has been accepted, else 0
                $comment['already_mod'] = $row["already_mod"];
                // 1 if comment has already been moderated, else 0
                $comment['date'] = $row['date'];
                // date the comment was posted
                $comment['possibly_name'] = $row['possibly_name'];
                // name of the author if available
                $comment['text'] = text_display_prepare(trim($row["text"]));
                // text of the comment
                $comment['my_vote'] = $row['my_vote'];
                // 1 if current user has voted for it, else 0
                $comment['my_provote'] = $row['my_provote'];
                // 1 if current user has voted +1, else 0
                $comment['pro_vote'] = $row['pro_vote'];
                // total of +1 votes
                $comment['total_vote'] = $row['total_vote'];
                // total number of votes
                $action->data[] = $comment;
                $action->set_result(True);
            }
        }
    }
    $action->output_result($output);
    return $action;
}