aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--category.php95
-rw-r--r--include/functions_category.inc.php147
-rw-r--r--include/functions_user.inc.php20
3 files changed, 166 insertions, 96 deletions
diff --git a/category.php b/category.php
index d79c178e7..8796ce8c4 100644
--- a/category.php
+++ b/category.php
@@ -52,9 +52,9 @@ if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
if ( $user['expand'] == 'true' or $_GET['expand'] == 'all' )
{
$page['tab_expand'] = array();
- $query = 'select id';
- $query.= ' from '.PREFIX_TABLE.'categories';
- $query.= ' where id_uppercat is null;';
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id_uppercat IS NULL;';
$result = mysql_query( $query );
$i = 0;
while ( $row = mysql_fetch_array( $result ) )
@@ -123,9 +123,9 @@ if ( !$user['is_the_guest'] )
$url = add_session_id('./category.php?cat=fav&expand='.$page['expand'] );
$vtp->setVar( $handle, 'favorites.url', $url );
// searching the number of favorite picture
- $query = 'select count(*) as count';
- $query.= ' from '.PREFIX_TABLE.'favorites';
- $query.= ' where user_id = '.$user['id'].';';
+ $query = 'SELECT COUNT(*) AS count';
+ $query.= ' FROM '.PREFIX_TABLE.'favorites';
+ $query.= ' WHERE user_id = '.$user['id'].';';
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$vtp->setVar( $handle, 'favorites.nb_favorites', $row['count'] );
@@ -237,19 +237,17 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$array_cat_directories = array();
}
- $query = 'select id,file,date_available,comment,';
- $query.= ' author,tn_ext,name,filesize,width,height,cat_id';
- $query.= ' from '.PREFIX_TABLE.'images';
+ $query = 'SELECT id,file,date_available,tn_ext,name,filesize,cat_id';
+ $query.= ' FROM '.PREFIX_TABLE.'images';
$query.= $page['where'];
$query.= $conf['order_by'];
- $query.= ' limit '.$page['start'].','.$page['nb_image_page'];
+ $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
$query.= ';';
$result = mysql_query( $query );
$vtp->addSession( $handle, 'thumbnails' );
$vtp->addSession( $handle, 'line' );
- // compteur d'itération pour aller ŕ la ligne
- // toutes les "$nb_image_ligne" images
+ // iteration counter to use a new <tr> every "$nb_image_line" pictures
$i = 1;
while ( $row = mysql_fetch_array( $result ) )
{
@@ -262,8 +260,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
}
$cat_directory = $array_cat_directories[$row['cat_id']];
}
- // filename without extension
- $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) );
+ $file = get_filename_wo_extension( $row['file'] );
// name of the picture
if ( $row['name'] != '' )
{
@@ -282,30 +279,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$thumbnail_url.= 'thumbnail/'.$conf['prefixe_thumbnail'];
$thumbnail_url.= $file.'.'.$row['tn_ext'];
// message in title for the thumbnail
- $tab_date = explode( '-', $row['date_available'] );
- $thumbnail_title = $lang['registration_date'];
- $thumbnail_title.= ' '.$tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0];
- if ( $row['comment'] != '' )
- {
- $thumbnail_title .= "\n".$lang['comment'].' : '.$row['comment'];
- }
- if ( $row['author'] != '' )
- {
- $thumbnail_title .= "\n".$lang['author'].' : '.$row['author'];
- }
- if ( $row['width'] == '' )
- {
- $taille_image = @getimagesize( $lien_image );
- $width = $taille_image[0];
- $height = $taille_image[1];
- }
- else
- {
- $width = $row['width'];
- $height = $row['height'];
- }
- $thumbnail_title .= "\n".$lang['size'].' : '.$width.'*'.$height;
- $thumbnail_title .= "\n".$lang['file'].' : '.$row['file'];
+ $thumbnail_title = $row['file'];
if ( $row['filesize'] == '' )
{
$poids = floor( filesize( $lien_image ) / 1024 );
@@ -314,7 +288,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
{
$poids = $row['filesize'];
}
- $thumbnail_title .= "\n".$lang['filesize'].' : '.$poids.' KB';
+ $thumbnail_title .= ' : '.$poids.' KB';
// url link on picture.php page
$url_link = './picture.php?cat='.$page['cat'];
$url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
@@ -337,9 +311,9 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
if ( $conf['show_comments'] and $user['show_nb_comments'] )
{
$vtp->addSession( $handle, 'nb_comments' );
- $query = 'select count(*) as nb_comments';
- $query.= ' from '.PREFIX_TABLE.'comments';
- $query.= ' where image_id = '.$row['id'];
+ $query = 'SELECT COUNT(*) AS nb_comments';
+ $query.= ' FROM '.PREFIX_TABLE.'comments';
+ $query.= ' WHERE image_id = '.$row['id'];
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
$vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
@@ -370,36 +344,31 @@ elseif ( isset( $page['cat'] )
and $page['cat_nb_images'] == 0 )
{
$vtp->addSession( $handle, 'thumbnails' );
-
- $query = 'select id,name,dir,date_dernier';
- $query.= ' from '.PREFIX_TABLE.'categories';
- $query.= ' where id_uppercat = '.$page['cat'];
- $query.= ' order by rank;';
- $cat_result = mysql_query( $query );
- $i = 1;
$vtp->addSession( $handle, 'line' );
- while ( $cat_row = mysql_fetch_array( $cat_result ) )
- {
- $result = get_cat_info( $cat_row['id'] );
+
+ $subcats = get_non_empty_sub_cat_ids( $page['cat'] );
+ $i = 1;
+ foreach ( $subcats as $subcat) {
+ $result = get_cat_info( $subcat['non_empty_cat'] );
$cat_directory = $result['dir'];
$name = '[ <span style="font-weight:bold;">';
- if ( $cat_row['name'] != '' )
+ if ( $subcat['name'] != '' )
{
- $name.= $cat_row['name'];
+ $name.= $subcat['name'];
}
else
{
- $name.= $cat_row['dir'];
+ $name.= $subcat['dir'];
}
$name.= '</span> ]';
$name = replace_space( $name );
- $query = 'select file,tn_ext';
- $query.= ' from '.PREFIX_TABLE.'images';
- $query.= ' where cat_id = '.$cat_row['id'];
- $query.= ' order by rand()';
- $query.= ' limit 0,1';
+ $query = 'SELECT file,tn_ext';
+ $query.= ' FROM '.PREFIX_TABLE.'images';
+ $query.= ' WHERE cat_id = '.$subcat['non_empty_cat'];
+ $query.= ' ORDER BY RAND()';
+ $query.= ' LIMIT 0,1';
$query.= ';';
$image_result = mysql_query( $query );
$image_row = mysql_fetch_array( $image_result );
@@ -416,7 +385,7 @@ elseif ( isset( $page['cat'] )
$thumbnail_title = '';
- $url_link = './category.php?cat='.$cat_row['id'];
+ $url_link = './category.php?cat='.$subcat['id'];
if ( !in_array( $page['cat'], $page['tab_expand'] ) )
{
$page['tab_expand'][sizeof( $page['tab_expand'] )] = $page['cat'];
@@ -432,8 +401,8 @@ elseif ( isset( $page['cat'] )
$vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
$vtp->setVar( $handle, 'thumbnail.name', $name );
- $date = explode( '-', $cat_row['date_dernier'] );
- $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
+ list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
+ $date = mktime( 0, 0, 0, $month, $day, $year );
$vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
$vtp->closeSession( $handle, 'thumbnail' );
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 3ec6102c1..25c54c94a 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -377,7 +377,7 @@ function initialize_category( $calling_page = 'category' )
$page['cat_nb_images'] = $result['nb_images'];
$page['cat_site_id'] = $result['site_id'];
$page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' );
- $page['where'] = ' where cat_id = '.$page['cat'];
+ $page['where'] = ' WHERE cat_id = '.$page['cat'];
}
else
{
@@ -391,12 +391,12 @@ function initialize_category( $calling_page = 'category' )
$page['title'].= ' : <span style="font-style:italic;">';
$page['title'].= $_GET['search']."</span>";
}
- $page['where'] = " where ( file like '%".$_GET['search']."%'";
- $page['where'].= " or name like '%".$_GET['search']."%'";
- $page['where'].= " or comment like '%".$_GET['search']."%' )";
+ $page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'";
+ $page['where'].= " OR name LIKE '%".$_GET['search']."%'";
+ $page['where'].= " OR comment LIKE '%".$_GET['search']."%' )";
- $query = 'select count(*) as nb_total_images';
- $query.= ' from '.PREFIX_TABLE.'images';
+ $query = 'SELECT COUNT(*) AS nb_total_images';
+ $query.= ' FROM '.PREFIX_TABLE.'images';
$query.= $page['where'];
$query.= ';';
@@ -408,12 +408,12 @@ function initialize_category( $calling_page = 'category' )
$page['title'] = $lang['favorites'];
$page['where'] = ', '.PREFIX_TABLE.'favorites';
- $page['where'].= ' where user_id = '.$user['id'];
- $page['where'].= ' and image_id = id';
+ $page['where'].= ' WHERE user_id = '.$user['id'];
+ $page['where'].= ' AND image_id = id';
- $query = 'select count(*) as nb_total_images';
- $query.= ' from '.PREFIX_TABLE.'favorites';
- $query.= ' where user_id = '.$user['id'];
+ $query = 'SELECT COUNT(*) AS nb_total_images';
+ $query.= ' FROM '.PREFIX_TABLE.'favorites';
+ $query.= ' WHERE user_id = '.$user['id'];
$query.= ';';
}
// pictures within the short period
@@ -423,11 +423,11 @@ function initialize_category( $calling_page = 'category' )
// We must find the date corresponding to :
// today - $conf['periode_courte']
$date = time() - 60*60*24*$user['short_period'];
- $page['where'] = " where date_available > '";
+ $page['where'] = " WHERE date_available > '";
$page['where'].= date( 'Y-m-d', $date )."'";
- $query = 'select count(*) as nb_total_images';
- $query.= ' from '.PREFIX_TABLE.'images';
+ $query = 'SELECT COUNT(*) AS nb_total_images';
+ $query.= ' FROM '.PREFIX_TABLE.'images';
$query.= $page['where'];
$query.= ';';
}
@@ -435,8 +435,8 @@ function initialize_category( $calling_page = 'category' )
else if ( $page['cat'] == 'most_visited' )
{
$page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
- $page['where'] = ' where cat_id != -1';
- $conf['order_by'] = ' order by hit desc, file asc';
+ $page['where'] = ' WHERE cat_id != -1';
+ $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
$page['cat_nb_images'] = $conf['top_number'];
if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
{
@@ -455,13 +455,9 @@ 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_cat = get_all_restrictions( $user['id'], $user['status'] );
- if ( sizeof( $restricted_cat ) > 0 )
- {
- for ( $i = 0; $i < sizeof( $restricted_cat ); $i++ )
- {
- $page['where'].= ' and cat_id != '.$restricted_cat[$i];
- }
+ $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $page['where'].= ' AND cat_id != '.$restricted_cat;
}
}
}
@@ -477,4 +473,109 @@ function initialize_category( $calling_page = 'category' )
$page['title'] = $lang['diapo_default_page_title'];
}
}
+
+// get_non_empty_sub_cat_ids returns an array composing of the infos of the
+// direct sub-categories of the given uppercat id. Each of these infos is
+// associated to the first found non empty category id. eg :
+//
+// - catname [cat_id]
+// - cat1 [1] -> given uppercat
+// - cat1.1 [2] (empty)
+// - cat1.1.1 [5] (empty)
+// - cat1.1.2 [6]
+// - cat1.2 [3]
+// - cat1.3 [4]
+//
+// get_non_empty_sub_cat_ids will return :
+// $cats[0]['id'] = 2;
+// $cats[0]['name'] = '';
+// $cats[0]['dir'] = 'cat1';
+// $cats[0]['date_dernier'] = '2003-05-17';
+// $cats[0]['non_empty_cat'] = 6;
+//
+// $cats[1]['id'] = 3;
+// $cats[1]['non_empty_cat'] = 3;
+//
+// $cats[1]['id'] = 4;
+// $cats[1]['non_empty_cat'] = 4;
+function get_non_empty_sub_cat_ids( $id_uppercat )
+{
+ global $user;
+
+ $cats = array();
+
+ $query = 'SELECT id,name,dir,date_dernier,nb_images';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id_uppercat = '.$id_uppercat;
+ // we must not show pictures of a forbidden category
+ $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $query.= ' AND id != '.$restricted_cat;
+ }
+ $query.= ' ORDER BY rank';
+ $query.= ';';
+
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ if ( $row['nb_images'] == 0 )
+ {
+ $non_empty_cat = get_first_non_empty_cat_id( $row['id'] );
+ }
+ else
+ {
+ $non_empty_cat = $row['id'];
+ }
+ // only categories with findable picture in any of its subcats is
+ // represented.
+ if ( $non_empty_cat != false )
+ {
+ $temp_cat = array(
+ 'id' => $row['id'],
+ 'name' => $row['name'],
+ 'dir' => $row['dir'],
+ 'date_dernier' => $row['date_dernier'],
+ 'non_empty_cat' => $non_empty_cat );
+ array_push( $cats, $temp_cat );
+ }
+ }
+ return $cats;
+}
+
+// get_first_non_empty_cat_id returns the id of the first non empty
+// sub-category to the given uppercat. If no picture is found in any
+// subcategory, false is returned.
+function get_first_non_empty_cat_id( $id_uppercat )
+{
+ global $user;
+
+ $query = 'SELECT id,nb_images';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id_uppercat = '.$id_uppercat;
+ // we must not show pictures of a forbidden category
+ $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $query.= ' AND id != '.$restricted_cat;
+ }
+ $query.= ' ORDER BY RAND()';
+ $query.= ';';
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ if ( $row['nb_images'] > 0 )
+ {
+ return $row['id'];
+ }
+ }
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ // recursive call
+ if ( $subcat = get_first_non_empty_cat_id( $row['id'] ) )
+ {
+ return $subcat;
+ }
+ }
+ return false;
+}
?> \ No newline at end of file
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index b19e53f18..dcb569485 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -224,29 +224,29 @@ function check_login_authorization()
function get_restrictions( $user_id, $user_status, $check_invisible )
{
// 1. getting the ids of the restricted categories
- $query = 'select cat_id';
- $query.= ' from '.PREFIX_TABLE.'restrictions';
- $query.= ' where user_id = '.$user_id;
+ $query = 'SELECT cat_id';
+ $query.= ' FROM '.PREFIX_TABLE.'restrictions';
+ $query.= ' WHERE user_id = '.$user_id;
$query.= ';';
$result = mysql_query( $query );
- $i = 0;
+
$restriction = array();
while ( $row = mysql_fetch_array( $result ) )
{
- $restriction[$i++] = $row['cat_id'];
+ array_push( $restriction, $row['cat_id'] );
}
if ( $check_invisible )
{
// 2. adding to the restricted categories, the invisible ones
- if ( $user_status != "admin" )
+ if ( $user_status != 'admin' )
{
- $query = 'select id';
- $query.= ' from '.PREFIX_TABLE.'categories';
- $query.= " where status='invisible';";
+ $query = 'SELECT id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= " WHERE status = 'invisible';";
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
- $restriction[$i++] = $row['id'];
+ array_push( $restriction, $row['id'] );
}
}
}