3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to add Disqus commenting to notice pages
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2010 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
36 * This plugin adds Disqus commenting to your notices. Enabling this
37 * plugin will make each notice page display the Disqus widget, and
38 * notice lists will display the number of commments each notice has.
40 * To use this plugin, you need to first register your site with Disqus
41 * and get a Discus 'shortname' for it.
45 * To enable the plugin, put the following in you config.php:
49 * 'shortname' => 'YOURSHORTNAME',
50 * 'div_style' => 'width:675px; padding-top:10px; position:relative; float:left;'
54 * NOTE: the 'div_style' in an optional parameter that passes in some
55 * inline CSS when creating the Disqus widget. It's a shortcut to make
56 * the widget look OK with the default StatusNet theme. If you leave
57 * it out you'll have to edit your theme CSS files to make the widget
58 * look good. You can also control the way the widget looks by
59 * adding style rules to your theme.
61 * See: http://help.disqus.com/entries/100878-css-customization
65 * @author Zach Copley <zach@status.net>
66 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
67 * @link http://status.net/
72 class DisqusPlugin extends Plugin
74 function onEndShowContentBlock($action)
76 if (get_class($action) == 'ShownoticeAction') {
79 $attrs['id'] = 'disqus_thread';
81 if ($this->div_style) {
82 $attrs['style'] = $this->div_style;
85 $action->element('div', $attrs, null);
87 $script = <<<ENDOFSCRIPT
88 var disqus_identifier = %d;
90 var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
91 dsq.src = 'http://%s.disqus.com/embed.js';
92 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
96 $action->inlineScript(sprintf($script, $action->notice->id, $this->shortname));
100 $attrs['id'] = 'disqus_thread_footer';
102 if ($this->div_style) {
103 $attrs['style'] = $this->div_style;
106 $action->elementStart('div', $attrs);
107 $action->elementStart('noscript');
109 $action->raw('Please enable JavaScript to view the ');
110 $noscriptUrl = 'http://disqus.com/?ref_noscript=' . $this->shortname;
111 $action->element('a', array('href' => $noscriptUrl), 'comments powered by Disqus.');
112 $action->elementEnd('noscript');
114 $action->elementStart('a', array('href' => 'http://disqus.com', 'class' => 'dsq-brlink'));
115 $action->raw('blog comments powered by ');
116 $action->element('span', array('class' => 'logo-disqus'), 'Disqus');
117 $action->elementEnd('a');
118 $action->elementEnd('div');
122 function onEndShowScripts($action)
125 $script = <<<ENDOFSCRIPT
126 var disqus_shortname = '%s';
128 var s = document.createElement('script'); s.async = true;
129 s.src = 'http://disqus.com/forums/%s/count.js';
130 (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
133 $action->inlineScript(sprintf($script, $this->shortname, $this->shortname));
138 function onStartShowNoticeItem($noticeListItem)
140 if (empty($noticeListItem->notice->is_local)) {
144 $noticeListItem->showNotice();
145 $noticeListItem->showNoticeInfo();
147 $noticeUrl = $noticeListItem->notice->bestUrl();
148 $noticeUrl .= '#disqus_thread';
150 $noticeListItem->out->element(
151 'a', array('href' => $noticeUrl, 'class' => 'disqus_count'), 'Comments'
154 $noticeListItem->showNoticeOptions();
155 Event::handle('EndShowNoticeItem', array($noticeListItem));
160 function onPluginVersion(&$versions)
162 $versions[] = array('name' => 'Disqus',
163 'version' => STATUSNET_VERSION,
164 'author' => 'Zach Copley',
165 'homepage' => 'http://status.net/wiki/Plugin:Disqus',
167 _m('Use <a href="http://disqus.com/">Disqus</a>'.
168 ' to add commenting to notice pages.'));