1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

Start of more flexible comment handling permissions

This commit is contained in:
e107steved
2011-10-20 22:11:58 +00:00
parent 8f903557ae
commit 35a42ffe41

View File

@@ -56,13 +56,14 @@ class comment
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)
{ {
//rating : boolean, to show rating system in comment //rating : boolean, to show rating system in comment
global $pref,$sql,$tp; global $pref, $sql, $tp;
if (isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE) if(isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE)
{ {
return; return;
} }
require_once (e_HANDLER."ren_help.php");
if (ANON == TRUE || USER == TRUE) require_once(e_HANDLER."ren_help.php");
if ($this->getCommentPermissions() == 'rw')
{ {
$itemid = $id; $itemid = $id;
$ns = new e107table; $ns = new e107table;
@@ -84,6 +85,7 @@ class comment
{ {
$text2 = "<input type='hidden' name='subject' value='".$tp->toForm($subject)."' />\n"; $text2 = "<input type='hidden' name='subject' value='".$tp->toForm($subject)."' />\n";
} }
if (isset($_GET['comment']) && $_GET['comment'] == 'edit') if (isset($_GET['comment']) && $_GET['comment'] == 'edit')
{ {
$eaction = 'edit'; $eaction = 'edit';
@@ -94,6 +96,7 @@ class comment
$eaction = 'edit'; $eaction = 'edit';
$tmp = explode(".", e_QUERY); $tmp = explode(".", e_QUERY);
$count = 0; $count = 0;
foreach ($tmp as $t) foreach ($tmp as $t)
{ {
if ($t == "edit") if ($t == "edit")
@@ -121,7 +124,7 @@ class comment
if ($prid != USERID || !USER) if ($prid != USERID || !USER)
{ // Editing not allowed { // Editing not allowed
echo "<div style='text-align: center;'>".COMLAN_329."</div>"; echo "<div style='text-align: center;'>".COMLAN_329."</div>";
require_once (FOOTERF); require_once(FOOTERF);
exit; exit;
} }
$caption = COMLAN_318; $caption = COMLAN_318;
@@ -133,12 +136,13 @@ class comment
$caption = COMLAN_9; $caption = COMLAN_9;
$comval = ""; $comval = "";
} }
//add the rating select box/result ? //add the rating select box/result ?
$rate = ""; $rate = "";
if ($rating == TRUE && !(ANON == TRUE && USER == FALSE)) if ($rating == TRUE && !(ANON == TRUE && USER == FALSE))
{ {
global $rater; global $rater;
require_once (e_HANDLER."rate_class.php"); require_once(e_HANDLER."rate_class.php");
if (!is_object($rater)) if (!is_object($rater))
{ {
$rater = new rater; $rater = new rater;
@@ -146,6 +150,7 @@ class comment
$rate = $rater->composerating($table, $itemid, $enter = TRUE, USERID, TRUE); $rate = $rater->composerating($table, $itemid, $enter = TRUE, USERID, TRUE);
$rate = "<tr><td style='width:20%; vertical-align:top;'>".COMLAN_327.":</td>\n<td style='width:80%;'>".$rate."</td></tr>\n"; $rate = "<tr><td style='width:20%; vertical-align:top;'>".COMLAN_327.":</td>\n<td style='width:80%;'>".$rate."</td></tr>\n";
} //end rating area } //end rating area
if (ANON == TRUE && USER == FALSE) if (ANON == TRUE && USER == FALSE)
{ // Box for author name (anonymous comments - if allowed) { // Box for author name (anonymous comments - if allowed)
$text .= "<tr>\n<td style='width:20%; vertical-align:top;'>".COMLAN_16."</td>\n<td style='width:80%'>\n<input class='tbox comment author' type='text' name='author_name' size='61' value='{$author_name}' maxlength='100' />\n</td>\n</tr>"; $text .= "<tr>\n<td style='width:20%; vertical-align:top;'>".COMLAN_16."</td>\n<td style='width:80%'>\n<input class='tbox comment author' type='text' name='author_name' size='61' value='{$author_name}' maxlength='100' />\n</td>\n</tr>";
@@ -164,15 +169,16 @@ class comment
{ // Comment entry not allowed - point to signup link { // Comment entry not allowed - point to signup link
$text = "<br /><div style='text-align:center'><b>".COMLAN_6." <a href='".e_SIGNUP."'>".COMLAN_321."</a> ".COMLAN_322."</b></div>"; $text = "<br /><div style='text-align:center'><b>".COMLAN_6." <a href='".e_SIGNUP."'>".COMLAN_321."</a> ".COMLAN_322."</b></div>";
} }
if ($return) if ($return)
{ {
return $text; return $text;
} }
else else
{ {
echo $text; echo $text;
} }
} }
/** /**
* Enter description here... * Enter description here...
* *
@@ -190,8 +196,8 @@ class comment
function render_comment($row, $table, $action, $id, $width, $subject, $addrating = FALSE) function render_comment($row, $table, $action, $id, $width, $subject, $addrating = FALSE)
{ {
//addrating : boolean, to show rating system in rendered comment //addrating : boolean, to show rating system in rendered comment
global $sql,$sc_style,$comment_shortcodes,$COMMENTSTYLE,$rater,$gen; global $sql, $sc_style, $comment_shortcodes, $COMMENTSTYLE, $rater, $gen;
global $pref,$comrow,$tp,$NEWIMAGE,$USERNAME,$RATING,$datestamp; global $pref, $comrow, $tp, $NEWIMAGE, $USERNAME, $RATING, $datestamp;
global $thisaction,$thistable,$thisid,$e107; global $thisaction,$thistable,$thisid,$e107;
if (isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE) if (isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE)
{ {
@@ -203,7 +209,7 @@ class comment
$thisaction = $action; $thisaction = $action;
if ($addrating === TRUE) if ($addrating === TRUE)
{ {
require_once (e_HANDLER."rate_class.php"); require_once(e_HANDLER."rate_class.php");
if (!$rater || !is_object($rater)) if (!$rater || !is_object($rater))
{ {
$rater = new rater; $rater = new rater;
@@ -331,13 +337,14 @@ class comment
} // End (nested comment handling) } // End (nested comment handling)
return $text; return $text;
} }
/** /**
* Enter description here... * Add a comment to an item
* *
* @param unknown_type $author_name * @param unknown_type $author_name
* @param unknown_type $comment * @param unknown_type $comment
* @param unknown_type $table * @param unknown_type $table
* @param unknown_type $id * @param integer $id - reference of item in source table to which comment is linked
* @param unknown_type $pid * @param unknown_type $pid
* @param unknown_type $subject * @param unknown_type $subject
* @param unknown_type $rateindex * @param unknown_type $rateindex
@@ -354,11 +361,8 @@ class comment
$tp = e107::getParser(); $tp = e107::getParser();
$e107cache = e107::getCache(); $e107cache = e107::getCache();
if ($this->getCommentPermissions() != 'rw') return;
if (isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE)
{
return;
}
if (isset($_GET['comment']) && $_GET['comment'] == 'edit') if (isset($_GET['comment']) && $_GET['comment'] == 'edit')
{ {
$eaction = 'edit'; $eaction = 'edit';
@@ -522,6 +526,7 @@ class comment
} }
return false; return false;
} }
/** /**
* Enter description here... * Enter description here...
* *
@@ -558,13 +563,13 @@ class comment
case "bugtrack": case "bugtrack":
$type = 6; $type = 6;
break; break;
default: default :
$type = $table; $type = $table;
break; break;
/**************************************** /****************************************
Add your comment type here in same format as above, ie ... Add your comment type here in same format as above, ie ...
case "your_comment_type"; $type = your_type_id; break; case "your_comment_type"; $type = your_type_id; break;
****************************************/ ****************************************/
} }
return $type; return $type;
} }
@@ -589,122 +594,158 @@ class comment
} }
} }
/** /**
* Enter description here... * Enter description here...
* *
* @param unknown_type $table * @param unknown_type $table
* @param unknown_type $id * @param unknown_type $id
* @return unknown * @return unknown
*/ */
function count_comments($table, $id)
{
global $sql, $tp;
$type = $this->getCommentType($table);
$count_comments = $sql->db_Count("comments", "(*)", "WHERE comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' ");
return $count_comments;
}
/**
* Get comment permissions; may be:
* - FALSE - no permission
* - 'ro' - read-only (Can't create)
* - 'rw' - can create and see
*
* This is an embryonic routine which is expected to evolve
*/
function getCommentPermissions()
{
global $pref;
function count_comments($table, $id) if(isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE)
{ {
global $sql,$tp; return FALSE;
$type = $this->getCommentType($table);
$count_comments = $sql->db_Count("comments", "(*)", "WHERE comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' ");
return $count_comments;
} }
/** if (isset($pref['comments_class']))
* Enter description here...
*
* @param unknown_type $table - the source table for the associated item
* @param unknown_type $action - usually 'comment' or 'reply'
* @param unknown_type $id - ID of item associated with comments (e.g. news ID)
* @param unknown_type $width - appears to not be used
* @param unknown_type $subject
* @param unknown_type $rate
*/
function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE, $return = FALSE, $tablerender = TRUE)
{ {
//compose comment : single call function will render the existing comments and show the form_comment if (!check_class($pref['comments_class']))
//rate : boolean, to show/hide rating system in comment, default FALSE
global $pref,$ns,$e107cache,$tp,$totcc;
if (isset($pref['comments_disabled']) && $pref['comments_disabled'] == TRUE)
{ {
return; return FALSE;
} }
$sql = e107::getDb(); return 'rw';
// Query no longer used }
// $count_comments = $this -> count_comments($table, $id, $pid=FALSE); else
$type = $this->getCommentType($table); {
$query = $pref['nested_comments'] ? if (USER) return 'rw'; // Only allow anonymous comments if specifically enabled.
"SELECT c.*, u.*, ue.* FROM #comments AS c if (ANON) return 'rw';
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id }
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id return 'ro';
WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."' AND c.comment_pid='0' ORDER BY c.comment_datestamp" }
:
"SELECT c.*, u.*, ue.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."' ORDER BY c.comment_datestamp";
$text = "";
$comment = ''; /**
$modcomment = ''; * Displays existing comments, and a comment entry form
$lock = ''; *
$ret['comment'] = ''; * @param unknown_type $table - the source table for the associated item
if ($comment_total = $sql->db_Select_gen($query)) * @param unknown_type $action - usually 'comment' or 'reply'
* @param unknown_type $id - ID of item associated with comments (e.g. news ID)
* @param unknown_type $width - appears to not be used
* @param unknown_type $subject
* @param unknown_type $rate
*/
function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE, $return = FALSE, $tablerender = TRUE)
{
//compose comment : single call function will render the existing comments and show the form_comment
//rate : boolean, to show/hide rating system in comment, default FALSE
global $pref, $ns, $e107cache, $tp, $totcc;
if ($this->getCommentPermissions() === FALSE) return;
$sql = e107::getDb();
$type = $this->getCommentType($table);
$query = $pref['nested_comments'] ?
"SELECT c.*, u.*, ue.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."' AND c.comment_pid='0' ORDER BY c.comment_datestamp"
:
"SELECT c.*, u.*, ue.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
WHERE c.comment_item_id='".intval($id)."' AND c.comment_type='".$tp->toDB($type, true)."' ORDER BY c.comment_datestamp";
$text = "";
$comment = '';
$modcomment = '';
$lock = '';
$ret['comment'] = '';
if ($comment_total = $sql->db_Select_gen($query))
{
$width = 0;
//Shortcodes could use $sql, so just grab all results
$rows = $sql->db_getList();
//while ($row = $sql->db_Fetch())
foreach ($rows as $row)
{ {
$width = 0; $lock = $row['comment_lock'];
//Shortcodes could use $sql, so just grab all results // $subject = $tp->toHTML($subject);
$rows = $sql->db_getList(); if ($pref['nested_comments'])
//while ($row = $sql->db_Fetch())
foreach ($rows as $row)
{ {
$lock = $row['comment_lock']; $text .= $this->render_comment($row, $table, $action, $id, $width, $tp->toHTML($subject), $rate);
// $subject = $tp->toHTML($subject);
if ($pref['nested_comments'])
{
$text .= $this->render_comment($row, $table, $action, $id, $width, $tp->toHTML($subject), $rate);
}
else
{
$text .= $this->render_comment($row, $table, $action, $id, $width, $tp->toHTML($subject), $rate);
}
}
if ($tablerender)
{
$text = $ns->tablerender(COMLAN_99, $text, '', TRUE);
}
if (!$return)
{
echo $text;
} }
else else
{ {
$ret['comment'] = $text; $text .= $this->render_comment($row, $table, $action, $id, $width, $tp->toHTML($subject), $rate);
}
if (ADMIN && getperms("B"))
{
$modcomment = "<div style='text-align:right'><a href='".e_ADMIN_ABS."modcomment.php?$table.$id'>".COMLAN_314."</a></div><br />";
} }
} }
if ($lock != "1")
if ($tablerender)
{ {
$comment = $this->form_comment($action, $table, $id, $subject, "", TRUE, $rate, $tablerender); $text = $ns->tablerender(COMLAN_99, $text, '', TRUE);
}
if (!$return)
{
echo $text;
} }
else else
{ {
$comment = "<br /><div style='text-align:center'><b>".COMLAN_328."</b></div>"; $ret['comment'] = $text;
} }
if (!$return)
if (ADMIN && getperms("B"))
{ {
echo $modcomment.$comment; $modcomment = "<div style='text-align:right'><a href='".e_ADMIN_ABS."modcomment.php?$table.$id'>".COMLAN_314."</a></div><br />";
} }
$ret['comment'] .= $modcomment;
$ret['comment_form'] = $comment;
$ret['caption'] = COMLAN_99;
return (!$return) ? "" : $ret;
} }
if (($lock != '1') && ($this->getCommentPermissions() === 'rw'))
function recalc_user_comments($id)
{ {
global $sql; $comment = $this->form_comment($action, $table, $id, $subject, "", TRUE, $rate, $tablerender);
}
else
{
$comment = "<br /><div style='text-align:center'><b>".COMLAN_328."</b></div>";
}
if (!$return)
{
echo $modcomment.$comment;
}
$ret['comment'] .= $modcomment;
$ret['comment_form'] = $comment;
$ret['caption'] = COMLAN_99;
return (!$return) ? "" : $ret;
}
function recalc_user_comments($id)
{
global $sql;
if (is_array($id)) if (is_array($id))
{ {
foreach ($id as $_id) foreach ($id as $_id)
@@ -963,22 +1004,22 @@ class comment
} }
} }
} // End Switch } // End Switch
if (varset($ret['comment_title'])) if (varset($ret['comment_title']))
{ {
$reta[] = $ret; $reta[] = $ret;
$valid++; $valid++;
} }
if ($amount && $valid >= $amount) if ($amount && $valid >= $amount)
{ {
return $reta; return $reta;
}
}
//loop if less records found than given $amount - probably because we discarded some
if ($amount && ($valid < $amount))
{
$reta = $this->getCommentData($amount, $from + $amount, $qry, $valid, $reta);
}
} }
return $reta;
} }
} //end class //loop if less records found than given $amount - probably because we discarded some
if ($amount && ($valid < $amount))
{
$reta = $this->getCommentData($amount, $from + $amount, $qry, $valid, $reta);
}
}
return $reta;
}
} //end class