Page 1 of 1

Mini-How-To: Using a Print Icon in your component

Posted: Sat May 06, 2006 9:24 pm
by mjaz
From a thread in the dev forum (http://forum.joomla.org/index.php/topic,41153)

I don't know if anything was written about this, so I wrote it myself.

Code: Select all

<?php
global $option; 

global $hide_js; 
// if joomla is called with ?hide_js=1 in the URL, PrintIcon won't work
// if you want to ignore this setting, use the following line instead:
// $hide_js = 1;

$popup = intval( mosGetParam( $_REQUEST, 'popup', 0 ) );

$row = new stdClass; // I don't think $row is used at all.

$params = new mosParameters( '' );

// if set to 0, there won't be a print icon at all
$params->set( 'print', '1' ); 

// set to 0 to use text instead of icon.
$params->set( 'icons', '1' ); 

// if set to 1, this will invoke the browser's print function.
$params->set( 'popup', $popup ); 

// lookup sefRelToAbs in the forum if you don't know what it does.
$link = sefRelToAbs ( 'index2.php?option='.$option.'&popup=1&yourparam=value' );

// if you set status to NULL, or omit it completely, 
//these default settings for the print window will be used. 
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,'
		 .'resizable=yes,width=640,height=480,directories=no,location=no';


mosHTML::PrintIcon( $row, $params, $hide_js, $link, $status ) 

?>

Re: Mini-How-To: Using a Print Icon in your component

Posted: Fri Feb 23, 2007 2:30 pm
by pe7er
Thanks for sharing this info!

Do you know by any chance how to create a custom background in the pop-up screen?
(or how to disable template_css so that the background isn't used in the pop-up)?

For people reading your code, sefRelToAbs converts all links in CMTs to SEF links.
Info: http://forum.joomla.org/index.php/topic,1500.0.html

Re: Mini-How-To: Using a Print Icon in your component

Posted: Fri Feb 23, 2007 4:04 pm
by mjaz
Use [php]$mainframe->addCustomHeadTag()[/php] to add a css file to the popup's html. The css can override anyhting that's in the template's css.
[php]
/**
* Adds a custom html string to the head block
* @param string The html to add to the head
*/
function addCustomHeadTag( $html )[/php]

It should be noted that all of this is for J!1.0.x (or 1.5 with legacy mode)

Re: Mini-How-To: Using a Print Icon in your component

Posted: Fri Feb 23, 2007 4:57 pm
by pe7er
Thanks!

Re: Mini-How-To: Using a Print Icon in your component

Posted: Tue Feb 27, 2007 3:58 pm
by mcsmom
Lets say I wanted to add this to a 3rd Party component. Where would I put it?

Re: Mini-How-To: Using a Print Icon in your component

Posted: Tue Feb 27, 2007 4:44 pm
by pe7er
I've put it at the place where I wanted a Print Icon + functionality.
I used the code at three different places, but you might put it in a new function and call that function from the places where you need the Print Icon.