vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Find Replace into Template PlugIn Code (https://vborg.vbsupport.ru/showthread.php?t=264690)

SorentoUltimate 06-03-2011 11:32 PM

Find Replace into Template PlugIn Code
 
Hi all,

in vb3 i use that code to make changes to templates (parse_templates hook)

PHP Code:

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

    
$string_fnd compile_template('<if condition="$show[\'contactus\']"><a href="$vboptions[contactuslink]" rel="nofollow" accesskey="9">$vbphrase[contact_us]</a> -</if>'); 
    
$string_add fetch_template('terrabyter_about_us_footer_link'); 
    
$vbulletin->templatecache['footer'] = str_replace($string_fnd$string_add "\r\n" $string_fnd$vbulletin->templatecache['footer']); 

    unset(
$string_fnd$string_add); 

how i do the same in vb4 ?

Thanks in Advance
SorentoUltimate

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

can someone help me on the above?

i need to make automatic template edits into plugins with code.

kh99 06-04-2011 04:15 PM

Have you tried this in vb4? I haven't tried it but all the same functions/variables seem to be there.

SorentoUltimate 06-04-2011 04:32 PM

i try that code:
PHP Code:

      $find_string  fetch_template('greeklish2greek_SHOWTHREAD_fnd');
      
$repl_string  fetch_template('greeklish2greek_SHOWTHREAD_rpl');
      
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find_string$repl_string$vbulletin->templatecache['SHOWTHREAD']); 

but not work, with error:

Quote:

Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: greeklish2greek_SHOWTHREAD_fnd in [path]/includes/functions.php on line 4097

Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: greeklish2greek_SHOWTHREAD_rpl in [path]/includes/functions.php on line 4097

TheLastSuperman 06-04-2011 05:08 PM

Lynne has a modification here you should view the .xml and see where your going wrong, will help you visualize how it's done in vB4 ;).

https://vborg.vbsupport.ru/showthread.php?t=229290

SorentoUltimate 06-04-2011 09:30 PM

Hi again,

Here are the Templates and Plugin Code to help me solve the problem :

a.Template "greeklish2greek_SHOWTHREAD_fnd"

Code:

    <div class="blockfoot actionbuttons">
        <div class="group">
            <span id="qr_posting_msg" class="hidden">
                <img src="{vb:stylevar imgdir_misc}/progress.gif" alt="{vb:rawphrase posting_quick_reply_please_wait}" />&nbsp;<strong>{vb:rawphrase posting_quick_reply_please_wait}</strong>
            </span>
            <vb:if condition="$show['fb_publishcheckbox']">
                {vb:raw fbpublishcheckbox}
            </vb:if>
            <input type="submit" class="button" value="{vb:rawphrase post_quick_reply}" accesskey="s" title="(Alt + S)" name="sbutton" tabindex="1" id="qr_submit" onclick="clickedelm = this.value" />
            <input type="submit" class="button" value="{vb:rawphrase go_advanced}" accesskey="x" title="(Alt + X)" name="preview" tabindex="1" id="qr_preview" onclick="clickedelm = this.value" />
            <input type="reset" id="qr_cancelbutton" class="button" style="display:none;" value="{vb:rawphrase cancel}" accesskey="c" title="(Alt + C)" name="cancel" tabindex="4" onclick="qr_reset();" />
        </div>
    </div>

_

b.Template "greeklish2greek_SHOWTHREAD_rpl"

Code:

    <div class="blockfoot actionbuttons">
        <div class="group">
            <span id="qr_posting_msg" class="hidden">
                <img src="{vb:stylevar imgdir_misc}/progress.gif" alt="{vb:rawphrase posting_quick_reply_please_wait}" />&nbsp;<strong>{vb:rawphrase posting_quick_reply_please_wait}</strong>
            </span>
            <vb:if condition="$show['fb_publishcheckbox']">
                {vb:raw fbpublishcheckbox}
            </vb:if>
            <input type="button" class="button" value="{vb:rawphrase greeklish2greek}" accesskey="g" title="(Alt + G)" name="greeklish2greek" tabindex="1" onClick="greeklish2greek_message('vbform', 'quick_reply', '2');" />
            <input type="submit" class="button" value="{vb:rawphrase post_quick_reply}" accesskey="s" title="(Alt + S)" name="sbutton" tabindex="1" id="qr_submit" onclick="clickedelm = this.value" />
            <input type="submit" class="button" value="{vb:rawphrase go_advanced}" accesskey="x" title="(Alt + X)" name="preview" tabindex="1" id="qr_preview" onclick="clickedelm = this.value" />
            <input type="reset" id="qr_cancelbutton" class="button" style="display:none;" value="{vb:rawphrase cancel}" accesskey="c" title="(Alt + C)" name="cancel" tabindex="4" onclick="qr_reset();" />
        </div>
    </div>

_


c.Part of Template "SHOWTHREAD"

Code:

.....
<vb:if condition="$show['quickreply']">
<div id="qr_defaultcontainer" class="blockfoot floatcontainer qrcontainer<vb:if condition="$show['qr_require_click']"> qr_require_click</vb:if>">
<form class="vbform" name="quick_reply" id="quick_reply" method="post" action="{vb:raw $vboptions.vbforum_url}{vb:if "$vboptions['vbforum_url']", '/', ''}newreply.php?do=postreply&amp;t={vb:raw threadid}"
    onsubmit="return qr_prepare_submit(this, {vb:raw vboptions.postminchars});">
    <div id="qr_error_tbody" class="block errorblock hidden">
        <h3 class="blockhead">{vb:rawphrase errors}</h3>
        <div class="blockbody formcontrols">
            <h3 class="blocksubhead">{vb:rawphrase errors_occured_when_submitted}</h3>
            <div class="blockrow error" id="qr_error_td"></div>
        </div>
        <div class="blockfoot actionbuttons"><div class="group"><a href="javascript://" class="textcontrol" onclick="return qr_hide_errors()">{vb:rawphrase okay}</a></div></div>
    </div>

    <div class="fullwidth"><h3 id="quickreply_title" class="blockhead"><img src="{vb:stylevar imgdir_button}/reply_40b.png" alt="{vb:rawphrase quick_reply}" style="float:{vb:stylevar left};padding-{vb:stylevar right}:{vb:stylevar padding}"/> {vb:rawphrase quick_reply}<a name="quickreply"></a> <img style="display:none" id="progress_newreplylink_bottom" src="{vb:stylevar imgdir_misc}/progress.gif"  alt="" /></h3></div>
    <div class="wysiwyg_block">
    <div class="blockbody formcontrols">
        <div class="blockrow">
            {vb:raw messagearea}
        </div>
        <vb:if condition="$bbuserinfo['signature']">
        <div class="blockrow">
            <ul class="checkradio group">
                <li><label for="cb_signature">
                    <input type="checkbox" name="signature" id="cb_signature" value="1" checked="checked" tabindex="1" />
                    {vb:rawphrase show_your_signature}
                </label></li>
            </ul>
        </div>
        </vb:if>
        <vb:if condition="$show['openclose']">
        <div class="openclose">
            <ul class="checkradio">
                <li><label for="cb_openclose">
                    <input type="checkbox" name="openclose" id="cb_openclose" value="1" tabindex="1" />
                    <vb:if condition="$show['closethread']">{vb:rawphrase close_this_thread}<vb:else />{vb:rawphrase reopen_this_thread}</vb:if>
                </label></li>
            </ul>
        </div>
        </vb:if>
    </div>

    <div class="blockfoot actionbuttons">
        <div class="group">
            <span id="qr_posting_msg" class="hidden">
                <img src="{vb:stylevar imgdir_misc}/progress.gif" alt="{vb:rawphrase posting_quick_reply_please_wait}" />&nbsp;<strong>{vb:rawphrase posting_quick_reply_please_wait}</strong>
            </span>
            <vb:if condition="$show['fb_publishcheckbox']">
                {vb:raw fbpublishcheckbox}
            </vb:if>
            <input type="submit" class="button" value="{vb:rawphrase post_quick_reply}" accesskey="s" title="(Alt + S)" name="sbutton" tabindex="1" id="qr_submit" onclick="clickedelm = this.value" />
            <input type="submit" class="button" value="{vb:rawphrase go_advanced}" accesskey="x" title="(Alt + X)" name="preview" tabindex="1" id="qr_preview" onclick="clickedelm = this.value" />
            <input type="reset" id="qr_cancelbutton" class="button" style="display:none;" value="{vb:rawphrase cancel}" accesskey="c" title="(Alt + C)" name="cancel" tabindex="4" onclick="qr_reset();" />
        </div>
    </div>

    </div>
    <input type="hidden" name="fromquickreply" value="1" />
    <input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
    <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
    <input type="hidden" name="do" value="postreply" />
    <input type="hidden" name="t" value="{vb:raw threadid}" id="qr_threadid" />
    <input type="hidden" name="p" value="{vb:raw qrpostid}" id="qr_postid" />
    <input type="hidden" name="specifiedpost" value="0" id="qr_specifiedpost" />
    <input type="hidden" name="parseurl" value="1" />
    <input type="hidden" name="loggedinuser" value="{vb:raw bbuserinfo.userid}" />
    <input type="hidden" name="posthash" value="" />
    <input type="hidden" name="poststarttime" value="" />

<vb:if condition="!is_browser('ie') AND $show['wysiwyg']">
    <!-- Mozilla work around for focusing on QR in WYSIWYG mode -->
    <div id="qr_scroll"></div>
</vb:if>

</form>
</div>

</vb:if>
.....

_

d.Plugin "parse_templates" Code

Code:

$find_string = vB_Template::fetch_template_raw('greeklish2greek_SHOWTHREAD_fnd');
$repl_string = vB_Template::fetch_template_raw('greeklish2greek_SHOWTHREAD_rpl');
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find_string, $repl_string, $vbulletin->templatecache['SHOWTHREAD']);

_

but not work, i need your help !!!!

SorentoUltimate 06-06-2011 10:03 AM

any help???????????

Boofo 06-06-2011 12:37 PM

<a href="https://vborg.vbsupport.ru/showthread.php?p=2204110#post2204110" target="_blank">https://vborg.vbsupport.ru/showt...10#post2204110</a>

SorentoUltimate 06-06-2011 02:04 PM

Hi Boofo,

i try that but not work

Code:

      $find_string = '';
      $repl_string = '';

      $parser          = new vB_TemplateParser(vB_Template::fetch_template_raw('greeklish2greek_SHOWTHREAD_fnd'));
      $parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
      $find_string    = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

      $parser          = new vB_TemplateParser(vB_Template::fetch_template_raw('greeklish2greek_SHOWTHREAD_rpl'));
      $parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
      $repl_string    = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
     
      $vbulletin->templatecache['SHOWTHREAD'] = str_replace($find_string, $repl_string, $vbulletin->templatecache['SHOWTHREAD']);

_

any idea what i'm doing wrong?

Boofo 06-06-2011 02:13 PM

Use the code EXACTLY as I posted. You can't change the position and syntax of the lines to what you want them to be. Just add your code to find and replace where I showed you in red. The template name is all you should be changing.


All times are GMT. The time now is 04:46 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.01156 seconds
  • Memory Usage 1,789KB
  • 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
  • (5)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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