YaWK  24.1
Yet another WebKit
soundcloud.php
Go to the documentation of this file.
1 <?php
3 {
4  /**
5  * @details<b>Embed any soundcloud track or playlist.</b>
6  *
7  * <p>If you want to embed a SoundCloud player on your website, this is the widget to do it.
8  * All you need is any public SoundCloud URL. The Widget comes with a few settings like: autoplay
9  * on or off, show comments, related music, and much more is customizable within the backend. </p>
10  *
11  *
12  * @author Daniel Retzl <[email protected]>
13  * @copyright 2018 Daniel Retzl
14  * @version 1.0.0
15  * @brief Embed a SoundCloud audio player.
16  */
17  class soundcloud
18  {
19  /** @param object global widget object data */
20  public $widget = '';
21  /** @param string The URL of your soundcloud track or playlist */
22  public $soundcloudUrl = '';
23  /** @param string Title above the player */
24  public $soundcloudTitle = '';
25  /** @param string Subtext gets drawn as small tag beside the title */
26  public $soundcloudSubtext = '';
27  /** @param bool true|false - Autoplay enabled? */
28  public $soundcloudAutoplay = false;
29  /** @param bool true|false - Hide related? */
30  public $soundcloudHideRelated = false;
31  /** @param bool true|false - Show Comments? */
32  public $soundcloudShowComments = false;
33  /** @param bool true|false - Show User? */
34  public $soundcloudShowUser = false;
35  /** @param bool true|false - Show Reposts? */
36  public $soundcloudShowReposts = false;
37  /** @param bool true|false - Show Teaser? */
38  public $soundcloudShowTeaser = false;
39  /** @param bool true|false - Visual? */
40  public $soundcloudVisual = false;
41  /** @param string Player Width (100%) */
42  public $soundcloudWidth = '100%';
43  /** @param string Player Height (300) */
44  public $soundcloudHeight = '300';
45  /** @param string Headline HTML Markup */
46  public $headline = '';
47  /** @param string Store an error msg, if one occurs */
48  public $errorMsg = '';
49 
50  /**
51  * @brief Load all widget settings from database and fill object
52  * @param object $db Database Object
53  * @brief Load all widget settings on object init.
54  */
55  public function __construct($db)
56  {
57  // load this widget settings from db
58  $this->widget = new \YAWK\widget();
60  foreach ($settings as $property => $value) {
61  $this->$property = $value;
62  }
63  }
64 
65  /**
66  * @brief Print all object data
67  * @brief (for development and testing purpose)
68  */
69  public function printObject()
70  {
71  // output all obj data
72  echo "<pre>";
73  print_r($this);
74  echo "</pre>";
75  exit;
76  }
77 
78  /**
79  * @brief Initialize: Set properties and embed SoundCloud player
80  * @brief use this method to run the clock
81  */
82  public function init()
83  {
84  // set object properties
85  $this->setProperties();
86  // $this->printObject();
87  // embed the SoundCloud Player
88  $this->embedPlayer();
89  }
90 
91  /**
92  * @brief Prepare SoundCloud Player Properties
93  * @brief Set Player Properties and HTML Markup Code
94  */
95  public function setProperties()
96  {
97  // check if soundcloud URL is set, not empty and a valid type (string)
98  if (isset($this->soundcloudUrl) && (!empty($this->soundcloudUrl)
99  && (is_string($this->soundcloudUrl))))
100  { // select everything AFTER the soundcloud.com/ part
101  $this->soundcloudUrl = strstr($this->soundcloudUrl, 'soundcloud.com/');
102  }
103  else
104  { // throw error msg
105  $this->errorMsg = "Here should be a SoundCloud music player, but no SoundCloud URL was set.";
106  }
107 
108  // if a heading is set and not empty
109  if (isset($this->soundcloudTitle) && (!empty($this->soundcloudTitle)))
110  {
111  // if subtext is set, add <small> subtext to string
112  if (isset($this->soundcloudSubtext) && (!empty($this->soundcloudSubtext)))
113  { // build a headline with heading and subtext
114  $this->soundcloudSubtext = "<small>$this->soundcloudSubtext</small>";
115  $this->headline = "<h1>$this->soundcloudTitle&nbsp;" . "$this->soundcloudSubtext</h1>";
116  }
117  else
118  { // build just a headline - without subtext
119  $this->headline = "<h1>$this->soundcloudTitle</h1>"; // draw just the heading
120  }
121  }
122  else
123  { // leave empty if it's not set
124  $this->headline = '';
125  }
126 
127  }
128 
129  /**
130  * @brief Embed SoundCloud Player
131  * @brief Load SoundCloud Iframe
132  */
133  public function embedPlayer()
134  {
135  // output headline
136  echo $this->headline;
137  // throw error (if one occurs)
138  echo $this->errorMsg;
139  // embed SoundCloud player
140  echo "<iframe
141  width=\"$this->soundcloudWidth\"
142  height=\"$this->soundcloudHeight\"
143  scrolling=\"no\"
144  frameborder=\"no\"
145  allow=\"autoplay\"
146  src=\"https://w.soundcloud.com/player/?url=https%3A//$this->soundcloudUrl&color=%23ff5500&auto_play=$this->soundcloudAutoplay&hide_related=$this->soundcloudHideRelated&show_comments=$this->soundcloudShowComments&show_user=$this->soundcloudShowUser&show_reposts=$this->soundcloudShowReposts&show_teaser=$this->soundcloudShowTeaser&visual=$this->soundcloudVisual\">
147  </iframe>";
148  }
149  }
150 }
Embed a SoundCloud audio player.
Definition: soundcloud.php:17
setProperties()
Prepare SoundCloud Player Properties.
Definition: soundcloud.php:94
init()
Initialize: Set properties and embed SoundCloud player.
Definition: soundcloud.php:81
embedPlayer()
Embed SoundCloud Player.
Definition: soundcloud.php:132
__construct($db)
Load all widget settings from database and fill object.
Definition: soundcloud.php:54
printObject()
Print all object data.
Definition: soundcloud.php:68
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
c jPlayer errorMsg
exit
if(isset($_POST['save'])) $settings
$value