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

Reply
 
Thread Tools Display Modes
  #11  
Old 04-14-2016, 12:44 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
...why does this method not work?

Code:
<head> = str_replace('head', 'head class="test"', <head>);
Because "<head>" is not a string variable.
Reply With Quote
  #12  
Old 04-14-2016, 01:04 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmmm, im no good with preg replaces, but shouldn't something like this work, on either global or parse templates.

this is not working
Code:
$find = preg_replace("/<head[^>]>/i", "TEST", $find);
Reply With Quote
  #13  
Old 04-14-2016, 01:23 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
hmmm, im no good with preg replaces, but shouldn't something like this work, on either global or parse templates.

this is not working
Code:
$find = preg_replace("/<head[^>]>/i", "TEST", $find);
You don't need to use regex here with preg_replace(), but what you need is to have the template code stored as a string, and then just use str_replace() on the string.
Reply With Quote
  #14  
Old 04-14-2016, 01:40 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What exactly are you trying to do because the head tag does not take any attributes, so there's literally nothing you can change with the actual tag itself. The contents can be changed but as I said that's easily accomplished with template hooks.
Reply With Quote
  #15  
Old 04-14-2016, 02:09 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

im trying to do something along the lines of (again not the code I'm actually using)
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
I was just using the head tag as filler, everything I'm trying to accomplish is the same concept and would be achieved the same way regardless.

so in the end i can replace a tag across multiple templates.

so think of it this way since instead of head, everything on here says body.

i want to add an onload event to all body tags, in every template, without having to say every template.

so we do something like this for every template there is a body tag:
Code:
$find = '<body>';
$replace = '<body onload="myFunction()">';
$vbulletin->templatecache['FORUMHOME'] = str_replace($find,$replace,$vbulletin->templatecache['FORUMHOME']);
$vbulletin->templatecache['showthread'] = str_replace($find,$replace,$vbulletin->templatecache['showthread']);
etc...
i'm simply asking is there a way to do this globally so you dont have to specify every template.

this would be an example of it, but this doesnt work:
Code:
$find = '<body>';
$replace = '<body onload="myFunction()">';
$find = str_replace($find, $replace, $find);
Reply With Quote
  #16  
Old 04-14-2016, 02:48 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What I would do to add an onload event to the body element on all pages is in a plugin hooked to "parse_templates" with the following:

PHP Code:
$spacer_close .= '<script>
function myFunction()
{
    alert("Hello!");
}
var el = document.getElementsByTagName("html")[0];
el.innerHTML = el.innerHTML.replace("<body>", "<body onload=\"myFunction();\">");
</script>'

However, there are better ways to add an event to a document, I am just trying to follow the example you gave.
Reply With Quote
  #17  
Old 04-14-2016, 03:06 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

mark thanks for always being around to help, but I feel like I'm wasting your time =/

I was only throwing another example to what could be achieved with the end result I'm looking for.

so lets look at what I'm intending on doing:
In every template that has a <html> tag, i want to add some attributes.

so lets say for just a one attribute example this is exactly what i want to do.

across every single template:
Code:
$find = '<html>';
$replace = '<html lang="en">';
$find = str_replace($find, $replace, $find);
we've already established that wont work,
but the end result should be something like this if it's achievable.

instead of doing:
Code:
$find = '<html>';
$replace = '<html lang="en">';
$vbulletin->templatecache['Template1'] = str_replace($find,$replace,$vbulletin->templatecache['Template1']);
$vbulletin->templatecache['Template2'] = str_replace($find,$replace,$vbulletin->templatecache['Template2']);
$vbulletin->templatecache['Template3'] = str_replace($find,$replace,$vbulletin->templatecache['Template3']);
$vbulletin->templatecache['Template4'] = str_replace($find,$replace,$vbulletin->templatecache['Template4']);
$vbulletin->templatecache['Template5'] = str_replace($find,$replace,$vbulletin->templatecache['Template5']);
$vbulletin->templatecache['Template6'] = str_replace($find,$replace,$vbulletin->templatecache['Template6']);
$vbulletin->templatecache['Template7'] = str_replace($find,$replace,$vbulletin->templatecache['Template7']);
etc....
Reply With Quote
  #18  
Old 04-14-2016, 06:06 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This works on my vB 4.2.x dev site...a plugin hooked at "parse_templates":

PHP Code:
$t_arr $vbulletin->templatecache;
$t_keys array_keys($t_arr);
$count count($t_keys);

for (
$n 0$n $count$n++)
{
    if (
strpos($t_arr[$t_keys[$n]], '<body') !== false)
    {
        
$vbulletin->templatecache[$t_keys[$n]] = str_replace('<body''<body name="myName"'$vbulletin->templatecache[$t_keys[$n]]);
    }

Reply With Quote
  #19  
Old 04-14-2016, 07:00 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

causes everything to go white with no page source lol
Reply With Quote
  #20  
Old 04-14-2016, 09:22 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
causes everything to go white with no page source lol
Yeah, I got the same on my vB 3.8.9 dev site, but I thought it worth a shot since it works with vB 4.2.x.

--------------- Added [DATE]1460691040[/DATE] at [TIME]1460691040[/TIME] ---------------

This works on my vB 3.8.9:

PHP Code:
$t_arr $vbulletin->templatecache;
$t_keys array_keys($t_arr);
$count count($t_keys);

for (
$n 0$n $count$n++)
{
    if (
strpos($t_arr[$t_keys[$n]], '<body') !== false)
    {
        
$vbulletin->templatecache[$t_keys[$n]] = str_replace("<body""<body name='myName'"$vbulletin->templatecache[$t_keys[$n]]);
    }

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 12:26 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.12911 seconds
  • Memory Usage 2,285KB
  • 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
  • (7)bbcode_code
  • (1)bbcode_html
  • (3)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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