vBulletin Modifications

Methodology for plugin template changes

Welcome to vBHackers.com! - vBHackers Updates:

Go Back   vBulletin Modifications > General vBulletin Section > General vBulletin Support

Reply
 
LinkBack Thread Tools
Old 04-07-2006, 01:56 PM   #1
tgreer
Guest

Default Methodology for plugin template changes

If you're authoring a product, and that product creates

1) plugin(s)

2) phrase(s)

I know you can associate plugins and phrases with a product. But what about template changes?

Is there a mechanism to associate a template version/change with a product? That seems very dangerous to me. Who knows but that another plugin might alter the same template?

It seems to me that the way to handle this is to create your OWN unique template, and then, if your product is enabled, swap the default template for your own.

How would you do this?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 04-07-2006, 02:01 PM   #2
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

I don't think there's an easy way to modify templates with a plugin. You could get the template with an SQL query and add your code to it (with a conditional around your code sothat it would only display when your plugin is running), but thats quite a complicated procedure.

To what would you apply this to though? Would you want to (for example) add some code to the FORUMHOME template only when your plugin is running?




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 02:37 PM   #3
tgreer
Guest

Default

Consider my "invite" system. It's fully-phrased. It uses a plugin for the main PHP code. That's fine.

But it's all meaningless unless the invitation is displayed, and that means changing a template.

I chose to change the forumrules template. If the person is authenticated, then show the normal posting rules. If they are a guest, however, then in my opinion, posting rules are meaningless... so replace them entirely with the invitation.

Now, if I were to make this a released hack, I can document the template changes a user would need to make.

However, I think a better approach is to not change forumrules at all, but to include a completely different template, call it invite_forumrules, and use a plugin to enable it.

Something like this:

You must first be a registered member to view any code.
So my questions are:

1. How do you cause vbulletin to use a different template than it normally would? I see calls to "fetch_template", so I imagine the plugin would need to use that mechanism.

2. Performance considerations: how would you make sure your template was properly cached?

Ok - some more specific information/questions:

vBulletin caches it's templates. So when there is a call for a template via the fetch_template() function, it fetches it from the cache. True? False?

Assume it's true - I see a cache_templates hook. So I think it would be possible to author a plugin that runs at that hook, which will check to see if your product is enabled, and if so, "swap" the template... something like:

$this->templates['forumrules'] = "invite_forumrules";

Does that make sense, or am I totally confused?

Last edited by tgreer; 04-07-2006 at 02:50 PM.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 03:11 PM   #4
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Right, I'll try to answer your questions the best I can, but I'll firstly give you a short inrtoduction of how the template system works:

Templates are called with the fetch_template function. This gets the template from either the cache or the DB (explenation bellow), adds the variables and outputs it with the use of the eval(); function. Depending on what you use it for (as a bit template using .=, or a page output using print_output();), it'll spit out its HTML a number of times or only one time.

If you'd want to Cache templates by making a file edit you'd simply need to add it to the $globaltemplates array. If you do not do so, the fetch_template will make a query in order to display the template, thus increasing the site load. Fetching a template from the cache uses up hardly any resources, nothing compared to an actual DB query.

What most files (especially in vB 3.5.x) do, is define the template called in a conditional, and than at the end of the page add:
You must first be a registered member to view any code.
Rather than add
You must first be a registered member to view any code.
to every conditional.
This makes custom calling of templates a whole lot easier, as you can simply define the new template in a hook in the conditional.

The problem here would be the performance issue. You'd have to load an uncached template, meaning it'll add an extra query to your file. I assume you could use the cache_templates hook, but to be honest I've never done so so I wouldn't know.

What you could possibly do, is add this to your plugin:
You must first be a registered member to view any code.
where $customarray could be:
You must first be a registered member to view any code.
I personally have no idea whether this works or not, but it should if its added near the top of the file (possibly the cache_templates hook?).

Do you perhaps know where the cache_templates hook is located (which file)?

Also, where is the forumrules hook located? I'll take a look at the file if you want, see if I can come up with something.
__________________
Need some custom work done for your site, but can't find a (freelance) coder willing to take on the job? Good news: you needn't look further, as I'm currently accepting custom jobs! From a template fix to a completely new portal system, you name it and I'll make it exclusively for your site! Interested? Send me a PM for details. ;)


Please note that I will only provide support through the vBHackers.com Forums, not through MSN/email/PM.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 03:34 PM   #5
tgreer
Guest

Default

I think I followed most of that, but it doesn't seem to address my specific question.

I mean, I think I understand how in general to fetch any template, including a custom template. But what the missing piece is, how can I make vBulletin fetch MY template INSTEAD OF an existing template, in every case where the existing template is used?

In the case of forumrules, it is fetched via a function call in the bigthree.php file. There is a hook location just prior to fetching the template. I don't think that's useful to me, as the fetch to forumrules is hard-coded directly after. I need some way to universally make forumrules = invite_forumrules.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 03:51 PM   #6
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Well, by the looks of it that's going to be impossible to change without either code or template changes

However, if you want to still fully automize the script you could try this:
In your install script, query the template forumrules. Stick this infront of it:
You must first be a registered member to view any code.
and stick this to the end of the template:
You must first be a registered member to view any code.
and save it back into the DB.

This takes away your performance concern aswell ;).

Also, you can change the !$bbuserinfo[userid] to anything you want. The above code will show your custom code to guests, as the userid of a guest is always 0.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 03:56 PM   #7
tgreer
Guest

Default

Thanks... but that's exactly the kind of thing I'm trying to avoid!

It seems I keep bumping into problems that I would have thought the plugin community had already addressed.

For example, it seems crazy to me that a plugin should require the user to make template changes. To me, it seems perfectly logical that the way to handle this is to simply provide new templates entirely. Then, there should be one simple method/place to say "if my product is installed, use THIS template instead of THAT template".




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 03:58 PM   #8
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Yes, the plugins aren't quite what I expected them to be when I first started using them either.

However, once vB starts documenting them correctly and starts adding more and more plugins, they'll probably become muchbetter.
Plugins have already made revolutionary changes to the hacking of vBulletin boards, now there's need for 1-2 edits... back in the days you'd need to make ~10 edits ;).

For now we'll just have to make a file edit or two if we want to get things to work exactly like we want them to .




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 04:07 PM   #9
tgreer
Guest

Default

I'm not giving up... this seems so logical to me! I'll figure it out. Thanks - in the three forums I've posted this topic, you're the only one to take time to reply.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-2006, 04:11 PM   #10
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Alright, good luck and: you're welcome ;).

Let me know if/when you find solution please - I'm quite interested myself.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables from .php to template Anubis General vBulletin Support 16 04-06-2006 07:17 PM
allowing 3 styles to share 1 template set?? figure004 General vBulletin Support 2 02-08-2006 04:33 PM
How Do You Delete A Template? Stunt General vBulletin Support 6 10-01-2005 02:38 PM
Index Template required Gary Bolton vBulletin Modification Requests 1 01-29-2005 08:45 AM


All times are GMT -3. The time now is 09:16 PM.


SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc. (Patent Pending)