Advanced search  

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]

Pages: [1]   Go Down

Author Topic: Help with PHP includes  (Read 4312 times)

0 Members and 1 Guest are viewing this topic.

dafyd

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Help with PHP includes
« on: January 02, 2005, 12:06:18 am »

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:

Code: [Select]
<?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

Code: [Select]
<?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!
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Help with PHP includes
« Reply #1 on: January 02, 2005, 12:19:19 am »

http://coppermine.sourceforge.net/faq.php#customHeader

If you want php code, you need to edit theme.php
Logged

Nibbler

  • Guest
Re: Help with PHP includes
« Reply #2 on: January 02, 2005, 12:24:33 am »

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

Code: [Select]
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.
Logged

dafyd

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Help with PHP includes
« Reply #3 on: January 02, 2005, 12:38:04 am »

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:

Code: [Select]
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!
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Help with PHP includes
« Reply #4 on: January 02, 2005, 12:42:01 am »

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

Also, where do you want it placed?
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: Help with PHP includes
« Reply #5 on: January 02, 2005, 12:44:14 am »

Have your function return a value instead of echoing the values, ie: return $somevalue;
Logged
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

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Help with PHP includes
« Reply #6 on: January 02, 2005, 12:46:18 am »

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
Logged

Nibbler

  • Guest
Re: Help with PHP includes
« Reply #7 on: January 02, 2005, 12:47:01 am »

Try like this:

Code: [Select]
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);
}
Logged

dafyd

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Help with PHP includes
« Reply #8 on: January 02, 2005, 12:52:07 am »

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.
Logged
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 20 queries.