Bläddra i källkod

Implement printer friendly through CSS also for non-javascript. This
will bring up a new window with read_body loaded with a message box
telling the user to print it. Also tweak the print stylesheet a bit.

Thijs Kinkhorst 17 år sedan
förälder
incheckning
3bcfa15f47

+ 1 - 0
ChangeLog

@@ -247,6 +247,7 @@ Version 1.5.2 - SVN
   - Allow database based preferences to read in default settings from the
     default_pref file next to hardcoding them into the DB class, thanks
     Thierry Godefroy.
+  - Reimplement printer friendly to make use of CSS.
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------

+ 1 - 1
config/conf.pl

@@ -1703,7 +1703,7 @@ sub display_use_tls($) {
 }
 
 # $encode_header_key
-sub command114{
+sub command114 {
     print "Encryption key allows to hide SquirrelMail Received: headers\n";
     print "in outbound messages. Interface uses encryption key to encode\n";
     print "username, remote address and proxied address, then stores encoded\n";

+ 6 - 3
css/print.css

@@ -1,7 +1,10 @@
 /* printer friendly style, currently only targeted at read_body */
 
-#page_header, .readMenuBar, .spacer, form, #listcommands, .field_Options { display: none; }
-
-
+/* Drop any irrelevant stuff that's normally on the read_body page */
+#page_header, .readMenuBar, .spacer, form, #printMessageBox,
+    #listcommands, .field_Options, .attachActions { display: none; }
 
+/* Display attachment list a bit better */
+.header5 { font-size: larger; }
+.readAttachments td, .fieldName { padding-right: 1em; }
 

+ 13 - 23
src/read_body.php

@@ -672,7 +672,7 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
 
 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
     global $base_uri, $where, $what, $show_html_default,
-           $oTemplate, $download_href,
+           $oTemplate, $download_href, $PHP_SELF,
            $unsafe_image_toggle_href, $unsafe_image_toggle_text;
 
     $urlMailbox = urlencode($mailbox);
@@ -688,29 +688,12 @@ function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
     }
     $url = $base_uri.'src/view_header.php?'.$query_string;
 
-
-    // Build the printer friend link
-    /* hackydiehack */
-
-    // Pull "view_unsafe_images" from the URL to find out if the unsafe images
-    // should be displayed. The default is not to display unsafe images.
-    if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
-        // If "view_unsafe_images" isn't part of the URL, default to not
-        // displaying unsafe images.
-        $view_unsafe_images = false;
+    if ( checkForJavaScript() ) { 
+        $pf_params = 'javascript:printThis();';
     } else {
-        //  If "view_unsafe_images" is part of the URL, display unsafe images
-        //  regardless of the value of the URL variable.
-        // FIXME: Do we really want to display the unsafe images regardless of the value in URL variable?
-        $view_unsafe_images = true;
+        $pf_params = set_url_var($PHP_SELF, 'print', '1');
     }
 
-    $pf_params = '?passed_ent_id=' . $urlPassed_ent_id .
-                 '&mailbox=' . $urlMailbox .
-                 '&passed_id=' . $urlPassed_id .
-                 '&view_unsafe_images='. (bool) $view_unsafe_images .
-                 '&show_html_default=' . $show_html_default;
-
     $links = array();
     $links[] = array (
                         'URL'   => $url,
@@ -718,7 +701,8 @@ function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
                      );
     $links[] = array (
                         'URL'   => $pf_params,
-                        'Text'  => _("View Printable Version")
+                        'Text'  => _("Print"),
+                        'Target' => '_blank'
                      );
     $links[] = array (
                         'URL'   => $download_href,
@@ -989,7 +973,13 @@ $_SESSION['mailbox_cache'] = $mailbox_cache;
 $oTemplate->assign('message_list_href', get_message_list_uri($aMailbox['NAME'], $startMessage, $what));
 
 displayPageHeader($color, $mailbox,'','');
-formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,false);
+
+/* this is the non-javascript version of printer friendly */
+if ( sqgetGlobalVar('print', $print, SQ_GET) ) {
+    $oTemplate->display('read_message_print.tpl');
+} else {
+    formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,false);
+}
 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
 
 $oTemplate->assign('message_body', $messagebody);

+ 7 - 1
templates/default/css/default.css

@@ -1100,4 +1100,10 @@ div.viewText td.spacer {
     background-color: #DCDCDC /* __COLOR0__ */;
 }
 
-
+#printMessageBox {
+    background-color: #fffff0;
+    border: 1px solid #f2e93a;
+    margin: 1em;
+    padding: 1em;
+    font-size: x-large;
+}

+ 6 - 0
templates/default/js/default.js

@@ -283,3 +283,9 @@ function checkForm(smaction) {
         }
     }
 }
+
+function printThis()
+{
+    parent.frames['right'].focus();
+    parent.frames['right'].print();
+}

+ 17 - 0
templates/default/read_message_print.tpl

@@ -0,0 +1,17 @@
+<?php
+/**
+ * read_message_print.tpl
+ *
+ * Let a non-JavaScript user know that they can print this page.
+ *
+ * @copyright &copy; 2008 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id: read_menubar_nav.tpl 12415 2007-05-18 11:05:23Z pdontthink $
+ * @package squirrelmail
+ * @subpackage templates
+ */
+?>
+
+<div id="printMessageBox">
+<?php echo _("Use your web browser's Print button or File -&gt; Print menu option to print this email. Afterwards, you can close this browser window again to return to SquirrelMail."); ?>
+</div>

+ 2 - 23
templates/default/read_toolbar.tpl

@@ -11,6 +11,7 @@
  *               following elements:
  *          $link['URL']  - URL needed to access the action
  *          $link['Text'] - Text to be displayed for the action.
+ *          $link['Target'] - Optional link target
  *
  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
@@ -33,31 +34,9 @@ extract($t);
         if (empty($link['Text']))
             continue;
             
-        # Printer firendly link must be handled a little differently
-        if ($link['Text'] == _("View Printable Version")) {
-            if ($javascript_on) {
-                ?>
- <script type="text/javascript">
- <!--
- function printFormat () {
-     var print_win = window.open("../src/printer_friendly_main.php<?php echo $link['URL']; ?>", "Print", "width=800; height=600");
-     print_win.focus();
- }
- // -->
- </script>
- <a href="javascript:printFormat()"><?php echo $link['Text']; ?></a>
-                <?php
-            } else {
-                # everything else follows this format...
-                ?>
- <a href="../src/printer_friendly_bottom.php<?php echo $link['URL']; ?>" target="_blank"><?php echo $link['Text']; ?></a>
-               <?php
-            }
-        } else {
             ?>
- <a href="<?php echo $link['URL']; ?>"><?php echo $link['Text']; ?></a>
+ <a href="<?php echo $link['URL']; ?>"<?php echo (empty($link['Target'])?'':' target="' . $link['Target'] . '"')?>><?php echo $link['Text']; ?></a>
             <?php
-        }
         
         # Spit out a divider between each element
         if ($count < count($links)-1) {

+ 7 - 0
templates/default_advanced/css/advanced.css

@@ -149,4 +149,11 @@
     background: #EEEEEE url(../images/grippie.png) no-repeat center 2px;
 }
 
+#printMessageBox {
+    background-color: #fffff0;
+    border: 1px solid #f2e93a;
+    margin: 1em;
+    padding: 1em;
+    font-size: x-large;
+}
 

+ 17 - 0
templates/default_advanced/read_message_print.tpl

@@ -0,0 +1,17 @@
+<?php
+/**
+ * read_message_print.tpl
+ *
+ * Let a non-JavaScript user know that they can print this page.
+ *
+ * @copyright &copy; 2008 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id: read_menubar_nav.tpl 12415 2007-05-18 11:05:23Z pdontthink $
+ * @package squirrelmail
+ * @subpackage templates
+ */
+?>
+
+<div id="printMessageBox">
+<?php echo _("Use your web browser's Print button or File -&gt; Print menu option to print this email. Afterwards, you can close this browser window again to return to SquirrelMail."); ?>
+</div>