Merge remote-tracking branch 'jvelilla/roc_google_search2.0' into roc_gs2.0
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
<library name="cms_feed_aggregator_module" location="..\..\modules\feed_aggregator\feed_aggregator-safe.ecf" readonly="false"/>
|
||||
<library name="cms_files_module" location="..\..\modules\files\files-safe.ecf" readonly="false"/>
|
||||
<library name="cms_google_search_module" location="..\..\modules\google_search\google_search-safe.ecf" readonly="false" use_application_options="true"/>
|
||||
<library name="cms_google_search_20_module" location="..\..\modules\google_search_20\google_search_20-safe.ecf" readonly="false" use_application_options="true"/>
|
||||
<library name="cms_messaging_module" location="..\..\modules\messaging\messaging-safe.ecf" readonly="false"/>
|
||||
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
|
||||
<library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"contact": { "location": "../../modules/contact" },
|
||||
"feed_aggregator": { "location": "../../modules/feed_aggregator" },
|
||||
"google_search": { "location": "../../modules/google_search" },
|
||||
"google_search_20": { "location": "../../modules/google_search_20" },
|
||||
"node": { "location": "../../modules/node" },
|
||||
"oauth20": { "location": "../../modules/oauth20" },
|
||||
"openid": { "location": "../../modules/openid" },
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"gcse": {
|
||||
"cx":""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<section>
|
||||
<header>
|
||||
<h2>Results for <kbd>{$cms_search_query/}</kbd></h2>
|
||||
</header>
|
||||
|
||||
<gcse:searchresults-only></gcse:searchresults-only>
|
||||
</section>
|
||||
@@ -40,7 +40,7 @@
|
||||
<!-- Page search -->
|
||||
<div class="row">
|
||||
<div class="col-md-2 col-md-offset-9">
|
||||
<form action="{$site_url/}gcse" class="search-form" id="gcse_search_form">
|
||||
<form action="{$site_url/}gcse20" class="search-form" id="gcse_search_form">
|
||||
<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>
|
||||
|
||||
@@ -86,7 +86,7 @@ feature -- CMS modules
|
||||
|
||||
-- Miscellanious
|
||||
a_setup.register_module (create {CMS_MESSAGING_MODULE}.make)
|
||||
a_setup.register_module (create {GOOGLE_CUSTOM_SEARCH_MODULE}.make)
|
||||
a_setup.register_module (create {GOOGLE_CUSTOM_SEARCH_MODULE_20}.make)
|
||||
a_setup.register_module (create {CMS_CUSTOM_BLOCK_MODULE}.make)
|
||||
a_setup.register_module (create {CMS_DEBUG_MODULE}.make)
|
||||
a_setup.register_module (create {CMS_DEMO_MODULE}.make)
|
||||
|
||||
5
modules/google_search_20/Readme.md
Normal file
5
modules/google_search_20/Readme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Google Custom Search Module 2.0.
|
||||
|
||||
https://developers.google.com/custom-search/docs/element
|
||||
The current solution is based on
|
||||
Results only <gcse:searchresults-only>
|
||||
20
modules/google_search_20/google_search_20-safe.ecf
Normal file
20
modules/google_search_20/google_search_20-safe.ecf
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-16-0 http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="google_search_20" uuid="3FAAD593-3428-43B9-8CE1-BC6E5FE81F19" library_target="google_search_20">
|
||||
<target name="google_search_20">
|
||||
<root all_classes="true"/>
|
||||
<capability>
|
||||
<concurrency support="scoop" use="scoop"/>
|
||||
</capability>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="cms" location="..\..\cms-safe.ecf" readonly="false"/>
|
||||
<library name="cms_app_env" location="..\..\library\app_env\app_env-safe.ecf" readonly="false"/>
|
||||
<library name="cms_config" location="..\..\library\configuration\config-safe.ecf"/>
|
||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||
<cluster name="src" location="src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
19
modules/google_search_20/google_search_20.ecf
Normal file
19
modules/google_search_20/google_search_20.ecf
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="google_search" uuid="3FAAD593-3428-43B9-8CE1-BC6E5FE81F19" library_target="google_search_20">
|
||||
<target name="google_search_20">
|
||||
<root all_classes="true"/>
|
||||
<option is_attached_by_default="false" void_safety="none">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="cms" location="..\..\cms.ecf" readonly="false"/>
|
||||
<library name="cms_app_env" location="..\..\library\app_env\app_env.ecf" readonly="false"/>
|
||||
<library name="cms_config" location="..\..\library\configuration\config.ecf"/>
|
||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
||||
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf"/>
|
||||
<cluster name="src" location="src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"gcse": {
|
||||
"cx":""
|
||||
}
|
||||
}
|
||||
7
modules/google_search_20/site/templates/block_search.tpl
Normal file
7
modules/google_search_20/site/templates/block_search.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
<section>
|
||||
<header>
|
||||
<h2>Results for <kbd>{$result.current_page.search_terms/}</kbd></h2>
|
||||
</header>
|
||||
|
||||
<gcse:searchresults-only></gcse:searchresults-only>
|
||||
</section>
|
||||
142
modules/google_search_20/src/google_custom_search_module_20.e
Normal file
142
modules/google_search_20/src/google_custom_search_module_20.e
Normal file
@@ -0,0 +1,142 @@
|
||||
note
|
||||
description: "[
|
||||
Module providing Google Custom Search functionality.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GOOGLE_CUSTOM_SEARCH_MODULE_20
|
||||
|
||||
inherit
|
||||
|
||||
CMS_MODULE
|
||||
redefine
|
||||
setup_hooks
|
||||
end
|
||||
|
||||
CMS_HOOK_AUTO_REGISTER
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
CMS_HOOK_RESPONSE_ALTER
|
||||
|
||||
CMS_HOOK_BLOCK_HELPER
|
||||
|
||||
SHARED_EXECUTION_ENVIRONMENT
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
SHARED_LOGGER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Create current module
|
||||
do
|
||||
version := "2.0"
|
||||
description := "Google custome search module 2.0"
|
||||
package := "search"
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "google_search_20"
|
||||
-- <Precursor>
|
||||
|
||||
feature -- Router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- Router configuration.
|
||||
local
|
||||
m: WSF_URI_MAPPING
|
||||
do
|
||||
create m.make_trailing_slash_ignored ("/gcse20", create {WSF_URI_AGENT_HANDLER}.make (agent handle_search (a_api, ?, ?)))
|
||||
a_router.map (m, a_router.methods_head_get)
|
||||
end
|
||||
|
||||
feature -- GCSE Keys
|
||||
|
||||
gcse_cx_key (api: CMS_API): detachable READABLE_STRING_8
|
||||
-- Get google custom search cx key.
|
||||
local
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
if attached api.module_configuration (Current, Void) as cfg then
|
||||
if
|
||||
attached cfg.text_item ("gcse.cx") as l_gcse_cx_key and then
|
||||
not l_gcse_cx_key.is_empty
|
||||
then
|
||||
Result := utf.utf_32_string_to_utf_8_string_8 (l_gcse_cx_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Handler
|
||||
|
||||
handle_search (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
do
|
||||
write_debug_log (generator + ".handle_search")
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||
if
|
||||
attached {WSF_STRING} req.query_parameter ("q") as l_query and then
|
||||
not l_query.value.is_empty
|
||||
then
|
||||
if
|
||||
attached gcse_cx_key (api) as l_cx
|
||||
then
|
||||
r.set_value (l_query.value, "cms_search_query")
|
||||
if
|
||||
attached smarty_template_block (Current, "search", api) as l_tpl_block
|
||||
then
|
||||
r.add_block (l_tpl_block, "content")
|
||||
end
|
||||
end
|
||||
else
|
||||
r.add_message ("No query submitted", Void)
|
||||
end
|
||||
r.execute
|
||||
end
|
||||
|
||||
|
||||
feature -- Hooks configuration
|
||||
|
||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||
-- Module hooks configuration.
|
||||
do
|
||||
auto_subscribe_to_hooks (a_hooks)
|
||||
end
|
||||
|
||||
response_alter (a_response: CMS_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_script: STRING
|
||||
do
|
||||
if attached gcse_cx_key (a_response.api) as l_ctx then
|
||||
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
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
gcse_20_script: STRING = "[
|
||||
(function() {
|
||||
var cx = '#CX_VALUE';
|
||||
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
|
||||
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
|
||||
'//www.google.com/cse/cse.js?cx=' + cx;
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
|
||||
})();
|
||||
]"
|
||||
end
|
||||
Reference in New Issue
Block a user