vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [vBulletin 4] Simple way of including an external PHP file (https://vborg.vbsupport.ru/showthread.php?t=242454)

BirdOPrey5 04-07-2011 11:26 PM

What I'm not understanding is why you would make several different php files when you could do the same with a single plugin or really even just template conditionals?

Can you give an example of the HTML code you want displayed from a php file?

karlm 04-08-2011 10:46 AM

OK, I'm doing it this way because I'm not a PHP guru... I'm doing it in a way I can understand.

So what I've done now is in the 'manage ads' area of the ACP, i've enabled a 'last post only' ad-spot.

While testing, it shows only to admins (once it goes live, i'll change this to show only to guests instead).

The content of this ad-code is:

Code:

<style type="text/css">
<!--
#adspot {
    width: 358px;
    height: 268px;
    border: none;
}
-->
</style>

<table style="text-align: left; width: 100%;" border="0" cellpadding="4"
cellspacing="4">
<tbody>
<tr align="center">
<td style="vertical-align: middle; text-align: center;">

<!-- GAMETAP  // UNDER 'PLAY ARCADE GAMES HERE' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 63 OR $GLOBALS['forumid'] == 54 OR $GLOBALS['forumid'] == 56">
<iframe src="/ads/gaming/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> 
</vb:if>


<!-- CHRISTIAN STORE random sizes  // UNDER 'Religion & spirituality' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 3">
<iframe src="/ads/religion/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> 
</vb:if>


<!-- MUSIC STORE random sizes  // UNDER 'music' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 52">
<iframe src="/ads/music/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> 
</vb:if>

<!-- SPORTS STORE random sizes  // UNDER 'sports' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 55">
<iframe src="/ads/sports/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> 
</vb:if>
</td>
</tr>
<tr align="center">
<td style="vertical-align: top;"><small><small><span
style="font-weight: bold;">Please <a href="/register.php" target="_parent">register</a> or sign in to remove these
advertisements.</span></small></small><br>
</td>
</tr>
</tbody>
</table>

In each directory is a series of text files with affiliate codes and the rotator picks a random file each time a viewer reads a thread.

I'm sure I could somehow move the /rotate.php file into the parent directory and have it refer to different sub-directories according to what forumID is being viewed... I have no doubt that can be done.

But - I don't know how to. So I'm trying to keep things simple for myself.

BirdOPrey5 04-09-2011 12:32 AM

Yeah I honestly can't see it getting any better than an IFRAME as you have it without making life A LOT for difficult.

In the unlikely event someone has a browser that doesn't allow IFRAMEs is there some static content you can put between the <IFRAME> and </IFRAME> tags besides "your browser does not support iframes" ? Maybe pick one of the codes you'll be randomizing so it's better than nothing?

karlm 04-10-2011 01:07 PM

Just wanted to add, as I said previously, I'm not guru where coding is concerned... However, after a quick flick through the vbmanual, I've managed to condense my code using <vb:else if xyz /> statements and an additional <vb:else />. This means, now, it will check to see if viewer is in forum x,y,z and show appropriate php files - otherwise (if not in the above mentioned forums) it will show a google-adsense post instead.

WIN!

iwpg 04-17-2011 05:02 AM

I am planning on getting my entire site converted to take adbantage VB 4. I have more than 50,000 pages, so basically, I cannot use the global_start hook, since I would have hundreds of files / scripts loading on every page. This would not be good...

I thought about using global_start with one product (php master file), and then using conditionals within the script to decide which file to load. But decided to wait until I get some advice on this. One thing I did notice: If you have a php file loaded with global_start, every VB page may or may not use those variables. For example, I created a PHP script that looked for the last 5 forum posts, used a variable called $threadid. It happens to be that $threadid is also used within VB. So the last threadid that was called within my custom script forced VB to use that variable! All links on the forum loaded my own script's variable $threadid. Is this normal behavior? I did change my variable name to something unique, but I'm getting a little paranoid about this, because I may have more than this variable that is also used by VB.

This is what I plan... Any feedback would be great.

Product Example:

ob_start();
include('Masterfile.php');
$masterfile = ob_get_contents();
ob_end_clean();

vB_Template::preRegister('customfiletemplate',arra y('loadexternalscripts' => $masterfile));

----------------------------------

Masterfile.php Example:
PHP Code:

if ($_GET['file']=='aboutus'){
include_once 
"aboutus.html";
}
elseif (
$_GET['file']=='otherpage'){
include_once 
"otherpage.php";


----------------------------------
Template:
{vb: raw loadexternalscripts}

The files would then be loaded like customfilepage.php?file=aboutus and Mod-rewrite would do the trick with bringing basic filenames to the request.

BirdOPrey5 04-17-2011 03:42 PM

I'm pretty sure I've heard the global_start hook isn't called on CMS pages anyway. They were going to remove that hook but kept it to keep compatibility with older mods, but didn't add it to the "new" parts of VB4.

I really can't image trying to work on 50,000 pages... good luck with that.

But using the same variable names is a concern. Not only should you avoid the variable names used by vBulletin but also names other people have used in mods you have installed. When I make a mod I'll usually call my variables $bop_post or $bop_thread for example to know I'm not changing data used elsewhere.

iwpg 04-18-2011 02:56 AM

Thanks for the info Joe, do you think the method that I plan would work? This way, only one hook is created and loaded, waiting for $_GET instructions to fire off scripts.

BirdOPrey5 04-18-2011 03:25 AM

Quote:

Originally Posted by iwpg (Post 2185834)
Thanks for the info Joe, do you think the method that I plan would work? This way, only one hook is created and loaded, waiting for $_GET instructions to fire off scripts.

I'm really not understanding what you are really doing... surely you don't plan to write a php elseif statement with 50,000 options... :confused:

iwpg 04-19-2011 03:55 AM

I am using VB to include 1 PHP file that is open to requests. These requests load the appropriate files if that's the page being requested. So, this allows a hook to be placed in global_start without actually loading a script and consuming enormous amounts of system resources. The 50,000+ pages are generated from about 10 scripts/programs.

In other words, I am using this script as a hook on global_start with a custom template that has the vb raw variable.

This is my PHP code (Master.php). Seems to work very well so far.
PHP Code:

<?php
global $fnuser,$fnuserid,$msxtotal;
$csl $_GET['csl']; // Custom Script Location - Single Files with no directories. Mod rewrite on
    
if ($csl=='About-Us') {
    require 
"C/about.shtml";
    
$fglink "About Us";
    
$fgptitle "About Our Business";
    }
    elseif (
$csl=='Sitemap') {
    require 
"C/sitemap.php";
    
$fglink "Sitemap";
    
$fgptitle "Website Sitemap";
    }

mysql_select_db(vb);//Want to select back to VB database just in case another database was selected
?>

Included script on the hook (M.php):
PHP Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''Master');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('CustomMaster',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$navbits construct_navbits(array('' => $fglink));
$navbar render_navbar_template($navbits);

$templater vB_Template::create('CustomMaster');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle'$fgptitle);
$templater->register('sidebarext'$sidebarext);
$templater->register('sidebaropen'$sidebaropen);  
print_output($templater->render());

?>

Mod-Rewrite Code:
Code:

RewriteRule ^C/([^/]+).php$ /FN/M.php?csl=$1 [QSA,L]
Then call it like M.php?csl=About-Us
Mod-Rewrite generates About-Us.php and you're done.

angelcosta 08-06-2011 08:55 PM

Thank you so freakin much!

The file get contents worked!


All times are GMT. The time now is 11:30 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.01601 seconds
  • Memory Usage 1,774KB
  • 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
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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