Rev 321 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 321 | Rev 360 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | class OIDplusPagePublicSearch extends OIDplusPagePluginPublic { |
20 | class OIDplusPagePublicSearch extends OIDplusPagePluginPublic { |
21 | 21 | ||
22 | public function init($html=true) { |
22 | public function init($html=true) { |
23 | OIDplus::config()->prepareConfigKey('search_min_term_length', 'Minimum length of a search term', '3', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
23 | OIDplus::config()->prepareConfigKey('search_min_term_length', 'Minimum length of a search term', '3', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
24 | if (!is_numeric($value) || ($value < 0)) { |
24 | if (!is_numeric($value) || ($value < 0)) { |
25 | throw new OIDplusException("Please enter a valid value."); |
25 | throw new OIDplusException(_L('Please enter a valid value.')); |
26 | } |
26 | } |
27 | }); |
27 | }); |
28 | } |
28 | } |
29 | 29 | ||
30 | public function gui($id, &$out, &$handled) { |
30 | public function gui($id, &$out, &$handled) { |
31 | if (explode('$',$id)[0] == 'oidplus:search') { |
31 | if (explode('$',$id)[0] == 'oidplus:search') { |
32 | $handled = true; |
32 | $handled = true; |
33 | 33 | ||
34 | $out['title'] = 'Search'; |
34 | $out['title'] = _L('Search'); |
35 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
35 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
36 | 36 | ||
37 | $out['text'] = ''; |
37 | $out['text'] = ''; |
38 | 38 | ||
39 | try { |
39 | try { |
Line 48... | Line 48... | ||
48 | } |
48 | } |
49 | 49 | ||
50 | // TODO: make it via AJAX? Reloading the whole page is not good. But attention: Also allow NoScript |
50 | // TODO: make it via AJAX? Reloading the whole page is not good. But attention: Also allow NoScript |
51 | $out['text'] .= '<form id="searchForm" action="?goto=oidplus:search" method="POST"> |
51 | $out['text'] .= '<form id="searchForm" action="?goto=oidplus:search" method="POST"> |
52 | <input type="hidden" name="search" value="1"> |
52 | <input type="hidden" name="search" value="1"> |
53 | Search for: <input type="text" id="term" name="term" value="'.htmlentities($search_term).'"><br><br> |
53 | '._L('Search for').': <input type="text" id="term" name="term" value="'.htmlentities($search_term).'"><br><br> |
54 | <script> |
54 | <script> |
55 | function searchNsSelect(ns) { |
55 | function searchNsSelect(ns) { |
56 | document.getElementById("search_options_oid").style.display = (ns == "oid") ? "block" : "none"; |
56 | document.getElementById("search_options_oid").style.display = (ns == "oid") ? "block" : "none"; |
57 | document.getElementById("search_options_object").style.display = (ns == "oidplus:ra") ? "none" : "block"; |
57 | document.getElementById("search_options_object").style.display = (ns == "oidplus:ra") ? "none" : "block"; |
58 | document.getElementById("search_options_ra").style.display = (ns == "oidplus:ra") ? "block" : "none"; |
58 | document.getElementById("search_options_ra").style.display = (ns == "oidplus:ra") ? "block" : "none"; |
59 | } |
59 | } |
60 | $( document ).ready(function() { |
60 | $( document ).ready(function() { |
61 | searchNsSelect(document.getElementById("namespace").value); |
61 | searchNsSelect(document.getElementById("namespace").value); |
62 | }); |
62 | }); |
63 | </script> |
63 | </script> |
64 | Search in: <select name="namespace" id="namespace" onchange="searchNsSelect(this.value);"><br><br>'; |
64 | '._L('Search in').': <select name="namespace" id="namespace" onchange="searchNsSelect(this.value);"><br><br>'; |
65 | 65 | ||
66 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
66 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
67 | $out['text'] .= '<option value="'.htmlentities($ot::ns()).'"'.(($ns == $ot::ns()) ? ' selected' : '').'>'.htmlentities($ot::objectTypeTitle()).'</option>'; |
67 | $out['text'] .= '<option value="'.htmlentities($ot::ns()).'"'.(($ns == $ot::ns()) ? ' selected' : '').'>'.htmlentities($ot::objectTypeTitle()).'</option>'; |
68 | } |
68 | } |
69 | $out['text'] .= '<option value="oidplus:ra"'.(($ns == 'oidplus:ra') ? ' selected' : '').'>Registration Authority</option> |
69 | $out['text'] .= '<option value="oidplus:ra"'.(($ns == 'oidplus:ra') ? ' selected' : '').'>'._L('Registration Authority').'</option> |
70 | </select><br><br> |
70 | </select><br><br> |
71 | <div id="search_options_ra"> |
71 | <div id="search_options_ra"> |
72 | <!-- TODO: RA specific selection criterias --> |
72 | <!-- TODO: RA specific selection criterias --> |
73 | </div> |
73 | </div> |
74 | <div id="search_options_object"> |
74 | <div id="search_options_object"> |
75 | <input type="checkbox" name="search_title" id="search_title" value="1"'.(isset($_POST["search_title"]) ? ' checked' : '').'> <label for="search_title">Search in field "Title"</label><br> |
75 | <input type="checkbox" name="search_title" id="search_title" value="1"'.(isset($_POST["search_title"]) ? ' checked' : '').'> <label for="search_title">'._L('Search in field "Title"').'</label><br> |
76 | <input type="checkbox" name="search_description" id="search_description" value="1"'.(isset($_POST["search_description"]) ? ' checked' : '').'> <label for="search_description">Search in field "Description"</label><br> |
76 | <input type="checkbox" name="search_description" id="search_description" value="1"'.(isset($_POST["search_description"]) ? ' checked' : '').'> <label for="search_description">'._L('Search in field "Description"').'</label><br> |
77 | <div id="search_options_oid"> |
77 | <div id="search_options_oid"> |
78 | <input type="checkbox" name="search_asn1id" id="search_asn1id" value="1"'.(isset($_POST["search_asn1id"]) ? ' checked' : '').'> <label for="search_asn1id">Search in field "ASN.1 identifier" (only OIDs)</label><br> |
78 | <input type="checkbox" name="search_asn1id" id="search_asn1id" value="1"'.(isset($_POST["search_asn1id"]) ? ' checked' : '').'> <label for="search_asn1id">'._L('Search in field "ASN.1 identifier" (only OIDs)').'</label><br> |
79 | <input type="checkbox" name="search_iri" id="search_iri" value="1"'.(isset($_POST["search_iri"]) ? ' checked' : '').'> <label for="search_iri">Search in field "Unicode label" (only OIDs)</label><br> |
79 | <input type="checkbox" name="search_iri" id="search_iri" value="1"'.(isset($_POST["search_iri"]) ? ' checked' : '').'> <label for="search_iri">'._L('Search in field "Unicode label" (only OIDs)').'</label><br> |
80 | </div> |
80 | </div> |
81 | </div> |
81 | </div> |
82 | <br> |
82 | <br> |
83 | 83 | ||
84 | <input type="submit" value="Search"> |
84 | <input type="submit" value="'._L('Search').'"> |
85 | </form>'; |
85 | </form>'; |
86 | 86 | ||
87 | if (isset($_POST['search'])) { |
87 | if (isset($_POST['search'])) { |
88 | // Note: The SQL collation defines if search is case sensitive or case insensitive |
88 | // Note: The SQL collation defines if search is case sensitive or case insensitive |
89 | 89 | ||
90 | $min_length = OIDplus::config()->getValue('search_min_term_length'); |
90 | $min_length = OIDplus::config()->getValue('search_min_term_length'); |
91 | 91 | ||
92 | $search_term = trim($search_term); |
92 | $search_term = trim($search_term); |
93 | 93 | ||
94 | if (strlen($search_term) == 0) { |
94 | if (strlen($search_term) == 0) { |
95 | $out['text'] .= '<p><font color="red">Error: You must enter a search term.</font></p>'; |
95 | $out['text'] .= '<p><font color="red">'._L('Error: You must enter a search term.').'</font></p>'; |
96 | } else if (strlen($search_term) < $min_length) { |
96 | } else if (strlen($search_term) < $min_length) { |
97 | $out['text'] .= '<p><font color="red">Error: Search term minimum length is '.$min_length.' characters.</font></p>'; |
97 | $out['text'] .= '<p><font color="red">'._L('Error: Search term minimum length is %1 characters.',$min_length).'</font></p>'; |
98 | } else { |
98 | } else { |
99 | if ($ns == 'oidplus:ra') { |
99 | if ($ns == 'oidplus:ra') { |
100 | $out['text'] .= '<h2>Search results for RA "'.htmlentities($search_term).'"</h2>'; |
100 | $out['text'] .= '<h2>'._L('Search results for RA %1',htmlentities($search_term)).'</h2>'; |
101 | 101 | ||
102 | $sql_where = array(); $prep_where = array(); |
102 | $sql_where = array(); $prep_where = array(); |
103 | $sql_where[] = "email like ?"; $prep_where[] = '%'.$search_term.'%'; |
103 | $sql_where[] = "email like ?"; $prep_where[] = '%'.$search_term.'%'; |
104 | $sql_where[] = "ra_name like ?"; $prep_where[] = '%'.$search_term.'%'; |
104 | $sql_where[] = "ra_name like ?"; $prep_where[] = '%'.$search_term.'%'; |
105 | 105 | ||
Line 111... | Line 111... | ||
111 | $email = str_replace('@', '&', $row->email); |
111 | $email = str_replace('@', '&', $row->email); |
112 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$email)).'>'.htmlentities($email).'</a>: <b>'.htmlentities($row->ra_name).'</b></p>'; |
112 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$email)).'>'.htmlentities($email).'</a>: <b>'.htmlentities($row->ra_name).'</b></p>'; |
113 | $count++; |
113 | $count++; |
114 | } |
114 | } |
115 | if ($count == 0) { |
115 | if ($count == 0) { |
116 | $out['text'] .= '<p>Nothing found</p>'; |
116 | $out['text'] .= '<p>'._L('Nothing found').'</p>'; |
117 | } |
117 | } |
118 | } else { |
118 | } else { |
119 | $out['text'] .= '<h2>Search results for "'.htmlentities($search_term).'" ('.htmlentities($ns).')</h2>'; |
119 | $out['text'] .= '<h2>'._L('Search results for %1 (%2)',htmlentities($search_term),htmlentities($ns)).'</h2>'; |
120 | 120 | ||
121 | $sql_where = array(); $prep_where = array(); |
121 | $sql_where = array(); $prep_where = array(); |
122 | $sql_where[] = "id like ?"; $prep_where[] = '%'.$search_term.'%'; // TODO: should we rather do findFitting(), so we can e.g. find GUIDs with different notation? |
122 | $sql_where[] = "id like ?"; $prep_where[] = '%'.$search_term.'%'; // TODO: should we rather do findFitting(), so we can e.g. find GUIDs with different notation? |
123 | if (isset($_POST["search_title"])) { $sql_where[] = "title like ?"; $prep_where[] = '%'.$search_term.'%'; } |
123 | if (isset($_POST["search_title"])) { $sql_where[] = "title like ?"; $prep_where[] = '%'.$search_term.'%'; } |
124 | if (isset($_POST["search_description"])) { $sql_where[] = "description like ?"; $prep_where[] = '%'.$search_term.'%'; } |
124 | if (isset($_POST["search_description"])) { $sql_where[] = "description like ?"; $prep_where[] = '%'.$search_term.'%'; } |
Line 146... | Line 146... | ||
146 | while ($row = $res->fetch_object()) { |
146 | while ($row = $res->fetch_object()) { |
147 | $out['text'] .= '<p><a '.OIDplus::gui()->link($row->id).'>'.htmlentities($row->id).'</a>: <b>'.htmlentities($row->title).'</b></p>'; // TODO: also show asn1id; highlight search match? |
147 | $out['text'] .= '<p><a '.OIDplus::gui()->link($row->id).'>'.htmlentities($row->id).'</a>: <b>'.htmlentities($row->title).'</b></p>'; // TODO: also show asn1id; highlight search match? |
148 | $count++; |
148 | $count++; |
149 | } |
149 | } |
150 | if ($count == 0) { |
150 | if ($count == 0) { |
151 | $out['text'] .= '<p>Nothing found</p>'; |
151 | $out['text'] .= '<p>'._L('Nothing found').'</p>'; |
152 | } |
152 | } |
153 | } |
153 | } |
154 | } |
154 | } |
155 | } |
155 | } |
156 | } catch (Exception $e) { |
156 | } catch (Exception $e) { |
157 | $out['text'] = "Error: ".$e->getMessage(); |
157 | $out['text'] = _L('Error: %1',$e->getMessage()); |
158 | } |
158 | } |
159 | } |
159 | } |
160 | } |
160 | } |
161 | 161 | ||
162 | public function publicSitemap(&$out) { |
162 | public function publicSitemap(&$out) { |
163 | $out[] = OIDplus::getSystemUrl().'?goto='.urlencode('oidplus:search'); |
163 | $out[] = 'oidplus:search'; |
164 | } |
164 | } |
165 | 165 | ||
166 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
166 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
167 | if (file_exists(__DIR__.'/treeicon.png')) { |
167 | if (file_exists(__DIR__.'/treeicon.png')) { |
168 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
168 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
Line 171... | Line 171... | ||
171 | } |
171 | } |
172 | 172 | ||
173 | $json[] = array( |
173 | $json[] = array( |
174 | 'id' => 'oidplus:search', |
174 | 'id' => 'oidplus:search', |
175 | 'icon' => $tree_icon, |
175 | 'icon' => $tree_icon, |
176 | 'text' => 'Search' |
176 | 'text' => _L('Search') |
177 | ); |
177 | ); |
178 | 178 | ||
179 | return true; |
179 | return true; |
180 | } |
180 | } |
181 | 181 |