<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: Kiril Threndor <mpnx@dev.illearth.net>                       |
// +----------------------------------------------------------------------+
// $Id: core_GetTheme.php,v 1.16.2.10 2004/08/15 12:57:27 kirilt Exp $

$theme_uri = NULL;
$theme_css = NULL;

if ( ! isset( $GLOBALS['Default_Theme'] ) ) // goBack Function Called Without Defining Config Variables
{
    include './config.php';
    @is_user();
}

// Determine User Theme

$chktheme = ( isset( $GLOBALS['uinf']['theme'] ) && $GLOBALS['uinf']['theme'] != '' && @is_dir( _DP_THEME_PAR . $GLOBALS['uinf']['theme'] ) ) ? ( $GLOBALS['uinf']['theme'] ) : ( $GLOBALS['Default_Theme'] );

// Determine Browser And Load Appropriate Master CSS

if ( ! $_SERVER['ua_sniff'] -> bot && ! $_SERVER['ua_sniff'] -> has_feature( 'css2' ) && $_SERVER['ua_sniff'] -> property( 'maj_ver' ) < 5 )
{
    define( '_T_NN4_THEME', 'nn4_Icey' );
}

if ( ! defined( '_T_NN4_THEME' ) )
{
    if ( $_SERVER['ua_sniff'] -> property( 'maj_ver' ) < 6 && $_SERVER['ua_sniff'] -> property( 'browser' ) == 'ie' )
    {
        define( '_T_USE_TABLES' , (bool)TRUE );
    }

    echo "<link rel='stylesheet' href='" . _URI_CSS_ROOT . "mpn_master.css' type='text/css' />\n";

    define( '_T_NN4_BORDER' , '' );
    define( '_T_UA_VER4' , (bool)FALSE );
}
else
{
    echo "<link rel='stylesheet' href='" . _URI_CSS_ROOT . "mpn_nn4master.css' type='text/css' />\n";

    // Set Some Variables For V4 Theme Loading

    define( '_T_UA_VER4' , (bool)TRUE );
    define( '_T_NN4_BORDER' , 'border="0"' );
    $Default_Theme = _T_NN4_THEME;
}

// Search Theme Array for Theme to Load

$theme_ary = $_SERVER['F_LIB'] -> buildThemeArray();

if ( ! empty( $theme_ary ) )
{
    foreach( $theme_ary as $v )
    {
        $a = $_SERVER['F_LIB'] -> searchMultiArray( $chktheme, $v );
        $b = $_SERVER['F_LIB'] -> searchMultiArray( $GLOBALS['Default_Theme'], $v );

        if ( $a )
        {
            $theme_name = current( $v );
            $theme_path = next( $v );
        }

        if ( $b )
        {
            $Default_Theme_Name = current( $v );
            $Default_Theme_Path = next( $v );
        }
    }

    if ( ! isset( $theme_name ) || ! isset( $theme_path ) )
    {
        $theme_name = $Default_Theme_Name;
        $theme_path = $Default_Theme_Path;
    }
}
else
{
    exit( "\n\n<h1>NO THEMES FOUND!</h1><br /><h2>Please Check Your Theme Options Or Contact Your Administrator</h2>\n\n" );
}

define( '_T_THEME_PATH' , $theme_path );  // Used In footer.php
define( '_T_THEME_NAME' , $theme_name );  // Used In footer.php

// Make Sure Theme exists

if ( ! is_dir( _T_THEME_PATH . 'theme.php' ) )
{
    // Load Page Style If Exists

    if ( defined( '_MPN_PAGE_ID' ) ) { $extStyle = _MPN_PAGE_ID; }

    if ( ! empty( $extStyle ) && is_integer( $extStyle ) )
    {
        pageStyle( $extStyle );
    }
    else
    {
        echo"\n\n<!-- NO PAGE STYLESHEET LOADED -->\n\n";
    }

    // Adjust URI For Theme CSS

    if ( ! _T_UA_VER4 ) // NN4 Theme Directory
    {
        $theme_uri = _URI_THEMES_ROOT . _T_THEME_NAME;
    }
    else
    {
        $theme_uri = _URI_THEMES_NN4 . _T_THEME_NAME;
    }

    // Theme URI for linking CSS and Images

    define( '_T_THEME_URI' , $theme_uri . '/' );
    define( '_T_THEME_CSS' , _T_THEME_PATH . 'style/' );
    define( '_T_THEME_CSS_URI' , _T_THEME_URI . 'style/' );

    // Link The Theme Css File ( theme_name.css or style.css **Context sensitive** )

    if ( is_file( _T_THEME_CSS . _T_THEME_NAME . '.css' ) )
    {
        $theme_css = _T_THEME_NAME . '.css';
    }
    else if ( is_file( _T_THEME_CSS . 'style.css' ) )
    {
        $theme_css = 'style.css';
    }

    if ( ! empty( $theme_css ) )
    {
        define( '_T_THEME_CSS_LINK' , '<link rel="stylesheet" href="' . _T_THEME_CSS_URI . $theme_css . '" type="text/css" />' . "\n" );

        echo _T_THEME_CSS_LINK;
    }
    else
    {
        echo "\n<!-- NO THEME CSS FOUND -->\n";
    }

    // Load The Theme

    require_once _T_THEME_PATH . 'theme.php';

    // Check Theme Variables

    checkThemeVariables();

    if ( defined( '_T_LAYOUT_CSS' ) )
    {
        echo '<link rel="stylesheet" href="' . _URI_CSS_LAYOUT . _T_LAYOUT_CSS . '" type="text/css" />' . "\n";
    }

    require_once _T_THEME_PATH . 'header.php';
}
else // The theme doesn't exist, Exit WIth Error Message
{
    exit( "\n\n<h1>THEME NOT FOUND!</h1><br /><h2>Please Contact Your Administrator</h2>\n\n" );
}

/********** END THEME LOADING ***********/

/**
 * Loads A Page Specific Sytle Sheet
 *
 * @param integer ( Number cooresponding to line number in style_list.txt )
 *
 * return array
 */

function pageStyle( $extStyle )
{
	$file = _DP_THEME_PAR_CSS . 'pages/style_list.txt';

    // read the list and return the appropriate css file name

	if ( ( $page_style = @file( $file ) ) && isset( $page_style[ $extStyle ] ) )
	{
		$linkStyle = '<link rel="stylesheet" href="' . _URI_CSS_PAGE . $page_style[ $extStyle ] . '" type="text/css" />';

		echo $linkStyle . "\n";
	}
	else
    {
        echo"\n\n<!-- NO PAGE STYLESHEET LOADED -->\n\n";
    }

} // End Function pageStyle

/**
 * Check Theme Define Color Variables, Define Them If Not Defined
 *
 * return void
 */

function checkThemeVariables()
{
    global $textcolor1, $textcolor2, $textcolor3, $textcolor4;
    global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4;

    $chk_ary = compact( 'textcolor1', 'textcolor2', 'textcolor3', 'textcolor4', 'bgcolor1', 'bgcolor2', 'bgcolor3', 'bgcolor4' );

    foreach( $chk_ary AS $key => $v )
    {
        if ( empty( $v ) || ! isset( $v ) || $v == '' )
        {
            switch( $key )
            {
                case 'textcolor1': $textcolor1 = '#000000'; break;
                case 'textcolor2': $textcolor2 = '#000000'; break;
                case 'textcolor3': $textcolor3 = '#000000'; break;
                case 'textcolor4': $textcolor4 = '#000000'; break;
                case 'bgcolor1'  : $bgcolor1   = '#FFFF00'; break;
                case 'bgcolor2'  : $bgcolor2   = '#FFFF00'; break;
                case 'bgcolor3'  : $bgcolor3   = '#FFFF00'; break;
                case 'bgcolor4'  : $bgcolor4   = '#FFFF00'; break;
            }
        }
    }

    return;

} // End Function checkThemeVariables

?>
