Quote:
Originally Posted by nhawk
Here's a snippet of the code to add an application type to the community menu...
Code:
while($application = $vbulletin->db->fetch_array($applications))
{
if ($vbulletin->options['advapp_inmenu'] && $vbulletin->userinfo['posts'] >= intval($application['postcount']) && is_member_of($vbulletin->userinfo, explode(',', $application['usergroup'])) && $application['community'] && $application['active'])
{
$template_hook['navbar_community_menu_end'] .= '<li><a href="application-forms.php?appid=' . $application['appid'] . '" title="' . $application['description'] . '">' . $application['type'] . '</a></li>';
}
}
|
Thanks, that's what I expected
The idea behind Navigation Manager is to give the Administrator full control over the menu structure - if you are creating links dynamically at runtime (which is still possible) you are IMHO somewhat defeating that goal.
Quote:
This reminds me of the addition of the <vb:each> in templates...
Nobody is going to tell me that reading a database, parse the data to build an array, sending that array to the template and parsing it a second time is faster than bulding/formating the array and sending it in all one lump piece of data to the template.
|
<vb:each> is a lot faster then doing a ton of vB_Template::create() ... render() calls in a loop
Here is a little benchmark:
PHP Code:
require('./global.php');
require(DIR . '/includes/adminfunctions_template.php');
$vbulletin->templatecache['text_bit'] = compile_template('{vb:raw text}');
$vbulletin->templatecache['text'] = compile_template('{vb:raw textbits}');
$vbulletin->templatecache['text_foreach'] = compile_template('<vb:each from="textbits" value="text">{vb:raw text}</vb:each>');
// Benchmarking bit templates
$start = microtime(true);
$textbits ='';
for ($i = 1; $i < 10000; $i++)
{
$templater = vB_Template::create('text_bit');
$templater->register('text', 'This is Text #' . $i);
$textbits .= $templater->render();
}
$templater = vB_Template::create('text');
$templater->register('textbits', $textbits);
$result1 = trim($templater->render());
$end = microtime(true);
header('Content-type: text/plain');
echo('Time taken for 10.000 Bit Templates: ' . ($end-$start) . "\n");
// Benachmarking <vb:each>
$start = microtime(true);
$textbits = array();
for ($i = 1; $i < 10000; $i++)
{
$textbits[] = 'This is Text #' . $i;
}
$templater = vB_Template::create('text_foreach');
$templater->register('textbits', $textbits);
$result2 = trim($templater->render());
$end = microtime(true);
echo('Time taken for 10.000 Array-Elements with <vb:each>: ' . ($end-$start) . "\n");
if ($result1 == $result2)
{
echo('Success - Both methods yielded the same result data');
}
else
{
echo('Huh? Smth. went wrong, the results are not identical');
echo("\n\n----\n$result1\n----\n$result2");
}