- Query: ``foo bar site:example.org/dir/``
- or use the ``site`` GET parameter:
``/?q=foo&site=example.org/dir``
+- OpenSearch support with HTML and Atom result lists
============
<link rel="stylesheet" href="css/phinde.css"/>
<link rel="icon" href="favicon.ico"/>
<meta name="generator" content="phinde" />
+ <link rel="search" title="{{apptitle}}" type="application/opensearchdescription+xml" href="/opensearchdescription.php"/>
{% block meta %}{% endblock %}
</head>
<body>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom"
+ xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
+ <title>"{{query}}" search results</title>
+ <link rel="self" href="{{fullUrl}}" type="application/atom+xml"/>
+ <updated>{{"now"|date("c")}}</updated>
+ <id>{{fullUrl}}</id>
+ <opensearch:totalResults>{{hitcount}}</opensearch:totalResults>
+ {% for hit in hits %}
+ {% set doc = hit._source %}
+ <entry>
+ <title>{{doc.title}}</title>
+ <link href="{{doc.url}}"/>
+ <id>{{doc.url}}</id>
+ {% if doc.modate %}
+ <updated>{{doc.modate|date('c')}}</updated>
+ {% endif %}
+ <content type="text">{{doc.htmlText|striptags}}</content>
+ </entry>
+ {% endfor %}
+</feed>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+ <ShortName>{{apptitle}}</ShortName>
+ <Description>Search</Description>
+ <Url type="application/atom+xml" rel="results"
+ template="{{absBaseUrl}}?q={searchTerms}&page={startPage?}&format=opensearch"/>
+ <Url type="text/html" rel="results" method="get"
+ template="{{absBaseUrl}}?q={searchTerms}"/>
+</OpenSearchDescription>
<div class="container">
<ul class="nav">
<li>
- <a class="brand" href="{{baseurl}}">{{apptitle}}</a>
+ <a class="brand" href="{{baseUrl}}">{{apptitle}}</a>
</li>
</ul>
<form class="navbar-form pull-left">
)
);
}
+
+ /**
+ * Create a full URL with protocol and host name
+ *
+ * @param string $path Path to the file, with leading /
+ *
+ * @return string Full URL
+ */
+ public static function fullUrl($path = '/')
+ {
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
+ $prot = 'https';
+ } else {
+ $prot = 'http';
+ }
+ return $prot . '://' . $_SERVER['HTTP_HOST'] . $path;
+ }
+
}
?>
);
$urlSortDate = $urlSortRelevance . '&sort=date';
+if (isset($_GET['format']) && $_GET['format'] == 'opensearch') {
+ $template = 'opensearch';
+ $baseLink .= '&format=opensearch';
+ header('Content-type: application/atom+xml');
+} else {
+ $template = 'search';
+}
+
render(
- 'search',
+ $template,
array(
'queryTime' => round($timeEnd - $timeBegin, 2) . 's',
'query' => $query,
+ 'fullUrl' => Helper::fullUrl($baseLink),
'cleanQuery' => $cleanQuery,
'urlNoSite' => $urlNoSite,
'site' => $site,
--- /dev/null
+<?php
+namespace phinde;
+/**
+ * OpenSearch XML description element
+ *
+ * @link http://www.opensearch.org/
+ */
+require 'www-header.php';
+
+header('Content-type: application/opensearchdescription+xml');
+render(
+ 'opensearchdescription',
+ array(
+ 'absBaseUrl' => Helper::fullUrl('/'),
+ )
+);
+?>
\ No newline at end of file
//$vars['htmlhelper'] = new HtmlHelper();
}
$vars['apptitle'] = 'cweiske.de search';
- $vars['baseurl'] = '/';
+ $vars['baseUrl'] = '/';
$template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
if ($return) {