Skip to content

Commit

Permalink
- feature 642: display both subcategory thumbnails and element thumbn…
Browse files Browse the repository at this point in the history
…ails (if a

category has both) in the index page
- get rid of $page['cat_nb_images'] and $page['thumbnails_include'] (superfluous)
- changed sql queries in section_init.inc.php for better performance with
flat category view
- web service fixes for categories.getList

git-svn-id: http://piwigo.org/svn/trunk@1820 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Feb 15, 2007
1 parent b39e05f commit 1171495
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 92 deletions.
11 changes: 4 additions & 7 deletions include/category_cats.inc.php
Expand Up @@ -181,11 +181,7 @@

if ($conf['subcatify'])
{
$template->set_filenames(
array(
'mainpage_categories' => 'mainpage_categories.tpl',
)
);
$template->set_filename('mainpage_categories', 'mainpage_categories.tpl');

foreach ($categories as $category)
{
Expand Down Expand Up @@ -231,7 +227,7 @@
}
else
{
$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
$template->set_filename( 'thumbnails', 'thumbnails.tpl');
// first line
$template->assign_block_vars('thumbnails.line', array());
// current row displayed
Expand Down Expand Up @@ -295,7 +291,8 @@
$conf['level_separator']=$old_level_separator;
}

$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
$template->assign_var_from_handle('CATEGORIES', 'thumbnails');
unset( $template->_tpldata['thumbnails.'] );//maybe write a func for that
}
}
?>
19 changes: 6 additions & 13 deletions include/functions_calendar.inc.php
Expand Up @@ -197,19 +197,12 @@ function initialize_calendar()
$must_show_list = true; // true until calendar generates its own display
if (script_basename() != 'picture') // basename without file extention
{
$template->assign_block_vars('calendar', array());

if ($calendar->generate_category_content())
{
unset(
$page['thumbnails_include'],
$page['items']
);

$page['items'] = array();
$must_show_list = false;
}

$template->assign_block_vars( 'calendar.views', array() );
foreach ($styles as $style => $style_data)
{
foreach ($views as $view)
Expand Down Expand Up @@ -260,9 +253,11 @@ function initialize_calendar()
$calendar_title = '<a href="'.$url.'">'
.$fields[$page['chronology_field']]['label'].'</a>';
$calendar_title.= $calendar->get_display_name();
//this should be an assign_block_vars, but I need to assign 'calendar'
//above and at that point I don't have the title yet.
$template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title;
$template->merge_block_vars('calendar',
array(
'TITLE' => $calendar_title
)
);
} // end category calling

if ($must_show_list)
Expand Down Expand Up @@ -293,9 +288,7 @@ function initialize_calendar()
$query .= '
'.$order_by;
}

$page['items'] = array_from_query($query, 'id');
$page['thumbnails_include'] = 'include/category_default.inc.php';
}
pwg_debug('end initialize_calendar');
}
Expand Down
68 changes: 15 additions & 53 deletions include/section_init.inc.php
Expand Up @@ -33,11 +33,6 @@
*
* - $page['items']: ordered list of items to display
*
* - $page['cat_nb_images']: number of items in the section (should be equal
* to count($page['items']))
*
* - $page['thumbnails_include']: include page managing thumbnails to
* display
*/

// "index.php?/category/12-foo/start-24&action=fill_caddie" or
Expand All @@ -51,6 +46,8 @@
// 'action' => 'fill_caddie'
// );

$page['items'] = array();

// some ISPs set PATH_INFO to empty string or to SCRIPT_FILENAME while in the
// default apache implementation it is not set
if ( $conf['question_mark_in_urls']==false and
Expand Down Expand Up @@ -364,7 +361,7 @@
(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'image_id'
'visible_images' => 'id'
),
'AND'
);
Expand Down Expand Up @@ -395,20 +392,12 @@
'uppercats' => $result['uppercats'],
'title' =>
get_cat_display_name($result['name'], '', false),
'thumbnails_include' =>
(($result['nb_images'] > 0) or (isset($page['flat'])))
? 'include/category_default.inc.php'
: 'include/category_cats.inc.php'
)
);
}
else
{
$page['title'] = $lang['no_category'];
$page['thumbnails_include'] =
(isset($page['flat']))
? 'include/category_default.inc.php'
: 'include/category_cats.inc.php';
}

if
Expand All @@ -426,36 +415,24 @@
}

if (isset($page['flat']))
{
// flat recent categories mode
$query = '
SELECT
DISTINCT(ic.image_id)
FROM '.IMAGES_TABLE.' AS i
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id
WHERE
'.(isset($page['category']) ? '
uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '1=1' ).'
'.$forbidden.'
;';

$where_sql = array_from_query($query, 'image_id');
if (!empty($where_sql))
{// flat categories mode
if ( isset($page['category']) )
{
$subcat_ids = get_subcat_ids( array($page['category']) );
$where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
}
else
{
$where_sql = 'image_id in ('.implode(',', $where_sql).')';
$where_sql = '1=1';
}
}
else
{
// Normal mode
{// Normal mode
$where_sql = 'category_id = '.$page['category'];
}

if (!empty($where_sql))
{
// Main query
$query = '
// Main query
$query = '
SELECT DISTINCT(image_id)
FROM '.IMAGE_CATEGORY_TABLE.'
INNER JOIN '.IMAGES_TABLE.' ON id = image_id
Expand All @@ -465,12 +442,7 @@
'.$conf['order_by'].'
;';

$page['items'] = array_from_query($query, 'image_id');
}
else
{
$page['items'] = array();
}
$page['items'] = array_from_query($query, 'image_id');
} //otherwise the calendar will requery all subitems
}
// special sections
Expand Down Expand Up @@ -513,7 +485,6 @@
array(
'title' => $title,
'items' => array_values($items),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand Down Expand Up @@ -546,7 +517,6 @@
$page,
array(
'title' => $lang['search_result'],
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand Down Expand Up @@ -578,7 +548,6 @@
array(
'title' => $lang['favorites'],
'items' => array_from_query($query, 'image_id'),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand All @@ -603,7 +572,6 @@
'title' => '<a href="'.duplicate_index_url().'">'
.$lang['recent_pics_cat'].'</a>',
'items' => array_from_query($query, 'id'),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand All @@ -616,7 +584,6 @@
$page,
array(
'title' => $lang['recent_cats_cat'],
'thumbnails_include' => 'include/category_cats.inc.php',
)
);
}
Expand All @@ -643,7 +610,6 @@
'title' => '<a href="'.duplicate_index_url().'">'
.$conf['top_number'].' '.$lang['most_visited_cat'].'</a>',
'items' => array_from_query($query, 'id'),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand All @@ -670,7 +636,6 @@
'title' => '<a href="'.duplicate_index_url().'">'
.$conf['top_number'].' '.$lang['best_rated_cat'].'</a>',
'items' => array_from_query($query, 'id'),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand All @@ -694,7 +659,6 @@
'title' => '<a href="'.duplicate_index_url().'">'
.$lang['random_cat'].'</a>',
'items' => array_from_query($query, 'id'),
'thumbnails_include' => 'include/category_default.inc.php',
)
);
}
Expand All @@ -710,8 +674,6 @@
initialize_calendar();
}

$page['cat_nb_images'] = isset($page['items']) ? count($page['items']) : 0;

if (script_basename() == 'picture'
and !isset($page['image_id']) )
{
Expand Down
20 changes: 11 additions & 9 deletions include/ws_functions.inc.php
Expand Up @@ -405,33 +405,35 @@ function ws_categories_getImages($params, &$service)
*/
function ws_categories_getList($params, &$service)
{
global $user;
global $user,$conf;

$where = array();
$where[]= 'user_id='.$user['id'];
if ($params['cat_id']>0)
{
$where[] = 'uppercats REGEXP \'(^|,)'.
(int)($params['cat_id'])
.'(,|$)\'';
}

if (!$params['recursive'])
{
if ($params['cat_id']>0)
$where[] = 'id_uppercat='.(int)($params['cat_id']);
$where[] = '(id_uppercat='.(int)($params['cat_id']).'
OR id='.(int)($params['cat_id']).')';
else
$where[] = 'id_uppercat IS NULL';
}
else if ($params['cat_id']>0)
{
$where[] = 'uppercats REGEXP \'(^|,)'.
(int)($params['cat_id'])
.'(,|$)\'';
}

if ($params['public'])
{
$where[] = 'status = "public"';
$where[] = 'visible = "true"';
$where[]= 'user_id='.$conf['guest_id'];
}
else
{
$where[] = 'id NOT IN ('.$user['forbidden_categories'].')';
$where[]= 'user_id='.$user['id'];
}

$query = '
Expand Down
23 changes: 15 additions & 8 deletions index.php
Expand Up @@ -68,12 +68,11 @@
check_restrictions($page['category']);
}

if (isset($page['cat_nb_images'])
and $page['cat_nb_images'] > $user['nb_image_page'])
if ( count($page['items']) > $user['nb_image_page'])
{
$page['navigation_bar'] = create_navigation_bar(
duplicate_index_url(array(), array('start')),
$page['cat_nb_images'],
count($page['items']),
$page['start'],
$user['nb_image_page'],
true
Expand Down Expand Up @@ -101,9 +100,9 @@
$template->set_filenames( array('index'=>'index.tpl') );
//-------------------------------------------------------------- category title
$template_title = $page['title'];
if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0)
if ( count($page['items']) > 0)
{
$template_title.= ' ['.$page['cat_nb_images'].']';
$template_title.= ' ['.count($page['items']).']';
}

if (isset($page['flat']) or isset($page['chronology_field']))
Expand Down Expand Up @@ -241,9 +240,17 @@
}

//------------------------------------------------------ main part : thumbnails
if (isset($page['thumbnails_include']))
if ( 0==$page['start']
and !isset($page['flat'])
and !isset($page['chronology_field'])
and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
)
{
include(PHPWG_ROOT_PATH.$page['thumbnails_include']);
include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
}
if ( !empty($page['items']) )
{
include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
}
//------------------------------------------------------- category informations

Expand All @@ -258,7 +265,7 @@
);
}

if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0
if ( count($page['items']) > 0
and $page['section'] != 'most_visited'
and $page['section'] != 'best_rated')
{
Expand Down
2 changes: 1 addition & 1 deletion picture.php
Expand Up @@ -453,7 +453,7 @@ function default_picture_content($content, $element_info)
}

$title = $picture['current']['name'];
$title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images'];
$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);

// metadata
$url_metadata = duplicate_picture_url();
Expand Down
2 changes: 1 addition & 1 deletion template/yoga/index.tpl
Expand Up @@ -81,8 +81,8 @@
<!-- END calendar -->

{MONTH_CALENDAR}
{THUMBNAILS}
{CATEGORIES}
{THUMBNAILS}

<!-- BEGIN cat_infos -->
<!-- BEGIN navigation -->
Expand Down

0 comments on commit 1171495

Please sign in to comment.