add parsing of get variable for default search engine
authorfpunktk <git@fpunktk.de>
Thu, 28 May 2015 18:18:49 +0000 (20:18 +0200)
committerfpunktk <git@fpunktk.de>
Thu, 28 May 2015 18:18:49 +0000 (20:18 +0200)
index.php

index 1f3311e..fd5297f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,9 +1,4 @@
 <!DOCTYPE html>
-<html>
-<head>
-<meta charset="UTF-8">
-<meta http-equiv="content-type" content="text/html; charset=UTF-8">
-<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
 
 <!--
 consearch
@@ -17,9 +12,21 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
 You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
 -->
 
+<?php
+$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'];
+}
+?>
+
+<html>
+<head>
+<meta charset="UTF-8">
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<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="opensearchdescription-consearch.xml.php" title="consearch">
+<link rel="search" type="application/opensearchdescription+xml" href="opensearchdescription-consearch.xml.php<?php if ( $dse ) { echo "?dse=$dse"; } ?>" title="consearch<?php if ( $dse ) { echo " ($dse)"; } ?>">
 
 <style type="text/css">
 * {
@@ -83,9 +90,12 @@ b64images["ud.png"] = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAIAAADAAbR1AAAABmJLR0T//
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 // 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
 // for f in *.png; do echo "b64images[\"${f}\"] = \"$(base64 $f | tr -d '\n')\";"; done > tmp.js
+?>
 
 var se = new Object(); // object of search engines
 // se["keyword"] = ["displayed name, max 7 chars", "url to which the querystring can be append", "b64images name"];
@@ -135,12 +145,18 @@ function parse_fragmentstring() {
             location.href = se[kw][1] + fragmentarr.join(" ");
         } else {
             // there is no keyword
-            // display all buttons and write the fragmentstring into the querystring input
-            document.getElementById("querystring").value = fragmentarr.join(" ");
+<?php
+if ( $dse ) {
+    // use a default searchengine
+    echo '            location.href = se["' . $dse . '"][1] + fragmentarr.join(" ");
+';
+} else {
+    // display all buttons and write the fragmentstring into the querystring input
+    echo '            document.getElementById("querystring").value = fragmentarr.join(" ");
             display_searchbuttons();
-            // or
-            // use a default searchengine
-            //location.href = se["sp"][1] + fragmentarr.join(" ");
+';
+}
+?>
         }
     }
 }