Caching templates if they exists.
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #11
RE: Caching templates if they exists.
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.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
05-23-2012 03:10 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #12
RE: Caching templates if they exists.
(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?

My Blog
05-23-2012 03:52 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #13
RE: Caching templates if they exists.
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...

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
05-23-2012 05:57 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #14
RE: Caching templates if they exists.
(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:
1
2
3
4
5
6
7
8
9
// $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).'";');


My Blog
05-23-2012 06:44 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #15
RE: Caching templates if they exists.
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.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
(This post was last modified: 05-23-2012 09:36 PM by Sama34.)
05-23-2012 09:33 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #16
RE: Caching templates if they exists.
(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.

My Blog
05-24-2012 11:53 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: