<?
//recuperation of config variables
include ("$DOCUMENT_ROOT/config_easysite.inc");
// useful for handling templates
include ("$EASYSITE_BASE/include/class.FastTemplate.php");
function make_page_with_content($contenu, $directory, $title, $message = '',$skin = '')
{
$DOCUMENT_ROOT = $GLOBALS["DOCUMENT_ROOT"];
//recuperation of config variables
include ("$DOCUMENT_ROOT/config_easysite.inc");
if (strcmp($skin,'') == 0)
{
$HTTP_COOKIE_VARS = $GLOBALS["HTTP_COOKIE_VARS"];
//fetch the user's chosen skin by looking into his precedent sended cookie
$CHOSEN_SKIN = $HTTP_COOKIE_VARS["CHOSEN_SKIN"];
//use default template if no skin was precedently chosen
if (strcmp($CHOSEN_SKIN,'') == 0)
$CHOSEN_SKIN = 'default';
}
else
$CHOSEN_SKIN = $skin;
$template_dir = "$EASYSITE_BASE/skins/$CHOSEN_SKIN/templates";
if (!is_dir ($template_dir))
{
// means that the cookie is set but contains a bad values
//reset the skin to default
$CHOSEN_SKIN = 'default';
}
// templates importation
$tpl = new FastTemplate("$EASYSITE_BASE/skins/$CHOSEN_SKIN/templates");
// the different templates in use
$tpl->define(
array
(
general => 'table_general.tpl',
rubrique => 'categorie.tpl',
lien => 'link.tpl',
header => 'header.tpl'
)
);
// we add the content of an eventual additional piece of html code
$contenu = $message . $contenu;
/* fetching of the other files presence and of the directory that are present */
$dh = opendir($directory);
while ($file = readdir ($dh))
{
if (is_dir("$directory/$file") && strcmp($file,'.') != 0 && strcmp($file,'..') != 0)
{
$categories[] = $file;
}
elseif (eregi("php$",$file))
{
$liens[] = $file;
}
}
closedir($dh);
/* making of the communication links of the left column of the page */
if ($liens)
{
while (list($key,$value) = each($liens))
{
$temp = explode(".",$value);
$nom = $temp[0];
if (is_file ("$directory/$nom.php"))
{
$lien = ereg_replace($DOCUMENT_ROOT,'',$directory) . '/' . $nom . '.php';
}
else
{
$lien = 'index.php';
}
if (!eregi ("index",$nom))
{
// $length = 12;
// if (strlen($nom) > $length)
// {
// $nom = substr($nom,0,$length) . ' ...';
// }
$nom = ereg_replace ("_"," ",$nom);
$tpl->assign(
array(
NAME=>$nom,
LINK=>$lien
)
);
$tpl->parse(LINKS,".lien");
}
}
$LIENS = $tpl->fetch("LINKS");
}
else
{
$LIENS = '';
}
/* making of the categories (head of the page) */
$nb_rubrique = count ($categories);
if ($categories)
{
reset ($categories);
while (list($key,$value) = each($categories))
{
$repertoire = $value;
$nom = ereg_replace("_"," ",$repertoire);
$directory_rel = ereg_replace($DOCUMENT_ROOT,'',$directory);
$directory_rel = '/' . ereg_replace("^/{1,2}","",$directory_rel);
$tpl->assign(
array
(
DIRECTORY => "$directory_rel/$repertoire/index.php",
CATEGORIE_IMAGE => $image,
DIRECTORY_NAME => $nom
)
);
$tpl->parse(CATEGORIE,".rubrique");
}
}
else
{
$tpl->assign(
array(
CATEGORIE => ''
)
);
}
//fetching the base variable content (relative path to the chosen skins)
$BASE = ereg_replace("$DOCUMENT_ROOT","",$EASYSITE_BASE) . '/skins/' . $CHOSEN_SKIN;
$inter = ereg_replace("$EASYSITE_BASE/","", $directory);
$tab = explode ("/",$inter);
$sum = $RELATIVE_PATH . '/';
for ($i=0;$i < count($tab);$i ++)
{
$sum = $sum . $tab[$i] . '/';
$LINK_POINTS .= "<a href=$sum" . "index.php>" . ereg_replace("_"," ",$tab[$i]) . "</a>";
if ($i != count($tab) - 1)
$LINK_POINTS .= " > ";
}
/* the rest of the page is made here */
$tpl->assign(
array (
LINKS => $LIENS,
NB_CATEGORIE => $nb_rubrique + 1,
TITLE => $title,
WEBMASTER_EMAIL => $WEBMASTER_EMAIL,
ADRESS => $ADRESS,
URL => $URL,
PHONE => $PHONE,
BASE => $BASE,
LINK_POINTS => $LINK_POINTS,
RELATIVE_PATH => $RELATIVE_PATH,
CONTENT => $contenu
)
);
$tpl->parse(BODY,"general");
//the message testing is given when building an other template
if (strcmp($message,'testing') == 0)
{
return($tpl->fetch("BODY"));
}
else
{
$tpl->parse(OUT,"header");
$tpl->FastPrint("OUT");
}
}
// storing of the visitors information in the mysql database
// means that a database is installed
if (strcmp($DATABASE_TYPE,"") != 0)
{
include "$EASYSITE_BASE/include/database_specific_config/connexion_$DATABASE_TYPE.inc";
$connection = connection($DATABASE_NAME,$DATABASE_USER,$DATABASE_USER_PASSWORD,$DATABASE_HOST);
$sql = "insert into hit (redirect_status,http_user_agent,http_via,remote_host,redirect_url,server_protocol
,request_method,query_string, http_referer, date) values ('$REDIRECT_STATUS','$HTTP_USER_AGENT','$HTTP_VIA','$REMOTE_HOST',
'$REDIRECT_URL','$SERVER_PROTOCOL','$REQUEST_METHOD','$QUERY_STRING','$HTTP_REFERER',
NOW())";
requette($DATABASE_NAME,$connection,$sql);
deconnection($connection);
}
// this fonction takes the content of your html pages and add to it the
// "meat" to make as a result a good looking page
function faire_page($fichier, $message = '',$skin='')
{
/* fetching of the content of the html file */
$fh = fopen($fichier,"r");
$contenu = fread($fh,filesize($fichier));
fclose($fh);
// construct the title of the page from the name of the file, for example
// "destruction.html" will give "destruction" as title
$title = explode(".", basename($fichier));
$title = ereg_replace("_", " ", $title[0]);
$directory = dirname($fichier);
return (make_page_with_content($contenu, $directory, $title, $message,$skin));
}
?>