diff --git a/metadata.json b/metadata.json
index 445dc6c..5c56bd4 100644
--- a/metadata.json
+++ b/metadata.json
@@ -1,10 +1,10 @@
{
- "author": "ALGZB",
- "email": "hello@algzb.com",
- "website": "https://algzb.com/github-comments-plugin-for-bludit",
- "version": "1.0",
- "releaseDate": "2020-09-10",
- "license": "MIT",
- "compatible": "3.13.1",
- "notes": ""
+ "author": "spleenftw",
+ "email": "",
+ "website": "https://github.com/Spleenftw/github-comments-for-bludit",
+ "version": "1.2.0",
+ "releaseDate": "2026-06-02",
+ "license": "MIT",
+ "compatible": "3.22.0",
+ "notes": "Fixed enable/disable toggles (PHP truthy-string bug); added Follow Site Theme option (reads blowdit-theme cookie); repo guard renders nothing when repo is unconfigured; htmlspecialchars escaping on repo and theme output."
}
diff --git a/plugin.php b/plugin.php
index 4ea3333..694ff00 100644
--- a/plugin.php
+++ b/plugin.php
@@ -5,128 +5,98 @@ class utterances extends Plugin {
public function init()
{
$this->dbFields = array(
- 'myUtterancesRepo'=>'',
- 'enablePages'=>true,
- 'enableStatic'=>true,
- 'enableSticky'=>true,
- 'utterancesTheme'=>''
+ 'myUtterancesRepo' => '',
+ 'enablePages' => true,
+ 'enableStatic' => true,
+ 'enableSticky' => true,
+ 'followSiteTheme' => true,
+ 'utterancesTheme' => 'github-dark'
);
}
+ private function isOn($key)
+ {
+ $v = $this->getValue($key);
+ return ($v === true || $v === 'true' || $v === 1 || $v === '1');
+ }
+
public function form()
{
global $L;
- $html = '
';
- $html .= $L->get('utterances-installation');
- $html .= '
';
+ $toggle = function ($key, $label) use ($L) {
+ $on = $this->isOn($key);
+ return ''
+ . '
';
+ };
- // Add your Utterances GitHub repository
+ $html = ''.$L->get('utterances-installation').'
';
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= ''.$L->get('utterances-tip').'';
- $html .= '
';
+ $html .= '';
+ $html .= '';
+ $html .= ''.$L->get('utterances-tip').'
';
- // Disable comments on static pages
-
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= '
';
-
- // Disable comments on static pages
-
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= '
';
-
- // Disable comments on sticky posts
-
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= '
';
-
- // Chose the GitHub theme for the comments
-
- $html .= '';
- $html .= '';
- $html .= '';
- $html .= '
';
+ $html .= $toggle('enablePages', $L->get('enable-utterances-on-pages'));
+ $html .= $toggle('enableStatic', $L->get('enable-utterances-on-static-pages'));
+ $html .= $toggle('enableSticky', $L->get('enable-utterances-on-sticky-pages'));
+ $html .= $toggle('followSiteTheme', 'Follow site theme (recommended)');
+ $t = $this->getValue('utterancesTheme');
+ $html .= '';
return $html;
}
public function pageEnd()
{
- global $url;
- global $WHERE_AM_I;
+ global $url, $WHERE_AM_I, $page;
-// Do not shows Utterances on page not found
+ if ($url->notFound()) { return false; }
+ if ($WHERE_AM_I !== 'page') { return false; }
+ if (!isset($page)) { return false; }
- if ($url->notFound()) {
- return false;
- }
+ $show = ($page->published() && $this->isOn('enablePages'))
+ || ($page->isStatic() && $this->isOn('enableStatic'))
+ || ($page->sticky() && $this->isOn('enableSticky'));
- if ($WHERE_AM_I==='page') {
- global $page;
- if ($page->published() && $this->getValue('enablePages')) {
- return $this->javascript();
- }
- if ($page->isStatic() && $this->getValue('enableStatic')) {
- return $this->javascript();
- }
- if ($page->sticky() && $this->getValue('enableSticky')) {
- return $this->javascript();
- }
- }
-
- return false;
+ return $show ? $this->javascript() : false;
}
-
-// Utterances javascript
+ private function resolveTheme()
+ {
+ if ($this->isOn('followSiteTheme')) {
+ $cookie = isset($_COOKIE['blowdit-theme']) ? $_COOKIE['blowdit-theme'] : '';
+ return ($cookie === 'light') ? 'github-light' : 'github-dark';
+ }
+ $t = $this->getValue('utterancesTheme');
+ return ($t !== '') ? $t : 'github-dark';
+ }
private function javascript()
{
- global $page;
- $pageURL = $page->permalink();
- $pageID = $page->uuid();
- $myUtterancesRepo = $this->getValue('myUtterancesRepo');
- $utterancesTheme = $this->getValue('utterancesTheme');
+ $repo = trim($this->getValue('myUtterancesRepo'));
+ if ($repo === '') { return false; }
-$code = <<resolveTheme(), ENT_QUOTES, 'UTF-8');
+ return <<