vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   PHP in vB4 template (https://vborg.vbsupport.ru/showthread.php?t=240584)

NickyDee 04-16-2010 02:46 PM

PHP in vB4 template
 
Hey,

I want to include a php file which generates a list (/Forum/statsinner.php) at the bottom of a custom vbulletin page (/Forum/database5yr.php).

To do this I have added an includephp plugin (in global start):

Code:

ob_start();
include('/Forum/statsinner.php');
$includedphp = ob_get_contents();
ob_end_clean();

and then added {vb:raw includedphp} to my custom pages template. (I have also tried global.includedphp)

However - this doesn't seem to be working. Have I done something crazy here? This has really got me stumped, any help would be very much appreciated.

somoneybaby 04-16-2010 08:07 PM

Quote:

Originally Posted by NickyDee (Post 2022212)
Hey,

I want to include a php file which generates a list (/Forum/statsinner.php) at the bottom of a custom vbulletin page (/Forum/database5yr.php).

To do this I have added an includephp plugin (in global start):

Code:

ob_start();
include('/Forum/statsinner.php');
$includedphp = ob_get_contents();
ob_end_clean();

and then added {vb:raw includedphp} to my custom pages template. (I have also tried global.includedphp)

However - this doesn't seem to be working. Have I done something crazy here? This has really got me stumped, any help would be very much appreciated.

I'm completely stumped as well. I am doing something similar and I'm getting nothing. In earlier versions of vB, you would just call $includedphp but that doesn't seem to be working either.

NickyDee 04-16-2010 08:25 PM

I think the problem we both have is that template/variables need to be pre-registered now whereas in the past they didn't.

But I can't for the life of me figure out where I'm going wrong. I've tried adding this (below) code into both my include PHP and my custom page PHP and still no luck:

Code:

vB_Template::preRegister('cpage_Stats',array('includedphp ' => $includedphp));

somoneybaby 04-16-2010 08:27 PM

Got it! Let me know if this works for you.

Code:

ob_start();
include('/Forum/statsinner.php');
$includedphp = ob_get_contents();
ob_end_clean();

vB_Template::preRegister('TEMPLATE_NAME_YOU_ARE_ADDING_CALL_INTO', array('includedphp' => $includedphp));

Then in your page template call {vb:raw $includedphp}

My example:

Code:

ob_start();
include("$_VhostPath/html/custom/vbulletin_display_login.php");
$pb_header_include = ob_get_contents();
ob_end_clean();

vB_Template::preRegister('header', array('pb_header_include' => $pb_header_include));

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

Quote:

Originally Posted by NickyDee (Post 2022375)
I think the problem we both have is that template/variables need to be pre-registered now whereas in the past they didn't.

But I can't for the life of me figure out where I'm going wrong. I've tried adding this (below) code into both my include PHP and my custom page PHP and still no luck:

Code:

vB_Template::preRegister('cpage_Stats',array('includedphp ' => $includedphp));

Check your call. Are you using {vb:raw $includedphp} instead of what your original post showed {vb:raw includedphp} ?

NickyDee 04-16-2010 08:51 PM

Okay, When I got it working, it knocked one of my other custom pages off. The global hook has disabled one of my other custom template pages.

Heres the link and the error code:

I'm not sure but I think maybe its not clearing the object buffering?

As of 13:27 today this is still not working. It seems if I disable my plugin (in the above posts), the page linked above works. If it enable them, i get the error you can see. :(

somoneybaby 04-19-2010 05:08 PM

Can you post your statsinner.php code? I'm thinking you are having some conflicts with your SQL queries?

NickyDee 04-19-2010 06:04 PM

I think you may be right, heres my statsinner.php code:

PHP Code:

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

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

define('THIS_SCRIPT''Stats');
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('cpage_Statsmain',);

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

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/Forum');
require_once('./global.php');
?>
<script type="text/javascript">
function load() { 
    var urlstring = window.location.href;
    if (urlstring.indexOf("ch1=a") > -1) { document.form1.ch1.checked = true } else { document.form1.ch1.checked = false };
    if (urlstring.indexOf("ch2=b") > -1) { document.form1.ch2.checked = true } else { document.form1.ch2.checked = false };
    if (urlstring.indexOf("ch3=c") > -1) { document.form1.ch3.checked = true } else { document.form1.ch3.checked = false };
    if (urlstring.indexOf("ch4=d") > -1) { document.form1.ch4.checked = true } else { document.form1.ch4.checked = false };
    if (urlstring.indexOf("ch5=e") > -1) { document.form1.ch5.checked = true } else { document.form1.ch5.checked = false };
    if (urlstring.indexOf("ch6=f") > -1) { document.form1.ch6.checked = true } else { document.form1.ch6.checked = false };
}
</script>
<?

if (isset($_GET['Submit1'])) {

    if (isset($_GET['ch1'])) { $ch1 = $_GET['ch1'];
    if ($ch1 == 'a') { $ch1 = 'checked';}
    }
    if (isset($_GET['ch2'])) { $ch2 = $_GET['ch2'];
    if ($ch2 == 'b') { $ch2 = 'checked';}
    }
    if (isset($_GET['ch3'])) { $ch3 = $_GET['ch3'];
    if ($ch3 == 'c') { $ch3 = 'checked';}
    }
    if (isset($_GET['ch4'])) { $ch4 = $_GET['ch4'];
    if ($ch4 == 'd') { $ch4 = 'checked';}
    }
    if (isset($_GET['ch5'])) { $ch5 = $_GET['ch5'];
    if ($ch5 == 'e') { $ch5 = 'checked';}
    }
    if (isset($_GET['ch6'])) { $ch6 = $_GET['ch6'];
    if ($ch6 == 'f') { $ch6 = 'checked';}
    }
}

//select the table

$query="SELECT * FROM medical_school WHERE CourseT = 'UG'";
if ($ch1 == checked) { // Order by resits only
  $query .= " AND Resits = 'Yes'";
} if ($ch2 == checked) { // Order by clearing only
  $query .= " AND Clearing = 'Yes'";
} if ($ch3 == checked) { // Order by biology only
  $query .= " AND Biology = '-'";
} if ($ch4 == checked) { // Order by chemistry only
  $query .= " AND Chemistry = '-'";
} if ($ch5 == checked) { // Order by ukcat only
  $query .= " AND UKCAT = '-'";
} if ($ch6 == checked) { // Order by ukcat only
  $query .= " AND Tests = '-'";}

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close(); ?>

<div style="width:880px; margin-left: 20px;">

<!-- Start of search options !-->
<a href="javascript:;" onmousedown="toggleDiv('advoptions');"><div id="sidebarheader" style="width:750px; margin-left: auto; margin-right: auto;">Advanced Search<div style="float:right"><img name="optionsimg" src="/nick/bararup.png" alt="minimize"  border="0"/></div></div></a>
<div id="advoptions" class="calitext" style="width: 750px; padding: 5px 5px 5px 5px; border: 1px solid #A0A0A0; border-top: 0px; margin-left: auto; margin-right: auto; display: none;">
    <form name="form1" method="GET" action="database5yr.php">
        <table width="730" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="240" align="left" valign="top">Show  courses that may allow:<br />
                <input type = "Checkbox" Name ="ch1" value ="a" <? if ($ch1 == 'a') { echo 'checked';} else { echo 'unchecked'; }?> >
                    Resits<br />
                <input type = "Checkbox" Name ="ch2" value ="b" <? if ($ch2 == 'b') { echo 'checked';}?>>
                    Clearing
            </td>
            <td width="240" align="left" valign="top">Show  courses that do not request:<br />
              <input type = "Checkbox" Name ="ch3" value ="c" <? if ($ch3 == 'c') { echo 'checked';}?>>
                    Biology<br />
              <input type = "Checkbox" Name ="ch4" value ="d" <? if ($ch4 == 'd') { echo 'checked';}?>>
                    Chemistry            </td>
            <td width="240" align="left" valign="top">
              Show  courses that do not use the:<br />
              <input type = "Checkbox" Name ="ch5" value ="e" <? if ($ch5 == 'e') { echo 'checked';}?>>
                    UKCAT<br />
              <input type = "Checkbox" Name ="ch6" value ="f" <? if ($ch6 == 'f') { echo 'checked';}?>>
                    BMAT<br />
                    <div style="float: right"><input type = "Submit" name = "Submit1" value = "Find" /></div>
                    <br />
            </td>
          </tr>
        </table>
    </form></div>
<!-- End of search options !-->
<div id="ukmsabout" class="calitext" style="width: 880px; margin-left: auto; margin-right: auto; font-weight: bold; font-size: 14px;">
Click on a medical school name for more information</div>
<div id="sidebarheader" style="width: 880px; text-align:center; line-height: 35px; height: 35px; background-image: url(/nick/sidebarheaderback30.png)">
        <table width="860" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="125"></td>
            <td width="75"><div style="text-align: center">Applications:</div></td>
            <td width="75"><div style="text-align: center">Places:</div></td>
            <td width="75"><div style="text-align: center">Per place:</div></td>
            <td width="75"><div style="text-align: center">Overseas:</div></td>
            <td width="65"><div style="text-align: center">Offer:</div></td>
            <td width="130"><div style="text-align: center">Subjects:</div></td>
            <td width="120"><div style="text-align: center">Tests:</div></td>
            <td width="60"><div style="text-align: center">Resits:</div></td>
            <td width="60"><div style="text-align: center">Clearing:</div></td>
          </tr>
      </table>
    </div>

<? $i=0;
while ($i < $num) {

$Name=mysql_result($result,$i,"Name");
$Applied=mysql_result($result,$i,"Applied");
$Foreign=mysql_result($result,$i,"Foreign");
$APP=mysql_result($result,$i,"APP");
$Accepted=mysql_result($result,$i,"Accepted");
$Biology=mysql_result($result,$i,"Biology");
$Chemistry=mysql_result($result,$i,"Chemistry");
$Grades=mysql_result($result,$i,"Other");
$UKCAT=mysql_result($result,$i,"UKCAT");
$Test=mysql_result($result,$i,"Tests");
$Resits=mysql_result($result,$i,"Resits");
$Clearing=mysql_result($result,$i,"Clearing");
$ID=mysql_result($result,$i,"ID");
?>

<div id="entry<? echo $ID; ?>" class="medschoolbox">
  <table width="860" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="125"><div style="font-weight: bold; margin-left: 10px;"><a href="/Forum/schoolstats.php?det=<? echo $ID; ?>"><? echo $Name; ?></a></div></td>
      <td width="75"><div style="text-align: center"><? echo $Applied; ?></div></td>
      <td width="75"><div style="text-align: center"><? echo $Accepted; ?></div></td>
      <td width="75"><div style="text-align: center"><? echo $APP; ?></div></td>
      <td width="75"><div style="text-align: center"><? echo $Foreign; ?></div></td>
      <td width="65"><div style="text-align: center"><? echo $Grades; ?></div></td>
      <td width="65"><div style="text-align: center"><? if ($Biology == '-') {} else {?> <img src="/nick/<? echo $Biology;  ?>b.png" /><? } ?></div></td>
      <td width="65"><div style="text-align: center"><? if ($Chemistry == '-') {} else {?> <img src="/nick/<? echo $Chemistry;  ?>c.png" /><? } ?></div></td>
      <td width="120"><div style="text-align: center">
        <? if ($UKCAT == '-') {} else { echo $UKCAT; } ?>
        <? if ($Test == '-') {} else { echo $Test; }  ?>
      </div></td>
      <td width="60"><div style="text-align: center">
        <? if ($Resits == '-') {} else { echo $Resits; }  ?>
      </div></td>
      <td width="60"><div style="text-align: center">
        <? if ($Clearing == '-') {} else { echo $Clearing; }  ?>
      </div></td>
    </tr>
  </table>
</div>
<? $i++; } ?>

I can't see where I am getting a conflict though :(

NickyDee 04-22-2010 09:31 PM

* bump *

NickyDee 04-29-2010 07:34 PM

* bump *

Kyle55155 05-01-2010 11:30 PM

I followed https://vborg.vbsupport.ru/showthread.php?t=228112 and it worked great. I created a new template called road4 and a new php file called road.php and it works great. Now I need to load up the contents of a php page I built that has lots of php code, db calls, javascript etc. I was thinking this was not going to work until i stumbled across this thread:



I can't seem to figure out exactly what you guys did to get this to work. So at this point I have the custom template based on the global style and I have the php page. So do I need to create another vbulletin PHP page and enter my php-javascript-html code on it? And where do I put

{vb:raw includedphp} ?

and where do I put vB_Template:reRegister('road4',array('includedphp ' => $includedphp));

?

If there are any kind souls who know how to do this I would really appreciate a post back.

NickyDee, I checked out your site and confirmed this is exactly what i need. I;m confused about statsinner.php. In that file you have a bunch of Vbulletin entries in addition to your PHP code.

How did you guys do this? Any help would be greatly appreciated.

Kyle

Kyle


All times are GMT. The time now is 02:17 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.01205 seconds
  • Memory Usage 1,807KB
  • 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
  • (6)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete