Index: opensearch.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/opensearch/opensearch.info,v retrieving revision 1.1 diff -u -p -r1.1 opensearch.info --- opensearch.info 27 Apr 2008 16:01:06 -0000 1.1 +++ opensearch.info 23 Jul 2008 21:53:30 -0000 @@ -1,4 +1,6 @@ ; $Id: opensearch.info,v 1.1 2008/04/27 16:01:06 hunmaat Exp $ name = OpenSearch Feed description = Allows Drupal search results to be returned in the OpenSearch RSS format -dependencies = search \ No newline at end of file +dependencies[] = search +package = Search +core = 6.x Index: opensearch.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/opensearch/opensearch.module,v retrieving revision 1.10 diff -u -p -r1.10 opensearch.module --- opensearch.module 27 Apr 2008 20:15:23 -0000 1.10 +++ opensearch.module 23 Jul 2008 21:53:31 -0000 @@ -2,42 +2,49 @@ // $Id: opensearch.module,v 1.10 2008/04/27 20:15:23 hunmaat Exp $ /** + * @file + * opensearch + */ + +/** + * Implementation of hook_init(). + */ +function opensearch_init() { + $type = (arg(0) == 'search' && arg(1) != '') ? arg(1) : 'node'; + $search_type = check_plain(module_invoke($type, 'search', 'name')); + $opensearch_shortname = t(check_plain(variable_get('opensearch_shortname', '@type search')), array('@type' => $search_type)); + + drupal_add_link(array( + 'rel' => 'search', + 'href' => url('opensearch/'. $type, array('absolute' => TRUE)), + 'type' => 'application/opensearchdescription+xml', + 'title' => variable_get('site_name', 'Drupal') . ' ' . $opensearch_shortname + )); +} + +/** * Implementation of hook_menu(). */ -function opensearch_menu($may_cache) { +function opensearch_menu() { $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/settings/opensearch', - 'title' => t('opensearch'), - 'callback' => 'opensearch_admin_settings', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - - foreach (module_list() as $name) { - if (module_hook($name, 'search') && $title = module_invoke($name, 'search', 'name')) { - $items[] = array( - 'path' => 'opensearch/' . $name, - 'title' => $title, - 'callback' => 'opensearch_view', - 'access' => user_access('search content'), - 'type' => MENU_LOCAL_TASK); - } + $items['admin/settings/opensearch'] = array( + 'title' => 'Opensearch', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('opensearch_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + + foreach (module_list() as $name) { + if (module_hook($name, 'search') && $title = module_invoke($name, 'search', 'name')) { + $items['opensearch/'. $name] = array( + 'title' => $title, + 'page callback' => 'opensearch_view', + 'access arguments' => array('search content'), + 'type' => MENU_LOCAL_TASK); } } - else { - $type = (arg(0) == 'search' && arg(1) != '') ? arg(1) : 'node'; - $search_type = check_plain(module_invoke($type, 'search', 'name')); - $opensearch_shortname = t(check_plain(variable_get('opensearch_shortname', '@type search')), array('@type' => $search_type)); - drupal_add_link(array( - 'rel' => 'search', - 'href' => url('opensearch/'. $type, NULL, NULL, TRUE), - 'type' => 'application/opensearchdescription+xml', - 'title' => $opensearch_shortname - )); - } return $items; } @@ -57,7 +64,7 @@ function opensearch_admin_settings() { $form['description']['opensearch_prefix'] = array( '#type' => 'markup', - '#value' => '

' . t('Your site offers the following OpenSearch description files: %links', array('%links' => theme('item_list', $links))) . '

', + '#value' => '

'. t('Your site offers the following OpenSearch description files: %links', array('%links' => theme('item_list', $links))) .'

', ); $form['description']['opensearch_shortname'] = array( '#type' => 'textfield', @@ -124,15 +131,17 @@ function opensearch_admin_settings() { '#default_value' => $opensearch_adult_content, ); - return system_settings_form('opensearch_admin_settings', $form); + return system_settings_form($form); } - -function opensearch_form_alter($form_id, &$form) { +/** + * Implementation of hook_form_alter + */ +function opensearch_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'search_form' && arg(2)) { // for pagination etc. $get = drupal_query_string_encode($_GET, array('q')); - $form['basic']['inline']['rss'] = array('#type' => 'markup', '#value' => theme('xml_icon', url('opensearch/' . arg(1). '/'. urlencode(search_get_keys()), trim($get)?$get:NULL))); + $form['basic']['inline']['rss'] = array('#type' => 'markup', '#value' => theme('xml_icon', url('opensearch/'. arg(1) .'/'. urlencode(search_get_keys()), array('query' => trim($get)?$get:NULL)))); } } @@ -153,7 +162,7 @@ function opensearch_view() { if (trim($keys)) { // Log the search keys: - watchdog('search', t('OpenSearch: %keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys)); + watchdog('search', 'OpenSearch: %keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys)); // Collect the search results: $results = module_invoke($type, 'search', 'search', $keys); @@ -185,12 +194,12 @@ function opensearch_feed($type, $keys, $ 'opensearch:totalResults' => $GLOBALS['pager_total_items'][0], 'opensearch:startIndex' => $GLOBALS['pager_page_array'][0] * 10 + 1, 'opensearch:itemsPerPage' => 10, - array('key' => 'opensearch:link', 'attributes' => array('href' => url('opensearch/'. $type, NULL, NULL, TRUE), 'type' => 'application/opensearchdescription+xml')), + array('key' => 'opensearch:link', 'attributes' => array('href' => url('opensearch/'. $type, array('absolute' => TRUE)), 'type' => 'application/opensearchdescription+xml')), array('key' => 'opensearch:Query', 'attributes' => array('role' => 'request', 'searchTerms' => $keys)), ); $output = "\n"; - $output .= "\n"; + $output .= " TRUE)) ."\" ". implode(' ', $namespaces) .">\n"; $output .= format_rss_channel( $keys .' - '. variable_get('site_name', 'drupal') .' '. module_invoke($type, 'search', 'name') .' '. t('search'), $base_url, @@ -241,8 +250,8 @@ function opensearch_description($type) { $opensearch_description = t($opensearch_description, array('@site' => $site_name, '@type' => $search_type)); $opensearch_longname = t($opensearch_longname, array('@site' => $site_name, '@type' => $search_type)); $url = check_url($base_url); - $url_search = str_replace(array('%7B', '%7D', '&'), array('{', '}', '&'), url('search/' . $type . '/{searchTerms}', 'page={startPage}', NULL, TRUE)); - $url_opensearch = str_replace(array('%7B', '%7D', '&'), array('{', '}', '&'), url('opensearch/' . $type . '/{searchTerms}', 'page={startPage}', NULL, TRUE)); + $url_search = str_replace(array('%7B', '%7D', '&'), array('{', '}', '&'), url('search/'. $type .'/{searchTerms}', array('query' => 'page={startPage}', 'absolute' => TRUE))); + $url_opensearch = str_replace(array('%7B', '%7D', '&'), array('{', '}', '&'), url('opensearch/'. $type .'/{searchTerms}', array('query' => 'page={startPage}', 'absolute' => TRUE))); $output = << @@ -287,15 +296,15 @@ DOC; $logo = theme_get_setting('logo'); if (theme_get_setting('toggle_logo') && ($logo_url = check_url(theme_get_setting('logo_path')))) { list($width, $height, $type, $image_attributes) = @getimagesize($logo_url); - $logo_url = $url. '/'. $logo_url; + $logo_url = $url .'/'. $logo_url; if ($height) { - $height = 'height="'. $height. '"'; + $height = 'height="'. $height .'"'; } if ($width) { - $width = 'width="'. $width. '"'; + $width = 'width="'. $width .'"'; } if ($type) { - $type = 'type="'. image_type_to_mime_type($type). '"'; + $type = 'type="'. image_type_to_mime_type($type) .'"'; } $output .= "\n $logo_url"; } @@ -305,15 +314,15 @@ DOC; $favicon_url = substr($favicon_url, 1); } list($width, $height, $type, $image_attributes) = @getimagesize($favicon_url); - $favicon_url = $url . '/' . $favicon_url; + $favicon_url = $url .'/'. $favicon_url; if ($height) { - $height = 'height="'. $height. '"'; + $height = 'height="'. $height .'"'; } if ($width) { - $width = 'width="'. $width. '"'; + $width = 'width="'. $width .'"'; } if ($type) { - $type = 'type="' . image_type_to_mime_type($type) . '"'; + $type = 'type="'. image_type_to_mime_type($type) .'"'; } $output .= "\n $favicon_url"; }