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

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

Administration: happy new year 2009, all PHP headers updated.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
RevLine 
[1597]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[3049]5// | Copyright(C) 2008-2009 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'].'
[1876]38  WHERE date_last >= SUBDATE(
[1597]39    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
[1677]40  )
41'.get_sql_condition_FandF
42  (
43    array
44      (
45        'visible_categories' => 'id',
46      ),
47    'AND'
48  ).'
49;';
[1597]50}
51else
52{
[1624]53  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
[1597]54  $query = '
[1624]55SELECT
[2515]56  c.*, nb_images, date_last, max_date_last, count_images, count_categories
57  FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
[1624]58  ON id = cat_id and user_id = '.$user['id'].'
[1597]59  WHERE id_uppercat '.
[1861]60  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'
[1677]61'.get_sql_condition_FandF
62  (
63    array
64      (
65        'visible_categories' => 'id',
66      ),
67    'AND'
68  ).'
[1597]69  ORDER BY rank
70;';
71}
72
73$result = pwg_query($query);
74$categories = array();
[1970]75$category_ids = array();
[1597]76$image_ids = array();
77
78while ($row = mysql_fetch_assoc($result))
79{
[1643]80  $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
[1624]81
[1597]82  if (isset($row['representative_picture_id'])
83      and is_numeric($row['representative_picture_id']))
84  { // if a representative picture is set, it has priority
85    $image_id = $row['representative_picture_id'];
86  }
87  else if ($conf['allow_random_representative'])
88  {// searching a random representant among elements in sub-categories
[2424]89    if ($row['count_images']>0)
90    {
91      $query = '
[1597]92SELECT image_id
93  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
[1648]94    ON ic.category_id = c.id';
[2424]95      $query.= '
[2330]96  WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')'
[2424]97    .get_sql_condition_FandF
98    (
99      array
100        (
101          'forbidden_categories' => 'c.id',
102          'visible_categories' => 'c.id',
103          'visible_images' => 'image_id'
104        ),
105      "\n  AND"
106    ).'
[1597]107  ORDER BY RAND()
108  LIMIT 0,1
109;';
[2424]110      $subresult = pwg_query($query);
111      if (mysql_num_rows($subresult) > 0)
112      {
113        list($image_id) = mysql_fetch_row($subresult);
114      }
[1597]115    }
116  }
117  else
118  { // searching a random representant among representant of sub-categories
[2424]119    if ($row['count_categories']>0 and $row['count_images']>0)
[1597]120    {
[2424]121      $query = '
122  SELECT representative_picture_id
123    FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
124    ON id = cat_id and user_id = '.$user['id'].'
125    WHERE uppercats LIKE \''.$row['uppercats'].',%\'
126      AND representative_picture_id IS NOT NULL'
127    .get_sql_condition_FandF
128    (
129      array
130        (
131          'visible_categories' => 'id',
132        ),
133      "\n  AND"
134    ).'
135    ORDER BY RAND()
136    LIMIT 0,1
137  ;';
138      $subresult = pwg_query($query);
139      if (mysql_num_rows($subresult) > 0)
140      {
141        list($image_id) = mysql_fetch_row($subresult);
142      }
[1597]143    }
144  }
145
146  if (isset($image_id))
147  {
148    $row['representative_picture_id'] = $image_id;
149    array_push($image_ids, $image_id);
150    array_push($categories, $row);
[1970]151    array_push($category_ids, $row['id']);
[1597]152  }
153  unset($image_id);
154}
155
[1970]156if ($conf['display_fromto'])
157{
158  $dates_of_category = array();
159  if (count($category_ids) > 0)
160  {
161    $query = '
162SELECT
163    category_id,
164    MIN(date_creation) AS date_creation_min,
165    MAX(date_creation) AS date_creation_max
166  FROM '.IMAGE_CATEGORY_TABLE.'
167    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
[2091]168  WHERE category_id IN ('.implode(',', $category_ids).')
[1971]169'.get_sql_condition_FandF
170  (
171    array
172      (
173        'visible_categories' => 'category_id',
[2091]174        'visible_images' => 'id'
[1971]175      ),
176    'AND'
177  ).'
[1970]178  GROUP BY category_id
179;';
180    $result = pwg_query($query);
181    while ($row = mysql_fetch_array($result))
182    {
183      $dates_of_category[ $row['category_id'] ] = array(
184        'from' => $row['date_creation_min'],
185        'to'   => $row['date_creation_max'],
186        );
187    }
188  }
189}
190
[1719]191if ($page['section']=='recent_cats')
192{
193  usort($categories, 'global_rank_compare');
194}
[1597]195if (count($categories) > 0)
196{
197  $thumbnail_src_of = array();
198
199  $query = '
200SELECT id, path, tn_ext
201  FROM '.IMAGES_TABLE.'
202  WHERE id IN ('.implode(',', $image_ids).')
203;';
204  $result = pwg_query($query);
205  while ($row = mysql_fetch_assoc($result))
206  {
207    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
208  }
209}
210
211if (count($categories) > 0)
212{
[1677]213  // Update filtered data
[1722]214  if (function_exists('update_cats_with_filtered_data'))
215  {
216    update_cats_with_filtered_data($categories);
217  }
[2079]218
[2274]219  $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
220
[1880]221  trigger_action('loc_begin_index_category_thumbnails', $categories);
[2274]222
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    $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
[1638]241
[2274]242    $tpl_var =
[1597]243        array(
[2231]244          'ID'    => $category['id'],
245          'TN_SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
[2515]246          'TN_ALT'   => strip_tags($category['name']),
247          'ICON_TS'  => $icon_ts,
[1597]248
249          'URL'   => make_index_url(
250            array(
[1861]251              'category' => $category
[1597]252              )
253            ),
[1624]254          'CAPTION_NB_IMAGES' => get_display_images_count
255                                  (
256                                    $category['nb_images'],
257                                    $category['count_images'],
[1851]258                                    $category['count_categories'],
259                                    true,
[1869]260                                    '<br />'
[1624]261                                  ),
[2079]262          'DESCRIPTION' =>
[2091]263            trigger_event('render_category_literal_description',
264              trigger_event('render_category_description',
[2175]265                @$category['comment'],
266                'subcatify_category_description')),
[1597]267          'NAME'  => $name,
[2274]268        );
[1970]269
[2274]270    if ($conf['display_fromto'])
271    {
272      if (isset($dates_of_category[ $category['id'] ]))
[1970]273      {
[2274]274        $from = $dates_of_category[ $category['id'] ]['from'];
275        $to   = $dates_of_category[ $category['id'] ]['to'];
276
277        if (!empty($from))
[1970]278        {
[2274]279          $info = '';
[2091]280
[2274]281          if ($from == $to)
[1970]282          {
[2274]283            $info = format_date($from);
[1970]284          }
[2274]285          else
286          {
287            $info = sprintf(
288              l10n('from %s to %s'),
289              format_date($from),
290              format_date($to)
291              );
292          }
293          $tpl_var['INFO_DATES'] = $info;
[1970]294        }
[2274]295      }
296    }//fromto
[2234]297
[2274]298    //plugins need to add/modify sth in this loop ?
299    $tpl_var = trigger_event('loc_index_category_thumbnail',
300                  $tpl_var, $category );
[1970]301
[2274]302    $template->append( 'category_thumbnails', $tpl_var);
[1597]303  }
304
[1880]305  trigger_action('loc_end_index_category_thumbnails', $categories);
[2274]306  $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
[1597]307}
[2274]308?>
Note: See TracBrowser for help on using the repository browser.