$replyto = 'false';
}
- $upload = null;
- $upload = MediaFile::fromUpload('attach');
-
- if (isset($upload)) {
-
- $content_shortened .= ' ' . $upload->shortUrl();
-
- if (Notice::contentTooLong($content_shortened)) {
+ $uploads = array();
+ foreach($_FILES as $name => $value) {
+ if(substr($name, 0, 6) == "attach") {
+ $upload = MediaFile::fromUpload($name);
+ if (isset($upload)) {
+ $content_shortened .= ' ' . $upload->shortUrl();
+ }
+ }
+ }
+ if (Notice::contentTooLong($content_shortened)) {
+ foreach($uploads as $upload) {
$upload->delete();
- $this->clientError(
- sprintf(
- _('Max notice size is %d chars, including attachment URL.'),
- Notice::maxContent()
- )
- );
}
+ $this->clientError(
+ sprintf(
+ _('Max notice size is %d chars, including attachment URL.'),
+ Notice::maxContent()
+ )
+ );
}
$options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
- if (isset($upload)) {
+ foreach($uploads as $upload) {
$upload->attachToNotice($notice);
}
-
-
if ($this->boolean('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
CounterBlackout: false,
MaxLength: 140,
PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
- HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]
+ HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307],
+ UploadCounter: 0
},
S: { // Selector
FormNoticeXHR: function(form) {
SN.C.I.NoticeDataGeo = {};
form.append('<input type="hidden" name="ajax" value="1"/>');
+
form.ajaxForm({
dataType: 'xml',
timeout: '60000',
}
else {
if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
- form
- .resetForm()
- .find('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ form.resetForm();
+ SN.U.NoticeClearAttachments(form);
+ SN.C.I.UploadCounter = 0;
+ SN.U.NoticeNewAttachment($('fieldset', form));
SN.U.FormNoticeEnhancements(form);
}
else {
}
}
form.resetForm();
- form.find('#'+SN.C.S.NoticeInReplyTo).val('');
- form.find('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ SN.U.NoticeClearAttachments(form);
+ SN.C.I.UploadCounter = 0;
+ SN.U.NoticeNewAttachment($('fieldset', form));
SN.U.FormNoticeEnhancements(form);
}
},
}
});
},
+
+ NoticeClearAttachments: function(form) {
+ $('input:file', form).remove();
+ $('div[class=' + SN.C.S.Success + ']', form).remove();
+ },
NoticeReply: function() {
if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
}
},
- NoticeDataAttach: function() {
- NDA = $('#'+SN.C.S.NoticeDataAttach);
+ NoticeDataAttach: function(NDANum) {
+ NDA = $('#'+SN.C.S.NoticeDataAttach+NDANum);
NDA.change(function() {
- S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>';
- NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
- if (NDAS.length > 0) {
- NDAS.replaceWith(S);
- }
- else {
- $('#'+SN.C.S.FormNotice).append(S);
- }
- $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
- $('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ S = '<div id="'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>';
+ $('#'+SN.C.S.FormNotice).append(S);
+
+ $('#'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+' button').click(function(){
+ $('#'+this.parentNode.getAttribute("id")).remove();
+ $('#'+this.parentNode.getAttribute("id").replace("_selected", "")).remove();
NDA.val('');
return false;
});
+ SN.C.I.UploadCounter++;
+ NDA.attr('style', 'display: none;');
+ SN.U.NoticeNewAttachment(NDA.parent());
+ $('#notice_data-attach-label').attr('for', SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter);
});
},
+
+ NoticeNewAttachment: function(parent) {
+ NEWFILE = '<input id="'+SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter+'" class="attach" type="file" name="attach'+SN.C.I.UploadCounter+'" title="'+NoticeAttachment_text.AttachFile+'"/>';
+ parent.append(NEWFILE);
+ SN.U.NoticeDataAttach(SN.C.I.UploadCounter);
+ },
NoticeLocationAttach: function() {
var NLat = $('#'+SN.C.S.NoticeLat).val();
SN.U.FormNoticeEnhancements($(this));
});
- SN.U.NoticeDataAttach();
+ SN.U.NoticeDataAttach("");
}
},
}
if (common_config('attachments', 'uploads')) {
- $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
+ $this->out->element('label', array('id' => 'notice_data-attach-label',
+ 'class' => 'attach-label',
+ 'for' => 'notice_data-attach'),
+ _('Attach'));
$this->out->element('input', array('id' => 'notice_data-attach',
+ 'class' => 'attach',
'type' => 'file',
- 'name' => 'attach',
+ 'name' => 'attach0',
'title' => _('Attach a file')));
$this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
}
$this->out->checkbox('notice_data-geo', _('Share my location'), true);
$this->out->elementEnd('div');
$this->out->inlineScript(' var NoticeDataGeo_text = {'.
- 'ShareDisable: "'._('Do not share my location').'",'.
- 'ErrorTimeout: "'._('Sorry, retrieving your geo location is taking longer than expected, please try again later').'"'.
+ 'ShareDisable: ' .json_encode(_('Do not share my location')).','.
+ 'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
+ '} ; var NoticeAttachment_text = {'.
+ 'AttachFile: ' . json_encode(_('Attach a file')) .
'}');
}