Compare commits
4 Commits
blog
...
javier_roc
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fa29340b2 | |||
|
|
b1988d5fe7 | ||
|
|
e767e1bc47 | ||
|
|
c2d0fbf445 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,6 +2,4 @@ EIFGENs
|
||||
*.swp
|
||||
*.log*
|
||||
*.rc
|
||||
*.bak
|
||||
*.sqlite
|
||||
Thumbs.db
|
||||
*.bak
|
||||
@@ -19,7 +19,6 @@
|
||||
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf" readonly="false"/>
|
||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
|
||||
<library name="smarty" location="$ISE_LIBRARY\contrib\library\text\template\smarty\smarty-safe.ecf" readonly="false"/>
|
||||
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
|
||||
|
||||
1
cms.ecf
1
cms.ecf
@@ -17,7 +17,6 @@
|
||||
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf" readonly="false"/>
|
||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf" readonly="false"/>
|
||||
<library name="cms_app_env" location=".\library\app_env\app_env.ecf"/>
|
||||
<library name="cms_model" location=".\library\model\cms_model.ecf" readonly="false"/>
|
||||
|
||||
@@ -31,13 +31,7 @@ feature -- Conversion
|
||||
do
|
||||
Precursor (a_node)
|
||||
if attached {CMS_BLOG} a_node as l_blog then
|
||||
if attached l_blog.tags as l_tags then
|
||||
across
|
||||
l_tags as ic
|
||||
loop
|
||||
add_tag (ic.item)
|
||||
end
|
||||
end
|
||||
-- l_blog
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,7 +42,7 @@ feature -- Access
|
||||
Result := {CMS_BLOG_NODE_TYPE}.name
|
||||
end
|
||||
|
||||
feature -- Access: node
|
||||
feature -- Access: content
|
||||
|
||||
summary: detachable READABLE_STRING_8
|
||||
-- A short summary of the node.
|
||||
@@ -60,12 +54,10 @@ feature -- Access: node
|
||||
-- Format associated with `content' and `summary'.
|
||||
-- For example: text, mediawiki, html, etc
|
||||
|
||||
feature -- Access: blog
|
||||
|
||||
tags: detachable ARRAYED_LIST [READABLE_STRING_32]
|
||||
-- Optional tags
|
||||
|
||||
feature -- Element change: node
|
||||
feature -- Element change
|
||||
|
||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||
do
|
||||
@@ -74,8 +66,6 @@ feature -- Element change: node
|
||||
format := a_format
|
||||
end
|
||||
|
||||
feature -- Element change: blog
|
||||
|
||||
add_tag (a_tag: READABLE_STRING_32)
|
||||
-- Set `parent' to `a_page'
|
||||
require
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
note
|
||||
description: "API to handle nodes of type blog. Extends the node API."
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch"
|
||||
date: "$Date: 2015-05-21 14:46:00 +0100$"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_BLOG_API
|
||||
|
||||
inherit
|
||||
CMS_MODULE_API
|
||||
rename
|
||||
make as make_with_cms_api
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
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
|
||||
-- <Precursor>
|
||||
do
|
||||
Precursor
|
||||
|
||||
-- Create the node storage for type blog
|
||||
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
|
||||
create {CMS_BLOG_STORAGE_SQL} blog_storage.make (l_storage_sql)
|
||||
else
|
||||
create {CMS_BLOG_STORAGE_NULL} blog_storage.make
|
||||
end
|
||||
-- initialize_node_types
|
||||
end
|
||||
|
||||
feature {CMS_API_ACCESS, CMS_MODULE, CMS_API} -- Restricted access
|
||||
|
||||
node_api: CMS_NODE_API
|
||||
|
||||
feature {CMS_MODULE} -- Access nodes storage.
|
||||
|
||||
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
|
||||
|
||||
blogs_count: INTEGER_64
|
||||
-- Number of nodes of type blog.
|
||||
do
|
||||
Result := blog_storage.blogs_count
|
||||
end
|
||||
|
||||
blogs_count_from_user (a_user: CMS_USER): INTEGER_64
|
||||
-- Number of nodes of type blog from user with `a_user_id'.
|
||||
require
|
||||
has_id: a_user.has_id
|
||||
do
|
||||
Result := blog_storage.blogs_count_from_user (a_user)
|
||||
end
|
||||
|
||||
blogs_order_created_desc: LIST [CMS_BLOG]
|
||||
-- List of nodes ordered by creation date (descending)
|
||||
do
|
||||
Result := nodes_to_blogs (blog_storage.blogs)
|
||||
end
|
||||
|
||||
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
|
||||
do
|
||||
-- load all posts and add the authors to each post
|
||||
Result := nodes_to_blogs (blog_storage.blogs_limited (a_limit, a_offset))
|
||||
end
|
||||
|
||||
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
|
||||
require
|
||||
has_id: a_user.has_id
|
||||
do
|
||||
-- load all posts and add the authors to each post
|
||||
Result := nodes_to_blogs (blog_storage.blogs_from_user_limited (a_user, a_limit, a_offset))
|
||||
end
|
||||
|
||||
feature {NONE} -- Helpers
|
||||
|
||||
nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG]
|
||||
-- Convert list of nodes into a list of blog when possible.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_BLOG]} Result.make (a_nodes.count)
|
||||
|
||||
if attached node_api as l_node_api then
|
||||
across
|
||||
a_nodes as ic
|
||||
loop
|
||||
if attached {CMS_BLOG} l_node_api.full_node (ic.item) as l_blog then
|
||||
Result.force (l_blog)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -20,7 +20,6 @@
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf"/>
|
||||
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
|
||||
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
note
|
||||
description: "Displays all posts (pages with type blog). It's possible to list posts by user."
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
||||
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
|
||||
revision: "$Revision 96616$"
|
||||
description: "Summary description for {CMS_BLOG_MODULE}."
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_BLOG_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
rename
|
||||
module_api as blog_api
|
||||
redefine
|
||||
register_hooks,
|
||||
initialize,
|
||||
is_installed,
|
||||
install,
|
||||
blog_api
|
||||
install
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||
@@ -44,10 +40,6 @@ feature {CMS_API} -- Module Initialization
|
||||
Precursor (api)
|
||||
|
||||
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
|
||||
l_node_api.add_content_type (ct)
|
||||
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
@@ -90,53 +82,13 @@ CREATE TABLE "blog_post_nodes"(
|
||||
end
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Access: API
|
||||
|
||||
blog_api: detachable CMS_BLOG_API
|
||||
-- <Precursor>
|
||||
|
||||
node_api: detachable CMS_NODE_API
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
if attached blog_api as l_blog_api then
|
||||
configure_web (a_api, l_blog_api, a_router)
|
||||
else
|
||||
-- Issue with api/dependencies,
|
||||
-- thus Current module should not be used!
|
||||
-- thus no url mapping
|
||||
end
|
||||
end
|
||||
|
||||
configure_web (a_api: CMS_API; a_blog_api: CMS_BLOG_API; a_router: WSF_ROUTER)
|
||||
-- Configure router mapping for web interface.
|
||||
local
|
||||
l_blog_handler: BLOG_HANDLER
|
||||
l_blog_user_handler: BLOG_USER_HANDLER
|
||||
l_uri_mapping: WSF_URI_MAPPING
|
||||
do
|
||||
-- TODO: for now, focused only on web interface, add REST api later. [2015-May-18]
|
||||
create l_blog_handler.make (a_api, a_blog_api)
|
||||
create l_blog_user_handler.make (a_api, a_blog_api)
|
||||
|
||||
-- Let the class BLOG_HANDLER handle the requests on "/blogs"
|
||||
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)
|
||||
|
||||
-- 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)
|
||||
|
||||
-- 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)
|
||||
|
||||
-- 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)
|
||||
|
||||
create Result.make (1)
|
||||
Result.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), Result.methods_get)
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
@@ -150,8 +102,19 @@ feature -- Hooks
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
-- Add the link to the blog to the main menu
|
||||
create lnk.make ("Blogs", "/blogs/")
|
||||
a_menu_system.primary_menu.extend (lnk)
|
||||
end
|
||||
|
||||
feature -- Handler
|
||||
|
||||
handle_blogs (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API)
|
||||
local
|
||||
r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
|
||||
do
|
||||
create r.make (req, res, a_api)
|
||||
r.set_main_content ("Blog module is in development ...")
|
||||
r.execute
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -17,11 +17,10 @@ feature {NONE} -- Initialization
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (3)
|
||||
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
|
||||
|
||||
@@ -1,279 +0,0 @@
|
||||
note
|
||||
description: "Request handler related to /blogs and /blogs/{page}. Displays all posts in the blog."
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
||||
date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $"
|
||||
revision: "$9661667$"
|
||||
|
||||
class
|
||||
BLOG_HANDLER
|
||||
|
||||
inherit
|
||||
CMS_BLOG_HANDLER
|
||||
|
||||
WSF_URI_HANDLER
|
||||
rename
|
||||
execute as uri_execute,
|
||||
new_mapping as new_uri_mapping
|
||||
end
|
||||
|
||||
WSF_URI_TEMPLATE_HANDLER
|
||||
rename
|
||||
execute as uri_template_execute,
|
||||
new_mapping as new_uri_template_mapping
|
||||
select
|
||||
new_uri_template_mapping
|
||||
end
|
||||
|
||||
WSF_RESOURCE_HANDLER_HELPER
|
||||
redefine
|
||||
do_get
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
CMS_API_ACCESS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- execute
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler for any kind of mapping.
|
||||
do
|
||||
execute_methods (req, res)
|
||||
end
|
||||
|
||||
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler for URI mapping.
|
||||
do
|
||||
execute (req, res)
|
||||
end
|
||||
|
||||
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler for URI-template mapping.
|
||||
do
|
||||
execute (req, res)
|
||||
end
|
||||
|
||||
feature -- Global Variables
|
||||
|
||||
page_number: NATURAL_32
|
||||
-- Current page number.
|
||||
|
||||
feature -- HTTP Methods
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
-- Read page number from path parameter.
|
||||
page_number := page_number_path_parameter (req)
|
||||
|
||||
-- Responding with `main_content_html (l_page)'.
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.set_main_content (main_content_html (l_page))
|
||||
l_page.execute
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
posts: LIST [CMS_NODE]
|
||||
-- Blog posts to display on given page ordered by date (descending).
|
||||
do
|
||||
Result := blog_api.blogs_order_created_desc_limited (
|
||||
entries_per_page,
|
||||
entries_per_page * (page_number - 1)
|
||||
)
|
||||
end
|
||||
|
||||
multiple_pages_needed : BOOLEAN
|
||||
-- Return if more that one page is needed to display posts.
|
||||
do
|
||||
Result := entries_per_page < total_entries
|
||||
end
|
||||
|
||||
pages_count: NATURAL_32
|
||||
-- Number of pages needed to display all posts.
|
||||
require
|
||||
entries_per_page > 0
|
||||
local
|
||||
tmp: REAL_32
|
||||
do
|
||||
tmp := total_entries.to_real_32 / entries_per_page.to_real_32;
|
||||
Result := tmp.ceiling.to_natural_32
|
||||
end
|
||||
|
||||
page_number_path_parameter (req: WSF_REQUEST): NATURAL_32
|
||||
-- Page number from path /blogs/{page}.
|
||||
-- Unsigned integer since negative pages are not allowed.
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
Result := 1 -- default if not get variable is set
|
||||
if attached {WSF_STRING} req.path_parameter ("page") as p_page then
|
||||
s := p_page.value
|
||||
if s.is_natural_32 then
|
||||
if s.to_natural_32 > 1 then
|
||||
Result := s.to_natural_32
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
total_entries: NATURAL_32
|
||||
-- Total number of entries/posts.
|
||||
do
|
||||
Result := blog_api.blogs_count.to_natural_32
|
||||
end
|
||||
|
||||
feature -- HTML Output
|
||||
|
||||
frozen main_content_html (page: CMS_RESPONSE): 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
|
||||
n: CMS_NODE
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
-- Output the title. If more than one page, also output the current page number
|
||||
append_page_title_html_to (a_output)
|
||||
|
||||
-- Get the posts from the current page (given by page number and entries per page)
|
||||
-- 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 +"%">")
|
||||
|
||||
-- Output the creation date
|
||||
append_creation_date_html_to (n, a_output)
|
||||
|
||||
-- Output the author of the post
|
||||
append_author_html_to (n, a_output)
|
||||
|
||||
-- Output the title of the post as a link (to the detail page)
|
||||
append_title_html_to (n, page, a_output)
|
||||
|
||||
-- Output the summary of the post and a more link to the detail page
|
||||
append_summary_html_to (n, page, a_output)
|
||||
|
||||
a_output.append ("</li>%N")
|
||||
end
|
||||
|
||||
-- End of post list
|
||||
a_output.append ("</ul>%N")
|
||||
|
||||
-- Pagination (older and newer links)
|
||||
append_pagination_html_to (a_output)
|
||||
end
|
||||
|
||||
append_page_title_html_to (a_output: STRING)
|
||||
-- Append the title of the page as a html string to `a_output'.
|
||||
-- It shows the current page number.
|
||||
do
|
||||
a_output.append ("<h2>Blog")
|
||||
if multiple_pages_needed then
|
||||
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
end
|
||||
a_output.append ("</h2>")
|
||||
end
|
||||
|
||||
append_creation_date_html_to (n: CMS_NODE; a_output: STRING)
|
||||
-- Append the creation date as a html string to `a_output'.
|
||||
local
|
||||
hdate: HTTP_DATE
|
||||
do
|
||||
if attached n.creation_date as l_modified then
|
||||
create hdate.make_from_date_time (l_modified)
|
||||
hdate.append_to_yyyy_mmm_dd_string (a_output)
|
||||
a_output.append (" ")
|
||||
end
|
||||
end
|
||||
|
||||
append_author_html_to (n: CMS_NODE; a_output: STRING)
|
||||
-- Append to `a_output', the author of node `n' as html link to author's posts.
|
||||
do
|
||||
if attached n.author as l_author then
|
||||
a_output.append ("by ")
|
||||
a_output.append ("<a class=%"blog_user_link%" href=%"/blogs/user/" + l_author.id.out + "%">" + l_author.name + "</a>")
|
||||
end
|
||||
end
|
||||
|
||||
append_title_html_to (n: CMS_NODE; page: CMS_RESPONSE; a_output: STRING)
|
||||
-- Append to `a_output', the title of node `n' as html link to detail page.
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
lnk := blog_api.node_api.node_link (n)
|
||||
a_output.append ("<span class=%"blog_title%">")
|
||||
a_output.append (page.link (lnk.title, lnk.location, Void))
|
||||
a_output.append ("</span>")
|
||||
end
|
||||
|
||||
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
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
if attached n.summary as l_summary then
|
||||
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
|
||||
a_output.append (f.formatted_output (l_summary))
|
||||
else
|
||||
a_output.append (page.formats.default_format.formatted_output (l_summary))
|
||||
end
|
||||
a_output.append ("<br />")
|
||||
a_output.append (page.link ("See more...", lnk.location, Void))
|
||||
a_output.append ("</p>")
|
||||
end
|
||||
end
|
||||
|
||||
append_pagination_html_to (a_output: STRING)
|
||||
-- Append to `a_output' with the pagination links (if necessary).
|
||||
local
|
||||
tmp: NATURAL_32
|
||||
do
|
||||
if multiple_pages_needed then
|
||||
a_output.append ("<div class=%"pagination%">")
|
||||
|
||||
-- If exist older posts show link to next page
|
||||
if page_number < pages_count then
|
||||
tmp := page_number + 1
|
||||
a_output.append (" <a class=%"blog_older_posts%" href=%"" + base_path + "/page/" + tmp.out + "%"><< Older Posts</a> ")
|
||||
end
|
||||
|
||||
-- Delimiter
|
||||
if page_number < pages_count AND page_number > 1 then
|
||||
a_output.append (" | ")
|
||||
end
|
||||
|
||||
-- If exist newer posts show link to previous page
|
||||
if page_number > 1 then
|
||||
tmp := page_number -1
|
||||
a_output.append (" <a class=%"blog_newer_posts%" href=%"" + base_path + "/page/" + tmp.out + "%">Newer Posts >></a> ")
|
||||
end
|
||||
|
||||
a_output.append ("</div>")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
base_path : STRING
|
||||
-- the path to the page that lists all blogs
|
||||
do
|
||||
Result := "/blogs"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,150 +0,0 @@
|
||||
note
|
||||
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>"
|
||||
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
|
||||
revision: "$Revision 96616$"
|
||||
|
||||
class
|
||||
BLOG_USER_HANDLER
|
||||
|
||||
inherit
|
||||
BLOG_HANDLER
|
||||
redefine
|
||||
do_get,
|
||||
posts,
|
||||
total_entries,
|
||||
append_page_title_html_to,
|
||||
base_path
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Global Variables
|
||||
|
||||
user : detachable CMS_USER
|
||||
|
||||
feature -- HTTP Methods
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_error: NOT_FOUND_ERROR_CMS_RESPONSE
|
||||
do
|
||||
user := Void
|
||||
if attached user_from_request (req) as l_user then
|
||||
user := l_user
|
||||
-- Output the results, similar as in the blog hanlder (but with other queries)
|
||||
Precursor (req, res)
|
||||
else
|
||||
-- Throw a bad request error because the user is not valid
|
||||
create l_error.make (req, res, api)
|
||||
l_error.set_main_content ("<h1>Error</h1>User with id " + user_id_path_parameter (req).out + " doesn't exist!")
|
||||
l_error.execute
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
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.
|
||||
local
|
||||
user_id: INTEGER_32
|
||||
do
|
||||
user_id := user_id_path_parameter (req)
|
||||
|
||||
if user_id <= 0 then
|
||||
-- Given user id is not valid
|
||||
Result := False
|
||||
else
|
||||
--Check if user with user_id exists
|
||||
Result := api.user_api.user_by_id (user_id) /= Void
|
||||
end
|
||||
end
|
||||
|
||||
user_from_request (req: WSF_REQUEST): detachable CMS_USER
|
||||
-- Eventual user with given id in the path of request `req'.
|
||||
local
|
||||
uid: like user_id_path_parameter
|
||||
do
|
||||
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
|
||||
|
||||
user_id_path_parameter (req: WSF_REQUEST): INTEGER_32
|
||||
-- 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
|
||||
s: STRING
|
||||
do
|
||||
Result := -1
|
||||
if attached {WSF_STRING} req.path_parameter ("user") as l_user_id then
|
||||
if l_user_id.is_integer then
|
||||
Result := l_user_id.integer_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
posts: LIST [CMS_BLOG]
|
||||
-- Blog posts to display on given page.
|
||||
-- Filters out the posts of the current user.
|
||||
do
|
||||
if attached user as l_user then
|
||||
Result := blog_api.blogs_from_user_order_created_desc_limited (l_user, entries_per_page, entries_per_page * (page_number - 1))
|
||||
else
|
||||
create {ARRAYED_LIST [CMS_BLOG]} Result.make (0)
|
||||
end
|
||||
end
|
||||
|
||||
total_entries : NATURAL_32
|
||||
-- Returns the number of total entries/posts of the current user
|
||||
do
|
||||
if attached user as l_user then
|
||||
Result := blog_api.blogs_count_from_user (l_user).to_natural_32
|
||||
else
|
||||
Result := Precursor
|
||||
end
|
||||
end
|
||||
|
||||
feature -- HTML Output
|
||||
|
||||
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
|
||||
do
|
||||
a_output.append ("<h2>Posts from ")
|
||||
if attached user as l_user then
|
||||
a_output.append (l_user.name)
|
||||
else
|
||||
a_output.append ("unknown user")
|
||||
end
|
||||
if multiple_pages_needed then
|
||||
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
-- Get the posts from the current page (limited by entries per page)
|
||||
end
|
||||
a_output.append ("</h2>")
|
||||
end
|
||||
|
||||
base_path : STRING
|
||||
-- Path to page listing all blogs.
|
||||
-- If user is logged in, include user id
|
||||
do
|
||||
if attached user as l_user then
|
||||
Result := "/blogs/user/" + l_user.id.out
|
||||
else
|
||||
Result := precursor
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
note
|
||||
description: "Deferred request handler related to /blogs/... Has an own blog api."
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
||||
date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $"
|
||||
revision: "$9661667$"
|
||||
|
||||
deferred class
|
||||
CMS_BLOG_HANDLER
|
||||
|
||||
inherit
|
||||
CMS_MODULE_HANDLER [CMS_BLOG_API]
|
||||
rename
|
||||
module_api as blog_api
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
entries_per_page: NATURAL_32
|
||||
do
|
||||
Result := blog_api.entries_per_page
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
note
|
||||
description: "Interface for accessing blog contents from the database."
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
revision: "$Revision: 96542 $"
|
||||
|
||||
deferred class
|
||||
CMS_BLOG_STORAGE_I
|
||||
|
||||
inherit
|
||||
CMS_NODE_STORAGE_I
|
||||
|
||||
feature -- Access
|
||||
|
||||
blogs_count: INTEGER_64
|
||||
-- Count of blog nodes
|
||||
deferred
|
||||
end
|
||||
|
||||
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||
-- Number of nodes of type blog from `a_user'.
|
||||
require
|
||||
has_id: a_user.has_id
|
||||
deferred
|
||||
end
|
||||
|
||||
blogs: LIST [CMS_NODE]
|
||||
-- List of nodes ordered by creation date (descending).
|
||||
deferred
|
||||
end
|
||||
|
||||
blogs_limited (limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- List of posts ordered by creation date from offset to offset + limit.
|
||||
deferred
|
||||
end
|
||||
|
||||
blogs_from_user_limited (a_user: CMS_USER; limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- List of posts from `a_user' ordered by creation date from offset to offset + limit.
|
||||
require
|
||||
has_id: a_user.has_id
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {CMS_BLOG_STORAGE_NULL}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_BLOG_STORAGE_NULL
|
||||
|
||||
inherit
|
||||
CMS_NODE_STORAGE_NULL
|
||||
|
||||
CMS_BLOG_STORAGE_I
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
blogs_count: INTEGER_64
|
||||
-- Count of nodes.
|
||||
do
|
||||
end
|
||||
|
||||
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||
-- <Precursor>
|
||||
do
|
||||
end
|
||||
|
||||
blogs: LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
blogs_limited (limit: NATURAL_32; offset: NATURAL_32) : LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
blogs_from_user_limited (a_user: CMS_USER; limit: NATURAL_32; offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
end
|
||||
end
|
||||
@@ -1,140 +0,0 @@
|
||||
note
|
||||
description: "Access to the sql database for the blog module"
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch>"
|
||||
date: "$Date: 2015-05-21 14:46:00 +0100$"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_BLOG_STORAGE_SQL
|
||||
|
||||
inherit
|
||||
CMS_NODE_STORAGE_SQL
|
||||
|
||||
CMS_BLOG_STORAGE_I
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
blogs_count: INTEGER_64
|
||||
-- <Precursor>
|
||||
do
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".blogs_count")
|
||||
sql_query (sql_select_blog_count, Void)
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_integer_64 (1)
|
||||
end
|
||||
end
|
||||
|
||||
blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".blogs_count_from_user")
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_user.id, "user")
|
||||
sql_query (sql_select_blog_count_from_user, l_parameters)
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_integer_64 (1)
|
||||
end
|
||||
end
|
||||
|
||||
blogs: LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".blogs")
|
||||
|
||||
from
|
||||
sql_query (sql_select_blogs_order_created_desc, Void)
|
||||
sql_start
|
||||
until
|
||||
sql_after
|
||||
loop
|
||||
if attached fetch_node as l_node then
|
||||
Result.force (l_node)
|
||||
end
|
||||
sql_forth
|
||||
end
|
||||
end
|
||||
|
||||
blogs_limited (a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".blogs_limited")
|
||||
|
||||
from
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_limit, "limit")
|
||||
l_parameters.put (a_offset, "offset")
|
||||
sql_query (sql_blogs_limited, l_parameters)
|
||||
sql_start
|
||||
until
|
||||
sql_after
|
||||
loop
|
||||
if attached fetch_node as l_node then
|
||||
Result.force (l_node)
|
||||
end
|
||||
sql_forth
|
||||
end
|
||||
end
|
||||
|
||||
blogs_from_user_limited (a_user: CMS_USER; a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".blogs_from_user_limited")
|
||||
|
||||
from
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_limit, "limit")
|
||||
l_parameters.put (a_offset, "offset")
|
||||
l_parameters.put (a_user.id, "user")
|
||||
sql_query (sql_blogs_from_user_limited, l_parameters)
|
||||
sql_start
|
||||
until
|
||||
sql_after
|
||||
loop
|
||||
if attached fetch_node as l_node then
|
||||
Result.force (l_node)
|
||||
end
|
||||
sql_forth
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Queries
|
||||
|
||||
sql_select_blog_count: STRING = "SELECT count(*) FROM Nodes WHERE status != -1 AND type = %"blog%";"
|
||||
-- Nodes count (Published and not Published)
|
||||
--| note: {CMS_NODE_API}.trashed = -1
|
||||
|
||||
sql_select_blog_count_from_user: STRING = "SELECT count(*) FROM Nodes WHERE status != -1 AND type = %"blog%" AND author = :user ;"
|
||||
-- Nodes count (Published and not Published)
|
||||
--| note: {CMS_NODE_API}.trashed = -1
|
||||
|
||||
sql_select_blogs_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;"
|
||||
-- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date.
|
||||
|
||||
sql_blogs_limited: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC LIMIT :limit OFFSET :offset ;"
|
||||
--- SQL Query to retrieve all node of type "blog" limited by limit and starting at offset
|
||||
|
||||
sql_blogs_from_user_limited: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" AND author = :user ORDER BY created DESC LIMIT :limit OFFSET :offset ;"
|
||||
--- SQL Query to retrieve all node of type "blog" from author with id limited by limit + offset
|
||||
|
||||
|
||||
end
|
||||
@@ -80,11 +80,12 @@ CREATE TABLE "tb_demo"(
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
map_uri_template_agent (a_router, "/demo/", agent handle_demo (?,?,a_api))
|
||||
map_uri_template_agent (a_router, "/demo/{id}", agent handle_demo_entry (?,?,a_api))
|
||||
create Result.make (2)
|
||||
map_uri_template_agent (Result, "/demo/", agent handle_demo (?,?,a_api))
|
||||
map_uri_template_agent (Result, "/demo/{id}", agent handle_demo_entry (?,?,a_api))
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
@@ -1,5 +1,35 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE "users"(
|
||||
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("uid">=0),
|
||||
"name" VARCHAR(100) NOT NULL,
|
||||
"password" VARCHAR(100) NOT NULL,
|
||||
"salt" VARCHAR(100) NOT NULL,
|
||||
"email" VARCHAR(250) NOT NULL,
|
||||
"status" INTEGER,
|
||||
"created" DATETIME NOT NULL,
|
||||
"signed" DATETIME,
|
||||
CONSTRAINT "name"
|
||||
UNIQUE("name")
|
||||
);
|
||||
|
||||
CREATE TABLE "roles"(
|
||||
"rid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("rid">=0),
|
||||
"name" VARCHAR(100) NOT NULL,
|
||||
CONSTRAINT "name"
|
||||
UNIQUE("name")
|
||||
);
|
||||
|
||||
CREATE TABLE "users_roles"(
|
||||
"uid" INTEGER NOT NULL CHECK("uid">=0),
|
||||
"rid" INTEGER NOT NULL CHECK("rid">=0)
|
||||
);
|
||||
|
||||
CREATE TABLE "role_permissions"(
|
||||
"rid" INTEGER NOT NULL CHECK("rid">=0),
|
||||
"permission" VARCHAR(255) NOT NULL,
|
||||
"module" VARCHAR(255)
|
||||
);
|
||||
|
||||
CREATE TABLE "logs"(
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
|
||||
@@ -18,11 +48,4 @@ CREATE TABLE "custom_values"(
|
||||
"value" VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE "path_aliases"(
|
||||
"pid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("pid">=0),
|
||||
"source" VARCHAR(255) NOT NULL,
|
||||
"alias" VARCHAR(255) NOT NULL,
|
||||
"lang" VARCHAR(12)
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE "users"(
|
||||
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("uid">=0),
|
||||
"name" VARCHAR(100) NOT NULL,
|
||||
"password" VARCHAR(100) NOT NULL,
|
||||
"salt" VARCHAR(100) NOT NULL,
|
||||
"email" VARCHAR(250) NOT NULL,
|
||||
"status" INTEGER,
|
||||
"created" DATETIME NOT NULL,
|
||||
"signed" DATETIME,
|
||||
CONSTRAINT "name"
|
||||
UNIQUE("name")
|
||||
);
|
||||
|
||||
CREATE TABLE "roles"(
|
||||
"rid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("rid">=0),
|
||||
"name" VARCHAR(100) NOT NULL,
|
||||
CONSTRAINT "name"
|
||||
UNIQUE("name")
|
||||
);
|
||||
|
||||
CREATE TABLE "users_roles"(
|
||||
"uid" INTEGER NOT NULL CHECK("uid">=0),
|
||||
"rid" INTEGER NOT NULL CHECK("rid">=0)
|
||||
);
|
||||
|
||||
CREATE TABLE "role_permissions"(
|
||||
"rid" INTEGER NOT NULL CHECK("rid">=0),
|
||||
"permission" VARCHAR(255) NOT NULL,
|
||||
"module" VARCHAR(255)
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
@@ -1,25 +0,0 @@
|
||||
ul.cms_blog_nodes {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
ul.cms_blog_nodes li.cms_type_blog {
|
||||
list-style: none;
|
||||
display: block;
|
||||
margin-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px dotted black;
|
||||
}
|
||||
ul.cms_blog_nodes li.cms_type_blog .blog_title a {
|
||||
color: black;
|
||||
font-size: 18px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
margin: 6px 0;
|
||||
}
|
||||
ul.cms_blog_nodes li.cms_type_blog .blog_title a:hover {
|
||||
color: #999;
|
||||
}
|
||||
ul.cms_blog_nodes li.cms_type_blog .blog_list_summary a {
|
||||
margin-top: 20px;
|
||||
display: block;
|
||||
}
|
||||
@@ -3,15 +3,13 @@ ul.cms-nodes {
|
||||
padding: 3px 3px 3px 3px;
|
||||
border: solid 1px #ccc;
|
||||
}
|
||||
ul.cms-nodes li {
|
||||
|
||||
li.cms_type_page {
|
||||
border-top: dotted 1px #ccc;
|
||||
}
|
||||
ul.cms-nodes li:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
ul.cms-nodes li.cms_type_page a::before {
|
||||
li.cms_type_page a::before {
|
||||
content: "[page] ";
|
||||
}
|
||||
ul.cms-nodes li.cms_type_blog a::before {
|
||||
content: "[blog] ";
|
||||
li.cms_type_page:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
ul.cms_blog_nodes{
|
||||
|
||||
padding:0;
|
||||
margin:0;
|
||||
|
||||
li.cms_type_blog{
|
||||
list-style: none;
|
||||
display: block;
|
||||
margin-top:20px;
|
||||
padding-bottom:20px;
|
||||
border-bottom:1px dotted black;
|
||||
|
||||
.blog_title a{
|
||||
color:black;
|
||||
font-size:18px;
|
||||
text-decoration: none;
|
||||
display:block;
|
||||
margin:6px 0;
|
||||
|
||||
&:hover{
|
||||
color:#999;
|
||||
}
|
||||
}
|
||||
|
||||
.blog_list_summary a{
|
||||
margin-top:20px;
|
||||
display:block;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,14 @@
|
||||
ul.cms-nodes {
|
||||
|
||||
list-style-type: none;
|
||||
padding: 3px 3px 3px 3px;
|
||||
border: solid 1px #ccc;
|
||||
|
||||
li{
|
||||
border-top: dotted 1px #ccc;
|
||||
&:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
}
|
||||
|
||||
li.cms_type_page a::before {
|
||||
}
|
||||
li.cms_type_page {
|
||||
a::before {
|
||||
content: "[page] ";
|
||||
}
|
||||
|
||||
li.cms_type_blog a::before {
|
||||
content: "[blog] ";
|
||||
border-top: dotted 1px #ccc;
|
||||
&:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
<!-- EWF CMS -->
|
||||
<link rel="stylesheet" href="{$site_url/}/theme/css/style.css">
|
||||
<link rel="stylesheet" href="{$site_url/}/theme/css/node.css">
|
||||
|
||||
<!-- CMS Blog Module -->
|
||||
<link rel="stylesheet" href="{$site_url/}/theme/css/blog.css">
|
||||
|
||||
<script src="{$site_url/}/theme/js/jquery-1.10.2.min.js"></script>
|
||||
<script src="{$site_url/}/theme/js/roc_auth.js"></script>
|
||||
|
||||
|
||||
@@ -28,8 +28,12 @@ feature {NONE} -- Initialization
|
||||
make (a_title: detachable like title; a_location: like location)
|
||||
-- Create current local link with optional title `a_title' and location `a_location'.
|
||||
do
|
||||
if a_title /= Void then
|
||||
title := a_title
|
||||
else
|
||||
title := a_location
|
||||
end
|
||||
location := a_location
|
||||
set_title (a_title)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -71,16 +75,6 @@ feature -- Status report
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_title (a_title: detachable like title)
|
||||
-- Set `title' to `a_title' or `location'.
|
||||
do
|
||||
if a_title /= Void then
|
||||
title := a_title
|
||||
else
|
||||
title := location
|
||||
end
|
||||
end
|
||||
|
||||
add_link (lnk: CMS_LINK)
|
||||
-- <Precursor>
|
||||
local
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
note
|
||||
description: "Storage based on Eiffel Store component."
|
||||
description: "Summary description for {CMS_STORAGE_STORE_SQL}."
|
||||
author: ""
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
@@ -7,7 +8,9 @@ deferred class
|
||||
CMS_STORAGE_STORE_SQL
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_SQL
|
||||
CMS_STORAGE
|
||||
|
||||
CMS_STORAGE_SQL_I
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
@@ -22,6 +25,7 @@ feature {NONE} -- Initialization
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
|
||||
create error_handler.make
|
||||
-- error_handler.add_synchronization (db_handler.database_error_handler)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Common ancestor for builders responsible to instantiate storage based
|
||||
on Eiffel Store storage.
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
deferred class
|
||||
CMS_STORAGE_STORE_SQL_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_SQL_BUILDER
|
||||
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
note
|
||||
description: "[
|
||||
Interface responsible to instantiate CMS_STORAGE_MYSQL object.
|
||||
Objects that ...
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
@@ -10,9 +10,7 @@ class
|
||||
CMS_STORAGE_MYSQL_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_STORE_SQL_BUILDER
|
||||
|
||||
GLOBAL_SETTINGS
|
||||
CMS_STORAGE_SQL_BUILDER
|
||||
|
||||
create
|
||||
make
|
||||
@@ -34,12 +32,6 @@ feature -- Factory
|
||||
create {DATABASE_CONNECTION_MYSQL} conn.login_with_connection_string (l_database_config.connection_string)
|
||||
if conn.is_connected then
|
||||
create Result.make (conn)
|
||||
set_map_zero_null_value (False) --| This way we map 0 to 0, instead of Null as default.
|
||||
if Result.is_available then
|
||||
if not Result.is_initialized then
|
||||
initialize (a_setup, Result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {CMS_STORAGE_SQLITE}."
|
||||
description: "Summary description for {CMS_STORAGE_MYSQL}."
|
||||
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
|
||||
revision: "$Revision: 96596 $"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
note
|
||||
description: "[
|
||||
Interface responsible to instantiate CMS_STORAGE_SQLITE object.
|
||||
Objects that ...
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
@@ -10,9 +10,7 @@ class
|
||||
CMS_STORAGE_SQLITE_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_STORE_SQL_BUILDER
|
||||
|
||||
GLOBAL_SETTINGS
|
||||
CMS_STORAGE_SQL_BUILDER
|
||||
|
||||
create
|
||||
make
|
||||
@@ -29,7 +27,6 @@ feature -- Factory
|
||||
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_SQLITE
|
||||
local
|
||||
s: STRING
|
||||
conn: DATABASE_CONNECTION
|
||||
do
|
||||
if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.environment.application_config_path) as l_database_config then
|
||||
s := "Driver=SQLite3 ODBC Driver;Database="
|
||||
@@ -37,17 +34,75 @@ feature -- Factory
|
||||
s.append (db_name)
|
||||
end
|
||||
s.append (";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
|
||||
create {DATABASE_CONNECTION_ODBC} conn.login_with_connection_string (s)
|
||||
if conn.is_connected then
|
||||
create Result.make (conn)
|
||||
set_map_zero_null_value (False) --| This way we map 0 to 0, instead of Null as default.
|
||||
if Result.is_available then
|
||||
if not Result.is_initialized then
|
||||
initialize (a_setup, Result)
|
||||
end
|
||||
create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (s))
|
||||
--create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (l_database_config.connection_string))
|
||||
if Result.is_available then
|
||||
if not Result.is_initialized then
|
||||
initialize (a_setup, Result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initialize (a_setup: CMS_SETUP; a_storage: CMS_STORAGE_STORE_SQL)
|
||||
local
|
||||
u: CMS_USER
|
||||
l_anonymous_role, l_authenticated_role, r: CMS_USER_ROLE
|
||||
l_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
--| Schema
|
||||
a_storage.sql_execute_file_script (a_setup.environment.path.extended ("scripts").extended ("core.sql"))
|
||||
|
||||
--| Roles
|
||||
create l_anonymous_role.make ("anonymous")
|
||||
a_storage.save_user_role (l_anonymous_role)
|
||||
|
||||
create l_authenticated_role.make ("authenticated")
|
||||
a_storage.save_user_role (l_authenticated_role)
|
||||
|
||||
--| Users
|
||||
create u.make ("admin")
|
||||
u.set_password ("istrator#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
--| Node
|
||||
-- FIXME: move that initialization to node module
|
||||
l_anonymous_role.add_permission ("view any page")
|
||||
a_storage.save_user_role (l_anonymous_role)
|
||||
|
||||
l_authenticated_role.add_permission ("create page")
|
||||
l_authenticated_role.add_permission ("view any page")
|
||||
l_authenticated_role.add_permission ("edit own page")
|
||||
l_authenticated_role.add_permission ("delete own page")
|
||||
a_storage.save_user_role (l_authenticated_role)
|
||||
|
||||
|
||||
--| For testing purpose, to be removed later.
|
||||
|
||||
-- Roles, view role for testing.
|
||||
create r.make ("view")
|
||||
r.add_permission ("view page")
|
||||
a_storage.save_user_role (r)
|
||||
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
|
||||
l_roles.force (r)
|
||||
|
||||
create u.make ("auth")
|
||||
u.set_password ("enticated#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
create u.make ("test")
|
||||
u.set_password ("test#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
create u.make ("view")
|
||||
u.set_password ("only#")
|
||||
u.set_email (a_setup.site_email)
|
||||
u.set_roles (l_roles)
|
||||
a_storage.new_user (u)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -37,11 +37,12 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
configure_api_login (a_api, a_router)
|
||||
configure_api_logoff (a_api, a_router)
|
||||
create Result.make (2)
|
||||
configure_api_login (a_api, Result)
|
||||
configure_api_logoff (a_api, Result)
|
||||
end
|
||||
|
||||
feature -- Access: filter
|
||||
|
||||
@@ -176,14 +176,6 @@ feature -- URL
|
||||
end
|
||||
end
|
||||
|
||||
node_link (a_node: CMS_NODE): CMS_LOCAL_LINK
|
||||
-- CMS link for node `a_node'.
|
||||
require
|
||||
a_node.has_id
|
||||
do
|
||||
create Result.make (a_node.title, cms_api.path_alias (node_path (a_node)))
|
||||
end
|
||||
|
||||
node_path (a_node: CMS_NODE): STRING
|
||||
-- URI path for node `a_node'.
|
||||
-- using the /node/{nid} url.
|
||||
@@ -242,11 +234,6 @@ feature -- Access: Node
|
||||
Result := a_node
|
||||
end
|
||||
|
||||
-- Update link with aliasing.
|
||||
if a_node /= Void and then a_node.has_id then
|
||||
a_node.set_link (node_link (a_node))
|
||||
end
|
||||
|
||||
-- Update partial user if needed.
|
||||
if
|
||||
Result /= Void and then
|
||||
@@ -272,17 +259,16 @@ feature -- Access: Node
|
||||
|
||||
feature -- Permission Scope: Node
|
||||
|
||||
has_permission_for_action_on_node (a_action: READABLE_STRING_8; a_node: CMS_NODE; a_user: detachable CMS_USER; ): BOOLEAN
|
||||
-- Has permission to execute action `a_action' on node `a_node', by eventual user `a_user'?
|
||||
local
|
||||
l_type_name: READABLE_STRING_8
|
||||
permission_scope (u: detachable CMS_USER; a_node: CMS_NODE): STRING
|
||||
-- Result 'own' if the user `u' is the owner of the node `a_node', in other case
|
||||
-- `any'.
|
||||
do
|
||||
l_type_name := a_node.content_type
|
||||
Result := cms_api.user_has_permission (a_user, a_action + " any " + l_type_name)
|
||||
if not Result and a_user /= Void then
|
||||
if is_author_of_node (a_user, a_node) then
|
||||
Result := cms_api.user_has_permission (a_user, a_action + " own " + l_type_name)
|
||||
end
|
||||
-- FIXME: check if this is ok, since a role may have "any" permission enabled, and "own" disabled,
|
||||
-- in this case, we should check both permissions
|
||||
-- obviously such case should be rare, and look like bad configured permissions, but this may occurs.
|
||||
Result := "any"
|
||||
if u /= Void and then is_author_of_node (u, a_node) then
|
||||
Result := "own"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ feature -- Conversion
|
||||
a_node.format
|
||||
)
|
||||
set_status (a_node.status)
|
||||
set_link (a_node.link)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -143,11 +142,6 @@ feature -- status report
|
||||
Result := a_content_type.is_case_insensitive_equal (content_type)
|
||||
end
|
||||
|
||||
feature -- Access: menu
|
||||
|
||||
link: detachable CMS_LOCAL_LINK
|
||||
-- Associated menu link.
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||
@@ -164,9 +158,6 @@ feature -- Element change
|
||||
-- Assign `title' with `a_title'.
|
||||
do
|
||||
title := a_title
|
||||
if attached link as lnk then
|
||||
lnk.set_title (a_title)
|
||||
end
|
||||
ensure
|
||||
title_assigned: title = a_title
|
||||
end
|
||||
@@ -220,14 +211,6 @@ feature -- Element change
|
||||
auther_set: author = u
|
||||
end
|
||||
|
||||
set_link (a_link: like link)
|
||||
-- Set `link' to `a_link'.
|
||||
do
|
||||
link := a_link
|
||||
end
|
||||
|
||||
feature -- Status change
|
||||
|
||||
mark_not_published
|
||||
-- Set status to not_published.
|
||||
do
|
||||
@@ -245,13 +228,14 @@ feature -- Status change
|
||||
end
|
||||
|
||||
mark_trashed
|
||||
-- Set status to trashed.
|
||||
-- Set status to published
|
||||
do
|
||||
set_status ({CMS_NODE_API}.trashed)
|
||||
ensure
|
||||
status_trash: status = {CMS_NODE_API}.trashed
|
||||
end
|
||||
|
||||
|
||||
feature {CMS_NODE_STORAGE_I} -- Access: status change.
|
||||
|
||||
set_status (a_status: like status)
|
||||
|
||||
@@ -17,11 +17,10 @@ feature {NONE} -- Initialization
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (3)
|
||||
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
|
||||
|
||||
@@ -15,13 +15,10 @@ feature -- Forms ...
|
||||
local
|
||||
ti: WSF_FORM_TEXT_INPUT
|
||||
fset: WSF_FORM_FIELD_SET
|
||||
ta, sum: CMS_FORM_TEXTAREA
|
||||
ta: WSF_FORM_TEXTAREA
|
||||
tselect: WSF_FORM_SELECT
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
cms_format: CMS_EDITOR_CONTENT_FORMAT
|
||||
do
|
||||
create cms_format
|
||||
|
||||
create ti.make ("title")
|
||||
ti.set_label ("Title")
|
||||
ti.set_size (70)
|
||||
@@ -33,47 +30,25 @@ feature -- Forms ...
|
||||
|
||||
f.extend_html_text ("<br/>")
|
||||
|
||||
-- Select field has to be initialized before textareas are replaced, because they depend on the selection of the field
|
||||
create tselect.make ("format")
|
||||
tselect.set_label ("Body's format")
|
||||
tselect.set_is_required (True)
|
||||
|
||||
-- Main Content
|
||||
create ta.make ("body")
|
||||
ta.set_rows (10)
|
||||
ta.set_cols (70)
|
||||
ta.show_as_editor_if_selected (tselect, cms_format.name)
|
||||
if a_node /= Void then
|
||||
ta.set_text_value (a_node.content)
|
||||
end
|
||||
ta.set_label ("Content")
|
||||
-- ta.set_label ("Body")
|
||||
ta.set_description ("This is the main content")
|
||||
ta.set_is_required (False)
|
||||
|
||||
-- Summary
|
||||
create sum.make ("summary")
|
||||
sum.set_rows (3)
|
||||
sum.set_cols (70)
|
||||
-- if cms_html is selected
|
||||
sum.show_as_editor_if_selected (tselect, cms_format.name)
|
||||
if a_node /= Void then
|
||||
sum.set_text_value (a_node.summary)
|
||||
end
|
||||
sum.set_label ("Summary")
|
||||
sum.set_description ("This is the summary")
|
||||
sum.set_is_required (False)
|
||||
|
||||
create fset.make
|
||||
fset.set_legend ("Body")
|
||||
|
||||
-- Add summary
|
||||
fset.extend (sum)
|
||||
fset.extend_html_text("<br />")
|
||||
|
||||
-- Add content (body)
|
||||
fset.extend (ta)
|
||||
|
||||
fset.extend_html_text ("<br/>")
|
||||
|
||||
create tselect.make ("format")
|
||||
tselect.set_label ("Body's format")
|
||||
tselect.set_is_required (True)
|
||||
across
|
||||
content_type.available_formats as c
|
||||
loop
|
||||
@@ -90,31 +65,11 @@ feature -- Forms ...
|
||||
fset.extend (tselect)
|
||||
|
||||
f.extend (fset)
|
||||
|
||||
-- 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)
|
||||
else
|
||||
ti.set_text_value (response.api.path_alias (response.node_api.node_path (a_node)))
|
||||
end
|
||||
end
|
||||
if
|
||||
attached f.fields_by_name ("title") as l_title_fields and then
|
||||
attached l_title_fields.first as l_title_field
|
||||
then
|
||||
f.insert_after (ti, l_title_field)
|
||||
else
|
||||
f.extend (ti)
|
||||
end
|
||||
end
|
||||
|
||||
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
local
|
||||
b,s: detachable READABLE_STRING_8
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
do
|
||||
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
|
||||
@@ -127,12 +82,6 @@ feature -- Forms ...
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
|
||||
-- Read out the summary field from the form data
|
||||
if attached fd.string_item ("summary") as l_summary then
|
||||
s := l_summary
|
||||
end
|
||||
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
@@ -140,19 +89,15 @@ feature -- Forms ...
|
||||
else
|
||||
f := response.formats.default_format
|
||||
end
|
||||
|
||||
-- Update node with summary and body content
|
||||
if b /= Void then
|
||||
a_node.set_content (b, s, f.name)
|
||||
a_node.set_content (b, Void, f.name) -- FIXME: summary
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): G
|
||||
-- <Precursor>
|
||||
local
|
||||
b,s: detachable READABLE_STRING_8
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
l_node: detachable like new_node
|
||||
do
|
||||
@@ -186,16 +131,9 @@ feature -- Forms ...
|
||||
end
|
||||
l_node.set_author (response.user)
|
||||
|
||||
--Summary
|
||||
if attached fd.string_item ("summary") as l_summary then
|
||||
s := l_summary
|
||||
end
|
||||
|
||||
--Content
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
@@ -203,10 +141,8 @@ feature -- Forms ...
|
||||
else
|
||||
f := response.formats.default_format
|
||||
end
|
||||
|
||||
-- Update node with summary and content
|
||||
if b /= Void then
|
||||
l_node.set_content (b, s, f.name)
|
||||
l_node.set_content (b, Void, f.name)
|
||||
end
|
||||
Result := l_node
|
||||
end
|
||||
@@ -224,9 +160,8 @@ 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)
|
||||
create lnk.make ("View", node_api.node_path (a_node))
|
||||
lnk.set_weight (1)
|
||||
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
|
||||
lnk.set_weight (2)
|
||||
@@ -245,23 +180,6 @@ feature -- Output
|
||||
s.append (")")
|
||||
end
|
||||
s.append ("</div>")
|
||||
|
||||
|
||||
-- We don't show the summary on the detail page, since its just a short view of the full content. Otherwise we would write the same thing twice.
|
||||
-- The usage of the summary is to give a short overview in the list of nodes or for the meta tag "description"
|
||||
|
||||
-- if attached a_node.summary as l_summary then
|
||||
-- s.append ("<p class=%"summary%">")
|
||||
-- if attached node_api.cms_api.format (a_node.format) as f then
|
||||
-- s.append (f.formatted_output (l_summary))
|
||||
-- else
|
||||
-- s.append (a_response.formats.default_format.formatted_output (l_summary))
|
||||
-- end
|
||||
|
||||
-- s.append ("</p>")
|
||||
|
||||
-- end
|
||||
|
||||
if attached a_node.content as l_content then
|
||||
s.append ("<p class=%"content%">")
|
||||
if attached node_api.cms_api.format (a_node.format) as f then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
note
|
||||
description: "Summary description for {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ feature -- Execution
|
||||
-- Computed response message.
|
||||
local
|
||||
b: STRING_8
|
||||
f: like new_edit_form
|
||||
f: like edit_form
|
||||
fd: detachable WSF_FORM_DATA
|
||||
nid: INTEGER_64
|
||||
do
|
||||
@@ -48,44 +48,43 @@ feature -- Execution
|
||||
attached node_api.node (nid) as l_node
|
||||
then
|
||||
if attached node_api.node_type_for (l_node) as l_type then
|
||||
if node_api.has_permission_for_action_on_node ("edit", l_node, current_user (request)) then
|
||||
f := new_edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
invoke_form_alter (f, fd)
|
||||
if has_permission ("edit " + node_api.permission_scope (current_user (request), l_node) + " " + l_type.name) then
|
||||
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
if request.is_post_request_method then
|
||||
f.validation_actions.extend (agent edit_form_validate (?, b))
|
||||
f.submit_actions.extend (agent edit_form_submit (?, l_node, l_type, b))
|
||||
f.process (Current)
|
||||
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)
|
||||
end
|
||||
|
||||
if attached redirection as l_location then
|
||||
-- FIXME: Hack for now
|
||||
set_title (l_node.title)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
|
||||
b.append (html_encoded (l_type.title) + " saved")
|
||||
else
|
||||
set_title (formatted_string (translation ("Edit $1 #$2", Void), [l_type.title, l_node.id]))
|
||||
set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
|
||||
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
|
||||
f.append_to_html (wsf_theme, b)
|
||||
end
|
||||
else
|
||||
b.append ("<h1>")
|
||||
b.append (translation ("Access denied", Void))
|
||||
b.append ("</h1>")
|
||||
b.append ("<h1>Access denied</h1>")
|
||||
end
|
||||
else
|
||||
set_title (translation ("Unknown node", Void))
|
||||
set_title ("Unknown node")
|
||||
end
|
||||
elseif
|
||||
attached {WSF_STRING} request.path_parameter ("type") as p_type and then
|
||||
attached node_api.node_type (p_type.value) as l_type
|
||||
then
|
||||
if has_permissions (<<"create any", "create " + l_type.name>>) then
|
||||
if has_permission ("create " + l_type.name) then
|
||||
if attached l_type.new_node (Void) as l_node then
|
||||
f := new_edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
invoke_form_alter (f, fd)
|
||||
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
if request.is_post_request_method then
|
||||
f.validation_actions.extend (agent edit_form_validate (?, b))
|
||||
f.submit_actions.extend (agent edit_form_submit (?, l_node, l_type, b))
|
||||
@@ -95,31 +94,25 @@ 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)
|
||||
end
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
|
||||
f.append_to_html (wsf_theme, b)
|
||||
else
|
||||
b.append ("<h1>")
|
||||
b.append (translation ("Server error", Void))
|
||||
b.append ("</h1>")
|
||||
b.append ("<h1>Server error</h1>")
|
||||
end
|
||||
else
|
||||
b.append ("<h1>")
|
||||
b.append (translation ("Access denied", Void))
|
||||
b.append ("</h1>")
|
||||
b.append ("<h1>Access denied</h1>")
|
||||
end
|
||||
else
|
||||
set_title (translation ("Create new content ...", Void))
|
||||
set_title ("Create new content ...")
|
||||
b.append ("<ul id=%"content-types%">")
|
||||
across
|
||||
node_api.node_types as ic
|
||||
loop
|
||||
if
|
||||
attached ic.item as l_node_type and then
|
||||
has_permissions (<<"create any", "create " + l_node_type.name>>)
|
||||
(has_permission ("create any") or has_permission ("create " + l_node_type.name))
|
||||
then
|
||||
b.append ("<li>" + link (l_node_type.name, "/node/add/" + l_node_type.name, Void))
|
||||
if attached l_node_type.description as d then
|
||||
@@ -198,25 +191,16 @@ 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_link (u) + "%" " + s + " node " + link (a_type.name +" #" + l_node.id.out, "/node/" + l_node.id.out , Void), 0, node_local_link (l_node))
|
||||
else
|
||||
api.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node))
|
||||
end
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
|
||||
if attached fd.string_item ("path_alias") as l_path_alias then
|
||||
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))
|
||||
end
|
||||
end
|
||||
|
||||
new_edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
|
||||
-- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'.
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: WSF_FORM_SUBMIT_INPUT
|
||||
@@ -232,7 +216,8 @@ feature -- Form
|
||||
end
|
||||
f.extend (th)
|
||||
|
||||
populate_form (a_node_type, f, a_node)
|
||||
fill_edit_form (a_type, f, a_node)
|
||||
|
||||
f.extend_html_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
@@ -243,15 +228,11 @@ feature -- Form
|
||||
ts.set_default_value ("Preview")
|
||||
f.extend (ts)
|
||||
|
||||
if
|
||||
a_node /= Void and then
|
||||
a_node.id > 0 and then
|
||||
has_permission ("delete " + a_name)
|
||||
then
|
||||
if a_node /= Void and then a_node.id > 0 and then has_permission ("delete " + a_name) then
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Delete")
|
||||
fixme ("[
|
||||
ts.set_default_value (translation ("Delete"))
|
||||
ts.set_default_value (i18n ("Delete"))i18n or other name such as "translated" or "translation
|
||||
]")
|
||||
f.extend (ts)
|
||||
end
|
||||
@@ -259,18 +240,8 @@ feature -- Form
|
||||
Result := f
|
||||
end
|
||||
|
||||
populate_form (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
-- Fill the web form `a_form' with data from `a_node' if set,
|
||||
-- and apply this to content type `a_content_type'.
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
wf.populate_form (Current, a_form, a_node)
|
||||
end
|
||||
end
|
||||
|
||||
new_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
-- Node creation with form_data `a_form_data' for the given content type `a_content_type'
|
||||
-- using optional `a_node' to get extra node data.
|
||||
--
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
Result := wf.new_node (Current, a_form_data, a_node)
|
||||
@@ -287,4 +258,11 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
fill_edit_form (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
wf.populate_form (Current, a_form, a_node)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -150,7 +150,7 @@ feature -- HTTP Methods
|
||||
l_id.is_integer and then
|
||||
attached node_api.node (l_id.integer_value) as l_node
|
||||
then
|
||||
if node_api.has_permission_for_action_on_node ("delete", l_node, current_user (req)) then
|
||||
if api.user_has_permission (l_user, "delete " + node_api.permission_scope (l_user, l_node) + " " + l_node.content_type) then
|
||||
node_api.delete_node (l_node)
|
||||
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
||||
else
|
||||
|
||||
@@ -51,48 +51,36 @@ feature -- Helpers
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Helpers: cms link
|
||||
feature -- Helpers
|
||||
|
||||
user_local_link (u: CMS_USER): CMS_LOCAL_LINK
|
||||
user_local_link (u: CMS_USER): CMS_LINK
|
||||
do
|
||||
create Result.make (u.name, user_url (u))
|
||||
create {CMS_LOCAL_LINK} Result.make (u.name, user_url (u))
|
||||
end
|
||||
|
||||
node_local_link (n: CMS_NODE): CMS_LOCAL_LINK
|
||||
node_local_link (n: CMS_NODE): CMS_LINK
|
||||
do
|
||||
if attached n.link as lnk then
|
||||
Result := lnk
|
||||
else
|
||||
Result := node_api.node_link (n)
|
||||
end
|
||||
create {CMS_LOCAL_LINK} Result.make (n.title, node_url (n))
|
||||
end
|
||||
|
||||
feature -- Helpers: html link
|
||||
|
||||
user_html_link (u: CMS_USER): like link
|
||||
user_link (u: CMS_USER): like link
|
||||
do
|
||||
Result := link (u.name, "/user/" + u.id.out, Void)
|
||||
end
|
||||
|
||||
node_html_link (n: CMS_NODE): like link
|
||||
node_link (n: CMS_NODE): like link
|
||||
do
|
||||
Result := link (n.title, "/node/" + n.id.out, Void)
|
||||
end
|
||||
|
||||
feature -- Helpers: URL
|
||||
|
||||
user_url (u: CMS_USER): like url
|
||||
require
|
||||
u_with_id: u.has_id
|
||||
do
|
||||
Result := url ("/user/" + u.id.out, Void)
|
||||
end
|
||||
|
||||
node_url (n: CMS_NODE): like url
|
||||
require
|
||||
n_with_id: n.has_id
|
||||
do
|
||||
Result := url (node_api.node_link (n).location, Void)
|
||||
Result := url ("/node/" + n.id.out, Void)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -40,7 +40,6 @@ feature -- HTTP Methods
|
||||
l_page: CMS_RESPONSE
|
||||
s: STRING
|
||||
n: CMS_NODE
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
-- At the moment the template is hardcoded, but we can
|
||||
-- get them from the configuration file and load them into
|
||||
@@ -58,10 +57,8 @@ feature -- HTTP Methods
|
||||
lst as ic
|
||||
loop
|
||||
n := ic.item
|
||||
lnk := node_api.node_link (n)
|
||||
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||
-- s.append (l_page.link (n.title + " (#" + n.id.out + ")", node_api.node_path (n), Void))
|
||||
s.append (l_page.link (n.title + " (#" + n.id.out + ")", node_api.node_path (n), Void))
|
||||
s.append ("</li>%N")
|
||||
end
|
||||
s.append ("</ul>%N")
|
||||
|
||||
@@ -109,8 +109,8 @@ feature {CMS_API} -- Access: API
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
local
|
||||
l_node_api: like node_api
|
||||
do
|
||||
@@ -119,7 +119,8 @@ feature -- Access: router
|
||||
create l_node_api.make (a_api)
|
||||
node_api := l_node_api
|
||||
end
|
||||
configure_web (a_api, l_node_api, a_router)
|
||||
create Result.make (2)
|
||||
configure_web (a_api, l_node_api, Result)
|
||||
end
|
||||
|
||||
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
|
||||
@@ -107,8 +107,6 @@ feature -- Change: Node
|
||||
no_id: not a_node.has_id
|
||||
valid_user: attached a_node.author as l_author and then l_author.id > 0
|
||||
deferred
|
||||
ensure
|
||||
has_id: a_node.has_id
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
|
||||
@@ -33,7 +33,6 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
nodes: LIST [CMS_NODE]
|
||||
-- List of nodes.
|
||||
do
|
||||
@@ -158,6 +157,51 @@ feature -- Change: Node
|
||||
sql_change (sql_delete_node, l_parameters)
|
||||
end
|
||||
|
||||
-- update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- -- FIXME: unused a_user_id !
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".update_node_title")
|
||||
-- create l_parameters.make (3)
|
||||
-- l_parameters.put (a_title, "title")
|
||||
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
|
||||
-- l_parameters.put (a_node_id, "nid")
|
||||
-- sql_change (sql_update_node_title, l_parameters)
|
||||
-- end
|
||||
|
||||
-- update_node_summary (a_user_id: Like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- -- FIXME: unused a_user_id !
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".update_node_summary")
|
||||
-- create l_parameters.make (3)
|
||||
-- l_parameters.put (a_summary, "summary")
|
||||
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
|
||||
-- l_parameters.put (a_node_id, "nid")
|
||||
-- sql_change (sql_update_node_summary, l_parameters)
|
||||
-- end
|
||||
|
||||
-- update_node_content (a_user_id: Like {CMS_USER}.id;a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- -- FIXME: unused a_user_id !
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".update_node_content")
|
||||
-- create l_parameters.make (3)
|
||||
-- l_parameters.put (a_content, "content")
|
||||
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
|
||||
-- l_parameters.put (a_node_id, "nid")
|
||||
-- sql_change (sql_update_node_content, l_parameters)
|
||||
-- end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
store_node (a_node: CMS_NODE)
|
||||
@@ -229,9 +273,9 @@ feature {NONE} -- Queries
|
||||
-- SQL Query to retrieve all nodes.
|
||||
--| note: {CMS_NODE_API}.trashed = -1
|
||||
|
||||
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes WHERE nid =:nid ORDER BY revision DESC, publish DESC LIMIT 1;"
|
||||
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
|
||||
|
||||
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes ORDER BY nid DESC, publish DESC LIMIT :rows OFFSET :offset ;"
|
||||
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
|
||||
|
||||
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, status, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :status, :author);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
@@ -84,7 +84,7 @@ feature {NONE} -- Initialization
|
||||
initialize_modules
|
||||
-- Intialize core modules.
|
||||
local
|
||||
-- m: CMS_MODULE
|
||||
m: CMS_MODULE
|
||||
do
|
||||
-- Core
|
||||
-- create {BASIC_AUTH_MODULE} m.make
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
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,11 +27,10 @@ feature -- Access
|
||||
once
|
||||
-- Can we provide an external file to read the
|
||||
-- supported formats?
|
||||
create {ARRAYED_LIST [CONTENT_FORMAT]} Result.make (4)
|
||||
create {ARRAYED_LIST [CONTENT_FORMAT]} Result.make (3)
|
||||
Result.force (plain_text)
|
||||
Result.force (full_html)
|
||||
Result.force (filtered_html)
|
||||
Result.force (cms_html)
|
||||
end
|
||||
|
||||
default_format: CONTENT_FORMAT
|
||||
@@ -44,11 +43,6 @@ feature -- Access
|
||||
create Result
|
||||
end
|
||||
|
||||
cms_html: CMS_EDITOR_CONTENT_FORMAT
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
full_html: FULL_HTML_CONTENT_FORMAT
|
||||
once
|
||||
create Result
|
||||
@@ -59,6 +53,7 @@ feature -- Access
|
||||
create Result
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
note
|
||||
description: "Class to import a WYSIWIG editor using javascript code"
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_EDITOR
|
||||
|
||||
feature -- Initialisation
|
||||
load_assets : STRING
|
||||
-- Loads all assest needed to show the editor
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Javascript
|
||||
|
||||
javascript_replace_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- Javascript code that replaces a textarea with the editor. The editor instance should be saved in editor_variable
|
||||
deferred
|
||||
end
|
||||
|
||||
javascript_restore_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- Javascript code that restores a textarea
|
||||
deferred
|
||||
end
|
||||
|
||||
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
|
||||
do
|
||||
Result := javascript_ready(javascript_replace_textarea (a_textarea))
|
||||
end
|
||||
|
||||
javascript_textarea_to_editor_if_selected (a_textarea : WSF_FORM_TEXTAREA; a_select_field : WSF_FORM_SELECT; a_value : STRING) : STRING
|
||||
-- Javascript code to display the textarea as a WYSIWIG editor if a_select_field has a_value
|
||||
local
|
||||
initial_replace_code, on_select_replace_code : STRING
|
||||
do
|
||||
-- Javascript that replaces the textarea if a_value is selected at load time
|
||||
initial_replace_code := javascript_ready(javascript_if_selected(a_select_field, a_value, javascript_replace_textarea(a_textarea)))
|
||||
|
||||
-- Javascript code that replaces the textarea as soon as value is selected at a_select_field
|
||||
on_select_replace_code := javascript_ready(
|
||||
javascript_init_editor_variable(a_textarea) +
|
||||
javascript_on_select(a_select_field, a_value,
|
||||
-- If a_value is selected, replace textarea
|
||||
javascript_replace_textarea(a_textarea),
|
||||
|
||||
-- Otherwise restore it
|
||||
javascript_restore_textarea(a_textarea)
|
||||
)
|
||||
)
|
||||
|
||||
Result := initial_replace_code + " " + on_select_replace_code
|
||||
end
|
||||
|
||||
javascript_init_editor_variable(a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- Returns the javascript code that initializes a local variable to store the editor instance
|
||||
do
|
||||
Result := "var " + editor_variable(a_textarea) + "; "
|
||||
end
|
||||
|
||||
|
||||
|
||||
javascript_if_selected(a_select_field : WSF_FORM_SELECT; a_value : STRING; a_code : STRING) : STRING
|
||||
-- Javascript that executes a_code if a_value is selected at a_select_field
|
||||
do
|
||||
Result := "if($('#" + field_id(a_select_field) + "').val() == %"" + a_value + "%"){ " + a_code + " }"
|
||||
end
|
||||
|
||||
javascript_ready (a_code : STRING) : STRING
|
||||
-- Wraps the given javascript code with a ready statement, such that it's executed when the document has loaded
|
||||
do
|
||||
Result := "$(function() { " + a_code + " });"
|
||||
end
|
||||
|
||||
javascript_on_select (a_select_field : WSF_FORM_SELECT; a_value : STRING; a_then : STRING; a_else : STRING) : STRING
|
||||
-- Javascript code that executes a_then if at the given select_field the given string value is selected, otherwise it executes a_else
|
||||
do
|
||||
Result := "$('#" + field_id(a_select_field) + "').change(function(){" +
|
||||
javascript_if_selected(a_select_field, a_value, a_then) +
|
||||
"else{" +
|
||||
a_else +
|
||||
"}" +
|
||||
"});"
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
field_id(a_select_field : WSF_FORM_SELECT) : STRING
|
||||
-- Returns the id of the given field
|
||||
do
|
||||
if attached a_select_field.css_id as a_id then
|
||||
Result := a_id
|
||||
else
|
||||
Result := a_select_field.name + "-select"
|
||||
end
|
||||
end
|
||||
|
||||
editor_variable (a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- Returns the variable name that stores the editor instance of the given textarea
|
||||
do
|
||||
Result := "editor_" + a_textarea.name
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,37 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {CMS_EDITOR_CKEDITOR}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_EDITOR_CKEDITOR
|
||||
|
||||
inherit
|
||||
CMS_EDITOR
|
||||
|
||||
feature -- Initialisation
|
||||
|
||||
load_assets : STRING
|
||||
-- <Precursor>
|
||||
do
|
||||
Result := "<script src=%"//cdn.ckeditor.com/4.4.7/standard/ckeditor.js%"></script>"
|
||||
end
|
||||
|
||||
feature -- Javascript
|
||||
|
||||
javascript_replace_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- <Precursor>
|
||||
do
|
||||
-- Replaces the textarea with an editor instance. Save the instance in a variable
|
||||
Result := editor_variable(a_textarea) + " = CKEDITOR.replace( '" + a_textarea.name + "' );"
|
||||
end
|
||||
|
||||
javascript_restore_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING
|
||||
-- <Precursor>
|
||||
do
|
||||
-- Replaces the textarea with an editor instance. Save the instance in a variable
|
||||
Result := "if (" + editor_variable(a_textarea) + " != undefined) " + editor_variable(a_textarea) + ".destroy();"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,77 +0,0 @@
|
||||
note
|
||||
description: "Extends the WSF form textarea with features to add a WYSIWIG editor."
|
||||
author: "Dario B<>sch <daboesch@student.ethz.ch"
|
||||
date: "$Date: 2015-05-23 16:02:55 +0100 (Sat, 23 May 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_FORM_TEXTAREA
|
||||
|
||||
inherit
|
||||
WSF_FORM_TEXTAREA
|
||||
redefine
|
||||
make,
|
||||
append_item_to_html
|
||||
end
|
||||
|
||||
CMS_EDITOR_CKEDITOR
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialisation
|
||||
|
||||
make (a_name: like name)
|
||||
-- <Precursor>
|
||||
do
|
||||
precursor(a_name)
|
||||
|
||||
-- By default we don't replace the textarea by an editor
|
||||
editor := False;
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
editor : BOOLEAN
|
||||
-- True if the textarea should be replaced by the editor. Default is false.
|
||||
|
||||
format_field : detachable WSF_FORM_SELECT
|
||||
-- Selection field for the format on that it depends, if the editor is shown or not.
|
||||
|
||||
condition_value : detachable STRING
|
||||
|
||||
feature -- Editor
|
||||
|
||||
show_as_editor
|
||||
-- The textarea will be replaced by a wysiwyg editor
|
||||
do
|
||||
editor := True
|
||||
end
|
||||
|
||||
show_as_editor_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING)
|
||||
-- Replaces the textarea only if a_select_field has a_value (or the value gets selected)
|
||||
do
|
||||
editor := True
|
||||
format_field := a_select_field
|
||||
condition_value := a_value
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
-- Add javascript to replace textarea with editor
|
||||
precursor(a_theme, a_html)
|
||||
if editor then
|
||||
a_html.append (load_assets)
|
||||
a_html.append ("<script type=%"text/javascript%">");
|
||||
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))
|
||||
else
|
||||
a_html.append (javascript_textarea_to_editor (Current))
|
||||
end
|
||||
a_html.append ("</script>")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -36,10 +36,11 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Router configuration.
|
||||
do
|
||||
a_router.handle ("/debug/", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_debug (a_api, ?, ?)))
|
||||
create Result.make (1)
|
||||
Result.handle ("/debug/", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_debug (a_api, ?, ?)))
|
||||
end
|
||||
|
||||
feature -- Hooks configuration
|
||||
|
||||
@@ -14,11 +14,6 @@ inherit
|
||||
default_create
|
||||
end
|
||||
|
||||
CMS_USER_STORAGE_NULL
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
rename
|
||||
default_create as default_create_rh
|
||||
@@ -45,34 +40,74 @@ feature -- Status report
|
||||
Result := True
|
||||
end
|
||||
|
||||
feature -- URL aliases
|
||||
feature -- Access: user
|
||||
|
||||
set_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- <Precursor>.
|
||||
has_user: BOOLEAN
|
||||
-- Has any user?
|
||||
do
|
||||
end
|
||||
|
||||
replace_path_alias (a_source: READABLE_STRING_8; a_previous_alias: detachable READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- Replace eventual previous alias `a_previous_alias' with a new alias `a_alias'
|
||||
-- on source `a_source'.
|
||||
users: LIST [CMS_USER]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
|
||||
end
|
||||
|
||||
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
unset_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- Unalias `a_source' from `a_alias'.
|
||||
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
path_alias (a_source: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- Return eventual path alias associated with `a_source'.
|
||||
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
source_of_path_alias (a_alias: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- Source path for alias `a_alias'.
|
||||
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Change: user
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
a_user.set_id (1)
|
||||
end
|
||||
|
||||
update_user (a_user: CMS_USER)
|
||||
-- Update user `a_user'.
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
feature -- Access: roles and permissions
|
||||
|
||||
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
|
||||
do
|
||||
end
|
||||
|
||||
user_roles_for (a_user: CMS_USER): LIST [CMS_USER_ROLE]
|
||||
-- User roles for user `a_user'.
|
||||
-- Note: anonymous and authenticated roles are not included.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} Result.make (0)
|
||||
end
|
||||
|
||||
user_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Change: roles and permissions
|
||||
|
||||
save_user_role (a_user_role: CMS_USER_ROLE)
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Logs
|
||||
|
||||
save_log (a_log: CMS_LOG)
|
||||
@@ -80,8 +115,6 @@ feature -- Logs
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Custom
|
||||
|
||||
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
|
||||
-- Save data `a_name:a_value' for type `a_type' (or default if none).
|
||||
do
|
||||
|
||||
15
src/persistence/cms_storage_sql_builder.e
Normal file
15
src/persistence/cms_storage_sql_builder.e
Normal file
@@ -0,0 +1,15 @@
|
||||
note
|
||||
description: "[
|
||||
Objects that ...
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
revision: "$Revision: 96542 $"
|
||||
|
||||
deferred class
|
||||
CMS_STORAGE_SQL_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_BUILDER
|
||||
|
||||
end
|
||||
@@ -19,34 +19,6 @@ feature -- Error Handling
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- URL aliases
|
||||
|
||||
set_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- Alias `a_source' with `a_alias'.
|
||||
deferred
|
||||
end
|
||||
|
||||
replace_path_alias (a_source: READABLE_STRING_8; a_previous_alias: detachable READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- Replace eventual previous alias `a_previous_alias' with a new alias `a_alias'
|
||||
-- on source `a_source'.
|
||||
deferred
|
||||
end
|
||||
|
||||
unset_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- Unalias `a_source' from `a_alias'.
|
||||
deferred
|
||||
end
|
||||
|
||||
path_alias (a_source: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- Return eventual path alias associated with `a_source'.
|
||||
deferred
|
||||
end
|
||||
|
||||
source_of_path_alias (a_alias: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- Source path for alias `a_alias'.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Logs
|
||||
|
||||
save_log (a_log: CMS_LOG)
|
||||
|
||||
@@ -18,123 +18,6 @@ inherit
|
||||
|
||||
SHARED_LOGGER
|
||||
|
||||
feature -- URL aliases
|
||||
|
||||
set_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_source, "source")
|
||||
l_parameters.put (a_alias, "alias")
|
||||
if attached source_of_path_alias (a_alias) as l_path then
|
||||
if a_source.same_string (l_path) then
|
||||
-- already up to date
|
||||
else
|
||||
error_handler.add_custom_error (0, "alias exists", "Path alias %"" + a_alias + "%" already exists!")
|
||||
end
|
||||
else
|
||||
sql_change (sql_insert_path_alias, l_parameters)
|
||||
end
|
||||
end
|
||||
|
||||
replace_path_alias (a_source: READABLE_STRING_8; a_previous_alias: detachable READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_previous_alias: detachable READABLE_STRING_8
|
||||
do
|
||||
error_handler.reset
|
||||
|
||||
if a_previous_alias = Void then
|
||||
l_previous_alias := path_alias (a_source)
|
||||
else
|
||||
l_previous_alias := a_previous_alias
|
||||
end
|
||||
if
|
||||
l_previous_alias /= Void and then
|
||||
not a_alias.same_string (l_previous_alias)
|
||||
then
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_source, "source")
|
||||
l_parameters.put (l_previous_alias, "old")
|
||||
l_parameters.put (a_alias, "alias")
|
||||
|
||||
sql_change (sql_update_path_alias, l_parameters)
|
||||
end
|
||||
end
|
||||
|
||||
unset_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
|
||||
if attached source_of_path_alias (a_alias) as l_path then
|
||||
if a_source.same_string (l_path) then
|
||||
-- Found
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_alias, "alias")
|
||||
sql_change (sql_delete_path_alias, l_parameters)
|
||||
else
|
||||
error_handler.add_custom_error (0, "alias mismatch", "Path alias %"" + a_alias + "%" is not related to source %"" + a_source + "%"!")
|
||||
end
|
||||
else
|
||||
-- No such alias
|
||||
end
|
||||
end
|
||||
|
||||
path_alias (a_source: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_source, "source")
|
||||
sql_query (sql_select_path_source, l_parameters)
|
||||
if not has_error then
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_string (1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
source_of_path_alias (a_alias: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
-- <Precursor>
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_alias, "alias")
|
||||
sql_query (sql_select_path_alias, l_parameters)
|
||||
if not has_error then
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_string (1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sql_select_path_alias: STRING = "SELECT source FROM path_aliases WHERE alias=:alias ;"
|
||||
-- SQL select path aliases.
|
||||
|
||||
sql_select_path_source: STRING = "SELECT alias FROM path_aliases WHERE source=:source ORDER BY pid DESC LIMIT 1;"
|
||||
-- SQL select latest path aliasing :source.
|
||||
|
||||
sql_insert_path_alias: STRING = "INSERT INTO path_aliases (source, alias) VALUES (:source, :alias);"
|
||||
-- SQL insert path alias.
|
||||
|
||||
sql_update_path_alias: STRING = "UPDATE path_aliases SET alias=:alias WHERE source=:source AND alias=:old ;"
|
||||
-- SQL update path alias.
|
||||
|
||||
sql_delete_path_alias: STRING = "DELETE FROM path_aliases WHERE alias=:alias;"
|
||||
-- SQL delete path alias
|
||||
|
||||
feature -- Logs
|
||||
|
||||
save_log (a_log: CMS_LOG)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
note
|
||||
description: "CMS Storage based on SQL statement."
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
deferred class
|
||||
CMS_STORAGE_SQL
|
||||
|
||||
inherit
|
||||
CMS_STORAGE
|
||||
|
||||
CMS_STORAGE_SQL_I
|
||||
|
||||
|
||||
end
|
||||
@@ -1,85 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Common ancestor for builders responsible to instantiate storage based
|
||||
on SQL statement storage.
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
revision: "$Revision: 96542 $"
|
||||
|
||||
deferred class
|
||||
CMS_STORAGE_SQL_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_BUILDER
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
initialize (a_setup: CMS_SETUP; a_storage: CMS_STORAGE_SQL)
|
||||
local
|
||||
u: CMS_USER
|
||||
l_anonymous_role, l_authenticated_role, r: CMS_USER_ROLE
|
||||
l_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
--| Schema
|
||||
a_storage.sql_execute_file_script (a_setup.environment.path.extended ("scripts").extended ("core.sql"))
|
||||
a_storage.sql_execute_file_script (a_setup.environment.path.extended ("scripts").extended ("user.sql"))
|
||||
|
||||
--| Roles
|
||||
create l_anonymous_role.make ("anonymous")
|
||||
a_storage.save_user_role (l_anonymous_role)
|
||||
|
||||
create l_authenticated_role.make ("authenticated")
|
||||
a_storage.save_user_role (l_authenticated_role)
|
||||
|
||||
--| Users
|
||||
create u.make ("admin")
|
||||
u.set_password ("istrator#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
--| Node
|
||||
-- FIXME: move that initialization to node module
|
||||
l_anonymous_role.add_permission ("view any page")
|
||||
a_storage.save_user_role (l_anonymous_role)
|
||||
|
||||
l_authenticated_role.add_permission ("create page")
|
||||
l_authenticated_role.add_permission ("view any page")
|
||||
l_authenticated_role.add_permission ("edit any page")
|
||||
l_authenticated_role.add_permission ("delete page")
|
||||
l_authenticated_role.add_permission ("view own page")
|
||||
l_authenticated_role.add_permission ("edit own page")
|
||||
l_authenticated_role.add_permission ("delete own page")
|
||||
a_storage.save_user_role (l_authenticated_role)
|
||||
|
||||
|
||||
--|-------------------------------------------|--
|
||||
--| For testing purpose, to be removed later. |--
|
||||
--|-------------------------------------------|--
|
||||
|
||||
-- Roles, view role for testing.
|
||||
create r.make ("view")
|
||||
r.add_permission ("view any page")
|
||||
a_storage.save_user_role (r)
|
||||
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
|
||||
l_roles.force (r)
|
||||
|
||||
create u.make ("auth")
|
||||
u.set_password ("enticated#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
create u.make ("test")
|
||||
u.set_password ("test#")
|
||||
u.set_email (a_setup.site_email)
|
||||
a_storage.new_user (u)
|
||||
|
||||
create u.make ("view")
|
||||
u.set_password ("only#")
|
||||
u.set_email (a_setup.site_email)
|
||||
u.set_roles (l_roles)
|
||||
a_storage.new_user (u)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,79 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {CMS_USER_STORAGE_NULL}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_USER_STORAGE_NULL
|
||||
|
||||
inherit
|
||||
CMS_USER_STORAGE_I
|
||||
|
||||
feature -- Access: user
|
||||
|
||||
has_user: BOOLEAN
|
||||
-- Has any user?
|
||||
do
|
||||
end
|
||||
|
||||
users: LIST [CMS_USER]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
|
||||
end
|
||||
|
||||
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Change: user
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
a_user.set_id (1)
|
||||
end
|
||||
|
||||
update_user (a_user: CMS_USER)
|
||||
-- Update user `a_user'.
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
feature -- Access: roles and permissions
|
||||
|
||||
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
|
||||
do
|
||||
end
|
||||
|
||||
user_roles_for (a_user: CMS_USER): LIST [CMS_USER_ROLE]
|
||||
-- User roles for user `a_user'.
|
||||
-- Note: anonymous and authenticated roles are not included.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} Result.make (0)
|
||||
end
|
||||
|
||||
user_roles: LIST [CMS_USER_ROLE]
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_USER_ROLE]} Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Change: roles and permissions
|
||||
|
||||
save_user_role (a_user_role: CMS_USER_ROLE)
|
||||
do
|
||||
end
|
||||
|
||||
end
|
||||
@@ -185,10 +185,8 @@ feature -- Query: module
|
||||
module_api (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE_API
|
||||
-- Enabled module API associated with module typed `a_type'.
|
||||
do
|
||||
if attached {CMS_MODULE} module (a_type) as mod then
|
||||
if mod.is_enabled then
|
||||
Result := mod.module_api
|
||||
end
|
||||
if attached module (a_type) as mod then
|
||||
Result := mod.module_api
|
||||
end
|
||||
end
|
||||
|
||||
@@ -234,66 +232,6 @@ feature -- Query: API
|
||||
Result := l_api
|
||||
end
|
||||
|
||||
feature -- Path aliases
|
||||
|
||||
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.
|
||||
local
|
||||
l_continue: BOOLEAN
|
||||
do
|
||||
if attached storage.path_alias (a_source) as l_existing_alias then
|
||||
if a_alias.same_string (l_existing_alias) then
|
||||
-- Already aliased as expected
|
||||
else
|
||||
-- New alias
|
||||
if a_keep_previous then
|
||||
l_continue := True
|
||||
else
|
||||
storage.replace_path_alias (a_source, l_existing_alias, a_alias)
|
||||
end
|
||||
end
|
||||
elseif a_alias.is_whitespace then
|
||||
-- Ignore
|
||||
elseif a_source.same_string (a_alias) then
|
||||
-- No need for alias
|
||||
else
|
||||
l_continue := True
|
||||
end
|
||||
if l_continue then
|
||||
storage.set_path_alias (a_source, a_alias)
|
||||
end
|
||||
end
|
||||
|
||||
unset_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
do
|
||||
storage.unset_path_alias (a_source, a_alias)
|
||||
end
|
||||
|
||||
path_alias (a_source: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Path alias associated with `a_source' or the source itself.
|
||||
do
|
||||
Result := a_source
|
||||
if attached storage.path_alias (Result) as l_path then
|
||||
Result := "/" + l_path
|
||||
end
|
||||
end
|
||||
|
||||
source_of_path_alias (a_alias: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- 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".
|
||||
--| If the alias is bad (i.e does not alias real path), then this function
|
||||
--| returns the alias itself.
|
||||
do
|
||||
Result := a_alias
|
||||
if attached storage.source_of_path_alias (Result) as l_path then
|
||||
Result := l_path
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element Change: Error
|
||||
|
||||
reset_error
|
||||
|
||||
@@ -32,19 +32,10 @@ feature {CMS_API} -- Module Initialization
|
||||
-- Initialize Current module with `api'.
|
||||
require
|
||||
is_enabled: is_enabled
|
||||
is_not_initialized: not is_initialized
|
||||
do
|
||||
-- Redefine to process specific module initialization.
|
||||
is_initialized := True
|
||||
ensure
|
||||
is_initialized: is_initialized
|
||||
end
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_initialized: BOOLEAN
|
||||
-- Is Current module initialized?
|
||||
|
||||
feature {CMS_API} -- Access: API
|
||||
|
||||
module_api: detachable CMS_MODULE_API
|
||||
@@ -75,10 +66,10 @@ feature {CMS_API} -- Module management
|
||||
|
||||
feature -- Router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- Setup url dispatching for Current module.
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Router configuration.
|
||||
require
|
||||
is_initialized: is_initialized
|
||||
is_enabled: is_enabled
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@ inherit
|
||||
undefine
|
||||
requires_proxy
|
||||
redefine
|
||||
execute_default,
|
||||
create_router,
|
||||
router
|
||||
execute_default
|
||||
end
|
||||
|
||||
WSF_FILTERED_SERVICE
|
||||
@@ -84,17 +82,10 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Settings: router
|
||||
|
||||
router: CMS_ROUTER
|
||||
|
||||
create_router
|
||||
-- Create `router'.
|
||||
do
|
||||
create router.make (api, 30)
|
||||
end
|
||||
|
||||
setup_router
|
||||
-- <Precursor>
|
||||
local
|
||||
l_module: CMS_MODULE
|
||||
l_api: like api
|
||||
l_router: like router
|
||||
do
|
||||
@@ -109,7 +100,8 @@ feature -- Settings: router
|
||||
across
|
||||
modules as ic
|
||||
loop
|
||||
ic.item.setup_router (l_router, l_api)
|
||||
l_module := ic.item
|
||||
l_router.import (l_module.router (l_api))
|
||||
end
|
||||
-- Configure files handler.
|
||||
configure_api_file_handler (l_router)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
note
|
||||
description: "Specific version of WSF_ROUTER for CMS component."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_ROUTER
|
||||
|
||||
inherit
|
||||
WSF_ROUTER
|
||||
rename
|
||||
make as make_router
|
||||
redefine
|
||||
path_to_dispatch
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_api: CMS_API; a_capacity: INTEGER)
|
||||
do
|
||||
api := a_api
|
||||
make_router (a_capacity)
|
||||
end
|
||||
|
||||
api: CMS_API
|
||||
|
||||
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'.
|
||||
do
|
||||
Result := api.source_of_path_alias (Precursor (req))
|
||||
end
|
||||
|
||||
end
|
||||
@@ -76,26 +76,6 @@ feature -- Access
|
||||
redirection: detachable READABLE_STRING_8
|
||||
-- Location for eventual redirection.
|
||||
|
||||
feature -- Internationalization (i18n)
|
||||
|
||||
translation (a_text: READABLE_STRING_GENERAL; opts: detachable CMS_API_OPTIONS): STRING_32
|
||||
-- Translated text `a_text' according to expected context (lang, ...)
|
||||
-- and adapt according to options eventually set by `opts'.
|
||||
do
|
||||
to_implement ("Implement i18n support [2015-may]")
|
||||
Result := a_text.as_string_32
|
||||
end
|
||||
|
||||
formatted_string (a_text: READABLE_STRING_GENERAL; args: TUPLE): STRING_32
|
||||
-- Format `a_text' using arguments `args'.
|
||||
--| ex: formatted_string ("hello $1, see page $title.", ["bob", "contact"] -> "hello bob, see page contact"
|
||||
local
|
||||
l_formatter: CMS_STRING_FORMATTER
|
||||
do
|
||||
create l_formatter
|
||||
Result := l_formatter.formatted_string (a_text, args)
|
||||
end
|
||||
|
||||
feature -- API
|
||||
|
||||
api: CMS_API
|
||||
@@ -202,33 +182,16 @@ feature -- Permission
|
||||
has_permission (a_permission: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Does current user has permission `a_permission' ?
|
||||
do
|
||||
api.logger.put_information (generator + ".has_permission", a_permission)
|
||||
Result := user_has_permission (current_user (request), a_permission)
|
||||
end
|
||||
|
||||
has_permissions (a_permission_list: ITERABLE [READABLE_STRING_GENERAL]): BOOLEAN
|
||||
-- Does current user has any of the permissions `a_permission_list' ?
|
||||
do
|
||||
Result := user_has_permissions (current_user (request), a_permission_list)
|
||||
end
|
||||
|
||||
user_has_permission (a_user: detachable CMS_USER; a_permission: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Does `a_user' has permission `a_permission' ?
|
||||
do
|
||||
Result := api.user_has_permission (a_user, a_permission)
|
||||
end
|
||||
|
||||
user_has_permissions (a_user: detachable CMS_USER; a_permission_list: ITERABLE [READABLE_STRING_GENERAL]): BOOLEAN
|
||||
-- Does `a_user' has any of the permissions `a_permission_list' ?
|
||||
do
|
||||
across
|
||||
a_permission_list as ic
|
||||
until
|
||||
Result
|
||||
loop
|
||||
Result := user_has_permission (a_user, ic.item)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Head customization
|
||||
|
||||
add_additional_head_line (s: READABLE_STRING_8; a_allow_duplication: BOOLEAN)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
note
|
||||
description: "Format a text using arguments."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_STRING_FORMATTER
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
formatted_string (a_string: READABLE_STRING_GENERAL; args: TUPLE): STRING_32
|
||||
do
|
||||
Result := i18n_formatter.formatted_string (a_string, args)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
i18n_formatter: I18N_STRING_FORMATTER
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user