diff options
author | gweltas <gweltas@piwigo.org> | 2004-02-02 00:55:18 +0000 |
---|---|---|
committer | gweltas <gweltas@piwigo.org> | 2004-02-02 00:55:18 +0000 |
commit | bef4b3e3aa8e3d54cbf8b4962b9b5d4a89b55429 (patch) | |
tree | 647b2cf07ee8451a9314e1e8aebd11d9396cb32b /include | |
parent | eea989f019f21fbd7ae4aa8e2f4a1503992c23bf (diff) |
Merge of the 1.3.1 release
Creation of an unique include file (common.php)
Creation of an unique define file (include/constants.php)
Modification of the installation procedure
git-svn-id: http://piwigo.org/svn/trunk@345 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r-- | include/config.inc.php | 47 | ||||
-rw-r--r-- | include/constants.php (renamed from include/constant.php) | 16 | ||||
-rw-r--r-- | include/functions.inc.php | 122 | ||||
-rw-r--r-- | include/functions_category.inc.php | 355 | ||||
-rw-r--r-- | include/functions_group.inc.php | 6 | ||||
-rw-r--r-- | include/functions_user.inc.php | 241 | ||||
-rw-r--r-- | include/functions_xml.inc.php | 4 | ||||
-rw-r--r-- | include/init.inc.php | 35 | ||||
-rw-r--r-- | include/page_header.php | 30 | ||||
-rw-r--r-- | include/page_tail.php | 19 | ||||
-rw-r--r-- | include/user.inc.php | 36 | ||||
-rw-r--r-- | include/vtemplate.class.php | 1 |
12 files changed, 395 insertions, 517 deletions
diff --git a/include/config.inc.php b/include/config.inc.php index ff633f5de..ada80a650 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -2,7 +2,7 @@ /*************************************************************************** * config.inc.php * * ------------------- * - * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * + * application : PhpWebGallery 1.4 <http://phpwebgallery.net> * * author : Pierrick LE GALL <pierrick@z0rglub.com> * * * * $Id$ @@ -16,14 +16,6 @@ * the Free Software Foundation; * * * ***************************************************************************/ -unset( $conf, $page, $user, $lang ); -$conf = array(); -$page = array(); -$user = array(); -$lang = array(); - -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 ? // // You have to modify $conf['order_by']. @@ -44,46 +36,13 @@ $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['slideshow_period'] = array(2,5,10); $conf['last_days'] = array(1,2,3,10,30,365); -$conf['version'] = 'devel'; +$conf['version'] = '1.4 - devel'; $conf['site_url'] = 'http://www.phpwebgallery.net'; $conf['forum_url'] = 'http://forum.phpwebgallery.net'; $conf['picture_ext'] = array('jpg','JPG','gif','GIF','png','PNG'); $conf['document_ext'] = array('doc','pdf','zip'); $conf['top_number'] = 10; $conf['anti-flood_time'] = 60; // seconds between 2 comments : 0 to disable +$conf['max_LOV_categories'] = 50; -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 : -// prefix_thumbnail --> $conf['prefix_thumbnail'] -$infos = array( 'prefix_thumbnail', 'webmaster', 'mail_webmaster', 'access', - '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','log','comments_validation', - 'comments_forall','authorize_cookies','mail_notification' ); - -$query = 'SELECT '; -foreach ( $infos as $i => $info ) { - if ( $i > 0 ) $query.= ','; - $query.= $info; -} -$query.= ' FROM '.PREFIX_TABLE.'config;'; - -$row = mysql_fetch_array( mysql_query( $query ) ); - -// affectation of each field of the table "config" to an information of the -// array $conf. -foreach ( $infos as $info ) { - $conf[$info] = $row[$info]; - // If the field is true or false, the variable is transformed into a boolean - // value. - if ( $row[$info] == 'true' or $row[$info] == 'false' ) - { - $conf[$info] = get_boolean( $row[$info] ); - } -} ?>
\ No newline at end of file diff --git a/include/constant.php b/include/constants.php index 07d940c3e..d7e8fded7 100644 --- a/include/constant.php +++ b/include/constants.php @@ -18,8 +18,22 @@ ***************************************************************************/ define( 'PREFIX_INCLUDE', '' ); + +// Debug Level +define('DEBUG', 1); // Debugging on +//define('DEBUG', 0); // Debugging off + +// Error codes +define('GENERAL_MESSAGE', 200); +define('GENERAL_ERROR', 202); +define('CRITICAL_MESSAGE', 203); +define('CRITICAL_ERROR', 204); + +// xml tags +define( 'ATT_REG', '\w+' ); +define( 'VAL_REG', '[^"]*' ); - // Table names +// Table names define('CATEGORIES_TABLE', $table_prefix.'categories'); define('COMMENTS_TABLE', $table_prefix.'comments'); define('CONFIG_TABLE', $table_prefix.'config'); diff --git a/include/functions.inc.php b/include/functions.inc.php index ccfc5fa88..67416291a 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1,20 +1,21 @@ <?php -// +-----------------------------------------------------------------------+ -// | functions.inc.php | -// +-----------------------------------------------------------------------+ -// | application : PhpWebGallery 1.3 <http://phpwebgallery.net> | -// | author : Pierrick LE GALL <pierrick@z0rglub.com> | -// +-----------------------------------------------------------------------+ -// | file : $RCSfile$ -// | tag : $Name$ -// | last update : $Date$ -// | revision : $Revision$ -// +-----------------------------------------------------------------------+ -// | 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; | -// +-----------------------------------------------------------------------+ +/*************************************************************************** + * functions.inc.php * + * ------------------- * + * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * + * author : Pierrick LE GALL <pierrick@z0rglub.com> * + * * + * $Id$ + * * + *************************************************************************** + *************************************************************************** + * * + * 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( PREFIX_INCLUDE.'./include/functions_user.inc.php' ); include( PREFIX_INCLUDE.'./include/functions_session.inc.php' ); include( PREFIX_INCLUDE.'./include/functions_category.inc.php' ); @@ -166,23 +167,27 @@ function get_filename_wo_extension( $filename ) return substr( $filename, 0, strrpos( $filename, '.' ) ); } -// get_dirs retourne un tableau contenant tous les sous-répertoires d'un -// répertoire -function get_dirs( $rep ) +/** + * returns an array contening sub-directories + * + * @param string $dir + * @return array + */ +function get_dirs( $directory ) { - $sub_rep = array(); + $sub_dirs = array(); - if ( $opendir = opendir ( $rep ) ) + if ( $opendir = opendir( $directory ) ) { while ( $file = readdir ( $opendir ) ) { - if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) ) + if ( $file != '.' and $file != '..' and is_dir ( $directory.'/'.$file ) ) { - array_push( $sub_rep, $file ); + array_push( $sub_dirs, $file ); } } } - return $sub_rep; + return $sub_dirs; } // The get_picture_size function return an array containing : @@ -265,22 +270,6 @@ function get_languages( $rep_language ) 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; -} - // - add_style replaces the // $search into <span style="$style">$search</span> // in the given $string. @@ -324,17 +313,6 @@ function replace_search( $string, $search ) return $string; } -function database_connection() -{ - include( PREFIX_INCLUDE.'./include/mysql.inc.php' ); - define( "PREFIX_TABLE", $prefixeTable ); - - @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; @@ -355,6 +333,7 @@ function templatize_array( $array, $global_array_name, $handle ) global $vtp, $lang, $page, $user, $conf; foreach ( $array as $value ) { + if (isset(${$global_array_name}[$value])) $vtp->setGlobalVar( $handle, $value, ${$global_array_name}[$value] ); } } @@ -432,4 +411,47 @@ function notify( $type, $infos = '' ) @mail( $to, $subject, $content, $headers, $options ); } } + +function pwg_write_debug() +{ + global $debug; + + $fp = @fopen( './log/debug.log', 'a+' ); + fwrite( $fp, "\n\n" ); + fwrite( $fp, $debug ); + fclose( $fp ); +} + +function pwg_query( $query ) +{ + global $count_queries,$queries_time; + + $start = get_moment(); + $output = ''; + + $count_queries++; + $output.= '<br /><br />['.$count_queries.'] '.$query; + $result = mysql_query( $query ); + $time = get_moment() - $start; + $queries_time+= $time; + $output.= '<b>('.number_format( $time, 3, '.', ' ').' s)</b>'; + $output.= '('.number_format( $queries_time, 3, '.', ' ').' s)'; + + // echo $output; + + return $result; +} + +function pwg_debug( $string ) +{ + global $debug,$t2,$count_queries; + + $now = explode( ' ', microtime() ); + $now2 = explode( '.', $now[0] ); + $now2 = $now[1].'.'.$now2[1]; + $time = number_format( $now2 - $t2, 3, '.', ' ').' s'; + $debug.= '['.$time.', '; + $debug.= $count_queries.' queries] : '.$string; + $debug.= "\n"; +} ?>
\ No newline at end of file diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index a691140d6..311935b49 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -17,31 +17,11 @@ * * ***************************************************************************/ -function get_subcats_id( $cat_id ) -{ - $restricted_cats = array(); - - $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 ) ) - { - 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_cats; -} - function check_restrictions( $category_id ) { global $user,$lang; - if ( is_user_allowed( $category_id, $user['restrictions'] ) > 0 ) + if ( in_array( $category_id, $user['restrictions'] ) ) { echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; echo '<a href="'.add_session_id( './category.php' ).'">'; @@ -49,7 +29,7 @@ function check_restrictions( $category_id ) 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) @@ -61,19 +41,14 @@ function check_cat_id( $cat ) unset( $page['cat'] ); if ( isset( $cat ) ) { - if ( isset( $page['plain_structure'] ) ) + if ( isset( $page['plain_structure'][$cat] ) ) { - if ( isset( $page['plain_structure'][$cat] ) ) - { - $page['cat'] = $cat; - } + $page['cat'] = $cat; } else if ( is_numeric( $cat ) ) { $query = 'SELECT id'; - $query.= ' FROM '.PREFIX_TABLE.'categories'; - $query.= ' WHERE id = '.$cat; - $query. ';'; + $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';'; $result = mysql_query( $query ); if ( mysql_num_rows( $result ) != 0 ) { @@ -91,17 +66,34 @@ function check_cat_id( $cat ) } } -function get_plain_structure() +function get_user_plain_structure() { - $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat', - 'rank','site_id'); + global $page,$user; + + $infos = array( 'name','id','uc.date_last','nb_images','dir','id_uppercat', + 'rank','site_id','nb_sub_categories','uppercats'); - $query = 'SELECT '; - foreach ( $infos as $i => $info ) { - if ( $i > 0 ) $query.= ','; - $query.= $info; + $query = 'SELECT '.implode( ',', $infos ); + $query.= ' FROM '.CATEGORIES_TABLE.' AS c'; +// $query.= ' ,'.PREFIX_TABLE.'user_category AS uc'; + $query.= ' INNER JOIN '.USER_CATEGORY_TABLE.' AS uc'; + $query.= ' ON c.id = uc.category_id'; + $query.= ' WHERE user_id = '.$user['id']; + if ( $page['expand'] != 'all' ) + { + $query.= ' AND (id_uppercat is NULL'; + if ( count( $page['tab_expand'] ) > 0 ) + { + $query.= ' OR id_uppercat IN ('.$page['expand'].')'; + } + $query.= ')'; + } + if ( $user['forbidden_categories'] != '' ) + { + $query.= ' AND id NOT IN '; + $query.= '('.$user['forbidden_categories'].')'; } - $query.= ' FROM '.PREFIX_TABLE.'categories'; +// $query.= ' AND c.id = uc.category_id'; $query.= ' ORDER BY id_uppercat ASC, rank ASC'; $query.= ';'; @@ -111,12 +103,13 @@ function get_plain_structure() { $category = array(); foreach ( $infos as $info ) { - $category[$info] = $row[$info]; - if ( $info == 'date_last' ) + if ( $info == 'uc.date_last' ) { - list($year,$month,$day) = explode( '-', $row[$info] ); - $category[$info] = mktime(0,0,0,$month,$day,$year); + list($year,$month,$day) = explode( '-', $row['date_last'] ); + $category['date_last'] = mktime(0,0,0,$month,$day,$year); } + else if ( isset( $row[$info] ) ) $category[$info] = $row[$info]; + else $category[$info] = ''; } $plain_structure[$row['id']] = $category; } @@ -124,27 +117,24 @@ function get_plain_structure() return $plain_structure; } -function create_structure( $id_uppercat, $restrictions ) +function create_user_structure( $id_uppercat ) { global $page; if ( !isset( $page['plain_structure'] ) ) - $page['plain_structure'] = get_plain_structure(); + $page['plain_structure'] = get_user_plain_structure(); $structure = array(); - $ids = get_subcat_ids( $id_uppercat ); + $ids = get_user_subcat_ids( $id_uppercat ); foreach ( $ids as $id ) { - if ( !in_array( $id, $restrictions ) ) - { - $category = $page['plain_structure'][$id]; - $category['subcats'] = create_structure( $id, $restrictions ); - array_push( $structure, $category ); - } + $category = $page['plain_structure'][$id]; + $category['subcats'] = create_user_structure( $id ); + array_push( $structure, $category ); } return $structure; } -function get_subcat_ids( $id_uppercat ) +function get_user_subcat_ids( $id_uppercat ) { global $page; @@ -157,31 +147,14 @@ function get_subcat_ids( $id_uppercat ) } // update_structure updates or add informations about each node of the -// structure : the last date, should the category be expanded in the menu ?, -// the associated expand string "48,14,54" -// -// 1. last date -// for each category of the structure, we have to find the most recent -// subcat so that the parent cat has the same last_date info. -// For example : we have : -// > pets (2003.02.15) -// > dogs (2003.06.14) -// > rex (2003.06.18) -// > toby (2003.06.13) -// > kitten (2003.07.05) -// We finally want to have : -// > pets (2003.07.05) <- changed to pets > kitten last date -// > dogs (2003.06.18) <- changed to pets > dogs > rex last date -// > rex (2003.06.18) -// > toby (2003.06.13) -// > kitten (2003.07.05) +// structure : // -// 2. should the category be expanded in the menu ? +// 1. should the category be expanded in the menu ? // If the category has to be expanded (ie its id is in the // $page['tab_expand'] or all the categories must be expanded by default), // $category['expanded'] is set to true. // -// 3. associated expand string +// 2. associated expand string // in the menu, there is a expand string (used in the URL) to tell which // categories must be expanded in the menu if this category is chosen function update_structure( $categories ) @@ -191,9 +164,6 @@ function update_structure( $categories ) $updated_categories = array(); foreach ( $categories as $category ) { - // update the last date of the category - $last_date = search_last_date( $category ); - $category['date_last'] = $last_date; // update the "expanded" key if ( $user['expand'] or $page['expand'] == 'all' @@ -205,7 +175,7 @@ function update_structure( $categories ) { $category['expanded'] = false; } - // update the "expand_string" key + // update the "expand_string" key if ( $page['expand'] == 'all' ) { $category['expand_string'] = 'all'; @@ -219,7 +189,7 @@ function update_structure( $categories ) // the $category['id'] $tab_expand = array_diff( $page['tab_expand'],array($category['id']) ); } - else if ( count( $category['subcats'] ) > 0 ) + else if ( $category['nb_sub_categories'] > 0 ) { // we have this time to add the $category['id']... $tab_expand = array_merge($page['tab_expand'],array($category['id'])); @@ -235,24 +205,6 @@ function update_structure( $categories ) return $updated_categories; } -// search_last_date searchs the last date for a given category. If we take -// back the example given for update_last_dates, we should have : -// search_last_date( pets ) --> 2003.07.05 -// search_last_date( pets > dogs ) --> 2003.06.18 -// and so on -function search_last_date( $category ) -{ - $date_last = $category['date_last']; - foreach ( $category['subcats'] as $subcat ) { - $subcat_date_last = search_last_date( $subcat ); - if ( $subcat_date_last > $date_last ) - { - $date_last = $subcat_date_last; - } - } - return $date_last; -} - // count_images returns the number of pictures contained in the given // category represented by an array, in this array, we have (among other // things) : @@ -262,6 +214,7 @@ function search_last_date( $category ) // pictures contained in the given given category function count_images( $categories ) { + return count_user_total_images(); $total = 0; foreach ( $categories as $category ) { $total+= $category['nb_images']; @@ -270,6 +223,23 @@ function count_images( $categories ) return $total; } +function count_user_total_images() +{ + global $user; + + $query = 'SELECT SUM(nb_images) AS total'; + $query.= ' FROM '.CATEGORIES_TABLE; + if ( count( $user['restrictions'] ) > 0 ) + $query.= ' WHERE id NOT IN ('.$user['forbidden_categories'].')'; + $query.= ';'; + + $row = mysql_fetch_array( mysql_query( $query ) ); + + if ( !isset( $row['total'] ) ) $row['total'] = 0; + + return $row['total']; +} + // variables : // $cat['comment'] // $cat['dir'] @@ -285,37 +255,45 @@ function get_cat_info( $id ) { global $page; - $cat = array(); - - $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir'; - $query.= ',date_last,uploadable,status,visible,representative_picture_id'; - $query.= ' FROM '.PREFIX_TABLE.'categories AS a'; - $query.= ', '.PREFIX_TABLE.'sites AS b'; + $infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url' + ,'dir','date_last','uploadable','status','visible' + ,'representative_picture_id','uppercats' ); + + $query = 'SELECT '.implode( ',', $infos ); + $query.= ' FROM '.CATEGORIES_TABLE.' AS a'; + $query.= ', '.SITES_TABLE.' AS b'; $query.= ' WHERE a.id = '.$id; - $query.= ' AND a.site_id = b.id;'; + $query.= ' AND a.site_id = b.id'; + $query.= ';'; $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['dir'] = $row['dir']; - $cat['date_last'] = $row['date_last']; - $cat['uploadable'] = get_boolean( $row['uploadable'] ); - $cat['status'] = $row['status']; - $cat['visible'] = get_boolean( $row['visible'] ); - $cat['representative_picture_id'] = $row['representative_picture_id']; - $cat['name'] = array(); + $cat = array(); + // affectation of each field of the table "config" to an information of the + // array $cat. + foreach ( $infos as $info ) { + if ( isset( $row[$info] ) ) $cat[$info] = $row[$info]; + else $cat[$info] = ''; + // If the field is true or false, the variable is transformed into a + // boolean value. + if ( $cat[$info] == 'true' or $cat[$info] == 'false' ) + { + $cat[$info] = get_boolean( $cat[$info] ); + } + } + $cat['comment'] = nl2br( $cat['comment'] ); - if ( !isset( $page['plain_structure'] ) ) - $page['plain_structure'] = get_plain_structure(); + $cat['name'] = array(); - array_push( $cat['name'], $page['plain_structure'][$id]['name'] ); - while ( $page['plain_structure'][$id]['id_uppercat'] != '' ) + $query = 'SELECT name FROM '.CATEGORIES_TABLE; + $query.= ' WHERE id IN ('.$cat['uppercats'].')'; + $query.= ' ORDER BY id ASC'; + $query.= ';'; + $result = mysql_query( $query ); + while( $row = mysql_fetch_array( $result ) ) { - $id = $page['plain_structure'][$id]['id_uppercat']; - array_push( $cat['name'], $page['plain_structure'][$id]['name'] ); + array_push( $cat['name'], $row['name'] ); } + return $cat; } @@ -337,17 +315,38 @@ function get_local_dir( $category_id ) { global $page; - if ( !isset( $page['plain_structure'] ) ) - $page['plain_structure'] = get_plain_structure(); - - // creating the local path : "root_cat/sub_cat/sub_sub_cat/" - $dir = $page['plain_structure'][$category_id]['dir'].'/'; - while ( $page['plain_structure'][$category_id]['id_uppercat'] != '' ) + $uppercats = ''; + $local_dir = ''; + + if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) ) + { + $uppercats = $page['plain_structure'][$category_id]['uppercats']; + } + else + { + $query = 'SELECT uppercats'; + $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id; + $query.= ';'; + $row = mysql_fetch_array( mysql_query( $query ) ); + $uppercats = $row['uppercats']; + } + + $upper_array = explode( ',', $uppercats ); + + $database_dirs = array(); + $query = 'SELECT id,dir'; + $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')'; + $query.= ';'; + $result = mysql_query( $query ); + while( $row = mysql_fetch_array( $result ) ) { - $category_id = $page['plain_structure'][$category_id]['id_uppercat']; - $dir = $page['plain_structure'][$category_id]['dir'].'/'.$dir; + $database_dirs[$row['id']] = $row['dir']; + } + foreach ( $upper_array as $id ) { + $local_dir.= $database_dirs[$id].'/'; } - return $dir; + + return $local_dir; } // retrieving the site url : "http://domain.com/gallery/" or @@ -356,12 +355,10 @@ function get_site_url( $category_id ) { global $page; - if ( !isset( $page['plain_structure'] ) ) - $page['plain_structure'] = get_plain_structure(); - $query = 'SELECT galleries_url'; - $query.= ' FROM '.PREFIX_TABLE.'sites'; - $query.= ' WHERE id = '.$page['plain_structure'][$category_id]['site_id']; + $query.= ' FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c'; + $query.= ' WHERE s.id = c.site_id'; + $query.= ' AND c.id = '.$category_id; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); return $row['galleries_url']; @@ -374,33 +371,19 @@ function get_site_url( $category_id ) // - $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 ) +function get_cat_display_name( $array_cat_names, $separation, + $style, $replace_space = true ) { - $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]; - } + $output = ''; + foreach ( $array_cat_names as $i => $name ) { + if ( $i > 0 ) $output.= $separation; + if ( $i < count( $array_cat_names ) - 1 or $style == '') + $output.= $name; else - { - if ( $style != "" ) - { - $output.= '<span style="'.$style.'">'; - } - $output.= $array_cat_names[$i]; - if ( $style != "" ) - { - $output.= "</span>"; - } - } + $output.= '<span style="'.$style.'">'.$name.'</span>'; } - return replace_space( $output ); + if ( $replace_space ) return replace_space( $output ); + else return $output; } // initialize_category initializes ;-) the variables in relation @@ -418,6 +401,7 @@ function get_cat_display_name( $array_cat_names, $separation, $style ) // 4. creation of the navigation bar function initialize_category( $calling_page = 'category' ) { + pwg_debug( 'start initialize_category' ); global $page,$lang,$user,$conf; if ( isset( $page['cat'] ) ) @@ -426,7 +410,8 @@ function initialize_category( $calling_page = 'category' ) // 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'].'&expand='.$page['expand']; + $url = './category.php?cat='.$page['cat']; + if ( isset($page['expand']) ) $url.= '&expand='.$page['expand']; // simple category if ( is_numeric( $page['cat'] ) ) { @@ -437,7 +422,8 @@ function initialize_category( $calling_page = 'category' ) $page['cat_nb_images'] = $result['nb_images']; $page['cat_site_id'] = $result['site_id']; $page['cat_uploadable'] = $result['uploadable']; - $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' ); + $page['uppercats'] = $result['uppercats']; + $page['title'] = get_cat_display_name( $page['cat_name'],' - ','',false); $page['where'] = ' WHERE category_id = '.$page['cat']; } else @@ -446,15 +432,10 @@ function initialize_category( $calling_page = 'category' ) or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' ) { // we must not show pictures of a forbidden category - $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); - if ( count( $restricted_cats ) > 0 ) + if ( $user['forbidden_categories'] != '' ) { - $where_append.= ' AND category_id NOT IN ('; - foreach ( $restricted_cats as $i => $restricted_cat ) { - if ( $i > 0 ) $where_append.= ','; - $where_append.= $restricted_cat; - } - $where_append.= ')'; + $forbidden = ' category_id NOT IN '; + $forbidden.= '('.$user['forbidden_categories'].')'; } } // search result @@ -499,11 +480,11 @@ function initialize_category( $calling_page = 'category' ) } } $page['where'].= ' )'; - $page['where'].= $where_append; + if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images'; - $query.= ' FROM '.PREFIX_TABLE.'images'; - $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic'; + $query.= ' FROM '.IMAGES_TABLE; + $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; $query.= ' ON id = ic.image_id'; $query.= $page['where']; $query.= ';'; @@ -515,12 +496,12 @@ function initialize_category( $calling_page = 'category' ) { $page['title'] = $lang['favorites']; - $page['where'] = ', '.PREFIX_TABLE.'favorites AS fav'; + $page['where'] = ', '.FAVORITES_TABLE.' AS fav'; $page['where'].= ' WHERE user_id = '.$user['id']; $page['where'].= ' AND fav.image_id = id'; $query = 'SELECT COUNT(*) AS nb_total_images'; - $query.= ' FROM '.PREFIX_TABLE.'favorites'; + $query.= ' FROM '.FAVORITES_TABLE; $query.= ' WHERE user_id = '.$user['id']; $query.= ';'; } @@ -533,11 +514,11 @@ function initialize_category( $calling_page = 'category' ) $date = time() - 60*60*24*$user['short_period']; $page['where'] = " WHERE date_available > '"; $page['where'].= date( 'Y-m-d', $date )."'"; - $page['where'].= $where_append; + if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images'; - $query.= ' FROM '.PREFIX_TABLE.'images'; - $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic'; + $query.= ' FROM '.IMAGES_TABLE; + $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; $query.= ' ON id = ic.image_id'; $query.= $page['where']; $query.= ';'; @@ -546,16 +527,19 @@ function initialize_category( $calling_page = 'category' ) else if ( $page['cat'] == 'most_visited' ) { $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat']; - $page['where'] = ' WHERE category_id != -1'.$where_append; + + if ( isset( $forbidden ) ) $page['where'] = ' WHERE '.$forbidden; + else $page['where'] = ''; $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'] ) + if ( isset( $page['start'] ) + and ($page['start']+$user['nb_image_page']>=$conf['top_number'])) { $page['nb_image_page'] = $conf['top_number'] - $page['start']; } } - if ( $query != '' ) + if ( isset($query)) { $result = mysql_query( $query ); $row = mysql_fetch_array( $result ); @@ -573,6 +557,7 @@ function initialize_category( $calling_page = 'category' ) { $page['title'] = $lang['diapo_default_page_title']; } + pwg_debug( 'end initialize_category' ); } // get_non_empty_subcat_ids returns an array with sub-categories id @@ -599,13 +584,14 @@ function get_non_empty_subcat_ids( $id_uppercat ) $ids = array(); $query = 'SELECT id,nb_images'; - $query.= ' FROM '.PREFIX_TABLE.'categories'; + $query.= ' FROM '.CATEGORIES_TABLE; $query.= ' WHERE id_uppercat '; if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL'; else $query.= '= '.$id_uppercat; // we must not show pictures of a forbidden category - foreach ( $user['restrictions'] as $restricted_cat ) { - $query.= ' AND id != '.$restricted_cat; + if ( $user['forbidden_categories'] != '' ) + { + $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; } $query.= ' ORDER BY rank'; $query.= ';'; @@ -632,11 +618,12 @@ function get_first_non_empty_cat_id( $id_uppercat ) global $user; $query = 'SELECT id,nb_images'; - $query.= ' FROM '.PREFIX_TABLE.'categories'; + $query.= ' FROM '.CATEGORIES_TABLE; $query.= ' WHERE id_uppercat = '.$id_uppercat; // we must not show pictures of a forbidden category - foreach ( $user['restrictions'] as $restricted_cat ) { - $query.= ' AND id != '.$restricted_cat; + if ( $user['forbidden_categories'] != '' ) + { + $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; } $query.= ' ORDER BY RAND()'; $query.= ';'; diff --git a/include/functions_group.inc.php b/include/functions_group.inc.php index 68c01b68d..8575b25a9 100644 --- a/include/functions_group.inc.php +++ b/include/functions_group.inc.php @@ -85,10 +85,8 @@ function is_group_allowed( $category_id, $restrictions ) $query.= ' WHERE id = '.$category_id; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); - if ( $row['id_uppercat'] == '' ) - { - $is_root = true; - } + if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = ''; + if ( $row['id_uppercat'] == '' ) $is_root = true; $category_id = $row['id_uppercat']; } diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 5bc70cf92..95ca7bb3c 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -37,8 +37,8 @@ function validate_mail_address( $mail_address ) } } -function register_user( - $login, $password, $password_conf, $mail_address, $status = 'guest' ) +function register_user( $login, $password, $password_conf, + $mail_address, $status = 'guest' ) { global $lang; @@ -49,44 +49,26 @@ function register_user( // 2. start ou end with space character // 3. include ' or " characters // 4. be already used - 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 ( $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 '.PREFIX_TABLE.'users'; - $query.= " where username = '".$login."';"; + $query = 'SELECT id'; + $query.= ' FROM '.PREFIX_TABLE.'users'; + $query.= " WHERE username = '".$login."'"; + $query.= ';'; $result = mysql_query( $query ); - if ( mysql_num_rows( $result ) > 0 ) - { - $error[$i++] = $lang['reg_err_login5']; - } + if ( mysql_num_rows($result) > 0 ) $error[$i++] = $lang['reg_err_login5']; } // given password must be the same as the confirmation - if ( $password != $password_conf ) - { - $error[$i++] = $lang['reg_err_pass']; - } + 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; - } + if ( $error_mail_address != '' ) $error[$i++] = $error_mail_address; // if no error until here, registration of the user if ( sizeof( $error ) == 0 ) @@ -94,25 +76,20 @@ function register_user( // 1. retrieving default values, the ones of the user "guest" $infos = array( 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', - 'short_period', 'long_period', 'template' ); - $query = 'select'; + 'short_period', 'long_period', 'template', + 'forbidden_categories' ); + $query = 'SELECT '; for ( $i = 0; $i < sizeof( $infos ); $i++ ) { - if ( $i > 0 ) - { - $query.= ','; - } - else - { - $query.= ' '; - } + if ( $i > 0 ) $query.= ','; $query.= $infos[$i]; } - $query.= ' from '.PREFIX_TABLE.'users'; - $query.= " where username = 'guest';"; + $query.= ' FROM '.PREFIX_TABLE.'users'; + $query.= " WHERE username = 'guest'"; + $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); // 2. adding new user - $query = 'insert into '.PREFIX_TABLE.'users'; + $query = 'INSERT INTO '.PREFIX_TABLE.'users'; $query.= ' ('; $query.= ' username,password,mail_address,status'; for ( $i = 0; $i < sizeof( $infos ); $i++ ) @@ -122,26 +99,13 @@ function register_user( $query.= ') values ('; $query.= " '".$login."'"; $query.= ",'".md5( $password )."'"; - if ( $mail_address != '' ) - { - $query.= ",'".$mail_address."'"; - } - else - { - $query.= ',NULL'; - } + if ( $mail_address != '' ) $query.= ",'".$mail_address."'"; + else $query.= ',NULL'; $query.= ",'".$status."'"; - for ( $i = 0; $i < sizeof( $infos ); $i++ ) - { + foreach ( $infos as $info ) { $query.= ','; - if ( $row[$infos[$i]] == '' ) - { - $query.= 'NULL'; - } - else - { - $query.= "'".$row[$infos[$i]]."'"; - } + if ( !isset( $row[$info] ) ) $query.= 'NULL'; + else $query.= "'".$row[$info]."'"; } $query.= ');'; mysql_query( $query ); @@ -165,6 +129,39 @@ function register_user( $query.= ' ('.$user_id.','.$row['cat_id'].');'; mysql_query ( $query ); } + // 5. associate new user to the same groups that the guest + $query = 'SELECT group_id'; + $query.= ' FROM '.PREFIX_TABLE.'user_group AS ug'; + $query.= ', '.PREFIX_TABLE.'users AS u'; + $query.= " WHERE u.username = 'guest'"; + $query.= ' AND ug.user_id = u.id'; + $query.= ';'; + $result = mysql_query( $query ); + while( $row = mysql_fetch_array( $result ) ) + { + $query = 'INSERT INTO '.PREFIX_TABLE.'user_group'; + $query.= ' (user_id,group_id) VALUES'; + $query.= ' ('.$user_id.','.$row['group_id'].')'; + $query.= ';'; + mysql_query ( $query ); + } + // 6. has the same categories informations than guest + $query = 'SELECT category_id,date_last,nb_sub_categories'; + $query.= ' FROM '.PREFIX_TABLE.'user_category AS uc'; + $query.= ', '.PREFIX_TABLE.'users AS u'; + $query.= " WHERE u.username = 'guest'"; + $query.= ' AND uc.user_id = u.id'; + $query.= ';'; + $result = mysql_query( $query ); + while( $row = mysql_fetch_array( $result ) ) + { + $query = 'INSERT INTO '.PREFIX_TABLE.'user_category'; + $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES'; + $query.= ' ('.$user_id.','.$row['category_id']; + $query.= ",'".$row['date_last']."',".$row['nb_sub_categories'].')'; + $query.= ';'; + mysql_query ( $query ); + } } return $error; } @@ -209,128 +206,14 @@ function check_login_authorization() { global $user,$lang,$conf,$page; - if ( $user['is_the_guest'] - and ( $conf['access'] == 'restricted' or $page['cat'] == 'fav' ) ) + if ( $user['is_the_guest']) + { + if ( $conf['access'] == 'restricted' || (isset($page['cat']) && $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, $use_groups = true ) -{ - // 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.'user_access'; - $query.= ' WHERE user_id = '.$user_id; - $query.= ';'; - $result = mysql_query( $query ); - while ( $row = mysql_fetch_array( $result ) ) - { - 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 ) - { - // 3. adding to the restricted categories, the invisible ones - if ( $user_status != 'admin' ) - { - $query = 'SELECT id'; - $query.= ' FROM '.PREFIX_TABLE.'categories'; - $query.= " WHERE visible = 'false';"; - $result = mysql_query( $query ); - while ( $row = mysql_fetch_array( $result ) ) - { - array_push( $forbidden, $row['id'] ); - } - } - } - return array_unique( $forbidden ); -} - -// 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 ) -{ - $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_cats; -} - -// 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 ) -{ - $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 user is allowed to go in this category - return 0; } ?>
\ No newline at end of file diff --git a/include/functions_xml.inc.php b/include/functions_xml.inc.php index 034b49512..a4645dc1e 100644 --- a/include/functions_xml.inc.php +++ b/include/functions_xml.inc.php @@ -16,10 +16,6 @@ * the Free Software Foundation; * * * ***************************************************************************/ - -//------------------------------------------------------------------ constantes -define( "ATT_REG", '\w+' ); -define( "VAL_REG", '[^"]*' ); //------------------------------------------------------------------- functions // getContent returns the content of a tag // diff --git a/include/init.inc.php b/include/init.inc.php deleted file mode 100644 index 1bcc96ae0..000000000 --- a/include/init.inc.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/*************************************************************************** - * init.inc.php * - * ------------------- * - * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * - * author : Pierrick LE GALL <pierrick@z0rglub.com> * - * * - * $Id$ - * * - *************************************************************************** - - *************************************************************************** - * * - * 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( "PREFIX_INCLUDE", '' ); - -include_once( './include/config.inc.php' ); -include_once( './include/user.inc.php' ); - -// 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' ); -// displaying the username in the language of the connected user, instead of -// "guest" as you can find in the database -if ( $user['is_the_guest'] ) $user['username'] = $lang['guest']; -include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' ); -?>
\ No newline at end of file diff --git a/include/page_header.php b/include/page_header.php new file mode 100644 index 000000000..68bb17993 --- /dev/null +++ b/include/page_header.php @@ -0,0 +1,30 @@ +<?php + +// +// Start output of page +// +$vtp = new VTemplate; +$handle = $vtp->Open( './template/'.$user['template'].'/header.vtp' ); +$vtp->setGlobalVar( $handle, 'charset', $lang['charset'] ); +$vtp->setGlobalVar( $handle, 'style', './template/'.$user['template'].'/'.$user['template'].'.css'); + + // refresh + if ( isset( $refresh ) && $refresh >0 && isset($url_link)) + { + $vtp->addSession( $handle, 'refresh' ); + $vtp->setVar( $handle, 'refresh.time', $refresh ); + $url = $url_link.'&slideshow='.$refresh; + $vtp->setVar( $handle, 'refresh.url', add_session_id( $url ) ); + $vtp->closeSession( $handle, 'refresh' ); + } + +$vtp->setGlobalVar( $handle, 'title', $title ); +$vtp->setVarF( $handle, 'header', './template/'.$user['template'].'/header.htm' ); + +// +// Generate the page +// + +$code = $vtp->Display( $handle, 0 ); +echo $code; +?>
\ No newline at end of file diff --git a/include/page_tail.php b/include/page_tail.php new file mode 100644 index 000000000..d4548f170 --- /dev/null +++ b/include/page_tail.php @@ -0,0 +1,19 @@ +<?php +$handle = $vtp->Open( './template/'.$user['template'].'/footer.vtp' ); + +//------------------------------------------------------------- generation time +$time = get_elapsed_time( $t2, get_moment() ); +$vtp->setGlobalVar( $handle, 'time', $time ); + +$vtp->setGlobalVar( $handle, 'generation_time', $lang['generation_time'] ); +$vtp->setGlobalVar( $handle, 'version', $conf['version'] ); +$vtp->setGlobalVar( $handle, 'site_url', $conf['site_url'] ); +$vtp->setVarF( $handle, 'footer', './template/'.$user['template'].'/footer.htm' ); + +// +// Generate the page +// + +$code = $vtp->Display( $handle, 0 ); +echo $code; +?>
\ No newline at end of file diff --git a/include/user.inc.php b/include/user.inc.php index a91a4b61b..d25f26b7a 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -16,6 +16,7 @@ * 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. @@ -24,14 +25,10 @@ $infos = array( 'id', 'username', 'mail_address', 'nb_image_line', 'nb_line_page', 'status', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', 'short_period', - 'long_period', 'template' ); + 'long_period', 'template', 'forbidden_categories' ); -$query_user = 'SELECT '; -foreach ( $infos as $i => $info ) { - if ( $i > 0 ) $query_user.= ','; - $query_user.= $info; -} -$query_user.= ' FROM '.PREFIX_TABLE.'users'; +$query_user = 'SELECT '.implode( ',', $infos ); +$query_user.= ' FROM '.USERS_TABLE; $query_done = false; $user['is_the_guest'] = false; @@ -59,7 +56,7 @@ if ( isset( $session_id ) { $page['session_id'] = $session_id; $query = 'SELECT user_id,expiration,ip'; - $query.= ' FROM '.PREFIX_TABLE.'sessions'; + $query.= ' FROM '.SESSIONS_TABLE; $query.= " WHERE id = '".$page['session_id']."'"; $query.= ';'; $result = mysql_query( $query ); @@ -72,7 +69,7 @@ if ( isset( $session_id ) { // deletion of the session from the database, // because it is out-of-date - $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions'; + $delete_query = 'DELETE FROM '.SESSIONS_TABLE; $delete_query.= " WHERE id = '".$page['session_id']."'"; $delete_query.= ';'; mysql_query( $delete_query ); @@ -96,18 +93,27 @@ if ( !$query_done ) $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. 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[$info] == 'true' or $row[$info] == 'false' ) + if ( isset( $row[$info] ) ) { - $user[$info] = get_boolean( $row[$info] ); + // If the field is true or false, the variable is transformed into a + // boolean value. + if ( $row[$info] == 'true' or $row[$info] == 'false' ) + $user[$info] = get_boolean( $row[$info] ); + else + $user[$info] = $row[$info]; + } + else + { + $user[$info] = ''; } } + +// special for $user['restrictions'] array +$user['restrictions'] = explode( ',', $user['forbidden_categories'] ); +if ( $user['restrictions'][0] == '' ) $user['restrictions'] = array(); ?>
\ No newline at end of file diff --git a/include/vtemplate.class.php b/include/vtemplate.class.php index e3ae0b058..45dfd7f10 100644 --- a/include/vtemplate.class.php +++ b/include/vtemplate.class.php @@ -15,7 +15,6 @@ * * *****************************************************************/ - // to make it work on nexen.net set_magic_quotes_runtime(0); |