News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

show edit as unread, mark modified as new - here's the code

Started by automerge, November 22, 2010, 05:46:39 PM

Previous topic - Next topic

automerge

Hi everyone,

I was looking for a mod that shows edited posts to other members as unread; this is VERY useful for regularly updated sticky posts an the like. Or, to quote another member:
QuoteI would need a feature or a Mod making it possible that editing a post makes it "new" again.

When you have a Forum (like mine), where entries are worked on (in the first post, the subsequent posts handle the comments) then they are constantly edited. But there is no chance to tell the community automatically that the topic should be read again - unless you post a reply and tell them explicitly "Read it again!" If you have a community based on such a system (which we've been used to from other Forum software) SMF makes it very hard for you to work efficiently in the long run.

I would assume that such a feature would only need a few lines of modification at the Forum code and could easily be made a feature or a Mod? There are a bunch of other Forum owners I know who miss such an option/feature as we.

Well, I haven't found any mod to achieve this goal, at least not for SMF 2.0 RC4, so I made my own (really really dirty) hack to implement this. Needless to say that I haven't coded any mod for SMF yet if you look at the code... It's just a dirty workaround.

I (and I guess many others too) would really appreciate if someone could work this out to a real mod. And maybe somebody with a bit more modding knowledge than me could create a checkbox to turn this feature off and on, maybe even user-wise, and hopefully this will find its way into the official SMF sometime. I can't imagine there's no need for that.

Enough talking, this is what I did to Post.php (lines with stars are original lines which can be used to look up where the code is inserted):

// MARK_EDIT_AS_NEW: indicate that we are not in edit mode
$editing = false;

* // This is an already existing message. Edit it.
* if (!empty($_REQUEST['msg']))
* {

// MARK_EDIT_AS_NEW: indicate that we are in edit mode
$editing = true;

[...]

* updateSettings(array(
* 'calendar_updated' => time(),
* ));
* }

// MARK_EDIT_AS_NEW: mark the post as unread!
if ($editing) {
// 1. mark board as unread: delete the board from log_boards - we want to show everyone except us that we've edited something important
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_boards
WHERE id_board = {int:board} AND id_member != {int:current_member}',
array(
'current_member' => $user_info['id'],
'board' => $board,
)
);
// 2. mark thread unread from where the edit happened: insert or update msgno-1 (id = read inclusive, so we need to decrease the id by 1)
// a) update all entries with msg_id >= edited msg_id to msgno-1 (the lower ones did not even read up to the edit yet; we don't want to disturb them)
$smcFunc['db_query']('', 'UPDATE {db_prefix}log_topics SET id_msg = LEAST({int:msg_id}-1, id_msg) WHERE id_topic = {int:topic_id}',
array(
'topic_id' => $topic,
'msg_id' => $_REQUEST['msg'],
)
);
// b) insert a record for all other users to make sure everyone reads the topic again!
$smcFunc['db_query']('', '
INSERT IGNORE INTO {db_prefix}log_topics (id_member, id_topic, id_msg)
SELECT id_member, {int:topic_id}, {int:msg_id}-1 FROM {db_prefix}members',
array(
'topic_id' => $topic,
'msg_id' => $_REQUEST['msg'],
)
);
}


* // Marking read should be done even for editing messages....
* // Mark all the parents read.  (since you just posted and they will be unread.)

Bigguy


automerge

When using the code, please consider what Kindred posted in another thread (thought that would be obvious, but maybe isn't):

Quotejust as a note: On a forum with over 2 millions messages and 32 thousand users...   doing that script could bog down the server forever...

So don't use this on a really big forum...

Bigguy


Shiryu19

No encuentro el archivo Post.php donde se encuentra?

I can not find the file Post.php where it is?
Dar las GRACIAS no cuesta nada

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

mano82

hey I found this mod very useful I thought it was nice to make a package (for training too).

I put the package in the mod section. It's waiting for approval now...

Advertisement: