News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Remove reply prefix only when viewing a topic

Started by HunterP, February 22, 2012, 03:30:10 PM

Previous topic - Next topic

HunterP


Hi there,

I'm trying to hide the reply prefix only when viewing a topic. In Display.php I find :

// Compose the memory eat- I mean message array.
$output = array(
'attachment' => loadAttachmentContext($message['id_msg']),
'alternate' => $counter % 2,
'id' => $message['id_msg'],
'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'],
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
'member' => &$memberContext[$message['id_member']],
'icon' => $message['icon'],
'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.gif',
'subject' => $message['subject'],
'time' => timeformat($message['poster_time']),
'timestamp' => forum_time(true, $message['poster_time']),
'counter' => $counter,
'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name'],
'edit_reason' => $message['edit_reason']
),
'body' => $message['body'],
'new' => empty($message['is_read']),
'approved' => $message['approved'],
'first_new' => isset($context['start_from']) && $context['start_from'] == $counter,
'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($message['id_member'], $context['user']['ignoreusers']),
'can_approve' => !$message['approved'] && $context['can_approve'],
'can_unapprove' => $message['approved'] && $context['can_approve'],
'can_modify' => (!$context['is_locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()))),
'can_remove' => allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']) || (allowedTo('delete_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time())),
'can_see_ip' => allowedTo('moderate_forum') || ($message['id_member'] == $user_info['id'] && !empty($user_info['id'])),
);


I assume that this line reads the message subject?

      'subject' => $message['subject'],

How can I check if the subject starts with the reply prefix, and if so, remove it?

Illori

you mean the "Re:" ? that is stored in the database as part of the subject for the messages.

HunterP

Quote from: Illori on February 22, 2012, 03:33:18 PM
you mean the "Re:" ? that is stored in the database as part of the subject for the messages.

I know, I know. But only on one specific place I'd like to check if this prefix exists and remove it. Meaning, not display it :)

Illori

and what you want i dont think would be that easy to do and would be best posted in the coding board as this is a coding issue not a core smf issue.

HunterP

Quote from: Illori on February 22, 2012, 04:24:25 PM
and what you want i dont think would be that easy to do and would be best posted in the coding board as this is a coding issue not a core smf issue.

Sorry, can someone move this topic, please?

Won't be that easy? In C++ it would be peace of cake, but PHP is not my thing :(

If the subject starts with "reply prefix", remove the first (length of "reply prefix") number of characters.
Shouldn't be that hard, I was hoping that someone would know this by heart :)

NanoSector

Quote from: Illori on February 22, 2012, 04:24:25 PM
and what you want i dont think would be that easy to do and would be best posted in the coding board as this is a coding issue not a core smf issue.
Why would this be hard? ???
If the OP doesn't care about ALL the Re:'s getting removed from the topic title, just do this:
$message['title'] = str_ireplace('Re: ', '', $message['title']);
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Kays

Hi, this looks like it'll do the trick also. :)

Code (display.php) Select

'subject' => substr($message['subject'], 0, strlen($txt['response_prefix'])) == $txt['response_prefix'] ? substr($message['subject'], strlen($txt['response_prefix'])) : $message['subject'],

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

HunterP

Quote from: Yoshi2889 on February 22, 2012, 04:57:55 PM
Why would this be hard? ???
If the OP doesn't care about ALL the Re:'s getting removed from the topic title, just do this:
$message['title'] = str_ireplace('Re: ', '', $message['title']);

That's what I meant, thanks! :)

NanoSector

Quote from: HunterP on February 22, 2012, 05:22:52 PM
Quote from: Yoshi2889 on February 22, 2012, 04:57:55 PM
Why would this be hard? ???
If the OP doesn't care about ALL the Re:'s getting removed from the topic title, just do this:
$message['title'] = str_ireplace('Re: ', '', $message['title']);

That's what I meant, thanks! :)
No problem, you can always comment the code again if you want the Re:'s to be back :)
Though I was wrong with the "title" part, it needs to be "subject", my bad :P
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

HunterP


Next issue. I wanted to get rid of the reply prefix for tweeted topics (or replies). This seems to work with the RSS function I guess? Anyway, above modification removes "Re:" when browsing a topic, but not when a topic gets tweeted. How and where can I fix this?

HunterP


Also, I'd like this to be a bit less greedy. If I have a topic named :

[Discussion] Re: Hot topic

Also this "Re:" will be removed. That's why I asked for "remove the reply prefix only if this is placed in the first (length of prefix) number of characters of the subject". :)

HunterP


Think I've already fixed it :)

if (substr($message['subject'], 0, strlen($context['response_prefix'])) == $context['response_prefix']) $message['subject'] = substr($message['subject'], strlen($context['response_prefix']));

Advertisement: