diff options
-rw-r--r-- | actions/attachment.php | 11 | ||||
-rw-r--r-- | actions/file.php | 12 | ||||
-rw-r--r-- | actions/newnotice.php | 26 | ||||
-rw-r--r-- | lib/router.php | 4 |
4 files changed, 46 insertions, 7 deletions
diff --git a/actions/attachment.php b/actions/attachment.php index e4dc0e054..ee4cd9640 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -111,7 +111,16 @@ class AttachmentAction extends Action function handle($args) { parent::handle($args); - $this->showPage(); + + if (empty($this->attachment->filename)) { + + // if it's not a local file, gtfo + + common_redirect($this->attachment->url, 303); + + } else { + $this->showPage(); + } } /** diff --git a/actions/file.php b/actions/file.php index 271f57ab9..8310e48df 100644 --- a/actions/file.php +++ b/actions/file.php @@ -56,5 +56,17 @@ class FileAction extends Action function handle() { common_redirect($this->filerec->url); } + + /** + * Is this action read-only? + * + * @return boolean true + */ + + function isReadOnly($args) + { + return true; + } + } diff --git a/actions/newnotice.php b/actions/newnotice.php index 15caff6ea..5f44a32a9 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -229,14 +229,25 @@ class NewnoticeAction extends Action 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, @@ -305,8 +316,8 @@ class NewnoticeAction extends Action @unlink($filepath); } - function rememberFile($filename, $mimetype, $short) - { + function storeFile($filename, $mimetype) { + $file = new File; $file->filename = $filename; @@ -325,11 +336,14 @@ class NewnoticeAction extends Action $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); diff --git a/lib/router.php b/lib/router.php index 1f39c60dc..784ea9882 100644 --- a/lib/router.php +++ b/lib/router.php @@ -152,6 +152,10 @@ class Router $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'), array('q' => '.+')); + $m->connect('attachment/:attachment', + array('action' => 'attachment'), + array('attachment' => '[0-9]+')); + $m->connect('attachment/:attachment/ajax', array('action' => 'attachment_ajax'), array('attachment' => '[0-9]+')); |