How to use php in templates

Tutorials for <a href="http://www.phpbbstyles.com/viewtopic.php?t=356">eXtreme Styles mod</a> for phpBB 2.0.

Moderator: Moderators

Postby starbanter on Sat Apr 23, 2005 8:02 pm

I have 52 different files I want it to randomly select from. How do I make it do that? I actually named the files 1.php, 2.php, 3.php through 52.php
starbanter
Registered User
Registered User
 
Posts: 5
Joined: Sat Apr 23, 2005 6:22 am

Postby PostBot on Sat Apr 23, 2005 9:05 pm

Change range in mt_rand()
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby starbanter on Sat Apr 23, 2005 9:14 pm

THANK YOU!!!! :)
starbanter
Registered User
Registered User
 
Posts: 5
Joined: Sat Apr 23, 2005 6:22 am

Postby Invader Zim on Sat Jul 30, 2005 7:59 pm

We've got a problem much like SoDesperate had. We also have an RSS feed we need to include in our index page, but alas, for some reason the include line:

Code: Select all
<?php include("/path/to/forum.php"); ?>


is not parsed at all. It shows up when you look at the source code in your browser.

We tried the suggested solution to SoDesperate's problem but for the life of us couldn't see any variabled that needed to be made global. It's just a simple include command.

See http://www.take13.net
The RSS should appear in the left hand column, right underneath "Take13 | Laatste Forum berichten".
Invader Zim
Registered User
Registered User
 
Posts: 1
Joined: Sat Jul 30, 2005 7:50 pm

PHP parsed in Post

Postby Smoothice on Sun Jul 31, 2005 2:07 am

Hello everyone,

I am wonderig if there is a way for php to be parsed inside a post. Now I know this is kind of dangerous so it would have to be limited to admin posts only. The reason for this is to do ad tracking for a couple of my customers. They have banner ads that I have posted and would like to have all the stats tracked. The software I am using requires php to track the views and click thrus.

I already have the extreme mod installed and have no problem running html in posts but really do need php.

If anyone can help me out that would be greatly appreciated.

Smoothice
Smoothice
Registered User
Registered User
 
Posts: 2
Joined: Thu Jul 07, 2005 4:59 am

php + html

Postby Fuzzy_TRB on Thu Aug 18, 2005 9:15 am

i have read what info i have been able to find but still cant get this code working can any please help me

<!-- USER -->
<?php if ($userdata) { ?>
<div align="right">
<table width="203" cellpadding="3" cellspacing="1" border="0" class="forumline">
<tr>
<td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Profile']; ?></span></td>
</tr>
<tr>
<td class="row1" align="left" width="100%">
<?php if ($userdata['session_logged_in']) { ?>
<table>
<tr>
<td valign="top"><?php echo phpbb_avatar_image($userdata['user_avatar_type'], $userdata['user_avatar']); ?></td>
<td valign="top">
<span class="gensmall">
<?php printf($lang['Welcome_subject'], $board_config['sitename']); ?>, <?php echo $userdata['username']; ?>.<br />
<?php printf($lang['You_last_visit'], create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone'])); ?><p />
</span>
</td>
</tr>
</table>
<span class="gensmall">
<a href="<?php echo append_sid($phpbb_root_path . 'privmsg.php?folder=inbox'); ?>"><?php
if ($userdata['user_new_privmsg'] == 0) {
echo $lang['No_new_pm']; }
elseif ($userdata['user_new_privmsg'] == 1) {
echo printf($lang['New_pm'], $userdata['user_new_privmsg']); }
else {
printf($lang['New_pms'], $userdata['user_new_privmsg']); }
?></a><br />
<a href="<?php echo append_sid($phpbb_root_path . 'search.php?search_id=newposts'); ?>"><?php echo $lang['Search_new']; ?> (<?php echo $new_posts['total']; ?>)</a><br />
<a href="<?php echo append_sid($phpbb_root_path . 'search.php?search_id=egosearch'); ?>"><?php echo $lang['Search_your_posts']; ?></a><br />
<a href="<?php echo append_sid($phpbb_root_path . 'search.php?search_id=unanswered'); ?>"><?php echo $lang['Search_unanswered']; ?></a>
</span>
<form action="<?php echo $phpbb_root_path; ?>login.php?logout=true&redirect=mainpagetribe.php" method="post" target="_self">
<div align="center"><input type="submit" class="mainoption" name="logout" value="Log out" /></p>
</form></div>


<?php } else { ?>
<span class="gensmall">
<?php printf($lang['Welcome_subject'], $board_config['sitename']); ?>, <?php echo $lang['Guest']; ?>.<p />
<a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=register'); ?>"><?php echo $lang['Register']; ?></a>
</span>
<?php } ?>
</td>
</tr>
</table>
</div>
<br />
<?php } ?>
<!-- USER -->
Fuzzy_TRB
Registered User
Registered User
 
Posts: 1
Joined: Thu Aug 18, 2005 9:11 am

Postby baz-x on Thu Aug 18, 2005 10:11 am

Remember: file is handled inside a function so any variable that you need should be set global inside <?php ?>. (like global $userdata, $lang, $phpbb_root_path;)
Regards
baz-x [blog] [website]
current projects:
» [span style="color: darkgreen"]Mex[/span] [span style="color: darkred"][ 75% ][/span]
» Nickpage Mod 2.0.0 ME [span style="color: red"][ paused ][/span]
» Style Demo Mod 1.2.2 ME [span style="color: red"][ paused ][/span]
User avatar
baz-x
Moderator
Moderator
 
Posts: 706
Joined: Sun Aug 15, 2004 9:12 pm
Location: Cache Management of Mex

Postby egriz on Sat Aug 20, 2005 2:15 am

ok, I am trying to use cpmfetch(coppermine fetch) in the .tpl file. I installed extreme style and it works.

I am trying to include a php file that has the code to randomly display one of the pictures from my coppermine gallery.

Here is the code that works to do this in a php file.

Code: Select all
<?php
include 'htp://www.egriz.com/phpfiles/cpmfetch/randomimages.php';
?>


the code within the file is
Code: Select all
<?php   
include "./cpmfetch.php";
$objCpm = new cpm('/GrizPics2');
$objCpm->cpm_viewRandomMediaFrom ( 1, 1, "cat=4,5,6", array("imagewidth"=>"150","imageheight" => "112","windowtarget" => "_blank","alttag" => "Random GrizPics Image") );
$objCpm->cpm_close();
?>


When I put the include function in the .tpl file, it just displays the code instead of actually running it!

Any ideas how to make this work? Thanks
egriz
Registered User
Registered User
 
Posts: 10
Joined: Sat Aug 20, 2005 2:09 am

Postby egriz on Sat Aug 20, 2005 4:14 pm

ok, I got it to work by using this code in the overall_header
Code: Select all
<?php   
include($phpbb_root_path . '../phpfiles/cpmfetch/cpmfetch.php');
$objCpm = new cpm('/GrizPics2');
$objCpm->cpm_viewRandomMediaFrom ( 1, 1, "cat=4,5,6", array("imagewidth"=>"150","imageheight" => "112","windowtarget" => "_blank","alttag" => "Random GrizPics Image", linkstyle => "grizpic") );
$objCpm->cpm_close();
?>

but then when viewing any topic an error comes up saying
Warning: mysql_query(): Access denied for user: [edited for user]' (Using password: NO) in /htdocs/www/GrizBoard/viewtopic.php on line 928

Warning: mysql_query(): A link to the server could not be established in /htdocs/www/GrizBoard/viewtopic.php on line 928

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /htdocs/www/GrizBoard/viewtopic.php on line 929

Warning: mysql_query(): Access denied for user: [edited for user]' (Using password: NO) in /htdocs/www/GrizBoard/viewtopic.php on line 928

Warning: mysql_query(): A link to the server could not be established in /htdocs/www/GrizBoard/viewtopic.php on line 928

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /htdocs/www/GrizBoard/viewtopic.php on line 929


the topics still show up, and you can sue the board normal, but that erro just shows up before the topics do!

any ideas?
egriz
Registered User
Registered User
 
Posts: 10
Joined: Sat Aug 20, 2005 2:09 am

Postby Dirtyrock on Sun Dec 11, 2005 4:38 am

Im wondering if someone can help with this..

I have installed exstream mod for the phpbb which states it will allow php in tpl files etc
but im having trouble formatting this code to work with a phpbb .TPL file..

Code: Select all
<?php
$number=5;
$category="1,2,3";
include("/x/x/x/x/x/x/x/x/x/news/show_news.php");
?>


I recieve the following error,,
Code: Select all
Error!
the template DirtyRock does not exists, note that templates are case sensetive and you must write the name exactly as it is

dirtyrock being the style i use for the phpbb forum.

I then read something about global varibles.. so i then tried this bit of code..

Code: Select all
<?php
global $number;
global $category;
$number=5;
$category="1,2,3";
include("/x/x/x/x/x/x/x/x/x/news/show_news.php");
?>


and get the same error on the page..

anyone help me correct this?
Dirtyrock
Registered User
Registered User
 
Posts: 1
Joined: Sun Dec 11, 2005 3:56 am

Postby Xorro on Fri Jan 20, 2006 10:09 am

I am looking to add some code to rotate my google ads, and show them once for every fourth page view, using this code

Code: Select all
<?php
global $showbanner;
global $showevery;

$showbanner = 0;

$showevery = 4;

$adsense_banner = 'my adsense code'; 

if ($_COOKIE['adsense'] == '') setcookie('adsense', 0); 

if ($_COOKIE['adsense'] > $showevery)

{

setcookie('adsense', 0);

$showbanner = 1;



else 

{

$cookie = $_COOKIE['adsense']+1;

setcookie('adsense',$cookie);



if ($showbanner == 1)

{

echo $adsense_banner;



else 

{

echo "alternative ad";

}

?>   


However, when it runs I get the following error

Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code:2) in /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code on line 118

Warning: Cannot modify header information - headers already sent by (output started at /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code:2) in /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code on line 136


Does anyone know what might be causing this?

Thanks[/code]
Xorro
Registered User
Registered User
 
Posts: 2
Joined: Fri Jan 20, 2006 10:05 am

Postby kvfb97 on Fri Jan 20, 2006 10:41 am

Try this:
Code: Select all
<?php

$showbanner = 0;
$showevery = 4;

$adsense_banner = 'my adsense code'; 
if ($_COOKIE['adsense'] == '') setcookie('adsense', 0); 

if ($_COOKIE['adsense'] > $showevery)
{
   setcookie('adsense', 0);
   echo $adsense_banner;

else 
{
   $cookie = $_COOKIE['adsense']+1;
   setcookie('adsense', $cookie);
}

?>
Tip: Don't argue with idiots, they'll drag you down to their level and beat you with experience.
User avatar
kvfb97
Registered User
Registered User
 
Posts: 1774
Joined: Mon Aug 02, 2004 8:18 am
Location: Northern Ireland, UK

Postby Xorro on Fri Jan 20, 2006 12:31 pm

Thanks, I'm still not having much luck tho, I think it would be easier if I just had a different include file depending on the page-view count -

Code: Select all
<?php

$showbanner = 0;
$showevery = 4;

if ($_COOKIE['adsense'] == '') setcookie('adsense', 0); 

if ($_COOKIE['adsense'] > $showevery)
{
   setcookie('adsense', 0);
   include("http://myurl/google.html");

else 
{
   $cookie = $_COOKIE['adsense']+1;
   setcookie('adsense', $cookie);
include("http://myurl/news.html");
}

?>




but this gives -

Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code:2) in /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code on line 98

Warning: Cannot modify header information - headers already sent by (output started at /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code:2) in /home/sites/site20/web/phpbb2/includes/template.php(929) : eval()'d code on line 108


the news.html file does display tho

Thanks for any help
[/code]
Xorro
Registered User
Registered User
 
Posts: 2
Joined: Fri Jan 20, 2006 10:05 am

Postby CrazyCow007 on Tue Mar 21, 2006 6:52 pm

Hi everybody !

I've a problem to include this PHP code in my overall header :

Code: Select all
<?php
if (eregi('msie', $HTTP_USER_AGENT) && !eregi('opera', $HTTP_USER_AGENT))
{
// Internet Explorer
echo ("<link rel=\"stylesheet\" href=\"http://www.jamesbond-fr.com/images/emx_nav_right_ie.css\" type=\"text/css\" />");
}
else
{
echo ("<link rel=\"stylesheet\" href=\"http://www.jamesbond-fr.com/images/emx_nav_right.css\" type=\"text/css\" />");
}
?>


On normal pages it works great but with eXtreme Styles it always return the emx_nav_right.css CSS file. Do you know if my code is possible to include to my phpBB forum ? :P

Many thanks in advance ! :wink:
CrazyCow007
Registered User
Registered User
 
Posts: 2
Joined: Fri Mar 10, 2006 7:00 pm

External Include in overall_header.tpl not working.

Postby cameronch on Thu Apr 13, 2006 9:23 pm

Hello, I've installed ExTreme Styles v2.3.1 and i am trying to include an external php file into the overall_header.tpl file.

this is the code i've inserted:
Code: Select all
<?php readfile('http://www.calarts.edu/3/includes/topnav.php'); ?>


I'm not seeing the header still at:
http://calartsweb.com/phpBB2/
where it should show up.

Is there a chance that i haven't installed the mod correctly or is something wrong with my code?

I look at the source and it isn't including the code at all. . .

Thanks
cameronch
Registered User
Registered User
 
Posts: 2
Joined: Thu Apr 13, 2006 9:16 pm

PreviousNext

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron