source: trunk/include/category_cats.inc.php @ 6316

Last change on this file since 6316 was 6316, checked in by plg, 15 years ago

merge r6313 from branch 2.1 to trunk

bug 1685 fixed: typo on identification.php link

File size: 8.9 KB
RevLine 
[1597]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[5196]5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1597]23
24/**
25 * This file is included by the main page to show thumbnails for a category
26 * that have only subcategories or to show recent categories
27 *
28 */
29
30if ($page['section']=='recent_cats')
31{
[1624]32  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
[1597]33  $query = '
[1624]34SELECT
[2515]35  c.*, nb_images, date_last, max_date_last, count_images, count_categories
36  FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
[1624]37  ON id = cat_id and user_id = '.$user['id'].'
[4367]38  WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']).'
[1677]39'.get_sql_condition_FandF
40  (
41    array
42      (
43        'visible_categories' => 'id',
44      ),
45    'AND'
46  ).'
47;';
[1597]48}
49else
50{
[1624]51  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
[1597]52  $query = '
[1624]53SELECT
[2515]54  c.*, nb_images, date_last, max_date_last, count_images, count_categories
55  FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
[1624]56  ON id = cat_id and user_id = '.$user['id'].'
[1597]57  WHERE id_uppercat '.
[1861]58  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'
[1677]59'.get_sql_condition_FandF
60  (
61    array
62      (
63        'visible_categories' => 'id',
64      ),
65    'AND'
66  ).'
[1597]67  ORDER BY rank
68;';
69}
70
71$result = pwg_query($query);
72$categories = array();
[1970]73$category_ids = array();
[1597]74$image_ids = array();
75
[4325]76while ($row = pwg_db_fetch_assoc($result))
[1597]77{
[1643]78  $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
[1624]79
[1597]80  if (isset($row['representative_picture_id'])
81      and is_numeric($row['representative_picture_id']))
82  { // if a representative picture is set, it has priority
83    $image_id = $row['representative_picture_id'];
84  }
85  else if ($conf['allow_random_representative'])
86  {// searching a random representant among elements in sub-categories
[2424]87    if ($row['count_images']>0)
88    {
89      $query = '
[1597]90SELECT image_id
91  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
[1648]92    ON ic.category_id = c.id';
[2424]93      $query.= '
[2330]94  WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')'
[2424]95    .get_sql_condition_FandF
96    (
97      array
98        (
99          'forbidden_categories' => 'c.id',
100          'visible_categories' => 'c.id',
101          'visible_images' => 'image_id'
102        ),
103      "\n  AND"
104    ).'
[4367]105  ORDER BY '.DB_RANDOM_FUNCTION.'()
[4334]106  LIMIT 1
[1597]107;';
[2424]108      $subresult = pwg_query($query);
[4325]109      if (pwg_db_num_rows($subresult) > 0)
[2424]110      {
[4325]111        list($image_id) = pwg_db_fetch_row($subresult);
[2424]112      }
[1597]113    }
114  }
115  else
116  { // searching a random representant among representant of sub-categories
[2424]117    if ($row['count_categories']>0 and $row['count_images']>0)
[1597]118    {
[2424]119      $query = '
120  SELECT representative_picture_id
121    FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
122    ON id = cat_id and user_id = '.$user['id'].'
123    WHERE uppercats LIKE \''.$row['uppercats'].',%\'
124      AND representative_picture_id IS NOT NULL'
125    .get_sql_condition_FandF
126    (
127      array
128        (
129          'visible_categories' => 'id',
130        ),
131      "\n  AND"
132    ).'
[4367]133    ORDER BY '.DB_RANDOM_FUNCTION.'()
[4334]134    LIMIT 1
[2424]135  ;';
136      $subresult = pwg_query($query);
[4325]137      if (pwg_db_num_rows($subresult) > 0)
[2424]138      {
[4325]139        list($image_id) = pwg_db_fetch_row($subresult);
[2424]140      }
[1597]141    }
142  }
143
144  if (isset($image_id))
145  {
146    $row['representative_picture_id'] = $image_id;
147    array_push($image_ids, $image_id);
148    array_push($categories, $row);
[1970]149    array_push($category_ids, $row['id']);
[1597]150  }
151  unset($image_id);
152}
153
[1970]154if ($conf['display_fromto'])
155{
156  $dates_of_category = array();
157  if (count($category_ids) > 0)
158  {
159    $query = '
160SELECT
161    category_id,
162    MIN(date_creation) AS date_creation_min,
163    MAX(date_creation) AS date_creation_max
164  FROM '.IMAGE_CATEGORY_TABLE.'
165    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
[2091]166  WHERE category_id IN ('.implode(',', $category_ids).')
[1971]167'.get_sql_condition_FandF
168  (
169    array
170      (
171        'visible_categories' => 'category_id',
[2091]172        'visible_images' => 'id'
[1971]173      ),
174    'AND'
175  ).'
[1970]176  GROUP BY category_id
177;';
178    $result = pwg_query($query);
[4325]179    while ($row = pwg_db_fetch_assoc($result))
[1970]180    {
181      $dates_of_category[ $row['category_id'] ] = array(
182        'from' => $row['date_creation_min'],
183        'to'   => $row['date_creation_max'],
184        );
185    }
186  }
187}
188
[1719]189if ($page['section']=='recent_cats')
190{
191  usort($categories, 'global_rank_compare');
192}
[1597]193if (count($categories) > 0)
194{
195  $thumbnail_src_of = array();
196
197  $query = '
198SELECT id, path, tn_ext
199  FROM '.IMAGES_TABLE.'
200  WHERE id IN ('.implode(',', $image_ids).')
201;';
202  $result = pwg_query($query);
[4325]203  while ($row = pwg_db_fetch_assoc($result))
[1597]204  {
205    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
206  }
207}
208
209if (count($categories) > 0)
210{
[1677]211  // Update filtered data
[1722]212  if (function_exists('update_cats_with_filtered_data'))
213  {
214    update_cats_with_filtered_data($categories);
215  }
[2079]216
[2274]217  $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
218
[1880]219  trigger_action('loc_begin_index_category_thumbnails', $categories);
[2274]220
[3124]221  $tpl_thumbnails_var = array();
222
[2274]223  foreach ($categories as $category)
[1597]224  {
[2433]225    $category['name'] = trigger_event(
226        'render_category_name',
227        $category['name'],
228        'subcatify_category_name'
229        );
230
[2274]231    if ($page['section']=='recent_cats')
[1597]232    {
[2274]233      $name = get_cat_display_name_cache($category['uppercats'], null, false);
234    }
235    else
236    {
237      $name = $category['name'];
238    }
[1597]239
[2274]240    $tpl_var =
[1597]241        array(
[2231]242          'ID'    => $category['id'],
243          'TN_SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
[2515]244          'TN_ALT'   => strip_tags($category['name']),
[3188]245          'icon_ts'  => get_icon($category['max_date_last'], $category['is_child_date_last']),
[1597]246
247          'URL'   => make_index_url(
248            array(
[1861]249              'category' => $category
[1597]250              )
251            ),
[1624]252          'CAPTION_NB_IMAGES' => get_display_images_count
253                                  (
254                                    $category['nb_images'],
255                                    $category['count_images'],
[1851]256                                    $category['count_categories'],
257                                    true,
[3185]258                                    '<br>'
[1624]259                                  ),
[2079]260          'DESCRIPTION' =>
[2091]261            trigger_event('render_category_literal_description',
262              trigger_event('render_category_description',
[2175]263                @$category['comment'],
264                'subcatify_category_description')),
[1597]265          'NAME'  => $name,
[2274]266        );
[1970]267
[2274]268    if ($conf['display_fromto'])
269    {
270      if (isset($dates_of_category[ $category['id'] ]))
[1970]271      {
[2274]272        $from = $dates_of_category[ $category['id'] ]['from'];
273        $to   = $dates_of_category[ $category['id'] ]['to'];
274
275        if (!empty($from))
[1970]276        {
[2274]277          $info = '';
[2091]278
[2274]279          if ($from == $to)
[1970]280          {
[2274]281            $info = format_date($from);
[1970]282          }
[2274]283          else
284          {
285            $info = sprintf(
286              l10n('from %s to %s'),
287              format_date($from),
288              format_date($to)
289              );
290          }
291          $tpl_var['INFO_DATES'] = $info;
[1970]292        }
[2274]293      }
294    }//fromto
[2234]295
[3124]296    $tpl_thumbnails_var[] = $tpl_var;
[1597]297  }
298
[3124]299  $tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories);
300  $template->assign( 'category_thumbnails', $tpl_thumbnails_var);
301
[2274]302  $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
[1597]303}
[3124]304pwg_debug('end include/category_cats.inc.php');
305?>
Note: See TracBrowser for help on using the repository browser.