*/ class syntax_plugin_vshare_video extends SyntaxPlugin { protected $sites; protected $sizes = [ 'small' => [255, 143], 'medium' => [425, 239], 'large' => [520, 293], 'full' => ['100%', ''], 'half' => ['50%', ''], ]; protected $alignments = [ 0 => 'none', 1 => 'right', 2 => 'left', 3 => 'center', ]; /** * Constructor. * Intitalizes the supported video sites */ public function __construct() { $this->sites = helper_plugin_vshare::loadSites(); } /** @inheritdoc */ public function getType() { return 'substition'; } /** @inheritdoc */ public function getPType() { return 'block'; } /** @inheritdoc */ public function getSort() { return 159; } /** @inheritdoc */ public function connectTo($mode) { $pattern = implode('|', array_keys($this->sites)); $this->Lexer->addSpecialPattern('\{\{\s?(?:' . $pattern . ')>[^}]*\}\}', $mode, 'plugin_vshare_video'); } /** @inheritdoc */ public function handle($match, $state, $pos, Doku_Handler $handler) { $command = substr($match, 2, -2); // title [$command, $title] = sexplode('|', $command, 2, ''); $title = trim($title); // alignment $align = 0; if (substr($command, 0, 1) == ' ') ++$align; if (substr($command, -1) == ' ') $align += 2; $command = trim($command); // get site and video [$site, $vid] = explode('>', $command); if (!$this->sites[$site]) return null; // unknown site if (!$vid) return null; // no video!? // what size? [$vid, $pstr] = sexplode('?', $vid, 2, ''); parse_str($pstr, $userparams); [$width, $height] = $this->parseSize($userparams); // get URL $url = $this->insertPlaceholders($this->sites[$site]['url'], $vid, $width, $height); [$url, $urlpstr] = sexplode('?', $url, 2, ''); parse_str($urlpstr, $urlparams); // merge parameters $params = array_merge($urlparams, $userparams); $url = $url . '?' . buildURLparams($params, '&'); return [ 'site' => $site, 'domain' => parse_url($url, PHP_URL_HOST), 'video' => $vid, 'url' => $url, 'align' => $this->alignments[$align], 'width' => $width, 'height' => $height, 'title' => $title ]; } /** @inheritdoc */ public function render($mode, Doku_Renderer $R, $data) { if ($mode != 'xhtml') return false; if (is_null($data)) return false; if (is_a($R, 'renderer_plugin_dw2pdf')) { $R->doc .= $this->pdf($data); } else { $R->doc .= $this->iframe($data, $this->getConf('gdpr') ? 'div' : 'iframe'); } return true; } /** * Prepare the HTML for output of the embed iframe * @param array $data * @param string $element Can be used to not directly embed the iframe * @return string */ public function iframe($data, $element = 'iframe') { $attributes = [ 'src' => $data['url'], 'width' => $data['width'], 'height' => $data['height'], 'style' => $this->sizeToStyle($data['width'], $data['height']), 'class' => 'vshare vshare__' . $data['align'], 'allowfullscreen' => '', 'frameborder' => 0, 'scrolling' => 'no', 'data-domain' => $data['domain'], 'loading' => 'lazy', ]; if ($this->getConf('extrahard')) { $attributes = array_merge($attributes, $this->hardenedIframeAttributes()); } return "<$element " . buildAttributes($attributes) . '>