Version: 3.00, by Erwin
Developer Last Online: May 2013
Version: 3.0.7
Rating:
Released: 01-04-2004
Last Update: Never
Installs: 200
No support by the author.
Updated version 2.00 thanks to buro9!
Updated version 3.00 thanks to Edgewize!
New in version 3.00:
Correct parsing in quotes, private messages etc.
Okay, this is the famous /me code first created by Chen. All credits go to him. I'm just putting up instructions on how to do this in vB3. It's very easy.
It was doing weird things when a user edits a post... so I've created this work around for the bit of text that goes into functions_bbcode.php
Code:
// HACK : START : ME
global $post;
if ('' == $post[username]) {
$meUsername = $bbuserinfo[username];
} else {
$meUsername = $post[username];
}
$bbcode = preg_replace('#^/me (.*)$#im', "<font color=\"red\">* $meUsername \\1</font>", $bbcode);
// HACK : END : ME
Essentially if you are editing a post the $post array does not exist, as another context is used instead. So you lose the username.
I've added a switch that tests for this, and if $post doesn't exist, it uses the name of the current poster... fine for my forum as I only allow post owners to edit their messages... but this is a crude hack and it will break when an admin or mod edits their post... so not good.
Does anyone know a better context that I can use? How to find out the equivalent of an $editpost array or the post id so that I can get the proper name.
It was doing weird things when a user edits a post... so I've created this work around for the bit of text that goes into functions_bbcode.php
Code:
// HACK : START : ME
global $post;
if ('' == $post[username]) {
$meUsername = $bbuserinfo[username];
} else {
$meUsername = $post[username];
}
$bbcode = preg_replace('#^/me (.*)$#im', "<font color=\"red\">* $meUsername \\1</font>", $bbcode);
// HACK : END : ME
Essentially if you are editing a post the $post array does not exist, as another context is used instead. So you lose the username.
I've added a switch that tests for this, and if $post doesn't exist, it uses the name of the current poster... fine for my forum as I only allow post owners to edit their messages... but this is a crude hack and it will break when an admin or mod edits their post... so not good.
Does anyone know a better context that I can use? How to find out the equivalent of an $editpost array or the post id so that I can get the proper name.
Cheers
David K
Good idea. I've been essentially too lazy to fix this as this hack is basically not that important on my site.
It was doing weird things when a user edits a post... so I've created this work around for the bit of text that goes into functions_bbcode.php
Code:
// HACK : START : ME
global $post;
if ('' == $post[username]) {
$meUsername = $bbuserinfo[username];
} else {
$meUsername = $post[username];
}
$bbcode = preg_replace('#^/me (.*)$#im', "<font color=\"red\">* $meUsername \\1</font>", $bbcode);
// HACK : END : ME
Essentially if you are editing a post the $post array does not exist, as another context is used instead. So you lose the username.
I've added a switch that tests for this, and if $post doesn't exist, it uses the name of the current poster... fine for my forum as I only allow post owners to edit their messages... but this is a crude hack and it will break when an admin or mod edits their post... so not good.
Does anyone know a better context that I can use? How to find out the equivalent of an $editpost array or the post id so that I can get the proper name.
As I said: Essentially if you are editing a post the $post array does not exist, as another context is used instead. So you lose the username
So... when posts with /me in are being edited... the edited version no longer contains the username... so /me might have been "* buro9" in the original, but after edit it was "* " and no username... the fix above presumes the person editing is the person who performs the action and inserts their username.
It's a minor thing, but one that was noticed immediately on my board... so I put this hack to this hack in there.
Look... if you haven't seen the bug, or experienced it... cool
But if you've seen it, and it nags you... then a workaround is above.
You don't have to use it.
Erwin! I've got it!
Could you update your hack?
Code:
// HACK : START : ME
global $post;
if ('' == $post[username]) {
global $reputation;
if ('' == $reputation[username]) {
global $pm;
if ('' == $pm[fromusername]) {
$meUsername = $bbuserinfo[username];
} else {
$meUsername = $pm[fromusername];
}
} else {
$meUsername = $reputation[username];
}
} else {
$meUsername = $post[username];
}
$bbcode = preg_replace('#^/me (.*)$#im', "<span class=\"postAction\">* $meUsername \\1 *</span>", $bbcode);
// HACK : END : ME
Note I've changed one thing regards the formatting that you might not want to change... I use a stylesheet for it so that I can use different colours according to style in use.
But it's the nested if's that is important... solves /me for PM's and reputation bits
// HACK : START : ME
global $post;
if ('' == $post[username]) {
global $reputation;
if ('' == $reputation[username]) {
global $pm;
if ('' == $pm[fromusername]) {
$meUsername = $bbuserinfo[username];
} else {
$meUsername = $pm[fromusername];
}
} else {
$meUsername = $reputation[username];
}
} else {
$meUsername = $post[username];
}
$bbcode = preg_replace('#^/me (.*)$#im', "<span class=\"postAction\">* $meUsername \\1 *</span>", $bbcode);
// HACK : END : ME
Note I've changed one thing regards the formatting that you might not want to change... I use a stylesheet for it so that I can use different colours according to style in use.
But it's the nested if's that is important... solves /me for PM's and reputation bits