From 6d496263bbcc662282a059aee76d74784ac44479 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 23 May 2010 19:37:12 -0400 Subject: First version of an OpenSearch endpoint for Elgg --- config.ini.sample | 45 ++++++++++++++++++++++ manifest.xml | 10 +++++ start.php | 47 +++++++++++++++++++++++ views/default/opensearch/includes.php | 7 ++++ views/opensearch_rss/page_shells/default.php | 42 ++++++++++++++++++++ views/opensearch_rss/search/layout.php | 2 + views/opensearch_rss/search/listing.php | 25 ++++++++++++ views/xml/opensearch/description.php | 57 ++++++++++++++++++++++++++++ 8 files changed, 235 insertions(+) create mode 100644 config.ini.sample create mode 100644 manifest.xml create mode 100644 start.php create mode 100644 views/default/opensearch/includes.php create mode 100644 views/opensearch_rss/page_shells/default.php create mode 100644 views/opensearch_rss/search/layout.php create mode 100644 views/opensearch_rss/search/listing.php create mode 100644 views/xml/opensearch/description.php diff --git a/config.ini.sample b/config.ini.sample new file mode 100644 index 000000000..770023186 --- /dev/null +++ b/config.ini.sample @@ -0,0 +1,45 @@ +; OpenSearch configuration + +; ShortName +; Contains a brief human-readable title that identifies this search engine. +; 16 characters or less of plain text. +; Required +shortname = "Elgg" + +; Description +; Contains a human-readable text description of the search engine. +; 1024 characters or less of plain text. +; Required +description = "Elgg search engine" + +; LongName +; Contains an extended human-readable title that identifies this search engine. +; 48 characters or less of plain text. +;longname = "" + +; Image +; Contains a URL that identifies the location of an image that can be used +; in association with this search content. Can be either a 16x16 ico or +; 64x64 png or both. Clients will choose the image that best fits the +; display area. The value should be relative to your Elgg root. +ico = "_graphics/favicon.ico" +;png = "" + +; Tags +; Contains a set of words that are used as keywords to identify and categorize +; this search content. Tags must be a single word and are delimited by the +; space character (' '). +; 256 characters or less, space delimited tags +;tags = "test search elgg" + +; Language +; Contains a string that indicates that the search engine supports search +; results in the specified language. +; * or codes according to XML 1.0 Language Identification +lang[] = "en-us" + +; Query +; Test query available to clients. +; Clients can submit this as a test query to ensure that the OpenSearch +; interface works. +;query = "test" diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 000000000..0038dc168 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/start.php b/start.php new file mode 100644 index 000000000..015fd3b1e --- /dev/null +++ b/start.php @@ -0,0 +1,47 @@ +pluginspath . 'opensearch'; + + if (!isset($page[0])) { + require "$base_path/search.php"; + return TRUE; + } + + // select page based on first URL element after /pg/hello/ + switch ($page[0]) { + case 'osd.xml': + elgg_set_viewtype('xml'); + page_draw('', elgg_view('opensearch/description')); + return TRUE; + break; + } + +} diff --git a/views/default/opensearch/includes.php b/views/default/opensearch/includes.php new file mode 100644 index 000000000..57e56723f --- /dev/null +++ b/views/default/opensearch/includes.php @@ -0,0 +1,7 @@ +sitename; +?> + + diff --git a/views/opensearch_rss/page_shells/default.php b/views/opensearch_rss/page_shells/default.php new file mode 100644 index 000000000..52aa8854c --- /dev/null +++ b/views/opensearch_rss/page_shells/default.php @@ -0,0 +1,42 @@ +\n"; + +// Set title +$search_terms = get_input('q'); +$title = $vars['config']->sitename; +$title .= " Search: $search_terms"; + +$description = "Search results for \"$search_terms\""; + +// Remove viewtype from URL +$search_url = str_replace('&view=opensearch_rss','', full_url()); + +$os_url = "{$vars['url']}pg/opensearch/osd.xml"; + + +?> + + + <?php echo $title; ?> + + + + 1 + 10 + + diff --git a/views/opensearch_rss/search/layout.php b/views/opensearch_rss/search/layout.php new file mode 100644 index 000000000..4cd2ff050 --- /dev/null +++ b/views/opensearch_rss/search/layout.php @@ -0,0 +1,2 @@ + $entity, + 'params' => $vars['params'], + 'results' => $vars['results'] + )); + } +} +elgg_set_viewtype('opensearch_rss'); + +echo $body; \ No newline at end of file diff --git a/views/xml/opensearch/description.php b/views/xml/opensearch/description.php new file mode 100644 index 000000000..f8eb0b040 --- /dev/null +++ b/views/xml/opensearch/description.php @@ -0,0 +1,57 @@ +site_guid); +$email = $site->email; + +$rss_url = "{$vars['url']}pg/opensearch/?q={searchTerms}&pw={startPage?}&format=rss"; +$html_url = "{$vars['url']}pg/search/?q={searchTerms}"; + +?> + + + + + + + email; ?> + + + + + + + + + + + + + + + + + + open + false + UTF-8 + UTF-8 + -- cgit v1.2.3 From 4d80af63de9125eda856652ee92cbd1e01afff51 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 23 May 2010 20:36:15 -0400 Subject: Added README --- README | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 000000000..1725196a6 --- /dev/null +++ b/README @@ -0,0 +1,14 @@ +OpenSearch endpoint for Elgg + +INSTALL +Rename config.ini.sample to config.ini +Edit config.ini to reflect your site +Activate the plugin + +USAGE +Adds an OpenSearch description definition to the html head. Browsers +will pick this up and allow you to add site specific search to your +search bar. + +The plugin also provides an RSS 2.0 feed that conforms to the OpenSearch +standard. -- cgit v1.2.3 From adb7af64321c8a80744ac0eaa870fdb38630294d Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Tue, 25 May 2010 07:07:22 -0400 Subject: OpenSearch RSS feed working with Elgg 1.7 --- views/opensearch_rss/pageshells/pageshell.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 views/opensearch_rss/pageshells/pageshell.php diff --git a/views/opensearch_rss/pageshells/pageshell.php b/views/opensearch_rss/pageshells/pageshell.php new file mode 100644 index 000000000..f883f236a --- /dev/null +++ b/views/opensearch_rss/pageshells/pageshell.php @@ -0,0 +1,6 @@ + Date: Tue, 25 May 2010 07:29:50 -0400 Subject: added language file --- languages/en.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 languages/en.php diff --git a/languages/en.php b/languages/en.php new file mode 100644 index 000000000..c0b3e5bf5 --- /dev/null +++ b/languages/en.php @@ -0,0 +1,9 @@ + "Search: %s", + 'opensearch:description' => "Search results for \"%s\"", + +); + +add_translation("en", $english); -- cgit v1.2.3 From bfcd3e087980e48b5b908fd30cf2e9b1aa3726e4 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Tue, 25 May 2010 07:39:47 -0400 Subject: Updated the RSS for language file and added files missing from previous commits --- manifest.xml | 4 ++-- start.php | 9 --------- views/opensearch_rss/page_shells/default.php | 8 +++----- views/opensearch_rss/search/listing.php | 1 - views/xml/opensearch/description.php | 6 +++--- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/manifest.xml b/manifest.xml index 0038dc168..a8733595b 100644 --- a/manifest.xml +++ b/manifest.xml @@ -3,8 +3,8 @@ - - + + diff --git a/start.php b/start.php index 015fd3b1e..7adc0f733 100644 --- a/start.php +++ b/start.php @@ -27,15 +27,6 @@ function opensearch_init() { function opensearch_handler($page) { global $CONFIG; - // file path to the page scripts - $base_path = $CONFIG->pluginspath . 'opensearch'; - - if (!isset($page[0])) { - require "$base_path/search.php"; - return TRUE; - } - - // select page based on first URL element after /pg/hello/ switch ($page[0]) { case 'osd.xml': elgg_set_viewtype('xml'); diff --git a/views/opensearch_rss/page_shells/default.php b/views/opensearch_rss/page_shells/default.php index 52aa8854c..e9510e9da 100644 --- a/views/opensearch_rss/page_shells/default.php +++ b/views/opensearch_rss/page_shells/default.php @@ -12,9 +12,9 @@ echo "\n"; // Set title $search_terms = get_input('q'); $title = $vars['config']->sitename; -$title .= " Search: $search_terms"; +$title .= ' ' . sprintf(elgg_echo('opensearch:title'), $search_terms); -$description = "Search results for \"$search_terms\""; +$description = sprintf(elgg_echo('opensearch:description'), $search_terms); // Remove viewtype from URL $search_url = str_replace('&view=opensearch_rss','', full_url()); @@ -29,10 +29,8 @@ $os_url = "{$vars['url']}pg/opensearch/osd.xml"; - 1 - 10