improve browserintegration and add parsing of get parameter in case
[consearch.git] / index.php
index 0eff2c189714a3319ddabe8bf4ad78511faf4eb7..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>';
     
@@ -43,7 +48,20 @@ if ( isset($_GET['get']) and $_GET['get'] === "opensearchdescription" ) {
 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
 <title>consearch</title>
 <link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAACMuuz63rNKAAAAK0lEQVQI12P4/58BiM4cZ9gdDUVnboNE/n8Hoc6JDLvLGLrLGF4DyWlAcQBYKBgvsgbJOAAAAABJRU5ErkJggg==" type="image/png">
-<link rel="search" type="application/opensearchdescription+xml" href="index.php?get=opensearchdescription<?php if ( $dse ) { echo "&amp;dse=$dse"; } ?>" title="consearch<?php if ( $dse ) { echo " ($dse)"; } ?>">
+<?php
+if ( $browserintegration ) {
+    echo '<link rel="search" type="application/opensearchdescription+xml" href="index.php?get=opensearchdescription';
+    if ( $dse ) {
+        echo "&amp;dse=$dse";
+    }
+    echo '" title="consearch';
+    if ( $dse ) {
+        echo " ($dse)";
+    }
+    echo '">';
+    echo "\n";
+}
+?>
 
 <style type="text/css">
 * {
@@ -110,7 +128,7 @@ b64images["leo.png"] = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACXBIWXMA
 
 <?php
 // for f in *.ico; do for q in {0..100}; do convert -quality $q $f ${f%*.ico}$q.png; done; echo "b64images[\"${f%*.ico}.png\"] = \"$(base64 $(\ls -1S ${f%*.ico}*.png | tail -n 1) | tr -d '\n')\";"; done
-// try optipng
+// try optipng or pngcrush
 // for f in *.png; do echo "b64images[\"${f}\"] = \"$(base64 $f | tr -d '\n')\";"; done > tmp.js
 ?>
 
@@ -134,7 +152,8 @@ se["osm"] = ["osm", "https://www.openstreetmap.org/?query=", "osm.png"];
 se["gm"] = ["g-maps", "https://www.google.de/maps/preview?hl=de&q=", "gm.png"];
 se["uu"] = ["uu_wiki", "http://wiki.ubuntuusers.de/", "uu.png"];
 se["man"] = ["u_man", "http://manpages.ubuntu.com/cgi-bin/search.py?ie=UTF-8&titles=Title&q=", "man-u.png"];
-se["ups"] = ["ups", "http://packages.ubuntu.com/search?searchon=names&suite=all&section=all&keywords=", "man-u.png"];
+se["dps"] = ["deb-pkg", "https://packages.debian.org/search?searchon=names&suite=all&section=all&keywords=", ""];
+se["ups"] = ["uu-pkg", "http://packages.ubuntu.com/search?searchon=names&suite=all&section=all&keywords=", "man-u.png"];
 se["yt"] = ["youtube", "https://www.youtube.com/results?search_query=", "yt.png"];
 se["imdb"] = ["imdb", "http://www.imdb.com/find?s=all&q=", "imdb.png"];
 se["az"] = ["amazon", "https://www.amazon.de/s/?url=search-alias%3Daps&field-keywords=", "az.png"];
@@ -148,18 +167,24 @@ se["gh"] = ["github", "https://github.com/search?utf8=✓&q=", ""];
 se["bb"] = ["bing", "https://www.bing.com/search?q=", ""];
 se["mdn"] = ["mdn", "https://developer.mozilla.org/search?q=", ""];
 se["ctan"] = ["ctan", "http://ctan.org/search/?phrase=", ""];
-se["gpg"] = ["gpg_key", "https://pgp.mit.edu/pks/lookup?op=index&fingerprint=on&search=", ""];
+se["gpg"] = ["pgp.mit", "https://pgp.mit.edu/pks/lookup?op=index&fingerprint=on&search=", ""];
+se["amo"] = ["amo", "https://addons.mozilla.org/search/?q=", ""];
 se["gsm"] = ["gsm", "http://www.gsmarena.com/results.php3?sQuickSearch=yes&sName=", ""];
+se["ck"] = ["chfkch", "http://www.chefkoch.de/suche.php?wo=2&suche=", ""];
+se["ypi"] = ["ypi", "http://youpronounce.it/search.jsp?q=", ""];
 
 function display_searchbuttons() {
     document.getElementById("searchbuttons").innerHTML = "";
     for ( kw in se ) {
-        document.getElementById("searchbuttons").innerHTML += '<button type="button" value="' + se[kw][0] + '" onclick=\'location.href="' + se[kw][1] + '" + document.getElementById("querystring").value\'><img src="data:image/png;base64,' + b64images[se[kw][2]] + '" alt="">&nbsp;' + se[kw][0] + "</button> \n";
+        document.getElementById("searchbuttons").innerHTML += '<button type="button" title="' + kw + '" value="' + se[kw][0] + '" onclick=\'location.href="' + se[kw][1] + '" + document.getElementById("querystring").value\'><img src="data:image/png;base64,' + b64images[se[kw][2]] + '" alt="">&nbsp;' + se[kw][0] + "</button> \n";
     }
 }
 
 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();
@@ -198,7 +223,7 @@ if ( $dse ) {
 
 <body onload="parse_fragmentstring();">
 
-<h1><a href="">fpunktk.de/consearch</a></h1>
+<h1><a href="./">fpunktk.de/consearch</a></h1>
 
 <noscript>
 <p style="color: red; font-size: 200%; font-weight: bold;">
@@ -206,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>
@@ -213,6 +245,26 @@ please enable javascript
 <div id="searchbuttons">
 </div>
 
+<p>
+<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>