Update metadata and enhance README with plugin settings details
This commit is contained in:
1 parent
39e8b0b78a
commit
b335ea4709
3 files changed
+77
-96
No files matched your search
+7
-7
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"author": "ALGZB",
|
"author": "spleenftw",
|
||||||
"email": "hello@algzb.com",
|
"email": "",
|
||||||
"website": "https://algzb.com/github-comments-plugin-for-bludit",
|
"website": "https://github.com/Spleenftw/github-comments-for-bludit",
|
||||||
"version": "1.0",
|
"version": "1.2.0",
|
||||||
"releaseDate": "2020-09-10",
|
"releaseDate": "2026-06-02",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"compatible": "3.13.1",
|
"compatible": "3.22.0",
|
||||||
"notes": ""
|
"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."
|
||||||
}
|
}
|
||||||
+59
-89
@@ -5,128 +5,98 @@ class utterances extends Plugin {
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'myUtterancesRepo'=>'',
|
'myUtterancesRepo' => '',
|
||||||
'enablePages'=>true,
|
'enablePages' => true,
|
||||||
'enableStatic'=>true,
|
'enableStatic' => true,
|
||||||
'enableSticky'=>true,
|
'enableSticky' => true,
|
||||||
'utterancesTheme'=>''
|
'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()
|
public function form()
|
||||||
{
|
{
|
||||||
global $L;
|
global $L;
|
||||||
|
|
||||||
$html = '<div class="alert alert-primary" role="alert">';
|
$toggle = function ($key, $label) use ($L) {
|
||||||
$html .= $L->get('utterances-installation');
|
$on = $this->isOn($key);
|
||||||
$html .= '</div>';
|
return '<div><label>'.$label.'</label>'
|
||||||
|
. '<select name="'.$key.'">'
|
||||||
|
. '<option value="true" '.($on ? 'selected' : '').'>'.$L->get('enabled').'</option>'
|
||||||
|
. '<option value="false" '.(!$on ? 'selected' : '').'>'.$L->get('disabled').'</option>'
|
||||||
|
. '</select></div>';
|
||||||
|
};
|
||||||
|
|
||||||
// Add your Utterances GitHub repository
|
$html = '<div class="alert alert-primary" role="alert">'.$L->get('utterances-installation').'</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
$html .= '<div><label>'.$L->get('utterances-repository').'</label>';
|
||||||
$html .= '<label>'.$L->get('utterances-repository').'</label>';
|
$html .= '<input name="myUtterancesRepo" id="jsmyUtterancesRepo" type="text" value="'.htmlspecialchars($this->getValue('myUtterancesRepo'), ENT_QUOTES, 'UTF-8').'">';
|
||||||
$html .= '<input name="myUtterancesRepo" id="jsmyUtterancesRepo" type="text" value="'.$this->getValue('myUtterancesRepo').'">';
|
$html .= '<span class="tip">'.$L->get('utterances-tip').'</span></div>';
|
||||||
$html .= '<span class="tip">'.$L->get('utterances-tip').'</span>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
// Disable comments on static pages
|
$html .= $toggle('enablePages', $L->get('enable-utterances-on-pages'));
|
||||||
|
$html .= $toggle('enableStatic', $L->get('enable-utterances-on-static-pages'));
|
||||||
$html .= '<div>';
|
$html .= $toggle('enableSticky', $L->get('enable-utterances-on-sticky-pages'));
|
||||||
$html .= '<label>'.$L->get('enable-utterances-on-pages').'</label>';
|
$html .= $toggle('followSiteTheme', 'Follow site theme (recommended)');
|
||||||
$html .= '<select name="enablePages">';
|
|
||||||
$html .= '<option value="true" '.($this->getValue('enablePages')===true?'selected':'').'>'.$L->get('enabled').'</option>';
|
|
||||||
$html .= '<option value="false" '.($this->getValue('enablePages')===false?'selected':'').'>'.$L->get('disabled').'</option>';
|
|
||||||
$html .= '</select>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
// Disable comments on static pages
|
|
||||||
|
|
||||||
$html .= '<div>';
|
|
||||||
$html .= '<label>'.$L->get('enable-utterances-on-static-pages').'</label>';
|
|
||||||
$html .= '<select name="enableStatic">';
|
|
||||||
$html .= '<option value="true" '.($this->getValue('enableStatic')===true?'selected':'').'>'.$L->get('enabled').'</option>';
|
|
||||||
$html .= '<option value="false" '.($this->getValue('enableStatic')===false?'selected':'').'>'.$L->get('disabled').'</option>';
|
|
||||||
$html .= '</select>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
// Disable comments on sticky posts
|
|
||||||
|
|
||||||
$html .= '<div>';
|
|
||||||
$html .= '<label>'.$L->get('enable-utterances-on-sticky-pages').'</label>';
|
|
||||||
$html .= '<select name="enableSticky">';
|
|
||||||
$html .= '<option value="true" '.($this->getValue('enableSticky')===true?'selected':'').'>'.$L->get('enabled').'</option>';
|
|
||||||
$html .= '<option value="false" '.($this->getValue('enableSticky')===false?'selected':'').'>'.$L->get('disabled').'</option>';
|
|
||||||
$html .= '</select>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
// Chose the GitHub theme for the comments
|
|
||||||
|
|
||||||
$html .= '<div>';
|
|
||||||
$html .= '<label>'.$L->get('utterances-select-theme').'</label>';
|
|
||||||
$html .= '<select name="utterancesTheme">';
|
|
||||||
$html .= '<option value="github-light" '.($this->getValue('utterancesTheme')==='github-light'?'selected':'').'>'.$L->get('GitHub Light').'</option>';
|
|
||||||
$html .= '<option value="github-dark" '.($this->getValue('utterancesTheme')==='github-dark'?'selected':'').'>'.$L->get('GitHub Dark').'</option>';
|
|
||||||
$html .= '<option value="github-dark-orange" '.($this->getValue('utterancesTheme')==='github-dark-orange'?'selected':'').'>'.$L->get('GitHub Dark Orange').'</option>';
|
|
||||||
$html .= '<option value="icy-dark" '.($this->getValue('utterancesTheme')==='icy-dark'?'selected':'').'>'.$L->get('Icy Dark').'</option>';
|
|
||||||
$html .= '<option value="dark-blue" '.($this->getValue('utterancesTheme')==='dark-blue'?'selected':'').'>'.$L->get('Dark Blue').'</option>';
|
|
||||||
$html .= '<option value="photon-dark" '.($this->getValue('utterancesTheme')==='photon-dark'?'selected':'').'>'.$L->get('Photon Dark').'</option>';
|
|
||||||
$html .= '</select>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
|
$t = $this->getValue('utterancesTheme');
|
||||||
|
$html .= '<div><label>'.$L->get('utterances-select-theme').'</label><select name="utterancesTheme">';
|
||||||
|
foreach (array('github-light','github-dark','github-dark-orange','icy-dark','dark-blue','photon-dark') as $opt) {
|
||||||
|
$html .= '<option value="'.$opt.'" '.($t === $opt ? 'selected' : '').'>'.$opt.'</option>';
|
||||||
|
}
|
||||||
|
$html .= '</select></div>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pageEnd()
|
public function pageEnd()
|
||||||
{
|
{
|
||||||
global $url;
|
global $url, $WHERE_AM_I, $page;
|
||||||
global $WHERE_AM_I;
|
|
||||||
|
|
||||||
// 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()) {
|
$show = ($page->published() && $this->isOn('enablePages'))
|
||||||
return false;
|
|| ($page->isStatic() && $this->isOn('enableStatic'))
|
||||||
|
|| ($page->sticky() && $this->isOn('enableSticky'));
|
||||||
|
|
||||||
|
return $show ? $this->javascript() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($WHERE_AM_I==='page') {
|
private function resolveTheme()
|
||||||
global $page;
|
{
|
||||||
if ($page->published() && $this->getValue('enablePages')) {
|
if ($this->isOn('followSiteTheme')) {
|
||||||
return $this->javascript();
|
$cookie = isset($_COOKIE['blowdit-theme']) ? $_COOKIE['blowdit-theme'] : '';
|
||||||
|
return ($cookie === 'light') ? 'github-light' : 'github-dark';
|
||||||
}
|
}
|
||||||
if ($page->isStatic() && $this->getValue('enableStatic')) {
|
$t = $this->getValue('utterancesTheme');
|
||||||
return $this->javascript();
|
return ($t !== '') ? $t : 'github-dark';
|
||||||
}
|
}
|
||||||
if ($page->sticky() && $this->getValue('enableSticky')) {
|
|
||||||
return $this->javascript();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Utterances javascript
|
|
||||||
|
|
||||||
private function javascript()
|
private function javascript()
|
||||||
{
|
{
|
||||||
global $page;
|
$repo = trim($this->getValue('myUtterancesRepo'));
|
||||||
$pageURL = $page->permalink();
|
if ($repo === '') { return false; }
|
||||||
$pageID = $page->uuid();
|
|
||||||
$myUtterancesRepo = $this->getValue('myUtterancesRepo');
|
|
||||||
$utterancesTheme = $this->getValue('utterancesTheme');
|
|
||||||
|
|
||||||
$code = <<<EOF
|
$repo = htmlspecialchars($repo, ENT_QUOTES, 'UTF-8');
|
||||||
|
$theme = htmlspecialchars($this->resolveTheme(), ENT_QUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
return <<<EOF
|
||||||
|
<section class="utterances-comments">
|
||||||
<script src="https://utteranc.es/client.js"
|
<script src="https://utteranc.es/client.js"
|
||||||
repo='$myUtterancesRepo'
|
repo="$repo"
|
||||||
issue-term="pathname"
|
issue-term="pathname"
|
||||||
theme='$utterancesTheme'
|
theme="$theme"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
async>
|
async>
|
||||||
</script>
|
</script>
|
||||||
|
</section>
|
||||||
EOF;
|
EOF;
|
||||||
return $code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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.
|
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.
|
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
|
## 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)
|
I'm using the plugin in my blog. [Check it out and leave a comment.](https://algzb.com/github-comments-plugin-for-bludit)
|
||||||
Reference in new issue
Block a user