News:

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

Main Menu

Has anyone created a mod like this?

Started by Biology Forums, June 11, 2018, 04:17:41 PM

Previous topic - Next topic

Biology Forums

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.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Biology Forums

Quote from: Kindred on June 11, 2018, 04:44:27 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.

Chen Zhen


I can give you 2 quick manual edits to accomplish this if you are comfortable with doing that.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Chen Zhen


file: ../Post.php

for "preview" find:

// Previewing, modifying, or posting?


add BEFORE that comment:

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:

// Previewing? Go back to start.


add BEFORE that comment:

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);
}

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Steve

DO NOT pm me for support!

Shambles

Quote from: 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.

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:


I would like to thank [OP] for starting this topic as it's proven very useful

Chen Zhen


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.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Shambles

No need to be so confrontational, Mr Zhen.

If OP thinks this is worth pursuing and wants more info, I shall provide it.

Biology Forums

I'll be implementing this tomorrow morning and update everyone then.

Thanks for the excellent tutorial, can't wait to start using @@ :D

Biology Forums

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?)

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.

Advertisement: