summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-23 14:29:46 -0700
committerZach Copley <zach@controlyourself.ca>2009-06-23 14:29:46 -0700
commitf04a54ed2f70686d67ed50da21bde61c55b07696 (patch)
treed4dbfac2a98e35b6f47696f787a3c2aa551f51ab /actions
parent31325f0995bb61413b07f166d253b13fb27d085d (diff)
parent2d3e990ed47ee1c7130e1febabe7133884a85c80 (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 'actions')
-rw-r--r--actions/newnotice.php101
-rw-r--r--actions/shownotice.php28
2 files changed, 99 insertions, 30 deletions
diff --git a/actions/newnotice.php b/actions/newnotice.php
index 09652d2b3..4a2c369f0 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -116,6 +116,9 @@ class NewnoticeAction extends Action
function getUploadedFileType() {
require_once 'MIME/Type.php';
+ $cmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd');
+ $cmd = common_config('attachments', 'filecommand');
+
$filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
if (in_array($filetype, common_config('attachments', 'supported'))) {
return $filetype;
@@ -221,16 +224,34 @@ class NewnoticeAction extends Action
}
}
+ if (isset($mimetype)) {
+ $filename = $this->saveFile($mimetype);
+ if (empty($filename)) {
+ $this->clientError(_('Couldn\'t save file.'));
+ }
+ $fileurl = File::url($filename);
+ $short_fileurl = common_shorten_url($fileurl);
+ $content_shortened .= ' ' . $short_fileurl;
+ if (mb_strlen($content_shortened) > 140) {
+ $this->deleteFile($filename);
+ $this->clientError(_('Max notice size is 140 chars, including attachment URL.'));
+ }
+ }
+
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
+ if (isset($filename)) {
+ $this->deleteFile($filename);
+ }
$this->clientError($notice);
}
if (isset($mimetype)) {
- $this->storeFile($notice, $mimetype);
+ $this->attachFile($notice, $filename, $mimetype, $short_fileurl);
}
+
common_broadcast_notice($notice);
if ($this->boolean('ajax')) {
@@ -256,50 +277,72 @@ class NewnoticeAction extends Action
}
}
- function storeFile($notice, $mimetype) {
+ function saveFile($mimetype) {
+
+ $cur = common_current_user();
- common_debug("NewnoticeAction::storeFile()");
+ if (empty($cur)) {
+ $this->serverError(_('Somehow lost the login in saveFile'));
+ }
$basename = basename($_FILES['attach']['name']);
- common_debug("Basename: $basename");
+ $filename = File::filename($cur->getProfile(), $basename, $mimetype);
+
+ $filepath = File::path($filename);
+
+ if (move_uploaded_file($_FILES['attach']['tmp_name'], $filepath)) {
+ return $filename;
+ } else {
+ $this->clientError(_('File could not be moved to destination directory.'));
+ }
+ }
+
+ function deleteFile($filename)
+ {
+ $filepath = File::path($filename);
+ @unlink($filepath);
+ }
- $filename = File::filename($notice->id, $basename);
+ function attachFile($notice, $filename, $mimetype, $short)
+ {
+ $file = new File;
+ $file->filename = $filename;
- common_debug("filename: $filename");
+ $file->url = common_local_url('file', array('notice' => $notice->id));
$filepath = File::path($filename);
- common_debug("filepath: $filepath");
+ $file->size = filesize($filepath);
+ $file->date = time();
+ $file->mimetype = $mimetype;
- if (move_uploaded_file($_FILES['attach']['tmp_name'], $filepath)) {
+ $file_id = $file->insert();
- $file = new File;
- $file->filename = $filename;
+ if (!$file_id) {
+ common_log_db_error($file, "INSERT", __FILE__);
+ $this->clientError(_('There was a database error while saving your file. Please try again.'));
+ }
- $file->url = common_local_url('file', array('notice' => $notice->id));
+ $file_redir = new File_redirection;
+ $file_redir->url = File::url($filename);
+ $file_redir->file_id = $file_id;
- common_debug("file->url =". $file->url);
+ $result = $file_redir->insert();
- $file->size = filesize($filepath);
- $file->date = time();
- $file->mimetype = $mimetype;
+ if (!$result) {
+ common_log_db_error($file_redir, "INSERT", __FILE__);
+ $this->clientError(_('There was a database error while saving your file. Please try again.'));
+ }
- if ($file_id = $file->insert()) {
- $file_redir = new File_redirection;
- $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->insert();
- $f2p = new File_to_post;
- $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.'));
- }
- } else {
- $this->clientError(_('File could not be moved to destination directory.'));
+ if (!$result) {
+ common_log_db_error($f2p, "INSERT", __FILE__);
+ $this->clientError(_('There was a database error while saving your file. Please try again.'));
}
}
diff --git a/actions/shownotice.php b/actions/shownotice.php
index b0d973a99..0d89af5ac 100644
--- a/actions/shownotice.php
+++ b/actions/shownotice.php
@@ -209,7 +209,7 @@ class ShownoticeAction extends Action
function showContent()
{
$this->elementStart('ol', array('class' => 'notices xoxo'));
- $nli = new NoticeListItem($this->notice, $this);
+ $nli = new SingleNoticeItem($this->notice, $this);
$nli->show();
$this->elementEnd('ol');
}
@@ -264,3 +264,29 @@ class ShownoticeAction extends Action
}
}
}
+
+class SingleNoticeItem extends NoticeListItem
+{
+ /**
+ * recipe function for displaying a single notice.
+ *
+ * We overload to show attachments.
+ *
+ * @return void
+ */
+
+ function show()
+ {
+ $this->showStart();
+ $this->showNotice();
+ $this->showNoticeAttachments();
+ $this->showNoticeInfo();
+ $this->showNoticeOptions();
+ $this->showEnd();
+ }
+
+ function showNoticeAttachments() {
+ $al = new AttachmentList($this->notice, $this->out);
+ $al->show();
+ }
+}