diff --git a/code/Site/actions.js b/code/Site/actions.js index 5a6c0f18..c8083a8a 100644 --- a/code/Site/actions.js +++ b/code/Site/actions.js @@ -1,3 +1,70 @@ +/** + * main action + */ +function main_action() { + if (this.allstories.size() == 0) { + res.data.body = this.renderSkinAsString("welcome"); + if (session.user) { + if (session.user == this.creator) + res.data.body += this.renderSkinAsString("welcomeowner"); + if (session.user.sysadmin) + res.data.body += this.renderSkinAsString("welcomesysadmin"); + } + } else { + this.renderStorylist(req.data.day); + res.data.body = this.renderSkinAsString("main"); + } + res.data.title = this.title; + this.renderSkin("page"); + logAccess(); +} + +/** + * edit action + */ +function edit_action() { + if (req.data.cancel) + res.redirect(this.href()); + else if (req.data.save) { + try { + res.message = this.evalPreferences(req.data, session.user); + res.redirect(this.href()); + } catch (err) { + res.message = err.toString(); + } + } + + res.data.action = this.href(req.action); + res.data.title = "Preferences of " + this.title; + res.data.body = this.renderSkinAsString("edit"); + this.renderSkin("page"); +} + + +/** + * delete action + */ +function delete_action() { + if (req.data.cancel) + res.redirect(this.href()); + else if (req.data.remove) { + try { + res.message = root.deleteSite(this); + res.redirect(root.href()); + } catch (err) { + res.message = err.toString(); + } + } + + res.data.action = this.href(req.action); + res.data.title = "Delete weblog: " + this.title; + var sp = new Object(); + sp.what = "the weblog "" + this.title + """; + res.data.body = this.renderSkinAsString("delete", sp); + this.renderSkin("page"); +} + + /** * wrapper to access colorpicker also from site */ @@ -64,3 +131,233 @@ function rss10_action() { this.rss_action(); return; } + + +/** + * rss feed + */ +function rss_action() { + res.contentType = "text/xml"; + res.dependsOn(this.lastupdate); + res.digest(); + + var now = new Date(); + var systitle = root.getSysTitle(); + var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + sdf.setTimeZone(new java.util.SimpleTimeZone(0, "UTC")); + + var collection = this.allstories; + if (req.data.show == "all") + collection = this.allcontent; + var size = collection.size(); + var max = req.data.max ? parseInt(req.data.max) : 7; + max = Math.min(max, size); + max = Math.min(max, 10); + + var param = new Object(); + if (max > 0 && this.online) { + var items = ""; + var resources = ""; + collection.prefetchChildren(0, max); + for (var i=0; i 0 ? sdf.format(this.lastUpdate): sdf.format(this.createtime); + param.items = items; + param.resources = resources; + this.renderSkin("rss", param); + } +} + +/** + * this action tries to get a file with the given name + * if it finds it, it increases the request-counter of this file + * sets the appropriate mimetype and redirects the browser to the file + */ +function getfile_action() { + var f = this.files.get(req.data.name); + if (f) { + f.requestcnt++; + res.contentType = f.mimetype; + res.redirect(getProperty("fileUrl") + this.alias + "/" + f.name); + } else { + res.message = getMessage("error.fileNotFound", req.data.name); + res.redirect(this.href()); + } +} + +/** + * most read stories of a site + */ +function mostread_action() { + res.data.title = "Most read stories of " + this.title; + res.data.body = this.renderSkinAsString("mostread"); + this.renderSkin("page"); +} + +/** + * referrers of a site + */ +function referrers_action() { + res.data.title = "Referrers in the last 24 hours of " + this.title; + res.data.body = this.renderSkinAsString("referrers"); + this.renderSkin("page"); +} + +/** + * search action + */ +function search_action() { + res.data.action = this.href(req.action); + res.data.title = "Search " + this.title; + res.data.body = this.renderSkinAsString("searchform"); + + if (req.data.q) { + var query = stripTags(req.data.q); + // array with sites to search + var sites = new Array (this); + var result = root.searchSites (query, this._id); + var found = result.length; + if (found == 0) + res.data.body += getMessage("error.searchNothingFound", query); + else { + var start = 0; + var end = found; + + if (found == 1) + res.data.body += getMessage("confirm.resultOne", query); + else if (found <= 10) + res.data.body += getMessage("confirm.resultMany", [encodeForm(query), found]); + else { + if (req.data.start) + start = Math.min (found-1, parseInt (req.data.start)); + if (isNaN (start)) + start = 0; + end = Math.min (found, start+10); + res.data.body += getMessage("confirm.resultMany", [encodeForm(query), found]); + res.data.body += " " + getMessage("confirm.resultDisplay", [start+1, end]); + } + + res.data.body += "
"; + + // note: I'm doing this without a "searchbody" skin, since + // I think there's not much need to customize the body of + // search results, esp. since its parts are fully customizable. + // of course, I may be wrong about that. + + // render prev links, if necessary + if (start > 0) { + var sp = new Object(); + sp.url = this.href() + "search?q=" + escape(query)+"&start=" + Math.max(0, start-10); + sp.text = "previous results"; + res.data.body += "

" + renderSkinAsString("prevpagelink", sp); + } + + // render result + for (var i=start; i"; + res.data.body = this.renderSkinAsString("delete", sp); + this.renderSkin("page"); +} + +/** + * context menu extension + */ +function menuext_action() { + this.renderSkin("menuext"); + return; +} + +/** + * context menu extension (accessible as /menuext.reg) + */ +function menuext_reg_action() { + res.contentType = "text/plain"; + this.renderSkin("menuext.reg"); + return; +} + +/** + * robots.txt action + */ +function robots_txt_action() { + res.contentType = "text/plain"; + this.renderSkin("robots"); +} \ No newline at end of file