How to use php in my template How to use php in my template
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

How to use php in my template

Started by saith, September 01, 2007, 06:09:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

saith

Hi,
I've installed a gallery on my website and I'm doing a theme for it to fit into the overall design of the site.
I'de like to use php on the template, like adding my includes and more but the main template file is in html.
Is there a way I can change that in order to modify the template how I'd want ?

Thanx in advance

Nibbler

No. Use the custom header/footer feature to include php files.

saith

Ok thanx. I guess I'll have to do that.
But I have some php code that I have to put before the html code begins or it won't work. And page header's content appears in the middle of the html code, just after the <body> tag. How can I put php code higher in the code, at the top of it ?

Nibbler

You can't have output before the start of the html. It's not valid. If you want php code to run before any page output then use the custom header feature as suggested.

saith

well it doesn't seem to work. When I put an include in the custom header fucntions it doesn't work, an error occurs

Nibbler

Why don't you post what the error is? That's what a support board is for.

saith

it says :
Parse error: syntax error, unexpected '<' in /home.10.9/legacynj/www/fr/gallery/themes/lnjo/theme.php on line 1164
It does that when I include a php file in the custum header.

Nibbler


saith

actually my template is a copy of the sample template. All I did is ad my include at the end of the header function like that :

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

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

        $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
        header("Content-Type: text/html; charset=$charset");
    user_save_profile();

    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $charset,
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        );

    echo template_eval($template_header, $template_vars);
include($_SERVER["DOCUMENT_ROOT"].'/fr/includes/rn-main.php');
}

It works without the incliude

Nibbler

Don't copy the entire sample theme. You should only copy the parts you want to change. Anyway, you must have done more than that to cause the error message you posted.Post line 1164 and a few lines above/below.

saith

I'm sorry, I got it wrong when you said custom header, I tought you were talking about the header function in the theme.php file. I corrected it. I deleted the files, and did it again from the beginning. This time I didn't edit the theme files (they are a copy from the sample template). All I did was to create a new file called header.inc.php that I put on the root of my gallery and I specified it's name on the configuration panel as the custom header. The only code I included in this file is :
<?php
include('../includes/rn-main.php');
?>


The error I get on any page of my gallery is :
Fatal error: Call to undefined function: append_sid() in /home.10.9/legacynj/www/fr/includes/rn-main.php on line 41

I don't get why it won't work. Do you have an idea of what's causing this ?

Nibbler

Apparently the file you are including needs other files to work. Make sure the paths are correct. They should be as seen from the Coppermine directory.

saith

Yeh you're actualy right. It'sd because of the code that I need to be included before the html. I could put that code before the html if I put {CUSTOM_HEADER} at the very beginning of the file. But then I already use the custom header into the body to include that rn-main.php file, and I already use the footer for the includes that are after the main gallery part. Is there a way I can ad another custom part appart from the custom header and custom footer ?

Nibbler

Moving {CUSTOM_HEADER} around makes no difference. The code you put there is already being run before any html is output. The result is captured and put in with the rest of the header. The header is then output complete.

saith

I think i've know where the problem is. Actually I have phpbb sessions loaded in my pages.
As you can see on my site here there's a login form on the right (it's in rn-main.php wich is an include displayed in every pages of my site). So finally phpbb sessions are included in rn-main.php
My gallery is bridged with phpbb, so it has phpbb sessions loaded too, and I guess it's not working because it loads the sessions 2 times in the same page and that's probably why it generates an error when I include rn-main.

Is there a way I could I remove the session call from the galery so it won't clash with rn-main's ?

Nibbler

Quote from: saith on September 04, 2007, 04:37:11 PM
Is there a way I could I remove the session call from the galery so it won't clash with rn-main's ?

No, because there is no such thing.,

saith

how could this be ? Isn't coppermine supposed to be using phpbb sessions when it's briged with it ?
It must use the sessions in order to have users logued in the gallery.

Sami

‍I don't answer to PM with support question
Please post your issue to related board

saith

well I don't know why but when I ad my include wich contain the session gestions, the gallery won't work, it doesn't even show an erro message, the page is blank. The include is fine since it works on every other pages of my website. The include contain :

<?php
define
('IN_PHPBB'true);
//COPIE SUR LA PAGE PARENTE $phpbb_root_path = '../forum/';
include($phpbb_root_path 'extension.inc');
//include($_SERVER["DOCUMENT_ROOT"].'/forum/extension.inc');
include($phpbb_root_path 'common.'.$phpEx);
 
$redirect_login '../../' $_SERVER['PHP_SELF'];
$redirect_logout '../../' $_SERVER['PHP_SELF'];
//$redirect_login = '../index.'.$phpEx;
//$redirect_logout = '../index.'.$phpEx;
//
// Start session management
//
$userdata session_pagestart($user_ipPAGE_SITE);
init_userprefs($userdata);
//
// End session management
//

$logout htmlspecialchars($HTTP_GET_VARS['logout']);

if ( 
$logout )
{
   
session_end($userdata['session_id'], $userdata['user_id']);
   
redirect(append_sid($redirect_logout));
}
?>



Do you have an idea why it won't work ?

Nibbler