View Full Version : Using a PHP script within HTML-templates
Dunkelkind
02-11-2007, 02:26 AM
Hello PP-community,
maybe my "problem" seems totally easy to solve but my knowledge about PHP isn't worth to mention :)
I want to include a simple PHP script (counter of my visitors since the beginning of my domain) in the footer of my html template files of my PP blog. The counter displays a small message (xxxxx hits (now x online)) as you can see at the start page of my website http://www.dunkelzeit.de . Before using Pixelpost as a blog/gallery system I used to call the script by simply adding following into the corresponding html page for displaying the counter:
<?php
include './<path_to_script>/count.php'
?>
Now by using PP it doesn't work anymore this way and when having a look at the source code in the browser window I even can read this PHP snippet. I assume that I have to include/call this script another way since the PP index.php is the essential page which just includes the templates when serving the client. Can someone help me with this issue? Any help is gladly appreciated :)
Dkozikowski
02-11-2007, 03:39 AM
Interesting. I was not aware that this was an issue but it makes sense now that I think about it.
I sent you a private message :)
Connie
02-11-2007, 06:22 AM
as usual,
this must be done with an addon
because addons will be read and interpreted as php
in the moment when the template is read, only <TAGs> are interpreted!
Dunkelkind
02-11-2007, 09:08 AM
Thank you both :)
@ dwilkinsjr
I gathered all information for you.
@ Connie
That makes some sense to me :)
austriaka
02-11-2007, 10:19 AM
have a look at the "current_datetime.php" which is found in addons folder of your pixelpost installation.
remove these lines:
$tz = $cfgrow["timezone"];
$current_date_time = gmdate($cfgrow['dateformat'],time() + (3600 * $tz));
and put the "include './<path_to_script>/count.php'" instead.
Now you can replace the message with the tag:
$tpl = str_replace("<COUNT_MESSAGE>",$counter_return,$tpl);
Name the file "count_addon.php" and put it into your addons folder.
HTH
KArin
Dkozikowski
02-11-2007, 11:06 AM
He's all set Karin. I already took his code and put it into an addon :)
Dunkelkind
02-11-2007, 11:09 AM
Great work :)
Thank you very much.
austriaka
02-11-2007, 12:11 PM
He's all set Karin. I already took his code and put it into an addon :)so why don't you publish it here?
It spares brainworking for help-willing people and gives advice for those who will come after us
;-)
KArin
Dkozikowski
02-11-2007, 06:45 PM
so why don't you publish it here?
It spares brainworking for help-willing people and gives advice for those who will come after us
;-)
KArin
:p Sorry ;)
All I did was take count.php and put it in an addon format. 2 second job, quick an dirty :)
The script could be enhanced by using some other pixelpost variables but it does what he wants it to do, count a page hit and show how many users are currently online.
euscera
03-29-2007, 01:55 AM
Still, care to put it here, I am running with the same thing here.
doesn't work with include("/home/grushca/public_html/cnstats/cnt.php");
and i'm having trouble putting it all together.
http://forum.pixelpost.org/showthread.php?t=6335&highlight=php+include
euscera
03-29-2007, 02:19 AM
here's what I got cncount.php in addon folder
$addon_name = "CnStats Counter";
$addon_description = "CNStats cne.php replacer.";
$addon_version = "0.1";
$cn_count = include("/home/grushca/public_html/cnstats/cnt.php");
$tpl = str_replace("<CN_COUNT>",$cn_count,$tpl );
as soon as its turned on in the control panel it starts couting -- so it includes even if i dont have <CN_COUNT> embedded into the template page and the design falls apart. What should I do?
Thanks
dakwegmo
03-30-2007, 04:50 PM
You'll need to use some logic to only include the file on the pages you want it to show up on. If you only want the counter to show up on your main image pages, then something like this might work:
$addon_name = "CnStats Counter";
$addon_description = "CNStats cne.php replacer.";
$addon_version = "0.1";
if(!isset($_GET['x']) {
$cn_count = include("/home/grushca/public_html/cnstats/cnt.php");
$tpl = str_replace("<CN_COUNT>",$cn_count,$tpl );
}
I'm pretty new to PHP and PixelPost's code, so someone else can correct me if I'm wrong.
Dkozikowski
03-30-2007, 10:17 PM
You'll need to use some logic to only include the file on the pages you want it to show up on. If you only want the counter to show up on your main image pages, then something like this might work:
$addon_name = "CnStats Counter";
$addon_description = "CNStats cne.php replacer.";
$addon_version = "0.1";
if(!isset($_GET['x']) {
$cn_count = include("/home/grushca/public_html/cnstats/cnt.php");
$tpl = str_replace("<CN_COUNT>",$cn_count,$tpl );
}
I'm pretty new to PHP and PixelPost's code, so someone else can correct me if I'm wrong.
if(isset($image_id)) {
is what i normally use when dealing with addons for the image_template.
euscera
03-30-2007, 11:19 PM
if(isset($image_id)) {
is what i normally use when dealing with addons for the image_template.
why do you need $image_id in there for?
thanks
Dennis
03-31-2007, 10:31 AM
To see if you're on the image_template.html or not.
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.