diff options
author | Zach Copley <zach@controlyourself.ca> | 2009-06-23 14:29:46 -0700 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2009-06-23 14:29:46 -0700 |
commit | f04a54ed2f70686d67ed50da21bde61c55b07696 (patch) | |
tree | d4dbfac2a98e35b6f47696f787a3c2aa551f51ab /classes/File.php | |
parent | 31325f0995bb61413b07f166d253b13fb27d085d (diff) | |
parent | 2d3e990ed47ee1c7130e1febabe7133884a85c80 (diff) |
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
* '0.8.x' of git@gitorious.org:laconica/dev: (61 commits)
Using default theme design values (it was previously set to identica
Updated default colour theme and IE6 colours for transparent values
chmod +x delete_status_network.sh
rm -Rf, not rmdir
script to delete a status network
chmod allsites.php
script to show all sites on a network
use different name for connection and database
use /etc/laconica/setup.cfg instead of local file
other base directories
On XHR notice post, calls NoticeAttachment to trigger thumbnail and
oembed and thumbnail don't need sequences
add innodb by default to status networks
pwgen not pwdgen
make pwgen command configurable
a little sql script to drop full-text index and use innodb for profile and notice
remove common_debug from newnotice
append uploads to content rather than showing them double
use a subclass for single notice items to show attachments
make file command configurable
...
Diffstat (limited to 'classes/File.php')
-rw-r--r-- | classes/File.php | 67 |
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; + } } |