/*
* TEMPLATE.inc.php - Bevat de klassen Template en CachedTemplate
*
* Template.inc.php is gebaseerd op het werk van Brian Lozier (brian@massassi.net)
* Check http://www.massassi.com/php/articles/template_engines/ voor het originele document
* Verschillende aanpassingen zijn gemaakt door Jurrie Overgoor
*
* NOTE: CachedTemplate nog niet bekeken!
*/
if (!defined('IN_SITE'))
die("Hacking attempt");
@session_start();
//Template GET var in session zetten
if (isset($_GET['template'])) {
$template = $_GET['template'];
if (!is_dir("templates/" . $template)) {
die("Error: unknown template '$template'.");
}
else {
$_SESSION['template'] = $template;
}
}
//Haal configuratie instellingen op, en maak voor elke arraywaarde een constante aan
require_once('config.inc.php');
while (list($key, $val) = each($config)) {
preg_match_all('/%([a-zA-Z0-9-_]+)%/i', $val, $tags);
foreach($tags[1] as $tag) {
$tag = strtoupper($tag);
if ($tag == "YEAR") {
$val = preg_replace('/%('.$tag.')%/i', date("Y"), $val);
}
}
//template constante vervangen indien template GET var gegeven is
if (strtoupper($key) == "TEMPLATE") {
if (isset($_SESSION['template'])) {
$val = $_SESSION['template'];
}
}
define(strtoupper($key), $val);
}
//maak constante van relatief pad naar templates dir
//define("TEMPLATE_PATH", PATH . "/" . TEMPLATE . "/");
define("TEMPLATE_PATH", PATH . "/templates/");
//Stel locale in naar config-waarde
//setlocale(LC_ALL, LOCALE);
class Template {
var $vars; // Holds all the template variables
var $templates; // Holds all the template files we need to load in sequence
/**
* Constructor
*
* NOTE: You do not have to give a template file. If you don't, make sure you load one later on using prependTemplate or appendTemplate.
*
* @param $file string The template you want to load
*/
function Template($file = null)
{
if ($file != null)
$this->appendTemplate($file);
else
$this->templates = null;
}
function setAdmin($bool) {
define("ADMIN", $bool);
}
/**
* prependTemplate - Puts a new template file at the beginning of the queue
*
* @param $file string The template you want to load (just say 'main_body', instead of 'templates/main_body.tpl')
*/
function prependTemplate($file)
{
if ((defined("ADMIN")) && (ADMIN == TRUE)) {
$prefix = "templates/";
}
else {
$prefix = "templates/";
}
if (file_exists($prefix.$file))
array_unshift($this->templates, $prefix.$file);
else
echo "Template.inc.php: prependTemplate called with: " . $file . " - It doesn't exist!";
}
/**
* appendTemplate - Puts a new template file at the end of the queue
*
* @param $file string The template you want to load
*/
function appendTemplate($file)
{
if ((defined("ADMIN")) && (ADMIN == TRUE)) {
$prefix = "templates/";
}
else {
$prefix = "";
}
if (file_exists($prefix.$file))
$this->templates[] = $prefix.$file;
else
echo "Template.inc.php: appendTemplate called with: " . $file . " - It doesn't exist!";
}
/**
* setVar - Set a template variable
*
* @param $name string The name of the template variable to set
* @param $value string The value of the template variable to set
*/
function setVar($name, $value)
{
if (is_object($value) && is_a($value, 'Template')) // Support for nested templates - NOTE: 'is_a' is deprecated as of PHP5 (use 'instanceof')
$this->vars[$name] = $value->fetch();
else
$this->vars[$name] = $value;
}
/**
* setVar - Sets multiple template variables
*
* @param $vars array A key/value pair array. The keys are the variable names, the values the variable values.
*/
function setVars($vars)
{
foreach ($vars as $name => $value)
$this->setVar($name, $value);
}
/**
* isVarSet - Returns wheter or not a template variable was set
*
* If a variable is NULL, isSet returns FALSE
*
* @param $name string The name of the variable to test
* @returns TRUE if the variable was set, FALSE otherwise
*/
function isVarSet($name)
{
return isset($this->vars[$name]);
}
/**
* getVar - Returns the value of a set template variable
*
* If isVarSet($name) == FALSE, we return NULL
*
* @param $name string The name of the template variable
* @returns The value of the variable if the variable was set, NULL otherwise
*/
function getVar($name)
{
return (isVarSet($name) ? $this->vars[$name] : NULL);
}
/**
* parse - Returns the parsed template
*
* This function opens all the template files in sequence, and parses them.
*
* @returns The parsed template as a string, ready for printing to the browser
*/
function parse()
{
if (count($this->templates) == 0)
{
echo "Template.inc.php: parse called without any valid templates loaded!";
return FALSE;
}
extract($this->vars); // Extract the vars to local namespace
ob_start(); // Start output buffering
foreach ($this->templates as $file)
include($file); // Include the file
$contents = ob_get_contents(); // Get the contents of the buffer
ob_end_clean(); // End buffering and discard
return $contents; // Return the contents
}
}
/**
* An extension to Template that provides automatic caching of
* template contents.
*/
class CachedTemplate extends Template {
var $cache_id;
var $expire;
var $cached;
/**
* Constructor.
*
* @param $cache_id string unique cache identifier
* @param $expire int number of seconds the cache will live
*/
function CachedTemplate($cache_id = null, $expire = 900) {
$this->Template();
$this->cache_id = $cache_id ? 'cache/' . md5($cache_id) : $cache_id;
$this->expire = $expire;
}
/**
* Test to see whether the currently loaded cache_id has a valid
* corrosponding cache file.
*/
function is_cached() {
if($this->cached) return true;
// Passed a cache_id?
if(!$this->cache_id) return false;
// Cache file exists?
if(!file_exists($this->cache_id)) return false;
// Can get the time of the file?
if(!($mtime = filemtime($this->cache_id))) return false;
// Cache expired?
if(($mtime + $this->expire) < time()) {
@unlink($this->cache_id);
return false;
}
else {
/**
* Cache the results of this is_cached() call. Why? So
* we don't have to double the overhead for each template.
* If we didn't cache, it would be hitting the file system
* twice as much (file_exists() & filemtime() [twice each]).
*/
$this->cached = true;
return true;
}
}
/**
* This function returns a cached copy of a template (if it exists),
* otherwise, it parses it as normal and caches the content.
*
* @param $file string the template file
*/
function fetch_cache($file) {
if($this->is_cached()) {
$fp = @fopen($this->cache_id, 'r');
$contents = fread($fp, filesize($this->cache_id));
fclose($fp);
return $contents;
}
else {
$contents = $this->fetch($file);
// Write the cache
if($fp = @fopen($this->cache_id, 'w')) {
fwrite($fp, $contents);
fclose($fp);
}
else {
die('Unable to write cache.');
}
return $contents;
}
}
}
?>
/* functions.inc.php
*
* Contains general configuration settings, variables and functions
* Attention: includes/db.inc.php must be called!
*/
@session_start();
//Website Offline
/*
if ((OFFLINE == TRUE) && (!ereg("offline\.php", $_SERVER['REQUEST_URI'])) && (!ereg("admin", $_SERVER['REQUEST_URI']))) {
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/offline.php");
}
*/
//Vervangt smilie-code door smilies
/*
function smile($string) {
$dbResult = db_query("SELECT id, code, smile_url, emoticon FROM `smilies` ORDER BY smilies_order ASC");
for ($i = 0 ; $i < db_num_rows($dbResult); $i++) {
$smilies[$i] = db_fetch_assoc($dbResult);
}
$string = str_replace(":`(", ":'(", $string);
$string = str_replace(":|", ":{", $string);
for($i = 0; $i < count($smilies); $i++) {
$code = $smilies[$i]['code'];
$src = TEMPLATE_PATH . "images/smilies/" . $smilies[$i]['smile_url'];
$alt = $smilies[$i]['emoticon'];
$string = str_replace($code, "", $string);
}
return $string;
echo mysql_error();
}
*/
//BBcode
/*
function bbcode($string) {
$string = str_replace("\n", "
", $string);
$string = preg_replace("/\[b\](.*?)\[\/b\]/si", "\\1", $string);
$string = preg_replace("/\[i\](.*?)\[\/i\]/si", "\\1", $string);
$string = preg_replace("#\[email\](.*?)\[/email\]#si", "\\1", $string);
$string = preg_replace("/\[u\](.*?)\[\/u\]/si", "\\1", $string);
$string = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "\\2", $string);
$string = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "\\3", $string);
$string = preg_replace("/\[code\](.*?)\[\/code\]/si",
"
Code: |
\\1 |
Quote:
\\1", $string); $string = preg_replace("/\[quote=(.*)\](.*?)\[\/quote\]/si", "
\\1 schreef:
\\2", $string); return $string; } //Strip BBcode function stripBBcode($string) { $string = preg_replace("/\[b\](.*?)\[\/b\]/si", "\\1", $string); $string = preg_replace("/\[i\](.*?)\[\/i\]/si", "\\1", $string); $string = preg_replace("#\[email\](.*?)\[/email\]#si", "\\1", $string); $string = preg_replace("/\[u\](.*?)\[\/u\]/si", "\\1", $string); $string = preg_replace("#\[url\](http://)?(.*?)\[/url\]#si", "\\2", $string); $string = preg_replace("#\[url=(http://)?(.*?)\](.*?)\[/url\]#si", "\\3", $string); $string = preg_replace("/\[code\](.*?)\[\/code\]/si", "[code]", $string); $string = preg_replace("/\[quote\](.*?)\[\/quote\]/si", "", $string); return($string); } */ //Embed YouTube Video's met bb-code function youtube($string) { $youtube = " \n
Code: |
\\1 |
Quote:
\\1", $string); $string = preg_replace("/\[quote=(.*)\](.*?)\[\/quote\]/si", "
\\1 schreef:
\\2", $string); $string = youtube($string); $string = flv($string); //$string = mov($sting); $string = mp3($string); return $string; } //Converteert html naar bbcode function html_to_bbcode($string) { // // Function convert HTML to BBCode // (C) DeViAnThans3 - 2005 // $string = str_replace("\n", "", $string); $from[] = '~
(.*?)<\/p>~is';
$from[] = '~(.*?)<\/del>~is';
$from[] = '~
", "\n", $string);
return $string;
}
//converteert relatieve urls in een string naar absolute urls
function relative_to_absolute($string) {
$from[] = '~~is';
$from[] = '~~is';
$to[] = '';
$to[] = '
';
$string = preg_replace($from, $to, $string);
return $string;
}
//formatteer getallen naar Nederlandse schrijfwijze.
function nl_format($nummer) {
$fnummer = number_format($nummer, 2, ',', '.');
return $fnummer;
}
//Converteert een datetime waarde naar waarde uit configuratie
function convert_date($date_format, $date=null) {
if (isset($date)) {
$date = strtotime($date);
$date = strftime($date_format, $date);
}
else $date = strftime($date_format);
return $date;
}
//Functie om Checked status van Radio button vast te leggen
function setChecked($option, $value) {
if ($option == $value) {
return "checked=\"checked\"";
}
}
//Functie om Selected status van selectbox vast te leggen
function setSelect($option, $value) {
if ($option == $value) {
return "selected=\"selected\"";
}
}
function random_string($len=8,$num=True) {
mt_srand(microtime() * 1000000);
for($password='';strlen($password)<$len;){
if (!mt_rand(0,2) && $num) {
$password.=chr(mt_rand(48,57));
} else if (!mt_rand(0,1)) {
$password.=chr(mt_rand(65,90));
} else {
$password.=chr(mt_rand(97,122));
}
}
return $password;
}
function random_number($len=8) {
for ($string='';strlen($string)<$len;) {
if ($string == '') {
$string .= mt_rand(1, 9);
}
else {
$string .= mt_rand(0, 9);
}
}
return $string;
}
//functie om snel de content van een array formatted te kunnen bekijken
function print_array($array) {
echo "
";
print_r($array);
echo "
";
}
//Zet text tussen procenttekens om naar bijbehorende Config constante waarde, mits deze bestaat
//Gebruik in tekst: %SITE_NAME%
function constant_text($string) {
preg_match_all('/%([a-zA-Z0-9-_]+)%/i', $string, $tags);
foreach($tags[1] as $tag) {
$tag = strtoupper($tag);
if ($tag == "YEAR") {
$string = preg_replace('/%('.$tag.')%/i', date("Y"), $string);
}
elseif ($tag == "USERNAME") {
if (isset($_SESSION['user'])) {
$username = $_SESSION['user'];
}
else {
$username = "gast";
}
$string = preg_replace('/%('.$tag.')%/i', $username, $string);
}
elseif (defined($tag)) {
$constant = constant($tag);
$string = preg_replace('/%('.$tag.')%/i', $constant, $string);
}
}
return $string;
}
function parseUrls($text) {
/*
$text = @eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1', $text);
$text = @eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1\\2', $text);
$text = @eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','\\1', $text);
*/
$pattern = '/(?i)(((https?|ftp|gopher):\/\/([^:]+\:[^@]*@)?)?([\d\w\-]+\.)?[\w\d\-\.]+\.[\w\d]+((\/[\w\d\-@%]+)*(\/([\w\d\.\_\-@]+\.[\w\d]+)?(\?[\w\d\?%,\.\/\##!@:=\+~_\-&]*(?\\1';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
?>
/* init.inc.php - Initial startup script */
/*
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ie6 = true;
if (strpos($user_agent, "MSIE 6") === false) {
$ie6 = false;
}
$path = PATH . "templates/images/";
if ($ie6 == true) {
$path .= "ie6/";
}
*/
//Change active state of menu items
function currentpage($current, $check) {
if ($current == $check) {
return "class = \"current\"";
}
}
//Parses textarea fields in config file correctly. With hyperlink parsing.
function parseConfigText($text) {
$text = nl2br($text);
$text = parseUrls($text);
return $text;
}
//Parse submenu for categories
function parseMenu() {
$menu = "";
$dbResult = db_query("SELECT url_name, name FROM categories WHERE published = 1 ORDER BY sorting DESC");
if (@db_num_rows($dbResult) != 0) {
$menu = "\n";
for ($i = 0; $i < db_num_rows($dbResult); $i++) {
$url_name = db_result($dbResult, $i, 0);
$name = htmlentities(db_result($dbResult, $i, 1), ENT_QUOTES, "UTF-8");
$menu .= "
\n";
return $menu;
}
}
/*
if (OFFLINE == TRUE) {
$page = new Template('templates/header.tpl');
$page->setVar('pageTitle', OFFLINE_TITLE);
$page->appendTemplate("templates/static.tpl");
$page->setVar('name', OFFLINE_TITLE);
$page->setVar('current', "");
$page->setVar('body', OFFLINE_TEXT);
$page->appendTemplate('templates/footer.tpl');
print $page->parse();
exit();
}
*/
/*
//Homepage texts
$homepage = "";
$dbResult = db_query("SELECT name, body FROM homepage ORDER BY id ASC");
for ($i = 0; $i < db_num_rows($dbResult); $i++) {
$name = db_result($dbResult, $i, 0);
$body = db_result($dbResult, $i, 1);
$homepage[$name] = $body;
}
define('FOOTER_LEFT', $homepage['footer_left']);
define('FOOTER_RIGHT', $homepage['footer_right']);
*/
?>
Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in /home/deb55154/domains/toneeluitgeverijpodium.nl/public_html/index.php:24
Stack trace:
#0 {main}
thrown in /home/deb55154/domains/toneeluitgeverijpodium.nl/public_html/index.php on line 24