forked from GNUsocial/gnu-social
Fiddling with merge request #98 to use internal routing functions
This commit is contained in:
parent
8356c2495c
commit
6a4470912f
@ -108,13 +108,20 @@ class File extends Managed_DataObject
|
|||||||
|
|
||||||
// if the given url is an local attachment url and the id already exists, don't
|
// if the given url is an local attachment url and the id already exists, don't
|
||||||
// save a new file record. This should never happen, but let's make it foolproof
|
// save a new file record. This should never happen, but let's make it foolproof
|
||||||
$attachment_path = common_path('attachment/');
|
// FIXME: how about attachments servers?
|
||||||
if (mb_strpos($given_url,$attachment_path) === 0) {
|
$u = parse_url($given_url);
|
||||||
$possible_file_id = mb_substr($given_url, mb_strlen($attachment_path));
|
if (isset($u['host']) && $u['host'] === common_config('site', 'server')) {
|
||||||
if(is_numeric($possible_file_id)) {
|
$r = Router::get();
|
||||||
$file = File::getKV('id',$possible_file_id);
|
$args = $r->map(mb_substr($u['path']));
|
||||||
if($file instanceof File) {
|
if ($args['action'] === 'attachment') {
|
||||||
|
try {
|
||||||
|
// $args['attachment'] should always be set if action===attachment, given our routing rules
|
||||||
|
$file = File::getByID($args['attachment']);
|
||||||
return $file;
|
return $file;
|
||||||
|
} catch (EmptyIdException $e) {
|
||||||
|
// ...but $args['attachment'] can also be 0...
|
||||||
|
} catch (NoResultException $e) {
|
||||||
|
// apparently this link goes to us, but is _not_ an existing attachment (File) ID?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user