1
0
mirror of https://github.com/e107inc/e107.git synced 2025-06-05 10:25:17 +02:00

Comment replies

This commit is contained in:
CaMer0n 2012-06-17 08:08:01 +00:00
parent ece6cdac0c
commit 5032fe7e84
5 changed files with 142 additions and 32 deletions

View File

@ -24,6 +24,11 @@
require_once('class2.php');
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE);
if (vartrue(e107::getPref('comments_disabled')))
{
exit;
}
if(e_AJAX_REQUEST) // TODO improve security
{
@ -33,8 +38,24 @@ if(e_AJAX_REQUEST) // TODO improve security
exit;
}
$ret = array();
if(varset($_GET['mode']) == 'reply' && vartrue($_POST['itemid']))
{
$status = e107::getComment()->replyComment($_POST['itemid']);
$ret['msg'] = "Couldn't delete comment";
$ret['error'] = ($status) ? false : true;
$ret['html'] = $status;
echo json_encode($ret);
exit;
}
if(varset($_GET['mode']) == 'delete' && vartrue($_POST['itemid']))
{
$status = e107::getComment()->deleteComment($_POST['itemid']);
@ -53,6 +74,7 @@ if(e_AJAX_REQUEST) // TODO improve security
echo json_encode($ret);
exit;
}
if(!vartrue($_POST['comment']) && varset($_GET['mode']) == 'submit')
{
@ -68,13 +90,15 @@ if(e_AJAX_REQUEST) // TODO improve security
$error = e107::getComment()->updateComment($_POST['itemid'],$_POST['comment']);
$ret['error'] = ($error) ? true : false;
$ret['msg'] = ($error) ? $error : "Saved!!!"; //TODO Common LAN
$ret['msg'] = ($error) ? $error : "Updated Successfully."; //TODO Common LAN
echo json_encode($ret);
exit;
}
// Insert Comment and return rendered html.
if(vartrue($_POST['comment']) && USERID) // ajax render comment
{
@ -100,8 +124,10 @@ if(e_AJAX_REQUEST) // TODO improve security
$row['comment_datestamp'] = time();
$row['comment_blocked'] = (vartrue($pref['comments_moderate']) ? 2 : 0);
$width = ($pid) ? 5 : 0;
$ret['html'] = "\n<!-- Appended -->\n";
$ret['html'] .= e107::getComment()->render_comment($row,'comment',intval($_POST['itemid']));
$ret['html'] .= e107::getComment()->render_comment($row,'comments','comment',intval($_POST['itemid']),$width);
$ret['html'] .= "\n<!-- end Appended -->\n";
$ret['error'] = false;

View File

@ -32,7 +32,7 @@ e107::css("inline","
.admin-theme-options { transition: opacity .20s ease-in-out;
-moz-transition: opacity .20s ease-in-out;
-webkit-transition: opacity .20s ease-in-out;
opacity:0.1;
opacity:0;
width:100%;
height:80px;
padding-top:50px;

View File

@ -91,7 +91,7 @@ class comment_shortcodes extends e_shortcode
{
if ($thisaction == "comment" && $pref['nested_comments'])
{
$REPLY = "<a href='".SITEURL."comment.php?reply.".$thistable.".".$this->var['comment_id'].".".$thisid."'>".COMLAN_326."</a>";
$REPLY = "<a id='e-comment-reply-".$this->var['comment_id']."' class='e-comment-reply' data-type='".$this->var['comment_type']."' data-target='".e_BASE."comment.php' href='".SITEURL."comment.php?reply.".$thistable.".".$this->var['comment_id'].".".$thisid."'>".COMLAN_326."</a>";
}
}
return $REPLY;
@ -209,9 +209,10 @@ class comment_shortcodes extends e_shortcode
if($this->mode == 'edit')
{
$value = (varset($this->var['eaction']) == "edit" ? COMLAN_320 : COMLAN_9);
$value = (varset($this->var['eaction']) == "edit" ? COMLAN_320 : COMLAN_9);
$pid = ($this->var['action'] == 'reply') ? $this->var['pid'] : 0;
return "<input data-sort='".$pref."' data-target='".e_BASE."comment.php' class='button e-comment-submit' type='submit' name='".$this->var['action']."submit' value='".$value."' />";
return "<input data-pid='{$pid}' data-sort='{$pref}' data-target='".e_BASE."comment.php' class='button e-comment-submit' type='submit' name='".$this->var['action']."submit' value='".$value."' />";
}
}

View File

@ -2,30 +2,37 @@
$(document).ready(function()
{
$(":input").tipsy({gravity: 'w',fade: true});
$(":input").tipsy({gravity: 'w',fade: true, live: true});
$(".e-tip").tipsy({gravity: 'sw',fade: true});
$(".e-tip").tipsy({gravity: 'sw',fade: true, live: true});
$(".e-comment-submit").click(function(){
$(".e-comment-submit").live("click", function(){
var url = $(this).attr("data-target");
var sort = $(this).attr("data-sort");
var data = $("form#e-comment-form").serialize();
var total = parseInt($("#e-comment-total").text());
var url = $(this).attr("data-target");
var sort = $(this).attr("data-sort");
var pid = parseInt($(this).attr("data-pid"));
var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form";
var data = $('form'+formid).serialize() ;
var total = parseInt($("#e-comment-total").text());
$.ajax({
type: 'POST',
url: url + '?ajax_used=1&mode=submit',
data: data,
success: function(html) {
success: function(data) {
console.log(html);
var a = $.parseJSON(html);
// console.log(data);
var a = $.parseJSON(data);
$("#comment").val('');
if(sort == 'desc')
if(pid != 0)
{
$('#comment-'+pid).after(a.html).hide().slideDown(800);
}
else if(sort == 'desc')
{
$(a.html).prependTo('#comments-container').hide().slideDown(800);
}
@ -37,7 +44,12 @@ $(document).ready(function()
if(!a.error)
{
$("#e-comment-total").text(total + 1);
$("#e-comment-total").text(total + 1);
if(pid != '0')
{
$(formid).hide();
}
}
else
{
@ -53,6 +65,47 @@ $(document).ready(function()
$(".e-comment-reply").live("click", function(){
var url = $(this).attr("data-target");
var table = $(this).attr("data-type");
var sp = $(this).attr('id').split("-");
var id = "#comment-" + sp[3];
if($('.e-comment-edit-save').length != 0) //prevent creating save button twice.
{
return false;
}
$.ajax({
type: 'POST',
url: url + '?ajax_used=1&mode=reply',
data: { itemid: sp[3], table: table },
success: function(data) {
var a = $.parseJSON(data);
if(!a.error)
{
// alert(a.html);
$(id).after(a.html).hide().slideDown(800);
}
}
});
return false;
});
$(".e-comment-edit").live("click", function(){
var url = $(this).attr("data-target");
@ -195,14 +248,18 @@ $(document).ready(function()
$(".e-rate-thumb").click(function(){
$(".e-rate-thumb").live("click", function(){
var src = $(this).attr("href");
var tmp = src.split('#');
id = tmp[1];
src = tmp[0];
var src = $(this).attr("href");
var thumb = $(this);
var tmp = src.split('#');
var id = tmp[1];
var src = tmp[0];
$.ajax({
type: "POST",
url: src,
@ -221,7 +278,7 @@ $(document).ready(function()
$('#'+id +'-up').text(up);
$('#'+id +'-down').text(down);
$(this).attr('title','Thanks for voting');
thumb.attr('title','Thanks for voting');
// alert('Thanks for liking');
}
});

View File

@ -113,6 +113,27 @@ class comment
}
function replyComment($id) // Ajax Reply.
{
$sql = e107::getDb();
if($sql->db_Select("comments","*","comment_id= ".intval($id)." LIMIT 1"))
{
$row = $sql->db_Fetch();
// [comment_id] =&gt; 65
return $this->form_comment('reply', $row['comment_type'], $row['comment_item_id'], $row['comment_subject'], false, true,false,false,$id);
}
}
/**
* Display the comment editing form
*
@ -125,7 +146,7 @@ class comment
* @param unknown_type $rating
* @return unknown
*/
function form_comment($action, $table, $id, $subject, $content_type, $return = FALSE, $rating = FALSE, $tablerender = TRUE)
function form_comment($action, $table, $id, $subject, $content_type, $return = FALSE, $rating = FALSE, $tablerender = TRUE,$pid = false)
{
//rating : boolean, to show rating system in comment
@ -222,8 +243,11 @@ class comment
// -------------------------------------------------------------
$text = "\n<div id='e-comment-form'>\n".e107::getMessage()->render('postcomment', true, false, false);//temporary here
$text .= "<form method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' id='e-comment-form' >";
$indent = ($action == 'reply') ? "style='margin-left:40px'" : "";
$formid = ($action == 'reply') ? "e-comment-form-reply" : "e-comment-form";
$text = "\n<div id='{$formid}' {$indent}>\n".e107::getMessage()->render('postcomment', true, false, false);//temporary here
$text .= "<form id='{$formid}' method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' >";
$data = array(
'action' => $action,
@ -231,6 +255,7 @@ class comment
'table' => $table,
'comval' => strip_tags(trim($comval)),
'itemid' => $itemid,
'pid' => $pid,
'eaction' => $eaction,
'rate' => $rate
);
@ -241,9 +266,9 @@ class comment
$text .= $tp->parseTemplate($this->template['FORM'], TRUE, e107::getScBatch('comment'));
$text .= "<div>"; // All Hidden Elements.
$text .= "\n<div>\n"; // All Hidden Elements.
$text .= (isset($action) && $action == "reply" ? "<input type='hidden' name='pid' value='{$id}' />" : '');
$text .= (varset($action) == "reply" && $pid ? "<input type='hidden' name='pid' value='{$pid}' />" : '');
$text .=(isset($eaction) && $eaction == "edit" ? "<input type='hidden' name='editpid' value='{$id}' />" : "");
$text .=(isset($content_type) && $content_type ? "<input type='hidden' name='content_type' value='{$content_type}' />" : '');
// $text .= (!$pref['nested_comments']) ? "<input type='hidden' name='subject' value='".$tp->toForm($subject)."' />\n" : "";
@ -254,8 +279,9 @@ class comment
<input type='hidden' name='table' value='".$table."' />\n
<input type='hidden' name='itemid' value='".$itemid."' />\n
</div>
</form>
</div>";
</form>\n";
$text .= "</div>";
if ($tablerender)
{