From d62c4938db1898dcd69bd61d8f64aa0e49f1bbbe Mon Sep 17 00:00:00 2001 From: kink Date: Sun, 8 Jun 2003 14:37:35 +0000 Subject: [PATCH] Fix comp_in_new: make outputing the compose link a function so that the comp_in_new works the same everywhere. In this new function, make sure that comp_in_new still works when JavaScript off. When JavaScript off, do not output all kinds of JavaScript functions which are never going to be called. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4977 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 5 + functions/page_header.php | 323 +++++++++++++++++---------------- functions/strings.php | 23 +++ functions/url_parser.php | 9 +- plugins/listcommands/setup.php | 22 +-- src/addressbook.php | 10 +- src/read_body.php | 25 +-- src/vcard.php | 7 +- 8 files changed, 218 insertions(+), 206 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8be36dcb..51ca2fee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,11 @@ Version 1.5.0 -- CVS - Fixed language bug in posting on modifying/deleting servers on mail_fetch plugin (#742705). - Fixed infinite loop in parseAddress on invalid mailadress (#742584). + - Rewrote ugly "Not a very useful errormessage" to something more friendly. + - Make central function for compose links to make sure compose_in_new always + works the same way. + - Fix that when JavaScript off, compose in new was broken (#749654). + - Do not output JavaScript functions in page_header when JavaScript off. ************************************** *** SquirrelMail Stable Series 1.4 *** diff --git a/functions/page_header.php b/functions/page_header.php index bf731b50..b44a746c 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -66,20 +66,24 @@ ECHO; echo "\n\n\n"; } - -function displayInternalLink($path, $text, $target='') { +function makeInternalLink($path, $text, $target='') { sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); if ($target != '') { $target = " target=\"$target\""; } - echo ''.$text.''; + return ''.$text.''; +} + +function displayInternalLink($path, $text, $target='') { + echo makeInternalLink($path, $text, $target=''); } function displayPageHeader($color, $mailbox, $xtra='', $session=false) { global $hide_sm_attributions, $PHP_SELF, $frame_top, $compose_new_win, $compose_width, $compose_height, - $attachemessages, $provider_name, $provider_uri; + $attachemessages, $provider_name, $provider_uri, + $javascript_on; sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION ); sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION ); @@ -97,121 +101,127 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) { $compose_uri = $base_uri.'src/compose.php?newmessage=1'; $session = 0; } - - switch ( $module ) { - case 'src/read_body.php': - $js =''; - if ($compose_new_win == '1') { - if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { - $compose_width = '640'; - } - if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { - $compose_height = '550'; - } - $js .= "\n".'\n"; + + if($javascript_on) { + + switch ( $module ) { + case 'src/read_body.php': + $js =''; + if ($compose_new_win == '1') { + if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { + $compose_width = '640'; + } + if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { + $compose_height = '550'; + } + $js .= "\n".'\n"; - } - displayHtmlHeader ('SquirrelMail', $js); - $onload = $xtra; - break; - case 'src/compose.php': - $js = '\n"; - $onload = 'onload="checkForm();"'; - displayHtmlHeader ('SquirrelMail', $js); - break; - - default: - $js = '\n"; + $onload = 'onload="checkForm();"'; + displayHtmlHeader ('SquirrelMail', $js); + break; + + default: + $js = '\n"; + $js .= "// -->\n". "\n"; + $onload = 'onload="checkForm();"'; + displayHtmlHeader ('SquirrelMail', $js); + break; - $onload = 'onload="checkForm();"'; - displayHtmlHeader ('SquirrelMail', $js); - break; - + } + } else { + /* do not use JavaScript */ + displayHtmlHeader ('SquirrelMail'); + $onload = ''; } echo "\n\n"; @@ -238,12 +248,7 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) { . html_tag( 'tr', '', '', $color[4] ) ."\n" . html_tag( 'td', '', 'left' ) ."\n"; $urlMailbox = urlencode($mailbox); - if ($compose_new_win == '1') { - echo ''. _("Compose").''; - } - else { - displayInternalLink ("src/compose.php?mailbox=$urlMailbox", _("Compose"), 'right'); - } + echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox); echo "  \n"; displayInternalLink ('src/addressbook.php', _("Addresses"), 'right'); echo "  \n"; @@ -272,55 +277,57 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) { /* blatently copied/truncated/modified from the above function */ function compose_Header($color, $mailbox) { - global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, - $data_dir, $username, $frame_top, $compose_new_win; - - - $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 ); - if (!isset($frame_top)) { - $frame_top = '_top'; - } + global $javascript_on; /* - Locate the first displayable form element - */ - switch ( $module ) { - case 'src/search.php': - $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1; - $onload = "onload=\"document.forms[$pos].elements[2].focus();\""; - displayHtmlHeader (_("Compose")); - break; - default: - $js = '\n"; - $onload = 'onload="checkForm();"'; - displayHtmlHeader (_("Compose"), $js); - break; - + "if( pos >= 0 ) {\n". + "document.forms[i-1].elements[pos].focus();\n". + "}\n". + "}\n"; + $js .= "// -->\n". + "\n"; + $onload = 'onload="checkForm();"'; + displayHtmlHeader (_("Compose"), $js); + break; + } + } else { + /* javascript off */ + displayHtmlHeader(_("Compose")); + $onload = ''; } echo "\n\n"; } -?> \ No newline at end of file +?> diff --git a/functions/strings.php b/functions/strings.php index db5ff7c2..c9e583f6 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -415,6 +415,29 @@ function TrimArray(&$array) { } } +/* returns a link to the compose-page, taking in consideration + * the compose_in_new and javascript settings. */ +function makeComposeLink($url, $text = null) +{ + global $compose_new_win,$javascript_on; + + if(!$text) { + $text = _("Compose"); + } + + if($compose_new_win != '1') { + return makeInternalLink($url, $text, 'right'); + } + + /* if we can use JS, use the fancy window, else just open a new one HTML-style */ + if($javascript_on) { + sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); + return ''. $text.''; + } + + return makeInternalLink($url, $text, '_blank'); +} + $PHP_SELF = php_self(); ?> diff --git a/functions/url_parser.php b/functions/url_parser.php index 0d9fc153..20b1fdae 100644 --- a/functions/url_parser.php +++ b/functions/url_parser.php @@ -35,7 +35,7 @@ $Email_RegExp_Match = '[0-9a-z]([-_.+]?[0-9a-z])*(%' . $Host_RegExp_Match . ')?@' . $Host_RegExp_Match; function parseEmail (&$body) { - global $color, $Email_RegExp_Match, $compose_new_win; + global $color, $Email_RegExp_Match; $sbody = $body; $addresses = array(); @@ -47,12 +47,7 @@ function parseEmail (&$body) { } /* Replace each email address with a compose URL */ foreach ($addresses as $email) { - $comp_uri = '../src/compose.php?send_to='.urlencode($email); - if ($compose_new_win == '1') { - $comp_uri = 'javascript:void(0)" onClick="comp_in_new(' - . "'$comp_uri'" . ')'; - } - $comp_uri = ''.$email.''; + $comp_uri = makeComposeLink('src/compose.php?send_to='.urlencode($email), $email); $body = str_replace($email, $comp_uri, $body); } /* Return number of unique addresses found */ diff --git a/plugins/listcommands/setup.php b/plugins/listcommands/setup.php index 04fdb20b..2337e97f 100644 --- a/plugins/listcommands/setup.php +++ b/plugins/listcommands/setup.php @@ -21,8 +21,7 @@ function squirrelmail_plugin_init_listcommands () { } function plugin_listcommands_menu() { - global $passed_id, $passed_ent_id, $color, $mailbox, - $message, $compose_new_win; + global $passed_id, $passed_ent_id, $color, $mailbox, $message; /** * Array of commands we can deal with from the header. The Reply option @@ -55,28 +54,21 @@ function plugin_listcommands_menu() { if ($proto == 'mailto') { if (($cmd == 'post') || ($cmd == 'owner')) { - $url = 'compose.php?'; + $url = 'src/compose.php?'; } else { - $url = "../plugins/listcommands/mailout.php?action=$cmd&"; + $url = "plugins/listcommands/mailout.php?action=$cmd&"; } $url .= 'send_to=' . strtr($act,'?','&'); - if ($compose_new_win == '1') { - $output[] = "" . $fieldsdescr[$cmd] . ''; - } - else { - $output[] = '' . $fieldsdescr[$cmd] . ''; - } + $output[] = makeComposeLink($url, $fieldsdescr[$cmd]); + if ($cmd == 'post') { $url .= '&passed_id='.$passed_id. '&mailbox='.urlencode($mailbox). (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); $url .= '&action=reply'; - if ($compose_new_win == '1') { - $output[] = "" . $fieldsdescr['reply'] . ''; - } else { - $output[] = '' . $fieldsdescr['reply'] . ''; - } + + $output[] = makeComposeLink($url, $fieldsdescr['reply']); } } else if ($proto == 'href') { $output[] = '' diff --git a/src/addressbook.php b/src/addressbook.php index 4ba7e969..d3d45fba 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -386,13 +386,9 @@ if ($showaddrlist) { html_tag( 'td', '', 'left', '', 'valign="top" width="1%" nowrap' ) . ' '; } $email = $abook->full_address($row); - if ($compose_new_win == '1') { - echo ''; - } - else { - echo ''; - } - echo htmlspecialchars($row['email']) . ' '."\n". + echo makeComposeLink('src/compose.php?send_to='.rawurlencode($email), + htmlspecialchars($row['email']) ) . + ' '."\n". html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'valign="top" width="1%"' ) . "\n"; $line++; diff --git a/src/read_body.php b/src/read_body.php index 3965c674..8d807610 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -472,7 +472,7 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { global $base_uri, $draft_folder, $where, $what, $color, $sort, - $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft, + $startMessage, $PHP_SELF, $save_as_draft, $enable_forward_as_attachment; $topbar_delimiter = ' | '; @@ -505,18 +505,11 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp $s .= '' . _("Delete") . ''; } - $comp_uri = $base_uri . 'src/compose.php' . + $comp_uri = 'src/compose.php' . '?passed_id=' . $passed_id . '&mailbox=' . $urlMailbox . (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); - if ($compose_new_win == '1') { - $link_open = ''; - } else { - $link_open = ''; - } if (($mailbox == $draft_folder) && ($save_as_draft)) { $comp_alt_uri = $comp_uri . '&action=draft'; $comp_alt_string = _("Resume Draft"); @@ -526,7 +519,7 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp } if (isset($comp_alt_uri)) { $s .= $topbar_delimiter; - $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . ''; + $s .= makeComposeLink($comp_alt_uri, $comp_alt_string); } $s .= ''; @@ -594,25 +587,25 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp $s .= '' . "\n" . html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . ''; $comp_action_uri = $comp_uri . '&action=forward'; - $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . ''; + $s .= makeComposeLink($comp_action_uri, _("Forward")); if ($enable_forward_as_attachment) { $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; $s .= $topbar_delimiter; - $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . ''; + $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment")); } $comp_action_uri = $comp_uri . '&action=reply'; $s .= $topbar_delimiter; - $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . ''; + $s .= makeComposeLink($comp_action_uri, _("Reply")); $comp_action_uri = $comp_uri . '&action=reply_all'; $s .= $topbar_delimiter; - $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . ''; + $s .= makeComposeLink($comp_action_uri, _("Reply All")); $s .= ''; - do_hook("read_body_menu_top"); + do_hook('read_body_menu_top'); echo $s; - do_hook("read_body_menu_bottom"); + do_hook('read_body_menu_bottom'); } function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { diff --git a/src/vcard.php b/src/vcard.php index ee109a6c..401e1208 100644 --- a/src/vcard.php +++ b/src/vcard.php @@ -115,10 +115,11 @@ $ShowValues = array( echo '
' . '' . "\n"; -if (isset($vcard_safe['email;internet'])) { $vcard_safe['email;internet'] = '' . $vcard_safe['email;internet'] . - ''; +if (isset($vcard_safe['email;internet'])) { + $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']), + $vcard_safe['email;internet']); } + if (isset($vcard_safe['url'])) { $vcard_safe['url'] = '' . $vcard_safe['url'] . ''; -- 2.25.1