2001-12-10 16:35:07 +00:00
|
|
|
/**
|
|
|
|
* this is the generic onStart handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onStart() {
|
|
|
|
scheduler();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this is the generic scheduler() function
|
|
|
|
*/
|
|
|
|
|
|
|
|
function scheduler() {
|
|
|
|
return(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* to register updates of a weblog at weblogs.com
|
|
|
|
* (and probably other services, soon), this
|
|
|
|
* function can be called via the scheduler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function pingUpdatedWeblogs() {
|
|
|
|
for (var i=0; i<root.allWeblogs.size(); i++) {
|
|
|
|
var blog = root.allWeblogs.get(i);
|
|
|
|
var now = new Date();
|
|
|
|
var period = 1000 * 60 * 10;
|
|
|
|
if ((now - blog.lastPing >= period) && (now - blog.lastUpdate <= period) && blog.online) {
|
|
|
|
writeln(blog.title + " was updated, so i'll ping weblogs.com...");
|
|
|
|
var url = "http://hopdev.helma.at" + blog.href();
|
|
|
|
//var ping = getURL("http://newhome.weblogs.com/pingSiteForm?name=" + blog.title + "&url=" + url);
|
|
|
|
var xr = new Remote("http://rpc.weblogs.com/RPC2");
|
|
|
|
var ping = xr.weblogUpdates.ping(blog.title, url);
|
|
|
|
if (ping.error)
|
|
|
|
writeln(ping.error);
|
|
|
|
blog.lastPing = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-18 08:57:33 +00:00
|
|
|
/**
|
|
|
|
* check if email-adress is syntactically correct
|
|
|
|
*/
|
|
|
|
|
|
|
|
function checkEmail(address) {
|
|
|
|
var m = new Mail();
|
|
|
|
m.addTo(address);
|
|
|
|
if (m.status)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if req.data.date[Year|Month|Date|Hours|Minutes] is valid
|
|
|
|
* if correct, creates dateobject and returns it
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
|
|
|
|
function checkDate() {
|
|
|
|
if (req.data.dateYear && req.data.dateMonth && req.data.dateDate && req.data.dateHours && req.data.dateMinutes) {
|
|
|
|
var ts = new Date();
|
|
|
|
ts.setYear(parseInt(req.data.dateYear));
|
|
|
|
ts.setMonth(parseInt(req.data.dateMonth));
|
|
|
|
ts.setDate(parseInt(req.data.dateDate));
|
|
|
|
ts.setHours(parseInt(req.data.dateHours));
|
|
|
|
ts.setMinutes(parseInt(req.data.dateMinutes));
|
|
|
|
ts.setSeconds(0);
|
|
|
|
return (ts);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-06-20 10:28:26 +00:00
|
|
|
/**
|
|
|
|
* functin checks if the string passed contains special characters like
|
|
|
|
* spaces, brackets etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function isClean(str) {
|
|
|
|
var validChar = new RegExp("[^a-z,^A-Z,^0-9]");
|
|
|
|
if (validChar.exec(str))
|
|
|
|
return false;
|
|
|
|
return true;
|
2001-09-05 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if there is a weblog-object in path
|
|
|
|
* if true, it sets the skin of response to "page" and returns the weblog-object found
|
|
|
|
* if false, it uses root and it's page-skin
|
|
|
|
*/
|
|
|
|
|
2001-11-18 13:18:56 +00:00
|
|
|
function setLayout(useSkin) {
|
2001-09-05 21:22:55 +00:00
|
|
|
if (path.weblog) {
|
2001-11-18 13:18:56 +00:00
|
|
|
res.skin = "weblog." + (useSkin ? useSkin : "page");
|
2001-09-05 21:22:55 +00:00
|
|
|
return (path.weblog);
|
|
|
|
} else {
|
2001-11-29 14:55:47 +00:00
|
|
|
res.skin = "root.page";
|
2001-09-05 21:22:55 +00:00
|
|
|
return (root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function creates macro-tags out of plain urls in text
|
|
|
|
* does this with three replace-operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
function formatLinks(str) {
|
|
|
|
var pre = "<% this.link to=\"";
|
|
|
|
var mid = "\" text=\"";
|
|
|
|
var post = "\" %>";
|
|
|
|
var l0 = new RegExp("<a href\\s*=\\s*\"?([^\\s\"]+)?\"?[^>]*?>([^<]*?)</a>");
|
|
|
|
var l1 = new RegExp("([fhtpsr]+:\\/\\/[^\\s]+?)([\\.,;\\)\\]\"]?(\\s|$))");
|
|
|
|
var l2 = new RegExp("(<%[^%]*?)" + pre + "(.*?)" + mid + ".*?" + post + "([^%]*?%>)");
|
|
|
|
l0.ignoreCase = l1.ignoreCase = l2.ignoreCase = true;
|
|
|
|
l0.global = l1.global = l2.global = true;
|
|
|
|
|
|
|
|
str = str.replace(l0, pre + "$1" + mid + "$2" + post);
|
|
|
|
str = str.replace(l1, pre + "$1" + mid + "$1" + post + "$3");
|
|
|
|
str = str.replace(l2, "$1$2$3");
|
|
|
|
return (str);
|
2001-09-07 13:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function activates URLs to HTML link tags
|
|
|
|
*/
|
2001-11-23 20:38:58 +00:00
|
|
|
|
2001-09-07 13:13:39 +00:00
|
|
|
function activateLinks (str) {
|
|
|
|
var pre = "<a href=\"";
|
|
|
|
var mid = "\">";
|
|
|
|
var post = "</a>";
|
|
|
|
|
|
|
|
var l1 = new RegExp("(^|\\s)([fhtpsr]+:\\/\\/[^\\s]+?)([\\.,;\\)\\]\"]?(\\s|$))");
|
|
|
|
l1.ignoreCase = true;
|
|
|
|
l1.global = true;
|
|
|
|
|
|
|
|
// this is odd, but we have to run the regexp twice to catch URLs
|
|
|
|
// which imediately follow each other. This is because the leading
|
|
|
|
// and trailing whitespaces are part of the expression, and if there's only
|
|
|
|
// one whitespace character between two URLs, the first match eats it up
|
|
|
|
// and the second URL doesn't match.
|
|
|
|
str = str.replace(l1, "$1" + pre + "$2" + mid + "$2" + post + "$4");
|
|
|
|
str = str.replace(l1, "$1" + pre + "$2" + mid + "$2" + post + "$4");
|
2001-12-04 13:12:44 +00:00
|
|
|
|
|
|
|
// do Wiki style substitution
|
|
|
|
return (doWikiStuff (str));
|
|
|
|
// return (str);
|
2001-09-07 13:13:39 +00:00
|
|
|
}
|
|
|
|
|
2001-10-02 10:55:33 +00:00
|
|
|
/**
|
|
|
|
* function checks if url is correct
|
|
|
|
* if not it assumes that http is the protocol
|
|
|
|
*/
|
|
|
|
|
|
|
|
function evalURL(url) {
|
|
|
|
if (url.indexOf("://") < 0)
|
|
|
|
return ("http://" + url);
|
|
|
|
return (url);
|
2001-10-07 19:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if user has permanent cookies
|
|
|
|
* storing username and password
|
|
|
|
*/
|
|
|
|
|
|
|
|
function autoLogin() {
|
|
|
|
if (user.uid)
|
|
|
|
return;
|
|
|
|
var name = req.data.avUsr;
|
|
|
|
var pw = req.data.avPw;
|
|
|
|
if (!name || !pw)
|
|
|
|
return;
|
|
|
|
var u = getUser(name);
|
|
|
|
if (!u)
|
|
|
|
return;
|
|
|
|
if (calcMD5(u.password) != pw)
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
if (user.login(name,u.password)) {
|
|
|
|
user.lastVisit = new Date();
|
|
|
|
res.message = "Welcome to Antville, " + user.name + "! Have fun!";
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
}
|
2001-10-21 12:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-11-03 09:16:59 +00:00
|
|
|
* function checks if the name of the requested object has a slash in it
|
|
|
|
* if true, it tries to fetch the appropriate parent-object (either weblog or root)
|
|
|
|
* and to fetch the object with the requested name in the specified collection
|
|
|
|
* @param String Name of the object to retrieve
|
|
|
|
* @param String Name of the pool to search in
|
|
|
|
* @return Obj Object with two properties: one containing the parent-object of the pool,
|
|
|
|
* the other containing the object itself;
|
|
|
|
* If parent or object is null, the function returns null.
|
2001-10-21 12:02:20 +00:00
|
|
|
*/
|
|
|
|
|
2001-11-03 09:16:59 +00:00
|
|
|
function getPoolObj(objName,pool) {
|
|
|
|
var p = new Object();
|
|
|
|
if (objName.indexOf("/") >= 0) {
|
|
|
|
var objPath = objName.split("/");
|
|
|
|
p.parent = (!objPath[0] || objPath[0] == "root") ? root : root.get(objPath[0]);
|
|
|
|
p.objName = objPath[1];
|
2001-10-21 12:02:20 +00:00
|
|
|
} else {
|
2001-11-03 09:16:59 +00:00
|
|
|
p.parent = path.weblog;
|
|
|
|
p.objName = objName;
|
2001-10-21 12:02:20 +00:00
|
|
|
}
|
2001-11-03 09:16:59 +00:00
|
|
|
if (!p.parent)
|
2001-10-21 12:02:20 +00:00
|
|
|
return null;
|
2001-11-03 09:16:59 +00:00
|
|
|
p.obj = p.parent[pool].get(p.objName);
|
|
|
|
if (!p.obj)
|
2001-10-21 12:02:20 +00:00
|
|
|
return null;
|
2001-11-03 09:16:59 +00:00
|
|
|
return (p);
|
2001-10-30 13:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function parses a string for <img> tags and turns them
|
|
|
|
* into <a> tags.
|
|
|
|
*/
|
2001-11-03 09:16:59 +00:00
|
|
|
|
2001-10-30 13:00:47 +00:00
|
|
|
function convertHtmlImageToHtmlLink(str) {
|
|
|
|
var re = new RegExp("<img src\\s*=\\s*\"?([^\\s\"]+)?\"?[^>]*?(alt\\s*=\\s*\"?([^\"]+)?\"?[^>]*?)?>");
|
|
|
|
re.ignoreCase = true;
|
|
|
|
re.global = true;
|
|
|
|
str = str.replace(re, "[<a href=\"$1\" title=\"$3\">Image</a>]");
|
|
|
|
return(str);
|
|
|
|
}
|
2001-11-03 09:16:59 +00:00
|
|
|
|