aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-07-01 09:27:20 +0000
committerz0rglub <z0rglub@piwigo.org>2003-07-01 09:27:20 +0000
commit0ec91d8b4834d63c65dcbef6ac49ab5a8f68ddd1 (patch)
treeb21ebe1713021f8f783f10b948acdb03878d5223 /include
parent1080c51deb551ec63677adb842025065fa0999ba (diff)
*** empty log message ***
git-svn-id: http://piwigo.org/svn/trunk@21 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/config.inc.php4
-rw-r--r--include/functions.inc.php19
-rw-r--r--include/functions_category.inc.php22
-rw-r--r--include/functions_group.inc.php104
-rw-r--r--include/functions_user.inc.php111
-rw-r--r--include/functions_xml.inc.php7
-rw-r--r--include/init.inc.php4
-rw-r--r--include/user.inc.php27
-rw-r--r--include/vtemplate.class.php865
9 files changed, 691 insertions, 472 deletions
diff --git a/include/config.inc.php b/include/config.inc.php
index f52996b9f..7df262d11 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -20,8 +20,8 @@ $page = array();
$user = array();
$lang = array();
-include_once( PREFIXE_INCLUDE.'./include/functions.inc.php' );
-include_once( PREFIXE_INCLUDE.'./include/vtemplate.class.php' );
+include_once( PREFIX_INCLUDE.'./include/functions.inc.php' );
+include_once( PREFIX_INCLUDE.'./include/vtemplate.class.php' );
// How to change the order of display for images in a category ?
//
diff --git a/include/functions.inc.php b/include/functions.inc.php
index eb8571e86..ec9081dce 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -18,6 +18,7 @@ include( 'functions_user.inc.php' );
include( 'functions_session.inc.php' );
include( 'functions_category.inc.php' );
include( 'functions_xml.inc.php' );
+include( 'functions_group.inc.php' );
//----------------------------------------------------------- generic functions
@@ -319,22 +320,22 @@ function replace_search( $string, $search )
function database_connection()
{
- // $cfgHote,$cfgUser,$cfgPassword,$cfgBase;
+// $xml_content = getXmlCode( PREFIXE_INCLUDE.'./include/database_config.xml' );
+// $mysql_conf = getChild( $xml_content, 'mysql' );
- $xml_content = getXmlCode( PREFIXE_INCLUDE.'./include/database_config.xml' );
- $mysql_conf = getChild( $xml_content, 'mysql' );
+// $cfgHote = getAttribute( $mysql_conf, 'host' );
+// $cfgUser = getAttribute( $mysql_conf, 'user' );
+// $cfgPassword = getAttribute( $mysql_conf, 'password' );
+// $cfgBase = getAttribute( $mysql_conf, 'base' );
+// define( PREFIX_TABLE, getAttribute( $mysql_conf, 'tablePrefix' ) );
- $cfgHote = getAttribute( $mysql_conf, 'host' );
- $cfgUser = getAttribute( $mysql_conf, 'user' );
- $cfgPassword = getAttribute( $mysql_conf, 'password' );
- $cfgBase = getAttribute( $mysql_conf, 'base' );
+ include( PREFIX_INCLUDE.'./include/mysql.inc.php' );
+ define( PREFIX_TABLE, $prefix_table );
@mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
or die ( "Could not connect to server" );
@mysql_select_db( $cfgBase )
or die ( "Could not connect to database" );
-
- define( PREFIX_TABLE, getAttribute( $mysql_conf, 'tablePrefix' ) );
}
function pwg_log( $file, $category, $picture = '' )
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 21de2ad71..de868db82 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -14,27 +14,25 @@
* the Free Software Foundation; *
* *
***************************************************************************/
+
function get_subcats_id( $cat_id )
{
- $restricted_cat = array();
- $i = 0;
+ $restricted_cats = array();
- $query = 'select id';
- $query.= ' from '.PREFIX_TABLE.'categories';
- $query.= ' where id_uppercat = '.$cat_id;
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id_uppercat = '.$cat_id;
$query.= ';';
$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];
+ array_push( $restricted_cats, $row['id'] );
+ $sub_restricted_cats = get_subcats_id( $row['id'] );
+ foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
+ array_push( $restricted_cats, $sub_restricted_cat );
}
}
-
- return $restricted_cat;
+ return $restricted_cats;
}
function check_restrictions( $category_id )
diff --git a/include/functions_group.inc.php b/include/functions_group.inc.php
new file mode 100644
index 000000000..f8987ab29
--- /dev/null
+++ b/include/functions_group.inc.php
@@ -0,0 +1,104 @@
+<?php
+/***************************************************************************
+ * functions_group.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; *
+ * *
+ ***************************************************************************/
+
+// get_group_restrictions returns an array containing all unaccessible
+// category ids.
+function get_group_restrictions( $group_id )
+{
+ // 1. retrieving ids of private categories
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= " WHERE status = 'private'";
+ $query.= ';';
+ $result = mysql_query( $query );
+ $privates = array();
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ array_push( $privates, $row['id'] );
+ }
+ // 2. retrieving all authorized categories for the group
+ $authorized = array();
+ $query = 'SELECT cat_id';
+ $query.= ' FROM '.PREFIX_TABLE.'group_access';
+ $query.= ' WHERE group_id = '.$group_id;
+ $query.= ';';
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ array_push( $authorized, $row['cat_id'] );
+ }
+
+ $forbidden = array();
+ foreach ( $privates as $private ) {
+ if ( !in_array( $private, $authorized ) )
+ {
+ array_push( $forbidden, $private );
+ }
+ }
+
+ return $forbidden;
+}
+
+// get_all_group_restrictions returns an array with ALL unaccessible
+// category ids, including sub-categories
+function get_all_group_restrictions( $group_id )
+{
+ $restricted_cats = get_group_restrictions( $group_id );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $sub_restricted_cats = get_subcats_id( $restricted_cat );
+ foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
+ array_push( $restricted_cats, $sub_restricted_cat );
+ }
+ }
+ return $restricted_cats;
+}
+
+// The function is_group_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_group_allowed( $category_id, $restrictions )
+{
+ $lowest_category_id = $category_id;
+
+ $is_root = false;
+ while ( !$is_root and !in_array( $category_id, $restrictions ) )
+ {
+ $query = 'SELECT id_uppercat';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id = '.$category_id;
+ $query.= ';';
+ $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 group is allowed to go in this category
+ return 0;
+}
+?> \ No newline at end of file
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index dcb569485..0f286b970 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -144,22 +144,22 @@ function register_user(
$query.= ');';
mysql_query( $query );
// 3. retrieving the id of the newly created user
- $query = 'select id';
- $query.= ' from '.PREFIX_TABLE.'users';
- $query.= " where username = '".$login."';";
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'users';
+ $query.= " WHERE username = '".$login."';";
$row = mysql_fetch_array( mysql_query( $query ) );
$user_id = $row['id'];
- // 4. adding restrictions to the new user, the same as the user "guest"
- $query = 'select cat_id';
- $query.= ' from '.PREFIX_TABLE.'restrictions as r';
+ // 4. adding access to the new user, the same as the user "guest"
+ $query = 'SELECT cat_id';
+ $query.= ' FROM '.PREFIX_TABLE.'user_access as ua';
$query.= ','.PREFIX_TABLE.'users as u ';
- $query.= ' where u.id = r.user_id';
+ $query.= ' where u.id = ua.user_id';
$query.= " and u.username = 'guest';";
$result = mysql_query( $query );
while( $row = mysql_fetch_array( $result ) )
{
- $query = 'insert into '.PREFIX_TABLE.'restrictions';
- $query.= ' (user_id,cat_id) values';
+ $query = 'INSERT INTO '.PREFIX_TABLE.'user_access';
+ $query.= ' (user_id,cat_id) VALUES';
$query.= ' ('.$user_id.','.$row['cat_id'].');';
mysql_query ( $query );
}
@@ -181,8 +181,8 @@ function update_user( $user_id, $mail_address, $status,
if ( sizeof( $error ) == 0 )
{
- $query = 'update '.PREFIX_TABLE.'users';
- $query.= " set status = '".$status."'";
+ $query = 'UPDATE '.PREFIX_TABLE.'users';
+ $query.= " SET status = '".$status."'";
if ( $use_new_password )
{
$query.= ", password = '".md5( $password )."'";
@@ -196,9 +196,8 @@ function update_user( $user_id, $mail_address, $status,
{
$query.= 'NULL';
}
- $query.= ' where id = '.$user_id;
+ $query.= ' WHERE id = '.$user_id;
$query.= ';';
- echo $query;
mysql_query( $query );
}
return $error;
@@ -209,7 +208,7 @@ function check_login_authorization()
global $user,$lang,$conf,$page;
if ( $user['is_the_guest']
- and ( $conf['acces'] == 'restreint' or $page['cat'] == 'fav' ) )
+ and ( $conf['access'] == 'restricted' or $page['cat'] == 'fav' ) )
{
echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
@@ -221,36 +220,75 @@ function check_login_authorization()
// 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 )
+function get_restrictions( $user_id, $user_status,
+ $check_invisible, $use_groups = true )
{
- // 1. getting the ids of the restricted categories
+ // 1. retrieving ids of private categories
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= " WHERE status = 'private'";
+ $query.= ';';
+ $result = mysql_query( $query );
+ $privates = array();
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ array_push( $privates, $row['id'] );
+ }
+ // 2. retrieving all authorized categories for the user
+ $authorized = array();
+ // 2.1. retrieving authorized categories thanks to personnal user
+ // authorization
$query = 'SELECT cat_id';
- $query.= ' FROM '.PREFIX_TABLE.'restrictions';
+ $query.= ' FROM '.PREFIX_TABLE.'user_access';
$query.= ' WHERE user_id = '.$user_id;
$query.= ';';
$result = mysql_query( $query );
-
- $restriction = array();
while ( $row = mysql_fetch_array( $result ) )
{
- array_push( $restriction, $row['cat_id'] );
+ array_push( $authorized, $row['cat_id'] );
}
+ // 2.2. retrieving authorized categories thanks to group authorization to
+ // which the user is a member
+ if ( $use_groups )
+ {
+ $query = 'SELECT ga.cat_id';
+ $query.= ' FROM '.PREFIX_TABLE.'user_group as ug';
+ $query.= ', '.PREFIX_TABLE.'group_access as ga';
+ $query.= ' WHERE ug.group_id = ga.group_id';
+ $query.= ' AND ug.user_id = '.$user_id;
+ $query.= ';';
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ array_push( $authorized, $row['cat_id'] );
+ }
+ $authorized = array_unique( $authorized );
+ }
+
+ $forbidden = array();
+ foreach ( $privates as $private ) {
+ if ( !in_array( $private, $authorized ) )
+ {
+ array_push( $forbidden, $private );
+ }
+ }
+
if ( $check_invisible )
{
- // 2. adding to the restricted categories, the invisible ones
+ // 3. adding to the restricted categories, the invisible ones
if ( $user_status != 'admin' )
{
$query = 'SELECT id';
$query.= ' FROM '.PREFIX_TABLE.'categories';
- $query.= " WHERE status = 'invisible';";
+ $query.= " WHERE visible = 'false';";
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
- array_push( $restriction, $row['id'] );
+ array_push( $forbidden, $row['id'] );
}
}
}
- return $restriction;
+ return array_unique( $forbidden );
}
// The get_all_restrictions function returns an array with all the
@@ -258,17 +296,14 @@ function get_restrictions( $user_id, $user_status, $check_invisible )
// sub-categories and invisible categories
function get_all_restrictions( $user_id, $user_status )
{
- $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];
+ $restricted_cats = get_restrictions( $user_id, $user_status, true );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $sub_restricted_cats = get_subcats_id( $restricted_cat );
+ foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
+ array_push( $restricted_cats, $sub_restricted_cat );
}
}
- return $restricted_cat;
+ return $restricted_cats;
}
// The function is_user_allowed returns :
@@ -277,19 +312,17 @@ function get_all_restrictions( $user_id, $user_status )
// - 2 : if an uppercat category is not allowed
function is_user_allowed( $category_id, $restrictions )
{
- global $user;
-
$lowest_category_id = $category_id;
$is_root = false;
while ( !$is_root and !in_array( $category_id, $restrictions ) )
{
- $query = 'select id_uppercat';
- $query.= ' from '.PREFIX_TABLE.'categories';
- $query.= ' where id = '.$category_id;
+ $query = 'SELECT id_uppercat';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id = '.$category_id;
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
- if ( $row['id_uppercat'] == "" )
+ if ( $row['id_uppercat'] == '' )
{
$is_root = true;
}
diff --git a/include/functions_xml.inc.php b/include/functions_xml.inc.php
index 1919608ad..61ed5d0f9 100644
--- a/include/functions_xml.inc.php
+++ b/include/functions_xml.inc.php
@@ -18,7 +18,6 @@
//------------------------------------------------------------------ constantes
define( ATT_REG, '\w+' );
define( VAL_REG, '[^"]*' );
-
//------------------------------------------------------------------- functions
// getContent returns the content of a tag
//
@@ -32,15 +31,15 @@ function getContent( $element )
// deleting start of the tag
$content = preg_replace( '/^<[^>]+>/', '', $element );
// deleting end of the tag
- $content = preg_replace( '/<\/\w+>$/', '', $content );
+ $content = preg_replace( '/<\/[^>]+>$/', '', $content );
// replacing multiple instance of space character
$content = preg_replace( '/\s+/', ' ', $content );
return $content;
}
-// The function get Attribute returns the value corresponding to the attribute
-// $attribute for the tag $element.
+// The function get Attribute returns the value corresponding to the
+// attribute $attribute for the tag $element.
function getAttribute( $element, $attribute )
{
$regex = '/^<\w+[^>]*'.$attribute.'\s*=\s*"('.VAL_REG.')"/i';
diff --git a/include/init.inc.php b/include/init.inc.php
index 21a3ac8b0..ad25a679b 100644
--- a/include/init.inc.php
+++ b/include/init.inc.php
@@ -14,8 +14,8 @@
* the Free Software Foundation; *
* *
***************************************************************************/
-define( PREFIXE_INCLUDE, '' );
-
+define( PREFIX_INCLUDE, '' );
+
include_once( './include/config.inc.php' );
include_once( './include/user.inc.php' );
diff --git a/include/user.inc.php b/include/user.inc.php
index 6447b220e..8efd8219f 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -24,7 +24,7 @@ $infos = array( 'id', 'username', 'mail_address', 'nb_image_line',
'maxheight', 'expand', 'show_nb_comments', 'short_period',
'long_period', 'template' );
-$query_user = 'select';
+$query_user = 'SELECT';
for ( $i = 0; $i < sizeof( $infos ); $i++ )
{
if ( $i > 0 )
@@ -37,16 +37,16 @@ for ( $i = 0; $i < sizeof( $infos ); $i++ )
}
$query_user.= $infos[$i];
}
-$query_user.= ' from '.PREFIX_TABLE.'users';
+$query_user.= ' FROM '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'sessions';
- $query.= " where id = '".$_GET['id']."'";
+ $query = 'SELECT user_id,expiration,ip';
+ $query.= ' FROM '.PREFIX_TABLE.'sessions';
+ $query.= " WHERE id = '".$_GET['id']."'";
$query.= ';';
$result = mysql_query( $query );
if ( mysql_num_rows( $result ) > 0 )
@@ -56,8 +56,8 @@ if ( isset( $_GET['id'] )
{
// deletion of the session from the database,
// because it is out-of-date
- $delete_query = 'delete from '.PREFIX_TABLE.'sessions';
- $delete_query.= " where id = '".$page['session_id']."'";
+ $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
+ $delete_query.= " WHERE id = '".$page['session_id']."'";
$delete_query.= ';';
mysql_query( $delete_query );
}
@@ -65,7 +65,7 @@ if ( isset( $_GET['id'] )
{
if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] )
{
- $query_user .= ' where id = '.$row['user_id'];
+ $query_user .= ' WHERE id = '.$row['user_id'];
$query_done = true;
}
}
@@ -73,7 +73,7 @@ if ( isset( $_GET['id'] )
}
if ( !$query_done )
{
- $query_user .= ' where id = 2';
+ $query_user .= ' WHERE id = 2';
$user['is_the_guest'] = true;
}
$query_user .= ';';
@@ -82,14 +82,13 @@ $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]];
+foreach ( $infos as $info ) {
+ $user[$info] = $row[$info];
// If the field is true or false, the variable is transformed into a
// boolean value.
- if ( $row[$infos[$i]] == 'true' || $row[$infos[$i]] == 'false' )
+ if ( $row[$info] == 'true' or $row[$info] == 'false' )
{
- $user[$infos[$i]] = get_boolean( $row[$infos[$i]] );
+ $user[$info] = get_boolean( $row[$info] );
}
}
?> \ No newline at end of file
diff --git a/include/vtemplate.class.php b/include/vtemplate.class.php
index 8f531412c..5f905ac92 100644
--- a/include/vtemplate.class.php
+++ b/include/vtemplate.class.php
@@ -2,372 +2,369 @@
/*****************************************************************
* VIRTUAL-TEMPLATE
*
- * Version : 1.3.1 Base Edition ( Juillet 2002 ) build 6
+ * Version : 1.3.2 Base Edition ( Decembre 2003 ) build 1
*
* Address : http://vtemplate.sourceforge.net
*
* Authors:
- * + THIEBAUT Jean-Baptiste(J.Baptiste@leweby.com) - http://www.leweby.com .
+ * + 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 )
- {
+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;
- }
+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();
- }
+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);
+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(){
+$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);
+if(!$this->used) return $this->error(2,array($this->stored,$this->name),"SESSION2",1);
// Set Globals vars.
- $this->generateCode();
- $this->used=0;
- return 1;
- }
+$this->generateCode();
+$this->used=0;
+return 1;
+}
- function reset(){
- $this->used = 0;
- $this->generated = NULL;
- return 1;
- }
+function reset(){
+$this->used = 0;
+$this->generated = NULL;
+return 1;
+}
- function addSubZone(&$subzone){
- $this->subzone[$subzone->name] = &$subzone;
- 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 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 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 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 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 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);
- }
+function inVarList($varname){
+return in_array($varname,$this->varlist);
+}
// Fin classe
- }
+}
- class VTemplate_Private extends Err{
+class VTemplate_Private extends Err{
/****************************************
- * Private Class. *
- * ***************************************/
+* 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.
+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){
+function getNom($code){
// Retourne le premier nom de zone qu'il trouve dans le code
- preg_match("(<!--VTP_([^()]+)-->)sU",$code,$reg);
+ 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));
+ // 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];
- }
+ return @$reg[1];
+}
- function endTag($code,$nom){
+function endTag($code,$nom){
// Renvoie TRUE(1) si le tag de fermeture est présent.
- preg_match("(<!--/VTP_$nom-->)sU",$code,$reg);
+ preg_match("(<!--/VTP_$nom-->)sU",$code,$reg);
- return ($reg[0]!="<!--/VTP_$nom-->") ? 0 : 1;
- }
+return ($reg[0]!="<!--/VTP_$nom-->") ? 0 : 1;
+}
- function getSource($code,$nom,$type=0){
+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);
+ preg_match_all ("(<!--VTP_$nom-->(.*)<!--/VTP_$nom-->)sU",$code,$reg);
- return $reg[$type][0];
- }
+return $reg[$type][0];
+}
- function parseZone($code_source,$nom_zone="|root|"){
+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));
+ // 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;
+ // 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"])){
+ // 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));
+ // 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);
+ // 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;
+ // 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
+ // 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;
- }
+return 1;
+}
/****************************************************************
Session Management functions ( SMF 1.0 )
-****************************************************************/
+ ****************************************************************/
- function createSession($handle,$zone = "|root|"){
+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]);
+$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]);
- }
- }
+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 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 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 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){
+function setGOpened($handle){
// Set Global var into the opened file
- foreach($this->v_global as $name => $val){
- $this->setGFile($handle,$name,$val);
- }
- return 1;
- }
+foreach($this->v_global as $name => $val){
+ $this->setGFile($handle,$name,$val);
+}
+return 1;
+}
// Fin VTemplate_Private
- }
+}
- class VTemplate extends VTemplate_Private{
+class VTemplate extends VTemplate_Private{
/****************************************
- * Public Class. *
- * ***************************************/
+* Public Class. *
+* ***************************************/
/****************************************************************
@@ -375,145 +372,233 @@ if ( !isset($DEFINE_VTEMPLATE) )
*****************************************************************/
- function Open($nomfichier){
+function Open($nomfichier){
// Ouverture d'un fichier source et retourne le handle de ce fichier
// Création du handle:
- $handle = "{".count($this->sessions)."}" ;
+$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);
+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;
+$this->file_name[$handle]=$nomfichier;
// Parse les zones
- $this->parseZone($source);
+$this->parseZone($source);
// Création du tableau de session
- $this->createSession($handle);
+$this->createSession($handle);
//Nettoyage des variables temporaires
- $this->sources=NULL;
+$this->sources=NULL;
// Set global var.
- $this->setGOpened($handle);
+$this->setGOpened($handle);
- $this->addSession($handle);
- return $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 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 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|"){
+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;
- }
+ // 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 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 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 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){
+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);
+$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];
- }
+ 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);
+ 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);
+ // 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);
- }
+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;
+
+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);
- }
+ if ($display) echo $c_genere; else return ($c_genere);
+}
+//fonction complementaire version BETA
+
+/*
+*
+On peut l'utiliser :
+- SetVarTab($array): tout les couples clef/valeur sont valorisées
+- SetVarTab($array,$index) seuls les couples clef/valeur dont la clef est dans le tableau index ou dont la valeur == $index (si pas tableau)
+Si $index contient ou est une clef de type zone.clef, la clef sera extraite du texte est servira d'index pour $array
+
+Vincent
+*/
+
+function setVarTab($handle,$zones,$index = array()){
+ if (is_array($index))
+ {
+ if (count($index)>0)
+ {
+ reset($index);
+ while (list (, $key) = each ($index))
+ {
+ $tab=explode(".",$key);
+ if(count($tab)==2){
+ $var=$tab[1];
+ }
+ else
+ {
+ $var=$tab[0];
+ }
+ setVar($handle,$key,$zones[$var]);
+ }
+ }
+ else
+ {
+ reset($zones);
+ while (list ($key, $val) = each ($zones))
+ {
+ setVar($handle,$key,$val);
+ }
+ }
+ }
+ else
+ {
+ setVar($handle,$index,$zones[$index]);
+ }
+}
+
+function setGlobalVarTab($handle,$zones,$index = array()){
+
+ if (is_array($index))
+ {
+ if (count($index)>0)
+ {
+ reset($index);
+ while (list (, $key) = each ($index))
+ {
+ $tab=explode(".",$key);
+ if(count($tab)==2){
+ $var=$tab[1];
+ }
+ else
+ {
+ $var=$tab[0];
+ }
+ setGlobalVar($handle,$key,$zones[$var]);
+ }
+ }
+ else
+ {
+ reset($zones);
+ while (list ($key, $val) = each ($zones))
+ {
+ GlobalVar($handle,$key,$val);
+ }
+ }
+ }
+ else
+ {
+ setBlobalVar($handle,$index,$zones[$index]);
+ }
+}
+
+
+
+
// End VTemplate
- }
- $DEFINE_VTEMPLATE = 1;
+}
+$DEFINE_VTEMPLATE = 1;
}
?>