diff --git a/examples/demo/demo-safe.ecf b/examples/demo/demo-safe.ecf index 2f8ffc1..83bb689 100644 --- a/examples/demo/demo-safe.ecf +++ b/examples/demo/demo-safe.ecf @@ -26,7 +26,7 @@ - + -
    +
      {foreach from="$result.items" item="item"} @@ -18,7 +18,7 @@
      -

      {htmlentities}{$item.snippet/}{/htmlentities}

      +

      {$item.html_snippet/}

      @@ -37,4 +37,4 @@
    1. Next
    2. {/if} - \ No newline at end of file + diff --git a/examples/demo/site/themes/bootstrap/assets/js/popup_search.js b/examples/demo/site/themes/bootstrap/assets/js/popup_search.js new file mode 100644 index 0000000..5854223 --- /dev/null +++ b/examples/demo/site/themes/bootstrap/assets/js/popup_search.js @@ -0,0 +1,8 @@ + $(document).ready(function() { + $('#gcse_search_form').submit(function() { + window.open('', 'formpopup', 'width=600,height=600,resizeable,scrollbars'); + this.target = 'formpopup'; + }); + }); + + diff --git a/examples/demo/site/themes/bootstrap/page.tpl b/examples/demo/site/themes/bootstrap/page.tpl index aba3059..76eb77a 100644 --- a/examples/demo/site/themes/bootstrap/page.tpl +++ b/examples/demo/site/themes/bootstrap/page.tpl @@ -5,9 +5,10 @@ - + + {if isset="$head"}{$head/}{/if} {if isset="$styles"}{$styles/}{/if} @@ -21,7 +22,10 @@ {$head_title/} + + + {if isset="$region_top"} @@ -40,7 +44,7 @@
      -
      +
      diff --git a/library/gcse/gcse.ecf b/library/gcse/gcse.ecf index a086fb8..707023d 100644 --- a/library/gcse/gcse.ecf +++ b/library/gcse/gcse.ecf @@ -1,28 +1,21 @@ - + - - /.git$ - /EIFGENs$ - /CVS$ - /.svn$ - + + /.git$ + /EIFGENs$ + /CVS$ + /.svn$ + - - - - - - + + diff --git a/library/gcse/src/gcse_api.e b/library/gcse/src/gcse_api.e index 5a46f82..213b3c5 100644 --- a/library/gcse/src/gcse_api.e +++ b/library/gcse/src/gcse_api.e @@ -19,17 +19,17 @@ feature {NONE} -- Initialization make (a_query_parameters: GCSE_QUERY_PARAMETERS) -- Create an object GCSE with query_parameters `a_query_parameters' do - query_paremeter := a_query_parameters + query_parameter := a_query_parameters ensure - query_parameters_set: query_paremeter = a_query_parameters + query_parameters_set: query_parameter = a_query_parameters end feature -- Access base_uri: STRING_8 = "https://www.googleapis.com/customsearch/v1" - -- Google custom search base URI + -- Google custom search base URI. - query_paremeter: GCSE_QUERY_PARAMETERS + query_parameter: GCSE_QUERY_PARAMETERS -- Google custom search parameters. last_result: detachable GCSE_RESPONSE @@ -38,7 +38,7 @@ feature -- Access feature -- Status Reports errors: detachable LIST [READABLE_STRING_8] - -- optional table of error codes + -- optional list of error messages. feature -- API @@ -53,12 +53,15 @@ feature -- API -- but it's possible to define atom response using the alt parameter. last_result := Void if attached get as l_response then + create l_gcse_response + l_gcse_response.set_status (l_response.status) + l_gcse_response.set_status_nessage (l_response.status_message) + if attached l_response.body as l_body then create l_parser.make_with_string (l_body) l_parser.parse_content - if l_parser.is_parsed and then attached {JSON_OBJECT} l_parser.parsed_json_object as jv then + if l_response.status = 200 and then l_parser.is_parsed and then attached {JSON_OBJECT} l_parser.parsed_json_object as jv then -- Queries - create l_gcse_response if attached {JSON_OBJECT} jv.item (queries_key) as jqueries then -- Next Page if attached {GCSE_PAGE} query_page (next_page_key, jqueries) as l_page then @@ -80,7 +83,8 @@ feature -- API end end end - + else + put_error (l_body) end else put_error (l_response.status.out) @@ -107,7 +111,7 @@ feature {NONE} -- Implementation new_uri: STRING_8 -- new uri (BaseUri?key=secret_value&cx=a_cx_id&q=a_query -- ?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures - -- full teamplte BaseUri?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}& + -- full template BaseUri?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}& -- safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}& -- googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}& -- siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}& @@ -118,24 +122,24 @@ feature {NONE} -- Implementation do create Result.make_from_string (base_uri) Result.append ("?key=") - Result.append (query_paremeter.secret) + Result.append (query_parameter.secret) Result.append ("&cx=") - Result.append (query_paremeter.cx) + Result.append (query_parameter.cx) Result.append ("&q=") - Result.append (query_paremeter.query) + Result.append (query_parameter.query) -- num - if attached query_paremeter.num as l_num then + if attached query_parameter.num as l_num then Result.append ("&num=") Result.append (l_num) end - if attached query_paremeter.start as l_start then + if attached query_parameter.start as l_start then Result.append ("&start=") Result.append (l_start) end end - put_error (a_code: READABLE_STRING_GENERAL) - -- put error with code `a_code'. + put_error (a_message: READABLE_STRING_GENERAL) + -- put error message `a_message'. local l_errors: like errors utf: UTF_CONVERTER @@ -145,35 +149,35 @@ feature {NONE} -- Implementation create {ARRAYED_LIST [STRING]} l_errors.make (1) errors := l_errors end - l_errors.force (utf.utf_32_string_to_utf_8_string_8 (a_code)) + l_errors.force (utf.utf_32_string_to_utf_8_string_8 (a_message)) end item (a_item: JSON_OBJECT): GCSE_PAGE_ITEM -- Google Result Metadata Item. do create Result - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("kind")) as l_kind then + if attached {JSON_STRING} a_item.item ("kind") as l_kind then Result.set_kind (l_kind.item) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("title")) as l_title then + if attached {JSON_STRING} a_item.item ("title") as l_title then Result.set_title (l_title.item) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("htmlTitle")) as l_htmltitle then - Result.set_html_title (l_htmltitle.item) + if attached {JSON_STRING} a_item.item ("htmlTitle") as l_htmltitle then + Result.set_html_title (l_htmltitle.unescaped_string_32) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("link")) as l_link then + if attached {JSON_STRING} a_item.item ("link") as l_link then Result.set_link (l_link.item) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("displayLink")) as l_display_link then + if attached {JSON_STRING} a_item.item ("displayLink") as l_display_link then Result.set_display_link (l_display_link.item) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("snippet")) as l_snippet then - Result.set_snippet (l_snippet.item) + if attached {JSON_STRING} a_item.item ("snippet") as l_snippet then + Result.set_snippet (l_snippet.unescaped_string_8) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("htmlSnippet")) as l_html_snippet then - Result.set_html_snippet (l_html_snippet.item) + if attached {JSON_STRING} a_item.item ("htmlSnippet") as l_html_snippet then + Result.set_html_snippet (l_html_snippet.unescaped_string_32) end - if attached {JSON_STRING} a_item.item (create {JSON_STRING}.make_from_string ("formattedUrl")) as l_formatted_url then + if attached {JSON_STRING} a_item.item ("formattedUrl") as l_formatted_url then Result.set_formatted_url (l_formatted_url.item) end end @@ -181,22 +185,26 @@ feature {NONE} -- Implementation query_page (a_page_key: JSON_STRING; a_queries: JSON_OBJECT): detachable GCSE_PAGE -- Google result medata query. Return a query page based for a query with page key `a_page_key', if any. do - if attached {JSON_ARRAY} a_queries.item (a_page_key) as jquerypage and then attached {JSON_OBJECT} jquerypage.i_th (1) as jpage then + if + attached {JSON_ARRAY} a_queries.item (a_page_key) as jquerypage and then + jquerypage.count > 0 and then + attached {JSON_OBJECT} jquerypage.i_th (1) as jpage + then create Result - if attached {JSON_STRING} jpage.item (create {JSON_STRING}.make_from_string ("title")) as l_title then + if attached {JSON_STRING} jpage.item ("title") as l_title then Result.set_title (l_title.item) end - if attached {JSON_STRING} jpage.item (create {JSON_STRING}.make_from_string ("totalResults")) as l_results then + if attached {JSON_STRING} jpage.item ("totalResults") as l_results then Result.set_total_results (l_results.item.to_integer) end - if attached {JSON_STRING} jpage.item (create {JSON_STRING}.make_from_string ("searchTerms")) as l_search_terms then + if attached {JSON_STRING} jpage.item ("searchTerms") as l_search_terms then Result.set_search_terms (l_search_terms.item) end -- TODO check if we should use INTEGER_64 - if attached {JSON_NUMBER} jpage.item (create {JSON_STRING}.make_from_string ("count")) as l_count then + if attached {JSON_NUMBER} jpage.item ("count") as l_count then Result.set_count (l_count.integer_64_item.as_integer_32) end - if attached {JSON_NUMBER} jpage.item (create {JSON_STRING}.make_from_string ("startIndex")) as l_index then + if attached {JSON_NUMBER} jpage.item ("startIndex") as l_index then Result.set_start_index (l_index.integer_64_item.as_integer_32) end end @@ -204,30 +212,15 @@ feature {NONE} -- Implementation feature {NONE} -- JSON Keys - queries_key: JSON_STRING - do - create Result.make_from_string ("queries") - end + queries_key: STRING = "queries" - next_page_key: JSON_STRING - do - create Result.make_from_string ("nextPage") - end + next_page_key: STRING = "nextPage" - request_key: JSON_STRING - do - create Result.make_from_string ("request") - end + request_key: STRING = "request" - previous_page_key: JSON_STRING - do - create Result.make_from_string ("previousPage") - end + previous_page_key: STRING = "previousPage" - items_key: JSON_STRING - do - create Result.make_from_string ("items") - end + items_key: STRING = "items" note copyright: "2011-2015 Javier Velilla, Jocelyn Fiat, Eiffel Software and others" diff --git a/library/gcse/src/gcse_page.e b/library/gcse/src/gcse_page.e index 9fc2cae..5387e75 100644 --- a/library/gcse/src/gcse_page.e +++ b/library/gcse/src/gcse_page.e @@ -6,6 +6,10 @@ note class GCSE_PAGE +inherit + + DEBUG_OUTPUT + feature -- Access search_terms: detachable STRING_8 @@ -67,9 +71,10 @@ feature -- Change element start_index_set: start_index = a_start_index end -feature -- Output +feature -- Status report - to_string: STRING_8 + debug_output: STRING_8 + -- do create Result.make_from_string ("%NPage details%N") if attached title as l_title then diff --git a/library/gcse/src/gcse_page_item.e b/library/gcse/src/gcse_page_item.e index 469bacc..7e5426c 100644 --- a/library/gcse/src/gcse_page_item.e +++ b/library/gcse/src/gcse_page_item.e @@ -8,7 +8,7 @@ class inherit - SHARED_HTML_ENCODER + DEBUG_OUTPUT feature -- Access @@ -27,9 +27,6 @@ feature -- Access snippet: detachable STRING_8 -- Snippet of this result - snippet_2: detachable STRING_8 - -- Snippet of this result - display_link: detachable STRING_8 -- Display link of this result @@ -79,7 +76,6 @@ feature -- Element change -- Assign `html_snippet' with `a_html_snippet'. do html_snippet := a_html_snippet - snippet_2 := html_encoded (a_html_snippet) ensure html_snippet_assigned: html_snippet = a_html_snippet end @@ -143,7 +139,8 @@ feature -- Element change feature -- Output - to_string: STRING_8 + debug_output: STRING_8 + -- do create Result.make_from_string ("%NPage Item details%N") if attached title as l_title then @@ -199,14 +196,6 @@ feature -- Output end - html_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8 - do - if s /= Void then - Result := html_encoder.general_encoded_string (s) - else - create Result.make_empty - end - end note copyright: "2011-2015 Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/gcse/src/gcse_page_map.e b/library/gcse/src/gcse_page_map.e index 67468ab..9b5f099 100644 --- a/library/gcse/src/gcse_page_map.e +++ b/library/gcse/src/gcse_page_map.e @@ -1,5 +1,21 @@ note - description: "Represent a google page map" + description: "[ + Represent a google page map + "pagemap": { + "cse_image": [ + { + "src": "https://www.eiffel.org/portal/files/userpictures/picture-40.jpg" + } + ], + "cse_thumbnail": [ + { + "width": "81", + "height": "61", + "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRnC-RKzps6BFItx_MLYBVskFI7U6u0y3VJBInomPYEF5sO6gkip94mLw" + } + ] + } + ]" date: "$Date: 2015-10-09 08:11:07 -0300 (vi., 09 oct. 2015) $" revision: "$Revision: 97973 $" EIS: "name=PageMaps", "src=https://developers.google.com/custom-search/docs/structured_data#pagemaps", "protocol=url" @@ -9,20 +25,7 @@ class feature -- Access --- "pagemap": { --- "cse_image": [ --- { --- "src": "https://www.eiffel.org/portal/files/userpictures/picture-40.jpg" --- } --- ], --- "cse_thumbnail": [ --- { --- "width": "81", --- "height": "61", --- "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRnC-RKzps6BFItx_MLYBVskFI7U6u0y3VJBInomPYEF5sO6gkip94mLw" --- } --- ] --- } + note diff --git a/library/gcse/src/gcse_query_parameters.e b/library/gcse/src/gcse_query_parameters.e index 77e91e1..6d8c18e 100644 --- a/library/gcse/src/gcse_query_parameters.e +++ b/library/gcse/src/gcse_query_parameters.e @@ -4,6 +4,150 @@ note Example url template "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json" ]" + optional_parameters: "[ + Optional parameters + c2coff string Enables or disables Simplified and Traditional Chinese Search. + The default value for this parameter is 0 (zero), meaning that the feature is enabled. Supported values are: + 1: Disabled + 0: Enabled (default) + cr string Restricts search results to documents originating in a particular country. + You may use Boolean operators in the cr parameter's value. + Google Search determines the country of a document by analyzing: + the top-level domain (TLD) of the document's URL + the geographic location of the Web server's IP address + See the Country Parameter Values page for a list of valid values for this parameter. + cref string The URL of a linked custom search engine specification to use for this request. + Does not apply for Google Site Search + If both cx and cref are specified, the cx value is used + cx string The custom search engine ID to use for this request. + If both cx and cref are specified, the cx value is used. + dateRestrict string Restricts results to URLs based on date. Supported values include: + d[number]: requests results from the specified number of past days. + w[number]: requests results from the specified number of past weeks. + m[number]: requests results from the specified number of past months. + y[number]: requests results from the specified number of past years. + exactTerms string Identifies a phrase that all documents in the search results must contain. + excludeTerms string Identifies a word or phrase that should not appear in any documents in the search results. + fileType string Restricts results to files of a specified extension. A list of file types indexable by Google can be found in Webmaster Tools Help Center. + filter string Controls turning on or off the duplicate content filter. + See Automatic Filtering for more information about Google's search results filters. Note that host crowding filtering applies only to multi-site searches. + By default, Google applies filtering to all search results to improve the quality of those results. + + + Acceptable values are: + "0": Turns off duplicate content filter. + "1": Turns on duplicate content filter. + gl string Geolocation of end user. + The gl parameter value is a two-letter country code. The gl parameter boosts search results whose country of origin matches the parameter value. See the Country Codes page for a list of valid values. + Specifying a gl parameter value should lead to more relevant results. This is particularly true for international customers and, even more specifically, for customers in English- speaking countries other than the United States. + googlehost string The local Google domain (for example, google.com, google.de, or google.fr) to use to perform the search. + highRange string + Specifies the ending value for a search range. + Use lowRange and highRange to append an inclusive search range of lowRange...highRange to the query. + hl string Sets the user interface language. + Explicitly setting this parameter improves the performance and the quality of your search results. + See the Interface Languages section of Internationalizing Queries and Results Presentation for more information, and Supported Interface Languages for a list of supported languages. + hq string Appends the specified query terms to the query, as if they were combined with a logical AND operator. + imgColorType string Returns black and white, grayscale, or color images: mono, gray, and color. + + Acceptable values are: + "color": color + "gray": gray + "mono": mono + imgDominantColor string Returns images of a specific dominant color. + + Acceptable values are: + "black": black + "blue": blue + "brown": brown + "gray": gray + "green": green + "pink": pink + "purple": purple + "teal": teal + "white": white + "yellow": yellow + imgSize string Returns images of a specified size. + + Acceptable values are: + "huge": huge + "icon": icon + "large": large + "medium": medium + "small": small + "xlarge": xlarge + "xxlarge": xxlarge + imgType string Returns images of a type. + + Acceptable values are: + "clipart": clipart + "face": face + "lineart": lineart + "news": news + "photo": photo + linkSite string Specifies that all search results should contain a link to a particular URL + lowRange string Specifies the starting value for a search range. + Use lowRange and highRange to append an inclusive search range of lowRange...highRange to the query. + lr string Restricts the search to documents written in a particular language (e.g., lr=lang_ja). + + Acceptable values are: + "lang_ar": Arabic + "lang_bg": Bulgarian + "lang_ca": Catalan + "lang_cs": Czech + "lang_da": Danish + "lang_de": German + "lang_el": Greek + "lang_en": English + "lang_es": Spanish + "lang_et": Estonian + "lang_fi": Finnish + "lang_fr": French + "lang_hr": Croatian + "lang_hu": Hungarian + "lang_id": Indonesian + "lang_is": Icelandic + "lang_it": Italian + "lang_iw": Hebrew + "lang_ja": Japanese + "lang_ko": Korean + "lang_lt": Lithuanian + "lang_lv": Latvian + "lang_nl": Dutch + "lang_no": Norwegian + "lang_pl": Polish + "lang_pt": Portuguese + "lang_ro": Romanian + "lang_ru": Russian + "lang_sk": Slovak + "lang_sl": Slovenian + "lang_sr": Serbian + "lang_sv": Swedish + "lang_tr": Turkish + "lang_zh-CN": Chinese (Simplified) + "lang_zh-TW": Chinese (Traditional) + + orTerms string Provides additional search terms to check for in a document, where each document in the search results must contain at least one of the additional search terms. + relatedSite string Specifies that all search results should be pages that are related to the specified URL. + rights string Filters based on licensing. Supported values include: cc_publicdomain, cc_attribute, cc_sharealike, cc_noncommercial, cc_nonderived, and combinations of these. + safe string Search safety level. + + Acceptable values are: + "high": Enables highest level of SafeSearch filtering. + "medium": Enables moderate SafeSearch filtering. + "off": Disables SafeSearch filtering. (default) + searchType string Specifies the search type: image. If unspecified, results are limited to webpages. + + Acceptable values are: + "image": custom image search. + siteSearch string Specifies all search results should be pages from a given site. + siteSearchFilter string Controls whether to include or exclude results from the site named in the siteSearch parameter. + + Acceptable values are: + "e": exclude + "i": include + sort string The sort expression to apply to the results. +]" date: "$Date: 2015-10-08 07:51:29 -0300 (ju., 08 oct. 2015) $" revision: "$Revision: 97966 $" EIS: "GCSE parameters", "src=https://developers.google.com/custom-search/json-api/v1/reference/cse/list", "protocol=URI" @@ -46,149 +190,6 @@ feature -- Access : Required Parameters feature -- Optional Parameters ---Optional parameters ---c2coff string Enables or disables Simplified and Traditional Chinese Search. --- The default value for this parameter is 0 (zero), meaning that the feature is enabled. Supported values are: --- 1: Disabled --- 0: Enabled (default) ---cr string Restricts search results to documents originating in a particular country. --- You may use Boolean operators in the cr parameter's value. --- Google Search determines the country of a document by analyzing: --- the top-level domain (TLD) of the document's URL --- the geographic location of the Web server's IP address --- See the Country Parameter Values page for a list of valid values for this parameter. ---cref string The URL of a linked custom search engine specification to use for this request. --- Does not apply for Google Site Search --- If both cx and cref are specified, the cx value is used ---cx string The custom search engine ID to use for this request. --- If both cx and cref are specified, the cx value is used. ---dateRestrict string Restricts results to URLs based on date. Supported values include: --- d[number]: requests results from the specified number of past days. --- w[number]: requests results from the specified number of past weeks. --- m[number]: requests results from the specified number of past months. --- y[number]: requests results from the specified number of past years. ---exactTerms string Identifies a phrase that all documents in the search results must contain. ---excludeTerms string Identifies a word or phrase that should not appear in any documents in the search results. ---fileType string Restricts results to files of a specified extension. A list of file types indexable by Google can be found in Webmaster Tools Help Center. ---filter string Controls turning on or off the duplicate content filter. --- See Automatic Filtering for more information about Google's search results filters. Note that host crowding filtering applies only to multi-site searches. --- By default, Google applies filtering to all search results to improve the quality of those results. - - --- Acceptable values are: --- "0": Turns off duplicate content filter. --- "1": Turns on duplicate content filter. --- gl string Geolocation of end user. ---The gl parameter value is a two-letter country code. The gl parameter boosts search results whose country of origin matches the parameter value. See the Country Codes page for a list of valid values. ---Specifying a gl parameter value should lead to more relevant results. This is particularly true for international customers and, even more specifically, for customers in English- speaking countries other than the United States. ---googlehost string The local Google domain (for example, google.com, google.de, or google.fr) to use to perform the search. ---highRange string ---Specifies the ending value for a search range. ---Use lowRange and highRange to append an inclusive search range of lowRange...highRange to the query. ---hl string Sets the user interface language. ---Explicitly setting this parameter improves the performance and the quality of your search results. ---See the Interface Languages section of Internationalizing Queries and Results Presentation for more information, and Supported Interface Languages for a list of supported languages. ---hq string Appends the specified query terms to the query, as if they were combined with a logical AND operator. ---imgColorType string Returns black and white, grayscale, or color images: mono, gray, and color. - --- Acceptable values are: --- "color": color --- "gray": gray --- "mono": mono ---imgDominantColor string Returns images of a specific dominant color. - --- Acceptable values are: --- "black": black --- "blue": blue --- "brown": brown --- "gray": gray --- "green": green --- "pink": pink --- "purple": purple --- "teal": teal --- "white": white --- "yellow": yellow ---imgSize string Returns images of a specified size. - --- Acceptable values are: --- "huge": huge --- "icon": icon --- "large": large --- "medium": medium --- "small": small --- "xlarge": xlarge --- "xxlarge": xxlarge ---imgType string Returns images of a type. - --- Acceptable values are: --- "clipart": clipart --- "face": face --- "lineart": lineart --- "news": news --- "photo": photo ---linkSite string Specifies that all search results should contain a link to a particular URL ---lowRange string Specifies the starting value for a search range. ---Use lowRange and highRange to append an inclusive search range of lowRange...highRange to the query. ---lr string Restricts the search to documents written in a particular language (e.g., lr=lang_ja). - --- Acceptable values are: --- "lang_ar": Arabic --- "lang_bg": Bulgarian --- "lang_ca": Catalan --- "lang_cs": Czech --- "lang_da": Danish --- "lang_de": German --- "lang_el": Greek --- "lang_en": English --- "lang_es": Spanish --- "lang_et": Estonian --- "lang_fi": Finnish --- "lang_fr": French --- "lang_hr": Croatian --- "lang_hu": Hungarian --- "lang_id": Indonesian --- "lang_is": Icelandic --- "lang_it": Italian --- "lang_iw": Hebrew --- "lang_ja": Japanese --- "lang_ko": Korean --- "lang_lt": Lithuanian --- "lang_lv": Latvian --- "lang_nl": Dutch --- "lang_no": Norwegian --- "lang_pl": Polish --- "lang_pt": Portuguese --- "lang_ro": Romanian --- "lang_ru": Russian --- "lang_sk": Slovak --- "lang_sl": Slovenian --- "lang_sr": Serbian --- "lang_sv": Swedish --- "lang_tr": Turkish --- "lang_zh-CN": Chinese (Simplified) --- "lang_zh-TW": Chinese (Traditional) - ---orTerms string Provides additional search terms to check for in a document, where each document in the search results must contain at least one of the additional search terms. ---relatedSite string Specifies that all search results should be pages that are related to the specified URL. ---rights string Filters based on licensing. Supported values include: cc_publicdomain, cc_attribute, cc_sharealike, cc_noncommercial, cc_nonderived, and combinations of these. ---safe string Search safety level. - --- Acceptable values are: --- "high": Enables highest level of SafeSearch filtering. --- "medium": Enables moderate SafeSearch filtering. --- "off": Disables SafeSearch filtering. (default) ---searchType string Specifies the search type: image. If unspecified, results are limited to webpages. - ---Acceptable values are: --- "image": custom image search. ---siteSearch string Specifies all search results should be pages from a given site. ---siteSearchFilter string Controls whether to include or exclude results from the site named in the siteSearch parameter. - --- Acceptable values are: --- "e": exclude --- "i": include --- sort string The sort expression to apply to the results. --- num : detachable STRING_8 diff --git a/library/gcse/src/gcse_response.e b/library/gcse/src/gcse_response.e index 5ffdfcb..32fdb2e 100644 --- a/library/gcse/src/gcse_response.e +++ b/library/gcse/src/gcse_response.e @@ -18,7 +18,6 @@ class feature -- Access - current_page: detachable GCSE_PAGE -- Metadata describing the query for the current set of results. -- This role is always present in the response. @@ -75,6 +74,34 @@ feature -- Change Element end l_items.force (a_item) end + + +feature -- Acess: HTTP Response + + status: INTEGER + -- HTTP status code. + + status_message: detachable READABLE_STRING_8 + -- associated textual phrase for the response status. + +feature -- Change Element: HTTP Response + + set_status (a_status: like status) + -- Set `status' with `a_status'. + do + status := a_status + ensure + status_set: status = a_status + end + + set_status_nessage (a_message: like status_message) + -- Set `status_message' with `a_message'. + do + status_message := a_message + ensure + status_message_set: status_message = a_message + end + ;note copyright: "2011-2015 Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/modules/custom_search/Readme.md b/modules/google_search/Readme.md similarity index 100% rename from modules/custom_search/Readme.md rename to modules/google_search/Readme.md diff --git a/modules/custom_search/custom_search.ecf b/modules/google_search/google_search.ecf similarity index 91% rename from modules/custom_search/custom_search.ecf rename to modules/google_search/google_search.ecf index 35bdfe6..e772135 100644 --- a/modules/custom_search/custom_search.ecf +++ b/modules/google_search/google_search.ecf @@ -1,6 +1,6 @@ - - + + diff --git a/modules/custom_search/site/config/custom_search.json b/modules/google_search/site/config/google_search.json similarity index 100% rename from modules/custom_search/site/config/custom_search.json rename to modules/google_search/site/config/google_search.json diff --git a/modules/custom_search/site/templates/block_search.tpl b/modules/google_search/site/templates/block_search.tpl similarity index 92% rename from modules/custom_search/site/templates/block_search.tpl rename to modules/google_search/site/templates/block_search.tpl index d37d146..b11c31b 100644 --- a/modules/custom_search/site/templates/block_search.tpl +++ b/modules/google_search/site/templates/block_search.tpl @@ -4,7 +4,7 @@ -
        +
          {foreach from="$result.items" item="item"} @@ -18,7 +18,7 @@
          -

          {htmlentities}{$item.snippet/}{/htmlentities}

          +

          {$item.html_snippet/}

          @@ -37,4 +37,4 @@
        1. Next
        2. {/if} - \ No newline at end of file + diff --git a/modules/google_search/src/google_custom_search_module.e b/modules/google_search/src/google_custom_search_module.e new file mode 100644 index 0000000..d325eb0 --- /dev/null +++ b/modules/google_search/src/google_custom_search_module.e @@ -0,0 +1,150 @@ +note + description: "[ + Module providing Google Custom Search functionality. + ]" + date: "$Date: 2015-10-09 20:50:01 -0300 (vi. 09 de oct. de 2015) $" + revision: "$Revision: 97982 $" + +class + GOOGLE_CUSTOM_SEARCH_MODULE + +inherit + + CMS_MODULE + + 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 := "1.0" + description := "Google custome search module" + package := "search" + end + +feature -- Access + + name: STRING = "google_search" + -- + +feature -- Router + + setup_router (a_router: WSF_ROUTER; a_api: CMS_API) + -- Router configuration. + do + a_router.handle ("/gcse", create {WSF_URI_AGENT_HANDLER}.make (agent handle_search (a_api, ?, ?)), a_router.methods_head_get) + end + +feature -- Recaptcha + + gcse_secret_key (api: CMS_API): detachable READABLE_STRING_8 + -- Get recaptcha security key. + local + utf: UTF_CONVERTER + do + if attached api.module_configuration (Current, Void) as cfg then + if + attached cfg.text_item ("gcse.secret_key") as l_recaptcha_key and then + not l_recaptcha_key.is_empty + then + Result := utf.utf_32_string_to_utf_8_string_8 (l_recaptcha_key) + end + end + end + + gcse_cx_key (api: CMS_API): detachable READABLE_STRING_8 + -- Get recaptcha security 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_recaptcha_key and then + not l_recaptcha_key.is_empty + then + Result := utf.utf_32_string_to_utf_8_string_8 (l_recaptcha_key) + end + end + end + +feature -- Handler + + handle_search (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) + local + r: CMS_RESPONSE + l_parameters:GCSE_QUERY_PARAMETERS + l_search: GCSE_API + do + -- TODO handle errors!!! + 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 and then + attached gcse_secret_key (api) as l_key + then + create l_parameters.make (l_key, l_cx, l_query.url_encoded_value ) + if + attached {WSF_STRING} req.query_parameter ("start") as l_index and then + attached {WSF_STRING} req.query_parameter ("num") as l_num + then + l_parameters.set_start (l_index.value) + l_parameters.set_num (l_num.value) + end + create l_search.make (l_parameters) + l_search.search + if + attached l_search.last_result as l_result and then + l_result.status = 200 + then + if attached template_block (Current, "search", r) as l_tpl_block then + l_tpl_block.set_value (l_result, "result") + r.add_block (l_tpl_block, "content") + end + else + -- Quota limit (403 status code) or not results. + google_search_site (req, r, l_query) + end + else + -- If no key are provided, at least output google search result page. + google_search_site (req, r, l_query) + end + else + r.add_message ("No query submitted", Void) + end + r.execute + end + +feature {NONE} -- Helper + + google_search_site (req: WSF_REQUEST; res: CMS_RESPONSE; query: WSF_STRING) + -- Workaround to output google search result page + -- If no key are provided or if GCSE reached the quota limit. + local + l_url_encoder: URL_ENCODER + do + create l_url_encoder + if req.is_https then + res.set_redirection ("https://www.google.com/search?sitesearch=" + l_url_encoder.general_encoded_string (res.absolute_url ("", Void)) + "&q=" + query.url_encoded_value) + else + res.set_redirection ("http://www.google.com/search?sitesearch=" + l_url_encoder.general_encoded_string (res.absolute_url ("", Void)) + "&q=" + query.url_encoded_value) + end + end +end