Rev 1293 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1293 | Rev 1311 | ||
---|---|---|---|
Line 65... | Line 65... | ||
65 | * @param string $html |
65 | * @param string $html |
66 | * @param string $term |
66 | * @param string $term |
67 | * @return string |
67 | * @return string |
68 | */ |
68 | */ |
69 | private function highlight_match(string $html, string $term): string { |
69 | private function highlight_match(string $html, string $term): string { |
70 | return str_replace(htmlentities($term), '<font color="red">'.htmlentities($term).'</font>', $html); |
70 | //return str_replace(htmlentities($term), '<font color="red">'.htmlentities($term).'</font>', $html); |
- | 71 | // Case insensitive: |
|
- | 72 | return preg_replace('@('.preg_quote(htmlentities($term),'@').')@i', '<font color="red">\\1</font>', $html); |
|
71 | } |
73 | } |
72 | 74 | ||
73 | /** |
75 | /** |
74 | * @param array $params |
76 | * @param array $params |
75 | * @return string |
77 | * @return string |
Line 87... | Line 89... | ||
87 | if (strlen($params['term']) == 0) { |
89 | if (strlen($params['term']) == 0) { |
88 | $output .= '<p><font color="red">'._L('Error: You must enter a search term.').'</font></p>'; |
90 | $output .= '<p><font color="red">'._L('Error: You must enter a search term.').'</font></p>'; |
89 | } else if (strlen($params['term']) < $min_length) { |
91 | } else if (strlen($params['term']) < $min_length) { |
90 | $output .= '<p><font color="red">'._L('Error: Search term minimum length is %1 characters.',$min_length).'</font></p>'; |
92 | $output .= '<p><font color="red">'._L('Error: Search term minimum length is %1 characters.',$min_length).'</font></p>'; |
91 | } else { |
93 | } else { |
92 | // TODO: case insensitive comparison (or should we leave that to the DBMS?) |
- | |
93 | - | ||
94 | if ($params['namespace'] == 'oidplus:ra') { |
94 | if ($params['namespace'] == 'oidplus:ra') { |
95 | $output .= '<h2>'._L('Search results for RA %1','<font color="red">'.htmlentities($params['term']).'</font>').'</h2>'; |
95 | $output .= '<h2>'._L('Search results for RA %1','<font color="red">'.htmlentities($params['term']).'</font>').'</h2>'; |
96 | 96 | ||
97 | $sql_where = array(); $prep_where = array(); |
97 | $sql_where = array(); $prep_where = array(); |
- | 98 | ||
98 | $sql_where[] = "email like ?"; $prep_where[] = '%'.$params['term'].'%'; |
99 | $sql_where[] = OIDplus::db()->getSlang()->lowerCase('email')." like ?"; $prep_where[] = '%'.$params['term'].'%'; |
99 | $sql_where[] = "ra_name like ?"; $prep_where[] = '%'.$params['term'].'%'; |
100 | $sql_where[] = OIDplus::db()->getSlang()->lowerCase('ra_name')." like ?"; $prep_where[] = '%'.$params['term'].'%'; |
100 | 101 | ||
101 | if (count($sql_where) == 0) $sql_where[] = '1=0'; |
102 | if (count($sql_where) == 0) $sql_where[] = '1=0'; |
102 | $res = OIDplus::db()->query("select * from ###ra where (".implode(' or ', $sql_where).")", $prep_where); |
103 | $res = OIDplus::db()->query("select * from ###ra where (".implode(' or ', $sql_where).")", $prep_where); |
103 | 104 | ||
104 | $count = 0; |
105 | $count = 0; |
Line 112... | Line 113... | ||
112 | } |
113 | } |
113 | } else { |
114 | } else { |
114 | $output .= '<h2>'._L('Search results for %1 (%2)','<font color="red">'.htmlentities($params['term']).'</font>',htmlentities($params['namespace'])).'</h2>'; |
115 | $output .= '<h2>'._L('Search results for %1 (%2)','<font color="red">'.htmlentities($params['term']).'</font>',htmlentities($params['namespace'])).'</h2>'; |
115 | 116 | ||
116 | $sql_where = array(); $prep_where = array(); |
117 | $sql_where = array(); $prep_where = array(); |
117 | $sql_where[] = "id like ?"; $prep_where[] = '%'.$params['term'].'%'; // TODO: should we rather do findFitting(), so we can e.g. find GUIDs with different notation? |
118 | $sql_where[] = OIDplus::db()->getSlang()->lowerCase('id')." like ?"; $prep_where[] = '%'.$params['term'].'%'; // TODO: should we rather do findFitting(), so we can e.g. find GUIDs with different notation? |
118 | if ($params["search_title"]) { $sql_where[] = "title like ?"; $prep_where[] = '%'.$params['term'].'%'; } |
119 | if ($params["search_title"]) { $sql_where[] = OIDplus::db()->getSlang()->lowerCase('title')." like ?"; $prep_where[] = '%'.$params['term'].'%'; } |
119 | if ($params["search_description"]) { $sql_where[] = "description like ?"; $prep_where[] = '%'.$params['term'].'%'; } |
120 | if ($params["search_description"]) { $sql_where[] = OIDplus::db()->getSlang()->lowerCase('description')." like ?"; $prep_where[] = '%'.$params['term'].'%'; } |
120 | 121 | ||
121 | if ($params["search_asn1id"]) { |
122 | if ($params["search_asn1id"]) { |
122 | $res = OIDplus::db()->query("select * from ###asn1id where name like ?", array('%'.$params['term'].'%')); |
123 | $res = OIDplus::db()->query("select * from ###asn1id where ".OIDplus::db()->getSlang()->lowerCase('name')." like ?", array('%'.$params['term'].'%')); |
123 | while ($row = $res->fetch_object()) { |
124 | while ($row = $res->fetch_object()) { |
124 | $sql_where[] = "id = ?"; $prep_where[] = $row->oid; |
125 | $sql_where[] = "id = ?"; $prep_where[] = $row->oid; |
125 | } |
126 | } |
126 | } |
127 | } |
127 | 128 | ||
128 | if ($params["search_iri"]) { |
129 | if ($params["search_iri"]) { |
129 | $res = OIDplus::db()->query("select * from ###iri where name like ?", array('%'.$params['term'].'%')); |
130 | $res = OIDplus::db()->query("select * from ###iri where ".OIDplus::db()->getSlang()->lowerCase('name')." like ?", array('%'.$params['term'].'%')); |
130 | while ($row = $res->fetch_object()) { |
131 | while ($row = $res->fetch_object()) { |
131 | $sql_where[] = "id = ?"; $prep_where[] = $row->oid; |
132 | $sql_where[] = "id = ?"; $prep_where[] = $row->oid; |
132 | } |
133 | } |
133 | } |
134 | } |
134 | 135 | ||
135 | if (count($sql_where) == 0) $sql_where[] = '1=0'; |
136 | if (count($sql_where) == 0) $sql_where[] = '1=0'; |
136 | array_unshift($prep_where, $params['namespace'].':%'); |
137 | array_unshift($prep_where, $params['namespace'].':%'); |
137 | 138 | ||
138 | $res = OIDplus::db()->query("select * from ###objects where id like ? and (".implode(' or ', $sql_where).")", $prep_where); |
139 | $res = OIDplus::db()->query("select * from ###objects where ".OIDplus::db()->getSlang()->lowerCase('id')." like ? and (".implode(' or ', $sql_where).")", $prep_where); |
139 | 140 | ||
140 | $count = 0; |
141 | $count = 0; |
141 | while ($row = $res->fetch_object()) { |
142 | while ($row = $res->fetch_object()) { |
142 | $output .= '<p><a '.OIDplus::gui()->link($row->id).'>'.$this->highlight_match(htmlentities($row->id),$params['term']).'</a>'; |
143 | $output .= '<p><a '.OIDplus::gui()->link($row->id).'>'.$this->highlight_match(htmlentities($row->id),$params['term']).'</a>'; |
143 | 144 |