|
// | branch : 1.4 |
// +-----------------------------------------------------------------------+
// | file : $RCSfile$
// | last update : $Date$
// | last modifier : $Author$
// | 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 |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
//--------------------------------------------------------------------- include
$phpwg_root_path = './';
include_once( $phpwg_root_path.'include/common.inc.php' );
//---------------------------------------------------------------------- logout
if ( isset( $_GET['act'] )
and $_GET['act'] == 'logout'
and isset( $_COOKIE['id'] ) )
{
// cookie deletion if exists
setcookie( 'id', '', 0, cookie_path() );
$url = 'category.php';
header( 'Request-URI: '.$url );
header( 'Content-Location: '.$url );
header( 'Location: '.$url );
exit();
}
//-------------------------------------------------- access authorization check
if ( isset( $_GET['cat'] ) ) check_cat_id( $_GET['cat'] );
check_login_authorization();
if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
{
check_restrictions( $page['cat'] );
}
//-------------------------------------------------------------- initialization
// detection of the start picture to display
if ( !isset( $_GET['start'] )
or !is_numeric( $_GET['start'] )
or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
$page['start'] = 0;
else
$page['start'] = $_GET['start'];
initialize_category();
// creation of the array containing the cat ids to expand in the menu
// $page['tab_expand'] contains an array with the category ids
// $page['expand'] contains the string to display in URL with comma
$page['tab_expand'] = array();
if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
{
$tab_expand = explode( ',', $_GET['expand'] );
foreach ( $tab_expand as $id ) {
if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
}
}
if ( isset($page['cat']) && is_numeric( $page['cat'] ) )
{
// the category displayed (in the URL cat=23) must be seen in the menu ->
// parent categories must be expanded
$uppercats = explode( ',', $page['uppercats'] );
foreach ( $uppercats as $uppercat ) {
array_push( $page['tab_expand'], $uppercat );
}
}
$page['tab_expand'] = array_unique( $page['tab_expand'] );
$page['expand'] = implode( ',', $page['tab_expand'] );
// in case of expanding all authorized cats
// The $page['expand'] equals 'all' and
// $page['tab_expand'] contains all the authorized cat ids
if ( $user['expand']
or ( isset( $_GET['expand'] ) and $_GET['expand'] == 'all' ) )
{
$page['tab_expand'] = array();
$page['expand'] = 'all';
}
// Sometimes, a "num" is provided in the URL. It is the number
// of the picture to show. This picture must be in the thumbnails page.
// We have to find the right $page['start'] that show the num picture
// in this category
if ( isset( $_GET['num'] )
and is_numeric( $_GET['num'] )
and $_GET['num'] >= 0 )
{
$page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
$page['start']*= $user['nb_image_page'];
}
// creating the structure of the categories (useful for displaying the menu)
// creating the plain structure : array of all the available categories and
// their relative informations, see the definition of the function
// get_user_plain_structure for further details.
$page['plain_structure'] = get_user_plain_structure();
$page['structure'] = create_user_structure( '' );
$page['structure'] = update_structure( $page['structure'] );
//----------------------------------------------------- template initialization
//
// Start output of page
//
$title = $page['title'];
include('include/page_header.php');
$template->set_filenames( array('category'=>'category.tpl') );
initialize_template();
//-------------------------------------------------------------- category title
$cat_title = $lang['no_category'];
if ( isset ( $page['cat'] ) )
{
if ( is_numeric( $page['cat'] ) )
{
$cat_title = get_cat_display_name( $page['cat_name'], '
',
'font-style:italic;' );
}
else
{
if ( $page['cat'] == 'search' )
{
$page['title'].= ' : ';
$page['title'].= $_GET['search']."";
}
$page['title'] = replace_space( $page['title'] );
}
}
$template->assign_vars(array(
'NB_PICTURE' => count_user_total_images(),
'TITLE' => $cat_title,
'USERNAME' => $user['username'],
'S_TOP'=>$conf['top_number'],
'S_SHORT_PERIOD'=>$user['short_period'],
'S_LONG_PERIOD'=>$user['long_period'],
'S_WEBMASTER'=>$conf['webmaster'],
'S_MAIL'=>$conf['mail_webmaster'],
'L_CATEGORIES' => $lang['categories'],
'L_HINT_CATEGORY' => $lang['hint_category'],
'L_SUBCAT' => $lang['sub-cat'],
'L_IMG_AVAILABLE' => $lang['images_available'],
'L_TOTAL' => $lang['total'],
'L_FAVORITE_HINT' => $lang['favorite_cat_hint'],
'L_FAVORITE' => $lang['favorite_cat'],
'L_STATS' => $lang['stats'],
'L_MOST_VISITED_HINT' => $lang['most_visited_cat_hint'],
'L_MOST_VISITED' => $lang['most_visited_cat'],
'L_RECENT_HINT' => $lang['recent_cat_hint'],
'L_RECENT' => $lang['recent_cat'],
'L_SUMMARY' => $lang['title_menu'],
'L_UPLOAD' => $lang['upload_picture'],
'L_COMMENT' => $lang['comments'],
'L_NB_IMG' => $lang['nb_image_category'],
'L_USER' => $lang['connected_user'],
'L_RECENT_IMAGE' => $lang['recent_image'],
'L_DAYS' => $lang['days'],
'L_SEND_MAIL' => $lang['send_mail'],
'L_TITLE_MAIL' => $lang['title_send_mail'],
'T_COLLAPSED' => $user['lien_collapsed'],
'T_SHORT'=>get_icon( time() ),
'T_LONG'=>get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) ),
'U_HOME' => add_session_id( 'category.php' ),
'U_FAVORITE' => add_session_id( './category.php?cat=fav&expand='.$page['expand'] ),
'U_MOST_VISITED'=>add_session_id( './category.php?cat=most_visited&expand='.$page['expand'] ),
'U_RECENT'=>add_session_id( './category.php?cat=recent&expand='.$page['expand'] )
)
);
foreach ( $page['structure'] as $category ) {
// display category is a function relative to the template
display_category( $category, ' ');
}
// favorites management
if ( !$user['is_the_guest'] )
{
// searching the number of favorite picture
$query = 'SELECT COUNT(*) AS count';
$query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';';
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) );
}
//--------------------------------------------------------------------- summary
$sum_title = '';
$sum_name='';
$sum_url = '';
if ( !$user['is_the_guest'] )
{
$sum_name=replace_space($lang['logout']);
$sum_url = 'category.php?act=logout';
}
else
{
$sum_title = $lang['hint_login'];
$sum_name=replace_space( $lang['menu_login']);
$sum_url = 'identification.php';
}
$template->assign_block_vars('summary', array(
'TITLE'=>$sum_title,
'NAME'=>$sum_name,
'U_SUMMARY'=>add_session_id( $sum_url ),
)
);
// customization link
if ( !$user['is_the_guest'] )
{
$template->assign_block_vars('summary', array(
'TITLE'=>$lang['hint_customize'],
'NAME'=>$lang['customize'],
'U_SUMMARY'=>add_session_id('profile.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] )),
));
}
// search link
$template->assign_block_vars('summary', array(
'TITLE'=>$lang['hint_search'],
'NAME'=>$lang['search'],
'U_SUMMARY'=>add_session_id( 'search.php' ),
));
// comments link
$template->assign_block_vars('summary', array(
'TITLE'=>$lang['hint_comments'],
'NAME'=>$lang['comments'],
'U_SUMMARY'=>add_session_id( 'comments.php' ),
));
// about link
$template->assign_block_vars('summary', array(
'TITLE'=>$lang['hint_about'],
'NAME'=>$lang['about'],
'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) )
));
// administration link
if ( $user['status'] == 'admin' )
{
$template->assign_block_vars('summary', array(
'TITLE'=>$lang['hint_admin'],
'NAME'=>$lang['admin'],
'U_SUMMARY'=>add_session_id( 'admin.php' )
));
}
//------------------------------------------------------------------ thumbnails
if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 )
{
$array_cat_directories = array();
$query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
$query.= ',storage_category_id';
$query.= ' FROM '.IMAGES_TABLE.' AS i';
$query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
$query.= ';';
$result = mysql_query( $query );
$template->assign_block_vars('thumbnails', array());
// iteration counter to use a new