antville/code/Story/macros.js

422 lines
11 KiB
JavaScript
Raw Normal View History

2002-07-01 16:36:27 +00:00
/*
* macro for rendering a part of the content.
*/
function content_macro(param) {
// check if this is a story with the old property layout. If so, convert to new.
if (this.text && !this.content) {
this.convertContentToXML();
}
if (param.as == "editor") {
param.name = "content_" + param.part;
param.value = this.getContentPart(param.part);
delete(param.part);
if (!param.height || parseInt(param.height) == 1)
renderInputText(param);
2002-07-01 16:36:27 +00:00
else
renderInputTextarea(param);
} else if (param.as == "image") {
var part = this.getContentPart (param.part);
if (part && this.site.images[part]) {
delete (param.part);
renderImage (this.site.images[part], param);
}
2002-07-01 16:36:27 +00:00
} else if (!this.content) {
return;
} else {
var part = this.getRenderedContentPart (param.part);
if (!part && param.fallback)
part = this.getRenderedContentPart (param.fallback);
if (param.part == "title" && param.as == "link" && !part) {
part = this.getRenderedContentPart ("text");
param.limit = "20";
}
if (param.as == "link")
openLink(this.href("main"));
if (!param.limit)
res.write(format(part));
2002-07-01 16:36:27 +00:00
else
renderTextPreview(part, param.limit);
if (param.as == "link")
closeLink();
}
}
2001-06-18 08:57:33 +00:00
/**
* macro rendering title of story
*/
function title_macro(param) {
2002-07-01 16:36:27 +00:00
param.part = "title";
this.content_macro (param);
2001-06-18 08:57:33 +00:00
}
/**
* macro rendering text of story
*/
function text_macro(param) {
2002-07-01 16:36:27 +00:00
param.part = "text";
this.content_macro (param);
2001-06-18 08:57:33 +00:00
}
/**
* macro rendering online-status of story
*/
function online_macro(param) {
if (param.as == "editor") {
var options = new Array("offline","online in topic","online in weblog");
renderDropDownBox("online",options,this.online);
} else {
if (!this.isOnline())
res.write("offline");
else if (parseInt(this.online,10) < 2) {
res.write("online in ");
openLink(this.site.topics.get(this.topic).href());
res.write(this.topic);
closeLink();
} else
res.write("online in weblog");
}
2001-06-18 08:57:33 +00:00
}
/**
* macro rendering createtime of story
*/
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";
renderInputText(param);
} else {
if (!this.createtime)
return;
res.write(formatTimestamp(this.createtime,param.format));
}
2001-06-18 08:57:33 +00:00
}
/**
* macro rendering modifytime of story
*/
function modifytime_macro(param) {
if (this.modifytime) {
res.write(formatTimestamp(this.modifytime,param.format));
}
}
2001-06-18 08:57:33 +00:00
2001-07-01 19:40:08 +00:00
/**
* macro renders the name of the author
* !!! left for backwards-compatibility !!!
2001-07-01 19:40:08 +00:00
*/
function author_macro(param) {
this.creator_macro(param);
}
/**
* macro renders the name of the creator
*/
function creator_macro(param) {
if (!this.creator)
2001-07-21 22:01:36 +00:00
return;
if (param.as == "link" && this.creator.url) {
openLink(this.creator.url);
res.write(this.creator.name);
closeLink();
} else
res.write(this.creator.name);
2001-07-01 19:40:08 +00:00
}
2001-07-21 22:01:36 +00:00
/**
* macro renders the name of the modifier
*/
function modifier_macro(param) {
if (!this.modifier)
2001-07-21 22:01:36 +00:00
return;
if (param.as == "link" && this.modifier.url) {
openLink(this.modifier.url);
2001-07-21 22:01:36 +00:00
res.write(this.modifier.name);
closeLink();
2001-07-21 22:01:36 +00:00
} else
res.write(this.modifier.name);
}
/**
* macro renders the url of this story
*/
function url_macro(param) {
res.write(this.href());
}
2001-06-18 08:57:33 +00:00
/**
* macro rendering a link to edit
* if user is allowed to edit
*/
function editlink_macro(param) {
if (!this.isEditDenied(session.user)) {
openLink(this.href("edit"));
if (param.image && this.site.images.get(param.image))
this.site.renderImage(this.site.images.get(param.image),param);
2001-06-18 08:57:33 +00:00
else
2001-07-21 22:01:36 +00:00
res.write(param.text ? param.text : "edit");
closeLink();
2001-06-18 08:57:33 +00:00
}
}
/**
* macro rendering a link to delete
* if user is creator of this story
2001-06-18 08:57:33 +00:00
*/
function deletelink_macro(param) {
if (!this.isDeleteDenied(session.user)) {
openLink(this.href("delete"));
if (param.image && this.site.images.get(param.image))
this.site.renderImage(this.site.images.get(param.image),param);
2001-06-18 08:57:33 +00:00
else
2001-07-21 22:01:36 +00:00
res.write(param.text ? param.text : "delete");
closeLink();
2001-06-18 08:57:33 +00:00
}
}
2001-11-18 13:23:36 +00:00
/**
* macro renders a link to
* toggle the online-status of this story
*/
function onlinelink_macro(param) {
if (!this.isEditDenied(session.user)) {
param.linkto = "edit";
param.urlparam = "set=" + (this.isOnline() ? "offline" : "online");
openMarkupElement("a",this.createLinkParam(param));
if (param.image && this.site.images.get(param.image))
this.site.renderImage(this.site.images.get(param.image),param);
2001-11-18 13:23:36 +00:00
else
res.write(this.isOnline() ? "set offline" : "set online");
closeMarkupElement("a");
2001-11-18 13:23:36 +00:00
}
}
/**
* macro renders a link to the story
*/
function viewlink_macro(param) {
if (this.isViewDenied(session.user))
2001-11-18 13:23:36 +00:00
return;
openLink(this.href());
if (param.image && this.site.images.get(param.image))
this.site.renderImage(this.site.images.get(param.image),param);
2001-11-18 13:23:36 +00:00
else
res.write(param.text ? param.text : "view");
closeLink();
2001-11-18 13:23:36 +00:00
}
2001-06-18 08:57:33 +00:00
/**
* macro rendering link to comments
2001-07-21 22:01:36 +00:00
* DEPRECATED
* this is just left for compatibility with existing sites
2001-07-21 22:01:36 +00:00
* use a simple like i.e. <% story.link to="comment" text="place your comment" %> instead
2001-06-18 08:57:33 +00:00
*/
function commentlink_macro(param) {
if (!this.hasDiscussions())
return;
openLink(this.href(param.to ? param.to : "comment"));
res.write(param.text ? param.text : "place your comment");
closeLink();
2001-06-18 08:57:33 +00:00
}
2001-07-21 22:01:36 +00:00
2001-06-18 08:57:33 +00:00
/**
* 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)
2001-06-18 08:57:33 +00:00
*/
function commentcounter_macro(param) {
if (!this.hasDiscussions())
return;
var commentCnt = this.comments.count();
if (!param.linkto)
param.linkto = "main";
if (commentCnt == 0) {
res.write(commentCnt + (param.no ? param.no : " comments"));
} else {
openMarkupElement("a", this.createLinkParam(param));
if (commentCnt == 1)
res.write(commentCnt + (param.one ? param.one : " comment"));
else
res.write(commentCnt + (param.more ? param.more : " comments"));
closeMarkupElement("a");
2001-06-18 08:57:33 +00:00
}
return;
2001-06-18 08:57:33 +00:00
}
/**
* macro loops over comments and renders them
*/
function comments_macro(param) {
if (!path.story.hasDiscussions())
return;
for (var i=0;i<this.size();i++) {
var c = this.get(i);
var linkParam = new Object();
linkParam.name = c._id;
renderMarkupElement("a", linkParam);
if (c.parent)
c.renderSkin("reply");
else
c.renderSkin("toplevel");
2001-06-18 08:57:33 +00:00
}
}
/**
* macro checks if user is logged in and not blocked
* if true, render form to add a comment
*/
function commentform_macro(param) {
if (session.user) {
2001-09-05 21:44:06 +00:00
var c = new comment();
c.renderSkin("edit");
} else {
openLink(this.site.members.href("login"));
2001-09-05 21:44:06 +00:00
res.write (param.text ? param.text : "login to add your comment!");
closeLink();
2001-09-05 21:44:06 +00:00
}
2001-06-18 08:57:33 +00:00
}
/**
* macro left for backwards-compatibility
* calls global image_macro()
2001-06-18 08:57:33 +00:00
*/
function image_macro(param) {
image_macro(param);
}
2001-07-21 22:01:36 +00:00
2001-08-26 19:15:29 +00:00
/**
* macro left for backwards-compatibility
* calls global image_macro() as "popup"
2001-08-26 19:15:29 +00:00
*/
function thumbnail_macro(param) {
param.as = "popup";
image_macro(param);
2001-08-26 19:15:29 +00:00
}
2001-07-21 22:01:36 +00:00
/**
* macro renders the property of story that defines if
* other users may edit this story
*/
function editableby_macro(param) {
if (param.as == "editor" && (session.user == this.creator || !this.creator)) {
var options = new Array("Subscribers and Contributors","Contributors only");
renderDropDownBox("editableby",options,this.editableby,"----");
2001-07-21 22:01:36 +00:00
} else {
if (this.editableby == 0)
res.write("Subscribers of and Contributors to " + this.site.title);
2001-07-21 22:01:36 +00:00
else if (this.editableby == 1)
res.write("Contributors to " + this.site.title);
2001-11-03 09:21:43 +00:00
else
res.write("Content Managers and Admins of " + this.site.title);
2001-07-21 22:01:36 +00:00
}
}
/**
* macro renders a checkbox for enabling/disabling discussions
*/
function discussions_macro(param) {
if (param.as == "editor") {
if (this.discussions == null && path.site.hasDiscussions())
param.check = "true";
renderInputCheckbox(this.createInputParam("discussions",param));
} else
res.write(parseInt(this.discussions,10) ? "yes" : "no");
}
/**
* macro renders a list of existing topics as dropdown
*/
function topicchooser_macro(param) {
var size = path.site.topics.size();
var options = new Array();
for (var i=0;i<size;i++) {
var topic = path.site.topics.get(i);
if (topic.size()) {
options[i] = topic.groupname;
if (this.topic == topic.groupname)
var selectedIndex = i;
}
}
renderDropDownBox("topicidx", options, selectedIndex, "-- choose topic --");
}
/**
* macro renders the name of the topic this story belongs to
* as link
*/
function topic_macro(param) {
if (!this.topic)
return;
openLink(this.site.topics.get(this.topic).href());
res.write(this.topic);
closeLink();
}
2002-04-24 13:35:44 +00:00
/**
* macro returns a list of references linking to a story
*/
2002-04-24 13:35:44 +00:00
function backlinks_macro() {
// this is a clone of site.listReferrers_macro.
2002-04-24 13:35:44 +00:00
var str = "";
var c = getDBConnection("antville");
var dbError = c.getLastError();
if (dbError)
return (getMsg("error","database",dbError));
2002-04-24 13:35:44 +00:00
// we're doing this with direct db access here
// (there's no need to do it with prototypes):
var query = "select *, count(*) as \"COUNT\" from AV_ACCESSLOG where ACCESSLOG_F_TEXT = " + this._id + " group by ACCESSLOG_REFERRER order by \"COUNT\" desc, ACCESSLOG_REFERRER asc;";
2002-04-24 13:35:44 +00:00
var rows = c.executeRetrieval(query);
var dbError = c.getLastError();
if (dbError)
return (getMsg("error","database",dbError));
2002-04-24 13:35:44 +00:00
var param = new Object();
while (rows.next()) {
param.count = rows.getColumnItem("COUNT");
// these two lines are necessary only for hsqldb connections:
if (param.count == 0)
continue;
param.referrer = rows.getColumnItem("ACCESSLOG_REFERRER");
2002-04-24 13:35:44 +00:00
param.text = param.referrer.length > 50 ? param.referrer.substring(0, 50) + "..." : param.referrer;
str += this.renderSkinAsString("backlinkItem", param);
2002-04-24 13:35:44 +00:00
}
rows.release();
2002-04-24 13:35:44 +00:00
param = new Object();
param.referrers = str;
if (str)
str = this.renderSkinAsString("backlinks", param);
2002-04-24 13:35:44 +00:00
return(str);
}