disqus comments:

* Made it work with articles not having an extended part.
* Made trackbacks visible again (for templates supporting it), css class
to be hidden configurable now.
This commit is contained in:
Grischa Brockhaus 2012-06-08 00:04:12 +02:00
parent 41fe797154
commit ee9fd65d25
3 changed files with 110 additions and 47 deletions

View file

@ -0,0 +1,3 @@
Version 0.2
* Made it work with articles not having an extended part.
* Made trackbacks visible again (for templates supporting it), css class to be hidden configurable now.

View file

@ -1,21 +1,17 @@
<?php
@define('PLUGIN_DISQUS_TITLE', 'Disqus comments');
@define('PLUGIN_DISQUS_DESC', 'Disqus.com is a webservice that allows you to manage comments, with central logins. It stores and manages comments outside of your Serendipity installation, and is embedded using JavaScript. For more information see disqus.com.');
@define('PLUGIN_DISQUS_DESC2', 'When disqus.com comments are enabled, any functionality that relies on serendipity-stored comments will no longer work, of course.
Internally, this plugin uses CSS to hide the Serendipity output for comments, trackbacks and the commentform. For that it sets "display:none" for these CSS classes:
.serendipity_comments
.serendipity_section_comments
.serendipity_section_trackbacks
.serendipity_section_commentform
If your template/theme uses other names, you need to add these classnames to your template, or hide these containers yourself.
@define('PLUGIN_DISQUS_DESC2', '
The plugin puts the disqus output inside the Smarty variable {$entry.plugin_display_dat} AND {$entry.disqus} which you can place inside your entries.tpl template at any position within the {$entry} loop.
If the entry displayed has DISQUS support already, the variable {$entry.has_disqus} is true.
');
@define('PLUGIN_DISQUS_ENABLE_SINCE', 'Enable disqus.com for entries since...');
@define('PLUGIN_DISQUS_ENABLE_SINCE_DESC', 'Enter a date (Y-m-d) for which disqus comments will be enabled, so that you can preserve older comments to be shown properly.');
@define('PLUGIN_DISQUS_SHORTNAME', 'Shortname of your disqus account');
@define('PLUGIN_DISQUS_SHORTNAME_DESC', 'Enter the shortname that you registered your disqus account under.');
@define('PLUGIN_DISQUS_SHORTNAME', 'Shortname of your disqus blog account');
@define('PLUGIN_DISQUS_SHORTNAME_DESC', 'Enter the shortname of this blog you registered under your disqus account.');
@define('PLUGIN_DISQUS_FOOTERCOMMENTLINK', 'Let DISQUS set comment count in footer');
@define('PLUGIN_DISQUS_FOOTERCOMMENTLINK_DESC', 'As the comment count is not known, this plugin will put "Comments" only instead of "N comments" into the footer. You can have DISQUS replace this with the correct count, but some templates might not display that correctly so you can disable the dynamic DISQUS replacement here.');
@define('PLUGIN_DISQUS_HIDE_COMMENTCSS', 'Hide comment css');
@define('PLUGIN_DISQUS_HIDE_COMMENTCSS_DESC', 'When disqus.com comments are enabled, any functionality that relies on serendipity-stored comments will no longer work, of course. Internally, this plugin uses CSS to hide the Serendipity output for comments and the commentform. For that it sets "display:none" for these CSS classes. Please enter the classes used in your template styling your comment area and comment form. The default should work on most templates.');

View file

@ -21,32 +21,27 @@ class serendipity_event_disqus extends serendipity_event {
$propbag->add('name', PLUGIN_DISQUS_TITLE);
$propbag->add('description', PLUGIN_DISQUS_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('author', 'Garvin Hicking, Grischa Brockhaus');
$propbag->add('requirements', array(
'serendipity' => '0.7',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('version', '0.1');
$propbag->add('version', '0.2');
$propbag->add('groups', array('FRONTEND_VIEWS'));
$propbag->add('event_hooks', array(
'frontend_display:html:per_entry' => true,
'entries_footer' => true
'entries_footer' => true,
'entry_display' => true
));
$propbag->add('configuration', array('shortname', 'enable_since'));
$propbag->add('configuration', array('shortname', 'enable_since','template_hide_css','footer_comment_link'));
}
function introspect_config_item($name, &$propbag) {
global $serendipity;
switch($name) {
/*
plugin_display_dat
$TRACKBACKS
$COMMENTS
$COMMENTFORM
*/
case 'enable_since':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DISQUS_ENABLE_SINCE);
@ -60,7 +55,19 @@ class serendipity_event_disqus extends serendipity_event {
$propbag->add('description', PLUGIN_DISQUS_SHORTNAME_DESC);
$propbag->add('default', '');
break;
case 'template_hide_css':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_DISQUS_HIDE_COMMENTCSS);
$propbag->add('description', PLUGIN_DISQUS_HIDE_COMMENTCSS_DESC);
$propbag->add('default', 'serendipity_section_comments,serendipity_section_commentform');
break;
case 'footer_comment_link':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_DISQUS_FOOTERCOMMENTLINK);
$propbag->add('description', PLUGIN_DISQUS_FOOTERCOMMENTLINK_DESC);
$propbag->add('default', 'false');
break;
}
return true;
@ -74,7 +81,7 @@ class serendipity_event_disqus extends serendipity_event {
echo nl2br(PLUGIN_DISQUS_DESC2);
}
function event_hook($event, &$bag, &$eventData, &$addData) {
function event_hook($event, &$bag, &$eventData, &$addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
@ -83,6 +90,10 @@ class serendipity_event_disqus extends serendipity_event {
switch($event) {
case 'entries_footer':
$putFooterLink = $this->get_config('footer_comment_link', false);
// If we don't have a DISQUSfied footer, the JS is of no sense.
if (!$putFooterLink) return true;
?>
<script type="text/javascript">
var disqus_shortname = '<?php echo $this->get_config('shortname'); ?>';
@ -104,16 +115,69 @@ class serendipity_event_disqus extends serendipity_event {
if ($eventData['timestamp'] < $ts) {
return true;
}
$eventData['comments'] = '<a href="' . $eventData['link'] . '#disqus_thread" data-disqus-identifier="disq_id_' . $eventData['id'] . '">Disqus</a>';
if (!$eventData['is_extended']) return true;
$disqus = '
<style type="text/css">
.serendipity_comments,
.serendipity_section_comments,
.serendipity_section_trackbacks,
.serendipity_section_commentform {
$putFooterLink = $this->get_config('footer_comment_link', false);
$eventData['has_disqus'] = true;
// This is problematic, because some templates (like 2k11) expect text only here!
if ($putFooterLink) {
$eventData['comments'] = '<a href="' . $eventData['link'] . '#disqus_thread" data-disqus-identifier="disq_id_' . $eventData['id'] . '">DISQUS</a>';
}
else {
$eventData['comments'] = COMMENTS;
}
return true;
case 'entry_display':
$singleArticle = $addData['extended'];
if (!$singleArticle) return true;
$_ts = explode('-', $this->get_config('enable_since'));
$ts = mktime(0, 0, 0, $_ts[1], $_ts[2], $_ts[0]);
if (isset($eventData) && is_array($eventData)) {
foreach($eventData as $event) {
if ($event['timestamp'] < $ts) {
continue;
}
$i = 0;
$disqus = $this->produce_disqus_output($event);
$event[$i]['display_dat'] .= $disqus;
$eventData[$i]['disqus'] .= $disqus;
$eventData[$i]['has_disqus'] = true;
$eventData[$i]['commentform'] = true;
$eventData[$i]['add_footer'] .= $disqus;
$i++;
}
}
return true;
default:
return false;
}
} else {
return false;
}
}
function produce_disqus_output(&$eventData) {
$hidecss = $this->get_config('template_hide_css','serendipity_section_comments,serendipity_section_commentform');
if (empty($hidecss)) return '';
$csslist = explode(',', $hidecss);
$hide = '';
$count = count($csslist);
$index = 0;
foreach ($csslist as $css) {
$hide .= '.' . $css;
$index ++;
if ($index<$count) $hide .= ',';
}
return '
<style type="text/css">'. $hide .
' {
display: none;
}
</style>
@ -125,7 +189,7 @@ class serendipity_event_disqus extends serendipity_event {
// The following are highly recommended additional parameters. Remove the slashes in front to use.
var disqus_identifier = \'disq_id_' . $eventData['id'] . '\';
var disqus_url = \'' . $eventData['rdf_ident'] . '\';
var disqus_url = \'' . $this->generate_article_url($eventData) . '\';
var disqus_title = \'' . addslashes($eventData['title']) . '\';
(function() {
@ -137,18 +201,18 @@ class serendipity_event_disqus extends serendipity_event {
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
';
}
function generate_article_url( $entry ) {
global $serendipity;
$urlparts = @parse_url($serendipity['baseURL']);
$server = $urlparts['scheme'] . '://' . $urlparts['host'];
if (!empty($urlparts['port'])) $server = $server . ':' . $urlparts['port'];
$relurl = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
$eventData['display_dat'] .= $disqus;
$eventData['disqus'] .= $disqus;
$eventData['commentform'] = true;
return true;
default:
return false;
}
} else {
return false;
}
return $server . $relurl;
}
}