bludit/bl-plugins/disqus/plugin.php

113 lines
3.5 KiB
PHP
Raw Normal View History

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'=>'',
2019-01-25 16:25:41 +01:00
'enablePages'=>true,
'enableStatic'=>true,
'enableSticky'=>true
2015-08-14 03:22:26 +02:00
);
}
public function form()
{
global $L;
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>';
$html .= '<label>'.$L->get('disqus-shortname').'</label>';
$html .= '<input name="shortname" id="jsshortname" type="text" value="'.$this->getValue('shortname').'">';
2019-01-25 16:25:41 +01:00
$html .= '<span class="tip">'.$L->get('Get the shortname from the Disqus general settings').'</span>';
2015-08-17 04:33:49 +02:00
$html .= '</div>';
2017-10-19 12:29:07 +02:00
$html .= '<div>';
$html .= '<label>'.$L->get('enable-disqus-on-pages').'</label>';
2017-10-19 12:29:07 +02:00
$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>';
2017-10-19 12:29:07 +02:00
$html .= '</select>';
2019-01-25 16:25:41 +01:00
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('enable-disqus-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>';
2017-10-19 12:29:07 +02:00
$html .= '<div>';
2019-01-25 16:25:41 +01:00
$html .= '<label>'.$L->get('enable-disqus-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>';
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()
{
2019-05-28 21:04:15 +02:00
global $url;
2019-01-25 16:25:41 +01:00
global $WHERE_AM_I;
2019-05-28 21:04:15 +02:00
// Do not shows
if ($url->notFound()) {
return false;
}
2019-01-25 16:25:41 +01:00
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();
}
2015-08-17 04:33:49 +02:00
}
2015-08-17 17:07:18 +02:00
return false;
2015-08-14 03:22:26 +02:00
}
2019-01-25 16:25:41 +01:00
private function javascript()
{
global $page;
$pageURL = $page->permalink();
$pageID = $page->uuid();
$shortname = $this->getValue('shortname');
$code = <<<EOF
<!-- Disqus plugin -->
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = '$pageURL';
this.page.identifier = '$pageID';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://$shortname.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<!-- /Disqus plugin -->
EOF;
return $code;
}
2017-10-19 12:29:07 +02:00
}