1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-10 09:36:23 +02:00

Issue #1944 (Partial fix) Comments use unique IDs.

This commit is contained in:
Cameron
2019-04-11 15:52:41 -07:00
parent 93f4146f03
commit c1e3e8889f
5 changed files with 66 additions and 51 deletions

View File

@ -85,7 +85,7 @@ if(e_AJAX_REQUEST) // TODO improve security
if(!vartrue($_POST['comment']) && varset($_GET['mode']) == 'submit') if(!vartrue($_POST['comment']) && varset($_GET['mode']) == 'submit')
{ {
$ret['error'] = true; $ret['error'] = true;
$ret['msg'] = COMLAN_336; $ret['msg'] = COMLAN_336." - ".implode(" ",$_GET);
echo json_encode($ret); echo json_encode($ret);
exit; exit;
} }

View File

@ -21,7 +21,7 @@ class comment_shortcodes extends e_shortcode
{ {
var $var; var $var;
function sc_subject_input($parm = '') function sc_subject_input($parm = null)
{ {
$tp = e107::getParser(); $tp = e107::getParser();
$pref = e107::getPref(); $pref = e107::getPref();
@ -65,7 +65,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_username($parm='') function sc_username($parm = null)
{ {
global $USERNAME; global $USERNAME;
if (isset($this->var['comment_author_id']) && $this->var['comment_author_id']) if (isset($this->var['comment_author_id']) && $this->var['comment_author_id'])
@ -82,7 +82,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_timedate($parm='') function sc_timedate($parm = null)
{ {
if($parm == 'relative') if($parm == 'relative')
{ {
@ -93,7 +93,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_reply($parm='') function sc_reply($parm = null)
{ {
global $REPLY, $action, $table, $id, $thisaction, $thistable, $thisid; global $REPLY, $action, $table, $id, $thisaction, $thistable, $thisid;
@ -136,7 +136,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_avatar($parm='') function sc_avatar($parm = null)
{ {
return $this->sc_comment_avatar($parm); return $this->sc_comment_avatar($parm);
@ -162,14 +162,14 @@ class comment_shortcodes extends e_shortcode
} }
function sc_comments($parm='') function sc_comments($parm = null)
{ {
global $COMMENTS; global $COMMENTS;
return (isset($this->var['user_id']) && $this->var['user_id'] ? LAN_COMMENTS.": ".$this->var['user_comments'] : COMLAN_194)."<br />"; return (isset($this->var['user_id']) && $this->var['user_id'] ? LAN_COMMENTS.": ".$this->var['user_comments'] : COMLAN_194)."<br />";
} }
function sc_joined($parm='') function sc_joined($parm = null)
{ {
global $JOINED, $gen; global $JOINED, $gen;
$JOINED = ''; $JOINED = '';
@ -181,17 +181,17 @@ class comment_shortcodes extends e_shortcode
} }
function sc_comment_itemid($parm='') // for ajax item id. function sc_comment_itemid($parm = null) // for ajax item id.
{ {
return 'comment-'.intval($this->var['comment_id']); return 'comment-'.intval($this->var['comment_id']);
} }
function sc_comment_moderate($parm='') function sc_comment_moderate($parm = null)
{ {
if(!getperms('0') && !getperms("B")) if(!getperms('0') && !getperms("B"))
{ {
return; return null;
} }
// TODO put into a <ul> drop-down format. // TODO put into a <ul> drop-down format.
@ -219,7 +219,7 @@ class comment_shortcodes extends e_shortcode
/* example {COMMENT_BUTTON} */ /* example {COMMENT_BUTTON} */
/* example {COMMENT_BUTTON: class=btn btn-default pull-right} */ /* example {COMMENT_BUTTON: class=btn btn-default pull-right} */
function sc_comment_button($parm = '') function sc_comment_button($parm = null)
{ {
$pref = e107::getPref('comments_sort'); $pref = e107::getPref('comments_sort');
$form = e107::getForm(); $form = e107::getForm();
@ -236,6 +236,8 @@ class comment_shortcodes extends e_shortcode
'data-pid' => $pid, 'data-pid' => $pid,
'data-sort' => $pref, 'data-sort' => $pref,
'data-target' => e_HTTP . 'comment.php', 'data-target' => e_HTTP . 'comment.php',
'data-container' => 'comments-container-'.$form->name2id($this->var['table']),
'data-input' => 'comment-input-'.$form->name2id($this->var['table'])
); );
return $form->submit($this->var['action'] . 'submit', $value, $options); return $form->submit($this->var['action'] . 'submit', $value, $options);
@ -244,7 +246,7 @@ class comment_shortcodes extends e_shortcode
/* example {AUTHOR_INPUT} */ /* example {AUTHOR_INPUT} */
/* example {AUTHOR_INPUT: inputclass=form-control&class=form-group} */ /* example {AUTHOR_INPUT: inputclass=form-control&class=form-group} */
function sc_author_input($parm = '') function sc_author_input($parm = null)
{ {
if($this->mode == 'edit') if($this->mode == 'edit')
{ {
@ -277,12 +279,12 @@ class comment_shortcodes extends e_shortcode
} }
function sc_comment_rate($parm='') function sc_comment_rate($parm = null)
{ {
if($this->var['comment_blocked'] > 0 || $this->var['rating_enabled'] == false) if($this->var['comment_blocked'] > 0 || $this->var['rating_enabled'] == false)
{ {
return; return null;
} }
$curVal = array( $curVal = array(
@ -296,7 +298,7 @@ class comment_shortcodes extends e_shortcode
/* example {COMMENT_INPUT} */ /* example {COMMENT_INPUT} */
/* example {COMMENT_INPUT: inputclass=form-control&class=form-group} */ /* example {COMMENT_INPUT: inputclass=form-control&class=form-group} */
function sc_comment_input($parm = '') function sc_comment_input($parm = null)
{ {
$inputclass = (!empty($parm['inputclass'])) ? $parm['inputclass'] : 'comment-input form-control'; $inputclass = (!empty($parm['inputclass'])) ? $parm['inputclass'] : 'comment-input form-control';
@ -304,6 +306,7 @@ class comment_shortcodes extends e_shortcode
$options = array( $options = array(
'class' => $inputclass, 'class' => $inputclass,
'placeholder' => COMLAN_403, 'placeholder' => COMLAN_403,
'id' => 'comment-input-'.e107::getForm()->name2id($this->var['table'])
); );
$text = '<div class="'.$class.'">'; $text = '<div class="'.$class.'">';
@ -324,7 +327,7 @@ class comment_shortcodes extends e_shortcode
/* /*
function sc_user_avatar($parm='') function sc_user_avatar($parm = null)
{ {
$this->var['user_id'] = USERID; $this->var['user_id'] = USERID;
$this->var['user_image'] = USERIMAGE; $this->var['user_image'] = USERIMAGE;
@ -333,7 +336,7 @@ class comment_shortcodes extends e_shortcode
*/ */
function sc_comment($parm='') function sc_comment($parm=null)
{ {
// global $COMMENT, $pref; // global $COMMENT, $pref;
$tp = e107::getParser(); $tp = e107::getParser();
@ -346,7 +349,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_comment_status($parm='') function sc_comment_status($parm = null)
{ {
switch ($this->var['comment_blocked']) switch ($this->var['comment_blocked'])
{ {
@ -359,7 +362,7 @@ class comment_shortcodes extends e_shortcode
break; break;
default: default:
return; return null;
break; break;
} }
@ -368,7 +371,7 @@ class comment_shortcodes extends e_shortcode
function sc_commentedit($parm='') function sc_commentedit($parm = null)
{ {
global $COMMENTEDIT, $comment_edit_query; global $COMMENTEDIT, $comment_edit_query;
$pref = e107::getPref(); $pref = e107::getPref();
@ -394,14 +397,14 @@ class comment_shortcodes extends e_shortcode
} }
function sc_rating($parm='') function sc_rating($parm = null)
{ {
global $RATING; global $RATING;
return $RATING; return $RATING;
} }
function sc_ipaddress($parm='') function sc_ipaddress($parm = null)
{ {
global $IPADDRESS, $e107; global $IPADDRESS, $e107;
//require_once(e_HANDLER."encrypt_handler.php"); //require_once(e_HANDLER."encrypt_handler.php");
@ -409,16 +412,16 @@ class comment_shortcodes extends e_shortcode
} }
function sc_level($parm='') function sc_level($parm = null)
{ {
global $LEVEL, $pref; global $LEVEL, $pref;
//FIXME - new level handler, currently commented to avoid parse errors //FIXME - new level handler, currently commented to avoid parse errors
//$ldata = get_level($this->var['user_id'], $this->var['user_forums'], $this->var['user_comments'], $this->var['user_chats'], $this->var['user_visits'], $this->var['user_join'], $this->var['user_admin'], $this->var['user_perms'], $pref); //$ldata = get_level($this->var['user_id'], $this->var['user_forums'], $this->var['user_comments'], $this->var['user_chats'], $this->var['user_visits'], $this->var['user_join'], $this->var['user_admin'], $this->var['user_perms'], $pref);
return ($this->var['user_admin'] ? vartrue($ldata[0]) : vartrue($ldata[1])); //return ($this->var['user_admin'] ? vartrue($ldata[0]) : vartrue($ldata[1]));
} }
function sc_location($parm='') function sc_location($parm = null)
{ {
global $LOCATION; global $LOCATION;
$tp = e107::getParser(); $tp = e107::getParser();
@ -426,7 +429,7 @@ class comment_shortcodes extends e_shortcode
} }
function sc_signature($parm='') function sc_signature($parm = null)
{ {
global $SIGNATURE; global $SIGNATURE;
$tp = e107::getParser(); $tp = e107::getParser();
@ -435,11 +438,11 @@ class comment_shortcodes extends e_shortcode
} }
function sc_comment_share($parm='') function sc_comment_share($parm = null)
{ {
if(!$xup = e107::getUser()->getProviderName()) if(!$xup = e107::getUser()->getProviderName())
{ {
return; return null;
} }
list($prov,$id) = explode("_",$xup); list($prov,$id) = explode("_",$xup);

View File

@ -1078,6 +1078,7 @@ class comment
$tp = e107::getParser(); $tp = e107::getParser();
$ns = e107::getRender(); $ns = e107::getRender();
$pref = e107::getPref(); $pref = e107::getPref();
$frm = e107::getForm();
if ($this->getCommentPermissions() === FALSE) return; if ($this->getCommentPermissions() === FALSE) return;
@ -1167,14 +1168,16 @@ class comment
$comment = "<br /><div style='text-align:center'><b>".COMLAN_328."</b></div>"; $comment = "<br /><div style='text-align:center'><b>".COMLAN_328."</b></div>";
} }
$containerTarget = "comments-container-".$frm->name2id($table);
if($text) if($text)
{ {
//XXX Do NOT add to template - too important to allow for modification. //XXX Do NOT add to template - too important to allow for modification.
$text = "<ul class='media-list' id='comments-container'>\n".$text."\n</ul>"; $text = "<ul class='media-list comments-container' id='".$containerTarget."'>\n".$text."\n</ul>";
} }
else else
{ {
$text = "<ul class='media-list' id='comments-container'><li><!-- --></li></ul>"; $text = "<ul class='media-list comments-container' id='".$containerTarget."'><li><!-- --></li></ul>";
} }
@ -1322,6 +1325,9 @@ class comment
//return "table=".$table." id=".$id." from=".$from; //return "table=".$table." id=".$id." from=".$from;
//$from = $from + $this->commentsPerPage; //$from = $from + $this->commentsPerPage;
$target = "comments-container-".e107::getForm()->name2id($table);
$navid = 'comments-nav-'.e107::getForm()->name2id($table);
// from calculations are done by eNav() js. // from calculations are done by eNav() js.
if($this->totalComments > $this->commentsPerPage) if($this->totalComments > $this->commentsPerPage)
@ -1329,8 +1335,8 @@ class comment
$prev = e_HTTP . 'comment.php?mode=list&amp;type=' . $table . '&amp;id=' . $id . '&amp;from=0'; $prev = e_HTTP . 'comment.php?mode=list&amp;type=' . $table . '&amp;id=' . $id . '&amp;from=0';
$next = e_HTTP . 'comment.php?mode=list&amp;type=' . $table . '&amp;id=' . $id . '&amp;from=0'; $next = e_HTTP . 'comment.php?mode=list&amp;type=' . $table . '&amp;id=' . $id . '&amp;from=0';
return "<a class='e-ajax btn btn-default btn-secondary btn-mini btn-sm' href='#' data-nav-total='{$this->totalComments}' data-nav-dir='down' data-nav-inc='{$this->commentsPerPage}' data-target='comments-container' data-src='{$prev}'>" . LAN_PREVIOUS . "</a> return "<a class='e-ajax btn btn-default btn-secondary btn-mini btn-sm {$navid}' href='#' data-nav-id='{$navid}' data-nav-total='{$this->totalComments}' data-nav-dir='down' data-nav-inc='{$this->commentsPerPage}' data-target='{$target}' data-src='{$prev}'>" . LAN_PREVIOUS . "</a>
<a class='e-ajax btn btn-default btn-secondary btn-mini btn-sm' href='#' data-nav-total='{$this->totalComments}' data-nav-dir='up' data-nav-inc='{$this->commentsPerPage}' data-target='comments-container' data-src='{$next}'>" . LAN_NEXT . "</a>"; <a class='e-ajax btn btn-default btn-secondary btn-mini btn-sm {$navid}' href='#' data-nav-id='{$navid}' data-nav-total='{$this->totalComments}' data-nav-dir='up' data-nav-inc='{$this->commentsPerPage}' data-target='{$target}' data-src='{$next}'>" . LAN_NEXT . "</a>";
} }
} }

View File

@ -166,6 +166,7 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
ajaxOptions.url = $element.attr('data-src'); ajaxOptions.url = $element.attr('data-src');
// Set Ajax type to "GET". // Set Ajax type to "GET".
ajaxOptions.type = 'GET'; ajaxOptions.type = 'GET';
} }
if(ajaxOptions.wait != null) if(ajaxOptions.wait != null)
@ -428,6 +429,7 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
var val = src.match(/from=(\d+)/); var val = src.match(/from=(\d+)/);
var amt = parseInt(val[1]); var amt = parseInt(val[1]);
var oldVal = 'from=' + amt; var oldVal = 'from=' + amt;
var newVal = null; var newVal = null;
@ -456,6 +458,11 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
newVal = 'from=' + add; newVal = 'from=' + add;
} }
if($(e).attr("data-nav-id"))
{
navid = '.' + $(e).attr("data-nav-id");
}
if(newVal) if(newVal)
{ {
src = src.replace(oldVal, newVal); src = src.replace(oldVal, newVal);

View File

@ -155,8 +155,12 @@ $(document).ready(function()
var sort = $(this).attr("data-sort"); var sort = $(this).attr("data-sort");
var pid = parseInt($(this).attr("data-pid")); var pid = parseInt($(this).attr("data-pid"));
var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form"; var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form";
var data = $('form'+formid).serialize() ; var data = $('form'+formid).serializeArray() ;
var total = parseInt($("#e-comment-total").text()); var total = parseInt($("#e-comment-total").text());
var container = '#' + $(this).attr("data-container");
var input = '#' + $(this).attr("data-input");
//TODO replace _POST['comment'] with $(input).val() so we can rename 'comment' in the form to something unique.
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -168,13 +172,7 @@ $(document).ready(function()
// console.log(data); // console.log(data);
var a = $.parseJSON(data); var a = $.parseJSON(data);
$("#comment").val(''); $(input).val('');
if($('#comments-container').length){
// alert('true');
}else{
// $("#e-comment-form").parent().prepend("<div id='comments-container'></div>");
}
if(pid != 0) if(pid != 0)
{ {
@ -182,17 +180,18 @@ $(document).ready(function()
} }
else if(sort == 'desc') else if(sort == 'desc')
{ {
$('#comments-container').prepend(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8 $(container).prepend(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
} }
else else
{ {
$('#comments-container').append(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8 $(container).append(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
alert('Thank you for commenting'); // possibly needed as the submission may go unoticed by the user alert('Thank you for commenting'); // possibly needed as the submission may go unoticed by the user
} }
if(!a.error) if(!a.error)
{ {
$("#e-comment-total").text(total + 1); $("#e-comment-total").text(total + 1);
if(pid != '0') if(pid != '0')
{ {
$(formid).hide(); $(formid).hide();