-
Notifications
You must be signed in to change notification settings - Fork 0
/
disqus.php
38 lines (34 loc) · 1.56 KB
/
disqus.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
<?php
// Disqus extension, https://github.com/GiovanniSalmeri/yellow-disqus
class YellowDisqus {
const VERSION = "0.9.1";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
$this->yellow->system->setDefault("disqusShortname", "yellow");
}
// Handle page content element
public function onParseContentElement($page, $name, $text, $attributes, $type) {
$output = null;
if ($name=="disqus" && ($type=="block" || $type=="inline") && !preg_match("/exclude/i", $page->get("comment"))) {
$shortname = $this->yellow->system->get("disqusShortname");
$url = $this->yellow->page->getUrl(true);
$language = $page->get("language");
$output = "<div id=\"disqus_thread\" data-shortname=\"".htmlspecialchars($shortname)."\" data-url=\"".htmlspecialchars($url)."\" data-language=\"$language\"></div>\n";
}
return $output;
}
// Handle page extra data
public function onParsePageExtra($page, $name) {
$output = null;
if ($name=="header") {
$assetLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreAssetLocation");
$output = "<script type=\"text/javascript\" defer=\"defer\" src=\"{$assetLocation}disqus.js\"></script>\n";
}
if ($name=="disqus" || $name=="comment") {
$output = $this->onParseContentElement($page, "disqus", "", "", "block");
}
return $output;
}
}