The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How to use the "$replace" to replace 6 lines?
Hi everyone. I was making one of my mods to a product last night, called PostBubble, which showes the post in postbit and legacy inside a Bubble or Box, and after many hours I managed to make it, but found out that my code is only replacing 1 line! I had to ask to remove my thread again, I have only learned replacing from 1 line, to replace. And the code that I have to replace, has 6 Rows / Lines!
And even I replace that 1 line, the code appears twice in my postbit Below you see the lines that I have to replace: Code:
<!-- message --> <div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message --> And I am trying to wrap 6 lines with DIVs , so it looks like this: Code:
<div class="red"> <!-- message --> <div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message --> </div> Code:
$replace = '<!-- message -->'; $vbulletin->templatecache['postbit'] = str_replace($replace,$replace.fetch_template('MYCODEHERE'),$vbulletin->templatecache['postbit']); $vbulletin->templatecache['postbit_legacy'] = str_replace($replace,$replace.fetch_template('MYCODEHERE'),$vbulletin->templatecache['postbit_legacy']); THANK YOU VERY MUCH IF YOU COULD HELP ME OUT WITH THIS! |
#2
|
||||
|
||||
So you're trying to replace this
Code:
<!-- message --> <div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message --> Code:
<div class="red"> <!-- message --> <div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message --> </div> PHP Code:
|
#3
|
|||
|
|||
Thank you Scanu, I gave it a shot, But did not work for my vB3, as you can see I use the fetch:
fetch_template('MYCODEHERE') and it seems not to fix it, but how to put this inside along the replace codes? But Even if it did not work on vB3, Then I could always get use of it on vB 4.. Thanks a lot mate for all the help you been provided.. |
#4
|
||||
|
||||
You're welcome Btw try this
PHP Code:
|
#5
|
|||
|
|||
Hi Scanu, After changing the DIV it suddenly worked, but I have now more than 6 lines to replace the code with.. As I said I wanna replace 6 lines with other 6 lines.. I wished it was easy as it sounds, but good news is it worked.
Its showing up 2 times, One inside POSTBUBBLE and one as normal. Like the image below, so I had to figure out what Its because I only replace the FIRST line, with the FULL CODE! And the full code is already in postbit.. and i am adding 1 more with my product! This is why. Here is image of my finished PRODUCT: As you can see it did work now but showing 2 times because of I only replace the first line.. Now there are 2 exact post in my postbit, and I realised I was only replacing 1 line with the full postbit code. And the original is still there. HERE IS THE DIV OR WRAP CODE: Code:
<div id="1" style="float:left; z-index: 1; position: Absolute;"> <br><img src="images/tip/aqua.png"> </div> <div style="z-index: 25; padding: 11px;"> <fieldset style="background: #ffffff; border:2px solid #54DFFE; margin:1px 3px 3px 1px; padding:7px; -moz-border-radius:8px; box-shadow: 0 0 1em #b6b6b6; -webkit-border-radius:8px; position: relative;"> MY POSTBIT CODE SHOULD BE IN HERE </fieldset> Here is the large example of the finished product today: Code:
<template name="post_bubble_threads" templatetype="template" date="1516171819" username="ChiNaMan" version="1.0"><![CDATA[ <div id="1" style="float:left; z-index: 1; position: Absolute;"> <br><img src="images/tip/aqua.png"> </div> <div style="z-index: 25; padding: 11px;"> <fieldset style="background: #ffffff; border:2px solid #54DFFE; margin:1px 3px 3px 1px; padding:7px; -moz-border-radius:8px; box-shadow: 0 0 1em #b6b6b6; -webkit-border-radius:8px; position: relative;"><!-- message --> <div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message --> </div></fieldset>]]></template> </templates> <plugins> <plugin active="1" executionorder="5"> <title>Post Bubble Cache</title> <hookname>cache_templates</hookname> <phpcode><![CDATA[if ($vbulletin->options['post_bubble_on']) { $globaltemplates = array_merge($globaltemplates, array('post_bubble_threads')); }]]></phpcode> </plugin> <plugin active="1" executionorder="5"> <title>Post Bubble</title> <hookname>global_start</hookname> <phpcode><![CDATA[if ($vbulletin->options['post_bubble_on']) { $replace = '<!-- message -->'; $vbulletin->templatecache['postbit'] = str_replace($replace,$replace.fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit']); $vbulletin->templatecache['postbit_legacy'] = str_replace($replace,$replace.fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit_legacy']); } ]]></phpcode> </plugin> </plugins> Now I am thinking about 2 Options, 1 option to REPLACE it with another CODE, or simply use the replace to wrap the code! And I am asking you to please take a look and tell me what is best. To use the replace and replace it all with new code, or only use the replace to replace the START and the END.. (Like Wrap it) Thats it, waiting for your reply and advice about how to REPLACE or WRAP the code. Cant wait to hear from you with this one! |
#6
|
||||
|
||||
Ok now i understand what tou're doing (you're making a template for it), so try this code
PHP Code:
And if it isn't working you can try this as replace variable $replace = '<!-- message --> <div id=\"post_message_$post[postid]\"> $ad_location[ad_showthread_firstpost_start] $post[message] </div> <!-- / message -->'; |
#7
|
|||
|
|||
Hi Scanu, I think your teori was perfect, but did not work, I tried both methods, it did a clean install, but nothing showes up in my Posbit or Posbit_Legacy as result! Else you did amazing...
I think your Teori right about the replacing, I was thinking what I only replace 2 or 3 important lines, Again, I wanna replace the 3 important lines from the code: Code:
<div id="post_message_$post[postid]"> $ad_location[ad_showthread_firstpost_start] $post[message] Code:
$ad_location[ad_showthread_firstpost_start] $post[message] |
#8
|
||||
|
||||
It's the least I can do, many users helped me too. I think the replace isn't working because there are variables in the code you want to replace, i figure it out in vb4 but i don't know a proper way in vb3' Does your css code work if you wrap just $post[message]? I mean would tis work?
Code:
<div id="1" style="float:left; z-index: 1; position: Absolute;"> <br><img src="images/tip/aqua.png"> </div> <div style="z-index: 25; padding: 11px;"> <fieldset style="background: #ffffff; border:2px solid #54DFFE; margin:1px 3px 3px 1px; padding:7px; -moz-border-radius:8px; box-shadow: 0 0 1em #b6b6b6; -webkit-border-radius:8px; position: relative;"> $post[message] </div></fieldset> PHP Code:
|
Благодарность от: | ||
ChiNa |
#9
|
|||
|
|||
Sorry for late reply Scanu, I was at work, was on from my phone but couldnt connect..
And Guess what? Check The Image: (It Finally Worked with your last reply and codes added) Wow , It finally worked PERFECT! Exactly as the last code you gave me in your last reply here... I only used the $post[message] as you said, and just like that I copied your code and made one for Postbit too, Here is the example of what I used: PHP Code:
THANK YOU SO MUCH, I let you know about it when I am done testing! Big THUMBS up for you brow.. |
#10
|
||||
|
||||
You're welcome! I think i know what the problem was, this is something that usually happens with str_replace, in the find string you need to copy everything as it is
Example PHP Code:
--------------- Added [DATE]1346100555[/DATE] at [TIME]1346100555[/TIME] --------------- Oh and also you don't need this anymore PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|