Mercurial Hosting > nabble
comparison src/nabble/view/web/embed/EmbedOptions.jtp @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children | 18cf4872fd7f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 <% | |
2 package nabble.view.web.embed; | |
3 | |
4 import fschmidt.util.servlet.AuthorizingServlet; | |
5 import nabble.model.ModelHome; | |
6 import nabble.model.Node; | |
7 import nabble.model.Person; | |
8 import nabble.model.Site; | |
9 import nabble.view.lib.EmbedUtils; | |
10 import nabble.view.lib.Jtp; | |
11 import nabble.view.lib.Shared; | |
12 | |
13 import javax.servlet.ServletException; | |
14 import javax.servlet.http.HttpServlet; | |
15 import javax.servlet.http.HttpServletRequest; | |
16 import javax.servlet.http.HttpServletResponse; | |
17 import java.io.IOException; | |
18 import java.io.PrintWriter; | |
19 | |
20 | |
21 public class EmbedOptions extends HttpServlet implements AuthorizingServlet { | |
22 | |
23 public String getAuthorizationKey(HttpServletRequest request) throws ServletException { | |
24 Site site = Jtp.getSite(request); | |
25 return site==null ? null : Jtp.getReadAuthorizationKey( site.getNode(Jtp.getLong(request,"node")) ); | |
26 } | |
27 | |
28 public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { | |
29 return Jtp.authorizeForRead(key,request,response); | |
30 } | |
31 | |
32 protected void service(HttpServletRequest request, HttpServletResponse response) | |
33 throws ServletException, IOException | |
34 { | |
35 PrintWriter out = response.getWriter(); | |
36 String context = request.getContextPath(); | |
37 Site site = Jtp.getSite(request); | |
38 if( site == null ) | |
39 return; | |
40 String nodeId = request.getParameter("node"); | |
41 if( nodeId == null ) | |
42 return; | |
43 Node node = site.getNode(Long.valueOf(nodeId)); | |
44 if (node == null) | |
45 return; | |
46 | |
47 boolean isForum = node.getKind() == Node.Kind.APP; | |
48 | |
49 Person visitor = Jtp.getVisitor(request, response); | |
50 | |
51 boolean allowed = Jtp.canBeEditedBy(node,visitor); | |
52 if (!allowed && isForum) { | |
53 Jtp.login("Only administrators can proceed in this area.", request, response); | |
54 return; | |
55 } | |
56 | |
57 String action = request.getParameter("action"); | |
58 if ("save".equals(action) && "POST".equals(request.getMethod())) { | |
59 String url = request.getParameter("url"); | |
60 String option = request.getParameter("option"); | |
61 String value = "this".equals(option)? url : null; | |
62 node.setEmbeddingUrl(value); | |
63 if (value != null) | |
64 response.sendRedirect(Jtp.path(node)); | |
65 else | |
66 Shared.javascriptRedirect(request, response, Jtp.path(node), null, true); | |
67 } | |
68 %> | |
69 <html> | |
70 <head> | |
71 <meta name="robots" content="noindex,nofollow"/> | |
72 <% Shared.title(request, response, "Embedding Options"); %> | |
73 </head> | |
74 <body> | |
75 <% Shared.minHeader(request,response, node); %> | |
76 <% Shared.editHeader(node.getSubjectHtml(), "Embedding Options", out); %> | |
77 | |
78 <div class="second-font field-title">Javascript Code</div> | |
79 <div class="weak-color" style="margin-left:1.5em"> | |
80 To add this <%=isForum? Jtp.viewName(node).toLowerCase() : "topic"%> to your website, copy and paste the following code on your HTML page:<br/> | |
81 <textarea style="height:3.5em;width:85%;margin:.3em .3em .3em 0;font-size:80%" readonly="true" onClick="this.focus();this.select();"><%=isForum? EmbedUtils.getForumSnippet(request, node) : EmbedUtils.getTopicSnippet(request, node)%></textarea> | |
82 <br>You can embed this <%=isForum? Jtp.viewName(node).toLowerCase():"topic"%> in more than one website. | |
83 <br>We suggest that you use a custom domain name to avoid third-party cookie problems. | |
84 <br>Please check the <a href="<%=context%>/help/Answer.jtp?id=36">Nabble Help</a> for more information. | |
85 </div> | |
86 | |
87 <% if (isForum) { %> | |
88 <div class="second-font field-title">Redirect Users</div> | |
89 <div id="more" class="weak-color" style="margin-left:1.5em"> | |
90 Redirect options are available only when the <%=Jtp.viewName(node).toLowerCase()%> is embedded. | |
91 </div> | |
92 | |
93 <form id="settings" method="post" action="/embed/EmbedOptions.jtp" accept-charset="UTF-8" style="display:none"> | |
94 <input type="hidden" name="action" value="save" /> | |
95 <input type="hidden" name="node" value="<%=node.getId()%>" /> | |
96 <input type="hidden" id="url" name="url" value="" /> | |
97 | |
98 <div class="weak-color" style="margin:0 0 1em 1.5em"> | |
99 Your embedded <%=Jtp.viewName(node).toLowerCase()%> is hosted on Nabble at this URL: <b><%=Jtp.url(node)%></b><br> | |
100 | |
101 <input type="radio" id="o1" name="option" value="nabble"></input> | |
102 <label for="o1">Allow users to view this <%=Jtp.viewName(node).toLowerCase()%> without embedding.</label><br/> | |
103 | |
104 <input type="radio" id="o2" name="option" value="this"></input> | |
105 <label for="o2">Redirect them to: <span id="embedding-url" style="font-weight:bold"></span>.</label><br/> | |
106 | |
107 <span id="radio3" style="display:none"> | |
108 <input type="radio" id="o3" name="option" value="that"></input> | |
109 <label for="o3" title="">Redirect them to: <span id="default-url" style="font-weight:bold"></span>.</label><br/> | |
110 </span> | |
111 </div> | |
112 <a href="<%=context%>/help/Answer.jtp?id=40">Learn More</a> | |
113 <div style="margin-top:1.4em"> | |
114 <input type="submit" value="Save Changes" /> or <a href="<%=Jtp.path(node)%>">Go back to the <%=Jtp.viewName(node).toLowerCase()%></a> | |
115 </div> | |
116 </form> | |
117 <% } %> | |
118 | |
119 <% String embedDefaultUrl = node.getEmbeddingUrl(); %> | |
120 <script type="text/javascript"> | |
121 var defaultUrl = "<%=Jtp.hideNull(embedDefaultUrl)%>"; | |
122 $(document).ready(function() { | |
123 if (Nabble.isEmbedded) { | |
124 $('#settings').show(); | |
125 $('#more').hide(); | |
126 | |
127 $('#url').val(Nabble.embeddingUrl); | |
128 $('#embedding-url').html(Nabble.embeddingUrl); | |
129 | |
130 if (defaultUrl == "") { | |
131 $('#o1').attr('checked', 'y'); | |
132 } else if (Nabble.embeddingUrl == defaultUrl) { | |
133 $('#o2').attr('checked', 'y'); | |
134 } else { | |
135 $('#radio3').show(); | |
136 $('#default-url').html(defaultUrl); | |
137 $('#o3').attr('checked', 'y'); | |
138 } | |
139 } | |
140 }); | |
141 </script> | |
142 | |
143 <% Shared.footer(request, response); %> | |
144 <% Shared.analytics(request,response); %> | |
145 </body> | |
146 </html> | |
147 <% | |
148 } | |
149 } | |
150 %> |