forked from Piwigo/Piwigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
96 lines (84 loc) · 2.63 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
<?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 |
// +-----------------------------------------------------------------------+
$words = array();
if (!empty($_GET['q']))
{
$words = split_allwords($_GET['q']);
}
$cat_ids = array();
if (isset($_GET['cat_id']))
{
check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
$cat_ids = array($_GET['cat_id']);
}
$search = array(
'mode' => 'AND',
'fields' => array(
'allwords' => array(
'words' => $words,
'mode' => 'AND',
'fields' => array('file', 'name', 'comment', 'tags', 'cat-title', 'cat-desc'),
),
'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']);
}
$search['fields']['tags'] = array(
'words' => $tag_ids,
'mode' => 'AND',
);
}
// 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',
);
}
save_search_and_redirect($search);
?>