Added default path alias for node.
Fixed set path alias, when alias already exists in the history.
This commit is contained in:
@@ -367,6 +367,85 @@ feature -- Change: Node
|
|||||||
error_handler.append (node_storage.error_handler)
|
error_handler.append (node_storage.error_handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- path_alias suggestion
|
||||||
|
|
||||||
|
path_alias_uri_suggestion (a_node: detachable CMS_NODE; a_content_type: CMS_CONTENT_TYPE): STRING
|
||||||
|
local
|
||||||
|
dt: DATE_TIME
|
||||||
|
uri: URI
|
||||||
|
do
|
||||||
|
create uri.make_from_string ("/")
|
||||||
|
uri.add_unencoded_path_segment (a_content_type.name)
|
||||||
|
if a_node /= Void then
|
||||||
|
dt := a_node.creation_date
|
||||||
|
else
|
||||||
|
create dt.make_now_utc
|
||||||
|
end
|
||||||
|
if attached cms_api.user as u and then not cms_api.user_api.is_admin_user (u) then
|
||||||
|
uri.add_unencoded_path_segment (cms_api.user_api.user_display_name (u))
|
||||||
|
end
|
||||||
|
uri.add_unencoded_path_segment (dt.year.out)
|
||||||
|
if dt.month <= 9 then
|
||||||
|
uri.add_unencoded_path_segment ("0" + dt.month.out)
|
||||||
|
else
|
||||||
|
uri.add_unencoded_path_segment (dt.month.out)
|
||||||
|
end
|
||||||
|
if a_node /= Void and then attached a_node.title as l_title then
|
||||||
|
uri.add_unencoded_path_segment (safe_path_alias_uri_segment_text (l_title))
|
||||||
|
else
|
||||||
|
uri.add_unencoded_path_segment ("")
|
||||||
|
end
|
||||||
|
|
||||||
|
Result := uri.string
|
||||||
|
end
|
||||||
|
|
||||||
|
safe_path_alias_uri_segment_text (s: READABLE_STRING_GENERAL): STRING_32
|
||||||
|
local
|
||||||
|
i,n: INTEGER
|
||||||
|
c, prev: CHARACTER_32
|
||||||
|
l_words: ITERABLE [READABLE_STRING_GENERAL]
|
||||||
|
w: STRING_32
|
||||||
|
do
|
||||||
|
l_words := << "a", "an", "as", "at", "before", "but", "by", "for", "from", "is", "in", "into", "like", "of", "off", "on", "onto", "per", "since", "than", "the", "this", "that", "to", "up", "via", "with" >>
|
||||||
|
from
|
||||||
|
i := 1
|
||||||
|
n := s.count
|
||||||
|
create Result.make (n)
|
||||||
|
create w.make_empty
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
|
c := s[i].as_lower
|
||||||
|
if c.is_alpha_numeric then
|
||||||
|
w.append_character (c)
|
||||||
|
prev := c
|
||||||
|
else
|
||||||
|
if w.is_empty then
|
||||||
|
-- Ignore
|
||||||
|
else
|
||||||
|
if across l_words as ic some w.same_string_general (ic.item) end then
|
||||||
|
-- Ignore
|
||||||
|
w.wipe_out
|
||||||
|
else
|
||||||
|
if not Result.is_empty then
|
||||||
|
Result.append_character ('-')
|
||||||
|
end
|
||||||
|
Result.append (w)
|
||||||
|
w.wipe_out
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
i := i + 1
|
||||||
|
end
|
||||||
|
if not w.is_empty then
|
||||||
|
if not Result.is_empty then
|
||||||
|
Result.append_character ('-')
|
||||||
|
end
|
||||||
|
Result.append (w)
|
||||||
|
w.wipe_out
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Node status
|
feature -- Node status
|
||||||
|
|
||||||
Not_published: INTEGER = 0
|
Not_published: INTEGER = 0
|
||||||
|
|||||||
@@ -107,10 +107,14 @@ feature -- Forms ...
|
|||||||
populate_form_with_path_alias (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
populate_form_with_path_alias (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
||||||
local
|
local
|
||||||
ti: WSF_FORM_TEXT_INPUT
|
ti: WSF_FORM_TEXT_INPUT
|
||||||
|
thi: WSF_FORM_HIDDEN_INPUT
|
||||||
l_uri: detachable READABLE_STRING_8
|
l_uri: detachable READABLE_STRING_8
|
||||||
l_iri: detachable READABLE_STRING_32
|
l_iri: detachable READABLE_STRING_32
|
||||||
|
l_auto_path_alias: READABLE_STRING_8
|
||||||
do
|
do
|
||||||
-- Path alias
|
-- Path alias
|
||||||
|
l_auto_path_alias := node_api.path_alias_uri_suggestion (a_node, content_type)
|
||||||
|
|
||||||
create ti.make ("path_alias")
|
create ti.make ("path_alias")
|
||||||
ti.set_label ("Path")
|
ti.set_label ("Path")
|
||||||
ti.set_pattern ("^([A-Za-z0-9-_+ ]).+")
|
ti.set_pattern ("^([A-Za-z0-9-_+ ]).+")
|
||||||
@@ -119,13 +123,19 @@ feature -- Forms ...
|
|||||||
if a_node /= Void and then a_node.has_id then
|
if a_node /= Void and then a_node.has_id then
|
||||||
if attached a_node.link as lnk then
|
if attached a_node.link as lnk then
|
||||||
l_uri := lnk.location
|
l_uri := lnk.location
|
||||||
|
if l_uri.same_string (node_api.node_path (a_node)) then
|
||||||
|
l_uri := ""
|
||||||
|
end
|
||||||
else
|
else
|
||||||
l_iri := percent_encoder.percent_decoded_string (response.api.location_alias (response.node_api.node_path (a_node)))
|
l_iri := percent_encoder.percent_decoded_string (response.api.location_alias (response.node_api.node_path (a_node)))
|
||||||
l_uri := l_iri.to_string_8
|
l_uri := l_iri.to_string_8
|
||||||
end
|
end
|
||||||
ti.set_text_value (l_uri)
|
ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed.<br/>%NFor example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.")
|
||||||
ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed. For example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.")
|
else
|
||||||
|
l_uri := ""
|
||||||
end
|
end
|
||||||
|
ti.set_text_value (l_uri)
|
||||||
|
ti.set_placeholder (l_auto_path_alias)
|
||||||
ti.set_validation_action (agent (fd: WSF_FORM_DATA; ia_response: NODE_RESPONSE; ia_node: detachable CMS_NODE)
|
ti.set_validation_action (agent (fd: WSF_FORM_DATA; ia_response: NODE_RESPONSE; ia_node: detachable CMS_NODE)
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
@@ -163,6 +173,11 @@ feature -- Forms ...
|
|||||||
else
|
else
|
||||||
f.extend (ti)
|
f.extend (ti)
|
||||||
end
|
end
|
||||||
|
-- Auto path alias / suggestion
|
||||||
|
create thi.make ("auto_path_alias")
|
||||||
|
thi.set_text_value (l_auto_path_alias)
|
||||||
|
thi.set_is_readonly (True)
|
||||||
|
f.insert_after (thi, ti)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||||
@@ -443,6 +458,4 @@ feature -- Output
|
|||||||
end
|
end
|
||||||
a_output.append ("</li>")
|
a_output.append ("</li>")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ feature -- Form
|
|||||||
l_node: detachable CMS_NODE
|
l_node: detachable CMS_NODE
|
||||||
s: STRING
|
s: STRING
|
||||||
l_node_path: READABLE_STRING_8
|
l_node_path: READABLE_STRING_8
|
||||||
l_path_alias, l_existing_path_alias: detachable READABLE_STRING_8
|
l_path_alias, l_existing_path_alias, l_auto_path_alias: detachable READABLE_STRING_8
|
||||||
do
|
do
|
||||||
fixme ("Refactor code per operacion: Preview, Save")
|
fixme ("Refactor code per operacion: Preview, Save")
|
||||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||||
@@ -301,10 +301,13 @@ feature -- Form
|
|||||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||||
end
|
end
|
||||||
|
|
||||||
if attached fd.string_item ("path_alias") as f_path_alias then
|
-- Path aliase
|
||||||
l_node_path := node_api.node_path (l_node)
|
l_node_path := node_api.node_path (l_node)
|
||||||
l_path_alias := percent_encoder.partial_encoded_string (f_path_alias, <<'/'>>)
|
|
||||||
l_existing_path_alias := api.location_alias (l_node_path)
|
l_existing_path_alias := api.location_alias (l_node_path)
|
||||||
|
|
||||||
|
l_auto_path_alias := node_api.path_alias_uri_suggestion (l_node, a_type)
|
||||||
|
if attached fd.string_item ("path_alias") as f_path_alias then
|
||||||
|
l_path_alias := percent_encoder.partial_encoded_string (f_path_alias, <<'/'>>)
|
||||||
if
|
if
|
||||||
l_existing_path_alias /= Void and then
|
l_existing_path_alias /= Void and then
|
||||||
l_path_alias.same_string (l_existing_path_alias)
|
l_path_alias.same_string (l_existing_path_alias)
|
||||||
@@ -314,7 +317,10 @@ feature -- Form
|
|||||||
elseif l_existing_path_alias /= Void and then l_path_alias.is_whitespace then
|
elseif l_existing_path_alias /= Void and then l_path_alias.is_whitespace then
|
||||||
-- Reset to builtin alias.
|
-- Reset to builtin alias.
|
||||||
if api.has_permission ("edit path_alias") then
|
if api.has_permission ("edit path_alias") then
|
||||||
api.set_path_alias (l_node_path, l_node_path, True)
|
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||||
|
elseif l_existing_path_alias.same_string (l_node_path) then
|
||||||
|
-- not aliased! Use default.
|
||||||
|
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||||
else
|
else
|
||||||
add_error_message ("Permission denied to reset path alias on node #" + l_node.id.out + "!")
|
add_error_message ("Permission denied to reset path alias on node #" + l_node.id.out + "!")
|
||||||
end
|
end
|
||||||
@@ -329,6 +335,12 @@ feature -- Form
|
|||||||
l_node.set_link (node_api.node_link (l_node))
|
l_node.set_link (node_api.node_link (l_node))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif l_existing_path_alias /= Void then
|
||||||
|
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_existing_path_alias))
|
||||||
|
elseif l_auto_path_alias /= Void then
|
||||||
|
-- Use auto path alias
|
||||||
|
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||||
|
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_auto_path_alias))
|
||||||
else
|
else
|
||||||
l_node.set_link (node_api.node_link (l_node))
|
l_node.set_link (node_api.node_link (l_node))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||||
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
|
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
|
||||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||||
|
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri-safe.ecf"/>
|
||||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||||
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
|
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
|
||||||
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf" readonly="false"/>
|
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf" readonly="false"/>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
||||||
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter.ecf"/>
|
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter.ecf"/>
|
||||||
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
||||||
|
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri.ecf"/>
|
||||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
||||||
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension.ecf" readonly="false"/>
|
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension.ecf" readonly="false"/>
|
||||||
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html.ecf" readonly="false"/>
|
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html.ecf" readonly="false"/>
|
||||||
|
|||||||
@@ -24,19 +24,34 @@ feature -- URL aliases
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
|
l_source: like source_of_path_alias
|
||||||
|
l_continue: BOOLEAN
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
|
|
||||||
create l_parameters.make (2)
|
create l_parameters.make (2)
|
||||||
l_parameters.put (a_source, "source")
|
l_parameters.put (a_source, "source")
|
||||||
l_parameters.put (a_alias, "alias")
|
l_parameters.put (a_alias, "alias")
|
||||||
if attached source_of_path_alias (a_alias) as l_path then
|
l_source := source_of_path_alias (a_alias)
|
||||||
if a_source.same_string (l_path) then
|
l_continue := True
|
||||||
|
if
|
||||||
|
l_source /= Void -- Alias exists!
|
||||||
|
then
|
||||||
|
if a_source.same_string (l_source) then
|
||||||
|
if attached path_alias (l_source) as l_alias and then l_alias.same_string (a_alias) then
|
||||||
-- already up to date
|
-- already up to date
|
||||||
|
l_continue := False
|
||||||
else
|
else
|
||||||
error_handler.add_custom_error (0, "alias exists", "Path alias %"" + a_alias + "%" already exists!")
|
-- multiple alias and a_alias is not the default alias
|
||||||
|
-- then unset, and set again !
|
||||||
|
unset_path_alias (a_source, a_alias)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
l_continue := False
|
||||||
|
error_handler.add_custom_error (0, "alias exists", "Path alias %"" + a_alias + "%" already exists!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if l_continue then
|
||||||
sql_insert (sql_insert_path_alias, l_parameters)
|
sql_insert (sql_insert_path_alias, l_parameters)
|
||||||
sql_finalize
|
sql_finalize
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user