54 $proxy_config = $this->config->proxy ?? [];
57 RequestOptions::TIMEOUT => 5,
58 RequestOptions::HTTP_ERRORS =>
false,
59 RequestOptions::VERIFY => (bool)
elgg_extract(
'verify_ssl', $proxy_config,
true),
66 $host =
rtrim($host,
':') .
":{$port}";
69 $options[RequestOptions::PROXY] = $host;
72 $this->client =
new Client(
$options);
88 if (empty($image_url)) {
92 $image_url = htmlspecialchars_decode($image_url);
103 if (stripos($image_url,
$site->getURL()) === 0) {
105 $cookie_config = $this->config->getCookieConfig();
108 $cookie_config[
'session'][
'name'] => $this->session->getID(),
111 $domain = $cookie_config[
'session'][
'domain'] ?:
$site->getDomain();
113 $cookiejar = CookieJar::fromArray($cookies,
$domain);
114 $options[RequestOptions::COOKIES] = $cookiejar;
118 $response = $this->client->get($image_url,
$options);
119 }
catch (TransferException $e) {
129 'data' => $response->getBody()->getContents(),
130 'content-type' => $response->getHeaderLine(
'content-type') ?:
'application/octet-stream',
131 'name' => basename($image_url),
147 $cache = $this->cache->load(self::CACHE_PREFIX .
md5($image_url));
161 return $this->cache->save(self::CACHE_PREFIX .
md5($image_url), $data);
Exception thrown if an argument is not of the expected type.
__construct(Config $config, SystemCache $cache,\ElggSession $session)
Constructor.
getImage(string $image_url)
Get an image.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
loadFromCache(string $image_url)
Load an image url from cache.
Fetch external images server side.
saveToCache(string $image_url, array $data)
Save image data in system cache for easy reuse.
elgg_get_site_entity()
Get the current site entity.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.