From 16cae0047d9b09a2b31f0ddee10b3bd9a4eb1ad0 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 9 Jul 2015 12:23:20 +0200 Subject: [PATCH] Revisited the format, filter and content type integration. Now, all formats used by CMS are instances of CMS_FORMAT, mainly to prepare the admin section in order to define format by config/database. CMS_NODE_API provides all queries to access the content types, and formats, this way a module can easily alter the formats by adding a new filter. TODO: see how to integrate permission checking, to control who can use a specific format (such as full HTML). --- modules/blog/cms_blog_module.e | 8 ++ modules/blog/cms_blog_node_type.e | 20 ---- modules/node/cms_content_type.e | 50 ++++++++ modules/node/cms_node_api.e | 44 +++++++ modules/node/cms_node_type.e | 16 +++ .../node/content_type/cms_page_node_type.e | 24 +--- modules/openid/filter/cms_openid_filter.e | 3 - .../persitence/cms_openid_storage_sql.e | 1 - src/kernel/content/format/cms_format.e | 113 ++++++++++++++++++ 9 files changed, 234 insertions(+), 45 deletions(-) create mode 100644 src/kernel/content/format/cms_format.e diff --git a/modules/blog/cms_blog_module.e b/modules/blog/cms_blog_module.e index 19c44c6..8bbacce 100644 --- a/modules/blog/cms_blog_module.e +++ b/modules/blog/cms_blog_module.e @@ -52,9 +52,17 @@ feature {CMS_API} -- Module Initialization node_api := l_node_api -- Depends on {CMS_NODE_MODULE} + create ct + --| For now, add all available formats to content type `ct'. + across + l_node_api.available_content_formats as ic + loop + ct.extend_format (ic.item) + end l_node_api.add_content_type (ct) l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct)) + -- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value -- For now, we only have extension based on SQL statement. if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then diff --git a/modules/blog/cms_blog_node_type.e b/modules/blog/cms_blog_node_type.e index 92fd7f5..d8d713c 100644 --- a/modules/blog/cms_blog_node_type.e +++ b/modules/blog/cms_blog_node_type.e @@ -8,21 +8,6 @@ class inherit CMS_NODE_TYPE [CMS_BLOG] - redefine - default_create - end - -feature {NONE} -- Initialization - - default_create - do - Precursor - create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4) - available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT}) - available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT}) - available_formats.extend (create {FULL_HTML_CONTENT_FORMAT}) - available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT}) - end feature -- Access @@ -35,11 +20,6 @@ feature -- Access description: STRING_32 = "Content published as a blog post." -- Optional description -feature -- Access - - available_formats: LIST [CONTENT_FORMAT] - -- Available formats for Current type. - feature -- Factory new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node diff --git a/modules/node/cms_content_type.e b/modules/node/cms_content_type.e index e250c74..ba72ab1 100644 --- a/modules/node/cms_content_type.e +++ b/modules/node/cms_content_type.e @@ -36,6 +36,56 @@ feature -- Access deferred end + format (a_name: READABLE_STRING_8): detachable CONTENT_FORMAT + -- Format named `a_name', if available. + do + across + available_formats as ic + until + Result /= Void + loop + Result := ic.item + if not a_name.is_case_insensitive_equal (Result.name) then + Result := Void + end + end + end + +feature -- Element change + + extend_format (f: CONTENT_FORMAT) + -- Add `f' to the list of `available_formats' + require + not_has_format: format (f.name) = Void + do + available_formats.extend (f) + ensure + format_added: format (f.name) /= Void + end + + remove_format (f: CONTENT_FORMAT) + -- Add `f' to the list of `available_formats' + local + lst: like available_formats + l_name: READABLE_STRING_GENERAL + do + from + l_name := f.name + lst := available_formats + lst.start + until + lst.after + loop + if l_name.is_case_insensitive_equal (lst.item.name) then + lst.remove + else + lst.forth + end + end + ensure + format_removed: format (f.name) = Void + 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/node/cms_node_api.e b/modules/node/cms_node_api.e index 0ff76d2..d5cbda6 100644 --- a/modules/node/cms_node_api.e +++ b/modules/node/cms_node_api.e @@ -38,10 +38,29 @@ feature {NONE} -- Initialization -- Initialize content type system. local ct: CMS_PAGE_NODE_TYPE + f: CMS_FORMAT do + -- Initialize built-in formats + create available_content_formats.make (4) + create f.make_from_format (create {PLAIN_TEXT_CONTENT_FORMAT}) + add_content_format (f) + create f.make_from_format (create {FILTERED_HTML_CONTENT_FORMAT}) + add_content_format (f) + create f.make_from_format (create {FULL_HTML_CONTENT_FORMAT}) + add_content_format (f) + create f.make ("cms_editor", "CMS HTML content") + add_content_format (f) + + -- Initialize content types. create content_types.make (1) create content_type_webform_managers.make (1) create ct + --| For now, add all available formats to content type `ct'. + across + available_content_formats as ic + loop + ct.extend_format (ic.item) + end add_content_type (ct) add_content_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct)) end @@ -164,6 +183,31 @@ feature -- Content type webform end end +feature -- Content formats + + available_content_formats: ARRAYED_LIST [CONTENT_FORMAT] + -- Available content formats. + + add_content_format (f: CONTENT_FORMAT) + -- Add content format `f' to `available_content_formats'. + do + available_content_formats.extend (f) + end + + content_format (a_name: READABLE_STRING_GENERAL): detachable CONTENT_FORMAT + -- Format named `a_name' if available. + do + across + available_content_formats as ic + until + Result = Void + loop + if a_name.is_case_insensitive_equal (ic.item.name) then + Result := ic.item + end + end + end + feature -- URL new_content_path (ct: detachable CMS_CONTENT_TYPE): STRING diff --git a/modules/node/cms_node_type.e b/modules/node/cms_node_type.e index 07c91ce..d96f055 100644 --- a/modules/node/cms_node_type.e +++ b/modules/node/cms_node_type.e @@ -11,6 +11,22 @@ deferred class inherit CMS_CONTENT_TYPE + redefine + default_create + end + +feature {NONE} -- Initialization + + default_create + do + Precursor + create available_formats.make (1) + end + +feature -- Access + + available_formats: ARRAYED_LIST [CONTENT_FORMAT] + -- Available formats for Current type. feature -- Factory diff --git a/modules/node/content_type/cms_page_node_type.e b/modules/node/content_type/cms_page_node_type.e index 3fe15b3..b336c77 100644 --- a/modules/node/content_type/cms_page_node_type.e +++ b/modules/node/content_type/cms_page_node_type.e @@ -1,5 +1,7 @@ note - description: "Summary description for {CMS_PAGE_NODE_TYPE}." + description: "[ + Interface defining a CMS page type. + ]" date: "$Date$" revision: "$Revision$" @@ -8,21 +10,6 @@ class inherit CMS_NODE_TYPE [CMS_PAGE] - redefine - default_create - end - -feature {NONE} -- Initialization - - default_create - do - Precursor - create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4) - available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT}) - available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT}) - available_formats.extend (create {FULL_HTML_CONTENT_FORMAT}) - available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT}) - end feature -- Access @@ -35,11 +22,6 @@ feature -- Access description: STRING_32 = "Use basic pages for your content, such as an 'About us' page." -- Optional description -feature -- Access - - available_formats: LIST [CONTENT_FORMAT] - -- Available formats for Current type. - feature -- Factory new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node diff --git a/modules/openid/filter/cms_openid_filter.e b/modules/openid/filter/cms_openid_filter.e index e45725a..277ab37 100644 --- a/modules/openid/filter/cms_openid_filter.e +++ b/modules/openid/filter/cms_openid_filter.e @@ -34,9 +34,6 @@ feature -- Basic operations execute (req: WSF_REQUEST; res: WSF_RESPONSE) -- Execute the filter. - local - o: OPENID_CONSUMER - v: OPENID_CONSUMER_VALIDATION do api.logger.put_debug (generator + ".execute ", Void) diff --git a/modules/openid/persitence/cms_openid_storage_sql.e b/modules/openid/persitence/cms_openid_storage_sql.e index fa2d9ff..ab85c2d 100644 --- a/modules/openid/persitence/cms_openid_storage_sql.e +++ b/modules/openid/persitence/cms_openid_storage_sql.e @@ -105,7 +105,6 @@ feature -- Change: User OAuth -- . local l_parameters: STRING_TABLE [detachable ANY] - l_string: STRING do error_handler.reset sql_begin_transaction diff --git a/src/kernel/content/format/cms_format.e b/src/kernel/content/format/cms_format.e new file mode 100644 index 0000000..49a16e9 --- /dev/null +++ b/src/kernel/content/format/cms_format.e @@ -0,0 +1,113 @@ +note + description: "Summary description for {CMS_FORMAT}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + CMS_FORMAT + +inherit + CONTENT_FORMAT + +create + make, + make_from_format + +feature {NONE} -- Initialization + + make (a_name: READABLE_STRING_8; a_title: detachable READABLE_STRING_8) + do + default_create + name := a_name + set_title (a_title) + create filters.make (0) + end + + make_from_format (a_format: CONTENT_FORMAT) + do + make (a_format.name, a_format.title) + import_filters_from_format (a_format) + end + +feature -- Access + + name: STRING + -- + + title: STRING + -- + + filters: ARRAYED_LIST [CONTENT_FILTER] + -- + + filter (a_name: READABLE_STRING_GENERAL): detachable CONTENT_FILTER + -- Filter named `a_name' if any. + do + across + filters as ic + until + Result /= Void + loop + if a_name.is_case_insensitive_equal (ic.item.name) then + Result := ic.item + end + end + end + +feature -- Element change + + set_title (a_title: detachable READABLE_STRING_8) + -- Set `title' according to `a_title' or `name' if `a_title' is blank. + do + if a_title = Void or else a_title.is_whitespace then + create title.make_from_string (name) + else + title := a_title + end + end + + import_filters_from_format (f: CONTENT_FORMAT) + do + across + f.filters as ic + loop + add_filter (ic.item) + end + end + + add_filter (f: CONTENT_FILTER) + require + has_no_such_filter: filter (f.name) = Void + do + filters.extend (f) + ensure + has_filter: filter (f.name) = f + end + + remove_filter_by_name (a_name: READABLE_STRING_GENERAL) + -- Remove filter named `a_name' if any. + local + lst: like filters + do + from + lst := filters + lst.start + until + lst.after + loop + if a_name.is_case_insensitive_equal (lst.item.name) then + lst.remove + else + lst.forth + end + end + ensure + filter_removed: filter (a_name) = Void + end + + +note + copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" +end