All pastes #618979 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-07-14 10:34 UTC
rendered paste body
<?php
    /** 
    * $Id $
    * vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
    *
    * This file is part of GNOPASTE
    *
    * @author   GNOPASTE Development Team <devel@ghcif.de>
    * @since    19/01/2005
    * @version  $Revision $
    *
    * Copyright (C) 2004-2007 by ghcif.de <devel@ghcif.de>
    *   
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful, 
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    */  


    /**
    * access check
    */
    if(!defined('IN_GNP')) {
        die('access denied!');
    }


    /**
    * error reporting
    */
    error_reporting(E_ALL);

    /**
    * generation time
    */
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime;


    /**
    * start caching 
    */
    ob_start();


    /**
    * if install file exists the script will die
    */
    if(file_exists('install.php'))
    {
        die('you have to install the script first!');
    }
    
    /**
    *  define session und sessionvars
    */
    session_start();
    if(!isset($_SESSION['name']))
    {
        $_SESSION['name'] = '';
    }
    if(!isset($_SESSION['tab_length']))
    {
        $_SESSION['tab_length'] = '';
    }
    if(!isset($_SESSION['code_lang']))
    {                                                       
        $_SESSION['code_lang'] = '';                                       
    }
    if(!isset($_SESSION['description']))
    {
        $_SESSION['description'] = '';
    }
    if(!isset($_SESSION['code']))
    {
        $_SESSION['code'] = '';
    }

    /**
    * includes
    */
    require_once(GNP_REAL_PATH . 'config.php');

    /**
    * connect to db
    */
    mysql_connect($dbhost, $dbuser, $dbpasswd) OR die(mysql_error());
    mysql_select_db($dbdatabase) OR die(mysql_error());

    /**
    * read config 
    */
    $sql = 'SELECT * FROM '.$tbl_prefix.'config;';  
    $query = mysql_query($sql) OR die(mysql_error());
    while($row = mysql_fetch_assoc($query))
    {
        $config[$row['config_name']] = $row['config_value'];
    }
    
    /**
    * load language file
    */
    if(file_exists(GNP_REAL_PATH . 'languages/'.$config['lang'].'_main.php'))   
    {
        include(GNP_REAL_PATH . 'languages/'.$config['lang'].'_main.php');
    }
    else
    {
        include(GNP_REAL_PATH . 'languages/en_main.php');
    }

    header('Content-Type: text/html; charset=' . $lang['charset']);

    /**
    * supported languages array
    */
    $language = array("Plain Text", "C89", "C", "C++", "PHP", "Perl", "Java", "VB", "C#", "Ruby", "Python", "Pascal", "mIRC", "PL/I", "SQL", "XML", "Scheme");
    sort($language);

    /**
    * select optionen for the supported languages
    */
    $lang_option = '';
    foreach($language as $optlang)
    {
        $lang_option .= '<option value="'.$optlang.'"';
        if(isset($_SESSION['code_lang']) AND trim($_SESSION['code_lang']) == $optlang)
        {
            $lang_option .= ' selected="selected"';
        }
        else
        {
            if($optlang == $config['first_selected_lang'])
            {
                $lang_option .= ' selected="selected"';
            }
        }
        $lang_option .= '>'.$optlang.'</option>';
    }

    /**
    * select optionen for the tab width
    */
    $tab_option = '';
    for($i = 0; $i <= 9; $i++)
    {
        $tab_option .= '<option value="'.$i.'"';
        if(is_numeric($_SESSION['tab_length']) AND trim($_SESSION['tab_length']) == $i)
        {
            $tab_option .= ' selected="selected"';
        }
        else
        {
            if($i == $config['std_tab'])
            {
                $tab_option .= ' selected="selected"';
            }
        }
        $tab_option .= '>'.$i.'</option>';
    }
?>