source: tags/build-A01/include/functions_webserv.inc.php @ 12409

Last change on this file since 12409 was 1674, checked in by vdigital, 18 years ago

WEB Service: Some corrections but still an incomplete version.

File size: 5.3 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-02-28 02:13:16 +0100 (mar., 28 févr. 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1058 $
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//------------------------------------------------------------------- functions
29// official_req returns the managed requests list in array format
30function official_req()
31{
32return array(
33    'random'                              /* Random order */
34  , 'list'               /* list on MBt & z0rglub request */
35  , 'maxviewed'             /* hit > 0 and hit desc order */
36  , 'recent'        /* recent = Date_available desc order */
37  , 'highrated'            /* avg_rate > 0 and desc order */
38  , 'oldest'                  /* Date_available asc order */
39  , 'lessviewed'                         /* hit asc order */
40  , 'lowrated'                      /* avg_rate asc order */
41  , 'undescribed'                  /* description missing */
42  , 'unnamed'                         /* new name missing */
43  , 'portraits'     /* width < height (portrait oriented) */
44  , 'landscapes'   /* width > height (landscape oriented) */
45  , 'squares'             /* width ~ height (square form) */
46);
47}
48
49
50// expand_id_list($ids) convert a human list expression to a full ordered list
51// example : expand_id_list( array(5,2-3,2) ) returns array( 2, 3, 5)
52function expand_id_list($ids)
53{
54    $tid = array();
55    foreach ( $ids as $id )
56    {
57      if ( is_numeric($id) )
58      {
59        $tid[] = (int) $id;
60      }
61      else
62      {
63        $range = explode( '-', $id );
64        if ( is_numeric($range[0]) and is_numeric($range[1]) )
65        {
66          $from = min($range[0],$range[1]);
67          $to = max($range[0],$range[1]);
68          for ($i = $from; $i <= $to; $i++) 
69          {
70            $tid[] = (int) $i;
71          }
72        }
73      }
74    }
75    $result = array_unique ($tid); // remove duplicates...
76    sort ($result);
77    return $result;
78}
79
80// check_target($string) verifies and corrects syntax of target parameter
81// example : check_target(cat/23,24,24,24,25,27) returns cat/23-25,27
82function check_target($list)
83{
84  if ( $list !== '' )
85  {
86    $type = explode('/',$list); // Find type list
87    if ( !in_array($type[0],array('list','cat','tag') ) )
88    {
89      $type[0] = 'list'; // Assume an id list
90    } 
91    $ids = explode( ',',$type[1] );
92    $list = $type[0] . '/';
93
94    // 1,2,21,3,22,4,5,9-12,6,11,12,13,2,4,6,
95
96    $result = expand_id_list( $ids ); 
97
98    // 1,2,3,4,5,6,9,10,11,12,13,21,22,
99    // I would like
100    // 1-6,9-13,21-22
101    $serial[] = $result[0]; // To be shifted                     
102    foreach ($result as $k => $id)
103    {
104      $next_less_1 = (isset($result[$k + 1]))? $result[$k + 1] - 1:-1;
105      if ( $id == $next_less_1 and end($serial)=='-' )
106      { // nothing to do
107      }
108      elseif ( $id == $next_less_1 )
109      {
110        $serial[]=$id;
111        $serial[]='-';
112      }
113      else
114      {
115        $serial[]=$id;  // end serie or non serie
116      }
117    }
118    $null = array_shift($serial); // remove first value
119    $list .= array_shift($serial); // add the real first one
120    $separ = ',';
121    foreach ($serial as $id)
122    {
123      $list .= ($id=='-') ? '' : $separ . $id;
124      $separ = ($id=='-') ? '-':','; // add comma except if hyphen
125    }
126  }
127  return $list;
128}
129
130
131// FIXME Function which could already exist somewhere else
132function convert_catlist($cat_ids)
133{
134  $cat_list = implode(',', $cat_ids);
135  $ret_ids = array();
136  $query = '
137  SELECT DISTINCT image_id
138    FROM '.IMAGE_CATEGORY_TABLE.'
139  WHERE category_id in ('.$cat_list.')
140  ;';
141  $result = pwg_query($query);
142  while ($row = mysql_fetch_array($result))
143  {
144    $ret_ids[] = $row['image_id'];
145  }
146  return $ret_ids;
147}
148?>
Note: See TracBrowser for help on using the repository browser.