2015-08-14 03:22:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginDisqus extends Plugin {
|
|
|
|
|
2015-08-17 17:07:18 +02:00
|
|
|
private $disable;
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
2015-08-17 04:33:49 +02:00
|
|
|
'shortname'=>'',
|
|
|
|
'enablePages'=>false,
|
|
|
|
'enablePosts'=>true,
|
|
|
|
'enableDefaultHomePage'=>false
|
2015-08-14 03:22:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-17 17:07:18 +02:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
// Disable the plugin IF ...
|
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$this->disable = false;
|
|
|
|
|
|
|
|
if( (!$this->getDbField('enablePosts')) && ($Url->whereAmI()=='post') ) {
|
|
|
|
$this->disable = true;
|
|
|
|
}
|
|
|
|
elseif( (!$this->getDbField('enablePages')) && ($Url->whereAmI()=='page') ) {
|
|
|
|
$this->disable = true;
|
|
|
|
}
|
|
|
|
elseif( !$this->getDbField('enableDefaultHomePage') && ($Url->whereAmI()=='page') )
|
|
|
|
{
|
|
|
|
global $Page;
|
|
|
|
global $Site;
|
|
|
|
if( $Site->homePage()==$Page->key() ) {
|
|
|
|
$this->disable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif( ($Url->whereAmI()!='post') && ($Url->whereAmI()!='page') ) {
|
|
|
|
$this->disable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
public function form()
|
|
|
|
{
|
|
|
|
global $Language;
|
|
|
|
|
|
|
|
$html = '<div>';
|
2015-08-17 04:33:49 +02:00
|
|
|
$html .= '<label>'.$Language->get('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>';
|
|
|
|
$html .= '<input name="enablePages" id="jsenablePages" type="checkbox" value="true" '.($this->getDbField('enablePages')?'checked':'').'>';
|
|
|
|
$html .= '<label class="forCheckbox" for="jsenablePages">'.$Language->get('Enable Disqus on pages').'</label>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
|
|
|
$html .= '<input name="enablePosts" id="jsenablePosts" type="checkbox" value="true" '.($this->getDbField('enablePosts')?'checked':'').'>';
|
|
|
|
$html .= '<label class="forCheckbox" for="jsenablePosts">'.$Language->get('Enable Disqus on posts').'</label>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
|
|
|
$html .= '<input name="enableDefaultHomePage" id="jsenableDefaultHomePage" type="checkbox" value="true" '.($this->getDbField('enableDefaultHomePage')?'checked':'').'>';
|
|
|
|
$html .= '<label class="forCheckbox" for="jsenableDefaultHomePage">'.$Language->get('Enable Disqus on default home page').'</label>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postEnd()
|
|
|
|
{
|
2015-08-17 17:07:18 +02:00
|
|
|
if( $this->disable ) {
|
|
|
|
return false;
|
2015-08-17 04:33:49 +02:00
|
|
|
}
|
2015-08-17 17:07:18 +02:00
|
|
|
|
|
|
|
$html = '<div id="disqus_thread"></div>';
|
2015-08-14 03:22:26 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pageEnd()
|
|
|
|
{
|
2015-08-17 17:07:18 +02:00
|
|
|
if( $this->disable ) {
|
|
|
|
return false;
|
2015-08-17 04:33:49 +02:00
|
|
|
}
|
2015-08-17 17:07:18 +02:00
|
|
|
|
|
|
|
$html = '<div id="disqus_thread"></div>';
|
2015-08-17 04:33:49 +02:00
|
|
|
return $html;
|
2015-08-14 03:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function siteHead()
|
|
|
|
{
|
2015-08-17 17:07:18 +02:00
|
|
|
if( $this->disable ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-14 03:22:26 +02:00
|
|
|
$html = '<style>#disqus_thread { margin: 20px 0 }</style>';
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function siteBodyEnd()
|
|
|
|
{
|
2015-08-17 17:07:18 +02:00
|
|
|
if( $this->disable ) {
|
|
|
|
return false;
|
2015-08-14 03:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$html = '
|
|
|
|
<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>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|