public static function populateFromAsset(AssetFileModel $asset) { if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) { try { $url = $asset->getUrl(); if (!UrlHelper::isAbsoluteUrl($url)) { $protocol = craft()->request->isSecureConnection() ? 'https' : 'http'; $url = UrlHelper::getUrlWithProtocol($url, $protocol); } // See http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php $rawData = @file_get_contents($url); if ($rawData) { $data = JsonHelper::decode($rawData); if ($data['__embeddedasset__']) { unset($data['__embeddedasset__']); $embed = new EmbeddedAssetsModel(); $embed->id = $asset->id; foreach ($data as $key => $value) { $embed->{$key} = $value; } return $embed; } } } catch (\Exception $e) { return null; } } return null; }
public function readAssetFile(AssetFileModel $asset) { $url = $asset->getUrl(); if (!UrlHelper::isAbsoluteUrl($url)) { $protocol = craft()->request->isSecureConnection() ? 'https' : 'http'; $url = UrlHelper::getUrlWithProtocol($url, $protocol); } return $this->_readExternalFile($url); }