mirror of
https://github.com/e107inc/e107.git
synced 2025-07-26 01:11:28 +02:00
Comment sort pref added. Ajax comment submission complete.
This commit is contained in:
42
comment.php
42
comment.php
@@ -24,6 +24,48 @@
|
||||
require_once('class2.php');
|
||||
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE);
|
||||
|
||||
// print_r($_POST);
|
||||
// exit;
|
||||
|
||||
if(e_AJAX_REQUEST)
|
||||
{
|
||||
|
||||
if(vartrue($_POST['comment']) && USERID)
|
||||
{
|
||||
$pid = intval(varset($_POST['pid'], 0)); // ID of the specific comment being edited (nested comments - replies)
|
||||
|
||||
$clean_authorname = $_POST['author_name'];
|
||||
$clean_comment = $_POST['comment'];
|
||||
$clean_subject = $_POST['subject'];
|
||||
|
||||
$newid = e107::getComment()->enter_comment($clean_authorname, $clean_comment, $_POST['table'], intval($_POST['itemid']), $pid, $clean_subject);
|
||||
|
||||
if($newid)
|
||||
{
|
||||
$row['comment_id'] = $newid;
|
||||
$row['comment_item_id'] = intval($_POST['itemid']);
|
||||
$row['comment_type'] = e107::getComment()->getCommentType($tp->toDB($_POST['table'],true));
|
||||
$row['comment_subject'] = $_POST['subject'];
|
||||
$row['comment_comment'] = $_POST['comment'];
|
||||
$row['user_image'] = USERIMAGE;
|
||||
$row['user_id'] = USERID;
|
||||
$row['user_name'] = USERNAME;
|
||||
$row['comment_datestamp'] = time();
|
||||
$row['comment_blocked'] = (vartrue($pref['comments_moderate']) ? 2 : 0);
|
||||
|
||||
echo "\n<!-- Appended -->\n";
|
||||
echo e107::getComment()->render_comment($row,'comment',intval($_POST['itemid']));
|
||||
echo "\n<!-- end Appended -->\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(e_HANDLER."news_class.php");
|
||||
require_once(e_HANDLER."comment_class.php");
|
||||
define("PAGE_NAME", COMLAN_99);
|
||||
|
@@ -1293,6 +1293,7 @@ $text .= "
|
||||
".$frm->radio_switch('nested_comments', $pref['nested_comments'], LAN_YES, LAN_NO)."
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='label'>".PRFLAN_90.": </td>
|
||||
<td class='control'>
|
||||
@@ -1318,6 +1319,18 @@ $text .= "
|
||||
".$frm->radio_switch('comments_moderate', $pref['comments_moderate'], LAN_YES, LAN_NO)."
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class='label'>Comment Sorting: </td>
|
||||
<td class='control'>";
|
||||
|
||||
$comment_sort = array(
|
||||
"desc" => "Most recent comments first", //default //TODO LAN
|
||||
'asc' => "Most recent comments last"
|
||||
);
|
||||
|
||||
$text .= $frm->selectbox('comments_sort',$comment_sort, $pref['comments_moderate'])."
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
@@ -28,7 +28,7 @@ class comment_shortcodes extends e_shortcode
|
||||
|
||||
if(vartrue($pref['nested_comments']))
|
||||
{
|
||||
return "<input class='tbox comment subject-input' type='text' placeholder='".COMLAN_324." name='subject' size='61' value='".$tp->toForm($this->var['subject'])."' maxlength='100' />";
|
||||
return "<input class='tbox comment subject-input' type='text' placeholder='".COMLAN_324."' name='subject' size='61' value='".$tp->toForm($this->var['subject'])."' maxlength='100' />";
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -196,9 +196,13 @@ class comment_shortcodes extends e_shortcode
|
||||
|
||||
function sc_comment_button($parm)
|
||||
{
|
||||
$pref = e107::getPref('comments_sort');
|
||||
|
||||
if($this->mode == 'edit')
|
||||
{
|
||||
return "<input class='button' type='submit' name='".$this->var['action']."submit' value='".(isset($this->var['eaction']) && $this->var['eaction'] == "edit" ? COMLAN_320 : COMLAN_9)."' />";
|
||||
$value = (varset($this->var['eaction']) == "edit" ? COMLAN_320 : COMLAN_9);
|
||||
|
||||
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."' />";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -247,7 +251,7 @@ class comment_shortcodes extends e_shortcode
|
||||
}
|
||||
else
|
||||
{
|
||||
return e107::getForm()->textarea('comment',$this->var['comval'], 5, 80,$options);
|
||||
return e107::getForm()->textarea('comment',$this->var['comval'], 3, 80,$options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,8 @@
|
||||
<core name="comments_disabled">0</core>
|
||||
<core name="comments_emoticons">0</core>
|
||||
<core name="comments_icon">0</core>
|
||||
<core name="comments_moderate">0</core>
|
||||
<core name="comments_moderate">0</core>
|
||||
<core name="comments_sort">desc</core>
|
||||
<core name="compress_output">0</core>
|
||||
<core name="contact_emailcopy">0</core>
|
||||
<core name="cookie_name">e107cookie</core>
|
||||
|
@@ -423,6 +423,63 @@ $(document).ready(function()
|
||||
});
|
||||
|
||||
|
||||
$(".e-comment-submit").click(function(){
|
||||
|
||||
var url = $(this).attr("data-target");
|
||||
var sort = $(this).attr("data-sort");
|
||||
var data = $("form#e-comment-form").serialize();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url + '?ajax_used=1',
|
||||
data: data,
|
||||
success: function(html) {
|
||||
|
||||
$("#comment").val('');
|
||||
if(sort == 'desc')
|
||||
{
|
||||
$(html).prependTo('#comments-container').hide().slideDown(800);
|
||||
}
|
||||
else
|
||||
{
|
||||
$(html).appendTo('#comments-container').hide().slideDown(800);
|
||||
alert('Thank you for commenting'); // possibly needed as the submission may go unoticed by the user
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
$(".e-comment-delete").click(function(){ //TODO - for admin use on front-end.
|
||||
|
||||
var url = $(this).attr("data-target");
|
||||
var sort = $(this).attr("data-sort");
|
||||
var data = $("form#e-comment-form").serialize();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url + '?ajax_used=1',
|
||||
data: data,
|
||||
success: function(html) {
|
||||
// var sort = $(this).attr("data-sort");
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
$(".e-rate-thumb").click(function(){
|
||||
|
||||
var src = $(this).attr("href");
|
||||
@@ -449,7 +506,7 @@ $(document).ready(function()
|
||||
|
||||
$('#'+id +'-up').text(up);
|
||||
$('#'+id +'-down').text(down);
|
||||
|
||||
$(this).attr('title','Thanks for voting');
|
||||
// alert('Thanks for liking');
|
||||
}
|
||||
});
|
||||
|
@@ -42,6 +42,8 @@ class comment
|
||||
);
|
||||
|
||||
private $template;
|
||||
|
||||
private $totalComments = 0;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -221,7 +223,7 @@ 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='dataform' >";
|
||||
$text .= "<form method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' id='e-comment-form' >";
|
||||
|
||||
$data = array(
|
||||
'action' => $action,
|
||||
@@ -245,9 +247,11 @@ class comment
|
||||
$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" : "";
|
||||
|
||||
|
||||
$text .= "
|
||||
<input type='hidden' name='e-token' value='".e_TOKEN."' />\n
|
||||
<input type='hidden' name='table' value='".$table."' />\n
|
||||
<input type='hidden' name='itemid' value='".$itemid."' />\n
|
||||
</div>
|
||||
</form>
|
||||
</div>";
|
||||
@@ -428,6 +432,8 @@ class comment
|
||||
unset($width);
|
||||
}
|
||||
}
|
||||
|
||||
$this->totalComments = $this->totalComments + $sub_total;
|
||||
} // End (nested comment handling)
|
||||
|
||||
|
||||
@@ -608,11 +614,11 @@ class comment
|
||||
}
|
||||
|
||||
//if rateindex is posted, enter the rating from this user
|
||||
if ($rateindex)
|
||||
{
|
||||
$rater->enterrating($rateindex);
|
||||
}
|
||||
return true;
|
||||
// if ($rateindex)
|
||||
// {
|
||||
// $rater->enterrating($rateindex);
|
||||
// }
|
||||
return $inserted_id; // return the ID number so it can be used. true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -771,6 +777,8 @@ class comment
|
||||
|
||||
$sql = e107::getDb();
|
||||
$type = $this->getCommentType($table);
|
||||
$sort = vartrue($pref['comments_sort'],'desc');
|
||||
|
||||
if(vartrue($pref['nested_comments']))
|
||||
{
|
||||
$query = "SELECT c.*, u.*, ue.*, r.* FROM #comments AS c
|
||||
@@ -780,7 +788,7 @@ class comment
|
||||
|
||||
WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."' AND c.comment_pid='0'
|
||||
AND (c.comment_blocked = 0 OR (c.comment_blocked > 0 AND c.comment_author_id = ".intval(USERID)."))
|
||||
ORDER BY c.comment_datestamp";
|
||||
ORDER BY c.comment_datestamp ".$sort;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -795,16 +803,19 @@ class comment
|
||||
$query .= "WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."'
|
||||
AND (c.comment_blocked = 0 OR (c.comment_blocked > 0 AND c.comment_author_id = ".intval(USERID)."))
|
||||
|
||||
ORDER BY c.comment_datestamp";
|
||||
ORDER BY c.comment_datestamp ".$sort;
|
||||
}
|
||||
|
||||
// TODO Preference for sort-order.
|
||||
|
||||
|
||||
$text = "";
|
||||
$comment = '';
|
||||
$modcomment = '';
|
||||
$lock = '';
|
||||
$ret['comment'] = '';
|
||||
|
||||
if ($comment_total = $sql->db_Select_gen($query))
|
||||
if ($this->totalComments = $sql->db_Select_gen($query))
|
||||
{
|
||||
$width = 0;
|
||||
//Shortcodes could use $sql, so just grab all results
|
||||
@@ -825,10 +836,11 @@ class comment
|
||||
}
|
||||
}
|
||||
|
||||
if ($tablerender)
|
||||
{
|
||||
|
||||
// if ($tablerender)
|
||||
// {
|
||||
// $text = $ns->tablerender(COMLAN_99, $text, '', TRUE);
|
||||
}
|
||||
// }
|
||||
|
||||
if (ADMIN && getperms("B"))
|
||||
{
|
||||
@@ -852,12 +864,13 @@ class comment
|
||||
{
|
||||
|
||||
$search = array("{MODERATE}","{COMMENTS}","{COMMENTFORM}");
|
||||
$replace = array($modcomment,$text,$comment);
|
||||
$replace = array($modcomment,"<div id='comments-container'>\n".$text."\n</div>",$comment);
|
||||
$TEMPL = str_replace($search,$replace,$this->template['LAYOUT']);
|
||||
|
||||
if ($tablerender)
|
||||
{
|
||||
echo $ns->tablerender(COMLAN_99, $TEMPL, 'comment', TRUE);
|
||||
|
||||
echo $ns->tablerender($this->totalComments." ".COMLAN_99, $TEMPL, 'comment', TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -113,7 +113,6 @@ $COMMENT_TEMPLATE['ITEM'] = '
|
||||
</div>
|
||||
|
||||
<div class="comment-box-right">
|
||||
|
||||
<div class="P10">
|
||||
|
||||
<span class="comment-box-username">{USERNAME}</span>
|
||||
@@ -121,26 +120,18 @@ $COMMENT_TEMPLATE['ITEM'] = '
|
||||
|
||||
<span class="comment-status">{COMMENT_STATUS}</span>
|
||||
<div class="comment-user-badge-bar">
|
||||
{COMMENT_RATE}
|
||||
{REPLY}
|
||||
{COMMENTEDIT}
|
||||
|
||||
|
||||
|
||||
{COMMENT_RATE}{REPLY}{COMMENTEDIT}
|
||||
</div>
|
||||
|
||||
<div class="clear_b H5"><!-- --></div>
|
||||
|
||||
{COMMENT}
|
||||
{COMMENT_MOD//ERATE}
|
||||
|
||||
|
||||
<div id="{COMMENT_ITEMID}-edit">{COMMENT}</div>
|
||||
{COMMENT_MOD//ERATE}
|
||||
</div>
|
||||
|
||||
</div>';
|
||||
|
||||
$COMMENT_TEMPLATE['ITEM_START'] = '<div id="{COMMENT_ITEMID}" class="comment-box clearfix">';
|
||||
$COMMENT_TEMPLATE['ITEM_END'] = '</div><div class="clear_b"><!-- --></div>';
|
||||
$COMMENT_TEMPLATE['ITEM_START'] = "\n\n<div id='{COMMENT_ITEMID}' class='comment-box clearfix'>\n";
|
||||
$COMMENT_TEMPLATE['ITEM_END'] = "\n</div><div class='clear_b'><!-- --></div>\n";
|
||||
|
||||
|
||||
$COMMENT_TEMPLATE['LAYOUT'] = '{COMMENTFORM}{COMMENTS}{MODERATE}';
|
||||
|
||||
|
Reference in New Issue
Block a user