Renamed node_api and node_storage by blog_api and blog_storage in related CMS_BLOG_* classes. Mainly to avoid confusion with NODE_ classes.
Merged CMS_BLOG_CONFIG with CMS_BLOG_API. In CMS_BLOG_API, prefer argument of type CMS_USER, rather than using directly user id. Added a CMS_EDITOR_CONTENT_FORMAT for now, to be the format editable by the WYSIWYG editor. Added CMS_MODULE.is_initialized: BOOLEAN to equip router, and module_api with expected preconditions. Fixed typo, especially in log output. Corrected a few routine names such as add_authors that should not be a function according to its name. Converted various function returning html content, to procedure appending html content to an output string to minimize temporary string object creation. Cosmetic: added spaces to make code easier to read, and indentation.
This commit is contained in:
@@ -31,7 +31,13 @@ feature -- Conversion
|
|||||||
do
|
do
|
||||||
Precursor (a_node)
|
Precursor (a_node)
|
||||||
if attached {CMS_BLOG} a_node as l_blog then
|
if attached {CMS_BLOG} a_node as l_blog then
|
||||||
-- l_blog
|
if attached l_blog.tags as l_tags then
|
||||||
|
across
|
||||||
|
l_tags as ic
|
||||||
|
loop
|
||||||
|
add_tag (ic.item)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,7 +48,7 @@ feature -- Access
|
|||||||
Result := {CMS_BLOG_NODE_TYPE}.name
|
Result := {CMS_BLOG_NODE_TYPE}.name
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access: content
|
feature -- Access: node
|
||||||
|
|
||||||
summary: detachable READABLE_STRING_8
|
summary: detachable READABLE_STRING_8
|
||||||
-- A short summary of the node.
|
-- A short summary of the node.
|
||||||
@@ -54,10 +60,12 @@ feature -- Access: content
|
|||||||
-- Format associated with `content' and `summary'.
|
-- Format associated with `content' and `summary'.
|
||||||
-- For example: text, mediawiki, html, etc
|
-- For example: text, mediawiki, html, etc
|
||||||
|
|
||||||
|
feature -- Access: blog
|
||||||
|
|
||||||
tags: detachable ARRAYED_LIST [READABLE_STRING_32]
|
tags: detachable ARRAYED_LIST [READABLE_STRING_32]
|
||||||
-- Optional tags
|
-- Optional tags
|
||||||
|
|
||||||
feature -- Element change
|
feature -- Element change: node
|
||||||
|
|
||||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||||
do
|
do
|
||||||
@@ -66,6 +74,8 @@ feature -- Element change
|
|||||||
format := a_format
|
format := a_format
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Element change: blog
|
||||||
|
|
||||||
add_tag (a_tag: READABLE_STRING_32)
|
add_tag (a_tag: READABLE_STRING_32)
|
||||||
-- Set `parent' to `a_page'
|
-- Set `parent' to `a_page'
|
||||||
require
|
require
|
||||||
|
|||||||
@@ -8,93 +8,108 @@ class
|
|||||||
CMS_BLOG_API
|
CMS_BLOG_API
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_NODE_API
|
CMS_MODULE_API
|
||||||
|
rename
|
||||||
|
make as make_with_cms_api
|
||||||
redefine
|
redefine
|
||||||
initialize,
|
initialize
|
||||||
node_storage
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
REFACTORING_HELPER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_api: CMS_API; a_node_api: CMS_NODE_API)
|
||||||
|
-- (from CMS_MODULE_API)
|
||||||
|
-- (export status {NONE})
|
||||||
|
do
|
||||||
|
node_api := a_node_api
|
||||||
|
make_with_cms_api (a_api)
|
||||||
|
end
|
||||||
|
|
||||||
initialize
|
initialize
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
Precursor
|
Precursor
|
||||||
-- Create the node storage for type blog
|
|
||||||
|
-- Create the node storage for type blog
|
||||||
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
|
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
|
||||||
create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql)
|
create {CMS_BLOG_STORAGE_SQL} blog_storage.make (l_storage_sql)
|
||||||
else
|
else
|
||||||
create {CMS_BLOG_STORAGE_NULL} node_storage.make
|
create {CMS_BLOG_STORAGE_NULL} blog_storage.make
|
||||||
end
|
end
|
||||||
initialize_node_types
|
-- initialize_node_types
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {CMS_API_ACCESS, CMS_MODULE, CMS_API} -- Restricted access
|
||||||
|
|
||||||
|
node_api: CMS_NODE_API
|
||||||
|
|
||||||
feature {CMS_MODULE} -- Access nodes storage.
|
feature {CMS_MODULE} -- Access nodes storage.
|
||||||
|
|
||||||
node_storage: CMS_BLOG_STORAGE_I
|
blog_storage: CMS_BLOG_STORAGE_I
|
||||||
|
|
||||||
|
feature -- Configuration of blog handlers
|
||||||
|
|
||||||
|
entries_per_page : NATURAL_32 = 2
|
||||||
|
-- The numbers of posts that are shown on one page. If there are more post a pagination is generated
|
||||||
|
--| For test reasons this is 2, so we don't have to create a lot of blog entries.
|
||||||
|
--| TODO: Set to bigger constant.
|
||||||
|
|
||||||
feature -- Access node
|
feature -- Access node
|
||||||
|
|
||||||
blogs_count: INTEGER_64
|
blogs_count: INTEGER_64
|
||||||
-- Number of nodes of type blog
|
-- Number of nodes of type blog.
|
||||||
do
|
do
|
||||||
Result := node_storage.blogs_count
|
Result := blog_storage.blogs_count
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_count_from_user (user_id: INTEGER_64) : INTEGER_64
|
blogs_count_from_user (a_user: CMS_USER): INTEGER_64
|
||||||
-- Number of nodes of type blog from user with user_id
|
-- Number of nodes of type blog from user with `a_user_id'.
|
||||||
|
require
|
||||||
|
has_id: a_user.has_id
|
||||||
do
|
do
|
||||||
Result := node_storage.blogs_count_from_user(user_id)
|
Result := blog_storage.blogs_count_from_user (a_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_order_created_desc: LIST[CMS_NODE]
|
blogs_order_created_desc: LIST [CMS_BLOG]
|
||||||
-- List of nodes ordered by creation date (descending)
|
-- List of nodes ordered by creation date (descending)
|
||||||
do
|
do
|
||||||
Result := add_authors(node_storage.blogs)
|
Result := nodes_to_blogs (blog_storage.blogs)
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_order_created_desc_limited (a_limit:NATURAL_32; a_offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_order_created_desc_limited (a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_BLOG]
|
||||||
-- List of nodes ordered by creation date and limited by limit and offset
|
-- List of nodes ordered by creation date and limited by limit and offset
|
||||||
local
|
|
||||||
tmp: LIST[CMS_NODE]
|
|
||||||
do
|
do
|
||||||
-- load all posts and add the authors to each post
|
-- load all posts and add the authors to each post
|
||||||
Result := add_authors(node_storage.blogs_limited (a_limit, a_offset))
|
Result := nodes_to_blogs (blog_storage.blogs_limited (a_limit, a_offset))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_from_user_order_created_desc_limited (a_user_id: INTEGER_32; a_limit:NATURAL_32; a_offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_from_user_order_created_desc_limited (a_user: CMS_USER; a_limit: NATURAL_32; a_offset: NATURAL_32) : LIST [CMS_BLOG]
|
||||||
-- List of nodes ordered by creation date and limited by limit and offset
|
-- List of nodes ordered by creation date and limited by limit and offset
|
||||||
local
|
require
|
||||||
tmp: LIST[CMS_NODE]
|
has_id: a_user.has_id
|
||||||
do
|
do
|
||||||
-- load all posts and add the authors to each post
|
-- load all posts and add the authors to each post
|
||||||
Result := add_authors(node_storage.blogs_from_user_limited (a_user_id, a_limit, a_offset))
|
Result := nodes_to_blogs (blog_storage.blogs_from_user_limited (a_user, a_limit, a_offset))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
feature {NONE} -- Helpers
|
||||||
|
|
||||||
add_authors(posts: LIST[CMS_NODE]) : LIST[CMS_NODE]
|
nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG]
|
||||||
-- sets the authors of all given sql results
|
-- Convert list of nodes into a list of blog when possible.
|
||||||
do
|
do
|
||||||
Result := posts
|
create {ARRAYED_LIST [CMS_BLOG]} Result.make (a_nodes.count)
|
||||||
if posts /= Void then
|
|
||||||
|
if attached node_api as l_node_api then
|
||||||
across
|
across
|
||||||
Result
|
a_nodes as ic
|
||||||
as
|
|
||||||
sql_result
|
|
||||||
loop
|
loop
|
||||||
if
|
if attached {CMS_BLOG} l_node_api.full_node (ic.item) as l_blog then
|
||||||
sql_result.item /= Void and then
|
Result.force (l_blog)
|
||||||
attached {CMS_PARTIAL_USER} sql_result.item.author as l_partial_author
|
|
||||||
then
|
|
||||||
if attached cms_api.user_api.user_by_id (l_partial_author.id) as l_author then
|
|
||||||
sql_result.item.set_author (l_author)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Configuration class for the blog module."
|
|
||||||
author: "Dario B<>sch <daboesch@student.ethz.ch"
|
|
||||||
date: "$Date: 2015-05-22 11:26:00 +0100$"
|
|
||||||
revision: "$Revision: 96616 $"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_BLOG_CONFIG
|
|
||||||
|
|
||||||
|
|
||||||
feature -- Configuration of blog handlers
|
|
||||||
|
|
||||||
entries_per_page : NATURAL_32
|
|
||||||
-- The numbers of posts that are shown on one page. If there are more post a pagination is generated
|
|
||||||
do
|
|
||||||
-- For test reasons this is 2, so we don't have to create a lot of blog entries.
|
|
||||||
-- TODO: Set to bigger constant.
|
|
||||||
Result := 2
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -10,13 +10,13 @@ class
|
|||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_MODULE
|
||||||
rename
|
rename
|
||||||
module_api as node_api
|
module_api as blog_api
|
||||||
redefine
|
redefine
|
||||||
register_hooks,
|
register_hooks,
|
||||||
initialize,
|
initialize,
|
||||||
is_installed,
|
is_installed,
|
||||||
install,
|
install,
|
||||||
node_api
|
blog_api
|
||||||
end
|
end
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||||
@@ -44,6 +44,10 @@ feature {CMS_API} -- Module Initialization
|
|||||||
Precursor (api)
|
Precursor (api)
|
||||||
|
|
||||||
if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then
|
if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then
|
||||||
|
create blog_api.make (api, l_node_api)
|
||||||
|
|
||||||
|
node_api := l_node_api
|
||||||
|
-- Depends on {NODE_MODULE}
|
||||||
create ct
|
create ct
|
||||||
l_node_api.add_content_type (ct)
|
l_node_api.add_content_type (ct)
|
||||||
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||||
@@ -88,46 +92,49 @@ CREATE TABLE "blog_post_nodes"(
|
|||||||
|
|
||||||
feature {CMS_API} -- Access: API
|
feature {CMS_API} -- Access: API
|
||||||
|
|
||||||
node_api: detachable CMS_BLOG_API
|
blog_api: detachable CMS_BLOG_API
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
|
|
||||||
|
node_api: detachable CMS_NODE_API
|
||||||
|
|
||||||
feature -- Access: router
|
feature -- Access: router
|
||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
|
||||||
l_node_api: like node_api
|
|
||||||
do
|
do
|
||||||
l_node_api := node_api
|
if attached blog_api as l_blog_api then
|
||||||
if l_node_api = Void then
|
configure_web (a_api, l_blog_api, a_router)
|
||||||
create l_node_api.make (a_api)
|
else
|
||||||
node_api := l_node_api
|
-- Issue with api/dependencies,
|
||||||
|
-- thus Current module should not be used!
|
||||||
|
-- thus no url mapping
|
||||||
end
|
end
|
||||||
configure_web (a_api, l_node_api, a_router)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
configure_web (a_api: CMS_API; a_blog_api: CMS_BLOG_API; a_router: WSF_ROUTER)
|
||||||
configure_web (a_api: CMS_API; a_node_api: CMS_BLOG_API; a_router: WSF_ROUTER)
|
-- Configure router mapping for web interface.
|
||||||
local
|
local
|
||||||
l_blog_handler: BLOG_HANDLER
|
l_blog_handler: BLOG_HANDLER
|
||||||
l_blog_user_handler: BLOG_USER_HANDLER
|
l_blog_user_handler: BLOG_USER_HANDLER
|
||||||
l_uri_mapping: WSF_URI_MAPPING
|
l_uri_mapping: WSF_URI_MAPPING
|
||||||
do
|
do
|
||||||
-- TODO: for now, focused only on web interface, add REST api later. [2015-May-18]
|
-- TODO: for now, focused only on web interface, add REST api later. [2015-May-18]
|
||||||
create l_blog_handler.make (a_api, a_node_api)
|
create l_blog_handler.make (a_api, a_blog_api)
|
||||||
create l_blog_user_handler.make (a_api, a_node_api)
|
create l_blog_user_handler.make (a_api, a_blog_api)
|
||||||
|
|
||||||
-- Let the class BLOG_HANDLER handle the requests on "/blogs"
|
-- Let the class BLOG_HANDLER handle the requests on "/blogs"
|
||||||
create l_uri_mapping.make_trailing_slash_ignored("/blogs", l_blog_handler)
|
create l_uri_mapping.make_trailing_slash_ignored ("/blogs", l_blog_handler)
|
||||||
a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get)
|
a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get)
|
||||||
|
|
||||||
-- We can add a page number after /blogs/ to get older posts
|
-- We can add a page number after /blogs/ to get older posts
|
||||||
a_router.handle_with_request_methods ("/blogs/page/{page}", l_blog_handler, a_router.methods_get)
|
a_router.handle_with_request_methods ("/blogs/page/{page}", l_blog_handler, a_router.methods_get)
|
||||||
|
|
||||||
-- If a user id is given route with blog user handler
|
-- If a user id is given route with blog user handler
|
||||||
|
--| FIXME: maybe /user/{user}/blogs/ would be better.
|
||||||
a_router.handle_with_request_methods ("/blogs/user/{user}", l_blog_user_handler, a_router.methods_get)
|
a_router.handle_with_request_methods ("/blogs/user/{user}", l_blog_user_handler, a_router.methods_get)
|
||||||
|
|
||||||
-- If a user id is given we also want to allow different pages
|
-- If a user id is given we also want to allow different pages
|
||||||
|
--| FIXME: what about /user/{user}/blogs/?page={page} ?
|
||||||
a_router.handle_with_request_methods ("/blogs/user/{user}/page/{page}", l_blog_user_handler, a_router.methods_get)
|
a_router.handle_with_request_methods ("/blogs/user/{user}/page/{page}", l_blog_user_handler, a_router.methods_get)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ feature {NONE} -- Initialization
|
|||||||
default_create
|
default_create
|
||||||
do
|
do
|
||||||
Precursor
|
Precursor
|
||||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (3)
|
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||||
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||||
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||||
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
||||||
|
available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT})
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ class
|
|||||||
BLOG_HANDLER
|
BLOG_HANDLER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_BLOG_CONFIG
|
|
||||||
|
|
||||||
CMS_BLOG_HANDLER
|
CMS_BLOG_HANDLER
|
||||||
|
|
||||||
WSF_URI_HANDLER
|
WSF_URI_HANDLER
|
||||||
@@ -41,60 +39,63 @@ create
|
|||||||
feature -- execute
|
feature -- execute
|
||||||
|
|
||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Execute request handler
|
-- Execute request handler for any kind of mapping.
|
||||||
do
|
do
|
||||||
execute_methods (req, res)
|
execute_methods (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Execute request handler
|
-- Execute request handler for URI mapping.
|
||||||
do
|
do
|
||||||
execute (req, res)
|
execute (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Execute request handler
|
-- Execute request handler for URI-template mapping.
|
||||||
do
|
do
|
||||||
execute (req, res)
|
execute (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Global Variables
|
feature -- Global Variables
|
||||||
|
|
||||||
page_number: NATURAL_32
|
page_number: NATURAL_32
|
||||||
|
-- Current page number.
|
||||||
|
|
||||||
feature -- HTTP Methods
|
feature -- HTTP Methods
|
||||||
|
|
||||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_page: CMS_RESPONSE
|
l_page: CMS_RESPONSE
|
||||||
do
|
do
|
||||||
|
-- Read page number from path parameter.
|
||||||
-- Read the page number from get variable
|
|
||||||
page_number := page_number_path_parameter (req)
|
page_number := page_number_path_parameter (req)
|
||||||
|
|
||||||
-- execute response by setting the main content
|
-- Responding with `main_content_html (l_page)'.
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||||
l_page.set_main_content (main_content_html(l_page))
|
l_page.set_main_content (main_content_html (l_page))
|
||||||
l_page.execute
|
l_page.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Query
|
feature -- Query
|
||||||
|
|
||||||
|
posts: LIST [CMS_NODE]
|
||||||
posts : LIST[CMS_NODE]
|
-- Blog posts to display on given page ordered by date (descending).
|
||||||
-- The posts to list on the given page ordered by date (descending)
|
|
||||||
do
|
do
|
||||||
Result := node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page)
|
Result := blog_api.blogs_order_created_desc_limited (
|
||||||
|
entries_per_page,
|
||||||
|
entries_per_page * (page_number - 1)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
more_than_one_page : BOOLEAN
|
multiple_pages_needed : BOOLEAN
|
||||||
-- Checks if all posts fit on one page (FALSE) or if more than one page is needed (TRUE)
|
-- Return if more that one page is needed to display posts.
|
||||||
do
|
do
|
||||||
Result := entries_per_page < total_entries
|
Result := entries_per_page < total_entries
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pages_count: NATURAL_32
|
||||||
pages : NATURAL_32
|
-- Number of pages needed to display all posts.
|
||||||
-- Returns the number of pages needed to display all posts
|
|
||||||
require
|
require
|
||||||
entries_per_page > 0
|
entries_per_page > 0
|
||||||
local
|
local
|
||||||
@@ -105,7 +106,8 @@ feature -- Query
|
|||||||
end
|
end
|
||||||
|
|
||||||
page_number_path_parameter (req: WSF_REQUEST): NATURAL_32
|
page_number_path_parameter (req: WSF_REQUEST): NATURAL_32
|
||||||
-- Returns the page number from the path /blogs/{page}. It's an unsigned integer since negative pages are not allowed
|
-- Page number from path /blogs/{page}.
|
||||||
|
-- Unsigned integer since negative pages are not allowed.
|
||||||
local
|
local
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
@@ -120,153 +122,150 @@ feature -- Query
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
total_entries : NATURAL_32
|
total_entries: NATURAL_32
|
||||||
-- Returns the number of total entries/posts
|
-- Total number of entries/posts.
|
||||||
do
|
do
|
||||||
Result := node_api.blogs_count.to_natural_32
|
Result := blog_api.blogs_count.to_natural_32
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- HTML Output
|
feature -- HTML Output
|
||||||
|
|
||||||
main_content_html (page: CMS_RESPONSE) : STRING
|
frozen main_content_html (page: CMS_RESPONSE): STRING
|
||||||
-- Return the content of the page as a html string
|
-- Content of the page as a html string.
|
||||||
|
do
|
||||||
|
create Result.make_empty
|
||||||
|
append_main_content_html_to (page, Result)
|
||||||
|
end
|
||||||
|
|
||||||
|
append_main_content_html_to (page: CMS_RESPONSE; a_output: STRING)
|
||||||
|
-- Append to `a_output, the content of the page as a html string.
|
||||||
local
|
local
|
||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
-- Output the title. If more than one page, also output the current page number
|
-- Output the title. If more than one page, also output the current page number
|
||||||
create Result.make_from_string (page_title_html)
|
append_page_title_html_to (a_output)
|
||||||
|
|
||||||
-- Get the posts from the current page (given by page number and entries per page)
|
-- Get the posts from the current page (given by page number and entries per page)
|
||||||
if attached posts as lst then
|
-- Start list of posts
|
||||||
|
a_output.append ("<ul class=%"cms_blog_nodes%">%N")
|
||||||
|
across
|
||||||
|
posts as ic
|
||||||
|
loop
|
||||||
|
n := ic.item
|
||||||
|
lnk := blog_api.node_api.node_link (n)
|
||||||
|
a_output.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
||||||
|
|
||||||
-- Start list of posts
|
-- Output the creation date
|
||||||
Result.append ("<ul class=%"cms_blog_nodes%">%N")
|
append_creation_date_html_to (n, a_output)
|
||||||
across
|
|
||||||
lst as ic
|
|
||||||
loop
|
|
||||||
n := ic.item
|
|
||||||
lnk := node_api.node_link (n)
|
|
||||||
Result.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
|
||||||
|
|
||||||
-- Output the creation date
|
-- Output the author of the post
|
||||||
Result.append (creation_date_html(n))
|
append_author_html_to (n, a_output)
|
||||||
|
|
||||||
-- Output the author of the post
|
-- Output the title of the post as a link (to the detail page)
|
||||||
Result.append (author_html(n))
|
append_title_html_to (n, page, a_output)
|
||||||
|
|
||||||
-- Output the title of the post as a link (to the detail page)
|
-- Output the summary of the post and a more link to the detail page
|
||||||
Result.append (title_html(n, page))
|
append_summary_html_to (n, page, a_output)
|
||||||
|
|
||||||
-- Output the summary of the post and a more link to the detail page
|
a_output.append ("</li>%N")
|
||||||
Result.append (summary_html(n, page))
|
|
||||||
|
|
||||||
Result.append ("</li>%N")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- End of post list
|
|
||||||
Result.append ("</ul>%N")
|
|
||||||
|
|
||||||
-- Pagination (older and newer links)
|
|
||||||
Result.append (pagination_html)
|
|
||||||
|
|
||||||
--end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- End of post list
|
||||||
|
a_output.append ("</ul>%N")
|
||||||
|
|
||||||
|
-- Pagination (older and newer links)
|
||||||
|
append_pagination_html_to (a_output)
|
||||||
end
|
end
|
||||||
|
|
||||||
page_title_html : STRING
|
append_page_title_html_to (a_output: STRING)
|
||||||
-- Returns the title of the page as a html string. It shows the current page number
|
-- Append the title of the page as a html string to `a_output'.
|
||||||
|
-- It shows the current page number.
|
||||||
do
|
do
|
||||||
create Result.make_from_string ("<h2>Blog")
|
a_output.append ("<h2>Blog")
|
||||||
if more_than_one_page then
|
if multiple_pages_needed then
|
||||||
Result.append (" (Page " + page_number.out + " of " + pages.out + ")")
|
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||||
end
|
end
|
||||||
Result.append ("</h2>")
|
a_output.append ("</h2>")
|
||||||
end
|
end
|
||||||
|
|
||||||
creation_date_html (n: CMS_NODE) : STRING
|
append_creation_date_html_to (n: CMS_NODE; a_output: STRING)
|
||||||
-- returns the creation date as a html string
|
-- Append the creation date as a html string to `a_output'.
|
||||||
local
|
local
|
||||||
hdate: HTTP_DATE
|
hdate: HTTP_DATE
|
||||||
do
|
do
|
||||||
Result := ""
|
|
||||||
if attached n.creation_date as l_modified then
|
if attached n.creation_date as l_modified then
|
||||||
create hdate.make_from_date_time (l_modified)
|
create hdate.make_from_date_time (l_modified)
|
||||||
Result.append (hdate.yyyy_mmm_dd_string)
|
hdate.append_to_yyyy_mmm_dd_string (a_output)
|
||||||
Result.append (" ")
|
a_output.append (" ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
author_html (n: CMS_NODE) : STRING
|
append_author_html_to (n: CMS_NODE; a_output: STRING)
|
||||||
-- returns a html string with a link to the autors posts
|
-- Append to `a_output', the author of node `n' as html link to author's posts.
|
||||||
do
|
do
|
||||||
Result := ""
|
|
||||||
if attached n.author as l_author then
|
if attached n.author as l_author then
|
||||||
Result.append ("by ")
|
a_output.append ("by ")
|
||||||
Result.append ("<a class=%"blog_user_link%" href=%"/blogs/user/" + l_author.id.out + "%">" + l_author.name + "</a>")
|
a_output.append ("<a class=%"blog_user_link%" href=%"/blogs/user/" + l_author.id.out + "%">" + l_author.name + "</a>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
title_html (n: CMS_NODE; page : CMS_RESPONSE) : STRING
|
append_title_html_to (n: CMS_NODE; page: CMS_RESPONSE; a_output: STRING)
|
||||||
-- returns a html string the title of the node that links on the detail page
|
-- Append to `a_output', the title of node `n' as html link to detail page.
|
||||||
local
|
local
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
lnk := node_api.node_link (n)
|
lnk := blog_api.node_api.node_link (n)
|
||||||
Result := "<span class=%"blog_title%">"
|
a_output.append ("<span class=%"blog_title%">")
|
||||||
Result.append (page.link (lnk.title, lnk.location, Void))
|
a_output.append (page.link (lnk.title, lnk.location, Void))
|
||||||
Result.append ("</span>")
|
a_output.append ("</span>")
|
||||||
end
|
end
|
||||||
|
|
||||||
summary_html (n: CMS_NODE; page : CMS_RESPONSE) : STRING
|
append_summary_html_to (n: CMS_NODE; page: CMS_RESPONSE; a_output: STRING)
|
||||||
-- returns a html string with the summary of the node and a link to the detail page
|
-- returns a html string with the summary of the node and a link to the detail page
|
||||||
local
|
local
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
Result := ""
|
|
||||||
lnk := node_api.node_link (n)
|
|
||||||
if attached n.summary as l_summary then
|
if attached n.summary as l_summary then
|
||||||
Result.append ("<p class=%"blog_list_summary%">")
|
lnk := blog_api.node_api.node_link (n)
|
||||||
|
a_output.append ("<p class=%"blog_list_summary%">")
|
||||||
if attached api.format (n.format) as f then
|
if attached api.format (n.format) as f then
|
||||||
Result.append (f.formatted_output (l_summary))
|
a_output.append (f.formatted_output (l_summary))
|
||||||
else
|
else
|
||||||
Result.append (page.formats.default_format.formatted_output (l_summary))
|
a_output.append (page.formats.default_format.formatted_output (l_summary))
|
||||||
end
|
end
|
||||||
Result.append ("<br />")
|
a_output.append ("<br />")
|
||||||
Result.append (page.link ("See more...", lnk.location, Void))
|
a_output.append (page.link ("See more...", lnk.location, Void))
|
||||||
Result.append ("</p>")
|
a_output.append ("</p>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pagination_html : STRING
|
append_pagination_html_to (a_output: STRING)
|
||||||
-- returns a html string with the pagination links (if necessary)
|
-- Append to `a_output' with the pagination links (if necessary).
|
||||||
local
|
local
|
||||||
tmp: NATURAL_32
|
tmp: NATURAL_32
|
||||||
do
|
do
|
||||||
Result := ""
|
if multiple_pages_needed then
|
||||||
if more_than_one_page then
|
a_output.append ("<div class=%"pagination%">")
|
||||||
|
|
||||||
Result.append ("<div class=%"pagination%">")
|
-- If exist older posts show link to next page
|
||||||
|
if page_number < pages_count then
|
||||||
-- If exist older posts show link to next page
|
|
||||||
if page_number < pages then
|
|
||||||
tmp := page_number + 1
|
tmp := page_number + 1
|
||||||
Result.append (" <a class=%"blog_older_posts%" href=%"" + base_path + "/page/" + tmp.out + "%"><< Older Posts</a> ")
|
a_output.append (" <a class=%"blog_older_posts%" href=%"" + base_path + "/page/" + tmp.out + "%"><< Older Posts</a> ")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delmiter
|
-- Delimiter
|
||||||
if page_number < pages AND page_number > 1 then
|
if page_number < pages_count AND page_number > 1 then
|
||||||
Result.append (" | ")
|
a_output.append (" | ")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If exist newer posts show link to previous page
|
-- If exist newer posts show link to previous page
|
||||||
if page_number > 1 then
|
if page_number > 1 then
|
||||||
tmp := page_number -1
|
tmp := page_number -1
|
||||||
Result.append (" <a class=%"blog_newer_posts%" href=%"" + base_path + "/page/" + tmp.out + "%">Newer Posts >></a> ")
|
a_output.append (" <a class=%"blog_newer_posts%" href=%"" + base_path + "/page/" + tmp.out + "%">Newer Posts >></a> ")
|
||||||
end
|
end
|
||||||
|
|
||||||
Result.append ("</div>")
|
a_output.append ("</div>")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
note
|
note
|
||||||
description: "Request handler related to /blogs/user/{id}/ or /blogs/user/{id}/page/{page}. Displays all posts of the given user"
|
description: "[
|
||||||
|
Request handler related to
|
||||||
|
/blogs/user/{id}/
|
||||||
|
or /blogs/user/{id}/page/{page}.
|
||||||
|
|
||||||
|
Displays all posts of the given user
|
||||||
|
]"
|
||||||
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
||||||
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
|
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
|
||||||
revision: "$Revision 96616$"
|
revision: "$Revision 96616$"
|
||||||
@@ -13,14 +19,13 @@ inherit
|
|||||||
do_get,
|
do_get,
|
||||||
posts,
|
posts,
|
||||||
total_entries,
|
total_entries,
|
||||||
page_title_html,
|
append_page_title_html_to,
|
||||||
base_path
|
base_path
|
||||||
end
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
|
|
||||||
feature -- Global Variables
|
feature -- Global Variables
|
||||||
|
|
||||||
user : detachable CMS_USER
|
user : detachable CMS_USER
|
||||||
@@ -30,71 +35,76 @@ feature -- HTTP Methods
|
|||||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_error: GENERIC_VIEW_CMS_RESPONSE
|
l_error: NOT_FOUND_ERROR_CMS_RESPONSE
|
||||||
do
|
do
|
||||||
-- Check if userID valid
|
user := Void
|
||||||
if user_valid (req) then
|
if attached user_from_request (req) as l_user then
|
||||||
user := load_user(req)
|
user := l_user
|
||||||
-- Output the results, similar as in the blog hanlder (but with other queries)
|
-- Output the results, similar as in the blog hanlder (but with other queries)
|
||||||
precursor(req, res)
|
Precursor (req, res)
|
||||||
else
|
else
|
||||||
-- Throw a bad request error because the user is not valid
|
-- Throw a bad request error because the user is not valid
|
||||||
create l_error.make (req, res, api)
|
create l_error.make (req, res, api)
|
||||||
l_error.set_main_content ("<h1>Error</h1>User with id " + user_path_parameter(req).out + " doesn't exist!")
|
l_error.set_main_content ("<h1>Error</h1>User with id " + user_id_path_parameter (req).out + " doesn't exist!")
|
||||||
l_error.execute
|
l_error.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Query
|
feature -- Query
|
||||||
|
|
||||||
user_valid (req: WSF_REQUEST) : BOOLEAN
|
user_valid (req: WSF_REQUEST) : BOOLEAN
|
||||||
-- Returns true if a valid user id is given and a user with this id exists; otherwise returns false.
|
-- Returns true if a valid user id is given and a user with this id exists,
|
||||||
|
-- otherwise returns false.
|
||||||
local
|
local
|
||||||
user_id: INTEGER_32
|
user_id: INTEGER_32
|
||||||
do
|
do
|
||||||
|
user_id := user_id_path_parameter (req)
|
||||||
user_id := user_path_parameter(req)
|
|
||||||
|
|
||||||
if user_id <= 0 then
|
if user_id <= 0 then
|
||||||
--Given user id is not valid
|
-- Given user id is not valid
|
||||||
Result := false
|
Result := False
|
||||||
else
|
else
|
||||||
--Check if user with user_id exists
|
--Check if user with user_id exists
|
||||||
Result := api.user_api.user_by_id (user_id) /= Void
|
Result := api.user_api.user_by_id (user_id) /= Void
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
load_user (req: WSF_REQUEST) : detachable CMS_USER
|
user_from_request (req: WSF_REQUEST): detachable CMS_USER
|
||||||
-- Returnes the user with the given id in the request req
|
-- Eventual user with given id in the path of request `req'.
|
||||||
require
|
local
|
||||||
user_valid(req)
|
uid: like user_id_path_parameter
|
||||||
do
|
do
|
||||||
Result := api.user_api.user_by_id (user_path_parameter(req))
|
uid := user_id_path_parameter (req)
|
||||||
|
if uid > 0 then
|
||||||
|
Result := api.user_api.user_by_id (uid)
|
||||||
|
else
|
||||||
|
-- Missing or invalid user id.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_path_parameter (req: WSF_REQUEST): INTEGER_32
|
user_id_path_parameter (req: WSF_REQUEST): INTEGER_32
|
||||||
-- Returns the user id from the path /blogs/{user}. It's an unsigned integer since negative ids are not allowed. If no valid id can be read it returns -1
|
-- User id from path /blogs/{user}.
|
||||||
|
-- Unsigned integer since negative ids are not allowed.
|
||||||
|
-- If no valid id can be read it returns -1
|
||||||
local
|
local
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
if attached {WSF_STRING} req.path_parameter ("user") as user_id then
|
Result := -1
|
||||||
s := user_id.value
|
if attached {WSF_STRING} req.path_parameter ("user") as l_user_id then
|
||||||
if s.is_integer_32 then
|
if l_user_id.is_integer then
|
||||||
if s.to_integer_32 > 0 then
|
Result := l_user_id.integer_value
|
||||||
Result := s.to_integer_32
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
posts : LIST[CMS_NODE]
|
posts: LIST [CMS_BLOG]
|
||||||
-- The posts to list on the given page. Filters out the posts of the current user
|
-- Blog posts to display on given page.
|
||||||
|
-- Filters out the posts of the current user.
|
||||||
do
|
do
|
||||||
if attached user as l_user then
|
if attached user as l_user then
|
||||||
Result := node_api.blogs_from_user_order_created_desc_limited (l_user.id.to_integer_32, entries_per_page, (page_number-1) * entries_per_page)
|
Result := blog_api.blogs_from_user_order_created_desc_limited (l_user, entries_per_page, entries_per_page * (page_number - 1))
|
||||||
else
|
else
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_BLOG]} Result.make (0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -102,33 +112,33 @@ feature -- Query
|
|||||||
-- Returns the number of total entries/posts of the current user
|
-- Returns the number of total entries/posts of the current user
|
||||||
do
|
do
|
||||||
if attached user as l_user then
|
if attached user as l_user then
|
||||||
Result := node_api.blogs_count_from_user(l_user.id).to_natural_32
|
Result := blog_api.blogs_count_from_user (l_user).to_natural_32
|
||||||
else
|
else
|
||||||
Result := precursor
|
Result := Precursor
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- HTML Output
|
feature -- HTML Output
|
||||||
|
|
||||||
page_title_html : STRING
|
append_page_title_html_to (a_output: STRING)
|
||||||
-- Returns the title of the page as a html string. It shows the current page number and the name of the current user
|
-- Returns the title of the page as a html string. It shows the current page number and the name of the current user
|
||||||
do
|
do
|
||||||
create Result.make_from_string ("<h2>Posts from ")
|
a_output.append ("<h2>Posts from ")
|
||||||
if attached user as l_user then
|
if attached user as l_user then
|
||||||
Result.append(l_user.name)
|
a_output.append (l_user.name)
|
||||||
else
|
else
|
||||||
Result.append ("unknown user")
|
a_output.append ("unknown user")
|
||||||
end
|
end
|
||||||
if more_than_one_page then
|
if multiple_pages_needed then
|
||||||
Result.append (" (Page " + page_number.out + " of " + pages.out + ")")
|
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||||
-- Get the posts from the current page (limited by entries per page)
|
-- Get the posts from the current page (limited by entries per page)
|
||||||
end
|
end
|
||||||
Result.append ("</h2>")
|
a_output.append ("</h2>")
|
||||||
end
|
end
|
||||||
|
|
||||||
base_path : STRING
|
base_path : STRING
|
||||||
-- the path to the page that lists all blogs. It must include the user id
|
-- Path to page listing all blogs.
|
||||||
|
-- If user is logged in, include user id
|
||||||
do
|
do
|
||||||
if attached user as l_user then
|
if attached user as l_user then
|
||||||
Result := "/blogs/user/" + l_user.id.out
|
Result := "/blogs/user/" + l_user.id.out
|
||||||
|
|||||||
@@ -10,7 +10,14 @@ deferred class
|
|||||||
inherit
|
inherit
|
||||||
CMS_MODULE_HANDLER [CMS_BLOG_API]
|
CMS_MODULE_HANDLER [CMS_BLOG_API]
|
||||||
rename
|
rename
|
||||||
module_api as node_api
|
module_api as blog_api
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
entries_per_page: NATURAL_32
|
||||||
|
do
|
||||||
|
Result := blog_api.entries_per_page
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_count_from_user (user_id: INTEGER_64) : INTEGER_64
|
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||||
-- Number of nodes of type blog from user with user_id
|
-- Number of nodes of type blog from `a_user'.
|
||||||
|
require
|
||||||
|
has_id: a_user.has_id
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,13 +28,15 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_limited (limit:NATURAL_32; offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_limited (limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||||
-- List of posts ordered by creation date from offset to offset + limit
|
-- List of posts ordered by creation date from offset to offset + limit.
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_from_user_limited (user_id: INTEGER_32; limit:NATURAL_32; offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_from_user_limited (a_user: CMS_USER; limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||||
-- List of posts from user_id ordered by creation date from offset to offset + limit
|
-- List of posts from `a_user' ordered by creation date from offset to offset + limit.
|
||||||
|
require
|
||||||
|
has_id: a_user.has_id
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -22,25 +22,25 @@ feature -- Access
|
|||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_count_from_user (user_id: INTEGER_64) : INTEGER_64
|
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||||
-- Number of nodes of type blog from user with user_id
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs: LIST[CMS_NODE]
|
blogs: LIST [CMS_NODE]
|
||||||
-- List of nodes.
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_limited (limit:NATURAL_32; offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_limited (limit: NATURAL_32; offset: NATURAL_32) : LIST [CMS_NODE]
|
||||||
-- List of posts ordered by creation date from offset to offset + limit
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_from_user_limited (user_id: INTEGER_32; limit:NATURAL_32; offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_from_user_limited (a_user: CMS_USER; limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||||
-- List of posts from user_id ordered by creation date from offset to offset + limit
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,25 +18,25 @@ create
|
|||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
blogs_count: INTEGER_64
|
blogs_count: INTEGER_64
|
||||||
-- Count of blog nodes
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".nodes_count")
|
write_information_log (generator + ".blogs_count")
|
||||||
sql_query (sql_select_blog_count, Void)
|
sql_query (sql_select_blog_count, Void)
|
||||||
if sql_rows_count = 1 then
|
if sql_rows_count = 1 then
|
||||||
Result := sql_read_integer_64 (1)
|
Result := sql_read_integer_64 (1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_count_from_user (user_id: INTEGER_64) : INTEGER_64
|
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||||
-- Number of nodes of type blog from user with user_id
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".nodes_count")
|
write_information_log (generator + ".blogs_count_from_user")
|
||||||
create l_parameters.make (2)
|
create l_parameters.make (2)
|
||||||
l_parameters.put (user_id, "user")
|
l_parameters.put (a_user.id, "user")
|
||||||
sql_query (sql_select_blog_count_from_user, l_parameters)
|
sql_query (sql_select_blog_count_from_user, l_parameters)
|
||||||
if sql_rows_count = 1 then
|
if sql_rows_count = 1 then
|
||||||
Result := sql_read_integer_64 (1)
|
Result := sql_read_integer_64 (1)
|
||||||
@@ -44,12 +44,12 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
|
|
||||||
blogs: LIST [CMS_NODE]
|
blogs: LIST [CMS_NODE]
|
||||||
-- List of nodes ordered by creation date (descending).
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".nodes")
|
write_information_log (generator + ".blogs")
|
||||||
|
|
||||||
from
|
from
|
||||||
sql_query (sql_select_blogs_order_created_desc, Void)
|
sql_query (sql_select_blogs_order_created_desc, Void)
|
||||||
@@ -64,15 +64,15 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_limited (a_limit:NATURAL_32; a_offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_limited (a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||||
-- List of nodes ordered by creation date from limit to limit + offset
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".nodes")
|
write_information_log (generator + ".blogs_limited")
|
||||||
|
|
||||||
from
|
from
|
||||||
create l_parameters.make (2)
|
create l_parameters.make (2)
|
||||||
@@ -90,21 +90,21 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
blogs_from_user_limited (a_user_id:INTEGER_32; a_limit:NATURAL_32; a_offset:NATURAL_32) : LIST[CMS_NODE]
|
blogs_from_user_limited (a_user: CMS_USER; a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||||
-- List of posts of the author with a_user_id ordered by creation date starting at offset and limited by limit
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".nodes")
|
write_information_log (generator + ".blogs_from_user_limited")
|
||||||
|
|
||||||
from
|
from
|
||||||
create l_parameters.make (2)
|
create l_parameters.make (2)
|
||||||
l_parameters.put (a_limit, "limit")
|
l_parameters.put (a_limit, "limit")
|
||||||
l_parameters.put (a_offset, "offset")
|
l_parameters.put (a_offset, "offset")
|
||||||
l_parameters.put (a_user_id, "user")
|
l_parameters.put (a_user.id, "user")
|
||||||
sql_query (sql_blogs_from_user_limited, l_parameters)
|
sql_query (sql_blogs_from_user_limited, l_parameters)
|
||||||
sql_start
|
sql_start
|
||||||
until
|
until
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ feature -- Access: Node
|
|||||||
Result := node_storage.nodes
|
Result := node_storage.nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
|
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
|
||||||
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ feature {NONE} -- Initialization
|
|||||||
default_create
|
default_create
|
||||||
do
|
do
|
||||||
Precursor
|
Precursor
|
||||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (3)
|
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||||
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||||
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||||
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
||||||
|
available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT})
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ feature -- Forms ...
|
|||||||
ta, sum: CMS_FORM_TEXTAREA
|
ta, sum: CMS_FORM_TEXTAREA
|
||||||
tselect: WSF_FORM_SELECT
|
tselect: WSF_FORM_SELECT
|
||||||
opt: WSF_FORM_SELECT_OPTION
|
opt: WSF_FORM_SELECT_OPTION
|
||||||
full_format: FULL_HTML_CONTENT_FORMAT
|
cms_format: CMS_EDITOR_CONTENT_FORMAT
|
||||||
do
|
do
|
||||||
|
create cms_format
|
||||||
|
|
||||||
create ti.make ("title")
|
create ti.make ("title")
|
||||||
ti.set_label ("Title")
|
ti.set_label ("Title")
|
||||||
ti.set_size (70)
|
ti.set_size (70)
|
||||||
@@ -31,18 +33,16 @@ feature -- Forms ...
|
|||||||
|
|
||||||
f.extend_html_text ("<br/>")
|
f.extend_html_text ("<br/>")
|
||||||
|
|
||||||
-- Select field has to be initialized before textareas are replaced, because they depend on the selection of the field
|
-- Select field has to be initialized before textareas are replaced, because they depend on the selection of the field
|
||||||
create tselect.make ("format")
|
create tselect.make ("format")
|
||||||
tselect.set_label ("Body's format")
|
tselect.set_label ("Body's format")
|
||||||
tselect.set_is_required (True)
|
tselect.set_is_required (True)
|
||||||
|
|
||||||
|
-- Main Content
|
||||||
create full_format.default_create
|
|
||||||
-- Main Content
|
|
||||||
create ta.make ("body")
|
create ta.make ("body")
|
||||||
ta.set_rows (10)
|
ta.set_rows (10)
|
||||||
ta.set_cols (70)
|
ta.set_cols (70)
|
||||||
ta.show_as_editor_if_selected (tselect, full_format.name)
|
ta.show_as_editor_if_selected (tselect, cms_format.name)
|
||||||
if a_node /= Void then
|
if a_node /= Void then
|
||||||
ta.set_text_value (a_node.content)
|
ta.set_text_value (a_node.content)
|
||||||
end
|
end
|
||||||
@@ -50,12 +50,12 @@ feature -- Forms ...
|
|||||||
ta.set_description ("This is the main content")
|
ta.set_description ("This is the main content")
|
||||||
ta.set_is_required (False)
|
ta.set_is_required (False)
|
||||||
|
|
||||||
-- Summary
|
-- Summary
|
||||||
create sum.make ("summary")
|
create sum.make ("summary")
|
||||||
sum.set_rows (10)
|
sum.set_rows (3)
|
||||||
sum.set_cols (70)
|
sum.set_cols (70)
|
||||||
-- if full_html is selected
|
-- if cms_html is selected
|
||||||
sum.show_as_editor_if_selected (tselect, full_format.name)
|
sum.show_as_editor_if_selected (tselect, cms_format.name)
|
||||||
if a_node /= Void then
|
if a_node /= Void then
|
||||||
sum.set_text_value (a_node.summary)
|
sum.set_text_value (a_node.summary)
|
||||||
end
|
end
|
||||||
@@ -66,15 +66,14 @@ feature -- Forms ...
|
|||||||
create fset.make
|
create fset.make
|
||||||
fset.set_legend ("Body")
|
fset.set_legend ("Body")
|
||||||
|
|
||||||
-- Add summary
|
-- Add summary
|
||||||
fset.extend (sum)
|
fset.extend (sum)
|
||||||
fset.extend_html_text("<br />")
|
fset.extend_html_text("<br />")
|
||||||
|
|
||||||
-- Add content (body)
|
-- Add content (body)
|
||||||
fset.extend (ta)
|
fset.extend (ta)
|
||||||
fset.extend_html_text ("<br/>")
|
fset.extend_html_text ("<br/>")
|
||||||
|
|
||||||
|
|
||||||
across
|
across
|
||||||
content_type.available_formats as c
|
content_type.available_formats as c
|
||||||
loop
|
loop
|
||||||
@@ -92,7 +91,7 @@ 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)
|
||||||
|
|||||||
31
src/kernel/content/format/cms_editor_content_format.e
Normal file
31
src/kernel/content/format/cms_editor_content_format.e
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
note
|
||||||
|
description: "HTML Content format editable with WYSIWYG editor."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
CMS_EDITOR_CONTENT_FORMAT
|
||||||
|
|
||||||
|
inherit
|
||||||
|
CONTENT_FORMAT
|
||||||
|
redefine
|
||||||
|
default_create
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
default_create
|
||||||
|
do
|
||||||
|
Precursor
|
||||||
|
create filters.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
name: STRING = "cms_editor"
|
||||||
|
|
||||||
|
title: STRING_8 = "CMS HTML content"
|
||||||
|
|
||||||
|
filters: ARRAYED_LIST [CONTENT_FILTER]
|
||||||
|
|
||||||
|
end
|
||||||
@@ -27,10 +27,11 @@ feature -- Access
|
|||||||
once
|
once
|
||||||
-- Can we provide an external file to read the
|
-- Can we provide an external file to read the
|
||||||
-- supported formats?
|
-- supported formats?
|
||||||
create {ARRAYED_LIST [CONTENT_FORMAT]} Result.make (3)
|
create {ARRAYED_LIST [CONTENT_FORMAT]} Result.make (4)
|
||||||
Result.force (plain_text)
|
Result.force (plain_text)
|
||||||
Result.force (full_html)
|
Result.force (full_html)
|
||||||
Result.force (filtered_html)
|
Result.force (filtered_html)
|
||||||
|
Result.force (cms_html)
|
||||||
end
|
end
|
||||||
|
|
||||||
default_format: CONTENT_FORMAT
|
default_format: CONTENT_FORMAT
|
||||||
@@ -43,6 +44,11 @@ feature -- Access
|
|||||||
create Result
|
create Result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cms_html: CMS_EDITOR_CONTENT_FORMAT
|
||||||
|
once
|
||||||
|
create Result
|
||||||
|
end
|
||||||
|
|
||||||
full_html: FULL_HTML_CONTENT_FORMAT
|
full_html: FULL_HTML_CONTENT_FORMAT
|
||||||
once
|
once
|
||||||
create Result
|
create Result
|
||||||
@@ -53,7 +59,6 @@ feature -- Access
|
|||||||
create Result
|
create Result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ feature -- Javascript
|
|||||||
|
|
||||||
javascript_textarea_to_editor(a_textarea : WSF_FORM_TEXTAREA) : STRING
|
javascript_textarea_to_editor(a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||||
-- Javascript code to display the textarea as a WYSIWIG editor as soon as the document is loaded
|
-- Javascript code to display the textarea as a WYSIWIG editor as soon as the document is loaded
|
||||||
local
|
|
||||||
l_code : STRING
|
|
||||||
do
|
do
|
||||||
Result := javascript_ready(javascript_replace_textarea (a_textarea))
|
Result := javascript_ready(javascript_replace_textarea (a_textarea))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,22 +21,22 @@ create
|
|||||||
|
|
||||||
feature -- Initialisation
|
feature -- Initialisation
|
||||||
|
|
||||||
make (a_name: like name)
|
make (a_name: like name)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
precursor(a_name)
|
precursor(a_name)
|
||||||
|
|
||||||
-- By default we don't replace the textarea by an editor
|
-- By default we don't replace the textarea by an editor
|
||||||
editor := False;
|
editor := False;
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
editor : BOOLEAN
|
editor : BOOLEAN
|
||||||
-- True if the textarea should be replaced by the editor. Default is false.
|
-- True if the textarea should be replaced by the editor. Default is false.
|
||||||
|
|
||||||
format_field : detachable WSF_FORM_SELECT
|
format_field : detachable WSF_FORM_SELECT
|
||||||
-- Selection field for the format on that it depends, if the editor is shown or not.
|
-- Selection field for the format on that it depends, if the editor is shown or not.
|
||||||
|
|
||||||
condition_value : detachable STRING
|
condition_value : detachable STRING
|
||||||
|
|
||||||
@@ -58,7 +58,6 @@ feature -- Editor
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
|
|
||||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||||
do
|
do
|
||||||
-- Add javascript to replace textarea with editor
|
-- Add javascript to replace textarea with editor
|
||||||
@@ -67,16 +66,12 @@ feature -- Conversion
|
|||||||
a_html.append (load_assets)
|
a_html.append (load_assets)
|
||||||
a_html.append ("<script type=%"text/javascript%">");
|
a_html.append ("<script type=%"text/javascript%">");
|
||||||
if attached format_field as l_field and then attached condition_value as l_value then
|
if attached format_field as l_field and then attached condition_value as l_value then
|
||||||
a_html.append (javascript_textarea_to_editor_if_selected(current, l_field, l_value))
|
a_html.append (javascript_textarea_to_editor_if_selected (Current, l_field, l_value))
|
||||||
else
|
else
|
||||||
a_html.append (javascript_textarea_to_editor(current))
|
a_html.append (javascript_textarea_to_editor (Current))
|
||||||
end
|
end
|
||||||
a_html.append ("</script>")
|
a_html.append ("</script>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Javascript Output
|
|
||||||
|
|
||||||
javascript_show_editor_on_full_html_select : STRING = ""
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -185,8 +185,10 @@ feature -- Query: module
|
|||||||
module_api (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE_API
|
module_api (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE_API
|
||||||
-- Enabled module API associated with module typed `a_type'.
|
-- Enabled module API associated with module typed `a_type'.
|
||||||
do
|
do
|
||||||
if attached module (a_type) as mod then
|
if attached {CMS_MODULE} module (a_type) as mod then
|
||||||
Result := mod.module_api
|
if mod.is_enabled then
|
||||||
|
Result := mod.module_api
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,19 @@ feature {CMS_API} -- Module Initialization
|
|||||||
-- Initialize Current module with `api'.
|
-- Initialize Current module with `api'.
|
||||||
require
|
require
|
||||||
is_enabled: is_enabled
|
is_enabled: is_enabled
|
||||||
|
is_not_initialized: not is_initialized
|
||||||
do
|
do
|
||||||
-- Redefine to process specific module initialization.
|
-- Redefine to process specific module initialization.
|
||||||
|
is_initialized := True
|
||||||
|
ensure
|
||||||
|
is_initialized: is_initialized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Status
|
||||||
|
|
||||||
|
is_initialized: BOOLEAN
|
||||||
|
-- Is Current module initialized?
|
||||||
|
|
||||||
feature {CMS_API} -- Access: API
|
feature {CMS_API} -- Access: API
|
||||||
|
|
||||||
module_api: detachable CMS_MODULE_API
|
module_api: detachable CMS_MODULE_API
|
||||||
@@ -68,6 +77,8 @@ feature -- Router
|
|||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
-- Setup url dispatching for Current module.
|
-- Setup url dispatching for Current module.
|
||||||
|
require
|
||||||
|
is_initialized: is_initialized
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user