ts3phpframework
Loading...
Searching...
No Matches
Html.php
Go to the documentation of this file.
1<?php
2
4
17
24class Html implements ViewerInterface
25{
31 protected string $pattern = "<table id='%0' class='%1' summary='%2'><tr class='%3'><td class='%4'>%5</td><td class='%6' title='%7'>%8 %9</td><td class='%10'>%11%12</td></tr></table>\n";
32
38 protected ?Node $currObj = null;
39
46 protected ?array $currSib = null;
47
53 protected int $currNum = 0;
54
60 protected string $iconpath;
61
67 protected ?string $flagpath;
68
74 protected ?string $ftclient;
75
81 protected array $cachedIcons = [100, 200, 300, 400, 500, 600];
82
88 protected array $remoteIcons = [];
89
99 public function __construct(string $iconpath = "images/viewer/", string $flagpath = null, string $ftclient = null, string $pattern = null)
100 {
101 $this->iconpath = $iconpath;
102 $this->flagpath = $flagpath;
103 $this->ftclient = $ftclient;
104
105 if ($pattern) {
106 $this->pattern = $pattern;
107 }
108 }
109
120 public function fetchObject(Node $node, array $siblings = []): string
121 {
122 $this->currObj = $node;
123 $this->currSib = $siblings;
124
125 $args = [
126 $this->getContainerIdent(),
127 $this->getContainerClass(),
128 $this->getContainerSummary(),
129 $this->getRowClass(),
130 $this->getPrefixClass(),
131 $this->getPrefix(),
132 $this->getCorpusClass(),
133 $this->getCorpusTitle(),
134 $this->getCorpusIcon(),
135 $this->getCorpusName(),
136 $this->getSuffixClass(),
137 $this->getSuffixIcon(),
138 $this->getSuffixFlag(),
139 ];
140
141 return StringHelper::factory($this->pattern)->arg($args);
142 }
143
150 protected function getContainerIdent(): string
151 {
152 return $this->currObj->getUniqueId();
153 }
154
161 protected function getContainerClass(): string
162 {
163 return "ts3_viewer " . $this->currObj->getClass(null);
164 }
165
172 protected function getContainerSummary(): int
173 {
174 return $this->currObj->getId();
175 }
176
183 protected function getRowClass(): string
184 {
185 return ++$this->currNum % 2 ? "row1" : "row2";
186 }
187
194 protected function getPrefixClass(): string
195 {
196 return "prefix " . $this->currObj->getClass(null);
197 }
198
204 protected function getPrefix(): string
205 {
206 $prefix = "";
207
208 if (count($this->currSib)) {
209 $last = array_pop($this->currSib);
210
211 foreach ($this->currSib as $sibling) {
212 $prefix .= ($sibling) ? $this->getImage("tree_line.gif") : $this->getImage("tree_blank.png");
213 }
214
215 $prefix .= ($last) ? $this->getImage("tree_end.gif") : $this->getImage("tree_mid.gif");
216 }
217
218 return $prefix;
219 }
220
228 protected function getCorpusClass(): string
229 {
230 $extras = "";
231
232 if ($this->currObj instanceof Channel && $this->currObj->isSpacer()) {
233 switch ($this->currObj->spacerGetType()) {
234 case (string)TeamSpeak3::SPACER_SOLIDLINE:
235 $extras .= " solidline";
236 break;
237
238 case (string)TeamSpeak3::SPACER_DASHLINE:
239 $extras .= " dashline";
240 break;
241
243 $extras .= " dashdotline";
244 break;
245
247 $extras .= " dashdotdotline";
248 break;
249
250 case (string)TeamSpeak3::SPACER_DOTLINE:
251 $extras .= " dotline";
252 break;
253 }
254
255 switch ($this->currObj->spacerGetAlign()) {
257 $extras .= " center";
258 break;
259
261 $extras .= " right";
262 break;
263
265 $extras .= " left";
266 break;
267 }
268 } elseif ($this->currObj instanceof Client && $this->currObj->client_is_recording) {
269 $extras .= " recording";
270 }
271
272 return "corpus " . $this->currObj->getClass(null) . $extras;
273 }
274
281 protected function getCorpusTitle(): ?string
282 {
283 if ($this->currObj instanceof Server) {
284 return "ID: " . $this->currObj->getId() . " | Clients: " . $this->currObj->clientCount() . "/" . $this->currObj["virtualserver_maxclients"] . " | Uptime: " . Convert::seconds($this->currObj["virtualserver_uptime"]);
285 } elseif ($this->currObj instanceof Channel && !$this->currObj->isSpacer()) {
286 return "ID: " . $this->currObj->getId() . " | Codec: " . Convert::codec($this->currObj["channel_codec"]) . " | Quality: " . $this->currObj["channel_codec_quality"];
287 } elseif ($this->currObj instanceof Client) {
288 return "ID: " . $this->currObj->getId() . " | Version: " . Convert::versionShort($this->currObj["client_version"]) . " | Platform: " . $this->currObj["client_platform"];
289 } elseif ($this->currObj instanceof ServerGroup || $this->currObj instanceof ChannelGroup) {
290 return "ID: " . $this->currObj->getId() . " | Type: " . Convert::groupType($this->currObj["type"]) . " (" . ($this->currObj["savedb"] ? "Permanent" : "Temporary") . ")";
291 }
292 return null;
293 }
294
301 protected function getCorpusIcon(): string
302 {
303 if ($this->currObj instanceof Channel && $this->currObj->isSpacer()) {
304 return "";
305 }
306
307 return $this->getImage($this->currObj->getIcon() . ".png");
308 }
309
316 protected function getCorpusName(): string
317 {
318 if ($this->currObj instanceof Channel && $this->currObj->isSpacer()) {
319 if ($this->currObj->spacerGetType() != TeamSpeak3::SPACER_CUSTOM) {
320 return "";
321 }
322
323 $string = $this->currObj["channel_name"]->section("]", 1, 99);
324
325 if ($this->currObj->spacerGetAlign() == TeamSpeak3::SPACER_ALIGN_REPEAT) {
326 $string->resize(30, $string);
327 }
328
329 return htmlspecialchars($string);
330 }
331
332 if ($this->currObj instanceof Client) {
333 $before = [];
334 $behind = [];
335
336 if (!$this->currObj->client_is_recording) {
337 foreach ($this->currObj->memberOf() as $group) {
338 if ($group->getProperty("namemode") == TeamSpeak3::GROUP_NAMEMODE_BEFORE) {
339 $before[] = "[" . htmlspecialchars($group["name"]) . "]";
340 } elseif ($group->getProperty("namemode") == TeamSpeak3::GROUP_NAMEMODE_BEHIND) {
341 $behind[] = "[" . htmlspecialchars($group["name"]) . "]";
342 }
343 }
344 } else {
345 $before[] = "***";
346 $behind[] = "*** [RECORDING]";
347 }
348
349 return implode("", $before) . " " . htmlspecialchars($this->currObj) . " " . implode("", $behind);
350 }
351
352 return htmlspecialchars($this->currObj);
353 }
354
361 protected function getSuffixClass(): string
362 {
363 return "suffix " . $this->currObj->getClass(null);
364 }
365
375 protected function getSuffixIcon(): string
376 {
377 if ($this->currObj instanceof Server) {
378 return $this->getSuffixIconServer();
379 } elseif ($this->currObj instanceof Channel) {
380 return $this->getSuffixIconChannel();
381 } elseif ($this->currObj instanceof Client) {
382 return $this->getSuffixIconClient();
383 }
384 return "";
385 }
386
396 protected function getSuffixIconServer(): string
397 {
398 $html = "";
399
400 if ($this->currObj["virtualserver_icon_id"]) {
401 if (!$this->currObj->iconIsLocal("virtualserver_icon_id") && $this->ftclient) {
402 if (!isset($this->cacheIcon[$this->currObj["virtualserver_icon_id"]])) {
403 $download = $this->currObj->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("virtualserver_icon_id"));
404
405 if ($this->ftclient == "data:image") {
406 $download = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
407 }
408
409 $this->cacheIcon[$this->currObj["virtualserver_icon_id"]] = $download;
410 } else {
411 $download = $this->cacheIcon[$this->currObj["virtualserver_icon_id"]];
412 }
413
414 if ($this->ftclient == "data:image") {
415 $html .= $this->getImage("data:" . Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Server Icon", null, false);
416 } else {
417 $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Server Icon", null, false);
418 }
419 } elseif (in_array($this->currObj["virtualserver_icon_id"], $this->cachedIcons)) {
420 $html .= $this->getImage("group_icon_" . $this->currObj["virtualserver_icon_id"] . ".png", "Server Icon");
421 }
422 }
423
424 return $html;
425 }
426
436 protected function getSuffixIconChannel(): string
437 {
438 if ($this->currObj instanceof Channel && $this->currObj->isSpacer()) {
439 return "";
440 }
441
442 $html = "";
443
444 if ($this->currObj["channel_flag_default"]) {
445 $html .= $this->getImage("channel_flag_default.png", "Default Channel");
446 }
447
448 if ($this->currObj["channel_flag_password"]) {
449 $html .= $this->getImage("channel_flag_password.png", "Password-protected");
450 }
451
452 if ($this->currObj["channel_codec"] == TeamSpeak3::CODEC_CELT_MONO || $this->currObj["channel_codec"] == TeamSpeak3::CODEC_OPUS_MUSIC) {
453 $html .= $this->getImage("channel_flag_music.png", "Music Codec");
454 }
455
456 if ($this->currObj["channel_needed_talk_power"]) {
457 $html .= $this->getImage("channel_flag_moderated.png", "Moderated");
458 }
459
460 if ($this->currObj["channel_icon_id"]) {
461 if (!$this->currObj->iconIsLocal("channel_icon_id") && $this->ftclient) {
462 if (!isset($this->cacheIcon[$this->currObj["channel_icon_id"]])) {
463 $download = $this->currObj->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("channel_icon_id"));
464
465 if ($this->ftclient == "data:image") {
466 $download = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
467 }
468
469 $this->cacheIcon[$this->currObj["channel_icon_id"]] = $download;
470 } else {
471 $download = $this->cacheIcon[$this->currObj["channel_icon_id"]];
472 }
473
474 if ($this->ftclient == "data:image") {
475 $html .= $this->getImage("data:" . Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Channel Icon", null, false);
476 } else {
477 $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Channel Icon", null, false);
478 }
479 } elseif (in_array($this->currObj["channel_icon_id"], $this->cachedIcons)) {
480 $html .= $this->getImage("group_icon_" . $this->currObj["channel_icon_id"] . ".png", "Channel Icon");
481 }
482 }
483
484 return $html;
485 }
486
496 protected function getSuffixIconClient(): string
497 {
498 $html = "";
499
500 if ($this->currObj["client_is_priority_speaker"]) {
501 $html .= $this->getImage("client_priority.png", "Priority Speaker");
502 }
503
504 if ($this->currObj["client_is_channel_commander"]) {
505 $html .= $this->getImage("client_cc.png", "Channel Commander");
506 }
507
508 if ($this->currObj["client_is_talker"]) {
509 $html .= $this->getImage("client_talker.png", "Talk Power granted");
510 } elseif ($cntp = $this->currObj->getParent()->channelGetById($this->currObj["cid"])->channel_needed_talk_power) {
511 if ($cntp > $this->currObj["client_talk_power"]) {
512 $html .= $this->getImage("client_mic_muted.png", "Insufficient Talk Power");
513 }
514 }
515
516 foreach ($this->currObj->memberOf() as $group) {
517 if (!$group["iconid"]) {
518 continue;
519 }
520
521 $type = ($group instanceof ServerGroup) ? "Server Group" : "Channel Group";
522
523 if (!$group->iconIsLocal("iconid") && $this->ftclient) {
524 if (!isset($this->cacheIcon[$group["iconid"]])) {
525 $download = $group->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $group->iconGetName("iconid"));
526
527 if ($this->ftclient == "data:image") {
528 $download = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
529 }
530
531 $this->cacheIcon[$group["iconid"]] = $download;
532 } else {
533 $download = $this->cacheIcon[$group["iconid"]];
534 }
535
536 if ($this->ftclient == "data:image") {
537 $html .= $this->getImage("data:" . Convert::imageMimeType($download) . ";base64," . base64_encode($download), $group . " [" . $type . "]", null, false);
538 } else {
539 $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), $group . " [" . $type . "]", null, false);
540 }
541 } elseif (in_array($group["iconid"], $this->cachedIcons)) {
542 $html .= $this->getImage("group_icon_" . $group["iconid"] . ".png", $group . " [" . $type . "]");
543 }
544 }
545
546 if ($this->currObj["client_icon_id"]) {
547 if (!$this->currObj->iconIsLocal("client_icon_id") && $this->ftclient) {
548 if (!isset($this->cacheIcon[$this->currObj["client_icon_id"]])) {
549 $download = $this->currObj->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->currObj->iconGetName("client_icon_id"));
550
551 if ($this->ftclient == "data:image") {
552 $download = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"])->download($download["ftkey"], $download["size"]);
553 }
554
555 $this->cacheIcon[$this->currObj["client_icon_id"]] = $download;
556 } else {
557 $download = $this->cacheIcon[$this->currObj["client_icon_id"]];
558 }
559
560 if ($this->ftclient == "data:image") {
561 $html .= $this->getImage("data:" . Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Client Icon", null, false);
562 } else {
563 $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Client Icon", null, false);
564 }
565 } elseif (in_array($this->currObj["client_icon_id"], $this->cachedIcons)) {
566 $html .= $this->getImage("group_icon_" . $this->currObj["client_icon_id"] . ".png", "Client Icon");
567 }
568 }
569
570 return $html;
571 }
572
579 protected function getSuffixFlag(): string
580 {
581 if (!$this->currObj instanceof Client) {
582 return "";
583 }
584
585 if ($this->flagpath && $this->currObj["client_country"]) {
586 return $this->getImage($this->currObj["client_country"]->toLower() . ".png", $this->currObj["client_country"], null, false, true);
587 }
588
589 return "";
590 }
591
602 protected function getImage(string $name, string $text = "", string $class = null, bool $iconpath = true, bool $flagpath = false): string
603 {
604 $src = "";
605
606 if ($iconpath) {
607 $src = $this->iconpath;
608 }
609
610 if ($flagpath) {
611 $src = $this->flagpath;
612 }
613
614 return "<img src='" . $src . $name . "' title='" . $text . "' alt='' align='top' />";
615 }
616}
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\Adapter objects.
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Helper* objects.
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery objects.
Helper class for data conversion.
Definition Convert.php:15
Class describing a TeamSpeak 3 channel group and all it's parameters.
Class describing a TeamSpeak 3 channel and all it's parameters.
Definition Channel.php:18
Class describing a TeamSpeak 3 client and all it's parameters.
Definition Client.php:18
Class describing a TeamSpeak 3 virtual server and all it's parameters.
Definition Server.php:21
Factory class all for TeamSpeak 3 PHP Framework objects.
const GROUP_NAMEMODE_BEHIND
2: display name after client nickname
const CODEC_CELT_MONO
3: celt mono (mono, 16bit, 48kHz)
const GROUP_NAMEMODE_BEFORE
1: display name before client nickname
const CODEC_OPUS_MUSIC
3: opus music (interactive)
const SPACER_ALIGN_REPEAT
3: repeat until the whole line is filled
const SPACER_DASHDOTDOTLINE
4: dash dot dot line
Renders nodes used in HTML-based TeamSpeak 3 viewers.
Definition Html.php:25
fetchObject(Node $node, array $siblings=[])
Definition Html.php:120
getImage(string $name, string $text="", string $class=null, bool $iconpath=true, bool $flagpath=false)
Definition Html.php:602
__construct(string $iconpath="images/viewer/", string $flagpath=null, string $ftclient=null, string $pattern=null)
Definition Html.php:99