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;
 }
 /**
  * Returns the site URL (with a trailing slash).
  *
  * @param string|null $protocol The protocol to use (http or https). If none is specified, it will default to
  *                              whatever's in the Site URL setting.
  *
  * @return string
  */
 public function getSiteUrl($protocol = null)
 {
     if (!isset($this->_siteUrl)) {
         // Start by checking the config
         $siteUrl = craft()->config->getLocalized('siteUrl');
         if (!$siteUrl) {
             if (defined('CRAFT_SITE_URL')) {
                 $siteUrl = CRAFT_SITE_URL;
             } else {
                 $siteUrl = $this->getInfo('siteUrl');
             }
             if ($siteUrl) {
                 // Parse it for environment variables
                 $siteUrl = craft()->config->parseEnvironmentString($siteUrl);
             } else {
                 // Figure it out for ourselves, then
                 $siteUrl = craft()->request->getBaseUrl(true);
             }
         }
         $this->setSiteUrl($siteUrl);
     }
     return UrlHelper::getUrlWithProtocol($this->_siteUrl, $protocol);
 }
 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);
 }