/modules/mod_seo/resources/resource_admin_seo.erl

https://code.google.com/p/zotonic/ · Erlang · 72 lines · 41 code · 14 blank · 17 comment · 0 complexity · a55b96c4e0090f06de266e24104b9e87 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% Date: 2009-08-07
  4. %% @doc Page with all SEO settings.
  5. %% Copyright 2009 Marc Worrell
  6. %%
  7. %% Licensed under the Apache License, Version 2.0 (the "License");
  8. %% you may not use this file except in compliance with the License.
  9. %% You may obtain a copy of the License at
  10. %%
  11. %% http://www.apache.org/licenses/LICENSE-2.0
  12. %%
  13. %% Unless required by applicable law or agreed to in writing, software
  14. %% distributed under the License is distributed on an "AS IS" BASIS,
  15. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. %% See the License for the specific language governing permissions and
  17. %% limitations under the License.
  18. -module(resource_admin_seo).
  19. -author("Marc Worrell <marc@worrell.nl>").
  20. -export([
  21. is_authorized/2,
  22. event/2
  23. ]).
  24. -include_lib("resource_html.hrl").
  25. is_authorized(ReqData, Context) ->
  26. z_acl:wm_is_authorized(use, mod_seo, ReqData, Context).
  27. html(Context) ->
  28. Vars = [
  29. {page_admin_seo, true}
  30. ],
  31. Html = z_template:render("admin_seo.tpl", Vars, Context),
  32. z_context:output(Html, Context).
  33. event({submit, admin_seo, _TriggerId, _TargetId}, Context) ->
  34. case z_acl:is_allowed(use, mod_seo, Context) of
  35. true ->
  36. save_settings(z_context:get_q_all(Context), Context),
  37. z_render:growl("Saved the SEO settings.", Context);
  38. false ->
  39. z_render:growl("You don't have permission to change the SEO settings.", Context)
  40. end.
  41. save_settings([], Context) ->
  42. Context;
  43. save_settings([{"seo" ++ _ = Key, Value} | T], Context) ->
  44. Value1 = clean(string:strip(Value, both), []),
  45. [Key1, Key2] = string:tokens(Key, "-"),
  46. m_config:set_value(list_to_atom(Key1), list_to_atom(Key2), Value1, Context),
  47. m_config:set_prop(list_to_atom(Key1), list_to_atom(Key2), no_config_edit, true, Context),
  48. save_settings(T, Context);
  49. save_settings([_|T], Context) ->
  50. save_settings(T, Context).
  51. clean([], Acc) ->
  52. lists:reverse(Acc);
  53. clean([H|T], Acc) when
  54. H =:= 10 orelse H =:= 13 orelse H =:= $" orelse H =:= $' orelse
  55. H =:= $& orelse H =:= $< orelse H =:= $> ->
  56. clean(T, [32|Acc]);
  57. clean([H|T], Acc) ->
  58. clean(T, [H|Acc]).