public function getURL()
{
if (!$this->file instanceof \ElggFile || !$this->file->exists()) {
elgg_log("Unable to resolve resource URL for a file that does not exist on filestore");
return false;
}
$relative_path = '';
$root_prefix = _elgg_services()->config->getDataPath();
$path = $this->file->getFilenameOnFilestore();
if (substr($path, 0, strlen($root_prefix)) == $root_prefix) {
$relative_path = substr($path, strlen($root_prefix));
}
if (!$relative_path) {
elgg_log("Unable to resolve relative path of the file on the filestore");
return false;
}
$data = array('expires' => isset($this->expires) ? $this->expires : 0, 'last_updated' => filemtime($this->file->getFilenameOnFilestore()), 'disposition' => $this->disposition == self::INLINE ? 'i' : 'a', 'path' => $relative_path);
if ($this->use_cookie) {
$data['cookie'] = _elgg_services()->session->getId();
if (empty($data['cookie'])) {
return false;
}
$data['use_cookie'] = 1;
} else {
$data['use_cookie'] = 0;
}
ksort($data);
$mac = _elgg_services()->crypto->getHmac($data)->getToken();
$url_segments = array('serve-file', "e{$data['expires']}", "l{$data['last_updated']}", "d{$data['disposition']}", "c{$data['use_cookie']}", $mac, $relative_path);
return elgg_normalize_url(implode('/', $url_segments));
}