aboutsummaryrefslogtreecommitdiff
path: root/views
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 /views
downloadelgg-6d496263bbcc662282a059aee76d74784ac44479.tar.gz
elgg-6d496263bbcc662282a059aee76d74784ac44479.tar.bz2
First version of an OpenSearch endpoint for Elgg
Diffstat (limited to 'views')
-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
5 files changed, 133 insertions, 0 deletions
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>