larina
08-02-2008, 06:10 PM
Hi,
as I don't want to put my advertisement code into the templates after every single update of vbulletin, vba links directory and all such software anymore, I started automatic template editing for this, using plug-ins.
It's a bit of work, but better doing it once than having to edit the templates after every single update over and over again.
The first software I did this is links directory v.3. You can see it in action: http://www.feelinggood24.de/links/ All templates are the original, the google banners are directly taken from the plug-ins I created.
How to do this ...
------------------------------------------------------------
First Step: Create one or more plugin(s) for your banner(s)
Put your banner code you are provided for example by google into a text-file and save it as a php-file, for example "ads468-60.php".
Create a folder at your server called for example "ads".
Upload ads468-60.php into the folder ads.
In admincp choose Plugins & Products - Add New Plugin
Fill the form like this:
Add-on: vBulletin
Hook: global_start
Titel: it's up to you, I choose "Ads 468x60" for this example
Order: 5
PHP-Code:
ob_start();
include('../ads/ads468-60.php');
$ads1 = ob_get_contents();
ob_end_clean();
Aktiv?: YES
Save it.
Take care, that the path to ads468-60.php is set correctly in the code. In this example both folders (ads and forum) exist in the website-root:
www.domain.com/ads/
www.domain.com/forum/
You would need to edit the path to ads468-60.php if you did it otherwise at your website.
Up to here you would be able to put $ads1 into every template you whish to show your banner at your website. This is one good step to the right direction, as you don't need to put the whole banner-code into the templates, but only the variable: $ads1 (You can create more plugins ... $ads2, $ads3, $ads4 to use different banners or banner-sizes, by the way).
But we want to go further, we don't want to add anything anymore into the templates at all. So go on with Step 2:
------------------------------------------------------------
Second Step: Create plugins which load $ads1, $ads2 ... into the templates automatically, without having to touch any templates
Create plugins like that:
In admincp choose Plugins & Products - Add New Plugin
Fill the form like this:
Add-on: vBadvanced Links Directory
Hook: global_start
Titel: it's up to you, I choose titles like "Ads1 - ADV_LINKS top" to know at once which banner at which place it shows
Order: 5
PHP-Code: look below, I'll give you the php-code for every links directory template
Aktiv?: YES
Save it.
Do this for all the links directory templates where banners should be shown. Only the php-code changes for each template as follows:
For ADV_LINKS (main page above random links):
$endif = '") : (""))."';
$ifstart = '".((';
$ifend = ') ? ("';
$newline = chr(13) . chr(10);
$find = $ifstart . '$show[\'randomlinks\']' . $ifend;
$replace = $ifstart . '$show[\'randomlinks\']' . $ifend . '<div align=\"center\">$ads1</div><br />' . $endif;
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
For ADV_LINKS (main page at the bottom):
$find = '<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">';
$replace = '<div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
For ADV_LINKS_ADD_EDIT
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_ADD_EDIT'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_ADD_EDIT']);
For ADV_LINKS_ADD_START
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_ADD_START'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_ADD_START']);
For ADV_LINKS_BROWSELINKS
$find = '<table cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">';
$replace = '<div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_BROWSELINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_BROWSELINKS']);
For ADV_LINKS_REPLY
$find = '$footer';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_REPLY'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_REPLY']);
For ADV_LINKS_REPORT
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_REPORT'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_REPORT']);
For ADV_LINKS_SEARCH
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SEARCH'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SEARCH']);
For ADV_LINKS_SENDTOFRIEND
$find = '$footer';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SENDTOFRIEND'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SENDTOFRIEND']);
For ADV_LINKS_SHOWLINK
$find = '<div class=\"smallfont\" align=\"center\">';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SHOWLINK'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SHOWLINK']);
Well, that's some copy and paste for you :D But done much faster than having to edit all the templates after every single software-update.
You can replace $ads1 in those codes with others ($ads2, $ads3 ...) if you have created more banner-plugins, as described in step 1. So you can define, which banner should be shown in which template.
------------------------------------------------------------
Some words to the code itself, in case you whish to understand it:
The line beginning with $find defines html-code inside the template (also a variable like $footer does work), where you want to add your banner-code. It must be unique, if this appears more than once in the same template, the banner would also appear more than once. So you really have to find a unique place to define $find.
The line beginning with $replace defines what you want to insert (in our case the banner code).
The line beginning with $vbulletin defines the template-name. Note that there are two places in this row where the template-name must be inserted.
That's all.
More tricky is, when the place where you want to insert your banner-code does not have simple html or a variable, but has an if-condition. This is the case in the first plugin: ADV_LINKS (main page above random links):
In the template at this place is written: <if condition="$show['randomlinks']">
So you have to use this code (I copy it here again):
$endif = '") : (""))."';
$ifstart = '".((';
$ifend = ') ? ("';
$newline = chr(13) . chr(10);
$find = $ifstart . '$show[\'randomlinks\']' . $ifend;
$replace = $ifstart . '$show[\'randomlinks\']' . $ifend . '<div align=\"center\">$ads1</div><br />' . $endif;
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
You see the difference? If you would instead want the banner appear above "New links" you would need to change "randomlinks" to "newlinks" in the code.
Well, perhaps this is helpfull for some people. It took me some time to find it out and I am so happy about it (being able to update all my software without having tons of work for template-edits in the future), so that I whish to share it with you.
Surely, if one day a software-update brings complete new templates where the used $find-place does not exist anymore, you would need to find a new place in the templates and adjust the plugins. But usually the updates don't cause such big changes.
And not to forget ... you surely always can set a plugin to Active? NO, if you don't want the banner to be shown there anymore.
larina
as I don't want to put my advertisement code into the templates after every single update of vbulletin, vba links directory and all such software anymore, I started automatic template editing for this, using plug-ins.
It's a bit of work, but better doing it once than having to edit the templates after every single update over and over again.
The first software I did this is links directory v.3. You can see it in action: http://www.feelinggood24.de/links/ All templates are the original, the google banners are directly taken from the plug-ins I created.
How to do this ...
------------------------------------------------------------
First Step: Create one or more plugin(s) for your banner(s)
Put your banner code you are provided for example by google into a text-file and save it as a php-file, for example "ads468-60.php".
Create a folder at your server called for example "ads".
Upload ads468-60.php into the folder ads.
In admincp choose Plugins & Products - Add New Plugin
Fill the form like this:
Add-on: vBulletin
Hook: global_start
Titel: it's up to you, I choose "Ads 468x60" for this example
Order: 5
PHP-Code:
ob_start();
include('../ads/ads468-60.php');
$ads1 = ob_get_contents();
ob_end_clean();
Aktiv?: YES
Save it.
Take care, that the path to ads468-60.php is set correctly in the code. In this example both folders (ads and forum) exist in the website-root:
www.domain.com/ads/
www.domain.com/forum/
You would need to edit the path to ads468-60.php if you did it otherwise at your website.
Up to here you would be able to put $ads1 into every template you whish to show your banner at your website. This is one good step to the right direction, as you don't need to put the whole banner-code into the templates, but only the variable: $ads1 (You can create more plugins ... $ads2, $ads3, $ads4 to use different banners or banner-sizes, by the way).
But we want to go further, we don't want to add anything anymore into the templates at all. So go on with Step 2:
------------------------------------------------------------
Second Step: Create plugins which load $ads1, $ads2 ... into the templates automatically, without having to touch any templates
Create plugins like that:
In admincp choose Plugins & Products - Add New Plugin
Fill the form like this:
Add-on: vBadvanced Links Directory
Hook: global_start
Titel: it's up to you, I choose titles like "Ads1 - ADV_LINKS top" to know at once which banner at which place it shows
Order: 5
PHP-Code: look below, I'll give you the php-code for every links directory template
Aktiv?: YES
Save it.
Do this for all the links directory templates where banners should be shown. Only the php-code changes for each template as follows:
For ADV_LINKS (main page above random links):
$endif = '") : (""))."';
$ifstart = '".((';
$ifend = ') ? ("';
$newline = chr(13) . chr(10);
$find = $ifstart . '$show[\'randomlinks\']' . $ifend;
$replace = $ifstart . '$show[\'randomlinks\']' . $ifend . '<div align=\"center\">$ads1</div><br />' . $endif;
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
For ADV_LINKS (main page at the bottom):
$find = '<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">';
$replace = '<div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
For ADV_LINKS_ADD_EDIT
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_ADD_EDIT'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_ADD_EDIT']);
For ADV_LINKS_ADD_START
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_ADD_START'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_ADD_START']);
For ADV_LINKS_BROWSELINKS
$find = '<table cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">';
$replace = '<div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_BROWSELINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_BROWSELINKS']);
For ADV_LINKS_REPLY
$find = '$footer';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_REPLY'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_REPLY']);
For ADV_LINKS_REPORT
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_REPORT'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_REPORT']);
For ADV_LINKS_SEARCH
$find = '</form>';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SEARCH'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SEARCH']);
For ADV_LINKS_SENDTOFRIEND
$find = '$footer';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SENDTOFRIEND'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SENDTOFRIEND']);
For ADV_LINKS_SHOWLINK
$find = '<div class=\"smallfont\" align=\"center\">';
$replace = '<br /><div align=\"center\">$ads1</div><br />';
$vbulletin->templatecache['ADV_LINKS_SHOWLINK'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS_SHOWLINK']);
Well, that's some copy and paste for you :D But done much faster than having to edit all the templates after every single software-update.
You can replace $ads1 in those codes with others ($ads2, $ads3 ...) if you have created more banner-plugins, as described in step 1. So you can define, which banner should be shown in which template.
------------------------------------------------------------
Some words to the code itself, in case you whish to understand it:
The line beginning with $find defines html-code inside the template (also a variable like $footer does work), where you want to add your banner-code. It must be unique, if this appears more than once in the same template, the banner would also appear more than once. So you really have to find a unique place to define $find.
The line beginning with $replace defines what you want to insert (in our case the banner code).
The line beginning with $vbulletin defines the template-name. Note that there are two places in this row where the template-name must be inserted.
That's all.
More tricky is, when the place where you want to insert your banner-code does not have simple html or a variable, but has an if-condition. This is the case in the first plugin: ADV_LINKS (main page above random links):
In the template at this place is written: <if condition="$show['randomlinks']">
So you have to use this code (I copy it here again):
$endif = '") : (""))."';
$ifstart = '".((';
$ifend = ') ? ("';
$newline = chr(13) . chr(10);
$find = $ifstart . '$show[\'randomlinks\']' . $ifend;
$replace = $ifstart . '$show[\'randomlinks\']' . $ifend . '<div align=\"center\">$ads1</div><br />' . $endif;
$vbulletin->templatecache['ADV_LINKS'] = str_replace($find, $replace . $find, $vbulletin->templatecache['ADV_LINKS']);
You see the difference? If you would instead want the banner appear above "New links" you would need to change "randomlinks" to "newlinks" in the code.
Well, perhaps this is helpfull for some people. It took me some time to find it out and I am so happy about it (being able to update all my software without having tons of work for template-edits in the future), so that I whish to share it with you.
Surely, if one day a software-update brings complete new templates where the used $find-place does not exist anymore, you would need to find a new place in the templates and adjust the plugins. But usually the updates don't cause such big changes.
And not to forget ... you surely always can set a plugin to Active? NO, if you don't want the banner to be shown there anymore.
larina