Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into 0.8.x

This commit is contained in:
Evan Prodromou 2009-06-22 17:13:28 -07:00
commit 205d8afe54
3 changed files with 112 additions and 47 deletions

View File

@ -257,17 +257,37 @@ class NewnoticeAction extends Action
}
function storeFile($notice, $mimetype) {
$filename = basename($_FILES['attach']['name']);
$destination = "file/{$notice->id}-$filename";
if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) {
common_debug("NewnoticeAction::storeFile()");
$basename = basename($_FILES['attach']['name']);
common_debug("Basename: $basename");
$filename = File::filename($notice->id, $basename);
common_debug("filename: $filename");
$filepath = File::path($filename);
common_debug("filepath: $filepath");
if (move_uploaded_file($_FILES['attach']['tmp_name'], $filepath)) {
$file = new File;
$file->filename = $filename;
$file->url = common_local_url('file', array('notice' => $notice->id));
$file->size = filesize(INSTALLDIR . "/$destination");
common_debug("file->url =". $file->url);
$file->size = filesize($filepath);
$file->date = time();
$file->mimetype = $mimetype;
if ($file_id = $file->insert()) {
$file_redir = new File_redirection;
$file_redir->url = common_path($destination);
$file_redir->url = File::url($filename);
$file_redir->file_id = $file_id;
$file_redir->insert();

View File

@ -145,5 +145,47 @@ class File extends Memcached_DataObject
}
return true;
}
// where should the file go?
static function filename($notice_id, $basename)
{
return $notice_id . '-' . $basename;
}
static function path($filename)
{
$dir = common_config('attachments', 'dir');
if ($dir[strlen($dir)-1] != '/') {
$dir .= '/';
}
return $dir . $filename;
}
static function url($filename)
{
$path = common_config('attachments', 'path');
if ($path[strlen($path)-1] != '/') {
$path .= '/';
}
if ($path[0] != '/') {
$path = '/'.$path;
}
$server = common_config('attachments', 'server');
if (empty($server)) {
$server = common_config('site', 'server');
}
// XXX: protocol
return 'http://'.$server.$path.$filename;
}
}

View File

@ -203,7 +203,10 @@ $config =
'frequency' => 10000,
'reporturl' => 'http://laconi.ca/stats/report'),
'attachments' =>
array('supported' => array('image/png',
array('server' => null,
'dir' => INSTALLDIR . '/file/',
'path' => $_path . '/file/',
'supported' => array('image/png',
'image/jpeg',
'image/gif',
'image/svg+xml',