diff options
author | z0rglub <z0rglub@piwigo.org> | 2004-06-25 20:29:51 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2004-06-25 20:29:51 +0000 |
commit | 634743c328e49073342d2d45534cdb83b6b0dc81 (patch) | |
tree | 24059d0ea56aecaa2a8df91fab8459f776fe4344 /category.php | |
parent | 9bd06409b2e095a5bebac771d1c498bc15060109 (diff) |
thumbnails display moved to included files include/category_*.inc.php
git-svn-id: http://piwigo.org/svn/trunk@441 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'category.php')
-rw-r--r-- | category.php | 490 |
1 files changed, 8 insertions, 482 deletions
diff --git a/category.php b/category.php index 66aaaa874..906082437 100644 --- a/category.php +++ b/category.php @@ -269,496 +269,22 @@ $template->assign_block_vars('summary', array( 'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) ) )); -//------------------------------------------------------------------ thumbnails -if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 ) +//------------------------------------------------------ main part : thumbnails +if (isset($page['cat']) and $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 <tr> every "$nb_image_line" pictures - $cell_number = 0; - // iteration counter to be sure not to create too much lines in the table - $line_number = 0; - - $row_number = 1; - $line_opened = false; - $displayed_pics = 0; - - while ( $row = mysql_fetch_array( $result ) ) - { - // retrieving the storage dir of the picture - if ( !isset($array_cat_directories[$row['storage_category_id']])) - { - $array_cat_directories[$row['storage_category_id']] = - get_complete_dir( $row['storage_category_id'] ); - } - $cat_directory = $array_cat_directories[$row['storage_category_id']]; - - $file = get_filename_wo_extension( $row['file'] ); - // name of the picture - if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name']; - else $name = str_replace( '_', ' ', $file ); - - if ( $page['cat'] == 'search' ) - { - $name = replace_search( $name, $_GET['search'] ); - } - // thumbnail url - $thumbnail_url = $cat_directory; - $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_url.= $file.'.'.$row['tn_ext']; - // message in title for the thumbnail - $thumbnail_title = $row['file']; - if ( $row['filesize'] == '' ) - $poids = floor( filesize( $cat_directory.$row['file'] ) / 1024 ); - else - $poids = $row['filesize']; - $thumbnail_title .= ' : '.$poids.' KB'; - // url link on picture.php page - $url_link = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat']; - $url_link.= '&image_id='.$row['id']; - if ( $page['cat'] == 'search' ) - { - $url_link.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; - } - // create a new line ? - if ( (!$line_opened or $row_number++ == $user['nb_image_line'] ) - and $displayed_pics++ < mysql_num_rows( $result ) ) - { - $template->assign_block_vars('thumbnails.line', array()); - $row_number = 1; - $line_opened = true; - } - - $template->assign_block_vars( - 'thumbnails.line.thumbnail', - array( - 'IMAGE'=>$thumbnail_url, - 'IMAGE_ALT'=>$row['file'], - 'IMAGE_TITLE'=>$thumbnail_title, - 'IMAGE_NAME'=>$name, - 'IMAGE_TS'=>get_icon( $row['date_available'] ), - - 'U_IMG_LINK'=>add_session_id( $url_link ) - )); - - if ( $conf['show_comments'] and $user['show_nb_comments'] ) - { - $query = 'SELECT COUNT(*) AS nb_comments'; - $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id']; - $query.= " AND validated = 'true'"; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); - $template->assign_block_vars( - 'thumbnails.line.thumbnail.nb_comments', - array('NB_COMMENTS'=>$row['nb_comments']) ); - } - } + include(PHPWG_ROOT_PATH.'include/category_default.inc.php'); } -//-------------------------------------------------------------------- calendar -elseif ( isset( $page['cat'] ) and $page['cat'] == 'calendar' ) +elseif (isset($page['cat']) and $page['cat'] == 'calendar') { - // years of image availability - $query = 'SELECT DISTINCT(YEAR(date_available)) AS year'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= ' AND id = image_id'; - $query.= ' ORDER BY year'; - $query.= ';'; - $result = mysql_query( $query ); - $calendar_years = array(); - while ( $row = mysql_fetch_array( $result ) ) - { - array_push( $calendar_years, $row['year'] ); - } - - if ( !isset( $page['calendar_year'] ) - or !in_array( $page['calendar_year'], $calendar_years ) ) - { - $page['calendar_year'] = max( $calendar_years ); - } - - // years navigation bar creation - $years_nav_bar = ''; - foreach ( $calendar_years as $calendar_year ) { - if ( $calendar_year == $page['calendar_year'] ) - { - $years_nav_bar.= ' <span class="selected">'; - $years_nav_bar.= $calendar_year; - $years_nav_bar.= '</span>'; - } - else - { - $url = PHPWG_ROOT_PATH.'category.php?cat=calendar'; - $url.= '&year='.$calendar_year; - $years_nav_bar.= ' '; - $years_nav_bar.= '<a href="'.add_session_id( $url ).'">'; - $years_nav_bar.= $calendar_year; - $years_nav_bar.= '</a>'; - } - } - $template->assign_block_vars( - 'calendar', - array( 'YEARS_NAV_BAR' => $years_nav_bar ) - ); - - $query = 'SELECT DISTINCT(MONTH(date_available)) AS month'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= ' AND id = image_id'; - $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; - $query.= ' ORDER BY month'; - $query.= ';'; - $result = mysql_query( $query ); - $calendar_months = array(); - while ( $row = mysql_fetch_array( $result ) ) - { - array_push( $calendar_months, $row['month'] ); - } - - // months navigation bar creation - $months_nav_bar = ''; - foreach ( $calendar_months as $calendar_month ) { - if ( isset( $page['calendar_month'] ) - and $calendar_month == $page['calendar_month'] ) - { - $months_nav_bar.= ' <span class="selected">'; - $months_nav_bar.= $lang['month'][(int)$calendar_month]; - $months_nav_bar.= '</span>'; - } - else - { - $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&month='; - $url.= $page['calendar_year'].'.'; - if ( $calendar_month < 10 ) - { - // adding leading zero - $url.= '0'; - } - $url.= $calendar_month; - $months_nav_bar.= ' '; - $months_nav_bar.= '<a href="'.add_session_id( $url ).'">'; - $months_nav_bar.= $lang['month'][(int)$calendar_month]; - $months_nav_bar.= '</a>'; - } - } - $template->assign_block_vars( - 'calendar', - array( 'MONTHS_NAV_BAR' => $months_nav_bar ) - ); - - $row_number = 1; - $line_opened = false; - $displayed_pics = 0; - $template->assign_block_vars('thumbnails', array()); - - if ( !isset( $page['calendar_month'] ) ) - { - // for each month of this year, display a random picture - foreach ( $calendar_months as $calendar_month ) { - $query = 'SELECT COUNT(id) AS nb_picture_month'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; - $query.= ' AND MONTH(date_available) = '.$calendar_month; - $query.= ' AND id = image_id'; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); - $nb_picture_month = $row['nb_picture_month']; - - $query = 'SELECT file,tn_ext,date_available,storage_category_id'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; - $query.= ' AND MONTH(date_available) = '.$calendar_month; - $query.= ' AND id = image_id'; - $query.= ' ORDER BY RAND()'; - $query.= ' LIMIT 0,1'; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); - - $file = get_filename_wo_extension( $row['file'] ); - - // creating links for thumbnail and associated category - $thumbnail_link = get_complete_dir( $row['storage_category_id'] ); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - - $name = $lang['month'][$calendar_month]; - $name.= ' '.$page['calendar_year']; - $name.= ' ['.$nb_picture_month.']'; - - $thumbnail_title = $lang['calendar_picture_hint'].$name; - - $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar'; - $url_link.= '&month='.$page['calendar_year'].'.'; - if ( $calendar_month < 10 ) - { - // adding leading zero - $url_link.= '0'; - } - $url_link.= $calendar_month; - - // create a new line ? - if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] ) - and $displayed_pics++ < count( $calendar_months ) ) - { - $template->assign_block_vars('thumbnails.line', array()); - $row_number = 1; - $line_opened = true; - } - - $template->assign_block_vars( - 'thumbnails.line.thumbnail', - array( - 'IMAGE'=>$thumbnail_link, - 'IMAGE_ALT'=>$row['file'], - 'IMAGE_TITLE'=>$thumbnail_title, - 'IMAGE_NAME'=>$name, - - 'U_IMG_LINK'=>add_session_id( $url_link ) - ) - ); - } - } - else - { - $query = 'SELECT DISTINCT(date_available) AS day'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= ' AND id = image_id'; - $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; - $query.= ' AND MONTH(date_available) = '.$page['calendar_month']; - $query.= ' ORDER BY day'; - $query.= ';'; - $result = mysql_query( $query ); - $calendar_days = array(); - while ( $row = mysql_fetch_array( $result ) ) - { - array_push( $calendar_days, $row['day'] ); - } - // for each month of this year, display a random picture - foreach ( $calendar_days as $calendar_day ) { - $query = 'SELECT COUNT(id) AS nb_picture_day'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= " AND date_available = '".$calendar_day."'"; - $query.= ' AND id = image_id'; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); - $nb_picture_day = $row['nb_picture_day']; - - $query = 'SELECT file,tn_ext,date_available,storage_category_id'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= $page['where']; - $query.= " AND date_available = '".$calendar_day."'"; - $query.= ' AND id = image_id'; - $query.= ' ORDER BY RAND()'; - $query.= ' LIMIT 0,1'; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); - - $file = get_filename_wo_extension( $row['file'] ); - - // creating links for thumbnail and associated category - $thumbnail_link = get_complete_dir( $row['storage_category_id'] ); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - - list($year,$month,$day) = explode( '-', $calendar_day ); - $unixdate = mktime(0,0,0,$month,$day,$year); - $name = $lang['day'][date( "w", $unixdate )]; - $name.= ' '.$day; - $name.= ' ['.$nb_picture_day.']'; - - $thumbnail_title = $lang['calendar_picture_hint'].$name; - - $url_link = PHPWG_ROOT_PATH.'category.php?cat=search'; - - // create a new line ? - if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] ) - and $displayed_pics++ <= count( $calendar_months ) ) - { - $template->assign_block_vars('thumbnails.line', array()); - $row_number = 1; - $line_opened = true; - } - - $template->assign_block_vars( - 'thumbnails.line.thumbnail', - array( - 'IMAGE'=>$thumbnail_link, - 'IMAGE_ALT'=>$row['file'], - 'IMAGE_TITLE'=>$thumbnail_title, - 'IMAGE_NAME'=>$name, - - 'U_IMG_LINK'=>add_session_id( $url_link ) - ) - ); - } - } + include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php'); } -//------------------------------------------------- recently updated categories -elseif ( isset( $page['cat'] ) and $page['cat'] == 'recent_cats' ) +elseif (isset($page['cat']) and $page['cat'] == 'recent_cats') { - // retrieving categories recently update, ie containing pictures added - // recently. The calculated table field categories.date_last will be - // easier to use - $query = 'SELECT id AS category_id'; - $query.= ' FROM '.CATEGORIES_TABLE; - $query.= ' WHERE date_last > '; - $query.= ' SUBDATE(CURRENT_DATE,INTERVAL '.$user['short_period'].' DAY)'; - if ( $user['forbidden_categories'] != '' ) - { - $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; - } - $query.= ';'; - $result = mysql_query( $query ); - - $row_number = 1; - $line_opened = false; - $displayed_pics = 0; - $cat_nb_images = mysql_num_rows( $result ); - $template->assign_block_vars('thumbnails', array()); - - // for each category, we have to search a recent picture to display and - // the name to display - while ( $row = mysql_fetch_array( $result ) ) - { - $cat_infos = get_cat_info( $row['category_id'] ); - $name = '['.get_cat_display_name($cat_infos['name'],'<br />','',false).']'; - - $query = 'SELECT id,file,tn_ext,storage_category_id'; - $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; - $query.= ' WHERE category_id = '.$row['category_id']; - $query.= ' AND date_available > '; - $query.= ' SUBDATE(CURRENT_DATE,INTERVAL '.$user['short_period'].' DAY)'; - $query.= ' AND id = image_id'; - $query.= ' ORDER BY RAND()'; - $query.= ' LIMIT 0,1'; - $query.= ';'; - $subrow = mysql_fetch_array( mysql_query( $query ) ); - - $file = get_filename_wo_extension( $subrow['file'] ); - - // creating links for thumbnail and associated category - $thumbnail_link = get_complete_dir( $subrow['storage_category_id'] ); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$subrow['tn_ext']; - - $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id']; - - // create a new line ? - if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] ) - and $displayed_pics++ < $cat_nb_images ) - { - $template->assign_block_vars('thumbnails.line', array()); - $row_number = 1; - $line_opened = true; - } - - $template->assign_block_vars( - 'thumbnails.line.thumbnail', - array( - 'IMAGE' => $thumbnail_link, - 'IMAGE_ALT' => $subrow['file'], - 'IMAGE_TITLE' => $lang['hint_category'], - 'IMAGE_NAME' => $name, - - 'U_IMG_LINK'=>add_session_id( $url_link ) - ) - ); - } + include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php'); } -//-------------------------------------------------------------- empty category else { - $subcats=array(); - if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] ); - else $subcats = get_non_empty_subcat_ids( '' ); - $cell_number = 0; - $i = 0; - - $template->assign_block_vars('thumbnails', array()); - - foreach ( $subcats as $subcat_id => $non_empty_id ) - { - $name = '<img src="'.$user['lien_collapsed'].'" style="border:none;"'; - $name.= ' alt=">"/> '; - $name.= '[ <span style="font-weight:bold;">'; - $name.= $page['plain_structure'][$subcat_id]['name']; - $name.= '</span> ]'; - - // searching the representative picture of the category - $query = 'SELECT representative_picture_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 '.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 - // that will be displayed ! - if ( isset( $row['representative_picture_id'] ) ) - $query.= ' AND id = '.$row['representative_picture_id']; - else - $query.= ' ORDER BY RAND()'; - $query.= ' LIMIT 0,1'; - $query.= ';'; - $image_result = mysql_query( $query ); - $image_row = mysql_fetch_array( $image_result ); - - $file = get_filename_wo_extension( $image_row['file'] ); - - // creating links for thumbnail and associated category - $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] ); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$image_row['tn_ext']; - - $thumbnail_title = $lang['hint_category']; - - $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$subcat_id; - - $date = $page['plain_structure'][$subcat_id]['date_last']; - - // sending vars to display - if (!$cell_number && $i < count( $subcats )) - { - $template->assign_block_vars('thumbnails.line', array()); - $cell_number = 0; - $i++; - } - if ( $cell_number++ == $user['nb_image_line'] -1 ) - { - $cell_number = 0; - } - - $template->assign_block_vars( - 'thumbnails.line.thumbnail', - array( - 'IMAGE'=>$thumbnail_link, - 'IMAGE_ALT'=>$image_row['file'], - 'IMAGE_TITLE'=>$thumbnail_title, - 'IMAGE_NAME'=>$name, - 'IMAGE_TS'=>get_icon( $date ), - - 'U_IMG_LINK'=>add_session_id( $url_link ) - ) - ); - } + include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php'); } //------------------------------------------------------- category informations if ( isset ( $page['cat'] ) ) |