aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2010-05-23 19:37:12 -0400
committerCash Costello <cash.costello@gmail.com>2010-05-23 19:37:12 -0400
commit6d496263bbcc662282a059aee76d74784ac44479 (patch)
tree8a1a2e751912c6f3cd46409d872dd13d1d7186df
downloadelgg-6d496263bbcc662282a059aee76d74784ac44479.tar.gz
elgg-6d496263bbcc662282a059aee76d74784ac44479.tar.bz2
First version of an OpenSearch endpoint for Elgg
-rw-r--r--config.ini.sample45
-rw-r--r--manifest.xml10
-rw-r--r--start.php47
-rw-r--r--views/default/opensearch/includes.php7
-rw-r--r--views/opensearch_rss/page_shells/default.php42
-rw-r--r--views/opensearch_rss/search/layout.php2
-rw-r--r--views/opensearch_rss/search/listing.php25
-rw-r--r--views/xml/opensearch/description.php57
8 files changed, 235 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest>
+ <field key="author" value="Cash Costello" />
+ <field key="version" value="1.0" />
+ <field key="description" value="OpenSearch plugin" />
+ <field key="website" value="" />
+ <field key="copyright" value="" />
+ <field key="licence" value="GNU Public License version 2" />
+ <field key="elgg_version" value="2010030101" />
+</plugin_manifest>
diff --git a/start.php b/start.php
new file mode 100644
index 000000000..015fd3b1e
--- /dev/null
+++ b/start.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * OpenSearch plugin
+ *
+ * http://www.opensearch.org/Home
+ *
+ * @author Cash Costello
+ * @license http://opensource.org/licenses/gpl-2.0.php GPL 2
+ */
+
+register_elgg_event_handler('init', 'system', 'opensearch_init');
+
+function opensearch_init() {
+ global $CONFIG;
+
+ register_page_handler('opensearch', 'opensearch_handler');
+
+ elgg_extend_view('metatags', 'opensearch/includes');
+}
+
+/**
+ * Handles OpenSearch requests
+ *
+ * @param array $page An array of URL elements
+ * @return boolean
+ */
+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');
+ 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 @@
+<?php
+
+$url = "{$vars['url']}pg/opensearch/osd.xml";
+$title = $vars['config']->sitename;
+?>
+
+<link rel="search" type="application/opensearchdescription+xml" href="<?php echo $url; ?>" title="<?php echo $title; ?>" />
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 @@
+<?php
+
+global $OPEN_SEARCH_COUNT;
+
+header("Content-Type: application/rss+xml");
+
+// allow caching as required by stupid MS products for https feeds.
+header('Pragma: public', TRUE);
+
+echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\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";
+
+
+?>
+<rss version="2.0" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
+<channel>
+ <title><?php echo $title; ?></title>
+ <link><?php echo $search_url; ?></link>
+ <description><?php echo $description; ?></description>
+ <opensearch:totalResults><?php echo $OPEN_SEARCH_COUNT; ?></opensearch:totalResults>
+ <opensearch:startIndex>1</opensearch:startIndex>
+ <opensearch:itemsPerPage>10</opensearch:itemsPerPage>
+ <atom:link rel="search" type="application/opensearchdescription+xml" href="<?php echo $os_url; ?>"/>
+ <opensearch:Query role="request" searchTerms="<?php echo $search_terms; ?>" startPage="1" />
+<?php
+
+ echo $vars['body'];
+
+?>
+</channel>
+</rss>
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 @@
+<?php
+echo $vars['body']; \ No newline at end of file
diff --git a/views/opensearch_rss/search/listing.php b/views/opensearch_rss/search/listing.php
new file mode 100644
index 000000000..367bf332f
--- /dev/null
+++ b/views/opensearch_rss/search/listing.php
@@ -0,0 +1,25 @@
+<?php
+
+global $OPEN_SEARCH_COUNT;
+if (!isset($OPEN_SEARCH_COUNT)) {
+ $OPEN_SEARCH_COUNT = 0;
+}
+
+$OPEN_SEARCH_COUNT += $vars['results']['count'];
+
+//var_dump($vars['results']);
+
+elgg_set_viewtype('rss');
+$entities = $vars['results']['entities'];
+foreach ($entities as $entity) {
+ if ($view = search_get_search_view($vars['params'], 'entity')) {
+ $body .= elgg_view($view, array(
+ 'entity' => $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 @@
+<?php
+/**
+ * Creates an OpenSearch description document from config.ini
+ * http://www.opensearch.org/Specifications/OpenSearch/1.1
+ */
+
+$config_ini = dirname(dirname(dirname(dirname(__FILE__)))) . '/config.ini';
+$config = parse_ini_file($config_ini);
+if ($config == FALSE) {
+ elgg_log("Unable to parse OpenSearch config file", 'ERROR');
+ return TRUE;
+}
+
+extract($config);
+
+$site = get_entity($CONFIG->site_guid);
+$email = $site->email;
+
+$rss_url = "{$vars['url']}pg/opensearch/?q={searchTerms}&amp;pw={startPage?}&amp;format=rss";
+$html_url = "{$vars['url']}pg/search/?q={searchTerms}";
+
+?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+ <ShortName><?php echo $shortname; ?></ShortName>
+ <Description><?php echo $description; ?></Description>
+<?php if (isset($longname)): ?>
+ <LongName><?php echo $longname; ?></LongName>
+<?php endif; ?>
+ <Contact><?php echo $site->email; ?></Contact>
+ <Url type="text/html" indexOffset="0" template="<?php echo $html_url; ?>"/>
+ <Url type="application/rss+xml" indexOffset="0" template="<?php echo $rss_url; ?>"/>
+<?php if (isset($ico)): ?>
+ <Image height="16" width="16" type="image/vnd.microsoft.icon"><?php echo "{$vars['url']}$ico"; ?></Image>
+<?php endif; ?>
+<?php if (isset($png)): ?>
+ <Image height="64" width="64" type="image/png"><?php echo "{$vars['url']}$png"; ?></Image>
+<?php endif; ?>
+<?php if (isset($tags)): ?>
+ <Tags><?php echo $tags; ?></Tags>
+<?php endif; ?>
+<?php if (isset($query)): ?>
+ <Query role="example" searchTerms="<?php echo $query; ?>" />
+<?php endif; ?>
+<?php
+if (isset($lang)):
+ foreach ($lang as $language):
+?>
+ <Language><?php echo $language; ?></Language>
+<?php
+ endforeach;
+endif;
+?>
+ <SyndicationRight>open</SyndicationRight>
+ <AdultContent>false</AdultContent>
+ <OutputEncoding>UTF-8</OutputEncoding>
+ <InputEncoding>UTF-8</InputEncoding>
+ </OpenSearchDescription>