summaryrefslogtreecommitdiff
path: root/classes/File.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-23 07:29:43 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-23 07:29:43 -0700
commita21a9f26c5f0eb034ea389659dd63ffad400de5b (patch)
treee314cb9cd4280481931bc814eeb013f2a672fa2b /classes/File.php
parente2becdb25138350170b58ae8f0d1ecd715533cf5 (diff)
append uploads to content rather than showing them double
Diffstat (limited to 'classes/File.php')
-rw-r--r--classes/File.php67
1 files changed, 36 insertions, 31 deletions
diff --git a/classes/File.php b/classes/File.php
index 1de136240..b98c9e665 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -124,8 +124,8 @@ class File extends Memcached_DataObject
function isRespectsQuota($user) {
if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
return sprintf(_('No file may be larger than %d bytes ' .
- 'and the file you sent was %d bytes. Try to upload a smaller version.'),
- common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
+ 'and the file you sent was %d bytes. Try to upload a smaller version.'),
+ common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
}
$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
@@ -148,44 +148,49 @@ class File extends Memcached_DataObject
// where should the file go?
- static function filename($notice_id, $basename)
- {
- return $notice_id . '-' . $basename;
- }
-
- static function path($filename)
- {
- $dir = common_config('attachments', 'dir');
+ static function filename($profile, $basename, $mimetype)
+ {
+ require_once 'MIME/Type/Extension.php';
+ $mte = new MIME_Type_Extension();
+ $ext = $mte->getExtension($mimetype);
+ $nickname = $profile->nickname;
+ $datestamp = strftime('%Y%m%dT%H%M%S', time());
+ $random = strtolower(common_confirmation_code(32));
+ return "$nickname-$datestamp-$random.$ext";
+ }
- if ($dir[strlen($dir)-1] != '/') {
- $dir .= '/';
- }
+ static function path($filename)
+ {
+ $dir = common_config('attachments', 'dir');
- return $dir . $filename;
- }
+ if ($dir[strlen($dir)-1] != '/') {
+ $dir .= '/';
+ }
- static function url($filename)
- {
- $path = common_config('attachments', 'path');
+ return $dir . $filename;
+ }
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
- }
+ static function url($filename)
+ {
+ $path = common_config('attachments', 'path');
- if ($path[0] != '/') {
- $path = '/'.$path;
- }
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
- $server = common_config('attachments', 'server');
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
- if (empty($server)) {
- $server = common_config('site', 'server');
- }
+ $server = common_config('attachments', 'server');
- // XXX: protocol
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
- return 'http://'.$server.$path.$filename;
- }
+ // XXX: protocol
+ return 'http://'.$server.$path.$filename;
+ }
}