embed-privacy.php
/**
     * Converts a service url (like a YouTube link) to a privacy secured embedded link.
     *
     * @param string $serviceUrl
     *
     * @return string
     */
Converts a service url (like a YouTube link) to a privacy secured embedded link.
@param string $serviceUrl

@return string
Converts a service url ( like a YouTube link ) to a privacy secured embedded link . @param string $serviceUrl @return string
public function embedPrivacy($serviceUrl)
    {
        $config = $this->grav['config'];
        if (empty($serviceUrl)) return '';
        if (!$config->get('plugins.embed-privacy.iframely_enabled')) return '';
        try {
            $twig = $this->getTwig();
            if ($config->get('plugins.embed-privacy.iframely_enabled') && !empty($config->get('plugins.embed-privacy.iframely_baseurl'))) {
                $service_embed = '';
                $iframelyResponse = @file_get_contents($config->get('plugins.embed-privacy.iframely_baseurl') . '/iframely?url=' . $serviceUrl);
                if (FALSE !== $iframelyResponse) {
                    $iframelyResponse = json_decode($iframelyResponse, TRUE);
                    if (isset($iframelyResponse['links']['player'][0]['html'])) {
                        $service_embed = $iframelyResponse['links']['player'][0]['html'];
                    } else if (isset($iframelyResponse['html'])) {
                        $service_embed = $iframelyResponse['html'];
                    }
                }
                if ($service_embed !== '') {
                    $data = [
                        'service_embed' => $service_embed
                    ];
                    return $twig->render('embedprivacy.html.twig', $data);
                }
            }
        } catch (\Exception $e) {
            return 'Could not load response from ' . $serviceUrl;
        }
        return '';
    }
public function embedPrivacy ( $ serviceUrl ) { $ config = $ this -> grav [ 'config' ] ; if ( empty ( $ serviceUrl ) ) return '' ; if ( ! $ config -> get ( 'plugins.embed-privacy.iframely_enabled' ) ) return '' ; try { $ twig = $ this -> getTwig ( ) ; if ( $ config -> get ( 'plugins.embed-privacy.iframely_enabled' ) && ! empty ( $ config -> get ( 'plugins.embed-privacy.iframely_baseurl' ) ) ) { $ service_embed = '' ; $ iframelyResponse = @ file_get_contents ( $ config -> get ( 'plugins.embed-privacy.iframely_baseurl' ) . '/iframely?url=' . $ serviceUrl ) ; if ( FALSE !== $ iframelyResponse ) { $ iframelyResponse = json_decode ( $ iframelyResponse , TRUE ) ; if ( isset ( $ iframelyResponse [ 'links' ] [ 'player' ] [ 0 ] [ 'html' ] ) ) { $ service_embed = $ iframelyResponse [ 'links' ] [ 'player' ] [ 0 ] [ 'html' ] ; } else if ( isset ( $ iframelyResponse [ 'html' ] ) ) { $ service_embed = $ iframelyResponse [ 'html' ] ; } } if ( $ service_embed !== '' ) { $ data = [ 'service_embed' => $ service_embed ] ; return $ twig -> render ( 'embedprivacy.html.twig' , $ data ) ; } } } catch ( \ Exception $ e ) { return 'Could not load response from ' . $ serviceUrl ; } return '' ; }
Converts a service url (like a YouTube link) to a privacy secured embedded link.
Converts a service url ( like a YouTube link ) to a privacy secured embedded link .
/** @var Config $config */ /** @var TwigEnvironment $twig */ //TODO switch w/ curl