added ability to insert attached images in HTML editor

release-0.6
svncommit 17 years ago
parent deb30262a7
commit 4315b0086b

@ -4,6 +4,7 @@ CHANGELOG RoundCube Webmail
2007/12/10 (estadtherr)
----------
- Upgrade to TinyMCE 2.1.3
- Allow inserting image attachments into HTML messages while composing
2007/12/10 (thomasb)
----------

@ -283,7 +283,7 @@ if ($_task=='mail')
if ($_action=='upload')
include('program/steps/mail/upload.inc');
if ($_action=='compose' || $_action=='remove-attachment')
if ($_action=='compose' || $_action=='remove-attachment' || $_action=='display-attachment')
include('program/steps/mail/compose.inc');
if ($_action=='addcontact')

@ -1884,7 +1884,6 @@ function rcube_webmail()
// upload attachment file
this.upload_file = function(form)
{
if (!form)
return false;

@ -29,8 +29,8 @@ function rcmail_editor_init(skin_path)
theme_advanced_toolbar_align : 'left',
extended_valid_elements : 'font[face|size|color|style],span[id|class|align|style]',
content_css : skin_path + '/editor_content.css',
popups_css : skin_path + '/editor_popup.css',
editor_css : skin_path + '/editor_ui.css'
editor_css : skin_path + '/editor_ui.css',
external_image_list_url : 'program/js/editor_images.js'
});
}

@ -0,0 +1,20 @@
var rc_client = tinyMCEPopup.windowOpener.rcube_webmail_client;
if (rc_client.gui_objects.attachmentlist)
{
var tinyMCEImageList = new Array();
var attachElems = rc_client.gui_objects.attachmentlist.getElementsByTagName("li");
for (i = 0; i < attachElems.length; i++)
{
var liElem = attachElems[i];
var fname = attachElems[i].id;
for (j = 0; j < liElem.childNodes.length; j++)
{
if (liElem.childNodes[j].nodeName == "#text")
{
fname = liElem.childNodes[j].nodeValue;
}
}
tinyMCEImageList.push([fname, rc_client.env.comm_path+'&_action=display-attachment&_file='+attachElems[i].id]);
}
};

@ -1420,7 +1420,7 @@ var TinyMCE_AdvancedTheme = {
_insertImage : function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) {
tinyMCE.execCommand("mceInsertContent", false, tinyMCE.createTagHTML('img', {
src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src), // Force absolute
src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, src), // Force absolute
mce_src : src,
alt : alt,
border : border,

@ -30,7 +30,7 @@ define('RCUBE_COMPOSE_DRAFT', 0x0108);
// remove an attachment
if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
{
{
$id = $regs[1];
if (is_array($_SESSION['compose']['attachments'][$id]))
{
@ -40,8 +40,20 @@ if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_
$OUTPUT->send();
exit;
}
}
}
if ($_action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
{
$id = $regs[1];
if (is_array($_SESSION['compose']['attachments'][$id]))
{
$apath = $_SESSION['compose']['attachments'][$id]['path'];
header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']);
header('Content-Length: ' . filesize($apath));
readfile($apath);
}
exit;
}
$MESSAGE_FORM = NULL;
$MESSAGE = NULL;
@ -52,10 +64,10 @@ $MESSAGE = NULL;
// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
{
{
rcmail_compose_cleanup();
$_SESSION['compose'] = array('id' => uniqid(rand()));
}
}
// add some labels to client
rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
@ -74,7 +86,7 @@ else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET))
if (!empty($msg_uid))
{
{
// similar as in program/steps/mail/show.inc
$MESSAGE = array('UID' => $msg_uid);
$MESSAGE['headers'] = &$IMAP->get_headers($msg_uid);
@ -99,14 +111,13 @@ if (!empty($msg_uid))
{
$_SESSION['compose']['draft_uid'] = $msg_uid;
}
}
}
/****** compose mode functions ********/
function rcmail_compose_headers($attrib)
{
{
global $IMAP, $MESSAGE, $DB, $compose_mode;
static $sa_recipients = array();
@ -153,7 +164,6 @@ function rcmail_compose_headers($attrib)
$allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
$field_type = 'textfield';
break;
}
if ($fname && !empty($_POST[$fname]))
@ -224,12 +234,12 @@ function rcmail_compose_headers($attrib)
$out = $form_start.$out;
return $out;
}
}
function rcmail_compose_header_from($attrib)
{
{
global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode;
// pass the following attributes to the form class
@ -321,12 +331,11 @@ function rcmail_compose_header_from($attrib)
$out = $form_start.$out;
return $out;
}
}
function rcmail_compose_body($attrib)
{
{
global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
list($form_start, $form_end) = get_form_tags($attrib);
@ -457,11 +466,11 @@ function rcmail_compose_body($attrib)
$out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
return $out;
}
}
function rcmail_create_reply_body($body, $bodyIsHtml)
{
{
global $IMAP, $MESSAGE;
if (! $bodyIsHtml)
@ -508,11 +517,11 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
}
return $prefix.$body.$suffix;
}
}
function rcmail_create_forward_body($body, $bodyIsHtml)
{
{
global $IMAP, $MESSAGE;
if (! $bodyIsHtml)
@ -547,11 +556,11 @@ function rcmail_create_forward_body($body, $bodyIsHtml)
rcmail_write_compose_attachments($MESSAGE);
return $prefix.$body;
}
}
function rcmail_create_draft_body($body, $bodyIsHtml)
{
{
global $IMAP, $MESSAGE;
// add attachments
@ -560,11 +569,11 @@ function rcmail_create_draft_body($body, $bodyIsHtml)
rcmail_write_compose_attachments($MESSAGE);
return $body;
}
}
function rcmail_write_compose_attachments(&$message)
{
{
global $IMAP, $CONFIG;
$temp_dir = unslashify($CONFIG['temp_dir']);
@ -594,11 +603,11 @@ function rcmail_write_compose_attachments(&$message)
}
$_SESSION['compose']['forward_attachments'] = TRUE;
}
}
function rcmail_compose_subject($attrib)
{
{
global $CONFIG, $MESSAGE, $compose_mode;
list($form_start, $form_end) = get_form_tags($attrib);
@ -640,11 +649,11 @@ function rcmail_compose_subject($attrib)
$out .= $form_end ? "\n$form_end" : '';
return $out;
}
}
function rcmail_compose_attachment_list($attrib)
{
{
global $OUTPUT, $CONFIG;
// add ID if not given
@ -680,12 +689,11 @@ function rcmail_compose_attachment_list($attrib)
$out .= '</ul>';
return $out;
}
}
function rcmail_compose_attachment_form($attrib)
{
{
global $OUTPUT, $SESS_HIDDEN_FIELD;
// add ID if not given
@ -713,21 +721,21 @@ EOF;
$OUTPUT->add_gui_object('uploadbox', $attrib['id']);
return $out;
}
}
function rcmail_compose_attachment_field($attrib)
{
{
// allow the following attributes to be added to the <input> tag
$attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
$out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
return $out;
}
}
function rcmail_priority_selector($attrib)
{
{
list($form_start, $form_end) = get_form_tags($attrib);
unset($attrib['form']);
@ -748,11 +756,11 @@ function rcmail_priority_selector($attrib)
$out .= $form_end ? "\n$form_end" : '';
return $out;
}
}
function rcmail_receipt_checkbox($attrib)
{
{
list($form_start, $form_end) = get_form_tags($attrib);
unset($attrib['form']);
@ -768,7 +776,7 @@ function rcmail_receipt_checkbox($attrib)
$out .= $form_end ? "\n$form_end" : '';
return $out;
}
}
function rcmail_editor_selector($attrib)
@ -820,7 +828,7 @@ function rcmail_editor_selector($attrib)
function get_form_tags($attrib)
{
{
global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;
$form_start = '';
@ -843,7 +851,7 @@ function get_form_tags($attrib)
$MESSAGE_FORM = $form_name;
return array($form_start, $form_end);
}
}
// register UI objects
@ -859,7 +867,6 @@ $OUTPUT->add_handlers(array(
'receiptcheckbox' => 'rcmail_receipt_checkbox',
));
/****** get contacts for this user and add them to client scripts ********/
require_once('include/rcube_contacts.inc');
@ -868,15 +875,14 @@ $CONTACTS = new rcube_contacts($DB, $USER->ID);
$CONTACTS->set_pagesize(1000);
if ($result = $CONTACTS->list_records())
{
{
$a_contacts = array();
while ($sql_arr = $result->iterate())
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
$OUTPUT->set_env('contacts', $a_contacts);
}
}
parse_template('compose');
?>

@ -248,8 +248,21 @@ else
// add stored attachments, if any
if (is_array($_SESSION['compose']['attachments']))
foreach ($_SESSION['compose']['attachments'] as $attachment)
foreach ($_SESSION['compose']['attachments'] as $id => $attachment)
{
$dispurl = '/\ssrc\s*=\s*[\'"]?\S+display-attachment\S+file=rcmfile' . $id . '[\'"]?/';
$match = preg_match($dispurl, $message_body);
if ($isHtml && ($match > 0))
{
$message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'"', $message_body);
$MAIL_MIME->setHTMLBody($message_body);
$MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name']);
}
else
{
$MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset);
}
}
// add submitted attachments
if (is_array($_FILES['_attachments']['tmp_name']))
@ -382,5 +395,4 @@ else
$OUTPUT->send('iframe');
}
?>

@ -43,7 +43,6 @@ function rcube_identity_form($attrib)
$OUTPUT->add_script("tinyMCE.init({ mode : 'specific_textareas'," .
"apply_source_formatting : true," .
"content_css : '\$__skin_path' + '/editor_content.css'," .
"popups_css : '\$__skin_path' + '/editor_popups.css'," .
"editor_css : '\$__skin_path' + '/editor_ui.css'," .
"theme : 'advanced'," .
"theme_advanced_toolbar_location : 'top'," .

Loading…
Cancel
Save