Updated CMS code.
Separated code to have a lib and an example. Improved design, fixed a few issues related to folder location. This is still experimental and require more work to be really friendly to use.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description : "[
|
||||
Filtered html format
|
||||
]"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FILTERED_HTML_FORMAT
|
||||
|
||||
inherit
|
||||
CMS_FORMAT
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create filters.make (3)
|
||||
filters.force (create {CMS_URL_FILTER})
|
||||
filters.force (create {CMS_HTML_FILTER})
|
||||
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
|
||||
|
||||
-- help := "<ul><li>Web page addresses and e-mail addresses turn into links automatically.</li><li>Allowed HTML tags: "
|
||||
-- across
|
||||
-- allowed_html_tags as c
|
||||
-- loop
|
||||
-- help.append ("<" + c.item + "> ")
|
||||
-- end
|
||||
-- help.append ("</li><li>Lines and paragraphs break automatically.</li></ul>")
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "filtered_html"
|
||||
|
||||
title: STRING_8 = "Filtered HTML"
|
||||
|
||||
filters: ARRAYED_LIST [CMS_FILTER]
|
||||
|
||||
end
|
||||
46
draft/application/cms/src/kernel/content/format/cms_format.e
Normal file
46
draft/application/cms/src/kernel/content/format/cms_format.e
Normal file
@@ -0,0 +1,46 @@
|
||||
note
|
||||
description: "Summary description for {WSF_CMS_FORMAT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_FORMAT
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING
|
||||
deferred
|
||||
end
|
||||
|
||||
title: READABLE_STRING_8
|
||||
deferred
|
||||
end
|
||||
|
||||
help: STRING
|
||||
do
|
||||
create Result.make (0)
|
||||
across
|
||||
filters as c
|
||||
loop
|
||||
if attached c.item.help as h and then not h.is_empty then
|
||||
Result.append ("<li>" + h + "</li>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
filters: LIST [CMS_FILTER]
|
||||
deferred
|
||||
end
|
||||
|
||||
to_html (a_text: READABLE_STRING_8): STRING_8
|
||||
do
|
||||
create Result.make_from_string (a_text)
|
||||
across
|
||||
filters as c
|
||||
loop
|
||||
c.item.filter (Result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FORMATS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FORMATS
|
||||
|
||||
feature -- Access
|
||||
|
||||
format (a_name: like {CMS_FORMAT}.name): detachable CMS_FORMAT
|
||||
do
|
||||
across
|
||||
all_formats as c
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
if c.item.name.same_string (a_name) then
|
||||
Result := c.item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
all_formats: LIST [CMS_FORMAT]
|
||||
once
|
||||
create {ARRAYED_LIST [CMS_FORMAT]} Result.make (3)
|
||||
Result.force (plain_text)
|
||||
Result.force (full_html)
|
||||
Result.force (filtered_html)
|
||||
end
|
||||
|
||||
default_format: CMS_FORMAT
|
||||
do
|
||||
Result := plain_text --FIXME
|
||||
end
|
||||
|
||||
plain_text: CMS_PLAIN_TEXT_FORMAT
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
full_html: CMS_FULL_HTML_FORMAT
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
filtered_html: CMS_FILTERED_HTML_FORMAT
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
note
|
||||
description : "[
|
||||
Full html format
|
||||
]"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FULL_HTML_FORMAT
|
||||
|
||||
inherit
|
||||
CMS_FORMAT
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create filters.make (2)
|
||||
filters.force (create {CMS_URL_FILTER})
|
||||
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "full_html"
|
||||
|
||||
title: STRING_8 = "Full HTML"
|
||||
|
||||
filters: ARRAYED_LIST [CMS_FILTER]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,49 @@
|
||||
note
|
||||
description : "[
|
||||
Plain Text format
|
||||
]"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
CMS_PLAIN_TEXT_FORMAT
|
||||
|
||||
inherit
|
||||
CMS_FORMAT
|
||||
redefine
|
||||
default_create,
|
||||
help
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create filters.make (2)
|
||||
filters.force (create {CMS_HTML_TO_TEXT_FILTER})
|
||||
filters.force (create {CMS_LINE_BREAK_CONVERTER_FILTER})
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "plain_text"
|
||||
|
||||
title: STRING_8 = "Plain text"
|
||||
|
||||
help: STRING
|
||||
do
|
||||
Result := "<li>No HTML tags allowed.</li>"
|
||||
Result.append (Precursor)
|
||||
end
|
||||
-- <ul>
|
||||
-- <li>No HTML tags allowed.</li>
|
||||
-- <li>Web page addresses and e-mail addresses turn into links automatically.</li>
|
||||
-- <li>Lines and paragraphs break automatically.</li>
|
||||
-- </ul>
|
||||
-- ]"
|
||||
|
||||
filters: ARRAYED_LIST [CMS_FILTER]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_FILTER
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: READABLE_STRING_8
|
||||
deferred
|
||||
end
|
||||
|
||||
title: READABLE_STRING_8
|
||||
deferred
|
||||
end
|
||||
|
||||
description: READABLE_STRING_8
|
||||
deferred
|
||||
end
|
||||
|
||||
help: READABLE_STRING_8
|
||||
do
|
||||
Result := description
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (s: STRING_8)
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,126 @@
|
||||
note
|
||||
description: "Summary description for {CMS_HTML_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_HTML_FILTER
|
||||
|
||||
inherit
|
||||
CMS_FILTER
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
allowed_html_tags := <<"a", "em", "strong", "cite", "blockquote", "code", "ul", "ol", "li", "dl">>
|
||||
description := "Allowed HTML tags: "
|
||||
across
|
||||
allowed_html_tags as c
|
||||
loop
|
||||
description.append ("<" + c.item + "> ")
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_8 = "html_filter"
|
||||
|
||||
title: STRING_8 = "HTML filter"
|
||||
|
||||
description: STRING_8
|
||||
|
||||
allowed_html_tags: ITERABLE [READABLE_STRING_8]
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
local
|
||||
l_new: STRING_8
|
||||
i: INTEGER
|
||||
n: INTEGER
|
||||
in_tag: BOOLEAN
|
||||
p1, p2: INTEGER
|
||||
do
|
||||
create l_new.make (a_text.count)
|
||||
from
|
||||
p1 := 1
|
||||
i := a_text.index_of ('<', 1)
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (1, i - 1))
|
||||
end
|
||||
n := a_text.count
|
||||
until
|
||||
i = 0 or i > n
|
||||
loop
|
||||
if a_text[i] = '<' then
|
||||
in_tag := True
|
||||
p1 := i
|
||||
p2 := a_text.index_of ('>', i + 1)
|
||||
if p2 = 0 then
|
||||
-- next '<'
|
||||
i := a_text.index_of ('<', i + 1)
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (p1, i - 1))
|
||||
end
|
||||
else
|
||||
if is_authorized (a_text.substring (p1, p2)) then
|
||||
l_new.append (a_text.substring (p1, p2))
|
||||
i := a_text.index_of ('<', p2 + 1)
|
||||
else
|
||||
i := a_text.index_of ('<', p2 + 1)
|
||||
end
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (p2 + 1, i - 1))
|
||||
end
|
||||
end
|
||||
else
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
l_new.append (a_text.substring (p1, n))
|
||||
a_text.wipe_out
|
||||
a_text.append (l_new)
|
||||
end
|
||||
|
||||
is_authorized (s: READABLE_STRING_8): BOOLEAN
|
||||
-- Is `s' authorized?
|
||||
--| `s' has either "<....>" or "<..../>" or "</.....>"
|
||||
local
|
||||
l_tagname: detachable STRING
|
||||
i,n,p1: INTEGER
|
||||
do
|
||||
-- create l_tagname.make_empty
|
||||
from
|
||||
i := 2 -- skip first '<'
|
||||
n := s.count
|
||||
until
|
||||
i > n or l_tagname /= Void
|
||||
loop
|
||||
if p1 > 0 then
|
||||
if s[i].is_space or s[i] = '/' or s[i] = '>' then
|
||||
l_tagname := s.substring (p1, i - 1)
|
||||
end
|
||||
else
|
||||
if s[i].is_space or s[i] = '/' then
|
||||
else
|
||||
p1 := i
|
||||
end
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
if l_tagname /= Void then
|
||||
l_tagname.to_lower
|
||||
Result := across allowed_html_tags as c some c.item.same_string (l_tagname) end
|
||||
else
|
||||
Result := True
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
note
|
||||
description: "Summary description for {CMS_HTML_TO_TEXT_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_HTML_TO_TEXT_FILTER
|
||||
|
||||
inherit
|
||||
CMS_FILTER
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_8 = "html_to_text"
|
||||
|
||||
title: STRING_8 = "HTML to text"
|
||||
|
||||
description: STRING_8 = "Replaces HTML tags and entities with plain text formatting, moving links at the end. This filter is just for text messages and it isn't safe for rendering content on a web page."
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
local
|
||||
enc: HTML_ENCODER
|
||||
s: STRING_8
|
||||
do
|
||||
create enc
|
||||
s := enc.encoded_string (a_text)
|
||||
a_text.wipe_out
|
||||
a_text.append (s)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
note
|
||||
description: "Summary description for {CMS_HTML_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_LINE_BREAK_CONVERTER_FILTER
|
||||
|
||||
inherit
|
||||
CMS_FILTER
|
||||
redefine
|
||||
help
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_8 = "line_break_converter"
|
||||
|
||||
title: STRING_8 = "Line break converter"
|
||||
|
||||
help: STRING = "Lines and paragraphs break automatically"
|
||||
|
||||
description: STRING_8 = "Converts line breaks into HTML (i.e. <br> and <p> tags)."
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
do
|
||||
a_text.replace_substring_all ("%N", "<br/>%N")
|
||||
-- FIXME jfiat [2012/09/12] :also use <p> ...
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,77 @@
|
||||
note
|
||||
description: "Summary description for {CMS_NO_HTML_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_NO_HTML_FILTER
|
||||
|
||||
inherit
|
||||
CMS_FILTER
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_8 = "no_html_filter"
|
||||
|
||||
title: STRING_8 = "No HTML filter"
|
||||
|
||||
description: STRING_8 = "HTML tags removed! "
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
local
|
||||
l_new: STRING_8
|
||||
i: INTEGER
|
||||
n: INTEGER
|
||||
in_tag: BOOLEAN
|
||||
p1, p2: INTEGER
|
||||
do
|
||||
create l_new.make (a_text.count)
|
||||
from
|
||||
p1 := 1
|
||||
i := a_text.index_of ('<', 1)
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (1, i - 1))
|
||||
end
|
||||
n := a_text.count
|
||||
until
|
||||
i = 0 or i > n
|
||||
loop
|
||||
if a_text[i] = '<' then
|
||||
in_tag := True
|
||||
p1 := i
|
||||
p2 := a_text.index_of ('>', i + 1)
|
||||
if p2 = 0 then
|
||||
-- next '<'
|
||||
i := a_text.index_of ('<', i + 1)
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (p1, i - 1))
|
||||
end
|
||||
else
|
||||
i := a_text.index_of ('<', p2 + 1)
|
||||
if i > 0 then
|
||||
l_new.append (a_text.substring (p2 + 1, i - 1))
|
||||
end
|
||||
end
|
||||
else
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
l_new.append (a_text.substring (p1, n))
|
||||
a_text.wipe_out
|
||||
a_text.append (l_new)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
note
|
||||
description: "Summary description for {CMS_URL_FILTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_URL_FILTER
|
||||
|
||||
inherit
|
||||
CMS_FILTER
|
||||
redefine
|
||||
help
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_8 = "url"
|
||||
|
||||
title: STRING_8 = "URL filter"
|
||||
|
||||
description: STRING_8 = "Turns web and e-mail addresses into clickable links."
|
||||
|
||||
help: STRING = "Web page addresses and e-mail addresses turn into links automatically."
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
do
|
||||
--| FIXME jfiat [2012/09/12] : todo
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user