PageRenderTime 34ms CodeModel.GetById 12ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

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