News:

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

Main Menu

Mod Setting in Language File

Started by Burke ♞ Knight, August 31, 2014, 12:04:35 PM

Previous topic - Next topic

Burke ♞ Knight

Okay, I'm working on a new mod, well, a re-work of an old one.
This mod changes text string in PersonalMessage.english.php

However, I'd like to make a setting for it, in modifications settings.
Now, how would I do that in a language file?

Here is how it is in the old mod:
    <file name="$languagedir/PersonalMessage.english.php">
        <operation>
            <search position="replace"><![CDATA[$txt['pm_email'] = 'You have just been sent a personal message by SENDER on ' . $context['forum_name'] . '.' . "\n\n" . 'IMPORTANT: Remember, this is just a notification. Please do not reply to this email.' . "\n\n" . 'The message they sent you was:' . "\n\n" . 'MESSAGE';]]></search>
            <add><![CDATA[$txt['pm_email'] = 'You have just been sent a personal message by SENDER on ' . $context['forum_name'] . '.' . "\n\n" . 'IMPORTANT: Remember, this is just a notification. Please do not reply to this email.' . "\n\n" . 'Instead, please visit the forum at ' . $GLOBALS['scripturl'] . '?action=pm to read your message.';]]></add>
        </operation>
    </file>


I need to get it so it can be switched in mod settings:
if(empty($modSettings['hpmtien_mod']))

How would I add that?

Arantor

Using conditionals in a language file is something that should NEVER be done. It's one of the things I was trying to phase out in 2.1 because it's bad practice and the language editor doesn't properly handle it anyway.

Declare a new language string and have the code which uses it switch between the two.

Burke ♞ Knight

Okay, and where is the code for sending the PM as email?

Arantor

In the heart of sendpm, if I remember rightly.

Burke ♞ Knight

Okay, mind you, I'm exploring uncharted territory here.
I see no sendpm file, but do find sendtopic.

Also, I could not find where the pm_email string is used in either PersonalMessage files.

EDIT:

Found this:

// Do the actual sending of the PM.
if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], !empty($_REQUEST['outbox']), null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
else
$context['send_log'] = array(
'sent' => array(),
'failed' => array()
);

Arantor

sendpm is a function in Subs-Post.php. It's the one that actually does PM sending.

In fact, a quick search in all SMF files for $txt['pm_email'] would find the exact thing you're looking for, Subs-Post.php line 1194. Never assume it's just in the front side controller, because all the real grunt work is done in the Subs-* files.

Burke ♞ Knight

Okay, I found the section, and am now trying to figure out exactly where and how my edit should go...

This is a new way for me, so please understand if I get it wrong a few times, before I get it right...LOL

I think I have to edit this part here:

$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email']);

And I hope this is what I have to do:

if(empty($modSettings['hpmtien_mod']))
{$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email_hpmtien']);

else

$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email']);
}



Arantor

Mostly there. Formatting's a bit off, to fit SMF's coding style it should probably be:
if (empty($modSettings['hpmtien_mod']))
$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email_hpmtien']);
else
$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), $txt['pm_email']);


Or the slightly more evil but more compact version:

$mailmessage = str_replace(array('SUBJECT', 'MESSAGE', 'SENDER'), array($subject, $message, un_htmlspecialchars($from['name'])), empty($modSettings['hpmtien_mod']) ? $txt['pm_email_hpmtien'] : $txt['pm_email']);

(If you go down this road, I would suggest not trying to make the replace smaller than the whole line. It will likely go badly.)

Burke ♞ Knight

I am replacing the whole line in the language file, if that is what you mean.

I am trying the first option, as I'm not so sure if it would get approved doing the evil way...
That evil black cat may have dibs on evil ways, after you, that is....LOL :)

Arantor

If you're replacing anything in the language file you're doing it wrong. The extra line should be additional, not instead of anything.

And in Subs-Post, it's a straight replacement.

It's a shame you weren't in chat last night. You might have seen things to revise your definition of evil.

Burke ♞ Knight

That was what I meant, that if activated, it would use the added txt string.
Sorry, was typing too fast and typed it wrong way...lol

EDIT:

Mod is finished and submitted to mod site. :)

Thank you, my friend, for your help and teaching. :)

Burke ♞ Knight

Solved, thanks to Arantor's help. :)

Advertisement: