74 lines
2.5 KiB
Text
74 lines
2.5 KiB
Text
var deny = this.isNotPublic(session.user);
|
|
if (deny) {
|
|
res.message = deny;
|
|
session.data.referrer = this.href();
|
|
res.redirect(this.members.href("login"));
|
|
}
|
|
|
|
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 = 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 += "<i>" + getMsg("error","searchNothingFound",query) + "</i>";
|
|
else {
|
|
var start = 0;
|
|
var end = found;
|
|
|
|
if (found == 1)
|
|
res.data.body += getMsg("confirm","resultOne",query);
|
|
else if (found <= 10)
|
|
res.data.body += getMsg("confirm","resultMany",new Array(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 += getMsg("confirm","resultMany",new Array(encodeForm(query),found));
|
|
res.data.body += getMsg("confirm","resultDisplay",new Array(start+1,end));
|
|
}
|
|
|
|
// 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 += "<br /><br />"+renderSkinAsString("prevpagelink",sp);
|
|
}
|
|
|
|
// render result
|
|
res.data.body += '<table border="0">';
|
|
for (var i=start; i<end; i++) {
|
|
var site = root.get(result[i].sitealias);
|
|
var item = site.allcontent.get(result[i].sid);
|
|
res.data.body += item.renderSkinAsString("searchview");
|
|
}
|
|
|
|
res.data.body += '</table>';
|
|
|
|
// render next links, if necessary
|
|
if (end < found) {
|
|
var sp = new Object();
|
|
sp.url = this.href() + "search?q="+escape(query)+"&start="+Math.min(found-1,start+10);
|
|
sp.text = "next results";
|
|
res.data.body += renderSkinAsString("nextpagelink",sp);
|
|
}
|
|
}
|
|
}
|
|
|
|
this.renderSkin("page");
|