/* * macro for rendering a part of the story content */ function content_macro(param) { switch (param.as) { case "editor" : var inputParam = this.content.createInputParam(param.part, param); delete inputParam.part; if (param.cols || param.rows) Html.textArea(inputParam); else Html.input(inputParam); break; case "image" : var part = this.content.getProperty(param.part); if (part && this.site.images[part]) { delete param.part; renderImage(this.site.images[part], param); } break; default : if (!param.clipping) param.clipping = "..."; var part = this.getRenderedContentPart(param.part); if (!part && param.fallback) part = this.getRenderedContentPart(param.fallback); if (param.as == "link") { if (this._prototype != "comment") Html.openLink({href: this.href()}); else Html.openLink({href: this.story.href() + "#" + this._id}); part = part ? part.stripTags() : param.clipping; } if (!param.limit) res.write(part); else res.write(part.clip(param.limit, param.clipping).softwrap(25)); if (param.as == "link") Html.closeLink(); } return; } /** * macro rendering online status of story */ function online_macro(param) { if (!this.online) res.write(param.no ? param.no : "offline"); else res.write(param.yes ? param.yes : "online"); return; } /** * macro rendering the location of the story */ function location_macro(param) { switch (this.online) { case 1: Html.link({href: this.site.topics.get(this.topic).href()}, "topic"); break; case 2: res.write("site"); break; } return; } /** * macro rendering createtime of story, either as editor, * plain text or as link to the frontpage of the day */ function createtime_macro(param) { if (param.as == "editor") { if (this.createtime) param.value = formatTimestamp(this.createtime, "yyyy-MM-dd HH:mm"); else param.value = formatTimestamp(new Date(), "yyyy-MM-dd HH:mm"); param.name = "createtime"; Html.input(param); } else if (this.createtime) { var text = formatTimestamp(this.createtime, param.format); if (param.as == "link" && this.online == 2) Html.link({href: path.site.get(String(this.day)).href()}, text); else res.write(text); } return; } /** * macro rendering a link to edit * if user is allowed to edit */ function editlink_macro(param) { if (session.user) { try { this.checkEdit(session.user, req.data.memberlevel); } catch (deny) { return; } Html.openLink({href: this.href("edit")}); if (param.image && this.site.images.get(param.image)) this.site.renderImage(this.site.images.get(param.image), param); else res.write(param.text ? param.text : "edit"); Html.closeLink(); } return; } /** * macro rendering a link to delete * if user is creator of this story */ function deletelink_macro(param) { if (session.user) { try { this.checkDelete(session.user, req.data.memberlevel); } catch (deny) { return; } Html.openLink({href: this.href("delete")}); if (param.image && this.site.images.get(param.image)) this.site.renderImage(this.site.images.get(param.image), param); else res.write(param.text ? param.text : "delete"); Html.closeLink(); } return; } /** * macro renders a link to * toggle the online-status of this story */ function onlinelink_macro(param) { if (session.user) { try { this.checkEdit(session.user, req.data.memberlevel); } catch (deny) { return; } if (this.online && param.mode != "toggle") return; delete param.mode; var text = param.text; param.linkto = "edit"; param.urlparam = "set=" + (this.online ? "offline" : "online"); Html.openTag("a", this.createLinkParam(param)); if (param.image && this.site.images.get(param.image)) this.site.renderImage(this.site.images.get(param.image), param); else { // currently, only the "set online" text is customizable, since this macro // is by default only used in that context outside the story manager. if (this.online) res.write("set offline"); else res.write(text ? text : "set online"); } Html.closeTag("a"); } return; } /** * macro renders a link to the story */ function viewlink_macro(param) { if (session.user) { try { this.checkView(session.user, req.data.memberlevel); } catch (deny) { return; } Html.openLink({href: this.href()}); if (param.image && this.site.images.get(param.image)) this.site.renderImage(this.site.images.get(param.image), param); else res.write(param.text ? param.text : "view"); Html.closeLink(); } return; } /** * macro rendering link to comments */ function commentlink_macro(param) { if (this.discussions && this.site.preferences.getProperty("discussions")) Html.link({href: this.href(param.to ? param.to : "comment")}, param.text ? param.text : "comment"); return; } /** * macro renders number of comments * options: text to use when no comment * text to use when one comment * text to use when more than one comment * action to link to (default: main) */ function commentcounter_macro(param) { if (!this.site.preferences.getProperty("discussions") || !this.discussions) return; var commentCnt = this.comments.count(); if (!param.linkto) param.linkto = "main"; // cloning the param object to remove the macro-specific // attributes from the clone for valid markup output: var param2 = Object.clone(param); delete param2.one; delete param2.more; delete param2.no; var linkflag = (param.as == "link" && param.as != "text" || !param.as && commentCnt > 0); if (linkflag) Html.openTag("a", this.createLinkParam(param2)); if (commentCnt == 0) res.write(param.no || param.no == "" ? param.no : "0 comments"); else if (commentCnt == 1) res.write(param.one ? param.one : "1 comment"); else res.write(commentCnt + (param.more ? param.more : " comments")); if (linkflag) Html.closeTag("a"); return; } /** * macro loops over comments and renders them */ function comments_macro(param) { var s = this.story ? this.story : this; if (!s.site.preferences.getProperty("discussions") || !s.discussions) return; this.comments.prefetchChildren(); for (var i=0;i