source: branches/branch-1_6/include/category_subcats.inc.php @ 1291

Last change on this file since 1291 was 1291, checked in by chrisaga, 18 years ago
  • merge trunk r1289:1290 into branch 1.6 (bug 358 fixed)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 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-04-29 10:36:49 +0000 (Sat, 29 Apr 2006) $
10// | last modifier : $Author: chrisaga $
11// | revision      : $Revision: 1291 $
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, comment, nb_images
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$categories = array();
47$image_ids = array();
48
49while ($row = mysql_fetch_array($result))
50{
51  if (isset($row['representative_picture_id'])
52      and is_numeric($row['representative_picture_id']))
53  {
54    // if a representative picture is set, it has priority
55    $image_id = $row['representative_picture_id'];
56  }
57  else if ($conf['allow_random_representative'])
58  {
59    // searching a random representant among elements in sub-categories
60    $query = '
61SELECT image_id
62  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
63    ON ic.category_id = c.id
64  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
65    AND c.id NOT IN ('.$user['forbidden_categories'].')
66  ORDER BY RAND()
67  LIMIT 0,1
68;';
69    $subresult = pwg_query($query);
70    if (mysql_num_rows($result) > 0)
71    {
72      list($image_id) = mysql_fetch_row($subresult);
73    }
74  }
75  else
76  {
77    // searching a random representant among representant of sub-categories
78    $query = '
79SELECT representative_picture_id
80  FROM '.CATEGORIES_TABLE.'
81  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
82    AND id NOT IN ('.$user['forbidden_categories'].')
83    AND representative_picture_id IS NOT NULL
84  ORDER BY RAND()
85  LIMIT 0,1
86;';
87    $subresult = pwg_query($query);
88    if (mysql_num_rows($subresult) > 0)
89    {
90      list($image_id) = mysql_fetch_row($subresult);
91    }
92  }
93
94  $comment = null;
95  if (isset($row['comment']))
96  {
97    $comment = strip_tags($row['comment'], '<a><br><p><b><i><small><strong>');
98  }
99
100  if (isset($image_id))
101  {
102    array_push(
103      $categories,
104      array(
105        'category'    => $row['id'],
106        'picture'     => $image_id,
107        'name'        => $row['name'],
108        'date_last'   => @$row['date_last'],
109        'comment'     => $comment,
110        'nb_images'   => $row['nb_images'],
111        )
112      );
113
114    array_push($image_ids, $image_id);
115  }
116
117  unset($image_id);
118}
119
120if (count($image_ids) > 0)
121{
122  $thumbnail_src_of = array();
123
124  $query = '
125SELECT id, path, tn_ext
126  FROM '.IMAGES_TABLE.'
127  WHERE id IN ('.implode(',', $image_ids).')
128;';
129  $result = pwg_query($query);
130  while ($row = mysql_fetch_array($result))
131  {
132    $thumbnail_src_of[$row['id']] =
133      get_thumbnail_src($row['path'], @$row['tn_ext']);
134  }
135
136  if ($conf['subcatify'])
137  {
138    $template->set_filenames(
139      array(
140        'mainpage_categories' => 'mainpage_categories.tpl',
141        )
142      );
143
144    $template->assign_block_vars('categories', array());
145
146    foreach ($categories as $category)
147    {
148      $template->assign_block_vars(
149        'categories.category',
150        array(
151          'SRC'   => $thumbnail_src_of[ $category['picture'] ],
152          'ALT'   => $category['name'],
153          'TITLE' => $lang['hint_category'],
154          'ICON'  => get_icon(@$category['date_last']),
155
156          'URL' => make_index_url(
157            array(
158              'category' => $category['category'],
159              'cat_name' => $category['name'],
160              )
161            ),
162          'NAME' => $category['name'],
163          'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
164          'DESCRIPTION' => @$category['comment'],
165          )
166        );
167    }
168
169    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
170  }
171  else
172  {
173    $template->assign_block_vars('thumbnails', array());
174    // first line
175    $template->assign_block_vars('thumbnails.line', array());
176    // current row displayed
177    $row_number = 0;
178
179    foreach ($categories as $category)
180    {
181      $template->assign_block_vars(
182        'thumbnails.line.thumbnail',
183        array(
184          'IMAGE'       => $thumbnail_src_of[ $category['picture'] ],
185          'IMAGE_ALT'   => $category['name'],
186          'IMAGE_TITLE' => $lang['hint_category'],
187          'IMAGE_TS'    => get_icon(@$category['date_last']),
188
189          'U_IMG_LINK'  => make_index_url(
190            array(
191              'category' => $category['category'],
192              'cat_name' => $category['name'],
193              )
194            ),
195          'CLASS'       => 'thumbCat',
196          )
197        );
198
199      $template->assign_block_vars(
200        'thumbnails.line.thumbnail.category_name',
201        array(
202          'NAME' => $category['name']
203          )
204        );
205
206      // create a new line ?
207      if (++$row_number == $user['nb_image_line'])
208      {
209        $template->assign_block_vars('thumbnails.line', array());
210        $row_number = 0;
211      }
212    }
213  }
214}
215?>
Note: See TracBrowser for help on using the repository browser.