/[drupal]/contributions/modules/semantic_search/semantic_search.module
ViewVC logotype

Contents of /contributions/modules/semantic_search/semantic_search.module

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:06 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) May 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 authors 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 /*
27 * notes for mirgration
28 * http://drupal.org/node/64279
29 * http://drupal.org/node/64279#drupal-get-form most major
30 * http://drupal.org/node/64279#form-building
31 * themes
32 * http://drupal.org/node/64292
33 *
34 * cool
35 * http://drupal.org/node/64279#hook-forms
36 * http://www.nicklewis.org/node/905 category
37 * http://drupal.org/node/69981
38 * http://www.lullabot.com/articles/an_introduction_to_the_content_construction_kit
39 *
40 *
41 * */
42 /**
43 * include files
44 * */
45 require 'semantic_search.includes.inc';
46
47 //now check that configs are properly set
48 $fs_temp_val = variable_get('ARC_DB_NAME',null);
49 if (empty($fs_temp_val) && user_access("administer semantic_search") ){
50 drupal_set_message(t('Please <a href="'.url(SEMANTIC_SEARCH_ADMIN_HOME.'/config',null,null,true).'">configure SemanticSearch</a>'),'error');
51 }
52
53 /**
54 * The SEMANTIC_SEARCH module provides a facted search tool for many types of
55 * faceted data which exist in some RDF form.
56 *
57 * Be sure to have these blocks display only on the SEMANTIC_SEARCH page.
58 * Usually the search form and "your search" are in a left column, and the
59 * search results show in the content area.
60 *
61 *
62 * INSTALLATION:
63 * You must configure as well as SEMANTIC_SEARCH with semantic_search.conf.inc[.sample]
64 * Also, you must configure SONIA with sonia.conf.inc[.sample]
65 *
66 * The RDF must contain Object and their properties, and Classes (Categories)
67 * and their subclasses. After the import, the UI needs some tweaking in the search...
68 *
69 * @author Jonathan Hendler <jonathan@civicactions.com>
70 * @author Dan Robinson <dan@civicactions.com>
71 *
72 * @todo fquery
73 * @todo panels for dynamic forms
74 *
75 * @package SEMANTIC_SEARCH
76 * @see SONIA
77 * @see ARC
78 * @see http://www.fsearch.org/trac/wiki/InstallingSEMANTIC_SEARCH
79 *
80 * */
81
82 /**
83 * catch this settings form and do synchronization
84 * */
85 //function semantic_search_settings_form_submit($form_id, $form_values) {
86 // system_settings_form_submit($form_id, $form_values);
87 // if (isset ($form_values['CCK_SYNC']) && ($form_values['CCK_SYNC'] == 1)) {
88 // drupal_set_message('SEMANTIC_SEARCH: synchronizing with CCK');
89 // _semantic_search_node_sync($form_values);
90 // }
91 // return 'admin/settings/semantic_search';
92 //}
93
94 //function semantic_search_settings_form_confirm(){
95 //$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
96 //
97 // return confirm_form($form,
98 // t('Are you sure you want to delete %title?', array('%title' => $node->title)),
99 // $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
100 // t('This action cannot be undone.'),
101 // t('Delete'), t('Cancel'));
102 //}
103
104 /**
105 *
106 * */
107 function _semantic_search_build_cache_link() {
108
109 }
110
111 /**
112 * settings hook
113 * */
114 //function semantic_search_settings_form() {
115 // if (!user_access("administer semantic_search")) {
116 // return message_admin_access();
117 // }
118 // _semantic_search_load_js_and_css();
119 // _semantic_search_node_index_check();
120 //
121 // $path = drupal_get_path('module', 'semantic_search');
122 // $js_path = $path . '/js';
123 // drupal_add_js($js_path . '/semantic_search.admin.js');
124 //
125 // global $_semantic_search_search;
126 // if (empty ($_semantic_search_search))
127 // _SEMANTIC_SEARCH_INIT();
128 //
129 // $form['semantic_search_settings'] = array (
130 // '#type' => 'fieldset',
131 // '#title' => 'Nina Settings'
132 // );
133 //
134 // // $the_type = 'SEMANTIC_SEARCH Javascript Enabled';
135 // // if (module_exist('semantic_search_rpc')) {
136 // // $form['semantic_search_settings'][$the_type] = array (
137 // // '#type' => 'checkbox',
138 // // '#title' => t('Enable AJAX on forms'
139 // // ), '#description' => t('Nina search forms will use Javascript Remoting. You can also turn this off' .
140 // // ' by disabling the semantic_search_rpc.module.'), '#return_value' => 1, '#default_value' => variable_get($the_type, '1'),);
141 // // } else {
142 // // $form['semantic_search_settings'][$the_type] = array (
143 // // '#value' => "You may want to <a href=\"" .
144 // // url('admin/modules'
145 // // ) . "\" title=\"\">enable the SEMANTIC_SEARCH rpc module for ajax</a>",);
146 // // }
147 //
148 // // $the_type = 'Display preview data';
149 // //
150 // // $form['semantic_search_settings'][$the_type] = array (
151 // // '#type' => 'checkbox',
152 // // '#title' => t('Display preview data of parameters in search results.'
153 // // ), '#description' => t('On rollover of parameters, should a preview of all available data be displayed?'), '#return_value' => 1, '#default_value' => variable_get($the_type, '0'),);
154 // //
155 //
156 // //CACHE BUILDER
157 // $cttitle = t('Clicking here will build up the index/cache.');
158 // $cttitle2 = t('Clicking here will erase all items in the cached index. ');
159 // $cttitle3 = t('Clicking here simply stop the cache from running. You can continue later.');
160 // $ctext = t('Build Search Index.');
161 // $ctext2 = t('Clear Search Index.');
162 // $ctext3 = t('Stop Building Index.');
163 // $description = t('The above buttons provide management for the indexing of ' .
164 // 'searches. Indexing will speed up the most common searches and remove load' .
165 // ' from the database. The size of the index is produced using a simple formula ' .
166 // 'based on the search form\'s choices.');
167 //
168 // $cache_builder = '<div id="cacheManager"><button id="cacheBuilder" title="' . $cttitle . '">';
169 // $cache_builder .= $ctext;
170 // $cache_builder .= '</button>';
171 // $cache_builder .= '<button id="cacheClearer" title="' . $cttitle2 . '">';
172 // $cache_builder .= $ctext2;
173 // $cache_builder .= '</button>';
174 // $cache_builder .= ' <button id="cacheStop" disabled="disabled" title="' . $cttitle3 . '">';
175 // $cache_builder .= $ctext3;
176 // $cache_builder .= '</button>';
177 // $cache_builder .= '</div>';
178 // $cache_builder .= '<div id="cacheBuilderStatus"></div>';
179 // $cache_builder .= '<div class="description">' . $description . '</div><br /><br />';
180 // $form['semantic_search_settings']['cache_builder'] = array (
181 // '#value' => $cache_builder,
182 //
183 // );
184 //
185 // // $the_type = 'Search Form Unset';
186 // //
187 // // $form['semantic_search_settings'][$the_type] = array (
188 // // '#type' => 'checkbox',
189 // // '#title' => t('Search Form Unset'
190 // // ), '#description' => t('When this is turned off, you must use the "my search"/breadcrumb block to ' .
191 // // 'remove search items. When it is selected, the search form rebuilds the search every time submit is sent.'), '#return_value' => 1, '#default_value' => variable_get($the_type, '1'),);
192 //
193 // $the_type = 'semantic_search_search_title';
194 // $form['semantic_search_settings'][$the_type] = array (
195 // '#type' => 'textfield',
196 // '#title' => t('Search Title'
197 // ), '#description' => t('What will the title of the search results be?'),
198 // //'#return_value' => 1,
199 // '#default_value' => variable_get($the_type, 'SEMANTIC_SEARCH Search'),);
200 //
201 // $the_type = 'semantic_search_search_form_title';
202 // $form['semantic_search_settings'][$the_type] = array (
203 // '#type' => 'textfield',
204 // '#title' => t('Search Form Title'
205 // ), '#description' => t('What will the title of the search form be?'),
206 // //'#return_value' => 1,
207 // '#default_value' => variable_get($the_type, 'SEMANTIC_SEARCH Search'),);
208 //
209 // $the_type = 'semantic_search_help_title';
210 // $form['semantic_search_settings'][$the_type] = array (
211 // '#type' => 'textfield',
212 // '#title' => t('Help Text Title'
213 // ), '#description' => t('This text is the title for retrieving help from the tooltip.'),
214 // //'#return_value' => 1,
215 // '#default_value' => variable_get($the_type, '[help]'),);
216 //
217 // $the_type = 'semantic_search_help_text';
218 // $form['semantic_search_settings'][$the_type] = array (
219 // '#type' => 'textarea',
220 // '#title' => t('Help Text'
221 // ), '#description' => t('This text displays in a tooltip near "your search terms" area. '),
222 // //'#return_value' => 1,
223 // '#default_value' => variable_get($the_type, t('You can add new terms to narrow the search' .
224 // ' by going to the search form or you can ' .
225 // 'remove search terms to expand the search.')),);
226 //
227 //
228 //
229 // $form['semantic_search_settings']['CCK_SYNC'] = array (
230 // '#type' => 'checkbox',
231 // '#title' => t('<strong>CCK SYNC</strong>'
232 // ), '#description' => t('When you select a CCK type below - all CCK data and related taxonomy terms will' .
233 // 'will be imported and indexed in SEMANTIC_SEARCH. This could take a VERY long time. You DO NOT need to sync if you change the order of field display under "field options".'), '#return_value' => 1, '#default_value' => 0,);
234 //
235 // $form['semantic_search_settings']['CCK_RESET'] = array (
236 // '#type' => 'checkbox',
237 // '#title' => t('<strong>RESET DATA</strong>'
238 // ), '#description' => t('Also, clear ALL the data in SEMANTIC_SEARCH - only use this when starting over!!!'), '#return_value' => 1, '#default_value' => 0,
239 // '#attributes'=>array('disabled'=>'disabled'));
240 //
241 //
242 // $index_size = _semantic_search_node_index_count();
243 // $total_node_count = _semantic_search_node_total_count();
244 // $the_type = 'SEMANTIC_SEARCH_IMPORT_BATCH_SIZE';
245 // $form['semantic_search_settings'][$the_type] = array (
246 // '#type' => 'textfield',
247 // '#title' => t('Batch Size'
248 // ), '#description' => t('There are currently %size of %total total nodes imported into SEMANTIC_SEARCH.<br>It takes a long time to build RDF. This lets you build in batches.',
249 // array('%size'=>$index_size,'%total'=>$total_node_count)),
250 // //'#return_value' => 1,
251 // '#default_value' => variable_get($the_type, 1000),
252 // '#attributes'=>array('disabled'=>'disabled'));
253 //
254 // $type_options = _content_type_info();
255 // //dbg($type_options,'$type_options');
256 //
257 // $form['semantic_search_settings']['div_begin_a']['#value'] = '<div id="cck-options">';
258 //
259 // $form['semantic_search_settings']['CCK Sync'] = array (
260 // '#type' => 'fieldset',
261 // '#title' => 'CCK Type Syncronization options ',
262 //
263 //
264 // );
265 //
266 // foreach ($type_options['content types'] as $id => $data) {
267 // $pref_name = 'display_' . $id;
268 // $label = $data['name'];
269 // $description = $data['description'];
270 // $fields = $data['fields'];
271 //
272 // $form['semantic_search_settings']['CCK Sync'][$pref_name] = array (
273 // '#type' => 'checkbox',
274 // '#title' => t('Store CCK type <strong>' . $label . '</strong> in SEMANTIC_SEARCH.'
275 // ), '#description' => t('Should CCK type <em>' . $label . ' (' . $description . ')</em> be stored in SEMANTIC_SEARCH to be available for RDF search and export"?'), '#return_value' => 1, '#default_value' => variable_get($pref_name, '0'),);
276 //
277 // if (!empty ($fields)) {
278 //
279 // $form['semantic_search_settings']['CCK Sync'][$pref_name . '_f'] = array (
280 // '#type' => 'fieldset',
281 // '#title' => '<em>"' . $label . '"</em> Field Options ',
282 // '#collapsible' => 1,
283 // '#collapsed' => 1
284 // );
285 //
286 // foreach ($fields as $fid => $field_data) {
287 // $pref_name2 = 'display_result_' . $fid;
288 //
289 // $field_label = $field_data['widget']['label'];
290 // $field_id = $fid;
291 //
292 // $form['semantic_search_settings']['CCK Sync'][$pref_name . '_f'][$pref_name2] = array (
293 // '#type' => 'select',
294 // '#title' => t('Display field <em>"' . $field_label . '"</em> in SEMANTIC_SEARCH search results.'
295 // ), '#description' => t('Should CCK field <em>' . $field_label . ' </em> display in the search results?' .
296 // '<br /> Note: 0 means do not display.'), '#options' => array (
297 // -5,
298 // -4,
299 // -3,
300 // -2,
301 // -1,
302 // 0,
303 // 1,
304 // 2,
305 // 3,
306 // 4,
307 // 5
308 // ), '#default_value' => variable_get($pref_name2, '4'),);
309 //
310 // //file settings
311 // $furi = SONIA_PROPERTY_ID_URI . $fid;
312 // $is_file_type = $_semantic_search_search->sonia->isFileType($furi);
313 // if ($is_file_type) {
314 // $file_pref_name = 'display_image_' . $fid;
315 // $form['semantic_search_settings']['CCK Sync'][$pref_name . '_f'][$file_pref_name] = array (
316 // '#type' => 'checkbox',
317 // '#title' => t('Display field <em>"' . $field_label . '"</em> in SEMANTIC_SEARCH search results as image.'
318 // ), '#description' => t('Should CCK field <em>' . $field_label . ' </em> display in the search results as an image?'), '#return_value' => 1, '#default_value' => variable_get($file_pref_name, '0'),);
319 // }
320 //
321 // }
322 // }
323 // //get cck fields and have a setting for
324 // //show in search results
325 // } //end cck types foreach
326 // $form['semantic_search_settings']['div_end_a']['#value'] = '</div>';
327 // //dbg($form,'$form');
328 // return system_settings_form( $form);
329 //} //end settings
330
331 /**
332 * Basic permissions and permisions dynamically generated from search
333 * */
334 function semantic_search_perm() {
335 $perms = array (
336 'access semantic_search',
337 'administer semantic_search',
338 'search semantic_search',
339 'configure semantic_search',
340 'new search',
341 'delete search'
342 );
343
344 //get dynamic
345 //'SemanticSearch of '.$search_name
346 $searches = _semantic_search_get_all_search_form_vars();
347
348 foreach ($searches as $key => $search) {
349 $search_name = $search['name'];
350 $perms [] = $search_name . ': configure search';
351 $perms [] = $search_name . ': access search';
352 }
353
354 return $perms;
355 } // function semantic_search_perm
356
357 /**
358 * Basic help function
359 * */
360 function semantic_search_help($section = '') {
361 $output = '';
362
363 switch ($section) {
364 case "admin/modules#description" :
365 $output = t('<strong>Semantic Search:</strong> Provides various faceted search functionality with ');
366 $output .= t('National Information Network for Artists (SEMANTIC_SEARCH)');
367 break;
368 case 'admin/help#modulename' :
369 $output = t('<strong>Semantic Search:</strong> Provides various faceted search functionality with ');
370 $output .= t('National Information Network for Artists (SEMANTIC_SEARCH)');
371 break;
372 }
373
374 return $output;
375 } //END semantic_search_help
376
377 /**
378 * menu callback
379 * */
380 function semantic_search_menu($may_cache) {
381
382
383 $items = array ();
384
385 //TODO generate dynamic searches here
386 $the_type = 'semantic_search_search_title';
387 $title_of_search = variable_get($the_type, 'SEMANTIC_SEARCH Search');
388
389 if (!$may_cache){
390 //////////////////////
391 // Default search
392 //init the search object
393 $items[] = array (
394 'path' => 'semantic_search',
395 'title' => t($title_of_search
396 ), 'callback' => '_semantic_search_search',
397 'access' => user_access('search semantic_search'),
398 'type' => MENU_CALLBACK
399 );
400
401 ///configuration and administration
402 $items[] = array (
403 'path' => SEMANTIC_SEARCH_ADMIN_HOME,
404 'title' => t('Semantic Search'),
405 'callback' => '_semantic_search_admin_semantic_search',
406 'access' => user_access('admin semantic_search'),
407 'type' => MENU_NORMAL_ITEM,
408
409 );
410
411 $searches = _semantic_search_get_all_search_form_vars();
412 // now generate the list of search urls
413 _semantic_search_get_menus($items,$searches,$may_cache);
414
415 if (empty($searches)){
416
417 $items[] = array (
418 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches',
419 'title' => t('New Search Configuration'),
420 'description' => t('Create a new search page.'),
421 'callback' => 'drupal_get_form',
422 'callback arguments' => array('semantic_search_search_form'),
423 'access' => user_access('admin semantic_search'),
424 'weight' => 0,
425 'type' => MENU_LOCAL_TASK
426 );
427
428 } else {
429 //the export to RDF page
430 $items[] = array (
431 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches',
432 'title' => t('Search Configurations'),
433 'callback' => '_semantic_search_admin_semantic_search',
434 'access' => user_access('admin semantic_search'),
435 'weight' => 0,
436 'type' => MENU_LOCAL_TASK
437 );
438
439 $items[] = array (
440 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches/new',
441 'title' => t('New Search Configuration'),
442 'description' => t('Create a new search page.'),
443 'callback' => 'drupal_get_form',
444 'callback arguments' => array('semantic_search_search_form'),
445 'access' => user_access('admin semantic_search'),
446 'weight' => 0,
447 'type' => MENU_LOCAL_TASK
448 );
449
450 }
451
452 if (!empty($searches)){
453
454 foreach($searches as $key=>$search){
455 $search_name = $search['name'];
456
457 $items[] = array (
458 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name,
459 'title' => t($search['title']) ,
460 'description' => t($search['description']),
461 'callback' => 'drupal_get_form',
462 'callback arguments' => array('semantic_search_search_form',$search_name),
463 'access' => user_access('admin semantic_search') || user_access($search_name . ': configure search' ),
464 'weight' => $key+1,
465 'type' => MENU_LOCAL_TASK
466 );
467
468
469 $items[] = array (
470 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/add',
471 'title' => t($search['title']) ,
472 'description' => t($search['description']),
473 'callback' => 'drupal_get_form',
474 'callback arguments' => array('semantic_search_search_field_form',$search_name),
475 'access' => user_access('admin semantic_search') || user_access($search_name . ': configure search' ),
476 'weight' => $key+1,
477 'type' => MENU_CALLBACK
478 );
479
480 //get all fields for this search
481 $fields = _semantic_search_get_all_search_field_vars($search_name);
482 foreach($fields as $field) {
483 $items[] = array (
484 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/searches/'.$search_name.'/edit/'.$field['id'],
485 'title' => t($search['title']).': '.$field['title'] ,
486 'description' => t('Edit ').t($search['description']),
487 'callback' => 'drupal_get_form',
488 'callback arguments' => array('semantic_search_search_field_form',$search_name,$field['id'],true),
489 'access' => user_access('admin semantic_search') || user_access($search_name . ': configure search' ),
490 'weight' => $key+1,
491 'type' => MENU_CALLBACK
492 );
493 }
494 }
495 }
496
497 //the export to RDF page
498 $items[] = array (
499 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/export',
500 'title' => t('Export'),
501 'callback' => '_semantic_search_export',
502 'access' => user_access('admin semantic_search'),
503 'weight' => 1,
504 'type' => MENU_LOCAL_TASK
505 );
506
507 //the export to RDF page
508 $items[] = array (
509 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/import',
510 'title' => t('Import'),
511 'callback' => '_semantic_search_export',
512 'access' => user_access('admin semantic_search'),
513 'weight' => 2,
514 'type' => MENU_LOCAL_TASK
515 );
516
517 //the export to RDF page
518 $items[] = array (
519 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/import/csv',
520 'title' => t('CSV'),
521 'callback' => '_semantic_search_export',
522 'access' => user_access('admin semantic_search'),
523 'weight' => 3,
524 'type' => MENU_LOCAL_TASK
525 );
526
527 $items[] = array (
528 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/import/microformats',
529 'title' => t('Micro Formats'),
530 'callback' => '_semantic_search_export',
531 'access' => user_access('admin semantic_search'),
532 'weight' => 4,
533 'type' => MENU_LOCAL_TASK
534 );
535
536 $items[] = array (
537 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/import/rdf',
538 'title' => t('RDF Files'),
539 'callback' => '_semantic_search_export',
540 'access' => user_access('admin semantic_search'),
541 'weight' => 5,
542 'type' => MENU_LOCAL_TASK
543 );
544
545
546 $items[] = array (
547 'path' => SEMANTIC_SEARCH_ADMIN_HOME.'/config',
548 'title' => t('Settings'),
549 'callback' => 'drupal_get_form',
550 'callback arguments'=> array('semantic_search_settings_form'),
551 'access' => user_access('admin semantic_search'),
552 'type' => MENU_LOCAL_TASK
553 );
554 //__nsp('semantic_search_menu() end');
555 //
556
557 } // !$may_cache
558
559
560 return $items;
561 }
562
563 /**
564 * SEMANTIC_SEARCH checks for a variable set via javascript
565 * */
566 function _semantic_search_check_redirect() {
567 if (!empty ($_COOKIE['SEMANTIC_SEARCH_REDIRECT']) && empty ($_SESSION['SEMANTIC_SEARCH_REDIRECTED'])) {
568 $url = $_COOKIE['SEMANTIC_SEARCH_REDIRECT'];
569 unset ($_COOKIE['SEMANTIC_SEARCH_REDIRECT']);
570 $_SESSION['SEMANTIC_SEARCH_REDIRECTED'] = true;
571
572 $this_uri = url($_SERVER['REQUEST_URI'], null, null, true);
573 if ($url != $this_uri) {
574 unset ($_COOKIE['SEMANTIC_SEARCH_REDIRECT']);
575 unset ($_SESSION['SEMANTIC_SEARCH_REDIRECTED']);
576 drupal_set_header('Location: ' . $url . "\n");
577 } else {
578 unset ($_COOKIE['SEMANTIC_SEARCH_REDIRECT']);
579 unset ($_SESSION['SEMANTIC_SEARCH_REDIRECTED']);
580 }
581 } else {
582 unset ($_COOKIE['SEMANTIC_SEARCH_REDIRECT']);
583 unset ($_SESSION['SEMANTIC_SEARCH_REDIRECTED']);
584 }
585
586 }
587
588 /**
589 * add semantic_search javascript libraries to Drupal
590 * */
591 function _semantic_search_load_js_and_css() {
592 global $semantic_search_css_loaded;
593 if (empty ($semantic_search_css_loaded)) {
594 $path = drupal_get_path('module', 'semantic_search');
595 $js_path = $path . '/js';
596 $css_path = $path . '/css';
597 /**
598 * add css
599 * */
600 $css = $css_path . '/semantic_search.css';
601 drupal_add_css($css);
602 $css = $css_path . '/semantic_search_ajax.css';
603 drupal_add_css($css);
604
605 //see http://drupal.org/node/88979
606 // DO NOT USE IN COMBINATION WITH AUTOCOMPLETE.JS
607 // detect if Drupal 5 ?
608 //drupal_add_js($js_path . '/jquery.js');
609 drupal_add_js($js_path . '/jquery_ajax.js');
610
611 //todo dynamically or statically combine these into one file
612 drupal_add_js($js_path . '/semantic_search.contrib.js');
613 drupal_add_js($js_path . '/jquery.history.js');
614 drupal_add_js($js_path . '/jquery.cache.js');
615 drupal_add_js($js_path . '/jquery.hook.js');
616 drupal_add_js($js_path . '/sha1.js');
617 drupal_add_js($js_path . '/semantic_search.helpers.js');
618 drupal_add_js($js_path . '/semantic_search.js');
619
620 if (user_access("administer semantic_search")) {
621 drupal_add_js($js_path . '/semantic_search.admin.js');
622 }
623
624 // now add some constants and configurations set by the server,
625 // but used in the javascript
626 $constants = ' var SEMANTIC_SEARCH_JSRPC_ADMIN_PATH = "' . SEMANTIC_SEARCH_JSRPC_ADMIN_PATH . '"; ';
627 $js_constants = "\n" . '<script type="text/javascript">' . $constants . '</script>' . "\n";
628 drupal_add_js($js_constants,'inline', false, false, false);
629 $semantic_search_css_loaded = true;
630 }
631 }
632
633 /**
634 * provides web based configuration for search facets
635 * */
636 function semantic_search_settings_form() {
637 global $base_url;
638
639 if (!user_access("administer semantic_search")) {
640 return message_admin_access();
641 }
642 _semantic_search_load_js_and_css();
643 _semantic_search_node_index_check();
644
645 $path = drupal_get_path('module', 'semantic_search');
646
647 global $_semantic_search_search;
648 if (empty ($_semantic_search_search))
649 _SEMANTIC_SEARCH_INIT();
650
651 $_semantic_search_search->getAllBaseOptions();
652
653 $form = array();
654
655 $form['install'] = array (
656 '#type' => 'checkbox',
657 '#title' => t('Install SemanticSearch database tables.'),
658 '#description' => t('You may need to install the tables for indexes, caches, and RDF data. <br/> (It is safe to run this after the initial install.)'),
659 '#return_value' => 1,
660 '#default_value' => 0,
661 //TODO detect '#attributes'=>array('disabled'=>'disabled')
662 );
663
664 $form['module_settings'] = array (
665 '#type' => 'fieldset',
666 '#title' => 'Basic Settings',
667 '#description' => t('Settings for All Searches'),
668 '#collapsible' => 1,
669 '#collapsed' => 1
670 );
671
672 /**
673 * base URL should match waht is in settings.php
674 * */
675 $form['module_settings']['_BASE_URL'] = _semantic_search_form_element(
676 '_BASE_URL',
677 'Base Url',
678 'For this site it should be <code >$base_url = '. $base_url.'</code>',
679 $base_url);
680
681 /**
682 * base URI for data specific to the site
683 * */
684 $form['module_settings']['_BASE_NAMESPACE_URL'] = _semantic_search_form_element(
685 '_BASE_NAMESPACE_URL',
686 'Base RDF namespace URI',
687 'The base URI used for the data on this site.',
688 'http://www.ahirc.org');
689
690
691 $form['store'] = array (
692 '#type' => 'fieldset',
693 '#title' => t('<strong>RDF Store Settings</strong>'),
694 '#description' => t('SemanticSearch uses SONIA (Simple Ontology and Inference' .
695 ' Algorithms) as an abstraction layer for for various RDF stores.' .
696 '<br /> There is planned support for RDF stores running remotely, locally, or aggregated from accross sites.'),
697 );
698
699 // $form['store']['default'] = array (
700 // '#type' => 'checkbox',
701 // '#title' => t('Use ARC as defualt store'),
702 // '#return_value' => 1,
703 // '#default_value' => 0,
704 // //TODO detect '#attributes'=>array('disabled'=>'disabled')
705 // );
706 //
707
708 $form['store']['arc_settings'] = array (
709 '#type' => 'fieldset',
710 '#title' => t('ARC Local Settings'),
711 '#description' => t('ARC settings for running ARC locally. <br />' .
712 'ARC is a PHP based RDF store by Benjamin Nowack.'),
713 '#collapsible' => 1,
714 '#collapsed' => 1
715 );
716
717
718 //define('SONIA_DEBUG', true);
719 /* location of an error log */
720 //define('SONIA_ERROR_LOG','/Temp/SONIAERROR.txt');
721 //define('SONIA_WRITE_ARC_LOG', true);
722 //define('SONIA_ARC_LOG_PATH', SONIA_LOCAL_ARC_TOOLS.'/logs/');
723
724 /**
725 * datatabase that ARC uses
726 * */
727 $form['store']['arc_settings']['ARC_DB_NAME'] = _semantic_search_form_element(
728 'ARC_DB_NAME',
729 'DB name',
730 'Name of the Database',
731 '');
732
733 /**
734 * ARC DB username
735 * */
736 $form['store']['arc_settings']['ARC_DB_USER'] = _semantic_search_form_element(
737 'ARC_DB_USER',
738 'DB username',
739 'Database username for establishing a connection',
740 '');
741
742 /**
743 * ARC DB password
744 * */
745 $form['store']['arc_settings']['ARC_DB_PW'] = _semantic_search_form_element(
746 'ARC_DB_PW',
747 'DB Password',
748 'Database password',
749 '');
750
751 /**
752 * ARC DB host
753 * */
754 $form['store']['arc_settings']['ARC_DB_HOST'] = _semantic_search_form_element(
755 'ARC_DB_HOST',
756 'DB host',
757 'Host for the ARC database',
758 'localhost');
759
760 /**
761 * ARC DB port... should be 3306 in most cases
762 * */
763 $form['store']['arc_settings']['ARC_DB_PORT'] = _semantic_search_form_element(
764 'ARC_DB_PORT',
765 'DB Port',
766 'Database Port Number',
767 3306);
768
769 /**
770 * table name prefix to use in case using the same DB which has non - arc tables
771 * */
772 $form['store']['arc_settings']['ARC_DB_PREFIX_NAME'] = _semantic_search_form_element(
773 'ARC_DB_PREFIX_NAME',
774 'ARC Database prefix',
775 'ARC prefixes table names to prevent tablename collision',
776 'semantic_search');
777
778 return system_settings_form($form);
779 }
780
781 /**
782 * catch this settings form and do synchronization
783 * */
784 function semantic_search_settings_form_submit($form_id, $form_values) {
785 system_settings_form_submit($form_id, $form_values);
786 //try to install
787 if ($form_values['install']){
788 require SEMANTIC_SEARCH_LOCATION.'semantic_search.install';
789 semantic_search_install();
790 }
791 return SEMANTIC_SEARCH_ADMIN_HOME.'/config';
792 }
793
794
795 /**
796 * @todo convert to theming function
797 * move this to semantic_search.module as main menu item
798 */
799 function _semantic_search_search($search_form = null) {
800 ////__nsp(' semantic_search.module _semantic_search_search() start');
801 //check to see if this is the url the user intends
802 //only if not RPC
803 _semantic_search_check_redirect();
804 //__nsp(' _semantic_search_search start');
805 global $_semantic_search_search;
806 if (empty ($_semantic_search_search))
807 _SEMANTIC_SEARCH_INIT();
808
809 //dbg($_semantic_search_search->sonia->io->startBuildingCache($_semantic_search_search),'huh?');
810
811 ////__nsp(' semantic_search.module (css start');
812 _semantic_search_load_js_and_css();
813 ////__nsp(' semantic_search.module (css end');
814 $_semantic_search_search_hash = 'all' . $_semantic_search_search->search_hash;
815 //__nsp(' semantic_search.module (cache start');
816 $result = (SONIA_USE_CACHE) ? $_semantic_search_search->sonia->io->getCache($_semantic_search_search_hash) : null;
817 //__nsp(' semantic_search.module theme("cache end');
818 if (SONIA_USE_CACHE && $result !== null) {
819 return $result;
820 } else {
821 //__nsp(' semantic_search.module enter iff');
822 $vars['$do_search$'] = $_semantic_search_search->doSearch();
823 $_semantic_search_search_result_found = $_semantic_search_search->searchResultsFound();
824
825 $pag = $_semantic_search_search->searchPaginaton();
826 $vars['$pagination$'] = theme("semantic_search_search_results_pagination", $pag);
827
828 $vars['$search_results$'] = _semantic_search_SearchResults($_semantic_search_search);
829 //__nsp(' semantic_search.module _semantic_search_search() _semantic_search_SearchResults( end');
830 $vars['$search_jellybean$'] = _semantic_search_SearchNavigation($_semantic_search_search);
831 //__nsp(' semantic_search.module _semantic_search_search() semantic_search_search begin');
832 $vars['$search_form$'] = theme("semantic_search_search", $_semantic_search_search,$search_form);
833 //__nsp(' semantic_search.module theme("semantic_search_search" end');
834 $vars['$search_title$'] = (true) ? t('Search CCK nodes') : '';
835 $vars['$search_results_title$'] = (!$vars['$do_search$']) ? t('Search Results') : $vars['$pagination$'];
836 //dbg($_semantic_search_search_result_found,'$_semantic_search_search_result_found');
837 $vars['$search_results_lower_nav$'] = (!$pag['search_results_success'] && $pag['do_search']) ? '' : $vars['$pagination$'];
838 ////__nsp(' semantic_search.module theme("semantic_search" start');
839 $result = theme("semantic_search", $vars);
840 ////__nsp(' semantic_search.module theme("semantic_search" end');
841
842 if (SONIA_USE_CACHE)
843 $_semantic_search_search->sonia->io->putCache($_semantic_search_search_hash, $result);
844 ////__nsp(' semantic_search.module _semantic_search_search() end');
845 return $result;
846 }
847
848 }
849
850 /**
851 * WARNING
852 * Until this page is only accessed by the proper path this will cause an error on every page
853 *
854 * */
855 function _SEMANTIC_SEARCH_INIT() {
856 //the search object
857 global $_semantic_search_search;
858 //a setting
859 global $use_search_cache;
860 $use_search_cache = variable_get('semantic_search_search_unset', '1');
861
862 db_set_active('arc');
863 $_semantic_search_search = new NinaSearch(); //from semantic_search.inc
864 db_set_active('default');
865 return '';
866 }
867
868 /**
869 * function for constructing search navigation display
870 * */
871 function _semantic_search_SearchNavigation(& $_semantic_search_search, $not_rpc = true, $toggle = true, $extra = null) {
872 $html = '';
873
874 if (is_object($_semantic_search_search)) {
875 db_set_active('arc');
876 $data = $_semantic_search_search->jellyBean($not_rpc, $toggle, $extra);
877 db_set_active('default');
878 }
879 return theme("semantic_search_navigation", $data);
880 }
881
882 /**
883 * wrapper for the drupal function
884 * adds some extra fields
885 * */
886 function _semantic_search_form_render($form) {
887
888 return drupal_get_form('_semantic_search_form_render_form', $form);
889 }
890
891 function _semantic_search_form_render_form($form){
892 global $_semantic_search_search;
893 if (empty ($_semantic_search_search))
894 _SEMANTIC_SEARCH_INIT();
895
896 $form['#action'] = $_semantic_search_search->makefullURLforRedirect();
897 return $form;
898 }
899
900
901 /**
902 * displays search results
903 * */
904 function _semantic_search_SearchResults(& $_semantic_search_search, $not_rpc = true) {
905 $html = '';
906 // dbg($_semantic_search_search->searchResults($not_rpc));
907 if (is_object($_semantic_search_search)) {
908 db_set_active('arc');
909 $html .= theme("semantic_search_search_results", $_semantic_search_search->searchResults($not_rpc));
910 db_set_active('default');
911 return $html;
912 }
913 } // _SearchResults();
914
915 /**
916 * @todo drupal specific configurations
917 * */
918 function semantic_search_configure() {
919 if (!user_access("configure semantic_search")) {
920 return message_admin_access();
921 }
922
923 return system_settings_form('menu_configure', $form);
924 }
925
926 /**
927 * any form based validation to do
928 * */
929 function _SEMANTIC_SEARCHSearch_validate($form_id, $form_values) {
930
931 }
932
933 /**
934 * catch this form and prevent a redirect
935 *
936 * @return false don't redirect
937 *
938 * */
939 function _SEMANTIC_SEARCHSearch_submit($form_id, $form_values) {
940 return false;
941 }
942
943 /**
944 * default admin function
945 * */
946 function _semantic_search_admin_semantic_search(){
947 $output = t('');
948
949 return $output;
950 }
951
952 function _semantic_search_check() {
953 global $_semantic_search_search;
954 if (empty ($_semantic_search_search))
955 _SEMANTIC_SEARCH_INIT();
956 return $_semantic_search_search;
957 }

  ViewVC Help
Powered by ViewVC 1.1.2