[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/ -> pdf.php (source)

   1  <?php
   2  /**
   3  * @version $Id: pdf.php 5075 2006-09-15 23:49:17Z friesengeist $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  * Created by Phil Taylor me@phil-taylor.com
  13  * Support file to display PDF Text Only using class from - http://www.ros.co.nz/pdf/readme.pdf
  14  * HTMLDoc is available from: http://www.easysw.com/htmldoc and needs installing on the server for better HTML to PDF conversion
  15  **/
  16  
  17  // no direct access
  18  defined( '_VALID_MOS' ) or die( 'Restricted access' );
  19  
  20  function dofreePDF() {
  21      global $mosConfig_live_site, $mosConfig_sitename, $mosConfig_offset;
  22      global $mainframe, $database, $my;
  23      
  24      $id         = intval( mosGetParam( $_REQUEST, 'id', 1 ) );
  25      
  26      $gid         = $my->gid;
  27      $now         = _CURRENT_SERVER_TIME;
  28      $nullDate     = $database->getNullDate();
  29      
  30      // query to check for state and access levels
  31      $query = "SELECT a.*, cc.name AS category, s.name AS section, s.published AS sec_pub, cc.published AS cat_pub,"
  32      . "\n  s.access AS sec_access, cc.access AS cat_access, s.id AS sec_id, cc.id as cat_id"
  33      . "\n FROM #__content AS a"
  34      . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
  35      . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = 'content'"
  36      . "\n WHERE a.id = " . (int) $id
  37      . "\n AND a.state = 1"
  38      . "\n AND a.access <= " . (int) $gid
  39      . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
  40      . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"    
  41      ;
  42      $database->setQuery( $query );
  43      $row = NULL;
  44      
  45      if ( $database->loadObject( $row ) ) {
  46          /*
  47          * check whether category is published
  48          */
  49          if ( !$row->cat_pub && $row->catid ) {
  50              mosNotAuth();  
  51              return;
  52          }
  53          /*
  54          * check whether section is published
  55          */
  56          if ( !$row->sec_pub && $row->sectionid ) {
  57              mosNotAuth(); 
  58              return;
  59          }
  60          /*
  61          * check whether category access level allows access
  62          */
  63          if ( ($row->cat_access > $gid) && $row->catid ) {
  64              mosNotAuth();  
  65              return;
  66          }
  67          /*
  68          * check whether section access level allows access
  69          */
  70          if ( ($row->sec_access > $gid) && $row->sectionid ) {
  71              mosNotAuth();  
  72              return;
  73          }
  74          
  75          include ( 'includes/class.ezpdf.php' );
  76      
  77          $params = new mosParameters( $row->attribs );    
  78          $params->def( 'author',     !$mainframe->getCfg( 'hideAuthor' ) );
  79          $params->def( 'createdate', !$mainframe->getCfg( 'hideCreateDate' ) );
  80          $params->def( 'modifydate', !$mainframe->getCfg( 'hideModifyDate' ) );
  81          
  82          $row->fulltext     = pdfCleaner( $row->fulltext );
  83          $row->introtext = pdfCleaner( $row->introtext );
  84      
  85          $pdf = new Cezpdf( 'a4', 'P' );  //A4 Portrait
  86          $pdf -> ezSetCmMargins( 2, 1.5, 1, 1);
  87          $pdf->selectFont( './fonts/Helvetica.afm' ); //choose font
  88      
  89          $all = $pdf->openObject();
  90          $pdf->saveState();
  91          $pdf->setStrokeColor( 0, 0, 0, 1 );
  92      
  93          // footer
  94          $pdf->addText( 250, 822, 6, $mosConfig_sitename );
  95          $pdf->line( 10, 40, 578, 40 );
  96          $pdf->line( 10, 818, 578, 818 );
  97          $pdf->addText( 30, 34, 6, $mosConfig_live_site );
  98          $pdf->addText( 250, 34, 6, _PDF_POWERED );
  99          $pdf->addText( 450, 34, 6, _PDF_GENERATED .' '. date( 'j F, Y, H:i', time() + $mosConfig_offset * 60 * 60 ) );
 100      
 101          $pdf->restoreState();
 102          $pdf->closeObject();
 103          $pdf->addObject( $all, 'all' );
 104          $pdf->ezSetDy( 30 );
 105      
 106          $txt1 = $row->title;
 107          $pdf->ezText( $txt1, 14 );
 108      
 109          $txt2 = AuthorDateLine( $row, $params );
 110      
 111          $pdf->ezText( $txt2, 8 );
 112          
 113          $txt3 = $row->introtext ."\n". $row->fulltext;
 114          $pdf->ezText( $txt3, 10 );
 115          
 116          $pdf->ezStream();
 117      } else {
 118          mosNotAuth();
 119          return;
 120      }
 121  }
 122  
 123  function decodeHTML( $string ) {
 124      $string = strtr( $string, array_flip(get_html_translation_table( HTML_ENTITIES ) ) );
 125      $string = preg_replace( "/&#([0-9]+);/me", "chr('\\1')", $string );
 126      
 127      return $string;
 128  }
 129  
 130  function get_php_setting ($val ) {
 131      $r = ( ini_get( $val ) == '1' ? 1 : 0 );
 132      
 133      return $r ? 'ON' : 'OFF';
 134  }
 135  
 136  function pdfCleaner( $text ) {    
 137      // Ugly but needed to get rid of all the stuff the PDF class cant handle
 138      
 139      $text = str_replace( '<p>',             "\n\n",     $text );
 140      $text = str_replace( '<P>',             "\n\n",     $text );
 141      $text = str_replace( '<br />',             "\n",         $text );
 142      $text = str_replace( '<br>',             "\n",         $text );
 143      $text = str_replace( '<BR />',             "\n",         $text );
 144      $text = str_replace( '<BR>',             "\n",         $text );
 145      $text = str_replace( '<li>',             "\n - ",     $text );
 146      $text = str_replace( '<LI>',             "\n - ",     $text );
 147      $text = str_replace( '{mosimage}',         '',         $text );
 148      $text = str_replace( '{mospagebreak}',     '',            $text );
 149      
 150      $text = strip_tags( $text );
 151      $text = decodeHTML( $text );
 152  
 153      return $text;
 154  }
 155  
 156  function AuthorDateLine( &$row, &$params ) {
 157      global $database;
 158      
 159      $text = '';
 160      
 161      if ( $params->get( 'author' ) ) {
 162          // Display Author name
 163          
 164          //Find Author Name
 165          $users_rows = new mosUser( $database );
 166          $users_rows->load( $row->created_by );
 167          $row->author     = $users_rows->name;
 168          $row->usertype     = $users_rows->usertype;        
 169          
 170          if ($row->usertype == 'administrator' || $row->usertype == 'superadministrator') {
 171              $text .= "\n";
 172              $text .=  _WRITTEN_BY .' '. ( $row->created_by_alias ? $row->created_by_alias : $row->author );
 173          } else {
 174              $text .= "\n";
 175              $text .=  _AUTHOR_BY .' '. ( $row->created_by_alias ? $row->created_by_alias : $row->author );
 176          }
 177      }
 178      
 179      if ( $params->get( 'createdate' ) && $params->get( 'author' ) ) {
 180          // Display Separator
 181          $text .= "\n";
 182      }
 183      
 184      if ( $params->get( 'createdate' ) ) {
 185          // Display Created Date
 186          if ( intval( $row->created ) ) {
 187              $create_date     = mosFormatDate( $row->created );
 188              $text             .= $create_date;
 189          }                
 190      }    
 191      
 192      if ( $params->get( 'modifydate' ) && ( $params->get( 'author' ) || $params->get( 'createdate' ) ) ) {
 193          // Display Separator
 194          $text .= "\n";
 195      }
 196      
 197      if ( $params->get( 'modifydate' ) ) {
 198          // Display Modified Date
 199          if ( intval( $row->modified ) ) {
 200              $mod_date     = mosFormatDate( $row->modified );
 201              $text         .= _LAST_UPDATED .' '. $mod_date;
 202              
 203          }
 204      }    
 205      
 206      $text .= "\n\n";
 207  
 208      return $text;
 209  }
 210  
 211  dofreePDF();
 212  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics