Help with PHP includes Help with PHP includes
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Help with PHP includes

Started by dafyd, January 02, 2005, 12:06:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dafyd

No doubt GauGau is going to tell me to search properly before I post this - I have, and I've followed the steps outlined as best I can, and I still need help...

My site at www.july162005.com has a header across all the pages with, among other things, a PHP countdown to July 16 2005. Now, I've got the rest of the header working fine by creating a new version of template.html, but for the life of me I can't get the dratted countdown to work properly. As I say, I've read everything on the board, and it really doesn't help.

The code for the countdown is the following:


<?php
define
("OFFSET"0);
define("YSECS"365*24*60*60);
define("DSECS"24*60*60);
define("HSECS"60*60);
define("MSECS"60);

function 
countdown($detail$year$month 1$day 1$hour 0$minute 0$second 0) {
$years $days $hours $minutes $seconds 0;
$now mktime() + OFFSET*60*60;
$then mktime($hour$minute$second$month$day$year);
$cdown abs($then $now);

if ($detail == 1$years round($cdown/YSECS);
else $years floor($cdown/YSECS);
$cdown %= YSECS;
if ($detail == 2$days round($cdown/DSECS);
else $days floor($cdown/DSECS);
$cdown %= DSECS;
if ($detail == 3$hours round($cdown/HSECS);
else $hours floor($cdown/HSECS);
$cdown %= HSECS;
if ($detail == 4$minutes round($cdown/MSECS);
else $minutes floor($cdown/MSECS);
$cdown %= MSECS;
$seconds $cdown;

$tnums = array($years$days$hours$minutes$seconds);
$ttext = array("year""day""hour""minute""second");

$shown 0;

for ($i=0;$i<$detail;$i++) {
if ($tnums[$i]) {
echo "$tnums[$i] $ttext[$i]";
$shown++;
if ($tnums[$i] != 1) echo "s";
$count 0;
for ($j=$i+1;$j<$detail;$j++) {
if ($tnums[$j]) $count++;
}
switch($count) {
case 0: break 2;
case 1: if ($shown>1) echo ","; echo " and "; break;
default: echo ", "; break;
}
}
}
if ($now $then) echo " ago";
if ($now == $then) echo "now";
}
?>



which is then called in the page as


<?php countdown(420050716000100); ?>


I think the problem I'm having is getting my head around the dynamic bit. If anyone can help, I'd be hugely grateful!

Tranz


Nibbler

You can follow the usual instructions that apply to custom headers. Make sure you include() that file, and call the function. So your pageheader function in your theme.php needs something like


include 'that_file.php';
.. a few lines later...
'{COUNTDOWN}' => countdown(4, 2005, 07, 16, 00, 01, 00),


Where {COUNTDOWN} is mentioned somewhere in your theme.html.

dafyd

I've done what you suggested, Nibbler, but for some reason the countdown text appears as the very first thing in the source of the outputted page (you can see what I mean at http://www.july162005.com/gallery/), so it appears right at the top of the page, outside of the body of the document.... I still can't see what I'm doing wrong!

Here's the pageheader function code that I'm using:


function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

include 'cdown.php';

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    user_save_profile();

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . $section,
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{MAIN_MENU}' => theme_main_menu(),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{COUNTDOWN}' => countdown(4, 2005, 07, 16, 00, 01, 00),
        );

    echo template_eval($template_header, $template_vars);
}


and {COUNTDOWN} is called in the page where I want it to appear.

I really don't understand why it doesn't work!

Tranz

Could you please post the code that includes {COUNTDOWN} so we can see its placement?

Also, where do you want it placed?

kegobeer

Have your function return a value instead of echoing the values, ie: return $somevalue;
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

Joachim Müller

refer to http://forum.coppermine-gallery.net/index.php?topic=13001.msg59293#msg59293 or http://forum.coppermine-gallery.net/index.php?topic=9863.msg44419#msg44419 - in those threads I walked two users through custom header setups (that's something your search should have come up with).

Joachim

Nibbler

Try like this:


function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    ob_start();
    include 'cdown.php';
    countdown(4, 2005, 07, 16, 00, 01, 00);
    $countdown = ob_get_clean();

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    user_save_profile();

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . $section,
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{MAIN_MENU}' => theme_main_menu(),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{COUNTDOWN}' => $countdown,
        );

    echo template_eval($template_header, $template_vars);
}

dafyd

Nibbler - that works, thank you ever so much!

GauGau - I did search, and I did follow the steps you laid out as best I could, but I came to an impasse. That's why I came to the forum for help. Sorry to be an incovenience to you. You advice in the previous posts was very useful for clearing up some other problems, though - thank you.