Sourcecode in Story/macros.js:
1: function backlinks_macro(param) {
2: // check if scheduler has done a new update of accesslog
3: // if not and we have cached backlinks simply return them
4: if (this.cache.lrBacklinks >= app.data.lastAccessLogUpdate)
5: return this.cache.rBacklinks;
6:
7: var c = getDBConnection("antville");
8: var dbError = c.getLastError();
9: if (dbError)
10: return getMessage("error.database", dbError);
11:
12: // we're doing this with direct db access here
13: // (there's no need to do it with prototypes):
14: var query = "select ACCESSLOG_REFERRER, count(*) as \"COUNT\" from AV_ACCESSLOG where ACCESSLOG_F_TEXT = " + this._id + " group by ACCESSLOG_REFERRER order by \"COUNT\" desc, ACCESSLOG_REFERRER asc;";
15: var rows = c.executeRetrieval(query);
16: var dbError = c.getLastError();
17: if (dbError)
18: return getMessage("error.database", dbError);
19:
20: // we show a maximum of 100 backlinks
21: var limit = Math.min((param.limit ? parseInt(param.limit, 10) : 100), 100);
22: res.push();
23:
24: var skinParam = new Object();
25: var cnt = 0;
26: while (rows.next() && cnt <= limit) {
27: skinParam.count = rows.getColumnItem("COUNT");
28: skinParam.referrer = rows.getColumnItem("ACCESSLOG_REFERRER");
29: skinParam.text = skinParam.referrer.clip(50, "...", true);
30: this.renderSkin("backlinkItem", skinParam);
31: cnt++;
32: }
33: rows.release();
34: // cache rendered backlinks and set timestamp for
35: // checking if backlinks should be rendered again
36: skinParam = {referrers: res.pop()};
37: if (skinParam.referrers.length > 0)
38: this.cache.rBacklinks = this.renderSkinAsString("backlinks", skinParam);
39: else
40: this.cache.rBacklinks = "";
41: this.cache.lrBacklinks = new Date();
42: res.write(this.cache.rBacklinks);
43: return;
44: }
|