Topic: Str_Replace question for a hook in footer

this is in footer.php ....

// End the transaction
$forum_db->end_transaction();

?>
    <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/">PunBB</a>'.($forum_config['o_show_version'] == '1' ? ' '.$forum_config['o_cur_version'] : '')); ?></p>
<?php
($hook = get_hook('ft_about_end')) ? eval($hook) : null;

$tpl_temp = forum_trim(ob_get_contents());
$tpl_main = str_replace('<!-- forum_about -->', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <!-- forum_about -->

I want to replace with an extension that puts image (with link) instead of text - just so in future I can add anyones website logo....

    <hooks>
        <hook id="ft_about_end"><![CDATA[
?>
    <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/"><img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>')?>
</p><?php
    
        ]]></hook>
    </hooks>

it is however only ADDING not replacing (it does work) - shows image and everything right, but ADD not replaced... sad

I looked at str_replace command - but I don't know which of first code block above needs to go in it... this isnt working:

    str_replace (sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/">PunBB</a>'.($forum_config['o_show_version'] == '1' ? ' '.$forum_config['o_cur_version'] : '')), sprintf($lang_common['Powered by'], '<a href="http://punbb.org"><img src="'.$ext_info['path'].'/img/punbb.png" alt="FluxBB" width="16" height="16" border="0"></a>'))

Re: Str_Replace question for a hook in footer

<p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/">PunBB</a>'.($forum_config['o_show_version'] == '1' ? ' '.$forum_config['o_cur_version'] : '')); ?></p>

  <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/"><img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>')?>
</p>

in a nutshell i want to replace red with green smile

Re: Str_Replace question for a hook in footer

I think you can change it using JavaScript and "copyright" id.

Or maybe you can replace this using previous hook. Not sure if it will work.

footer.php

($hook = get_hook('ft_about_pre_copyright')) ? eval($hook) : null;

// End the transaction
$forum_db->end_transaction();

?>
    <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/">PunBB</a>'.($forum_config['o_show_version'] == '1' ? ' '.$forum_config['o_cur_version'] : '')); ?></p>
<?php
($hook = get_hook('ft_about_end')) ? eval($hook) : null;

manifest.xml

<hooks>

    <hook id="ft_about_pre_copyright"><![CDATA[
$forum_db->end_transaction();
if (true)
{
?>
    <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/"><img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>')?></p>
<?php
}
else
{
    ]]></hook>

    <hook id="ft_about_end"><![CDATA[
}
    ]]></hook>

</hooks>
YonasH's repository + Extensions Directory = PunBB Extensions Online Library (in progress....)

Away. I will be back soon.

Re: Str_Replace question for a hook in footer

hm thats not working my end. you dont know if I can use  str_replace  to just overwrite the footer (red) ?

Re: Str_Replace question for a hook in footer

The footer is already in the buffer. You need to get the buffer, clear it, and re-send the footer with your changes made.

$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace('>PunBB<', '<img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>', $tpl_temp);

6 (edited by KeyDog 2009-01-05 15:31)

Re: Str_Replace question for a hook in footer

so you'd replace this : (that shows the png and powered by next to powered by punbb )

    <hooks>
        <hook id="ft_about_end"><![CDATA[
?>
    <p id="copyright"><?php echo sprintf($lang_common['Powered by'], '<a href="http://punbb.informer.com/"><img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>')?>
</p><?php
    
        ]]></hook>
    </hooks>

with this?

    <hooks>
        <hook id="ft_about_end"><![CDATA[

$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace('>PunBB<', '<img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>', $tpl_temp);    
        ]]></hook>
    </hooks>

don't leave anything out... smile step by step

thank you

Re: Str_Replace question for a hook in footer

Yep.

8 (edited by KeyDog 2009-01-06 10:58)

Re: Str_Replace question for a hook in footer

back again neutral
trying to replace the powered by  with design by in addition to the initial working code
my question : how do i seperate the $lang_common['Powered by']  from the '<a href....>' ?
do i do so with a ,    or  what?  that will mess up the str_replace i guess
input welcome

  <hook id="ft_about_end"><![CDATA[

$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace($lang_common['Powered by']'<a href="http://punbb.informer.com/">PunBB</a>', $lang_common['Design by'] '<a href="http://keydogbb.info"><img src="'.$ext_info['path'].'/img/info.png" alt="PunBB" width="16" height="16" border="0"></a>', $tpl_temp);   
        ]]></hook>

PS: i have added in my lang_common design by .... not that you think that's causing error

idea will be at end to have extension that says:

Powered by []   
Design by []

or something like  Code:[] Design:[]

for the moment i'm just trying to get the powered by replaced though

thanks.

Re: Str_Replace question for a hook in footer

echo str_replace(array('>PunBB<', $lang_common['Powered by']), array('<img src="'.$ext_info['path'].'/img/punbb.png" alt="PunBB" width="16" height="16" border="0"></a>', $lang_common['Design by']), $tpl_temp);

10

Re: Str_Replace question for a hook in footer

thx star! big_smile
bestest fastest coder out there big_smile

11

Re: Str_Replace question for a hook in footer

$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace(array($lang_common['Powered by'],'<a href="http://punbb.informer.com/">PunBB</a>'), array($lang_common['Design by'],'<a href="http://keydogbb.info"><img src="'.$ext_info['path'].'/img/info.png" alt="PunBB" width="16" height="16" border="0"/></a>'), $tpl_temp);


any idea why the above is not replacing the powered by?
it just keeps using the powered by instead of design by.....

does the forum_trim need to take account of the array differently?

stuck...

12 (edited by User33 2009-01-06 16:46)

Re: Str_Replace question for a hook in footer

ob_end_clean();
?>
<p id="copyright">Whatever you want on the copyright...</p>
<?php

13

Re: Str_Replace question for a hook in footer

<hook id="ft_about_end"><![CDATA[


ob_end_clean();
?>
    <p id="copyright"><?php echo sprintf($lang_common['Design by'],'<a href="http://keydogbb.info"><img src="'.$ext_info['path'].'/img/info.png" alt="PunBB" width="16" height="16" border="0"/></a>'.($forum_config['o_show_version'] == '1' ? ' '.$forum_config['o_cur_version'] : '')); ?></p>
<?php   
        ]]></hook>

=   Notice: Undefined index: Design by in      .......... footer.php(46)     line 12

14

Re: Str_Replace question for a hook in footer

Undefined index: Design by

'Design by' doesn't exist...

15

Re: Str_Replace question for a hook in footer

'Item info plural'            =>    '%s [ %s to %s of %s ]', // e.g. Topics [ 10 to 20 of 30 ]
'Info separator'            =>    ' ', // e.g. 1 Page | 10 Topics
'Powered by'                =>    'Powered by <strong>%s</strong>',
'Design by'                    =>    'Design by',

can I not add it like the way I did above to the common.php   ?

16 (edited by User33 2009-01-06 17:25)

Re: Str_Replace question for a hook in footer

It's not finding it...

17 (edited by KeyDog 2009-01-06 17:31)

Re: Str_Replace question for a hook in footer

nah, tried that now aswell in addition to <strong>%a</strong>    and now   just   %s additionally.
always same error...

but if i change powered by  .... it always immediately reflects change - so i know i'm in right file and uploading right one.


EDIT: also if i change powered by    'powered by <....>'   to  'design by.... it reflects change - but not the additional line   starting with 'design by' ...

18

Re: Str_Replace question for a hook in footer

Maybe I'm not clearing buffer properly?
At the moment it's telling me it can't find 'Design By'  line I added to lang  common.php - which is strange, as I am 100% sure it is in there and that I am uploading correct file.

If I change

'Powered by'    -->   'Powered by ....'

to

'Powered by'    --->  'Design by ....'

it immediately picks up the change in my footer output

but if I try calling on

'Design by'       --->  'Design by ... '

I get error message

Index Design by      not found etc.....

I don't get it.

Can you add additional things to lang common.php like that or am I missing something?

And the PHP Manual which I looked at in this case for this function doesn't do much to clarify taken into account buffer etc.

If you or other dev, coder can spot problem I' appreciate....


Thanks.

19

Re: Str_Replace question for a hook in footer

if(!isset($lang_common['Design by'])) die("It's not set");

Put that somewhere on the hook.

20

Re: Str_Replace question for a hook in footer

My extension code 1:1 - aswell as my common.php

no change.

21

Re: Str_Replace question for a hook in footer

Does it say "It's not set" somewhere when you try it?

22

Re: Str_Replace question for a hook in footer

no nothing. shows clean page.

23

Re: Str_Replace question for a hook in footer

Then just try setting

$lang_common['Design by'] = 'Design by';

outside the file. (in your hook)

24

Re: Str_Replace question for a hook in footer

<hooks>
        <hook id="ft_about_end"><![CDATA[

$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace(array($lang_common['Powered by'],'<a href="http://punbb.informer.com/">PunBB</a>'), array($lang_common['Design by'],'<a href="http://keydogbb.info"><img src="'.$ext_info['path'].'/img/info.png" alt="PunBB" width="16" height="16" border="0"/></a>'), $tpl_temp);


if(!isset($lang_common['Design by'])) die("It's not set");
$lang_common['Design by'] = 'Design by';
        ]]></hook>
    </hooks>

tried this no change. image is displayed correctly. but text is left unchanged from outset.

25

Re: Str_Replace question for a hook in footer

        <hook id="ft_about_end"><![CDATA[
$lang_common['Design by'] = 'Design by';
$tpl_temp = forum_trim(ob_get_contents());
ob_end_clean();
echo str_replace(array($lang_common['Powered by'],'<a href="http://punbb.informer.com/">PunBB</a>'), array($lang_common['Design by'],'<a href="http://keydogbb.info"><img src="'.$ext_info['path'].'/img/info.png" alt="PunBB" width="16" height="16" border="0"/></a>'), $tpl_temp);
        ]]></hook>