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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2012, 01:41 AM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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 -->
Now my point that I have a class called <div class="red"> </div>
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>
Below is my replace code, for postbit and postbit_legacy:
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']);
And as you see I only have the options to replace !-- message -->, and so far this is what I know! Now hopefully someone could teach me or explain how to replace all the 6 Rows / Lines or tell me another method to put the divs arround these 6 lines.

THANK YOU VERY MUCH IF YOU COULD HELP ME OUT WITH THIS!
Reply With Quote
  #2  
Old 08-27-2012, 09:32 AM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 -->
With this?
Code:
<div class="red">
<!-- message -->
        <div id="post_message_$post[postid]">
            $ad_location[ad_showthread_firstpost_start]
            $post[message]
        </div>
        <!-- / message -->
 </div>
I don't know how should be on vb3 but try this
PHP Code:
$replace '<!-- message -->';
        
$vbulletin->templatecache['postbit'] = str_replace($replace,'<div class="red">'.$replace,$vbulletin->templatecache['postbit']);
        
$vbulletin->templatecache['postbit_legacy'] = str_replace($replace,'<div class="red">'.$replace,$vbulletin->templatecache['postbit_legacy']);
$replace '<!-- / message -->';
        
$vbulletin->templatecache['postbit'] = str_replace($replace,$replace.'</div>',$vbulletin->templatecache['postbit']);
        
$vbulletin->templatecache['postbit_legacy'] = str_replace($replace,$replace.'</div>',$vbulletin->templatecache['postbit_legacy']); 
Reply With Quote
  #3  
Old 08-27-2012, 01:24 PM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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..
Reply With Quote
  #4  
Old 08-27-2012, 02:16 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're welcome Btw try this
PHP Code:
$replace '<!-- message -->';
       
$vbulletin->templatecache['postbit'] = str_replace($replace,'<div class=\"red\">'.$replace,$vbulletin->templatecache['postbit']);
      
$vbulletin->templatecache['postbit_legacy'] = str_replace($replace,'<div class=\"red\">'.$replace,$vbulletin->templatecache['postbit_legacy']);
$replace '<!-- / message -->';
     
$vbulletin->templatecache['postbit'] = str_replace($replace,$replace.'</div>',$vbulletin->templatecache['postbit']);
      
$vbulletin->templatecache['postbit_legacy'] = str_replace($replace,$replace.'</div>',$vbulletin->templatecache['postbit_legacy']); 
What hook are you using? And what isn't working?
Reply With Quote
  #5  
Old 08-27-2012, 02:36 PM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
So i was thinking instead of REPLACING so many lines, I could maybe only replace the start and the end like I showed in my first POST as an examlpe, If I could simply WRAP the dive arround it it could be better than replacing so many lines..I posted it so you could see what I was talking about, , which did work, but still not done.

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>
The BLUE colored code is the code that I have to REPLACE or WRAP it with the red code arround, with RED. I hope you understood my point... The RED is my DIV or WRAP code, that I wanna wrap arround the BLUE colored... And Orange colored is the code I pasted in my first post!

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!
Reply With Quote
  #6  
Old 08-27-2012, 02:46 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok now i understand what tou're doing (you're making a template for it), so try this code
PHP Code:
        $replace '<!-- message -->
        <div id="post_message_$post[postid]">
            $ad_location[ad_showthread_firstpost_start]
            $post[message]
        </div>
        <!-- / message -->'
;
        
$vbulletin->templatecache['postbit'] = str_replace($replace,fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit']);
        
$vbulletin->templatecache['postbit_legacy'] = str_replace($replace,fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit_legacy']); 

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 -->';
Reply With Quote
  #7  
Old 08-27-2012, 03:42 PM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]
And if it didnt work, then I will try replace 2 of the lines instead:
Code:
            $ad_location[ad_showthread_firstpost_start]
             $post[message]
Scanu it means a lot that you are using your preciouse time to help me and other people on here! I have seen your contribution,.. Thanks a lot mate.. I really appreciate your time and help!
Reply With Quote
  #8  
Old 08-27-2012, 03:59 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
If so try just this
PHP Code:
$vbulletin->templatecache['postbit_legacy'] = str_replace('$post[message]',fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit_legacy']); 
Reply With Quote
Благодарность от:
ChiNa
  #9  
Old 08-27-2012, 07:08 PM
ChiNa ChiNa is offline
 
Join Date: Jul 2012
Posts: 457
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$replace '<!-- message -->';
$vbulletin->templatecache['postbit'] = str_replace('$post[message]',fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit']); 
$vbulletin->templatecache['postbit_legacy'] = str_replace('$post[message]',fetch_template('post_bubble_threads'),$vbulletin->templatecache['postbit_legacy']); 
And ofcourse the CSS on top that you replied me with. Now I will try test it and post a few times to see its fully done,, and hopefully It wont fail on me....

THANK YOU SO MUCH,
I let you know about it when I am done testing!

Big THUMBS up for you brow..
Reply With Quote
  #10  
Old 08-27-2012, 07:47 PM
Scanu's Avatar
Scanu Scanu is offline
 
Join Date: Nov 2010
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$find 'test';
//Is different with
$find 'test       '
This should happen when you find codes with more than one line

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

Oh and also you don't need this anymore
PHP Code:
$replace+=+'<!--+message+-->'
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 04:35 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.08353 seconds
  • Memory Usage 2,310KB
  • Queries Executed 11 (?)
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
  • (10)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete