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:44:08 +02:00
parent 51699f3bd3
commit 91457080fd
31 changed files with 237 additions and 94 deletions

View File

@@ -101,7 +101,7 @@ feature -- Hooks
local local
lnk: CMS_LOCAL_LINK lnk: CMS_LOCAL_LINK
do do
create lnk.make ("Blogs", "/blogs/") create lnk.make ("Blogs", "blogs/")
a_menu_system.primary_menu.extend (lnk) a_menu_system.primary_menu.extend (lnk)
end end

View File

@@ -110,9 +110,9 @@ feature -- Hooks
if a_block_id.is_case_insensitive_equal_general ("demo-info") then if a_block_id.is_case_insensitive_equal_general ("demo-info") then
if a_response.request.request_uri.starts_with ("/demo/") then if a_response.request.request_uri.starts_with ("/demo/") then
create m.make_with_title (a_block_id, "Demo", 2) create m.make_with_title (a_block_id, "Demo", 2)
create lnk.make ("/demo/abc", a_response.url ("/demo/abc", Void)) create lnk.make ("demo: abc", "demo/abc")
m.extend (lnk) m.extend (lnk)
create lnk.make ("/demo/123", a_response.url ("/demo/123", Void)) create lnk.make ("demo: 123", "demo/123")
m.extend (lnk) m.extend (lnk)
create mb.make (m) create mb.make (m)
a_response.add_block (mb, "sidebar_second") a_response.add_block (mb, "sidebar_second")
@@ -125,7 +125,7 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK lnk: CMS_LOCAL_LINK
-- perms: detachable ARRAYED_LIST [READABLE_STRING_8] -- perms: detachable ARRAYED_LIST [READABLE_STRING_8]
do do
create lnk.make ("Demo", "/demo/") create lnk.make ("Demo", "demo/")
a_menu_system.primary_menu.extend (lnk) a_menu_system.primary_menu.extend (lnk)
end end
@@ -137,8 +137,8 @@ feature -- Handler
r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
do do
create r.make (req, res, a_api) create r.make (req, res, a_api)
r.set_main_content ("NODE module does not yet implement %"" + req.path_info + "%" ...") r.set_main_content ("DEMO module does not yet implement %"" + req.path_info + "%" ...")
r.add_error_message ("NODE Module: not yet implemented") r.add_error_message ("DEMO Module: not yet implemented")
r.execute r.execute
end end

View File

@@ -25,8 +25,10 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_title: detachable like title; a_location: like location) make (a_title: detachable READABLE_STRING_GENERAL; a_location: like location)
-- Create current local link with optional title `a_title' and location `a_location'. -- Create current local link with optional title `a_title' and location `a_location'.
require
is_valid_local_location_argument: not a_location.starts_with_general ("/")
do do
location := a_location location := a_location
set_title (a_title) set_title (a_title)
@@ -71,13 +73,13 @@ feature -- Status report
feature -- Element change feature -- Element change
set_title (a_title: detachable like title) set_title (a_title: detachable READABLE_STRING_GENERAL)
-- Set `title' to `a_title' or `location'. -- Set `title' to `a_title' or `location'.
do do
if a_title /= Void then if a_title /= Void then
title := a_title title := a_title.as_string_32
else else
title := location title := location.as_string_32
end end
end end

View File

@@ -109,9 +109,9 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK lnk: CMS_LOCAL_LINK
do do
if attached a_response.current_user (a_response.request) as u then if attached a_response.current_user (a_response.request) as u then
create lnk.make (u.name + " (Logout)", "/basic_auth_logoff?destination=" + a_response.request.request_uri) create lnk.make (u.name + " (Logout)", "basic_auth_logoff?destination=" + a_response.request.request_uri)
else else
create lnk.make ("Login", "/basic_auth_login?destination=" + a_response.request.request_uri) create lnk.make ("Login", "basic_auth_login?destination=" + a_response.request.request_uri)
end end
-- if not a_menu_system.primary_menu.has (lnk) then -- if not a_menu_system.primary_menu.has (lnk) then
lnk.set_weight (99) lnk.set_weight (99)

View File

@@ -22,11 +22,12 @@ feature -- Basic operations
-- Execute the filter. -- Execute the filter.
local local
l_auth: HTTP_AUTHORIZATION l_auth: HTTP_AUTHORIZATION
utf: UTF_CONVERTER
do do
api.logger.put_debug (generator + ".execute ", Void) api.logger.put_debug (generator + ".execute ", Void)
create l_auth.make (req.http_authorization) create l_auth.make (req.http_authorization)
if attached req.raw_header_data as l_raw_data then if attached req.raw_header_data as l_raw_data then
api.logger.put_debug (generator + ".execute " + l_raw_data, Void) api.logger.put_debug (generator + ".execute " + utf.escaped_utf_32_string_to_utf_8_string_8 (l_raw_data), Void)
end end
-- A valid user -- A valid user
if if

View File

@@ -170,9 +170,9 @@ feature -- URL
-- or URI of path for selection of new content possibilities if ct is Void. -- or URI of path for selection of new content possibilities if ct is Void.
do do
if ct /= Void then if ct /= Void then
Result := "/node/add/" + ct.name Result := "node/add/" + ct.name
else else
Result := "/node/" Result := "node/"
end end
end end
@@ -190,13 +190,13 @@ feature -- URL
require require
a_node.has_id a_node.has_id
do do
Result := "/node/" + a_node.id.out Result := "node/" + a_node.id.out
end end
nodes_path: STRING nodes_path: STRING
-- URI path for list of nodes. -- URI path for list of nodes.
do do
Result := "/nodes" Result := "nodes"
end end
feature -- Access: Node feature -- Access: Node

View File

@@ -9,6 +9,8 @@ deferred class
inherit inherit
CMS_NODE_TYPE_WEBFORM_MANAGER_I [G] CMS_NODE_TYPE_WEBFORM_MANAGER_I [G]
SHARED_WSF_PERCENT_ENCODER
feature -- Forms ... feature -- Forms ...
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE) populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
@@ -18,6 +20,7 @@ feature -- Forms ...
ta: WSF_FORM_TEXTAREA ta: WSF_FORM_TEXTAREA
tselect: WSF_FORM_SELECT tselect: WSF_FORM_SELECT
opt: WSF_FORM_SELECT_OPTION opt: WSF_FORM_SELECT_OPTION
l_uri: detachable READABLE_STRING_8
do do
create ti.make ("title") create ti.make ("title")
ti.set_label ("Title") ti.set_label ("Title")
@@ -66,16 +69,37 @@ feature -- Forms ...
f.extend (fset) f.extend (fset)
-- Path aliase -- Path alias
create ti.make ("path_alias") create ti.make ("path_alias")
ti.set_label ("Path") ti.set_label ("Path")
ti.set_size (70) ti.set_size (70)
if a_node /= Void and then a_node.has_id then if a_node /= Void and then a_node.has_id then
if attached a_node.link as lnk then if attached a_node.link as lnk then
ti.set_text_value (lnk.location) l_uri := lnk.location
else else
ti.set_text_value (response.api.path_alias (response.node_api.node_path (a_node))) l_uri := percent_encoder.percent_decoded_string (response.api.path_alias (response.node_api.node_path (a_node)))
end end
ti.set_text_value (l_uri)
ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed. For example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.")
ti.set_validation_action (agent (fd: WSF_FORM_DATA; a_response: CMS_RESPONSE)
do
if
attached fd.string_item ("path_alias") as f_path_alias
then
if a_response.api.is_valid_path_alias (f_path_alias) then
-- Ok.
elseif f_path_alias.is_empty then
-- Ok
elseif f_path_alias.starts_with_general ("/") then
fd.report_invalid_field ("path_alias", "Path alias should not start with a slash '/' .")
elseif f_path_alias.has_substring ("://") then
fd.report_invalid_field ("path_alias", "Path alias should not be absolute url .")
else
-- TODO: implement full path alias validation
end
end
end(?, response)
)
end end
if if
attached f.fields_by_name ("title") as l_title_fields and then attached f.fields_by_name ("title") as l_title_fields and then
@@ -180,7 +204,7 @@ feature -- Output
node_api := a_response.node_api node_api := a_response.node_api
a_response.add_variable (a_node, "node") a_response.add_variable (a_node, "node")
create lnk.make (a_response.translation ("View", Void), a_response.node_local_link (a_node).location) lnk := a_response.node_local_link (a_node, a_response.translation ("View", Void))
lnk.set_weight (1) lnk.set_weight (1)
a_response.add_to_primary_tabs (lnk) a_response.add_to_primary_tabs (lnk)

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
initialize initialize
do do
Precursor Precursor
create {WSF_CMS_THEME} wsf_theme.make (Current, theme) create {CMS_TO_WSF_THEME} wsf_theme.make (Current, theme)
end end
wsf_theme: WSF_THEME wsf_theme: WSF_THEME
@@ -58,8 +58,8 @@ feature -- Execution
fd := f.last_data fd := f.last_data
end end
if l_node.has_id then if l_node.has_id then
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("View", Void), node_url (l_node)), primary_tabs) add_to_menu (node_local_link (l_node, translation ("View", Void)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), "/node/" + l_node.id.out + "/edit"), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (l_node) + "/edit"), primary_tabs)
end end
if attached redirection as l_location then if attached redirection as l_location then
@@ -96,8 +96,8 @@ feature -- Execution
set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out) set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
if l_node.has_id then if l_node.has_id then
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("View", Void), node_url (l_node)), primary_tabs) add_to_menu (node_local_link (l_node, translation ("View", Void)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), "/node/" + l_node.id.out + "/edit"), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (l_node) + "/edit"), primary_tabs)
end end
f.append_to_html (wsf_theme, b) f.append_to_html (wsf_theme, b)
@@ -121,7 +121,7 @@ feature -- Execution
attached ic.item as l_node_type and then attached ic.item as l_node_type and then
has_permissions (<<"create any", "create " + l_node_type.name>>) has_permissions (<<"create any", "create " + l_node_type.name>>)
then then
b.append ("<li>" + link (l_node_type.name, "/node/add/" + l_node_type.name, Void)) b.append ("<li>" + link (l_node_type.name, "node/add/" + l_node_type.name, Void))
if attached l_node_type.description as d then if attached l_node_type.description as d then
b.append ("<div class=%"description%">" + d + "</div>") b.append ("<div class=%"description%">" + d + "</div>")
end end
@@ -167,6 +167,7 @@ feature -- Form
l_preview: BOOLEAN l_preview: BOOLEAN
l_node: detachable CMS_NODE l_node: detachable CMS_NODE
s: STRING s: STRING
l_path_alias: detachable READABLE_STRING_8
do do
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview") l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
if not l_preview then if not l_preview then
@@ -198,20 +199,29 @@ feature -- Form
end end
node_api.save_node (l_node) node_api.save_node (l_node)
if attached current_user (request) as u then if attached current_user (request) as u then
api.log ("node", "User %"" + user_html_link (u) + "%" " + s + " node " + link (a_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node)) api.log ("node",
"User %"" + user_html_link (u) + "%" " + s + " node " + node_html_link (l_node, a_type.name + " #" + l_node.id.out),
0, node_local_link (l_node, Void)
)
else else
api.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node)) api.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node, Void))
end end
add_success_message ("Node #" + l_node.id.out + " saved.") add_success_message ("Node #" + l_node.id.out + " saved.")
if attached fd.string_item ("path_alias") as l_path_alias then if
attached fd.string_item ("path_alias") as f_path_alias and then
not f_path_alias.is_empty
then
l_path_alias := percent_encoder.partial_encoded_string (f_path_alias, <<'/'>>)
-- Path alias, are always from the root of the cms.
api.set_path_alias (node_api.node_path (l_node), l_path_alias, False) api.set_path_alias (node_api.node_path (l_node), l_path_alias, False)
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_path_alias)) l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_path_alias))
else else
l_node.set_link (node_api.node_link (l_node)) l_node.set_link (node_api.node_link (l_node))
end end
if attached l_node.link as lnk then
set_redirection (node_url (l_node)) set_redirection (lnk.location)
end
end end
end end

View File

@@ -53,30 +53,45 @@ feature -- Helpers
feature -- Helpers: cms link feature -- Helpers: cms link
user_local_link (u: CMS_USER): CMS_LOCAL_LINK user_local_link (u: CMS_USER; a_opt_title: detachable READABLE_STRING_GENERAL): CMS_LOCAL_LINK
do do
create Result.make (u.name, user_url (u)) if a_opt_title /= Void then
create Result.make (a_opt_title, user_url (u))
else
create Result.make (u.name, user_url (u))
end
end end
node_local_link (n: CMS_NODE): CMS_LOCAL_LINK node_local_link (n: CMS_NODE; a_opt_title: detachable READABLE_STRING_GENERAL): CMS_LOCAL_LINK
do do
if attached n.link as lnk then if attached n.link as lnk then
Result := lnk Result := lnk
else else
Result := node_api.node_link (n) Result := node_api.node_link (n)
end end
if a_opt_title /= Void and then not Result.title.same_string_general (a_opt_title) then
create Result.make (a_opt_title, Result.location)
end
end end
feature -- Helpers: html link feature -- Helpers: html link
user_html_link (u: CMS_USER): like link user_html_link (u: CMS_USER): like link
do do
Result := link (u.name, "/user/" + u.id.out, Void) Result := link (u.name, "user/" + u.id.out, Void)
end end
node_html_link (n: CMS_NODE): like link node_html_link (n: CMS_NODE; a_opt_title: detachable READABLE_STRING_GENERAL): like link
local
l_title: detachable READABLE_STRING_GENERAL
do do
Result := link (n.title, "/node/" + n.id.out, Void) if a_opt_title /= Void then
l_title := a_opt_title
else
l_title := n.title
end
Result := link (l_title, node_api.node_path (n), Void)
end end
feature -- Helpers: URL feature -- Helpers: URL
@@ -85,7 +100,7 @@ feature -- Helpers: URL
require require
u_with_id: u.has_id u_with_id: u.has_id
do do
Result := url ("/user/" + u.id.out, Void) Result := url ("user/" + u.id.out, Void)
end end
node_url (n: CMS_NODE): like url node_url (n: CMS_NODE): like url

View File

@@ -27,7 +27,7 @@ feature {NONE} -- Initialization
initialize initialize
do do
Precursor Precursor
create {WSF_CMS_THEME} wsf_theme.make (Current, theme) create {CMS_TO_WSF_THEME} wsf_theme.make (Current, theme)
end end
wsf_theme: WSF_THEME wsf_theme: WSF_THEME

View File

@@ -173,10 +173,10 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK lnk: CMS_LOCAL_LINK
-- perms: detachable ARRAYED_LIST [READABLE_STRING_8] -- perms: detachable ARRAYED_LIST [READABLE_STRING_8]
do do
create lnk.make ("List of nodes", a_response.url ("/nodes", Void)) create lnk.make ("List of nodes", "nodes")
a_menu_system.primary_menu.extend (lnk) a_menu_system.primary_menu.extend (lnk)
create lnk.make ("Create ..", a_response.url ("/node/", Void)) create lnk.make ("Create ..", "node/")
a_menu_system.primary_menu.extend (lnk) a_menu_system.primary_menu.extend (lnk)
end end

View File

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

View File

@@ -62,7 +62,7 @@ feature -- Access: Site
-- Mainly used for internal notification. -- Mainly used for internal notification.
site_url: detachable READABLE_STRING_8 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 front_page_path: detachable READABLE_STRING_8
-- Optional path defining the front page. -- Optional path defining the front page.

View File

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

View File

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

View File

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

View File

@@ -70,14 +70,4 @@ feature -- Media Type
end end
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 end

View File

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

View File

@@ -31,8 +31,22 @@ feature {WSF_ROUTER_MAPPING} -- Dispatch helper
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8 path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
-- Path used by the router, to apply url dispatching of request `req'. -- Path used by the router, to apply url dispatching of request `req'.
local
l_path: STRING_8
do 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
end end

View File

@@ -29,6 +29,7 @@ feature {NONE} -- Initialization
initialize initialize
do do
initialize_site_url
get_theme get_theme
create menu_system.make create menu_system.make
initialize_block_region_settings initialize_block_region_settings
@@ -36,6 +37,27 @@ feature {NONE} -- Initialization
register_hooks register_hooks
end 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 register_hooks
local local
l_module: CMS_MODULE l_module: CMS_MODULE
@@ -164,15 +186,12 @@ feature -- URL utilities
end end
site_url: READABLE_STRING_8 site_url: READABLE_STRING_8
do -- Absolute site url.
Result := absolute_host (request, "")
end
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
-- Base url if any. -- Base url if any.
--| Usually it is Void, but it could be --| Usually it is Void, but it could be
--| /project/demo/ --| /project/demo/
--| FIXME: for now, no way to change that. Always at the root "/"
feature -- Access: CMS feature -- Access: CMS
@@ -183,7 +202,7 @@ feature -- Access: CMS
front_page_url: READABLE_STRING_8 front_page_url: READABLE_STRING_8
do do
Result := request.absolute_script_url ("/") Result := absolute_url ("/", Void)
end end
values: CMS_VALUE_TABLE values: CMS_VALUE_TABLE
@@ -806,9 +825,9 @@ feature -- Theme
create l_info.make_default create l_info.make_default
end end
if l_info.engine.is_case_insensitive_equal_general ("smarty") then 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 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 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") 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 end
@@ -834,7 +853,7 @@ feature -- Generation
lnk: CMS_LINK lnk: CMS_LINK
do do
-- Menu -- Menu
create {CMS_LOCAL_LINK} lnk.make ("Home", "/") create {CMS_LOCAL_LINK} lnk.make ("Home", "")
lnk.set_weight (-10) lnk.set_weight (-10)
add_to_primary_menu (lnk) add_to_primary_menu (lnk)
invoke_menu_system_alter (menu_system) invoke_menu_system_alter (menu_system)
@@ -920,8 +939,8 @@ feature -- Generation
end end
-- Variables -- Variables
page.register_variable (request.absolute_script_url (""), "site_url") page.register_variable (absolute_url ("", Void), "site_url")
page.register_variable (request.absolute_script_url (""), "host") -- Same as `site_url'. page.register_variable (absolute_url ("", Void), "host") -- Same as `site_url'.
page.register_variable (request.is_https, "is_https") page.register_variable (request.is_https, "is_https")
if attached current_user_name (request) as l_user then if attached current_user_name (request) as l_user then
page.register_variable (l_user, "user") page.register_variable (l_user, "user")
@@ -1102,8 +1121,8 @@ feature {NONE} -- Execution
-- h.put_location (l_location) -- h.put_location (l_location)
response.redirect_now (l_location) response.redirect_now (l_location)
else else
-- h.put_location (request.absolute_script_url (l_location)) -- h.put_location (request.absolute_url (l_location, Void))
response.redirect_now (request.absolute_script_url (l_location)) response.redirect_now (absolute_url (l_location, Void))
end end
else else
h.put_header_object (header) h.put_header_object (header)

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE) custom_prepare (page: CMS_HTML_PAGE)
do 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.set_status_code ({HTTP_STATUS_CODE}.bad_request)
page.register_variable (page.status_code.out, "code") page.register_variable (page.status_code.out, "code")
end end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE) custom_prepare (page: CMS_HTML_PAGE)
do 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.set_status_code ({HTTP_STATUS_CODE}.forbidden)
page.register_variable (page.status_code.out, "code") page.register_variable (page.status_code.out, "code")
end end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE) custom_prepare (page: CMS_HTML_PAGE)
do 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.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
page.register_variable (page.status_code.out, "code") page.register_variable (page.status_code.out, "code")
end end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE) custom_prepare (page: CMS_HTML_PAGE)
do 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.set_status_code ({HTTP_STATUS_CODE}.not_found)
page.register_variable (page.status_code.out, "code") page.register_variable (page.status_code.out, "code")
end end

View File

@@ -20,7 +20,7 @@ feature -- Generation
custom_prepare (page: CMS_HTML_PAGE) custom_prepare (page: CMS_HTML_PAGE)
do 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.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
page.register_variable (page.status_code.out, "code") page.register_variable (page.status_code.out, "code")
end end

View File

@@ -9,6 +9,8 @@ deferred class
inherit inherit
CMS_ENCODERS CMS_ENCODERS
CMS_URL_UTILITIES
REFACTORING_HELPER REFACTORING_HELPER
@@ -16,6 +18,12 @@ feature {NONE} -- Access
setup: CMS_SETUP 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 feature -- Access
name: STRING 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 Result := across regions as ic some a_region_name.is_case_insensitive_equal (ic.item) end
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 feature -- Conversion
menu_html (a_menu: CMS_MENU; is_horizontal: BOOLEAN; a_options: detachable CMS_HTML_OPTIONS): STRING_8 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 else
s.append ("<li class=%""+ cl + "%">") s.append ("<li class=%""+ cl + "%">")
end 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 if
(lnk.is_expanded or lnk.is_collapsed) and then (lnk.is_expanded or lnk.is_collapsed) and then
attached lnk.children as l_children attached lnk.children as l_children

View File

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

View File

@@ -14,7 +14,7 @@ create
feature {NONE} -- Initialization 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 do
setup := a_setup setup := a_setup
information := a_info information := a_info
@@ -23,6 +23,7 @@ feature {NONE} -- Initialization
else else
templates_directory := a_setup.theme_location templates_directory := a_setup.theme_location
end end
set_site_url (abs_site_url)
ensure ensure
setup_set: setup = a_setup setup_set: setup = a_setup
information_set: information = a_info information_set: information = a_info

View File

@@ -1,10 +1,10 @@
note note
description: "Summary description for {WSF_CMS_THEME}." description: "Theme from the EWF framework, but dedicated for the CMS."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
WSF_CMS_THEME CMS_TO_WSF_THEME
inherit inherit
WSF_THEME WSF_THEME
@@ -25,13 +25,14 @@ feature -- Access
request: WSF_REQUEST request: WSF_REQUEST
response: detachable CMS_RESPONSE response: CMS_RESPONSE
cms_theme: CMS_THEME cms_theme: CMS_THEME
feature -- Element change feature -- Element change
set_response (a_response: CMS_RESPONSE) set_response (a_response: CMS_RESPONSE)
-- Set `response' to `a_response'.
do do
response := a_response response := a_response
end end
@@ -39,20 +40,15 @@ feature -- Element change
feature -- Core feature -- Core
site_url: READABLE_STRING_8 site_url: READABLE_STRING_8
-- CMS site url.
do do
if attached response as r then Result := response.site_url
Result := r.site_url
else
Result := request.absolute_script_url ("")
end
end end
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
-- Base url if any. -- Base url if any.
do do
if attached response as r then Result := response.base_url
Result := r.base_url
end
end end
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