com web/php: Added default google CSE search.: include/google-cse.inc include/prepend.inc quickref.php results.php
| From: | Philip Olson | Date: | Thu, 16 Aug 2012 07:04:06 +0000 |
| Subject: | com web/php: Added default google CSE search.: include/google-cse.inc include/prepend.inc quickref.php results.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-14517@lists.php.net to get a copy of this message | ||
Commit: 3cd800c78ba6d9705f7936d4eb8abd7d5464b48e
Author: Philip Olson <philip@php.net> Thu, 16 Aug 2012 00:04:06 -0700
Parents: 3866e9ed7e3110ff4e393bfd7bc28e581f340c73
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=3cd800c78ba6d9705f7936d4eb8abd7d5464b48e
Log:
Added default google CSE search.
Changed paths:
D include/google-cse.inc
M include/prepend.inc
M quickref.php
M results.php
Diff:
diff --git a/include/google-cse.inc b/include/google-cse.inc
deleted file mode 100644
index ef4e9e2..0000000
--- a/include/google-cse.inc
+++ /dev/null
@@ -1,13 +0,0 @@
-<div id="cse" style="width: 100%;">Loading</div>
-<script src="http://www.google.com/jsapi"
type="text/javascript"></script>
-<script type="text/javascript">
- google.load('search', '1', {language : 'en', style :
google.loader.themes.MINIMALIST});
- google.setOnLoadCallback(function() {
- var customSearchOptions = {}; var customSearchControl = new google.search.CustomSearchControl(
- '011570197911755000456:fip9wopfz_u', customSearchOptions);
- customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
- var options = new google.search.DrawOptions();
- options.setAutoComplete(true);
- customSearchControl.draw('cse', options);
- }, true);
-</script>
diff --git a/include/prepend.inc b/include/prepend.inc
index 95bce64...4131413 100644
--- a/include/prepend.inc
+++ b/include/prepend.inc
@@ -192,3 +192,29 @@ function myphpnet_beta() {
return false;
}
+// Default: Default search.
+// Lang: Not yet implemented (TODO: Compare google lang codes with ours. We did this for bing
already, so maybe it's an easy fix)
+// TODO: Possible $default escaping issues
+function google_cse($default = '', $lang = 'en') {
+?>
+<div id="cse" style="width: 100%;">Loading</div>
+<script src="http://www.google.com/jsapi"
type="text/javascript"></script>
+<script type="text/javascript">
+ google.load('search', '1', {language : '<?php echo $lang;
?>', style : google.loader.themes.MINIMALIST});
+ google.setOnLoadCallback(function() {
+ var customSearchOptions = {}; var customSearchControl = new google.search.CustomSearchControl(
+ '011570197911755000456:fip9wopfz_u', customSearchOptions);
+ customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
+ var options = new google.search.DrawOptions();
+ options.setAutoComplete(true);
+ customSearchControl.draw('cse', options);
+<?php
+ if ($default) {
+ echo " customSearchControl.execute(" . json_encode($default) . ");";
+ }
+?>
+ }, true);
+</script>
+<?php
+}
+
diff --git a/quickref.php b/quickref.php
index 210d98e..90d89e8 100644
--- a/quickref.php
+++ b/quickref.php
@@ -133,7 +133,11 @@ if ($snippet = is_known_snippet($notfound)) {
?>
<h1>Perform an alternative search here</h1>
-<?php include $_SERVER['DOCUMENT_ROOT'] . '/include/google-cse.inc'; ?>
+<?php
+ // TODO Fix encoding issues. We encode this earlier. Using _decode for now.
+ // We allow users to search for tags like <foo>
+ google_cse(htmlspecialchars_decode($notfound, ENT_QUOTES));
+?>
<h1>PHP Function List</h1>
diff --git a/results.php b/results.php
index 2bdd713..bffb852 100644
--- a/results.php
+++ b/results.php
@@ -64,7 +64,10 @@ if (!is_array($res)) {
// No results for query
if ($res['ResultSet']['totalResultsAvailable'] == 0) {
echo '<h1>Perform an alternative search instead</h1>';
- include $_SERVER['DOCUMENT_ROOT'] . '/include/google-cse.inc';
+
+ // TODO Research possible encoding issues
+ google_cse($q);
+
exit_with_pretty_error(null, 'No matches', 'No pages matched your query');
exit;
}