Home
>
Outdated forums
>
Phorum 3 forums (READ ONLY)
>
Finished Mods and Plug-ins (READ ONLY)
>
Topic
Delete_My_Post Feature
Posted by dude
Delete_My_Post Feature January 06, 2003 04:16AM |
To enable Phorum users to delete the messages that they created previously without deleting other users responding, or without destroying the continuity of the remaining thread, I have added the Delete_My_Post feature. It will first check the ownership of all derivative messages of the target deleting message, and then only allow users to remove the messages that will not affect the continuity of the remaining portion of the thread which is owned jointly by the original author and the other responders.
To make this feature less intrusive to the original Phorum codes, I choose the following approach so that alterations can be easily removed once this feature is included in a future release:
1. Create delete_my_post.php in the "./include" directory
2. Create user_delete.php in the main directory
3. Alter the read.php in the main directory
[c]Installation Guide[/c]
1. Create delete_my_post.php file in the include directory as shown below.
====================
<?php
if ( !defined( "_COMMON_PHP" ) ) return;
function delete_messages($ids)
{
GLOBAL $PHORUM, $DB, $q;
if(!is_array($ids)) $id_array=explode(",", $ids);
// get all message-ids involved
$SQL="Select id from $PHORUM[ForumTableName] where id in ($ids)";
$q->query($DB, $SQL);
while(list($key, $id)=each($id_array)){
$lists[]=_get_message_tree($id);
}
$lists=implode(",", $lists);
$arr=explode(",", $lists);
$counter = count($arr);
// get all involved threads
$SQL="SELECT DISTINCT(thread) from $PHORUM[ForumTableName] where id in ($lists)";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$threads[]=$rec['thread'];
}
$threads=implode(",",$threads);
$phorum_user=phorum_return_user();
// check user ids
$msg="all yours!";
for ($i = 0; $i < count($arr); $i++) {
$arr_key = $arr[$i];
$SQL="Select author from $PHORUM[ForumTableName] where id=$arr_key";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
if($phorum_user[username]!==$rec[author]){
$msg="not all yours!";
break;
}
}
}
// checkpoint
if($msg == "not all yours!"){
return $msg;
}
// delete headers
$SQL="Delete from $PHORUM[ForumTableName] where id in ($lists)";
$q->query($DB, $SQL);
// delete bodies
$SQL="Delete from $PHORUM[ForumTableName]_bodies where id in ($lists)";
$q->query($DB, $SQL);
// delete attachments
$SQL="Select message_id,id,filename from $PHORUM[ForumTableName]_attachments where message_id in ($lists)";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$PHORUM[AttachmentDir]/$PHORUM[ForumTableName]/$rec[message_id]_$rec[id]".strtolower(strrchr($rec["filename"], "."));
unlink($filename);
}
// delete attachments from attachments-table
$SQL="Delete from $PHORUM[ForumTableName]_attachments where message_id in ($lists)";
$q->query($DB, $SQL);
// reset the modifystamp
$SQL="SELECT thread,max(datestamp) as datestamp from $PHORUM[ForumTableName] where thread in ($threads) group by thread";
$q->query($DB, $SQL);
$q2= new query($DB);
while($rec=$q->getrow()){
list($date,$time) = explode(" ", $rec["datestamp"]);
list($year,$month,$day) = explode("-", $date);
list($hour,$minute,$second) = explode(":", $time);
$tstamp = mktime($hour,$minute,$second,$month,$day,$year);
$SQL="update $PHORUM[ForumTableName] set modifystamp=$tstamp where thread=$rec[thread]";
$q2->query($DB, $SQL);
}
}
function _get_message_tree($id)
{
global $PHORUM, $DB;
$q = new query($DB);
$SQL="Select id from $PHORUM[ForumTableName] where parent=$id";
$q->query($DB, $SQL);
$tree="$id";
while($rec=$q->getrow()){
$tree.=","._get_message_tree($rec["id"]);
}
return $tree;
}
?>
=====================
2. Create user_delete.php in the main directory as shown below.
=====================
<?php
require "./common.php";
include "$include_path/delete_my_post.php";
delete_messages($i);
if($i==$t){
header("Location: $list_page.$ext?f=$num$GetVars");
} else {
header("Location: $read_page.$ext?f=$num&i=$t&t=$t$GetVars");
}
?>
======================
3. Alter the read.php and Update the lang file
3.1 Define a new term $1DeleteMyPost in the corresponding language files(e.g., "english.php" or other in-use lang files in the "./lang" directory) so that step 3.2 can use this variable later.
3.2 Add a link to the new feature in the read.php
Locate the Edit_My_Post segment of codes as shown below.
<?php if($phorum_user["id"]==$head_row["userid"] && $PHORUM['ForumAllowEdit']){ ?>
<tr>
<td valign="TOP" width="100%" align="RIGHT" <?php echo bgcolor($ForumTableBodyColor2); ?>>
<?php echo "<a href=\"$forum_url/edit.$ext?f=$ForumId&i=$rec_id&t=$thread$GetVars\">";?><FONT color='<?php echo $ForumNavFontColor; ?>' class="PhorumNav"><?php echo $lEditMyPost; ?></font></a>
Add the following new segment of codes right after it.
|
<a href="javascript:delmsg('<?php echo "$forum_url/user_delete.$ext?f=$ForumId&i=$rec_id&t=$thread$GetVars";?>')"><FONT color='<?php echo $ForumTableBodyFontColor1; ?>' class="PhorumNav"><?php echo $lDeleteMyPost; ?></font></a>
Now, the installation is done!! If you have put these codes on the server, you and your users should be able to use this new Delete_My_Post feature.
Let me know, if there is any problem.
******* Disclaimer and Tips *******
I have tested this feature, and it worked well. Developers can copy and paste these codes into their Phorum at their own risk. I am not responsible for any damage incurred thereafter.
I suggest developers may save the original read.php file somewhere else. If this feature can not be successfully installed and used after going through all three steps, then developers can simply copy the old read.php file to the main directory to overwrite the newly altered one. Therefore, Phorum can be restored to the way it was in no time. Then, developers can take time to remove the newly created "delete_my_post.php" and "user_delete.php" files as well as the definition of $1DeleteMyPost in the lang file of step 3.1 without incurring any trouble.
You can also edit the $lDelMessageWarning variable in the language file to explain to users that how this delete feature is supposed to work. In addition, you are encouraged to add explanatory page to show users why they failed, if they still tried to delete messages to either affect the continuity of the thread or to encroach upon other's ownership.
To make this feature less intrusive to the original Phorum codes, I choose the following approach so that alterations can be easily removed once this feature is included in a future release:
1. Create delete_my_post.php in the "./include" directory
2. Create user_delete.php in the main directory
3. Alter the read.php in the main directory
[c]Installation Guide[/c]
1. Create delete_my_post.php file in the include directory as shown below.
====================
<?php
if ( !defined( "_COMMON_PHP" ) ) return;
function delete_messages($ids)
{
GLOBAL $PHORUM, $DB, $q;
if(!is_array($ids)) $id_array=explode(",", $ids);
// get all message-ids involved
$SQL="Select id from $PHORUM[ForumTableName] where id in ($ids)";
$q->query($DB, $SQL);
while(list($key, $id)=each($id_array)){
$lists[]=_get_message_tree($id);
}
$lists=implode(",", $lists);
$arr=explode(",", $lists);
$counter = count($arr);
// get all involved threads
$SQL="SELECT DISTINCT(thread) from $PHORUM[ForumTableName] where id in ($lists)";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$threads[]=$rec['thread'];
}
$threads=implode(",",$threads);
$phorum_user=phorum_return_user();
// check user ids
$msg="all yours!";
for ($i = 0; $i < count($arr); $i++) {
$arr_key = $arr[$i];
$SQL="Select author from $PHORUM[ForumTableName] where id=$arr_key";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
if($phorum_user[username]!==$rec[author]){
$msg="not all yours!";
break;
}
}
}
// checkpoint
if($msg == "not all yours!"){
return $msg;
}
// delete headers
$SQL="Delete from $PHORUM[ForumTableName] where id in ($lists)";
$q->query($DB, $SQL);
// delete bodies
$SQL="Delete from $PHORUM[ForumTableName]_bodies where id in ($lists)";
$q->query($DB, $SQL);
// delete attachments
$SQL="Select message_id,id,filename from $PHORUM[ForumTableName]_attachments where message_id in ($lists)";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$PHORUM[AttachmentDir]/$PHORUM[ForumTableName]/$rec[message_id]_$rec[id]".strtolower(strrchr($rec["filename"], "."));
unlink($filename);
}
// delete attachments from attachments-table
$SQL="Delete from $PHORUM[ForumTableName]_attachments where message_id in ($lists)";
$q->query($DB, $SQL);
// reset the modifystamp
$SQL="SELECT thread,max(datestamp) as datestamp from $PHORUM[ForumTableName] where thread in ($threads) group by thread";
$q->query($DB, $SQL);
$q2= new query($DB);
while($rec=$q->getrow()){
list($date,$time) = explode(" ", $rec["datestamp"]);
list($year,$month,$day) = explode("-", $date);
list($hour,$minute,$second) = explode(":", $time);
$tstamp = mktime($hour,$minute,$second,$month,$day,$year);
$SQL="update $PHORUM[ForumTableName] set modifystamp=$tstamp where thread=$rec[thread]";
$q2->query($DB, $SQL);
}
}
function _get_message_tree($id)
{
global $PHORUM, $DB;
$q = new query($DB);
$SQL="Select id from $PHORUM[ForumTableName] where parent=$id";
$q->query($DB, $SQL);
$tree="$id";
while($rec=$q->getrow()){
$tree.=","._get_message_tree($rec["id"]);
}
return $tree;
}
?>
=====================
2. Create user_delete.php in the main directory as shown below.
=====================
<?php
require "./common.php";
include "$include_path/delete_my_post.php";
delete_messages($i);
if($i==$t){
header("Location: $list_page.$ext?f=$num$GetVars");
} else {
header("Location: $read_page.$ext?f=$num&i=$t&t=$t$GetVars");
}
?>
======================
3. Alter the read.php and Update the lang file
3.1 Define a new term $1DeleteMyPost in the corresponding language files(e.g., "english.php" or other in-use lang files in the "./lang" directory) so that step 3.2 can use this variable later.
3.2 Add a link to the new feature in the read.php
Locate the Edit_My_Post segment of codes as shown below.
<?php if($phorum_user["id"]==$head_row["userid"] && $PHORUM['ForumAllowEdit']){ ?>
<tr>
<td valign="TOP" width="100%" align="RIGHT" <?php echo bgcolor($ForumTableBodyColor2); ?>>
<?php echo "<a href=\"$forum_url/edit.$ext?f=$ForumId&i=$rec_id&t=$thread$GetVars\">";?><FONT color='<?php echo $ForumNavFontColor; ?>' class="PhorumNav"><?php echo $lEditMyPost; ?></font></a>
Add the following new segment of codes right after it.
|
<a href="javascript:delmsg('<?php echo "$forum_url/user_delete.$ext?f=$ForumId&i=$rec_id&t=$thread$GetVars";?>')"><FONT color='<?php echo $ForumTableBodyFontColor1; ?>' class="PhorumNav"><?php echo $lDeleteMyPost; ?></font></a>
Now, the installation is done!! If you have put these codes on the server, you and your users should be able to use this new Delete_My_Post feature.
Let me know, if there is any problem.
******* Disclaimer and Tips *******
I have tested this feature, and it worked well. Developers can copy and paste these codes into their Phorum at their own risk. I am not responsible for any damage incurred thereafter.
I suggest developers may save the original read.php file somewhere else. If this feature can not be successfully installed and used after going through all three steps, then developers can simply copy the old read.php file to the main directory to overwrite the newly altered one. Therefore, Phorum can be restored to the way it was in no time. Then, developers can take time to remove the newly created "delete_my_post.php" and "user_delete.php" files as well as the definition of $1DeleteMyPost in the lang file of step 3.1 without incurring any trouble.
You can also edit the $lDelMessageWarning variable in the language file to explain to users that how this delete feature is supposed to work. In addition, you are encouraged to add explanatory page to show users why they failed, if they still tried to delete messages to either affect the continuity of the thread or to encroach upon other's ownership.
Re: Delete_My_Post Feature January 06, 2003 04:31AM |
Registered: 23 years ago Posts: 24 |
I am using 3.4.20021005. This new feature is tested on the same version.
BTW, what version is this modder's forum, why didn't it check the username for duplication? Earlier, I forgot to log on before leaving notes on this Delete_My_Post new feature, but Phorum did not stop me from using the same username "dude" which is an already registered name. How strange?!
BTW, what version is this modder's forum, why didn't it check the username for duplication? Earlier, I forgot to log on before leaving notes on this Delete_My_Post new feature, but Phorum did not stop me from using the same username "dude" which is an already registered name. How strange?!
Re: Delete_My_Post Feature August 20, 2003 07:20AM |
Registered: 20 years ago Posts: 5 |
Hey Dude
I've tried out your mod, as it would really help with the way I'm running my phorum. But...I'm having a problem, I think only with definining the new term in the lang file.
Here's what I've put in
$1DeleteMyPost = "Admin Only";
The phorum is live so I don't want people deleting stuff yet, until (and if) I get this working properly, hence the 'Admin Only' : )
Here's the error I get when the file is saved
"Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in c:\program files\ez systems\ezpublish\phorum-3.4.3a\lang\english.php on line 12
Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in c:\program files\ez systems\ezpublish\phorum-3.4.3a\lang\english.php on line 12"
Any clues as to what my problem is ?
Cheers.
Simon
I've tried out your mod, as it would really help with the way I'm running my phorum. But...I'm having a problem, I think only with definining the new term in the lang file.
Here's what I've put in
$1DeleteMyPost = "Admin Only";
The phorum is live so I don't want people deleting stuff yet, until (and if) I get this working properly, hence the 'Admin Only' : )
Here's the error I get when the file is saved
"Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in c:\program files\ez systems\ezpublish\phorum-3.4.3a\lang\english.php on line 12
Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in c:\program files\ez systems\ezpublish\phorum-3.4.3a\lang\english.php on line 12"
Any clues as to what my problem is ?
Cheers.
Simon
Re: Delete_My_Post Feature August 20, 2003 07:47AM |
Registered: 20 years ago Posts: 5 |
Sorry, you do not have permission to post/reply in this forum.