src/Service.php
public function requestUrl(string $url): EmbeddedAsset
	{
		$cacheService = Craft::$app->getCache();

		$cacheKey = 'embeddedasset:' . $url;
		$embeddedAsset = $cacheService->get($cacheKey);

		if (!$embeddedAsset)
		{
			$pluginSettings = EmbeddedAssets::$plugin->getSettings();

			$options = [
				'min_image_width' => $pluginSettings->minImageSize,
				'min_image_height' => $pluginSettings->minImageSize,
				'oembed' => ['parameters' => []],
			];

			if (!empty($pluginSettings->parameters))
			{
				foreach ($pluginSettings->parameters as $parameter)
				{
					$param = $parameter['param'];
					$value = $parameter['value'];
					$options['oembed']['parameters'][$param] = $value;
				}
			}

			if ($pluginSettings->embedlyKey) $options['oembed']['embedly_key'] = $pluginSettings->embedlyKey;
			if ($pluginSettings->iframelyKey) $options['oembed']['iframely_key'] = $pluginSettings->iframelyKey;
			if ($pluginSettings->googleKey) $options['google'] = ['key' => $pluginSettings->googleKey];
			if ($pluginSettings->soundcloudKey) $options['soundcloud'] = ['key' => $pluginSettings->soundcloudKey];
			if ($pluginSettings->facebookKey) $options['facebook'] = ['key' => $pluginSettings->facebookKey];

			$adapter = Embed::create($url, $options);
			$array = $this->_convertFromAdapter($adapter);
			$embeddedAsset = $this->createEmbeddedAsset($array);

			$cacheService->set($cacheKey, $embeddedAsset, $pluginSettings->cacheDuration);
		}

		return $embeddedAsset;
	}
public function requestUrl(string $url): EmbeddedAsset
	{
		$cacheService = Craft::$app->getCache();

		$cacheKey = 'embeddedasset:' . $url;
		$embeddedAsset = $cacheService->get($cacheKey);

		if (!$embeddedAsset)
		{
			$pluginSettings = EmbeddedAssets::$plugin->getSettings();

			$options = [
				'min_image_width' => $pluginSettings->minImageSize,
				'min_image_height' => $pluginSettings->minImageSize,
				'oembed' => ['parameters' => []],
			];

			if (!empty($pluginSettings->parameters))
			{
				foreach ($pluginSettings->parameters as $parameter)
				{
					$param = $parameter['param'];
					$value = $parameter['value'];
					$options['oembed']['parameters'][$param] = $value;
				}
			}

			if ($pluginSettings->embedlyKey) $options['oembed']['embedly_key'] = $pluginSettings->embedlyKey;
			if ($pluginSettings->iframelyKey) $options['oembed']['iframely_key'] = $pluginSettings->iframelyKey;
			if ($pluginSettings->googleKey) $options['google'] = ['key' => $pluginSettings->googleKey];
			if ($pluginSettings->soundcloudKey) $options['soundcloud'] = ['key' => $pluginSettings->soundcloudKey];
			if ($pluginSettings->facebookKey) $options['facebook'] = ['key' => $pluginSettings->facebookKey];

			$adapter = Embed::create($url, $options);
			$array = $this->_convertFromAdapter($adapter);
			$embeddedAsset = $this->createEmbeddedAsset($array);

			$cacheService->set($cacheKey, $embeddedAsset, $pluginSettings->cacheDuration);
		}

		return $embeddedAsset;
	}
public function requestUrl ( string $ url ) : EmbeddedAsset { $ cacheService = Craft :: $ app -> getCache ( ) ; $ cacheKey = 'embeddedasset:' . $ url ; $ embeddedAsset = $ cacheService -> get ( $ cacheKey ) ; if ( ! $ embeddedAsset ) { $ pluginSettings = EmbeddedAssets :: $ plugin -> getSettings ( ) ; $ options = [ 'min_image_width' => $ pluginSettings -> minImageSize , 'min_image_height' => $ pluginSettings -> minImageSize , 'oembed' => [ 'parameters' => [ ] ] , ] ; if ( ! empty ( $ pluginSettings -> parameters ) ) { foreach ( $ pluginSettings -> parameters as $ parameter ) { $ param = $ parameter [ 'param' ] ; $ value = $ parameter [ 'value' ] ; $ options [ 'oembed' ] [ 'parameters' ] [ $ param ] = $ value ; } } if ( $ pluginSettings -> embedlyKey ) $ options [ 'oembed' ] [ 'embedly_key' ] = $ pluginSettings -> embedlyKey ; if ( $ pluginSettings -> iframelyKey ) $ options [ 'oembed' ] [ 'iframely_key' ] = $ pluginSettings -> iframelyKey ; if ( $ pluginSettings -> googleKey ) $ options [ 'google' ] = [ 'key' => $ pluginSettings -> googleKey ] ; if ( $ pluginSettings -> soundcloudKey ) $ options [ 'soundcloud' ] = [ 'key' => $ pluginSettings -> soundcloudKey ] ; if ( $ pluginSettings -> facebookKey ) $ options [ 'facebook' ] = [ 'key' => $ pluginSettings -> facebookKey ] ; $ adapter = Embed :: create ( $ url , $ options ) ; $ array = $ this -> _convertFromAdapter ( $ adapter ) ; $ embeddedAsset = $ this -> createEmbeddedAsset ( $ array ) ; $ cacheService -> set ( $ cacheKey , $ embeddedAsset , $ pluginSettings -> cacheDuration ) ; } return $ embeddedAsset ; }
Requests embed data from a URL.

@param string $url
@return EmbeddedAsset
Requests embed data from a URL .