if (empty($filename)) {
$this->clientError(_('Couldn\'t save file.'));
}
- $fileurl = File::url($filename);
+
+ $fileRecord = $this->storeFile($filename, $mimetype);
+
+ $fileurl = common_local_url('attachment',
+ array('attachment' => $fileRecord->id));
+
+ // not sure this is necessary -- Zach
+ $this->maybeAddRedir($fileRecord->id, $fileurl);
+
$short_fileurl = common_shorten_url($fileurl);
$content_shortened .= ' ' . $short_fileurl;
+
if (mb_strlen($content_shortened) > 140) {
$this->deleteFile($filename);
$this->clientError(_('Max notice size is 140 chars, including attachment URL.'));
}
- $fileRecord = $this->rememberFile($filename, $mimetype, $short_fileurl);
+
+ // Also, not sure this is necessary -- Zach
+ $this->maybeAddRedir($fileRecord->id, $short_fileurl);
}
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
@unlink($filepath);
}
- function rememberFile($filename, $mimetype, $short)
- {
+ function storeFile($filename, $mimetype) {
+
$file = new File;
$file->filename = $filename;
$this->clientError(_('There was a database error while saving your file. Please try again.'));
}
- $this->maybeAddRedir($file_id, $short);
-
return $file;
}
+ function rememberFile($file, $short)
+ {
+ $this->maybeAddRedir($file->id, $short);
+ }
+
function maybeAddRedir($file_id, $url)
{
$file_redir = File_redirection::staticGet('url', $url);