Let's you upload a file with a notice and have it shown with other attachments.
This commit is contained in:
parent
4edb1c6e0c
commit
af700ea277
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||
function fileUpload() {
|
||||
var form = $form[0];
|
||||
|
||||
if ($(':input[@name=submit]', form).length) {
|
||||
if ($(':input[name=submit]', form).length) {
|
||||
alert('Error: Form elements must not be named "submit".');
|
||||
return;
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ $.fn.clearForm = function() {
|
|||
$.fn.clearFields = $.fn.clearInputs = function() {
|
||||
return this.each(function() {
|
||||
var t = this.type, tag = this.tagName.toLowerCase();
|
||||
if (t == 'text' || t == 'password' || tag == 'textarea')
|
||||
if (t == 'file' || t == 'text' || t == 'password' || tag == 'textarea')
|
||||
this.value = '';
|
||||
else if (t == 'checkbox' || t == 'radio')
|
||||
this.checked = false;
|
||||
|
|
12
js/util.js
12
js/util.js
|
@ -17,6 +17,17 @@
|
|||
*/
|
||||
|
||||
$(document).ready(function(){
|
||||
$('input#notice_data-attach').toggle();
|
||||
$('label[for=notice_data-attach]').text('Upload a file as an attachment?');
|
||||
$('label[for=notice_data-attach]').click(function () {
|
||||
if ('Upload a file as an attachment?' == $(this).text()) {
|
||||
$(this).text('Upload: ');
|
||||
$('input#notice_data-attach').slideDown('fast');
|
||||
} else {
|
||||
$('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');});
|
||||
}
|
||||
});
|
||||
|
||||
$('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; });
|
||||
$("a.thumbnail").hover(
|
||||
function() {
|
||||
|
@ -227,6 +238,7 @@ $(document).ready(function(){
|
|||
}
|
||||
}
|
||||
$("#notice_data-text").val("");
|
||||
$("#notice_data-attach").val("");
|
||||
counter();
|
||||
}
|
||||
$("#form_notice").removeClass("processing");
|
||||
|
|
|
@ -80,13 +80,15 @@ class AttachmentList extends Widget
|
|||
|
||||
function show()
|
||||
{
|
||||
$atts = new File;
|
||||
$att = $atts->getAttachments($this->notice->id);
|
||||
if (empty($att)) return 0;
|
||||
|
||||
$this->out->elementStart('dl', array('id' =>'attachment'));
|
||||
$this->out->element('dt', null, _('Attachments'));
|
||||
$this->out->elementStart('dd');
|
||||
$this->out->elementStart('ul', array('class' => 'attachments'));
|
||||
|
||||
$atts = new File;
|
||||
$att = $atts->getAttachments($this->notice->id);
|
||||
foreach ($att as $n=>$attachment) {
|
||||
$item = $this->newListItem($attachment);
|
||||
$item->show();
|
||||
|
|
16
lib/form.php
16
lib/form.php
|
@ -52,6 +52,8 @@ require_once INSTALLDIR.'/lib/widget.php';
|
|||
|
||||
class Form extends Widget
|
||||
{
|
||||
var $enctype = null;
|
||||
|
||||
/**
|
||||
* Show the form
|
||||
*
|
||||
|
@ -63,11 +65,15 @@ class Form extends Widget
|
|||
|
||||
function show()
|
||||
{
|
||||
$this->out->elementStart('form',
|
||||
array('id' => $this->id(),
|
||||
'class' => $this->formClass(),
|
||||
'method' => 'post',
|
||||
'action' => $this->action()));
|
||||
$attributes = array('id' => $this->id(),
|
||||
'class' => $this->formClass(),
|
||||
'method' => 'post',
|
||||
'action' => $this->action());
|
||||
|
||||
if (!empty($this->enctype)) {
|
||||
$attributes['enctype'] = $this->enctype;
|
||||
}
|
||||
$this->out->elementStart('form', $attributes);
|
||||
$this->out->elementStart('fieldset');
|
||||
$this->formLegend();
|
||||
$this->sessionToken();
|
||||
|
|
|
@ -89,7 +89,8 @@ class NoticeForm extends Form
|
|||
} else {
|
||||
$this->user = common_current_user();
|
||||
}
|
||||
|
||||
|
||||
$this->enctype = 'multipart/form-data';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,18 +137,25 @@ class NoticeForm extends Form
|
|||
{
|
||||
$this->out->element('label', array('for' => 'notice_data-text'),
|
||||
sprintf(_('What\'s up, %s?'), $this->user->nickname));
|
||||
$this->out->elementStart('span', array('style' => 'float: right; margin-top: 2em;'));
|
||||
// $this->out->element('a', array('href' => '#attach'), ' [ATTACH]');
|
||||
$this->out->elementEnd('span');
|
||||
// XXX: vary by defined max size
|
||||
$this->out->element('textarea', array('id' => 'notice_data-text',
|
||||
'cols' => 35,
|
||||
'rows' => 4,
|
||||
'name' => 'status_textarea'),
|
||||
($this->content) ? $this->content : '');
|
||||
|
||||
$this->out->elementStart('dl', 'form_note');
|
||||
$this->out->element('dt', null, _('Available characters'));
|
||||
$this->out->element('dd', array('id' => 'notice_text-count'),
|
||||
'140');
|
||||
$this->out->elementEnd('dl');
|
||||
$this->out->element('br', array('style' => 'clear:both'));
|
||||
// $this->out->elementStart('a', array('href' => '#'));
|
||||
$this->out->element('label', array('for' => 'notice_data-attach'), _('Upload: '));
|
||||
// $this->out->elementEnd('a');
|
||||
$this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach'));
|
||||
|
||||
if ($this->action) {
|
||||
$this->out->hidden('notice_return-to', $this->action, 'returnto');
|
||||
|
|
|
@ -206,6 +206,7 @@ class NoticeListItem extends Widget
|
|||
return 'shownotice' !== $this->out->args['action'];
|
||||
}
|
||||
|
||||
/*
|
||||
function attachmentCount($discriminant = true) {
|
||||
$file_oembed = new File_oembed;
|
||||
$query = "select count(*) as c from file_oembed join file_to_post on file_oembed.file_id = file_to_post.file_id where post_id=" . $this->notice->id;
|
||||
|
@ -213,11 +214,16 @@ class NoticeListItem extends Widget
|
|||
$file_oembed->fetch();
|
||||
return intval($file_oembed->c);
|
||||
}
|
||||
*/
|
||||
|
||||
function showWithAttachment() {
|
||||
}
|
||||
|
||||
function showNoticeInfo()
|
||||
{
|
||||
$this->out->elementStart('div', 'entry-content');
|
||||
$this->showNoticeLink();
|
||||
// $this->showWithAttachment();
|
||||
$this->showNoticeSource();
|
||||
$this->showContext();
|
||||
$this->out->elementEnd('div');
|
||||
|
@ -388,6 +394,11 @@ class NoticeListItem extends Widget
|
|||
$this->out->element('abbr', array('class' => 'published',
|
||||
'title' => $dt),
|
||||
common_date_string($this->notice->created));
|
||||
|
||||
$f2p = File_to_post::staticGet('post_id', $this->notice->id);
|
||||
if (!empty($f2p)) {
|
||||
$this->out->text(_(' (with attachments) '));
|
||||
}
|
||||
$this->out->elementEnd('a');
|
||||
$this->out->elementEnd('dd');
|
||||
$this->out->elementEnd('dl');
|
||||
|
|
|
@ -164,6 +164,12 @@ class Router
|
|||
array('action' => 'newnotice'),
|
||||
array('replyto' => '[A-Za-z0-9_-]+'));
|
||||
|
||||
/*
|
||||
$m->connect('notice/:notice/file',
|
||||
array('action' => 'file'),
|
||||
array('notice' => '[0-9]+'));
|
||||
*/
|
||||
|
||||
$m->connect('notice/:notice',
|
||||
array('action' => 'shownotice'),
|
||||
array('notice' => '[0-9]+'));
|
||||
|
|
Loading…
Reference in New Issue
Block a user