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 = ''; + $toggle = function ($key, $label) use ($L) { + $on = $this->isOn($key); + return '
' + . '
'; + }; - // Add your Utterances GitHub repository + $html = ''; - $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 << - + EOF; - return $code; } - } diff --git a/readme.md b/readme.md index 249db9f..d1615ab 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,17 @@ The plugin uses [Utterrrances](https://utteranc.es/) to manage the comments. 4. Go to your Bludit admin panel and activate the GitHub Comments plugin. 5. Go to the pluging settings and enter your repository using the format **OWNER/REPO** . Do not add the url address and double check white spaces. +## Settings + +| Setting | Default | Description | +|---|---|---| +| Repository | *(empty)* | GitHub repo in `OWNER/REPO` format. Comments are disabled until this is set. | +| Enable on pages | Enabled | Show comments on regular posts. | +| Enable on static pages | Enabled | Show comments on static pages. | +| Enable on sticky pages | Enabled | Show comments on sticky posts. | +| Follow site theme | Enabled | Reads the `blowdit-theme` cookie and selects `github-light` or `github-dark` automatically. Disable to pick a fixed theme below. | +| Theme | github-dark | Manual theme override (ignored when Follow site theme is on). | + ## Demo and support I'm using the plugin in my blog. [Check it out and leave a comment.](https://algzb.com/github-comments-plugin-for-bludit)