summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorRobin Millette <millette@controlyourself.ca>2009-05-26 21:20:04 -0400
committerRobin Millette <millette@controlyourself.ca>2009-05-26 21:20:04 -0400
commitaf700ea27703bbec5aa1078a84f9fd44c0260322 (patch)
treea227167390948f5791b8190435fbb9cfdbd0bc38 /actions
parent4edb1c6e0cfcaee256757ed20b4ff8d482158906 (diff)
Let's you upload a file with a notice and have it shown with other attachments.
Diffstat (limited to 'actions')
-rw-r--r--actions/newnotice.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/actions/newnotice.php b/actions/newnotice.php
index ae0ff9636..d7507c118 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -109,6 +109,10 @@ class NewnoticeAction extends Action
}
}
+ function isFileAttached() {
+ return $_FILES['attach']['error'] === UPLOAD_ERR_OK;
+ }
+
/**
* Save a new notice, based on arguments
*
@@ -158,7 +162,6 @@ class NewnoticeAction extends Action
$replyto = 'false';
}
-// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
($replyto == 'false') ? null : $replyto);
@@ -167,6 +170,9 @@ class NewnoticeAction extends Action
return;
}
+ if ($this->isFileAttached()) {
+ $this->storeFile($notice);
+ }
$this->saveUrls($notice);
common_broadcast_notice($notice);
@@ -194,6 +200,33 @@ class NewnoticeAction extends Action
}
}
+ function storeFile($notice) {
+ $filename = basename($_FILES['attach']['name']);
+ $destination = "file/{$notice->id}-$filename";
+ if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) {
+ $file = new File;
+// $file->url = common_local_url('file', array('notice' => $notice->id));
+ $file->url = common_path($destination);
+ $file->size = filesize(INSTALLDIR . "/$destination");
+ $file->date = time();
+ $file->mimetype = $_FILES['attach']['type'];
+ if ($ok = $file->insert()) {
+ $f2p = new File_to_post;
+ $f2p->file_id = $ok;
+ $f2p->post_id = $notice->id;
+ $f2p->insert();
+ } else {
+ die('inserting file, dying');
+ }
+ }
+/*
+ $url = common_local_url('file', array('notice' => $notice->id));
+ echo "$destination<br />";
+ die($url);
+*/
+ }
+
+
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
@@ -203,7 +236,7 @@ class NewnoticeAction extends Action
*
* @return void
*/
- function saveUrls($notice) {
+ function saveUrls($notice, $uploaded = null) {
common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id);
}