-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.php
65 lines (57 loc) · 1.59 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class KokenDisqus extends KokenPlugin {
function __construct()
{
$this->require_setup = true;
$this->register_hook('before_closing_body', 'render_js');
$this->register_hook('discussion', 'render_div');
$this->register_hook('discussion_count', 'render_count_div');
}
function render_div($item)
{
echo '<script>var disqus_identifier = "koken_disqus_' . $item['__koken__'] . '_' . $item['id'] . '";</script><div id="disqus_thread"></div>';
}
function render_count_div($item)
{
echo '<a href="' . $item['url'] . '#disqus_thread" data-disqus-identifier="koken_disqus_' . $item['__koken__'] . '_' . $item['id'] . '"></a>';
}
function render_js()
{
echo <<<OUT
<script type="text/javascript">
var disqus_shortname = '{$this->data->shortname}';
(function() {
var disqus = function() {
if ($('#disqus_thread').length) {
$.getScript(location.protocol + '//' + disqus_shortname + '.disqus.com/embed.js');
}
if ($('[data-disqus-identifier]').length) {
window.DISQUSWIDGETS = undefined;
$.getScript(location.protocol + '//' + disqus_shortname + '.disqus.com/count.js');
}
}
$(function() {
if ($.pjax) {
$(document).on('pjax:success pjax:end', function() {
window.setTimeout(function() {
if (window.DISQUS && $('#disqus_thread').length) {
window.DISQUS.reset({
reload: true,
config: function() {
this.page.url = window.location.href;
this.page.identifier = disqus_identifier;
}
});
} else {
disqus();
}
}, 250)
});
}
disqus();
});
}());
</script>
OUT;
}
}