dbFields = array( '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; $toggle = function ($key, $label) use ($L) { $on = $this->isOn($key); return '
' . '
'; }; $html = ''; $html .= '
'; $html .= ''; $html .= ''.$L->get('utterances-tip').'
'; $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, $WHERE_AM_I, $page; if ($url->notFound()) { return false; } if ($WHERE_AM_I !== 'page') { return false; } if (!isset($page)) { return false; } $show = ($page->published() && $this->isOn('enablePages')) || ($page->isStatic() && $this->isOn('enableStatic')) || ($page->sticky() && $this->isOn('enableSticky')); return $show ? $this->javascript() : false; } 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() { $repo = trim($this->getValue('myUtterancesRepo')); if ($repo === '') { return false; } $repo = htmlspecialchars($repo, ENT_QUOTES, 'UTF-8'); $theme = htmlspecialchars($this->resolveTheme(), ENT_QUOTES, 'UTF-8'); return << EOF; } }