0
|
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 out.print( "\r\n<html>\r\n <head>\r\n <meta name=\"robots\" content=\"noindex,nofollow\"/>\r\n " );
|
|
70 Shared.title(request, response, "Embedding Options");
|
|
71 out.print( "\r\n </head>\r\n <body>\r\n " );
|
|
72 Shared.minHeader(request,response, node);
|
|
73 out.print( "\r\n " );
|
|
74 Shared.editHeader(node.getSubjectHtml(), "Embedding Options", out);
|
|
75 out.print( "\r\n\r\n <div class=\"second-font field-title\">Javascript Code</div>\r\n <div class=\"weak-color\" style=\"margin-left:1.5em\">\r\n To add this " );
|
|
76 out.print( (isForum? Jtp.viewName(node).toLowerCase() : "topic") );
|
|
77 out.print( " to your website, copy and paste the following code on your HTML page:<br/>\r\n <textarea style=\"height:3.5em;width:85%;margin:.3em .3em .3em 0;font-size:80%\" readonly=\"true\" onClick=\"this.focus();this.select();\">" );
|
|
78 out.print( (isForum? EmbedUtils.getForumSnippet(request, node) : EmbedUtils.getTopicSnippet(request, node)) );
|
|
79 out.print( "</textarea>\r\n <br>You can embed this " );
|
|
80 out.print( (isForum? Jtp.viewName(node).toLowerCase():"topic") );
|
|
81 out.print( " in more than one website.\r\n <br>We suggest that you use a custom domain name to avoid third-party cookie problems.\r\n <br>Please check the <a href=\"" );
|
|
82 out.print( (context) );
|
|
83 out.print( "/help/Answer.jtp?id=36\">Nabble Help</a> for more information.\r\n </div>\r\n\r\n " );
|
|
84 if (isForum) {
|
|
85 out.print( "\r\n <div class=\"second-font field-title\">Redirect Users</div>\r\n <div id=\"more\" class=\"weak-color\" style=\"margin-left:1.5em\">\r\n Redirect options are available only when the " );
|
|
86 out.print( (Jtp.viewName(node).toLowerCase()) );
|
|
87 out.print( " is embedded.\r\n </div>\r\n\r\n <form id=\"settings\" method=\"post\" action=\"/embed/EmbedOptions.jtp\" accept-charset=\"UTF-8\" style=\"display:none\">\r\n <input type=\"hidden\" name=\"action\" value=\"save\" />\r\n <input type=\"hidden\" name=\"node\" value=\"" );
|
|
88 out.print( (node.getId()) );
|
|
89 out.print( "\" />\r\n <input type=\"hidden\" id=\"url\" name=\"url\" value=\"\" />\r\n\r\n <div class=\"weak-color\" style=\"margin:0 0 1em 1.5em\">\r\n Your embedded " );
|
|
90 out.print( (Jtp.viewName(node).toLowerCase()) );
|
|
91 out.print( " is hosted on Nabble at this URL: <b>" );
|
|
92 out.print( (Jtp.url(node)) );
|
|
93 out.print( "</b><br>\r\n\r\n <input type=\"radio\" id=\"o1\" name=\"option\" value=\"nabble\"></input>\r\n <label for=\"o1\">Allow users to view this " );
|
|
94 out.print( (Jtp.viewName(node).toLowerCase()) );
|
|
95 out.print( " without embedding.</label><br/>\r\n\r\n <input type=\"radio\" id=\"o2\" name=\"option\" value=\"this\"></input>\r\n <label for=\"o2\">Redirect them to: <span id=\"embedding-url\" style=\"font-weight:bold\"></span>.</label><br/>\r\n\r\n <span id=\"radio3\" style=\"display:none\">\r\n <input type=\"radio\" id=\"o3\" name=\"option\" value=\"that\"></input>\r\n <label for=\"o3\" title=\"\">Redirect them to: <span id=\"default-url\" style=\"font-weight:bold\"></span>.</label><br/>\r\n </span>\r\n </div>\r\n <a href=\"" );
|
|
96 out.print( (context) );
|
|
97 out.print( "/help/Answer.jtp?id=40\">Learn More</a>\r\n <div style=\"margin-top:1.4em\">\r\n <input type=\"submit\" value=\"Save Changes\" /> or <a href=\"" );
|
|
98 out.print( (Jtp.path(node)) );
|
|
99 out.print( "\">Go back to the " );
|
|
100 out.print( (Jtp.viewName(node).toLowerCase()) );
|
|
101 out.print( "</a>\r\n </div>\r\n </form>\r\n " );
|
|
102 }
|
|
103 out.print( "\r\n \r\n " );
|
|
104 String embedDefaultUrl = node.getEmbeddingUrl();
|
|
105 out.print( "\r\n <script type=\"text/javascript\">\r\n var defaultUrl = \"" );
|
|
106 out.print( (Jtp.hideNull(embedDefaultUrl)) );
|
|
107 out.print( "\";\r\n $(document).ready(function() {\r\n if (Nabble.isEmbedded) {\r\n $('#settings').show();\r\n $('#more').hide();\r\n \r\n $('#url').val(Nabble.embeddingUrl);\r\n $('#embedding-url').html(Nabble.embeddingUrl);\r\n\r\n if (defaultUrl == \"\") {\r\n $('#o1').attr('checked', 'y');\r\n } else if (Nabble.embeddingUrl == defaultUrl) {\r\n $('#o2').attr('checked', 'y');\r\n } else {\r\n $('#radio3').show();\r\n $('#default-url').html(defaultUrl);\r\n $('#o3').attr('checked', 'y'); \r\n }\r\n }\r\n });\r\n </script>\r\n\r\n " );
|
|
108 Shared.footer(request, response);
|
|
109 out.print( "\r\n " );
|
|
110 Shared.analytics(request,response);
|
|
111 out.print( "\r\n </body>\r\n</html>\r\n" );
|
|
112
|
|
113 }
|
|
114 }
|
|
115
|