2015-08-14 03:22:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginDisqus extends Plugin {
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
2017-10-19 12:29:07 +02:00
|
|
|
'shortname'=>'',
|
|
|
|
'enablePages'=>false,
|
|
|
|
'enablePosts'=>true
|
2015-08-14 03:22:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function form()
|
|
|
|
{
|
2018-08-03 19:03:09 +02:00
|
|
|
global $language;
|
2015-08-14 03:22:26 +02:00
|
|
|
|
2018-07-02 00:24:53 +02:00
|
|
|
$html = '<div class="alert alert-primary" role="alert">';
|
|
|
|
$html .= $this->description();
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('disqus-shortname').'</label>';
|
2017-05-30 19:18:18 +02:00
|
|
|
$html .= '<input name="shortname" id="jsshortname" type="text" value="'.$this->getValue('shortname').'">';
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2017-10-19 12:29:07 +02:00
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('enable-disqus-on-pages').'</label>';
|
2017-10-19 12:29:07 +02:00
|
|
|
$html .= '<select name="enablePages">';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<option value="true" '.($this->getValue('enablePages')===true?'selected':'').'>'.$language->get('enabled').'</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('enablePages')===false?'selected':'').'>'.$language->get('disabled').'</option>';
|
2017-10-19 12:29:07 +02:00
|
|
|
$html .= '</select>';
|
|
|
|
$html .= '</div>';
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('enable-disqus-on-posts').'</label>';
|
2017-10-19 12:29:07 +02:00
|
|
|
$html .= '<select name="enablePosts">';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<option value="true" '.($this->getValue('enablePosts')===true?'selected':'').'>'.$language->get('enabled').'</option>';
|
|
|
|
$html .= '<option value="false" '.($this->getValue('enablePosts')===false?'selected':'').'>'.$language->get('disabled').'</option>';
|
2017-10-19 12:29:07 +02:00
|
|
|
$html .= '</select>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pageEnd()
|
|
|
|
{
|
2018-07-17 19:13:01 +02:00
|
|
|
global $content;
|
|
|
|
global $url, $page;
|
2017-05-30 19:18:18 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
$page = $content[0];
|
2017-07-29 00:08:19 +02:00
|
|
|
if (empty($page)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
if ( !$url->notFound() &&
|
|
|
|
( $url->whereAmI()=='page' &&
|
2018-08-02 22:33:53 +02:00
|
|
|
(($this->getValue('enablePosts') && $page->published()) ||
|
|
|
|
($this->getValue('enablePages') && $page->static()))
|
2018-07-02 00:24:53 +02:00
|
|
|
) &&
|
2017-10-19 12:29:07 +02:00
|
|
|
$page->allowComments() ) {
|
2017-05-30 19:18:18 +02:00
|
|
|
$html = '<div id="disqus_thread"></div>';
|
|
|
|
$html .= '<script type="text/javascript">
|
|
|
|
var disqus_config = function () {
|
2017-05-30 20:28:55 +02:00
|
|
|
this.page.url = "'.$page->permalink().'";
|
|
|
|
this.page.identifier = "'.$page->uuid().'";
|
2017-05-30 19:18:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var d = document, s = d.createElement("script");
|
|
|
|
s.src = "https://'.$this->getValue('shortname').'.disqus.com/embed.js";
|
|
|
|
s.setAttribute("data-timestamp", +new Date());
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
})();
|
|
|
|
</script>
|
2017-05-30 20:28:55 +02:00
|
|
|
';
|
|
|
|
return $html;
|
2015-08-17 04:33:49 +02:00
|
|
|
}
|
2015-08-17 17:07:18 +02:00
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
return false;
|
2015-08-14 03:22:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 12:29:07 +02:00
|
|
|
}
|