2001-06-18 08:57:33 +00:00
|
|
|
/**
|
|
|
|
* check if there are any stories in the previous month
|
|
|
|
*/
|
|
|
|
|
2001-07-01 19:27:28 +00:00
|
|
|
function renderLinkToPrevMonth(cal) {
|
2001-09-05 21:31:29 +00:00
|
|
|
// create Object used to pass to format-function
|
|
|
|
var tsParam = new Object();
|
2001-07-01 19:27:28 +00:00
|
|
|
tsParam.format = "MMMM";
|
|
|
|
|
2001-06-18 08:57:33 +00:00
|
|
|
if (!this.size())
|
|
|
|
return (" ");
|
|
|
|
if (parseInt(this.get(this.size()-1).groupname,10) < parseInt(cal.getTime().format("yyyyMMdd"),10)) {
|
|
|
|
// there are any stories left back in history, so try to get them ...
|
|
|
|
prevDay = false;
|
|
|
|
while (!prevDay) {
|
|
|
|
cal.add(java.util.Calendar.DATE,-1);
|
|
|
|
if (this.get(cal.getTime().format("yyyyMMdd")))
|
|
|
|
prevDay = this.get(cal.getTime().format("yyyyMMdd"));
|
|
|
|
}
|
2001-08-15 09:09:32 +00:00
|
|
|
return ("<a href=\"" + prevDay.href() + "\">" + this.formatTimestamp(cal.getTime(),tsParam) + "</a>");
|
2001-06-18 08:57:33 +00:00
|
|
|
} else {
|
|
|
|
return (" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if there are any stories in the previous month
|
|
|
|
*/
|
|
|
|
|
2001-07-01 19:27:28 +00:00
|
|
|
function renderLinkToNextMonth(cal) {
|
2001-09-05 21:31:29 +00:00
|
|
|
// create Object used to pass to format-function
|
|
|
|
var tsParam = new Object();
|
2001-07-01 19:27:28 +00:00
|
|
|
tsParam.format = "MMMM";
|
|
|
|
|
2001-06-18 08:57:33 +00:00
|
|
|
if (!this.size())
|
|
|
|
return (" ");
|
2002-03-29 14:31:12 +00:00
|
|
|
if (parseInt(this.get(0).groupname,10) > parseInt(cal.getTime().format("yyyyMMdd"),10)) {
|
2001-06-18 08:57:33 +00:00
|
|
|
// there are any stories, so try to get them ...
|
|
|
|
nextDay = false;
|
|
|
|
while (!nextDay) {
|
|
|
|
cal.add(java.util.Calendar.DATE,1);
|
2002-03-29 14:31:12 +00:00
|
|
|
if (this.get(cal.getTime().format("yyyyMMdd")))
|
|
|
|
nextDay = this.get(cal.getTime().format("yyyyMMdd"));
|
2001-06-18 08:57:33 +00:00
|
|
|
}
|
2001-08-15 09:09:32 +00:00
|
|
|
return ("<a href=\"" + nextDay.href() + "\">" + this.formatTimestamp(cal.getTime(),tsParam) + "</a>");
|
2001-06-18 08:57:33 +00:00
|
|
|
} else {
|
|
|
|
return (" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-29 14:31:12 +00:00
|
|
|
|
|
|
|
|
2001-06-18 08:57:33 +00:00
|
|
|
/**
|
|
|
|
* function saves new properties of weblog
|
2001-12-10 23:46:24 +00:00
|
|
|
* @param Obj Object containing the form values
|
|
|
|
* @param Obj User-Object modifying this weblog
|
2001-12-13 18:25:00 +00:00
|
|
|
* @return Obj Object containing two properties:
|
|
|
|
* - error (boolean): true if error happened, false if everything went fine
|
|
|
|
* - message (String): containing a message to user
|
2001-06-18 08:57:33 +00:00
|
|
|
*/
|
|
|
|
|
2001-12-13 18:25:00 +00:00
|
|
|
function evalPreferences(param,modifier) {
|
|
|
|
var result = new Object();
|
|
|
|
result.error = false;
|
|
|
|
if (!checkEmail(param.email)) {
|
|
|
|
result.message = "The email-address is invalid!";
|
|
|
|
result.error = true;
|
|
|
|
return (result);
|
|
|
|
}
|
2002-02-06 18:06:57 +00:00
|
|
|
this.title = stripTags(param.title);
|
2001-12-10 23:46:24 +00:00
|
|
|
this.tagline = param.tagline;
|
2001-12-13 18:25:00 +00:00
|
|
|
this.email = param.email;
|
2001-12-10 23:46:24 +00:00
|
|
|
this.bgcolor = param.bgcolor;
|
|
|
|
this.textfont = param.textfont;
|
|
|
|
this.textsize = param.textsize;
|
|
|
|
this.textcolor = param.textcolor;
|
|
|
|
this.linkcolor = param.linkcolor;
|
|
|
|
this.alinkcolor = param.alinkcolor;
|
|
|
|
this.vlinkcolor = param.vlinkcolor;
|
|
|
|
this.titlefont = param.titlefont;
|
|
|
|
this.titlesize = param.titlesize;
|
|
|
|
this.titlecolor = param.titlecolor;
|
|
|
|
this.smallfont = param.smallfont;
|
|
|
|
this.smallsize = param.smallsize;
|
|
|
|
this.smallcolor = param.smallcolor;
|
|
|
|
this.days = parseInt(param.days,10);
|
2002-03-27 11:24:36 +00:00
|
|
|
var online = parseInt(param.online,10);
|
|
|
|
if (this.online && !online)
|
|
|
|
this.lastoffline = new Date();
|
|
|
|
this.online = online;
|
2001-12-10 23:46:24 +00:00
|
|
|
this.online = parseInt(param.online,10);
|
|
|
|
this.discussions = parseInt(param.discussions,10);
|
|
|
|
this.usercontrib = parseInt(param.usercontrib,10);
|
|
|
|
this.archive = parseInt(param.archive,10);
|
2002-04-26 08:17:28 +00:00
|
|
|
this.enableping = parseInt(param.enableping,10);
|
2001-12-10 23:46:24 +00:00
|
|
|
// store selected locale in this.language and this.country
|
|
|
|
var locs = java.util.Locale.getAvailableLocales();
|
|
|
|
var newLoc = locs[parseInt(param.locale,10)];
|
|
|
|
if (!newLoc)
|
|
|
|
newLoc = java.util.Locale.getDefault();
|
|
|
|
this.country = newLoc.getCountry();
|
|
|
|
this.language = newLoc.getLanguage();
|
|
|
|
|
|
|
|
// long dateformat
|
|
|
|
var patterns = getDefaultDateFormats();
|
|
|
|
var ldf = patterns[parseInt(param.longdateformat,10)];
|
|
|
|
this.longdateformat = ldf ? ldf : null;
|
|
|
|
|
|
|
|
// short dateformat
|
|
|
|
var patterns = getDefaultDateFormats("short");
|
|
|
|
var ldf = patterns[parseInt(param.shortdateformat,10)];
|
|
|
|
this.shortdateformat = ldf ? ldf : null;
|
|
|
|
|
|
|
|
this.modifytime = new Date();
|
|
|
|
this.modifier = modifier;
|
2001-12-13 18:25:00 +00:00
|
|
|
result.message = "The changes were saved successfully!";
|
|
|
|
return (result);
|
2001-06-18 08:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function returns true if discussions are enabled
|
|
|
|
* for this weblog
|
|
|
|
*/
|
|
|
|
|
|
|
|
function hasDiscussions() {
|
|
|
|
if (parseInt(this.discussions,10))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function returns true if weblog is online
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
|
|
|
|
function isOnline() {
|
|
|
|
if (parseInt(this.online,10))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function creates the directory that will contain the images of this weblog
|
|
|
|
*/
|
|
|
|
|
|
|
|
function createImgDirectory() {
|
|
|
|
var dir = new File(getProperty("imgPath") + this.alias + "/");
|
|
|
|
return (dir.mkdir());
|
2001-07-01 19:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if language and/or country was specified for this weblog
|
|
|
|
* if true, it returns the timestamp formatted with the given locale
|
|
|
|
*/
|
|
|
|
|
|
|
|
function formatTimestamp(ts,param) {
|
2001-12-10 23:46:24 +00:00
|
|
|
var fmt = "yyyy/MM/dd HH:mm";
|
|
|
|
if (param.format == "short")
|
|
|
|
fmt = this.shortdateformat ? this.shortdateformat : "dd.MM HH:mm";
|
|
|
|
else if (param.format == "long")
|
|
|
|
fmt = this.longdateformat ? this.longdateformat : "yyyy/MM/dd HH:mm";
|
|
|
|
else if (param.format)
|
|
|
|
fmt = param.format;
|
2001-07-01 19:27:28 +00:00
|
|
|
var sdf = new java.text.SimpleDateFormat(fmt,this.getLocale());
|
2001-12-10 23:46:24 +00:00
|
|
|
var result = tryEval("sdf.format(ts)");
|
|
|
|
if (result.error)
|
|
|
|
return ("[error: wrong date-format]");
|
|
|
|
return (result.value);
|
2001-07-01 19:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if language and country were specified
|
|
|
|
* for this weblog. if so, it returns a Locale-object
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getLocale() {
|
2001-12-10 23:46:24 +00:00
|
|
|
if (this.language)
|
|
|
|
return (new java.util.Locale(this.language,this.country ? this.country : ""));
|
2001-07-01 19:27:28 +00:00
|
|
|
else
|
|
|
|
return (java.util.Locale.getDefault());
|
2001-07-09 20:01:48 +00:00
|
|
|
}
|
2001-12-10 23:46:24 +00:00
|
|
|
|
2001-12-12 15:18:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* helper function to sort story reads
|
|
|
|
* @param Obj story a to be compared with story b
|
|
|
|
* @param Obj story b to be compared with story a
|
|
|
|
* @return Integer -1: a>b; 1: a<b; 0: a=b
|
|
|
|
*/
|
|
|
|
function sortMostReads(s1, s2) {
|
|
|
|
var s1reads = s1.reads + s1.cache.reads;
|
|
|
|
var s2reads = s2.reads + s2.cache.reads;
|
|
|
|
if (s1reads > s2reads)
|
|
|
|
return(-1);
|
|
|
|
else if (s1reads < s2reads)
|
|
|
|
return(1);
|
|
|
|
else
|
|
|
|
return(0);
|
|
|
|
}
|
2001-12-16 18:06:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* function checks if story is online in weblog
|
|
|
|
* @param Obj story to check
|
|
|
|
* @return Boolean true if online, false if not
|
|
|
|
*/
|
|
|
|
|
|
|
|
function isStoryOnline(st) {
|
|
|
|
if (parseInt(st.online,10) == 2)
|
|
|
|
return true;
|
|
|
|
return false;
|
2002-02-05 11:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function parses a string for <img> tags and turns them
|
|
|
|
* into <a> tags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function rssConvertHtmlImageToHtmlLink(str) {
|
|
|
|
var re = new RegExp("<img src\\s*=\\s*\"?([^\\s\"]+)?\"?[^>]*?(alt\\s*=\\s*\"?([^\"]+)?\"?[^>]*?)?>");
|
|
|
|
re.ignoreCase = true;
|
|
|
|
re.global = true;
|
2002-02-05 11:25:11 +00:00
|
|
|
str = str.replace(re, "[<a href=\"$1\" title=\"$3\">Image</a>]");
|
2002-02-05 11:13:45 +00:00
|
|
|
return(str);
|
|
|
|
}
|
|
|
|
|
2002-03-27 11:24:36 +00:00
|
|
|
/**
|
|
|
|
* function deletes all assets of a weblog (recursive!)
|
|
|
|
*/
|
|
|
|
|
|
|
|
function deleteAll() {
|
|
|
|
this.members.deleteAll();
|
|
|
|
this.images.deleteAll();
|
|
|
|
this.goodies.deleteAll();
|
|
|
|
this.skins.deleteAll();
|
|
|
|
// loop over days and remove stories
|
|
|
|
for (var i=this.size();i>0;i--) {
|
|
|
|
var day = this.get(i-1);
|
|
|
|
day.deleteAll();
|
|
|
|
}
|
|
|
|
// loop over topics and remove stories
|
|
|
|
for (var i=this.topics.size();i>0;i--) {
|
|
|
|
var topic = this.topics.get(i-1);
|
|
|
|
topic.deleteAll();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if weblog is trusted
|
|
|
|
* @return Boolean true in case weblog is trusted, false otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
function isTrusted() {
|
|
|
|
if (parseInt(this.trusted,10))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-04-29 09:51:35 +00:00
|
|
|
|
2002-04-29 12:02:37 +00:00
|
|
|
/**
|
|
|
|
* send notification to weblogs.com
|
|
|
|
* that this weblog was updated
|
|
|
|
* @return Object with properties error and message
|
|
|
|
*/
|
|
|
|
|
2002-04-29 10:35:58 +00:00
|
|
|
function ping() {
|
2002-04-29 12:02:37 +00:00
|
|
|
// we're doing it the xml-rpc way
|
|
|
|
// (specs at http://newhome.weblogs.com/directory/11)
|
2002-04-29 10:24:22 +00:00
|
|
|
var xr = new Remote("http://rpc.weblogs.com/RPC2");
|
|
|
|
var ping = xr.weblogUpdates.ping(this.title, this.href());
|
|
|
|
|
2002-04-29 10:42:27 +00:00
|
|
|
var result = new Object();
|
|
|
|
result.error = ping.result.flerror;
|
|
|
|
result.message = ping.result.message;
|
|
|
|
|
2002-04-29 11:49:06 +00:00
|
|
|
if (result.error)
|
2002-04-29 12:02:37 +00:00
|
|
|
writeln("Error when notifying weblogs.com for updated weblog #" + this._id + ": " + result.message);
|
2002-04-29 11:49:06 +00:00
|
|
|
|
2002-04-29 12:02:37 +00:00
|
|
|
// this is the easy post url method (maybe faster?)
|
|
|
|
// var ping = getURL("http://newhome.weblogs.com/pingSiteForm?name=" + this.title + "&url=" + this.href());
|
2002-04-29 10:35:58 +00:00
|
|
|
|
2002-04-29 12:02:37 +00:00
|
|
|
// lastping is always set to now to prevent blogs
|
|
|
|
// hanging in the scheduler if a fatal error occurs
|
|
|
|
this.lastping = new Date();
|
2002-04-29 10:42:27 +00:00
|
|
|
return(result);
|
2002-04-29 09:51:35 +00:00
|
|
|
}
|