improve browserintegration and add parsing of get parameter in case
[consearch.git] / index.php
index d0c2543a1559bbb43f22d1b8c536c30e584c6478..2321c8be56d9ba4563f7af65b931cd8af11073e5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -15,8 +15,13 @@ $dse = "";
 if ( isset($_GET['dse']) and preg_match('/^[0-9a-z]{1,5}$/', $_GET['dse']) === 1 ) { // TODO: prevent injection, check whether dse is a valid searchengine
     $dse = $_GET['dse'];
 }
+$browserintegration = "";
+if ( isset($_GET['include']) and $_GET['include'] == "browserintegration" ) {
+    $browserintegration = "true";
+}
 
 if ( isset($_GET['get']) and $_GET['get'] === "opensearchdescription" ) {
+    header('Content-Type: text/xml');
     echo '<?xml version="1.0" encoding="UTF-8"?>
 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 <ShortName>consearch';
@@ -27,7 +32,7 @@ if ( isset($_GET['get']) and $_GET['get'] === "opensearchdescription" ) {
 <Contact>consearch @ f p u n k t k . de</Contact>
 <Url type="text/html" template="https://www.fpunktk.de/consearch/index.php';
     if ( $dse ) { echo "?dse=$dse"; }
-    echo '#{searchTerms}" />
+    echo '#{searchTerms}"></Url>
 <Image height="16" width="16" type="image/png">https://www.fpunktk.de/consearch/consearch.png</Image>
 </OpenSearchDescription>';
     
@@ -44,7 +49,7 @@ if ( isset($_GET['get']) and $_GET['get'] === "opensearchdescription" ) {
 <title>consearch</title>
 <link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAACMuuz63rNKAAAAK0lEQVQI12P4/58BiM4cZ9gdDUVnboNE/n8Hoc6JDLvLGLrLGF4DyWlAcQBYKBgvsgbJOAAAAABJRU5ErkJggg==" type="image/png">
 <?php
-if ( isset($_GET['include']) and $_GET['include'] == "opensearchdescriptionlink" ) {
+if ( $browserintegration ) {
     echo '<link rel="search" type="application/opensearchdescription+xml" href="index.php?get=opensearchdescription';
     if ( $dse ) {
         echo "&amp;dse=$dse";
@@ -177,6 +182,9 @@ function display_searchbuttons() {
 
 function parse_fragmentstring() {
     var fragmentstring = document.URL.substr( document.URL.split("#")[0].length + 1 );
+    if ( fragmentstring == "" ) {
+        var fragmentstring = document.URL.substr( document.URL.split("consearchterm=")[0].length + 14 );
+    }
     if ( fragmentstring == "" ) {
         display_searchbuttons();
         document.getElementById("querystring").focus();
@@ -223,6 +231,13 @@ please enable javascript
 </p>
 </noscript>
 
+<?php
+if ( $browserintegration ) {
+    // hide input and searchbuttons
+    echo '<div style="display: none;">' . "\n";
+}
+?>
+
 <div>
 <label><input id="querystring" type="text"></label>
 </div>
@@ -231,9 +246,25 @@ please enable javascript
 </div>
 
 <p>
-<a href="?include=opensearchdescriptionlink">add to browser</a>
+<a href="?include=browserintegration">add to browser</a>
+</p>
+
+<?php
+if ( $browserintegration ) {
+    echo '</div>
+
+<p>
+Now add consearch to your browser. In firefox this is done via the searchbar. If this does not work then consearch can be added via the following form, but this would send all queries to the server :-(
 </p>
 
+<form method="GET" action="./">' . "\n";
+    if ( $dse ) { echo '<input type="hidden" name="dse" value="' . $dse . '">' . "\n"; }
+    echo '<input type="text" name="consearchterm" value="">
+</form>
+';
+}
+?>
+
 <p>
 <a href="https://github.com/fpunktk/consearch">about</a>
 </p>