/**
 * Returns display text for images counter of category
 *
 * @param int $cat_nb_images nb images directly in category
 * @param int $cat_count_images nb images in category (including subcats)
 * @param int $cat_count_categories nb subcats
 * @param bool $short_message if true append " in this album"
 * @param string $separator
 * @return string
 */
function get_display_images_count($cat_nb_images, $cat_count_images, $cat_count_categories, $short_message = true, $separator = '\\n')
{
    $display_text = '';
    if ($cat_count_images > 0) {
        if ($cat_nb_images > 0 and $cat_nb_images < $cat_count_images) {
            $display_text .= get_display_images_count($cat_nb_images, $cat_nb_images, 0, $short_message, $separator) . $separator;
            $cat_count_images -= $cat_nb_images;
            $cat_nb_images = 0;
        }
        //at least one image direct or indirect
        $display_text .= l10n_dec('%d photo', '%d photos', $cat_count_images);
        if ($cat_count_categories == 0 or $cat_nb_images == $cat_count_images) {
            //no descendant categories or descendants do not contain images
            if (!$short_message) {
                $display_text .= ' ' . l10n('in this album');
            }
        } else {
            $display_text .= ' ' . l10n_dec('in %d sub-album', 'in %d sub-albums', $cat_count_categories);
        }
    }
    return $display_text;
}
 }
 $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
 trigger_notify('loc_begin_index_category_thumbnails', $categories);
 $tpl_thumbnails_var = array();
 foreach ($categories as $category) {
     if (0 == $category['count_images']) {
         continue;
     }
     $category['name'] = trigger_change('render_category_name', $category['name'], 'subcatify_category_name');
     if ($page['section'] == 'recent_cats') {
         $name = get_cat_display_name_cache($category['uppercats'], null);
     } else {
         $name = $category['name'];
     }
     $representative_infos = $infos_of_image[$category['representative_picture_id']];
     $tpl_var = array_merge($category, array('ID' => $category['id'], 'representative' => $representative_infos, 'TN_ALT' => strip_tags($category['name']), 'URL' => make_index_url(array('category' => $category)), 'CAPTION_NB_IMAGES' => get_display_images_count($category['nb_images'], $category['count_images'], $category['count_categories'], true, '<br>'), 'DESCRIPTION' => trigger_change('render_category_literal_description', trigger_change('render_category_description', @$category['comment'], 'subcatify_category_description')), 'NAME' => $name));
     if ($conf['index_new_icon']) {
         $tpl_var['icon_ts'] = get_icon($category['max_date_last'], $category['is_child_date_last']);
     }
     if ($conf['display_fromto']) {
         if (isset($dates_of_category[$category['id']])) {
             $from = $dates_of_category[$category['id']]['from'];
             $to = $dates_of_category[$category['id']]['to'];
             if (!empty($from)) {
                 $tpl_var['INFO_DATES'] = format_fromto($from, $to);
             }
         }
     }
     $tpl_thumbnails_var[] = $tpl_var;
 }
 // pagination