1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2008 Olivier Meunier and contributors |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | class dcTsearch |
---|
13 | { |
---|
14 | public static function corePostSearch(&$core,$p) |
---|
15 | { |
---|
16 | $words =& $p[0]; |
---|
17 | $sql =& $p[1]; |
---|
18 | $params =& $p[2]; |
---|
19 | |
---|
20 | # We need to format query string |
---|
21 | $search = self::formatQuery($words,$core); |
---|
22 | if (empty($search)) { |
---|
23 | return; |
---|
24 | } |
---|
25 | |
---|
26 | # That's tricky, one day we'll have a query builder ;) |
---|
27 | list($select,$from) = explode('FROM',$sql,2); |
---|
28 | list($from,$where) = explode('WHERE',$from,2); |
---|
29 | |
---|
30 | $from .= " INNER JOIN find_post('".$search."') F USING(post_id) "; |
---|
31 | |
---|
32 | $sql = $select.' FROM '.$from.' WHERE '.$where; |
---|
33 | |
---|
34 | # We must set $words to null to avoid regular search to continue |
---|
35 | $words = null; |
---|
36 | } |
---|
37 | |
---|
38 | public static function coreCommentSearch(&$core,$p) |
---|
39 | { |
---|
40 | $words =& $p[0]; |
---|
41 | $sql =& $p[1]; |
---|
42 | $params =& $p[2]; |
---|
43 | |
---|
44 | # We need to format query string |
---|
45 | $search = self::formatQuery($words,$core); |
---|
46 | if (empty($search)) { |
---|
47 | return; |
---|
48 | } |
---|
49 | |
---|
50 | # That's tricky, one day we'll have a query builder ;) |
---|
51 | list($select,$from) = explode('FROM',$sql,2); |
---|
52 | list($from,$where) = explode('WHERE',$from,2); |
---|
53 | |
---|
54 | $from .= " INNER JOIN find_comment('".$search."') F USING(comment_id) "; |
---|
55 | |
---|
56 | $sql = $select.' FROM '.$from.' WHERE '.$where; |
---|
57 | |
---|
58 | # We must set $words to null to avoid regular search to continue |
---|
59 | $words = null; |
---|
60 | } |
---|
61 | |
---|
62 | private static function formatQuery($s,&$core) |
---|
63 | { |
---|
64 | $s = implode(' ',$s); |
---|
65 | $s = preg_replace('/[&|!\\\]/',' ',$s); |
---|
66 | $s = preg_split('/\s+/',trim($s)); |
---|
67 | foreach ($s as &$q) { |
---|
68 | $q = $core->con->escape($q); |
---|
69 | } |
---|
70 | |
---|
71 | if (empty($s)) { |
---|
72 | return null; |
---|
73 | } |
---|
74 | |
---|
75 | return implode(' & ',$s); |
---|
76 | } |
---|
77 | } |
---|
78 | ?> |
---|