diff options
author | Sem <sembrestels@riseup.net> | 2013-11-09 16:15:20 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2013-11-09 16:15:20 +0100 |
commit | 293fe873dcbedf45571807b722ce859e00a5a3a5 (patch) | |
tree | 4ce7adf3dbeed0a4ac2fbefd55f8844f504db499 /mod | |
parent | ba0d506ade08ae46ba665474a8b9c81e838f2eee (diff) | |
parent | 853cb44b625cbe0e1cae3dff197d54645a1291a1 (diff) | |
download | elgg-293fe873dcbedf45571807b722ce859e00a5a3a5.tar.gz elgg-293fe873dcbedf45571807b722ce859e00a5a3a5.tar.bz2 |
Add 'mod/opensearch/' from commit '853cb44b625cbe0e1cae3dff197d54645a1291a1'
git-subtree-dir: mod/opensearch
git-subtree-mainline: ba0d506ade08ae46ba665474a8b9c81e838f2eee
git-subtree-split: 853cb44b625cbe0e1cae3dff197d54645a1291a1
Diffstat (limited to 'mod')
-rw-r--r-- | mod/opensearch/README | 21 | ||||
-rw-r--r-- | mod/opensearch/languages/ca.php | 26 | ||||
-rw-r--r-- | mod/opensearch/languages/en.php | 28 | ||||
-rw-r--r-- | mod/opensearch/languages/es.php | 23 | ||||
-rw-r--r-- | mod/opensearch/languages/eu.php | 11 | ||||
-rwxr-xr-x | mod/opensearch/languages/pl.php | 11 | ||||
-rw-r--r-- | mod/opensearch/manifest.xml | 16 | ||||
-rw-r--r-- | mod/opensearch/start.php | 33 | ||||
-rw-r--r-- | mod/opensearch/views/default/opensearch/includes.php | 10 | ||||
-rw-r--r-- | mod/opensearch/views/default/plugins/opensearch/settings.php | 97 | ||||
-rw-r--r-- | mod/opensearch/views/opensearch_rss/page/default.php | 42 | ||||
-rw-r--r-- | mod/opensearch/views/opensearch_rss/page/layouts/default.php | 5 | ||||
-rw-r--r-- | mod/opensearch/views/opensearch_rss/search/layout.php | 5 | ||||
-rw-r--r-- | mod/opensearch/views/opensearch_rss/search/list.php | 27 | ||||
-rw-r--r-- | mod/opensearch/views/xml/opensearch/description.php | 75 |
15 files changed, 430 insertions, 0 deletions
diff --git a/mod/opensearch/README b/mod/opensearch/README new file mode 100644 index 000000000..a25a00c93 --- /dev/null +++ b/mod/opensearch/README @@ -0,0 +1,21 @@ +OpenSearch endpoint for Elgg + +OVERVIEW +------------- +OpenSearch is a standard for exposing the data in your website for search +to browsers and other web sites. For more information on this technology, visit +the Wikipedia page on OpenSearch at http://en.wikipedia.org/wiki/OpenSearch + +INSTALL +------------- + * Activate the plugin + * Edit OpenSearch settings in administration pages to reflect your site + +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. diff --git a/mod/opensearch/languages/ca.php b/mod/opensearch/languages/ca.php new file mode 100644 index 000000000..35e4dfb9e --- /dev/null +++ b/mod/opensearch/languages/ca.php @@ -0,0 +1,26 @@ +<?php +/** + * OpenSearch Catalan language file + */ + +$catalan = array( + 'opensearch:title' => "Cerca: %s" , + 'opensearch:description' => "Resultats de la cerca \"%s\"", + 'opensearch:engine' => 'Motor de cerca %s', + 'opensearh:settings:shortname' => 'Nom curt', + 'opensearh:settings:desc' => 'Descripció', + 'opensearh:settings:longname' => 'Nom llarg', + 'opensearh:settings:icon' => 'Icona', + 'opensearh:settings:tags' => 'Etiquetes', + 'opensearh:settings:lang' => 'Idioma', + 'opensearh:settings:query' => 'Pregunta', + 'opensearh:settings:shortname:description' => 'Conté un petit títol llegible que identifica el motor de cerca. 16 caràcters o menys de text pla. <strong>Requerit</strong>', + 'opensearh:settings:desc:description' => 'Conté una petita descripció llegible sobre el motor de cerca. 1024 caràcters o menys de text pla. <strong>Requerit</strong>', + 'opensearh:settings:longname:description' => 'Conté un títol llegible llarg que identifica el motor de cerca. 48 caràcters o menys de text pla.', + 'opensearh:settings:icon:description' => 'Conté una adreça que identifica la localització d\'una imatge que pot ser utilitzada en associació amb el contingut d\'aquesta cerca. Pot ser un .ico de 16x16, un png de 64x64 o ambdues. Els clients escolliran la imatge que millor encaixi amb l\'espai disponible. El valor ha d\'estar relacionat amb el teu root de l\'Elgg', + 'opensearh:settings:tags:description' => 'Conté un grup de paraules que poden ser utilitzades com a paraules clau per a identificar i categoritzar el contingut d\'aquesta cerca. Les etiquetes han de ser una paraula simple i han de ser delimitades amb el caràcter d\'espai (\' \'). 256 caràcters o menys, l\'espai delimita les etiquetes', + 'opensearh:settings:lang:description' => 'Conté una cadena que indica que el motor de cerca està cercant resultats en un idioma específic. * o codis d\'acord amb la identificació d\'idiomes de l\'XML 1.0', + 'opensearh:settings:query:description' => 'Pregunta de prova disponible pels clients. El clients poden enviar aquesta com una pregunta de prova per assegurar-se que la interfície de l\'OpenSearch funciona.', +); + +add_translation('ca', $catalan); diff --git a/mod/opensearch/languages/en.php b/mod/opensearch/languages/en.php new file mode 100644 index 000000000..9a77f362b --- /dev/null +++ b/mod/opensearch/languages/en.php @@ -0,0 +1,28 @@ +<?php +/** + * OpenSearch English language file + */ + +$english = array( + 'opensearch:title' => "Search: %s", + 'opensearch:description' => "Search results for \"%s\"", + 'opensearch:engine' => "%s Search Engine", + + 'opensearh:settings:shortname' => "Short name", + 'opensearh:settings:desc' => "Description", + 'opensearh:settings:longname' => "Long name", + 'opensearh:settings:icon' => "Icon", + 'opensearh:settings:tags' => "Tags", + 'opensearh:settings:lang' => "Language", + 'opensearh:settings:query' => "Query", + 'opensearh:settings:shortname:description' => "Contains a brief human-readable title that identifies this search engine. 16 characters or less of plain text. <strong>Required</strong>", + 'opensearh:settings:desc:description' => "Contains a human-readable text description of the search engine. 1024 characters or less of plain text. <strong>Required</strong>", + 'opensearh:settings:longname:description' => "Contains an extended human-readable title that identifies this search engine. 48 characters or less of plain text.", + 'opensearh:settings:icon:description' => "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.", + 'opensearh:settings:tags:description' => "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", + 'opensearh:settings:lang:description' => "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", + 'opensearh:settings:query:description' => "Test query available to clients. Clients can submit this as a test query to ensure that the OpenSearch interface works.", + +); + +add_translation("en", $english); diff --git a/mod/opensearch/languages/es.php b/mod/opensearch/languages/es.php new file mode 100644 index 000000000..c2d9bee60 --- /dev/null +++ b/mod/opensearch/languages/es.php @@ -0,0 +1,23 @@ +<?php +$es = array ( + 'opensearch:title' => 'Búsqueda: %s', + 'opensearch:description' => 'Resultados de la búsqueda "%s"', + 'opensearch:engine' => 'Motor de búsqueda de %s', + 'opensearh:settings:shortname' => 'Nombre corto', + 'opensearh:settings:desc' => 'Descripción', + 'opensearh:settings:longname' => 'Nombre largo', + 'opensearh:settings:icon' => 'Icono', + 'opensearh:settings:tags' => 'Etiquetas', + 'opensearh:settings:lang' => 'Idioma', + 'opensearh:settings:query' => 'Petición', + 'opensearh:settings:shortname:description' => 'Contiene un título breve para este motor de búsqueda. 16 carácteres o menos de texto plano. <strong>Requerido</strong>', + 'opensearh:settings:desc:description' => 'Contiene una descripción del motor de búsqueda. 1024 carácteres o menos de texto plano. <strong>Requerido</strong>', + 'opensearh:settings:longname:description' => 'Contiene un título más largo para este motor de búsqueda. 48 carácteres o menos de texto plano.', + 'opensearh:settings:icon:description' => 'Contiene la URL de la localización de una imagen de icono. Puede ser un ico de 16x16 o un png 64x64 píxeles. El dirección debería ser relativa a la raíz de Elgg.', + 'opensearh:settings:tags:description' => 'Continene un conjunto de palabras usadas como palabras clave para identificar y categorizar este contenido de búsqueda. Las etiquetas deberían ser palabras simples y delimtadas por espacios (\' \'). 256 carácteres o menos, etiquetas delimitadas por espacios', + 'opensearh:settings:lang:description' => 'Contiene una cadena que indica que el motor de búsqueda soporta resultados de búsqueda en el idioma especificado. * o códigos acorde al XML 1.0 Language Identification', + 'opensearh:settings:query:description' => 'Petición de prueba disponible para clientes. Los clientes pueden enviarlo como petición de prueba para asegurarse de que el interfaz OpenSearch funciona.', +); + +add_translation("es", $es); + diff --git a/mod/opensearch/languages/eu.php b/mod/opensearch/languages/eu.php new file mode 100644 index 000000000..151e5d906 --- /dev/null +++ b/mod/opensearch/languages/eu.php @@ -0,0 +1,11 @@ +<?php +/** + * OpenSearch Basque language file + */ + +$basque = array( + 'opensearch:title' => "Bilatu: %s", + 'opensearch:description' => "\"%s\" bilaketaren emaitak", +); + +add_translation("eu", $basque); diff --git a/mod/opensearch/languages/pl.php b/mod/opensearch/languages/pl.php new file mode 100755 index 000000000..f73a1042d --- /dev/null +++ b/mod/opensearch/languages/pl.php @@ -0,0 +1,11 @@ +<?php +/** + * OpenSearch Polish language file + */ + +$polish = array( + 'opensearch:title' => "Szukaj: %s" , + 'opensearch:description' => "Wyniki wyszukiwania dla \"%s\"" +); + +add_translation('pl', $polish); diff --git a/mod/opensearch/manifest.xml b/mod/opensearch/manifest.xml new file mode 100644 index 000000000..98ae3356d --- /dev/null +++ b/mod/opensearch/manifest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>OpenSearch</name> + <author>Cash Costello</author> + <version>1.8.0</version> + <category>utility</category> + <category>search</category> + <description>OpenSearch integration</description> + <website>https://github.com/cash/opensearch</website> + <copyright>Cash Costello 2010-2011</copyright> + <license>GNU Public License version 2</license> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> +</plugin_manifest> diff --git a/mod/opensearch/start.php b/mod/opensearch/start.php new file mode 100644 index 000000000..88329c8d1 --- /dev/null +++ b/mod/opensearch/start.php @@ -0,0 +1,33 @@ +<?php +/** + * OpenSearch plugin + * + * http://www.opensearch.org/Home + * + * @author Cash Costello + * @license http://opensource.org/licenses/gpl-2.0.php GPL 2 + */ + +elgg_register_event_handler('init', 'system', 'opensearch_init'); + +function opensearch_init() { + elgg_register_page_handler('opensearch', 'opensearch_handler'); + elgg_extend_view('page/elements/head', 'opensearch/includes'); +} + +/** + * Handles OpenSearch requests + * + * @param array $page An array of URL elements + * @return bool + */ +function opensearch_handler($page) { + switch ($page[0]) { + case 'osd.xml': + elgg_set_viewtype('xml'); + echo elgg_view_page('', elgg_view('opensearch/description')); + return true; + break; + } + return false; +} 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> |