summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-22 17:13:28 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-22 17:13:28 -0700
commit205d8afe546b385100103dafc439d0397c36cbf4 (patch)
treecb90bbae9f2995257586eb0cd86f9d06dc05826d
parent875e122a24987dcd46c45f0f8823ab2a49dfb031 (diff)
parentd9bebfd6512353690be8bf8cc596a0656ef48ae9 (diff)
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into 0.8.x
-rw-r--r--actions/newnotice.php34
-rw-r--r--classes/File.php58
-rw-r--r--lib/common.php67
3 files changed, 112 insertions, 47 deletions
diff --git a/actions/newnotice.php b/actions/newnotice.php
index 72ccd8c32..09652d2b3 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -257,23 +257,43 @@ 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();
$f2p = new File_to_post;
- $f2p->file_id = $file_id;
- $f2p->post_id = $notice->id;
+ $f2p->file_id = $file_id;
+ $f2p->post_id = $notice->id;
$f2p->insert();
} else {
$this->clientError(_('There was a database error while saving your file. Please try again.'));
diff --git a/classes/File.php b/classes/File.php
index 47af1c550..1de136240 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -30,7 +30,7 @@ require_once INSTALLDIR.'/classes/File_to_post.php';
* Table Definition for file
*/
-class File extends Memcached_DataObject
+class File extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@ -38,12 +38,12 @@ class File extends Memcached_DataObject
public $__table = 'file'; // table name
public $id; // int(4) primary_key not_null
public $url; // varchar(255) unique_key
- public $mimetype; // varchar(50)
- public $size; // int(4)
- public $title; // varchar(255)
- public $date; // int(4)
- public $protected; // int(4)
- public $filename; // varchar(255)
+ public $mimetype; // varchar(50)
+ public $size; // int(4)
+ public $title; // varchar(255)
+ public $date; // int(4)
+ public $protected; // int(4)
+ public $filename; // varchar(255)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
@@ -116,7 +116,7 @@ class File extends Memcached_DataObject
$x = File::staticGet($file_id);
if (empty($x)) die('Impossible!');
}
-
+
File_to_post::processNew($file_id, $notice_id);
return $x;
}
@@ -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;
+ }
+
}
diff --git a/lib/common.php b/lib/common.php
index 2327dcb0e..20f1ab35e 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -202,38 +202,41 @@ $config =
array('run' => 'web',
'frequency' => 10000,
'reporturl' => 'http://laconi.ca/stats/report'),
- 'attachments' =>
- array('supported' => array('image/png',
- 'image/jpeg',
- 'image/gif',
- 'image/svg+xml',
- 'audio/mpeg',
- 'audio/x-speex',
- 'application/ogg',
- 'application/pdf',
- 'application/vnd.oasis.opendocument.text',
- 'application/vnd.oasis.opendocument.text-template',
- 'application/vnd.oasis.opendocument.graphics',
- 'application/vnd.oasis.opendocument.graphics-template',
- 'application/vnd.oasis.opendocument.presentation',
- 'application/vnd.oasis.opendocument.presentation-template',
- 'application/vnd.oasis.opendocument.spreadsheet',
- 'application/vnd.oasis.opendocument.spreadsheet-template',
- 'application/vnd.oasis.opendocument.chart',
- 'application/vnd.oasis.opendocument.chart-template',
- 'application/vnd.oasis.opendocument.image',
- 'application/vnd.oasis.opendocument.image-template',
- 'application/vnd.oasis.opendocument.formula',
- 'application/vnd.oasis.opendocument.formula-template',
- 'application/vnd.oasis.opendocument.text-master',
- 'application/vnd.oasis.opendocument.text-web',
- 'application/x-zip',
- 'application/zip',
- 'text/plain',
- 'video/mpeg',
- 'video/mp4',
- 'video/quicktime',
- 'video/mpeg'),
+ 'attachments' =>
+ array('server' => null,
+ 'dir' => INSTALLDIR . '/file/',
+ 'path' => $_path . '/file/',
+ 'supported' => array('image/png',
+ 'image/jpeg',
+ 'image/gif',
+ 'image/svg+xml',
+ 'audio/mpeg',
+ 'audio/x-speex',
+ 'application/ogg',
+ 'application/pdf',
+ 'application/vnd.oasis.opendocument.text',
+ 'application/vnd.oasis.opendocument.text-template',
+ 'application/vnd.oasis.opendocument.graphics',
+ 'application/vnd.oasis.opendocument.graphics-template',
+ 'application/vnd.oasis.opendocument.presentation',
+ 'application/vnd.oasis.opendocument.presentation-template',
+ 'application/vnd.oasis.opendocument.spreadsheet',
+ 'application/vnd.oasis.opendocument.spreadsheet-template',
+ 'application/vnd.oasis.opendocument.chart',
+ 'application/vnd.oasis.opendocument.chart-template',
+ 'application/vnd.oasis.opendocument.image',
+ 'application/vnd.oasis.opendocument.image-template',
+ 'application/vnd.oasis.opendocument.formula',
+ 'application/vnd.oasis.opendocument.formula-template',
+ 'application/vnd.oasis.opendocument.text-master',
+ 'application/vnd.oasis.opendocument.text-web',
+ 'application/x-zip',
+ 'application/zip',
+ 'text/plain',
+ 'video/mpeg',
+ 'video/mp4',
+ 'video/quicktime',
+ 'video/mpeg'),
'file_quota' => 5000000,
'user_quota' => 50000000,
'monthly_quota' => 15000000,