aboutsummaryrefslogtreecommitdiffstats
path: root/BSF/search_rules.php
blob: 942f4dc22cb8be389cea434bd3867f602e9bfc9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based picture gallery                                  |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

/**
 * returns language value 'included' or 'excluded' depending on boolean
 * value. This function is useful only to make duplicate code shorter
 *
 * @param bool is_included
 * @return string
 */
function inc_exc_str($is_included)
{
  return $is_included ? l10n('included') : l10n('excluded');
}

// +-----------------------------------------------------------------------+
// |                           initialization                              |
// +-----------------------------------------------------------------------+

define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
check_status(ACCESS_FREE);
include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' );

$page['body_id'] = 'thePopuphelpPage';
$title = l10n('Piwigo Help');
$page['page_banner'] = '<h1>'.$title.'</h1>';
$page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
include(PHPWG_ROOT_PATH.'include/page_header.php');

$template->set_filenames(array('search_rules' => 'search_rules.tpl'));

// +-----------------------------------------------------------------------+
// |                        Textual rules creation                         |
// +-----------------------------------------------------------------------+

// Rules are stored in database, serialized in an array. This array must be
// transformed into a list of textual rules.

$search = get_search_array($_GET['search_id']);

if (isset($search['q']))
{
  $template->append( 'search_words', $search['q'] );
}
else
{
  $template->assign(
    array(
      'INTRODUCTION'
        => 'OR' == $search['mode']
        ? l10n('At least one listed rule must be satisfied.')
        : l10n('Each listed rule must be satisfied.'),
      )
    );
}

if (isset($search['fields']['allwords']))
{
  $template->append( 'search_words',
      sprintf(
        l10n('searched words : %s'),
        join(', ', $search['fields']['allwords']['words'])
        )
      );
}

if (isset($search['fields']['tags']))
{
  $template->assign('SEARCH_TAGS_MODE', $search['fields']['tags']['mode']);
  
  $query = '
SELECT name
  FROM '.TAGS_TABLE.'
  WHERE id IN ('.implode(',', $search['fields']['tags']['words']).')
;';
  $template->assign(
      'search_tags',
      array_from_query($query, 'name')
    );
}

if (isset($search['fields']['author']))
{
  $template->append(
    'search_words',
     sprintf(
          l10n('author(s) : %s'),
          join(', ', $search['fields']['author']['words'])
        )
      );
}

if (isset($search['fields']['cat']))
{
  if ($search['fields']['cat']['sub_inc'])
  {
    // searching all the categories id of sub-categories
    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
  }
  else
  {
    $cat_ids = $search['fields']['cat']['words'];
  }

  $query = '
SELECT id, uppercats, global_rank
  FROM '.CATEGORIES_TABLE.'
  WHERE id IN ('.
    implode(',', $cat_ids).
    ')
;';
  $result = pwg_query($query);

  $categories = array();
  if (!empty($result))
  {
    while ($row = mysql_fetch_array($result))
    {
      array_push($categories, $row);
    }
  }
  usort($categories, 'global_rank_compare');

  foreach ($categories as $category)
  {
    $template->append(
      'search_categories',
      get_cat_display_name_cache(
          $category['uppercats'],
          null,                      // no url on category names
          false                    // no blank replacement
          )
      );
  }
}

foreach (array('date_available', 'date_creation') as $datefield)
{
  if ('date_available' == $datefield)
  {
    $lang_items = array(
      'date'   => 'became available on %s',
      'period' => 'became available between %s (%s) and %s (%s)',
      'after'  => 'became available after %s (%s)',
      'before' => 'became available before %s (%s)',
      );
  }
  elseif ('date_creation' == $datefield)
  {
    $lang_items = array(
      'date'   => 'created on %s',
      'period' => 'created between %s (%s) and %s (%s)',
      'after'  => 'created after %s (%s)',
      'before' => 'created before %s (%s)',
      );
  }

  $keys = array(
    'date'   => $datefield,
    'after'  => $datefield.'-after',
    'before' => $datefield.'-before',
    );

  if (isset($search['fields'][ $keys['date'] ]))
  {
    $template->assign(
      strtoupper($datefield),
      sprintf(
          l10n($lang_items['date']),
          format_date($search['fields'][ $keys['date'] ])
          )
      );
  }
  elseif (isset($search['fields'][ $keys['before'] ])
          and isset($search['fields'][ $keys['after'] ]))
  {
    $template->assign(
      strtoupper($datefield),
      sprintf(
          l10n($lang_items['period']),

          format_date($search['fields'][ $keys['after'] ]['date']),
          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),

          format_date($search['fields'][ $keys['before'] ]['date']),
          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
          )
      );
  }
  elseif (isset($search['fields'][ $keys['before'] ]))
  {
    $template->assign(
      strtoupper($datefield),
      sprintf(
          l10n($lang_items['before']),

          format_date($search['fields'][ $keys['before'] ]['date']),
          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
          )
      );
  }
  elseif (isset($search['fields'][ $keys['after'] ]))
  {
    $template->assign(
      strtoupper($datefield),
      sprintf(
          l10n($lang_items['after']),

          format_date($search['fields'][ $keys['after'] ]['date']),
          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
          )
      );
  }
}

// +-----------------------------------------------------------------------+
// |                           html code display                           |
// +-----------------------------------------------------------------------+

$template->pparse('search_rules');
include(PHPWG_ROOT_PATH.'include/page_tail.php');
?>