diff --git a/comment.php b/comment.php
index 490c7f110..aed4684c0 100644
--- a/comment.php
+++ b/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\n";
+ echo e107::getComment()->render_comment($row,'comment',intval($_POST['itemid']));
+ echo "\n\n";
+ }
+ }
+
+
+
+
+
+ exit;
+}
+
require_once(e_HANDLER."news_class.php");
require_once(e_HANDLER."comment_class.php");
define("PAGE_NAME", COMLAN_99);
diff --git a/e107_admin/prefs.php b/e107_admin/prefs.php
index 153819f1b..204891138 100644
--- a/e107_admin/prefs.php
+++ b/e107_admin/prefs.php
@@ -1293,6 +1293,7 @@ $text .= "
".$frm->radio_switch('nested_comments', $pref['nested_comments'], LAN_YES, LAN_NO)."
+
".PRFLAN_90.": |
@@ -1318,6 +1319,18 @@ $text .= "
".$frm->radio_switch('comments_moderate', $pref['comments_moderate'], LAN_YES, LAN_NO)."
|
+
+ Comment Sorting: |
+ ";
+
+ $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'])."
+ |
+
diff --git a/e107_core/shortcodes/batch/comment_shortcodes.php b/e107_core/shortcodes/batch/comment_shortcodes.php
index 821403f47..88c69c4df 100644
--- a/e107_core/shortcodes/batch/comment_shortcodes.php
+++ b/e107_core/shortcodes/batch/comment_shortcodes.php
@@ -28,7 +28,7 @@ class comment_shortcodes extends e_shortcode
if(vartrue($pref['nested_comments']))
{
- return "";
+ return "";
}
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 "var['eaction'] == "edit" ? COMLAN_320 : COMLAN_9)."' />";
+ $value = (varset($this->var['eaction']) == "edit" ? COMLAN_320 : COMLAN_9);
+
+ return "";
}
}
@@ -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);
}
}
diff --git a/e107_core/xml/default_install.xml b/e107_core/xml/default_install.xml
index f5e8f25ff..f0a93a656 100644
--- a/e107_core/xml/default_install.xml
+++ b/e107_core/xml/default_install.xml
@@ -25,7 +25,8 @@
0
0
0
- 0
+ 0
+ desc
0
0
e107cookie
diff --git a/e107_files/jslib/core/all.jquery.js b/e107_files/jslib/core/all.jquery.js
index d1813537a..b4fc02c69 100644
--- a/e107_files/jslib/core/all.jquery.js
+++ b/e107_files/jslib/core/all.jquery.js
@@ -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');
}
});
diff --git a/e107_handlers/comment_class.php b/e107_handlers/comment_class.php
index 9bf498da1..6dc0d5544 100644
--- a/e107_handlers/comment_class.php
+++ b/e107_handlers/comment_class.php
@@ -42,6 +42,8 @@ class comment
);
private $template;
+
+ private $totalComments = 0;
function __construct()
{
@@ -221,7 +223,7 @@ class comment
// -------------------------------------------------------------
$text = "\n
";
@@ -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,"",$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
{
diff --git a/e107_themes/templates/comment_template.php b/e107_themes/templates/comment_template.php
index 937c3335f..9142dd327 100644
--- a/e107_themes/templates/comment_template.php
+++ b/e107_themes/templates/comment_template.php
@@ -113,7 +113,6 @@ $COMMENT_TEMPLATE['ITEM'] = '
';
-$COMMENT_TEMPLATE['ITEM_START'] = '';
+$COMMENT_TEMPLATE['ITEM_START'] = "\n\n\n";
+
$COMMENT_TEMPLATE['LAYOUT'] = '{COMMENTFORM}{COMMENTS}{MODERATE}';