public function getYoutubeCode()
{
if (!$this->id) {
return $this->getEmptyCode();
}
$options = $this->getOptions();
$code = "";
// get youtube id
$youtubeId = $this->id;
if (strpos($youtubeId, "//") !== false) {
$parts = parse_url($this->id);
parse_str($parts["query"], $vars);
if ($vars["v"]) {
$youtubeId = $vars["v"];
}
//get youtube id if form urls like http://www.youtube.com/embed/youtubeId
if (strpos($this->id, 'embed') !== false) {
$explodedPath = explode('/', $parts['path']);
$youtubeId = $explodedPath[array_search('embed', $explodedPath) + 1];
}
if ($parts["host"] == "youtu.be") {
$youtubeId = trim($parts["path"], " /");
}
}
if (!$youtubeId) {
return $this->getEmptyCode();
}
$width = "100%";
if (array_key_exists("width", $options)) {
$width = $options["width"];
}
$height = "300";
if (array_key_exists("height", $options)) {
$height = $options["height"];
}
$valid_youtube_prams = ["autohide", "autoplay", "cc_load_policy", "color", "controls", "disablekb", "enablejsapi", "end", "fs", "iv_load_policy", "list", "listType", "loop", "modestbranding", "origin", "playerapiid", "playlist", "rel", "showinfo", "start", "theme"];
$additional_params = "";
$clipConfig = [];
if (is_array($options["config"]["clip"])) {
$clipConfig = $options["config"]["clip"];
}
// this is to be backward compatible to <= v 1.4.7
$configurations = $clipConfig;
if (is_array($options["youtube"])) {
$configurations = array_merge($clipConfig, $options["youtube"]);
}
if (!empty($configurations)) {
foreach ($configurations as $key => $value) {
if (in_array($key, $valid_youtube_prams)) {
if (is_bool($value)) {
if ($value) {
$additional_params .= "&" . $key . "=1";
} else {
$additional_params .= "&" . $key . "=0";
}
} else {
$additional_params .= "&" . $key . "=" . $value;
}
}
}
}
$code .= '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_tag_video">
<iframe width="' . $width . '" height="' . $height . '" src="//www.youtube-nocookie.com/embed/' . $youtubeId . '?wmode=transparent' . $additional_params . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>';
return $code;
}