3 * @version $Id: pdf.php 4562 2006-08-18 23:26:32Z stingrey $
\r
5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
\r
6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
\r
7 * Joomla! is free software. This version may have been modified pursuant
\r
8 * to the GNU General Public License, and as distributed it includes or
\r
9 * is derivative of works licensed under the GNU General Public License or
\r
10 * other free or open source software licenses.
\r
11 * See COPYRIGHT.php for copyright notices and details.
\r
12 * Created by Phil Taylor me@phil-taylor.com
\r
13 * Support file to display PDF Text Only using class from - http://www.ros.co.nz/pdf/readme.pdf
\r
14 * HTMLDoc is available from: http://www.easysw.com/htmldoc and needs installing on the server for better HTML to PDF conversion
\r
18 defined( '_VALID_MOS' ) or die( 'Restricted access' );
\r
20 function dofreePDF() {
\r
21 global $mosConfig_live_site, $mosConfig_sitename, $mosConfig_offset;
\r
22 global $mainframe, $database, $my;
\r
24 $id = intval( mosGetParam( $_REQUEST, 'id', 1 ) );
\r
27 $now = _CURRENT_SERVER_TIME;
\r
28 $nullDate = $database->getNullDate();
\r
30 // query to check for state and access levels
\r
31 $query = "SELECT a.*, cc.name AS category, s.name AS section, s.published AS sec_pub, cc.published AS cat_pub,"
\r
32 . "\n s.access AS sec_access, cc.access AS cat_access, s.id AS sec_id, cc.id as cat_id"
\r
33 . "\n FROM #__content AS a"
\r
34 . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
\r
35 . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = 'content'"
\r
36 . "\n WHERE a.id = $id"
\r
37 . "\n AND a.state = 1"
\r
38 . "\n AND a.access <= $gid"
\r
39 . "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
\r
40 . "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
\r
42 $database->setQuery( $query );
\r
45 if ( $database->loadObject( $row ) ) {
\r
47 * check whether category is published
\r
49 if ( !$row->cat_pub && $row->catid ) {
\r
54 * check whether section is published
\r
56 if ( !$row->sec_pub && $row->sectionid ) {
\r
61 * check whether category access level allows access
\r
63 if ( ($row->cat_access > $gid) && $row->catid ) {
\r
68 * check whether section access level allows access
\r
70 if ( ($row->sec_access > $gid) && $row->sectionid ) {
\r
75 include( 'includes/class.ezpdf.php' );
\r
77 $params = new mosParameters( $row->attribs );
\r
78 $params->def( 'author', !$mainframe->getCfg( 'hideAuthor' ) );
\r
79 $params->def( 'createdate', !$mainframe->getCfg( 'hideCreateDate' ) );
\r
80 $params->def( 'modifydate', !$mainframe->getCfg( 'hideModifyDate' ) );
\r
82 $row->fulltext = pdfCleaner( $row->fulltext );
\r
83 $row->introtext = pdfCleaner( $row->introtext );
\r
85 $pdf = new Cezpdf( 'a4', 'P' ); //A4 Portrait
\r
86 $pdf -> ezSetCmMargins( 2, 1.5, 1, 1);
\r
87 $pdf->selectFont( './fonts/Helvetica.afm' ); //choose font
\r
89 $all = $pdf->openObject();
\r
91 $pdf->setStrokeColor( 0, 0, 0, 1 );
\r
94 $pdf->addText( 250, 822, 6, $mosConfig_sitename );
\r
95 $pdf->line( 10, 40, 578, 40 );
\r
96 $pdf->line( 10, 818, 578, 818 );
\r
97 $pdf->addText( 30, 34, 6, $mosConfig_live_site );
\r
98 $pdf->addText( 250, 34, 6, _PDF_POWERED );
\r
99 $pdf->addText( 450, 34, 6, _PDF_GENERATED .' '. date( 'j F, Y, H:i', time() + $mosConfig_offset * 60 * 60 ) );
\r
101 $pdf->restoreState();
\r
102 $pdf->closeObject();
\r
103 $pdf->addObject( $all, 'all' );
\r
104 $pdf->ezSetDy( 30 );
\r
106 $txt1 = $row->title;
\r
107 $pdf->ezText( $txt1, 14 );
\r
109 $txt2 = AuthorDateLine( $row, $params );
\r
111 $pdf->ezText( $txt2, 8 );
\r
113 $txt3 = $row->introtext ."\n". $row->fulltext;
\r
114 $pdf->ezText( $txt3, 10 );
\r
123 function decodeHTML( $string ) {
\r
124 $string = strtr( $string, array_flip(get_html_translation_table( HTML_ENTITIES ) ) );
\r
125 $string = preg_replace( "/&#([0-9]+);/me", "chr('\\1')", $string );
\r
130 function get_php_setting ($val ) {
\r
131 $r = ( ini_get( $val ) == '1' ? 1 : 0 );
\r
133 return $r ? 'ON' : 'OFF';
\r
136 function pdfCleaner( $text ) {
\r
137 // Ugly but needed to get rid of all the stuff the PDF class cant handle
\r
139 $text = str_replace( '<p>', "\n\n", $text );
\r
140 $text = str_replace( '<P>', "\n\n", $text );
\r
141 $text = str_replace( '<br />', "\n", $text );
\r
142 $text = str_replace( '<br>', "\n", $text );
\r
143 $text = str_replace( '<BR />', "\n", $text );
\r
144 $text = str_replace( '<BR>', "\n", $text );
\r
145 $text = str_replace( '<li>', "\n - ", $text );
\r
146 $text = str_replace( '<LI>', "\n - ", $text );
\r
147 $text = str_replace( '{mosimage}', '', $text );
\r
148 $text = str_replace( '{mospagebreak}', '', $text );
\r
150 $text = strip_tags( $text );
\r
151 $text = decodeHTML( $text );
\r
156 function AuthorDateLine( &$row, &$params ) {
\r
161 if ( $params->get( 'author' ) ) {
\r
162 // Display Author name
\r
165 $users_rows = new mosUser( $database );
\r
166 $users_rows->load( $row->created_by );
\r
167 $row->author = $users_rows->name;
\r
168 $row->usertype = $users_rows->usertype;
\r
170 if ($row->usertype == 'administrator' || $row->usertype == 'superadministrator') {
\r
172 $text .= _WRITTEN_BY .' '. ( $row->created_by_alias ? $row->created_by_alias : $row->author );
\r
175 $text .= _AUTHOR_BY .' '. ( $row->created_by_alias ? $row->created_by_alias : $row->author );
\r
179 if ( $params->get( 'createdate' ) && $params->get( 'author' ) ) {
\r
180 // Display Separator
\r
184 if ( $params->get( 'createdate' ) ) {
\r
185 // Display Created Date
\r
186 if ( intval( $row->created ) ) {
\r
187 $create_date = mosFormatDate( $row->created );
\r
188 $text .= $create_date;
\r
192 if ( $params->get( 'modifydate' ) && ( $params->get( 'author' ) || $params->get( 'createdate' ) ) ) {
\r
193 // Display Separator
\r
197 if ( $params->get( 'modifydate' ) ) {
\r
198 // Display Modified Date
\r
199 if ( intval( $row->modified ) ) {
\r
200 $mod_date = mosFormatDate( $row->modified );
\r
201 $text .= _LAST_UPDATED .' '. $mod_date;
\r