MyBB Hacks

Full Version: Caching templates if they exists.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Really sorry about this Zinga, but my English is not that good. Can you please explain rewrite your post in a different way?

It is your the second line what I don't understand.
(05-22-2012 05:43 PM)ZiNgA BuRgA Wrote: [ -> ]One would imagine that you don't specify arbitrary groups - for additional groups, don't you grab the list of user groups from the user, not a template?
Okay, in other words, the user has a list of groups that they belong to.  Which can be different for each user.
Templates are fairly static across users, so why are you putting usergroup specific code in templates?
Because if for example I'm part of the "admin (4)" group as primary, and "Boys (11)" group, and the "Jerks (8)" group as additional groups, in profile MyBB by default will display my displaygroup image (Admin for this example) using {$memprofile['groupimage']}.

Admins will be able to show all additional image gorups using {$memprofile['agi']}.

But if they want to show the "Jerks" groupimage using another template that or far apart from the "Boys" one, they can just paste {$memprofile['agis']['8']} inside the member_profile template.

Then  the plugin just evals the {$memprofile['agis']['8']} variable using the member_profile_groupimage_8 template.

That template may be an exact copy of the member_profile_groupimage one, or a custom code, it doesn't matter.

The thing is that if member_profile_groupimage_8 doesnt exists, I don't want to try to eval the variable, so just return null or ''.

Maybe just attaching my file may be better to understand what I mean.


Please note that {$memprofile['agis']['8']} is suppose to print the group image of GID 8 in profiles, if X user is part of that group in his additional usergroup list, or usegroup (if he has a displaygroup) it will return the image as normal.

But is Y user doesn't have GID 8 as additional the the variable will return null, like empty or whatever.

... Yes, don't even I understand what I write, will try to attach my plugin tomorrow...
(05-23-2012 05:57 PM)Sama34 Wrote: [ -> ]they can just paste {$memprofile['agis']['8']} inside the member_profile template.
I just don't get why you want to do this though.
Do you need the extra flexibility of simply appending it to {$memprofile['agis']} ?

Again, why not add an extra column into the usergroups table which has custom HTML for the group image - do you absolutely have to do it through profiles?

Even if so, it's unlikely that a user will have that many groups, so just cache them using $templates->cache function will work:

PHP Code:
// $usergroups contains all groups' IDs user is a part of
$templates_to_cache = 'member_profile_groupimage_' . implode(',member_profile_groupimage_', $usergroups);
$templates->cache($templates_to_cache);

...

foreach($usergroups as $usergroup)
  if($templates->cache['member_profile_groupimage_'.$usergroup]) // weak condition: you may wish to change if you want 100% accuracy, but not that important
    eval('$booyah = "'.$templates->get_the_damn_thing('member_profile_groupimage_'.$usergroup).'";');

I wanted this to add something different to my plugin, because there are about who-knows-how-many of the same kind already vaible out there (and I din't liked any of them).

After post #4 here Idecided to drop it and keep the basic plugin idea, but then it was kind of a personal challenge to be honest >_>

I think I see what you mean, caching the whole amount of templates is worse that the feature's worth, am I right?

And for about the extra colum, the answer may be that it does not meet what I intended in the first place Arf

BTW, I really appreciate your patience Zinga Burga.
(05-23-2012 09:33 PM)Sama34 Wrote: [ -> ]I think I see what you mean, caching the whole amount of templates is worse that the feature's worth, am I right?
What I wrote about is caching the templates, but it does increase the total query count by 1 (regardless of the number of groups).

IIRC, $mybb->user is available on global_start, so you could append to the template list there if you wish.
Pages: 1 2
Reference URL's