Changed the way search modules get integrated with the theme via a new region "search".
Improved current module for google search 2.0.
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"gcse": {
|
|
||||||
"cx":""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"gcse": {
|
"gcse": {
|
||||||
"cx":""
|
"search_engine_id":""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<form action="{$site_url/}gcse20" class="search-form" id="search-form">
|
||||||
|
<div class="form-group has-feedback">
|
||||||
|
<input type="search" class="form-control" name="q" id="search-query" placeholder="search" value="{htmlentities}{$cms_search_query/}{/htmlentities}" >
|
||||||
|
<span class="glyphicon glyphicon-search form-control-feedback"></span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -37,17 +37,14 @@
|
|||||||
{$page.primary_nav/}
|
{$page.primary_nav/}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{if isset="$page.regions.search"}
|
||||||
<!-- Page search -->
|
<!-- Page search -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-2 col-md-offset-9">
|
<div class="col-md-2 col-md-offset-9">
|
||||||
<form action="{$site_url/}gcse20" class="search-form" id="gcse_search_form">
|
{$page.regions.search/}
|
||||||
<div class="form-group has-feedback">
|
|
||||||
<input type="search" class="form-control" name="q" id="gcse_search" placeholder="search" value="{htmlentities}{$cms_search_query/}{/htmlentities}" >
|
|
||||||
<span class="glyphicon glyphicon-search form-control-feedback"></span>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<!-- General Page Content -->
|
<!-- General Page Content -->
|
||||||
<div id='content' class='row-fluid'>
|
<div id='content' class='row-fluid'>
|
||||||
<!-- Left Sidebar sidebar_first -->
|
<!-- Left Sidebar sidebar_first -->
|
||||||
|
|||||||
6
examples/demo/site/themes/bootstrap/search.tpl
Normal file
6
examples/demo/site/themes/bootstrap/search.tpl
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<form action="{$site_url/}search" class="search-form" id="search-form">
|
||||||
|
<div class="form-group has-feedback">
|
||||||
|
<input type="search" class="form-control" name="q" id="search-query" placeholder="search" value="{htmlentities}{$cms_search_query/}{/htmlentities}" >
|
||||||
|
<span class="glyphicon glyphicon-search form-control-feedback"></span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -4,6 +4,7 @@ author=jvelilla
|
|||||||
version=0.1
|
version=0.1
|
||||||
regions[page_top] = Top
|
regions[page_top] = Top
|
||||||
regions[header] = Header
|
regions[header] = Header
|
||||||
|
regions[search] = Search
|
||||||
regions[content] = Content
|
regions[content] = Content
|
||||||
regions[highlighted] = Highlighted
|
regions[highlighted] = Highlighted
|
||||||
regions[help] = Help
|
regions[help] = Help
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
Google Custom Search Module 2.0.
|
Google Custom Search Module 2.0.
|
||||||
|
|
||||||
https://developers.google.com/custom-search/docs/element
|
# Based on Google Custom Search Engine (CSE)
|
||||||
The current solution is based on
|
- https://developers.google.com/custom-search/docs/element
|
||||||
Results only <gcse:searchresults-only>
|
- Search form provides a parameter `q` for the search query.
|
||||||
|
- Results are displayed in associated page /gcse2 (using <gcse:searchresults-only> )
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
- edit the `site/modules/google_search_20/config/google_search_20.json` file, and set the value `gcse.search_engine_id`.
|
||||||
|
|
||||||
|
# How to get a Custom Search engine ID?
|
||||||
|
- See https://support.google.com/customsearch/answer/2649143?hl=en
|
||||||
|
- https://cse.google.com/all
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"gcse": {
|
||||||
|
"search_engine_id":""
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<form action="{$site_url/}gcse20" class="search-form" id="search-form">
|
||||||
|
<div class="form-group has-feedback">
|
||||||
|
<input type="search" class="form-control" name="q" id="search-query" placeholder="search" value="{htmlentities}{$cms_search_query/}{/htmlentities}" >
|
||||||
|
<span class="glyphicon glyphicon-search form-control-feedback"></span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<section>
|
<section>
|
||||||
<header>
|
<header>
|
||||||
<h2>Results for <kbd>{$result.current_page.search_terms/}</kbd></h2>
|
<h2>Results for <kbd>{$cms_search_query/}</kbd></h2>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<gcse:searchresults-only></gcse:searchresults-only>
|
<gcse:searchresults-only></gcse:searchresults-only>
|
||||||
@@ -9,7 +9,6 @@ class
|
|||||||
GOOGLE_CUSTOM_SEARCH_MODULE_20
|
GOOGLE_CUSTOM_SEARCH_MODULE_20
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
CMS_MODULE
|
CMS_MODULE
|
||||||
redefine
|
redefine
|
||||||
setup_hooks
|
setup_hooks
|
||||||
@@ -19,7 +18,7 @@ inherit
|
|||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
CMS_HOOK_RESPONSE_ALTER
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_BLOCK_HELPER
|
CMS_HOOK_BLOCK_HELPER
|
||||||
|
|
||||||
@@ -64,13 +63,13 @@ feature -- Router
|
|||||||
feature -- GCSE Keys
|
feature -- GCSE Keys
|
||||||
|
|
||||||
gcse_cx_key (api: CMS_API): detachable READABLE_STRING_8
|
gcse_cx_key (api: CMS_API): detachable READABLE_STRING_8
|
||||||
-- Get google custom search cx key.
|
-- Get google custom search engine id.
|
||||||
local
|
local
|
||||||
utf: UTF_CONVERTER
|
utf: UTF_CONVERTER
|
||||||
do
|
do
|
||||||
if attached api.module_configuration (Current, Void) as cfg then
|
if attached api.module_configuration (Current, Void) as cfg then
|
||||||
if
|
if
|
||||||
attached cfg.text_item ("gcse.cx") as l_gcse_cx_key and then
|
attached cfg.text_item ("gcse.search_engine_id") as l_gcse_cx_key and then
|
||||||
not l_gcse_cx_key.is_empty
|
not l_gcse_cx_key.is_empty
|
||||||
then
|
then
|
||||||
Result := utf.utf_32_string_to_utf_8_string_8 (l_gcse_cx_key)
|
Result := utf.utf_32_string_to_utf_8_string_8 (l_gcse_cx_key)
|
||||||
@@ -83,6 +82,8 @@ feature -- Handler
|
|||||||
handle_search (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_search (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
|
l_script: STRING
|
||||||
|
b: CMS_CONTENT_BLOCK
|
||||||
do
|
do
|
||||||
write_debug_log (generator + ".handle_search")
|
write_debug_log (generator + ".handle_search")
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
@@ -95,9 +96,16 @@ feature -- Handler
|
|||||||
then
|
then
|
||||||
r.set_value (l_query.value, "cms_search_query")
|
r.set_value (l_query.value, "cms_search_query")
|
||||||
if
|
if
|
||||||
attached smarty_template_block (Current, "search", api) as l_tpl_block
|
attached smarty_template_block (Current, "gcse_search_results", api) as l_tpl_block
|
||||||
then
|
then
|
||||||
r.add_block (l_tpl_block, "content")
|
r.add_block (l_tpl_block, "content")
|
||||||
|
|
||||||
|
if attached gcse_cx_key (api) as l_ctx then
|
||||||
|
create l_script.make_from_string (gcse_20_script)
|
||||||
|
l_script.replace_substring_all ("#CX_VALUE", l_ctx)
|
||||||
|
create b.make_raw ("gcse2_js", Void, "<script>%N" + l_script + "%N</script>", Void)
|
||||||
|
r.add_block (b, "footer")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -106,7 +114,6 @@ feature -- Handler
|
|||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Hooks configuration
|
feature -- Hooks configuration
|
||||||
|
|
||||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
@@ -115,18 +122,25 @@ feature -- Hooks configuration
|
|||||||
auto_subscribe_to_hooks (a_hooks)
|
auto_subscribe_to_hooks (a_hooks)
|
||||||
end
|
end
|
||||||
|
|
||||||
response_alter (a_response: CMS_RESPONSE)
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
-- <Precursor>
|
|
||||||
local
|
|
||||||
l_script: STRING
|
|
||||||
do
|
do
|
||||||
if attached gcse_cx_key (a_response.api) as l_ctx then
|
Result := <<"gcse_search_form">>
|
||||||
create l_script.make_from_string (gcse_20_script)
|
|
||||||
l_script.replace_substring_all ("#CX_VALUE", l_ctx)
|
|
||||||
a_response.add_javascript_content (l_script)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
|
do
|
||||||
|
if a_block_id.is_case_insensitive_equal_general ("gcse_search_form") then
|
||||||
|
if a_response.request.is_get_request_method then
|
||||||
|
if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
|
||||||
|
a_response.add_block (l_tpl_block, "search")
|
||||||
|
else
|
||||||
|
debug ("cms")
|
||||||
|
a_response.add_warning_message ("Error with block [" + a_block_id + "]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
@@ -134,9 +148,9 @@ feature {NONE} -- Implementation
|
|||||||
(function() {
|
(function() {
|
||||||
var cx = '#CX_VALUE';
|
var cx = '#CX_VALUE';
|
||||||
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
|
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
|
||||||
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
|
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
|
||||||
'//www.google.com/cse/cse.js?cx=' + cx;
|
var s = document.getElementsByTagName('script')[0];
|
||||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
|
s.parentNode.insertBefore(gcse, s);
|
||||||
})();
|
})();
|
||||||
]"
|
]"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user