diff --git a/themes/hugo-mastodon-comments/static/comments/config.sample.php b/themes/hugo-mastodon-comments/static/comments/config.sample.php index bbfa309..7671577 100644 --- a/themes/hugo-mastodon-comments/static/comments/config.sample.php +++ b/themes/hugo-mastodon-comments/static/comments/config.sample.php @@ -1,9 +1,11 @@ 'https://mastodon.social', - 'user-id' => 379833, - 'search-url' => 'https?://fsfe.org', // please use https?:// as schema - 'cache_toots' => 300, - 'cache_comments' => 300, - 'debug' => true + 'mastodon-instance' => 'https://mastodon.social', // URL of your Mastodon instance + 'user-id' => 379833, // Your Mastodon-ID. A bit tricky to find out, the API might help + // the URL of your blog. All toots are searched for this string + // please use https?:// as schema + 'search-url' => 'https?://fsfe.org', + 'cache_toots' => 300, // seconds to cache toots + 'cache_comments' => 300, // seconds to cache comments (per ID) + 'debug' => false // writes some debug messages in error_log ]; diff --git a/themes/hugo-mastodon-comments/static/comments/getcomments.js b/themes/hugo-mastodon-comments/static/comments/getcomments.js index 2c02f81..c9c85be 100644 --- a/themes/hugo-mastodon-comments/static/comments/getcomments.js +++ b/themes/hugo-mastodon-comments/static/comments/getcomments.js @@ -43,7 +43,7 @@ $(document).ready(function() { } else { $("#comments").empty(); $("#statistics").empty(); - $("#reference").append("Comments are handled by my Mastodon account. Sadly this article wasn't published at Mastodon. Feel free to send me a mail if you want to share your thoughts regarding this topic."); + $("#reference").append("Comments are handled by my Mastodon account. Sadly this article wasn't published at Mastodon. Feel free to send me a mail if you want to share your thoughts regarding this topic."); } } diff --git a/themes/hugo-mastodon-comments/static/comments/getcomments.php b/themes/hugo-mastodon-comments/static/comments/getcomments.php index fe418b4..06fe4aa 100644 --- a/themes/hugo-mastodon-comments/static/comments/getcomments.php +++ b/themes/hugo-mastodon-comments/static/comments/getcomments.php @@ -1,5 +1,6 @@ tags, until (and excluding) a " preg_match("|$searchurl.+?(?=\")|i", $json['content'], $matches); if(!empty($matches)) { - return(strtolower($matches[0])); + return(strtolower($matches[0])); // take first match inside toot } else { return(""); } } /* of context, extract the interesting bits */ function filterComments($descendants, $root, &$result) { + // go through each comment foreach ($descendants as $d) { $result['comments'][$d['id']] = [ 'author' => [ @@ -182,7 +185,7 @@ if ($cachebreak) { debug("Toots cache is up-to-date"); } -/* prepare $result array */ +/* prepare empty $result array with structure */ $result = ['comments' => [], 'stats' => ['reblogs' => 0, 'favs' => 0, 'replies' => 0, 'url' => '', 'root' => 0]]; /* check if URL from $search exists in $toots */ @@ -190,7 +193,7 @@ $id = array_keys(array_column($toots, 'url'), strtolower($search)); if (empty($id)) { debug("Blog URL \"$search\" has not been found"); } else { - // if multiple exist, take the oldest one (highest array position) + // if multiple toots with the searched URL exist, take the oldest one (largest array index) $id = $toots[end($id)]['id']; /* read cached comments, or reload new comments if cached data too old */ @@ -219,6 +222,7 @@ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // headers to tell that result is JSON header('Content-type: application/json'); +// actually output result as JSON, to be digested by getcomments.js echo json_encode($result); ?>