!7 static S text, title; concept Text { S conceptID; S title; S text; S by; } p { db(); indexConceptField(Text, 'conceptID); indexConceptField(Text, 'by); load("text"); load("title"); if (isMainProgram()) serveHttpAndOpenBrowser(); } synchronized html { uri = dropPrefix("/", uri); if (possibleGlobalID(uri)) { S id = uri; Text t = findConcept(Text, conceptID := id); ret t == null ? "Text with ID " + id + " not found" : p(ahref(botLink(), "<< back")) + h3(t.conceptID + " - " + dynamize(or2(t.title, "Untitled"))) + textFormat(t.text) + p("by " + t.by); } S newTitle = params.get("title"); if (newTitle != null) { title = newTitle; save("title"); } S newText = params.get("text"); if (newText != null) { text = newText; save("text"); } S user = cookieConcept(); S msg = ""; if (nempty(params.get("publish"))) { Text t = uniq_sync(Text, +title, +text, by := user); if (empty(t.conceptID)) cset(t, conceptID := aGlobalID()); msg = "Published as: " + t.conceptID; } S list = p("Published texts: " + join(", ", map(func(Text t) { ahref(selfLink(t.conceptID), t.conceptID) }, list(Text)))); ret (empty(msg) ? "" : p(msg)) + list + p("You are: " + or2(user, "?")) + hpostform([[
#TEXT#<>
|
|