I originally posted a request for an add on to be made for me, but since then I have decided to have a go at making it myself.
The simple premise is the good old /me command as seen in numerous chat systems including mIRC and Steam. So, if I were to type in a post: /me would like to create an add on then it would get transformed into:
* Yorick would like to create an add on
Some have questioned the need and/or feasibility of such an add on, but with it being available natively in myBB and SMF and available as a mod in vBulletin then I'm sure it's very feasible.
And actually I've made some progress:
So actually this code is broken. The reason it is broken is because $message.username or $message is undefined. $message.username is used in the message and post templates to call the post author's username.
If $me = 'Yorick' then actually the code works how I want - but /me will always transform into Yorick instead of the actual author's username.
So I feel like we're close.
I can get around the aforementioned error regarding the variable being undefined by changing the $templateName to 'message' or 'post' as they must be defined there. But unfortunately - and I don't know why - doing so completely ignores the /me code.
Any help gratefully received. Once we have this working we are going to release it ourselves on the Resource Manager so hopefully anyone else in the future can make use of this.
EDIT: We did start work on a slightly different variation where instead of replacing /me with the contents of a variable instead we tried to get /me to call a template which would call the variable. Is that something that might work better?
The simple premise is the good old /me command as seen in numerous chat systems including mIRC and Steam. So, if I were to type in a post: /me would like to create an add on then it would get transformed into:
* Yorick would like to create an add on
Some have questioned the need and/or feasibility of such an add on, but with it being available natively in myBB and SMF and available as a mod in vBulletin then I'm sure it's very feasible.
And actually I've made some progress:
PHP:
<?php
class Me_EventListener_TemplatePostRender
{
static public function listen($templateName, &$output, &$containerData, XenForo_Template_Abstract $template){
if($templateName == 'thread_view'){
$me = {$message.username};
$output = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "<b>\\1 * '{$me}' \\2</b>", $output);
}
}
}
So actually this code is broken. The reason it is broken is because $message.username or $message is undefined. $message.username is used in the message and post templates to call the post author's username.
If $me = 'Yorick' then actually the code works how I want - but /me will always transform into Yorick instead of the actual author's username.
So I feel like we're close.
I can get around the aforementioned error regarding the variable being undefined by changing the $templateName to 'message' or 'post' as they must be defined there. But unfortunately - and I don't know why - doing so completely ignores the /me code.
Any help gratefully received. Once we have this working we are going to release it ourselves on the Resource Manager so hopefully anyone else in the future can make use of this.
EDIT: We did start work on a slightly different variation where instead of replacing /me with the contents of a variable instead we tried to get /me to call a template which would call the variable. Is that something that might work better?