/[drupal]/contributions/modules/semantic_search/includes/semantic_search.themes.inc
ViewVC logotype

Contents of /contributions/modules/semantic_search/includes/semantic_search.themes.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 5 06:37:07 2007 UTC (2 years, 5 months ago) by hendler
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
adding files from our SVN
1 <?php
2 /*
3 * Copyright (C) October 2006 Jonathan Hendler
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 * The author can be contacted at:
20 * - jonathan [at] civicactions (dot) com
21 *
22 * @license http://www.affero.org/oagpl.html
23 * @link http://drupal.org/project/semantic_search
24 */
25 /**
26 * semantic_search's theme function
27 * */
28 function theme_semantic_search($vars){
29 $filpath = SEMANTIC_SEARCH_LOCATION . 'html/search.htm';
30 return _semantic_search_temp_template($filpath, $vars);
31 }
32
33
34 /**
35 * tell us if a link is external
36 * */
37 function _semantic_search_external_link($url){
38 return !strstr($url,_BASE_URL);
39 }
40
41 /**
42 * temp replacement for phptemplate
43 * */
44 function _semantic_search_temp_template($filpath, $vars) {
45 $text = file_get_contents($filpath);
46 return str_replace(array_keys($vars), array_values($vars), $text);
47 }
48
49 /**
50 * override this function with your own theme
51 * */
52 function theme_semantic_search_navigation($data) {
53 //data to return
54 // $data = array ();
55 // $data['results_found'] = $this->searchResultsFound();
56 // $data['is_rpc'] = !$not_rpc;
57 // $data['url'] = NinaNav :: search_link($this->search_params);
58 // $data['jellyBeanMenu'] = $this->displayJellyBeanMenu($data['url']);
59 // $data['jellyBeans'] = array (); //o key, 1 value, 2 remove link
60 $html = '';
61 $remove_symbol = '[X]&nbsp';
62 $url = $data['url'];
63 $count = 0;
64
65
66 if ($data['is_rpc'] && $data['search_active']) {
67 $html .= '<div class="naturalQuery" id="naturalQuery" >';
68 }
69
70 if ($data['search_active']) {
71 $html .= $data['jellyBeanMenu'];
72 $html .= $data['extra'];
73 $html .= '<div id="naturalQueryContent" >';
74
75 foreach ($data['jellyBeans'] as $jb) {
76 if ($count > 0)
77 $html .= ',&nbsp;';
78
79 $html .= '<div class="nlq" >';
80 $html .= '<a href="' . $jb[2] . '" title="remove your search for ' . $jb[1] . '" onclick=" $(this).text(\'\');">' . $remove_symbol . '</a>';
81 if ($jb[3]) {
82 $html .= ' <strong>' . $jb[1] . '</strong>';
83 } else { //is text
84 $html .= ' <strong>"<em>' . $jb[1] . '</em>"</strong>';
85 }
86 $html .= '</div>';
87 $count++;
88 }
89
90 $html .= '</div>'; //end naturalQueryContent
91 }
92
93 if ($data['is_rpc'] && $data['search_active'])
94 $html .= '</div>';
95
96 return $html;
97
98 }
99
100 /**
101 * navigation elements for within the search navigation area
102 * */
103 function theme_semantic_search_navigation_menu($data) {
104
105 $html = '<div id="JellyBeanMenu">';
106 $html .= '<div class="restartSearch" > - <a href="' . $data['restart'] . '">restart search</a></div>';
107 $html .= '<div class="bookmarkSearch" > - <a href="' . $data['url'] . '">bookmark search</a></div>';
108
109 $html .= '<div class="NinaSearchHelp" id="NinaSearchNavHelpTitle" >';
110 $html .= $data['help_title'] . '</div> ';
111 $html .= '<div class="NinaToolTip" id="NinaSearchNavHelp" >' . $data['help_text'] . '</div>';
112 $html .= '</div>';
113 return $html;
114 }
115
116 /**
117 * @todo internationalize with t() function
118 * */
119 function theme_semantic_search_search_results_pagination($data) {
120 $html = '';
121 $base_url = $data['base_url'];
122 $restart_url = $data['restart_url'];
123
124 if (!$data['search_results_success']) {
125 if ($data['do_search']) {
126 $html .= t('No results found, Please <a href="'.$restart_url.'" title="Restart Search">restart your search</a> or adjust your search by removing some terms.');
127 }
128
129 } else {
130 if (($data['begin'] + 1) == $data['end']) {
131 $html .= '<div class="results-displayed-text" >Displaying item ' . ($data['begin'] + 1) . '</div>';
132 } else {
133 $html .= '<div class="results-displayed-text" >Displaying items ' . ($data['begin'] + 1) . ' through ' . $data['end'] . ' (of ' . $data['total'] . ' total)</div>';
134 }
135
136 $pagination .= '<span class="semantic_searchPagination">';
137 if (!empty ($data['previous_link'])) {
138 $pagination .= '<a href="' . $data['previous_link'] . '">Previous</a>&nbsp;&nbsp;';
139 }
140
141 $pagination .= '&nbsp;&nbsp;';
142
143 if (!empty ($data['next_link'])) {
144 $pagination .= '<a href="' . $data['next_link'] . '">Next</a>&nbsp;&nbsp;';
145 }
146
147 $pagination .= '</span>';
148 $html .= $pagination;
149 }
150
151 return $html;
152 }
153
154
155 function theme_semantic_search_search_results_row(
156 &$search_result,
157 $show_complete_link = true,
158 $show_more =true,
159 $use_unorderd_list = false,
160 $show_numbers = true,
161 $tcount =0){
162
163 //sort by key
164 ksort($search_result['rows']);
165 $title = $search_result['#title'];
166 $title_extra = (!empty($search_result['#title_extra'])) ? $search_result['#title_extra']: '';
167 $result_number = $search_result['#result_number'];
168 $node_url = $search_result['#node_url'];
169
170 $hash = md5($node_url);
171
172 if ($show_more){
173 $more = '<span class="moreInfo" onClick="semantic_searchToggle(\'hr'.$hash.'\');" ';
174 $more .= '>View Profile Highlights [+/-]</span>';
175 }
176
177 $complete_link = ($show_complete_link)?'<div class="completeInfoLink"><a href="'.$node_url.'" title="view complete details" >View Complete Profile >> </a></div>':'';
178
179
180 $display_html = $hidden_html = $image_html = $top_html = '';
181 $separator = ':&nbsp;&nbsp;';
182
183 if ($use_unorderd_list) $top_html .= '<li>';
184 $altclass = ($tcount%2 == 0) ? ' searchResultAltClass ':'';
185 $top_html .= "\n".'<div class="searchResult '.$altclass.'">';
186 $top_html .= $more;
187 if (!$use_unorderd_list && $show_numbers) $top_html .= '<span class="number">' . $result_number . '</span>';
188
189 $target = (_semantic_search_external_link($node_url) ) ? ' target="_blank" ' :'';
190 $top_html .= '<div class="NinaSearchResultTitle"><a href="' . $node_url . '" '.$target.' >' . $title . '</a>'.$title_extra.'</div>';
191 $top_html .= $complete_link;
192
193 foreach($search_result['rows'] as $field){
194 if (!$field['title'] && !$field['image']){
195 //if type = image or file
196
197 //add alink to field names
198 $name = '<span class="semantic_searchFieldLabel">'.$field['name'].'</span>';
199 $field['value'] = (!is_array($field['value'])) ? $field['value'] : implode(', ',$field['value']);
200
201
202 if ((!$field['hidden'] || $field['searched']) && !$field['image']){
203 if ($field['searched']) {
204 //makes the search result show up first
205 //if (isset ($this->search_params['qstring'])) $field['qstring']{
206 //dbg($field['qstring'],"field['qstring']");
207
208 if (!empty($field['qstring'])) {
209 $search_terms = $field['qstring'];
210 foreach ($search_terms as $search_term){
211 if (!is_array($search_term)){
212 $field['value']= str_replace($search_term,
213 '<span class="semantic_searchHighlightedTerm">' . $search_term . '</span>', $field['value']);
214 }
215 else {
216 foreach($search_term as $search_term2)
217 $field['value']= str_replace($search_term2,
218 '<span class="semantic_searchHighlightedTerm">' . $search_term . '</span>', $field['value']);
219 }
220 }
221 }
222
223 $display_html .= "<div class=\"NinaSearchResultField searched\">{$name}{$separator}{$field['value']}</div>";
224 } else {
225 $display_html .= "<div class=\"NinaSearchResultField\">{$name}{$separator}{$field['value']}</div>";
226 }
227 }
228 else if ($show_more){
229 $hidden_html .= "<div class=\"NinaSearchResultField\">{$name}{$separator}{$field['value']}</div>";
230 }
231
232 } else if ($field['image']){
233 $image_html = '<img class="semantic_searchSearchResultImage" src="'.$field['value'].'" title="'.$field['name'].'" alt="'.$field['name'].'" /> ';
234 }
235
236
237 }
238 $top_html = $image_html.$top_html;
239 $final_html = $top_html.$display_html;
240 if ($show_more) $final_html .='<div class="hiddenSearchResults" id="hr'.$hash.'">'.$hidden_html.'</div>';
241 $final_html .='</div>';
242 if ($use_unorderd_list) $final_html .= '</li>';
243
244 return $final_html;
245
246 }
247
248 function theme_semantic_search_search_results($data, $unordered_list= false) {
249 $not_rpc = $data['not_rpc'];
250 $total = $data['total'];
251 $base_url = $data['base_url'];
252 $begin = $data['begin'];
253 $displayed = $data['displayed'];
254
255 $html = '';
256
257 //not sure
258 $the_type = 'semantic_search_display_preview_data';
259 $display_all_paramter_counts = variable_get($the_type, '0');
260
261 $container_type = ($unordered_list) ?'ul':'div';
262 if ($not_rpc)
263 $html .= '<'.$container_type.' class="searchResults" id="semantic_searchSearchResults">';
264
265 $count = 0;
266
267 if(!empty($data['search_results']) && is_array($data['search_results'])){
268
269 foreach ($data['search_results'] as $search_result) {
270 ++$count;
271 $html .= theme("semantic_search_search_results_row",$search_result, false,false,false,false,$count);
272 }
273
274 }
275
276 //$html .= 'dbg '. $this->sonia->getDebugText();
277 if ($not_rpc)
278 $html .= '</'.$container_type.'>';
279
280 if ($data['do_search'] && $not_rpc)
281 $html .= ' <br class="brclear" /> ';
282
283 return $html;
284
285
286
287
288 //this chunk contains some code which might beneeded later.
289
290
291
292
293 //
294 //
295 // //pagination hack
296 // if (($count >= $begin) && ($count < ($displayed + $begin))) {
297 // $hidden_search_results = $main_search_results = array ();
298 // $inner_count = 0;
299 //
300 // $more = '<span class="moreInfo" ';
301 // $more .= ' onClick="javascript: ';
302 // $more .= 'var hidden = document.getElementById(\'hr' . $count . '\').style.display; ';
303 // $more .= ' if (hidden != \'none\') ';
304 // $more .= '{ document.getElementById(\'hr' . $count . '\').style.display = \'none\'; }';
305 // $more .= 'else { document.getElementById(\'hr' . $count . '\').style.display = \'block\'; }';
306 // $more .= '" ';
307 // $more .= '>More Info [+/-]</span>';
308 //
309 // //HACK check that this is a node and not a file
310 // //if (stristr($key,SONIA_OBJECT_ID_URI))
311 // if (true) {
312 // $nid = SONIA_H :: getIDFromURI($key);
313 // $url = url('node/' . $nid);
314 // $thtml = '';
315 // //hidden fields
316 // $hhtml = '';
317 //
318 // $thtml .= '<div class="searchResult">';
319 // $thtml .= '<span class="number">' . ($count +1) . '</span>';
320 // $param_count = 1;
321 // $param_display_data = array ();
322 //
323 // foreach ($value as $data) {
324 // $property = $data['p'];
325 // $object = $data['o'];
326 // $property_label = (isset ($data['p_l'])) ? $data['p_l'] : ''; //$this->sonia->getlabel($property);
327 //
328 // //todo return this as part of main query
329 // $is_file_type = false; //$this->sonia->isFileType($property);
330 // $fid = SONIA_H :: getIDFromURI($property);
331 //
332 // //set up display order
333 // $pref_name2 = 'display_result_' . $fid;
334 // $display_visibly = variable_get($pref_name2, '4');
335 // $display_order = 10 + $display_visibly;
336 //
337 // if ($property == SONIA_RDFS_CREATE_LABEL) {
338 // //always first
339 // $param_display_data[0][0] = '<div class="NinaSearchResultTitle"><a href="' . $url . '">' . $object . '</a></div>';
340 // } else
341 // if ($is_file_type) //this may end up being slow - should be optional in query
342 // {
343 // $file_pref_name = 'display_image_' . $fid;
344 // $display_as_image = variable_get($file_pref_name, '0');
345 // $image_info = $this->sonia->store->getFileInfo($object);
346 // $image = SONIA_H :: getFileInfo($image_info);
347 // if ($display_as_image) {
348 // $thtml .= '<div class="soniaImage" > <img src="' . $image['path'] . '" title="' . $property_label . '" alt="' . $property_label . '" /></div>';
349 // } else
350 // if (user_access("administer semantic_search")) {
351 // $turl = url('admin/settings/semantic_search');
352 // //drupal_set_message('Result '.($count+1).' has been <a href="'.$turl.'">shut off</a>');
353 // }
354 // } else
355 // if ($property == SONIA_RDF_CREATE_TYPE) {
356 // //check to see if this class type is permitted to be displayed in search results
357 // $content_type = SONIA_H :: getIDFromURI($object);
358 // $pref_name = 'display_' . $content_type;
359 // $allowed = variable_get($pref_name, '1');
360 // //debug
361 // if (!$allowed)
362 // $html .= "$pref_name not allowed <br />";
363 // } else
364 // if ($property_label != null) {
365 // $param_in_search = $this->sonia->checkPropertyInSearch($property);
366 //
367 // $codedkey = SONIA_H :: encodeURI($property);
368 //
369 // //add this property to a search
370 // //make into an admin option
371 // if (false) {
372 // $add_plink_search = '<span class="semantic_searchFieldLabel"><a href="' . $base_url . '&' . SONIA_FORM_REQUEST_PREFIX . '[facet][' . $codedkey . ']=1"';
373 // //$add_plink_search .= ' onMouseOut=" document.getElementById(\''.md5($k).md5($key).'\').style.visibility=\'hidden\'; document.getElementById(\''.md5($k).md5($key).'\').style.display=\'none\'; " ';
374 // //$add_plink_search .= ' onMouseOver=" document.getElementById(\''.md5($k).md5($key).'\').style.visibility=\'visible\'; document.getElementById(\''.md5($k).md5($key).'\').style.display=\'block\'; " ';
375 // $add_plink_search .= ' title="find all spaces with the facet ' . ucfirst($property_label) . ' " >';
376 // $add_plink_search .= $property_label;
377 // $add_plink_search .= '</a></span>';
378 // } else {
379 // $add_plink_search = '<span class="semantic_searchFieldLabel">';
380 // $add_plink_search .= $property_label;
381 // $add_plink_search .= '</span>';
382 // }
383 //
384 // if ($param_in_search) {
385 // //hilight qustring in search
386 // if (isset ($this->search_params['qstring'])) {
387 // foreach ($this->search_params['qstring'] as $term) {
388 // $search_term = $term;
389 // //only take the first one .. for now
390 // break;
391 // }
392 //
393 // $object_highlighted = str_replace($search_term, '<span class="semantic_searchHighlightedTerm">' . $search_term . '</span>', $object);
394 // } else {
395 // $object_highlighted = $object;
396 // }
397 // } else {
398 // $object_highlighted = $object;
399 // }
400 //
401 // //displays an option to mouse over values on search results
402 // // fields and add those values to the search.
403 // //todo make into admin option
404 // if (false) {
405 // $object_encoded = SONIA_H :: encodeURI($object);
406 // $object_link = '<span class="objectSearch" ><a href=';
407 // $object_link .= '"' . $base_url . '&' . SONIA_FORM_REQUEST_PREFIX . '[p_value][' . $codedkey . ']=' . $object_encoded . '"';
408 // $object_link .= ' title=" find all spaces with the the facet ' . ucfirst($property_label) . ' and this value" ';
409 // $object_link .= '>';
410 // $object_link .= $object_highlighted . '</a></span>';
411 // } else {
412 // $object_link = $object_highlighted;
413 // }
414 //
415 // if ($display_visibly == 5 && !$param_in_search) //hide
416 // {
417 // $hhtml .= "$add_plink_search{$separator}$object_link<br />";
418 // } else
419 // if ($param_in_search) {
420 // //makes the search result show up first
421 // $param_display_data[0][$param_count] = "<div class=\"searched\" >$add_plink_search{$separator}$object_link </div>";
422 // } else //
423 // {
424 // $param_display_data[$display_order][$param_count] = "$add_plink_search{$separator}$object_link";
425 // }
426 // }
427 // $param_count++;
428 // } // end param foreach
429 //
430 // //parse output
431 // ksort($param_display_data);
432 // $icount = 0;
433 // foreach ($param_display_data as $pdata) {
434 // ksort($pdata);
435 // foreach ($pdata as $display) {
436 // $thtml .= '<div class="NinaSearchResultField">' . $display . '</div>';
437 // if ($icount == 0)
438 // $thtml .= $more;
439 // $icount++;
440 // }
441 // }
442 //
443 // if ($allowed) {
444 // //turn these off with jQuery
445 // $html .= $thtml;
446 // $html .= '<div class="hiddenSearchResults" id="hr' . $count . '" >' . $hhtml . '</div>';
447 // $html .= '</div>';
448 // $html .= "<script language=\"JavaScript\" type=\"text/javascript\">" . ' document.getElementById(\'hr' . $count . '\').style.display = \'none\'; </script>';
449 //
450 // }
451 //
452 // }
453 // } //end pagination hack
454 // $count++;
455
456 } //end theme_semantic_search_search_results
457
458

  ViewVC Help
Powered by ViewVC 1.1.2