Advertisement:

Author Topic: Has anyone created a mod like this?  (Read 997 times)

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,705
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
Has anyone created a mod like this?
« 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.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,433
  • Gender: Male
    • Kindred-999 on GitHub
Re: Has anyone created a mod like this?
« Reply #1 on: June 11, 2018, 04:44:27 PM »
search for mentions in the mod site
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,705
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
Re: Has anyone created a mod like this?
« Reply #2 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.

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,181
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Has anyone created a mod like this?
« Reply #3 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.

My SMF Mods & Plug-Ins

WebDev
Simple Portal Support

Request politely & demand nothing.

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,181
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Has anyone created a mod like this?
« Reply #4 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);
}

My SMF Mods & Plug-Ins

WebDev
Simple Portal Support

Request politely & demand nothing.

Offline Steve

  • Freak
  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,499
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: Has anyone created a mod like this?
« Reply #5 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.
Online Manual

Please do not PM me for support.

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: Has anyone created a mod like this?
« Reply #6 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

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,181
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Has anyone created a mod like this?
« Reply #7 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.

My SMF Mods & Plug-Ins

WebDev
Simple Portal Support

Request politely & demand nothing.

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,158
  • Gender: Male
    • i30 Owners Club
Re: Has anyone created a mod like this?
« Reply #8 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.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,705
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
Re: Has anyone created a mod like this?
« Reply #9 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

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,705
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
Re: Has anyone created a mod like this?
« Reply #10 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.