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

Last change on this file since 1131 was 1131, checked in by rvelices, 19 years ago

improvement: urls for tags can contain now only the tag or the id and tag

improvement: urls for category can be now id and category names (instead
of only id)

improvement: added 2 indexes (#image_tag.tag_id and #tags.url_name)

improvement: identification, register, search pages automatically set focus
on first form input

improvement: focus, nofocus css class now valid for all forms

fix: category comment is tag stripped in category_subcats.inc.php
(otherwise issues with html/scripts inside category comment)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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-06 02:23:54 +0000 (Thu, 06 Apr 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1131 $
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$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  $comment = null;
94  if ( isset($row['comment']) )
95  {
96    $comment = strip_tags( $row['comment'] );
97  }
98
99  if (isset($image_id))
100  {
101    array_push(
102      $cat_thumbnails,
103      array(
104        'category' => $row['id'],
105        'picture' => $image_id,
106        'name' => $row['name'],
107        'date_last' => @$row['date_last'],
108        'comment' => $comment,
109        'nb_images' => $row['nb_images'],
110        )
111      );
112  }
113
114  unset($image_id);
115}
116
117if (count($cat_thumbnails) > 0)
118{
119  $images = array();
120
121  foreach ($cat_thumbnails as $item)
122  {
123    $images[$item['picture']] = '';
124  }
125
126  $query = '
127SELECT id, path, tn_ext
128  FROM '.IMAGES_TABLE.'
129  WHERE id IN ('.implode(',', array_keys($images)).')
130;';
131  $result = pwg_query($query);
132  while ($row = mysql_fetch_array($result))
133  {
134    $images[$row['id']] = get_thumbnail_src($row['path'], @$row['tn_ext']);
135  }
136
137  $template->assign_block_vars('categories', array());
138
139  foreach ($cat_thumbnails as $item)
140  {
141    $template->assign_block_vars(
142      'categories.category',
143      array(
144        'SRC'   => $images[$item['picture']],
145        'ALT'   => $item['name'],
146        'TITLE' => $lang['hint_category'],
147        'ICON'  => get_icon(@$item['date_last']),
148
149        'URL' => make_index_url(
150          array(
151            'category' => $item['category'],
152            'cat_name' => $item['name'],
153            )
154          ),
155        'NAME' => $item['name'],
156        'NB_IMAGES' => $item['nb_images'],
157        'DESCRIPTION' => @$item['comment'],
158        )
159      );
160  }
161}
162?>
Note: See TracBrowser for help on using the repository browser.