speedway
Well-known member
Hi all
I would like to create an addon that displays the thread age next to the thread title, for example in the Whats New page. Here is a shot of what I mean:
I have this on my VB forum at the moment and the code doesn't look like anything special. There are three places it happens (from VB):
The first one is placed into the hook "threadbit_process":
The next hook to be used is "showthread_getinfo":
and lastly in the hook "process_template_complete":
Where this appears is controlled by an option:
If someone could give me some pointers as to where to start and I'll go from there.
Cheers
I would like to create an addon that displays the thread age next to the thread title, for example in the Whats New page. Here is a shot of what I mean:
I have this on my VB forum at the moment and the code doesn't look like anything special. There are three places it happens (from VB):
The first one is placed into the hook "threadbit_process":
Code:
$ta_start = "<span style=\"color: " . vB_Template_Runtime::fetchStyleVar('boofo_threaddays_color') . "\">";
$ta_end = "</span>";
$threaddays = floor((TIMENOW - $thread['dateline'])/86400);
switch ($threaddays)
{
case '0':
$thread['threaddays'] = "– $ta_start<b>" . $vbphrase['today'] . "</b>$ta_end";
break;
case '1':
$thread['threaddays'] = "– $ta_start" . $threaddays . " " . $vbphrase['boofo_threaddays_dayold'] . "$ta_end";
break;
default:
$thread['threaddays'] = "– $ta_start" . $threaddays . " " . $vbphrase['boofo_threaddays_daysold'] . "$ta_end";
break;
}
The next hook to be used is "showthread_getinfo":
Code:
$ta_start = "<span style=\"color: " . vB_Template_Runtime::fetchStyleVar('boofo_threaddays_color') . "\">";
$ta_end = "</span>";
$threaddays = floor((TIMENOW - $thread['dateline'])/86400);
switch ($threaddays)
{
case '0':
$thread['threaddays'] = "– $ta_start<b>" . $vbphrase['today'] . "</b>$ta_end";
break;
case '1':
$thread['threaddays'] = "– $ta_start" . $threaddays . " " . $vbphrase['boofo_threaddays_dayold'] . "$ta_end";
break;
default:
$thread['threaddays'] = "– $ta_start" . $threaddays . " " . $vbphrase['boofo_threaddays_daysold'] . "$ta_end";
break;
}
and lastly in the hook "process_template_complete":
Code:
$location = $vbulletin->options['boofo_threaddays_location'];
switch ($location)
{
case '0':
default:
break;
case '1':
require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('{vb:raw thread.threadtitle}</a>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$parser = new vB_TemplateParser('{vb:raw thread.threadtitle}</a> {vb:raw thread.threaddays}');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$vbulletin->templatecache['search_threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['search_threadbit']);
$vbulletin->templatecache['threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit']);
$vbulletin->templatecache['threadbit_deleted'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit_deleted']);
unset($find, $replace);
// Showthread title at top of thread
$parser = new vB_TemplateParser('{vb:raw threadinfo.title}</a>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$parser = new vB_TemplateParser('{vb:raw threadinfo.title}</a> {vb:raw thread.threaddays}');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']);
unset($find, $replace);
break;
case '2':
require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('{vb:rawphrase started_by_x_y_z_a, {vb:link member, {vb:raw thread}, null, \'postuserid\', \'postusername\'}, {vb:raw thread.postusername}, {vb:raw thread.startdate}, {vb:raw thread.starttime}, {vb:stylevar dirmark}}');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$parser = new vB_TemplateParser('{vb:rawphrase started_by_x_y_z_a, {vb:link member, {vb:raw thread}, null, \'postuserid\', \'postusername\'}, {vb:raw thread.postusername}, {vb:raw thread.startdate}, {vb:raw thread.starttime}, {vb:stylevar dirmark}} {vb:raw thread.threaddays}');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$vbulletin->templatecache['search_threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['search_threadbit']);
$vbulletin->templatecache['threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit']);
$vbulletin->templatecache['threadbit_deleted'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit_deleted']);
unset($find, $replace);
break;
}
Where this appears is controlled by an option:
If someone could give me some pointers as to where to start and I'll go from there.
Cheers