aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/config.inc.php94
-rw-r--r--include/functions.inc.php286
-rw-r--r--include/functions_category.inc.php481
-rw-r--r--include/functions_session.inc.php135
-rw-r--r--include/functions_user.inc.php302
-rw-r--r--include/index.php7
-rw-r--r--include/init.inc.php38
-rw-r--r--include/user.inc.php93
-rw-r--r--include/vtemplate.class.php519
9 files changed, 1955 insertions, 0 deletions
diff --git a/include/config.inc.php b/include/config.inc.php
new file mode 100644
index 000000000..f0a348a24
--- /dev/null
+++ b/include/config.inc.php
@@ -0,0 +1,94 @@
+<?php
+/***************************************************************************
+ * config.inc.php *
+ * ------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+unset( $conf, $page, $user, $lang );
+$conf = array();
+$page = array();
+$user = array();
+$lang = array();
+
+include_once( PREFIXE_INCLUDE.'./include/mysql.inc.php' );
+include_once( PREFIXE_INCLUDE.'./include/functions.inc.php' );
+include_once( PREFIXE_INCLUDE.'./include/vtemplate.class.php' );
+//
+// How to change the order of display for images in a category ?
+//
+// You have to modify $conf['order_by'].
+// There are several fields that can order the display :
+// - date_available : the date of the adding to the gallery
+// - file : the name of the file
+// Once you've chosen which field(s) to use for ordering,
+// you must chose the ascending or descending order for each field.
+// examples :
+// 1. $conf['order_by'] = " order by date_available desc, file asc";
+// will order pictures by date_available descending & by filename ascending
+// 2. $conf['order_by'] = " order by file asc";
+// will only order pictures by file ascending
+// without taking into account the date_available
+$conf['order_by'] = " order by date_available desc, file asc";
+
+$conf['repertoire_image'] = './images/';
+$conf['nb_image_row'] = array ('4','5','6','7','8');
+$conf['nb_row_page'] = array ('2','3','4','5','6','7','10','20','1000');
+$conf['version'] = '1.3';
+$conf['site_url'] = 'http://www.phpwebgallery.net';
+$conf['forum_url'] = 'http://forum.phpwebgallery.net';
+
+database_connection();
+// rertieving the configuration informations for site
+// $infos array is used to know the fields to retrieve in the table "config"
+// Each field becomes an information of the array $conf.
+// Example :
+// prefixe_thumbnail --> $conf['prefixe_thumbnail']
+$infos = array( 'prefixe_thumbnail', 'webmaster', 'mail_webmaster', 'acces',
+ 'session_id_size', 'session_keyword', 'session_time',
+ 'max_user_listbox', 'show_comments', 'nb_comment_page',
+ 'upload_available', 'upload_maxfilesize', 'upload_maxwidth',
+ 'upload_maxheight', 'upload_maxwidth_thumbnail',
+ 'upload_maxheight_thumbnail' );
+
+$query = 'select';
+for ( $i = 0; $i < sizeof( $infos ); $i++ )
+{
+ if ( $i > 0 )
+ {
+ $query.= ',';
+ }
+ else
+ {
+ $query.= ' ';
+ }
+ $query.= $infos[$i];
+}
+$query .= ' from '.$prefixeTable.'config;';
+
+$row = mysql_fetch_array( mysql_query( $query ) );
+
+// affectation of each field of the table "config" to an information of the
+// array $conf.
+for ( $i = 0; $i < sizeof( $infos ); $i++ )
+{
+ $conf[$infos[$i]] = $row[$infos[$i]];
+ // If the field is true or false, the variable is transformed into a boolean
+ // value.
+ if ( $row[$infos[$i]] == 'true' || $row[$infos[$i]] == 'false' )
+ {
+ $conf[$infos[$i]] = get_boolean( $row[$infos[$i]] );
+ }
+}
+$conf['log'] = false;
+$conf['top_number'] = 10;
+?> \ No newline at end of file
diff --git a/include/functions.inc.php b/include/functions.inc.php
new file mode 100644
index 000000000..a45c4f43d
--- /dev/null
+++ b/include/functions.inc.php
@@ -0,0 +1,286 @@
+<?php
+/***************************************************************************
+ * functions.inc.php *
+ * ------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+include( 'functions_user.inc.php' );
+include( 'functions_session.inc.php' );
+include( 'functions_category.inc.php' );
+
+//----------------------------------------------------------- generic functions
+
+// The function get_boolean transforms a string to a boolean value. If the
+// string is "false" (case insensitive), then the boolean value false is
+// returned. In any other case, true is returned.
+function get_boolean( $string )
+{
+ $boolean = true;
+ if ( preg_match( '/^false$/i', $string ) )
+ {
+ $boolean = false;
+ }
+ return $boolean;
+}
+
+// The function array_remove removes a value from the given array if the value
+// existed in this array.
+function array_remove( $array, $value )
+{
+ $i = 0;
+ $output = array();
+ foreach ( $array as $v )
+ {
+ if ( $v != $value )
+ {
+ $output[$i++] = $v;
+ }
+ }
+ return implode( ',', $output );
+}
+
+// The function get_moment returns a float value coresponding to the number
+// of seconds since the unix epoch (1st January 1970) and the microseconds
+// are precised : e.g. 1052343429.89276600
+function get_moment()
+{
+ $t1 = explode( " ", microtime() );
+ $t2 = explode( ".", $t1[0] );
+ $t2 = $t1[1].".".$t2[1];
+ return $t2;
+}
+
+// The function get_elapsed_time returns the number of seconds (with 3
+// decimals precision) between the start time and the end time given.
+function get_elapsed_time( $start, $end )
+{
+ return number_format( $end - $start, 3, '.', ' ').' s';
+}
+
+// - The replace_space function replaces space and '-' characters
+// by their HTML equivalent &nbsb; and &minus;
+// - The function does not replace characters in HTML tags
+// - This function was created because IE5 does not respect the
+// CSS "white-space: nowrap;" property unless space and minus
+// characters are replaced like this function does.
+function replace_space( $string )
+{
+ //return $string;
+ $return_string = "";
+ $remaining = $string;
+
+ $start = 0;
+ $end = 0;
+ $start = strpos ( $remaining, "<" );
+ $end = strpos ( $remaining, ">" );
+ while ( is_numeric( $start ) and is_numeric( $end ) )
+ {
+ $treatment = substr ( $remaining, 0, $start );
+ $treatment = str_replace( " ", "&nbsp;", $treatment );
+ $treatment = str_replace( "-", "&minus;", $treatment );
+ $return_string.= $treatment.substr ( $remaining, $start,
+ $end - $start + 1 );
+ $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
+ $start = strpos ( $remaining, "<" );
+ $end = strpos ( $remaining, ">" );
+ }
+ $treatment = str_replace( " ", "&nbsp;", $remaining );
+ $treatment = str_replace( "-", "&minus;", $treatment );
+ $return_string.= $treatment;
+
+ return $return_string;
+}
+
+// get_dirs retourne un tableau contenant tous les sous-répertoires d'un
+// répertoire
+function get_dirs( $rep )
+{
+ $sub_rep = array();
+
+ if ( $opendir = opendir ( $rep ) )
+ {
+ while ( $file = readdir ( $opendir ) )
+ {
+ if ( $file != "." and $file != ".." and is_dir ( $rep.$file ) )
+ {
+ array_push( $sub_rep, $file );
+ }
+ }
+ }
+ return $sub_rep;
+}
+
+// The get_picture_size function return an array containing :
+// - $picture_size[0] : final width
+// - $picture_size[1] : final height
+// The final dimensions are calculated thanks to the original dimensions and
+// the maximum dimensions given in parameters. get_picture_size respects
+// the width/height ratio
+function get_picture_size( $original_width, $original_height,
+ $max_width, $max_height )
+{
+ $width = $original_width;
+ $height = $original_height;
+ $is_original_size = true;
+
+ if ( $max_width != "" )
+ {
+ if ( $original_width > $max_width )
+ {
+ $width = $max_width;
+ $height = floor( ( $width * $original_height ) / $original_width );
+ }
+ }
+ if ( $max_height != "" )
+ {
+ if ( $original_height > $max_height )
+ {
+ $height = $max_height;
+ $width = floor( ( $height * $original_width ) / $original_height );
+ $is_original_size = false;
+ }
+ }
+ if ( is_numeric( $max_width ) and is_numeric( $max_height )
+ and $max_width != 0 and $max_height != 0 )
+ {
+ $ratioWidth = $original_width / $max_width;
+ $ratioHeight = $original_height / $max_height;
+ if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
+ {
+ if ( $ratioWidth < $ratioHeight )
+ {
+ $width = floor( $original_width / $ratioHeight );
+ $height = $max_height;
+ }
+ else
+ {
+ $width = $max_width;
+ $height = floor( $original_height / $ratioWidth );
+ }
+ $is_original_size = false;
+ }
+ }
+ $picture_size = array();
+ $picture_size[0] = $width;
+ $picture_size[1] = $height;
+ return $picture_size;
+}
+
+//-------------------------------------------- PhpWebGallery specific functions
+
+// get_languages retourne un tableau contenant tous les languages
+// disponibles pour PhpWebGallery
+function get_languages( $rep_language )
+{
+ $languages = array();
+ $i = 0;
+ if ( $opendir = opendir ( $rep_language ) )
+ {
+ while ( $file = readdir ( $opendir ) )
+ {
+ if ( is_file ( $rep_language.$file )
+ and $file != "index.php"
+ and strrchr ( $file, "." ) == ".php" )
+ {
+ $languages[$i++] =
+ substr ( $file, 0, strlen ( $file )
+ - strlen ( strrchr ( $file, "." ) ) );
+ }
+ }
+ }
+ return $languages;
+}
+
+// get_themes retourne un tableau contenant tous les "template - couleur"
+function get_themes( $theme_dir )
+{
+ $themes = array();
+ $main_themes = get_dirs( $theme_dir );
+ for ( $i = 0; $i < sizeof( $main_themes ); $i++ )
+ {
+ $colors = get_dirs( $theme_dir.$main_themes[$i].'/' );
+ for ( $j = 0; $j < sizeof( $colors ); $j++ )
+ {
+ array_push( $themes, $main_themes[$i].' - '.$colors[$j] );
+ }
+ }
+ return $themes;
+}
+
+// - The replace_search function replaces a $search string by the search in
+// another color
+// - The function does not replace characters in HTML tags
+function replace_search( $string, $search )
+{
+ //return $string;
+ $style_search = "background-color:white;color:red;";
+ $return_string = "";
+ $remaining = $string;
+
+ $start = 0;
+ $end = 0;
+ $start = strpos ( $remaining, "<" );
+ $end = strpos ( $remaining, ">" );
+ while ( is_numeric( $start ) and is_numeric( $end ) )
+ {
+ $treatment = substr ( $remaining, 0, $start );
+ $treatment = eregi_replace( $search, "<span style=\"".$style_search."\">".
+ $search."</span>", $treatment );
+ $return_string.= $treatment.substr ( $remaining, $start,
+ $end - $start + 1 );
+ $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
+ $start = strpos ( $remaining, "<" );
+ $end = strpos ( $remaining, ">" );
+ }
+ $treatment = eregi_replace( $search, "<span style=\"".$style_search."\">".
+ $search."</span>", $remaining );
+ $return_string.= $treatment;
+
+ return $return_string;
+}
+
+function database_connection()
+{
+ global $cfgHote,$cfgUser,$cfgPassword,$cfgBase;
+ @mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
+ or die ( "Could not connect to server" );
+ @mysql_select_db( $cfgBase )
+ or die ( "Could not connect to database" );
+}
+
+function pwg_log( $file, $category, $picture = '' )
+{
+ global $conf, $user, $prefixeTable;
+
+ if ( $conf['log'] )
+ {
+ $query = 'insert into '.$prefixeTable.'history';
+ $query.= ' (date,login,IP,file,category,picture) values';
+ $query.= " (".time().", '".$user['pseudo']."'";
+ $query.= ",'".$_SERVER['REMOTE_ADDR']."'";
+ $query.= ",'".$file."','".$category."','".$picture."');";
+ mysql_query( $query );
+ }
+}
+
+function templatize_array( $array, $global_array_name )
+{
+ global $vtp, $handle, $lang, $page, $user, $conf;
+
+ for( $i = 0; $i < sizeof( $array ); $i++ )
+ {
+ $vtp->setGlobalVar( $handle, $array[$i],
+ ${$global_array_name}[$array[$i]] );
+ }
+}
+?> \ No newline at end of file
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
new file mode 100644
index 000000000..051e89f56
--- /dev/null
+++ b/include/functions_category.inc.php
@@ -0,0 +1,481 @@
+<?php
+/***************************************************************************
+ * functions_category.inc.php *
+ * -------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+function get_subcats_id( $cat_id )
+{
+ global $prefixeTable;
+
+ $restricted_cat = array();
+ $i = 0;
+
+ $query = "select id";
+ $query.= " from $prefixeTable"."categories";
+ $query.= " where id_uppercat = $cat_id;";
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ $restricted_cat[$i++] = $row['id'];
+ $sub_restricted_cat = get_subcats_id( $row['id'] );
+ for ( $j = 0; $j < sizeof( $sub_restricted_cat ); $j++ )
+ {
+ $restricted_cat[$i++] = $sub_restricted_cat[$j];
+ }
+ }
+
+ return $restricted_cat;
+}
+
+function check_restrictions( $category_id )
+{
+ global $user,$lang,$prefixeTable;
+
+ if ( is_user_allowed( $category_id, $user['restrictions'] ) > 0 )
+ {
+ echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
+ echo '<a href="'.add_session_id( './category.php' ).'">';
+ echo $lang['thumbnails'].'</a></div>';
+ exit();
+ }
+}
+
+// the check_cat_id function check whether the $cat is a right parameter :
+// - $cat is numeric and corresponds to a category in the database
+// - $cat equals 'fav' (for favorites)
+// - $cat equals 'search' (when the result of a search is displayed)
+function check_cat_id( $cat )
+{
+ global $page,$prefixeTable;
+ unset( $page['cat'] );
+ if ( isset( $cat ) )
+ {
+ if ( is_numeric( $cat ) )
+ {
+ $query = "select id from $prefixeTable"."categories where id = $cat;";
+ $result = mysql_query( $query );
+ if ( mysql_num_rows( $result ) != 0 )
+ {
+ $page['cat'] = $cat;
+ }
+ }
+ if ( $cat == 'fav' or $cat == 'search' or $cat == 'most_visited'
+ or $cat == 'best_rated' or $cat == 'recent' )
+ {
+ $page['cat'] = $cat;
+ }
+ }
+}
+
+function display_cat( $id_uppercat, $indent, $restriction, $tab_expand )
+{
+ global $prefixeTable,$user,$lang,$conf,$page,$vtp,$handle;
+
+ $query = 'select name,id,date_dernier,nb_images,dir';
+ $query.= ' from '.$prefixeTable.'categories';
+ $query.= ' where id_uppercat';
+ if ( $id_uppercat == "" )
+ {
+ $query.= ' is NULL';
+ }
+ else
+ {
+ $query.= ' = '.$id_uppercat;
+ }
+ $query.= ' order by rank asc;';
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ if ( !in_array( $row['id'], $restriction ) )
+ {
+ $nb_subcats = get_nb_subcats( $row['id'] );
+
+ $expand = "";
+ // si la catégorie n'a pas de sous catégorie
+ // ou que l'on doit développer toutes les catégories par défaut
+ // alors on utilise l'expand par défaut
+ if ( $nb_subcats == 0 or $user['expand'] == "true" )
+ {
+ $expand = $page['expand'];
+ }
+ // si la catégorie n'est pas dans les catégories à développer
+ // alors on l'ajoute aux catégories à développer
+ else if ( !in_array( $row['id'], $tab_expand ) )
+ {
+ $expand = implode( ",", $tab_expand );
+ if ( strlen( $expand ) > 0 )
+ {
+ $expand.= ",";
+ }
+ $expand.= $row['id'];
+ }
+ // si la catégorie est déjà dans les catégories à développer
+ // alors on la retire des catégories à développer
+ else
+ {
+ $expand = array_remove( $tab_expand, $row['id'] );
+ }
+ $url = "./category.php?cat=".$page['cat']."&amp;expand=$expand";
+ if ( $page['cat'] == 'search' )
+ {
+ $url.= "&amp;search=".$_GET['search'];
+ }
+ $lien_cat = add_session_id_to_url( $url );
+ if ( $row['name'] == "" )
+ {
+ $name = str_replace( "_", " ", $row['dir'] );
+ }
+ else
+ {
+ $name = $row['name'];
+ }
+
+ $vtp->addSession( $handle, 'category' );
+ $vtp->setVar( $handle, 'category.indent', $indent );
+
+ if ( $user['expand'] == "true" or $nb_subcats == 0 )
+ {
+ $vtp->addSession( $handle, 'bullet_wo_link' );
+ $vtp->setVar( $handle, 'bullet_wo_link.bullet_url',
+ $user['lien_collapsed'] );
+ $vtp->setVar( $handle, 'bullet_wo_link.bullet_alt', '&gt;' );
+ $vtp->closeSession( $handle, 'bullet_wo_link' );
+ }
+ else
+ {
+ $vtp->addSession( $handle, 'bullet_w_link' );
+ $vtp->setVar( $handle, 'bullet_w_link.bullet_link', $lien_cat );
+ $vtp->setVar( $handle, 'bullet_w_link.bullet_alt', '&gt;' );
+ if ( in_array( $row['id'], $tab_expand ) )
+ {
+ $vtp->setVar( $handle, 'bullet_w_link.bullet_url',
+ $user['lien_expanded'] );
+ }
+ else
+ {
+ $vtp->setVar( $handle, 'bullet_w_link.bullet_url',
+ $user['lien_collapsed'] );
+ }
+ $vtp->closeSession( $handle, 'bullet_w_link' );
+ }
+ $vtp->setVar( $handle, 'category.link_url',
+ add_session_id( './category.php?cat='.
+ $row['id'].'&amp;expand='.$expand ) );
+ $vtp->setVar( $handle, 'category.link_name', $name );
+ if ( $id_uppercat == "" )
+ {
+ $vtp->setVar( $handle, 'category.name_style', 'font-weight:bold;' );
+ }
+ if ( $nb_subcats > 0 )
+ {
+ $vtp->addSession( $handle, 'subcat' );
+ $vtp->setVar( $handle, 'subcat.nb_subcats', $nb_subcats );
+ $vtp->closeSession( $handle, 'subcat' );
+ }
+ $vtp->setVar( $handle, 'category.total_cat', $row['nb_images'] );
+ $date_dispo = explode( "-", $row['date_dernier'] );
+ $date_cat = mktime( 0, 0, 0, $date_dispo[1], $date_dispo[2],
+ $date_dispo[0] );
+ $vtp->setVar( $handle, 'category.cat_icon', get_icon( $date_cat ) );
+ $vtp->closeSession( $handle, 'category' );
+
+ if ( in_array( $row['id'], $tab_expand ) or $user['expand'] == "true" )
+ {
+ display_cat( $row['id'], $indent.'&nbsp;&nbsp;&nbsp;&nbsp;',
+ $restriction, $tab_expand );
+ }
+ }
+ }
+}
+
+function get_nb_subcats( $id )
+{
+ global $prefixeTable,$user;
+
+ $query = 'select count(*) as count';
+ $query.= ' from '.$prefixeTable.'categories';
+ $query.= ' where id_uppercat = '.$id;
+ for ( $i = 0; $i < sizeof( $user['restrictions'] ); $i++ )
+ {
+ $query.= " and id != ".$user['restrictions'][$i];
+ }
+ $query.= ';';
+ $result = mysql_query( $query );
+ $row = mysql_fetch_array( $result );
+ return $row['count'];
+}
+
+function get_total_image( $id, $restriction )
+{
+ global $prefixeTable;
+
+ $total = 0;
+
+ $query = 'select id,nb_images';
+ $query.= ' from '.$prefixeTable.'categories';
+ $query.= ' where id_uppercat';
+ if ( !is_numeric( $id ) )
+ {
+ $query.= ' is NULL';
+ }
+ else
+ {
+ $query.= ' = '.$id;
+ }
+ $query.= ";";
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ if ( !in_array( $row['id'], $restriction ) )
+ {
+ $total+= $row['nb_images'];
+ $total+= get_total_image( $row['id'], $restriction );
+ }
+ }
+ return $total;
+}
+
+// variables :
+// $cat['comment']
+// $cat['dir']
+// $cat['last_dir']
+// $cat['name'] is an array :
+// - $cat['name'][0] is the lowest cat name
+// and
+// - $cat['name'][n] is the most uppercat name findable
+// $cat['nb_images']
+// $cat['id_uppercat']
+// $cat['site_id']
+function get_cat_info( $id )
+{
+ global $prefixeTable;
+
+ $cat = array();
+ $cat['name'] = array();
+
+ $query = 'select nb_images,id_uppercat,comment,site_id,galleries_url,dir';
+ $query.= ' from '.$prefixeTable.'categories as a';
+ $query.= ', '.$prefixeTable.'sites as b';
+ $query.= ' where a.id = '.$id;
+ $query.= ' and a.site_id = b.id;';
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ $cat['site_id'] = $row['site_id'];
+ $cat['id_uppercat'] = $row['id_uppercat'];
+ $cat['comment'] = nl2br( $row['comment'] );
+ $cat['nb_images'] = $row['nb_images'];
+ $cat['last_dir'] = $row['dir'];
+ $galleries_url = $row['galleries_url'];
+
+ $cat['dir'] = "";
+ $i = 0;
+ $is_root = false;
+ $row['id_uppercat'] = $id;
+ while ( !$is_root )
+ {
+ $query = 'select name,dir,id_uppercat';
+ $query.= ' from '.$prefixeTable.'categories';
+ $query.= ' where id = '.$row['id_uppercat'].';';
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ $cat['dir'] = $row['dir']."/".$cat['dir'];
+ if ( $row['name'] == "" )
+ {
+ $cat['name'][$i] = str_replace( "_", " ", $row['dir'] );
+ }
+ else
+ {
+ $cat['name'][$i] = $row['name'];
+ }
+ if ( $row['id_uppercat'] == "" )
+ {
+ $is_root = true;
+ }
+ $i++;
+ }
+ $cat['local_dir'] = substr( $cat['dir'], 0 , strlen( $cat['dir'] ) - 1 );
+ $cat['dir'] = $galleries_url.$cat['dir'];
+
+ return $cat;
+}
+
+// The function get_cat_display_name returns a string containing the list
+// of upper categories to the root category from the lowest category shown
+// example : "anniversaires - fete mere 2002 - animaux - erika"
+// You can give two parameters :
+// - $separation : the string between each category name " - " for example
+// - $style : the style of the span tag for the lowest category,
+// "font-style:italic;" for example
+function get_cat_display_name( $array_cat_names, $separation, $style )
+{
+ $output = "";
+ for ( $i = sizeof( $array_cat_names ) - 1; $i >= 0; $i-- )
+ {
+ if ( $i != sizeof( $array_cat_names ) - 1 )
+ {
+ $output.= $separation;
+ }
+ if ( $i != 0 )
+ {
+ $output.= $array_cat_names[$i];
+ }
+ else
+ {
+ if ( $style != "" )
+ {
+ $output.= '<span style="'.$style.'">';
+ }
+ $output.= $array_cat_names[$i];
+ if ( $style != "" )
+ {
+ $output.= "</span>";
+ }
+ }
+ }
+ return replace_space( $output );
+}
+
+// initialize_category initializes ;-) the variables in relation
+// with category :
+// 1. calculation of the number of pictures in the category
+// 2. determination of the SQL query part to ask to find the right category
+// $page['where'] is not the same if we are in
+// - simple category
+// - search result
+// - favorites displaying
+// - most visited pictures
+// - best rated pictures
+// - recent pictures
+// 3. determination of the title of the page
+// 4. creation of the navigation bar
+function initialize_category( $calling_page = 'category' )
+{
+ global $prefixeTable,$page,$lang,$user,$conf;
+
+ if ( isset( $page['cat'] ) )
+ {
+ // $page['nb_image_page'] is the number of picture to display on this page
+ // By default, it is the same as the $user['nb_image_page']
+ $page['nb_image_page'] = $user['nb_image_page'];
+ // $url is used to create the navigation bar
+ $url = './category.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
+ // simple category
+ if ( is_numeric( $page['cat'] ) )
+ {
+ $result = get_cat_info( $page['cat'] );
+ $page['comment'] = $result['comment'];
+ $page['cat_dir'] = $result['dir'];
+ $page['cat_name'] = $result['name'];
+ $page['cat_nb_images'] = $result['nb_images'];
+ $page['cat_site_id'] = $result['site_id'];
+ $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' );
+ $page['where'] = ' where cat_id = '.$page['cat'];
+ }
+ else
+ {
+ $query = '';
+ // search result
+ if ( $page['cat'] == 'search' )
+ {
+ $page['title'] = $lang['search_result'];
+ if ( $calling_page == 'picture' )
+ {
+ $page['title'].= ' : <span style="font-style:italic;">';
+ $page['title'].= $_GET['search']."</span>";
+ }
+ $page['where'] = " where ( file like '%".$_GET['search']."%'";
+ $page['where'].= " or name like '%".$_GET['search']."%'";
+ $page['where'].= " or comment like '%".$_GET['search']."%' )";
+
+ $query = 'select count(*) as nb_total_images';
+ $query.= ' from '.$prefixeTable.'images';
+ $query.= $page['where'];
+ $query.= ';';
+
+ $url.= '&amp;search='.$_GET['search'];
+ }
+ // favorites displaying
+ else if ( $page['cat'] == 'fav' )
+ {
+ $page['title'] = $lang['favorites'];
+
+ $page['where'] = ', '.$prefixeTable.'favorites';
+ $page['where'].= ' where user_id = '.$user['id'];
+ $page['where'].= ' and image_id = id';
+
+ $query = 'select count(*) as nb_total_images';
+ $query.= ' from '.$prefixeTable.'favorites';
+ $query.= ' where user_id = '.$user['id'];
+ $query.= ';';
+ }
+ // pictures within the short period
+ else if ( $page['cat'] == 'recent' )
+ {
+ $page['title'] = $lang['recent_cat_title'];
+ // We must find the date corresponding to :
+ // today - $conf['periode_courte']
+ $date = time() - 60*60*24*$user['short_period'];
+ $page['where'] = " where date_available > '";
+ $page['where'].= date( 'Y-m-d', $date )."'";
+
+ $query = 'select count(*) as nb_total_images';
+ $query.= ' from '.$prefixeTable.'images';
+ $query.= $page['where'];
+ $query.= ';';
+ }
+ // most visited pictures
+ else if ( $page['cat'] == 'most_visited' )
+ {
+ $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
+ $page['where'] = ' where cat_id != -1';
+ $conf['order_by'] = ' order by hit desc, file asc';
+ $page['cat_nb_images'] = $conf['top_number'];
+ if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
+ {
+ $page['nb_image_page'] = $conf['top_number'] - $page['start'];
+ }
+ }
+
+ if ( $query != '' )
+ {
+ $result = mysql_query( $query );
+ $row = mysql_fetch_array( $result );
+ $page['cat_nb_images'] = $row['nb_total_images'];
+ }
+
+ if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
+ or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
+ {
+ // we must not show pictures of a forbidden category
+ $restricted_cat = get_all_restrictions( $user['id'], $user['status'] );
+ if ( sizeof( $restricted_cat ) > 0 )
+ {
+ for ( $i = 0; $i < sizeof( $restricted_cat ); $i++ )
+ {
+ $page['where'].= ' and cat_id != '.$restricted_cat[$i];
+ }
+ }
+ }
+ }
+ if ( $calling_page == 'category' )
+ {
+ $page['navigation_bar'] =
+ create_navigation_bar( $url, $page['cat_nb_images'], $page['start'],
+ $user['nb_image_page'], 'back' );
+ }
+ }
+ else
+ {
+ $page['title'] = $lang['diapo_default_page_title'];
+ }
+}
+?> \ No newline at end of file
diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php
new file mode 100644
index 000000000..e85447221
--- /dev/null
+++ b/include/functions_session.inc.php
@@ -0,0 +1,135 @@
+<?php
+/***************************************************************************
+ * functions_session.inc.php *
+ * ------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+function generate_key()
+{
+ global $conf;
+ $md5 = md5( substr( microtime(), 2, 6 ).$conf['session_keyword'] );
+ $init = "";
+ for ( $i = 0; $i < strlen( $md5 ); $i++ )
+ {
+ if ( is_numeric( $md5[$i] ) )
+ {
+ $init.= "$md5[$i]";
+ }
+ }
+ $init = substr( $init, 0, 8 );
+ mt_srand( $init );
+ $key = "";
+ for ( $i = 0; $i < $conf['session_id_size']; $i++ )
+ {
+ $c = mt_rand( 0, 2 );
+ if ( $c == 0 )
+ {
+ $key .= chr( mt_rand( 65, 90 ) );
+ }
+ elseif ( $c == 1 )
+ {
+ $key .= chr( mt_rand( 97, 122 ) );
+ }
+ else
+ {
+ $key .= mt_rand( 0, 9 );
+ }
+ }
+ return $key;
+}
+
+function session_create( $pseudo )
+{
+ global $conf,$prefixeTable,$REMOTE_ADDR;
+ // 1. trouver une clé de session inexistante
+ $id_found = false;
+ while ( !$id_found )
+ {
+ $generated_id = generate_key();
+ $query = 'select id';
+ $query.= ' from '.$prefixeTable.'sessions';
+ $query.= " where id = '".$generated_id."';";
+ $result = mysql_query( $query );
+ if ( mysql_num_rows( $result ) == 0 )
+ {
+ $id_found = true;
+ }
+ }
+ // 2. récupération de l'id de l'utilisateur dont le pseudo
+ // est passé en paramètre
+ $query = 'select id';
+ $query.= ' from '.$prefixeTable.'users';
+ $query.= " where pseudo = '".$pseudo."';";
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ $user_id = $row['id'];
+ // 3. insertion de la session dans la base de donnée
+ $expiration = $conf['session_time']*60+time();
+ $query = 'insert into '.$prefixeTable.'sessions';
+ $query.= ' (id,user_id,expiration,ip) values';
+ $query.= "('".$generated_id."','".$user_id;
+ $query.= "','".$expiration."','".$REMOTE_ADDR."');";
+ mysql_query( $query );
+
+ return $generated_id;
+}
+
+function add_session_id_to_url( $url, $redirect = false )
+{
+ global $page, $user;
+ $amp = "&amp;";
+ if ( $redirect )
+ {
+ $amp = "&";
+ }
+ if ( !$user['is_the_guest'] )
+ {
+ if ( ereg( "\.php\?",$url ) )
+ {
+ return $url.$amp."id=".$page['session_id'];
+ }
+ else
+ {
+ return $url."?id=".$page['session_id'];
+ }
+ }
+ else
+ {
+ return $url;
+ }
+}
+
+function add_session_id( $url, $redirect = false )
+{
+ global $page, $user;
+ $amp = "&amp;";
+ if ( $redirect )
+ {
+ $amp = "&";
+ }
+ if ( !$user['is_the_guest'] )
+ {
+ if ( ereg( "\.php\?",$url ) )
+ {
+ return $url.$amp."id=".$page['session_id'];
+ }
+ else
+ {
+ return $url."?id=".$page['session_id'];
+ }
+ }
+ else
+ {
+ return $url;
+ }
+}
+?> \ No newline at end of file
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
new file mode 100644
index 000000000..48160f113
--- /dev/null
+++ b/include/functions_user.inc.php
@@ -0,0 +1,302 @@
+<?php
+/***************************************************************************
+ * functions_user.inc.php *
+ * -------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+function validate_mail_address( $mail_address )
+{
+ global $lang;
+
+ $output = '';
+ // le mail doit être conforme à qqch du type : nom@serveur.com
+ if ( $mail_address != ''
+ and !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
+ $mail_address ) )
+ {
+ $output = $lang['reg_err_mail_address'];
+ }
+
+ return $output;
+}
+
+function register_user( $login, $password, $password_conf,
+ $mail_address, $status = 'visiteur' )
+{
+ global $prefixeTable;
+
+ $error = array();
+ $i = 0;
+ // le login ne doit pas
+ // 1. être vide
+ // 2. commencer ou se terminer par un espace
+ // 3. comporter les caractères ' ou "
+ // 4. être déjà utilisé
+ if ( $login == '' )
+ {
+ $error[$i++] = $lang['reg_err_login1'];
+ }
+ if ( ereg( "^.* $", $login) )
+ {
+ $error[$i++] = $lang['reg_err_login2'];
+ }
+ if ( ereg( "^ .*$", $login ) )
+ {
+ $error[$i++] = $lang['reg_err_login3'];
+ }
+ if ( ereg( "'", $login ) or ereg( "\"", $login ) )
+ {
+ $error[$i++] = $lang['reg_err_login4'];
+ }
+ else
+ {
+ $query = 'select id';
+ $query.= ' from '.$prefixeTable.'users';
+ $query.= " where pseudo = '".$login."';";
+ $result = mysql_query( $query );
+ if ( mysql_num_rows( $result ) > 0 )
+ {
+ $error[$i++] = $lang['reg_err_login5'];
+ }
+ }
+ // on vérifie que le password rentré correspond bien
+ // à la confirmation faite par l'utilisateur
+ if ( $password != $password_conf )
+ {
+ $error[$i++] = $lang['reg_err_pass'];
+ }
+
+ $error_mail_address = validate_mail_address( $mail_address );
+ if ( $error_mail_address != '' )
+ {
+ $error[$i++] = $error_mail_address;
+ }
+
+ // on enregistre le nouvel utilisateur si aucune
+ //erreur détectée dans les paramètres
+ if ( sizeof( $error ) == 0 )
+ {
+ // 1.récupération des valeurs par défaut de l'application
+ $infos = array( 'nb_image_line', 'nb_line_page', 'theme', 'language',
+ 'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
+ 'short_period', 'long_period', 'template' );
+ $query = 'select';
+ for ( $i = 0; $i < sizeof( $infos ); $i++ )
+ {
+ if ( $i > 0 )
+ {
+ $query.= ',';
+ }
+ else
+ {
+ $query.= ' ';
+ }
+ $query.= $infos[$i];
+ }
+ $query.= ' from '.$prefixeTable.'users';
+ $query.= " where pseudo = 'visiteur';";
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ // 2.ajout du nouvel utilisateur
+ $query = 'insert into '.$prefixeTable.'users';
+ $query.= ' (';
+ $query.= ' pseudo,password,mail_address,status';
+ for ( $i = 0; $i < sizeof( $infos ); $i++ )
+ {
+ $query.= ','.$infos[$i];
+ }
+ $query.= ' values (';
+ $query.= " '".$login."'";
+ $query.= ",'".md5( $password )."'";
+ if ( $mail_address != '' )
+ {
+ $query.= ",'".$mail_address."'";
+ }
+ else
+ {
+ $query.= ',NULL';
+ }
+ $query.= ",'".$status."'";
+ for ( $i = 0; $i < sizeof( $infos ); $i++ )
+ {
+ $query.= ','.$row[$infos[$i]];
+ }
+ $query.= ');';
+ mysql_query( $query );
+ // 3. récupérer l'identifiant de l'utilisateur nouvellement créé
+ $query = 'select id';
+ $query.= ' from '.$prefixeTable.'users';
+ $query.= " where pseudo = '".$login."';";
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ $user_id = $row['id'];
+ // 4.ajouter les restrictions au nouvel utilisateur,
+ // les mêmes que celles de l'utilisateur par défaut
+ $query = 'select cat_id';
+ $query.= ' from '.$prefixeTable.'restrictions as r';
+ $query.= ','.$prefixeTable.'users as u ';
+ $query.= ' where u.id = r.user_id';
+ $query.= " and u.pseudo = 'visiteur';";
+ $result = mysql_query( $query );
+ while( $row = mysql_fetch_array( $result ) )
+ {
+ $query = 'insert into '.$prefixeTable.'restrictions';
+ $query.= ' (user_id,cat_id) values';
+ $query.= ' ('.$user_id.','.$row['cat_id'].');';
+ mysql_query ( $query );
+ }
+ }
+ return $error;
+}
+
+function update_user( $user_id, $mail_address, $status,
+ $use_new_password = false, $password = '' )
+{
+ global $prefixeTable;
+
+ $error = array();
+ $i = 0;
+
+ $error_mail_address = validate_mail_address( $mail_address );
+ if ( $error_mail_address != '' )
+ {
+ $error[$i++] = $error_mail_address;
+ }
+
+ if ( sizeof( $error ) == 0 )
+ {
+ $query = 'update '.$prefixeTable.'users';
+ $query.= " set status = '".$status."'";
+ if ( $use_new_password )
+ {
+ $query.= ", password = '".md5( $password )."'";
+ }
+ $query.= ', mail_address = ';
+ if ( $mail_address != '' )
+ {
+ $query.= "'".$mail_address."'";
+ }
+ else
+ {
+ $query.= 'NULL';
+ }
+ $query.= ' where id = '.$user_id;
+ $query.= ';';
+ mysql_query( $query );
+ }
+ return $error;
+}
+
+function check_login_authorization()
+{
+ global $user,$lang,$conf,$page;
+ if ( $user['is_the_guest']
+ and ( $conf['acces'] == 'restreint' or $page['cat'] == 'fav' ) )
+ {
+ echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
+ echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
+ exit();
+ }
+}
+
+// The function get_restrictions returns an array with the ids of the
+// restricted categories for the user.
+// If the $check_invisible parameter is set to true, invisible categories
+// are added to the restricted one in the array.
+function get_restrictions( $user_id, $user_status, $check_invisible )
+{
+ global $prefixeTable;
+
+ // 1. getting the ids of the restricted categories
+ $query = "select cat_id";
+ $query.= " from $prefixeTable"."restrictions";
+ $query.= " where user_id = $user_id;";
+ $result = mysql_query( $query );
+ $i = 0;
+ $restriction = array();
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ $restriction[$i++] = $row['cat_id'];
+ }
+ if ( $check_invisible )
+ {
+ // 2. adding to the restricted categories, the invisible ones
+ if ( $user_status != "admin" )
+ {
+ $query = 'select id';
+ $query.= ' from '.$prefixeTable.'categories';
+ $query.= " where status='invisible';";
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ $restriction[$i++] = $row['id'];
+ }
+ }
+ }
+ return $restriction;
+}
+
+// The get_all_restrictions function returns an array with all the
+// categories id which are restricted for the user. Including the
+// sub-categories and invisible categories
+function get_all_restrictions( $user_id, $user_status )
+{
+ global $prefixeTable;
+
+ $restricted_cat = get_restrictions( $user_id, $user_status, true );
+ $i = sizeof( $restricted_cat );
+ for ( $k = 0; $k < sizeof( $restricted_cat ); $k++ )
+ {
+ $sub_restricted_cat = get_subcats_id( $restricted_cat[$k] );
+ for ( $j = 0; $j < sizeof( $sub_restricted_cat ); $j++ )
+ {
+ $restricted_cat[$i++] = $sub_restricted_cat[$j];
+ }
+ }
+ return $restricted_cat;
+}
+
+// The function is_user_allowed returns :
+// - 0 : if the category is allowed with this $restrictions array
+// - 1 : if this category is not allowed
+// - 2 : if an uppercat category is not allowed
+function is_user_allowed( $category_id, $restrictions )
+{
+ global $user,$prefixeTable;
+
+ $lowest_category_id = $category_id;
+
+ $is_root = false;
+ while ( !$is_root and !in_array( $category_id, $restrictions ) )
+ {
+ $query = "select id_uppercat";
+ $query.= " from $prefixeTable"."categories";
+ $query.= " where id = $category_id;";
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ if ( $row['id_uppercat'] == "" )
+ {
+ $is_root = true;
+ }
+ $category_id = $row['id_uppercat'];
+ }
+
+ if ( in_array( $lowest_category_id, $restrictions ) )
+ {
+ return 1;
+ }
+ if ( in_array( $category_id, $restrictions ) )
+ {
+ return 2;
+ }
+ // this user is allowed to go in this category
+ return 0;
+}
+?> \ No newline at end of file
diff --git a/include/index.php b/include/index.php
new file mode 100644
index 000000000..0b5239bb2
--- /dev/null
+++ b/include/index.php
@@ -0,0 +1,7 @@
+<?php
+$url = '../category.php';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?> \ No newline at end of file
diff --git a/include/init.inc.php b/include/init.inc.php
new file mode 100644
index 000000000..041545b3f
--- /dev/null
+++ b/include/init.inc.php
@@ -0,0 +1,38 @@
+<?php
+/***************************************************************************
+ * init.inc.php *
+ * ------------------- *
+ * application : PhpWebGallery 1.3 *
+ * author : Pierrick LE GALL <pierrick@z0rglub.com> *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+define( PREFIXE_INCLUDE, '' );
+
+include_once( './include/config.inc.php' );
+include_once( './include/user.inc.php' );
+
+include( './theme/'.$user['theme'].'/conf.php' );
+$user['lien_expanded'] = './theme/'.$user['theme'].'/expanded.gif';
+$user['lien_collapsed'] = './theme/'.$user['theme'].'/collapsed.gif';
+// calculation of the number of picture to display per page
+$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
+// retrieving the restrictions for this user
+$user['restrictions'] = get_restrictions( $user['id'], $user['status'], true );
+
+$isadmin = false;
+include_once( './language/'.$user['language'].'.php' );
+if ( $user['is_the_guest'] )
+{
+ $user['pseudo'] = $lang['guest'];
+}
+include_once( './template/'.$user['template'].'/style.inc.php' );
+include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' );
+?> \ No newline at end of file
diff --git a/include/user.inc.php b/include/user.inc.php
new file mode 100644
index 000000000..b323385e7
--- /dev/null
+++ b/include/user.inc.php
@@ -0,0 +1,93 @@
+<?php
+/***************************************************************************
+ * user.inc.php is a part of PhpWebGallery *
+ * ------------------- *
+ * last update : Saturday, October 26, 2002 *
+ * email : pierrick@z0rglub.com *
+ * *
+ ***************************************************************************
+
+ ***************************************************************************
+ * *
+ * 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; *
+ * *
+ ***************************************************************************/
+// retrieving user informations
+// $infos array is used to know the fields to retrieve in the table "users"
+// Each field becomes an information of the array $user.
+// Example :
+// status --> $user['status']
+$infos = array( 'id', 'pseudo', 'mail_address', 'nb_image_line',
+ 'nb_line_page', 'status', 'theme', 'language', 'maxwidth',
+ 'maxheight', 'expand', 'show_nb_comments', 'short_period',
+ 'long_period', 'template' );
+
+$query_user = 'select';
+for ( $i = 0; $i < sizeof( $infos ); $i++ )
+{
+ if ( $i > 0 )
+ {
+ $query_user.= ',';
+ }
+ else
+ {
+ $query_user.= ' ';
+ }
+ $query_user.= $infos[$i];
+}
+$query_user.= ' from '.$prefixeTable.'users';
+$query_done = false;
+$user['is_the_guest'] = false;
+if ( isset( $_GET['id'] )
+ && ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $_GET['id'] ) )
+{
+ $page['session_id'] = $_GET['id'];
+ $query = "select user_id, expiration, ip ";
+ $query.= "from $prefixeTable"."sessions ";
+ $query.= "where id = '".$_GET['id']."';";
+ $result = mysql_query( $query );
+ if ( mysql_num_rows( $result ) > 0 )
+ {
+ $row = mysql_fetch_array( $result );
+ if ( $row['expiration'] < time() )
+ {
+ // deletion of the session from the database,
+ // because it is out-of-date
+ $delete_query = "delete from ".$prefixeTable."sessions";
+ $delete_query.= " where id = ".$page['session_id'].";";
+ mysql_query( $delete_query );
+ }
+ else
+ {
+ if ( $REMOTE_ADDR == $row['ip'] )
+ {
+ $query_user .= ' where id = '.$row['user_id'];
+ $query_done = true;
+ }
+ }
+ }
+}
+if ( !$query_done )
+{
+ $query_user .= " where pseudo = 'visiteur'";
+ $user['is_the_guest'] = true;
+}
+$query_user .= ';';
+
+$row = mysql_fetch_array( mysql_query( $query_user ) );
+
+// affectation of each value retrieved in the users table into a variable
+// of the array $user.
+for ( $i = 0; $i < sizeof( $infos ); $i++ )
+{
+ $user[$infos[$i]] = $row[$infos[$i]];
+ // If the field is true or false, the variable is transformed into a boolean
+ // value.
+ if ( $row[$infos[$i]] == 'true' || $row[$infos[$i]] == 'false' )
+ {
+ $user[$infos[$i]] = get_boolean( $row[$infos[$i]] );
+ }
+}
+?> \ No newline at end of file
diff --git a/include/vtemplate.class.php b/include/vtemplate.class.php
new file mode 100644
index 000000000..8f531412c
--- /dev/null
+++ b/include/vtemplate.class.php
@@ -0,0 +1,519 @@
+<?php
+/*****************************************************************
+ * VIRTUAL-TEMPLATE
+ *
+ * Version : 1.3.1 Base Edition ( Juillet 2002 ) build 6
+ *
+ * Address : http://vtemplate.sourceforge.net
+ *
+ * Authors:
+ * + THIEBAUT Jean-Baptiste(J.Baptiste@leweby.com) - http://www.leweby.com .
+ * + CAMPANA François (fc@netouaibe.com).
+ * Licence: GPL.
+ *
+ *
+ *****************************************************************/
+
+if ( !isset($DEFINE_VTEMPLATE) )
+{
+ define("ALL",1);
+ define("VARTAG","{#"); // Tag d'ouverture des variables :
+ // vous pouvez changer ce paramètre.
+ define("VTEMPLATE_VERSION","1.3.1");
+ define("VTEMPLATE_TYPE","BA");
+ define("VTEMPLATE_BUILD","6");
+
+
+ class Err
+ {
+ var $msg;
+ var $titre;
+
+ function error( $errno, $arg = "", $code = 0, $disp = 0 )
+ {
+// Gestion des erreurs
+ switch($errno)
+ {
+ case 1:
+ $this->titre="Erreur de session n° $code";
+ $this->msg = "La zone $arg est déjà ouverte.Avant d'ajouter une session sur cette zone, vous devez la fermer à l'aide de la fonction closeSession().<br>" ;
+ break;
+ case 2:
+ $this->titre="Erreur de session n° $code";
+ $this->msg = "Vous tentez de fermer une session de la zone $arg alors qu'aucune session pour cette zone n'existe.Pour ouvrir une session, utilisez la fonction addSession().<br>";
+ break;
+ case 3:
+ $this->titre="Erreur de session n° $code";
+ $var = $arg[1];
+ $zone = $arg[0];
+ $this->msg = "Vous essayez de valoriser la variable $var sans avoir créer de session de la zone $zone.Utilisez la fonction addSession() pour créer une session, puis setVar pour valoriser une variable.<br>";
+ break;
+ case 4:
+ $this->titre="Erreur de session n° $code";
+ $var = $arg[1];
+ $zone = $arg[0];
+ $this->msg = "La variable $var que vous souhaitez valoriser n'existe pas dans la zone $zone.<br>";
+ break;
+ case 5:
+ $this->titre="Erreur de parsing n° $code";
+ $this->msg = "Vous utilisez des caractère non autorisés pour déclarer vos zones.Vous pouvez utiliser tous les caractères à l'exception de \'{\' , \'#\' \'}\' et \'|\'.<br>";
+ break;
+ case 6:
+ $this->titre="Erreur de parsing n° $code";
+ $this->msg = "Vous ne pouvez pas utiliser le même nom ($arg)de zone plusieurs fois.<br>";
+ break;
+ case 7:
+ $this->titre="Erreur de parsing n° $code";
+ $this->msg = "Vous avez oublié de fermer la zone $arg.<br>";
+ break;
+ case 8:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "Le fichier template $arg est introuvable.<br>";
+ break;
+ case 9:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "Impossible d'ouvrir le fichier $arg.Vérifiez les droits de ce fichier.<br>";
+ break;
+ case 10:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "Impossible de lire le fichier template $arg.<br>";
+ break;
+ case 11:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "La zone $arg est introuvable.Vérifiez la syntaxe de cette zone.<br>";
+ break;
+ case 12:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "La variable $arg est introuvable .Vérifiez la syntaxe de la variable.<br>";
+ break;
+ case 13:
+ $this->titre="Erreur de traitement n° $code";
+ $this->msg = "L'identifiant de fichier spécifié n'existe pas.Vérifiez les fonctions Open() de votre script.<br>";
+ break;
+ case 14:
+ $this->titre="Erreur de traitement n° $code";
+ $var = $arg[1];
+ $file = $arg[0];
+ $this->msg = "La variable $var dans le fichier $file est introuvable.Vérifiez la syntaxe de la variable.<br>";
+ break;
+ case 15:
+ $this->titre="Erreur de traitement n° $code";
+ $var = $arg[2];
+ $zone = $arg[1];
+ $fichier = $arg[0];
+ $this->msg = "La variable $var dans la zone $zone du fichier $fichier est introuvable.Vérifiez la syntaxe de la variable et du nom de la zone.<br>";
+ break;
+ default:
+ $this->titre = "Erreur inconnue $code";
+ $this->msg = "Veuillez le rapporter aux auteurs de la classe.";
+ }
+ $this->titre .= ": <br>";
+ if ($disp){
+ $web = "Pour plus d'informations, consultez la <a href=\"http://www.virtual-solution.net/vtemplate/docs/debug-mod.php?version=".VTEMPLATE_VERSION."&build=".VTEMPLATE_BUILD."&type=".VTEMPLATE_TYPE."&error=$code\" target=\"_blank\">doc en ligne</a>";
+ echo "<font face=verdana size=2 color=red><u>$this->titre</u><i>$this->msg</i>$web<br><br></font>";
+ }
+ return -1;
+ }
+// Fin classe
+ }
+
+ class Session extends err{
+
+ var $name; // Name of the session
+ var $globalvar = array(); // List of global variable of the session
+ var $varlist = array(); // List of var in this session
+ var $subzone = array(); // list of sub-zone
+ var $temp; // Generated code for the current session
+ var $generated = NULL; // The final code
+ var $source; // Source code
+ var $used=0; // Indicates if the session contain used variable
+ var $stored; // Give the filename were is stored the session
+
+ function Session($name,$source,$stored){
+ $this->name = $name;
+ $this->source = $source;
+ $this->stored = $stored;
+ $this->parseVar();
+ }
+
+ function parseVar(){
+ // Récupération des noms des variables
+ $regle = "|".VARTAG."(.*)}|sU";
+ preg_match_all ($regle,$this->source,$var1);
+ // Création du tableau de variable à partir de la liste parsée.
+ $this->varlist=@array_merge($var[1],$var1[1]);
+ return 1;
+ }
+
+ function init(){
+ if($this->used) return $this->error(1,array($this->stored,$this->name),"SESSION1",1);
+// Reset generated code
+ $this->temp = $this->source;
+ $this->used = 1;
+ }
+ function closeSession(){
+// Check if the zone has been used.
+ if(!$this->used) return $this->error(2,array($this->stored,$this->name),"SESSION2",1);
+// Set Globals vars.
+ $this->generateCode();
+ $this->used=0;
+ return 1;
+ }
+
+ function reset(){
+ $this->used = 0;
+ $this->generated = NULL;
+ return 1;
+ }
+
+ function addSubZone(&$subzone){
+ $this->subzone[$subzone->name] = &$subzone;
+ return 1;
+ }
+
+ function setVar($varname,$value){
+ if (!$this->used) return $this->error(3,array($this->stored,$this->name,$varname),"SESSION3",1);
+ if (!in_array($varname,$this->varlist)) return $this->error(4,array($this->name,$varname),"SESSION4",1);
+ $regle = "(\\".VARTAG."$varname\})";
+ $this->temp = preg_replace($regle,$value,$this->temp);
+ return 1;
+ }
+
+ function dispVar(){
+ echo "Liste variables de $this->name:<br>";
+ foreach ( $this->varlist as $vars )
+ echo "$vars <br>";
+ }
+
+ function setGlobalVar($varname,$value){
+ $set = 0;
+ if (in_array($varname,$this->varlist)){
+ // Replace the var into this session
+ $this->globalvar[$varname]=$value;
+ $set = 1;
+ }
+ // Replace the var into sub zones
+ foreach(array_keys($this->subzone) as $subzone){
+ $set = $this->subzone[$subzone]->setGlobalVar($varname,$value) || $set;
+ }
+ return $set;
+ }
+
+ function replaceGlobalVar(){
+ if ( count($this->globalvar) )
+ foreach($this->globalvar as $varname => $value){
+ $regle = "(\\".VARTAG."$varname\})";
+ $this->temp = preg_replace($regle,$value,$this->temp);
+ }
+ }
+
+
+ function generateCode(){
+ if ($this->used == 0) return $this->generated;
+ // Replace global var.
+ if ( count($this->globalvar) ) $this->replaceGlobalVar();
+ // Replace all unused variable by ""
+ $regle = "|\\".VARTAG."(.*)\}|";
+ $this->temp = preg_replace($regle,"",$this->temp);
+ // Generate the subzone(s) code
+ if(count($this->subzone)){
+ foreach(array_keys($this->subzone) as $subzone){
+ $text = ($this->subzone[$subzone]->used) ? $this->subzone[$subzone]->generateCode() : $this->subzone[$subzone]->generated;
+ $this->temp = preg_replace("(\|$subzone\|)",$text,$this->temp);
+ $this->subzone[$subzone]->reset();
+ }
+ }
+ $this->generated .= $this->temp;
+ return $this->generated;
+ }
+
+ function inVarList($varname){
+ return in_array($varname,$this->varlist);
+ }
+
+// Fin classe
+ }
+
+ class VTemplate_Private extends Err{
+/****************************************
+ * Private Class. *
+ * ***************************************/
+
+ var $sources=array(); // Sources des zones issues de la premiere partie du parsing.
+ var $sessions=array(); // Tableau de sessions
+ var $v_global=array(); // Globla var array.
+
+/****************************************************************
+ Parsing Functions for Template files. ( PF 1.0 )
+****************************************************************/
+
+ function getNom($code){
+// Retourne le premier nom de zone qu'il trouve dans le code
+
+ preg_match("(<!--VTP_([^()]+)-->)sU",$code,$reg);
+
+ // Tester la présence des caratère invalides dans le nom ( | et {});
+ if (@count(explode("|",$reg[1]))>1 || @count(explode("{",$reg[1]))>1 || @count(explode("}",$reg[1]))>1) exit($this->error(5,$reg[1],"PARSE1",1));
+
+ return @$reg[1];
+ }
+
+ function endTag($code,$nom){
+// Renvoie TRUE(1) si le tag de fermeture est présent.
+
+ preg_match("(<!--/VTP_$nom-->)sU",$code,$reg);
+
+ return ($reg[0]!="<!--/VTP_$nom-->") ? 0 : 1;
+ }
+
+ function getSource($code,$nom,$type=0){
+// Retourne le source de la zone de nom $nom
+
+ preg_match_all ("(<!--VTP_$nom-->(.*)<!--/VTP_$nom-->)sU",$code,$reg);
+
+ return $reg[$type][0];
+ }
+
+ function parseZone($code_source,$nom_zone="|root|"){
+// Fonction récursive de parsing du fichier template
+ // Vérification que la zone n'existe pas
+ if (isset($this->sources[$nom_zone])) exit($this->error(6,$nom_zone,"PARSE2",1));
+
+ // Enregistrement du code source
+ $this->sources[$nom_zone]["source"]=$code_source;
+
+ // Rappel de la fonction pour chaque fils.
+ while($nom_fils=$this->getNom($this->sources[$nom_zone]["source"])){
+
+ // Vérification que le tag de fin est présent.
+ if (!$this->endTag($code_source,$nom_fils)) exit($this->error(7,$nom_fils,"PARSE3",1));
+
+ // Parse le fils
+ $this->parseZone($this->getSource($this->sources[$nom_zone]["source"],$nom_fils,1),$nom_fils);
+
+ // Enregistre le nom du fils dans la liste des fils
+ $this->sources[$nom_zone]["fils"][]=$nom_fils;
+
+ // Remplace le code du fils dans le source du père
+ $this->sources[$nom_zone]["source"]=str_replace(
+ $this->getSource($this->sources[$nom_zone]["source"],$nom_fils,0),
+ "|$nom_fils|",
+ $this->sources[$nom_zone]["source"]
+ );
+ // Teste si la zone $nom_fils n'existe pas plusieurs fois dans la zone $nom_zone
+ if (count(explode("|$nom_fils|",$this->sources[$nom_zone]["source"]))>2) exit($this->error(6,$nom_fils,"PARSE4",1));
+ }// fin While
+
+ return 1;
+ }
+
+/****************************************************************
+ Session Management functions ( SMF 1.0 )
+****************************************************************/
+
+ function createSession($handle,$zone = "|root|"){
+// Create a new session of the zone
+ $this->sessions[$handle][$zone] = new Session($zone,$this->sources[$zone]["source"],$this->file_name[$handle]);
+
+// Create sub-zone
+ if (@count($this->sources[$zone]["fils"])){
+ foreach($this->sources[$zone]["fils"] as $subzone){
+ $this->createSession($handle,$subzone);
+ $this->sessions[$handle][$zone]->addSubZone($this->sessions[$handle][$subzone]);
+ }
+ }
+
+//end createSession
+ }
+
+
+/****************************************************************
+ Global Variable Management Functions ( GVMF 1.0 )
+****************************************************************/
+
+ function setGZone($handle,$zone,$var,$value){
+ // Define Global var for $zone and its sub-zone.
+ // Set global value to $zone vars.
+ return $this->sessions[$handle][$zone]->setGlobalVar($var,$value);
+ }
+
+ function setGFile($handle,$var,$value) {
+ return $this->sessions[$handle]["|root|"]->setGlobalVar($var,$value);
+ }
+
+ function setGAll($var,$value){
+ $declare = 0;
+ $this->v_global[$var]=$value;
+ if (is_array($this->sessions)){
+ foreach($this->sessions as $handle => $v){
+ $declare = $this->setGFile($handle,$var,$value) || $declare;
+ }
+ }
+ return $declare;
+ }
+
+ function setGOpened($handle){
+// Set Global var into the opened file
+ foreach($this->v_global as $name => $val){
+ $this->setGFile($handle,$name,$val);
+ }
+ return 1;
+ }
+
+// Fin VTemplate_Private
+ }
+
+
+ class VTemplate extends VTemplate_Private{
+/****************************************
+ * Public Class. *
+ * ***************************************/
+
+
+/****************************************************************
+ Core Functions
+*****************************************************************/
+
+
+ function Open($nomfichier){
+// Ouverture d'un fichier source et retourne le handle de ce fichier
+// Création du handle:
+ $handle = "{".count($this->sessions)."}" ;
+
+
+// Récupération du source à parser
+ if (!@file_exists($nomfichier)) return $this->error(8,$nomfichier,"TTT1",1);
+ if (!$f_id=@fopen($nomfichier,"r")) return $this->error(9,$nomfichier,"TTT2",1);
+ if (!$source=@fread($f_id, filesize($nomfichier))) return $this->error(10,$nomfichier,"TTT3",1);
+ clearstatcache();
+ fclose($f_id);
+
+// Store the filename
+ $this->file_name[$handle]=$nomfichier;
+
+// Parse les zones
+ $this->parseZone($source);
+
+// Création du tableau de session
+ $this->createSession($handle);
+
+//Nettoyage des variables temporaires
+ $this->sources=NULL;
+
+// Set global var.
+ $this->setGOpened($handle);
+
+ $this->addSession($handle);
+ return $handle;
+ }
+
+ function newSession($handle="{0}",$nom_zone = "|root|"){
+ if ( $this->sessions[$handle][$nom_zone]->used ) $this->closeSession($handle,$nom_zone);
+ $this->addSession($handle,$nom_zone,$cache,$time,$num_session);
+ return 1;
+ }
+
+ function addSession($handle="{0}",$nom_zone = "|root|"){
+ // Does the zone exist ?
+ if(!isset($this->sessions[$handle][$nom_zone])) return $this->error(11,array($nom_zone,$this->file_name[$handle]),"TTT4",1);
+ $this->sessions[$handle][$nom_zone]->init();
+ return 1;
+ }
+
+ function closeSession($handle="{0}",$nom_zone = "|root|"){
+// Close the current session and all his sub-session
+ // Check if the zone exists.
+ if(!isset($this->sessions[$handle][$nom_zone])) return $this->error(11,array($nom_zone,$this->file_name[$handle]),"TTT5",1);
+ // Closing sub-zone
+ $this->sessions[$handle][$nom_zone]->closeSession();
+ return 1;
+ }
+
+ function setGlobalVar($arg1,$arg2,$arg3){
+ if ($arg1 == 1){
+ if (!$this->setGAll($arg2,$arg3)) return $this->error(12,$arg2,"TTT6",1);
+ return 1;
+ }
+ if (!isset($this->sessions[$arg1])) return $this->error(13,$arg1,"TTT7",1);
+ $tab=explode(".",$arg2);
+ if (count($tab)==1){
+ if (!$this->setGFile($arg1,$arg2,$arg3)) return $this->error(14,array($this->file_name[$arg1],$arg2),"TTT8",1);
+ }
+ else if (count($tab==2)){
+ if (!isset($this->sessions[$arg1][$tab[0]])) return $this->error(11,array($tab[0],$this->file_name[$arg1],"TTT9",1));
+ if (!$this->setGZone($arg1,$tab[0],$tab[1],$arg3)) return $this->error(15,array($this->file_name[$arg1],$tab[0],$tab[1]),"TTT10",1);
+ }
+ return 1;
+ }
+
+ function setVar($handle,$zone_var,$val){
+ // Fill the variable
+ $tab=explode(".",$zone_var);
+ if(count($tab)==2){
+ $zone=$tab[0];
+ $var=$tab[1];
+ }
+ else
+ {
+ $zone="|root|";
+ $var=$tab[0];
+ }
+
+ // Teste l'existence de la zone dans la liste
+ if (!isset($this->sessions[$handle][$zone])) return $this->error(11,array($this->file_name[$handle],$zone),"TTT11",1);
+
+ //Enregistre la variable
+ return $this->sessions[$handle][$zone]->setVar($var,$val);
+ }
+
+ function Parse($handle_dest,$zone_var_dest,$handle_source,$zone_source="|root|"){
+ if($this->sessions[$handle_source][$zone_source]->used == 1) $this->closeSession($handle_source,$zone_source);
+ $this->setVar($handle_dest,$zone_var_dest, $this->sessions[$handle_source][$zone_source]->generated);
+ }
+
+ function setVarF($handle,$zone_var,$file){
+// Fonction qui ouvre le fichier file et copie ce qu'il y a dedans dans une variable.
+ $tab=explode(".",$zone_var);
+
+// Récupération nom de la zone et de la variable.
+ if(count($tab)==2){
+ $zone=$tab[0];
+ $var=$tab[1];
+ }
+ else
+ {
+ $zone="|root|";
+ $var=$tab[0];
+ }
+// Teste l'existence de la zone dans la liste
+ if (!is_object($this->sessions[$handle][$zone])) return $this->error(11,array($handle,$zone),"TTT12",1);
+
+ // Récupération du source à lire
+ if (!@file_exists($file)) return $this->error(8,$file,"TTT13",1);
+ if (!$f_id=@fopen($file,"r")) return $this->error(9,$file,"TTT14",1);
+ if (!$val=@fread($f_id, filesize($file))) return $this->error(10,$file,"TTT15",1);
+ clearstatcache();
+ fclose($f_id);
+
+//Enregistre la variable
+ return $this->sessions[$handle][$zone]->setVar($var,$val);
+ }
+
+ function isZone($handle, $zone="|root|")
+ {
+ return isset($this->sessions[$handle][$zone]) ;
+ }
+
+ function Display($handle="{0}",$display=1,$zone="|root|"){
+ $this->closeSession($handle,$zone);
+ $c_genere = $this->sessions[$handle][$zone]->generated;
+
+ if ($display) echo $c_genere; else return ($c_genere);
+ }
+
+
+// End VTemplate
+ }
+ $DEFINE_VTEMPLATE = 1;
+}
+?>