vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Need help injecting code (https://vborg.vbsupport.ru/showthread.php?t=247193)

NathanLedet 07-24-2010 01:00 AM

Need help injecting code
 
Trying to do a str_replace in postbit_legacy and I'm not getting any results - Here's my code.

PHP Code:

    if ($vbulletin->options['legacypostbit']) 
    { 
        
$find compile_template('<vb:if condition="$post[\'postid\'] AND $post[\'threadid\'] AND !$show[\'moderated\']">
                    <a name="post{vb:raw post.postid}" href="{vb:link thread, {vb:raw thread}, {vb:raw pageinfo_post}}#post{vb:raw post.postid}" class="<vb:if condition="$show[\'inlinemod\']">ie</vb:if>postcounter">#{vb:raw post.postcount}</a><a id="postcount{vb:raw post.postid}" name="{vb:raw post.postcount}"></a>
                </vb:if>'
);
        
$add "testing...";
        
$vbulletin->templatecache['postbit_legacy'] = str_replace($find$find $add$vbulletin->templatecache['postbit_legacy']);     
    } 

What it's supposed to be doing is looking for the post number, and then adding my variable onto it.

Any ideas/suggestions?

Thanks :)

Boofo 07-24-2010 01:50 AM

Try this:

Code:

    if ($vbulletin->options['legacypostbit']) 
    { 
        $find = trim(preg_replace('#^\$final_rendered = \'(.*)\';$#s', '\\1', compile_template('<vb:if condition="$post[\'postid\'] AND $post[\'threadid\'] AND !$show[\'moderated\']">
                    <a name="post{vb:raw post.postid}" href="{vb:link thread, {vb:raw thread}, {vb:raw pageinfo_post}}#post{vb:raw post.postid}" class="<vb:if condition="$show[\'inlinemod\']">ie</vb:if>postcounter">#{vb:raw post.postcount}</a><a id="postcount{vb:raw post.postid}" name="{vb:raw post.postcount}"></a>
                </vb:if>')));
        $add = "testing...";
        $vbulletin->templatecache['postbit_legacy'] = str_replace($find, $find . $add, $vbulletin->templatecache['postbit_legacy']);     
    }


NathanLedet 07-24-2010 01:57 AM

1 Attachment(s)
Thanks, but it didn't work for me.

Check out my attachment...what I've circled...between the post counter and the checkbox is where I want to inject that code.

That is posbit_legacy, right?

Boofo 07-24-2010 02:31 AM

Try running the code I gave you in the process_templates_complete hook.

NathanLedet 07-27-2010 05:17 PM

Thanks,

I tried that and got no love. :(

Boofo 07-27-2010 05:30 PM

Okay, try this:

Code:

require_once(DIR . '/includes/adminfunctions_template.php');

$find = trim(preg_replace('#^\$final_rendered = \'(.*)\';$#s', '\\1', compile_template('<vb:if condition="$post[\'postid\'] AND $post[\'threadid\'] AND !$show[\'moderated\']">
                    <a name="post{vb:raw post.postid}" href="{vb:link thread, {vb:raw thread}, {vb:raw pageinfo_post}}#post{vb:raw post.postid}" class="<vb:if condition="$show[\'inlinemod\']">ie</vb:if>postcounter">#{vb:raw post.postcount}</a><a id="postcount{vb:raw post.postid}" name="{vb:raw post.postcount}"></a>
                </vb:if>')));
$replace = trim(preg_replace('#^\$final_rendered = \'(.*)\';$#s', '\\1', compile_template('<vb:if condition="$post[\'postid\'] AND $post[\'threadid\'] AND !$show[\'moderated\']">
                    <a name="post{vb:raw post.postid}" href="{vb:link thread, {vb:raw thread}, {vb:raw pageinfo_post}}#post{vb:raw post.postid}" class="<vb:if condition="$show[\'inlinemod\']">ie</vb:if>postcounter">#{vb:raw post.postcount}</a><a id="postcount{vb:raw post.postid}" name="{vb:raw post.postcount}"></a>
                </vb:if>testing...')));

$vbulletin->templatecache['postbit_legacy'] = str_replace($find, $replace, $vbulletin->templatecache['postbit_legacy']);


NathanLedet 07-27-2010 07:14 PM

Still not showing up.

I echo'd out the variable $find to see what was going on and I get this:

HTML Code:

if ($post['postid'] AND $post['threadid'] AND !$show['moderated']) {
                                        $final_rendered .= '
                    <a name="post' . $post['postid'] . '" href="' . vB_Template_Runtime::linkBuild("thread", $thread, $pageinfo_post) . '#post' . $post['postid'] . '" class="' . ''; if ($show['inlinemod']) {
                                        $final_rendered .= 'ie';
                                } else {
                        $final_rendered .= '';
                }$final_rendered .= '' . 'postcounter"
>
#' . $post['postcount'] . '</a><a id="postcount' . $post['postid'] . '" name="' . $post['postcount'] . '"></a>
                ';
                                } else {
                        $final_rendered .= '';
                }$final_rendered .= '' . '


Boofo 07-27-2010 07:30 PM

What I gave you should have worked.

What are you trying to add and where? Maybe getting the specifics will help.

NathanLedet 07-27-2010 07:46 PM

Quote:

Originally Posted by Boofo (Post 2075461)
What I gave you should have worked.

I know - seems really strange that it isn't :(

Quote:

What are you trying to add and where? Maybe getting the specifics will help.
Thanks.

If you look up to a previous post where I added an attachment, you will see the Post number with the checkbox to the right of it (what's circled)

Right in between the post # and the checkbox, I'm trying to add a hyperlink.

The method I'm trying to use is to avoid going into the postbit_legacy template and manually adding it. By searching for a specific string, and then appending the hyperlink to that string would do the trick...at least, that's what I've learned from viewing other people's mods.

Problem is I haven't found a similar mod that is 4.0 compatible...I see this technique used a lot in 3.x mods

Boofo 07-27-2010 08:07 PM

Yes, the variables make it a little more difficult to do straight-forward string replaces now.

Let me ask you this... does the hyperlink need to go there or can you put it in a different spot?

NathanLedet 07-27-2010 08:13 PM

Quote:

Originally Posted by Boofo (Post 2075491)
Yes, the variables make it a little more difficult to do straight-forward string replaces now.

Let me ask you this... does the hyperlink need to go there or can you put it in a different spot?

I would prefer that it goes there - I am updating a plugin that is only compatible with 3.x - and that's where the link was originally placed.

The hyperlink contains post ID information, so each link will be unique.


All times are GMT. The time now is 05:55 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.01068 seconds
  • Memory Usage 1,754KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete