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

@@ -109,9 +109,9 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK
do
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
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
-- if not a_menu_system.primary_menu.has (lnk) then
lnk.set_weight (99)

View File

@@ -22,11 +22,12 @@ feature -- Basic operations
-- Execute the filter.
local
l_auth: HTTP_AUTHORIZATION
utf: UTF_CONVERTER
do
api.logger.put_debug (generator + ".execute ", Void)
create l_auth.make (req.http_authorization)
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
-- A valid user
if

View File

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

View File

@@ -9,6 +9,8 @@ deferred class
inherit
CMS_NODE_TYPE_WEBFORM_MANAGER_I [G]
SHARED_WSF_PERCENT_ENCODER
feature -- Forms ...
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
@@ -18,6 +20,7 @@ feature -- Forms ...
ta: WSF_FORM_TEXTAREA
tselect: WSF_FORM_SELECT
opt: WSF_FORM_SELECT_OPTION
l_uri: detachable READABLE_STRING_8
do
create ti.make ("title")
ti.set_label ("Title")
@@ -66,16 +69,37 @@ feature -- Forms ...
f.extend (fset)
-- Path aliase
-- Path alias
create ti.make ("path_alias")
ti.set_label ("Path")
ti.set_size (70)
if a_node /= Void and then a_node.has_id then
if attached a_node.link as lnk then
ti.set_text_value (lnk.location)
l_uri := lnk.location
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
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
if
attached f.fields_by_name ("title") as l_title_fields and then
@@ -180,7 +204,7 @@ feature -- Output
node_api := a_response.node_api
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)
a_response.add_to_primary_tabs (lnk)

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
initialize
do
Precursor
create {WSF_CMS_THEME} wsf_theme.make (Current, theme)
create {CMS_TO_WSF_THEME} wsf_theme.make (Current, theme)
end
wsf_theme: WSF_THEME
@@ -58,8 +58,8 @@ feature -- Execution
fd := f.last_data
end
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 (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), "/node/" + l_node.id.out + "/edit"), 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_api.node_path (l_node) + "/edit"), primary_tabs)
end
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)
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 (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), "/node/" + l_node.id.out + "/edit"), 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_api.node_path (l_node) + "/edit"), primary_tabs)
end
f.append_to_html (wsf_theme, b)
@@ -121,7 +121,7 @@ feature -- Execution
attached ic.item as l_node_type and then
has_permissions (<<"create any", "create " + l_node_type.name>>)
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
b.append ("<div class=%"description%">" + d + "</div>")
end
@@ -167,6 +167,7 @@ feature -- Form
l_preview: BOOLEAN
l_node: detachable CMS_NODE
s: STRING
l_path_alias: detachable READABLE_STRING_8
do
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
if not l_preview then
@@ -198,20 +199,29 @@ feature -- Form
end
node_api.save_node (l_node)
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
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
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)
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_path_alias))
else
l_node.set_link (node_api.node_link (l_node))
end
set_redirection (node_url (l_node))
if attached l_node.link as lnk then
set_redirection (lnk.location)
end
end
end

View File

@@ -53,30 +53,45 @@ feature -- Helpers
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
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
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
if attached n.link as lnk then
Result := lnk
else
Result := node_api.node_link (n)
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
feature -- Helpers: html link
user_html_link (u: CMS_USER): like link
do
Result := link (u.name, "/user/" + u.id.out, Void)
Result := link (u.name, "user/" + u.id.out, Void)
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
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
feature -- Helpers: URL
@@ -85,7 +100,7 @@ feature -- Helpers: URL
require
u_with_id: u.has_id
do
Result := url ("/user/" + u.id.out, Void)
Result := url ("user/" + u.id.out, Void)
end
node_url (n: CMS_NODE): like url

View File

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

View File

@@ -1,58 +0,0 @@
note
description: "Summary description for {WSF_CMS_THEME}."
date: "$Date$"
revision: "$Revision$"
class
WSF_CMS_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: detachable CMS_RESPONSE
cms_theme: CMS_THEME
feature -- Element change
set_response (a_response: CMS_RESPONSE)
do
response := a_response
end
feature -- Core
site_url: READABLE_STRING_8
do
if attached response as r then
Result := r.site_url
else
Result := request.absolute_script_url ("")
end
end
base_url: detachable READABLE_STRING_8
-- Base url if any.
do
if attached response as r then
Result := r.base_url
end
end
end

View File

@@ -1,30 +0,0 @@
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

View File

@@ -173,10 +173,10 @@ feature -- Hooks
lnk: CMS_LOCAL_LINK
-- perms: detachable ARRAYED_LIST [READABLE_STRING_8]
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)
create lnk.make ("Create ..", a_response.url ("/node/", Void))
create lnk.make ("Create ..", "node/")
a_menu_system.primary_menu.extend (lnk)
end