Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Topic started by: Study Force on June 11, 2018, 04:17:41 PM

Title: Has anyone created a mod like this?
Post by: Study Force on June 11, 2018, 04:17:41 PM
I'd like to implement on my forum something where if you type @@ in a thread, it automatically replaces it with the OP's username.
Title: Re: Has anyone created a mod like this?
Post by: Kindred on June 11, 2018, 04:44:27 PM
search for mentions in the mod site
Title: Re: Has anyone created a mod like this?
Post by: Study Force on June 11, 2018, 06:44:42 PM
search for mentions in the mod site

I think mentions is a little more complex involving jquery, pm sending, etc. I want something simple as described.
Title: Re: Has anyone created a mod like this?
Post by: Chen Zhen on June 11, 2018, 11:35:20 PM

I can give you 2 quick manual edits to accomplish this if you are comfortable with doing that.
Title: Re: Has anyone created a mod like this?
Post by: Chen Zhen on June 11, 2018, 11:41:49 PM

file: ../Post.php

for "preview" find:
Code: [Select]
// Previewing, modifying, or posting?

add BEFORE that comment:
Code: [Select]
if (isset($_REQUEST['message']))
{
$request = $smcFunc['db_query']('', '
SELECT id_member, poster_name
FROM {db_prefix}messages
WHERE id_topic = {int:topic}
ORDER BY poster_time ASC
LIMIT 1',
array(
'topic' => (int) $topic,
));

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$OP = array(
'name' => $row['poster_name'],
'id' => $row['id_member'],
'link' => '[url=' . $scripturl . '?action=profile;u=' . $row['id_member'] . ']' . $row['poster_name'] . '[/url]',
);
}

$smcFunc['db_free_result']($request);
$new = str_replace('@@', $OP['link'], $_REQUEST['message']);
$_REQUEST['message'] = rtrim($new);
}

for saving the post find:
Code: [Select]
// Previewing? Go back to start.

add BEFORE that comment:
Code: [Select]
if (isset($_POST['message']))
{
$request = $smcFunc['db_query']('', '
SELECT id_member, poster_name
FROM {db_prefix}messages
WHERE id_topic = {int:topic}
ORDER BY poster_time ASC
LIMIT 1',
array(
'topic' => (int) $topic,
));

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$OP = array(
'name' => $row['poster_name'],
'id' => $row['id_member'],
'link' => '[url=' . $scripturl . '?action=profile;u=' . $row['id_member'] . ']' . $row['poster_name'] . '[/url]',
);
}

$smcFunc['db_free_result']($request);
$new = str_replace('@@', $OP['link'], $_POST['message']);
$_POST['message'] = rtrim($new);
}
Title: Re: Has anyone created a mod like this?
Post by: Steve on June 12, 2018, 03:37:07 PM
Or, if you're not dead set on @@: https://custom.simplemachines.org/mods/index.php?mod=1224

Doesn't get much easier than that.
Title: Re: Has anyone created a mod like this?
Post by: Shambles on June 12, 2018, 03:52:50 PM
Or, if you're not dead set on @@: https://custom.simplemachines.org/mods/index.php?mod=1224

Doesn't get much easier than that.

That mod is a "joke mod" and not what the OP is looking for. It certainly doesn't reveal who the Topic Starter is.

But I guess you knew that  :P

@Study Force:

I implemented this using a new BBcode I called "OP":

Code: ( in Subs.php) [Select]
array(
'tag' => 'op',
'type' => 'closed',
'content' => (!empty($context['name_started'])) ? '<a href="'. $scripturl. '?action=profile;u=' .$context['topic_starter_id']. '">' .$context['name_started']. '</a>' : '',

So, when you need to use it you say something like this:

Code: [Select]
I would like to thank [OP] for starting this topic as it's proven very useful
Title: Re: Has anyone created a mod like this?
Post by: Chen Zhen on June 12, 2018, 05:49:42 PM

Are you going to show this OP how to populate $context['topic_starter_id'] and $context['name_started'] prior to adding that?
Those have no values by default.
Also at the moment your array is missing the closing bracket prior to the comma.
Title: Re: Has anyone created a mod like this?
Post by: Shambles on June 12, 2018, 05:56:35 PM
No need to be so confrontational, Mr Zhen.

If OP thinks this is worth pursuing and wants more info, I shall provide it.
Title: Re: Has anyone created a mod like this?
Post by: Study Force on June 12, 2018, 11:32:05 PM
I'll be implementing this tomorrow morning and update everyone then.

Thanks for the excellent tutorial, can't wait to start using @@ :D
Title: Re: Has anyone created a mod like this?
Post by: Study Force on June 13, 2018, 10:01:47 AM
Here's what I did. Made a few changes to the already awesome code provided by @Chen Zenn

Notice the initial arguments: Only check if the message contains @@ and don't check if the topic is empty (because... what's the point?)

Code: [Select]
if (strpos($_REQUEST['message'], '@@') !== false && !empty($topic))
{
$request = db_query("
SELECT
ID_MEMBER, posterName
FROM
{$db_prefix}messages
WHERE
ID_TOPIC = $topic
LIMIT 1", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
$OP = array(
'name' => $row['posterName'],
'id' => $row['ID_MEMBER'],
'link' => '[url=' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . ']' . $row['posterName'] . '[/url]',
);
}

mysql_free_result($request);

$new = str_replace('@@', $OP['link'], $_REQUEST['message']);
$_REQUEST['message'] = rtrim($new);
}

This code is modified to work with SMF 1.x.