Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2013, 08:55 PM
create365 create365 is offline
 
Join Date: Aug 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default replace variables in style with xml

So I was wondering, is it possible to write a code that will replace style variables?
I'm rewriting mod for username/displayname replacement, and I want it to be installed automatically.
Regarding this: https://vborg.vbsupport.ru/showthread.php?t=302333

So I have variable
{bbuserinfo.username} and I need to replace it with my custom code with <vb:if>.


Any way to accomplish this with XML import, not editing templates manually?

Hooks won't help here.
Reply With Quote
  #2  
Old 09-17-2013, 10:21 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what you're asking. Where is the {bbuserinfo.username} that you want to replace?
Reply With Quote
  #3  
Old 09-19-2013, 01:15 PM
create365 create365 is offline
 
Join Date: Aug 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I'm not sure what you're asking. Where is the {bbuserinfo.username} that you want to replace?
Let's say it's in XXX template. I need to replace template variables in existing templates. Never done that with plugins, I only used template hooks and insert new templates.

Is there a way to edit exsiting template when importing product? The simplest example:

Let's say in template XXX we have this code:
<div>test</div>
I want to replace this in this template with:
<div>other_test</div>

While importing product, the template already exists, there are no template hooks there. Is there a way to do it with xml plugin install code for example?
Reply With Quote
  #4  
Old 09-19-2013, 02:27 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There is a product that I believe does what you want, but if you use it you'd of course need anyone who uses your product to install it first, and I believe it puts a copyright notice on each page. In any case, it's here: www.vbulletin.org/forum/showthread.php?t=152931

What you can also do is write a plugin to do a search and replace on the template when it's in the template cache. If you make a plugin using hook parse_templates, the cached template will be in $vbulletin->templatecache['template_name']. But it's complicated by the fact that what is in the cache is actually php code that produces the template when eval'd. So you might be able to do a simple replacement if you just want to replace some text, but if you want to replace something that is inserted by a variable, it's more difficult to figure out what to use for the match and replacement text.
Reply With Quote
  #5  
Old 09-24-2013, 01:41 PM
create365 create365 is offline
 
Join Date: Aug 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't understand me.

I am writing a product.

To install it, I need to modify existing vBulletin template. The only way so far I know, was to use vBulletin template hooks and/or plugins system.

My question is, is it possible to modify existing vBulletin template - FORUMHOME, to insert custom code inside?

I know I can include whole forumhome template in the script and replace it, but if somebody edited it manually those changes will be lost.

EDIT: Yes, that's what I'm looking for more-less. So this is a plugin, there is no way to do that on "vanilla" vB?
Reply With Quote
  #6  
Old 09-24-2013, 03:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I thought I understood. Or I guess I should say, if I didn't understand before, I still don't.

Anything is possible. The templates are stored in the database, so you could execute a query to change a template, then call the function to recompile it (since a compiled version is also stored in the database). Also, a forum might have more than one style, and each style may or may not have a separate version of that template, so you'd have to handle that. You'd also want to remove your change when the template is uninstalled. There isn't any support for doing this in vb, and I haven't heard of anyone actually doing it that way, but maybe you have a reason for doing it that way that I don't know about.

I think the usual thing to do is to write code to modify the template cache so that it appears that the template has changed, even though it won't look like it's changed in the template editor. That also avoids the style issue and the uninstall issue. I described how to do that in my previous post.

If I still don't understand, maybe someone else can help.
Reply With Quote
  #7  
Old 09-25-2013, 01:49 PM
create365 create365 is offline
 
Join Date: Aug 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That is what I asked. Thank you for your answer, it helped a lot.

Last question, how is it done if there is no template hook to use at this specific place, and there is a need to insert own template variable/show something there?

EDIT:
Okay, found something like:
Code:
$vbulletin->templatecache['threadadmin_editthread'] = str_replace('<div class="blockrow">
				<label for="notes">', '<div>\' . $extrathreadfields . \'</div><div class="blockrow">
			<label for="notes">', $vbulletin->templatecache['threadadmin_editthread']);
So that is what I wanted. Not a nice way, so I wanted to ask if there is other option to achieve this. But apparently there is not.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 02:47 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04715 seconds
  • Memory Usage 2,219KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete