diff options
Diffstat (limited to 'mod/opensearch/views')
7 files changed, 261 insertions, 0 deletions
diff --git a/mod/opensearch/views/default/opensearch/includes.php b/mod/opensearch/views/default/opensearch/includes.php new file mode 100644 index 000000000..6aceb45c2 --- /dev/null +++ b/mod/opensearch/views/default/opensearch/includes.php @@ -0,0 +1,10 @@ +<?php +/** + * OpenSearch head include + */ + +$url = elgg_normalize_url('opensearch/osd.xml'); +$title = elgg_get_site_entity()->name; +?> + +<link rel="search" type="application/opensearchdescription+xml" href="<?php echo $url; ?>" title="<?php echo $title; ?>" /> diff --git a/mod/opensearch/views/default/plugins/opensearch/settings.php b/mod/opensearch/views/default/plugins/opensearch/settings.php new file mode 100644 index 000000000..23ba19538 --- /dev/null +++ b/mod/opensearch/views/default/plugins/opensearch/settings.php @@ -0,0 +1,97 @@ +<?php +/** + * Opensearch plugin settings + */ + +// set default value +if (!isset($vars['entity']->shortname)) { + $vars['entity']->shortname = elgg_get_site_entity()->name; +} +if (!isset($vars['entity']->desc)) { + $vars['entity']->desc = elgg_echo('opensearch:engine', array(elgg_get_site_entity()->name)); +} +if (!isset($vars['entity']->longname)) { + $vars['entity']->longname = elgg_get_site_entity()->description; +} +if (!isset($vars['entity']->icon)) { + $vars['entity']->icon = '_graphics/favicon.ico'; +} +if (!isset($vars['entity']->tags)) { + $vars['entity']->tags = ''; +} +if (!isset($vars['entity']->lang)) { + $vars['entity']->lang = 'en-us'; +} +if (!isset($vars['entity']->query)) { + $vars['entity']->query = ''; +} + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:shortname').'</label> '; +echo elgg_echo('opensearh:settings:shortname:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[shortname]', + 'value' => $vars['entity']->shortname, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:desc').'</label> '; +echo elgg_echo('opensearh:settings:desc:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[desc]', + 'value' => $vars['entity']->desc, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:longname').'</label> '; +echo elgg_echo('opensearh:settings:longname:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[longname]', + 'value' => $vars['entity']->longname, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:icon').'</label> '; +echo elgg_echo('opensearh:settings:icon:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[icon]', + 'value' => $vars['entity']->icon, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:tags').'</label> '; +echo elgg_echo('opensearh:settings:tags:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[tags]', + 'value' => $vars['entity']->tags, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:lang').'</label> '; +echo elgg_echo('opensearh:settings:lang:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[lang]', + 'value' => $vars['entity']->lang, +)); +echo '</div>'; + +echo '<div>'; +echo '<label>'.elgg_echo('opensearh:settings:query').'</label> '; +echo elgg_echo('opensearh:settings:query:description'); +echo ' '; +echo elgg_view('input/text', array( + 'name' => 'params[query]', + 'value' => $vars['entity']->query, +)); +echo '</div>'; diff --git a/mod/opensearch/views/opensearch_rss/page/default.php b/mod/opensearch/views/opensearch_rss/page/default.php new file mode 100644 index 000000000..79cd544c4 --- /dev/null +++ b/mod/opensearch/views/opensearch_rss/page/default.php @@ -0,0 +1,42 @@ +<?php +/** + * Page shell for OpenSearch RSS feed + */ + +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 = elgg_get_site_entity()->name; +$title .= ' ' . elgg_echo('opensearch:title', array($search_terms)); + +$description = elgg_echo('opensearch:description', array($search_terms)); + +// Remove viewtype from URL +$search_url = str_replace('&view=opensearch_rss', '', full_url()); + +$os_url = elgg_normalize_url('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> + <atom:link rel="search" type="application/opensearchdescription+xml" href="<?php echo $os_url; ?>"/> + <opensearch:Query role="request" searchTerms="<?php echo addslashes($search_terms); ?>" startPage="1" /> +<?php + + echo $vars['body']; + +?> +</channel> +</rss> diff --git a/mod/opensearch/views/opensearch_rss/page/layouts/default.php b/mod/opensearch/views/opensearch_rss/page/layouts/default.php new file mode 100644 index 000000000..488734f84 --- /dev/null +++ b/mod/opensearch/views/opensearch_rss/page/layouts/default.php @@ -0,0 +1,5 @@ +<?php +/** + * OpenSearch RSS layout shell + */ +echo $vars['content'];
\ No newline at end of file diff --git a/mod/opensearch/views/opensearch_rss/search/layout.php b/mod/opensearch/views/opensearch_rss/search/layout.php new file mode 100644 index 000000000..d5bb9fe57 --- /dev/null +++ b/mod/opensearch/views/opensearch_rss/search/layout.php @@ -0,0 +1,5 @@ +<?php +/** + * OpenSearch search layout + */ +echo $vars['body'];
\ No newline at end of file diff --git a/mod/opensearch/views/opensearch_rss/search/list.php b/mod/opensearch/views/opensearch_rss/search/list.php new file mode 100644 index 000000000..bc7b5574e --- /dev/null +++ b/mod/opensearch/views/opensearch_rss/search/list.php @@ -0,0 +1,27 @@ +<?php +/** + * OpenSearch serach results list + */ + +global $OPEN_SEARCH_COUNT; +if (!isset($OPEN_SEARCH_COUNT)) { + $OPEN_SEARCH_COUNT = 0; +} + +$OPEN_SEARCH_COUNT += $vars['results']['count']; + + +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/mod/opensearch/views/xml/opensearch/description.php b/mod/opensearch/views/xml/opensearch/description.php new file mode 100644 index 000000000..586cadf83 --- /dev/null +++ b/mod/opensearch/views/xml/opensearch/description.php @@ -0,0 +1,75 @@ +<?php +/** + * Creates an OpenSearch description document from plugin settings + * http://www.opensearch.org/Specifications/OpenSearch/1.1 + */ + +// reset cache headers because IE8 is stupid +header('Pragma: public', true); +header('Cache-Control: public', true); + +$site = elgg_get_site_entity(); +$email = $site->email; + +$shortname = elgg_get_plugin_setting('shortname', 'opensearch'); +$description = elgg_get_plugin_setting('desc', 'opensearch'); +$longname = elgg_get_plugin_setting('longname', 'opensearch'); +$icon = elgg_get_plugin_setting('icon', 'opensearch'); +$tags = elgg_get_plugin_setting('tags', 'opensearch'); +$lang = string_to_tag_array(elgg_get_plugin_setting('lang', 'opensearch')); +$query = elgg_get_plugin_setting('query', 'opensearch'); + +if (empty($shortname)) { + $shortname = $site->name; +} +if (empty($description)) { + $description = elgg_echo('opensearch:engine', array(elgg_get_site_entity()->name)); +} +if (empty($icon)) { + $icon = '_graphics/favicon.ico'; +} +if (empty($lang)) { + $lang = 'en-us'; +} + + +$rss_url = elgg_normalize_url('search/?q={searchTerms}&view=opensearch_rss'); +$rss_url = elgg_format_url($rss_url); +$html_url = elgg_normalize_url('search/?q={searchTerms}'); +$site_url = elgg_get_site_url(); + +?> +<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" template="<?php echo $html_url; ?>"/> + <Url type="application/rss+xml" template="<?php echo $rss_url; ?>"/> +<?php if (preg_match("/.ico$/", $icon)): ?> + <Image height="16" width="16" type="image/vnd.microsoft.icon"><?php echo "{$site_url}$icon"; ?></Image> +<?php elseif (preg_match("/.png$/", $icon)): ?> + <Image height="64" width="64" type="image/png"><?php echo "{$site_url}$icon"; ?></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> |