use of freemarker.template.SimpleHash in project jforum2 by rafaelsteil.
the class ViewCommon method contextToPagination.
/**
* Prepared the user context to use data pagination.
* The following variables are set to the context:
* <p>
* <ul>
* <li> <i>totalPages</i> - total number of pages
* <li> <i>recordsPerPage</i> - how many records will be shown on each page
* <li> <i>totalRecords</i> - number of records fount
* <li> <i>thisPage</i> - the current page being shown
* <li> <i>start</i> -
* </ul>
* </p>
* @param start int
* @param totalRecords int
* @param recordsPerPage int
*/
public static void contextToPagination(int start, int totalRecords, int recordsPerPage) {
SimpleHash context = JForumExecutionContext.getTemplateContext();
context.put("totalPages", new Double(Math.ceil((double) totalRecords / (double) recordsPerPage)));
context.put("recordsPerPage", new Integer(recordsPerPage));
context.put("totalRecords", new Integer(totalRecords));
context.put("thisPage", new Double(Math.ceil((double) (start + 1) / (double) recordsPerPage)));
context.put("start", new Integer(start));
}
use of freemarker.template.SimpleHash in project jforum2 by rafaelsteil.
the class AjaxAction method sendTestMail.
/**
* Sends a test message
* @param sender The sender's email address
* @param host the smtp host
* @param auth if need authorization or not
* @param username the smtp server username, if auth is needed
* @param password the smtp server password, if auth is needed
* @param to the recipient
* @return The status message
*/
public void sendTestMail() {
String sender = this.request.getParameter("sender");
String host = this.request.getParameter("host");
String port = this.request.getParameter("port");
String auth = this.request.getParameter("auth");
String ssl = this.request.getParameter("ssl");
String username = this.request.getParameter("username");
String password = this.request.getParameter("password");
String to = this.request.getParameter("to");
// Save the current values
String originalHost = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST);
String originalAuth = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_AUTH);
String originalUsername = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_USERNAME);
String originalPassword = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_PASSWORD);
String originalSender = SystemGlobals.getValue(ConfigKeys.MAIL_SENDER);
String originalSSL = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_SSL);
String originalPort = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_PORT);
// Now put the new ones
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_HOST, host);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_AUTH, auth);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_USERNAME, username);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PASSWORD, password);
SystemGlobals.setValue(ConfigKeys.MAIL_SENDER, sender);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_SSL, ssl);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PORT, port);
String status = "OK";
// Send the test mail
class TestSpammer extends Spammer {
public TestSpammer(String to) {
List l = new ArrayList();
User user = new User();
user.setEmail(to);
l.add(user);
this.setUsers(l);
this.setTemplateParams(new SimpleHash());
this.prepareMessage("JForum Test Mail", null);
}
protected String processTemplate() throws Exception {
return ("Test mail from JForum Admin Panel. Sent at " + new Date());
}
protected void createTemplate(String messageFile) throws Exception {
}
}
Spammer s = new TestSpammer(to);
try {
s.dispatchMessages();
} catch (Exception e) {
status = StringEscapeUtils.escapeJavaScript(e.toString());
logger.error(e.toString(), e);
} finally {
// Restore the original values
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_HOST, originalHost);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_AUTH, originalAuth);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_USERNAME, originalUsername);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PASSWORD, originalPassword);
SystemGlobals.setValue(ConfigKeys.MAIL_SENDER, originalSender);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_SSL, originalSSL);
SystemGlobals.setValue(ConfigKeys.MAIL_SMTP_PORT, originalPort);
}
this.setTemplateName(TemplateKeys.AJAX_TEST_MAIL);
this.context.put("status", status);
}
use of freemarker.template.SimpleHash in project jforum2 by rafaelsteil.
the class ModerationHelper method moveTopics.
private void moveTopics() {
SimpleHash context = JForumExecutionContext.getTemplateContext();
context.put("persistData", JForumExecutionContext.getRequest().getParameter("persistData"));
context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
String[] topics = JForumExecutionContext.getRequest().getParameterValues("topic_id");
if (topics.length > 0) {
// If forum_id is null, get from the database
String forumId = JForumExecutionContext.getRequest().getParameter("forum_id");
if (forumId == null) {
int topicId = Integer.parseInt(topics[0]);
Topic topic = TopicRepository.getTopic(new Topic(topicId));
if (topic == null) {
topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(topicId);
}
forumId = Integer.toString(topic.getForumId());
}
context.put("forum_id", forumId);
StringBuffer sb = new StringBuffer(128);
for (int i = 0; i < topics.length - 1; i++) {
sb.append(topics[i]).append(",");
}
sb.append(topics[topics.length - 1]);
context.put("topics", sb.toString());
}
}
use of freemarker.template.SimpleHash in project jforum2 by rafaelsteil.
the class SummaryModel method sendPostsSummary.
public void sendPostsSummary(List recipients) {
logger.info("Sending Weekly summary...");
// Gets a Date seven days before now
int daysBefore = Integer.parseInt(SystemGlobals.getValue(ConfigKeys.SUMMARY_DAYS_BEFORE));
// New date "X" days before now, where "X" is the number set on the variable daysBefore
long dateBefore = Calendar.getInstance().getTimeInMillis() - (daysBefore * 1000 * 60 * 60 * 24);
List posts = listPosts(new Date(dateBefore), new Date());
String forumLink = ViewCommon.getForumLink();
SimpleHash params = new SimpleHash();
params.put("posts", posts);
params.put("url", forumLink);
params.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
String subject = SystemGlobals.getValue(ConfigKeys.MAIL_SUMMARY_SUBJECT);
this.setUsers(this.recipientsAsUsers(recipients));
this.setTemplateParams(params);
this.prepareMessage(subject, SystemGlobals.getValue(ConfigKeys.MAIL_SUMMARY_FILE));
super.dispatchMessages();
}
use of freemarker.template.SimpleHash in project jforum2 by rafaelsteil.
the class GenericRSS method createRSS.
public String createRSS() {
try {
Template t = JForumExecutionContext.templateConfig().getTemplate(SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR) + "/rss_template.htm");
StringWriter sw = new StringWriter();
SimpleHash templateContext = JForumExecutionContext.getTemplateContext();
templateContext.put("encoding", SystemGlobals.getValue(ConfigKeys.ENCODING));
templateContext.put("rss", this.rss);
t.process(templateContext, sw);
return sw.toString();
} catch (Exception e) {
throw new ForumException(e);
}
}
Aggregations