Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Durr on October 27, 2009, 10:11:51 AM

Title: No 'last edit' for Administrators
Post by: Durr on October 27, 2009, 10:11:51 AM
Hello there,

Is there any mod that disables 'Last edit' for when Administrators edit a post?
Title: Re: No 'last edit' for Administrators
Post by: Arantor on October 27, 2009, 02:13:00 PM
Do other members have the ability to edit posts?

There isn't a mod currently available for this AFAIK but it shouldn't be a huge edit if you wanted to do so.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on October 27, 2009, 02:59:36 PM
This is not as easy as it sounds since the id_group of the member who modified the message isn't stored within the messages table, however, is possible.  Will need to do a JOIN on the messages table in the Display() function within Display.php where $messages_request gets defined.  You can do a LEFT JOIN {db_prefix}members table and check for modified_name (from messages table) = real_name (from members table).  Where the id_group != 1 (from the members table) which will return all but the Administrators, and then you can use it for the $message[] array here:
'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name']
),

you can add another index to it like so: 'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name'],
'group' => !empty($message['modified_group'])
),

and than in Display.template.php, you can check for this at around here:// Show "« Last Edit: Time by Person »" if this post was edited.
if ($settings['show_modify'] && !empty($message['modified']['name']))
echo '
&#171; <em>', $txt['last_edit'], ': ', $message['modified']['time'], ' ', $txt['by'], ' ', $message['modified']['name'], '</em> &#187;';

Which you can change to:// Show "« Last Edit: Time by Person »" if this post was edited.
if ($settings['show_modify'] && !empty($message['modified']['name']) && $message['modified']['group'])
echo '
&#171; <em>', $txt['last_edit'], ': ', $message['modified']['time'], ' ', $txt['by'], ' ', $message['modified']['name'], '</em> &#187;';


Well good luck with it :)

And you can also just get all id_group if you want and just compare it using && $message['modified']['group'] != 1
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on October 27, 2009, 03:20:35 PM
Sorry, for the double post.

Doing it this way will prevent your previous posts from displaying last modified by Admin, but another way to do this for future posts, would be to do it in Subs-Post.php in the modifyPost() function.  Look here...
if (!empty($msgOptions['modify_time']))
{
$messages_columns['modified_time'] = $msgOptions['modify_time'];
$messages_columns['modified_name'] = $msgOptions['modify_name'];
$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
}


You can check for $user_info['is_admin'] and if so, don't add them...

Cheers :)
Title: Re: No 'last edit' for Administrators
Post by: Durr on October 27, 2009, 06:04:53 PM
Thanks Sologhost, I've done the following:

Display.php

$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);

to

$messages_request = $smcFunc['db_query']('', '
SELECT
msgs.id_msg, msgs.icon, msgs.subject, msgs.poster_time, msgs.poster_ip, msgs.id_member, msgs.modified_time, msgs.modified_name, msgs.body,
msgs.smileys_enabled, msgs.poster_name, msgs.poster_email, msgs.approved,
msgs.id_msg_modified < {int:new_from} AS is_read,
mmbrs.id_group AS modified_group
FROM {db_prefix}messages AS msgs
LEFT JOIN {db_prefix}members AS mmbrs ON msgs.modified_name = mmbrs.real_name
WHERE msgs.id_msg IN ({array_int:message_list})
ORDER BY msgs.id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);


and

'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name']
),

to

'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name'],
'group' => $message['modified_group']
),


Display.template.php:

if ($settings['show_modify'] && !empty($message['modified']['name']))

to

if ($settings['show_modify'] && !empty($message['modified']['name']) && ($message['modified']['group'] != 1))



It worked
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on October 27, 2009, 08:05:34 PM
Cheers, knew it would ;)
Title: [SMF 2.0.x] List of completed translations
Post by: MultiformeIngegno on October 28, 2009, 02:35:36 AM
Thanks!! It's really useful!!
Title: Re: No 'last edit' for Administrators
Post by: Durr on October 28, 2009, 10:18:05 PM
Could be a nice mod :)
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on October 28, 2009, 10:56:34 PM
You are welcome to go ahead and create it bro.  It's too small for my liking...
Title: Re: No 'last edit' for Administrators
Post by: MultiformeIngegno on October 30, 2009, 02:27:03 AM
I've found this, but it adds a link to remove the "last edit", doesn't remove it automatically...
http://custom.simplemachines.org/mods/index.php?mod=982
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 03, 2009, 12:29:20 PM
Hi everyone
This may sound really noobish...but I need help getting this to work on my forums. :(
I can't seem to find the code to modify in Display.php [from Durr's post] and I was a bit confused by SoLoGHoST post's where I have to join tables. I also tried the "Last Edit" mod linked by lorenzone92 and it doesn't seem to work.

I'd really appreciate if someone would please help me with this. :)
I'm using SMF 1.1.10 and the Helios skin (Not sure if that's relevant to know but I figured it wouldn't hurt to tell anyway).

Regards,
Kruss
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 01:54:01 AM
for 1.1.10, just search for the $messages_request within Display.php and change the following table so that it is similar to what Durr has posted.  The column names may be slightly different, I'm not sure as I don't have an SMF 1.1.10 to look at for this edit.  But I'm pretty sure the $messages_request array is still there.  And do the rest of the edits, looking for where it gets defined.  For example, search for:  'modified' => array( in Display.php and do similar changes as what is already defined in there.  Just add the group index in here at the end.  And do a search for:  &#171; <em>', $txt['last_edit'] within Display.template.php and do similar changes to it that Durr has posted in that post as well.

Please try the following, if you still have problems, I'll take a look at it more deeply and give you exact FIND/REPLACE edits for SMF 1.1.10.

Cheers :)
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 09:48:29 AM
Thanks SoLoGHoST, I've done the following:

Display.php
$messages_request = db_query("
SELECT
msgs.ID_MSG, msgs.icon, msgs.subject, msgs.posterTime, msgs.posterIP, msgs.ID_MEMBER, msgs.modifiedTime, msgs.modifiedName, msgs.body,
msgs.smileysEnabled, msgs.posterName, msgs.posterEmail,
msgs.ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead
FROM {$db_prefix}messages AS msgs
LEFT JOIN ($db_prefix)members AS mmbrs ON msgs.modifiedName = mmbrs.realName
WHERE msgs.ID_MSG IN (" . implode(',', $messages) . ")
ORDER BY msgs.ID_MSG" . (empty($options['view_newest_first']) ? '' : ' DESC'), __FILE__, __LINE__);

// Go to the last message if the given time is beyond the time of the last message.
if (isset($context['start_from']) && $context['start_from'] >= $topicinfo['numReplies'])
$context['start_from'] = $topicinfo['numReplies'];

// Since the anchor information is needed on the top of the page we load these variables beforehand.
$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
if (empty($options['view_newest_first']))
$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
else
$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $topicinfo['numReplies'] - $context['start_from'];
}
else
{
$messages_request = false;
$context['first_message'] = 0;
$context['first_new_message'] = false;
}


'modified' => array(
'time' => timeformat($message['modifiedTime']),
'timestamp' => forum_time(true, $message['modifiedTime']),
'name' => $message['modifiedName']
'group' => $message['modifiedGroup']
),


Display.template.php

if ($settings['show_modify'] && !empty($message['modified']['name']) && ($message['modified']['group'] != 1))

Do you mind checking what I did wrong? Or I'm missing a bracket? Because it gave me this error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/a/d/0/22439/22439/public_html/forum/Sources/Display.php on line 912

I checked the  line 912 and I can't see anything wrong with it...

if (empty($options['view_newest_first']))
$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
else
$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $topicinfo['numReplies'] - $context['start_from'];
}
else
{
$messages_request = false;
$context['first_message'] = 0;
$context['first_new_message'] = false;
}


I appreciate your help! Thanks in advance. :)
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 09:55:58 AM
Ok, right off of the bat I see this problem...
'modified' => array(
         'time' => timeformat($message['modifiedTime']),
         'timestamp' => forum_time(true, $message['modifiedTime']),
         'name' => $message['modifiedName']
         'group' => $message['modifiedGroup']
      ),

You need a comma after $message['modifiedName'] since you are adding another value to the array, like this:'modified' => array(
         'time' => timeformat($message['modifiedTime']),
         'timestamp' => forum_time(true, $message['modifiedTime']),
         'name' => $message['modifiedName'],
         'group' => $message['modifiedGroup']
      ),

Let me know if you get anymore errors after adding in the comma.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 10:03:52 AM
Also, I don't see you defining modifiedGroup in the query that should be getting it from the members table, ID_GROUP column:

msgs.ID_MSG, msgs.icon, msgs.subject, msgs.posterTime, msgs.posterIP, msgs.ID_MEMBER, msgs.modifiedTime, msgs.modifiedName, msgs.body,
            msgs.smileysEnabled, msgs.posterName, msgs.posterEmail,
            msgs.ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead


There is no mmbrs.ID_GROUP AS modifiedGroup being declared here, so it will never find it.

You will need to change this:msgs.ID_MSG, msgs.icon, msgs.subject, msgs.posterTime, msgs.posterIP, msgs.ID_MEMBER, msgs.modifiedTime, msgs.modifiedName, msgs.body,
            msgs.smileysEnabled, msgs.posterName, msgs.posterEmail,
            msgs.ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead

to this:msgs.ID_MSG, msgs.icon, msgs.subject, msgs.posterTime, msgs.posterIP, msgs.ID_MEMBER, msgs.modifiedTime, msgs.modifiedName, msgs.body,
            msgs.smileysEnabled, msgs.posterName, msgs.posterEmail,
            msgs.ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead, mmbrs.ID_GROUP AS modifiedGroup

Keep the rest of it the same as it looks fine to me, but haven't really looked over thoroughly though.
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 10:32:34 AM
Thanks for the quick reply! Yeah, I seem to have forgotten how easily a simply syntax error can cause trouble. Now though I'm getting a different error message...

Database Error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'members AS mmbrs ON msgs.modifiedName = mmbrs.realName
WHERE
File: /home/a/d/0/22439/22439/public_html/forum/Sources/Display.php
Line: 740

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.10, while your database is at version 1.1.9. The above error might possibly go away if you execute the latest version of upgrade.php.


Does that mean I have to update MySQL?
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 10:45:20 AM
Can you please show me line #740, I'll need the whole database query for this.

Will take a look at for you once you've inputted this info from Display.php.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 10:51:49 AM
Ok, just now seeing this also...

LEFT JOIN ($db_prefix)members AS mmbrs ON msgs.modifiedName = mmbrs.realName

Should be this instead:

LEFT JOIN ($db_prefix)members AS mmbrs ON (mmbrs.realName = msgs.modifiedName)

Note the parenthesis.
Title: Re: No 'last edit' for Administrators
Post by: Arantor on November 04, 2009, 10:54:34 AM
Um... also ($db_prefix)members should be {$db_prefix}members...? Otherwise it'll be calling on (smf_)members...?
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 11:03:16 AM
Uhm, do you think it'll be better if I just post the whole Display.php for you?
I've attached it here if you want to take a look.

Thanks again!
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 11:10:21 AM
Ohhh, WoW, thanks Arantor, that's the Main problem than.  Will fix it up a little for you than.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 11:16:40 AM
Ok, Try this one...
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 11:26:13 AM
Perfect! It works. Thanks a lot, to both SoLoGHoST and Arantor :)
One last question if you don't mind...

If I wanted to do this for the previous messages, can I just add the code you wrote on the Display.php as well?

Quote from: SoLoGHoST on October 27, 2009, 03:20:35 PM
Sorry, for the double post.

Doing it this way will prevent your previous posts from displaying last modified by Admin, but another way to do this for future posts, would be to do it in Subs-Post.php in the modifyPost() function.  Look here...
if (!empty($msgOptions['modify_time']))
{
$messages_columns['modified_time'] = $msgOptions['modify_time'];
$messages_columns['modified_name'] = $msgOptions['modify_name'];
$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
}


You can check for $user_info['is_admin'] and if so, don't add them...

Cheers :)

Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 12:20:36 PM
Hello, this will do it for all messages within the topic (limited by those on that particular topic page).  So you don't need it.  But are you talking about all edited posts?  Or just those edited by an Administrator??  The one you are using only does posts edited by an Administrator.
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 12:45:55 PM
Just all edited post by the Administrator actually. I know I can turn off the 'Last modification' option for everyone. The one you helped me with still shows the "Last Edit" for the previous messages.
Title: Re: No 'last edit' for Administrators
Post by: MultiformeIngegno on November 04, 2009, 02:03:40 PM
SoLoGHoST: can you please post a "sum" of the edits to make with these recent fixes?
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 02:36:55 PM
Quote from: Kruss on November 04, 2009, 12:45:55 PM
Just all edited post by the Administrator actually. I know I can turn off the 'Last modification' option for everyone. The one you helped me with still shows the "Last Edit" for the previous messages.

Ok, I don't know what you are talking about here.  The $messages_request array gets loaded with all posts within the topic from start to finish via limit of how many posts to display per page.  So you didn't do just one post here, you did them all!

Bro, I have to go, so I will catch up on this topic tomorrow.

Quote from: lorenzone92 on November 04, 2009, 02:03:40 PM
SoLoGHoST: can you please post a "sum" of the edits to make with these recent fixes?
I'll do this tomorrow if I have the time.  Although, I know Arantor knows what's going on, so if he beats me to it, Cheers ;)
Title: Re: No 'last edit' for Administrators
Post by: Kruss on November 04, 2009, 03:33:59 PM
Quote from: SoLoGHoST on November 04, 2009, 02:36:55 PM
Quote from: Kruss on November 04, 2009, 12:45:55 PM
Just all edited post by the Administrator actually. I know I can turn off the 'Last modification' option for everyone. The one you helped me with still shows the "Last Edit" for the previous messages.

Ok, I don't know what you are talking about here.  The $messages_request array gets loaded with all posts within the topic from start to finish via limit of how many posts to display per page.  So you didn't do just one post here, you did them all!

Bro, I have to go, so I will catch up on this topic tomorrow.

No problem. I appreciate all the help. :)
Actually, ignore my post above. It was a mistake on my part. I forgot to re-upload the Display.template.php so the "Last Modified" was still showing up.

All is well now. Thanks a lot again!

Title: Re: No 'last edit' for Administrators
Post by: MultiformeIngegno on November 04, 2009, 05:16:41 PM
Quote from: SoLoGHoST on November 04, 2009, 02:36:55 PM
Quote from: lorenzone92 on November 04, 2009, 02:03:40 PM
SoLoGHoST: can you please post a "sum" of the edits to make with these recent fixes?
I'll do this tomorrow if I have the time.  Although, I know Arantor knows what's going on, so if he beats me to it, Cheers ;)
Thanks!!! :D
Title: Re: No 'last edit' for Administrators
Post by: Arantor on November 04, 2009, 05:22:00 PM
Quote from: lorenzone92 on November 04, 2009, 02:03:40 PM
I'll do this tomorrow if I have the time.  Although, I know Arantor knows what's going on, so if he beats me to it, Cheers ;)

Sorry, I'm not in a position to do this at the moment.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 04, 2009, 05:26:57 PM
Ok, Arantor.  Strange choice of words there (position?).  Well, I'll be doing it tomorrow than.  All of the edits are already in this topic, you just need to get the right ones.
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on November 05, 2009, 03:17:32 AM
Ok, For SMF 2.0.x Durr has shown us his edits within this topic in THIS POST (http://www.simplemachines.org/community/index.php?topic=344737.msg2330314#msg2330314).  However, to accomplish this for SMF 1.1.10, you'll need to do the following EDITS.

Open ./Sources/Display.php

FIND:$messages_request = db_query("
SELECT
ID_MSG, icon, subject, posterTime, posterIP, ID_MEMBER, modifiedTime, modifiedName, body,
smileysEnabled, posterName, posterEmail,
ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead
FROM {$db_prefix}messages
WHERE ID_MSG IN (" . implode(',', $messages) . ")
ORDER BY ID_MSG" . (empty($options['view_newest_first']) ? '' : ' DESC'), __FILE__, __LINE__);


REPLACE WITH:$messages_request = db_query("
SELECT
msgs.ID_MSG, msgs.icon, msgs.subject, msgs.posterTime, msgs.posterIP, msgs.ID_MEMBER, msgs.modifiedTime, msgs.modifiedName, msgs.body,
msgs.smileysEnabled, msgs.posterName, msgs.posterEmail,
msgs.ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead, mmbrs.ID_GROUP AS modifiedGroup
FROM {$db_prefix}messages AS msgs
LEFT JOIN {$db_prefix}members AS mmbrs ON (mmbrs.realName = msgs.modifiedName)
WHERE msgs.ID_MSG IN (" . implode(',', $messages) . ")
ORDER BY msgs.ID_MSG" . (empty($options['view_newest_first']) ? '' : ' DESC'), __FILE__, __LINE__);


FIND:'name' => $message['modifiedName']

ADD AFTER:,
'group' => $message['modifiedGroup']


OPEN ./Themes/default/Display.template.php

FIND:if ($settings['show_modify'] && !empty($message['modified']['name'])

ADD AFTER: && $message['modified']['group'] != 1

There ya go all done.  So will now work for SMF 1.1.x.

Cheers :)
Title: Re: No 'last edit' for Administrators
Post by: SN on December 18, 2009, 08:57:43 AM
this should be a Mod, its a very useful edit
Title: Re: No 'last edit' for Administrators
Post by: SoLoGHoST on December 18, 2009, 10:31:51 AM
You are free to use the code if you'd like.  We all pretty much contributed to it here.  So, maybe just give us a little credit or something is all, if you use it.  Honestly, this is too small of a mod and too easy for me to care to make it a mod.  So, like I said, feel free to make it a mod if you'd like.  You don't have to mention anything about me, but perhaps the other members who contributed to it may want a word or 2 stating that they helped with this mods creation.

In any case,
Good Luck :)