Added support for base_url (i.e the CMS can be hosted on the root, or sub folder).

Local paths are relative to cms site url (i.e no starting slash).
Favor CMS_RESPONSE.absolute_url and url .. instead of using directly WSF_REQUEST.absolute_script_url and script_url.
Handled unicode truncation issue for logger.
Code cleaning.
This commit is contained in:
2015-05-19 13:50:39 +02:00
33 changed files with 258 additions and 117 deletions

View File

@@ -39,17 +39,21 @@ feature {NONE} -- Initialization
end
configure
local
l_url: like site_url
do
--| Site id, used to identified a site, this could be set to a uuid, or else
site_id := text_item_or_default ("site.id", "_EWF_CMS_NO_ID_")
-- Site url: optional, but ending with a slash
site_url := string_8_item ("site_url")
if attached site_url as l_url and then not l_url.is_empty then
if l_url[l_url.count] /= '/' then
site_url := l_url + "/"
l_url := string_8_item ("site_url")
if l_url /= Void and then not l_url.is_empty then
if l_url [l_url.count] /= '/' then
l_url := l_url + "/"
end
end
site_url := l_url
-- Site name
site_name := text_item_or_default ("site.name", "EWF::CMS")

View File

@@ -62,7 +62,7 @@ feature -- Access: Site
-- Mainly used for internal notification.
site_url: detachable READABLE_STRING_8
-- Optional base url of the site.
-- Optional url of current CMS site.
front_page_path: detachable READABLE_STRING_8
-- Optional path defining the front page.

View File

@@ -1,6 +1,6 @@
note
description: "[
Objects that ...
CMS Storage for core functionalities.
]"
author: "$Author$"
date: "$Date$"

View File

@@ -234,9 +234,16 @@ feature -- Query: API
feature -- Path aliases
is_valid_path_alias (a_alias: READABLE_STRING_8): BOOLEAN
do
Result := a_alias.is_empty or else not a_alias.starts_with_general ("/")
end
set_path_alias (a_source, a_alias: READABLE_STRING_8; a_keep_previous: BOOLEAN)
-- Set `a_alias' as alias of `a_source',
-- and eventually unset previous alias if any.
require
valid_alias: is_valid_path_alias (a_alias)
local
l_continue: BOOLEAN
do
@@ -281,8 +288,8 @@ feature -- Path aliases
-- Resolved path for alias `a_alias'.
--| the CMS supports aliases for path, and then this function simply returns
--| the effective target path/url for this `a_alias'.
--| For instance: /articles/2015/may/this-is-an-article can be an alias to /node/123
--| This function will return "/node/123".
--| For instance: articles/2015/may/this-is-an-article can be an alias to node/123
--| This function will return "node/123".
--| If the alias is bad (i.e does not alias real path), then this function
--| returns the alias itself.
do

View File

@@ -19,15 +19,17 @@ feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the filter
local
utf: UTF_CONVERTER
do
fixme ("Check if it's ok to add new fetures CMS_API.has_error:BOOLEAN and CMS_API.error_description.")
if not api.has_error then
api.logger.put_information (generator + ".execute with req: " + req.debug_output, Void)
if attached req.raw_header_data as l_header_data then
api.logger.put_debug (generator + ".execute with req header: " + l_header_data, Void)
api.logger.put_debug (generator + ".execute with req header: " + utf.escaped_utf_32_string_to_utf_8_string_8 (l_header_data), Void)
end
if attached req.raw_input_data as l_input_data then
api.logger.put_debug (generator + ".execute with req input: " + l_input_data, Void)
api.logger.put_debug (generator + ".execute with req input: " + utf.escaped_utf_32_string_to_utf_8_string_8 (l_input_data), Void)
end
execute_next (req, res)
else

View File

@@ -70,14 +70,4 @@ feature -- Media Type
end
end
feature -- Absolute Host
absolute_host (req: WSF_REQUEST; a_path:STRING): STRING
do
Result := req.absolute_script_url (a_path)
if Result.last_index_of ('/', Result.count) = Result.count then
Result.remove_tail (1)
end
end
end

View File

@@ -13,6 +13,7 @@ inherit
feature -- Core
site_url: READABLE_STRING_8
-- Absolute site URL of Current CMS site.
deferred
end

View File

@@ -31,8 +31,22 @@ feature {WSF_ROUTER_MAPPING} -- Dispatch helper
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
-- Path used by the router, to apply url dispatching of request `req'.
local
l_path: STRING_8
do
Result := api.source_of_path_alias (Precursor (req))
create l_path.make_from_string (Precursor (req))
if not l_path.is_empty and l_path [1] = '/' then
l_path.remove_head (1)
end
Result := api.source_of_path_alias (l_path)
if Result.is_empty then
Result := "/"
elseif Result [1] /= '/' then
create l_path.make (Result.count + 1)
l_path.append_character ('/')
l_path.append (Result)
Result := l_path
end
end
end

View File

@@ -29,6 +29,7 @@ feature {NONE} -- Initialization
initialize
do
initialize_site_url
get_theme
create menu_system.make
initialize_block_region_settings
@@ -36,6 +37,27 @@ feature {NONE} -- Initialization
register_hooks
end
initialize_site_url
-- Initialize site and base url.
local
l_url: detachable READABLE_STRING_8
i,j: INTEGER
do
--| WARNING: do not use `absolute_url' and `url', since it relies on site_url and base_url.
l_url := setup.site_url
if l_url = Void then
l_url := request.absolute_script_url ("/")
end
site_url := l_url
i := l_url.substring_index ("://", 1)
if i > 0 then
j := l_url.index_of ('/', i + 3)
if j > 0 then
base_url := l_url.substring (j, l_url.count)
end
end
end
register_hooks
local
l_module: CMS_MODULE
@@ -164,15 +186,12 @@ feature -- URL utilities
end
site_url: READABLE_STRING_8
do
Result := absolute_host (request, "")
end
-- Absolute site url.
base_url: detachable READABLE_STRING_8
-- Base url if any.
--| Usually it is Void, but it could be
--| /project/demo/
--| FIXME: for now, no way to change that. Always at the root "/"
feature -- Access: CMS
@@ -183,7 +202,7 @@ feature -- Access: CMS
front_page_url: READABLE_STRING_8
do
Result := request.absolute_script_url ("/")
Result := absolute_url ("/", Void)
end
values: CMS_VALUE_TABLE
@@ -806,9 +825,9 @@ feature -- Theme
create l_info.make_default
end
if l_info.engine.is_case_insensitive_equal_general ("smarty") then
create {SMARTY_CMS_THEME} theme.make (setup, l_info)
create {SMARTY_CMS_THEME} theme.make (setup, l_info, site_url)
else
create {MISSING_CMS_THEME} theme.make (setup)
create {MISSING_CMS_THEME} theme.make (setup, l_info, site_url)
status_code := {HTTP_STATUS_CODE}.service_unavailable
to_implement ("Check how to add the Retry-after, http://tools.ietf.org/html/rfc7231#section-6.6.4 and http://tools.ietf.org/html/rfc7231#section-7.1.3")
end
@@ -834,7 +853,7 @@ feature -- Generation
lnk: CMS_LINK
do
-- Menu
create {CMS_LOCAL_LINK} lnk.make ("Home", "/")
create {CMS_LOCAL_LINK} lnk.make ("Home", "")
lnk.set_weight (-10)
add_to_primary_menu (lnk)
invoke_menu_system_alter (menu_system)
@@ -920,8 +939,8 @@ feature -- Generation
end
-- Variables
page.register_variable (request.absolute_script_url (""), "site_url")
page.register_variable (request.absolute_script_url (""), "host") -- Same as `site_url'.
page.register_variable (absolute_url ("", Void), "site_url")
page.register_variable (absolute_url ("", Void), "host") -- Same as `site_url'.
page.register_variable (request.is_https, "is_https")
if attached current_user_name (request) as l_user then
page.register_variable (l_user, "user")
@@ -1102,8 +1121,8 @@ feature {NONE} -- Execution
-- h.put_location (l_location)
response.redirect_now (l_location)
else
-- h.put_location (request.absolute_script_url (l_location))
response.redirect_now (request.absolute_script_url (l_location))
-- h.put_location (request.absolute_url (l_location, Void))
response.redirect_now (absolute_url (l_location, Void))
end
else
h.put_header_object (header)

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.register_variable (absolute_url (request.path_info, Void), "request")
page.set_status_code ({HTTP_STATUS_CODE}.bad_request)
page.register_variable (page.status_code.out, "code")
end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.register_variable (absolute_url (request.path_info, Void), "request")
page.set_status_code ({HTTP_STATUS_CODE}.forbidden)
page.register_variable (page.status_code.out, "code")
end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.register_variable (absolute_url (request.path_info, Void), "request")
page.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
page.register_variable (page.status_code.out, "code")
end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.register_variable (absolute_url (request.path_info, Void), "request")
page.set_status_code ({HTTP_STATUS_CODE}.not_found)
page.register_variable (page.status_code.out, "code")
end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.register_variable (absolute_url (request.path_info, Void), "request")
page.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
page.register_variable (page.status_code.out, "code")
end

View File

@@ -9,6 +9,8 @@ deferred class
inherit
CMS_ENCODERS
CMS_URL_UTILITIES
REFACTORING_HELPER
@@ -16,6 +18,12 @@ feature {NONE} -- Access
setup: CMS_SETUP
site_url: READABLE_STRING_8 assign set_site_url
-- Absolute URL for Current CMS site.
base_url: detachable READABLE_STRING_8
-- Optional base url of current CMS site.
feature -- Access
name: STRING
@@ -41,6 +49,30 @@ feature -- Status report
Result := across regions as ic some a_region_name.is_case_insensitive_equal (ic.item) end
end
feature -- Element change
set_site_url (a_url: READABLE_STRING_8)
-- Set `site_url' to `a_url'.
require
a_url.ends_with_general ("/")
local
i,j: INTEGER
do
base_url := Void
if a_url[a_url.count] = '/' then
site_url := a_url
else
site_url := a_url + "/"
end
i := a_url.substring_index ("://", 1)
if i > 0 then
j := a_url.index_of ('/', i + 3)
if j > 0 then
base_url := a_url.substring (j, a_url.count)
end
end
end
feature -- Conversion
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN; a_options: detachable CMS_HTML_OPTIONS): STRING_8
@@ -133,7 +165,11 @@ feature {NONE} -- Implementation
else
s.append ("<li class=%""+ cl + "%">")
end
s.append ("<a href=%"" + (lnk.location) + "%">" + html_encoded (lnk.title) + "</a>")
s.append ("<a href=%"")
s.append (url (lnk.location, Void))
s.append ("%">")
s.append (html_encoded (lnk.title))
s.append ("</a>")
if
(lnk.is_expanded or lnk.is_collapsed) and then
attached lnk.children as l_children

View File

@@ -18,15 +18,19 @@ create
feature {NONE} -- Initialization
make (a_setup: like setup)
make (a_setup: like setup; a_info: like information; abs_site_url: READABLE_STRING_8)
do
setup := a_setup
information := a_info
set_site_url (abs_site_url)
ensure
setup_set: setup = a_setup
end
feature -- Access
information: CMS_THEME_INFORMATION
name: STRING = "missing theme"
regions: ARRAY [STRING]

View File

@@ -14,7 +14,7 @@ create
feature {NONE} -- Initialization
make (a_setup: like setup; a_info: like information;)
make (a_setup: like setup; a_info: like information; abs_site_url: READABLE_STRING_8)
do
setup := a_setup
information := a_info
@@ -23,6 +23,7 @@ feature {NONE} -- Initialization
else
templates_directory := a_setup.theme_location
end
set_site_url (abs_site_url)
ensure
setup_set: setup = a_setup
information_set: information = a_info

View File

@@ -0,0 +1,54 @@
note
description: "Theme from the EWF framework, but dedicated for the CMS."
date: "$Date$"
revision: "$Revision$"
class
CMS_TO_WSF_THEME
inherit
WSF_THEME
create
make
feature {NONE} -- Initialization
make (res: CMS_RESPONSE; a_cms_theme: CMS_THEME)
do
request := res.request
cms_theme := a_cms_theme
set_response (res)
end
feature -- Access
request: WSF_REQUEST
response: CMS_RESPONSE
cms_theme: CMS_THEME
feature -- Element change
set_response (a_response: CMS_RESPONSE)
-- Set `response' to `a_response'.
do
response := a_response
end
feature -- Core
site_url: READABLE_STRING_8
-- CMS site url.
do
Result := response.site_url
end
base_url: detachable READABLE_STRING_8
-- Base url if any.
do
Result := response.base_url
end
end

View File

@@ -0,0 +1,17 @@
note
description: "Summary description for {WSF_CMS_THEME}."
date: "$Date$"
revision: "$Revision$"
class
WSF_CMS_THEME
obsolete "Use CMS_TO_WSF_THEME [2015-May]"
inherit
CMS_TO_WSF_THEME
create
make
end

View File

@@ -0,0 +1,30 @@
note
description: " Null theme for void-safety purpose."
date: "$Date$"
revision: "$Revision$"
class
WSF_NULL_THEME
inherit
WSF_THEME
create
make
feature {NONE} -- Initialization
make
do
end
feature -- Core
site_url: STRING = ""
base_url: detachable READABLE_STRING_8
-- Base url if any.
do
end
end