@@ -10,17 +10,17 @@ |
||
10 | 10 | |
11 | 11 | $value = elgg_extract('value', $vars); |
12 | 12 | if (empty($value) && $value !== 0 && $value !== '0') { |
13 | - return; |
|
13 | + return; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | $href = elgg_extract('href', $vars); |
17 | 17 | $vars['rel'] = 'tag'; |
18 | 18 | |
19 | 19 | if ($href) { |
20 | - $vars['text'] = $value; |
|
21 | - $vars['encode_text'] = true; |
|
20 | + $vars['text'] = $value; |
|
21 | + $vars['encode_text'] = true; |
|
22 | 22 | |
23 | - echo elgg_view('output/url', $vars); |
|
23 | + echo elgg_view('output/url', $vars); |
|
24 | 24 | } else { |
25 | - echo elgg_view('output/text', $vars); |
|
25 | + echo elgg_view('output/text', $vars); |
|
26 | 26 | } |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | * Initialize search plugin |
11 | 11 | */ |
12 | 12 | function search_init() { |
13 | - require_once 'search_hooks.php'; |
|
13 | + require_once 'search_hooks.php'; |
|
14 | 14 | |
15 | - // page handler for search actions and results |
|
16 | - elgg_register_page_handler('search', 'search_page_handler'); |
|
15 | + // page handler for search actions and results |
|
16 | + elgg_register_page_handler('search', 'search_page_handler'); |
|
17 | 17 | |
18 | - // register some default search hooks |
|
19 | - elgg_register_plugin_hook_handler('search', 'object', 'search_objects_hook'); |
|
20 | - elgg_register_plugin_hook_handler('search', 'user', 'search_users_hook'); |
|
21 | - elgg_register_plugin_hook_handler('search', 'group', 'search_groups_hook'); |
|
18 | + // register some default search hooks |
|
19 | + elgg_register_plugin_hook_handler('search', 'object', 'search_objects_hook'); |
|
20 | + elgg_register_plugin_hook_handler('search', 'user', 'search_users_hook'); |
|
21 | + elgg_register_plugin_hook_handler('search', 'group', 'search_groups_hook'); |
|
22 | 22 | |
23 | - // tags and comments are a bit different. |
|
24 | - // register a search types and a hooks for them. |
|
25 | - elgg_register_plugin_hook_handler('search_types', 'get_types', 'search_custom_types_tags_hook'); |
|
26 | - elgg_register_plugin_hook_handler('search', 'tags', 'search_tags_hook'); |
|
23 | + // tags and comments are a bit different. |
|
24 | + // register a search types and a hooks for them. |
|
25 | + elgg_register_plugin_hook_handler('search_types', 'get_types', 'search_custom_types_tags_hook'); |
|
26 | + elgg_register_plugin_hook_handler('search', 'tags', 'search_tags_hook'); |
|
27 | 27 | |
28 | - // add in CSS for search elements |
|
29 | - elgg_extend_view('elgg.css', 'search/css'); |
|
28 | + // add in CSS for search elements |
|
29 | + elgg_extend_view('elgg.css', 'search/css'); |
|
30 | 30 | |
31 | - // extend view for elgg topbar search box |
|
32 | - elgg_extend_view('page/elements/sidebar', 'search/header', 0); |
|
31 | + // extend view for elgg topbar search box |
|
32 | + elgg_extend_view('page/elements/sidebar', 'search/header', 0); |
|
33 | 33 | |
34 | - elgg_register_plugin_hook_handler('robots.txt', 'site', 'search_exclude_robots'); |
|
34 | + elgg_register_plugin_hook_handler('robots.txt', 'site', 'search_exclude_robots'); |
|
35 | 35 | |
36 | - elgg_register_plugin_hook_handler('view_vars', 'output/tag', 'search_output_tag'); |
|
36 | + elgg_register_plugin_hook_handler('view_vars', 'output/tag', 'search_output_tag'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function search_page_handler($page) { |
46 | 46 | |
47 | - // if there is no q set, we're being called from a legacy installation |
|
48 | - // it expects a search by tags. |
|
49 | - // actually it doesn't, but maybe it should. |
|
50 | - // maintain backward compatibility |
|
51 | - if (!get_input('q', get_input('tag', null))) { |
|
52 | - set_input('q', $page[0]); |
|
53 | - //set_input('search_type', 'tags'); |
|
54 | - } |
|
55 | - |
|
56 | - echo elgg_view_resource('search/index'); |
|
57 | - return true; |
|
47 | + // if there is no q set, we're being called from a legacy installation |
|
48 | + // it expects a search by tags. |
|
49 | + // actually it doesn't, but maybe it should. |
|
50 | + // maintain backward compatibility |
|
51 | + if (!get_input('q', get_input('tag', null))) { |
|
52 | + set_input('q', $page[0]); |
|
53 | + //set_input('search_type', 'tags'); |
|
54 | + } |
|
55 | + |
|
56 | + echo elgg_view_resource('search/index'); |
|
57 | + return true; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -70,116 +70,116 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300, $tag_match = false) { |
72 | 72 | |
73 | - $haystack = strip_tags($haystack); |
|
74 | - $haystack_length = elgg_strlen($haystack); |
|
75 | - $haystack_lc = elgg_strtolower($haystack); |
|
76 | - |
|
77 | - if (!$tag_match) { |
|
78 | - $words = search_remove_ignored_words($query, 'array'); |
|
79 | - } else { |
|
80 | - $words = []; |
|
81 | - } |
|
82 | - |
|
83 | - // if haystack < $max_length return the entire haystack w/formatting immediately |
|
84 | - if ($haystack_length <= $max_length) { |
|
85 | - $return = search_highlight_words($words, $haystack); |
|
86 | - |
|
87 | - return $return; |
|
88 | - } |
|
89 | - |
|
90 | - // get the starting positions and lengths for all matching words |
|
91 | - $starts = []; |
|
92 | - $lengths = []; |
|
93 | - foreach ($words as $word) { |
|
94 | - $word = elgg_strtolower($word); |
|
95 | - $count = elgg_substr_count($haystack_lc, $word); |
|
96 | - $word_len = elgg_strlen($word); |
|
97 | - $haystack_len = elgg_strlen($haystack_lc); |
|
98 | - |
|
99 | - // find the start positions for the words |
|
100 | - if ($count > 1) { |
|
101 | - $offset = 0; |
|
102 | - while (false !== $pos = elgg_strpos($haystack_lc, $word, $offset)) { |
|
103 | - $start = ($pos - $min_match_context > 0) ? $pos - $min_match_context : 0; |
|
104 | - $starts[] = $start; |
|
105 | - $stop = $pos + $word_len + $min_match_context; |
|
106 | - $lengths[] = $stop - $start; |
|
107 | - $offset += $pos + $word_len; |
|
108 | - |
|
109 | - if ($offset >= $haystack_len) { |
|
110 | - break; |
|
111 | - } |
|
112 | - } |
|
113 | - } else { |
|
114 | - $pos = elgg_strpos($haystack_lc, $word); |
|
115 | - $start = ($pos - $min_match_context > 0) ? $pos - $min_match_context : 0; |
|
116 | - $starts[] = $start; |
|
117 | - $stop = $pos + $word_len + $min_match_context; |
|
118 | - $lengths[] = $stop - $start; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - $offsets = search_consolidate_substrings($starts, $lengths); |
|
123 | - |
|
124 | - // figure out if we can adjust the offsets and lengths |
|
125 | - // in order to return more context |
|
126 | - $total_length = array_sum($offsets); |
|
127 | - |
|
128 | - $add_length = 0; |
|
129 | - if ($total_length < $max_length && $offsets) { |
|
130 | - $add_length = floor((($max_length - $total_length) / count($offsets)) / 2); |
|
131 | - |
|
132 | - $starts = []; |
|
133 | - $lengths = []; |
|
134 | - foreach ($offsets as $offset => $length) { |
|
135 | - $start = ($offset - $add_length > 0) ? $offset - $add_length : 0; |
|
136 | - $length = $length + $add_length; |
|
137 | - $starts[] = $start; |
|
138 | - $lengths[] = $length; |
|
139 | - } |
|
140 | - |
|
141 | - $offsets = search_consolidate_substrings($starts, $lengths); |
|
142 | - } |
|
143 | - |
|
144 | - // sort by order of string size descending (which is roughly |
|
145 | - // the proximity of matched terms) so we can keep the |
|
146 | - // substrings with terms closest together and discard |
|
147 | - // the others as needed to fit within $max_length. |
|
148 | - arsort($offsets); |
|
149 | - |
|
150 | - $return_strs = []; |
|
151 | - $total_length = 0; |
|
152 | - foreach ($offsets as $start => $length) { |
|
153 | - $string = trim(elgg_substr($haystack, $start, $length)); |
|
154 | - |
|
155 | - // continue past if adding this substring exceeds max length |
|
156 | - if ($total_length + $length > $max_length) { |
|
157 | - continue; |
|
158 | - } |
|
159 | - |
|
160 | - $total_length += $length; |
|
161 | - $return_strs[$start] = $string; |
|
162 | - } |
|
163 | - |
|
164 | - // put the strings in order of occurence |
|
165 | - ksort($return_strs); |
|
166 | - |
|
167 | - // add ...s where needed |
|
168 | - $return = implode('...', $return_strs); |
|
169 | - if (!array_key_exists(0, $return_strs)) { |
|
170 | - $return = "...$return"; |
|
171 | - } |
|
172 | - |
|
173 | - // add to end of string if last substring doesn't hit the end. |
|
174 | - $starts = array_keys($return_strs); |
|
175 | - $last_pos = $starts[count($starts)-1]; |
|
176 | - if ($last_pos + elgg_strlen($return_strs[$last_pos]) < $haystack_length) { |
|
177 | - $return .= '...'; |
|
178 | - } |
|
179 | - |
|
180 | - $return = search_highlight_words($words, $return); |
|
181 | - |
|
182 | - return $return; |
|
73 | + $haystack = strip_tags($haystack); |
|
74 | + $haystack_length = elgg_strlen($haystack); |
|
75 | + $haystack_lc = elgg_strtolower($haystack); |
|
76 | + |
|
77 | + if (!$tag_match) { |
|
78 | + $words = search_remove_ignored_words($query, 'array'); |
|
79 | + } else { |
|
80 | + $words = []; |
|
81 | + } |
|
82 | + |
|
83 | + // if haystack < $max_length return the entire haystack w/formatting immediately |
|
84 | + if ($haystack_length <= $max_length) { |
|
85 | + $return = search_highlight_words($words, $haystack); |
|
86 | + |
|
87 | + return $return; |
|
88 | + } |
|
89 | + |
|
90 | + // get the starting positions and lengths for all matching words |
|
91 | + $starts = []; |
|
92 | + $lengths = []; |
|
93 | + foreach ($words as $word) { |
|
94 | + $word = elgg_strtolower($word); |
|
95 | + $count = elgg_substr_count($haystack_lc, $word); |
|
96 | + $word_len = elgg_strlen($word); |
|
97 | + $haystack_len = elgg_strlen($haystack_lc); |
|
98 | + |
|
99 | + // find the start positions for the words |
|
100 | + if ($count > 1) { |
|
101 | + $offset = 0; |
|
102 | + while (false !== $pos = elgg_strpos($haystack_lc, $word, $offset)) { |
|
103 | + $start = ($pos - $min_match_context > 0) ? $pos - $min_match_context : 0; |
|
104 | + $starts[] = $start; |
|
105 | + $stop = $pos + $word_len + $min_match_context; |
|
106 | + $lengths[] = $stop - $start; |
|
107 | + $offset += $pos + $word_len; |
|
108 | + |
|
109 | + if ($offset >= $haystack_len) { |
|
110 | + break; |
|
111 | + } |
|
112 | + } |
|
113 | + } else { |
|
114 | + $pos = elgg_strpos($haystack_lc, $word); |
|
115 | + $start = ($pos - $min_match_context > 0) ? $pos - $min_match_context : 0; |
|
116 | + $starts[] = $start; |
|
117 | + $stop = $pos + $word_len + $min_match_context; |
|
118 | + $lengths[] = $stop - $start; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + $offsets = search_consolidate_substrings($starts, $lengths); |
|
123 | + |
|
124 | + // figure out if we can adjust the offsets and lengths |
|
125 | + // in order to return more context |
|
126 | + $total_length = array_sum($offsets); |
|
127 | + |
|
128 | + $add_length = 0; |
|
129 | + if ($total_length < $max_length && $offsets) { |
|
130 | + $add_length = floor((($max_length - $total_length) / count($offsets)) / 2); |
|
131 | + |
|
132 | + $starts = []; |
|
133 | + $lengths = []; |
|
134 | + foreach ($offsets as $offset => $length) { |
|
135 | + $start = ($offset - $add_length > 0) ? $offset - $add_length : 0; |
|
136 | + $length = $length + $add_length; |
|
137 | + $starts[] = $start; |
|
138 | + $lengths[] = $length; |
|
139 | + } |
|
140 | + |
|
141 | + $offsets = search_consolidate_substrings($starts, $lengths); |
|
142 | + } |
|
143 | + |
|
144 | + // sort by order of string size descending (which is roughly |
|
145 | + // the proximity of matched terms) so we can keep the |
|
146 | + // substrings with terms closest together and discard |
|
147 | + // the others as needed to fit within $max_length. |
|
148 | + arsort($offsets); |
|
149 | + |
|
150 | + $return_strs = []; |
|
151 | + $total_length = 0; |
|
152 | + foreach ($offsets as $start => $length) { |
|
153 | + $string = trim(elgg_substr($haystack, $start, $length)); |
|
154 | + |
|
155 | + // continue past if adding this substring exceeds max length |
|
156 | + if ($total_length + $length > $max_length) { |
|
157 | + continue; |
|
158 | + } |
|
159 | + |
|
160 | + $total_length += $length; |
|
161 | + $return_strs[$start] = $string; |
|
162 | + } |
|
163 | + |
|
164 | + // put the strings in order of occurence |
|
165 | + ksort($return_strs); |
|
166 | + |
|
167 | + // add ...s where needed |
|
168 | + $return = implode('...', $return_strs); |
|
169 | + if (!array_key_exists(0, $return_strs)) { |
|
170 | + $return = "...$return"; |
|
171 | + } |
|
172 | + |
|
173 | + // add to end of string if last substring doesn't hit the end. |
|
174 | + $starts = array_keys($return_strs); |
|
175 | + $last_pos = $starts[count($starts)-1]; |
|
176 | + if ($last_pos + elgg_strlen($return_strs[$last_pos]) < $haystack_length) { |
|
177 | + $return .= '...'; |
|
178 | + } |
|
179 | + |
|
180 | + $return = search_highlight_words($words, $return); |
|
181 | + |
|
182 | + return $return; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -195,42 +195,42 @@ discard block |
||
195 | 195 | * @return array |
196 | 196 | */ |
197 | 197 | function search_consolidate_substrings($offsets, $lengths) { |
198 | - // sort offsets by occurence |
|
199 | - asort($offsets, SORT_NUMERIC); |
|
200 | - |
|
201 | - // reset the indexes maintaining association with the original offsets. |
|
202 | - $offsets = array_merge($offsets); |
|
203 | - |
|
204 | - $new_lengths = []; |
|
205 | - foreach ($offsets as $i => $offset) { |
|
206 | - $new_lengths[] = $lengths[$i]; |
|
207 | - } |
|
208 | - |
|
209 | - $lengths = $new_lengths; |
|
210 | - |
|
211 | - $return = []; |
|
212 | - $count = count($offsets); |
|
213 | - for ($i=0; $i<$count; $i++) { |
|
214 | - $offset = $offsets[$i]; |
|
215 | - $length = $lengths[$i]; |
|
216 | - $end_pos = $offset + $length; |
|
217 | - |
|
218 | - // find the next entry that doesn't overlap |
|
219 | - while (array_key_exists($i+1, $offsets) && $end_pos > $offsets[$i+1]) { |
|
220 | - $i++; |
|
221 | - if (!array_key_exists($i, $offsets)) { |
|
222 | - break; |
|
223 | - } |
|
224 | - $end_pos = $lengths[$i] + $offsets[$i]; |
|
225 | - } |
|
226 | - |
|
227 | - $length = $end_pos - $offset; |
|
228 | - |
|
229 | - // will never have a colliding offset, so can return as a single array |
|
230 | - $return[$offset] = $length; |
|
231 | - } |
|
232 | - |
|
233 | - return $return; |
|
198 | + // sort offsets by occurence |
|
199 | + asort($offsets, SORT_NUMERIC); |
|
200 | + |
|
201 | + // reset the indexes maintaining association with the original offsets. |
|
202 | + $offsets = array_merge($offsets); |
|
203 | + |
|
204 | + $new_lengths = []; |
|
205 | + foreach ($offsets as $i => $offset) { |
|
206 | + $new_lengths[] = $lengths[$i]; |
|
207 | + } |
|
208 | + |
|
209 | + $lengths = $new_lengths; |
|
210 | + |
|
211 | + $return = []; |
|
212 | + $count = count($offsets); |
|
213 | + for ($i=0; $i<$count; $i++) { |
|
214 | + $offset = $offsets[$i]; |
|
215 | + $length = $lengths[$i]; |
|
216 | + $end_pos = $offset + $length; |
|
217 | + |
|
218 | + // find the next entry that doesn't overlap |
|
219 | + while (array_key_exists($i+1, $offsets) && $end_pos > $offsets[$i+1]) { |
|
220 | + $i++; |
|
221 | + if (!array_key_exists($i, $offsets)) { |
|
222 | + break; |
|
223 | + } |
|
224 | + $end_pos = $lengths[$i] + $offsets[$i]; |
|
225 | + } |
|
226 | + |
|
227 | + $length = $end_pos - $offset; |
|
228 | + |
|
229 | + // will never have a colliding offset, so can return as a single array |
|
230 | + $return[$offset] = $length; |
|
231 | + } |
|
232 | + |
|
233 | + return $return; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -241,43 +241,43 @@ discard block |
||
241 | 241 | * @return string |
242 | 242 | */ |
243 | 243 | function search_highlight_words($words, $string) { |
244 | - $i = 1; |
|
245 | - $replace_html = [ |
|
246 | - 'strong' => rand(10000, 99999), |
|
247 | - 'class' => rand(10000, 99999), |
|
248 | - 'search-highlight' => rand(10000, 99999), |
|
249 | - 'search-highlight-color' => rand(10000, 99999) |
|
250 | - ]; |
|
251 | - |
|
252 | - foreach ($words as $word) { |
|
253 | - // remove any boolean mode operators |
|
254 | - $word = preg_replace("/([\-\+~])([\w]+)/i", '$2', $word); |
|
244 | + $i = 1; |
|
245 | + $replace_html = [ |
|
246 | + 'strong' => rand(10000, 99999), |
|
247 | + 'class' => rand(10000, 99999), |
|
248 | + 'search-highlight' => rand(10000, 99999), |
|
249 | + 'search-highlight-color' => rand(10000, 99999) |
|
250 | + ]; |
|
251 | + |
|
252 | + foreach ($words as $word) { |
|
253 | + // remove any boolean mode operators |
|
254 | + $word = preg_replace("/([\-\+~])([\w]+)/i", '$2', $word); |
|
255 | 255 | |
256 | - // escape the delimiter and any other regexp special chars |
|
257 | - $word = preg_quote($word, '/'); |
|
256 | + // escape the delimiter and any other regexp special chars |
|
257 | + $word = preg_quote($word, '/'); |
|
258 | 258 | |
259 | - $search = "/($word)/i"; |
|
260 | - |
|
261 | - // @todo |
|
262 | - // must replace with placeholders in case one of the search terms is |
|
263 | - // in the html string. |
|
264 | - // later, will replace the placeholders with the actual html. |
|
265 | - // Yeah this is hacky. I'm tired. |
|
266 | - $strong = $replace_html['strong']; |
|
267 | - $class = $replace_html['class']; |
|
268 | - $highlight = $replace_html['search-highlight']; |
|
269 | - $color = $replace_html['search-highlight-color']; |
|
270 | - |
|
271 | - $replace = "<$strong $class=\"$highlight $color{$i}\">$1</$strong>"; |
|
272 | - $string = preg_replace($search, $replace, $string); |
|
273 | - $i++; |
|
274 | - } |
|
275 | - |
|
276 | - foreach ($replace_html as $replace => $search) { |
|
277 | - $string = str_replace($search, $replace, $string); |
|
278 | - } |
|
279 | - |
|
280 | - return $string; |
|
259 | + $search = "/($word)/i"; |
|
260 | + |
|
261 | + // @todo |
|
262 | + // must replace with placeholders in case one of the search terms is |
|
263 | + // in the html string. |
|
264 | + // later, will replace the placeholders with the actual html. |
|
265 | + // Yeah this is hacky. I'm tired. |
|
266 | + $strong = $replace_html['strong']; |
|
267 | + $class = $replace_html['class']; |
|
268 | + $highlight = $replace_html['search-highlight']; |
|
269 | + $color = $replace_html['search-highlight-color']; |
|
270 | + |
|
271 | + $replace = "<$strong $class=\"$highlight $color{$i}\">$1</$strong>"; |
|
272 | + $string = preg_replace($search, $replace, $string); |
|
273 | + $i++; |
|
274 | + } |
|
275 | + |
|
276 | + foreach ($replace_html as $replace => $search) { |
|
277 | + $string = str_replace($search, $replace, $string); |
|
278 | + } |
|
279 | + |
|
280 | + return $string; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | */ |
292 | 292 | function search_remove_ignored_words($query, $format = 'array') { |
293 | 293 | |
294 | - // don't worry about "s or boolean operators |
|
295 | - //$query = str_replace(array('"', '-', '+', '~'), '', stripslashes(strip_tags($query))); |
|
296 | - $query = stripslashes(strip_tags($query)); |
|
297 | - $query = trim($query); |
|
294 | + // don't worry about "s or boolean operators |
|
295 | + //$query = str_replace(array('"', '-', '+', '~'), '', stripslashes(strip_tags($query))); |
|
296 | + $query = stripslashes(strip_tags($query)); |
|
297 | + $query = trim($query); |
|
298 | 298 | |
299 | - $words = preg_split('/\s+/', $query); |
|
299 | + $words = preg_split('/\s+/', $query); |
|
300 | 300 | |
301 | - if ($format == 'string') { |
|
302 | - return implode(' ', $words); |
|
303 | - } |
|
301 | + if ($format == 'string') { |
|
302 | + return implode(' ', $words); |
|
303 | + } |
|
304 | 304 | |
305 | - return $words; |
|
305 | + return $words; |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -315,43 +315,43 @@ discard block |
||
315 | 315 | * @return string |
316 | 316 | */ |
317 | 317 | function search_get_search_view($params, $view_type) { |
318 | - switch ($view_type) { |
|
319 | - case 'list': |
|
320 | - case 'entity': |
|
321 | - case 'layout': |
|
322 | - break; |
|
323 | - |
|
324 | - default: |
|
325 | - return false; |
|
326 | - } |
|
327 | - |
|
328 | - $view_order = []; |
|
329 | - |
|
330 | - // check if there's a special search list view for this type:subtype |
|
331 | - if (isset($params['type']) && $params['type'] && isset($params['subtype']) && $params['subtype']) { |
|
332 | - $view_order[] = "search/{$params['type']}/{$params['subtype']}/$view_type"; |
|
333 | - } |
|
334 | - |
|
335 | - // also check for the default type |
|
336 | - if (isset($params['type']) && $params['type']) { |
|
337 | - $view_order[] = "search/{$params['type']}/$view_type"; |
|
338 | - } |
|
339 | - |
|
340 | - // check search types |
|
341 | - if (isset($params['search_type']) && $params['search_type']) { |
|
342 | - $view_order[] = "search/{$params['search_type']}/$view_type"; |
|
343 | - } |
|
344 | - |
|
345 | - // finally default to a search list default |
|
346 | - $view_order[] = "search/$view_type"; |
|
347 | - |
|
348 | - foreach ($view_order as $view) { |
|
349 | - if (elgg_view_exists($view)) { |
|
350 | - return $view; |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - return false; |
|
318 | + switch ($view_type) { |
|
319 | + case 'list': |
|
320 | + case 'entity': |
|
321 | + case 'layout': |
|
322 | + break; |
|
323 | + |
|
324 | + default: |
|
325 | + return false; |
|
326 | + } |
|
327 | + |
|
328 | + $view_order = []; |
|
329 | + |
|
330 | + // check if there's a special search list view for this type:subtype |
|
331 | + if (isset($params['type']) && $params['type'] && isset($params['subtype']) && $params['subtype']) { |
|
332 | + $view_order[] = "search/{$params['type']}/{$params['subtype']}/$view_type"; |
|
333 | + } |
|
334 | + |
|
335 | + // also check for the default type |
|
336 | + if (isset($params['type']) && $params['type']) { |
|
337 | + $view_order[] = "search/{$params['type']}/$view_type"; |
|
338 | + } |
|
339 | + |
|
340 | + // check search types |
|
341 | + if (isset($params['search_type']) && $params['search_type']) { |
|
342 | + $view_order[] = "search/{$params['search_type']}/$view_type"; |
|
343 | + } |
|
344 | + |
|
345 | + // finally default to a search list default |
|
346 | + $view_order[] = "search/$view_type"; |
|
347 | + |
|
348 | + foreach ($view_order as $view) { |
|
349 | + if (elgg_view_exists($view)) { |
|
350 | + return $view; |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + return false; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -363,31 +363,31 @@ discard block |
||
363 | 363 | * @return str |
364 | 364 | */ |
365 | 365 | function search_get_where_sql($table, $fields, $params) { |
366 | - $query = $params['query']; |
|
367 | - |
|
368 | - // add the table prefix to the fields |
|
369 | - foreach ($fields as $i => $field) { |
|
370 | - if ($table) { |
|
371 | - $fields[$i] = "$table.$field"; |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - $likes = []; |
|
376 | - $query_parts = explode(' ', $query); |
|
377 | - foreach ($fields as $field) { |
|
378 | - $sublikes = []; |
|
379 | - foreach ($query_parts as $query_part) { |
|
380 | - $query_part = sanitise_string($query_part); |
|
381 | - if (strlen($query_part) == 0) { |
|
382 | - continue; |
|
383 | - } |
|
384 | - $sublikes[] = "$field LIKE '%$query_part%'"; |
|
385 | - } |
|
386 | - $likes[] = '(' . implode(' AND ', $sublikes) . ')'; |
|
387 | - } |
|
388 | - |
|
389 | - $likes_str = implode(' OR ', $likes); |
|
390 | - return "($likes_str)"; |
|
366 | + $query = $params['query']; |
|
367 | + |
|
368 | + // add the table prefix to the fields |
|
369 | + foreach ($fields as $i => $field) { |
|
370 | + if ($table) { |
|
371 | + $fields[$i] = "$table.$field"; |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + $likes = []; |
|
376 | + $query_parts = explode(' ', $query); |
|
377 | + foreach ($fields as $field) { |
|
378 | + $sublikes = []; |
|
379 | + foreach ($query_parts as $query_part) { |
|
380 | + $query_part = sanitise_string($query_part); |
|
381 | + if (strlen($query_part) == 0) { |
|
382 | + continue; |
|
383 | + } |
|
384 | + $sublikes[] = "$field LIKE '%$query_part%'"; |
|
385 | + } |
|
386 | + $likes[] = '(' . implode(' AND ', $sublikes) . ')'; |
|
387 | + } |
|
388 | + |
|
389 | + $likes_str = implode(' OR ', $likes); |
|
390 | + return "($likes_str)"; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | |
@@ -402,43 +402,43 @@ discard block |
||
402 | 402 | */ |
403 | 403 | function search_get_order_by_sql($entities_table, $type_table, $sort, $order) { |
404 | 404 | |
405 | - $on = null; |
|
406 | - |
|
407 | - switch ($sort) { |
|
408 | - default: |
|
409 | - case 'relevance': |
|
410 | - // default is relevance descending. |
|
411 | - // ascending relevancy is silly and complicated. |
|
412 | - $on = ''; |
|
413 | - break; |
|
414 | - case 'created': |
|
415 | - $on = "$entities_table.time_created"; |
|
416 | - break; |
|
417 | - case 'updated': |
|
418 | - $on = "$entities_table.time_updated"; |
|
419 | - break; |
|
420 | - case 'action_on': |
|
421 | - // @todo not supported yet in core |
|
422 | - $on = ''; |
|
423 | - break; |
|
424 | - case 'alpha': |
|
425 | - // @todo not support yet because both title |
|
426 | - // and name columns are used for this depending |
|
427 | - // on the entity, which we don't always know. >:O |
|
428 | - break; |
|
429 | - } |
|
430 | - $order = strtolower($order); |
|
431 | - if ($order != 'asc' && $order != 'desc') { |
|
432 | - $order = 'DESC'; |
|
433 | - } |
|
434 | - |
|
435 | - if ($on) { |
|
436 | - $order_by = "$on $order"; |
|
437 | - } else { |
|
438 | - $order_by = ''; |
|
439 | - } |
|
440 | - |
|
441 | - return $order_by; |
|
405 | + $on = null; |
|
406 | + |
|
407 | + switch ($sort) { |
|
408 | + default: |
|
409 | + case 'relevance': |
|
410 | + // default is relevance descending. |
|
411 | + // ascending relevancy is silly and complicated. |
|
412 | + $on = ''; |
|
413 | + break; |
|
414 | + case 'created': |
|
415 | + $on = "$entities_table.time_created"; |
|
416 | + break; |
|
417 | + case 'updated': |
|
418 | + $on = "$entities_table.time_updated"; |
|
419 | + break; |
|
420 | + case 'action_on': |
|
421 | + // @todo not supported yet in core |
|
422 | + $on = ''; |
|
423 | + break; |
|
424 | + case 'alpha': |
|
425 | + // @todo not support yet because both title |
|
426 | + // and name columns are used for this depending |
|
427 | + // on the entity, which we don't always know. >:O |
|
428 | + break; |
|
429 | + } |
|
430 | + $order = strtolower($order); |
|
431 | + if ($order != 'asc' && $order != 'desc') { |
|
432 | + $order = 'DESC'; |
|
433 | + } |
|
434 | + |
|
435 | + if ($on) { |
|
436 | + $order_by = "$on $order"; |
|
437 | + } else { |
|
438 | + $order_by = ''; |
|
439 | + } |
|
440 | + |
|
441 | + return $order_by; |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | /** |
@@ -453,13 +453,13 @@ discard block |
||
453 | 453 | * @return string |
454 | 454 | */ |
455 | 455 | function search_exclude_robots($hook, $type, $text) { |
456 | - $text .= <<<TEXT |
|
456 | + $text .= <<<TEXT |
|
457 | 457 | User-agent: * |
458 | 458 | Disallow: /search/ |
459 | 459 | |
460 | 460 | TEXT; |
461 | 461 | |
462 | - return $text; |
|
462 | + return $text; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -469,26 +469,26 @@ discard block |
||
469 | 469 | * @return array |
470 | 470 | */ |
471 | 471 | function search_output_tag(\Elgg\Hook $hook) { |
472 | - $vars = $hook->getValue(); |
|
473 | - if (isset($vars['href'])) { |
|
474 | - // leave unaltered |
|
475 | - return; |
|
476 | - } |
|
472 | + $vars = $hook->getValue(); |
|
473 | + if (isset($vars['href'])) { |
|
474 | + // leave unaltered |
|
475 | + return; |
|
476 | + } |
|
477 | 477 | |
478 | - $query_params = [ |
|
479 | - 'q' => elgg_extract('value', $vars), |
|
480 | - 'search_type' => 'tags', |
|
481 | - 'type' => elgg_extract('type', $vars, null, false), |
|
482 | - 'subtype' => elgg_extract('subtype', $vars, null, false), |
|
483 | - ]; |
|
478 | + $query_params = [ |
|
479 | + 'q' => elgg_extract('value', $vars), |
|
480 | + 'search_type' => 'tags', |
|
481 | + 'type' => elgg_extract('type', $vars, null, false), |
|
482 | + 'subtype' => elgg_extract('subtype', $vars, null, false), |
|
483 | + ]; |
|
484 | 484 | |
485 | - $url = elgg_extract('base_url', $vars, 'search'); |
|
485 | + $url = elgg_extract('base_url', $vars, 'search'); |
|
486 | 486 | |
487 | - unset($vars['base_url']); |
|
488 | - unset($vars['type']); |
|
489 | - unset($vars['subtype']); |
|
487 | + unset($vars['base_url']); |
|
488 | + unset($vars['type']); |
|
489 | + unset($vars['subtype']); |
|
490 | 490 | |
491 | - $vars['href'] = elgg_http_add_url_query_elements($url, $query_params); |
|
491 | + $vars['href'] = elgg_http_add_url_query_elements($url, $query_params); |
|
492 | 492 | |
493 | - return $vars; |
|
493 | + return $vars; |
|
494 | 494 | } |