vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   vB4.2 Navigation Manager - how to discussion (https://vborg.vbsupport.ru/showthread.php?t=283146)

Andreas 05-19-2012 07:44 PM

Quote:

Originally Posted by nhawk (Post 2330786)
But I see people using it something like this...

Code:

in PHP..
While $whatever...
{
      $whatever_each_array[] = xpartofdata;
}
$templater->register('whatever'. $whatever_each_array);

In template..
<ul>
<vb:each whatever_each>
        <li>{vb:raw whatever_array_part}</li>
</vb:each>
</ul>


Although that is a bit slower than hardcoding the HTML, this is the way it should be done as it separates the presentation from the business logic.

If the designer want's to do smth. complletely different from <ul> he can do that by simply modifying the template - with the list entries being generated in PHP he can't

kh99 05-19-2012 09:25 PM

Quote:

Originally Posted by Andreas (Post 2330764)
<vb:each> is a lot faster then doing a ton of vB_Template::create() ... render() calls in a loop :)

I'm curious, do you know why that is? Is it the time needed to create the objects?

AusPhotography 05-20-2012 06:14 AM

Quote:

Originally Posted by kh99 (Post 2330811)
I'm curious, do you know why that is? Is it the time needed to create the objects?

The render uses 'eval' 'nuff said

Kym

AusPhotography 05-20-2012 06:45 AM

This is very handy... https://vborg.vbsupport.ru/showthread.php?t=283123 (Thanks Andreas)

Also Scott's post on vb.com https://www.vbulletin.com/forum/show...56#post2295256

nhawk 05-20-2012 10:22 AM

Quote:

Originally Posted by Andreas (Post 2330789)
Although that is a bit slower than hardcoding the HTML, this is the way it should be done as it separates the presentation from the business logic.

If the designer want's to do smth. complletely different from <ul> he can do that by simply modifying the template - with the list entries being generated in PHP he can't

Even though I'm not a big fan of anything that increases processing time, I see your point. :)

And a note for any other coders that might want to add menus via DB addition rather than at installation.. Be sure you run build_language() after adding the navigation and phrase info. If you don't, your phrase won't appear in the menus.

EDIT: Another note.. The information that's the original topic of this thread gets added to the install XML when you export it. So, you just need to create the navigation links and export a new XML for the mod.

kh99 05-20-2012 12:03 PM

Quote:

Originally Posted by snoopytas (Post 2330878)
The render uses 'eval' 'nuff said

Kym

OK, but I ran this modified version of the benchmark:

PHP Code:

require('./global.php');
require(
DIR '/includes/adminfunctions_template.php');

$vbulletin->options['addtemplatename'] = 0;

$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();
    
$text 'This is Text #' $i;
    eval(
$vbulletin->templatecache['text_bit']);
    
$textbits .= $final_rendered;
}
$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");



and I got these results:

Code:

Time taken for 10.000 Bit Templates: 0.072948932647705
Time taken for 10.000 Array-Elements with <vb:each>: 0.011199951171875
Success - Both methods yielded the same result data


vs. these for the original version:

Code:

Time taken for 10.000 Bit Templates: 1.542927980423
Time taken for 10.000 Array-Elements with <vb:each>: 0.011492967605591
Success - Both methods yielded the same result data


That's 6.5 times slower vs 134 times slower, and seems to indicate that eval() isn't the main offender.

Andreas 05-20-2012 12:12 PM

It's basically the overhead required for variable registration and object creation that makes rending templates in a loop pretty slow.

kh99 05-20-2012 12:41 PM

Yeah, I played around more and found that my times dropped from 1.5 to 0.7 just by not calling register_globals().

BirdOPrey5 05-20-2012 01:41 PM

Quote:

Originally Posted by Andreas (Post 2330753)
If it is a "static" link - yes, it should be added to the navigation table upon Add-on installation.
(Which will happen automatically if you have already added that link on your developement system, assigned in to the Add-on and exported the XML).

But if it's not a static link? I'm supposed to tell user's to do it themselves now because vBulletin thinks they want more control over their navbar? Respectfully, most user's do not want total control, they want things done for them.

I've come up with this code, it's not efficient but it works, I will work on efficiency-

nhawk I know you mentioned making a database change but I prefer to avoid db edits if possible.

This example adds a link to Quick Links
No phrase needed.

On navigation_tab_complete hook:

PHP Code:

//Quick Links Add in 4.2.0 Start
  
foreach ($tabdata AS $key => &$thistab)
  {
   if (
is_array($thistab['children']))
   {
    foreach (
$thistab['children'] AS &$ttab)
    {
     if (
$ttab['name'] == 'vbmenu_qlinks')
     {
       
$nl['root']  = $key;
       
$nl['type']  = 'link';
       
$nl['url']    = 'myfile.php';
       
$nl['title']  = 'Link Title';
       
$nl['name']  = 'custom_name_here';
       
$nl['children'] = 0;
       
$ttab['children'][] =  $nl;
     }
    }
   }
  }
//Quick Links Add 4.2.0 END 

Mind you that needs to be run for each new link which itself will likely be some kind of loop.

Andreas 05-20-2012 02:06 PM

Quote:

Originally Posted by BirdOPrey5 (Post 2330964)
But if it's not a static link?

That is a problem :)

I do not know the exact ideas behind Navigation Manager , but I think it simply wasn't designed with dynamic links in mind as vBulletin itself (except vBulletin CMS) does not do that.

As I see it, there are currently three alternatives (of which none is realldy ideal):
  • Programatically create/update/delete links in navigation manager based on the Add-on data
    Pro: Full control over the links
    Con: Rather complicated management for the Add-on, might requires extensive changes to the logic
  • Don't create any links and leave it up to the user
  • Pro: Full control, no additional work the for Add-on author
    Con: A lot of work for the Administrator
  • Create links at runtime
    Pro: Fairly easy to do
    Con: Zero control over placement in Navigation Manager, code can be a little bit inefficient

IMHO the best solution would be if the Navigation Manager would offer "Dynamic Content" items which would just act as placeholders in ACP and are only being filled with content on the frontend when needed.
This would be easy to implement and maintain for Add-ons and would still give the Administrator the power to control placement, etc.

http://tracker.vbulletin.com/browse/VBIV-15123


All times are GMT. The time now is 07:32 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02870 seconds
  • Memory Usage 1,778KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (2)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete