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

Diff of /contributions/modules/dynosearcho/dynosearcho.module

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

revision 1.5, Mon Nov 10 21:29:29 2008 UTC revision 1.5.2.1, Fri Mar 13 16:33:22 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: dynosearcho.module,v 1.2 2008/01/20 17:19:43 ultimike Exp $  // $Id: dynosearcho.module,v 1.1 2008/12/28 14:10:02 manello Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 11  Line 11 
11   * can be configured to display a configurable number of results from specific node types.   * can be configured to display a configurable number of results from specific node types.
12   */   */
13    
 // TODO: add ability to search users  
14  // add optional datetime to results  // add optional datetime to results
15    
16  /**  /**
17   * Implementation of hook_help   * Implementation of hook_help
18   */   */
19  function dynosearcho_help($section) {  function dynosearcho_help($path, $arg) {
20    switch ($section) {    switch ($path) {
21      case 'admin/modules#description':      case 'admin/modules#description':
22        return t('DynoSearcho provides a dynamic (AHAH) way to search for content by title and tags.');        return t('DynoSearcho provides a dynamic (AHAH) way to search for content by title and tags.');
23      case 'admin/help#dynosearcho':      case 'admin/help#dynosearcho':
# Line 54  present and the search results are shown Line 53  present and the search results are shown
53  /**  /**
54   * Implementation of hook_menu   * Implementation of hook_menu
55   */   */
56  function dynosearcho_menu($may_cache) {  function dynosearcho_menu() {
57    $items = array();    $items = array();
58      $items['admin/settings/dynosearcho'] = array(
59    if ($may_cache) {      'title' => 'DynoSearcho',
60      $items[] = array(      'description' => 'Defines the settings for DynoSearcho',
61          'title' => 'DynoSearcho',      'page callback' => 'drupal_get_form',
62          'description' => 'Defines the settings for DynoSearcho',      'page arguments' => array('_dynosearcho_settings'),
63          'path' => 'admin/settings/dynosearcho',      'access callback' => 'user_access',
64          'callback' => 'drupal_get_form',      'access arguments' => array('administer site configuration'),
65          'callback arguments' => array('_dynosearcho_settings'),      'type' => MENU_NORMAL_ITEM,
66          'access' => user_access('administer site configuration'),    );
67          'type' => MENU_NORMAL_ITEM,    $items['dynosearcho'] = array(
68      );      'description' => 'Perform a DynoSearch search.',
69    }      'page callback' => 'drupal_get_form',
70    else {      'page arguments' => array('dynosearcho_dosearch'),
71      $items[] = array(      'access callback' => 'user_access',
72          'description' => 'Perform a DynoSearch search.',      'access arguments' => array('access content'),
73          'path' => 'dynosearcho',      'type' => MENU_NORMAL_ITEM,
74          'callback' => 'dynosearcho_dosearch',    );
         'callback arguments' => array(arg(1), arg(2), arg(3)),  
         'access' => user_access('access content'),  
         'type' => MENU_CALLBACK  
     );  
   }  
75    return $items;    return $items;
76  }  }
77    
# Line 113  function dynosearcho_block($op = 'list', Line 107  function dynosearcho_block($op = 'list',
107      variable_set('dynosearcho_use_og_desc_'. $delta, $edit['use_og_desc']);      variable_set('dynosearcho_use_og_desc_'. $delta, $edit['use_og_desc']);
108      variable_set('dynosearcho_no_results_'. $delta, $edit['no_results']);      variable_set('dynosearcho_no_results_'. $delta, $edit['no_results']);
109      variable_set('dynosearcho_header_'. $delta, $edit['header']);      variable_set('dynosearcho_header_'. $delta, $edit['header']);
110      variable_set('dynosearcho_display_menu_paths_'. $delta, $edit['display_menu_paths']);      variable_set('dynosearcho_sort_by_login_'. $delta, $edit['sort_by_login']);
111      variable_set('dynosearcho_search_type_'. $delta, $edit['search_type']);      variable_set('dynosearcho_search_type_'. $delta, $edit['search_type']);
112      variable_set('dynosearcho_integrated_search_'. $delta, $edit['integrated_search']);      variable_set('dynosearcho_integrated_search_'. $delta, $edit['integrated_search']);
113      return;      return;
# Line 157  function dynosearcho_block_settings_form Line 151  function dynosearcho_block_settings_form
151    
152    if (!module_exists('search')) {    if (!module_exists('search')) {
153      $form['integrated_search']['#value'] = 0;      $form['integrated_search']['#value'] = 0;
154      $form['integrated_search']['#disabled'] = true;      $form['integrated_search']['#disabled'] = TRUE;
155      $form['integrated_search']['#description'] = t('The search module must be enabled for this option to be available.');      $form['integrated_search']['#description'] = t('The search module must be enabled for this option to be available.');
156    }    }
157    
# Line 187  function dynosearcho_block_settings_form Line 181  function dynosearcho_block_settings_form
181    
182    $form['search_type'] = array(    $form['search_type'] = array(
183      '#type' => 'radios',      '#type' => 'radios',
184      '#title' => t('Search Type'),      '#title' => t('Search type'),
185      '#default_value' => variable_get('dynosearcho_search_type_'. $delta, 'node'),      '#default_value' => variable_get('dynosearcho_search_type_'. $delta, 'node'),
186      '#options' => array(      '#options' => array(
187                      'node' => t('node'),        'node' => t('node'),
188                      'menu' => t('menu')        'user' => t('user')
189                    ),      ),
190      '#description' => t('Select the type of search this DynoSearcho block will perform.'),      '#description' => t('Select the type of search this DynoSearcho block will perform.'),
191      '#attributes' => array('class' => 'dynosearcho_searchtype'),      '#attributes' => array('class' => 'dynosearcho-searchtype'),
192    );    );
193    
194    $form['node_search'] = array(    $form['node_search'] = array(
195      '#type' => 'fieldset',      '#type' => 'fieldset',
196      '#title' => 'Node Search Settings',      '#title' => 'Node search settings',
197      '#description' => t('These settings only apply if searching for nodes.'),      '#description' => t('These settings only apply if searching for nodes.'),
198      '#collapsible' => false,      '#collapsible' => FALSE,
199      '#attributes' => array('id' => 'dynosearcho_nodesearch'),      '#attributes' => array('id' => 'dynosearcho-nodesearch'),
200    );    );
201    
202    $form['node_search']['searchable_node_types'] = array(    $form['node_search']['searchable_node_types'] = array(
# Line 256  function dynosearcho_block_settings_form Line 250  function dynosearcho_block_settings_form
250      '#description' => t('This will replace the teaser text with the Organic Groups description. <strong>This should only be checked if the DynoSearcho box is only going to be searching groups.</strong>'),      '#description' => t('This will replace the teaser text with the Organic Groups description. <strong>This should only be checked if the DynoSearcho box is only going to be searching groups.</strong>'),
251    );    );
252    
253    $form['menu_search'] = array(    $form['user_search'] = array(
254      '#type' => 'fieldset',      '#type' => 'fieldset',
255      '#title' => 'Menu Search Settings',      '#title' => 'User search settings',
256      '#description' => t('These settings only apply if searching for menu items.'),      '#description' => t('These settings only apply if searching for site users.'),
257      '#collapsible' => false,      '#collapsible' => FALSE,
258      '#attributes' => array('id' => 'dynosearcho_menusearch'),      '#attributes' => array('id' => 'dynosearcho-usersearch'),
259    );    );
260    
261    $form['menu_search']['display_menu_paths'] = array(    $form['user_search']['sort_by_login'] = array(
262      '#type' => 'checkbox',      '#type' => 'checkbox',
263      '#title' => t('Display menu paths in results'),      '#title' => t('Sort users by last login'),
264      '#default_value' => variable_get('dynosearcho_display_menu_paths_'. $delta, '1'),      '#default_value' => variable_get('dynosearcho_sort_by_login_'. $delta, '0'),
265      '#description' => t('If selected, the menu path will be displayed along with the menu title.'),      '#description' => t('If selected, users will be sorted by last login instead of alphabetically.'),
266    );    );
267    
268    return $form;    return $form;
269  }  }
270    
271    
272  function _dynosearcho_settings() {  function _dynosearcho_settings() {
273    $form['dynosearcho_number_of_blocks'] = array(    $form['dynosearcho_number_of_blocks'] = array(
274      '#type' => 'textfield',      '#type' => 'textfield',
# Line 285  function _dynosearcho_settings() { Line 281  function _dynosearcho_settings() {
281    return system_settings_form($form);    return system_settings_form($form);
282  }  }
283    
284  function dynosearcho_search_form($delta, $matches = NULL) {  function dynosearcho_search_form(&$form_state, $delta, $matches = NULL) {
285    drupal_add_js(drupal_get_path('module', 'dynosearcho') .'/dynosearcho.js');    drupal_add_js(drupal_get_path('module', 'dynosearcho') .'/dynosearcho.js');
286    drupal_add_css(drupal_get_path('module', 'dynosearcho') .'/dynosearcho.css');    drupal_add_css(drupal_get_path('module', 'dynosearcho') .'/dynosearcho.css');
287    
288    $form['#id'] = 'dynosearcho_search_form_' . $delta;    $form = array();
289      $form['#id'] = 'dynosearcho_search_form_'. $delta;
290    $form['#attributes'] = array('class' => 'dynosearcho');    $form['#attributes'] = array('class' => 'dynosearcho');
291    
292    if (variable_get('dynosearcho_integrated_search_'. $delta, '0')) {    if (module_exists('search')) {
293      $form['dynosearcho_integrated_search_'. $delta] = array(      if (variable_get('dynosearcho_integrated_search_'. $delta, '1')) {
294        '#type' => 'hidden',        $form['dynosearcho_integrated_search_'. $delta] = array(
295        '#value' => 1,          '#type' => 'hidden',
296      );          '#value' => 1,
297          );
298        }
299        else {
300          $form['dynosearcho_integrated_search_'. $delta] = array(
301            '#type' => 'hidden',
302            '#value' => 0,
303          );
304        }
305    }    }
   if (!module_exists('search')) $form['dynosearcho_integrated_search_'. $delta]['#value'] = 0;  
306    
307    $form['header'] = array(    $form['header'] = array(
308      '#value' => variable_get('dynosearcho_header_'. $delta, 'Enter keywords to begin.'),      '#value' => variable_get('dynosearcho_header_'. $delta, 'Enter keywords to begin.'),
309    );    );
310    
   if ((arg(0) == 'dynosearcho') && (arg(3) == '1')) {  
     $default_value = arg(2);  
   }  
311    $form['dynosearcho_search_'. $delta] = array(    $form['dynosearcho_search_'. $delta] = array(
312      '#type' => 'textfield',      '#type' => 'textfield',
313      '#title' => variable_get('dynosearcho_search_box_title_'. $delta, 'Keywords'),      '#title' => variable_get('dynosearcho_search_box_title_'. $delta, 'Keywords'),
314      '#description' => t('Use commas to separate multiple keywords.'),      '#description' => t('Use commas to separate multiple keywords.'),
315      '#maxlength' => 60,      '#maxlength' => 60,
316        '#default_value' => '', // seems like required to set it to something, otherwise there's ahah error sometimes with integrated search on (i.e. no path)
317      '#size' => 10,      '#size' => 10,
318      '#default_value' => $default_value,      '#attributes' => array('class' => 'dynosearcho-searchbox'),
     '#attributes' => array('class' => 'dynosearcho_searchbox'),  
319    );    );
320    
321    $form['dynosearcho_delta'] = array(    $form['dynosearcho_exp_'. $delta] = array(
     '#type' => 'hidden',  
     '#value' => $delta,  
   );  
   
   $form['dynosearcho_url_'. $delta] = array(  
322      '#type' => 'hidden',      '#type' => 'hidden',
323      '#value' => url('dynosearcho'),      '#ahah' => array(
324          'path' => 'dynosearcho',
325          'wrapper' => 'dynosearcho-results-'. $delta,
326          'method' => 'replace',
327          'effect' => 'fade',
328          'event' => 'blur',
329        ),
330    );    );
331    
332    $form['dynosearcho_basepath_'. $delta] = array(    $form['dynosearcho_delta'] = array(
333      '#type' => 'hidden',      '#type' => 'hidden',
334      '#value' => base_path(),      '#value' => $delta,
335      '#attributes' => array('class' => 'dynosearcho_basepath'),      '#maxlength' => 60,
336    );      '#size' => 10,
   
   $form['dynosearcho_results_' . $delta] = array(  
     '#value' => '<div class="dynosearcho_results" id="dynosearcho_results_' . $delta . '">' . $matches . '</div>',  
337    );    );
338    
339    $form['submit'] = array(    $form['submit'] = array(
340      '#type' => 'submit',      '#type' => 'submit',
341      '#value' => t('Search')      '#value' => t('Search'),
342        '#attributes' => array('class' => 'no-js'),
343      );
344    
345      $form['dynosearcho_results_'. $delta] = array(
346        '#type' => 'markup',
347        '#prefix' => '<div id="dynosearcho-results-'. $delta .'">',
348        '#suffix' => '</div>',
349        '#value' => ' ',
350    );    );
351    
352    return $form;    return $form;
353  }  }
354    
355  function dynosearcho_search_form_submit($form_id, $form_values) {  function dynosearcho_search_form_submit($form, &$form_state) {
356    //echo 'form_id: ' . $form_id . '<br/>';    $search_type = variable_get('dynosearcho_search_type_'. $form_state['values']['dynosearcho_delta'], 'node');
357    //print_r($form_values);exit;    $form_state['redirect'] = 'search/'. $search_type .'/'. $form_state['values']['dynosearcho_search_'. $form_state['values']['dynosearcho_delta']];
   return 'dynosearcho/'. $form_values['dynosearcho_delta'] .'/'. $form_values['dynosearcho_search_'. $form_values['dynosearcho_delta']] .'/1';  
358  }  }
359    
360  function dynosearcho_dosearch($delta = 0, $string, $whole_page = false) {  function dynosearcho_dosearch() {
361    // separate out multiple keywords if necessary    $form_state = array('values' => $_POST);
362    $keywords = explode(',', $string);    $delta = check_plain($form_state['values']['dynosearcho_delta']);
363      $string = check_plain($form_state['values']['dynosearcho_search_'. $delta]);
364      $keywords = explode(', ', $string);
365      $whole_page = FALSE;
366    switch (variable_get('dynosearcho_search_type_'. $delta, 'node')) {    switch (variable_get('dynosearcho_search_type_'. $delta, 'node')) {
367      case 'node':      case 'node':
368        return dynosearcho_nodesearch($delta, $keywords, $whole_page);        $output = dynosearcho_nodesearch($delta, $keywords, $whole_page);
369        break;      break;
370      case 'menu':      case 'user':
371        return dynosearcho_menusearch($delta, $keywords, $whole_page);        $output = dynosearcho_usersearch($delta, $keywords, $whole_page);
372        break;        break;
373    }    }
374      print drupal_to_js(array('data' => $output, 'status' => true));
375      exit();
376  }  }
377    
 function _dynosearcho_menu_search_preg($find, $in_array, $keys_found) {  
   if (is_array($in_array)) {  
     $theitem = $in_array;  
     foreach ($in_array as $key => $val) {  
       if (is_array($val)) {  
         $keys_found = _dynosearcho_menu_search_preg($find, $val, $keys_found);  
       }  
       else {  
         if (preg_match('/'. $find .'/i', $val)) {  
           $keys_found[] = $theitem;  
         }  
       }  
     }  
     return $keys_found;  
   }  
   return $keys_found;  
 }  
378    
379  //----- Thanks to a.fotoglidis (http://us2.php.net/manual/en/function.array-unique.php#68339) for this function  function dynosearcho_usersearch($delta, $keywords, $whole_page) {
380  function _dynosearcho_menu_elim_dups($array, $row_element) {    if (!user_access('access user profiles')) {
381    $new_array[0] = $array[0];      return '<span class="dynosearcho-info dynosearcho-message">'. t('You are not authorized to search users') .'</span>';
382    foreach ($array as $current) {    }
383      $add_flag = 1;    else {
384      foreach ($new_array as $tmp) {      $matches = array();
385        if ($current[$row_element]==$tmp[$row_element]) {      if (variable_get('dynosearcho_sort_by_login_'. $delta, '1')) {
386          $add_flag = 0; break;        $sort = "3 DESC";
387        }
388        else {
389          $sort = "1 ASC";
390        }
391        $sql = "SELECT name, mail, login FROM {users} WHERE (name LIKE '%%%s%%' OR mail LIKE '%%%s%%') ORDER BY ". $sort;
392        foreach ($keywords as $keyword) {
393          $keyword = trim($keyword);
394          $result = db_query($sql, $keyword, $keyword);
395          while ($user = db_fetch_object($result)) {
396            $matches[] = l($user->name, 'user/'. $user->uid) .' ['. l($user->mail, 'mailto:'. $user->mail) .']';
397        }        }
398      }      }
399      if ($add_flag) $new_array[] = $current;      $total_matches = count($matches);
400    }      $array_temp = array_chunk($matches, variable_get('dynosearcho_block_results_returned_'. $delta, '10'), FALSE);
401    return $new_array;      $matches = $array_temp[0];
402  }      $array_text = array();
403        if ($total_matches > variable_get('dynosearcho_block_results_returned_'. $delta, '10')) {
404  function dynosearcho_menusearch($delta, $keywords, $whole_page) {        $temp = variable_get('dynosearcho_results_info_text_'. $delta, '%totalmatches total matches available, only top %resultsreturned results displayed. Enter additional keywords to narrow down search.');
405    // build one query for each keyword, then run and merge the results        $variables = array(
406    $rawmatches = array();          '%totalmatches' => $total_matches,
407            '%resultsreturned' => variable_get('dynosearcho_block_results_returned_'. $delta, '10'),
408    $menu = menu_get_menu();        );
409          $array_text['title'] = '<span class="dynosearcho-info">'. strtr($temp, $variables) .'</span>';
410    foreach ($keywords as $keyword) {        $matches[] = $array_text;
411      $keyword = trim($keyword);      }
412      $rawmatches = _dynosearcho_menu_search_preg($keyword, $menu['visible'], $rawmatches);      if (!$whole_page) {
413    }        return theme('item_list', $matches, NULL, 'ul', array('id' => 'dynosearcho-user-search', 'class' => 'dynosearcho'));
414    $rawmatches = _dynosearcho_menu_elim_dups($rawmatches, 'path');      }
415        else {
416    $matches = array();        $output = theme('dynosearcho_results', $matches);
417    foreach ($rawmatches as $match) {        return drupal_get_form('dynosearcho_search_form', $delta, $output);
     $item = array();  
     $item['title'] = l($match['title'], $match['path']);  
     if (variable_get('dynosearcho_display_menu_paths_'. $delta, '1')) {  
       $item['teaser'] = $match['path'];  
     }  
     $matches[] = $item;  
   }  
   
   //----- get the total number of matches for display  
   $total_matches = count($matches);  
   // only return the desired number of matches - this has to be done here and not with db_query_range because of array_intersect_key stuff  
   $array_temp = array_chunk($matches, variable_get('dynosearcho_block_results_returned_'. $delta, '10'), true);  
   $matches = $array_temp[0];  
   $array_text = array();  
   if ($total_matches > variable_get('dynosearcho_block_results_returned_'. $delta, '10')) {  
     $temp = variable_get('dynosearcho_results_info_text_'. $delta, '%totalmatches total matches available, only top %resultsreturned results displayed. Enter additional keywords to narrow down search.');  
     $variables = array(  
       '%totalmatches' => $total_matches,  
       '%resultsreturned' => variable_get('dynosearcho_block_results_returned_'. $delta, '10'),  
     );  
     $array_text['title'] = '<span class="dynosearcho_info">'. strtr($temp, $variables) .'</span>';  
     $matches[] = $array_text;  
   }  
   
   if (!$whole_page) {  
     $jsoutput = array();  
     foreach ($matches as $match) {  
       $jsoutput[] = theme('dynosearcho_menu_results_item', $match);  
418      }      }
     print drupal_to_js($jsoutput);  
     exit();  
   }  
   else {  
     $output = theme('dynosearcho_results', $matches);  
     return drupal_get_form('dynosearcho_search_form', $delta, $output);  
419    }    }
420  }  }
421    
# Line 458  function dynosearcho_nodesearch($delta, Line 427  function dynosearcho_nodesearch($delta,
427        $str_types_esc[$key] = "'". db_escape_string($value) ."'";        $str_types_esc[$key] = "'". db_escape_string($value) ."'";
428      }      }
429    }    }
430     // build one query for each keyword, then run and merge the results
   // build one query for each keyword, then run and merge the results  
431    $matches = array();    $matches = array();
432    if (user_access('access content')) {    if (user_access('access content')) {
433      $sql = "SELECT DISTINCT n.nid, n.changed, r.format, ";      $sql = "SELECT DISTINCT n.nid, n.changed, ";
434      if (variable_get('dynosearcho_display_relevant_tags_'. $delta, '1')) {      if (variable_get('dynosearcho_display_relevant_tags_'. $delta, '1')) {
435        $sql .= "td.name, ";        $sql .= "td.name, ";
436      }      }
437      if (variable_get('dynosearcho_teaser_length_'. $delta, '0')) {      if (variable_get('dynosearcho_teaser_length_'. $delta, '0')) {
438        // borrowed the teaser trimming code from node.module        // borrowed the teaser trimming code from node.module
439        $breakpoints = array('</p>' => 4, '<br />' => 0, '<br>' => 0, "\n" => 0, '. ' => 1, '! ' => 1, '? ' => 1, '。' => 3, '؟ ' => 1);        $breakpoints = array('</p>' => 4, '<br />' => 0, '<br>' => 0, "\n" => 0, '. ' => 1, '! ' => 1, '? ' => 1);
440        if (variable_get('dynosearcho_use_og_desc_'. $delta, '0')) {        if (variable_get('dynosearcho_use_og_desc_'. $delta, '0')) {
441          $sql .= "og.description AS teaser, ";          $sql .= "og.description AS teaser, ";
442        }        }
# Line 477  function dynosearcho_nodesearch($delta, Line 445  function dynosearcho_nodesearch($delta,
445        }        }
446      }      }
447      $sql .= "n.title FROM {node} n ";      $sql .= "n.title FROM {node} n ";
448      $sql .= "LEFT JOIN {node_revisions} r ON n.vid=r.vid ";      if (variable_get('dynosearcho_teaser_length_'. $delta, '0')) {
449          $sql .= "LEFT JOIN {node_revisions} r ON n.vid=r.vid ";
450        }
451      if (variable_get('dynosearcho_use_og_desc_'. $delta, '0')) {      if (variable_get('dynosearcho_use_og_desc_'. $delta, '0')) {
452        $sql .= "LEFT JOIN {og} og ON n.nid=og.nid ";        $sql .= "LEFT JOIN {og} og ON n.nid=og.nid ";
453      }      }
# Line 488  function dynosearcho_nodesearch($delta, Line 458  function dynosearcho_nodesearch($delta,
458        $result = db_query(db_rewrite_sql($sql), $keyword, $keyword);        $result = db_query(db_rewrite_sql($sql), $keyword, $keyword);
459        while ($node = db_fetch_object($result)) {        while ($node = db_fetch_object($result)) {
460          $item = array();          $item = array();
         $item['node'] = $node;  
461          $item['title'] = l($node->title, 'node/'. $node->nid);          $item['title'] = l($node->title, 'node/'. $node->nid);
462          if (variable_get('dynosearcho_display_edit_links_'. $delta, '0') &&          if (variable_get('dynosearcho_display_edit_links_'. $delta, '0') && (user_access('administer_nodes'))) {
463             (user_access('administer_nodes'))) {            $item['editlink'] .= l('edit', 'node/'. $node->nid .'/edit');
           $item['editlink'] .= l('edit', 'node/'. $node->nid . '/edit');  
464          }          }
465          $item['moddate'] = $node->changed;          $item['moddate'] = $node->changed;
466          if (variable_get('dynosearcho_display_relevant_tags_'. $delta, '1')) {          if (variable_get('dynosearcho_display_relevant_tags_'. $delta, '1')) {
# Line 509  function dynosearcho_nodesearch($delta, Line 477  function dynosearcho_nodesearch($delta,
477                }                }
478              }              }
479            }            }
480            $item['teaser'] = check_markup($node->teaser, $node->format, FALSE);            $item['teaser'] = $node->teaser;
481          }          }
482          $tempmatches[$node->nid] = $item;          // provide node object for extended theming
483            $item['node'] = $node;
484    
485            //$tempmatches = [$node->nid] = $item;
486            $matches[$node->nid] = $item;
487        }        }
488        // this effectively provides the logical "and" for multiple keywords        // this effectively provides the logical "and" for multiple keywords
489        if (count($matches)) {        // This Wasn't working for me, now works ! Please check what's going on ...
490         /* if (count($matches)) {
491          $matches = array_intersect_key($matches, $tempmatches);          $matches = array_intersect_key($matches, $tempmatches);
492        }        }else{
       else {  
493          $matches = $tempmatches;          $matches = $tempmatches;
494        }        }
495          */
496        // this sorts the matches        // this sorts the matches
497        if (variable_get('dynosearcho_sort_by_date_'. $delta, '0')) {        if (variable_get('dynosearcho_sort_by_date_'. $delta, '0')) {
498          uasort($matches, "_dynosearcho_datemod_compare");          uasort($matches, "_dynosearcho_datemod_compare");
# Line 531  function dynosearcho_nodesearch($delta, Line 504  function dynosearcho_nodesearch($delta,
504        //----- get the total number of matches for display        //----- get the total number of matches for display
505        $total_matches = count($matches);        $total_matches = count($matches);
506        // only return the desired number of matches - this has to be done here and not with db_query_range because of array_intersect_key stuff        // only return the desired number of matches - this has to be done here and not with db_query_range because of array_intersect_key stuff
507        $array_temp = array_chunk($matches, variable_get('dynosearcho_block_results_returned_'. $delta, '10'), true);        $array_temp = array_chunk($matches, variable_get('dynosearcho_block_results_returned_'. $delta, '10'), TRUE);
508        $matches = $array_temp[0];        $matches = $array_temp[0];
509        $array_text = array();        $array_text = array();
510        if ($total_matches > variable_get('dynosearcho_block_results_returned_'. $delta, '10')) {        if ($total_matches > variable_get('dynosearcho_block_results_returned_'. $delta, '10')) {
# Line 547  function dynosearcho_nodesearch($delta, Line 520  function dynosearcho_nodesearch($delta,
520    }    }
521    if (gettype($matches) == 'NULL' || !count($matches)) {    if (gettype($matches) == 'NULL' || !count($matches)) {
522      $array_text = array();      $array_text = array();
523      $array_text['title'] = '<span class="dynosearcho_info dynosearcho_message">'. variable_get('dynosearcho_no_results_'. $delta, 'Your search parameters did not return any results.') .'</span>';      $array_text['title'] = '<span class="dynosearcho-info dynosearcho-message">'. variable_get('dynosearcho_no_results_'. $delta, 'Your search parameters did not return any results.') .'</span>';
524      $matches[] = $array_text;      $matches[] = $array_text;
525    }    }
526    if (!$whole_page) {    if (!$whole_page) {
527      $jsoutput = array();      $output = '';
528      foreach ($matches as $match) {      foreach ($matches as $match) {
529        $jsoutput[] = theme('dynosearcho_results_item', $match);        $output .= theme('dynosearcho_results_item', $match);
530      }      }
531      print drupal_to_js($jsoutput);      return $output;
     exit();  
532    }    }
533    else {    else {
534      $output = theme('dynosearcho_results', $matches);      $output = theme('dynosearcho_results', $matches);
# Line 571  function _dynosearcho_datemod_compare($a Line 543  function _dynosearcho_datemod_compare($a
543      return ($a['moddate'] > $b['moddate']) ? -1 : 1;      return ($a['moddate'] > $b['moddate']) ? -1 : 1;
544  }  }
545    
546    function dynosearcho_theme() {
547      return array(
548        'dynosearcho_results' => array(
549          'arguments' => array('items' => NULL),
550        ),
551        'dynosearcho_results_item' => array(
552          'arguments' => array('item' => NULL),
553        ),
554        'dynosearcho_menu_results_item' => array(
555          'arguments' => array('item' => NULL),
556        ),
557      );
558    }
559  function theme_dynosearcho_results($items) {  function theme_dynosearcho_results($items) {
560    $output = "<ul>";    $output = '<ul>';
561    foreach ($items as $item) {    foreach ($items as $item) {
562      $output .= '<li>';      $output .= '<li>';
563      $output .= theme('dynosearcho_results_item', $item);      $output .= theme('dynosearcho_results_item', $item);
# Line 581  function theme_dynosearcho_results($item Line 566  function theme_dynosearcho_results($item
566    $output .= '<ul>';    $output .= '<ul>';
567    return $output;    return $output;
568  }  }
   
569  function theme_dynosearcho_results_item($item) {  function theme_dynosearcho_results_item($item) {
570    $output = $item['title'];    $output = '<div class="dynosearcho-result">'. $item['title'];
571    if ($item['editlink']) $output .= ' - <span class="dynosearcho_editlink">'. $item['editlink'] .'</span>';    if ($item['editlink']) $output .= ' - <span class="dynosearcho-editlink">'. $item['editlink'] .'</span>';
572    if ($item['tag']) $output .= ' - <span class="dynosearcho_reltag">Relevant Tag: '. $item['tag'] .'</span>';    if ($item['tag']) $output .= ' - <span class="dynosearcho-reltag">Relevant Tag: '. $item['tag'] .'</span>';
573    if ($item['teaser']) $output .= ' - <span class="dynosearcho_teaser">'. $item['teaser'] .'</span>';    if ($item['teaser']) $output .= ' - <span class="dynosearcho-teaser">'. $item['teaser'] .'</span>';
574    return html_entity_decode($output);    $output .= '</div>';
 }  
   
 function theme_dynosearcho_menu_results_item($item) {  
   $output = $item['title'];  
   if ($item['teaser']) $output .= '<br/><span class="dynosearcho_teaser">'. $item['teaser'] .'</span>';  
575    return html_entity_decode($output);    return html_entity_decode($output);
576  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

  ViewVC Help
Powered by ViewVC 1.1.2