Actions

Talk

Difference between revisions of "PDF Display Fix in IE7"

From Joomla! Documentation

Line 37: Line 37:
 
Regards
 
Regards
 
Mick Holton
 
Mick Holton
 
'''I added code to fix IE8 also.
 
Here are the 2 files:'''
 
 
 
icon.php
 
 
<?php
 
require_once("libraries/joomla/utilities/browser_detection.php");
 
 
/**
 
* @version $Id: icon.php 11213 2008-10-25 12:43:11Z pasamio $
 
* @package Joomla
 
* @subpackage Content
 
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 
* @license GNU/GPL, see LICENSE.php
 
* Joomla! is free software. This version may have been modified pursuant to the
 
* GNU General Public License, and as distributed it includes or is derivative
 
* of works licensed under the GNU General Public License or other free or open
 
* source software licenses. See COPYRIGHT.php for copyright notices and
 
* details.
 
*/
 
 
// no direct access
 
defined('_JEXEC') or die('Restricted access');
 
 
/**
 
* Content Component HTML Helper
 
*
 
* @static
 
* @package Joomla
 
* @subpackage Content
 
* @since 1.5
 
*/
 
class JHTMLIcon
 
{
 
function create($article, $params, $access, $attribs = array())
 
{
 
$uri =& JFactory::getURI();
 
$ret = $uri->toString();
 
 
$url = 'index.php?task=new&ret='.base64_encode($ret).'&id=0&sectionid='.$article->sectionid;
 
 
if ($params->get('show_icons')) {
 
$text = JHTML::_('image.site', 'new.png', '/images/M_images/', NULL, NULL, JText::_('New') );
 
} else {
 
$text = JText::_('New').'&nbsp;';
 
}
 
 
$attribs = array( 'title' => JText::_( 'New' ));
 
return JHTML::_('link', JRoute::_($url), $text, $attribs);
 
}
 
 
function pdf($article, $params, $access, $attribs = array())
 
{
 
$url  = 'index.php?view=article';
 
$url .=  @$article->catslug ? '&catid='.$article->catslug : '';
 
$url .= '&id='.$article->slug.'&format=pdf';
 
 
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
 
 
// checks template image directory for image, if non found default are loaded
 
if ($params->get('show_icons')) {
 
$text = JHTML::_('image.site', 'pdf_button.png', '/images/M_images/', NULL, NULL, JText::_('PDF'));
 
} else {
 
$text = JText::_('PDF').'&nbsp;';
 
}
 
 
$attribs['title'] = JText::_( 'PDF' );
 
$user_browser = browser_detection('browser');
 
          if ($user_browser == 'msie8') {
 
            $attribs['target'] = '_blank';
 
          } else {                   
 
            $attribs['onclick'] =
 
    "window.open(this.href,'win2','".$status."'); return
 
    false;";
 
          }
 
          if ($user_browser == 'msie7') {
 
            $attribs['target'] = '_blank';
 
          } else {                   
 
            $attribs['onclick'] =
 
    "window.open(this.href,'win2','".$status."'); return
 
    false;";
 
          }
 
 
$attribs['rel']    = 'nofollow';
 
 
return JHTML::_('link', JRoute::_($url), $text, $attribs);
 
}
 
 
function email($article, $params, $access, $attribs = array())
 
{
 
$uri =& JURI::getInstance();
 
$base = $uri->toString( array('scheme', 'host', 'port'));
 
$link = $base.JRoute::_( ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid) , false );
 
$url = 'index.php?option=com_mailto&tmpl=component&link='.base64_encode( $link );
 
 
$status = 'width=400,height=350,menubar=yes,resizable=yes';
 
 
if ($params->get('show_icons')) {
 
$text = JHTML::_('image.site', 'emailButton.png', '/images/M_images/', NULL, NULL, JText::_('Email'));
 
} else {
 
$text = '&nbsp;'.JText::_('Email');
 
}
 
 
$attribs['title'] = JText::_( 'Email' );
 
$attribs['onclick'] = "window.open(this.href,'win2','".$status."'); return false;";
 
 
$output = JHTML::_('link', JRoute::_($url), $text, $attribs);
 
return $output;
 
}
 
 
function edit($article, $params, $access, $attribs = array())
 
{
 
$user =& JFactory::getUser();
 
$uri =& JFactory::getURI();
 
$ret = $uri->toString();
 
 
if ($params->get('popup')) {
 
return;
 
}
 
 
if ($article->state < 0) {
 
return;
 
}
 
 
if (!$access->canEdit && !($access->canEditOwn && $article->created_by == $user->get('id'))) {
 
return;
 
}
 
 
JHTML::_('behavior.tooltip');
 
 
$url = 'index.php?view=article&id='.$article->slug.'&task=edit&ret='.base64_encode($ret);
 
$icon = $article->state ? 'edit.png' : 'edit_unpublished.png';
 
$text = JHTML::_('image.site', $icon, '/images/M_images/', NULL, NULL, JText::_('Edit'));
 
 
if ($article->state == 0) {
 
$overlib = JText::_('Unpublished');
 
} else {
 
$overlib = JText::_('Published');
 
}
 
$date = JHTML::_('date', $article->created);
 
$author = $article->created_by_alias ? $article->created_by_alias : $article->author;
 
 
$overlib .= '&lt;br /&gt;';
 
$overlib .= JText::_($article->groups);
 
$overlib .= '&lt;br /&gt;';
 
$overlib .= $date;
 
$overlib .= '&lt;br /&gt;';
 
$overlib .= $author;
 
 
$button = JHTML::_('link', JRoute::_($url), $text);
 
 
$output = '<span class="hasTip" title="'.JText::_( 'Edit Item' ).' :: '.$overlib.'">'.$button.'</span>';
 
return $output;
 
}
 
 
 
function print_popup($article, $params, $access, $attribs = array())
 
{
 
$url  = 'index.php?view=article';
 
$url .=  @$article->catslug ? '&catid='.$article->catslug : '';
 
$url .= '&id='.$article->slug.'&tmpl=component&print=1&layout=default&page='.@ $request->limitstart;
 
 
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
 
 
// checks template image directory for image, if non found default are loaded
 
if ( $params->get( 'show_icons' ) ) {
 
$text = JHTML::_('image.site',  'printButton.png', '/images/M_images/', NULL, NULL, JText::_( 'Print' ) );
 
} else {
 
$text = JText::_( 'ICON_SEP' ) .'&nbsp;'. JText::_( 'Print' ) .'&nbsp;'. JText::_( 'ICON_SEP' );
 
}
 
 
$attribs['title'] = JText::_( 'Print' );
 
$attribs['onclick'] = "window.open(this.href,'win2','".$status."'); return false;";
 
$attribs['rel']    = 'nofollow';
 
 
return JHTML::_('link', JRoute::_($url), $text, $attribs);
 
}
 
 
function print_screen($article, $params, $access, $attribs = array())
 
{
 
// checks template image directory for image, if non found default are loaded
 
if ( $params->get( 'show_icons' ) ) {
 
$text = JHTML::_('image.site',  'printButton.png', '/images/M_images/', NULL, NULL, JText::_( 'Print' ) );
 
} else {
 
$text = JText::_( 'ICON_SEP' ) .'&nbsp;'. JText::_( 'Print' ) .'&nbsp;'. JText::_( 'ICON_SEP' );
 
}
 
return '<a href="#" onclick="window.print();return false;">'.$text.'</a>';
 
}
 
 
}
 
 
 
 
 
 
browser_detection.php
 
 
<?php
 
 
/*
 
Script Name: Simple 'if' PHP Browser detection
 
Author: Harald Hope, Website: http://TechPatterns.com/
 
Script Source URI: http://TechPatterns.com/downloads/php_browser_detection.php
 
Version 2.0.2
 
Copyright (C) 29 June 2007
 
 
Modified 22 April 2008 by Jon Czerwinski
 
Added IE 7 version detection
 
 
This program is free software; you can redistribute it and/or modify it under
 
the terms of the GNU General Public License as published by the Free Software
 
Foundation; either version 3 of the License, or (at your option) any later version.
 
 
This program is distributed in the hope that it will be useful, but WITHOUT
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
 
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
 
 
Coding conventions:
 
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
 
*/
 
 
/*
 
the order is important, because opera must be tested first, and ie4 tested for before ie general
 
same for konqueror, then safari, then gecko, since safari navigator user agent id's with 'gecko' in string.
 
note that $dom_browser is set for all  modern dom browsers, this gives you a default to use, unfortunately we
 
haven't figured out a way to do this with actual method testing, which would be much better and reliable.
 
 
Please note: you have to call the function in order to get access to the variables, you call it by this:
 
 
browser_detection('browser');
 
 
then put you code that you want to use the variables with after that.
 
 
*/
 
 
function browser_detection( $which_test ) {
 
 
        // initialize the variables
 
        $browser = '';
 
        $dom_browser = '';
 
 
        // set to lower case to avoid errors, check to see if http_user_agent is set
 
        $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
 
 
        // run through the main browser possibilities, assign them to the main $browser variable
 
        if (stristr($navigator_user_agent, "opera"))
 
        {
 
                $browser = 'opera';
 
                $dom_browser = true;
 
        }
 
 
/*
 
Test for IE 8 added
 
April 1, 2009
 
Carlo Allegretti
 
Bologna Italy
 
http://callegretti.spaces.live.com/
 
http://www.multimodo.it/
 
*/
 
        elseif (stristr($navigator_user_agent, "msie 8"))
 
        {
 
                $browser = 'msie8';
 
                $dom_browser = false;
 
        }
 
 
/*
 
Test for IE 7 added
 
April 22, 2008
 
Jon Czerwinski
 
*/
 
        elseif (stristr($navigator_user_agent, "msie 7"))
 
        {
 
                $browser = 'msie7';
 
                $dom_browser = false;
 
        }
 
 
        elseif (stristr($navigator_user_agent, "msie 4"))
 
        {
 
                $browser = 'msie4';
 
                $dom_browser = false;
 
        }
 
 
        elseif (stristr($navigator_user_agent, "msie"))
 
        {
 
                $browser = 'msie';
 
                $dom_browser = true;
 
        }
 
 
        elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari")))
 
        {
 
                $browser = 'safari';
 
                $dom_browser = true;
 
        }
 
 
        elseif (stristr($navigator_user_agent, "gecko"))
 
        {
 
                $browser = 'mozilla';
 
                $dom_browser = true;
 
        }
 
 
        elseif (stristr($navigator_user_agent, "mozilla/4"))
 
        {
 
                $browser = 'ns4';
 
                $dom_browser = false;
 
        }
 
 
        else
 
        {
 
                $dom_browser = false;
 
                $browser = false;
 
        }
 
 
        // return the test result you want
 
        if ( $which_test == 'browser' )
 
        {
 
                return $browser;
 
        }
 
        elseif ( $which_test == 'dom' )
 
        {
 
                return $dom_browser;
 
                //  note: $dom_browser is a boolean value, true/false, so you can just test if
 
                // it's true or not.
 
        }
 
}
 
 
/*
 
you would call it like this:
 
 
$user_browser = browser_detection('browser');
 
 
if ( $user_browser == 'opera' )
 
{
 
        do something;
 
}
 
 
or like this:
 
 
if ( browser_detection('dom') )
 
{
 
        execute the code for dom browsers
 
}
 
else
 
{
 
        execute the code for non DOM browsers
 
}
 
 
and so on.......
 
 
 
*/
 
?>
 

Revision as of 09:12, 1 April 2009

This worked well for me and it solved the pdf function in IE8. The next issue that was created was two windows opening in Mozilla Firefox. I'm not much of a coder but this was my fix and it seemed to work...

After updating as per the "PDF Display Fix in IE7" by:

Script Name: Simple 'if' PHP Browser detection Author: Harald Hope, Website: http://TechPatterns.com/ Script Source URI: http://TechPatterns.com/downloads/php_browser_detection.php Version 2.0.2 Copyright (C) 29 June 2007

Modified 22 April 2008 by Jon Czerwinski Added IE 7 version detection

I then made this modification to step 2 only:

STEP 2

Everything is the same except the following code:

   $user_browser = browser_detection('browser');
   if ($user_browser == 'msie7') {
   $attribs['onclick'] =
   "window.open(this.href,'win2','".$status."'); return
   false;";
   }

I removed this code:

   $attribs['target'] = '_blank';
   } else {

It all seems to be working nicely.

I'm now working on adding headers and footers to link back to my site (pdf and print)

Regards Mick Holton