Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SITE: improved get_comment action and made it callable through ajax.php

  • Loading branch information...
commit 1f56ca7a6055a725e33dae9e1fcb245831b70814 1 parent bd61831
@Asimov4 Asimov4 authored
View
10 SITE/ajax.php
@@ -25,7 +25,9 @@
include_once("config.php");
include_once("script_php/pages_secondlevel/actions.php");
-include_once("script_php/pages_secondlevel/comments.php");
+
+$privileges = user_privilege_level();
+$login = $_SESSION['login_c'];
// Demande
@@ -39,11 +41,11 @@
{
// appel de la fonction post par Ajax
case "post":
- post($_POST['title'],$_POST['message'],$_POST['anonymization'],$_POST['category'],$_SESSION['login_c'],$valid=0,$output='JSON');
+ post($_POST['title'],$_POST['message'],$_POST['anonymization'],$_POST['category'],$login,$valid=0,$output='JSON');
break;
- case "unrollcomment":
- affichage_comments(27);
+ case "comments":
+ get_comments(27,$privileges,$login,$output='JSON');
break;
// Message d'erreur
View
12 SITE/examples/example_unrollcomments.php
@@ -27,7 +27,7 @@
<body>
-<a class='speccom' href="?action=unrollcomment&amp;order=0&amp;thread_id=27#a27">
+<a class='speccom' href="?action=comments&amp;order=0&amp;thread_id=27#a27">
<span class="newslinkcomment_roll">2 comments</span>
</a>
@@ -56,11 +56,15 @@
url: url,
success: function(rep)
{
- $('.newsformcomment').html(rep);
+ var display = '<ul>';
+ var callback = jQuery.parseJSON(rep);
+ $.each(callback.DATA, function(key,comment) {
+ display = display + '<li>' + comment.text + ' - ' + comment.possibly_name + ' - ' + comment.date + '</li>';
+ });
+ display = display + '</ul>';
+ $('.newsformcomment').html(display);
}
});
-
-
return false;
View
69 SITE/script_php/pages_secondlevel/actions.php
@@ -25,6 +25,7 @@
include_once("tool.php");
include_once("errors.php");
include_once("votes.php");
+include_once("comments.php");
/**
* class for action functions
@@ -34,6 +35,7 @@ class action {
var $result = False; // Result of the action
var $warnings = array(); // list of generated warnings
var $successes = array(); // list of generated successes
+ var $data = array();
// set result
function set_result($result) {
@@ -66,7 +68,7 @@ function echo_successes() {
// display all results in JSON format
function output_result($output) {
- $array = array( 'RESULT' => $this->result, 'WARNINGS' => $this->warnings, 'SUCCESSES' => $this->successes );
+ $array = array( 'RESULT' => $this->result, 'WARNINGS' => $this->warnings, 'SUCCESSES' => $this->successes, 'DATA' => $this->data );
if ($output == 'JSON') {
echo json_encode($array);
@@ -164,5 +166,70 @@ function post($title,$message,$anonymization,$category,$login,$valid=0,$output='
return $action;
}
+
+/**
+ * returns a list of comments for a given thread id
+ *
+ * @param string $title title of the idea
+ * @param string $message message of the idea
+ * @param string $anonymization tells if idea is to be anonymized
+ * @param integer $category id of the category for the idea
+ * @param string $login login of the poster
+ * @param integer $valid says if the idea needs to be moderated (default 0 = needs moderation)
+ * @return array
+ */
+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,
+ SUM(V.vote) AS pro_vote, COUNT(V.vote) AS total_vote,
+ MAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop) AS my_vote,
+ MAX(CAST(SHA1(CONCAT('%s',CAST(V.rand_prop AS CHAR))) AS CHAR)=V.hash_prop AND V.vote) AS my_provote
+ FROM comment C, vote_comment V
+ WHERE C.thread_id='%s' AND V.comment_id=C.comment_id
+ GROUP BY C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name)
+ UNION
+ (SELECT C.comment_id,C.rand_prop,C.hash_prop,C.text,C.date,C.is_valid,C.already_mod,C.possibly_name,
+ 0 AS pro_vote, 0 AS total_vote,0 AS my_vote, 0 AS my_provote
+ FROM comment C
+ WHERE C.thread_id='%s' AND C.comment_id<>ALL(SELECT comment_id FROM vote_comment))
+ ORDER 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['is_proprio'] = check_property($row["rand_prop"],$row["hash_prop"]);
+ $comment['is_valid'] = $row["is_valid"];
+ $comment['already_mod'] = $row["already_mod"];
+ $comment['date'] = $row['date'];
+ $comment['possibly_name'] = $row['possibly_name'];
+ $comment['text'] = text_display_prepare(trim($row["text"]));
+ $comment['my_vote'] = $row['my_vote'];
+ $comment['my_provote'] = $row['my_provote'];
+ $comment['total_vote'] = $row['total_vote'];
+
+ $action->data[$row["comment_id"]] = $comment;
+
+ }
+ }
+ }
+
+ $action->output_result($output);
+ return $action;
+}
+
?>
View
4 SITE/script_php/pages_secondlevel/comments.php
@@ -772,7 +772,7 @@ function display_speccom($unique_mode,$ancre,$thread_id,$nb_comment,$roll) {
}
// display a comment with all its wrapper
-function display_comment($row,$is_logged,$privileges,$is_admin,$unique_mode) {
+function display_comment($row,$is_logged,$privileges,$unique_mode) {
$is_proprio=check_property($row["rand_prop"],$row["hash_prop"]);
$is_valid=$row["is_valid"];
@@ -1047,7 +1047,7 @@ function affichage_comments($thread_id,$moderation_mode=false,$unique_mode=false
{
// afficher les commentaires
- display_comment($row,$is_logged,$privileges,$is_admin,$unique_mode);
+ display_comment($row,$is_logged,$privileges,$unique_mode);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.