-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
130 lines (114 loc) · 3.4 KB
/
search.php
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
<?php
// +-----------------------------------------------------------------------+
// | This file is part of Piwigo. |
// | |
// | For copyright and license information, please view the COPYING.txt |
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+
//--------------------------------------------------------------------- include
define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php');
// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok |
// +-----------------------------------------------------------------------+
check_status(ACCESS_GUEST);
trigger_notify('loc_begin_search');
// +-----------------------------------------------------------------------+
// | Create a default search |
// +-----------------------------------------------------------------------+
$search = array(
'mode' => 'AND',
'fields' => array()
);
// list of filters in user preferences
// allwords, cat, tags, author, added_by, filetypes, date_posted
$default_fields = array('allwords', 'cat', 'tags', 'author');
if (is_a_guest() or is_generic())
{
$fields = $default_fields;
}
else
{
$fields = userprefs_get_param('gallery_search_filters', $default_fields);
}
$words = array();
if (!empty($_GET['q']))
{
$words = split_allwords($_GET['q']);
}
if (count($words) > 0 or in_array('allwords', $fields))
{
$search['fields']['allwords'] = array(
'words' => $words,
'mode' => 'AND',
'fields' => array('file', 'name', 'comment', 'tags', 'author', 'cat-title', 'cat-desc'),
);
}
$cat_ids = array();
if (isset($_GET['cat_id']))
{
check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
$cat_ids = array($_GET['cat_id']);
}
if (count($cat_ids) > 0 or in_array('cat', $fields))
{
$search['fields']['cat'] = array(
'words' => $cat_ids,
'sub_inc' => true,
);
}
if (count(get_available_tags()) > 0)
{
$tag_ids = array();
if (isset($_GET['tag_id']))
{
check_input_parameter('tag_id', $_GET, false, '/^\d+(,\d+)*$/');
$tag_ids = explode(',', $_GET['tag_id']);
}
if (count($tag_ids) > 0 or in_array('tags', $fields))
{
$search['fields']['tags'] = array(
'words' => $tag_ids,
'mode' => 'AND',
);
}
}
if (in_array('author', $fields))
{
// does this Piwigo has authors for current user?
$query = '
SELECT
id
FROM '.IMAGES_TABLE.' AS i
JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
'.get_sql_condition_FandF(
array(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'id'
),
' WHERE '
).'
AND author IS NOT NULL
LIMIT 1
;';
$first_author = query2array($query);
if (count($first_author) > 0)
{
$search['fields']['author'] = array(
'words' => array(),
'mode' => 'OR',
);
}
}
foreach (array('added_by', 'filetypes', 'date_posted') as $field)
{
if (in_array($field, $fields))
{
$search['fields'][$field] = array();
}
}
list($search_uuid, $search_url) = save_search($search);
redirect($search_url);
?>