Advertisement:

Author Topic: show edit as unread, mark modified as new - here's the code  (Read 4819 times)

Offline automerge

  • Semi-Newbie
  • *
  • Posts: 10
show edit as unread, mark modified as new - here's the code
« on: November 22, 2010, 05:46:39 PM »
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:
Quote
I 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):
Code: [Select]
// 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.)

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 13,007
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • What's Ur Beef
Re: show edit as unread, mark modified as new - here's the code
« Reply #1 on: November 24, 2010, 07:55:54 AM »
This looks very useful, thanks for the edits. :)

Offline automerge

  • Semi-Newbie
  • *
  • Posts: 10
Re: show edit as unread, mark modified as new - here's the code
« Reply #2 on: November 24, 2010, 08:02:14 AM »
When using the code, please consider what Kindred posted in another thread (thought that would be obvious, but maybe isn't):

Quote
just 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...

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 13,007
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • What's Ur Beef
Re: show edit as unread, mark modified as new - here's the code
« Reply #3 on: November 24, 2010, 08:03:07 AM »
Makes perfect sense, thanks for the tip. :)

Offline Shiryu19

  • Jr. Member
  • **
  • Posts: 162
  • Gender: Male
  • Royalplayers.es
Re: show edit as unread, mark modified as new - here's the code
« Reply #4 on: November 03, 2014, 10:55:48 AM »
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

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: show edit as unread, mark modified as new - here's the code
« Reply #5 on: November 03, 2014, 11:24:38 AM »
Sources/Post.php
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

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

Offline mano82

  • Semi-Newbie
  • *
  • Posts: 20
Re: show edit as unread, mark modified as new - here's the code
« Reply #6 on: June 14, 2015, 02:54:27 PM »
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...