<?php
/*
File name : includes/common.php
Program : phpore
Author : Jérémy FAIVRE (docteur.night)
Email : docteurnight@hotmail.com
Last modification : //
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.
*/
{
}
//
// constantes
//
define('CLASSES_TABLE', $config->table_prefix . 'classes'); define('CHATBOX_TABLE', $config->table_prefix . 'chatbox'); define('CONFIG_TABLE', $config->table_prefix . 'config'); define('EVENTS_TABLE', $config->table_prefix . 'events'); define('MAPS_TABLE', $config->table_prefix . 'maps'); define('TILESETS_TABLE', $config->table_prefix . 'tilesets'); define('USERS_TABLE', $config->table_prefix . 'users'); define('VARS_TABLE', $config->table_prefix . 'vars');
//
// fonctions
//
// met en cache une variable
function create_cache($var_name)
{
$file = '<?php' . "\n\n" . 'if ( !defined(\'IN_PHPORE\') )' . "\n" . '{' . "\n\t" . 'exit;' . "\n" . '}' . "\n\n" . '$' . $var_name . ' = unserialize(\'' . quotes
(serialize($$var_name)) . '\');' . "\n\n" . '?>';
$handle = fopen($config->path . $config->cache_dir . 'data_' . md5($var_name) . '.' . $config->phpex, 'w+'); $result = fwrite($handle, $file);
return $result;
}
// récupčre une variable mise en cache
function get_cache($var_name)
{
if ( is_file($config->path . $config->cache_dir . 'data_' . $var_name . '.' . $config->phpex) ) {
include($config->path . $config->cache_dir . 'data_' . $var_name . '.' . $config->phpex);
return true;
}
else
{
return false;
}
}
// la fonction inverse de htmlspecialchars()
function htmlspecialchars_decode($text)
{
return strtr($text, array_flip(get_html_translation_table
(HTML_SPECIALCHARS
))); }
// remplace "'" par "\'" et "\" par "\\" pour utiliser des chaines sous la forme 'voici ma chaine : \'ma chaine\''
function quotes($text)
{
}
// retourne du code javascript lors d'un rafraichissement
function js_eval($content, $id, $type = 0)
{
$user->update_db();
$config->update_db();
if ( !empty($buffer) ) // erreur dans le script {
$content = 'document.write(\'' . quotes($buffer) . '\');' . $content;
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate');
$refresh_forcing = ( !empty($_GET['refresh_forcing']) ) ?
true : false;
if ( $type == 1 )
{
// rafraichissement par fenętre dans panneau d'admin
die('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Style-Type" content="text/css" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title></title></head><body><script type="text/javascript">window.opener.parent.main.content_to_refresh_' . $id . ' = \'' . quotes
($content) . '\';window.close();</script></body></html>'); }
elseif ( $type == 2 )
{
die('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Style-Type" content="text/css" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title></title></head><body><script type="text/javascript">' . $content . '</script></body></html>'); }
else
{
if ( $config->refresh_method == 0 || $refresh_forcing )
{
// rafraichissement par iframe
die('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Style-Type" content="text/css" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title></title></head><body><script type="text/javascript">parent.content_to_refresh_' . $id . ' = \'' . quotes
($content) . '\';</script></body></html>'); }
else
{
// rafraichissement par XMLHttpRequest
die(utf8_encode
($content)); }
}
}
// création rapide d'une page pour afficher un message de notification ou d'erreur
function message_die($title, $content)
{
global $template, $user, $config;
if ( isset($_GET['mod']) && substr($_GET['mod'], 0, 6) == 'admin.' ) {
$template->set_filenames(array( 'header' => 'admin_header.tpl',
'footer' => 'admin_footer.tpl',
'body' => 'die.tpl'
));
}
else
{
$template->set_filenames(array( 'header' => 'page_header.tpl',
'footer' => 'page_footer.tpl',
'body' => 'die.tpl'
));
}
$template->assign_vars(array( 'PAGE_NAME' => $title,
'DIE_TITLE' => $title,
'DIE_CONTENT' => $content
));
$template->pparse('header');
$template->pparse('body');
$template->pparse('footer');
$user->update_db();
$config->update_db();
}