Topic: styles on frontpage

I found another post on the subject, but the code really didnt work...

How do you get the style from the forum to apply to the main site? The code I have now only gets the default, it cant tell if the user is logged in and has a preference...

here is the code I use

<?php

define('PUN_TURN_OFF_MAINT', 1); 
define('PUN_QUIET_VISIT', 1); 

define('PUN_ROOT','systems/forums/'); 
require PUN_ROOT.'include/common.php';

if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

// Now we determine what style we should use
$style = (isset($cur_user)) ? $cur_user['style'] : $pun_config['o_default_style'];

?>
<head>
<link rel="stylesheet" type="text/css" href="systems/forums/style/<?php echo $style ?>.css">
</head>

Again, all it gets is the default theme loaded...but not the logged in user's preference

Re: styles on frontpage

nevermind, I rewrote the code to a different statement that works

<?php

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1); 

define('PUN_ROOT','systems/forums/');
require PUN_ROOT.'include/common.php';

if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

if ($pun_user['is_guest'])
    {
        $style = $pun_config['o_default_style'];
    } else {
        $style = $pun_user["style"];
    }
?>
<head>
<link rel="stylesheet" type="text/css" href="systems/forums/style/<?php echo $style ?>.css">
</head>

so if anyone else needs help with it, there is a method that works big_smile

Re: styles on frontpage

Actually, you can skip the is_guest check. $pun_user['style'] will be the correct style regardless of whether the user is logged in or not.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

4 (edited by Ludo 2005-04-13 17:10)

Re: styles on frontpage

Well, this code works but it gives me errors .
I got these errors:

Notice: Undefined index: action in /home/ju37853/test5.php on line 128

Notice: Undefined index: show in /home/ju37853/test5.php on line 129

Notice: Constant PUN_ROOT already defined in /home/ju37853/forum/extern.php on line 111

Fatal error: Cannot redeclare check_cookie() (previously declared in /home/ju37853/forum/include/functions.php:28) in /home/ju37853/forum/include/functions.php on line 28

The error is caused by include('http://host.com/forums/extern.php?action=active');

Any idea?

Ludo,

5

Re: styles on frontpage

In fact, the problem seem to be linked to the call function:

<?php
$ancien_get_action = $_GET['action'];
$ancien_get_show = $_GET['show'];
$_GET['action'] = 'active';
$_GET['show'] = 8;
include($_SERVER['HTTP_RACINE'] . '/forum/extern.php');
$_GET['action'] = $ancien_get_action;
$_GET['show'] = $ancien_get_show;
?>

Really any idea?

Ludo,

Re: styles on frontpage

I have no idea what the two first errors are about. They seem to emerge from the script test5.php. The other two errors are caused by you including extern.php twice for some reason.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: styles on frontpage

first two errors are from

$ancien_get_action = $_GET['action'];
$ancien_get_show = $_GET['show'];

you should cut it down to

<?php
$_GET['action'] = 'active';
$_GET['show'] = 8;
include($_SERVER['HTTP_RACINE'] . '/forum/extern.php');
?>

also i think the PUN_ROOT and checkcookie errors are because you already included common.php and defined PUN_ROOT at the top of the page?

8

Re: styles on frontpage

The first problem is solved with the code you gave me. You were absolutely right.
Now I only got two errors:

Notice: Constant PUN_ROOT already defined in /home/ju37853/forum/extern.php on line 111

Fatal error: Cannot redeclare check_cookie() (previously declared in /home/ju37853/forum/include/functions.php:28) in /home/ju37853/forum/include/functions.php on line 28

common is called only once. Pun_root is alos called once at the top of the page.
I mean, I just use the code given in this thread:

<?php

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1); 

define('PUN_ROOT','forum/');
require ($_SERVER['HTTP_RACINE'] . '/forum/include/common.php');

if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

if ($pun_user['is_guest'])
    {
        $style = $pun_config['o_default_style'];
    } else {
        $style = $pun_user["style"];
    }
?>

and

<link rel="stylesheet" type="text/css" href="http://www.pluriservices.net/forum/style/<?php echo $style ?>.css">

Is there a solution?

Ludo, wink

Re: styles on frontpage

Rickard said you could skip the style check. And I assume on the page when you call that file, you also call common.php elsewhere wink

Re: styles on frontpage

you can't include extern.php after including common.php

11

Re: styles on frontpage

and there is not any alternative solution?

Ludo,

Re: styles on frontpage

you could put the http path for extern.php if your host allows it to include it as html not php, or put the contents of extern.php where you include it

13

Re: styles on frontpage

Ok, so now, I only got one error with that code in my page:

<?php
// The maximum number of topics that will be displayed
$show_max_topics = 60;

// The length at which topic subjects will be truncated (for HTML output)
$max_subject_length = 25;

// DO NOT EDIT ANYTHING BELOW THIS LINE! (unless you know what you are doing)


@include PUN_ROOT.'config.php';

// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
    exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');


// Disable error reporting for uninitialized variables
error_reporting(E_ALL);

// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);


// Load the functions script
require PUN_ROOT.'include/functions.php';

// Load DB abstraction layer and try to connect
require PUN_ROOT.'include/dblayer/common_db.php';

// Get the forum config
$result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch forum config', __FILE__, __LINE__, 

$db->error());
while ($cur_config_item = $db->fetch_row($result))
    $pun_config[$cur_config_item[0]] = $cur_config_item[1];

// Make sure we (guests) have permission to read the forums
$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', 

__FILE__, __LINE__, $db->error());
if ($db->result($result) == '0')
    exit('No permission');


// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
if (!isset($lang_common))
    exit('There is no valid language pack \''.$pun_config['o_default_lang'].'\' installed. Please reinstall a language of 

that name.');

if (!isset($_GET['action']))
    exit('No parameters supplied. See extern.php for instructions.');


//
// Converts the CDATA end sequence ]]> into ]]>
//
function escape_cdata($str)
{
    return str_replace(']]>', ']]>', $str);
}


//
// Show recent discussions
//
if ($_GET['action'] == 'active' || $_GET['action'] == 'new')
{
    $order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted';
    $forum_sql = '';

    // Was any specific forum ID's supplied?
    if (isset($_GET['fid']) && $_GET['fid'] != '')
    {
        $fids = explode(',', trim($_GET['fid']));
        $fids = array_map('intval', $fids);

        if (!empty($fids))
            $forum_sql = ' AND f.id IN('.implode(',', $fids).')';
    }

    // Any forum ID's to exclude?
    if (isset($_GET['nfid']) && $_GET['nfid'] != '')
    {
        $nfids = explode(',', trim($_GET['nfid']));
        $nfids = array_map('intval', $nfids);

        if (!empty($nfids))
            $forum_sql = ' AND f.id NOT IN('.implode(',', $nfids).')';
    }

    // Should we output this as RSS?
    if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS')
    {
        $rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc 

New'];
        $url_action = ($_GET['action'] == 'active') ? '&action=new' : '';

        // Send XML/no cache headers
        header('Content-Type: text/xml');
        header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');

        // It's time for some syndication!
        echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\r\n";
        echo '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" 

"http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\r\n";
        echo '<rss version="0.91">'."\r\n";
        echo '<channel>'."\r\n";
        echo "\t".'<title>'.pun_htmlspecialchars($pun_config['o_board_title']).'</title>'."\r\n";
        echo "\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n";
        echo "\t".'<description>'.pun_htmlspecialchars($rss_description.' 

'.$pun_config['o_board_title']).'</description>'."\r\n";
        echo "\t".'<language>en-us</language>'."\r\n";

        // Fetch 15 topics
        $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name FROM 

'.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS 

fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS 

NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT 15') or error('Unable to fetch topic list', __FILE__, __LINE__, 

$db->error());

        while ($cur_topic = $db->fetch_assoc($result))
        {
            if ($pun_config['o_censoring'] == '1')
                $cur_topic['subject'] = censor_words($cur_topic['subject']);

            echo "\t".'<item>'."\r\n";
            echo "\t\t".'<title>'.pun_htmlspecialchars($cur_topic['subject']).'</title>'."\r\n";
            echo 

"\t\t".'<link>'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].$url_action.'</link>'."\r\n";
            echo "\t\t".'<description><![CDATA['.escape_cdata($lang_common['Forum'].': <a 

href="'.$pun_config['o_base_url'].'/viewforum.php?id='.$cur_topic['fid'].'">'.$cur_topic['forum_name'].'</a><br 

/>'."\r\n".$lang_common['Author'].': '.$cur_topic['poster'].'<br />'."\r\n".$lang_common['Posted'].': '.date('r', 

$cur_topic['posted']).'<br />'."\r\n".$lang_common['Last post'].': '.date('r', 

$cur_topic['last_post'])).']]></description>'."\r\n";
            echo "\t".'</item>'."\r\n";
        }

        echo '</channel>'."\r\n";
        echo '</rss>';
    }


    // Output regular HTML
    else
    {
        $show = isset($_GET['show']) ? intval($_GET['show']) : 15;
        if ($show < 1 || $show > 50)
            $show = 15;

        // Fetch $show topics
        $result = $db->query('SELECT t.id, t.subject FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums 

AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE 

(fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or 

error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

        while ($cur_topic = $db->fetch_assoc($result))
        {
            if ($pun_config['o_censoring'] == '1')
                $cur_topic['subject'] = censor_words($cur_topic['subject']);

            if (pun_strlen($cur_topic['subject']) > $max_subject_length)
                $subject_truncated = pun_htmlspecialchars(trim(substr($cur_topic['subject'], 0, 

($max_subject_length-5)))).' …';
            else
                $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);

            echo '<li><a 

href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" 

title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a></li>'."\n";
        }
    }

    return;
}

else
    exit('Bad request');
?>

The error I got:

Fatal error: Cannot redeclare check_cookie() (previously declared in /home/ju37853/forum/include/functions.php:28) in /home/ju37853/forum/include/functions.php on line 28

I have to modify anything else?

Ludo,

14

Re: styles on frontpage

functions.php was already required. So, I deleted one.
Now I got a new error, but I do not find how to solve it:

Fatal error: Cannot redeclare class dblayer in /home/ju37853/forum/include/dblayer/mysql.php on line 32

Ludo,

Re: styles on frontpage

rewmove

@include PUN_ROOT.'config.php';

// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
    exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');


// Disable error reporting for uninitialized variables
error_reporting(E_ALL);

// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);


// Load the functions script
require PUN_ROOT.'include/functions.php';

// Load DB abstraction layer and try to connect
require PUN_ROOT.'include/dblayer/common_db.php';

// Get the forum config
$result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch forum config', __FILE__, __LINE__, 

$db->error());
while ($cur_config_item = $db->fetch_row($result))
    $pun_config[$cur_config_item[0]] = $cur_config_item[1];

16 (edited by Ludo 2005-04-18 19:08)

Re: styles on frontpage

I finally solved error problem.
Now, extern.php is in my page.
It tells me:
No parameters supplied. See extern.php for instructions.

What do I have to modify to manually put parameters in extern.php



Ludo,

17

Re: styles on frontpage

I put that before extern's code:
$_GET['action'] = 'active';
$_GET['show'] = 10;
$_GET['nfid'] = 11;

So now, recents discussions are displayed.
The only problem I got is that all the code after extern is not displayed. A problem with return; ?

Ludo,

18

Re: styles on frontpage

To sum up, the code I use is this one:

<?php

$_GET['action'] = 'active';
$_GET['show'] = 10;
$_GET['nfid'] = 11;

// The maximum number of topics that will be displayed
$show_max_topics = 60;

// The length at which topic subjects will be truncated (for HTML output)
$max_subject_length = 28;

// DO NOT EDIT ANYTHING BELOW THIS LINE! (unless you know what you are doing)

// Make sure we (guests) have permission to read the forums
$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', 

__FILE__, __LINE__, $db->error());
if ($db->result($result) == '0')
    exit('No permission');


// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
if (!isset($lang_common))
    exit('There is no valid language pack \''.$pun_config['o_default_lang'].'\' installed. Please reinstall a language of 

that name.');

if (!isset($_GET['action']))
    exit('No parameters supplied. See extern.php for instructions.');


//
// Converts the CDATA end sequence ]]> into ]]>
//
function escape_cdata($str)
{
    return str_replace(']]>', ']]>', $str);
}


//
// Show recent discussions
//
if ($_GET['action'] == 'active' || $_GET['action'] == 'new')
{
    $order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted';
    $forum_sql = '';

    // Was any specific forum ID's supplied?
    if (isset($_GET['fid']) && $_GET['fid'] != '')
    {
        $fids = explode(',', trim($_GET['fid']));
        $fids = array_map('intval', $fids);

        if (!empty($fids))
            $forum_sql = ' AND f.id IN('.implode(',', $fids).')';
    }

    // Any forum ID's to exclude?
    if (isset($_GET['nfid']) && $_GET['nfid'] != '')
    {
        $nfids = explode(',', trim($_GET['nfid']));
        $nfids = array_map('intval', $nfids);

        if (!empty($nfids))
            $forum_sql = ' AND f.id NOT IN('.implode(',', $nfids).')';
    }

    // Should we output this as RSS?
    if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS')
    {
        $rss_description = ($_GET['action'] == 'active') ? $lang_common['RSS Desc Active'] : $lang_common['RSS Desc 

New'];
        $url_action = ($_GET['action'] == 'active') ? '&action=new' : '';

        // Send XML/no cache headers
        header('Content-Type: text/xml');
        header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');

        // It's time for some syndication!
        echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\r\n";
        echo '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" 

"http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\r\n";
        echo '<rss version="0.91">'."\r\n";
        echo '<channel>'."\r\n";
        echo "\t".'<title>'.pun_htmlspecialchars($pun_config['o_board_title']).'</title>'."\r\n";
        echo "\t".'<link>'.$pun_config['o_base_url'].'/</link>'."\r\n";
        echo "\t".'<description>'.pun_htmlspecialchars($rss_description.' 

'.$pun_config['o_board_title']).'</description>'."\r\n";
        echo "\t".'<language>en-us</language>'."\r\n";

        // Fetch 15 topics
        $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name FROM 

'.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS 

fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS 

NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT 15') or error('Unable to fetch topic list', __FILE__, __LINE__, 

$db->error());

        while ($cur_topic = $db->fetch_assoc($result))
        {
            if ($pun_config['o_censoring'] == '1')
                $cur_topic['subject'] = censor_words($cur_topic['subject']);

            echo "\t".'<item>'."\r\n";
            echo "\t\t".'<title>'.pun_htmlspecialchars($cur_topic['subject']).'</title>'."\r\n";
            echo 

"\t\t".'<link>'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].$url_action.'</link>'."\r\n";
            echo "\t\t".'<description><![CDATA['.escape_cdata($lang_common['Forum'].': <a 

href="'.$pun_config['o_base_url'].'/viewforum.php?id='.$cur_topic['fid'].'">'.$cur_topic['forum_name'].'</a><br 

/>'."\r\n".$lang_common['Author'].': '.$cur_topic['poster'].'<br />'."\r\n".$lang_common['Posted'].': '.date('r', 

$cur_topic['posted']).'<br />'."\r\n".$lang_common['Last post'].': '.date('r', 

$cur_topic['last_post'])).']]></description>'."\r\n";
            echo "\t".'</item>'."\r\n";
        }

        echo '</channel>'."\r\n";
        echo '</rss>';
    }


    // Output regular HTML
    else
    {
        $show = isset($_GET['show']) ? intval($_GET['show']) : 15;
        if ($show < 1 || $show > 50)
            $show = 15;

        // Fetch $show topics
        $result = $db->query('SELECT t.id, t.subject FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums 

AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE 

(fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or 

error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

        while ($cur_topic = $db->fetch_assoc($result))
        {
            if ($pun_config['o_censoring'] == '1')
                $cur_topic['subject'] = censor_words($cur_topic['subject']);

            if (pun_strlen($cur_topic['subject']) > $max_subject_length)
                $subject_truncated = pun_htmlspecialchars(trim(substr($cur_topic['subject'], 0, 

($max_subject_length-5)))).' …';
            else
                $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);

            echo '<li><a 

href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" 

title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a></li>'."\n";
        }
    }

    return;
}


else
    exit('Bad request');




?>

This code seems not to allow anything to be displayed after.
I remember I had a similary problem. I told Rickard that exit; should be replaced by return; which was done.
But now, I really do not see where the problem comes from.

Ludo,

19

Re: styles on frontpage

I finally solved the problem alone.
I just get rid off the last return;
I hope this will not cause any security problem.

Ludo,