<?php

class rwdvideo_shortcode extends ddvisualeditor_shortcode
{
	protected $_sTitle = 'PBI_VISUAL_EDITOR_SHORTCODE_RWDVIDEO';

	protected $_sBackgroundColor = '#648AA7';

	protected $_sIcon = 'fa-video-camera';


    public function install()
    {
        $this->setShortCode( basename( __FILE__, '.php' ) );

        $oLang = oxRegistry::getLang();

        $this->setOptions(
			array(
                'url'         => array(
                    'type'    => 'text',
                    'label'   => $oLang->translateString( 'PBI_VISUAL_EDITOR_SHORTCODE_RWDVIDEO_URL' ),
                    'preview' => true
				),
			)
        );
	}

    public function parse( $sContent = '', $aParams = array() )
    {
        $oConfig = $this->getConfig();
		$html = null;

		if (preg_match('/youtube/', $aParams['url'])) {
			$embed_yt = '<div class="m-videoembed m-videoembed--youtube">
				<iframe class="m-videoembed-video" width="%s" height="%s" src="https://www.youtube-nocookie.com/embed/%s" frameborder="0" allowfullscreen></iframe>
			</div>';

			parse_str( parse_url( $aParams['url'], PHP_URL_QUERY ), $my_array_of_vars );
			$yt_id = (isset($my_array_of_vars['v'])) ? $my_array_of_vars['v'] : null;


			var_dump($yt_id);

			$html = sprintf($embed_yt,
				560,
				315,
				$yt_id
			);
		}

		return $html;
    }
}
