source: trunk/include/functions_category.inc.php @ 442

Last change on this file since 442 was 442, checked in by z0rglub, 20 years ago
  • code refactoring
  • for calendar category, adds the support of the day request (displays the list of category for this day)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                      functions_category.inc.php                       |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-06-25 20:31:48 +0000 (Fri, 25 Jun 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 442 $
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 * Provides functions to handle categories.
30 *
31 *
32 */
33
34/**
35 * Is the category accessible to the connected user ?
36 *
37 * Note : if the user is not authorized to see this category, page creation
38 * ends (exit command in this function)
39 *
40 * @param int category id to verify
41 * @return void
42 */
43function check_restrictions( $category_id )
44{
45  global $user,$lang;
46
47  if ( in_array( $category_id, $user['restrictions'] ) )
48  {
49    echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
50    echo '<a href="'.add_session_id( './category.php' ).'">';
51    echo $lang['thumbnails'].'</a></div>';
52    exit();
53  }
54}
55
56/**
57 * Checks whether the argument is a right parameter category id
58 *
59 * The argument is a right parameter if corresponds to one of these :
60 *
61 *  - is numeric and corresponds to a category in the database
62 *  - equals 'fav' (for favorites)
63 *  - equals 'search' (when the result of a search is displayed)
64 *  - equals 'most_visited'
65 *  - equals 'best_rated'
66 *  - equals 'recent_pics'
67 *  - equals 'recent_cats'
68 *  _ equals 'calendar'
69 *
70 * The function fills the global var $page['cat'] and returns nothing
71 *
72 * @param mixed category id or special category name
73 * @return void
74 */
75function check_cat_id( $cat )
76{
77  global $page;
78
79  unset( $page['cat'] );
80  if ( isset( $cat ) )
81  {
82    if ( isset( $page['plain_structure'][$cat] ) )
83    {
84      $page['cat'] = $cat;
85    }
86    else if ( is_numeric( $cat ) )
87    {
88      $query = 'SELECT id';
89      $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';';
90      $result = mysql_query( $query );
91      if ( mysql_num_rows( $result ) != 0 )
92      {
93        $page['cat'] = $cat;
94      }
95    }
96    if ( $cat == 'fav'
97         or $cat == 'search'
98         or $cat == 'most_visited'
99         or $cat == 'best_rated'
100         or $cat == 'recent_pics'
101         or $cat == 'recent_cats'
102         or $cat == 'calendar' )
103    {
104      $page['cat'] = $cat;
105    }
106  }
107}
108
109function get_user_plain_structure()
110{
111  global $page,$user;
112 
113  $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat',
114                  'rank','site_id','uppercats');
115 
116  $query = 'SELECT '.implode( ',', $infos );
117  $query.= ' FROM '.CATEGORIES_TABLE;
118  $query.= ' WHERE 1 = 1'; // stupid but permit using AND after it !
119  if ( !$user['expand'] )
120  {
121    $query.= ' AND (id_uppercat is NULL';
122    if ( count( $page['tab_expand'] ) > 0 )
123    {
124      $query.= ' OR id_uppercat IN ('.implode(',',$page['tab_expand']).')';
125    }
126    $query.= ')';
127  }
128  if ( $user['forbidden_categories'] != '' )
129  {
130    $query.= ' AND id NOT IN ';
131    $query.= '('.$user['forbidden_categories'].')';
132  }
133  $query.= ' ORDER BY id_uppercat ASC, rank ASC';
134  $query.= ';';
135
136  $plain_structure = array();
137  $result = mysql_query( $query );
138  while ( $row = mysql_fetch_array( $result ) )
139  {
140    $category = array();
141    foreach ( $infos as $info ) {
142      if ( $info == 'uc.date_last')
143      {
144        if ( empty( $row['date_last'] ) )
145        {
146          $category['date_last'] = 0;
147        }
148        else
149        {
150          list($year,$month,$day) = explode( '-', $row['date_last'] );
151          $category['date_last'] = mktime(0,0,0,$month,$day,$year);
152        }
153      }
154      else if ( isset( $row[$info] ) ) $category[$info] = $row[$info];
155      else                             $category[$info] = '';
156    }
157    $plain_structure[$row['id']] = $category;
158  }
159
160  return $plain_structure;
161}
162
163function create_user_structure( $id_uppercat )
164{
165  global $page;
166
167  if ( !isset( $page['plain_structure'] ) )
168    $page['plain_structure'] = get_user_plain_structure();
169
170  $structure = array();
171  $ids = get_user_subcat_ids( $id_uppercat );
172  foreach ( $ids as $id ) {
173    $category = $page['plain_structure'][$id];
174    $category['subcats'] = create_user_structure( $id );
175    array_push( $structure, $category );
176  }
177  return $structure;
178}
179
180function get_user_subcat_ids( $id_uppercat )
181{
182  global $page;
183
184  $ids = array();
185  foreach ( $page['plain_structure'] as $id => $category ) {
186    if ( $category['id_uppercat'] == $id_uppercat ) array_push( $ids, $id );
187    else if ( count( $ids ) > 0 )                   return $ids;
188  }
189  return $ids;
190}
191
192// update_structure updates or add informations about each node of the
193// structure :
194//
195// 1. should the category be expanded in the menu ?
196// If the category has to be expanded (ie its id is in the
197// $page['tab_expand'] or all the categories must be expanded by default),
198// $category['expanded'] is set to true.
199//
200// 2. associated expand string
201// in the menu, there is a expand string (used in the URL) to tell which
202// categories must be expanded in the menu if this category is chosen
203function update_structure( $categories )
204{
205  global $page, $user;
206
207  $updated_categories = array();
208
209  foreach ( $categories as $category ) {
210    // update the "expanded" key
211    if ( $user['expand']
212         or in_array( $category['id'], $page['tab_expand'] ) )
213    {
214      $category['expanded'] = true;
215    }
216    else
217    {
218      $category['expanded'] = false;
219    }
220    // recursive call
221    $category['subcats'] = update_structure( $category['subcats'] );
222    // adding the updated category
223    array_push( $updated_categories, $category );
224  }
225
226  return $updated_categories;
227}
228
229// count_images returns the number of pictures contained in the given
230// category represented by an array, in this array, we have (among other
231// things) :
232// $category['nb_images'] -> number of pictures in this category
233// $category['subcats'] -> array of sub-categories
234// count_images goes to the deepest sub-category to find the total number of
235// pictures contained in the given given category
236function count_images( $categories )
237{
238  return count_user_total_images();
239  $total = 0;
240  foreach ( $categories as $category ) {
241    $total+= $category['nb_images'];
242    $total+= count_images( $category['subcats'] );
243  }
244  return $total;
245}
246
247function count_user_total_images()
248{
249  global $user;
250
251  $query = 'SELECT SUM(nb_images) AS total';
252  $query.= ' FROM '.CATEGORIES_TABLE;
253  if ( count( $user['restrictions'] ) > 0 )
254    $query.= ' WHERE id NOT IN ('.$user['forbidden_categories'].')';
255  $query.= ';';
256 
257  $row = mysql_fetch_array( mysql_query( $query ) );
258
259  if ( !isset( $row['total'] ) ) $row['total'] = 0;
260
261  return $row['total'];
262}
263
264/**
265 * Retrieve informations about a category in the database
266 *
267 * Returns an array with following keys :
268 *
269 *  - comment
270 *  - dir : directory, might be empty for virtual categories
271 *  - name : an array with indexes from 0 (lowest cat name) to n (most
272 *           uppercat name findable)
273 *  - nb_images
274 *  - id_uppercat
275 *  - site_id
276 *  -
277 *
278 * @param int category id
279 * @return array
280 */
281function get_cat_info( $id )
282{
283  $infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url'
284                  ,'dir','date_last','uploadable','status','visible'
285                  ,'representative_picture_id','uppercats' );
286
287  $query = 'SELECT '.implode( ',', $infos );
288  $query.= ' FROM '.CATEGORIES_TABLE.' AS a';
289  $query.= ', '.SITES_TABLE.' AS b';
290  $query.= ' WHERE a.id = '.$id;
291  $query.= ' AND a.site_id = b.id';
292  $query.= ';';
293  $row = mysql_fetch_array( mysql_query( $query ) );
294
295  $cat = array();
296  // affectation of each field of the table "config" to an information of the
297  // array $cat.
298  foreach ( $infos as $info ) {
299    if ( isset( $row[$info] ) ) $cat[$info] = $row[$info];
300    else                        $cat[$info] = '';
301    // If the field is true or false, the variable is transformed into a
302    // boolean value.
303    if ( $cat[$info] == 'true' or $cat[$info] == 'false' )
304    {
305      $cat[$info] = get_boolean( $cat[$info] );
306    }
307  }
308  $cat['comment'] = nl2br( $cat['comment'] );
309
310  $cat['name'] = array();
311
312  $query = 'SELECT name,id FROM '.CATEGORIES_TABLE;
313  $query.= ' WHERE id IN ('.$cat['uppercats'].')';
314  $query.= ' ORDER BY id ASC';
315  $query.= ';';
316  $result = mysql_query( $query );
317  while( $row = mysql_fetch_array( $result ) )
318  {
319    $cat['name'][$row['id']] = $row['name'];
320  }
321 
322  return $cat;
323}
324
325// get_complete_dir returns the concatenation of get_site_url and
326// get_local_dir
327// Example : "pets > rex > 1_year_old" is on the the same site as the
328// PhpWebGallery files and this category has 22 for identifier
329// get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/"
330function get_complete_dir( $category_id )
331{
332  return get_site_url( $category_id ).get_local_dir( $category_id );
333}
334
335// get_local_dir returns an array with complete path without the site url
336// Example : "pets > rex > 1_year_old" is on the the same site as the
337// PhpWebGallery files and this category has 22 for identifier
338// get_local_dir(22) returns "pets/rex/1_year_old/"
339function get_local_dir( $category_id )
340{
341  global $page;
342
343  $uppercats = '';
344  $local_dir = '';
345
346  if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
347  {
348    $uppercats = $page['plain_structure'][$category_id]['uppercats'];
349  }
350  else
351  {
352    $query = 'SELECT uppercats';
353    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
354    $query.= ';';
355    $row = mysql_fetch_array( mysql_query( $query ) );
356    $uppercats = $row['uppercats'];
357  }
358
359  $upper_array = explode( ',', $uppercats );
360
361  $database_dirs = array();
362  $query = 'SELECT id,dir';
363  $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
364  $query.= ';';
365  $result = mysql_query( $query );
366  while( $row = mysql_fetch_array( $result ) )
367  {
368    $database_dirs[$row['id']] = $row['dir'];
369  }
370  foreach ( $upper_array as $id ) {
371    $local_dir.= $database_dirs[$id].'/';
372  }
373
374  return $local_dir;
375}
376
377// retrieving the site url : "http://domain.com/gallery/" or
378// simply "./galleries/"
379function get_site_url( $category_id )
380{
381  global $page;
382
383  $query = 'SELECT galleries_url';
384  $query.= ' FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c';
385  $query.= ' WHERE s.id = c.site_id';
386  $query.= ' AND c.id = '.$category_id;
387  $query.= ';';
388  $row = mysql_fetch_array( mysql_query( $query ) );
389  return $row['galleries_url'];
390}
391
392// initialize_category initializes ;-) the variables in relation
393// with category :
394// 1. calculation of the number of pictures in the category
395// 2. determination of the SQL query part to ask to find the right category
396//    $page['where'] is not the same if we are in
397//       - simple category
398//       - search result
399//       - favorites displaying
400//       - most visited pictures
401//       - best rated pictures
402//       - recent pictures
403// 3. determination of the title of the page
404// 4. creation of the navigation bar
405function initialize_category( $calling_page = 'category' )
406{
407  pwg_debug( 'start initialize_category' );
408  global $page,$lang,$user,$conf;
409
410  if ( isset( $page['cat'] ) )
411  {
412    // $page['nb_image_page'] is the number of picture to display on this page
413    // By default, it is the same as the $user['nb_image_page']
414    $page['nb_image_page'] = $user['nb_image_page'];
415    // $url is used to create the navigation bar
416    $url = './category.php?cat='.$page['cat'];
417    if ( isset($page['expand']) ) $url.= '&amp;expand='.$page['expand'];
418    // simple category
419    if ( is_numeric( $page['cat'] ) )
420    {
421      $result = get_cat_info( $page['cat'] );
422      $page['comment']        = $result['comment'];
423      $page['cat_dir']        = $result['dir'];
424      $page['cat_name']       = $result['name'];
425      $page['cat_nb_images']  = $result['nb_images'];
426      $page['cat_site_id']    = $result['site_id'];
427      $page['cat_uploadable'] = $result['uploadable'];
428      $page['uppercats']      = $result['uppercats'];
429      $page['title'] = get_cat_display_name( $page['cat_name'],' - ','',false);
430      $page['where'] = ' WHERE category_id = '.$page['cat'];
431    }
432    else
433    {
434      if ( $page['cat'] == 'search'
435           or $page['cat'] == 'most_visited'
436           or $page['cat'] == 'recent_pics'
437           or $page['cat'] == 'recent_cats'
438           or $page['cat'] == 'best_rated'
439           or $page['cat'] == 'calendar' )
440      {
441        // we must not show pictures of a forbidden category
442        if ( $user['forbidden_categories'] != '' )
443        {
444          $forbidden = ' category_id NOT IN ';
445          $forbidden.= '('.$user['forbidden_categories'].')';
446        }
447      }
448      // search result
449      if ( $page['cat'] == 'search' )
450      {
451        $page['title'] = $lang['search_result'];
452        if ( $calling_page == 'picture' )
453        {
454          $page['title'].= ' : <span style="font-style:italic;">';
455          $page['title'].= $_GET['search']."</span>";
456        }
457
458        $page['where'] = ' WHERE (';
459        $fields = array( 'file', 'name', 'comment', 'keywords' );
460        $words = explode( ',', $_GET['search'] );
461        $sql_search = array();
462        foreach ( $words as $i => $word ) {
463          // if the user searchs any of the words, the where statement must
464          // be :
465          // field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' ...
466          // OR field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' ...
467          if ( $_GET['mode'] == 'OR' )
468          {
469            if ( $i != 0 ) $page['where'].= ' OR';
470            foreach ( $fields as $j => $field ) {
471              if ( $j != 0 ) $page['where'].= ' OR';
472              $page['where'].= ' '.$field." LIKE '%".$word."%'";
473            }
474          }
475          // if the user searchs all the words :
476          // ( field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' )
477          // AND ( field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' )
478          else if ( $_GET['mode'] == 'AND' )
479          {
480            if ( $i != 0 ) $page['where'].= ' AND';
481            $page['where'].= ' (';
482            foreach ( $fields as $j => $field ) {
483              if ( $j != 0 ) $page['where'].= ' OR';
484              $page['where'].= ' '.$field." LIKE '%".$word."%'";
485            }
486            $page['where'].= ' )';
487          }
488        }
489        $page['where'].= ' )';
490        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
491
492        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
493        $query.= ' FROM '.IMAGES_TABLE;
494        $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
495        $query.= ' ON id = ic.image_id';
496        $query.= $page['where'];
497        $query.= ';';
498
499        $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
500      }
501      // favorites displaying
502      else if ( $page['cat'] == 'fav' )
503      {
504        $page['title'] = $lang['favorites'];
505
506        $page['where'] = ', '.FAVORITES_TABLE.' AS fav';
507        $page['where'].= ' WHERE user_id = '.$user['id'];
508        $page['where'].= ' AND fav.image_id = id';
509     
510        $query = 'SELECT COUNT(*) AS nb_total_images';
511        $query.= ' FROM '.FAVORITES_TABLE;
512        $query.= ' WHERE user_id = '.$user['id'];
513        $query.= ';';
514      }
515      // pictures within the short period
516      else if ( $page['cat'] == 'recent_pics' )
517      {
518        $page['title'] = $lang['recent_pics_cat_title'];
519        // We must find the date corresponding to :
520        // today - $conf['periode_courte']
521        $date = time() - 60*60*24*$user['short_period'];
522        $page['where'] = " WHERE date_available > '";
523        $page['where'].= date( 'Y-m-d', $date )."'";
524        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
525
526        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
527        $query.= ' FROM '.IMAGES_TABLE;
528        $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic';
529        $query.= ' ON id = ic.image_id';
530        $query.= $page['where'];
531        $query.= ';';
532      }
533      // categories containing recent pictures
534      else if ( $page['cat'] == 'recent_cats' )
535      {
536        $page['title'] = $lang['recent_cats_cat_title'];
537        $page['cat_nb_images'] = 0;
538      }
539      // most visited pictures
540      else if ( $page['cat'] == 'most_visited' )
541      {
542        $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
543       
544        if ( isset( $forbidden ) ) $page['where'] = ' WHERE '.$forbidden;
545        else                       $page['where'] = '';
546        $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
547        $page['cat_nb_images'] = $conf['top_number'];
548        if ( isset( $page['start'] )
549             and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
550        {
551          $page['nb_image_page'] = $conf['top_number'] - $page['start'];
552        }
553      }
554      else if ( $page['cat'] == 'calendar' )
555      {
556        $page['cat_nb_images'] = 0;
557        $page['title'] = $lang['calendar'];
558        if (isset($_GET['year'])
559            and preg_match('/^\d+$/', $_GET['year']))
560        {
561          $page['calendar_year'] = (int)$_GET['year'];
562        }
563        if (isset($_GET['month'])
564            and preg_match('/^(\d+)\.(\d{2})$/', $_GET['month'], $matches))
565        {
566          $page['calendar_year'] = (int)$matches[1];
567          $page['calendar_month'] = (int)$matches[2];
568        }
569        if (isset($_GET['day'])
570            and preg_match('/^(\d+)\.(\d{2})\.(\d{2})$/',
571                           $_GET['day'],
572                           $matches))
573        {
574          $page['calendar_year'] = (int)$matches[1];
575          $page['calendar_month'] = (int)$matches[2];
576          $page['calendar_day'] = (int)$matches[3];
577        }
578        if (isset($page['calendar_year']))
579        {
580          $page['title'] .= ' (';
581          if (isset($page['calendar_day']))
582          {
583            $unixdate = mktime(0,0,0,
584                               $page['calendar_month'],
585                               $page['calendar_day'],
586                               $page['calendar_year']);
587            $page['title'].= $lang['day'][date("w", $unixdate)];
588            $page['title'].= ' '.$page['calendar_day'].', ';
589          }
590          if (isset($page['calendar_month']))
591          {
592            $page['title'] .= $lang['month'][$page['calendar_month']].' ';
593          }
594          $page['title'] .= $page['calendar_year'];
595          $page['title'] .= ')';
596        }
597        if (isset($forbidden))
598        {
599          $page['where'] = 'WHERE '.$forbidden;
600        }
601        else
602        {
603          $page['where'] = 'WHERE 1=1';
604        }
605      }
606
607      if (isset($query))
608      {
609        $result = mysql_query( $query );
610        $row = mysql_fetch_array( $result );
611        $page['cat_nb_images'] = $row['nb_total_images'];
612      }
613    }
614    if ( $calling_page == 'category' )
615    {
616      $page['navigation_bar'] =
617        create_navigation_bar( $url, $page['cat_nb_images'], $page['start'],
618                               $user['nb_image_page'], 'back' );
619    }
620  }
621  else
622  {
623    $page['title'] = $lang['diapo_default_page_title'];
624  }
625  pwg_debug( 'end initialize_category' );
626}
627
628// get_non_empty_subcat_ids returns an array with sub-categories id
629// associated with their first non empty category id.
630//
631//                          example :
632//
633// - catname [cat_id]
634// - cat1 [1] -> given uppercat
635//   - cat1.1 [12] (empty)
636//     - cat1.1.1 [5] (empty)
637//     - cat1.1.2 [6]
638//   - cat1.2 [3]
639//   - cat1.3 [4]
640//
641// get_non_empty_sub_cat_ids will return :
642//   $ids[12] = 6;
643//   $ids[3]  = 3;
644//   $ids[4]  = 4;
645function get_non_empty_subcat_ids( $id_uppercat )
646{
647  global $user;
648
649  $ids = array();
650
651  $query = 'SELECT id,nb_images';
652  $query.= ' FROM '.CATEGORIES_TABLE;
653  $query.= ' WHERE id_uppercat ';
654  if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL';
655  else                               $query.= '= '.$id_uppercat;
656  // we must not show pictures of a forbidden category
657  if ( $user['forbidden_categories'] != '' )
658  {
659    $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
660  }
661  $query.= ' ORDER BY rank';
662  $query.= ';';
663
664  $result = mysql_query( $query );
665  while ( $row = mysql_fetch_array( $result ) )
666  {
667    // only categories with findable picture in any of its subcats is
668    // represented.
669    if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] )
670         or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )
671    {
672      $ids[$row['id']] = $non_empty_cat;
673    }
674  }
675  return $ids;
676}
677
678// get_first_non_empty_cat_id returns the id of the first non empty
679// sub-category to the given uppercat. If no picture is found in any
680// subcategory, false is returned.
681function get_first_non_empty_cat_id( $id_uppercat )
682{
683  global $user;
684
685  $query = 'SELECT id,nb_images';
686  $query.= ' FROM '.CATEGORIES_TABLE;
687  $query.= ' WHERE id_uppercat = '.$id_uppercat;
688  // we must not show pictures of a forbidden category
689  if ( $user['forbidden_categories'] != '' )
690  {
691    $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
692  }
693  $query.= ' ORDER BY RAND()';
694  $query.= ';';
695  $result = mysql_query( $query );
696  while ( $row = mysql_fetch_array( $result ) )
697  {
698    if ( $row['nb_images'] > 0 )
699    {
700      return $row['id'];
701    }
702  }
703  $result = mysql_query( $query );
704  while ( $row = mysql_fetch_array( $result ) )
705  {
706    // recursive call
707    if ( $subcat = get_first_non_empty_cat_id( $row['id'] ) )
708    {
709      return $subcat;
710    }
711  }
712  return false;
713}
714?>
Note: See TracBrowser for help on using the repository browser.