Warning: session_start(): open(/var/lib/php/sessions/sess_qtd23dmstb9i8e68m0u77gjiso, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
// See #1023660 for the older 99 lines version
concept Page {
S url;
}
concept Entry {
S globalID = aGlobalID();
new Ref page;
int count;
S key, value;
S ip;
}
static int lines;
sbool allowMultipleCasesInValues = true;
p {
dbIndexingCI(Page, 'url, Entry, 'key, Entry, 'value);
lines = countLines(mySource());
}
sS getValue(Page page, S key) {
ret getString value(highestByField count(objectsWhereIC(findBackRefs(page, Entry), +key)));
}
sS pageDisplayName(Page page) {
S name = getValue(page, "read as");
bool unnaturalName = nempty(name) && !eq(makeAGIDomain(name), page.url);
ret unnaturalName ? name + " " + squareBracketed(page.url) : or2(name, unpackAGIDomainOpt(page.url));
}
set flag NoNanoHTTPD. html {
S q = params.get('q);
S domain = or2(params.get('domain), domain());
if (nempty(q)) {
domain = makeAGIDomain(q);
if (l(domain) > maximumDomainPartLength()) // escape with "domain="
ret hrefresh("http://agi.blue/" + hquery(+domain, key := "read as", value := q));
ret hrefresh("http://" + domain + (eq(q, domain) ? "" : "/" + hquery(key := "read as", value := q)));
//uri = "/"; replaceMapWithParams(params, key := "read as", value := q);
}
S url = domain + dropTrailingSlash(uri);
Page page, bool newPage = unpair uniqCI2_sync(Page, +url);
if (newPage) dbLog("New page", +url);
S top = p(ahref("http://agi.blue", hsnippetimg(#1101682, width := 565/5, height := 800/5, title := "Robot by Peerro @ DeviantArt")))
+ p(small(b(ahref("http://agi.blue", "agi.blue"))
+ " | " + targetBlank(progLink(), "source code") + " of this web site (" + nLines(lines) + ") | " + targetBlank("https://gitter.im/agi-blue/community", "sponsor https?") + " | by " + targetBlank("https://BotCompany.de", "BC") + " | " + targetBlank("http://fiverr.tinybrain.de/", "Fiverr") + " | " + targetBlank("https://discordapp.com/invite/SEAjPqk", "Discord")));
if (eqicOneOf(url, "agi.blue", "www.agi.blue"))
ret hhtml(hhead_title("agi.blue Overview") // HOME PAGE
+ hbody_fullcenter(top
+ hform(b("GIVE ME INPUT:") + "
" + htextinput('q) + " " + hsubmit("Ask"))
+ h1("agi.blue has " + nPages(countConcepts(Page)))
+ p(nlToBr(nemptyLines(map(func(Page p) -> S {
ahref(fixAGILink("http://" + p.url), htmlEncode2(pageDisplayName(p)))
}, sortedByFieldDesc _modified(list(Page))))))
));
S key = trim(params.get('key)), value = trim(params.get('value));
L entries = withDBLock(func -> L {
L entries = findBackRefs(page, Entry);
print("Entries: " + l(entries));
if (nempty(key) && nempty(value)) {
S ip = subBot_clientIP();
if (!any(e -> eqic(e.key, key) && eq_icIf(!allowMultipleCasesInValues, e.value, value) && eq(e.ip, ip), entries)) {
print("SAVING");
Entry e = cnew Entry(+page, +key, +value, +ip, count := l(entries) + 1);
entries.add(e);
dbLog("New entry", page := page.url, globalID := e.globalID, count := e.count, +key, +value);
}
}
ret entries;
});
sortByFieldInPlace created(entries);
numberEntriesInConceptField count(entries);
S get = params.get('get);
if (nempty(get))
ret serveText(jsonEncode(collect value(llNotNulls(firstWhereIC(entries, key := get)))));
S key2 = key, value2 = value; if (nempty(key) && nempty(value)) key2 = value2 = ""; // input reset
bool withHidden = eq(params.get('withHidden), "1");
new Set hide;
if (!withHidden) for (Entry e : entries) if (eqic(e.key, 'hide) && isSquareBracketedInt(e.value)) addAll(hide, e.count, parseInt(unSquareBracket(e.value)));
new MultiMap mmMeta;
for (Entry e : entries) if (isSquareBracketedInt(e.key)) mmMeta.put(parseInt(unSquareBracket(e.key)), e.value);
new MultiMap mm;
for (Entry e : entries) mm.put(e.key, e.value);
S name = or2(/* ouch */ last(mm.get("read as")), /* end ouch */ unpackAGIDomain(page.url), page.url);
ret hhtml(hhead_title(pageDisplayName(page)) + hbody(hfullcenterAndTopRight(
top + h1(ahref_unstyled("http://" + url, htmlEncode2(name)) + (newPage ? " [huh????]" : ""))
+ p(nlToBr(nemptyLines(map(entries, func(Entry e) -> S {
!withHidden && (hide.contains(e.count) || eqic(e.key, "read as") && eqic(e.value, name)) ? "" : "[" + e.count + "] " +
htmlencode2(e.key) + ": " + b(
isURL(e.value)
|| cic(mmMeta.get(e.count), "is a URL")
|| isAGIDomain(e.value)
? ahref(fixAGILink(absoluteURL(e.value)), htmlencode2(e.value))
: ahref(agiBlue_linkForPhrase(e.value), htmlencode2(e.value))
) }))))
+ hpostform(h3("Add an entry")
+ "Key: " + hinputfield(key := key2) + " Value: " + hinputfield(value := value2) + "
" + hsubmit("Add")
)
, hform(b("GIVE ME INPUT:") + " " + htextinput('q) + " " + hsubmit("Ask")))));
}
svoid dbLog(O... params) {
logQuoted(programFile("db.log"), ll(params));
}