aboutsummaryrefslogtreecommitdiffstats
path: root/category.php
diff options
context:
space:
mode:
authorgweltas <gweltas@piwigo.org>2004-02-02 00:55:18 +0000
committergweltas <gweltas@piwigo.org>2004-02-02 00:55:18 +0000
commitbef4b3e3aa8e3d54cbf8b4962b9b5d4a89b55429 (patch)
tree647b2cf07ee8451a9314e1e8aebd11d9396cb32b /category.php
parenteea989f019f21fbd7ae4aa8e2f4a1503992c23bf (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 'category.php')
-rw-r--r--category.php166
1 files changed, 88 insertions, 78 deletions
diff --git a/category.php b/category.php
index 1058eb958..0b93e6d06 100644
--- a/category.php
+++ b/category.php
@@ -16,14 +16,13 @@
* the Free Software Foundation; *
* *
***************************************************************************/
-// determine the initial instant to indicate the generation time of this page
-$t1 = explode( ' ', microtime() );
-$t2 = explode( '.', $t1[0] );
-$t2 = $t1[1].'.'.$t2[1];
-//----------------------------------------------------------- personnal include
-include_once( './include/init.inc.php' );
+//----------------------------------------------------------- include
+$phpwg_root_path = './';
+include_once( $phpwg_root_path.'common.php' );
//---------------------------------------------------------------------- logout
-if ( $_GET['act'] == 'logout' and isset( $_COOKIE['id'] ) )
+if ( isset( $_GET['act'] )
+ and $_GET['act'] == 'logout'
+ and isset( $_COOKIE['id'] ) )
{
// cookie deletion if exists
setcookie( 'id', '', 0, cookie_path() );
@@ -34,18 +33,23 @@ if ( $_GET['act'] == 'logout' and isset( $_COOKIE['id'] ) )
exit();
}
//-------------------------------------------------- access authorization check
-// creating the plain structure : array of all the available categories and
-// their relative informations, see the definition of the function
-// get_plain_structure for further details.
-$page['plain_structure'] = get_plain_structure();
-
-check_cat_id( $_GET['cat'] );
+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
@@ -56,80 +60,83 @@ if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
foreach ( $tab_expand as $id ) {
if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
}
- if ( is_numeric( $page['cat'] ) )
- {
- // the category displayed (in the URL cat=23) must be seen in the menu ->
- // parent categories must be expanded
- $parent = $page['plain_structure'][$page['cat']]['id_uppercat'];
- while ( $parent != '' )
- {
- array_push( $page['tab_expand'], $parent );
- $parent = $page['plain_structure'][$parent]['id_uppercat'];
- }
+}
+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['expand'] = implode( ',', $page['tab_expand'] );
}
+$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 $_GET['expand'] == 'all' )
+if ( $user['expand']
+ or ( isset( $_GET['expand'] ) and $_GET['expand'] == 'all' ) )
{
$page['tab_expand'] = array();
$page['expand'] = 'all';
}
-// 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'];
-}
// 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 ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
+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)
-$page['structure'] = create_structure( '', $user['restrictions'] );
+// 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'] );
-initialize_category();
+
//----------------------------------------------------- template initialization
-$vtp = new VTemplate;
+
+//
+// Start output of page
+//
+$title = $page['title'];
+include('include/page_header.php');
+
$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
initialize_template();
$tpl = array(
'categories','hint_category','sub-cat','images_available','total',
'title_menu','nb_image_category','send_mail','title_send_mail',
- 'generation_time','connected_user','recent_image','days','generation_time',
+ 'connected_user','recent_image','days',
'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint',
'most_visited_cat','recent_cat','recent_cat_hint','upload_picture',
'comments' );
templatize_array( $tpl, 'lang', $handle );
-$tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
+$tpl = array( 'mail_webmaster','webmaster','top_number');
templatize_array( $tpl, 'conf', $handle );
$tpl = array( 'short_period','long_period','lien_collapsed', 'username' );
templatize_array( $tpl, 'user', $handle );
-$tpl = array( 'title','navigation_bar','cat_comment','cat_nb_images' );
+$tpl = array( 'navigation_bar','cat_comment','cat_nb_images' );
templatize_array( $tpl, 'page', $handle );
// special global template vars
$vtp->setGlobalVar( $handle, 'icon_short', get_icon( time() ) );
$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
-$nb_total_pictures = count_images( $page['structure'] );
+$nb_total_pictures = count_user_total_images();
$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
+
//------------------------------------------------------------- categories menu
+$vtp->setVar( $handle, 'home_url', add_session_id( 'category.php' ) );
// normal categories
foreach ( $page['structure'] as $category ) {
// display category is a function relative to the template
@@ -143,7 +150,7 @@ if ( !$user['is_the_guest'] )
$vtp->setVar( $handle, 'favorites.url', add_session_id( $url ) );
// searching the number of favorite picture
$query = 'SELECT COUNT(*) AS count';
- $query.= ' FROM '.PREFIX_TABLE.'favorites';
+ $query.= ' FROM '.FAVORITES_TABLE;
$query.= ' WHERE user_id = '.$user['id'].';';
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
@@ -181,9 +188,10 @@ if ( !$user['is_the_guest'] )
$vtp->closeSession( $handle, 'summary' );
// customization link
$vtp->addSession( $handle, 'summary' );
- $url = './profile.php?cat='.$page['cat'];
- $url.= '&amp;expand='.$page['expand'];
- if ( $page['cat'] == 'search' )
+ $url = './profile.php';
+ if (isset($page['cat']) && isset($page['expand']))
+ $url.='?cat='.$page['cat'].'&amp;expand='.$page['expand'];
+ if ( isset($page['cat']) && $page['cat'] == 'search' )
{
$url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
@@ -253,8 +261,8 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
$query.= ',storage_category_id';
- $query.= ' FROM '.PREFIX_TABLE.'images AS i';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_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'];
@@ -270,7 +278,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
while ( $row = mysql_fetch_array( $result ) )
{
// retrieving the storage dir of the picture
- if ( $array_cat_directories[$row['storage_category_id']] == '' )
+ if ( !isset($array_cat_directories[$row['storage_category_id']]))
{
$array_cat_directories[$row['storage_category_id']] =
get_complete_dir( $row['storage_category_id'] );
@@ -279,8 +287,8 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$file = get_filename_wo_extension( $row['file'] );
// name of the picture
- if ( $row['name'] != '' ) $name = $row['name'];
- else $name = str_replace( '_', ' ', $file );
+ if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name'];
+ else $name = str_replace( '_', ' ', $file );
if ( $page['cat'] == 'search' )
{
@@ -320,8 +328,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
{
$vtp->addSession( $handle, 'nb_comments' );
$query = 'SELECT COUNT(*) AS nb_comments';
- $query.= ' FROM '.PREFIX_TABLE.'comments';
- $query.= ' WHERE image_id = '.$row['id'];
+ $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id'];
$query.= " AND validated = 'true'";
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
@@ -350,13 +357,16 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
//-------------------------------------------------------------- empty category
elseif ( ( isset( $page['cat'] )
and is_numeric( $page['cat'] )
- and $page['cat_nb_images'] == 0 )
- or $_GET['cat'] == '' )
+ and $page['cat_nb_images'] == 0
+ and $page['plain_structure'][$page['cat']]['nb_sub_categories'] > 0)
+ or (!isset($_GET['cat'])))
{
$vtp->addSession( $handle, 'thumbnails' );
$vtp->addSession( $handle, 'line' );
- $subcats = get_non_empty_subcat_ids( $page['cat'] );
+ $subcats=array();
+ if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] );
+ else $subcats = get_non_empty_subcat_ids( '' );
$cell_number = 1;
$i = 0;
foreach ( $subcats as $subcat_id => $non_empty_id ) {
@@ -368,17 +378,17 @@ elseif ( ( isset( $page['cat'] )
// searching the representative picture of the category
$query = 'SELECT representative_picture_id';
- $query.= ' FROM '.PREFIX_TABLE.'categories';
- $query.= ' WHERE id = '.$non_empty_id;
+ $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id;
+ $query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
$query = 'SELECT file,tn_ext,storage_category_id';
- $query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
$query.= ' WHERE category_id = '.$non_empty_id;
+ $query.= ' AND id = image_id';
// if the category has a representative picture, this is its thumbnail
- // tha will be displayed !
- if ( $row['representative_picture_id'] != '' )
+ // that will be displayed !
+ if ( isset( $row['representative_picture_id'] ) )
$query.= ' AND id = '.$row['representative_picture_id'];
else
$query.= ' ORDER BY RAND()';
@@ -397,7 +407,7 @@ elseif ( ( isset( $page['cat'] )
$thumbnail_title = $lang['hint_category'];
$url_link = './category.php?cat='.$subcat_id;
- if ( !in_array( $page['cat'], $page['tab_expand'] ) )
+ if ( isset($page['cat'])&& !in_array( $page['cat'], $page['tab_expand'] ) )
{
array_push( $page['tab_expand'], $page['cat'] );
$page['expand'] = implode( ',', $page['tab_expand'] );
@@ -459,30 +469,30 @@ if ( isset ( $page['cat'] ) )
$vtp->setVar( $handle, 'cat_infos.cat_name',
get_cat_display_name( $page['cat_name'], ' - ',
'font-style:italic;' ) );
+ // upload a picture in the category
+ if ( $page['cat_site_id'] == 1
+ and $conf['upload_available']
+ and $page['cat_uploadable'] )
+ {
+ $vtp->addSession( $handle, 'upload' );
+ $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
+ $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
+ $vtp->closeSession( $handle, 'upload' );
+ }
}
else
{
$vtp->setVar( $handle, 'cat_infos.cat_name', $page['title'] );
}
- // upload a picture in the category
- if ( $page['cat_site_id'] == 1
- and $conf['upload_available']
- and $page['cat_uploadable'] )
- {
- $vtp->addSession( $handle, 'upload' );
- $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
- $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
- $vtp->closeSession( $handle, 'upload' );
- }
+
$vtp->closeSession( $handle, 'cat_infos' );
}
//------------------------------------------------------------ log informations
pwg_log( 'category', $page['title'] );
mysql_close();
-//------------------------------------------------------------- generation time
-$time = get_elapsed_time( $t2, get_moment() );
-$vtp->setGlobalVar( $handle, 'time', $time );
//----------------------------------------------------------- html code display
$code = $vtp->Display( $handle, 0 );
echo $code;
+
+include('include/page_tail.php');
?> \ No newline at end of file