source: trunk/include/category_subcats.inc.php @ 1119

Last change on this file since 1119 was 1098, checked in by chrisaga, 19 years ago

-new : add a 'CLASS' element in 'thumbnails.line.thumbnail' array to store a different classname for
category thumbnails and element thubnails in order to be able to display them differently.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-25 12:40:24 +0000 (Sat, 25 Mar 2006) $
10// | last modifier : $Author: chrisaga $
11// | revision      : $Revision: 1098 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * This file is included by the main page to show thumbnails for a category
30 * that have only subcategories
31 *
32 */
33
34$query = '
35SELECT id, name, date_last, representative_picture_id
36  FROM '.CATEGORIES_TABLE.'
37  WHERE id_uppercat '.
38  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
39    AND id NOT IN ('.$user['forbidden_categories'].')
40  ORDER BY rank
41;';
42$result = pwg_query($query);
43
44// $conf['allow_random_representative']
45
46$cat_thumbnails = array();
47
48while ($row = mysql_fetch_array($result))
49{
50  if (isset($row['representative_picture_id'])
51      and is_numeric($row['representative_picture_id']))
52  {
53    // if a representative picture is set, it has priority
54    $image_id = $row['representative_picture_id'];
55  }
56  else if ($conf['allow_random_representative'])
57  {
58    // searching a random representant among elements in sub-categories
59    $query = '
60SELECT image_id
61  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
62    ON ic.category_id = c.id
63  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
64    AND c.id NOT IN ('.$user['forbidden_categories'].')
65  ORDER BY RAND()
66  LIMIT 0,1
67;';
68    $subresult = pwg_query($query);
69    if (mysql_num_rows($result) > 0)
70    {
71      list($image_id) = mysql_fetch_row($subresult);
72    }
73  }
74  else
75  {
76    // searching a random representant among representant of sub-categories
77    $query = '
78SELECT representative_picture_id
79  FROM '.CATEGORIES_TABLE.'
80  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
81    AND id NOT IN ('.$user['forbidden_categories'].')
82    AND representative_picture_id IS NOT NULL
83  ORDER BY RAND()
84  LIMIT 0,1
85;';
86    $subresult = pwg_query($query);
87    if (mysql_num_rows($subresult) > 0)
88    {
89      list($image_id) = mysql_fetch_row($subresult);
90    }
91  }
92
93  if (isset($image_id))
94  {
95    array_push(
96      $cat_thumbnails,
97      array(
98        'category' => $row['id'],
99        'picture' => $image_id,
100        'name' => $row['name'],
101        'date_last' => @$row['date_last']
102        )
103      );
104  }
105
106  unset($image_id);
107}
108
109if (count($cat_thumbnails) > 0)
110{
111  $images = array();
112 
113  foreach ($cat_thumbnails as $item)
114  {
115    $images[$item['picture']] = '';
116  }
117
118  $query = '
119SELECT id, path, tn_ext
120  FROM '.IMAGES_TABLE.'
121  WHERE id IN ('.implode(',', array_keys($images)).')
122;';
123  $result = pwg_query($query);
124  while ($row = mysql_fetch_array($result))
125  {
126    $images[$row['id']] = get_thumbnail_src($row['path'], @$row['tn_ext']);
127  }
128
129  $template->assign_block_vars('thumbnails', array());
130  // first line
131  $template->assign_block_vars('thumbnails.line', array());
132  // current row displayed
133  $row_number = 0;
134 
135  foreach ($cat_thumbnails as $item)
136  {
137    $template->assign_block_vars(
138      'thumbnails.line.thumbnail',
139      array(
140        'IMAGE'       => $images[$item['picture']],
141        'IMAGE_ALT'   => $item['name'],
142        'IMAGE_TITLE' => $lang['hint_category'],
143        'IMAGE_TS'    => get_icon(@$item['date_last']),
144       
145        'U_IMG_LINK'  => make_index_url(
146          array(
147            'category' => $item['category'],
148            )
149          ),
150        'CLASS'       => 'thumbCat',
151        )
152      );
153   
154    $template->assign_block_vars(
155      'thumbnails.line.thumbnail.category_name',
156      array(
157        'NAME' => $item['name']
158        )
159      );
160   
161    // create a new line ?
162    if (++$row_number == $user['nb_image_line'])
163    {
164      $template->assign_block_vars('thumbnails.line', array());
165      $row_number = 0;
166    }
167  }
168}
169?>
Note: See TracBrowser for help on using the repository browser.