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

Diff of /contributions/modules/search404/search404.module

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

revision 1.15.2.11, Mon Jun 15 08:23:54 2009 UTC revision 1.15.2.12, Fri Jun 26 10:47:06 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: search404.module,v 1.15.2.6 2009/01/19 06:39:00 zyxware Exp $ */  /* $Id: search404.module,v 1.15.2.11 2009/06/15 08:23:54 zyxware Exp $ */
3  /**  /**
4   * Implementation of hook_menu().   * Implementation of hook_menu().
5   */   */
# Line 112  function search404_page() { Line 112  function search404_page() {
112      }      }
113      if ($keys) {      if ($keys) {
114        // TODO: watchdog?        // TODO: watchdog?
115        $results = module_invoke($type_search, 'search', 'search', $keys);        if (module_exists('google') && user_access('search Google CSE') && variable_get('search404_do_google_cse', false)) {
116        if (isset($results) && is_array($results) && count($results) == 1 && variable_get('search404_jump', false)) {          drupal_set_message(t('The page you requested does not exist. For your convenience, a google search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
117          // First, check to see if there is exactly 1 result          drupal_goto ('search/google/'. $keys);
118          drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');        } else {
119          // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()          $results = module_invoke($type_search, 'search', 'search', $keys);
120          $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;          if (isset($results) && is_array($results) && count($results) == 1 && variable_get('search404_jump', false)) {
121          drupal_goto();            // First, check to see if there is exactly 1 result
122        }            drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
123        elseif (isset($results) && is_array($results) && count($results) > 1 && variable_get('search404_first', false)) {            // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
124          drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');            $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;
125          // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()            drupal_goto();
126          $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;          }
127          drupal_goto();          elseif (isset($results) && is_array($results) && count($results) > 1 && variable_get('search404_first', false)) {
128        }            drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
129        else {            // overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
130          drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');            $_REQUEST['destination'] = 'node/'. $results[0]['node']->nid;
131          if (isset($results) && is_array($results) && count($results) > 0) {            drupal_goto();
           drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);  
           // EVIL HAXX!  
             $oldgetq = $_GET['q'];  
             $olddestination = $_REQUEST['destination'];  
             unset($_REQUEST['destination']);  
             $_GET['q'] = "search/$type_search/$keys";  
             $results = theme('search_results', $results, 'node');  
             $_GET['q'] = $oldgetq;  
             $_REQUEST['destination'] = $olddestination;  
           // END OF EVIL HAXX!  
132          }          }
133          else {          else {
134            $results = search_help('search#noresults', drupal_help_arg());            drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
135              if (isset($results) && is_array($results) && count($results) > 0) {
136                drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);
137                // EVIL HAXX!
138                  $oldgetq = $_GET['q'];
139                  $olddestination = $_REQUEST['destination'];
140                  unset($_REQUEST['destination']);
141                  $_GET['q'] = "search/$type_search/$keys";
142                  $results = theme('search_results', $results, 'node');
143                  $_GET['q'] = $oldgetq;
144                  $_REQUEST['destination'] = $olddestination;
145                // END OF EVIL HAXX!
146              }
147              else {
148                $results = search_help('search#noresults', drupal_help_arg());
149              }
150              $results = theme('box', t('Search results'), $results);
151          }          }
         $results = theme('box', t('Search results'), $results);  
152        }        }
153      }      }
154      // Construct the search form.      // Construct the search form.
# Line 188  function search404_settings() { Line 193  function search404_settings() {
193      '#title' => t('Show left and right sidebars in page when a 404 search occurs'),      '#title' => t('Show left and right sidebars in page when a 404 search occurs'),
194      '#default_value' => variable_get('search404_block_show', false),      '#default_value' => variable_get('search404_block_show', false),
195    );    );
196    
197      $form['search404_do_google_cse'] = array(
198        '#type' => 'checkbox',
199        '#title' => t('Do a Google CSE Search instead of a Drupal Search when a 404 Occurs'),
200        '#description' => t('Requires Google CSE and Google CSE Search Modules to be Enabled'),
201        '#attributes' => module_exists('google') ? array()  : array ('disabled' => 'disabled'),
202        '#default_value' => variable_get('search404_do_google_cse', false),
203      );
204    
205    $form['advanced'] = array(    $form['advanced'] = array(
206      '#type' => 'fieldset',      '#type' => 'fieldset',
207      '#title' => t('Advanced settings'),      '#title' => t('Advanced settings'),

Legend:
Removed from v.1.15.2.11  
changed lines
  Added in v.1.15.2.12

  ViewVC Help
Powered by ViewVC 1.1.2