In-post private text.

Started by KJToo, May 16, 2005, 11:59:34 PM

Previous topic - Next topic

KJToo

I'm running a role-playing game on my Simple Machines Forum, and one of the members suggested implementing in-post private text. This would be a custom BBCode tag that accepts one or more member names as attributes and displays the text between the opening and closing tags only to those members. For example, if I want to send a private message to forum user Gator, I would do the following.

...public portion of the message

[private="Gator"]This is the private portion.[/private]

More public message text...


Ideally, the tag would accept multiple forum member names:

...public portion of the message

[private="Gator","KJToo","Big Drac Attack"]This is the private portion.[/private]

More public message text...


I have searched high and low for an existing MOD that will do this, but have found nothing. MODs that currently "hide" text (spoilers, for example) do so by altering the text color to match the background color, but that wouldn't be sufficient in this case.

Has this BBCode already been developed? If so, where might I find it? If not... well, I'm at a loss. The best I've been able to manage after an hour or so of digging through the SMF files is to locate the BBCode parser in Subs.php. I'm not a programmer, but would be willing to do the work if I had a bit of direction.

LostProphecy

Angelus Ex Quo Nox

Dannii

I don't really understand the subs.php page very well, but it should be possible. It would be easier (and more convienient for names changes) if you had it for user account ids instad.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

KJToo

Quote from: eldacar on May 17, 2005, 04:53:54 AM
I don't really understand the subs.php page very well, but it should be possible. It would be easier (and more convienient for names changes) if you had it for user account ids instad.

I can see where it would be beneficial to use account IDs, but that wouldn't be terribly convenient for most users, who might not be aware of how to find the ID number of a particular user account. In a forum (such as mine) where user name changes are disallowed, it would be far simpler to use account names.

However, perhaps there might be some behind-the-scenes conversion. When entering the post, the poster uses the account name, but SMF stores the account ID number in the database (and perhaps generates a warning if the account name doesn't exist).

KJToo

Okay, I had a lot of help with this from a PHP guru who frequents my forum. Here's what we came up with:

In Subs.php, locate the parsecode function:

function parsecode(&$message)
{
global $modSettings, $scripturl, $txt;


Change this:
global $modSettings, $scripturl, $txt;
To this:
global $modSettings, $scripturl, $txt, $user_info;

Within the same function, find this:

$arr2 = array();

After that, add:

// Private text  [private=user]No one else can see![/private]
// If the [private] tag is disabled, display nothing.
if(isset($add['[private='])){
$arr1[] = '~\[private=([\w,\-\s]+?)\](.+?)\[/private\]~ie';
$curruser = $user_info['name'];
$arr2[] = isset($disabled['private']) ? '' : 'in_array(strtolower($curruser),split(",",strtolower("$1"))) ? \'<span style="font-size: 80%; font-weight: bold;">Private text for $1:</span><br /><div style="background-color: black; color: white; border: 1px solid white; padding: 2px 4px 2px 4px;">$2</div>\' : \'\'';
}


The remaining changes are necessary to ensure that private text cannot be viewed when quoting messages containing private text.

In Post.php locate the post function. Deep in that function, find the following:

$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);

After that, add this:


// Remove any private text.
$form_message = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $form_message);


Now find this:

$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);

After that, add:


// Remove any private text.
$row['body'] = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $row['body']);


All tests I've run on this so far have been successful, but I can't guarantee that it will work in all cases. If anyone can offer tips or suggestions to tweak it, please let me know.

LostProphecy

hmmm i'd be willing to test it for you if you like :)... at work at the moment, but i'll install it asap and see how she goes :) ;)
Angelus Ex Quo Nox

KJToo

Okay, I've made an improvement to deal with extraneous spaces before and/or after commas separating usernames. I've also added a BBCode button that makes adding private text a little simpler.

Sub.php
Find:
function parsecode(&$message)
{
global $modSettings, $scripturl, $txt;

Replace with:
function parsecode(&$message)
{
global $modSettings, $scripturl, $txt, $user_info;


Find:
$arr2 = array();
After, add:
// Private text  [private=user]No one else can see![/private] (KJToo)
if(isset($add['[private='])){
$arr1[] = '~\[private=([\w,\-\s]+?)\](.+?)\[/private\]~ie';
$curruser = $user_info['name'];
$arr2[] = isset($disabled['private']) ? '' : 'in_array(strtolower($curruser),preg_split("/[\s]*,[\s]*/", strtolower("$1"))) ? \'<span style="font-size: 80%; font-weight: bold;">Private text for $1:</span><br /><div class="privateblock">$2</div>\' : \'\'';
}


Post.php

Find:
$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);

After, add:
// Remove any private text. (KJToo)
$form_message = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $form_message);


Find:
$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);

After, add:
// Remove any private text. (KJToo)
$row['body'] = preg_replace(array('~\n?\[private.*?\].+?\[/private\]\n?~is', '~^\n~', '~\[/private\]~'), '', $row['body']);


Now to add the BBCode button. Note: if you have multiple themes installed, check each theme directory for the file Post.template.php. Some themes have their own version of this file, but many use the default (Themes\default\Post.template.php).

Post.template.php
Find:
'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
After, add:
'private' => array('private' => 'private', 'before' => '[private='. $user_info['name'] . ']', 'after' => '[/private]', 'description' => 'Private Text'),

Last but not least, tack the following on the end of the various iterations of style.css that appear in the Themes directories.

style.css
/* Private text */

.privateblock
{
border: 1px solid blue;
background: black;
color: white;
padding: 2px 4px 2px 4px;
}

The button graphic I'm using is a very simple transparent GIF that can be dropped into the images\bbc directory of most themes:

The Classic theme doesn't use transparent GIFs, so I created a separate image for the Classic theme:

The proper format for private text follows.
[private=username]This is private text.[private]
[private=username1,username2,username3]This is private text.[private]

The default code displays private text in a white-on-black section, but the color scheme can be easily modified to suit individual tastes by editing the code inserted into style.css.

LostProphecy

*pouts*

bugger... the translations in beta 2 are different, so unfortunately i can't install this mod :(
Angelus Ex Quo Nox

Wretched

This mod is EXACTLY what I'm looking for but doesn't seem to be compatible with 1.1.2. Any pointers on updating it?

Wretched

Anybody? The subs.php is totally throwing me trying to convert it.

SleePy

Is this issue solved or do you still require assistance?

What error are you receiving?
Jeremy D — Site Team / SMF Developer
Support the SMF Support team!
Profiles:GitHub
Join us on IRC Libera.chat/#smf

Wretched

No, not resolved yet.

I don't understand what the subs.php part of the mod is doing and have no idea how to translate it to 1.1.3

Advertisement: