Compare commits

...

3 Commits

Author SHA1 Message Date
f80268c1ac Updated CMS_HOOK_BLOCK, to provide a better block_identifiers (CMS_RESPONSE): detachable ITERABLE [READABLE_STRING_8] query, to be implemented by CMS_HOOK_RESPONSE_BLOCK descendants.
Added CONFIG_READER.table_keys: detachable LIST [READABLE_STRING_32].
2016-02-19 00:10:09 +01:00
77e2c28d18 Added logs admin viewer.
Added CMS_SETUP.is_debug: BOOLEAN  (see cms.ini   site.debug setting)
2016-02-19 00:03:15 +01:00
af137629e0 Restored previous template_block* function signatures and made them obsolete.
Added smarty_template_block* functions as new recommended functions.
2016-02-18 16:26:00 +01:00
38 changed files with 697 additions and 83 deletions

View File

@@ -25,6 +25,7 @@
<library name="cms_basic_auth_module" location="..\..\modules\basic_auth\basic_auth-safe.ecf" readonly="false"/> <library name="cms_basic_auth_module" location="..\..\modules\basic_auth\basic_auth-safe.ecf" readonly="false"/>
<library name="cms_blog_module" location="..\..\modules\blog\cms_blog_module-safe.ecf" readonly="false"/> <library name="cms_blog_module" location="..\..\modules\blog\cms_blog_module-safe.ecf" readonly="false"/>
<library name="cms_contact_module" location="..\..\modules\contact\contact-safe.ecf" readonly="false"/> <library name="cms_contact_module" location="..\..\modules\contact\contact-safe.ecf" readonly="false"/>
<library name="cms_custom_block_module" location="..\..\modules\custom_block\custom_block-safe.ecf" readonly="false"/>
<library name="cms_demo_module" location="modules\demo\cms_demo_module-safe.ecf" readonly="false"/> <library name="cms_demo_module" location="modules\demo\cms_demo_module-safe.ecf" readonly="false"/>
<library name="cms_email_service" location="..\..\library\email\email-safe.ecf" readonly="false"/> <library name="cms_email_service" location="..\..\library\email\email-safe.ecf" readonly="false"/>
<library name="cms_feed_aggregator_module" location="..\..\modules\feed_aggregator\feed_aggregator-safe.ecf" readonly="false"/> <library name="cms_feed_aggregator_module" location="..\..\modules\feed_aggregator\feed_aggregator-safe.ecf" readonly="false"/>

View File

@@ -18,3 +18,4 @@ set ROC_CMS_DIR=%~dp0
%ROC_CMD% install --module ..\..\modules\session_auth --dir %ROC_CMS_DIR% %ROC_CMD% install --module ..\..\modules\session_auth --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\taxonomy --dir %ROC_CMS_DIR% %ROC_CMD% install --module ..\..\modules\taxonomy --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\files --dir %ROC_CMS_DIR% %ROC_CMD% install --module ..\..\modules\files --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\custom_block --dir %ROC_CMS_DIR%

View File

@@ -6,6 +6,7 @@ root-dir=site/www
[site] [site]
# General token that could be use for cookies, and related. # General token that could be use for cookies, and related.
id=_EIFFEL_CMS_ id=_EIFFEL_CMS_
#debug=true
# Name of the site, for the title, and eventual message. # Name of the site, for the title, and eventual message.
name=Eiffel CMS name=Eiffel CMS

View File

@@ -0,0 +1,10 @@
{
"blocks": {
"test": {
"title": "Custom block test",
"region": "footer",
"weight": 100,
"conditions": ["path:demo/*"]
}
}
}

View File

@@ -0,0 +1,3 @@
<div>
This is a nice custom block test for site {$sitename/}.
</div>

View File

@@ -77,6 +77,7 @@ feature -- CMS modules
-- Miscellanious -- Miscellanious
a_setup.register_module (create {GOOGLE_CUSTOM_SEARCH_MODULE}.make) a_setup.register_module (create {GOOGLE_CUSTOM_SEARCH_MODULE}.make)
a_setup.register_module (create {CMS_CUSTOM_BLOCK_MODULE}.make)
a_setup.register_module (create {CMS_DEBUG_MODULE}.make) a_setup.register_module (create {CMS_DEBUG_MODULE}.make)
a_setup.register_module (create {CMS_DEMO_MODULE}.make) a_setup.register_module (create {CMS_DEMO_MODULE}.make)

View File

@@ -34,7 +34,7 @@ feature -- Query
end end
resolved_text_list_item (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32] resolved_text_list_item (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32]
-- List of String item associated with key `k', -- List of String items associated with key `k',
-- and expanded values to resolved variables ${varname}. -- and expanded values to resolved variables ${varname}.
do do
if attached text_list_item (k) as lst then if attached text_list_item (k) as lst then
@@ -50,7 +50,7 @@ feature -- Query
end end
resolved_text_table_item (k: READABLE_STRING_GENERAL): detachable STRING_TABLE [READABLE_STRING_32] resolved_text_table_item (k: READABLE_STRING_GENERAL): detachable STRING_TABLE [READABLE_STRING_32]
-- Table of String item associated with key `k', -- Table of String items associated with key `k',
-- and expanded values to resolved variables ${varname}. -- and expanded values to resolved variables ${varname}.
do do
if attached text_table_item (k) as tb then if attached text_table_item (k) as tb then
@@ -71,12 +71,17 @@ feature -- Query
end end
text_list_item (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32] text_list_item (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32]
-- List of String item associated with key `k'. -- List of String items associated with key `k'.
deferred deferred
end end
text_table_item (k: READABLE_STRING_GENERAL): detachable STRING_TABLE [READABLE_STRING_32] text_table_item (k: READABLE_STRING_GENERAL): detachable STRING_TABLE [READABLE_STRING_32]
-- Table of String item associated with key `k'. -- Table of String items associated with key `k'.
deferred
end
table_keys (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32]
-- Keys of table associated with key `k'.
deferred deferred
end end

View File

@@ -163,6 +163,20 @@ feature -- Access: Config Reader
end end
end end
table_keys (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32]
-- <Precursor>
do
if attached {STRING_TABLE [like item]} item (k) as l_list then
create {ARRAYED_LIST [READABLE_STRING_32]} Result.make (l_list.count)
Result.compare_objects
across
l_list as ic
loop
Result.force (ic.key.as_string_32)
end
end
end
integer_item (k: READABLE_STRING_GENERAL): INTEGER integer_item (k: READABLE_STRING_GENERAL): INTEGER
-- Integer item associated with key `k'. -- Integer item associated with key `k'.
do do
@@ -522,7 +536,7 @@ feature {NONE} -- Implementation
invariant invariant
note note
copyright: "2011-2015, Jocelyn Fiat, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -106,6 +106,20 @@ feature -- Access: Config Reader
end end
end end
table_keys (k: READABLE_STRING_GENERAL): detachable LIST [READABLE_STRING_32]
-- <Precursor>
do
if attached {JSON_OBJECT} item (k) as obj then
create {ARRAYED_LIST [READABLE_STRING_32]} Result.make (obj.count)
Result.compare_objects
across
obj as ic
loop
Result.force (ic.key.item)
end
end
end
integer_item (k: READABLE_STRING_GENERAL): INTEGER integer_item (k: READABLE_STRING_GENERAL): INTEGER
-- Integer item associated with key `k'. -- Integer item associated with key `k'.
do do

View File

@@ -85,6 +85,14 @@ feature -- Test
) )
) )
assert ("keys of (table)", attached cfg.table_keys ("table") as tb and then (
tb.i_th (1) ~ {STRING_32} "a" and
tb.i_th (2) ~ {STRING_32} "b" and
tb.i_th (3) ~ {STRING_32} "c" and
tb.i_th (4) ~ {STRING_32} "d"
)
)
if attached cfg.sub_config ("second") as cfg_second then if attached cfg.sub_config ("second") as cfg_second then
assert ("has_item (is)", cfg_second.has_item ("is")) assert ("has_item (is)", cfg_second.has_item ("is"))
assert ("item (is)", attached cfg_second.text_item ("is") as v and then v.same_string_general ("2")) assert ("item (is)", attached cfg_second.text_item ("is") as v and then v.same_string_general ("2"))
@@ -208,6 +216,14 @@ feature -- Test
) )
) )
assert ("keys of (table)", attached cfg.table_keys ("table") as tb and then (
tb.i_th (1) ~ {STRING_32} "a" and
tb.i_th (2) ~ {STRING_32} "b" and
tb.i_th (3) ~ {STRING_32} "c" and
tb.i_th (4) ~ {STRING_32} "d"
)
)
if attached cfg.sub_config ("second") as cfg_second then if attached cfg.sub_config ("second") as cfg_second then
assert ("has_item (is)", cfg_second.has_item ("is")) assert ("has_item (is)", cfg_second.has_item ("is"))
assert ("item (is)", attached cfg_second.text_item ("is") as v and then v.same_string_general ("2")) assert ("item (is)", attached cfg_second.text_item ("is") as v and then v.same_string_general ("2"))

View File

@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
feature -- Access feature -- Access
id: INTEGER id: INTEGER_64
-- Unique identifier of Current. -- Unique identifier of Current.
category: READABLE_STRING_8 category: READABLE_STRING_8
@@ -124,4 +124,7 @@ feature -- Constants
level_info: INTEGER = 7 level_info: INTEGER = 7
level_debug: INTEGER = 8 level_debug: INTEGER = 8
note
copyright: "2011-2016, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -54,6 +54,7 @@ feature -- Access: router
l_user_handler: CMS_USER_HANDLER l_user_handler: CMS_USER_HANDLER
l_role_handler: CMS_ROLE_HANDLER l_role_handler: CMS_ROLE_HANDLER
l_admin_logs_handler: CMS_LOGS_HANDLER
l_admin_cache_handler: CMS_ADMIN_CACHE_HANDLER l_admin_cache_handler: CMS_ADMIN_CACHE_HANDLER
l_admin_export_handler: CMS_ADMIN_EXPORT_HANDLER l_admin_export_handler: CMS_ADMIN_EXPORT_HANDLER
@@ -76,6 +77,11 @@ feature -- Access: router
create l_uri_mapping.make_trailing_slash_ignored ("/admin/roles", l_roles_handler) create l_uri_mapping.make_trailing_slash_ignored ("/admin/roles", l_roles_handler)
a_router.map (l_uri_mapping, a_router.methods_get_post) a_router.map (l_uri_mapping, a_router.methods_get_post)
create l_admin_logs_handler.make (a_api)
create l_uri_mapping.make_trailing_slash_ignored ("/admin/logs", l_admin_logs_handler)
a_router.map (l_uri_mapping, a_router.methods_get)
create l_admin_cache_handler.make (a_api) create l_admin_cache_handler.make (a_api)
create l_uri_mapping.make_trailing_slash_ignored ("/admin/cache", l_admin_cache_handler) create l_uri_mapping.make_trailing_slash_ignored ("/admin/cache", l_admin_cache_handler)
a_router.map (l_uri_mapping, a_router.methods_get_post) a_router.map (l_uri_mapping, a_router.methods_get_post)
@@ -108,6 +114,7 @@ feature -- Security
Result.force ("admin roles") Result.force ("admin roles")
Result.force ("admin modules") Result.force ("admin modules")
Result.force ("install modules") Result.force ("install modules")
Result.force ("view logs")
Result.force ("admin core caches") Result.force ("admin core caches")
Result.force ("clear blocks cache") Result.force ("clear blocks cache")
Result.force ("admin export") Result.force ("admin export")
@@ -148,18 +155,6 @@ feature -- Hooks
-- Per module export permission! -- Per module export permission!
create lnk.make ("Export", "admin/export") create lnk.make ("Export", "admin/export")
admin_lnk.extend (lnk) admin_lnk.extend (lnk)
-- if
-- a_response.has_permission ("access " + {CMS_ADMIN_MODULE}.name) -- Note: admin user has all permissions enabled by default.
-- then
-- lnk := admin_lnk
-- lnk.set_title ("Admin")
-- a_menu_system.management_menu.extend (lnk)
-- elseif admin_lnk.has_children then
-- a_menu_system.management_menu.extend (admin_lnk)
-- end
-- admin_lnk.set_permission_arguments (<<"access " + {CMS_ADMIN_MODULE}.name>>)
end end
end end

View File

@@ -26,6 +26,7 @@ feature -- Process
l_admin_links.force (["core", <<"admin users">>, local_link ("Users", "admin/users"), "View/Edit/Add Users"]) l_admin_links.force (["core", <<"admin users">>, local_link ("Users", "admin/users"), "View/Edit/Add Users"])
l_admin_links.force (["core", <<"admin roles">>, local_link ("Roles", "admin/roles"), "View/Edit/Add Roles"]) l_admin_links.force (["core", <<"admin roles">>, local_link ("Roles", "admin/roles"), "View/Edit/Add Roles"])
l_admin_links.force (["core", <<"admin modules">>, local_link ("Modules", "admin/modules"), "(un)Install modules"]) l_admin_links.force (["core", <<"admin modules">>, local_link ("Modules", "admin/modules"), "(un)Install modules"])
l_admin_links.force (["core", <<"view logs">>, local_link ("Logs", "admin/logs"), "View logs"])
l_admin_links.force (["support", <<"admin cache">>, local_link ("Cache", "admin/cache"), "Clear caches"]) l_admin_links.force (["support", <<"admin cache">>, local_link ("Cache", "admin/cache"), "Clear caches"])
l_admin_links.force (["support", <<"admin export">>, local_link ("Export", "admin/export"), "Export CMS contents, and modules contents."]) l_admin_links.force (["support", <<"admin export">>, local_link ("Export", "admin/export"), "Export CMS contents, and modules contents."])
create categories.make_caseless (3) create categories.make_caseless (3)

View File

@@ -0,0 +1,114 @@
note
description: "[
Handler for a CMS logs in the CMS interface.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_LOGS_HANDLER
inherit
CMS_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
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute (req, res)
end
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_logs: LIST [CMS_LOG]
l_log: CMS_LOG
r: CMS_RESPONSE
l_cat: detachable READABLE_STRING_8
l_lower: INTEGER
l_count: INTEGER
b: STRING
do
if api.has_permission ("view logs") then
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("category") as p_cat then
l_cat := p_cat.value
end
if attached {WSF_STRING} req.query_parameter ("lower") as p_lower and then p_lower.is_integer then
l_lower := p_lower.integer_value
end
if attached {WSF_STRING} req.query_parameter ("count") as p_count and then p_count.is_integer then
l_count := p_count.integer_value
end
l_logs := api.logs (l_cat, l_lower, l_count)
create b.make (100)
b.append ("<ul class=%"logs%">%N")
across
l_logs as ic
loop
l_log := ic.item
b.append ("<li class=%"log-level-"+ l_log.level.out +"%">")
b.append ("[" + l_log.category + "] ")
b.append (l_log.message)
b.append ("%N<p>(date: " + l_log.date.out + ")")
if attached l_log.link as lnk then
b.append (" <a href=%"" + req.script_url (lnk.location) + "%">" + html_encoded (lnk.title) + "</a>")
end
b.append ("</p>%N")
if attached l_log.info as l_info then
b.append ("<pre>" + l_info + "</pre>%N")
end
b.append ("</li>%N")
end
b.append ("</ul>%N")
r.set_main_content (b)
r.set_page_title ("Logs ...")
r.set_title ("Logs")
else
create {FORBIDDEN_ERROR_CMS_RESPONSE} r.make (req, res, api)
end
r.execute
end
end

View File

@@ -210,7 +210,7 @@ feature -- Handler
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
create b.make_empty create b.make_empty
l_user := r.user l_user := r.user
if attached template_block (Current, "account_info", api) as l_tpl_block then if attached smarty_template_block (Current, "account_info", api) as l_tpl_block then
l_tpl_block.set_weight (-10) l_tpl_block.set_weight (-10)
r.add_block (l_tpl_block, "content") r.add_block (l_tpl_block, "content")
else else
@@ -248,7 +248,7 @@ feature -- Handler
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
create b.make_empty create b.make_empty
l_user := r.user l_user := r.user
if attached template_block (Current, "account_edit", api) as l_tpl_block then if attached smarty_template_block (Current, "account_edit", api) as l_tpl_block then
l_tpl_block.set_weight (-10) l_tpl_block.set_weight (-10)
r.add_block (l_tpl_block, "content") r.add_block (l_tpl_block, "content")
else else
@@ -935,7 +935,7 @@ feature {NONE} -- Block views
or else a_response.values.has ("error_email") or else a_response.values.has ("error_email")
) )
then then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
-- l_tpl_block.set_value (a_response.values.item ("error_name"), "error_name") -- l_tpl_block.set_value (a_response.values.item ("error_name"), "error_name")
-- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") -- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email")
-- l_tpl_block.set_value (a_response.values.item ("email"), "email") -- l_tpl_block.set_value (a_response.values.item ("email"), "email")
@@ -951,7 +951,7 @@ feature {NONE} -- Block views
end end
end end
elseif a_response.request.is_post_request_method then elseif a_response.request.is_post_request_method then
if attached template_block (Current, "post_register", a_response.api) as l_tpl_block then if attached smarty_template_block (Current, "post_register", a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")
@@ -965,7 +965,7 @@ feature {NONE} -- Block views
get_block_view_reactivate (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_reactivate (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")
@@ -974,7 +974,7 @@ feature {NONE} -- Block views
end end
elseif a_response.request.is_post_request_method then elseif a_response.request.is_post_request_method then
if a_response.values.has ("error_email") or else a_response.values.has ("is_active") then if a_response.values.has ("error_email") or else a_response.values.has ("is_active") then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
-- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") -- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email")
-- l_tpl_block.set_value (a_response.values.item ("email"), "email") -- l_tpl_block.set_value (a_response.values.item ("email"), "email")
-- l_tpl_block.set_value (a_response.values.item ("is_active"), "is_active") -- l_tpl_block.set_value (a_response.values.item ("is_active"), "is_active")
@@ -985,7 +985,7 @@ feature {NONE} -- Block views
end end
end end
else else
if attached template_block (Current, "post_reactivate", a_response.api) as l_tpl_block then if attached smarty_template_block (Current, "post_reactivate", a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")
@@ -999,7 +999,7 @@ feature {NONE} -- Block views
get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")
@@ -1008,7 +1008,7 @@ feature {NONE} -- Block views
end end
elseif a_response.request.is_post_request_method then elseif a_response.request.is_post_request_method then
if a_response.values.has ("error_email") or else a_response.values.has ("error_username") then if a_response.values.has ("error_email") or else a_response.values.has ("error_username") then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
-- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email") -- l_tpl_block.set_value (a_response.values.item ("error_email"), "error_email")
-- l_tpl_block.set_value (a_response.values.item ("email"), "email") -- l_tpl_block.set_value (a_response.values.item ("email"), "email")
-- l_tpl_block.set_value (a_response.values.item ("error_username"), "error_username") -- l_tpl_block.set_value (a_response.values.item ("error_username"), "error_username")
@@ -1020,7 +1020,7 @@ feature {NONE} -- Block views
end end
end end
else else
if attached template_block (Current, "post_password", a_response.api) as l_tpl_block then if attached smarty_template_block (Current, "post_password", a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")
@@ -1034,7 +1034,7 @@ feature {NONE} -- Block views
get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
-- l_tpl_block.set_value (a_response.values.item ("token"), "token") -- l_tpl_block.set_value (a_response.values.item ("token"), "token")
-- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token") -- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token")
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
@@ -1045,7 +1045,7 @@ feature {NONE} -- Block views
end end
elseif a_response.request.is_post_request_method then elseif a_response.request.is_post_request_method then
if a_response.values.has ("error_token") or else a_response.values.has ("error_password") then if a_response.values.has ("error_token") or else a_response.values.has ("error_password") then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
-- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token") -- l_tpl_block.set_value (a_response.values.item ("error_token"), "error_token")
-- l_tpl_block.set_value (a_response.values.item ("error_password"), "error_password") -- l_tpl_block.set_value (a_response.values.item ("error_password"), "error_password")
-- l_tpl_block.set_value (a_response.values.item ("token"), "token") -- l_tpl_block.set_value (a_response.values.item ("token"), "token")
@@ -1056,7 +1056,7 @@ feature {NONE} -- Block views
end end
end end
else else
if attached template_block (Current, "post_reset", a_response.api) as l_tpl_block then if attached smarty_template_block (Current, "post_reset", a_response.api) as l_tpl_block then
a_response.add_block (l_tpl_block, "content") a_response.add_block (l_tpl_block, "content")
else else
debug ("cms") debug ("cms")

View File

@@ -118,7 +118,7 @@ feature {NONE} -- Implementation: routes
r.add_error_message ("You are already signed in!") r.add_error_message ("You are already signed in!")
r.set_main_content (r.link ("Logout", "account/roc-logout", Void)) r.set_main_content (r.link ("Logout", "account/roc-logout", Void))
else else
if attached template_block (Current, "login", api) as l_tpl_block then if attached smarty_template_block (Current, "login", api) as l_tpl_block then
r.add_javascript_url (r.url ("module/" + name + "/files/js/roc_basic_auth.js", Void)) r.add_javascript_url (r.url ("module/" + name + "/files/js/roc_basic_auth.js", Void))
create vals.make (1) create vals.make (1)
@@ -170,7 +170,7 @@ feature {NONE} -- Block views
local local
vals: CMS_VALUE_TABLE vals: CMS_VALUE_TABLE
do do
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1) create vals.make (1)
-- add the variable to the block -- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response) a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -181,7 +181,7 @@ feature -- Hooks
if a_block_id.is_case_insensitive_equal_general ("contact") then if a_block_id.is_case_insensitive_equal_general ("contact") then
-- "contact", "post_contact" -- "contact", "post_contact"
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
if attached recaptcha_site_key (a_response.api) as l_recaptcha_site_key then if attached recaptcha_site_key (a_response.api) as l_recaptcha_site_key then
l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key") l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key")
end end
@@ -201,7 +201,7 @@ feature -- Hooks
f: CMS_FORM f: CMS_FORM
do do
a_response.add_style (a_response.url ("/module/" + name + "/files/css/contact.css", Void), Void) a_response.add_style (a_response.url ("/module/" + name + "/files/css/contact.css", Void), Void)
if attached template_block (Current, "contact", api) as l_tpl_block then if attached smarty_template_block (Current, "contact", api) as l_tpl_block then
if attached recaptcha_site_key (api) as l_recaptcha_site_key then if attached recaptcha_site_key (api) as l_recaptcha_site_key then
l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key") l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key")
end end
@@ -339,7 +339,7 @@ feature -- Hooks
r.values.force (True, "has_error") r.values.force (True, "has_error")
vars.put ("True", "has_error") vars.put ("True", "has_error")
end end
if attached template_block_with_values (Current, "post_contact", api, vars) as l_tpl_block then if attached smarty_template_block_with_values (Current, "post_contact", api, vars) as l_tpl_block then
across across
r.values as tb r.values as tb
loop loop
@@ -354,7 +354,7 @@ feature -- Hooks
-- send a bad request status code and redisplay the form with the previous data loaded. -- send a bad request status code and redisplay the form with the previous data loaded.
r.set_value (False, "error") r.set_value (False, "error")
r.set_status_code ({HTTP_STATUS_CODE}.bad_request) r.set_status_code ({HTTP_STATUS_CODE}.bad_request)
if attached template_block_with_values (Current, "contact", api, vars) as l_tpl_block then if attached smarty_template_block_with_values (Current, "contact", api, vars) as l_tpl_block then
across across
r.values as tb r.values as tb
loop loop
@@ -377,7 +377,7 @@ feature -- Hooks
write_error_log (generator + ".handle_post_contact: Internal Server error") write_error_log (generator + ".handle_post_contact: Internal Server error")
r.values.force (True, "has_error") r.values.force (True, "has_error")
r.set_status_code ({HTTP_CONSTANTS}.internal_server_error) r.set_status_code ({HTTP_CONSTANTS}.internal_server_error)
if attached template_block_with_values (Current, "post_contact", api, vars) as l_tpl_block then if attached smarty_template_block_with_values (Current, "post_contact", api, vars) as l_tpl_block then
across across
r.values as tb r.values as tb
loop loop

View File

@@ -0,0 +1,165 @@
note
description: "[
Module that provide custom block factory.
]"
author: "$Author: jfiat $"
date: "$Date: 2016-01-08 22:43:12 +0100 (ven., 08 janv. 2016) $"
revision: "$Revision: 98369 $"
class
CMS_CUSTOM_BLOCK_MODULE
inherit
CMS_MODULE
rename
module_api as custom_block_api
redefine
initialize,
setup_hooks,
custom_block_api
end
CMS_HOOK_RESPONSE_BLOCK
CMS_HOOK_BLOCK_HELPER
CMS_HOOK_AUTO_REGISTER
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
REFACTORING_HELPER
create
make
feature {NONE} -- Initialization
make
-- Create current module
do
version := "1.0"
description := "Custom Block"
package := "layout"
end
feature -- Access
name: STRING = "custom_block"
-- <Precursor>
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)
-- Initialize Current module with `api'.
do
create custom_block_api.make (api)
Precursor (api)
end
custom_block_api: detachable CMS_MODULE_API
-- <Precursor>.
feature -- Router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- Router configuration.
do
end
feature -- Hooks configuration
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- Module hooks configuration.
do
auto_subscribe_to_hooks (a_hooks)
a_hooks.subscribe_to_block_hook (Current)
end
feature -- Hooks
block_identifiers (a_response: detachable CMS_RESPONSE): detachable ARRAYED_LIST [READABLE_STRING_8]
-- <Precursor>
local
api: CMS_API
l_name: READABLE_STRING_32
l_block_id: READABLE_STRING_8
l_conds: detachable ARRAYED_LIST [CMS_BLOCK_CONDITION]
do
if attached custom_block_api as l_mod_api then
api := l_mod_api.cms_api
if
attached api.module_configuration (Current, name) as cfg and then
attached cfg.table_keys ("blocks") as lst
then
create Result.make (0)
across
lst as ic
loop
l_name := ic.item
if l_name.is_valid_as_string_8 then
l_block_id := l_name.to_string_8
if a_response /= Void then
if attached cfg.text_list_item ("blocks." + l_block_id + ".conditions") as l_cond_expressions then
if l_conds = Void then
create l_conds.make (l_cond_expressions.count)
end
across
l_cond_expressions as exp_ic
loop
l_conds.force (create {CMS_BLOCK_EXPRESSION_CONDITION}.make (exp_ic.item))
end
end
if l_conds = Void or else l_conds.is_empty then
Result.force ("?" + l_block_id)
elseif are_conditions_satisfied (l_conds, a_response) then
Result.force (l_block_id)
end
else
Result.force ("?" + l_block_id)
end
end
end
end
end
end
are_conditions_satisfied (a_conditions: LIST [CMS_BLOCK_CONDITION]; a_response: CMS_RESPONSE): BOOLEAN
-- Are `a_conditions' satisfied for `a_response'?
do
Result := across a_conditions as ic some ic.item.satisfied_for_response (a_response) end
end
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
l_region: detachable READABLE_STRING_8
l_cond: CMS_BLOCK_EXPRESSION_CONDITION
do
if attached smarty_template_block (Current, a_block_id, a_response.api) as bk then
if attached a_response.api.module_configuration (Current, name) as cfg then
if
attached cfg.text_item ("blocks." + a_block_id + ".region") as s and then
s.is_valid_as_string_8
then
l_region := s.to_string_8
end
bk.set_weight (cfg.integer_item ("blocks." + a_block_id + ".weight"))
bk.set_title (cfg.text_item ("blocks." + a_block_id + ".title"))
if attached cfg.text_list_item ("blocks." + a_block_id + ".conditions") as l_cond_exp_list then
across
l_cond_exp_list as ic
loop
create l_cond.make (ic.item)
bk.add_condition (l_cond)
end
end
end
a_response.add_block (bk, l_region)
else
a_response.add_debug_message ("Missing template for custom block %"" + a_block_id + "%"!")
end
end
end

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="custom_block_module" uuid="F9B7C390-04F2-4E59-9040-00DD68A5BDBC" library_target="custom_block_module">
<target name="custom_block_module">
<root all_classes="true" />
<file_rule>
<exclude>/.svn$</exclude>
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\cms-safe.ecf"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
<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_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="custom_block_module" uuid="F9B7C390-04F2-4E59-9040-00DD68A5BDBC" library_target="custom_block_module">
<target name="custom_block_module">
<root all_classes="true"/>
<file_rule>
<exclude>/.svn$</exclude>
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="cms" location="..\..\cms.ecf"/>
<library name="cms_model" location="..\..\library\model\cms_model.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
<library name="wsf_encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,10 @@
{
"blocks": {
"test": {
"title": "Custom block test",
"region": "footer",
"weight": 100,
"conditions": ["path:demo/*"]
}
}
}

View File

@@ -0,0 +1,3 @@
<div>
This is a nice custom block test for site {$sitename/}.
</div>

View File

@@ -114,7 +114,7 @@ feature -- Handler
attached l_search.last_result as l_result and then attached l_search.last_result as l_result and then
l_result.status = 200 l_result.status = 200
then then
if attached template_block (Current, "search", api) as l_tpl_block then if attached smarty_template_block (Current, "search", api) as l_tpl_block then
l_tpl_block.set_value (l_result, "result") l_tpl_block.set_value (l_result, "result")
r.add_block (l_tpl_block, "content") r.add_block (l_tpl_block, "content")
end end

View File

@@ -243,7 +243,7 @@ feature -- Hooks
a_response.location.same_string ("account") a_response.location.same_string ("account")
then then
if if
attached template_block (Current, "account_info", a_response.api) as l_tpl_block and then attached smarty_template_block (Current, "account_info", a_response.api) as l_tpl_block and then
attached a_response.user as l_user attached a_response.user as l_user
then then
associate_account (l_user, a_response.values) associate_account (l_user, a_response.values)
@@ -323,7 +323,7 @@ feature {NONE} -- Block views
local local
vals: CMS_VALUE_TABLE vals: CMS_VALUE_TABLE
do do
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1) create vals.make (1)
-- add the variable to the block -- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response) a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -270,7 +270,7 @@ feature {NONE} -- Block views
local local
vals: CMS_VALUE_TABLE vals: CMS_VALUE_TABLE
do do
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1) create vals.make (1)
-- add the variable to the block -- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response) a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -141,7 +141,7 @@ feature {NONE} -- Implementation: routes
if api.user_is_authenticated then if api.user_is_authenticated then
r.add_error_message ("You are already signed in!") r.add_error_message ("You are already signed in!")
else else
if attached template_block (Current, "login", api) as l_tpl_block then if attached smarty_template_block (Current, "login", api) as l_tpl_block then
create vals.make (1) create vals.make (1)
-- add the variable to the block -- add the variable to the block
l_tpl_block.set_value (api.user, "user") l_tpl_block.set_value (api.user, "user")
@@ -223,7 +223,7 @@ feature {NONE} -- Implementation: routes
end end
else else
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if attached template_block (Current, "login", api) as l_tpl_block then if attached smarty_template_block (Current, "login", api) as l_tpl_block then
l_tpl_block.set_value (l_username.value, "username") l_tpl_block.set_value (l_username.value, "username")
l_tpl_block.set_value ("Wrong: Username or password ", "error") l_tpl_block.set_value ("Wrong: Username or password ", "error")
r.add_block (l_tpl_block, "content") r.add_block (l_tpl_block, "content")
@@ -232,7 +232,7 @@ feature {NONE} -- Implementation: routes
r.execute r.execute
else else
create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api) create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api)
if attached template_block (Current, "login", api) as l_tpl_block then if attached smarty_template_block (Current, "login", api) as l_tpl_block then
if attached {WSF_STRING} req.form_parameter ("username") as l_username then if attached {WSF_STRING} req.form_parameter ("username") as l_username then
l_tpl_block.set_value (l_username.value, "username") l_tpl_block.set_value (l_username.value, "username")
end end
@@ -272,7 +272,7 @@ feature {NONE} -- Block views
local local
vals: CMS_VALUE_TABLE vals: CMS_VALUE_TABLE
do do
if attached template_block (Current, a_block_id, a_response.api) as l_tpl_block then if attached smarty_template_block (Current, a_block_id, a_response.api) as l_tpl_block then
create vals.make (1) create vals.make (1)
-- add the variable to the block -- add the variable to the block
a_response.api.hooks.invoke_value_table_alter (vals, a_response) a_response.api.hooks.invoke_value_table_alter (vals, a_response)

View File

@@ -20,6 +20,9 @@ feature {NONE} -- Initialization
do do
site_location := environment.path site_location := environment.path
-- Debug mode.
is_debug := attached string_8_item ("site.debug") as l_debug and then l_debug.is_case_insensitive_equal_general ("yes")
--| Site id, used to identified a site, this could be set to a uuid, or else --| Site id, used to identified a site, this could be set to a uuid, or else
site_id := string_8_item_or_default ("site.id", "_ROC_CMS_NO_ID_") site_id := string_8_item_or_default ("site.id", "_ROC_CMS_NO_ID_")
@@ -259,6 +262,11 @@ feature -- Access: Site
-- Optional path defining the front page. -- Optional path defining the front page.
-- By default "" or "/". -- By default "" or "/".
feature -- Settings
is_debug: BOOLEAN
-- Is debug mode enabled?
feature -- Query feature -- Query
text_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32 text_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32

View File

@@ -1,6 +1,6 @@
note note
description: "[ description: "[
Hook providing a way to alter a block. Hook providing a way to provide blocks.
]" ]"
date: "$Date: 2014-11-19 20:00:19 +0100 (mer., 19 nov. 2014) $" date: "$Date: 2014-11-19 20:00:19 +0100 (mer., 19 nov. 2014) $"
revision: "$Revision: 96123 $" revision: "$Revision: 96123 $"
@@ -13,13 +13,21 @@ inherit
feature -- Hook feature -- Hook
block_list: ITERABLE [like {CMS_BLOCK}.name] block_list: detachable ITERABLE [like {CMS_BLOCK}.name]
-- List of block names, managed by current object. -- List of block names, managed by current object.
-- If prefixed by "?", condition will be check -- If prefixed by "?", condition will be checked
-- to determine if it should be displayed (and computed) or not. -- to determine if it should be displayed (and computed) or not.
deferred deferred
end end
block_identifiers (a_response: detachable CMS_RESPONSE): detachable ITERABLE [like {CMS_BLOCK}.name]
-- List of block names, managed by current object, in the context of `a_response' if set.
-- If prefixed by "?", condition will be checked
-- to determine if it should be displayed (and computed) or not.
do
Result := block_list
end
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
-- Get block object identified by `a_block_id' and associate with `a_response'. -- Get block object identified by `a_block_id' and associate with `a_response'.
deferred deferred

View File

@@ -8,7 +8,7 @@ deferred class
feature {NONE} -- Factory feature {NONE} -- Factory
template_block (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API): detachable CMS_SMARTY_TEMPLATE_BLOCK smarty_template_block (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API): detachable CMS_SMARTY_TEMPLATE_BLOCK
-- Smarty content block for `a_block_id' in the context of `a_module' and `a_cms_api'. -- Smarty content block for `a_block_id' in the context of `a_module' and `a_cms_api'.
local local
res: PATH res: PATH
@@ -26,11 +26,11 @@ feature {NONE} -- Factory
end end
end end
template_block_with_values (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API; a_values: STRING_TABLE [ANY]): like template_block smarty_template_block_with_values (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_cms_api: CMS_API; a_values: STRING_TABLE [ANY]): like smarty_template_block
-- Smarty content block for `a_block_id' in the context of `a_module' and `a_cms_api', -- Smarty content block for `a_block_id' in the context of `a_module' and `a_cms_api',
-- With additional `a_values'. -- With additional `a_values'.
do do
Result := template_block (a_module, a_block_id, a_cms_api) Result := smarty_template_block (a_module, a_block_id, a_cms_api)
if Result /= Void then if Result /= Void then
across across
a_values as ic a_values as ic
@@ -40,6 +40,25 @@ feature {NONE} -- Factory
end end
end end
feature {NONE} -- Factory: obsolete
template_block (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
-- Smarty content block for `a_block_id' in the context of `a_module' and `a_response'.
obsolete
"Use smarty_template_block [Feb/2016]"
do
Result := smarty_template_block (a_module, a_block_id, a_response.api)
end
template_block_with_values (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE; a_values: STRING_TABLE [ANY]): like smarty_template_block
-- Smarty content block for `a_block_id' in the context of `a_module' and `a_response',
-- With additional `a_values'.
obsolete
"Use smarty_template_block_with_values [Feb/2016]"
do
Result := smarty_template_block_with_values (a_module, a_block_id, a_response.api, a_values)
end
note note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -150,9 +150,12 @@ feature -- Hook: block
across across
lst as c lst as c
loop loop
if attached {CMS_HOOK_BLOCK} c.item as h then if
attached {CMS_HOOK_BLOCK} c.item as h and then
attached h.block_identifiers (a_response) as l_names
then
across across
h.block_list as blst l_names as blst
loop loop
bl := blst.item bl := blst.item
bl_optional := bl.count > 0 and bl[1] = '?' bl_optional := bl.count > 0 and bl[1] = '?'
@@ -252,6 +255,6 @@ feature -- Hook: export
end end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -0,0 +1,45 @@
note
description: "[
Hook providing a way to provide blocks,
within the context of a response.
]"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HOOK_RESPONSE_BLOCK
inherit
CMS_HOOK_BLOCK
rename
block_identifiers as old_block_identifiers
redefine
old_block_identifiers
end
feature -- Hook
frozen block_list: detachable ITERABLE [like {CMS_BLOCK}.name]
-- List of block names, managed by current object.
-- If prefixed by "?", condition will be checked
-- to determine if it should be displayed (and computed) or not.
do
Result := block_identifiers (Void)
end
frozen old_block_identifiers (a_response: detachable CMS_RESPONSE): detachable ITERABLE [like {CMS_BLOCK}.name]
do
Result := block_identifiers (a_response)
end
block_identifiers (a_response: detachable CMS_RESPONSE): detachable ITERABLE [like {CMS_BLOCK}.name]
-- List of block names, managed by current object, in the context of `a_response' if set.
-- If prefixed by "?", condition will be checked
-- to determine if it should be displayed (and computed) or not.
deferred
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -15,7 +15,7 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_exp: READABLE_STRING_8) make (a_exp: READABLE_STRING_GENERAL)
do do
expression := a_exp expression := a_exp
end end
@@ -30,18 +30,18 @@ feature -- Access
description: STRING_32 description: STRING_32
do do
create Result.make_from_string_general ("Expression: %"") create Result.make_from_string_general ("Expression: %"")
Result.append_string_general (expression) Result.append_string_general (expression.as_string_32)
Result.append_character ('%"') Result.append_character ('%"')
end end
expression: STRING expression: READABLE_STRING_GENERAL
feature -- Evaluation feature -- Evaluation
satisfied_for_response (res: CMS_RESPONSE): BOOLEAN satisfied_for_response (res: CMS_RESPONSE): BOOLEAN
local local
exp: like expression exp: like expression
l_path: READABLE_STRING_8 l_path: READABLE_STRING_GENERAL
kmp: KMP_WILD kmp: KMP_WILD
do do
exp := expression exp := expression
@@ -61,12 +61,12 @@ feature -- Evaluation
Result := kmp.pattern_matches Result := kmp.pattern_matches
end end
else else
Result := res.location.same_string (l_path) Result := l_path.same_string (res.location)
end end
end end
end end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -93,6 +93,14 @@ feature -- Logs
do do
end end
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
-- List of recent logs from `a_lower' to `a_lower+a_count'.
-- If `a_category' is set, filter to return only associated logs.
-- If `a_count' <= 0 then, return all logs.
do
create {ARRAYED_LIST [CMS_LOG]} Result.make (0)
end
feature -- Custom feature -- Custom
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8) set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
@@ -128,6 +136,6 @@ feature -- Custom
end end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -59,6 +59,13 @@ feature -- Logs
deferred deferred
end end
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
-- List of recent logs from `a_lower' to `a_lower+a_count'.
-- If `a_category' is set, filter to return only associated logs.
-- If `a_count' <= 0 then, return all logs.
deferred
end
feature -- Misc feature -- Misc
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8) set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
@@ -82,6 +89,6 @@ feature -- Misc
end end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -206,9 +206,94 @@ feature -- Logs
sql_finalize sql_finalize
end end
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): ARRAYED_LIST [CMS_LOG]
-- <Precursor>.
local
l_parameters: detachable STRING_TABLE [detachable ANY]
l_sql: READABLE_STRING_8
do
error_handler.reset
create l_parameters.make (3)
if a_category /= Void then
l_parameters.put (a_category, "category")
l_sql := sql_select_categorized_logs
else
l_sql := sql_select_logs
end
if a_count > 0 then
l_parameters.put (a_lower, "offset")
l_parameters.put (a_count, "size")
check l_sql.ends_with_general (";") end
l_sql := l_sql.substring (1, l_sql.count - 1) -- Remove ';'
+ "LIMIT :size OFFSET :offset ;"
end
from
if a_count > 0 then
create Result.make (a_count)
else
create Result.make (10)
end
if l_parameters.is_empty then
l_parameters := Void
end
sql_query (l_sql, l_parameters)
sql_start
until
sql_after
loop
if attached fetch_log as l_log then
Result.force (l_log)
end
sql_forth
end
sql_finalize
end
fetch_log: detachable CMS_LOG
-- SQL: 1:id, 2:category, 3:level, 4:uid, 5:message, 6:info, 7:link, 8:date
local
l_cat: detachable READABLE_STRING_8
l_mesg: detachable READABLE_STRING_8
l_level: INTEGER
l_date: detachable DATE_TIME
i: INTEGER
lnk: CMS_LOCAL_LINK
do
l_cat := sql_read_string (2)
l_mesg := sql_read_string (5)
l_level := sql_read_integer_32 (3)
l_date := sql_read_date_time (8)
if l_cat = Void then
l_cat := "unknown"
end
if l_mesg = Void then
l_mesg := ""
end
create Result.make (l_cat, l_mesg, l_level, l_date)
Result.set_id (sql_read_integer_64 (1))
Result.set_info (sql_read_string (6))
if attached sql_read_string_32 (7) as l_link_text then
-- Format: "[title](location)"
i := l_link_text.index_of ('(', 1)
if i > 0 then
create lnk.make (l_link_text.substring (2, i - 2), l_link_text.substring (i + 1, l_link_text.count - 1))
Result.set_link (lnk)
end
end
end
sql_insert_log: STRING = "INSERT INTO logs (category, level, uid, message, info, link, date) VALUES (:category, :level, :uid, :message, :info, :link, :date);" sql_insert_log: STRING = "INSERT INTO logs (category, level, uid, message, info, link, date) VALUES (:category, :level, :uid, :message, :info, :link, :date);"
-- SQL Insert to add a new node. -- SQL Insert to add a new node.
sql_select_logs: STRING = "SELECT id, category, level, uid, message, info, link, date FROM logs ORDER by date DESC;"
-- SQL Insert to add a new node.
sql_select_categorized_logs: STRING = "SELECT id, category, level, uid, message, info, link, date FROM logs WHERE category=:category ORDER by date DESC;"
-- SQL Insert to add a new node.
feature -- Misc feature -- Misc
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8) set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
@@ -326,6 +411,6 @@ feature -- Misc
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -170,6 +170,14 @@ feature -- Access
storage: CMS_STORAGE storage: CMS_STORAGE
-- Default persistence storage. -- Default persistence storage.
feature -- Settings
is_debug: BOOLEAN
-- Is debug mode enabled?
do
Result := setup.is_debug
end
feature {NONE} -- Access: request feature {NONE} -- Access: request
request: WSF_REQUEST request: WSF_REQUEST
@@ -261,6 +269,14 @@ feature -- Status Report
feature -- Logging feature -- Logging
logs (a_category: detachable READABLE_STRING_8; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
-- List of recent logs from `a_lower' to `a_lower+a_count'.
-- If `a_category' is set, filter to return only associated logs.
-- If `a_count' <= 0 then, return all logs.
do
Result := storage.logs (a_category, a_lower, a_count)
end
log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK) log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK)
local local
l_log: CMS_LOG l_log: CMS_LOG
@@ -674,11 +690,16 @@ feature -- Environment/ module
create {INI_CONFIG} Result.make_from_file (l_path) create {INI_CONFIG} Result.make_from_file (l_path)
end end
end end
if Result = Void and a_name /= Void then if Result = Void then
-- Use sub config from default? if
if attached {CONFIG_READER} module_configuration_by_name_in_location (a_module_name, a_dir, Void) as cfg then a_name /= Void and then
attached {CONFIG_READER} module_configuration_by_name_in_location (a_module_name, a_dir, Void) as cfg
then
-- Use sub config from default.
Result := cfg.sub_config (a_name) Result := cfg.sub_config (a_name)
end end
elseif Result.has_error then
log ("modules", "module configuration has error %"" + p.utf_8_name + "%"", {CMS_LOG}.level_error, Void)
end end
end end

View File

@@ -3,9 +3,12 @@ note
date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $" date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96620 $" revision: "$Revision: 96620 $"
deferred class class
CMS_MODULE_API CMS_MODULE_API
create
make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_api: CMS_API) make (a_api: CMS_API)
@@ -67,6 +70,6 @@ feature -- Bridge to CMS API
end end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -992,6 +992,13 @@ feature -- Message
m.append (a_msg + "</li>") m.append (a_msg + "</li>")
end end
add_debug_message (a_msg: READABLE_STRING_8)
do
if api.is_debug then
add_message (a_msg, "debug")
end
end
add_notice_message (a_msg: READABLE_STRING_8) add_notice_message (a_msg: READABLE_STRING_8)
do do
add_message (a_msg, "notice") add_message (a_msg, "notice")