Skip to content

Instantly share code, notes, and snippets.

@heinrich5991
Forked from FT45/config.php
Created December 15, 2010 15:20
Show Gist options
  • Save heinrich5991/742070 to your computer and use it in GitHub Desktop.
Save heinrich5991/742070 to your computer and use it in GitHub Desktop.
<?php
// Pathes
define('INC_PATH', 'inc/');
define('DL_PATH', 'downloads/');
define('PAGE_PATH', 'page/');
define('SLIDE_PATH', 'img/slide/');
// Teeworlds Version
define('CURRENT_VERSION', '0.5.2');
// MySql
define('HOST', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'teeworldsde');
?>
<meta name="description" content="{< description >}" />
<meta name="keywords" content="{< keywords >}" />
<meta name="author" content="{< author >}" />
<meta charset="{< charset >}" />
<title>Teeworlds.de - {< title >}</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/header.css" rel="stylesheet" type="text/css">
<link href="css/content.css" rel="stylesheet" type="text/css">
<link href="css/forms.css" rel="stylesheet" type="text/css">
<link href="css/menu.css" rel="stylesheet" type="text/css">
<link href="css/footer.css" rel="stylesheet" type="text/css">
<script src="jquery/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery/jquery.faded.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery/jquery.scroll.js" type="text/javascript" charset="utf-8"></script>
<header></header>
{< irc >}
<section class="content">
{< announcment >}
{< content_top >}
{< content_slide >}
{< content_text >}
</section>
<footer></footer>
{< skript >}
{< ads >}
<?php
include_once( 'config.php');
//Klasse definieren
include_once( INC_PATH . 'main.php');
$page = new page();
// Zu MySql verbinden
$page->mysql(HOST, USERNAME, PASSWORD, DATABASE);
?>
<!DOCTYPE HTML>
<html>
<?php
$page->show($_GET['page'], $_GET['id']);
?>
</html>
<?php
class page {
// Pfad zu '$page'
private $file;
// Allgemeine Informationen zur Seite
private $page;
public $id;
// Meta
public $meta;
function mysql($host, $username, $password, $database) {
$con = mysql_connect($host,$username,$password);
if (!$con):
die('Keine Verbindung zu MySql möglich: ' . mysql_error());
endif;
mysql_select_db($database, $con) or die('Database!');
}
public function show($_page='', $_id='') {
// Entfernt Whitespaces (oder andere Zeichen) am Anfang und Ende eines Strings
$page = trim($_page);
$id = trim($_id);
if($this->whitelist($page) == false):
echo '<p><b>Diese Seite ist nicht erlaubt.</b></p>';
break;
endif;
// Variable '$page' wird gespeichert.
if($page == ''):
$this->page = 'index'
else:
$this->page = $page;
endif;
// Variable '$id' wird gespeichert.
$this->id = settype($id, "integer");
if(is_int($id)):
echo 'Die \'ID\' muss eine Zahl sein!';
endif;
// Variable '$file' wird gespeichert.
$this->file = PAGE_PATH;
$this->file .= $this->page . '.php';
// Überprüfen, ob eine Datei mit dem Pfad und Namen: '$file' existiert.
if(file_exists($this->file)):
// Überprüfen, ob diese Datei lesbar ist.
if(is_readable($this->file)):
$this->get_meta($this->page);
echo '<head>';
include_once('head.php');
echo '</head>';
echo '<body>';
include_once($this->file);
echo '</body>';
else:
echo '<p><b>Der Inhalt der Seite konnte nicht gelesen werden.</b></p>';
endif;
else:
echo '<p><b>Sie haben einen ung&uuml;ltigen oder falschen Link aufgerufen.</b></p>';
endif;
}
public function whitelist($page) {
$erlaubte_seiten = array
(
'index',
'wiki'
);
if(in_array( $seite, $erlaubte_seiten)):
return true;
else:
return false;
endif;
}
private function get_meta($_page) {
$this->meta = array();
// Kleiner Schutz gegen Hacker
$page = mysql_real_escape_string($_page);
$result = mysql_query("SELECT * FROM page WHERE _title = '$page'");
if(mysql_num_rows($this->result) != 0):
$row = mysql_fetch_array($result);
$this->meta['title'] = $row['title'];
$this->meta['description'] = $row['description'];
$this->meta['author'] = row['author'];
$this->meta['charset'] = $row['charset'];
else:
$this->meta['title'] = 'Error!';
$this->meta['description'] = 'Error!';
$this->meta['author'] = 'Teeworlds.de';
$this->meta['charset'] = 'utf-8';
endif;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment