-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
132 lines (104 loc) · 4.31 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
class utterances extends Plugin {
public function init()
{
$this->dbFields = array(
'myUtterancesRepo'=>'',
'enablePages'=>true,
'enableStatic'=>true,
'enableSticky'=>true,
'utterancesTheme'=>''
);
}
public function form()
{
global $L;
$html = '<div class="alert alert-primary" role="alert">';
$html .= $L->get('utterances-installation');
$html .= '</div>';
// Add your Utterances GitHub repository
$html .= '<div>';
$html .= '<label>'.$L->get('utterances-repository').'</label>';
$html .= '<input name="myUtterancesRepo" id="jsmyUtterancesRepo" type="text" value="'.$this->getValue('myUtterancesRepo').'">';
$html .= '<span class="tip">'.$L->get('utterances-tip').'</span>';
$html .= '</div>';
// Disable comments on static pages
$html .= '<div>';
$html .= '<label>'.$L->get('enable-utterances-on-pages').'</label>';
$html .= '<select name="enablePages">';
$html .= '<option value="true" '.($this->getValue('enablePages')===true?'selected':'').'>'.$L->get('enabled').'</option>';
$html .= '<option value="false" '.($this->getValue('enablePages')===false?'selected':'').'>'.$L->get('disabled').'</option>';
$html .= '</select>';
$html .= '</div>';
// Disable comments on static pages
$html .= '<div>';
$html .= '<label>'.$L->get('enable-utterances-on-static-pages').'</label>';
$html .= '<select name="enableStatic">';
$html .= '<option value="true" '.($this->getValue('enableStatic')===true?'selected':'').'>'.$L->get('enabled').'</option>';
$html .= '<option value="false" '.($this->getValue('enableStatic')===false?'selected':'').'>'.$L->get('disabled').'</option>';
$html .= '</select>';
$html .= '</div>';
// Disable comments on sticky posts
$html .= '<div>';
$html .= '<label>'.$L->get('enable-utterances-on-sticky-pages').'</label>';
$html .= '<select name="enableSticky">';
$html .= '<option value="true" '.($this->getValue('enableSticky')===true?'selected':'').'>'.$L->get('enabled').'</option>';
$html .= '<option value="false" '.($this->getValue('enableSticky')===false?'selected':'').'>'.$L->get('disabled').'</option>';
$html .= '</select>';
$html .= '</div>';
// Chose the GitHub theme for the comments
$html .= '<div>';
$html .= '<label>'.$L->get('utterances-select-theme').'</label>';
$html .= '<select name="utterancesTheme">';
$html .= '<option value="github-light" '.($this->getValue('utterancesTheme')==='github-light'?'selected':'').'>'.$L->get('GitHub Light').'</option>';
$html .= '<option value="github-dark" '.($this->getValue('utterancesTheme')==='github-dark'?'selected':'').'>'.$L->get('GitHub Dark').'</option>';
$html .= '<option value="github-dark-orange" '.($this->getValue('utterancesTheme')==='github-dark-orange'?'selected':'').'>'.$L->get('GitHub Dark Orange').'</option>';
$html .= '<option value="icy-dark" '.($this->getValue('utterancesTheme')==='icy-dark'?'selected':'').'>'.$L->get('Icy Dark').'</option>';
$html .= '<option value="dark-blue" '.($this->getValue('utterancesTheme')==='dark-blue'?'selected':'').'>'.$L->get('Dark Blue').'</option>';
$html .= '<option value="photon-dark" '.($this->getValue('utterancesTheme')==='photon-dark'?'selected':'').'>'.$L->get('Photon Dark').'</option>';
$html .= '</select>';
$html .= '</div>';
return $html;
}
public function pageEnd()
{
global $url;
global $WHERE_AM_I;
// Do not shows Utterances on page not found
if ($url->notFound()) {
return false;
}
if ($WHERE_AM_I==='page') {
global $page;
if ($page->published() && $this->getValue('enablePages')) {
return $this->javascript();
}
if ($page->isStatic() && $this->getValue('enableStatic')) {
return $this->javascript();
}
if ($page->sticky() && $this->getValue('enableSticky')) {
return $this->javascript();
}
}
return false;
}
// Utterances javascript
private function javascript()
{
global $page;
$pageURL = $page->permalink();
$pageID = $page->uuid();
$myUtterancesRepo = $this->getValue('myUtterancesRepo');
$utterancesTheme = $this->getValue('utterancesTheme');
$code = <<<EOF
<script src="https://utteranc.es/client.js"
repo='$myUtterancesRepo'
issue-term="pathname"
theme='$utterancesTheme'
crossorigin="anonymous"
async>
</script>
EOF;
return $code;
}
}