vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Insert HTML or (pre-processed!) PHP file above specific forum (https://vborg.vbsupport.ru/showthread.php?t=67942)

Spinball 08-02-2004 10:00 PM

Insert HTML or (pre-processed!) PHP file above specific forum
 
This is a very simple but very powerful hack for VB 3 which I've not been able to find elsewhere so decided to write.

It inserts a named external file (or files) above a specific forum (or forums). I use it to insert some HTML from HTML AND PHP (!) files above specific forums.
It works perfectly on my forums with over 28,000 members.

It requires editing one file and one template.

The amazing thing I discovered is that if the php function used (file_get_contents) is used on a php file, the php is processed BEFORE the file contents are read into the string.

The first attached image shows this hack 'including' a php file which dynamically builds a list from a database on a different server into a drop-down list box.

The second image shows the inclusion of a banner and beneath it a HTML file showing latest news (which is created automatically).

* Updated August 7 2004. Altered the text file to include instructions on how to insert the file at the top of your forum list *.
Please note that the forum list instructions are untested. If someone uses it, please let me know if it works ok.
One question, though. This hack is so simple but so powerful, howcome nobody has done it before? Or have they already?

Spinball 08-03-2004 08:22 AM

How to use this hack to display rotating banners.
You can use the above hack on a php script to create any number of rotating banners above your forums (without any modification to the forum table as per other hacks). Create a .php file as follows:

PHP Code:

<?php
$banners 
= array (
        
"banner1.gif|link1.pl|Alt text for banner 1|0|468|60",
        
"banner2.gif|link2.pl|Alt text for banner 2|0|468|60",
        
"banner3.gif|link3.pl|Alt text for banner 3|0|468|60",
        
"banner4.gif|link4.pl|Alt text for banner 4|0|468|60"
);
$banner $banners[mt_rand(0,sizeof($banners) - 1)];
list(
$imgsrc,$myurl,$alttext,$border,$width,$height) = explode ('|',$banner);
echo(
"<A HREF=\"http://www.yourdomain.com/cgi-bin/$myurl\" TARGET = \"_blank\"><IMG src=\"http://www.yourdomain.com/adverts/banners/$imgsrc?" mt_rand(1,999) . "\" border=\"$border\" width=\"$width\" height = \"$height\" alt=\"$alttext\"></A>");
?>

Notes:
  1. banner1.gif to banner4.gif are the names of the banner files
  2. the banner files exist in the /adverts/banners/ folder on your website (change this to whatever you want)
  3. link1.pl to link4.pl are simple perl scripts which open up the target websites (see below)
  4. the perl scripts are in your cgi-bin folder
  5. the 0|468|60 are the border width (0=no border), banner width and banner height for each banner. Mine are all the same - no border and 468x60.
  6. using _blank for the target makes the new websites open in a new window. Remove the TARGET = \"_blank\" bit if you want it to open in the same window

Upload this php file to your server and have the above hack open it.
If you want to display the same set of banners on several forums, just have them open this file. If you want a different set of banners you'll need to create a different version of this file for each.

Other notes:
The reason for calling the perl scripts is so that a hit stats package like Webtrends can count the number of times the perl scrips have been run and provide you with the number of clicks for your banners in it's report.

A typical perl script would look like this:
HTML Code:

#!/usr/bin/perl
print "Location: http://www.targetdomain.com/";

Oh and adding
PHP Code:

mt_rand(1,999

on to the end of the name of the image helps ensure that people's cache doesn't open up old versions of banners.
--------------------------------------------------------------------------------------------------
Give users a control panel option to change how the added information is displayed
I use this hack to include different news feed above certain forums but some users wanted it displayed at the bottom or not at all.
This is very easy and thanks to Colin F who helped me.

First create a new user option. I'll use my installation as an example.
Admin CP > User Profile Fields > Add New User Profile Field.
For the Profile field type choose Single Selection Radio Buttons or Single Selection Menu whichever you prefer. I chose the latter since it looks more similar to existing multiple choice user options.
Complete the new profile field information.
My forum users use this profile field to decide how to display the news and I set the Options to
Above threads
Below threads
Not shown
I set the default to Yes, but No First Blank Option. And the field IS required.
Lastly for the display page 'Which page displays this option?' choose Options: other.
Ok, now you have the new profile field. Take a look at the list of User Profile Fields in the User Profile Field Manager to find which field your new option is. Mine was field9.

Now all you have to do is edit the FORUMDISPLAY template.
Below $navbar insert
-------------------
<if condition="$mycustomheader AND $bbuserinfo[field9] == 'Above threads'">$mycustomheader</if>
-------------------
Note that this is the original hack altered to display the $customheader information IF the user has chosen to display it above threads.
--------------------

Then below
------------------------------
<!-- ############## END THREADS LIST ############## -->
</if>
-------------------------------
Insert
------------------------------
<if condition="$mycustomheader AND $bbuserinfo[field9] == 'Below threads'">$mycustomheader</if>
------------------------------
Note that if users have chosen the third option 'Not shown', then the $mycustomheader information is never shown :)

jluerken 08-03-2004 10:20 AM

Is this also working for the forumhome?
I want to add a small table right unter the navbar and want to phpinclude a file there.

Spinball 08-03-2004 10:49 AM

Yes it will.
Instructions added into the text file August 7 2004.

msu 08-05-2004 09:16 PM

thanx for this cool hack , and it will be great if you make it for vbulletin 2.x.x people

:)

Spinball 08-07-2004 08:38 PM

Quote:

Originally Posted by msu
thanx for this cool hack , and it will be great if you make it for vbulletin 2.x.x people

:)

This will work with vB2, you'll just need to find the right places to put the php code and which template to edit and where within that template.
I don't run vb2 any more so if someone would like to have a look and let me know, I'll add it to the instructions.

msu 08-07-2004 09:07 PM

thank you again :)

hukgwai 08-08-2004 02:38 PM

I recieved this error after following your instructions:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/myfolder/forums/forumdisplay.php on line 372

Is there something wrong with your file?

in your instructions for setting up on forumhome, it seems to be for calling up the file in a specific forum, maybe i am missing something here?

how do i have the banners show up on every page?

Spinball 08-08-2004 03:05 PM

Quote:

Originally Posted by hukgwai

in your instructions for setting up on forumhome, it seems to be for calling up the file in a specific forum, maybe i am missing something here?

how do i have the banners show up on every page?

Yeah - you're right - I've updated it, thanks.
Is this the source of your error?
If not what is the line at 372 in your file?

xxxGiJoe 08-13-2004 02:35 PM

Works GREAT!!!

http://wolfgaming.net/wgn/vB/forumdisplay.php?f=161

YLP1 08-29-2004 12:38 AM

Can you use this mod to pull in the Latest Topics mod used in the portal? Or is there a way to pull in the latest topics/posts without using the portal mod?

I'm very new to VB and PHP so any help is greatly appreicated.

I am trying to put the most recent topics/posts at the top of the forum and get it scroll when moused over...I'm having a devil of a time figuring this out.

Spinball 08-29-2004 07:13 AM

Not familiar with the Latest Topics mod and don't have time right now to investigate.
I would imagine that nearly anything is possible with a little coding.

dr.science 10-28-2004 01:16 AM

I've added this, and it looks very good. I just have a couple questions. How do I center the image on top of my forum list? It is far left right now. Also, I can't seem to get the images links to work. I have been playing with it for a while and can't seem to figure out how to get the perl scripts working, or even functional.

thanks for your help!

gfd 10-28-2004 08:38 PM

you can wrap your banner/link in a div:

<div style="text-align:center;">
<a href......>banner</a>
</div>

.... i don't know about the links. It would help if you can post a link to your page.

dr.science 10-29-2004 02:36 AM

Sorry, it's here:

http://www.d-series.org/forums/?

Thanks!

dr.science 11-24-2004 07:47 PM

Quote:

Originally Posted by dr.science
Sorry, it's here:

http://www.d-series.org/forums/?

Thanks!

Can someone help me please? I am trying to do a couple oth things and I can't seem to get them done right.

My banner images do not link correctly to the sites they are for. I am not familiar ith how to make a perl script.

Also, where do I input the code to center the banners on the forum home page? Do I just use this code: <div style="text-align:center;">
<a href......>banner</a>
</div> ???

Thanks for all of your help. I would really appreciate it if someone would help me so I can get this fixed.

Thanks again!
http://www.d-series.org/forums/?

Spinball 11-24-2004 08:38 PM

What code are you using to display the banner?
You just need to put a centre that. Ill help if you post the HTML which is displaying the banner.

With regard to the perl script to make the link work, if you want to count the number of clicks of the banner then you need to use a perl script as the target of the banner. This is so you can count the number of times the perl script has been opened using a normal log file analysis program like Webtrends.
The perl script should be located in your cgi-bin folder and you will need to make your banner link <A HREF= 'link to your perl script' target='_blank'>
The link itself can be relative e.g.: '../cgi-bin/yourperlscript.pl'
or direct 'htp://www.yoursite.com/cgi-bin/yourperscript.pl'.
The first one is preferable.
It looks like you haven't got the link location correct.
The perl script will work if you put it in your cgi-bin folder and in telnet or with an appropriate ftp program chmod 755 yourperlscript.pl
Presumably you have copied my example to create the correct perl script?

Note : it's possible to have an alternative to using a perl script if you instead have the link fire up your own php application which counts the clicks for you.
But you will need some programming and database experience to do this.

Mamochka 12-06-2004 09:47 PM

Hi,Spinball

you typed for Ex:
#!/usr/bin/perl
print "Location: http://www.targetdomain.com/";

Can you make Ex with next info -> www.mylink.com alttext=MyLink

and Ex for Forumhome,because I want to put the Banner above a navlink.

Thanks again!

Spinball 12-07-2004 06:01 AM

You'll have to use one of the other hacks for banners above the navbar.
The perl script you quoted above is simply for couning the hits as explained in the description accompanying this thread.

turkforum 12-28-2004 04:05 AM

it will be a very nice hack but!
It only shows at forumdisplay.php when someone reads the thread showtread.php does not show the banner
i have more than 100 forums and some categories is not possible to make this hack available for categories?
or lets say how can i enable multiple forums
like
if ($forumid==76) {
$mycustomheader = file_get_contents("http://domain.net/hosting.htm");
}
// get external data
do i have to copy and paste te code for multiple fourms or is there comma like code for multiple forums
like
if ($forumid==76,x,y,z) { i tried comma but doesnot work

Spinball 12-28-2004 08:12 AM

I have used my hack to display banners above and below threads.
Edit showthread.php and find
*********************************************
// ################################################## ###########################
// output page
eval('print_output("' . fetch_template('SHOWTHREAD') . '");');
*********************************************
and add this code before it:
*********************************************
$headerbanner = "<P ALIGN=\"CENTER\" CLASS=\"smallfont\">" . file_get_contents("http://www.url_of_your_script.php?forumid=$forumid&type=h eader") . "</P>";
$footerbanner = "<P ALIGN=\"CENTER\" CLASS=\"smallfont\">" . file_get_contents("http://www.url_of_your_script.php?forumid=$forumid&type=f ooter") . "</P>";
*********************************************
Then in the SHOWTHREAD template, find
*********************************************
$navbar
*********************************************
and after it, put
*********************************************
<if condition="$headerbanner">$headerbanner</if>
*********************************************
and find
*********************************************
<if condition="$bbuserinfo[field11] == 'Yes'">$quickreply</if>
*********************************************
and above it add
*********************************************
<if condition="$footerbanner">$footerbanner</if>
*********************************************

Then write your php script to output banners depending on what forumid is passed and whether it's the header or footer:

PHP Code:

$forumid $_REQUEST['forumid'];
$type $_REQUEST['type'];

switch (
$forumid) {
 case 
36:                                 // for your forum number 36 only...
   
if ($type == "header") {
      
$banners = array (
      
"banner_1.gif|banner_1.pl|The alt text|0|468|60",
      
"banner_2.gif|banner_2.pl|The alt text|0|468|60"
      
);
   } elseif (
$type == "footer") {
      
$banners = array (
      
"banner_3.gif|banner_3.pl|The alt text|0|468|60",
      
"banner_4.gif|banner_4.pl|The alt text|0|468|60"
      
);
   }
   break;
 case 
37:                                 // for your forum number 37 only...
   
if ($type == "header") {
      
$banners = array (
      
"banner_5.gif|banner_5.pl|The alt text|0|468|60",
      
"banner_6.gif|banner_6.pl|The alt text|0|468|60"
      
);
   } elseif (
$type == "footer") {
      
$banners = array (
      
"banner_7.gif|banner_7.pl|The alt text|0|468|60",
      
"banner_8.gif|banner_8.pl|The alt text|0|468|60"
      
);
   }
   break;
}
$banner $banners[mt_rand(0,sizeof($banners) - 1)];
list(
$imgsrc,$myurl,$alttext,$border,$width,$height) = explode ('|',$banner);
echo (
"<A HREF='http://www.your_domain.com/cgi-bin/$myurl' TARGET='_blank'><IMG src='http://www.your_domain/path_to_your/banners/$imgsrc?" mt_rand(1,9999) . "' border='$border' width='$width' height='$height' alt='$alttext'></A>"); 

I'm actually working on a complete vBulletin banner solution which enables you to display (rotating) banners above the forum list and also above and below every thread (and anywhere else you want). But it's work-in-progress.

Re your specific code request, I recommend you learn some PHP.
PHP Code:

if ($forumid==76 or $forumid==78 or $forumid==81

or if you have lots of forums, use the 'switch' command as per my example above.

Re displaying banners for whole categories, you might be able to do it, but I don't have time to look into it this year :)

keithsl 01-08-2005 04:17 PM

How would you do this if you want to include something on top of every page of the forum?

Spinball 01-08-2005 04:42 PM

You wouldn't need to use this hack - use the phpinclude_start template instead.

YLP1 01-08-2005 06:05 PM

Quote:

Originally Posted by Spinball
You wouldn't need to use this hack - use the phpinclude_start template instead.

Are there instructions for the php newbie to use this start tempate? Thanks in advance.

Spinball 01-08-2005 06:09 PM

Do a search on vbulletin.com for phpinclude

H@K@N 01-09-2005 12:10 PM

Hi,

i am going to try, to use the shoutcast status Box, which is availible for vba-portal, on my Forumhome.

When i try to include the shoutcast.php below the $navbar it says :

Code:

Fatal error: Call to undefined function: fetch_template() in /srv/www/htdocs/web1/html/shoutcast.php on line 68
On the Line 68 i have following :

Code:

eval('$home[$mods[\'modid\']][\'content\'] .= "' . fetch_template('adv_portal_shoutcast') . '";');
what should i change to have that script running ?

th@nks

sabret00the 01-09-2005 12:18 PM

try this, you're eval is a mess as is
PHP Code:

        eval("\$home['content'] .= \"" fetch_template("adv_portal_shoutcast") . "\";"); 


H@K@N 01-09-2005 03:12 PM

th@nks 4 reply, but i have still this error :

Code:

Fatal error: Call to undefined function: fetch_template() in /srv/www/htdocs/web1/html/shoutcast.php on line 68


here i paste the whole script :

PHP Code:

<?php
// Shoutcast Server Stats
// Parses shoutcasts xml to make an effective stats thing for any website

//Configuration
$scdef "TEst FM";   // Default station name
$scip "myipadress";       // ip or url of shoutcast server
$scport "8000";       // port of shoutcast server
$scpass "yourpass";  // password to shoutcast server
$maxusers "32"//max users for your server
//End configuration

$scfp = @fsockopen($scip$scport, &$errno, &$errstr3);

if(!
$scfp) {
eval(
"\$home['content'] .= \"" fetch_template("adv_portal_shoutcast_off") . "\";"); 
}else{
if(
$scsuccs!=1){
fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
while(!
feof($scfp)) {
  
$page .= fgets($scfp1000);
}
}

//define  xml elements

$loop = array("STREAMSTATUS""BITRATE""SERVERTITLE""CURRENTLISTENERS");
$y=0;
while(
$loop[$y]!=''){
  
$pageed ereg_replace(".*<$loop[$y]>"""$page);
  
$scphp strtolower($loop[$y]);
  $
$scphp ereg_replace("</$loop[$y]>.*"""$pageed);
  if(
$loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE || $loop[$y]==SERVERTITLE)
   $
$scphp urldecode($$scphp);

// uncomment the next line to see all variables
//echo'$'.$scphp.' = '.$$scphp.'<br>';
  
$y++;
}
//end intro xml elements

//get song info and history
$pageed ereg_replace(".*<SONGHISTORY>"""$page);
$pageed ereg_replace("<SONGHISTORY>.*"""$pageed);
$songatime explode("<SONG>"$pageed);
$r=1;
while(
$songatime[$r]!=""){
  
$t=$r-1;
  
$playedat[$t] = ereg_replace(".*<PLAYEDAT>"""$songatime[$r]);
  
$playedat[$t] = ereg_replace("</PLAYEDAT>.*"""$playedat[$t]);
  
$song[$t] = ereg_replace(".*<TITLE>"""$songatime[$r]);
  
$song[$t] = ereg_replace("</TITLE>.*"""$song[$t]);
  
$song[$t] = urldecode($song[$t]);
  
$dj[$t] = ereg_replace(".*<SERVERTITLE>"""$page);
  
$dj[$t] = ereg_replace("</SERVERTITLE>.*"""$pageed);
$r++;
}
//end song info

fclose($scfp);
}

//display stats
if($scfp) {
if(
$streamstatus == "1"){
//you may edit the html below, make sure to keep variable intact
eval("\$home['content'] .= \"" fetch_template("adv_portal_shoutcast") . "\";"); 
} else {
eval(
"\$home['content'] .= \"" fetch_template("adv_portal_shoutcast_off") . "\";"); 
}
}
?>


i hade the eval twice, so i have tried also to change the eval below the server settings, but still not working.


gr33tz

sabret00the 01-09-2005 03:52 PM

you need to include the global.php :)

H@K@N 01-09-2005 05:21 PM

Quote:

Originally Posted by sabret00the
you need to include the global.php :)


Th@nks 4 help but i can't include that.

if i use :

require_once('./global.php');

into the Header of the php,Forumhome is going to open the shoutcast.php himself on the Index, and i cannot login anymore.

gr33tz

Spinball 01-10-2005 09:31 AM

Sorry but is this relevant to the hack?

Julio 03-24-2005 02:43 PM

Also, where do I input the code to center the banners on the forum home page? Do I just use this code: <div style="text-align:center;">
<a href......>banner</a>
</div> ???

PLEASE let me know as well!

Spinball 03-24-2005 03:00 PM

Well I use the phpinclude_start template:
Code:

ob_start();
require("/home/sites/avforums/public_html/page_top.php");
$forum_heading = ob_get_contents();
ob_end_clean();

and then right at the top of the header template:
Code:

$forum_heading
And the page_top.php file I call some banner serving software.

Julio 04-21-2005 09:00 PM

After a couple of weeks of using this mod, and everything working OK, Today I logged to my forums, and I am getting the following error message at the top of FORUMHOME.

Warning: file_get_contents(): URL file-access is disabled in the server configuration in /index.php on line 59

Warning: file_get_contents(http://www.mydomain.com/forums/banners.php): failed to open stream: no suitable wrapper could be found in /index.php on line 59

Spinball 04-22-2005 09:51 AM

Sounds like there has been some kind of configuration change.
If you access the URL in your browser rather than in the file_get_contents, does it work?

Julio 04-22-2005 05:02 PM

Yes, it works.

Spinball 04-22-2005 06:34 PM

The message
Quote:

URL file-access is disabled in the server configuration
might offer you a clue.
If it worked previously, check (with your hosts) whether the configuration of the server has changed in some way.

makaiguy 04-08-2006 04:10 PM

Quote:

Originally Posted by Julio
After a couple of weeks of using this mod, and everything working OK, Today I logged to my forums, and I am getting the following error message at the top of FORUMHOME.

Warning: file_get_contents(): URL file-access is disabled in the server configuration in /index.php on line 59

Warning: file_get_contents(http://www.mydomain.com/forums/banners.php): failed to open stream: no suitable wrapper could be found in /index.php on line 59

I had this same problem when I moved a working 3.5.4 installation to a new server, which apparently was configured differently. I found it worked if I changed it to not address the file via http:
PHP Code:

$mycustomheader file_get_contents("filename.php"): 


makaiguy 04-12-2006 12:16 AM

Adding to my post, above, re URL file-access is disabled in the server configuration:

I found this is because my server has the PHP option allow_url_fopen disabled, thus preventing accessing the file via http. For importing static html, the solution in the above post was fine.

But one of my import files was a php file that generated some variable text depending on the date. When accessing this directly instead of as an http import, all I got was the static php code, not the RESULT of running the php code.

The support folks at the server suggested using their installed cURL library in place of get_file_contents(). The following modification to this hack in forumdisplay.php is now working for me:
PHP Code:

Replace:

$mycustomheader file_get_contents("http://www.mydomain.com/forums/filename.php"):

With

   
$ch curl_init();
   
$timeout 5// set to zero for no timeout
   
curl_setopt ($chCURLOPT_URL'http://www.mydomain.com/forums/filename.php');
   
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
   
curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout);
   
$mycustomheader curl_exec($ch);
   
curl_close($ch); 

If you're having the same problem, check with your host as to whether they have the cURL library available.

Oleks 04-20-2006 07:24 PM

Quote:

Originally Posted by Spinball
The amazing thing I discovered is that if the php function used (file_get_contents) is used on a php file, the php is processed BEFORE the file contents are read into the string.

Hi,
It seams, this is not the case for my server.
I see the text of the .php file, not the results of execution.

What I should ask my host to change?


All times are GMT. The time now is 04:43 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.01502 seconds
  • Memory Usage 1,941KB
  • 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
  • (1)bbcode_html_printable
  • (8)bbcode_php_printable
  • (8)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete