-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZendeskChat.php
61 lines (54 loc) · 2.19 KB
/
ZendeskChat.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
<?php
namespace inquid\zendeskchat;
use InvalidArgumentException;
/**
* This is just an example.
*/
class ZendeskChat extends \yii\base\Widget
{
public $host;
const ZENDESK_URL = ".zendesk.com";
public function init()
{
parent::init();
if ($this->host === null) {
if (isset(\Yii::$app->params['zendesk_host']))
$this->host = \Yii::$app->params['zendesk_host'];
else
throw new InvalidArgumentException('Missing zendesk host');
}
if (!$this->endsWith($this->host, self::ZENDESK_URL)) {
$this->host = $this->host . self::ZENDESK_URL;
}
}
public function run()
{
return "<!-- Start of inquid Zendesk Widget script -->
<script>/*<![CDATA[*/
window.zEmbed || function (e, t) {
var n, o, d, i, s, a = [], r = document.createElement(\"iframe\");
window.zEmbed = function () {
a.push(arguments)
}, window.zE = window.zE || window.zEmbed, r.src = \"javascript:false\", r.title = \"\", r.role = \"presentation\", (r.frameElement || r).style.cssText = \"display: none\", d = document.getElementsByTagName(\"script\"), d = d[d.length - 1], d.parentNode.insertBefore(r, d), i = r.contentWindow, s = i.document;
try {
o = s
} catch (e) {
n = document.domain, r.src = 'javascript:var d=document.open();d.domain=\"' + n + '\";void(0);', o = s
}
o.open()._l = function () {
var e = this.createElement(\"script\");
n && (this.domain = n), e.id = \"js-iframe-async\", e.src = \"https://assets.zendesk.com/embeddable_framework/main.js\", this.t = +new Date, this.zendeskHost = \"" . $this->host . "\", this.zEQueue = a, this.body.appendChild(e)
}, o.write('<body onload=\"document._l();\">'), o.close()
}();
/*]]>*/</script>
<!-- End of inquid Zendesk Widget script -->";
}
private function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
}