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

Diff of /contributions/modules/serapi/serapi.module

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

revision 1.3, Wed Nov 5 10:10:33 2008 UTC revision 1.4, Wed Nov 5 10:38:04 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: serapi.module,v 1.2 2008/11/05 09:00:03 yaph Exp $  // $Id: serapi.module,v 1.3 2008/11/05 10:10:33 yaph Exp $
3  error_reporting(E_ALL);  error_reporting(E_ALL);
4    
5  /**  /**
# Line 16  function serapi_get_search($referer = '' Line 16  function serapi_get_search($referer = ''
16      return false;      return false;
17    }    }
18    
   $engines = array(  
     'google' => array(  
       'host_pattern' => 'www.google.',  
       'query_param' => 'q'  
     ),  
     'yahoo' => array(  
       'host_pattern' => 'search.yahoo.com',  
       'query_param' => 'p'  
     ),  
     'live' => array(  
       'host_pattern' => 'search.live.com',  
       'query_param' => 'q'  
     ),  
     'ask' => array(  
       'host_pattern' => 'ask.com',  
       'query_param' => 'q'  
     )  
   );  
   
19    $url_parts = parse_url($referer);    $url_parts = parse_url($referer);
20    // only check urls that contain a query string, hell awaits when    // only check urls that contain a query string, hell awaits when
21    // search engines start to use url rewriting for serps    // search engines start to use url rewriting for serps
22    if (is_array($url_parts) && isset($url_parts['host']) && isset($url_parts['query'])) {    if (is_array($url_parts) && isset($url_parts['host']) && isset($url_parts['query'])) {
23        $engines = serapi_get_engine_list();
24        // always check arrays before using them in foreach
25        if(!is_array($engines)) {
26          return false;
27        }
28      foreach($engines as $name => $prop) {      foreach($engines as $name => $prop) {
29        if (false !== stripos($url_parts['host'], $prop['host_pattern'])) {        if (false !== stripos($url_parts['host'], $prop['host_pattern'])) {
30          $query = $url_parts['query'];          $query = $url_parts['query'];
# Line 66  function serapi_get_search($referer = '' Line 52  function serapi_get_search($referer = ''
52  }  }
53    
54  /**  /**
55     * Returns an array of search engines supported
56     * by this module
57     *
58     * @return Array
59     * Array of search engines
60     */
61    function serapi_get_engine_list() {
62      return array(
63        'google' => array(
64          'host_pattern' => 'www.google.',
65          'query_param' => 'q'
66        ),
67        'yahoo' => array(
68          'host_pattern' => 'search.yahoo.com',
69          'query_param' => 'p'
70        ),
71        'live' => array(
72          'host_pattern' => 'search.live.com',
73          'query_param' => 'q'
74        ),
75        'ask' => array(
76          'host_pattern' => 'ask.com',
77          'query_param' => 'q'
78        ),
79        'aol.de' => array(
80          'host_pattern' => '.aol.de',
81          'query_param' => 'q'
82        ),
83        'aol' => array(
84          'host_pattern' => '.aol.',
85          'query_param' => 'query'
86        ),
87        'altavista' => array(
88          'host_pattern' => 'altavista.com',
89          'query_param' => 'q'
90        ),
91        'alltheweb' => array(
92          'host_pattern' => 'alltheweb.com',
93          'query_param' => 'q'
94        ),
95      );
96    }
97    
98    /**
99   * Implementation of hook_block   * Implementation of hook_block
100   */   */
101  function serapi_block($op = 'list', $delta = 0, $edit = array()) {  function serapi_block($op = 'list', $delta = 0, $edit = array()) {
# Line 142  function serapi_get_test_urls() { Line 172  function serapi_get_test_urls() {
172      // live      // live
173      'http://search.live.com/results.aspx?q=drupal',      'http://search.live.com/results.aspx?q=drupal',
174      'http://search.live.com/results.aspx?q=drupal+cms&amp;go=&form=QBLH',      'http://search.live.com/results.aspx?q=drupal+cms&amp;go=&form=QBLH',
175      'http://search.live.com/results.aspx?q=live+search+sucks&go=&form=QBLH'      'http://search.live.com/results.aspx?q=live+search+sucks&go=&form=QBLH',
176        // aol actually sucks bad
177        'http://search.aol.com/aol/search?s_it=searchbox.webhome&query=drupal+cms',
178        'http://suche.aol.de/aol/search?q=drupal+cms&langRestrict=2',
179        'http://busqueda.aol.es/aol/search?invocationType=topsearchbox&query=drupal&rp=',
180        // altavista
181        'http://www.altavista.com/web/results?itag=ody&q=drupal&kgs=1&kls=0',
182        'http://de.altavista.com/web/results?itag=ody&q=drupal&kgs=1&kls=0',
183        'http://es.altavista.com/web/results?itag=ody&q=drupal+content+management+framework&kgs=1&kls=0',
184        // alltheweb
185        'http://www.alltheweb.com/search?q=drupal+framework',
186        'http://www.alltheweb.com/search?cat=web&cs=iso88591&q=drupal+cms&rys=0&itag=crv&_sb_lang=pref',
187        'http://www.alltheweb.com/search?cat=web&cs=iso88591&q=drupal&rys=0&itag=crv&_sb_lang=pref'
188    );    );
189  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2