2015-08-14 03:22:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginDisqus extends Plugin {
|
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
private $enable;
|
2015-08-17 17:07:18 +02:00
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
2015-08-17 04:33:49 +02:00
|
|
|
'shortname'=>'',
|
2016-06-05 03:31:07 +02:00
|
|
|
'enablePages'=>0,
|
|
|
|
'enablePosts'=>0,
|
|
|
|
'enableDefaultHomePage'=>1
|
2015-08-14 03:22:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-17 17:07:18 +02:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
global $Url;
|
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
$this->enable = false;
|
2015-08-17 17:07:18 +02:00
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
if( $this->getDbField('enablePosts') && ($Url->whereAmI()=='post') ) {
|
|
|
|
$this->enable = true;
|
2015-08-17 17:07:18 +02:00
|
|
|
}
|
2016-02-06 21:35:12 +01:00
|
|
|
elseif( $this->getDbField('enablePages') && ($Url->whereAmI()=='page') ) {
|
|
|
|
$this->enable = true;
|
2015-08-17 17:07:18 +02:00
|
|
|
}
|
2016-02-06 21:35:12 +01:00
|
|
|
elseif( $this->getDbField('enableDefaultHomePage') && ($Url->whereAmI()=='home') )
|
2015-08-17 17:07:18 +02:00
|
|
|
{
|
2016-02-06 21:35:12 +01:00
|
|
|
$this->enable = true;
|
2015-08-17 17:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
public function form()
|
|
|
|
{
|
|
|
|
$html = '<div>';
|
2016-11-07 20:58:47 +01:00
|
|
|
$html .= '<label>'.$this->L('Disqus shortname').'</label>';
|
2015-08-14 03:22:26 +02:00
|
|
|
$html .= '<input name="shortname" id="jsshortname" type="text" value="'.$this->getDbField('shortname').'">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '<div>';
|
2016-06-05 03:31:07 +02:00
|
|
|
$html .= '<input type="hidden" name="enablePages" value="0">';
|
|
|
|
$html .= '<input name="enablePages" id="jsenablePages" type="checkbox" value="1" '.($this->getDbField('enablePages')?'checked':'').'>';
|
2016-11-07 20:58:47 +01:00
|
|
|
$html .= '<label class="forCheckbox" for="jsenablePages">'.$this->L('Enable Disqus on pages').'</label>';
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2016-06-05 03:31:07 +02:00
|
|
|
$html .= '<input type="hidden" name="enablePosts" value="0">';
|
|
|
|
$html .= '<input name="enablePosts" id="jsenablePosts" type="checkbox" value="1" '.($this->getDbField('enablePosts')?'checked':'').'>';
|
2016-11-07 20:58:47 +01:00
|
|
|
$html .= '<label class="forCheckbox" for="jsenablePosts">'.$this->L('Enable Disqus on posts').'</label>';
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2016-06-05 03:31:07 +02:00
|
|
|
$html .= '<input type="hidden" name="enableDefaultHomePage" value="0">';
|
|
|
|
$html .= '<input name="enableDefaultHomePage" id="jsenableDefaultHomePage" type="checkbox" value="1" '.($this->getDbField('enableDefaultHomePage')?'checked':'').'>';
|
2016-11-07 20:58:47 +01:00
|
|
|
$html .= '<label class="forCheckbox" for="jsenableDefaultHomePage">'.$this->L('Enable Disqus on default home page').'</label>';
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postEnd()
|
|
|
|
{
|
2016-02-06 21:35:12 +01:00
|
|
|
if( $this->enable ) {
|
|
|
|
return '<div id="disqus_thread"></div>';
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function pageEnd()
|
|
|
|
{
|
2016-02-06 22:05:58 +01:00
|
|
|
global $Url;
|
|
|
|
|
|
|
|
// Bludit check not-found page after the plugin method construct.
|
|
|
|
// It's necesary check here the page not-found.
|
|
|
|
|
|
|
|
if( $this->enable && !$Url->notFound()) {
|
2016-02-06 21:35:12 +01:00
|
|
|
return '<div id="disqus_thread"></div>';
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function siteHead()
|
|
|
|
{
|
2016-02-06 21:35:12 +01:00
|
|
|
if( $this->enable ) {
|
|
|
|
return '<style>#disqus_thread { margin: 20px 0 }</style>';
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function siteBodyEnd()
|
|
|
|
{
|
2016-02-06 21:35:12 +01:00
|
|
|
if( $this->enable ) {
|
2015-08-14 03:22:26 +02:00
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
$html = '
|
2015-08-14 03:22:26 +02:00
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var disqus_shortname = "'.$this->getDbField('shortname').'";
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
|
|
|
|
dsq.src = "//" + disqus_shortname + ".disqus.com/embed.js";
|
|
|
|
(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
|
|
|
|
})();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>';
|
|
|
|
|
2016-02-06 21:35:12 +01:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-08-14 03:22:26 +02:00
|
|
|
}
|
2016-02-06 21:35:12 +01:00
|
|
|
}
|