posts.xsl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. _ _ ____ _
  4. _| || |_/ ___| ___ _ __ _ __ ___ | |
  5. |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
  6. |_ _|___) | __/ |_) | |_) | (_) |_|
  7. |_||_| |____/ \___| .__/| .__/ \___/(_)
  8. |_| |_|
  9. Personal Social Web.
  10. Copyright (C) The #Seppo contributors. All rights reserved.
  11. This program is free software: you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation, either version 3 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. https://w3.org/TR/xslt-10
  22. https://w3.org/TR/xpath-10
  23. -->
  24. <xsl:stylesheet
  25. xmlns="http://www.w3.org/1999/xhtml"
  26. xmlns:a="http://www.w3.org/2005/Atom"
  27. xmlns:as="https://www.w3.org/ns/activitystreams#"
  28. xmlns:georss="http://www.georss.org/georss"
  29. xmlns:ldp="http://www.w3.org/ns/ldp#"
  30. xmlns:media="http://search.yahoo.com/mrss/"
  31. xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
  32. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  33. xmlns:schema="http://schema.org#"
  34. xmlns:se="http://seppo.social/"
  35. xmlns:seppo="http://seppo.social/2023/ns#"
  36. xmlns:toot="http://joinmastodon.org/ns#"
  37. xmlns:wf="urn:ietf:rfc:7033"
  38. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  39. exclude-result-prefixes="a as opensearch ldp media georss rdf se"
  40. xmlns:math="http://exslt.org/math"
  41. extension-element-prefixes="math"
  42. version="1.0">
  43. <!-- xsl:variable name="redirector">https://anonym.to/?</xsl:variable --> <!-- mask the HTTP_REFERER -->
  44. <xsl:variable name="redirector"></xsl:variable>
  45. <xsl:variable name="archive">https://web.archive.org/web/</xsl:variable>
  46. <xsl:include href="util.xsl"/>
  47. <xsl:output
  48. method="html"
  49. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  50. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  51. <!-- http://stackoverflow.com/a/16328207 -->
  52. <xsl:key name="CategorY" match="a:entry/a:category" use="@term" />
  53. <xsl:variable name="self" select="/*/a:link[@rel = 'self']/@href"/>
  54. <xsl:variable name="xml_base_absolute" select="/*/@xml:base"/>
  55. <xsl:variable name="xml_base" select="normalize-space($xml_base_absolute)"/>
  56. <xsl:variable name="xml_base_pub" select="concat($xml_base,'o')"/>
  57. <xsl:variable name="skin_base" select="concat($xml_base,'themes/current')"/>
  58. <xsl:variable name="cgi_base" select="concat($xml_base,'seppo.cgi')"/>
  59. <!-- a bit hairy, but actually works -->
  60. <xsl:variable name="xml_base_relative">../../<xsl:choose>
  61. <xsl:when test="'seppo.cgi/search/?q=' = substring($self, 1, 24)"/>
  62. <xsl:when test="'//' = translate($self, 'abcdefghijklmnopqrstuvwxyz0123456789-', '')"/>
  63. <xsl:otherwise>../</xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:variable>
  66. <xsl:variable name="perso" select="document(concat($xml_base,'activitypub/actor.xml'))/rdf:RDF/as:Person"/>
  67. <xsl:template match="/">
  68. <!--
  69. Do not set a class="logged-out" initially, but do via early JavaScript.
  70. If JavaScript is off, we need a mixture between logged-in and -out.
  71. -->
  72. <html xmlns="http://www.w3.org/1999/xhtml" data-xml-base-pub="{$xml_base_pub}" lang="en" xml:lang="en" class="script-inactive">
  73. <xsl:if test="234 &lt; count(a:feed/a:category)">
  74. <xsl:attribute name="class">manytags</xsl:attribute>
  75. </xsl:if>
  76. <xsl:call-template name="head"/>
  77. <body>
  78. <xsl:apply-templates select="a:feed|a:entry" mode="root"/>
  79. </body>
  80. </html>
  81. </xsl:template>
  82. <xsl:template name="head">
  83. <head>
  84. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  85. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  86. <link rel="icon" type="image/jpg" href="{$xml_base}me-avatar.jpg"/>
  87. <link rel="stylesheet" type="text/css" href="{$skin_base}/awesomplete.css"/>
  88. <link rel="stylesheet" type="text/css" href="{$skin_base}/style.css"/>
  89. <script src="{$skin_base}/posts.js"></script>
  90. <script src="{$skin_base}/awesomplete.js"></script>
  91. <!-- script src="{$skin_base}/../../live.js"></script -->
  92. <link rel="alternate" type="application/atom+xml" href="."/>
  93. <link rel="self" type="application/xhtml+xml" href="."/>
  94. <title><xsl:value-of select="a:*/a:title"/></title>
  95. </head>
  96. </xsl:template>
  97. <xsl:template match="a:feed" mode="root">
  98. <noscript><p>JavaScript deactivated, almost fully functional, but <em>nicer</em> if on.</p></noscript>
  99. <xsl:call-template name="links_commands"/>
  100. <!-- h1><xsl:value-of select="a:title"/></h1 -->
  101. <p id="tags" class="categories">
  102. <xsl:variable name="countMax">
  103. <!-- https://stackoverflow.com/a/17966412 -->
  104. <xsl:for-each select="a:category">
  105. <xsl:sort select="@label" data-type="number" order="descending"/>
  106. <xsl:if test="position() = 1"><xsl:value-of select="@label"/></xsl:if>
  107. </xsl:for-each>
  108. </xsl:variable>
  109. <xsl:variable name="labelsDesc">
  110. <xsl:for-each select="a:category">
  111. <xsl:sort select="@label" order="descending"/>
  112. <xsl:value-of select="@label"/>
  113. </xsl:for-each>
  114. </xsl:variable>
  115. <xsl:for-each select="a:category[@label >= 1]">
  116. <xsl:sort select="@term" order="ascending"/>
  117. <!-- not log, just linear, similar to https://github.com/sebsauvage/Shaarli/blob/master/index.php#L1254 -->
  118. <xsl:variable name="size" select="8 + 40 * @label div $countMax"/>
  119. <a style="font-size:{$size}pt" href="{$cgi_base}/search/?q=%23{@term}+" class="tag" data-count="{@label}"><span class="label"><xsl:value-of select="@term"/></span><span style="font-size:8pt">&#160;(<span class="count"><xsl:value-of select="@label"/></span>)</span></a><xsl:text> </xsl:text>
  120. </xsl:for-each>
  121. </p>
  122. <ol id="entries" data-level="0" class="even">
  123. <xsl:apply-templates select="a:entry"/>
  124. </ol>
  125. <xsl:call-template name="prev-next">
  126. <xsl:with-param name="id">lower</xsl:with-param>
  127. </xsl:call-template>
  128. <xsl:call-template name="footer"/>
  129. </xsl:template>
  130. <xsl:template name="prev-next">
  131. <xsl:param name="id">-</xsl:param>
  132. <xsl:if test="a:link[@rel='first'] or a:link[@rel='last']">
  133. <table id="{$id}-prev-next" class="prev-next noshade">
  134. <tbody>
  135. <tr>
  136. <xsl:variable name="self" select="a:link[@rel='self']"/>
  137. <td class="text-left" aria-label="First" title="most recent">
  138. <xsl:variable name="link" select="a:link[@rel='first']"/>
  139. <a href="{$xml_base_relative}{$link/@href}#upper-prev-next" class="first btn"><xsl:value-of select="$link/@title"/></a>
  140. </td>
  141. <td class="text-center" title="more recent">
  142. <xsl:variable name="link" select="a:link[@rel='previous']"/>
  143. <a href="{$xml_base_relative}{$link/@href}#lower-prev-next" class="previous enabled btn">&#160;<xsl:value-of select="$link/@title"/>&#160;</a>
  144. </td>
  145. <td class="text-center" title="current">
  146. <span class="hidden-xs"></span><xsl:value-of select="$self/@title"/>
  147. </td>
  148. <td class="text-center" title="older">
  149. <xsl:variable name="link" select="a:link[@rel='next']"/>
  150. <xsl:variable name="disabled"><xsl:if test="not($link)">disabled</xsl:if></xsl:variable>
  151. <a href="{$xml_base_relative}{$link/@href}#upper-prev-next" class="previous {$disabled} btn">&#160;<xsl:value-of select="$link/@title"/>&#160;</a>
  152. </td>
  153. <td class="text-right" title="oldest">
  154. <xsl:variable name="link" select="a:link[@rel='last']"/>
  155. <a href="{$xml_base_relative}{$link/@href}#lower-prev-next" class="last btn"><xsl:value-of select="$link/@title"/></a>
  156. </td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. </xsl:if>
  161. </xsl:template>
  162. <xsl:template name="links_commands">
  163. <div aria-label="Header" id="header">
  164. <div id="banner">
  165. <div id="banner-img">
  166. <img alt="Banner" src="{$xml_base}me-banner.jpg"/>
  167. </div>
  168. <div id="head-grid">
  169. <div>
  170. <a class="btn" href="{$xml_base}" rel="first">🏡 <span class="hidden-xs">Home</span></a>
  171. <form action="{$cgi_base}/notifyme" class="hidden-logged-in" id="form_notifyme" name="notifyme">
  172. <input name="resource" required="required" pattern="(acct:|@)?[a-zA-Z0-9._~\-]+@[a-zA-Z0-9._~\-]+"
  173. placeholder="@alice@example.com" title="your address to get notified" />
  174. <input name="rel" type="hidden" value="http://ostatus.org/schema/1.0/subscribe"/>
  175. <input type="submit" value="Notify 🔔" />
  176. </form>
  177. <a class="btn hidden-logged-out" href="{$cgi_base}/timeline/" rel="nofollow">🕞 <span class="hidden-xs">Timeline</span></a>
  178. <a class="btn hidden-logged-out" href="{$cgi_base}/profile" rel="nofollow">🎭 <span class="hidden-xs">Profile</span></a>
  179. <a class="btn hidden-logged-out" href="{$cgi_base}/backoffice/" rel="nofollow" title="Backoffice">⚙️ <span class="hidden-xs">Backoffice</span></a>
  180. </div>
  181. <a id="link_login" href=
  182. "{$cgi_base}/login?returnurl=.." class="btn hidden-logged-in" rel="nofollow" name=
  183. "link_login"><span class="hidden-xs">Login</span> 👋</a>
  184. <a id="link_logout" href=
  185. "{$cgi_base}/logout" class="btn hidden-logged-out" rel="nofollow" name=
  186. "link_logout"><span class="hidden-xs">Logout</span> 👋</a>
  187. </div>
  188. <div id="subscribe" class="hidden-logged-out">
  189. <a class="btn" href="{$xml_base}activitypub/subscribed/" rel="nofollow" title="a.k.a. Following">👂 <span class="hidden-xs">Subscribed</span></a>
  190. <a class="btn" href="{$xml_base}activitypub/notify/" rel="nofollow" title="a.k.a. Followers">📣 <span class="hidden-xs">Notify</span></a>
  191. <a class="btn disabled" href="{$xml_base}activitypub/blocked/" rel="nofollow">🤐 <span class="hidden-xs">Blocked</span></a>
  192. </div>
  193. </div>
  194. <div class="" id="avatar">
  195. <a href="{$xml_base}"><img alt="Avatar" src="{$xml_base}me-avatar.jpg"/></a>
  196. </div>
  197. <h3 class="" id="name"><a href="{$perso/as:url/@rdf:resource}" title="name"><xsl:value-of select="$perso/as:name"/></a></h3>
  198. <xsl:variable name="host1" select="$perso/as:url/@rdf:resource"/>
  199. <xsl:variable name="host0" select="substring-after($host1,'://')"/>
  200. <xsl:variable name="host" select="substring-before($host0,'/')"/>
  201. <p class=""><a href="{$perso/as:url/@rdf:resource}" title="preferredUsername">@<span id="preferredUsername"><xsl:value-of select="$perso/as:preferredUsername"/></span>@<xsl:value-of select="$host"/></a></p>
  202. <xsl:if test="1 or a:link[@rel='first']/@href = a:link[@rel='self']/@href">
  203. <div class="noshade hidden-logged-in" id="bio">
  204. <p class="clickable" title="summary">
  205. <xsl:call-template name="linefeed2br">
  206. <xsl:with-param name="string" select="$perso/as:summary"/>
  207. </xsl:call-template>
  208. </p>
  209. <dl>
  210. <xsl:for-each select="$perso/as:attachment/schema:PropertyValue[schema:value]">
  211. <dt class="clickable"><xsl:value-of select="as:name"/></dt>
  212. <dd class="clickable"><xsl:value-of select="schema:value"/></dd>
  213. </xsl:for-each>
  214. </dl>
  215. </div>
  216. </xsl:if>
  217. <xsl:comment> https://stackoverflow.com/a/18520870 http://jsfiddle.net/66Ynx/ </xsl:comment>
  218. <form id="form_search" name="form_search" action="{$cgi_base}/search/">
  219. <input disabled="disabled" class="disabled awesomplete" tabindex="100" name="q" id="q" value="{@se:searchTerms}" type="text" placeholder="🔍
  220. Search text or #tag or @actor ..." data-multiple="true"/>
  221. </form>
  222. <form id="form_post" name="form_post" class="hidden-logged-out" action="{$cgi_base}/post">
  223. <input tabindex="300" name="post" type="text" placeholder="What to #post? (text note or URL)" autofocus="autofocus"/>
  224. </form>
  225. <xsl:call-template name="prev-next">
  226. <xsl:with-param name="id">upper</xsl:with-param>
  227. </xsl:call-template>
  228. </div>
  229. </xsl:template>
  230. <xsl:template name="footer">
  231. <p id="footer">
  232. <a title="Syndicate" href="{$xml_base_absolute}{a:link[@rel='self']/@href}">
  233. <img alt="Feed" src="{$skin_base}/feed-icon.svg"/>
  234. </a>
  235. <xsl:text> </xsl:text>
  236. <a title="Validate (Atom 1.0)" href="https://validator.w3.org/feed/check.cgi?url={$xml_base_absolute}{a:link[@rel='self']/@href}">
  237. <img alt="Validity badge (Atom 1.0)" src="{$skin_base}/valid-atom.svg"/>
  238. </a>
  239. <!-- <xsl:text> </xsl:text>
  240. <a href="https://validator.w3.org/check?uri=referer">
  241. <img alt="Valid XHTML 1.0 Strict" src="{$skin_base}/valid-xhtml10-blue-v.svg"/>
  242. </a>
  243. <a href="https://jigsaw.w3.org/css-validator/check/referer?profile=css3&amp;usermedium=screen&amp;warning=2&amp;vextwarning=false&amp;lang=de">
  244. <img alt="CSS ist valide!" src="{$skin_base}/valid-css-blue-v.svg"/>
  245. </a>
  246. -->
  247. <xsl:text> </xsl:text>
  248. <!--
  249. <a href="{a:link[@rel='about']/@href}">
  250. About<xsl:if test="string-length(a:link[@rel='about']/@href) &lt; 2"><span> link rel='about' missing.</span></xsl:if>
  251. </a>
  252. <xsl:text> </xsl:text>
  253. <a href="{a:link[@rel='license']/@href}">
  254. <xsl:value-of select="a:link[@rel='license']/@title"/><xsl:if test="string-length(a:link[@rel='license']/@href) &lt; 2"><span> link rel='license' missing.</span></xsl:if>
  255. </a>
  256. <xsl:text> </xsl:text>
  257. <a href="{a:link[@rel='terms-of-service']/@href}">
  258. § Imprint<xsl:if test="string-length(a:link[@rel='terms-of-service']/@href) &lt; 2"><span> link rel='terms-of-service' missing.</span></xsl:if>
  259. </a>
  260. <xsl:text> </xsl:text>
  261. <a href="{a:link[@rel='privacy-policy']/@href}">
  262. 🤫 Privacy<xsl:if test="string-length(a:link[@rel='terms-of-service']/@href) &lt; 2"><span> link rel='terms-of-service' missing.</span></xsl:if>
  263. </a>
  264. -->
  265. <xsl:text> </xsl:text>
  266. <a title="Generator" href="https://{a:generator/@uri}">
  267. <xsl:value-of select="a:generator"/>
  268. </a>
  269. </p>
  270. </xsl:template>
  271. <xsl:template match="a:entry" mode="root">
  272. <noscript><p>JavaScript deactivated, almost fully functional, but <em>nicer</em> if on.</p></noscript>
  273. <xsl:call-template name="links_commands"/>
  274. <ol id="entries" data-level="0" class="even">
  275. <xsl:apply-templates select="."/>
  276. </ol>
  277. <xsl:call-template name="footer"/>
  278. </xsl:template>
  279. <xsl:template match="a:entry">
  280. <xsl:variable name="link" select="a:link[not(@rel)]/@href"/>
  281. <xsl:variable name="self" select="a:link[@rel='self']/@href"/>
  282. <xsl:variable name="id_slash" select="substring-after($self, '/p/')"/>
  283. <xsl:variable name="id" select="substring-after($self, '#')"/>
  284. <li class="noshade" id="{$id}" data-id="{a:id}">
  285. <h3>
  286. <xsl:if test="media:thumbnail/@url">
  287. <!-- https://varvy.com/pagespeed/defer-images.html -->
  288. <!-- img alt="Vorschaubild" data-src="{media:thumbnail/@url}" src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" / -->
  289. </xsl:if>
  290. <xsl:choose>
  291. <xsl:when test="$link">
  292. <a href="{$redirector}{$link}" rel="noopener noreferrer" referrerpolicy="no-referrer"><xsl:value-of select="a:title"/></a>
  293. </xsl:when>
  294. <xsl:otherwise>
  295. <xsl:value-of select="a:title"/>
  296. </xsl:otherwise>
  297. </xsl:choose>
  298. </h3>
  299. <xsl:if test="a:summary">
  300. <h5>
  301. <xsl:call-template name="linefeed2br">
  302. <xsl:with-param name="string" select="a:summary"/>
  303. </xsl:call-template>
  304. </h5>
  305. </xsl:if>
  306. <!-- p class="small text-right"><a><xsl:value-of select="$link"/></a></p -->
  307. <!-- html content won't work that easy (out-of-the-firebox): https://bugzilla.mozilla.org/show_bug.cgi?id=98168#c140 -->
  308. <!-- workaround via jquery: http://stackoverflow.com/a/9714567 -->
  309. <!-- Überbleibsel vom Shaarli Atom Feed raus: -->
  310. <!-- xsl:value-of select="substring-before(a:content[not(@src)], '&lt;br&gt;(&lt;a href=&quot;https://links.mro.name/?')" disable-output-escaping="yes" / -->
  311. <xsl:apply-templates select="a:content"/>
  312. <xsl:if test="a:category">
  313. <p class="categories">
  314. <xsl:for-each select="a:category">
  315. <xsl:sort select="@term"/>
  316. <xsl:if test="position() != 1">
  317. <xsl:text>, </xsl:text>
  318. </xsl:if>
  319. <a href="{@scheme}{@term}/" class="tag">#<xsl:value-of select="@term"/></a>
  320. </xsl:for-each>
  321. </p>
  322. </xsl:if>
  323. <p class="footer">
  324. <xsl:variable name="entry_updated" select="a:updated"/>
  325. <xsl:variable name="entry_updated_human"><xsl:call-template name="human_time"><xsl:with-param name="time" select="$entry_updated"/></xsl:call-template></xsl:variable>
  326. <xsl:variable name="entry_published" select="a:published"/>
  327. <xsl:variable name="entry_published_human"><xsl:call-template name="human_time"><xsl:with-param name="time" select="$entry_published"/></xsl:call-template></xsl:variable>
  328. <a class="time" title="last: {$entry_updated_human}" href="{a:link[@rel='self']/@href}"><xsl:value-of select="$entry_published_human"/> 🔗</a>
  329. <xsl:for-each select="a:author[wf:uri]">
  330. <xsl:text> * </xsl:text>
  331. <a class="from" title="from" href="{$cgi_base}/{wf:uri}">
  332. <!-- img alt="Avatar" src="{wf:icon}"/ -->
  333. @<xsl:value-of select="substring-after(wf:uri,'acct:')"/>
  334. </a>
  335. </xsl:for-each>
  336. <xsl:if test="$link">
  337. *
  338. <a href="{$archive}{$link}" rel="noopener noreferrer" referrerpolicy="no-referrer">@archive.org</a>
  339. </xsl:if>
  340. <span class="hidden-logged-out">
  341. <xsl:variable name="can_edit" select="a:link[@rel='edit']/@href"/>
  342. <xsl:if test="$can_edit">
  343. *
  344. <a class="disabled" href="{$cgi_base}/edit?id={translate(a:id,'#','$')}" rel="nofollow">Edit</a><xsl:text> </xsl:text>
  345. </xsl:if>
  346. *
  347. <xsl:if test="not($can_edit)">
  348. <a class="disabled" href="{$cgi_base}/like?id={translate(a:id,'#','$')}" rel="nofollow" title="Like">❤️ </a>
  349. &#xa0;
  350. </xsl:if>
  351. <a class="disabled" href="{$cgi_base}/boost?id={translate(a:id,'#','$')}" rel="nofollow" title="Boost">🚀 </a>
  352. <xsl:if test="not($can_edit)">
  353. &#xa0;
  354. <a class="disabled" href="{$cgi_base}/block?id={a:author/a:uri}" rel="nofollow" title="Block">🤐 </a>
  355. </xsl:if>
  356. &#xa0;
  357. <a class="disabled" href="{$cgi_base}/reply?id={translate(a:id,'#','$')}" rel="nofollow" title="Reply">💬 </a>
  358. <!-- xsl:text> </xsl:text>
  359. <a href="{$xml_base}{a:link[@rel='edit']/@href}" rel="nofollow">Edit</a><xsl:text> </xsl:text -->
  360. </span>
  361. *
  362. <a class="disabled" href="{$cgi_base}/replies?id={a:id}">Replies</a>
  363. </p>
  364. <!-- iframe data-src="{$cgi_base}/replies?id={a:id}"/ -->
  365. </li>
  366. </xsl:template>
  367. <xsl:template match="a:content[not(@type) or @type = 'text']">
  368. <xsl:if test="string-length(.) &gt; 0">
  369. <p class="clickable rendered type-text">
  370. <xsl:call-template name="linefeed2br">
  371. <xsl:with-param name="string" select="."/>
  372. </xsl:call-template>
  373. </p>
  374. </xsl:if>
  375. </xsl:template>
  376. </xsl:stylesheet>