Tuesday, February 2, 2010

HOW TO: Allow users to delete their own forum posts! [kunena & Joomla]

Enjoy!

1: post.php (/components/com_kunena/template/default/)

1.1) Find:

[code]
else if ($do == "deletepostnow")
{

if (!$is_Moderator)
[/code]

1.2) Change to:

[code]
else if ($do == "deletepostnow")
{
$modified_reason = addslashes(mosGetParam($_POST, "modified_reason", null));
$modified_by = $my->id;
$modified_time = CKunenaTools::fbGetInternalTime();
$id = (int) $id;

$database->setQuery("SELECT * FROM #__fb_messages LEFT JOIN #__fb_messages_text ON #__fb_messages.id=#__fb_messages_text.mesid WHERE #__fb_messages.id=$id");
$message1 = $database->loadObjectList();
check_dberror("Unable to load messages.");
$mes = $message1[0];
$userid = $mes->userid;

//Check for a moderator or superadmin
if ($is_Moderator) {
$allowEdit = 1;
}

if ($fbConfig->useredit == 1 && $my->id != "")
{
//Now, if the author==viewer and the viewer is allowed to edit his/her own post the let them edit
if ($my->id == $userid) {
if(((int)$fbConfig->useredittime)==0) {
$allowEdit = 1;
}
else {
$modtime = $mes->modified_time;
if(!$modtime) {
$modtime = $mes->time;
}
if(($modtime + ((int)$fbConfig->useredittime) + ((int)$fbConfig->useredittimegrace)) >= CKunenaTools::fbGetInternalTime()) {
$allowEdit = 1;
}
}
}
}

if (!$allowEdit == 1)
[/code]

1.1.1) Find:

[code]
else if ($do == "delete")
{

if (!$is_Moderator)
[/code]

1.1.2) Change to:

[code]
else if ($do == "delete")
{
$modified_reason = addslashes(mosGetParam($_POST, "modified_reason", null));
$modified_by = $my->id;
$modified_time = CKunenaTools::fbGetInternalTime();
$id = (int) $id;

$database->setQuery("SELECT * FROM #__fb_messages LEFT JOIN #__fb_messages_text ON #__fb_messages.id=#__fb_messages_text.mesid WHERE #__fb_messages.id=$id");
$message1 = $database->loadObjectList();
check_dberror("Unable to load messages.");
$mes = $message1[0];
$userid = $mes->userid;

//Check for a moderator or superadmin
if ($is_Moderator) {
$allowEdit = 1;
}

if ($fbConfig->useredit == 1 && $my->id != "")
{
//Now, if the author==viewer and the viewer is allowed to edit his/her own post the let them edit
if ($my->id == $userid) {
if(((int)$fbConfig->useredittime)==0) {
$allowEdit = 1;
}
else {
$modtime = $mes->modified_time;
if(!$modtime) {
$modtime = $mes->time;
}
if(($modtime + ((int)$fbConfig->useredittime) + ((int)$fbConfig->useredittimegrace)) >= CKunenaTools::fbGetInternalTime()) {
$allowEdit = 1;
}
}
}
}

if (!$allowEdit == 1)
[/code]

2: message.php (/components/com_kunena/template/default_ex/) * NB: default_ex must be the template you are using)

2.1) Find:

[code]
if ($msg_edit) {
echo " | " . $msg_edit;
[/code]

2.2) Change to:

[code]
if ($msg_edit) {
echo " | " . $msg_edit;
echo " | " . $msg_delete;
[/code]

3: view.php (/components/com_kunena/template/default_ex/) * NB: default_ex must be the template you are using)

3.1) Find:

[code]
if($allowEdit)
{
$msg_edit = CKunenaLink::GetTopicPostLink('edit', $catid, $fmessage->id , $fbIcons['edit']?'Edit':_GEN_EDIT);

[/code]

3.2) Change to:

[code]
if($allowEdit)
{
$msg_delete = CKunenaLink::GetTopicPostLink('delete', $catid, $fmessage->id , $fbIcons['delete']?'Delete':_GEN_DELETE);
$msg_edit = CKunenaLink::GetTopicPostLink('edit', $catid, $fmessage->id , $fbIcons['edit']?'Edit':_GEN_EDIT);

[/code]

No comments:

Post a Comment