YaWK  24.1
Yet another WebKit
twitch.php
Go to the documentation of this file.
1 <?php
3 {
4  /**
5  * @details<b>Twitch Widget - embed any twitch channel</b>
6  *
7  * <p>Twitch is a gaming streaming platform. Use this widget to embed any
8  * twitch channel. You can set your channel, width, height, either if the
9  * chat should be displayed or not, allow fullscreen and more.</p>
10  *
11  *
12  * @author Daniel Retzl <[email protected]>
13  * @copyright 2018 Daniel Retzl
14  * @version 1.0.0
15  * @brief Embed any Twitch channel
16  */
17  class twitch extends \YAWK\widget
18  {
19  /** @param object global widget object data */
20  public $widget = '';
21  /** @param string Title that will be shown above widget */
22  public $twitchHeading = '';
23  /** @param string Subtext will be displayed beside title */
24  public $twitchSubtext = '';
25  /** @param string Channel that will be included */
26  public $twitchChannel = "yourChannel";
27  /** @param string Height of your channel */
28  public $twitchChannelHeight = "720";
29  /** @param string Width of your channel */
30  public $twitchChannelWidth = "100%";
31  /** @param bool Allow fullscreen? */
32  public $twitchChannelFullscreen = true;
33  /** @param int Show chat window? */
34  public $twitchChat = "1";
35  /** @param int Chat window height */
36  public $twitchChatHeight = "250";
37  /** @param int Chat window width */
38  public $twitchChatWidth = "100%";
39 
40  /**
41  * @brief Load all widget settings from database and fill object
42  * @param object $db Database Object
43  * @brief Load all widget settings on object init.
44  */
45  public function __construct($db)
46  {
47  // load this widget settings from db
48  $this->widget = new \YAWK\widget();
50  foreach ($settings as $property => $value) {
51  $this->$property = $value;
52  }
53  }
54 
55  /**
56  * @brief Init twitch widget
57  * @brief Twitch Widget Init
58  */
59  public function init()
60  { // display heading
61  echo $this->getHeading($this->twitchHeading, $this->twitchSubtext);
62  // to output correct html
63  if ($this->twitchChannelFullscreen === "true") { // set fullscreen property
64  $allowfullscreen = "allowfullscreen=\"true\"";
65  } else { // or leave empty if fullscreen should be false
66  $allowfullscreen = '';
67  }
68 // HTML output
69  echo "
70 <!-- twitch video stream -->
71 <iframe
72  src=\"http://player.twitch.tv/?channel=$this->twitchChannel\"
73  height=\"$this->twitchChannelHeight\"
74  width=\"$this->twitchChannelWidth\"
75  frameborder=\"0\"
76  scrolling=\"no\"
77  $allowfullscreen\">
78 </iframe>";
79 
80 // check if chat should be shown
81  if (isset($this->twitchChat) && ($this->twitchChat === 1)) { // ok, show chat html frame
82  echo "
83 
84 <!-- twitch chat -->
85 <iframe
86  frameborder=\"0\"
87  scrolling=\"no\"
88  src=\"http://www.twitch.tv/popout/$this->twitchChannel/chat\"
89  height=\"$this->twitchChatHeight\"
90  width=\"$this->twitchChatWidth\">
91 </iframe>";
92  }
93  }
94  }
95 }
96 ?>
Embed any Twitch channel.
Definition: twitch.php:17
__construct($db)
Load all widget settings from database and fill object.
Definition: twitch.php:44
init()
Init twitch widget.
Definition: twitch.php:58
Widgets are small, useful tools that you can include everywhere in your website.
Definition: widget.php:22
getWidgetSettingsArray($db)
Get widget settings and return it as array.
Definition: widget.php:69
getHeading($heading, $subtext)
Get widget heading and subtext, return headline.
Definition: widget.php:669
if(isset($_POST['save'])) $settings
$value