From 51699f3bd384d4f4f1668746db11a065401fec94 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 19 May 2015 12:25:16 +0200 Subject: [PATCH 1/2] updated db schema --- examples/demo/site/scripts/core.sql | 2 +- examples/demo/site/scripts/node.sql | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/demo/site/scripts/core.sql b/examples/demo/site/scripts/core.sql index 04dbec8..4a48224 100644 --- a/examples/demo/site/scripts/core.sql +++ b/examples/demo/site/scripts/core.sql @@ -15,7 +15,7 @@ CREATE TABLE "logs"( CREATE TABLE "custom_values"( "type" VARCHAR(255) NOT NULL, "name" VARCHAR(255) NOT NULL, - "value" VARCHAR(255) NOT NULL + "value" TEXT ); CREATE TABLE "path_aliases"( diff --git a/examples/demo/site/scripts/node.sql b/examples/demo/site/scripts/node.sql index d30a854..565b03f 100644 --- a/examples/demo/site/scripts/node.sql +++ b/examples/demo/site/scripts/node.sql @@ -1,18 +1,18 @@ BEGIN; -CREATE TABLE "nodes"( - "nid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("nid">=0), - "revision" INTEGER, - "type" TEXT NOT NULL, - "title" VARCHAR(255) NOT NULL, - "summary" TEXT, - "content" MEDIUMTEXT NOT NULL, - "format" VARCHAR(255), - "author" INTEGER, - "publish" DATETIME, - "created" DATETIME NOT NULL, - "changed" DATETIME NOT NULL, - "status" INTEGER +CREATE TABLE "nodes" ( + "nid" INTEGER NOT NULL CHECK("nid" > 0) PRIMARY KEY AUTOINCREMENT UNIQUE, + "revision" INTEGER, + "type" TEXT NOT NULL, + "title" VARCHAR(255) NOT NULL, + "summary" TEXT, + "content" TEXT NOT NULL, + "format" VARCHAR(128), + "author" INTEGER, + "publish" DATETIME, + "created" DATETIME NOT NULL, + "changed" DATETIME NOT NULL, + "status" INTEGER ); CREATE TABLE page_nodes( From 91457080fd2f16b4e2fa159c76d435df1e029ca4 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 19 May 2015 13:44:08 +0200 Subject: [PATCH 2/2] 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. --- examples/demo/modules/blog/cms_blog_module.e | 2 +- examples/demo/modules/demo/cms_demo_module.e | 10 ++--- library/model/src/link/cms_local_link.e | 10 +++-- modules/basic_auth/basic_auth_module.e | 4 +- modules/basic_auth/filter/basic_auth_filter.e | 3 +- modules/node/cms_node_api.e | 8 ++-- .../handler/cms_node_type_webform_manager.e | 32 ++++++++++++-- modules/node/handler/node_form_response.e | 32 +++++++++----- modules/node/handler/node_response.e | 29 ++++++++++--- modules/node/handler/node_view_response.e | 2 +- modules/node/node_module.e | 4 +- src/configuration/cms_default_setup.e | 12 ++++-- src/configuration/cms_setup.e | 2 +- src/persistence/core/cms_core_storage_i.e | 2 +- src/service/cms_api.e | 11 ++++- src/service/filter/cms_error_filter.e | 6 ++- src/service/misc/cms_request_util.e | 10 ----- src/service/misc/cms_url_utilities.e | 1 + src/service/path/cms_router.e | 16 ++++++- src/service/response/cms_response.e | 43 +++++++++++++------ .../error/bad_request_error_cms_response.e | 2 +- .../error/forbidden_error_cms_response.e | 2 +- .../internal_server_error_cms_response.e | 2 +- .../error/not_found_error_cms_response.e | 2 +- .../not_implemented_error_cms_response.e | 2 +- src/theme/cms_theme.e | 38 +++++++++++++++- src/theme/missing_theme/missing_cms_theme.e | 6 ++- src/theme/smarty_theme/smarty_cms_theme.e | 3 +- .../theme/wsf/cms_to_wsf_theme.e | 18 +++----- src/theme/wsf/wsf_cms_theme.e | 17 ++++++++ .../theme/wsf}/wsf_null_theme.e | 0 31 files changed, 237 insertions(+), 94 deletions(-) rename modules/node/handler/wsf_cms_theme.e => src/theme/wsf/cms_to_wsf_theme.e (65%) create mode 100644 src/theme/wsf/wsf_cms_theme.e rename {modules/node/handler => src/theme/wsf}/wsf_null_theme.e (100%) diff --git a/examples/demo/modules/blog/cms_blog_module.e b/examples/demo/modules/blog/cms_blog_module.e index b75fdcd..d60c35e 100644 --- a/examples/demo/modules/blog/cms_blog_module.e +++ b/examples/demo/modules/blog/cms_blog_module.e @@ -101,7 +101,7 @@ feature -- Hooks local lnk: CMS_LOCAL_LINK do - create lnk.make ("Blogs", "/blogs/") + create lnk.make ("Blogs", "blogs/") a_menu_system.primary_menu.extend (lnk) end diff --git a/examples/demo/modules/demo/cms_demo_module.e b/examples/demo/modules/demo/cms_demo_module.e index e0f1ff1..0ab359e 100644 --- a/examples/demo/modules/demo/cms_demo_module.e +++ b/examples/demo/modules/demo/cms_demo_module.e @@ -110,9 +110,9 @@ feature -- Hooks if a_block_id.is_case_insensitive_equal_general ("demo-info") then if a_response.request.request_uri.starts_with ("/demo/") then 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) - create lnk.make ("/demo/123", a_response.url ("/demo/123", Void)) + create lnk.make ("demo: 123", "demo/123") m.extend (lnk) create mb.make (m) a_response.add_block (mb, "sidebar_second") @@ -125,7 +125,7 @@ feature -- Hooks lnk: CMS_LOCAL_LINK -- perms: detachable ARRAYED_LIST [READABLE_STRING_8] do - create lnk.make ("Demo", "/demo/") + create lnk.make ("Demo", "demo/") a_menu_system.primary_menu.extend (lnk) end @@ -137,8 +137,8 @@ feature -- Handler r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE do create r.make (req, res, a_api) - r.set_main_content ("NODE module does not yet implement %"" + req.path_info + "%" ...") - r.add_error_message ("NODE Module: not yet implemented") + r.set_main_content ("DEMO module does not yet implement %"" + req.path_info + "%" ...") + r.add_error_message ("DEMO Module: not yet implemented") r.execute end diff --git a/library/model/src/link/cms_local_link.e b/library/model/src/link/cms_local_link.e index 376ccac..146d6f7 100644 --- a/library/model/src/link/cms_local_link.e +++ b/library/model/src/link/cms_local_link.e @@ -25,8 +25,10 @@ create 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'. + require + is_valid_local_location_argument: not a_location.starts_with_general ("/") do location := a_location set_title (a_title) @@ -71,13 +73,13 @@ feature -- Status report 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'. do if a_title /= Void then - title := a_title + title := a_title.as_string_32 else - title := location + title := location.as_string_32 end end diff --git a/modules/basic_auth/basic_auth_module.e b/modules/basic_auth/basic_auth_module.e index 3efe2c2..515cac7 100644 --- a/modules/basic_auth/basic_auth_module.e +++ b/modules/basic_auth/basic_auth_module.e @@ -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) diff --git a/modules/basic_auth/filter/basic_auth_filter.e b/modules/basic_auth/filter/basic_auth_filter.e index 59423fd..0154d04 100644 --- a/modules/basic_auth/filter/basic_auth_filter.e +++ b/modules/basic_auth/filter/basic_auth_filter.e @@ -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 diff --git a/modules/node/cms_node_api.e b/modules/node/cms_node_api.e index 8f0a8d9..f56f6a0 100644 --- a/modules/node/cms_node_api.e +++ b/modules/node/cms_node_api.e @@ -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 diff --git a/modules/node/handler/cms_node_type_webform_manager.e b/modules/node/handler/cms_node_type_webform_manager.e index f571c26..5af3918 100644 --- a/modules/node/handler/cms_node_type_webform_manager.e +++ b/modules/node/handler/cms_node_type_webform_manager.e @@ -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) diff --git a/modules/node/handler/node_form_response.e b/modules/node/handler/node_form_response.e index c01330a..9f92e28 100644 --- a/modules/node/handler/node_form_response.e +++ b/modules/node/handler/node_form_response.e @@ -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 ("
  • " + link (l_node_type.name, "/node/add/" + l_node_type.name, Void)) + b.append ("
  • " + link (l_node_type.name, "node/add/" + l_node_type.name, Void)) if attached l_node_type.description as d then b.append ("
    " + d + "
    ") 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 diff --git a/modules/node/handler/node_response.e b/modules/node/handler/node_response.e index 1bad113..6c444a5 100644 --- a/modules/node/handler/node_response.e +++ b/modules/node/handler/node_response.e @@ -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 diff --git a/modules/node/handler/node_view_response.e b/modules/node/handler/node_view_response.e index e62a316..aac253f 100644 --- a/modules/node/handler/node_view_response.e +++ b/modules/node/handler/node_view_response.e @@ -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 diff --git a/modules/node/node_module.e b/modules/node/node_module.e index 8df4eab..4e4e3f2 100644 --- a/modules/node/node_module.e +++ b/modules/node/node_module.e @@ -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 diff --git a/src/configuration/cms_default_setup.e b/src/configuration/cms_default_setup.e index 9a16640..64ec4b0 100644 --- a/src/configuration/cms_default_setup.e +++ b/src/configuration/cms_default_setup.e @@ -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") diff --git a/src/configuration/cms_setup.e b/src/configuration/cms_setup.e index 792f84e..1b53010 100644 --- a/src/configuration/cms_setup.e +++ b/src/configuration/cms_setup.e @@ -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. diff --git a/src/persistence/core/cms_core_storage_i.e b/src/persistence/core/cms_core_storage_i.e index 89926de..ef87eba 100644 --- a/src/persistence/core/cms_core_storage_i.e +++ b/src/persistence/core/cms_core_storage_i.e @@ -1,6 +1,6 @@ note description: "[ - Objects that ... + CMS Storage for core functionalities. ]" author: "$Author$" date: "$Date$" diff --git a/src/service/cms_api.e b/src/service/cms_api.e index 655ed43..0209c97 100644 --- a/src/service/cms_api.e +++ b/src/service/cms_api.e @@ -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 diff --git a/src/service/filter/cms_error_filter.e b/src/service/filter/cms_error_filter.e index a07a3bc..0e5f457 100644 --- a/src/service/filter/cms_error_filter.e +++ b/src/service/filter/cms_error_filter.e @@ -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 diff --git a/src/service/misc/cms_request_util.e b/src/service/misc/cms_request_util.e index e29bc61..f49337a 100644 --- a/src/service/misc/cms_request_util.e +++ b/src/service/misc/cms_request_util.e @@ -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 diff --git a/src/service/misc/cms_url_utilities.e b/src/service/misc/cms_url_utilities.e index 73feb92..89505a6 100644 --- a/src/service/misc/cms_url_utilities.e +++ b/src/service/misc/cms_url_utilities.e @@ -13,6 +13,7 @@ inherit feature -- Core site_url: READABLE_STRING_8 + -- Absolute site URL of Current CMS site. deferred end diff --git a/src/service/path/cms_router.e b/src/service/path/cms_router.e index fdc0452..ce1982e 100644 --- a/src/service/path/cms_router.e +++ b/src/service/path/cms_router.e @@ -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 diff --git a/src/service/response/cms_response.e b/src/service/response/cms_response.e index 18d99d4..b0dc598 100644 --- a/src/service/response/cms_response.e +++ b/src/service/response/cms_response.e @@ -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) diff --git a/src/service/response/error/bad_request_error_cms_response.e b/src/service/response/error/bad_request_error_cms_response.e index 4c15239..002a3c3 100644 --- a/src/service/response/error/bad_request_error_cms_response.e +++ b/src/service/response/error/bad_request_error_cms_response.e @@ -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 diff --git a/src/service/response/error/forbidden_error_cms_response.e b/src/service/response/error/forbidden_error_cms_response.e index 5616c8b..62518e5 100644 --- a/src/service/response/error/forbidden_error_cms_response.e +++ b/src/service/response/error/forbidden_error_cms_response.e @@ -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 diff --git a/src/service/response/error/internal_server_error_cms_response.e b/src/service/response/error/internal_server_error_cms_response.e index 43eb930..f23a871 100644 --- a/src/service/response/error/internal_server_error_cms_response.e +++ b/src/service/response/error/internal_server_error_cms_response.e @@ -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 diff --git a/src/service/response/error/not_found_error_cms_response.e b/src/service/response/error/not_found_error_cms_response.e index 2f9ae36..2c7d63c 100644 --- a/src/service/response/error/not_found_error_cms_response.e +++ b/src/service/response/error/not_found_error_cms_response.e @@ -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 diff --git a/src/service/response/error/not_implemented_error_cms_response.e b/src/service/response/error/not_implemented_error_cms_response.e index 159b9b4..e46e9fd 100644 --- a/src/service/response/error/not_implemented_error_cms_response.e +++ b/src/service/response/error/not_implemented_error_cms_response.e @@ -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 diff --git a/src/theme/cms_theme.e b/src/theme/cms_theme.e index d90c625..f88f7e9 100644 --- a/src/theme/cms_theme.e +++ b/src/theme/cms_theme.e @@ -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 ("
  • ") end - s.append ("" + html_encoded (lnk.title) + "") + s.append ("") + s.append (html_encoded (lnk.title)) + s.append ("") if (lnk.is_expanded or lnk.is_collapsed) and then attached lnk.children as l_children diff --git a/src/theme/missing_theme/missing_cms_theme.e b/src/theme/missing_theme/missing_cms_theme.e index b6c5ab9..bd767a5 100644 --- a/src/theme/missing_theme/missing_cms_theme.e +++ b/src/theme/missing_theme/missing_cms_theme.e @@ -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] diff --git a/src/theme/smarty_theme/smarty_cms_theme.e b/src/theme/smarty_theme/smarty_cms_theme.e index 5f408e4..4ff9657 100644 --- a/src/theme/smarty_theme/smarty_cms_theme.e +++ b/src/theme/smarty_theme/smarty_cms_theme.e @@ -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 diff --git a/modules/node/handler/wsf_cms_theme.e b/src/theme/wsf/cms_to_wsf_theme.e similarity index 65% rename from modules/node/handler/wsf_cms_theme.e rename to src/theme/wsf/cms_to_wsf_theme.e index 8ef9e3a..c3cf6cc 100644 --- a/modules/node/handler/wsf_cms_theme.e +++ b/src/theme/wsf/cms_to_wsf_theme.e @@ -1,10 +1,10 @@ note - description: "Summary description for {WSF_CMS_THEME}." + description: "Theme from the EWF framework, but dedicated for the CMS." date: "$Date$" revision: "$Revision$" class - WSF_CMS_THEME + CMS_TO_WSF_THEME inherit WSF_THEME @@ -25,13 +25,14 @@ feature -- Access request: WSF_REQUEST - response: detachable CMS_RESPONSE + 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 @@ -39,20 +40,15 @@ feature -- Element change feature -- Core site_url: READABLE_STRING_8 + -- CMS site url. do - if attached response as r then - Result := r.site_url - else - Result := request.absolute_script_url ("") - end + Result := response.site_url end base_url: detachable READABLE_STRING_8 -- Base url if any. do - if attached response as r then - Result := r.base_url - end + Result := response.base_url end end diff --git a/src/theme/wsf/wsf_cms_theme.e b/src/theme/wsf/wsf_cms_theme.e new file mode 100644 index 0000000..7d8d69a --- /dev/null +++ b/src/theme/wsf/wsf_cms_theme.e @@ -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 diff --git a/modules/node/handler/wsf_null_theme.e b/src/theme/wsf/wsf_null_theme.e similarity index 100% rename from modules/node/handler/wsf_null_theme.e rename to src/theme/wsf/wsf_null_theme.e