Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.6 > vBulletin 3.6 Add-ons

Reply
 
Thread Tools
Edit Templates On Fly - A step towards easy-to-install modifications Details »»
Edit Templates On Fly - A step towards easy-to-install modifications
Version: 1.0.0, by Milad Milad is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Category: Administrative and Maintenance Tools - Version: 3.6.5 Rating:
Released: 04-23-2007 Last Update: Never Installs: 11
Uses Plugins
 
No support by the author.

Description:
This will enable modifications writers to edit templates on fly, to make there modifications as easy-to-install as possible. It consists of some functions, which had been written to ease template edits, without any actual editing from the webmasters side,

Installation:
Just import the XML file as a product.
Click install to receive updates and support.

Documentation:
All functions are declared in the hook init_startup, with Execution Order of 1, to be the first plug-in which is being executed in the whole scripts.

Current version contains the following functions:
  • insert_to_template

    Inserts something to a template.

    • return: nothing

    void insert_to_template (string $templatename, string $location, string $addition, [mixed $position = 'after'])

    • string $templatename: The template name to modify (ex: header, footer etc.).
    • string $location: A unique text in the template, where you want to insert your addition. If this text is not unique then the addition will be joined to all instances.
    • string $addition: The addition.
    • mixed $position: has two possible values, after (The default one): to insert the addition after the location, before: to insert the addition before the location.

  • delete_from_template

    Deletes something from a template.

    • return: nothing

    void delete_from_template (string $templatename, string $texttodelete)

    • string $templatename: The template name to delete from (ex: header, footer etc.).
    • string $texttodelete: A unique text in the template to be deleted. If this text is not unique then all instances will be deleted.

  • replace_in_template

    Replaces a text in a template.

    • return: nothing

    void replace_in_template (string $templatename, string $texttofind, string $texttoreplace)

    • string $templatename: The template name to replace in (ex: header, footer etc.).
    • string $texttofind: A unique text in the template to replace. If this text is not unique then all instances will be replaced.
    • string $texttoreplace: The replacing text.

  • print_template

    Print a template in the browser, this helps you to see the working content of a template which is different from what do you see in the templates editor, so you can choose the proper text from a template.

    • return: nothing, but it prints the template in the browser

    void print_template (string $templatename)

    • string $templatename: The template name to print in the browser (ex: header, footer etc.).


Restrictions:
  • You can't modify a template after it had been fetched by fetch_template function.
  • Because no template is cached before the hook global_start, using those functions in following hooks makes nonsense:
    • init_startup
    • style_fetch
    • cache_templates


Examples:
  • Add an image to the header:
    PHP Code:
    replace_in_template('header''&nbsp;''<img src="bla bla bla" alt="" border="0" />'); 
  • Insert a template inside another template, this will reduce the number of eval()s leading to better performance.
    PHP Code:
    insert_to_template('FORUMHOME''<!-- logged-in users -->'$vbulletin->templatecache['sometemplate'], 'before'); 
    Of course the template (sometemplate) must be already cashed.

  • Replace the index.php in the header with ./
    PHP Code:
    replace_in_template('header''href=\"" . $GLOBALS[\'vbulletin\']->options[\'forumhome\'] . ".php" . $GLOBALS[\'vbulletin\']->session->vars[\'sessionurl_q\'] . "\"''href=\"./" . $GLOBALS[\'vbulletin\']->session->vars[\'sessionurl_q\'] . "\"'); 

Notes for coders:
Feel free to use those functions in your mods, and please don't forget to add a dependency for this product (edit_templates_onfly). This will guarantee that every user of your mod will install this modification, so your mod will function properly, this mod will be a centralized method to edit templates, a method which is subject to be developed well, so you can't copy those functions in your mods.
Your suggestions and participations are welcomed.

Change log:
  • April, 19 2007, Initial release 1.0.0, functions: insert_to_template, delete_from_template, replace_in_template and print_template.

Credits:
The first person whom I saw uses this method to edit templates is Zero Tolerance in his vBShout mod, I learned it there.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 04-24-2007, 10:26 AM
nexialys
Guest
 
Posts: n/a
Default

good idea for new functions...

actually you do not need to check function_exists ... there is no such functions in vBulletin anyway...
Reply With Quote
  #3  
Old 04-24-2007, 10:30 AM
valdet's Avatar
valdet valdet is offline
 
Join Date: Feb 2007
Posts: 505
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Installed, waiting for user feedback..
Reply With Quote
  #4  
Old 04-24-2007, 11:25 AM
ZomgStuff ZomgStuff is offline
 
Join Date: Feb 2007
Posts: 469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Will try when I get home.
Reply With Quote
  #5  
Old 04-24-2007, 11:25 AM
magnus's Avatar
magnus magnus is offline
 
Join Date: Apr 2002
Location: Miami, FL
Posts: 1,107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Isn't this just basically renaming str_replace? From a deployment standpoint, I'm not sure a prettier function is worth the cost of a dependency. There's really no actual gain.

However, if you were to create a function that utilizies preg_replace (or ereg_replace, respectively) to help simplify the joys of Regex for some of the greener developers, that would probably be more well adopted.

I'm not knocking it, I think it's great that someone is taking an initiative. I'm just thinking down the road, as a developer, of possible support quandries that could arise when having to explain to end users about dependencies, etc.
Reply With Quote
  #6  
Old 04-24-2007, 11:41 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yes, ist nothing other then str_replace
heres i much better method http://www.vbhacks-germany.org/showthread.php?t=5572
Reply With Quote
  #7  
Old 04-24-2007, 12:06 PM
nexialys
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by ragtek View Post
yes, ist nothing other then str_replace
heres i much better method http://www.vbhacks-germany.org/showthread.php?t=5572
please provide the method, not a link on a site that requires registration...

oh, and btw, this is not a Mod or a Addon... it's just some functions that would help coders in some situations... please DO NOT INSTALL if you don't know what to do with this...
Reply With Quote
  #8  
Old 04-24-2007, 12:36 PM
Bolas's Avatar
Bolas Bolas is offline
 
Join Date: Jan 2003
Location: Venice
Posts: 111
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nexialys View Post
please provide the method, not a link on a site that requires registration...

oh, and btw, this is not a Mod or a Addon... it's just some functions that would help coders in some situations... please DO NOT INSTALL if you don't know what to do with this...
Does vb.org need a section <em>ad hoc</em> for user function or libraries..?
Reply With Quote
  #9  
Old 04-24-2007, 12:47 PM
magnus's Avatar
magnus magnus is offline
 
Join Date: Apr 2002
Location: Miami, FL
Posts: 1,107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's an example from one of my modifications using preg_replace in order to make on-the-fly template changes to all templates -- including modified ones:

PHP Code:
$find '/<tr(.*)>/';
preg_match($find$vbulletin->templatecache['threadbit'], $match);
$vbulletin->templatecache['threadbit'] = preg_replace($find'<tr' $match[1] . ' id=\"vbpostrow_$thread[' . ($vbulletin->options['ajax_firstpost_firstlast'] ? 'lastpostid' 'firstpostid') . ']\">'$vbulletin->templatecache['threadbit']);
unset(
$find$match);
            
$find '/\$thread\[title_editable\](\s*)<div(.*)?>/';
preg_match($find$vbulletin->templatecache['threadbit'], $match);
$vbulletin->templatecache['threadbit'] = preg_replace($find$match[0] . $match[1] . '    <img id=\"vbpostimg_$thread[' . ($vbulletin->options['ajax_firstpost_firstlast'] ? 'lastpostid' 'firstpostid') . ']\" src=\"$stylevar[imgdir_button]/expand.gif\" onclick=\"return vbpost_get($thread[' . ($vbulletin->options['ajax_firstpost_firstlast'] ? 'lastpostid' 'firstpostid') . '])\" onMouseOver=\"this.style.cursor=\'pointer\';\" />'$vbulletin->templatecache['threadbit']);
unset(
$find$match); 
The problem with using str_replace is that most people have a tendency to edit their templates. Thus, the static text you're searching the template for may have been changed. Now, if the text has been removed altogether there's nothing you can do -- however, if say by default you're looking for:
HTML Code:
<div>
And, in the users template it's changed to:
HTML Code:
<div class="alt1">
Your str_replace is NOT going to find it:
PHP Code:
$output str_replace('<div>''<div id="MyID">'$text); 
However, using preg_replace WILL:
PHP Code:
$output preg_replace('/<div(.*)>/''<div id="MyID">'$text); 
In my example code above, I use preg_match to retain the user's variables even after inserting my own:
PHP Code:
preg_match('/<div(.*)>/'$text$match);
$output preg_replace('/<div(.*)>/''<div' $match[1] . ' id=\"MyID\">'$text); 
Reply With Quote
  #10  
Old 04-24-2007, 02:51 PM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nexialys View Post
please provide the method, not a link on a site that requires registration...

oh, and btw, this is not a Mod or a Addon... it's just some functions that would help coders in some situations... please DO NOT INSTALL if you don't know what to do with this...
it changes direkt the template on hack install or you change it if it isnt available
its not on the fly, it changes on the hack install, or on your change(you have a field template change in de acp)
there you can set a search string and a change string....
like this method here, but not on fly...
sorry for the bad english, i hope i helped
Reply With Quote
Reply

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

Forum Jump


All times are GMT. The time now is 06:17 AM.


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.05713 seconds
  • Memory Usage 2,324KB
  • Queries Executed 23 (?)
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
  • (2)bbcode_html
  • (7)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (8)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete